BAOLH
2026-07-16 fc53df39ae2f72a9e3154b4e42b714a0a82853bc
工资详情页添加离职试算功能
7 files modified
247 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/constant/Constant.java 5 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/NewSalaryRepository.java 9 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/rest/NewSalaryController.java 8 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/NewSalaryService.java 7 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/NewSalaryServiceImpl.java 110 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/salary/newSalary.js 10 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/salary/newSalary/index.vue 98 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/constant/Constant.java
@@ -1,5 +1,7 @@
package me.zhengjie.modules.constant;
import java.math.BigDecimal;
public class Constant {
    // 角色级别:超级管理员
    public static final Long ROLE_LEVEL_SUPER = 1L;
@@ -453,4 +455,7 @@
    // 字典:企业微信考勤白名单
    public static final String DICT_WECOM_EXCLUDE_LIST = "wecom_exclude_list";
    // 最低限度加班费
    public static final BigDecimal MIN_OVERTIME_PAY = BigDecimal.valueOf(12);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/NewSalaryRepository.java
@@ -48,4 +48,13 @@
    @Modifying
    @Query(value = "DELETE FROM salary WHERE user_id = ?1 AND salary_year_month LIKE CONCAT(?2, '%')", nativeQuery = true)
    void deleteByUserIdAndSalaryYearMonth(Long userId, String salaryYearMonth);
    /**
     * 根据用户ID和工资年月计数
     *
     * @param userId
     * @param salaryYearMonth
     * @return
     */
    int countAllByUserIdAndSalaryYearMonth(Long userId, Timestamp salaryYearMonth);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/rest/NewSalaryController.java
@@ -129,6 +129,14 @@
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    @PostMapping(value = "/resignCalc")
    @Log("离职试算")
    @ApiOperation("离职试算")
    @PreAuthorize("@el.check('newSalary:generate')")
    public ResponseEntity<Object> resignCalcNewSalary(@Validated @RequestBody NewSalaryQueryCriteria criteria) {
        newSalaryService.resignCalc(criteria);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    @GetMapping("/getMeritWage")
    @ApiOperation("获取业绩工资")
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/NewSalaryService.java
@@ -116,5 +116,12 @@
     */
    void generate(NewSalaryQueryCriteria criteria);
    /**
     * 离职试算
     *
     * @param criteria /
     */
    void resignCalc(NewSalaryQueryCriteria criteria);
    Double getMeritWage(Double CompletedAchievementsHoursRate,Long level);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/NewSalaryServiceImpl.java
@@ -18,9 +18,9 @@
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.attendance.domain.AttendanceLeave;
import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository;
import me.zhengjie.modules.attendance.repository.AttendanceOvertimeRepository;
import me.zhengjie.modules.attendance.service.AttendanceLeaveService;
import me.zhengjie.modules.attendance.service.AttendanceService;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria;
@@ -70,7 +70,6 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
@@ -105,6 +104,7 @@
    private final MeritWageRepository meritWageRepository;
    private final MeritLevelRepository meritLevelRepository;
    private final WeComServiceImpl weComService;
    private final AttendanceLeaveService attendanceLeaveService;
    @Override
    public Map<String, Object> queryAll(NewSalaryQueryCriteria criteria, Pageable pageable) {
@@ -388,6 +388,48 @@
    }
    @Override
    public void resignCalc(NewSalaryQueryCriteria criteria) {
        // 用户检索类
        UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
        userQueryCriteria.setEnabled(true);
        if (criteria.getUserIds() != null) {
            userQueryCriteria.setUserIds(criteria.getUserIds());
        }
        // 获取用户列表
        List<UserSmallDto> userDtoList = userService.querySmallAll(userQueryCriteria);
        // 获取用户ID列表
        List<Long> userIds = userDtoList.stream().map(UserSmallDto::getId).collect(Collectors.toList());
        try {
            // 更新打卡状态为等待的考勤信息
            checkAttendanceStatus(userIds, criteria.getTargetYearMonth());
        } catch (Exception e) {
            e.printStackTrace();
            throw new BadRequestException("考勤信息获取失败!");
        }
        // 用户工资信息补完(非重新生成,防止数据覆盖情况)
        List<String> errors = new ArrayList<>();
        Timestamp salaryYearMonth = Timestamp.valueOf(LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
        for (Long userId : userIds) {
            if (newSalaryRepository.countAllByUserIdAndSalaryYearMonth(userId, salaryYearMonth) == 0) {
                singleUserSalarySettlement(userId, criteria.getTargetYearMonth(), errors);
            }
        }
        // 在循环结束后处理错误
        if (!errors.isEmpty()) {
            // 将所有的错误信息收集到一个字符串中
            String errorMessage = String.join("; ", errors);
            // 抛出一个新的异常
            throw new RuntimeException(errorMessage);
        }
        // 离职试算
        for (Long userId : userIds) {
            singleUserResignCalc(userId, criteria.getTargetYearMonth());
        }
    }
    @Override
    public Double getMeritWage(Double completedAchievementsHoursRate, Long level) {
        //获取到当前这个级别的业绩工资
        MeritWage meritWage = meritWageRepository.findByLevelId(level);
@@ -451,6 +493,68 @@
        }
    }
    // 单个用户离职试算
    private void singleUserResignCalc(Long userId, String targetYearMonth) {
        Timestamp salaryYearMonth = Timestamp.valueOf(LocalDate.parse(targetYearMonth, DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
        List<NewSalary> newSalaryList = newSalaryRepository.findByUserIdAndSalaryYearMonth(userId, salaryYearMonth);
        if (newSalaryList.size() > 0) {
            try {
                NewSalary editNewSalary = newSalaryList.get(0);
                StringBuilder strBuilder = new StringBuilder(Optional.ofNullable(editNewSalary.getRemarks()).orElse(""));
                // 全部年假额度
                BigDecimal surplusYearTime = BigDecimal.valueOf(attendanceLeaveService.getAnnualLeaveQuota(userId, String.valueOf(salaryYearMonth.toLocalDateTime().getYear())));
                // 剩余年假
                BigDecimal remainYearTime = BigDecimal.valueOf(attendanceLeaveService.getYearTimeLength(userId, String.valueOf(salaryYearMonth.toLocalDateTime().getYear())));
                // 离职前可用额度
                BigDecimal resignYearTime = surplusYearTime.multiply(BigDecimal.valueOf(salaryYearMonth.toLocalDateTime().getMonthValue())).divide(BigDecimal.valueOf(12), 2, RoundingMode.HALF_UP);
                // 超出额度
                BigDecimal exceedYearTime = surplusYearTime.subtract(remainYearTime).subtract(resignYearTime).max(BigDecimal.ZERO);
                strBuilder.append("\n年假(扣除):\n");
                strBuilder.append(String.format("【基本工资 / 174 * 超出额度H】:%.2f / 174 * %.2f = %.2f \n", editNewSalary.getBasicWage(), exceedYearTime, editNewSalary.getBasicWage().divide(BigDecimal.valueOf(174), 2, RoundingMode.HALF_UP).multiply(exceedYearTime)));
                // 调休结算
                strBuilder.append("\n调休(结算):\n");
                UserLevelWageQueryCriteria criteria = new UserLevelWageQueryCriteria();
                criteria.setUserId(userId);
                criteria.setTargetYearMonth(targetYearMonth);
                UserLevelWageDto userLevelWageDto = userLevelWageService.queryTargetYearMonth(criteria);
                BigDecimal minOvertimePay = Constant.MIN_OVERTIME_PAY;
                BigDecimal attendanceLegalHolidayHours = BigDecimal.ZERO;
                BigDecimal attendanceWeekendHours = BigDecimal.ZERO;
                // 结算日期范围划定
                LocalDate currentLocalDate = salaryYearMonth.toLocalDateTime().toLocalDate().plusMonths(1);
                LocalDate endLocalDate = LocalDate.now().withDayOfMonth(1).plusMonths(3);
                while (!currentLocalDate.isAfter(endLocalDate)) {
                    // 考勤查询类
                    AttendanceQueryCriteria attendanceQueryCriteria = new AttendanceQueryCriteria();
                    attendanceQueryCriteria.setUserId(userId);
                    attendanceQueryCriteria.setTargetYearMonth(currentLocalDate.toString());
                    // 查询某月需结算的(结算三个月前的,如4月时结算1月份的)法定节假日调休小时数
                    BigDecimal currentLegal = BigDecimal.valueOf(attendanceService.queryAttendanceLegalOverTimeHours(attendanceQueryCriteria));
                    attendanceLegalHolidayHours = attendanceLegalHolidayHours.add(currentLegal);
                    // 查询某月需结算的(结算三个月前的,如4月时结算1月份的)非法定节假日调休小时数
                    BigDecimal currentUnLegal = BigDecimal.valueOf(attendanceService.queryAttendanceUnLegalOverTimeHours(attendanceQueryCriteria));
                    attendanceWeekendHours = attendanceWeekendHours.add(currentUnLegal);
                    if (currentLegal.doubleValue() > 0 || currentUnLegal.doubleValue() > 0) {
                        strBuilder.append(String.format("%d年%d月:%.2fH \n", currentLocalDate.minusMonths(3).getYear(), currentLocalDate.minusMonths(3).getMonthValue(), currentLegal.add(currentUnLegal)));
                    }
                    currentLocalDate = currentLocalDate.plusMonths(1);
                }
                BigDecimal comptimeWage = editNewSalary.getBasicWage().multiply(attendanceLegalHolidayHours).multiply(BigDecimal.valueOf(3)).divide(BigDecimal.valueOf(174), 2, RoundingMode.HALF_UP)
                        .add(Optional.ofNullable(userLevelWageDto.getOverTimeWage()).orElse(minOvertimePay).multiply(attendanceWeekendHours));
                strBuilder.append(String.format("【(基本工资 * 法定假日剩余调休H * 3 / 174) + (加班费 * 非法定假日剩余调休H)】:(%.2f * %.2f * 3 / 174) + (%.2f * %.2f) = %.2f \n", editNewSalary.getBasicWage(), attendanceLegalHolidayHours, Optional.ofNullable(userLevelWageDto.getOverTimeWage()).orElse(minOvertimePay), attendanceWeekendHours, comptimeWage));
                // 保存数据
                editNewSalary.setRemarks(strBuilder.toString());
                newSalaryRepository.save(editNewSalary);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    // 获取平日加班费
    private NewSalary getNormalOverTimeWage(Long userId, String targetYearMonth, NewSalary newSalary) throws ParseException {
        // 考勤查询类
@@ -478,7 +582,7 @@
        JSONObject calcFormulaJson = Optional.ofNullable(newSalary.getCalcFormula()).map(JSONObject::parseObject).orElse(new JSONObject(4));
        // 平日加班费
        BigDecimal minOvertimePay = BigDecimal.valueOf(12);
        BigDecimal minOvertimePay = Constant.MIN_OVERTIME_PAY;
        if (userLevelWageDto.getOverTimeWage() != null) {
//            System.out.println("用户" + userId + "的级别工资中平日加班时间" + attendanceHours + "小时,配置加班费用为:" + userLevelWageDto.getOverTimeWage() + "元/小时!");
            newSalary.setOvertimeAllowance(userLevelWageDto.getOverTimeWage().multiply(BigDecimal.valueOf(overtimeHours).add(BigDecimal.valueOf(overtimeHolidayHours)).add(BigDecimal.valueOf(overtimeWeekendHolidayHours))));
eladmin-web-master/src/api/salary/newSalary.js
@@ -71,4 +71,12 @@
  })
}
export default { getAll, add, edit, del, workDays, publicity, approve, generate, getMeritWage }
export function resignCalc(data) {
  return request({
    url: 'api/newSalary/resignCalc',
    method: 'POST',
    data
  })
}
export default { getAll, add, edit, del, workDays, publicity, approve, generate, getMeritWage, resignCalc }
eladmin-web-master/src/views/salary/newSalary/index.vue
@@ -68,6 +68,16 @@
          style="margin-right: 6px;"
          @click="openGenerate"
        >生成</el-button>
        <el-button
          slot="right"
          v-permission="permission.generate"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-plus"
          style="margin-right: 6px;"
          @click="openResignCalc"
        >离职试算</el-button>
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="690px">
@@ -426,6 +436,37 @@
          <el-button :loading="generateLoading" type="primary" @click="submitGenerate">确认</el-button>
        </div>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="cancelResignCalc" :visible.sync="resignCalc.dialogVisible" title="离职试算" width="500px">
        <el-form ref="resignCalcForm" :model="resignCalc.form" :rules="resignCalc.rules" size="small" label-width="80px">
          <el-form-item label="离职年月" prop="targetYearMonth">
            <el-date-picker
              v-model="resignCalc.form.targetYearMonth"
              value-format="yyyy-MM-dd"
              type="month"
              style="width: 370px;"
              placeholder="请选择"
            />
          </el-form-item>
          <el-form-item label="所属员工" prop="userIds">
            <el-cascader
              v-model="resignCalc.form.userIds"
              :filterable="true"
              :options="options"
              :props="props"
              clearable
              collapse-tags
              placeholder="请选择"
              :show-all-levels="false"
              style="width: 370px"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="cancelResignCalc">取消</el-button>
          <el-button :loading="resignCalc.loading" type="primary" @click="submitResignCalc">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
@@ -675,6 +716,15 @@
        targetYearMonth: [
          { required: true, message: '工资年月不能为空', trigger: 'change' }
        ]
      },
      // 离职试算
      resignCalc: {
        rules: {
          targetYearMonth: [{ required: true, message: '离职年月不能为空', trigger: 'change' }]
        },
        form: { targetYearMonth: null, userIds: [] },
        dialogVisible: false,
        loading: false
      },
      // 预计基本工资随机数
      basicWageRandom: 0,
@@ -1163,6 +1213,54 @@
      }
      this.selval = tempList
    },
    // 生成表单打开
    openResignCalc() {
      const that = this
      // 生成表单状态
      that.$set(that.resignCalc, 'dialogVisible', true)
    },
    // 提交离职试算
    submitResignCalc() {
      const that = this
      // 表单验证
      that.$refs['resignCalcForm'].validate((valid) => {
        if (valid) {
          // 生成表单加载
          that.$set(that.resignCalc, 'loading', true)
          // 用户数据
          const selectUserIds = that.resignCalc.form.userIds.map(item => item[item.length - 1])
          // 离职试算
          crudNewSalary.resignCalc({ targetYearMonth: that.resignCalc.form.targetYearMonth, userIds: selectUserIds }).then(res => {
            // 生成表单加载
            that.$set(that.resignCalc, 'loading', false)
            // 生成表单关闭
            that.cancelResignCalc()
            // 搜索:刷新表格
            that.crud.toQuery()
            // 消息提示
            that.crud.notify('生成成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
          }).catch(() => {
            // 生成表单加载
            that.$set(that.resignCalc, 'loading', false)
            // 生成表单关闭
            that.cancelResignCalc()
            // 搜索:刷新表格
            that.crud.toQuery()
          })
        }
      })
    },
    // 取消离职试算
    cancelResignCalc() {
      const that = this
      // 生成表单状态
      that.$set(that.resignCalc, 'dialogVisible', false)
      that.$set(that.resignCalc, 'loading', false)
      that.$set(that.resignCalc, 'form', { targetYearMonth: null, userIds: [] })
      // 清空表单
      that.$refs['resignCalcForm'].clearValidate()
    },
    // 获取当月最后一天
    getMonthLastDay(dateStr) {
      const date = new Date(dateStr)