weaver-hrm-salary/src/com/engine/salary/wrapper/SalarySystemConfigWrapper.java

376 lines
18 KiB
Java
Raw Normal View History

2022-07-05 16:56:09 +08:00
package com.engine.salary.wrapper;
2022-08-11 10:27:15 +08:00
import com.engine.common.util.ServiceUtil;
2022-07-05 16:56:09 +08:00
import com.engine.core.impl.Service;
2024-08-08 09:50:04 +08:00
import com.engine.salary.entity.config.SalaryConfig;
import com.engine.salary.entity.salaryarchive.config.ArchiveFieldConfig;
2024-08-08 16:53:31 +08:00
import com.engine.salary.entity.salaryformula.config.FormluaConfig;
import com.engine.salary.entity.salaryitem.config.SalaryItemAllConfig;
2024-08-08 09:50:04 +08:00
import com.engine.salary.entity.taxagent.config.TaxAgentConfig;
import com.engine.salary.service.SalaryArchiveItemService;
2024-08-08 16:53:31 +08:00
import com.engine.salary.service.SalaryFormulaService;
2024-08-08 09:50:04 +08:00
import com.engine.salary.service.SalaryItemService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.service.impl.SalaryArchiveItemServiceImpl;
2024-08-08 16:53:31 +08:00
import com.engine.salary.service.impl.SalaryFormulaServiceImpl;
2024-08-08 09:50:04 +08:00
import com.engine.salary.service.impl.SalaryItemServiceImpl;
import com.engine.salary.service.impl.TaxAgentServiceImpl;
2024-08-08 16:53:31 +08:00
import com.engine.salary.sys.entity.param.*;
2022-09-05 17:20:57 +08:00
import com.engine.salary.sys.entity.po.SalarySysConfPO;
2022-09-28 10:08:51 +08:00
import com.engine.salary.sys.entity.vo.AppSettingVO;
2022-09-19 16:44:32 +08:00
import com.engine.salary.sys.entity.vo.OrderRuleVO;
2022-08-11 10:27:15 +08:00
import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum;
import com.engine.salary.sys.service.SalarySysConfService;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
2023-07-13 16:51:01 +08:00
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.engine.salary.util.valid.RuntimeTypeEnum;
import com.engine.salary.util.valid.ValidUtil;
2024-08-08 16:53:31 +08:00
import com.engine.salary.util.xml.XStreamUtil;
2022-09-05 17:20:57 +08:00
import org.apache.commons.lang3.StringUtils;
2024-08-08 16:53:31 +08:00
import org.apache.poi.util.IOUtils;
import weaver.file.ImageFileManager;
2022-07-05 16:56:09 +08:00
import weaver.general.BaseBean;
2022-08-11 10:27:15 +08:00
import weaver.hrm.User;
2022-07-05 16:56:09 +08:00
2024-08-08 11:03:55 +08:00
import java.io.*;
2024-08-08 16:53:31 +08:00
import java.nio.charset.StandardCharsets;
import java.util.Date;
2022-07-05 16:56:09 +08:00
import java.util.HashMap;
import java.util.List;
2022-07-05 16:56:09 +08:00
import java.util.Map;
/**
* 累计专项附加扣除
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class SalarySystemConfigWrapper extends Service {
2022-08-11 10:27:15 +08:00
private SalarySysConfService getSalarySysConfService(User user) {
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
}
2024-08-08 09:50:04 +08:00
private SalaryItemService getSalaryItemService(User user) {
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
private SalaryArchiveItemService getSalaryArchiveItemService(User user) {
return ServiceUtil.getService(SalaryArchiveItemServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
2024-08-08 16:53:31 +08:00
private SalaryFormulaService getSalaryFormulaService(User user) {
return ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
}
2022-07-05 16:56:09 +08:00
public Map<String, Object> info() {
BaseBean baseBean = new BaseBean();
String log = baseBean.getPropValue("hrmSalary", "log");
String version = baseBean.getPropValue("hrmSalary", "version");
String openFormulaForcedEditing = baseBean.getPropValue("hrmSalary", "openFormulaForcedEditing");
2023-07-13 16:55:23 +08:00
String showEncryptOperationButton = baseBean.getPropValue("hrmSalary", "showEncryptOperationButton");
2022-07-05 16:56:09 +08:00
Map<String, Object> o = new HashMap<>();
o.put("log", log);
o.put("version", version);
o.put("openFormulaForcedEditing", openFormulaForcedEditing);
2023-07-13 16:55:23 +08:00
o.put("showEncryptOperationButton", showEncryptOperationButton);
2023-07-13 16:51:01 +08:00
List<SalarySysConfPO> confPOS = getSalarySysConfService(user).listSome(SalarySysConfPO.builder().build());
Map<String, String> map = SalaryEntityUtil.convert2Map(confPOS, SalarySysConfPO::getConfKey, SalarySysConfPO::getConfValue);
o.putAll(map);
2022-07-05 16:56:09 +08:00
return o;
}
2022-08-11 10:27:15 +08:00
/**
* 操作是否需要申报功能
*
* @param flag 开启 0/关闭 1/重新开启 2
* @return 执行结果
*/
public boolean operateTaxDeclarationFunction(TaxDeclarationFunctionEnum flag) {
return getSalarySysConfService(user).operateTaxDeclarationFunction(flag);
}
2022-09-05 17:20:57 +08:00
/**
* 获取单一配置
*
* @param code
* @return
*/
public String getOneByCode(String code) {
SalarySysConfPO one = getSalarySysConfService(user).getOneByCode(code);
if (one != null) {
return one.getConfValue();
} else {
return StringUtils.EMPTY;
}
}
public PageInfo<SalarySysConfPO> list(SalarySysConfQueryParam param) {
List<SalarySysConfPO> salarySysConfPOS = getSalarySysConfService(user).listSome(SalarySysConfPO.builder().build());
List<SalarySysConfPO> list = SalaryPageUtil.subList(param.getCurrent(), param.getPageSize(), salarySysConfPOS);
PageInfo<SalarySysConfPO> page = new PageInfo<>(list, SalarySysConfPO.class);
page.setTotal(salarySysConfPOS.size());
page.setPageNum(param.getCurrent());
page.setPageSize(param.getPageSize());
return page;
}
public void save(SalarySysConfPO salarySysConfPO) {
ValidUtil.doValidator(salarySysConfPO);
getSalarySysConfService(user).save(salarySysConfPO);
}
public void update(SalarySysConfPO salarySysConfPO) {
ValidUtil.doValidator(salarySysConfPO, RuntimeTypeEnum.UPDATE);
getSalarySysConfService(user).update(salarySysConfPO);
}
2022-09-15 15:41:48 +08:00
public SalarySysConfPO detail(Long id) {
2022-09-19 16:44:32 +08:00
return getSalarySysConfService(user).getById(id);
2022-09-15 15:41:48 +08:00
}
2022-09-19 13:41:09 +08:00
public void updateByCode(SalarySysConfPO salarySysConfPO) {
getSalarySysConfService(user).updateByCode(salarySysConfPO);
}
2022-09-19 16:44:32 +08:00
public void updateOrderRule(OrderRuleParam param) {
getSalarySysConfService(user).updateOrderRule(param);
}
public OrderRuleVO orderRule() {
return getSalarySysConfService(user).orderRule();
}
2022-09-22 10:10:18 +08:00
2022-09-22 11:42:02 +08:00
public void saveMatchEmployeeModeRule(MatchEmployeeModeSaveParam param) {
ValidUtil.doValidator(param);
getSalarySysConfService(user).saveMatchEmployeeModeRule(param.getRule());
2022-09-22 10:10:18 +08:00
}
2022-09-27 17:43:43 +08:00
public void saveAppSetting(AppSettingSaveParam param) {
ValidUtil.doValidator(param);
getSalarySysConfService(user).saveAppSetting(param);
}
2022-09-28 10:08:51 +08:00
public AppSettingVO appSetting() {
2024-08-08 09:50:04 +08:00
return getSalarySysConfService(user).appSetting();
2022-09-28 10:08:51 +08:00
}
2022-10-10 09:43:57 +08:00
public Map<String, Object> saveEncryptSetting(AppSettingSaveParam param) {
2024-08-08 09:50:04 +08:00
return getSalarySysConfService(user).saveEncryptSetting(param);
2022-10-10 09:43:57 +08:00
}
2022-10-12 14:24:01 +08:00
public Map<String, Object> getEncryptProgress(String progressId) {
return getSalarySysConfService(user).getEncryptProgress(progressId);
}
public void saveSalaryAcctEmployeeRule(String rule) {
getSalarySysConfService(user).saveSalaryAcctEmployeeRule(rule);
}
2023-06-29 10:35:55 +08:00
2023-06-29 16:38:50 +08:00
public void saveWithDrawTaxDeclaration(SalarySysConfPO param) {
getSalarySysConfService(user).saveWithDrawTaxDeclaration(param);
}
2023-06-29 10:35:55 +08:00
public void saveArchiveDelete(String setting) {
getSalarySysConfService(user).saveArchiveDelete(setting);
}
2023-07-11 15:29:13 +08:00
2023-07-13 11:33:58 +08:00
public void operate(SalarySysConfPO salarySysConfPO) {
getSalarySysConfService(user).operate(salarySysConfPO);
}
2023-07-11 15:29:13 +08:00
public void saveSalarySendFeedback(SalarySysConfPO param) {
getSalarySysConfService(user).saveSalarySendFeedback(param);
}
2024-08-08 09:50:04 +08:00
2024-08-08 16:53:31 +08:00
public SalaryConfig downloadConfig() {
2024-08-08 09:50:04 +08:00
SalaryConfig salaryConfig = new SalaryConfig();
2024-08-08 16:53:31 +08:00
FormluaConfig formluaConfig = getSalaryFormulaService(user).getFormluaConfig();
salaryConfig.setFormluaConfig(formluaConfig);
SalaryItemAllConfig salaryItemConfig = getSalaryItemService(user).getConfig();
salaryConfig.setSalaryItemConfig(salaryItemConfig);
ArchiveFieldConfig archiveFieldConfig = getSalaryArchiveItemService(user).getConfig();
salaryConfig.setArchiveFieldConfigs(archiveFieldConfig);
2024-08-08 09:50:04 +08:00
List<TaxAgentConfig> taxAgentConfigs = getTaxAgentService(user).getAllConfig();
salaryConfig.setTaxAgentConfigs(taxAgentConfigs);
2024-08-08 16:53:31 +08:00
return salaryConfig;
}
2024-08-08 09:50:04 +08:00
2024-08-08 16:53:31 +08:00
public void uploadConfig(uploadConfigParam param) {
Date now = new Date();
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(param.getImageId()));
Reader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
StringBuilder xml = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
xml.append(line);
}
SalaryConfig config = XStreamUtil.unmarshal(SalaryConfig.class, xml.toString());
System.out.println(config);
// List<SalaryItemExcelConfig> configs = ExcelParseHelper.parse2Map(fileInputStream, SalaryItemExcelConfig.class, 0, 1, 13, EXCEL_TYPE_XLSX);
//
// // 错误excel内容
// ImportExcelResponse response = ImportExcelResponse.builder().totalCount(configs.size()).successCount(configs.size()).errorCount(0).errorData(new ArrayList<>()).build();
//
// List<SysSalaryItemPO> sysSalaryItemPOS = sysSalaryItemBiz.listAll();
// Set<String> sysItems = SalaryEntityUtil.properties(sysSalaryItemPOS, SysSalaryItemPO::getName);
//
// List<SalaryItemPO> adds = new ArrayList<>();
// List<SalaryItemPO> updates = new ArrayList<>();
// Map<Long, Map<String, String>> formulaItems = new HashMap<>();
// for (int i = 0; i < configs.size(); i++) {
// String rowIndex = String.format("第%s行", i + 2);
// SalaryItemExcelConfig config = configs.get(i);
// String name = config.getName();
// SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByDefaultLabel(config.getValueType());
// SalaryDataTypeEnum salaryDataTypeEnum = SalaryDataTypeEnum.parseByValue(config.getDataType());
// SalaryItemPO itemPO = getByName(name);
// if (itemPO == null) {
//
// if (sysItems.contains(name)) {
// ImportExcelResponse.Error error = ImportExcelResponse.Error.builder().message(String.format("%s“%s”的名称与系统名称冲突", rowIndex, name)).build();
// response.setSuccessCount(response.getSuccessCount() - 1);
// response.setErrorCount(response.getErrorCount() + 1);
// response.getErrorData().add(error);
// continue;
// }
//
// itemPO = SalaryItemPO.builder()
// .id(IdGenerator.generate())
// .code(IdGenerator.getUUID())
// .name(name)
// .systemType(SalarySystemTypeEnum.CUSTOM.getValue())
// .sysSalaryItemId(org.apache.commons.lang3.math.NumberUtils.LONG_ZERO)
// .useDefault(SalaryOnOffEnum.parseByDefaultLabel(config.getUseDefault()).getValue())
// .useInEmployeeSalary(SalaryOnOffEnum.OFF.getValue())
// .hideDefault(SalaryOnOffEnum.parseByDefaultLabel(config.getHideDefault()).getValue())
// .roundingMode(SalaryRoundingModeEnum.parseByDefaultLabel(config.getRoundingMode()).getValue())
// .pattern(NumberUtil.isNumber(config.getPattern()) ? Integer.parseInt(config.getPattern()) : 2)
// .valueType(salaryValueTypeEnum.getValue())
// .dataType(salaryDataTypeEnum.getValue())
// //后补
// .formulaId(0L)
// .description(config.getDescription())
// .canEdit(org.apache.commons.lang3.math.NumberUtils.INTEGER_ONE)
// .creator((long) user.getUID())
// .deleteType(0)
// .createTime(now)
// .updateTime(now)
// .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
// .sharedType(0)
// .taxAgentIds("")
// .sortedIndex(NumberUtil.isNumber(config.getSortedIndex()) ? Integer.parseInt(config.getSortedIndex()) : null)
// .width(NumberUtil.isNumber(config.getWidth()) ? Integer.parseInt(config.getWidth()) : null)
// .defaultValue(config.getDefaultValue())
// .build();
// adds.add(itemPO);
// } else {
//
// if (SalarySystemTypeEnum.parseByValue(itemPO.getSystemType()) == SalarySystemTypeEnum.SYSTEM) {
// ImportExcelResponse.Error error = ImportExcelResponse.Error.builder().message(String.format("%s“%s”是系统薪资项目不支持修改", rowIndex, name)).build();
// response.setSuccessCount(response.getSuccessCount() - 1);
// response.setErrorCount(response.getErrorCount() + 1);
// response.getErrorData().add(error);
// continue;
// }
//
// itemPO.setUseDefault(SalaryOnOffEnum.parseByDefaultLabel(config.getUseDefault()).getValue());
// itemPO.setHideDefault(SalaryOnOffEnum.parseByDefaultLabel(config.getHideDefault()).getValue());
// itemPO.setRoundingMode(SalaryRoundingModeEnum.parseByDefaultLabel(config.getRoundingMode()).getValue());
// itemPO.setPattern(NumberUtil.isNumber(config.getPattern()) ? Integer.parseInt(config.getPattern()) : 2);
// itemPO.setValueType(salaryValueTypeEnum.getValue());
// itemPO.setDataType(salaryDataTypeEnum.getValue());
// //后补
// itemPO.setFormulaId(0L);
// itemPO.setDescription(config.getDescription());
// itemPO.setUpdateTime(now);
// itemPO.setSortedIndex(NumberUtil.isNumber(config.getSortedIndex()) ? Integer.parseInt(config.getSortedIndex()) : null);
// itemPO.setWidth(NumberUtil.isNumber(config.getWidth()) ? Integer.parseInt(config.getWidth()) : null);
// itemPO.setDefaultValue(config.getDefaultValue());
// updates.add(itemPO);
// }
//
// //解析公式
// if (salaryValueTypeEnum == SalaryValueTypeEnum.FORMULA || salaryValueTypeEnum == SalaryValueTypeEnum.SQL) {
// Long id = itemPO.getId();
// String formula = config.getFormula();
// String sqlReturnKey = config.getSqlReturnKey();
// Map<String, String> map = new HashMap<>();
// map.put("rowIndex", rowIndex);
// map.put("formula", formula);
// map.put("sqlReturnKey", sqlReturnKey);
// formulaItems.put(id, map);
// }
// }
//
// adds.forEach(getSalaryItemMapper()::insertIgnoreNull);
// updates.forEach(getSalaryItemMapper()::updateIgnoreNull);
//
// for (Long id : formulaItems.keySet()) {
// SalaryItemPO itemPO = getById(id);
// Map<String, String> map = formulaItems.get(id);
// String rowIndex = map.get("rowIndex");
// String formula = map.get("formula");
// String sqlReturnKey = map.get("sqlReturnKey");
// SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByValue(itemPO.getValueType());
// SalaryDataTypeEnum salaryDataTypeEnum = SalaryDataTypeEnum.parseByValue(itemPO.getDataType());
// SalaryFormulaSaveParam saveParam = SalaryFormulaSaveParam.builder()
// .name(itemPO.getName())
// .module("salary")
// .useFor("salaryitem")
// .referenceType(salaryValueTypeEnum == SalaryValueTypeEnum.FORMULA ? ReferenceTypeEnum.FORMULA.getValue() : ReferenceTypeEnum.SQL.getValue())
// .returnType(salaryDataTypeEnum == SalaryDataTypeEnum.STRING ? ReturnTypeEnum.STRING.getValue() : ReturnTypeEnum.NUMBER.getValue())
// .validateType(salaryDataTypeEnum == SalaryDataTypeEnum.STRING ? ReturnTypeEnum.STRING.getValue() : ReturnTypeEnum.NUMBER.getValue())
// .extendParam("{\"isCustomFunction\":\"0\",\"sqlReturnKey\":\"" + sqlReturnKey + "\",\"openDecrypt\":\"0\",\"datasource\":{\"datasourceId\":\"\"}}")
// .formula(formula)
// .build();
//
// try {
// FormulaPO formulaPO = getSalaryFormulaService(user).save(saveParam);
// itemPO.setFormulaId(formulaPO.getId());
// getSalaryItemMapper().updateIgnoreNull(itemPO);
// } catch (Exception e) {
// ImportExcelResponse.Error error = ImportExcelResponse.Error.builder().message(String.format("%s“%s”的公式设置有误%s", rowIndex, itemPO.getName(), e.getMessage())).build();
// response.setSuccessCount(response.getSuccessCount() - 1);
// response.setErrorCount(response.getErrorCount() + 1);
// response.getErrorData().add(error);
// }
// }
// return response;
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(fileInputStream);
}
2024-08-08 09:50:04 +08:00
}
2022-07-05 16:56:09 +08:00
}