huminmin
4 天以前 b8607f49fb2ec4a4113aeb01455e90ae83781bcc
src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -4,7 +4,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.bean.dto.UserAccountDto;
import com.ruoyi.production.bean.dto.UserProductionAccountingDto;
import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
@@ -13,12 +13,8 @@
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.staff.controller.TaxCalculator;
import com.ruoyi.staff.mapper.SchemeApplicableStaffMapper;
import com.ruoyi.staff.mapper.SchemeInsuranceDetailMapper;
import com.ruoyi.staff.mapper.StaffOnJobMapper;
import com.ruoyi.staff.pojo.SchemeApplicableStaff;
import com.ruoyi.staff.pojo.SchemeInsuranceDetail;
import com.ruoyi.staff.pojo.StaffOnJob;
import com.ruoyi.staff.mapper.*;
import com.ruoyi.staff.pojo.*;
import com.ruoyi.staff.service.SchemeApplicableStaffService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -48,21 +44,25 @@
    private final SysUserMapper sysUserMapper;
    private final SysDeptMapper sysDeptMapper;
    private final StaffOnJobMapper staffOnJobMapper;
    private final PersonalShiftMapper personalShiftMapper;
    private final PersonalAttendanceLocationConfigMapper personalAttendanceLocationConfigMapper;
    private final SalesLedgerProductionAccountingService salesLedgerProductionAccountingService;
    private final SubsidyConfigurationMapper subsidyConfigurationMapper;
    @Override
    public R<?> listPage(Page page, SchemeApplicableStaff schemeApplicableStaff) {
    public AjaxResult listPage(Page page, SchemeApplicableStaff schemeApplicableStaff) {
        LambdaQueryWrapper<SchemeApplicableStaff> schemeApplicableStaffLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(schemeApplicableStaff != null){
            if(StringUtils.isNotEmpty(schemeApplicableStaff.getTitle())){
                schemeApplicableStaffLambdaQueryWrapper.like(SchemeApplicableStaff::getTitle, schemeApplicableStaff.getTitle());
            }
        }
        schemeApplicableStaffLambdaQueryWrapper.orderByDesc(SchemeApplicableStaff::getId);
        Page<SchemeApplicableStaff> page1 = schemeApplicableStaffMapper.selectPage(page, schemeApplicableStaffLambdaQueryWrapper);
        List<Long> collect = page1.getRecords().stream().map(SchemeApplicableStaff::getId).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(collect)){
            return R.ok(page1);
            return AjaxResult.success(page1);
        }
        List<SchemeInsuranceDetail> schemeInsuranceDetails = schemeInsuranceDetailMapper
                .selectList(new LambdaQueryWrapper<SchemeInsuranceDetail>()
@@ -82,7 +82,7 @@
                item.setDeptNames(sysDepts.stream().map(SysDept::getDeptName).collect(Collectors.joining(",")));
            }
        });
        return R.ok(page1);
        return AjaxResult.success(page1);
    }
    public void setSchemeApplicableStaffUserInfo(SchemeApplicableStaff schemeApplicableStaff) {
@@ -103,12 +103,12 @@
    }
    @Override
    public R<?> add(SchemeApplicableStaff schemeApplicableStaff) {
    public AjaxResult add(SchemeApplicableStaff schemeApplicableStaff) {
        if(schemeApplicableStaff == null){
            return R.fail("参数错误");
            return AjaxResult.error("参数错误");
        }
        if(CollectionUtils.isEmpty(schemeApplicableStaff.getSchemeInsuranceDetailList())){
            return R.fail("请选择方案明细");
            return AjaxResult.error("请选择方案明细");
        }
        setSchemeApplicableStaffUserInfo(schemeApplicableStaff); //根据部门设置用户信息
        int insert = schemeApplicableStaffMapper.insert(schemeApplicableStaff);
@@ -116,13 +116,13 @@
            item.setSchemeId(schemeApplicableStaff.getId());
            schemeInsuranceDetailMapper.insert(item);
        });
        return R.ok(insert);
        return AjaxResult.success(insert);
    }
    @Override
    public R<?> updateSchemeApplicableStaff(SchemeApplicableStaff schemeApplicableStaff) {
    public AjaxResult updateSchemeApplicableStaff(SchemeApplicableStaff schemeApplicableStaff) {
        if(schemeApplicableStaff == null){
            return R.fail("参数错误");
            return AjaxResult.error("参数错误");
        }
        setSchemeApplicableStaffUserInfo(schemeApplicableStaff); //根据部门设置用户信息
        int update = schemeApplicableStaffMapper.updateById(schemeApplicableStaff);
@@ -133,18 +133,18 @@
            item.setSchemeId(schemeApplicableStaff.getId());
            schemeInsuranceDetailMapper.insert(item);
        });
        return R.ok(update);
        return AjaxResult.success(update);
    }
    @Override
    public R<?> delete(List<Long> ids) {
    public AjaxResult delete(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return R.fail("参数错误");
            return AjaxResult.error("参数错误");
        }
        int delete = schemeApplicableStaffMapper.deleteBatchIds(ids);
        schemeInsuranceDetailMapper.delete(new LambdaQueryWrapper<SchemeInsuranceDetail>()
                .in(SchemeInsuranceDetail::getSchemeId, ids));
        return R.ok(delete);
        return AjaxResult.success(delete);
    }
    /**
@@ -190,15 +190,93 @@
        // 实发工资
        BigDecimal netSalary = new BigDecimal("0.00");
        map.put("netSalary", netSalary);
        // 调用基本工资
        // 根据排班数据计算白班天数和夜班天数
        BigDecimal dayDays = new BigDecimal("0.00");
        BigDecimal nightDays = new BigDecimal("0.00");
        // 查询当月排班记录
        List<PersonalShift> shiftList = personalShiftMapper.selectList(new LambdaQueryWrapper<PersonalShift>()
                .eq(PersonalShift::getStaffOnJobId, staffId)
                .like(PersonalShift::getWorkTime, date));
        if(!CollectionUtils.isEmpty(shiftList)){
            // 收集所有班次配置ID
            List<Integer> configIds = shiftList.stream()
                    .map(PersonalShift::getPersonalAttendanceLocationConfigId)
                    .filter(Objects::nonNull)
                    .collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(configIds)){
                // 查询班次配置信息
                List<PersonalAttendanceLocationConfig> configList = personalAttendanceLocationConfigMapper.selectList(
                        new LambdaQueryWrapper<PersonalAttendanceLocationConfig>()
                                .in(PersonalAttendanceLocationConfig::getId, configIds));
                // 构建班次配置映射
                Map<Integer, String> configMap = configList.stream()
                        .collect(Collectors.toMap(
                                PersonalAttendanceLocationConfig::getId,
                                PersonalAttendanceLocationConfig::getShift,
                                (a, b) -> a));
                // 统计白班和夜班天数
                for (PersonalShift shift : shiftList) {
                    Integer configId = shift.getPersonalAttendanceLocationConfigId();
                    String shiftName = configMap.get(configId);
                    if(shiftName != null){
                        // 根据班次名称判断:包含"白"或"日"为白班,包含"夜"为夜班
                        if(shiftName.contains("白") || shiftName.contains("日")){
                            dayDays = dayDays.add(BigDecimal.ONE);
                        } else if(shiftName.contains("夜")){
                            nightDays = nightDays.add(BigDecimal.ONE);
                        }
                    }
                }
            }
        }
        map.put("dayDays", dayDays); // 白班天数
        map.put("nightDays", nightDays); // 夜班天数
        // 查询餐补和夜班补贴
        // 计算餐补(回族特有)和夜班补助
        BigDecimal mealAmount = new BigDecimal("0.00"); // 餐补
        BigDecimal nightAmount = new BigDecimal("0.00"); // 夜班补助
        // 获取餐补和夜班补贴标准(从补贴配置中获取)
        SubsidyConfiguration subsidyConfig = subsidyConfigurationMapper.selectOne(null);
        BigDecimal mealStandard = new BigDecimal("0.00"); // 餐补标准
        BigDecimal nightStandard = new BigDecimal("0.00"); // 夜班补贴标准
        if(subsidyConfig != null){
            mealStandard = subsidyConfig.getMealAmount() != null ? subsidyConfig.getMealAmount() : new BigDecimal("0.00");
            nightStandard = subsidyConfig.getNightAmount() != null ? subsidyConfig.getNightAmount() : new BigDecimal("0.00");
        }
        // 餐补:民族为回族特有,计算方式为(白班天数+夜班天数)*餐补标准
        StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId);
        if(staffOnJobDto == null){
            return;
        }
        String nation = staffOnJobDto.getNation();
        if("回族".equals(nation)){
            mealAmount = dayDays.add(nightDays).multiply(mealStandard);
        }
        // 夜班补助:夜班天数*夜班补贴标准
        nightAmount = nightDays.multiply(nightStandard);
        map.put("mealAmount", mealAmount); // 餐补
        map.put("nightAmount", nightAmount); // 夜班补助
        // 调用基本工资
        basicSalary = staffOnJobDto.getBasicSalary();
        map.put("basicSalary", basicSalary);
        // 应发工资
        map.put("grossSalary", basicSalary);
        // 应发工资(基本工资+餐补+夜班补助+其他收入)
        grossSalary = basicSalary.add(mealAmount).add(nightAmount).add(otherIncome);
        map.put("grossSalary", grossSalary);
        // 实发工资初始值
        netSalary = grossSalary;
        map.put("netSalary", netSalary);
        // 个税金额(无社保版)
        BigDecimal bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
        map.put("salaryTax", bigDecimal);
@@ -241,10 +319,14 @@
        // 个税金额(社保版)
        bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
        map.put("salaryTax", bigDecimal);
        // 应扣工资
        map.put("deductSalary", bigDecimal.add(fundPersonal).add(socialPersonal));
        // 实发工资
        map.put("netSalary", basicSalary.subtract(bigDecimal).subtract(fundPersonal).subtract(socialPersonal));
        // 应扣工资 = 个税 + 公积金个人 + 社保个人 + 其他支出
        deductSalary = bigDecimal.add(fundPersonal).add(socialPersonal).add(otherDeduct);
        map.put("deductSalary", deductSalary);
        // 实发工资 = 应发工资 - 应扣工资
        netSalary = grossSalary.subtract(deductSalary);
        map.put("netSalary", netSalary);
    }