198 lines
8.3 KiB
Java
198 lines
8.3 KiB
Java
package com.engine.salary.action;
|
||
|
||
import cn.hutool.core.util.StrUtil;
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.salary.entity.siarchives.po.InsuranceArchivesBaseInfoPO;
|
||
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
||
import com.engine.salary.enums.siaccount.EmployeeStatusEnum;
|
||
import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper;
|
||
import com.engine.salary.mapper.taxagent.TaxAgentMapper;
|
||
import com.engine.salary.service.SIArchivesService;
|
||
import com.engine.salary.service.impl.SIArchivesServiceImpl;
|
||
import com.engine.salary.util.SalaryDateUtil;
|
||
import com.engine.salary.util.SalaryEntityUtil;
|
||
import com.engine.salary.util.db.MapperProxyFactory;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import weaver.conn.RecordSet;
|
||
import weaver.general.Util;
|
||
import weaver.hrm.User;
|
||
import weaver.interfaces.workflow.action.Action;
|
||
import weaver.soa.workflow.request.Property;
|
||
import weaver.soa.workflow.request.RequestInfo;
|
||
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* @Author: sy
|
||
* @Description: 福利档案减员action
|
||
* @Date: 2023/8/22
|
||
**/
|
||
@Slf4j
|
||
public class StayDelToStopSIArchiveAction implements Action {
|
||
|
||
private InsuranceBaseInfoMapper getInsuranceBaseInfoMapper() {
|
||
return MapperProxyFactory.getProxy(InsuranceBaseInfoMapper.class);
|
||
}
|
||
|
||
private SIArchivesService getSIArchivesService(User user) {
|
||
return ServiceUtil.getService(SIArchivesServiceImpl.class,user);
|
||
}
|
||
|
||
private TaxAgentMapper getTaxAgentMapper() {
|
||
return MapperProxyFactory.getProxy(TaxAgentMapper.class);
|
||
}
|
||
|
||
private String tableName;
|
||
|
||
|
||
public String getTableName() {
|
||
return tableName;
|
||
}
|
||
|
||
public void setTableName(String tableName) {
|
||
this.tableName = tableName;
|
||
}
|
||
|
||
// 是否执行action的字段, 0代表不执行,其余代表执行
|
||
private String enableField;
|
||
|
||
public String getEnableField() {
|
||
return enableField;
|
||
}
|
||
|
||
public void setEnableField(String enableField) {
|
||
this.enableField = enableField;
|
||
}
|
||
|
||
@Override
|
||
public String execute(RequestInfo requestInfo) {
|
||
try {
|
||
|
||
Property[] properties = requestInfo.getMainTableInfo().getProperty();
|
||
Map<String, String> fieldMap = Arrays.stream(properties).collect(Collectors.toMap(Property::getName,
|
||
property -> Util.null2String(property.getValue())));
|
||
|
||
String enable = fieldMap.get(enableField);
|
||
if (StringUtils.isNotBlank(enable) && enable.equals("0")) {
|
||
// 不执行action
|
||
return SUCCESS;
|
||
}
|
||
RecordSet rs = new RecordSet();
|
||
|
||
String queryImageId = "select salaryname,processfield from " + tableName + " where workflowid = ?";
|
||
rs.executeQuery(queryImageId, requestInfo.getWorkflowid());
|
||
|
||
List<StayDelToStopSIArchiveAction.SalaryField> list = new ArrayList<>();
|
||
while (rs.next()) {
|
||
String processField = rs.getString("processfield");
|
||
String salaryName = rs.getString("salaryname");
|
||
String value = fieldMap.get(processField);
|
||
list.add(new StayDelToStopSIArchiveAction.SalaryField(processField, salaryName, value));
|
||
}
|
||
// 流程数据
|
||
Map<String, Object> importDataMap = SalaryEntityUtil.convert2Map(list, StayDelToStopSIArchiveAction.SalaryField::getSalaryName, StayDelToStopSIArchiveAction.SalaryField::getValue);
|
||
log.info("StayDelToStopSIArchiveAction,tableName :{},workflowid:{},流程参数:{}",tableName, requestInfo.getWorkflowid(), importDataMap);
|
||
String taxAgentName = importDataMap.getOrDefault("个税扣缴义务人", "").toString();
|
||
List<TaxAgentPO> taxAgentPOS = getTaxAgentMapper().listByName(taxAgentName);
|
||
if(CollectionUtils.isEmpty(taxAgentPOS)){
|
||
requestInfo.getRequestManager().setMessage("个税扣缴义务人不存在!");
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
Long taxAgentId = Long.valueOf( taxAgentPOS.get(0).getId() );
|
||
Long employeeId = Long.valueOf(importDataMap.getOrDefault("员工id", "-1").toString());
|
||
|
||
String payEndYearMonth = importDataMap.getOrDefault("最后缴纳月", "").toString();
|
||
// 如果只有一个“最后缴纳月”, 代表社保、公积金、其他均使用同一个最后缴纳月
|
||
String fundEndYearMonth = importDataMap.getOrDefault("公积金最后缴纳月", "").toString();
|
||
String otherEndYearMonth = importDataMap.getOrDefault("其他福利最后缴纳月", "").toString();
|
||
if (StrUtil.isNotBlank(payEndYearMonth) && !SalaryDateUtil.checkYearMonth(payEndYearMonth)) {
|
||
requestInfo.getRequestManager().setMessage("最后缴纳月格式有误,正确格式示例为'2021-01'");
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
|
||
if (StrUtil.isNotBlank(fundEndYearMonth) && !SalaryDateUtil.checkYearMonth(fundEndYearMonth)) {
|
||
requestInfo.getRequestManager().setMessage("公积金最后缴纳月格式有误,正确格式示例为'2021-01'");
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
|
||
if (StrUtil.isNotBlank(otherEndYearMonth) && !SalaryDateUtil.checkYearMonth(otherEndYearMonth)) {
|
||
requestInfo.getRequestManager().setMessage("其他福利最后缴纳月格式有误,正确格式示例为'2021-01'");
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
|
||
//操作人
|
||
String uid = importDataMap.getOrDefault("操作人","1").toString();
|
||
User user = new User(Integer.parseInt(uid));
|
||
// 获取福利档案
|
||
InsuranceArchivesBaseInfoPO insuranceArchivesBaseInfoPO = getInsuranceBaseInfoMapper().getOneByEmployeeIdAndPayOrg(taxAgentId, employeeId);
|
||
if(insuranceArchivesBaseInfoPO == null){
|
||
requestInfo.getRequestManager().setMessage("该个税扣缴义务人下该员工不存在福利档案,请检查后重试!");
|
||
return FAILURE_AND_CONTINUE;
|
||
} else if(StrUtil.isBlank(payEndYearMonth) && !insuranceArchivesBaseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())){
|
||
requestInfo.getRequestManager().setMessage("该个税扣缴义务人下该员工的福利档案状态不是待减员,无法进行减员操作,请检查后重试!");
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
//减员
|
||
Map<String, Object> resultMap = new HashMap<>();
|
||
if (StrUtil.isBlank(payEndYearMonth)) {
|
||
resultMap = getSIArchivesService(user).stayDelToStop(Collections.singletonList(insuranceArchivesBaseInfoPO.getId()));
|
||
} else {
|
||
resultMap = getSIArchivesService(user).stopWithoutLimit(Collections.singletonList(insuranceArchivesBaseInfoPO.getId()), payEndYearMonth, fundEndYearMonth, otherEndYearMonth);
|
||
}
|
||
if (resultMap.get("type").toString().equals("fail")) {
|
||
requestInfo.getRequestManager().setMessage(resultMap.get("msg").toString());
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
log.error("减员异常", e);
|
||
requestInfo.getRequestManager().setMessage(e.getMessage());
|
||
return FAILURE_AND_CONTINUE;
|
||
}
|
||
return SUCCESS;
|
||
}
|
||
|
||
|
||
class SalaryField {
|
||
|
||
private String processField;
|
||
|
||
private String salaryName;
|
||
|
||
private String value;
|
||
|
||
public String getProcessField() {
|
||
return processField;
|
||
}
|
||
|
||
public void setProcessField(String processField) {
|
||
this.processField = processField;
|
||
}
|
||
|
||
public String getSalaryName() {
|
||
return salaryName;
|
||
}
|
||
|
||
public void setSalaryName(String salaryName) {
|
||
this.salaryName = salaryName;
|
||
}
|
||
|
||
public String getValue() {
|
||
return value;
|
||
}
|
||
|
||
public void setValue(String value) {
|
||
this.value = value;
|
||
}
|
||
|
||
public SalaryField(String processField, String salaryName, String value) {
|
||
this.processField = processField;
|
||
this.salaryName = salaryName;
|
||
this.value = value;
|
||
}
|
||
}
|
||
}
|