关键零部件绑定关系管理完善导入

This commit is contained in:
梁琦涛
2024-09-25 15:55:13 +08:00
parent adf47c2494
commit 91bea54fe9
5 changed files with 37 additions and 29 deletions
@@ -50,7 +50,7 @@ public class ESPlanQueryDTO {
@ApiModelProperty(value = "主起草单位") @ApiModelProperty(value = "主起草单位")
private String mainDraftingUnit; private String mainDraftingUnit;
@ApiModelProperty(value = "主起草单位责任人") @ApiModelProperty(value = "主起草单位业务支持-关键零部件绑定关系管理")
private String mainDraftingUnitResponsiblePerson; private String mainDraftingUnitResponsiblePerson;
@ApiModelProperty(value = "项目状态") @ApiModelProperty(value = "项目状态")
@@ -157,8 +157,7 @@ public class LawsPartRelevanceController {
@PostMapping(value = "/importExcel") @PostMapping(value = "/importExcel")
// @RequiresPermissions("marketStandard:detail:operate") // @RequiresPermissions("marketStandard:detail:operate")
public Result<?> importExcel(@RequestParam("file") @ApiParam("文件") MultipartFile file) { public Result<?> importExcel(@RequestParam("file") @ApiParam("文件") MultipartFile file) {
lawsPartRelevanceService.importExcel(file); return lawsPartRelevanceService.importExcel(file);
return Result.OK(ResultCommon.OK);
} }
/** /**
@@ -60,7 +60,7 @@ public class LawsPartRelevance implements Serializable {
* 关键零部件名称 * 关键零部件名称
*/ */
@ApiModelProperty(value = "关键零部件名称") @ApiModelProperty(value = "关键零部件名称")
@Excel(name = "关键零部件名称", width = 15) @Excel(name = "关键零部件名称", width = 15, dictTable = "laws_part_pmm_partition_info", dicCode = "fnd_gpc", dicText = "reg_part_name_cn")
@TableField(exist = false) @TableField(exist = false)
@Dict(dictTable = "laws_part_pmm_partition_info", dicCode = "fnd_gpc", dicText = "reg_part_name_cn") @Dict(dictTable = "laws_part_pmm_partition_info", dicCode = "fnd_gpc", dicText = "reg_part_name_cn")
private String regPartNameCn; private String regPartNameCn;
@@ -2,6 +2,7 @@ package com.jero.modules.laws.part.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.part.entity.LawsPartRelevance; import com.jero.modules.laws.part.entity.LawsPartRelevance;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@@ -25,7 +26,7 @@ public interface ILawsPartRelevanceService extends IService<LawsPartRelevance> {
void edit(LawsPartRelevance lawsPartRelevance); void edit(LawsPartRelevance lawsPartRelevance);
void importExcel(MultipartFile file); Result<?> importExcel(MultipartFile file);
ModelAndView downloadTemplate(HttpServletResponse response); ModelAndView downloadTemplate(HttpServletResponse response);
} }
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.common.api.vo.ResultCommon; import com.jero.common.api.vo.ResultCommon;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.system.base.controller.JeroController; import com.jero.common.system.base.controller.JeroController;
@@ -165,10 +166,10 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
} }
@Override @Override
public void importExcel(MultipartFile file) { public Result<?> importExcel(MultipartFile file) {
// 校验文件是否为excel // 校验文件是否为excel
if (!ImportExcelUtil.checkExcelFile(file)) { if (!ImportExcelUtil.checkExcelFile(file)) {
throw new JeroBootException(ResultCommon.IMPORT_THE_EXCEL_FILE); return Result.error(ResultCommon.IMPORT_THE_EXCEL_FILE);
} }
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
params.setHeadRows(1); params.setHeadRows(1);
@@ -176,13 +177,13 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
boolean b = ImportExcelUtil. boolean b = ImportExcelUtil.
checkTemplateTitle(file, LawsPartRelevance.class, 0, 0); checkTemplateTitle(file, LawsPartRelevance.class, 0, 0);
if (!b) { if (!b) {
throw new JeroBootException(ResultCommon.IMPORT_TEMPLATE_ERROR); return Result.error(ResultCommon.IMPORT_TEMPLATE_ERROR);
} }
try { try {
List<LawsPartRelevance> listLawsPartRelevance = ExcelImportUtil.importExcel( List<LawsPartRelevance> listLawsPartRelevance = ExcelImportUtil.importExcel(
file.getInputStream(), LawsPartRelevance.class, params); file.getInputStream(), LawsPartRelevance.class, params);
if(CollectionUtils.isEmpty(listLawsPartRelevance)){ if(CollectionUtils.isEmpty(listLawsPartRelevance)){
throw new JeroBootException(ResultCommon.IMPORT_DATA_CANNOT_BE_EMPTY); return Result.error(ResultCommon.IMPORT_DATA_CANNOT_BE_EMPTY);
} }
StringBuilder m = new StringBuilder(); StringBuilder m = new StringBuilder();
for (LawsPartRelevance lawsPartRelevance : listLawsPartRelevance) { for (LawsPartRelevance lawsPartRelevance : listLawsPartRelevance) {
@@ -197,8 +198,18 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
queryLawsPartRelevance.select("CONCAT(fnd_gpc,'_',system_code) as fnd_gpc"); queryLawsPartRelevance.select("CONCAT(fnd_gpc,'_',system_code) as fnd_gpc");
queryLawsPartRelevance.in("CONCAT(fnd_gpc,'_',system_code)",listCode); queryLawsPartRelevance.in("CONCAT(fnd_gpc,'_',system_code)",listCode);
List<LawsPartRelevance> listOld = list(queryLawsPartRelevance); List<LawsPartRelevance> listOld = list(queryLawsPartRelevance);
List<LawsPartRelevance> listNotNull = listLawsPartRelevance.stream().filter(o->!StringUtils.isBlank(o.getFndGpc())).collect(Collectors.toList());
List<LawsPartPmmPartitionInfo> lawsPartPmmPartitionInfoList = new ArrayList<>();
if(!CollectionUtils.isEmpty(listNotNull)){
List<String> listFndGpc = listLawsPartRelevance.stream().map(LawsPartRelevance::getFndGpc).collect(Collectors.toList());
String fndGpc = String.join(",", listFndGpc);
listFndGpc = Arrays.asList(fndGpc.split(","));
LambdaQueryWrapper<LawsPartPmmPartitionInfo> queryLawsPartPmmPartitionInfo = new LambdaQueryWrapper<>();
queryLawsPartPmmPartitionInfo.in(LawsPartPmmPartitionInfo::getFndGpc,listFndGpc);
lawsPartPmmPartitionInfoList = lawsPartPmmPartitionInfoService
.list(queryLawsPartPmmPartitionInfo);
}
List<LawsPartPmmPartitionInfo> lawsPartPmmPartitionInfoList = lawsPartPmmPartitionInfoService.list();
Set<String> setAlready = new HashSet<>(); Set<String> setAlready = new HashSet<>();
// 校验数据 // 校验数据
for (int i = 0; i < listLawsPartRelevance.size(); i++) { for (int i = 0; i < listLawsPartRelevance.size(); i++) {
@@ -213,16 +224,14 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
// 验证关键零部件名称是否正确 // 验证关键零部件名称是否正确
if(CollectionUtils.isEmpty(lawsPartPmmPartitionInfoList)){ if(CollectionUtils.isEmpty(lawsPartPmmPartitionInfoList)){
s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"关键零部件名称 does not exist" : "关键零部件名称不存在"); "关键零部件名称 does not exist," : "关键零部件名称不存在,");
}else{ }else{
List<LawsPartPmmPartitionInfo> lawsPartPmmPartitionInfoListSub = lawsPartPmmPartitionInfoList List<String> listFndGpc = Arrays.asList(lawsPartRelevance.getFndGpc().split(","));
.stream().filter(o->Objects.equals(o.getRegPartNameCn(), long l = lawsPartPmmPartitionInfoList
lawsPartRelevance.getRegPartNameCn())).collect(Collectors.toList()); .stream().filter(o->listFndGpc.contains(o.getFndGpc())).count();
if(!CollectionUtils.isEmpty(lawsPartPmmPartitionInfoListSub)){ if(l != listFndGpc.size()){
lawsPartRelevance.setFndGpc(lawsPartPmmPartitionInfoListSub.get(0).getFndGpc());
}else{
s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"关键零部件名称 does not exist" : "关键零部件名称不存在"); "关键零部件名称 does not exist," : "关键零部件名称不存在,");
} }
} }
} }
@@ -230,29 +239,28 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
if(formType.contains("1")){ if(formType.contains("1")){
if(StringUtils.isBlank(lawsPartRelevance.getSystemCode())){ if(StringUtils.isBlank(lawsPartRelevance.getSystemCode())){
s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"功能系统码 cannot be empty" : "功能系统码不能为空"); "功能系统码 cannot be empty," : "功能系统码不能为空,");
} }
if(StringUtils.isBlank(lawsPartRelevance.getDecisionRequirement())){ if(StringUtils.isBlank(lawsPartRelevance.getDecisionRequirement())){
s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append(Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"技术特性判定要求 cannot be empty" : "技术特性判定要求不能为空"); "技术特性判定要求 cannot be empty," : "技术特性判定要求不能为空,");
} }
} }
// 校验是否存在 // 校验是否存在
String code = lawsPartRelevance.getFndGpc() + "_" + lawsPartRelevance.getSystemCode(); String code = lawsPartRelevance.getFndGpc() + "_" + lawsPartRelevance.getSystemCode();
if(!CollectionUtils.isEmpty(listOld)){ if(!CollectionUtils.isEmpty(listOld)){
long l = listOld.stream().filter(o->Objects.equals(o.getFndGpc() + "_" + o.getSystemCode(), long l = listOld.stream().filter(o->Objects.equals(o.getFndGpc(), code)).count();
code)).count();
if(l > 0){ if(l > 0){
throw new JeroBootException((Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append((Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"名称与功能系统码 already exists" : "名称与功能系统码已存在")); "名称与功能系统码 already exists," : "名称与功能系统码已存在,"));
} }
} }
// 校验重复 // 校验重复
if(!CollectionUtils.isEmpty(setAlready) && !StringUtils.isBlank(code)){ if(!CollectionUtils.isEmpty(setAlready) && !StringUtils.isBlank(code)){
long l = setAlready.stream().filter(o->Objects.equals(o,code)).count(); long l = setAlready.stream().filter(o->Objects.equals(o,code)).count();
if(l > 0){ if(l > 0){
throw new JeroBootException((Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ? s.append((Objects.equals(LocaleContextHolder.getLocale(),Locale.ENGLISH) ?
"名称与功能系统码 duplicate" : "名称与功能系统码重复")); "名称与功能系统码 duplicate," : "名称与功能系统码重复,"));
} }
} }
setAlready.add(code); setAlready.add(code);
@@ -263,13 +271,13 @@ public class LawsPartRelevanceServiceImpl extends ServiceImpl<LawsPartRelevanceM
} }
} }
if(!StringUtils.isBlank(m.toString())){ if(!StringUtils.isBlank(m.toString())){
throw new JeroBootException(m.toString()); return Result.error(m.toString());
} }
saveBatch(listLawsPartRelevance); saveBatch(listLawsPartRelevance);
return Result.OK(ResultCommon.OK);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
throw new JeroBootException(ResultCommon.ERROR); return Result.error(ResultCommon.ERROR);
} finally { } finally {
try { try {
file.getInputStream().close(); file.getInputStream().close();