|
|
@@ -0,0 +1,232 @@
|
|
|
+package com.jeesite.modules.mes.service;
|
|
|
+
|
|
|
+import com.jeesite.common.collect.ListUtils;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.idgen.IdGen;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.common.service.CrudService;
|
|
|
+import com.jeesite.modules.mes.dao.MesProductDbjRecordDao;
|
|
|
+import com.jeesite.modules.mes.entity.MesLineProcess;
|
|
|
+import com.jeesite.modules.mes.entity.MesLineProcessMaterial;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductDbjBind;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductDbjRecord;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductDbjRecordItem;
|
|
|
+import com.jeesite.modules.mes.resp.BindMaterialResp;
|
|
|
+import com.jeesite.modules.mes.resp.ParamsResp;
|
|
|
+import com.jeesite.modules.mes.util.CommonUitl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 单部件加工记录Service
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MesProductDbjRecordService extends CrudService<MesProductDbjRecordDao, MesProductDbjRecord> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductDbjRecordItemService mesProductDbjRecordItemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductDbjBindService mesProductDbjBindService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesLineProcessMaterialService mesLineProcessMaterialService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MesProductDbjRecord get(MesProductDbjRecord mesProductDbjRecord) {
|
|
|
+ return super.get(mesProductDbjRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<MesProductDbjRecord> findPage(MesProductDbjRecord mesProductDbjRecord) {
|
|
|
+ return super.findPage(mesProductDbjRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MesProductDbjRecord> findList(MesProductDbjRecord mesProductDbjRecord) {
|
|
|
+ return super.findList(mesProductDbjRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void save(MesProductDbjRecord mesProductDbjRecord) {
|
|
|
+ super.save(mesProductDbjRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单部件工位质量上传后落库
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void saveFromUpload(String sn, String oldOprno, String lineSn, String craft, String content,
|
|
|
+ String userCode, List<ParamsResp> paramsResps, List<BindMaterialResp> bmlists,
|
|
|
+ MesLineProcess mesLineProcess, Integer intervalSec) {
|
|
|
+ String partSn = StringUtils.trimToEmpty(sn);
|
|
|
+ String result = "OK".equals(content) ? "OK" : "NG";
|
|
|
+ String batchId = IdGen.nextId();
|
|
|
+ String materielSn = buildMaterielSn(bmlists);
|
|
|
+
|
|
|
+ MesProductDbjRecord record = new MesProductDbjRecord();
|
|
|
+ record.setLineSn(lineSn);
|
|
|
+ record.setOprno(oldOprno);
|
|
|
+ record.setSn(StringUtils.isEmpty(partSn) ? null : partSn);
|
|
|
+ // 单部件工位仅扫精追码,主工件码在后续工序绑定后再回写
|
|
|
+ record.setDbjSn(null);
|
|
|
+ record.setCraft(StringUtils.isEmpty(craft) ? "100000" : craft);
|
|
|
+ record.setResult(result);
|
|
|
+ record.setMaterielSn(materielSn);
|
|
|
+ record.setDeviceNo(mesLineProcess.getDevices());
|
|
|
+ record.setGzNo(mesLineProcess.getGzs());
|
|
|
+ record.setIntervalSec(intervalSec);
|
|
|
+ record.setUserCode(userCode);
|
|
|
+ record.setSource("0");
|
|
|
+ record.setBatchId(batchId);
|
|
|
+ if (StringUtils.isNotEmpty(userCode)) {
|
|
|
+ record.setCreateBy(userCode);
|
|
|
+ record.setUpdateBy(userCode);
|
|
|
+ }
|
|
|
+ super.save(record);
|
|
|
+
|
|
|
+ List<MesProductDbjRecordItem> items = buildItems(paramsResps, oldOprno, lineSn, bmlists);
|
|
|
+ mesProductDbjRecordItemService.saveBatch(record.getId(), items);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情展示:补全过程参数的物料名称(兼容历史数据)
|
|
|
+ */
|
|
|
+ public List<MesProductDbjRecordItem> findItemsForRecord(MesProductDbjRecord record) {
|
|
|
+ if (record == null || StringUtils.isEmpty(record.getId())) {
|
|
|
+ return ListUtils.newArrayList();
|
|
|
+ }
|
|
|
+ List<MesProductDbjRecordItem> items = mesProductDbjRecordItemService.findByRecordId(record.getId());
|
|
|
+ enrichItemMaterialNames(items, record.getOprno(), record.getLineSn());
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildMaterielSn(List<BindMaterialResp> bmlists) {
|
|
|
+ if (ListUtils.isEmpty(bmlists)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<String> sns = new ArrayList<>();
|
|
|
+ for (BindMaterialResp bindMaterialResp : bmlists) {
|
|
|
+ if (StringUtils.isNotEmpty(bindMaterialResp.getBatchSn())) {
|
|
|
+ sns.add(bindMaterialResp.getBatchSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sns.isEmpty() ? null : StringUtils.join(sns, ",");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 后续工序绑定主工件码后,回写历史单部件加工记录
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void backfillDbjSn(String partSn, String dbjSn) {
|
|
|
+ if (StringUtils.isEmpty(partSn) || StringUtils.isEmpty(dbjSn)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MesProductDbjRecord query = new MesProductDbjRecord();
|
|
|
+ query.setSn(partSn);
|
|
|
+ List<MesProductDbjRecord> records = findList(query);
|
|
|
+ for (MesProductDbjRecord record : records) {
|
|
|
+ if (StringUtils.isEmpty(record.getDbjSn())) {
|
|
|
+ record.setDbjSn(dbjSn);
|
|
|
+ super.save(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按精追码或主工件码查询关联绑定记录
|
|
|
+ */
|
|
|
+ public List<MesProductDbjBind> findBindListForRecord(MesProductDbjRecord record) {
|
|
|
+ List<MesProductDbjBind> bindList = new ArrayList<>();
|
|
|
+ if (record == null) {
|
|
|
+ return bindList;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getSn())) {
|
|
|
+ MesProductDbjBind byPartSn = new MesProductDbjBind();
|
|
|
+ byPartSn.setMaterielSn(record.getSn());
|
|
|
+ byPartSn.getSqlMap().getOrder().setOrderBy("a.create_date DESC");
|
|
|
+ bindList.addAll(mesProductDbjBindService.findList(byPartSn));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(record.getDbjSn())) {
|
|
|
+ MesProductDbjBind byDbjSn = new MesProductDbjBind();
|
|
|
+ byDbjSn.setDbjSn(record.getDbjSn());
|
|
|
+ byDbjSn.getSqlMap().getOrder().setOrderBy("a.create_date DESC");
|
|
|
+ for (MesProductDbjBind bind : mesProductDbjBindService.findList(byDbjSn)) {
|
|
|
+ if (bindList.stream().noneMatch(item -> item.getId().equals(bind.getId()))) {
|
|
|
+ bindList.add(bind);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bindList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<MesProductDbjRecordItem> buildItems(List<ParamsResp> paramsResps, String oprno, String lineSn,
|
|
|
+ List<BindMaterialResp> bmlists) {
|
|
|
+ List<MesProductDbjRecordItem> items = new ArrayList<>();
|
|
|
+ if (ListUtils.isEmpty(paramsResps)) {
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+ Map<String, String> craftMaterialMap = buildCraftMaterialNameMap(oprno, lineSn, bmlists);
|
|
|
+ int sort = 0;
|
|
|
+ for (ParamsResp paramsResp : paramsResps) {
|
|
|
+ if (paramsResp == null || StringUtils.isEmpty(paramsResp.getCraft())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MesProductDbjRecordItem item = new MesProductDbjRecordItem();
|
|
|
+ item.setCraft(paramsResp.getCraft());
|
|
|
+ item.setCraftName(craftMaterialMap.get(paramsResp.getCraft()));
|
|
|
+ item.setResult(paramsResp.getResult());
|
|
|
+ item.setVal(paramsResp.getVal());
|
|
|
+ item.setSort(sort++);
|
|
|
+ items.add(item);
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void enrichItemMaterialNames(List<MesProductDbjRecordItem> items, String oprno, String lineSn) {
|
|
|
+ if (ListUtils.isEmpty(items)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> craftMaterialMap = buildCraftMaterialNameMap(oprno, lineSn, null);
|
|
|
+ for (MesProductDbjRecordItem item : items) {
|
|
|
+ if (StringUtils.isEmpty(item.getCraftName()) && StringUtils.isNotEmpty(item.getCraft())) {
|
|
|
+ item.setCraftName(craftMaterialMap.get(item.getCraft()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> buildCraftMaterialNameMap(String oprno, String lineSn, List<BindMaterialResp> bmlists) {
|
|
|
+ Map<String, String> craftMaterialMap = new HashMap<>();
|
|
|
+ if (!ListUtils.isEmpty(bmlists)) {
|
|
|
+ for (BindMaterialResp bindMaterialResp : bmlists) {
|
|
|
+ if (StringUtils.isNotEmpty(bindMaterialResp.getCraft())
|
|
|
+ && StringUtils.isNotEmpty(bindMaterialResp.getMaterialTitle())) {
|
|
|
+ craftMaterialMap.put(bindMaterialResp.getCraft(), bindMaterialResp.getMaterialTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(oprno) || StringUtils.isEmpty(lineSn)) {
|
|
|
+ return craftMaterialMap;
|
|
|
+ }
|
|
|
+ MesLineProcessMaterial query = new MesLineProcessMaterial();
|
|
|
+ query.setOprno(CommonUitl.formatOprno(oprno));
|
|
|
+ query.setLineSn(lineSn);
|
|
|
+ List<MesLineProcessMaterial> materials = mesLineProcessMaterialService.findList(query);
|
|
|
+ if (!ListUtils.isEmpty(materials)) {
|
|
|
+ for (MesLineProcessMaterial material : materials) {
|
|
|
+ if (StringUtils.isNotEmpty(material.getCraft())
|
|
|
+ && StringUtils.isNotEmpty(material.getMaterialTitle())) {
|
|
|
+ craftMaterialMap.putIfAbsent(material.getCraft(), material.getMaterialTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return craftMaterialMap;
|
|
|
+ }
|
|
|
+}
|