|
|
|
@ -0,0 +1,366 @@
|
|
|
|
|
//package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel;
|
|
|
|
|
//
|
|
|
|
|
//import cn.estsh.i3plus.ext.mes.apiservice.unit.exception.MesException;
|
|
|
|
|
//import cn.estsh.i3plus.mes.api.iservice.busi.IExcelImportService;
|
|
|
|
|
//import cn.estsh.i3plus.mes.apiservice.serviceimpl.busi.CommonService;
|
|
|
|
|
//import cn.estsh.i3plus.mes.apiservice.util.DateUtil;
|
|
|
|
|
//import cn.estsh.i3plus.mes.apiservice.util.MesCommonUtil;
|
|
|
|
|
//import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
//import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
//import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.bean.*;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.model.ExcelImportErrorModel;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.model.ExcelImportResultModel;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.repository.*;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.unit.DateUtilExt;
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.unit.MesExtEnumUtil;
|
|
|
|
|
//import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
//import cn.hutool.core.io.unit.DataUnit;
|
|
|
|
|
//import io.swagger.annotations.ApiParam;
|
|
|
|
|
//import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
//import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
|
//import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
//import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
//import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
//import org.springframework.stereotype.Service;
|
|
|
|
|
//import org.springframework.util.CollectionUtils;
|
|
|
|
|
//import org.springframework.util.StringUtils;
|
|
|
|
|
//
|
|
|
|
|
//import javax.persistence.Column;
|
|
|
|
|
//import java.util.*;
|
|
|
|
|
//
|
|
|
|
|
//import static cn.estsh.i3plus.platform.plugin.echarts.code.Trigger.item;
|
|
|
|
|
//
|
|
|
|
|
///**
|
|
|
|
|
// * @Description : MES工单导入,排序
|
|
|
|
|
// * @Reference :
|
|
|
|
|
// * @Author : junsheng.li
|
|
|
|
|
// * @CreateDate 2024/5/16 14:14
|
|
|
|
|
// * @Modify:
|
|
|
|
|
// **/
|
|
|
|
|
//@Service
|
|
|
|
|
//@Slf4j
|
|
|
|
|
//public class MesWorkOrderSortExcelServiceImpl implements IExcelImportService {
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private CommonService commonService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesPartRepository partRepository;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesWorkOrderRepository mesWorkOrderRDao;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesWorkCenterRepository mesWorkCenterRDao;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesShiftRepository mesShiftRDao;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private MesProductVersionRepository mesProductVersionRDao;
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public ExcelImportResultModel insertDataByExcel(Workbook workbook, String organizeCode, String userName) {
|
|
|
|
|
//
|
|
|
|
|
// //读取表格
|
|
|
|
|
// ExcelImportResultModel excelImportResultModel = this.sheetExtractMesWorkOrder(workbook.getSheetAt(0), organizeCode, userName);
|
|
|
|
|
// //数据入库
|
|
|
|
|
// this.insertExcelMesWorkOrder(excelImportResultModel);
|
|
|
|
|
// return excelImportResultModel;
|
|
|
|
|
//// return null;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * 工位BOM表导入-读取表格
|
|
|
|
|
// *
|
|
|
|
|
// * @param sheetAt
|
|
|
|
|
// * @param organizeCode
|
|
|
|
|
// * @param userName
|
|
|
|
|
// * @return
|
|
|
|
|
// */
|
|
|
|
|
// private ExcelImportResultModel sheetExtractMesWorkOrder(Sheet sheetAt, String organizeCode, String userName) {
|
|
|
|
|
//
|
|
|
|
|
// //从0行开始读取
|
|
|
|
|
// int totalNumberOfRows = sheetAt.getLastRowNum() + 1;
|
|
|
|
|
//
|
|
|
|
|
// //MesStationBom集合
|
|
|
|
|
// List<MesWorkOrder> mesWorkOrderList = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// //成功数量
|
|
|
|
|
// Integer successRowNum = 0;
|
|
|
|
|
// //失败数量
|
|
|
|
|
// Integer failRowNum = 0;
|
|
|
|
|
// //错误的行号
|
|
|
|
|
// String errorRows = "";
|
|
|
|
|
//
|
|
|
|
|
// //错误行信息集合
|
|
|
|
|
// List<ExcelImportErrorModel> excelImportErrorModels = new ArrayList<>();
|
|
|
|
|
// //vinCode集合
|
|
|
|
|
// List<String> vinCodeList = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// // 查询物料表
|
|
|
|
|
// Map<String, Object> partNoMap;
|
|
|
|
|
// try {
|
|
|
|
|
// partNoMap = MesCommonUtil.getCodeEntityMap(partRepository, "partNo", organizeCode, "物料表");
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// partNoMap = null;
|
|
|
|
|
// }
|
|
|
|
|
// // 查询产线信息
|
|
|
|
|
// Map<String, Object> mesWorkCenterMap;
|
|
|
|
|
// try {
|
|
|
|
|
// mesWorkCenterMap = MesCommonUtil.getCodeEntityMap(mesWorkCenterRDao, "workCenterCode", organizeCode, "工作中心表");
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// mesWorkCenterMap = null;
|
|
|
|
|
// }
|
|
|
|
|
// // 班次信息
|
|
|
|
|
// Map<String, Object> shiftMap;
|
|
|
|
|
// try {
|
|
|
|
|
// shiftMap = MesCommonUtil.getCodeEntityMap(mesShiftRDao, "shiftCode", organizeCode, "班次信息表");
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// shiftMap = null;
|
|
|
|
|
// }
|
|
|
|
|
// // 工单信息
|
|
|
|
|
// Map<String, Object> vinCodeMap;
|
|
|
|
|
// try {
|
|
|
|
|
// vinCodeMap = MesCommonUtil.getCodeEntityMap(mesWorkOrderRDao, "vinCode", organizeCode, "工单信息表");
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// vinCodeMap = null;
|
|
|
|
|
// }
|
|
|
|
|
// //查询生产版本
|
|
|
|
|
// DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
// ddlPackBean.setOrderByStr(" order by createDatetime desc ");
|
|
|
|
|
// List<MesProductVersion> productVersionList = mesProductVersionRDao.findByHqlWhere(ddlPackBean);
|
|
|
|
|
// if(CollectionUtils.isEmpty(productVersionList)){
|
|
|
|
|
// MesException.throwMesBusiException("生产版本信息不存在");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Map<String, String> map = new HashMap<>();
|
|
|
|
|
//
|
|
|
|
|
// for (int i = (sheetAt.getFirstRowNum() + 1); i < totalNumberOfRows; i++) {
|
|
|
|
|
// Row row = sheetAt.getRow(i);
|
|
|
|
|
// //空行跳过
|
|
|
|
|
// if (null == row) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// //获取总列数
|
|
|
|
|
// Short lastCellNum = row.getLastCellNum();
|
|
|
|
|
// if (lastCellNum > 0) {
|
|
|
|
|
//
|
|
|
|
|
// int rowNum = i + 1; //当前行号
|
|
|
|
|
// int errorNum = 0; //错误数量
|
|
|
|
|
// String cellNum = ""; //错误列号
|
|
|
|
|
// String errorInfo = ""; //错误信息
|
|
|
|
|
// String planStartTime = null;
|
|
|
|
|
// String planEndTime = null;
|
|
|
|
|
//
|
|
|
|
|
// //工单标识(S:10/P:20/N:30/E:40)
|
|
|
|
|
// String orderFlag = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(0).setCellType(CellType.STRING);
|
|
|
|
|
// orderFlag = row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //生产线代码
|
|
|
|
|
// String workCenterCode = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(1).setCellType(CellType.STRING);
|
|
|
|
|
// workCenterCode = row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //ERP总成零件号
|
|
|
|
|
// String partNo = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(2).setCellType(CellType.STRING);
|
|
|
|
|
// partNo = row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //计划时间(yyyy-MM-dd)
|
|
|
|
|
// String planDate = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(3).setCellType(CellType.STRING);
|
|
|
|
|
// planDate = row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //班次(1:早班/2:晚班)
|
|
|
|
|
// String shiftCode = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(4).setCellType(CellType.STRING);
|
|
|
|
|
// shiftCode = row.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //客户订单号
|
|
|
|
|
// String custOrder = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(5).setCellType(CellType.STRING);
|
|
|
|
|
// custOrder = row.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //vin号
|
|
|
|
|
// String vinCode = null;
|
|
|
|
|
// try {
|
|
|
|
|
// row.getCell(6).setCellType(CellType.STRING);
|
|
|
|
|
// vinCode = row.getCell(6, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// }
|
|
|
|
|
// //校验工单标识
|
|
|
|
|
// if (StringUtils.isEmpty(orderFlag)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "A;";
|
|
|
|
|
// errorInfo += "第A列数据必填;";
|
|
|
|
|
// }else{
|
|
|
|
|
// if (null == MesExtEnumUtil.ORDER_TYPE_IDENTIFICATION.valueOfDescription(Integer.parseInt(orderFlag))) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "A;";
|
|
|
|
|
// errorInfo += "第A列数据无效";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //校验产线编号
|
|
|
|
|
// if (StringUtils.isEmpty(workCenterCode)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "B;";
|
|
|
|
|
// errorInfo += "第列数据必填;";
|
|
|
|
|
// }else{
|
|
|
|
|
// if (Objects.isNull(mesWorkCenterMap)||!mesWorkCenterMap.containsKey(workCenterCode)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "B;";
|
|
|
|
|
// errorInfo += "第B列数据无效";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //ERP总成零件号
|
|
|
|
|
// if (StringUtils.isEmpty(partNo)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "C;";
|
|
|
|
|
// errorInfo += "第C列数据必填;";
|
|
|
|
|
// }else{
|
|
|
|
|
// if (Objects.isNull(partNoMap)||!partNoMap.containsKey(partNo)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "C;";
|
|
|
|
|
// errorInfo += "第C列数据无效";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //计划开始时间(yyyy-MM-dd)
|
|
|
|
|
// if (StringUtils.isEmpty(planDate)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "D;";
|
|
|
|
|
// errorInfo += "第D列数据必填;";
|
|
|
|
|
// }
|
|
|
|
|
// //班次(1:早班/2:晚班)
|
|
|
|
|
// if (StringUtils.isEmpty(shiftCode)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "E;";
|
|
|
|
|
// errorInfo += "第E列数据必填;";
|
|
|
|
|
// }else{
|
|
|
|
|
// if (Objects.isNull(shiftMap)||!shiftMap.containsKey(shiftCode)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "E;";
|
|
|
|
|
// errorInfo += "第E列数据无效";
|
|
|
|
|
// }else{
|
|
|
|
|
// MesShift mesShift = (MesShift) shiftMap.get(shiftCode);
|
|
|
|
|
// //拼接
|
|
|
|
|
// planStartTime = planDate + " " + mesShift.getStartTime();
|
|
|
|
|
// planEndTime = planDate + " " + mesShift.getEndTime();
|
|
|
|
|
// try {
|
|
|
|
|
// int windowStartEndTimeCompare = DateUtilExt.compareDateTime(DateUtil.BASE_FORMAT, planStartTime, planEndTime);
|
|
|
|
|
// if (windowStartEndTimeCompare > 0) {
|
|
|
|
|
// planEndTime = TimeTool.pareDateToString(DateUtil.addDays(planEndTime,1));
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "E;";
|
|
|
|
|
// errorInfo += "第E列班次对应时间格式异常";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //vin号
|
|
|
|
|
// if (StringUtils.isEmpty(vinCode)) {
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "G;";
|
|
|
|
|
// errorInfo += "第G列数据必填;";
|
|
|
|
|
// }else{
|
|
|
|
|
// if(vinCodeList.contains(vinCode)||(!Objects.isNull(vinCodeMap) && vinCodeMap.containsKey(vinCode))){
|
|
|
|
|
// errorNum++;
|
|
|
|
|
// cellNum += "G;";
|
|
|
|
|
// errorInfo += "第G列数据重复";
|
|
|
|
|
// }else{
|
|
|
|
|
// vinCodeList.add(vinCode);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //没有错误的时候,封装MesWorkOrder
|
|
|
|
|
// if (errorNum == 0) {
|
|
|
|
|
// MesWorkOrder mesWorkOrder = new MesWorkOrder();
|
|
|
|
|
// ConvertBean.serviceModelInitialize(mesWorkOrder, userName);
|
|
|
|
|
// mesWorkOrder.setOrganizeCode(organizeCode);
|
|
|
|
|
// mesWorkOrder.setWorkCenterCode(workCenterCode);
|
|
|
|
|
// MesWorkCenter center = (MesWorkCenter) mesWorkCenterMap.get(workCenterCode);
|
|
|
|
|
// mesWorkOrder.setAreaCode(center.getAreaCode());
|
|
|
|
|
// mesWorkOrder.setErpWorkCenterCode(center.getSapWorkCenter());
|
|
|
|
|
// MesPart mesPart = (MesPart)partNoMap.get(partNo);
|
|
|
|
|
// mesWorkOrder.setPartNo(mesPart.getPartNo());
|
|
|
|
|
// mesWorkOrder.setPartNameRdd(mesPart.getPartName());
|
|
|
|
|
// mesWorkOrder.setPlanStartTime(planStartTime);
|
|
|
|
|
// mesWorkOrder.setPlanEndTime(planEndTime);
|
|
|
|
|
// mesWorkOrder.setQty(1d);
|
|
|
|
|
// mesWorkOrder.setShiftCode(shiftCode);
|
|
|
|
|
// MesShift mesShift = (MesShift) shiftMap.get(shiftCode);
|
|
|
|
|
// mesWorkOrder.setShiftName(mesShift.getShiftName());
|
|
|
|
|
// mesWorkOrder.setWorkOrderStatus(MesExtEnumUtil.ORDER_STATUS.CREATE.getValue());
|
|
|
|
|
// mesWorkOrder.setWorkOrderType(MesExtEnumUtil.ORDER_TYPE.SORT.getValue());
|
|
|
|
|
// mesWorkOrder.setOrderFlag(Integer.parseInt(orderFlag));
|
|
|
|
|
// item.getWorkOrderType() ==
|
|
|
|
|
// mesWorkOrder.setEndTime(endTime);
|
|
|
|
|
// mesWorkOrder.setPrtVehicleCount(Integer.parseInt(prtVehicleCount));
|
|
|
|
|
// mesWorkOrder.setPrtVehicleActualCount(Integer.parseInt(prtVehicleActualCount));
|
|
|
|
|
// mesWorkOrder.setSourcePartNo(sourcePartNo);
|
|
|
|
|
// mesWorkOrder.setTargetPartNo(targetPartNo);
|
|
|
|
|
// partPtr.setIsCustomerSendPrtInfo(Integer.parseInt(isCustomerSendPrtInfo));
|
|
|
|
|
// partPtr.setSeqInfoPrtPart(seqInfoPrtPart);
|
|
|
|
|
// partPtr.setPtrProjectNo(ptrProjectNo);
|
|
|
|
|
// partPtr.setTargetPartNoSnRuleCode(targetPartNoSnRuleCode);
|
|
|
|
|
// partPtr.setPartTypeCode(Integer.parseInt(partTypeCode));
|
|
|
|
|
// partPtr.setIsInterPrt(Integer.parseInt(isInterPrt));
|
|
|
|
|
// partPtr.setVisualSingleDisplayItem(visualSingleDisplayItem);
|
|
|
|
|
// partPtr.setStartSeq(startSeq);
|
|
|
|
|
// partPtr.setVisualSingleReplacePosition(visualSingleReplacePosition);
|
|
|
|
|
// partPtr.setHardwareVersionNo(hardwareVersionNo);
|
|
|
|
|
// partPtr.setSoftwareVersionNo(softwareVersionNo);
|
|
|
|
|
// partPtr.setStatus(Integer.parseInt(status));
|
|
|
|
|
// partPtr.setMemo(memo);
|
|
|
|
|
// partPtrList.add(partPtr);
|
|
|
|
|
// successRowNum++;
|
|
|
|
|
// } else {
|
|
|
|
|
// //封装错误行信息ExcelImportErrorModel
|
|
|
|
|
// excelImportErrorModels = commonService.getExcelImportErrorModels(excelImportErrorModels, rowNum, errorNum, cellNum, errorInfo);
|
|
|
|
|
//
|
|
|
|
|
// errorRows += rowNum + ";";
|
|
|
|
|
// failRowNum++;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //校验EXCEL数据
|
|
|
|
|
// commonService.checkExcelData(failRowNum, successRowNum, errorRows);
|
|
|
|
|
// //封装返回结果
|
|
|
|
|
// ExcelImportResultModel excelImportResultModel = commonService.getExcelImportResultModel(failRowNum, successRowNum, excelImportErrorModels, errorRows);
|
|
|
|
|
// excelImportResultModel.setExcelList((failRowNum > 0) ? null : partPtrList);
|
|
|
|
|
// return excelImportResultModel;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// private void insertExcelMesWorkOrder(ExcelImportResultModel excelImportResultModel) {
|
|
|
|
|
// if (excelImportResultModel == null) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// List<MesWorkOrder> partPtrList = excelImportResultModel.getExcelList();
|
|
|
|
|
// if (CollectionUtils.isEmpty(partPtrList)) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// partPtrList.forEach(k -> {
|
|
|
|
|
// if (StringUtils.isEmpty(k.getId())) {
|
|
|
|
|
// mesWorkOrderRDao.insert(k);
|
|
|
|
|
// } else {
|
|
|
|
|
// mesWorkOrderRDao.update(k);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//}
|