376 lines
18 KiB
Java
376 lines
18 KiB
Java
package com.engine.salary.wrapper;
|
||
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.core.impl.Service;
|
||
import com.engine.salary.entity.config.SalaryConfig;
|
||
import com.engine.salary.entity.salaryarchive.config.ArchiveFieldConfig;
|
||
import com.engine.salary.entity.salaryformula.config.FormluaConfig;
|
||
import com.engine.salary.entity.salaryitem.config.SalaryItemAllConfig;
|
||
import com.engine.salary.entity.taxagent.config.TaxAgentConfig;
|
||
import com.engine.salary.service.SalaryArchiveItemService;
|
||
import com.engine.salary.service.SalaryFormulaService;
|
||
import com.engine.salary.service.SalaryItemService;
|
||
import com.engine.salary.service.TaxAgentService;
|
||
import com.engine.salary.service.impl.SalaryArchiveItemServiceImpl;
|
||
import com.engine.salary.service.impl.SalaryFormulaServiceImpl;
|
||
import com.engine.salary.service.impl.SalaryItemServiceImpl;
|
||
import com.engine.salary.service.impl.TaxAgentServiceImpl;
|
||
import com.engine.salary.sys.entity.param.*;
|
||
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
||
import com.engine.salary.sys.entity.vo.AppSettingVO;
|
||
import com.engine.salary.sys.entity.vo.OrderRuleVO;
|
||
import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum;
|
||
import com.engine.salary.sys.service.SalarySysConfService;
|
||
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
||
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;
|
||
import com.engine.salary.util.xml.XStreamUtil;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.apache.poi.util.IOUtils;
|
||
import weaver.file.ImageFileManager;
|
||
import weaver.general.BaseBean;
|
||
import weaver.hrm.User;
|
||
|
||
import java.io.*;
|
||
import java.nio.charset.StandardCharsets;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 累计专项附加扣除
|
||
* <p>Copyright: Copyright (c) 2022</p>
|
||
* <p>Company: 泛微软件</p>
|
||
*
|
||
* @author qiantao
|
||
* @version 1.0
|
||
**/
|
||
public class SalarySystemConfigWrapper extends Service {
|
||
|
||
private SalarySysConfService getSalarySysConfService(User user) {
|
||
return ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
private SalaryFormulaService getSalaryFormulaService(User user) {
|
||
return ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
|
||
}
|
||
|
||
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");
|
||
String showEncryptOperationButton = baseBean.getPropValue("hrmSalary", "showEncryptOperationButton");
|
||
|
||
Map<String, Object> o = new HashMap<>();
|
||
o.put("log", log);
|
||
o.put("version", version);
|
||
o.put("openFormulaForcedEditing", openFormulaForcedEditing);
|
||
o.put("showEncryptOperationButton", showEncryptOperationButton);
|
||
|
||
|
||
List<SalarySysConfPO> confPOS = getSalarySysConfService(user).listSome(SalarySysConfPO.builder().build());
|
||
Map<String, String> map = SalaryEntityUtil.convert2Map(confPOS, SalarySysConfPO::getConfKey, SalarySysConfPO::getConfValue);
|
||
o.putAll(map);
|
||
return o;
|
||
}
|
||
|
||
/**
|
||
* 操作是否需要申报功能
|
||
*
|
||
* @param flag 开启 0/关闭 1/重新开启 2
|
||
* @return 执行结果
|
||
*/
|
||
public boolean operateTaxDeclarationFunction(TaxDeclarationFunctionEnum flag) {
|
||
return getSalarySysConfService(user).operateTaxDeclarationFunction(flag);
|
||
}
|
||
|
||
/**
|
||
* 获取单一配置
|
||
*
|
||
* @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);
|
||
}
|
||
|
||
public SalarySysConfPO detail(Long id) {
|
||
return getSalarySysConfService(user).getById(id);
|
||
}
|
||
|
||
public void updateByCode(SalarySysConfPO salarySysConfPO) {
|
||
getSalarySysConfService(user).updateByCode(salarySysConfPO);
|
||
}
|
||
|
||
public void updateOrderRule(OrderRuleParam param) {
|
||
getSalarySysConfService(user).updateOrderRule(param);
|
||
}
|
||
|
||
public OrderRuleVO orderRule() {
|
||
return getSalarySysConfService(user).orderRule();
|
||
}
|
||
|
||
public void saveMatchEmployeeModeRule(MatchEmployeeModeSaveParam param) {
|
||
ValidUtil.doValidator(param);
|
||
getSalarySysConfService(user).saveMatchEmployeeModeRule(param.getRule());
|
||
}
|
||
|
||
public void saveAppSetting(AppSettingSaveParam param) {
|
||
ValidUtil.doValidator(param);
|
||
getSalarySysConfService(user).saveAppSetting(param);
|
||
}
|
||
|
||
public AppSettingVO appSetting() {
|
||
|
||
return getSalarySysConfService(user).appSetting();
|
||
|
||
}
|
||
|
||
public Map<String, Object> saveEncryptSetting(AppSettingSaveParam param) {
|
||
return getSalarySysConfService(user).saveEncryptSetting(param);
|
||
}
|
||
|
||
public Map<String, Object> getEncryptProgress(String progressId) {
|
||
return getSalarySysConfService(user).getEncryptProgress(progressId);
|
||
}
|
||
|
||
public void saveSalaryAcctEmployeeRule(String rule) {
|
||
getSalarySysConfService(user).saveSalaryAcctEmployeeRule(rule);
|
||
}
|
||
|
||
public void saveWithDrawTaxDeclaration(SalarySysConfPO param) {
|
||
getSalarySysConfService(user).saveWithDrawTaxDeclaration(param);
|
||
}
|
||
|
||
public void saveArchiveDelete(String setting) {
|
||
getSalarySysConfService(user).saveArchiveDelete(setting);
|
||
}
|
||
|
||
public void operate(SalarySysConfPO salarySysConfPO) {
|
||
getSalarySysConfService(user).operate(salarySysConfPO);
|
||
}
|
||
|
||
public void saveSalarySendFeedback(SalarySysConfPO param) {
|
||
getSalarySysConfService(user).saveSalarySendFeedback(param);
|
||
}
|
||
|
||
public SalaryConfig downloadConfig() {
|
||
|
||
SalaryConfig salaryConfig = new SalaryConfig();
|
||
|
||
|
||
FormluaConfig formluaConfig = getSalaryFormulaService(user).getFormluaConfig();
|
||
salaryConfig.setFormluaConfig(formluaConfig);
|
||
|
||
SalaryItemAllConfig salaryItemConfig = getSalaryItemService(user).getConfig();
|
||
salaryConfig.setSalaryItemConfig(salaryItemConfig);
|
||
|
||
ArchiveFieldConfig archiveFieldConfig = getSalaryArchiveItemService(user).getConfig();
|
||
salaryConfig.setArchiveFieldConfigs(archiveFieldConfig);
|
||
|
||
List<TaxAgentConfig> taxAgentConfigs = getTaxAgentService(user).getAllConfig();
|
||
salaryConfig.setTaxAgentConfigs(taxAgentConfigs);
|
||
|
||
return salaryConfig;
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|