瀏覽代碼

fix:eop刀具申请

wang.sq@aliyun.com 2 月之前
父節點
當前提交
d14bf6c907

+ 62 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/centralToolMagazine/service/impl/ToolManagementServiceImpl.java

@@ -27,6 +27,7 @@ import com.github.zuihou.business.productionReadyCenter.dao.CuttingToolMapper;
 import com.github.zuihou.business.productionReadyCenter.entity.*;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureProductionresourceService;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureToolService;
+import com.github.zuihou.business.productionReadyCenter.service.CuttingToolService;
 import com.github.zuihou.business.productionReadyCenter.service.MachineCuttingToolService;
 import com.github.zuihou.business.productionResourceCenter.entity.Productionresource;
 import com.github.zuihou.business.productionResourceCenter.service.CutterCategoriesService;
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
 
 import static com.github.zuihou.common.constant.CacheKey.TENANT;
 import static com.github.zuihou.utils.BizAssert.isFalse;
+import static java.util.stream.Collectors.groupingBy;
 
 /**
  * <p>
@@ -105,6 +107,9 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
     @Autowired
     private ProductionresourceBizService productionresourceBizService;
 
+    @Autowired
+    private CuttingToolService cuttingToolService;
+
     //默认机床刀位数
     private final int DEVICE_CUTTER_POSITION = 40;
 
@@ -195,6 +200,7 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
 
         List<ToolCheckDTO> returnList=new ArrayList<>();
 
+
         planIds.stream().forEach(item ->{
             PlanProduct planProduct = planProductMapper.selectOne(Wraps.<PlanProduct>lbQ().eq(PlanProduct::getPlanId, item));
             Long bomId=planProduct.getBomId();
@@ -205,6 +211,7 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
                     .eq(BomVersionInfo::getBomId,bomId));
             if(Objects.isNull(bomVersionInfo)){
                 ToolCheckDTO toolCheckDTO=new ToolCheckDTO();
+                toolCheckDTO.setIsNoCutter(0);
                 toolCheckDTO.setName(bBom.getName());
                 toolCheckDTO.setHasCuttingToolsFlag("否");
                 toolCheckDTO.setIsTask("否");
@@ -247,6 +254,7 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
             if(needToolList.isEmpty()|| needToolList.size()<=0){
                 log.info("刀具校验:未配置工艺刀具");
                 ToolCheckDTO toolCheckDTO=new ToolCheckDTO();
+                toolCheckDTO.setIsNoCutter(0);
                 toolCheckDTO.setName(bBom.getName());
                 toolCheckDTO.setHasCuttingToolsFlag("否");
                 toolCheckDTO.setIsTask("否");
@@ -258,6 +266,58 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
             //List<Long> resourceId = resourceList.stream().map(BomProcedureProductionresource::getResourceId).collect(Collectors.toList());
 
             List<CutterCategories> finalNeedToolList = needToolList;
+
+
+
+            // 刀具不在产线,需要发送刀具需求
+            HashMap<String, CutterCategories> noCuttersHashMap = new HashMap();
+            resourceList.stream().forEach(vo->{
+                List<CutterCategories> needCutterCategories = new ArrayList<>();
+                // 需求的刀具数据
+                Map<String, List<CutterCategories>> collect = finalNeedToolList.stream().collect(groupingBy(CutterCategories::getCutterT));
+                //机床现有刀具集合
+                Productionresource productionresource = productionresourceBizService.getById(vo.getResourceId());
+                //判断是否机床
+                if(StringUtils.isEmpty(productionresource.getModeSpecification())){
+                    return;
+                }
+
+                List<String> realToolId = machineCuttingToolService.list(new LbqWrapper<MachineCuttingTool>().eq(MachineCuttingTool::getMachineId, vo.getResourceId())).stream().map(obj->obj.getCuttingToolId()).collect(Collectors.toList());
+                // 查询刀架有的刀
+                List<CuttingTool> cutterInStorgeInfo = cuttingToolService.getCutterInStorgeInfo();
+                if(cutterInStorgeInfo!=null && !cutterInStorgeInfo.isEmpty()){
+                    List<String> collect1 = cutterInStorgeInfo.stream().map(CuttingTool::getCuttingToolNo).map(Object::toString).collect(Collectors.toList());
+                    realToolId.addAll(collect1);
+                }
+                // 比对是否有缺失的数据
+                collect.forEach((s, cutterCategories) -> {
+                    if(!realToolId.contains(s)){
+                        needCutterCategories.add(cutterCategories.get(0));
+                    }
+                });
+
+                if(needCutterCategories.isEmpty()){
+                    return;
+                }
+                List<String> cutterTs = needCutterCategories.stream().map(CutterCategories::getCutterT).collect(Collectors.toList());
+
+                ToolCheckDTO toolCheckDTO =new ToolCheckDTO();
+                toolCheckDTO.setIsNoCutter(1);
+                toolCheckDTO.setIsTask(needCutterCategories.size()>0?"是":"否");
+                toolCheckDTO.setNumber(needCutterCategories.size());
+                toolCheckDTO.setId(vo.getResourceId());
+                toolCheckDTO.setDeviceName(vo.getName());
+                toolCheckDTO.setName(bBom.getName());
+                toolCheckDTO.setList(cutterTs);
+                toolCheckDTO.setHasCuttingToolsFlag(CollectionUtil.isEmpty(cutterTs) ? "是" : "否" );
+                toolCheckDTO.setMsg(CollectionUtil.isNotEmpty(cutterTs) ?
+                        "缺少:"+needCutterCategories.stream().map(obj->obj.getCutterName()).collect(Collectors.joining(",")):"校验成功" );
+                toolCheckDTO.setPlanId(item);
+                returnList.add(toolCheckDTO);
+            });
+
+
+            // 刀具在产线,但没有在机床
             resourceList.stream().forEach(vo->{
                 ToolCheckDTO toolCheckDTO=new ToolCheckDTO();
 
@@ -300,6 +360,8 @@ public class ToolManagementServiceImpl extends SuperCacheServiceImpl<ToolManagem
                     //true 机床刀库空闲个数大于缺刀个数
                     Boolean isFree=freeCount > lackTools.size();
                     //ToolTask findToolTask = toolTaskMapper.selectOne(Wraps.<ToolTask>lbQ().eq(ToolTask::getPlanId, item));
+
+                    toolCheckDTO.setIsNoCutter(0);
                     toolCheckDTO.setIsTask(lackTools.size()>0?"是":"否");
                     toolCheckDTO.setId(vo.getResourceId());
                     toolCheckDTO.setDeviceName(vo.getName());

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/dao/CuttingToolMapper.java

@@ -38,4 +38,6 @@ public interface CuttingToolMapper extends SuperMapper<CuttingTool> {
 
     List<CuttingTool> getGoodSByStorgeId(Long storgeId);
 
+    List<CuttingTool> getCutterInStorgeInfo();
+
 }

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/CuttingToolService.java

@@ -66,4 +66,6 @@ public interface CuttingToolService extends SuperCacheService<CuttingTool> {
     CuttingTool queryOneCuttingTool(Map<String, String > map);
 
     List<CuttingTool> getGoodSByStorgeId(Long storgeId);
+
+    List<CuttingTool> getCutterInStorgeInfo();
 }

+ 6 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/CuttingToolServiceImpl.java

@@ -167,4 +167,10 @@ public class CuttingToolServiceImpl extends SuperCacheServiceImpl<CuttingToolMap
 
         return this.baseMapper.getGoodSByStorgeId(storgeId);
     }
+
+    @Override
+    public List<CuttingTool> getCutterInStorgeInfo() {
+
+        return this.baseMapper.getCutterInStorgeInfo();
+    }
 }

+ 11 - 0
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/CuttingToolMapper.xml

@@ -105,5 +105,16 @@
             s.storge_id =#{storgeId}
     </select>
 
+    <select id="getCutterInStorgeInfo" resultType="com.github.zuihou.business.productionReadyCenter.entity.CuttingTool" parameterType="Long">
+        SELECT
+            mict.cutting_tool_no,
+            mict.cutting_tool_name,
+            mict.specifications,
+            siss.storge_id
+        FROM
+            `imcs_cutting_tool` mict
+            INNER JOIN imcs_s_stock_info siss ON mict.id = siss.goods_id
+    </select>
+
 
 </mapper>

+ 40 - 8
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/MesController.java

@@ -4,6 +4,7 @@ package com.github.zuihou.business.controller.externalApi;
 import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baidubce.services.tsdb.model.GroupBy;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -11,10 +12,12 @@ import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.controller.SuperController;
 import com.github.zuihou.base.request.PageParams;
+import com.github.zuihou.business.centralToolMagazine.dto.ToolCheckDTO;
 import com.github.zuihou.business.controller.operationManagementCenter.OrderController;
 import com.github.zuihou.business.controller.operationManagementCenter.PlanController;
 import com.github.zuihou.business.controller.operationManagementCenter.WorkpieceController;
 import com.github.zuihou.business.controller.productionReadyCenter.MMeterialController;
+import com.github.zuihou.business.cuttercategories.entity.CutterCategories;
 import com.github.zuihou.business.externalApi.dto.*;
 import com.github.zuihou.business.externalApi.entity.MesAttachment;
 import com.github.zuihou.business.externalApi.entity.MesNotice;
@@ -53,10 +56,7 @@ import org.springframework.web.bind.annotation.*;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
@@ -179,15 +179,47 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
 
     }
 
+    
+    @Autowired
+    private CuttingToolService cuttingToolService;
+    
     @ApiOperation(value = "刀具需求下发给EOP", notes = "刀具需求下发给EOP")
     @PostMapping("/externalApi/sendCutterNeedToEop")
-    public R sendCutterNeedToEop(@RequestBody String data) {
+    public R sendCutterNeedToEop(@RequestBody List<ToolCheckDTO> datas) {
         log.info("定时================发送刀具需求给Eop系统开始================");
-        CutterNeedDto cutterNeedDto = JSONObject.parseObject(data, CutterNeedDto.class);
-        MesNotice mesNotice = MesNotice.builder().orderNo(cutterNeedDto.getAUFNR()).buType("TASKDISTRIBUTE").lineCode("407109")
-                .status("1").apiType("CUTTERNEED").source("PRODUCTION_LINE").targetSource("EOP").acceptPar(JSONObject.toJSONString(data)).build();
+        BaseContextHandler.setTenant("0000");
+
+        List list = new ArrayList();
+        Map<Long, CuttingTool> collect = cuttingToolService.list().stream().collect(Collectors.toMap(t -> t.getCuttingToolNo(), t -> t));
+
+        for (ToolCheckDTO data : datas) {
+            for (String cutterT : data.getList()) {
+                if (!collect.containsKey(Long.parseLong(cutterT))){
+                    continue;
+                }
+
+                CuttingTool cuttingTool = collect.get(Long.parseLong(cutterT));
+                String factoryMaterialCode = cuttingTool.getFactoryMaterialCode();
+                String[] splitFactoryMaterialCode = factoryMaterialCode.split(";");
+
+                for (int i = 0; i < splitFactoryMaterialCode.length; i++) {
+                    JSONObject jsonObject =new JSONObject();
+                    jsonObject.put("MATNR", splitFactoryMaterialCode[i]);
+                    jsonObject.put("QTY", 1);
+
+                    list.add(jsonObject);
+                }
+            }
+        }
+
+        
+        MesNotice mesNotice = MesNotice.builder().orderNo(System.currentTimeMillis()+"").buType("TASKDISTRIBUTE").lineCode("407109")
+                .status("1").apiType("CUTTERNEED").source("PRODUCTION_LINE").targetSource("EOP").acceptPar(JSONObject.toJSONString(list)).build();
         try {
             boolean b = baseService.addNotice(mesNotice);
+            if(b){
+                
+            }
             // todo 发送远程地址,发送数据
         } catch (Exception e) {
             return R.fail(e.getMessage());

+ 3 - 0
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/centralToolMagazine/dto/ToolCheckDTO.java

@@ -23,6 +23,9 @@ public class ToolCheckDTO {
     //机床刀库空闲个数是否大于缺刀个数
     private Boolean isFree;
     private Long taskId;
+    private Integer number;
+    // 缺少刀具,需要发送需求申请,0不需要,1需要
+    private Integer isNoCutter;
 
     //换出来的刀库库位ID
     private List<ToolStorgePageDTO> storgeId;