|
|
|
@ -1,13 +1,122 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IMesCraftRouteDetailService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IMesCraftRouteService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesCraftDao;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
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.MesCraftRoute;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesCraftRouteDetail;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesCraftRouteRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.wms.WmsAgImportModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.wms.bean.*;
|
|
|
|
|
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 cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
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.RequestParam;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@Api(description = "工艺路线")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesCraftRoute")
|
|
|
|
|
public class MesCraftRouteController extends BaseMesController<MesCraftRoute> {
|
|
|
|
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(MesCraftRouteController.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesCraftRouteDetailService mesCraftRouteDetailService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesCraftRouteRepository mesCraftRouteRepository;
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/all/import")
|
|
|
|
|
@ApiOperation(value = "流程导入")
|
|
|
|
|
public ResultBean allImport(@RequestParam("file") MultipartFile file, String organizeCode) {
|
|
|
|
|
ValidatorBean.checkNotNull(organizeCode, "参数organizeCode(工厂代码)不可为空或长度为0的字符串");
|
|
|
|
|
try {
|
|
|
|
|
//数据空校验以及转换
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, RedisCacheTool.getImppRedis());
|
|
|
|
|
List<MesCraftRoute> routeList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
MesCraftRoute.class, "MesCraftRoute", true);
|
|
|
|
|
List<MesCraftRouteDetail> routeDetailList = getDataAndInitValid(excelTool, file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
MesCraftRouteDetail.class, "MesCraftRouteDetail", true);
|
|
|
|
|
//String userName = AuthUtil.getSessionUser().getUserName();
|
|
|
|
|
String userName ="zxw";
|
|
|
|
|
routeList.forEach(mesCraftRoute -> {
|
|
|
|
|
mesCraftRoute.setOrganizeCode(organizeCode);
|
|
|
|
|
ConvertBean.serviceModelInitialize(mesCraftRoute,userName);
|
|
|
|
|
|
|
|
|
|
DdlPackBean roadPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(mesCraftRoute.getCraftRouteCode(), "craftRouteCode", roadPackBean);
|
|
|
|
|
|
|
|
|
|
boolean flg = mesCraftRouteRepository.isExitByHql(roadPackBean);
|
|
|
|
|
if (flg) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("工艺路线代码【%s】已经存在,请检查数据", mesCraftRoute.getCraftRouteCode())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
routeDetailList.forEach(mesCraftRouteDetail -> {
|
|
|
|
|
mesCraftRouteDetail.setOrganizeCode(organizeCode);
|
|
|
|
|
ConvertBean.serviceModelInitialize(mesCraftRouteDetail,userName);
|
|
|
|
|
});
|
|
|
|
|
baseService.insertBatch(routeList);
|
|
|
|
|
|
|
|
|
|
mesCraftRouteDetailService.insertBatch(routeDetailList);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|