feat(smartfactory): 新增搬运组薪资确认功能
- 添加确认搬运组薪资的接口和实现逻辑 - 新增相关的数据结构和枚举定义 - 实现薪资确认后的数据处理和插入员工薪资表 - 优化错误处理和数据校验
This commit is contained in:
parent
3aef43868f
commit
32cc7a4f65
@ -40,6 +40,6 @@ public interface ErrorCodeConstants {
|
||||
// ========== 搬运模块 1_000_005_000 ==========
|
||||
ErrorCode CANNOT_FIND_THE_CORRESPONDING_FACTORY_HANDLING_SPECIFICATION = new ErrorCode(1_000_005_001, "找不到对应的工厂搬运规格");
|
||||
ErrorCode FACTORY_HANDLING_SPECIFICATION_EXISTS = new ErrorCode(1_000_005_002, "工厂搬运规格已存在");
|
||||
|
||||
ErrorCode SPECIFICATION_USER_AMOUNT_NOT_EXISTS = new ErrorCode(1_000_005_003, "工厂当前月份存在未分配人员数据!");
|
||||
|
||||
}
|
||||
|
@ -12,10 +12,8 @@ import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupamount
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.vo.HandlingGroupUserAmountItemVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupuseramount.HandlingGroupUserAmountDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsService;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.handlinggroupuseramount.HandlingGroupUserAmountService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -47,9 +45,6 @@ public class HandlingGroupAmountSpecificationsController {
|
||||
@Resource
|
||||
private HandlingGroupUserAmountService handlingGroupUserAmountService;
|
||||
|
||||
@Resource
|
||||
private FactoryInfoService factoryInfoService;
|
||||
|
||||
@PostMapping("/batchCreate")
|
||||
@Operation(summary = "批量创建搬运组工资规格关联")
|
||||
public CommonResult<Boolean> batchCreate(@Valid @RequestBody HandlingGroupAmountSpecificationsBatchCreateVO vo) {
|
||||
|
@ -99,6 +99,15 @@ public class HandlingGroupUserAmountController {
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
@GetMapping("/confirm")
|
||||
@Operation(summary = "确认搬运组薪资")
|
||||
public CommonResult<Boolean> confirmHandlingGroupUserAmount(@RequestParam("factoryId") Long factoryId,
|
||||
@RequestParam("month") String month) {
|
||||
|
||||
handlingGroupUserAmountService.confirmHandlingGroupUserAmount(factoryId, month);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出搬运组每日个人工资记录 Excel")
|
||||
@OperateLog(type = EXPORT)
|
||||
|
@ -6,7 +6,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@ -22,4 +21,7 @@ public class HandlingGroupUserAmountItemVO {
|
||||
@Schema(description = "搬运组每日个人工资")
|
||||
@ExcelProperty("搬运组每日个人工资")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "状态 0未确认 1已确认")
|
||||
private Integer status;
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 搬运组每日个人工资记录 Response VO")
|
||||
@Data
|
||||
@ -38,6 +37,9 @@ public class HandlingGroupUserAmountRespVO {
|
||||
@ExcelProperty("搬运组每日个人工资")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "状态 0.未确认 1.已确认")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -64,4 +63,8 @@ public class HandlingGroupUserAmountDO extends BaseDO {
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 状态 1未确认 2已确认
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 搬运组每日个人工资记录 Mapper
|
||||
@ -72,4 +71,8 @@ public interface HandlingGroupUserAmountMapper extends BaseMapperX<HandlingGroup
|
||||
* @return
|
||||
*/
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupAmountSpecificationsId(@Param("handlingGroupAmountSpecificationsIds") List<Long> handlingGroupAmountSpecificationsIds);
|
||||
|
||||
List<HandlingGroupUserAmountDO> selectAmountSum(@Param("factoryId") Long factoryId, @Param("month") String month);
|
||||
|
||||
Long selectIsExists(@Param("factoryId") Long factoryId, @Param("month") String month);
|
||||
}
|
||||
|
@ -95,4 +95,11 @@ public interface HandlingGroupUserAmountService extends IService<HandlingGroupUs
|
||||
* @return
|
||||
*/
|
||||
List<HandlingGroupUserAmountDO> getByHandlingGroupAmountSpecificationsId(List<Long> handlingGroupAmountSpecificationsIds);
|
||||
|
||||
/**
|
||||
* 确认搬运工组薪资,确认后添加至员工薪资表
|
||||
* @param factoryId
|
||||
* @param month
|
||||
*/
|
||||
void confirmHandlingGroupUserAmount(Long factoryId, String month);
|
||||
}
|
||||
|
@ -1,15 +1,27 @@
|
||||
package cn.iocoder.yudao.module.smartfactory.service.handlinggroupuseramount;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
|
||||
import cn.iocoder.yudao.module.bpm.api.oa.BpmOALoanApi;
|
||||
import cn.iocoder.yudao.module.bpm.api.oa.vo.loan.BpmOALoanSumDTO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.dto.StaffWagesPageDTO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.handlinggroupuseramount.vo.*;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staffsalary.vo.DeductionItemsVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staffsalary.vo.SalarySubjectItemsVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupuseramount.HandlingGroupUserAmountDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staffsalary.StaffSalaryDO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.mysql.handlinggroupamountspecifications.HandlingGroupAmountSpecificationsMapper;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.mysql.handlinggroupuseramount.HandlingGroupUserAmountMapper;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.mysql.staffsalary.StaffSalaryMapper;
|
||||
import cn.iocoder.yudao.module.smartfactory.service.staff.StaffService;
|
||||
import cn.iocoder.yudao.module.system.api.loan.LoanApi;
|
||||
import cn.iocoder.yudao.module.system.api.loan.dto.LoanDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -17,8 +29,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.module.smartfactory.enums.ErrorCodeConstants.SPECIFICATION_USER_AMOUNT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 搬运组每日个人工资记录 Service 实现类
|
||||
@ -33,6 +52,19 @@ public class HandlingGroupUserAmountServiceImpl extends ServiceImpl<HandlingGrou
|
||||
private HandlingGroupUserAmountMapper handlingGroupUserAmountMapper;
|
||||
@Resource
|
||||
private HandlingGroupAmountSpecificationsMapper handlingGroupAmountSpecificationsMapper;
|
||||
|
||||
@Resource
|
||||
private BpmOALoanApi bpmOALoanApi;
|
||||
|
||||
@Resource
|
||||
private LoanApi loanApi;
|
||||
|
||||
@Resource
|
||||
private StaffService staffService;
|
||||
|
||||
@Resource
|
||||
private StaffSalaryMapper staffSalaryMapper;
|
||||
|
||||
private static final String NAME = "姓名";
|
||||
private static final String TOTAL_AMOUNT = "总金额";
|
||||
// 提取常量
|
||||
@ -144,5 +176,76 @@ public class HandlingGroupUserAmountServiceImpl extends ServiceImpl<HandlingGrou
|
||||
return handlingGroupUserAmountMapper.getByHandlingGroupAmountSpecificationsId(handlingGroupAmountSpecificationsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmHandlingGroupUserAmount(Long factoryId, String month) {
|
||||
|
||||
// 查询搬运工 月工资总额
|
||||
List<HandlingGroupUserAmountDO> userAmountSums = handlingGroupUserAmountMapper.selectAmountSum(factoryId, month);
|
||||
if (CollUtil.isEmpty(userAmountSums)) {
|
||||
throw exception(SPECIFICATION_USER_AMOUNT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验 工厂当前月份是否存在未分配搬运工数据
|
||||
Long count = handlingGroupUserAmountMapper.selectIsExists(factoryId, month);
|
||||
if (count > 0L) {
|
||||
throw exception(SPECIFICATION_USER_AMOUNT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 更新搬运组薪资 状态
|
||||
handlingGroupUserAmountMapper.update(null, new LambdaUpdateWrapper<HandlingGroupUserAmountDO>()
|
||||
.set(HandlingGroupUserAmountDO::getStatus, 1)
|
||||
.eq(HandlingGroupUserAmountDO::getFactoryId, factoryId)
|
||||
.like(HandlingGroupUserAmountDO::getDateStr, month));
|
||||
|
||||
// 获取厂区得员工信息
|
||||
Set<Long> staffIds = convertSet(userAmountSums, HandlingGroupUserAmountDO::getUserId);
|
||||
List<StaffDO> staffDOS = staffService.getList(staffIds);
|
||||
Map<Long, StaffDO> staffMap = convertMap(staffDOS, StaffDO::getId);
|
||||
|
||||
// 获取员工借支记录
|
||||
List<BpmOALoanSumDTO> loanDOS = bpmOALoanApi.getListByStaffId(staffIds, month).getCheckedData();
|
||||
Map<Long, BigDecimal> loanMap = loanDOS.stream()
|
||||
.collect(Collectors.toMap(
|
||||
BpmOALoanSumDTO::getSfUserId,
|
||||
BpmOALoanSumDTO::getTotalAmount,
|
||||
BigDecimal::add
|
||||
));
|
||||
|
||||
// 获取员工剩余的 工资借支金额
|
||||
List<LoanDTO> sysLoanDOS = loanApi.getListByMonth(staffIds, month).getCheckedData();
|
||||
Map<Long, BigDecimal> sysLoanMap = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(sysLoanDOS)) {
|
||||
sysLoanMap = sysLoanDOS.stream()
|
||||
.collect(Collectors.toMap(LoanDTO::getUserId, LoanDTO::getRemainingAmount));
|
||||
}
|
||||
|
||||
Map<Long, BigDecimal> finalSysLoanMap = sysLoanMap;
|
||||
List<StaffSalaryDO> salaryDOS = userAmountSums.stream().map(item -> {
|
||||
StaffSalaryDO salaryDO = new StaffSalaryDO()
|
||||
.setStaffId(item.getUserId())
|
||||
.setFactoryId(item.getFactoryId())
|
||||
.setMonth(month)
|
||||
.setPayableAmount(item.getAmount())
|
||||
.setReturnAmount(loanMap.getOrDefault(item.getUserId(), BigDecimal.ZERO)
|
||||
.add(finalSysLoanMap.getOrDefault(item.getUserId(), BigDecimal.ZERO)))
|
||||
.setDeductionItems(Collections.singletonList(
|
||||
new DeductionItemsVO()
|
||||
.setKey("insurance")
|
||||
.setValue("50")));
|
||||
// 设置实发工资
|
||||
salaryDO.setRealAmount(salaryDO.getPayableAmount().subtract(salaryDO.getReturnAmount()));
|
||||
// 设置薪资主体数据
|
||||
if (staffMap.get(item.getUserId()).getSalarySubject() != null) {
|
||||
salaryDO.setSalarySubjectItems(Collections.singletonList(
|
||||
new SalarySubjectItemsVO()
|
||||
.setSalarySubjectId(staffMap.get(item.getUserId()).getSalarySubject())
|
||||
.setAmount(salaryDO.getPayableAmount())
|
||||
));
|
||||
}
|
||||
return salaryDO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 插入工资记录
|
||||
staffSalaryMapper.insertBatch(salaryDOS);
|
||||
}
|
||||
}
|
||||
|
@ -149,4 +149,35 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectAmountSum" resultType="cn.iocoder.yudao.module.smartfactory.dal.dataobject.handlinggroupuseramount.HandlingGroupUserAmountDO">
|
||||
SELECT
|
||||
user_id AS userId,
|
||||
SUM(amount) AS amount
|
||||
FROM
|
||||
sf_handling_group_user_amount
|
||||
WHERE
|
||||
deleted = 0
|
||||
AND status = 0
|
||||
AND factory_id = #{factoryId}
|
||||
AND date_str LIKE CONCAT('%', #{month}, '%')
|
||||
GROUP BY
|
||||
user_id
|
||||
</select>
|
||||
|
||||
<select id="selectIsExists" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
sf_handling_group_amount_specifications a
|
||||
WHERE
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM sf_handling_group_user_amount b
|
||||
WHERE a.factory_id = b.factory_id AND a.date_str = b.date_str
|
||||
)
|
||||
AND a.factory_id = #{factoryId}
|
||||
AND a.date_str LIKE CONCAT('%', #{month}, '%')
|
||||
AND a.deleted = 0
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user