修改描述

tags/yfai-mes-ext-v1.0
LML丶 1 year ago
parent e48469618d
commit b8fd0e9419

@ -10,4 +10,6 @@ import cn.estsh.i3plus.pojo.mes.bean.MesDefectAlarmConfig;
public interface IMesDefectAlarmConfigService extends IBaseMesService<MesDefectAlarmConfig> { public interface IMesDefectAlarmConfigService extends IBaseMesService<MesDefectAlarmConfig> {
public void saveDefectAlarmConfigByJob(String org);
} }

@ -0,0 +1,17 @@
package cn.estsh.i3plus.ext.mes.apiservice.dao;
import cn.estsh.i3plus.ext.mes.pojo.model.MesDefectRecordModel;
import java.util.List;
/**
* @Description : SAP
* @Reference :
* @Author : junsheng.li
* @CreateDate 2024/5/7 15:13
* @Modify:
**/
public interface IMesDefectRecordDao {
List<MesDefectRecordModel> queryMesDefectRecordGroupBy(String organizeCode, Integer count);
}

@ -0,0 +1,74 @@
package cn.estsh.i3plus.ext.mes.apiservice.daoimpl;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesDefectRecordDao;
import cn.estsh.i3plus.ext.mes.pojo.model.MesDefectRecordModel;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.ArrayList;
import java.util.List;
/**
* @Description :
* @Reference :
* @Author :
* @CreateDate : 2024-05-13 18:08
* @Modify:
**/
@Service
@Slf4j
public class MesDefectRecordDaoImpl implements IMesDefectRecordDao {
@Autowired
private EntityManager entityManager;
@Override
public List<MesDefectRecordModel> queryMesDefectRecordGroupBy(String organizeCode, Integer count) {
StringBuffer hql = new StringBuffer("select mdr.part_no ,mp.part_type_code mdr.sides ,mdr.defect_location_code ,mdr.defect_code ");
hql.append(" from mes_defect_record as mdr");
hql.append(" inner join mes_part as mp where mdr.part_no = mp.part_no and mdr.organize_code = mp.organize_code ");
hql.append(" and mdr.is_deleted = mp.is_deleted and mdr.is_valid = mp.is_valid ");
hql.append(" where mdr.organize_code = :organizeCode ");
hql.append(" and mdr.is_deleted = :isDeleted ");
hql.append(" and mdr.is_valid = :isValid ");
hql.append(" and mdr.nc_type = 0 ");
hql.append(" group by mdr.part_no ,mp.part_type_code mdr.sides ,mdr.defect_location_code ,mdr.defect_code ");
hql.append(" having count() > " + count);
Query query = entityManager.createNativeQuery(hql.toString());
query.setParameter("organizeCode", organizeCode);
query.setParameter("isValid", CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
query.setParameter("isDeleted", CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
List list = query.getResultList();
List<MesDefectRecordModel> modelList = new ArrayList<>();
for (Object result : list) {
Object[] cells = (Object[]) result;
MesDefectRecordModel model = new MesDefectRecordModel();
String partNo = String.valueOf(cells[0]);
String partTypeCode = String.valueOf(cells[1]);
String sides = String.valueOf(cells[2]);
String defectLocationCode = String.valueOf(cells[3]);
String defectCode = String.valueOf(cells[4]);
model.setPartNo(partNo);
model.setPartTypeCode(partTypeCode);
model.setSides(Integer.parseInt(sides));
model.setDefectLocationCode(defectLocationCode);
model.setDefectCode(defectCode);
modelList.add(model);
}
return modelList;
}
}

@ -0,0 +1,88 @@
package cn.estsh.i3plus.ext.mes.apiservice.schedulejob;
import cn.estsh.i3plus.ext.mes.api.base.IMesDefectAlarmConfigService;
import cn.estsh.i3plus.mes.apiservice.schedulejob.BaseMesScheduleJob;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description : SAP MES +
* @Reference :
* @Author : gsz
* @CreateDate : 2024-05-10 11:03
* @Modify:
**/
// 禁止 JOB 并发执行
@DisallowConcurrentExecution
@ApiOperation("缺陷告警配置job")
public class MesDefectAlarmConfigJob extends BaseMesScheduleJob {
public static final Logger LOGGER = LoggerFactory.getLogger(MesDefectAlarmConfigJob.class);
private static final long serialVersionUID = 9072058154235836696L;
@Autowired
private IMesDefectAlarmConfigService defectAlarmConfigService;
@Value("${server.port}")
private String serverPort;
@Value("${impp.server.ip}")
private String ip;
public MesDefectAlarmConfigJob() {
super(MesDefectAlarmConfigJob.class, "缺陷告警配置job按工厂划分");
this.setMultiInstance(true);
}
@Override
public void executeMesJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
try {
String jobParam = this.getJobParam();
if (StringUtils.isBlank(jobParam)) {
throw new IllegalArgumentException("jobc参数为空请检查参数");
}
Map<String, Object> paramMap = new HashMap<>();
try {
paramMap = (Map<String, Object>) JSONObject.parse(jobParam);
} catch (Exception e) {
LOGGER.error("参数格式不是JSON");
return;
}
if (CollectionUtils.isEmpty(paramMap)) {
LOGGER.error("检测数据同步定时任务,没有配置参数");
return;
}
List<String> organizeCodeList = (List<String>) paramMap.get("org");
for (String organizeCode : organizeCodeList) {
defectAlarmConfigService.saveDefectAlarmConfigByJob(organizeCode);
}
LOGGER.info("缺陷告警配置job结束 ----- end");
} catch (Exception e) {
LOGGER.error("SAP接口表数据同步作业任务结束e:{}", e.toString());
//sendErrorMessage(e.toString());
}
}
}

@ -1,18 +1,39 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base; package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesConfigService;
import cn.estsh.i3plus.ext.mes.api.base.IMesDefectAlarmConfigService; import cn.estsh.i3plus.ext.mes.api.base.IMesDefectAlarmConfigService;
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesDefectRecordDao;
import cn.estsh.i3plus.ext.mes.pojo.model.MesDefectRecordModel;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack; import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesDefect;
import cn.estsh.i3plus.pojo.mes.bean.MesDefectAlarmConfig; import cn.estsh.i3plus.pojo.mes.bean.MesDefectAlarmConfig;
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
import cn.estsh.i3plus.pojo.mes.repository.MesDefectRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesPartRepository;
import cn.estsh.impp.framework.boot.util.ValidatorBean; import cn.estsh.impp.framework.boot.util.ValidatorBean;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
@Slf4j @Slf4j
public class MesDefectAlarmConfigService extends BaseMesService<MesDefectAlarmConfig> implements IMesDefectAlarmConfigService { public class MesDefectAlarmConfigService extends BaseMesService<MesDefectAlarmConfig> implements IMesDefectAlarmConfigService {
@Autowired
private IMesDefectRecordDao defectRecordDao;
@Autowired
private MesPartRepository partRepository;
@Autowired
private MesDefectRepository defectRepository;
@Autowired
private IMesConfigService configService;
protected void onInsertBean(MesDefectAlarmConfig item) { protected void onInsertBean(MesDefectAlarmConfig item) {
// 数据校验 // 数据校验
ValidatorBean.checkNotNull(item.getPartTypeCode(), "零件类型不能为空"); ValidatorBean.checkNotNull(item.getPartTypeCode(), "零件类型不能为空");
@ -31,4 +52,46 @@ public class MesDefectAlarmConfigService extends BaseMesService<MesDefectAlarmCo
DdlPreparedPack.getStringEqualPack(bean.getPartTypeCode(), "partTypeCode", packBean); DdlPreparedPack.getStringEqualPack(bean.getPartTypeCode(), "partTypeCode", packBean);
} }
@Override
public void saveDefectAlarmConfigByJob(String org) {
String count = configService.getCfgValue(org, "DEFECT_ALARM_CONFIG_COUNT");
//不良类型
List<MesDefectRecordModel> modelList = defectRecordDao.queryMesDefectRecordGroupBy(org, Integer.parseInt(count));
for (MesDefectRecordModel model : modelList) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(org);
DdlPreparedPack.getStringEqualPack(model.getDefectCode(), "defectCode", packBean);
DdlPreparedPack.getStringLikerPack(model.getDefectLocationCode(), "defectLocationCode", packBean);
DdlPreparedPack.getStringEqualPack(model.getPartTypeCode(), "partTypeCode", packBean);
DdlPreparedPack.getStringEqualPack(model.getPartNo(), "partNo", packBean);
DdlPreparedPack.getNumEqualPack(model.getSides(), "sides", packBean);
boolean flg = baseRDao.isExitByHql(packBean);
if (!flg) {
DdlPackBean defectPackBean = DdlPackBean.getDdlPackBean(org);
DdlPreparedPack.getStringEqualPack(model.getDefectCode(), "defectCode", defectPackBean);
MesDefect defect = defectRepository.getByProperty(defectPackBean);
DdlPackBean partPackBean = DdlPackBean.getDdlPackBean(org);
DdlPreparedPack.getStringEqualPack(model.getPartNo(), "partNo", partPackBean);
MesPart part = partRepository.getByProperty(partPackBean);
MesDefectAlarmConfig config = new MesDefectAlarmConfig();
config.setPartNo(part.getPartNo());
config.setPartName(part.getPartName());
config.setDefectCode(defect.getDefectCode());
config.setDefectName(defect.getDefectName());
config.setDefectLocationCode(model.getDefectLocationCode());
config.setPartTypeCode(part.getPartTypeCode());
config.setPartTypeName(part.getPartTypeName());
config.setSides(model.getSides());
config.setOrganizeCode(org);
ConvertBean.serviceModelInitialize(config, "xxljob");
baseRDao.save(config);
}
}
}
} }

