| | |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.staff.controller.TaxCalculator; |
| | | import com.ruoyi.staff.dto.StaffOnJobDto; |
| | | import com.ruoyi.staff.mapper.SchemeInsuranceDetailMapper; |
| | | import com.ruoyi.staff.mapper.StaffOnJobMapper; |
| | | import com.ruoyi.staff.pojo.SchemeApplicableStaff; |
| | | import com.ruoyi.staff.mapper.SchemeApplicableStaffMapper; |
| | | import com.ruoyi.staff.pojo.SchemeInsuranceDetail; |
| | | import com.ruoyi.staff.pojo.StaffOnJob; |
| | | import com.ruoyi.staff.service.IStaffOnJobService; |
| | | import com.ruoyi.staff.service.SchemeApplicableStaffService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | @Autowired |
| | | private StaffOnJobMapper staffOnJobMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | public void setSchemeApplicableStaffUserInfo(SchemeApplicableStaff schemeApplicableStaff) { |
| | | // 通过部门获取人员id |
| | | List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectList(new LambdaQueryWrapper<SysUserDept>() |
| | | .in(SysUserDept::getDeptId, schemeApplicableStaff.getDeptIds())); |
| | | if(CollectionUtils.isEmpty(sysUserDepts)){ |
| | | String[] split = schemeApplicableStaff.getDeptIds().split(","); |
| | | List<StaffOnJob> staffOnJobs = staffOnJobMapper.selectList(new LambdaQueryWrapper<StaffOnJob>() |
| | | .in(StaffOnJob::getSysDeptId, Arrays.stream(split).map(Long::valueOf).collect(Collectors.toList()))); |
| | | if(CollectionUtils.isEmpty(staffOnJobs)){ |
| | | throw new IllegalArgumentException("部门下无员工"); |
| | | } |
| | | List<SysUser> sysUsers = sysUserMapper.selectUserByIds(sysUserDepts.stream().map(SysUserDept::getUserId).collect(Collectors.toList())); |
| | | if(CollectionUtils.isEmpty(sysUsers)){ |
| | | throw new IllegalArgumentException("部门下无员工"); |
| | | } |
| | | schemeApplicableStaff.setStaffIds(sysUsers |
| | | schemeApplicableStaff.setStaffIds(staffOnJobs |
| | | .stream() |
| | | .map(SysUser::getUserId) |
| | | .map(StaffOnJob::getId) |
| | | .filter(Objects::nonNull) // 过滤掉 null 值 |
| | | .map(String::valueOf) |
| | | .collect(Collectors.joining( ","))); |
| | | schemeApplicableStaff.setStaffNames(sysUsers.stream().map(SysUser::getNickName).collect(Collectors.joining(","))); |
| | | schemeApplicableStaff.setStaffNames(staffOnJobs.stream().map(StaffOnJob::getStaffName).collect(Collectors.joining(","))); |
| | | } |
| | | |
| | | @Override |
| | |
| | | .in(SchemeInsuranceDetail::getSchemeId, ids)); |
| | | return AjaxResult.success(delete); |
| | | } |
| | | |
| | | /** |
| | | * 通过员工id计算社保方案 |
| | | * @param id |
| | | */ |
| | | public void calculateByEmployeeId(Integer id,Map<String, Object> map) { |
| | | // 1. 入参校验 |
| | | if (id == null) { |
| | | return; // 或返回空列表,根据业务需求调整 |
| | | } |
| | | Long staffId = id.longValue(); |
| | | // 社保金额 |
| | | BigDecimal schemeAmount = new BigDecimal("0.00"); |
| | | // 公积金金额 |
| | | BigDecimal gjj = new BigDecimal("0.00"); |
| | | // 基本工资 |
| | | BigDecimal basicSalary = new BigDecimal("0.00"); |
| | | map.put("gjj", gjj); // 公积金 |
| | | map.put("schemeAmount", schemeAmount); // 社保金额 |
| | | map.put("basicSalary", basicSalary); // 基本工资 |
| | | // 个税金额 |
| | | BigDecimal salaryTax = new BigDecimal("0.00"); |
| | | map.put("salaryTax", salaryTax); |
| | | // 计件工资 |
| | | BigDecimal pieceSalary = new BigDecimal("0.00"); |
| | | map.put("pieceSalary", pieceSalary); |
| | | // 计时工资 |
| | | BigDecimal hourlySalary = new BigDecimal("0.00"); |
| | | map.put("hourlySalary", hourlySalary); |
| | | // 其他收入 |
| | | BigDecimal otherIncome = new BigDecimal("0.00"); |
| | | map.put("otherIncome", otherIncome); |
| | | // 其他支出 |
| | | BigDecimal otherDeduct = new BigDecimal("0.00"); |
| | | map.put("otherDeduct", otherDeduct); |
| | | // 应发工资 |
| | | BigDecimal grossSalary = new BigDecimal("0.00"); |
| | | map.put("grossSalary", grossSalary); |
| | | // 应扣工资 |
| | | BigDecimal deductSalary = new BigDecimal("0.00"); |
| | | map.put("deductSalary", deductSalary); |
| | | // 实发工资 |
| | | BigDecimal netSalary = new BigDecimal("0.00"); |
| | | map.put("netSalary", netSalary); |
| | | // 调用基本工资 |
| | | StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId); |
| | | if(staffOnJobDto == null){ |
| | | return; |
| | | } |
| | | basicSalary = staffOnJobDto.getBasicSalary(); |
| | | map.put("basicSalary", basicSalary); |
| | | // 应发工资 |
| | | map.put("grossSalary", basicSalary); |
| | | // 个税金额(无社保版) |
| | | BigDecimal bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, schemeAmount, gjj); |
| | | map.put("salaryTax", bigDecimal); |
| | | // 2. 查询该人员对应的社保方案 |
| | | List<SchemeApplicableStaff> schemeList = schemeApplicableStaffMapper.selectSchemeByStaffId(staffId); |
| | | if (CollectionUtils.isEmpty(schemeList)) { |
| | | return; // 无匹配方案,返回空列表 |
| | | } |
| | | // 3. 为每个方案关联明细列表 |
| | | for (SchemeApplicableStaff scheme : schemeList) { |
| | | List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(scheme.getId()); |
| | | // 根据明细列表计算社保缴费金额 |
| | | if(CollectionUtils.isEmpty(detailList)){ |
| | | continue; |
| | | } |
| | | for (SchemeInsuranceDetail detail : detailList) { |
| | | if("住房公积金".equals(detail.getInsuranceType())){ |
| | | gjj = gjj.add(calculateByEmployeeIdType(detail.getInsuranceType(),gjj, staffOnJobDto, detail)); |
| | | }else{ |
| | | schemeAmount = schemeAmount.add(calculateByEmployeeIdType(detail.getInsuranceType(),schemeAmount, staffOnJobDto, detail)); |
| | | } |
| | | } |
| | | } |
| | | map.put("schemeAmount", schemeAmount); |
| | | map.put("gjj", gjj); |
| | | // 个税金额(社保版) |
| | | bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, schemeAmount, gjj); |
| | | map.put("salaryTax", bigDecimal); |
| | | // 应扣工资 |
| | | map.put("deductSalary", bigDecimal.add(gjj).add(schemeAmount)); |
| | | // 实发工资 |
| | | map.put("netSalary", basicSalary.subtract(bigDecimal).subtract(gjj).subtract(schemeAmount)); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 计算 |
| | | * @param type |
| | | * @param bigDecimal |
| | | * @param staffOnJobDto |
| | | * @param detail |
| | | * @return |
| | | */ |
| | | public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, StaffOnJob staffOnJobDto,SchemeInsuranceDetail detail) { |
| | | // 判断是否调用基本工资 |
| | | if (detail.getUseBasicSalary() == 1) { |
| | | BigDecimal divide = detail.getPaymentBase().multiply(detail.getPersonalRatio()).divide(new BigDecimal("100"), 2); |
| | | bigDecimal = bigDecimal.add(divide); |
| | | }else{ |
| | | // 调用基本工资 |
| | | BigDecimal multiply = staffOnJobDto.getBasicSalary().multiply(detail.getPersonalRatio().divide(new BigDecimal("100"), 2)); |
| | | bigDecimal = bigDecimal.add(multiply); |
| | | } |
| | | bigDecimal = bigDecimal.add(detail.getPersonalFixed()); |
| | | return bigDecimal; |
| | | } |
| | | } |