weaver-hrm-salary/src/com/engine/salary/service/impl/PushServiceImpl.java

283 lines
13 KiB
Java
Raw Normal View History

2024-11-15 13:57:35 +08:00
package com.engine.salary.service.impl;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
2024-11-18 16:41:48 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.push.dto.PushSettingDTO;
2024-11-15 13:57:35 +08:00
import com.engine.salary.entity.push.param.PushSettingItemSaveParam;
import com.engine.salary.entity.push.param.PushSettingSaveParam;
import com.engine.salary.entity.push.po.PushSettingItemPO;
import com.engine.salary.entity.push.po.PushSettingPO;
2024-11-18 16:41:48 +08:00
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;
2024-11-15 13:57:35 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.push.PushSettingItemMapper;
import com.engine.salary.mapper.push.PushSettingMapper;
2024-11-18 16:41:48 +08:00
import com.engine.salary.service.*;
import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum;
import com.engine.salary.util.SalaryEntityUtil;
2024-11-15 13:57:35 +08:00
import com.engine.salary.util.db.IdGenerator;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.valid.ValidUtil;
2024-11-18 16:41:48 +08:00
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
2024-11-18 17:52:48 +08:00
import weaver.general.TimeUtil;
2024-11-15 13:57:35 +08:00
import weaver.hrm.User;
2024-11-18 17:52:48 +08:00
import java.text.SimpleDateFormat;
2024-11-18 16:41:48 +08:00
import java.util.*;
import java.util.stream.Collectors;
2024-11-15 13:57:35 +08:00
/**
* 推送服务
* <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);
}
2024-11-18 16:41:48 +08:00
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 SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
}
2024-11-15 13:57:35 +08:00
2024-11-18 16:41:48 +08:00
private SalaryAcctResultService getSalaryAcctResultService(User user) {
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
2024-11-15 13:57:35 +08:00
}
@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 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().getValue())
.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().getValue());
po.setFieldName(param.getFieldName());
po.setFieldType(param.getFieldType().getValue());
po.setUpdateTime(now);
getPushSettingItemMapper().update(po);
}
return po;
}
2024-11-18 16:41:48 +08:00
@Override
public List<PushSettingDTO> pushOneRecord(Long salaryAcctRecordId) {
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
//查询核算人员
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();
2024-11-18 17:52:48 +08:00
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));
}};
2024-11-18 16:41:48 +08:00
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(",")));
System.out.println(sql);
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);
}
}
});
return null;
}
2024-11-15 13:57:35 +08:00
}