|
@@ -2,10 +2,14 @@ package com.fjhx.mes.service.technology.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.mes.entity.applicable.po.ApplicableProducts;
|
|
@@ -13,20 +17,18 @@ import com.fjhx.mes.entity.production.po.ProductionProcesses;
|
|
|
import com.fjhx.mes.entity.technology.dto.TechnologyDto;
|
|
|
import com.fjhx.mes.entity.technology.dto.TechnologySelectDto;
|
|
|
import com.fjhx.mes.entity.technology.po.Technology;
|
|
|
+import com.fjhx.mes.entity.technology.po.TechnologyProcessLine;
|
|
|
import com.fjhx.mes.entity.technology.vo.TechnologyVo;
|
|
|
import com.fjhx.mes.mapper.technology.TechnologyMapper;
|
|
|
import com.fjhx.mes.service.applicable.ApplicableProductsService;
|
|
|
import com.fjhx.mes.service.production.ProductionProcessesService;
|
|
|
+import com.fjhx.mes.service.technology.TechnologyProcessLineService;
|
|
|
import com.fjhx.mes.service.technology.TechnologyService;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
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.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -48,6 +50,8 @@ public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technol
|
|
|
ApplicableProductsService applicableProductsService;
|
|
|
@Autowired
|
|
|
ProductInfoService productInfoService;
|
|
|
+ @Autowired
|
|
|
+ private TechnologyProcessLineService technologyProcessLineService;
|
|
|
|
|
|
@Override
|
|
|
public Page<TechnologyVo> getPage(TechnologySelectDto dto) {
|
|
@@ -73,7 +77,7 @@ public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technol
|
|
|
for (ApplicableProducts applicableProducts : applicableProductsList1) {
|
|
|
ProductInfo productInfo = productInfoMap.get(applicableProducts.getProductId());
|
|
|
if (ObjectUtil.isNotEmpty(productInfo)) {
|
|
|
- productNameList.add(productInfo.getName()+"("+productInfo.getSpec()+")");
|
|
|
+ productNameList.add(productInfo.getName() + "(" + productInfo.getSpec() + ")");
|
|
|
} else {
|
|
|
productNameList.add("未知商品:" + applicableProducts.getProductId());
|
|
|
}
|
|
@@ -140,7 +144,7 @@ public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technol
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void add(TechnologyDto technologyDto) {
|
|
|
String join = String.join(",", technologyDto.getProcessRouteList());
|
|
@@ -151,9 +155,15 @@ public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technol
|
|
|
applicableProducts.setTechnologyId(technologyDto.getId());
|
|
|
}
|
|
|
applicableProductsService.saveBatch(productList);
|
|
|
+
|
|
|
+ //保存工艺线路列表
|
|
|
+ List<TechnologyProcessLine> technologyProcessLines = analysisJsonData(technologyDto);
|
|
|
+ if (ObjectUtil.isNotEmpty(technologyProcessLines)) {
|
|
|
+ technologyProcessLineService.saveBatch(technologyProcessLines);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void edit(TechnologyDto technologyDto) {
|
|
|
String join = String.join(",", technologyDto.getProcessRouteList());
|
|
@@ -165,13 +175,76 @@ public class TechnologyServiceImpl extends ServiceImpl<TechnologyMapper, Technol
|
|
|
applicableProducts.setTechnologyId(technologyDto.getId());
|
|
|
}
|
|
|
applicableProductsService.saveBatch(productList);
|
|
|
+
|
|
|
+ //修改工艺线路列表,只能全删了再创建
|
|
|
+ technologyProcessLineService.remove(q -> q.eq(TechnologyProcessLine::getTechnologyId, technologyDto.getId()));
|
|
|
+ List<TechnologyProcessLine> technologyProcessLines = analysisJsonData(technologyDto);
|
|
|
+ if (ObjectUtil.isNotEmpty(technologyProcessLines)) {
|
|
|
+ technologyProcessLineService.saveBatch(technologyProcessLines);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
this.removeById(id);
|
|
|
applicableProductsService.remove(q -> q.eq(ApplicableProducts::getTechnologyId, id));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理流程图JSON
|
|
|
+ */
|
|
|
+ private List<TechnologyProcessLine> analysisJsonData(TechnologyDto technologyDto) {
|
|
|
+ //读取流程图json信息
|
|
|
+ JSONArray nodeObject = JSONArray.parseArray(technologyDto.getNodeObject());
|
|
|
+ //遍历信息
|
|
|
+ Map<String, JSONObject> nodeMap = new HashMap<>();
|
|
|
+ List<JSONObject> lineList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < nodeObject.size(); i++) {
|
|
|
+ JSONObject json = nodeObject.getJSONObject(i);
|
|
|
+ String shape = json.getString("shape");
|
|
|
+ //节点
|
|
|
+ if (shape.equals("handle-btn")) {
|
|
|
+ nodeMap.put(json.getString("id"), json);
|
|
|
+ }
|
|
|
+ //线
|
|
|
+ if (shape.equals("edge")) {
|
|
|
+ lineList.add(json);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TechnologyProcessLine> technologyProcessLineList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (JSONObject jsonObject : lineList) {
|
|
|
+ JSONObject source = jsonObject.getJSONObject("source");
|
|
|
+ String sourceCell = source.getString("cell");
|
|
|
+ JSONObject target = jsonObject.getJSONObject("target");
|
|
|
+ String targetCell = target.getString("cell");
|
|
|
+
|
|
|
+ TechnologyProcessLine technologyProcessLine = new TechnologyProcessLine();
|
|
|
+ //读取源节点信息
|
|
|
+ if (sourceCell.equals("1") || sourceCell.equals("2")) {
|
|
|
+ technologyProcessLine.setSourceProcessesId(Long.parseLong(sourceCell));
|
|
|
+ } else {
|
|
|
+ JSONObject from = nodeMap.get(sourceCell);
|
|
|
+ Assert.notEmpty(from, "查询不到节点信息:" + sourceCell);
|
|
|
+ technologyProcessLine.setSourceProcessesId(from.getLong("productionId"));
|
|
|
+ }
|
|
|
+ //读取目标节点信息
|
|
|
+ if (targetCell.equals("1") || targetCell.equals("2")) {
|
|
|
+ technologyProcessLine.setTargetProcessesId(Long.parseLong(targetCell));
|
|
|
+ } else {
|
|
|
+ JSONObject to = nodeMap.get(targetCell);
|
|
|
+ Assert.notEmpty(to, "查询不到节点信息:" + targetCell);
|
|
|
+ technologyProcessLine.setTargetProcessesId(to.getLong("productionId"));
|
|
|
+ }
|
|
|
+
|
|
|
+ technologyProcessLine.setTechnologyId(technologyDto.getId());
|
|
|
+
|
|
|
+ technologyProcessLineList.add(technologyProcessLine);
|
|
|
+ }
|
|
|
+
|
|
|
+ return technologyProcessLineList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|