277 lines
12 KiB
Java
277 lines
12 KiB
Java
|
|
package com.engine.salary.service.impl;
|
|||
|
|
|
|||
|
|
import cn.hutool.json.JSONUtil;
|
|||
|
|
import com.engine.common.util.ServiceUtil;
|
|||
|
|
import com.engine.core.impl.Service;
|
|||
|
|
import com.engine.salary.biz.SalarySobBiz;
|
|||
|
|
import com.engine.salary.biz.SalaryTemplateBiz;
|
|||
|
|
import com.engine.salary.entity.salaryBill.bo.SalaryTemplateBO;
|
|||
|
|
import com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO;
|
|||
|
|
import com.engine.salary.entity.salaryBill.dto.SalaryTemplateSalaryItemSetListDTO;
|
|||
|
|
import com.engine.salary.entity.salaryBill.param.SalaryTemplateCopyParam;
|
|||
|
|
import com.engine.salary.entity.salaryBill.param.SalaryTemplateDefaultUseParam;
|
|||
|
|
import com.engine.salary.entity.salaryBill.param.SalaryTemplateQueryParam;
|
|||
|
|
import com.engine.salary.entity.salaryBill.param.SalaryTemplateSaveParam;
|
|||
|
|
import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO;
|
|||
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobItemAggregateDTO;
|
|||
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
|||
|
|
import com.engine.salary.enums.salarybill.SalaryTemplateWhetherEnum;
|
|||
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|||
|
|
import com.engine.salary.service.SalarySobItemService;
|
|||
|
|
import com.engine.salary.service.SalaryTemplateService;
|
|||
|
|
import org.apache.commons.collections.CollectionUtils;
|
|||
|
|
import org.springframework.beans.BeanUtils;
|
|||
|
|
import weaver.hrm.User;
|
|||
|
|
|
|||
|
|
import java.time.LocalDateTime;
|
|||
|
|
import java.util.*;
|
|||
|
|
import java.util.stream.Collectors;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @Description: 工资单模板
|
|||
|
|
* @Author: wangxiangzhong
|
|||
|
|
* @Date: 2021-12-08 14:44
|
|||
|
|
*/
|
|||
|
|
public class SalaryTemplateServiceImpl extends Service implements SalaryTemplateService {
|
|||
|
|
|
|||
|
|
private SalaryTemplateBiz mapper = new SalaryTemplateBiz();
|
|||
|
|
|
|||
|
|
private SalarySobBiz salarySobMapper = new SalarySobBiz();
|
|||
|
|
|
|||
|
|
private SalarySobItemService getSalarySobItemService(User user) {
|
|||
|
|
return ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
|
|||
|
|
}
|
|||
|
|
// @Autowired
|
|||
|
|
// private LoggerTemplate salaryTemplateLoggerTemplate;
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public SalaryTemplatePO getById(Long id) {
|
|||
|
|
return mapper.getById(id);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// @Override
|
|||
|
|
// public Map<String, Object> listPage(SalaryTemplateQueryParam queryParam) {
|
|||
|
|
// mapper.list(queryParam);
|
|||
|
|
// return page;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public String defaultUse(SalaryTemplateDefaultUseParam defaultUseParamy) {
|
|||
|
|
// 校验参数
|
|||
|
|
SalaryTemplateDefaultUseParam.checkParam(defaultUseParamy);
|
|||
|
|
|
|||
|
|
SalaryTemplatePO salaryTemplate = getById(defaultUseParamy.getId());
|
|||
|
|
|
|||
|
|
if (salaryTemplate == null) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板不存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 选中默认使用
|
|||
|
|
SalaryTemplatePO po = new SalaryTemplatePO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
po.setSalarySobId(salaryTemplate.getSalarySobId());
|
|||
|
|
po.setUseType(SalaryTemplateWhetherEnum.FALSE.getValue());
|
|||
|
|
mapper.updateById(po);
|
|||
|
|
|
|||
|
|
SalaryTemplatePO salaryTemplateNew = new SalaryTemplatePO();
|
|||
|
|
BeanUtils.copyProperties(salaryTemplate, salaryTemplateNew);
|
|||
|
|
salaryTemplateNew.setUseType(SalaryTemplateWhetherEnum.TRUE.getValue());
|
|||
|
|
mapper.updateById(salaryTemplateNew);
|
|||
|
|
|
|||
|
|
// 记录日志
|
|||
|
|
// SalaryLoggerUtil.recordUpdateSingleLog(salaryTemplateLoggerTemplate,
|
|||
|
|
// salaryTemplate.getId(),
|
|||
|
|
// salaryTemplateNew.getName(),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100534, "设为默认使用"),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100534, "设为默认使用"),
|
|||
|
|
// salaryTemplate,
|
|||
|
|
// salaryTemplateNew);
|
|||
|
|
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public String save(SalaryTemplateSaveParam saveParam) {
|
|||
|
|
// 校验参数
|
|||
|
|
SalaryTemplateSaveParam.checkParam(saveParam);
|
|||
|
|
|
|||
|
|
SalaryTemplatePO po = new SalaryTemplatePO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
po.setName(saveParam.getName());
|
|||
|
|
List<SalaryTemplatePO> salaryTemplates = mapper.listSome(po);
|
|||
|
|
|
|||
|
|
if (CollectionUtils.isNotEmpty(salaryTemplates)) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板名称不允许重复");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SalarySobPO salarySobPO = new SalarySobPO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
po.setId(saveParam.getSalarySobId());
|
|||
|
|
List<SalarySobPO> salarySobs = salarySobMapper.listSome(salarySobPO);
|
|||
|
|
|
|||
|
|
if (CollectionUtils.isEmpty(salarySobs)) {
|
|||
|
|
throw new SalaryRunTimeException("薪资账套不存在");
|
|||
|
|
}
|
|||
|
|
// todo 薪资项目设置检查校验
|
|||
|
|
// 保存
|
|||
|
|
// saveParam.setId(IdGenerator.generate());
|
|||
|
|
SalaryTemplatePO salaryTemplate = SalaryTemplateBO.convertToPO(saveParam, (long) user.getUID());
|
|||
|
|
salaryTemplate.setSendEmailId(saveParam.getSendEmail());
|
|||
|
|
salaryTemplate.setEmailStatus(saveParam.getEmailStatus()?1:0);
|
|||
|
|
salaryTemplate.setMsgStatus(saveParam.getMsgStatus()?1:0);
|
|||
|
|
salaryTemplate.setTextContentPosition(saveParam.getTextContentPosition());
|
|||
|
|
salaryTemplate.setSalaryItemNullStatus(saveParam.getSalaryItemNullStatus()?1:0);
|
|||
|
|
salaryTemplate.setSalaryItemZeroStatus(saveParam.getSalaryItemZeroStatus()?1:0);
|
|||
|
|
mapper.insert(salaryTemplate);
|
|||
|
|
// 记录日志
|
|||
|
|
// SalaryLoggerUtil.recordAddSingleLog(salaryTemplateLoggerTemplate,
|
|||
|
|
// salaryTemplate.getId(),
|
|||
|
|
// salaryTemplate.getName(),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100538, "新增工资单模板"),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100538, "新增工资单模板"),
|
|||
|
|
// salaryTemplate);
|
|||
|
|
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public String update(SalaryTemplateSaveParam saveParam) {
|
|||
|
|
// 校验参数
|
|||
|
|
SalaryTemplateSaveParam.checkParam(saveParam);
|
|||
|
|
// 校验是否可以编辑
|
|||
|
|
if (saveParam.getId() == null) {
|
|||
|
|
throw new SalaryRunTimeException("参数错误");
|
|||
|
|
}
|
|||
|
|
SalaryTemplatePO salaryTemplate = getById(saveParam.getId());
|
|||
|
|
if (salaryTemplate == null) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板不存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 工资单模板编辑时不允许调整账套
|
|||
|
|
if (!salaryTemplate.getSalarySobId().equals(saveParam.getSalarySobId())) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板编辑时不允许调整账套");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SalaryTemplatePO po = new SalaryTemplatePO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
po.setName(saveParam.getName());
|
|||
|
|
List<SalaryTemplatePO> salaryTemplates = mapper.listSome(po);
|
|||
|
|
|
|||
|
|
boolean nameExist = salaryTemplates.stream().anyMatch(e -> !Objects.equals(e.getId(), saveParam.getId()));
|
|||
|
|
if (nameExist) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板名称不允许重复");
|
|||
|
|
}
|
|||
|
|
SalarySobPO salarySobPO = new SalarySobPO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
po.setId(saveParam.getSalarySobId());
|
|||
|
|
List<SalarySobPO> salarySobs = salarySobMapper.listSome(salarySobPO);
|
|||
|
|
|
|||
|
|
if (CollectionUtils.isEmpty(salarySobs)) {
|
|||
|
|
throw new SalaryRunTimeException("薪资账套不存在");
|
|||
|
|
}
|
|||
|
|
// 更新工资单
|
|||
|
|
SalaryTemplatePO salaryTemplateNew = new SalaryTemplatePO();
|
|||
|
|
BeanUtils.copyProperties(salaryTemplate, salaryTemplateNew);
|
|||
|
|
BeanUtils.copyProperties(saveParam, salaryTemplateNew);
|
|||
|
|
salaryTemplateNew.setUpdateTime(new Date());
|
|||
|
|
salaryTemplateNew.setSendEmailId(saveParam.getSendEmail());
|
|||
|
|
salaryTemplateNew.setEmailStatus(saveParam.getEmailStatus()?1:0);
|
|||
|
|
salaryTemplateNew.setMsgStatus(saveParam.getMsgStatus()?1:0);
|
|||
|
|
salaryTemplateNew.setTextContentPosition(saveParam.getTextContentPosition());
|
|||
|
|
salaryTemplateNew.setSalaryItemNullStatus(saveParam.getSalaryItemNullStatus()?1:0);
|
|||
|
|
salaryTemplateNew.setSalaryItemZeroStatus(saveParam.getSalaryItemZeroStatus()?1:0);
|
|||
|
|
// todo 薪资项目设置检查校验
|
|||
|
|
salaryTemplateNew.setSalaryItemSetting(JSONUtil.toJsonStr(saveParam.getSalaryItemSetting()));
|
|||
|
|
mapper.updateById(salaryTemplateNew);
|
|||
|
|
// 记录日志
|
|||
|
|
// SalaryLoggerUtil.recordUpdateSingleLog(salaryTemplateLoggerTemplate,
|
|||
|
|
// salaryTemplate.getId(),
|
|||
|
|
// salaryTemplateNew.getName(),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100539, "编辑工资单模板"),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100539, "编辑工资单模板"),
|
|||
|
|
// salaryTemplate,
|
|||
|
|
// salaryTemplateNew);
|
|||
|
|
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public String copy(SalaryTemplateCopyParam copyParam) {
|
|||
|
|
// 校验参数
|
|||
|
|
SalaryTemplateCopyParam.checkParam(copyParam);
|
|||
|
|
|
|||
|
|
SalaryTemplatePO salaryTemplate = getById(copyParam.getId());
|
|||
|
|
if (salaryTemplate == null) {
|
|||
|
|
throw new SalaryRunTimeException("被复制的工资单不存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
List<SalaryTemplateListDTO> salaryTemplates = mapper.list(SalaryTemplateQueryParam.builder().name(copyParam.getName()).build());
|
|||
|
|
|
|||
|
|
if (CollectionUtils.isNotEmpty(salaryTemplates)) {
|
|||
|
|
throw new SalaryRunTimeException("工资单模板名称不允许重复");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SalaryTemplatePO salaryTemplateNew = new SalaryTemplatePO();
|
|||
|
|
BeanUtils.copyProperties(salaryTemplate, salaryTemplateNew);
|
|||
|
|
salaryTemplateNew.setName(copyParam.getName());
|
|||
|
|
salaryTemplateNew.setUseType(SalaryTemplateWhetherEnum.FALSE.getValue());
|
|||
|
|
// salaryTemplateNew.setId(IdGenerator.generate());
|
|||
|
|
mapper.insert(salaryTemplateNew);
|
|||
|
|
// 记录日志
|
|||
|
|
// SalaryLoggerUtil.recordAddSingleLog(salaryTemplateLoggerTemplate,
|
|||
|
|
// salaryTemplateNew.getId(),
|
|||
|
|
// salaryTemplateNew.getName(),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100541, "复制工资单模板"),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100541, "复制工资单模板"),
|
|||
|
|
// salaryTemplateNew);
|
|||
|
|
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public String delete(Collection<Long> ids) {
|
|||
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|||
|
|
throw new SalaryRunTimeException("参数错误");
|
|||
|
|
}
|
|||
|
|
List<SalaryTemplateListDTO> salaryTemplates = mapper.list(SalaryTemplateQueryParam.builder().ids(ids).build());
|
|||
|
|
if (CollectionUtils.isEmpty(salaryTemplates)) {
|
|||
|
|
throw new SalaryRunTimeException("要删除的工资单在不存在或已删除");
|
|||
|
|
}
|
|||
|
|
// TODO 正在使用的记录不允许删除
|
|||
|
|
mapper.deleteByIds(ids);
|
|||
|
|
// 记录日志
|
|||
|
|
// salaryTemplates.forEach(e -> SalaryLoggerUtil.recordDeleteSingleLog(salaryTemplateLoggerTemplate,
|
|||
|
|
// e.getId(),
|
|||
|
|
// e.getName(),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100542, "删除工资单模板"),
|
|||
|
|
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100542, "删除工资单模板")+":" + e.getName(),
|
|||
|
|
// e));
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public List<Map<String, Object>> selectSalarySobList() {
|
|||
|
|
SalarySobPO po = new SalarySobPO();
|
|||
|
|
po.setDeleteType(0);
|
|||
|
|
List<SalarySobPO> salarySobs = salarySobMapper.listSome(po);
|
|||
|
|
|
|||
|
|
return salarySobs.stream().map(m->{
|
|||
|
|
Map<String, Object> map = new HashMap<>(2);
|
|||
|
|
map.put("id", String.valueOf(m.getId()));
|
|||
|
|
map.put("content", m.getName());
|
|||
|
|
return map;
|
|||
|
|
}).collect(Collectors.toList());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public List<SalaryTemplateSalaryItemSetListDTO> getSalaryItemSet(Long salarySobId) {
|
|||
|
|
SalarySobItemAggregateDTO salarySobItemAggregate = getSalarySobItemService(user).getAggregateBySalarySobId(salarySobId);
|
|||
|
|
return SalaryTemplateBO.convertSalarySobItemAggregateToSalaryItemSet(salarySobItemAggregate, new Long(user.getUID()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public List<SalaryTemplatePO> getDefaultTemplates(List<Long> salarySobIds) {
|
|||
|
|
return mapper.listDefaultTemplates(salarySobIds);
|
|||
|
|
}
|
|||
|
|
}
|