414 lines
19 KiB
Java
414 lines
19 KiB
Java
package com.engine.salary.service.impl;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.engine.common.util.ServiceUtil;
|
|
import com.engine.core.impl.Service;
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
import com.engine.salary.entity.push.dto.PushSettingDTO;
|
|
import com.engine.salary.entity.push.dto.PushSettingItemDTO;
|
|
import com.engine.salary.entity.push.param.PushSettingItemQueryParam;
|
|
import com.engine.salary.entity.push.param.PushSettingItemSaveParam;
|
|
import com.engine.salary.entity.push.param.PushSettingQueryParam;
|
|
import com.engine.salary.entity.push.param.PushSettingSaveParam;
|
|
import com.engine.salary.entity.push.po.PushRecordDetailPO;
|
|
import com.engine.salary.entity.push.po.PushRecordPO;
|
|
import com.engine.salary.entity.push.po.PushSettingItemPO;
|
|
import com.engine.salary.entity.push.po.PushSettingPO;
|
|
import com.engine.salary.entity.salaryacct.bo.CalculateFormulaVarBO;
|
|
import com.engine.salary.entity.salaryacct.bo.SalaryAcctCalculateBO;
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
|
|
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
|
import com.engine.salary.enums.push.PushItemFieldEnum;
|
|
import com.engine.salary.enums.push.PushRecordDetailStatusEnum;
|
|
import com.engine.salary.enums.push.PushRecordStatusEnum;
|
|
import com.engine.salary.enums.salaryformula.SalarySQLReferenceEnum;
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
import com.engine.salary.mapper.push.PushRecordMapper;
|
|
import com.engine.salary.mapper.push.PushSettingItemMapper;
|
|
import com.engine.salary.mapper.push.PushSettingMapper;
|
|
import com.engine.salary.service.*;
|
|
import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum;
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
import com.engine.salary.util.db.IdGenerator;
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
import com.engine.salary.util.page.PageInfo;
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
|
import com.engine.salary.util.valid.ValidUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.formmode.setup.ModeRightInfo;
|
|
import weaver.general.TimeUtil;
|
|
import weaver.hrm.User;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 推送服务
|
|
* <p>Copyright: Copyright (c) 2024</p>
|
|
* <p>Company: 泛微软件</p>
|
|
*
|
|
* @author qiantao
|
|
* @version 1.0
|
|
**/
|
|
public class PushServiceImpl extends Service implements PushService {
|
|
|
|
private PushSettingMapper getPushSettingMapper() {
|
|
return MapperProxyFactory.getProxy(PushSettingMapper.class);
|
|
}
|
|
|
|
private PushSettingItemMapper getPushSettingItemMapper() {
|
|
return MapperProxyFactory.getProxy(PushSettingItemMapper.class);
|
|
}
|
|
|
|
private PushRecordMapper getPushRecordMapper() {
|
|
return MapperProxyFactory.getProxy(PushRecordMapper.class);
|
|
}
|
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
}
|
|
|
|
private SalaryItemService getSalaryItemService(User user) {
|
|
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
|
}
|
|
|
|
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
|
|
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
|
|
}
|
|
|
|
private SalarySobService getSalarySobService(User user) {
|
|
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
|
}
|
|
|
|
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
|
|
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
|
|
}
|
|
|
|
private SalaryAcctResultService getSalaryAcctResultService(User user) {
|
|
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<PushSettingDTO> settingList(PushSettingQueryParam param) {
|
|
List<PushSettingPO> pushSettingPOS = getPushSettingMapper().listAll();
|
|
|
|
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listAll();
|
|
Map<Long, SalarySobPO> sobPOMap = SalaryEntityUtil.convert2Map(salarySobPOS, SalarySobPO::getId);
|
|
|
|
List<PushSettingDTO> list = pushSettingPOS.stream()
|
|
.filter(po -> StrUtil.isBlank(param.getName()) || po.getName().contains(param.getName())).map(
|
|
po -> PushSettingDTO.builder()
|
|
.id(po.getId())
|
|
.name(po.getName())
|
|
.tableName(po.getTableName())
|
|
.modeName(po.getModeName())
|
|
.modeId(po.getModeId())
|
|
.able(po.getAble())
|
|
.salarySobs(po.getSalarySobIds().stream().map(sobPOMap::get).collect(Collectors.toList()))
|
|
.build()).collect(Collectors.toList());
|
|
return SalaryPageUtil.buildPage(param.getCurrent(), param.getPageSize(), list, PushSettingDTO.class);
|
|
}
|
|
|
|
@Override
|
|
public PushSettingPO save(PushSettingSaveParam param) {
|
|
ValidUtil.doValidator(param);
|
|
|
|
Date now = new Date();
|
|
|
|
Long id = param.getId();
|
|
PushSettingPO po;
|
|
if (id == null) {
|
|
po = PushSettingPO.builder()
|
|
.id(IdGenerator.generate())
|
|
.able(param.getAble())
|
|
.name(param.getName())
|
|
.salarySobIds(param.getSalarySobIds())
|
|
.modeId(param.getModeId())
|
|
.modeName(param.getModeName())
|
|
.tableName(param.getTableName())
|
|
.creator((long) user.getUID())
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.deleteType(0)
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
.build();
|
|
|
|
getPushSettingMapper().insertIgnoreNull(po);
|
|
|
|
} else {
|
|
po = getPushSettingMapper().getById(id);
|
|
if (po == null) {
|
|
throw new SalaryRunTimeException("推送配置不存在!");
|
|
}
|
|
po.setAble(param.getAble());
|
|
po.setAble(param.getAble());
|
|
po.setName(param.getName());
|
|
po.setSalarySobIds(param.getSalarySobIds());
|
|
po.setModeId(param.getModeId());
|
|
po.setModeName(param.getModeName());
|
|
po.setTableName(param.getTableName());
|
|
po.setUpdateTime(now);
|
|
|
|
getPushSettingMapper().update(po);
|
|
}
|
|
|
|
return po;
|
|
}
|
|
|
|
@Override
|
|
public void delete(Long id) {
|
|
getPushSettingMapper().delete(PushSettingPO.builder().id(id).build());
|
|
getPushSettingItemMapper().delete(PushSettingItemPO.builder().settingId(id).build());
|
|
}
|
|
|
|
@Override
|
|
public PageInfo<PushSettingItemDTO> itemList(PushSettingItemQueryParam param) {
|
|
List<PushSettingItemPO> pushSettingItemPOS = getPushSettingItemMapper().listSome(PushSettingItemPO.builder().settingId(param.getSettingId()).build());
|
|
|
|
List<PushSettingItemDTO> list = pushSettingItemPOS.stream().map(po -> PushSettingItemDTO.builder()
|
|
.id(po.getId())
|
|
.settingId(po.getSettingId())
|
|
.item(po.getItem())
|
|
.itemName(po.getItemName())
|
|
.source(po.getSource())
|
|
.sourceName(SalarySQLReferenceEnum.parseByValue(po.getSource()).getDefaultLabel())
|
|
.fieldName(po.getFieldName())
|
|
.fieldType(PushItemFieldEnum.parseByValue(po.getFieldType()))
|
|
.fieldTypeName(PushItemFieldEnum.parseByValue(po.getFieldType()).getDefaultLabel())
|
|
.build()
|
|
).collect(Collectors.toList());
|
|
|
|
return new PageInfo<>(list, PushSettingItemDTO.class);
|
|
}
|
|
|
|
@Override
|
|
public PushSettingItemPO saveItem(PushSettingItemSaveParam param) {
|
|
ValidUtil.doValidator(param);
|
|
Date now = new Date();
|
|
Long id = param.getId();
|
|
PushSettingItemPO po;
|
|
if (id == null) {
|
|
po = PushSettingItemPO.builder()
|
|
.id(IdGenerator.generate())
|
|
.settingId(param.getSettingId())
|
|
.item(param.getItem())
|
|
.itemName(param.getItemName())
|
|
.source(param.getSource())
|
|
.fieldName(param.getFieldName())
|
|
.fieldType(param.getFieldType().getValue())
|
|
.creator((long) user.getUID())
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.deleteType(0)
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
.build();
|
|
|
|
getPushSettingItemMapper().insertIgnoreNull(po);
|
|
|
|
} else {
|
|
po = getPushSettingItemMapper().getById(id);
|
|
if (po == null) {
|
|
throw new SalaryRunTimeException("推送配置明细不存在!");
|
|
}
|
|
po.setSettingId(param.getSettingId());
|
|
po.setItem(param.getItem());
|
|
po.setItemName(param.getItemName());
|
|
po.setSource(param.getSource());
|
|
po.setFieldName(param.getFieldName());
|
|
po.setFieldType(param.getFieldType().getValue());
|
|
po.setUpdateTime(now);
|
|
|
|
getPushSettingItemMapper().update(po);
|
|
|
|
}
|
|
|
|
return po;
|
|
}
|
|
|
|
@Override
|
|
public void deleteItem(Long id) {
|
|
getPushSettingItemMapper().delete(PushSettingItemPO.builder().id(id).build());
|
|
}
|
|
|
|
@Override
|
|
public void pushOneRecord(Long salaryAcctRecordId) {
|
|
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
|
|
|
|
if (salaryAcctRecordPO == null) {
|
|
throw new SalaryRunTimeException("核算记录不存在!");
|
|
}
|
|
|
|
//查询核算人员
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordId(salaryAcctRecordPO.getId());
|
|
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listAll();
|
|
|
|
//查询薪资核算记录的薪资周期、考勤周期等
|
|
SalarySobCycleDTO salarySobCycleDTO = getSalaryAcctRecordService(user).getSalarySobCycleById(salaryAcctRecordPO.getId());
|
|
|
|
SalaryAcctCalculateBO salaryAcctCalculateBO = new SalaryAcctCalculateBO()
|
|
.setSalaryAcctRecordPO(salaryAcctRecordPO)
|
|
.setSalarySobPO(new SalarySobPO())
|
|
.setSalarySobCycleDTO(salarySobCycleDTO)
|
|
.setOtherSalaryAcctRecordPOS(new ArrayList<>())
|
|
.setSalarySobItemPOS(new ArrayList<>())
|
|
.setSalaryItemIdWithPriorityList(new ArrayList<>())
|
|
.setExpressFormulas(new ArrayList<>())
|
|
.setSalaryItemPOS(salaryItemPOS)
|
|
.setSalarySobAdjustRulePOS(new ArrayList<>())
|
|
.setWelfareColumns(new HashMap<>())
|
|
.setAttendQuoteFieldListDTOS(new ArrayList<>())
|
|
.setSalaryAcctEmployeePOS(salaryAcctEmployeePOS)
|
|
.setIssuedFieldIds(new HashSet<>())
|
|
.setChildMonitor(null)
|
|
.setResults(null)
|
|
.setCalculateKey(null)
|
|
.setVariableItems(new ArrayList<>())
|
|
.setTaxDeclarationFunction(TaxDeclarationFunctionEnum.OPEN);
|
|
|
|
|
|
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
|
|
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIdsAll(employeeIds);
|
|
|
|
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getId, Collectors.toList());
|
|
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
|
|
|
|
CalculateFormulaVarBO calculateFormulaVarBO = new CalculateFormulaVarBO(simpleEmployees, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), salaryAcctResultPOS, new ArrayList<>());
|
|
Map<String, List<CalculateFormulaVarBO.FormulaVarValue>> formulaVarMap = calculateFormulaVarBO.convert2FormulaVar(salaryAcctCalculateBO);
|
|
|
|
|
|
List<PushSettingPO> pushSettingPOS = getPushSettingMapper().listSome(PushSettingPO.builder().able(1).build());
|
|
pushSettingPOS.stream()
|
|
.filter(po -> po.getSalarySobIds().contains(salaryAcctRecordPO.getSalarySobId()))
|
|
.forEach(setting -> {
|
|
|
|
Long id = setting.getId();
|
|
List<PushSettingItemPO> pushSettingItemPOS = getPushSettingItemMapper().listSome(PushSettingItemPO.builder().settingId(id).build());
|
|
|
|
|
|
//每个人插入一条
|
|
for (SalaryAcctEmployeePO emp : salaryAcctEmployeePOS) {
|
|
//1 获取当前薪资核算人员的公式中的变量的值
|
|
List<CalculateFormulaVarBO.FormulaVarValue> formulaVarValues = formulaVarMap.get(emp.getEmployeeId() + "_" + emp.getTaxAgentId());
|
|
//2 人员信息
|
|
List<CalculateFormulaVarBO.FormulaVarValue> empInfo = formulaVarMap.get(emp.getEmployeeId() + "");
|
|
formulaVarValues.addAll(empInfo);
|
|
Map<String, String> formulaVarValueMap = SalaryEntityUtil.convert2Map(formulaVarValues, CalculateFormulaVarBO.FormulaVarValue::getFieldId, CalculateFormulaVarBO.FormulaVarValue::getFieldValue);
|
|
|
|
Integer modeId = setting.getModeId();
|
|
|
|
List<String> fields = new ArrayList<String>() {{
|
|
add("formmodeid");
|
|
add("modedatacreater");
|
|
add("modedatacreatertype");
|
|
add("modedatacreatedate");
|
|
add("modedatacreatetime");
|
|
}};
|
|
String currDate = TimeUtil.getCurrentDateString();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
String currTime = sdf.format(new Date());
|
|
List<Object> values = new ArrayList<Object>() {{
|
|
add(modeId);
|
|
add(1);
|
|
add(0);
|
|
add(String.format("'%s'", currDate));
|
|
add(String.format("'%s'", currTime));
|
|
}};
|
|
for (PushSettingItemPO item : pushSettingItemPOS) {
|
|
//数据库字段
|
|
String fieldName = item.getFieldName();
|
|
fields.add(fieldName);
|
|
// 公式变量的值
|
|
String field = item.getSource() + "_" + item.getItem();
|
|
String value = formulaVarValueMap.getOrDefault(field, StringUtils.EMPTY);
|
|
PushItemFieldEnum pushItemFieldEnum = PushItemFieldEnum.parseByValue(item.getFieldType());
|
|
values.add(pushItemFieldEnum.convertValue(value));
|
|
}
|
|
String tableName = setting.getTableName();
|
|
String sql = String.format("insert into %s (%s) values (%s)", tableName, String.join(",", fields), values.stream().map(Object::toString).collect(Collectors.joining(",")));
|
|
RecordSet rs = new RecordSet();
|
|
rs.execute(sql);
|
|
|
|
if (modeId != null) {
|
|
rs.executeQuery("select max(id) from " + tableName);
|
|
int mainId = 0;
|
|
if (rs.next()) {
|
|
mainId = rs.getInt(1);
|
|
}
|
|
ModeRightInfo ModeRightInfo = new ModeRightInfo();
|
|
ModeRightInfo.setNewRight(true);
|
|
ModeRightInfo.editModeDataShare(1, modeId, mainId);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void createPushRecord(Long salaryAcctRecordId) {
|
|
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
|
|
|
|
if (salaryAcctRecordPO == null) {
|
|
throw new SalaryRunTimeException("核算记录不存在!");
|
|
}
|
|
List<PushSettingPO> pushSettingPOS = getPushSettingMapper().listSome(PushSettingPO.builder().able(1).build());
|
|
|
|
Date now = new Date();
|
|
List<PushRecordPO> pushRecordPOList = pushSettingPOS.stream()
|
|
.filter(po -> po.getSalarySobIds().contains(salaryAcctRecordPO.getSalarySobId()))
|
|
.map(po -> PushRecordPO.builder()
|
|
.id(IdGenerator.generate())
|
|
.name(po.getName())
|
|
.settingId(po.getId())
|
|
.acctRecordId(salaryAcctRecordId)
|
|
.status(PushRecordStatusEnum.PREPARE.getValue())
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.creator((long) user.getUID())
|
|
.deleteType(NumberUtils.INTEGER_ZERO)
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
.build()
|
|
)
|
|
.collect(Collectors.toList());
|
|
|
|
pushRecordPOList.forEach(record -> {
|
|
getPushRecordMapper().insertIgnoreNull(record);
|
|
|
|
|
|
//查询核算人员
|
|
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordId(salaryAcctRecordPO.getId());
|
|
|
|
salaryAcctEmployeePOS.stream().map(employee -> PushRecordDetailPO.builder()
|
|
.id(IdGenerator.generate())
|
|
.acctEmpId(employee.getId())
|
|
.recordId(record.getId())
|
|
.status(PushRecordDetailStatusEnum.PREPARE.getValue())
|
|
.createTime(now)
|
|
.updateTime(now)
|
|
.creator((long) user.getUID())
|
|
.deleteType(NumberUtils.INTEGER_ZERO)
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
.build())
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
//创建推送记录
|
|
|
|
//推送记录明细
|
|
|
|
|
|
}
|