excel导入工具

This commit is contained in:
钱涛 2024-08-12 17:17:52 +08:00
parent ecb0f6f7bc
commit 845f117d9c
8 changed files with 80 additions and 32 deletions

View File

@ -59,5 +59,6 @@ public interface SalaryFormulaService {
void update(FormulaPO formulaPO);
FormluaConfig getConfig();
void parseConfig(FormluaConfig config);
}

View File

@ -153,6 +153,7 @@ public interface SalaryItemService {
void syncSalaryItemToSalarySobItem(SyncSalaryItemParam syncSalaryItemParam);
SalaryItemAllConfig getConfig();
void parseConfig(SalaryItemAllConfig salaryItemConfig);
List<SalaryItemExcelConfig> getConfig(SalaryItemExportParam param);

View File

@ -752,22 +752,29 @@ public class SalaryArchiveItemServiceImpl extends Service implements SalaryArchi
@Override
public void parseConfig(ArchiveFieldConfig config) {
long uid = user.getUID();
List<SalaryItemPO> salaryItemPOList = getSalaryItemService(user).listAll();
Set<Long> ids = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getId);
Set<String> names = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getName);
Set<String> codes = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getCode);
Map<Long, SalaryItemPO> idMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getId);
Map<String, SalaryItemPO> nameMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getName);
Map<String, SalaryItemPO> codeMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getCode);
Optional.ofNullable(config.getSalaryItems())
Optional.ofNullable(config .getSalaryItems())
.orElse(new ArrayList<>())
.forEach(itemPO -> {
//todo 异常提示
if (ids.contains(itemPO.getId())) {
if (idMap.containsKey(itemPO.getId())) {
getSalaryItemMapper().updateIgnoreNull(itemPO);
} else if (nameMap.containsKey(itemPO.getName())) {
SalaryItemPO salaryItemPO = nameMap.get(itemPO.getName());
itemPO.setId(salaryItemPO.getId());
itemPO.setCreator(uid);
getSalaryItemMapper().updateIgnoreNull(itemPO);
}else if(names.contains(itemPO.getName())){
}else if(codes.contains(itemPO.getCode())){
}else {
} else if (codeMap.containsKey(itemPO.getCode())) {
SalaryItemPO salaryItemPO = codeMap.get(itemPO.getCode());
itemPO.setId(salaryItemPO.getId());
itemPO.setCreator(uid);
getSalaryItemMapper().updateIgnoreNull(itemPO);
} else {
getSalaryItemMapper().insertIgnoreNull(itemPO);
}
});

View File

@ -785,21 +785,27 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
@Override
public void parseConfig(SalaryItemAllConfig salaryItemConfig) {
long uid = user.getUID();
List<SalaryItemPO> salaryItemPOList = listAll();
Set<Long> ids = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getId);
Set<String> names = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getName);
Set<String> codes = SalaryEntityUtil.properties(salaryItemPOList, SalaryItemPO::getCode);
Map<Long, SalaryItemPO> idMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getId);
Map<String, SalaryItemPO> nameMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getName);
Map<String, SalaryItemPO> codeMap = SalaryEntityUtil.convert2Map(salaryItemPOList, SalaryItemPO::getCode);
Optional.ofNullable(salaryItemConfig.getSalaryItems())
.orElse(new ArrayList<>())
.forEach(itemPO -> {
//todo 异常提示
if (ids.contains(itemPO.getId())) {
} else if (names.contains(itemPO.getName())) {
} else if (codes.contains(itemPO.getCode())) {
if (idMap.containsKey(itemPO.getId())) {
getSalaryItemMapper().updateIgnoreNull(itemPO);
} else if (nameMap.containsKey(itemPO.getName())) {
SalaryItemPO salaryItemPO = nameMap.get(itemPO.getName());
itemPO.setId(salaryItemPO.getId());
itemPO.setCreator(uid);
getSalaryItemMapper().updateIgnoreNull(itemPO);
} else if (codeMap.containsKey(itemPO.getCode())) {
SalaryItemPO salaryItemPO = codeMap.get(itemPO.getCode());
itemPO.setId(salaryItemPO.getId());
itemPO.setCreator(uid);
getSalaryItemMapper().updateIgnoreNull(itemPO);
} else {
getSalaryItemMapper().insertIgnoreNull(itemPO);
}

View File

@ -140,5 +140,6 @@ public interface SalarySysConfService {
void saveSettingByType(String confValue, String confKey, String title, String app);
SysConfig getConfig();
void parseConfig(SysConfig config);
}

View File

@ -65,6 +65,7 @@ import weaver.hrm.User;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static com.engine.salary.sys.constant.SalarySysConstant.*;
import static java.util.concurrent.Executors.newFixedThreadPool;
@ -514,17 +515,36 @@ public class SalarySysConfServiceImpl extends Service implements SalarySysConfSe
public SysConfig getConfig() {
SysConfig sysConfig = new SysConfig();
List<SalarySysConfPO> salarySysConfPOS = getSalarySysConfMapper().listAll();
//去除加密配置
salarySysConfPOS = salarySysConfPOS.stream().filter(po -> !po.getConfKey().equals(OPEN_APPLICATION_ENCRYPT)).collect(Collectors.toList());
sysConfig.setSalarySysConfs(salarySysConfPOS);
return sysConfig;
}
@Override
public void parseConfig(SysConfig config) {
List<SalarySysConfPO> salarySysConfs = config.getSalarySysConfs();
if (CollectionUtils.isEmpty(salarySysConfs)) {
return;
}
salarySysConfs.forEach(po -> {
SalarySysConfPO sysConfPO = getSalarySysConfMapper().getOneByCode(po.getConfKey());
if (sysConfPO == null) {
getSalarySysConfMapper().insertIgnoreNull(po);
} else {
sysConfPO.setConfValue(po.getConfValue());
getSalarySysConfMapper().updateIgnoreNull(sysConfPO);
}
});
}
/**
* 开启/关闭加解密
*
* @param confValue
*/
public void updateEncrypt(String confValue) {

View File

@ -8,6 +8,7 @@ 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.util.ResponseResult;
import com.engine.salary.util.excel.ImportExcelResponse;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.xml.XStreamUtil;
import com.engine.salary.wrapper.SalarySystemConfigWrapper;
@ -339,10 +340,6 @@ public class SalarySystemConfigController {
User user = HrmUserVarify.getUser(request, response);
SalaryConfig salaryConfig = getSalarySystemConfigWrapper(user).downloadConfig();
// XStream xStream = new XStream();
// //由于使用的注解将自动检测注解开启
// xStream.autodetectAnnotations(true);
// String xml = xStream.toXML(salaryConfig);
String xml = XStreamUtil.marshal(salaryConfig);
String fileName = "薪酬配置" + LocalDate.now();
@ -372,7 +369,7 @@ public class SalarySystemConfigController {
@Produces(MediaType.APPLICATION_JSON)
public String initConfig(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody uploadConfigParam param) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<uploadConfigParam, Object>(user).run(getSalarySystemConfigWrapper(user)::uploadConfig, param);
return new ResponseResult<uploadConfigParam, ImportExcelResponse>(user).run(getSalarySystemConfigWrapper(user)::uploadConfig, param);
}

View File

@ -8,6 +8,7 @@ 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.entity.taxagent.po.TaxAgentBasePO;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.*;
import com.engine.salary.service.impl.*;
import com.engine.salary.sys.config.SysConfig;
@ -19,6 +20,7 @@ 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.excel.ImportExcelResponse;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.engine.salary.util.valid.RuntimeTypeEnum;
@ -32,9 +34,7 @@ import weaver.hrm.User;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 累计专项附加扣除
@ -200,8 +200,12 @@ public class SalarySystemConfigWrapper extends Service {
}
public SalaryConfig downloadConfig() {
Boolean chief = getTaxAgentService(user).isChief((long) user.getUID());
if (!chief) {
throw new SalaryRunTimeException("您不是薪酬总管理员,无法迁入出配置!");
}
SalaryConfig salaryConfig = new SalaryConfig();
SysConfig sysConfig = getSalarySysConfService(user).getConfig();
@ -225,7 +229,14 @@ public class SalarySystemConfigWrapper extends Service {
return salaryConfig;
}
public void uploadConfig(uploadConfigParam param) {
public ImportExcelResponse uploadConfig(uploadConfigParam param) {
Boolean chief = getTaxAgentService(user).isChief((long) user.getUID());
if (!chief) {
throw new SalaryRunTimeException("您不是薪酬总管理员,无法迁入配置!");
}
ImportExcelResponse response = ImportExcelResponse.builder().build();
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(param.getImageId()));
@ -239,6 +250,8 @@ public class SalarySystemConfigWrapper extends Service {
SalaryConfig config = XStreamUtil.unmarshal(SalaryConfig.class, xml.toString());
getSalarySysConfService(user).parseConfig(config.getSysConfig());
getSalaryFormulaService(user).parseConfig(config.getFormluaConfig());
getSalaryItemService(user).parseConfig(config.getSalaryItemConfig());
@ -249,8 +262,10 @@ public class SalarySystemConfigWrapper extends Service {
getTaxAgentService(user).parseConfig(config.getTaxAgentConfigs());
return response;
} catch (IOException e) {
e.printStackTrace();
response.setErrorData(Collections.singletonList(ImportExcelResponse.Error.builder().message("文件读取失败!").build()));
return response;
} finally {
IOUtils.closeQuietly(fileInputStream);
}