|
@@ -1,24 +1,44 @@
|
|
|
package com.fjhx.oa.service.user.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
+import com.fjhx.file.entity.FileInfoVo;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
+import com.fjhx.oa.entity.user.dto.UserSalaryDto;
|
|
|
import com.fjhx.oa.entity.user.dto.UserSalarySelectDto;
|
|
|
import com.fjhx.oa.entity.user.po.UserSalary;
|
|
|
+import com.fjhx.oa.entity.user.po.UserSalaryDetail;
|
|
|
+import com.fjhx.oa.entity.user.po.UserSalaryManage;
|
|
|
+import com.fjhx.oa.entity.user.vo.UserSalaryDetailVo;
|
|
|
import com.fjhx.oa.entity.user.vo.UserSalaryVo;
|
|
|
import com.fjhx.oa.mapper.user.UserSalaryMapper;
|
|
|
+import com.fjhx.oa.service.user.UserSalaryDetailService;
|
|
|
+import com.fjhx.oa.service.user.UserSalaryManageService;
|
|
|
import com.fjhx.oa.service.user.UserSalaryService;
|
|
|
+import com.fjhx.tenant.utils.DeptUtils;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.function.Consumer;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 用户薪资备份表 服务实现类
|
|
|
+ * 用户薪资 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author
|
|
@@ -27,14 +47,21 @@ import java.util.function.Consumer;
|
|
|
@Service
|
|
|
public class UserSalaryServiceImpl extends ServiceImpl<UserSalaryMapper, UserSalary> implements UserSalaryService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserSalaryDetailService userSalaryDetailService;
|
|
|
+ @Resource
|
|
|
+ private UserSalaryManageService userSalaryManageService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<UserSalaryVo> getPage(UserSalarySelectDto dto) {
|
|
|
- IWrapper<UserSalary> wrapper = getWrapper();
|
|
|
- wrapper.orderByDesc("us", UserSalary::getId);
|
|
|
- Page<UserSalaryVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper();
|
|
|
+ Page<UserSalaryVo> page = baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<UserSalaryVo> records = page.getRecords();
|
|
|
+ setInfo(records);
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public List<UserSalaryVo> getList(Consumer<LambdaQueryWrapper<UserSalary>> consumer) {
|
|
|
List<UserSalaryVo> userSalaryVos = BeanUtil.copyToList(this.list(consumer), UserSalaryVo.class);
|
|
@@ -42,10 +69,144 @@ public class UserSalaryServiceImpl extends ServiceImpl<UserSalaryMapper, UserSal
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public UserSalaryVo detail(Long id) {
|
|
|
- UserSalary UserSalary = this.getById(id);
|
|
|
- UserSalaryVo result = BeanUtil.toBean(UserSalary, UserSalaryVo.class);
|
|
|
- return result;
|
|
|
+ public UserSalaryVo detail(Long userId) {
|
|
|
+ Assert.notEmpty(userId, "用户Id不能为空!");
|
|
|
+ UserSalaryVo detail = baseMapper.getDetail(userId);
|
|
|
+ if (ObjectUtil.isEmpty(detail)) {
|
|
|
+ throw new ServiceException("查询不到用户薪资信息!");
|
|
|
+ }
|
|
|
+ setInfo(Collections.singletonList(detail));
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public synchronized void edit(UserSalaryDto dto) {
|
|
|
+ Assert.notEmpty(dto.getUserId(), "用户Id不能为空!");
|
|
|
+ Integer dataVer = 0;
|
|
|
+ //先处理历史版本数据
|
|
|
+ List<UserSalaryDetail> oldList = userSalaryDetailService.list(q -> q
|
|
|
+ .eq(UserSalaryDetail::getUserId, dto.getUserId())
|
|
|
+ .eq(UserSalaryDetail::getIsCurrentVer, 1)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(oldList)) {
|
|
|
+ for (UserSalaryDetail userSalaryDetail : oldList) {
|
|
|
+ dataVer = userSalaryDetail.getDataVer();
|
|
|
+ userSalaryDetail.setIsCurrentVer(0);
|
|
|
+ }
|
|
|
+ userSalaryDetailService.updateBatchById(oldList);
|
|
|
+ }
|
|
|
+ //保存历史版本
|
|
|
+ UserSalary oldUserSalary = this.getOne(q -> q.eq(UserSalary::getUserId, dto.getUserId()).eq(UserSalary::getIsCurrentVer, 1));
|
|
|
+ if (ObjectUtil.isNotEmpty(oldUserSalary)) {
|
|
|
+ UserSalary userSalary = BeanUtil.copyProperties(userSalaryManageService.getById(dto.getUserId()), UserSalary.class);
|
|
|
+ userSalary.setId(oldUserSalary.getId());
|
|
|
+ userSalary.setIsCurrentVer(0);
|
|
|
+ this.updateById(userSalary);
|
|
|
+ }
|
|
|
+
|
|
|
+ //再处理新数据
|
|
|
+ //计算工资
|
|
|
+ BigDecimal ratio;
|
|
|
+ if (ObjectUtil.equals(dto.getEmployeeType(), 10)) {
|
|
|
+ BigDecimal internshipRatio = dto.getInternshipRatio();
|
|
|
+ if (ObjectUtil.isEmpty(internshipRatio)) {
|
|
|
+ internshipRatio = oldUserSalary.getInternshipRatio();
|
|
|
+ }
|
|
|
+ ratio = internshipRatio.divide(BigDecimal.valueOf(100));
|
|
|
+ } else if (ObjectUtil.equals(dto.getEmployeeType(), 20)) {
|
|
|
+ BigDecimal probationRatio = dto.getProbationRatio();
|
|
|
+ if (ObjectUtil.isEmpty(probationRatio)) {
|
|
|
+ probationRatio = oldUserSalary.getProbationRatio();
|
|
|
+ }
|
|
|
+ ratio = probationRatio.divide(BigDecimal.valueOf(100));
|
|
|
+ } else if (ObjectUtil.equals(dto.getEmployeeType(), 30)) {
|
|
|
+ ratio = BigDecimal.valueOf(1);
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未知劳动关系!");
|
|
|
+ }
|
|
|
+ BigDecimal amount = dto.getUserSalaryDetailList().stream()
|
|
|
+ .filter(item -> ObjectUtil.equals(item.getType(), 10))
|
|
|
+ .map(UserSalaryDetail::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal perfAmount = dto.getUserSalaryDetailList().stream()
|
|
|
+ .filter(item -> ObjectUtil.equals(item.getType(), 20))
|
|
|
+ .map(UserSalaryDetail::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ dto.setAmount(amount.multiply(ratio).setScale(4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ dto.setPerfAmount(perfAmount.multiply(ratio).setScale(4, BigDecimal.ROUND_HALF_UP));
|
|
|
+
|
|
|
+ dataVer++;//版本号+1
|
|
|
+ userSalaryManageService.updateById(BeanUtil.copyProperties(dto, UserSalaryManage.class));
|
|
|
+ ObsFileUtil.editFile(dto.getFileList(), dto.getUserId(), 10);
|
|
|
+
|
|
|
+ UserSalary newUserSalary = BeanUtil.copyProperties(dto, UserSalary.class);
|
|
|
+ newUserSalary.setDataVer(dataVer);
|
|
|
+ newUserSalary.setIsCurrentVer(1);
|
|
|
+ this.save(newUserSalary);
|
|
|
+ ObsFileUtil.copyFileAndSave(dto.getFileList(), newUserSalary.getId(), 10);
|
|
|
+
|
|
|
+ List<UserSalaryDetail> userSalaryDetailList = dto.getUserSalaryDetailList();
|
|
|
+ for (UserSalaryDetail userSalaryDetail : userSalaryDetailList) {
|
|
|
+ userSalaryDetail.setId(null);
|
|
|
+ userSalaryDetail.setUserSalaryId(newUserSalary.getId());
|
|
|
+ userSalaryDetail.setUserId(dto.getUserId());
|
|
|
+ userSalaryDetail.setDataVer(dataVer);
|
|
|
+ userSalaryDetail.setIsCurrentVer(1);
|
|
|
+ }
|
|
|
+ userSalaryDetailService.saveBatch(userSalaryDetailList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserSalaryVo> getHistoryVerList(Long userId) {
|
|
|
+ Assert.notEmpty(userId, "用户id不能为空!");
|
|
|
+ List<UserSalaryVo> list = this.getList(q -> q
|
|
|
+ .eq(UserSalary::getUserId, userId)
|
|
|
+ .orderByDesc(UserSalary::getDataVer)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //赋值明细
|
|
|
+ List<Long> ids = list.stream().map(UserSalary::getId).collect(Collectors.toList());
|
|
|
+ List<UserSalaryDetailVo> userSalaryDetailVos = userSalaryDetailService.getList(IWrapper.getWrapper()
|
|
|
+ .in(UserSalaryDetail::getUserSalaryId, ids)
|
|
|
+ );
|
|
|
+ Map<Long, List<UserSalaryDetailVo>> collect = userSalaryDetailVos.stream().collect(Collectors.groupingBy(UserSalaryDetail::getUserSalaryId));
|
|
|
+ for (UserSalaryVo userSalary : list) {
|
|
|
+ userSalary.setUserSalaryDetailList(collect.getOrDefault(userSalary.getId(), new ArrayList<>()));
|
|
|
+ }
|
|
|
+
|
|
|
+ UserUtil.assignmentNickName(list, UserSalary::getUserId, UserSalaryVo::setUserName);
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void setInfo(List<UserSalaryVo> list) {
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> userIds = list.stream().map(UserSalary::getUserId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<UserSalaryDetail>> usdMap = userSalaryDetailService.mapKGroup(UserSalaryDetail::getUserId, q -> q
|
|
|
+ .in(UserSalaryDetail::getUserId, userIds)
|
|
|
+ .eq(UserSalaryDetail::getIsCurrentVer, 1)
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(userIds, 10);
|
|
|
+ Map<Long, String> deptNameMap = DeptUtils.getDeptNameMap();
|
|
|
+ for (UserSalaryVo userSalaryManageVo : list) {
|
|
|
+ List<UserSalaryDetail> orDefault = usdMap.getOrDefault(userSalaryManageVo.getUserId(), new ArrayList<>());
|
|
|
+ userSalaryManageVo.setUserSalaryDetailList(BeanUtil.copyToList(orDefault, UserSalaryDetailVo.class));
|
|
|
+ userSalaryManageVo.setFileList(fileMap.getOrDefault(userSalaryManageVo.getUserId(), new ArrayList<>()));
|
|
|
+ userSalaryManageVo.setCompanyName(deptNameMap.get(userSalaryManageVo.getCompanyId()));
|
|
|
+ userSalaryManageVo.setDeptName(deptNameMap.get(userSalaryManageVo.getDeptId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //赋值部门名称树
|
|
|
+ DeptUtils.assignmentDeptNames(list, UserSalaryVo::getDeptId, (item, nameList) -> {
|
|
|
+ item.setDeptNames(nameList.stream().collect(Collectors.joining("=>")));
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|