@ -0,0 +1,223 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel;
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.MesCommonUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.util.MesConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesItemPartErrorPrevention;
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
import cn.estsh.i3plus.pojo.mes.model.ExcelImportErrorModel;
import cn.estsh.i3plus.pojo.mes.model.ExcelImportResultModel;
import cn.estsh.i3plus.pojo.mes.repository.MesItemPartErrorPreventionRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesPartRepository;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description :
* @Reference :
* @Author :
* @CreateDate : 2024-05-13 16:50
* @Modify:
**/
@Service
@Slf4j
public class MesItemPartErrorPreventionExcelService implements IExcelImportService {
@Autowired
private CommonService commonService;
@Autowired
private MesPartRepository partRepository;
@Autowired
private MesItemPartErrorPreventionRepository itemPartErrorPreventionRepository;
@Override
public ExcelImportResultModel insertDataByExcel(Workbook workbook, String organizeCode, String userName) {
//读取表格
ExcelImportResultModel excelImportResultModel = this.sheetExtractMesStationBom(workbook.getSheetAt(0), organizeCode, userName);
//数据入库
this.insertExcelMesItemPartErrorPrevention(excelImportResultModel);
return excelImportResultModel;
// return null;
}
/**
* BOM-
*
* @param sheetAt
* @param organizeCode
* @param userName
* @return
*/
private ExcelImportResultModel sheetExtractMesStationBom(Sheet sheetAt, String organizeCode, String userName) {
//从0行开始读取
int totalNumberOfRows = sheetAt.getLastRowNum() + 1;
//MesStationBom集合
List<MesItemPartErrorPrevention> itemPartErrorPreventions = new ArrayList<>();
//成功数量
Integer successRowNum = 0;
//失败数量
Integer failRowNum = 0;
//错误的行号
String errorRows = "";
//错误行信息集合
List<ExcelImportErrorModel> excelImportErrorModels = new ArrayList<>();
// 查询物料表
Map<String, Object> partCodeEntityMap;
try {
partCodeEntityMap = MesCommonUtil.getCodeEntityMap(partRepository, "partNo", organizeCode, "物料表");
} catch (Exception e) {
partCodeEntityMap = null;
}
//查询关键件条码校验规则表
List<MesItemPartErrorPrevention> itemPartErrorPreventionList = itemPartErrorPreventionRepository.findByProperty(new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_DELETED},
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()});
Map<String, List<MesItemPartErrorPrevention>> preventionMap =
itemPartErrorPreventionList.stream().collect(Collectors.groupingBy(k -> k.getPreventionObjectCode() + "&" + k.getPartNo()));
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 preventionObjectCode = row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
//防错代码
String preventionCode = null;
try {
row.getCell(1).setCellType(CellType.STRING);
preventionCode = row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//零件号
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) {
}
//批次号
String lot = null;
try {
row.getCell(3).setCellType(CellType.STRING);
lot = row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
if (!map.containsKey(preventionObjectCode + "&" + partNo)) {
map.put(preventionObjectCode + "&" + partNo, String.valueOf(rowNum));
} else {
errorNum++;
cellNum += "A;C;";
errorInfo += "第A列数据:" + preventionObjectCode + ",第C列数据:" + partNo;
}
//校验物料号
if (StringUtils.isEmpty(partNo)) {
errorNum++;
cellNum += "C;";
errorInfo += "第C列数据必填;";
} else {
if (CollectionUtils.isEmpty(partCodeEntityMap) ||
(!CollectionUtils.isEmpty(partCodeEntityMap) && !partCodeEntityMap.containsKey(partNo))) {
errorNum++;
cellNum += "C;";
errorInfo += "第C列数据无效;";
}
}
//没有错误的时候封装MesStationBom
if (errorNum == 0) {
MesItemPartErrorPrevention itemPartErrorPrevention;
if (preventionMap.containsKey(preventionObjectCode + "&" + partNo)) {
itemPartErrorPrevention = preventionMap.get(partNo).get(0);
ConvertBean.serviceModelUpdate(itemPartErrorPrevention, userName);
} else {
itemPartErrorPrevention = new MesItemPartErrorPrevention();
ConvertBean.serviceModelInitialize(itemPartErrorPrevention, userName);
}
itemPartErrorPrevention.setPartNo(partNo);
itemPartErrorPrevention.setOrganizeCode(organizeCode);
MesPart part = (MesPart) partCodeEntityMap.get(partNo);
itemPartErrorPrevention.setPartName(part.getPartName());
itemPartErrorPrevention.setLot(lot);
itemPartErrorPrevention.setPreventionObjectCode(preventionObjectCode);
itemPartErrorPrevention.setPreventionCode(preventionCode);
itemPartErrorPreventions.add(itemPartErrorPrevention);
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 : itemPartErrorPreventions);
return excelImportResultModel;
}
private void insertExcelMesItemPartErrorPrevention(ExcelImportResultModel excelImportResultModel) {
if (excelImportResultModel == null) {
return;
}
List<MesItemPartErrorPrevention> itemPartErrorPreventions = excelImportResultModel.getExcelList();
if (CollectionUtils.isEmpty(itemPartErrorPreventions)) {
return;
}
itemPartErrorPreventions.forEach(k -> {
if (StringUtils.isEmpty(k.getId())) {
itemPartErrorPreventionRepository.insert(k);
} else {
itemPartErrorPreventionRepository.update(k);
}
});
}
}

