|
|
@ -1,11 +1,41 @@
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesTimeEfficientCfg;
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.*;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesAssemblyNosortCfgRepository;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentProdParamCfgRepository;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesTimeEfficientCfgRepository;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
|
|
|
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collector;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 非排序产品加工规则配置
|
|
|
|
* 非排序产品加工规则配置
|
|
|
@ -14,4 +44,93 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesProdRuleNosortCfg")
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesProdRuleNosortCfg")
|
|
|
|
public class MesProdRuleNosortCfgController extends BaseMesController<MesProdRuleNosortCfg>{
|
|
|
|
public class MesProdRuleNosortCfgController extends BaseMesController<MesProdRuleNosortCfg>{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(MesProdRuleNosortCfgController.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MesAssemblyNosortCfgRepository assemblyNosortCfgRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MesEquipmentProdParamCfgRepository equipmentProdParamCfgRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MesTimeEfficientCfgRepository timeEfficientCfgRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/all/import")
|
|
|
|
|
|
|
|
@ApiOperation(value = "流程导入")
|
|
|
|
|
|
|
|
public ResultBean allImport(@RequestParam("file") MultipartFile file) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
String organizeCode = AuthUtil.getOrganizeCode();
|
|
|
|
|
|
|
|
//String organizeCode = "CK01";
|
|
|
|
|
|
|
|
//数据空校验以及转换
|
|
|
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
|
|
|
|
|
|
|
List<MesProdRuleNosortCfg> ruleNosortCfgList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
|
|
|
MesProdRuleNosortCfg.class, "MesProdRuleNosortCfg", true);
|
|
|
|
|
|
|
|
List<MesAssemblyNosortCfg> assemblyNosortCfgList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
|
|
|
MesAssemblyNosortCfg.class, "MesAssemblyNosortCfg", true);
|
|
|
|
|
|
|
|
List<MesEquipmentProdParamCfg> equipmentProdParamCfgList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
|
|
|
MesEquipmentProdParamCfg.class, "MesEquipmentProdParamCfg", true);
|
|
|
|
|
|
|
|
List<MesTimeEfficientCfg> timeEfficientCfgList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
|
|
|
MesTimeEfficientCfg.class, "MesTimeEfficientCfg", true);
|
|
|
|
|
|
|
|
String userName = AuthUtil.getSessionUser().getUserName();
|
|
|
|
|
|
|
|
//String userName ="zxw";
|
|
|
|
|
|
|
|
ruleNosortCfgList.forEach(ruleNosortCfg -> {
|
|
|
|
|
|
|
|
ruleNosortCfg.setOrganizeCode(organizeCode);
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(ruleNosortCfg,userName);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
List<MesProdRuleNosortCfg> ruleNosortCfgs = baseService.insertBatch(ruleNosortCfgList);
|
|
|
|
|
|
|
|
Map<String, List<MesProdRuleNosortCfg>> ruleNosortCfgMap = ruleNosortCfgs.stream().collect(Collectors.groupingBy(MesProdRuleNosortCfg::getNo));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assemblyNosortCfgList.forEach(assemblyNosortCfg -> {
|
|
|
|
|
|
|
|
List<MesProdRuleNosortCfg> mesProdRuleNosortCfgs = ruleNosortCfgMap.get(assemblyNosortCfg.getNo());
|
|
|
|
|
|
|
|
assemblyNosortCfg.setPid(mesProdRuleNosortCfgs.get(0).getId());
|
|
|
|
|
|
|
|
assemblyNosortCfg.setOrganizeCode(organizeCode);
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(assemblyNosortCfg,userName);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
assemblyNosortCfgRepository.saveAll(assemblyNosortCfgList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
equipmentProdParamCfgList.forEach(equipmentProdParamCfg -> {
|
|
|
|
|
|
|
|
List<MesProdRuleNosortCfg> mesProdRuleNosortCfgs = ruleNosortCfgMap.get(equipmentProdParamCfg.getNo());
|
|
|
|
|
|
|
|
equipmentProdParamCfg.setSourceId(mesProdRuleNosortCfgs.get(0).getId());
|
|
|
|
|
|
|
|
equipmentProdParamCfg.setOrganizeCode(organizeCode);
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(equipmentProdParamCfg,userName);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
equipmentProdParamCfgRepository.saveAll(equipmentProdParamCfgList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
timeEfficientCfgList.forEach(timeEfficientCfg -> {
|
|
|
|
|
|
|
|
List<MesProdRuleNosortCfg> mesProdRuleNosortCfgs = ruleNosortCfgMap.get(timeEfficientCfg.getNo());
|
|
|
|
|
|
|
|
timeEfficientCfg.setSourceId(mesProdRuleNosortCfgs.get(0).getId());
|
|
|
|
|
|
|
|
timeEfficientCfg.setOrganizeCode(organizeCode);
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(timeEfficientCfg,userName);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
timeEfficientCfgRepository.saveAll(timeEfficientCfgList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("导入成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* SHEET初始校验
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param excelTool
|
|
|
|
|
|
|
|
* @param fileName
|
|
|
|
|
|
|
|
* @param inputStream
|
|
|
|
|
|
|
|
* @param dataBean
|
|
|
|
|
|
|
|
* @param sheetName
|
|
|
|
|
|
|
|
* @param <T>
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private <T> List<T> getDataAndInitValid(ExcelTool excelTool, String fileName, InputStream inputStream,
|
|
|
|
|
|
|
|
Class<T> dataBean, String sheetName, boolean isCheckDataEmpty) throws Exception {
|
|
|
|
|
|
|
|
List<T> beanList = excelTool.importData(fileName, inputStream, dataBean, sheetName);
|
|
|
|
|
|
|
|
LOGGER.info("导入的【" + sheetName + "】数据" + JsonUtilTool.getJSONArrayByList(beanList));
|
|
|
|
|
|
|
|
if (isCheckDataEmpty && CollectionUtils.isEmpty(beanList)) {
|
|
|
|
|
|
|
|
MesException.throwBusiException(String.format("导入的【%s】数据为空", sheetName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return beanList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|