@ -0,0 +1,390 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel;
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.MesCommonUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.mes.bean.MesPartPtr;
import cn.estsh.i3plus.pojo.mes.model.ExcelImportErrorModel;
import cn.estsh.i3plus.pojo.mes.model.ExcelImportResultModel;
import cn.estsh.i3plus.pojo.mes.repository.MesPartPtrRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesPartRepository;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description :
* @Reference :
* @Author :
* @CreateDate : 2024-05-13 16:50
* @Modify:
**/
@Service
@Slf4j
public class MesPartPtrExcelService implements IExcelImportService {
@Autowired
private CommonService commonService;
@Autowired
private MesPartRepository partRepository;
@Autowired
private MesPartPtrRepository partPtrRepository;
@Override
public ExcelImportResultModel insertDataByExcel(Workbook workbook, String organizeCode, String userName) {
//读取表格
ExcelImportResultModel excelImportResultModel = this.sheetExtractMesStationBom(workbook.getSheetAt(0), organizeCode, userName);
//数据入库
this.insertExcelMesPartPtr(excelImportResultModel);
return excelImportResultModel;
// return null;
}
/**
* BOM-
*
* @param sheetAt
* @param organizeCode
* @param userName
* @return
*/
private ExcelImportResultModel sheetExtractMesStationBom(Sheet sheetAt, String organizeCode, String userName) {
//从0行开始读取
int totalNumberOfRows = sheetAt.getLastRowNum() + 1;
//MesStationBom集合
List<MesPartPtr> partPtrList = new ArrayList<>();
//成功数量
Integer successRowNum = 0;
//失败数量
Integer failRowNum = 0;
//错误的行号
String errorRows = "";
//错误行信息集合
List<ExcelImportErrorModel> excelImportErrorModels = new ArrayList<>();
// 查询物料表
Map<String, Object> partCodeEntityMap;
try {
partCodeEntityMap = MesCommonUtil.getCodeEntityMap(partRepository, "partNo", organizeCode, "物料表");
} catch (Exception e) {
partCodeEntityMap = null;
}
// //查询关键件条码校验规则表
// List<MesPartPtr> partPtrList = partPtrRepository.findByProperty(new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_DELETED},
// new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()});
// Map<String, List<MesPartPtr>> preventionMap =
// partPtrList.stream().collect(Collectors.groupingBy(k -> k.getPreventionObjectCode() + "&" + k.getPartNo()));
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 workCenterCode = row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
//开始时间
String startTime = null;
try {
row.getCell(1).setCellType(CellType.STRING);
startTime = row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//结束时间
String endTime = null;
try {
row.getCell(2).setCellType(CellType.STRING);
endTime = row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//PTR车辆数量
String prtVehicleCount = null;
try {
row.getCell(3).setCellType(CellType.STRING);
prtVehicleCount = row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//PTR车辆实际数量
String prtVehicleActualCount = null;
try {
row.getCell(4).setCellType(CellType.STRING);
prtVehicleActualCount = row.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//原零件号
String sourcePartNo = null;
try {
row.getCell(5).setCellType(CellType.STRING);
sourcePartNo = row.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//替换零件号
String targetPartNo = null;
try {
row.getCell(6).setCellType(CellType.STRING);
targetPartNo = row.getCell(6, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//是否客户 发送PTR信息
String isCustomerSendPrtInfo = null;
try {
row.getCell(7).setCellType(CellType.STRING);
isCustomerSendPrtInfo = row.getCell(7, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//排序信息PTR零件号
String seqInfoPrtPart = null;
try {
row.getCell(8).setCellType(CellType.STRING);
seqInfoPrtPart = row.getCell(8, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//PTR项目编号
String ptrProjectNo = null;
try {
row.getCell(9).setCellType(CellType.STRING);
ptrProjectNo = row.getCell(9, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//替换零件条码规则
String targetPartNoSnRuleCode = null;
try {
row.getCell(10).setCellType(CellType.STRING);
targetPartNoSnRuleCode = row.getCell(10, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//总成类型
String partTypeCode = null;
try {
row.getCell(11).setCellType(CellType.STRING);
partTypeCode = row.getCell(11, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//总成类型
String isInterPrt = null;
try {
row.getCell(12).setCellType(CellType.STRING);
isInterPrt = row.getCell(12, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//目视单显示项
String visualSingleDisplayItem = null;
try {
row.getCell(13).setCellType(CellType.STRING);
visualSingleDisplayItem = row.getCell(13, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//起始序号
String startSeq = null;
try {
row.getCell(14).setCellType(CellType.STRING);
startSeq = row.getCell(14, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//目视单替换位置
String visualSingleReplacePosition = null;
try {
row.getCell(14).setCellType(CellType.STRING);
visualSingleReplacePosition = row.getCell(14, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//硬件版本号
String hardwareVersionNo = null;
try {
row.getCell(15).setCellType(CellType.STRING);
hardwareVersionNo = row.getCell(15, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//软件版本号
String softwareVersionNo = null;
try {
row.getCell(16).setCellType(CellType.STRING);
softwareVersionNo = row.getCell(16, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//软件版本号
String status = null;
try {
row.getCell(17).setCellType(CellType.STRING);
status = row.getCell(17, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//软件版本号
String memo = null;
try {
row.getCell(18).setCellType(CellType.STRING);
memo = row.getCell(18, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
// if (!map.containsKey(preventionObjectCode + "&" + partNo)) {
// map.put(preventionObjectCode + "&" + partNo, String.valueOf(rowNum));
// } else {
// errorNum++;
// cellNum += "A;C;";
// errorInfo += "第A列数据:" + preventionObjectCode + ",第C列数据:" + partNo;
// }
//
// //校验物料号
// if (StringUtils.isEmpty(partNo)) {
// errorNum++;
// cellNum += "C;";
// errorInfo += "第C列数据必填;";
// } else {
// if (CollectionUtils.isEmpty(partCodeEntityMap) ||
// (!CollectionUtils.isEmpty(partCodeEntityMap) && !partCodeEntityMap.containsKey(partNo))) {
// errorNum++;
// cellNum += "C;";
// errorInfo += "第C列数据无效;";
// }
// }
//校验产线编号
if (StringUtils.isEmpty(workCenterCode)) {
errorNum++;
cellNum += "A;";
errorInfo += "第A列数据必填;";
}
//校验原零件号
if (StringUtils.isEmpty(sourcePartNo)) {
errorNum++;
cellNum += "F;";
errorInfo += "第F列数据必填;";
}
//校验产线编号
if (StringUtils.isEmpty(targetPartNo)) {
errorNum++;
cellNum += "G;";
errorInfo += "第G列数据必填;";
}
//校验替换零件号
if (StringUtils.isEmpty(ptrProjectNo)) {
errorNum++;
cellNum += "J;";
errorInfo += "第J列数据必填;";
}
//校验总成类型
if (StringUtils.isEmpty(partTypeCode)) {
errorNum++;
cellNum += "L;";
errorInfo += "第L列数据必填;";
}
//没有错误的时候封装MesStationBom
if (errorNum == 0) {
MesPartPtr partPtr;
// if (preventionMap.containsKey(preventionObjectCode + "&" + partNo)) {
// itemPartErrorPrevention = preventionMap.get(partNo).get(0);
// ConvertBean.serviceModelUpdate(itemPartErrorPrevention, userName);
// } else {
partPtr = new MesPartPtr();
ConvertBean.serviceModelInitialize(partPtr, userName);
// }
partPtr.setWorkCenterCode(workCenterCode);
partPtr.setStartTime(startTime);
partPtr.setEndTime(endTime);
partPtr.setPrtVehicleCount(Integer.parseInt(prtVehicleCount));
partPtr.setPrtVehicleActualCount(Integer.parseInt(prtVehicleActualCount));
partPtr.setSourcePartNo(sourcePartNo);
partPtr.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 insertExcelMesPartPtr(ExcelImportResultModel excelImportResultModel) {
if (excelImportResultModel == null) {
return;
}
List<MesPartPtr> partPtrList = excelImportResultModel.getExcelList();
if (CollectionUtils.isEmpty(partPtrList)) {
return;
}
partPtrList.forEach(k -> {
if (StringUtils.isEmpty(k.getId())) {
partPtrRepository.insert(k);
} else {
partPtrRepository.update(k);
}
});
}
}

@ -0,0 +1,24 @@
package cn.estsh.i3plus.ext.mes.pojo.model;
import io.swagger.annotations.ApiParam;
import lombok.Data;
@Data
public class MesDefectRecordModel {
@ApiParam("物料号")
private String partNo;
@ApiParam("零件类型代码-零件类别")
private String partTypeCode;
@ApiParam("缺陷代码")
private String defectCode;
@ApiParam("位置")
private String defectLocationCode;
@ApiParam("面位-正反面")
private Integer sides;
}

@ -13,6 +13,69 @@ import com.fasterxml.jackson.annotation.JsonFormat;
public class MesExtEnumUtil { public class MesExtEnumUtil {
/** /**
* mes
*/
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum MES_EXCEL {
MES_ITEM_PART_ERROR_PREVENTION(40, "mesItemPartErrorPreventionExcelService", "原材料防错,支持编辑"),
MES_PART_PTR(41, "mesPartPtrExcelService", "PTR支持编辑"),
MES_EXPERIMENTAL_PIECE_RULE(42, "mesExperimentalPieceRuleExcelService", "实验件规则,支持编辑");
private int value;
private String service;
private String description;
MES_EXCEL(int value, String service, String description) {
this.value = value;
this.service = service;
this.description = description;
}
public static MES_EXCEL getByValue(int value) {
for (MES_EXCEL excel : values()) {
if (excel.getValue() == value) {
return excel;
}
}
return null;
}
public static String valueOfDescription(int val) {
String tmp = null;
for (int i = 0; i < values().length; i++) {
if (values()[i].value == val) {
tmp = values()[i].description;
}
}
return tmp;
}
public static String valueOfService(int val) {
String tmp = null;
for (int i = 0; i < values().length; i++) {
if (values()[i].value == val) {
tmp = values()[i].service;
}
}
return tmp;
}
public int getValue() {
return value;
}
public String getService() {
return service;
}
public String getDescription() {
return description;
}
}
/**
* *
*/ */
@JsonFormat( @JsonFormat(

Loading…
Cancel
Save