cl
2024-05-23 ba1a7a9ef126296e2798e313dc5b43f775a1123c
提交 | 用户 | 时间
d43481 1 package cn.stylefeng.guns.plcserver.callback;
C 2
3
4 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
5 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
6 import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
7 import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService;
8 import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
9 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
10 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
11 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
12 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
13 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
14 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
15 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
16 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
17 import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
18 import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
19 import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
20 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
21 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
22 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
23 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
24 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
25 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
26 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
27 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
28 import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
29 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
30 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
31 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
32 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
33 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
34 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
35 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
36 import cn.stylefeng.guns.plcserver.opc.OPCElement;
37 import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool;
38 import cn.stylefeng.guns.plcserver.tool.DateTool;
39 import cn.stylefeng.guns.plcserver.tool.LogUtil;
40 import com.kangaroohy.milo.model.ReadWriteEntity;
41 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
42 import com.kangaroohy.milo.service.MiloService;
43 import org.apache.commons.lang3.StringUtils;
44 import org.apache.log4j.Logger;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.stereotype.Component;
47
48 import java.util.*;
49
50 @Component
73bc06 51 public class COP010Callback  {
d43481 52
C 53     public MiloService miloService;
54
55     @Autowired
56     public ProductionOrdeInfoService productionOrdeInfoService;
57     @Autowired
58     public PassingStationCollectionService passingStationCollectionService;
59     @Autowired
60     public ParamCollectionService paramCollectionService;
61     @Autowired
62     public CollectionParamConfService collectionParamConfService;
63     @Autowired
64     public SerialNumbersConfService serialNumbersConfService;
65     @Autowired
66     private EquipmentStatusService equipmentStatusService;
67
68     @Autowired
69     private EquipmentAlarmService equipmentAlarmService;
70     @Autowired
71     private MaterialTraceabilityService materialTraceabilityService;
72     @Autowired
73     private EquipmentInfoService equipmentInfoService;
74     @Autowired
75     private RepairManageInfoService repairManageInfoService;
76
77     @Autowired
78     private LocationInfoService locationInfoService;
79
80     @Autowired
81     private GreaseManageService greaseManageService;
82
83     @Autowired
84     private ProductionOrderRecordsService productionOrderRecordsService;
85
86     @Autowired
87     private ProductionOrderBatchInfoService productionOrderBatchInfoService;
88
89     private static Logger logger;
90     LogUtil logUtil = new LogUtil();
91     static {
92         logger = Logger.getLogger(COP010Callback.class);
93     }
94     private static Date IN_TIME = null;
95     private static String S_ORDER_CODE = "";//工单编号
96     private static String S_PRODUCT_CODE = "";//产品编号
97     private static String S_PRODUCT_TYPE= "";//产品类型
98     private static String S_SFC_CODE = "";//总成编码
99     private static String PRODUCTION_LINE  = "COP";//产线号
100     private static String LOCATION_CODE  = "COP010";//工位号
101     private static List list = null;
102
103     public COP010Callback(MiloService miloService,
104                           ProductionOrdeInfoService productionOrdeInfoService,
105                           PassingStationCollectionService passingStationCollectionService,
106                           ParamCollectionService paramCollectionService,
107                           CollectionParamConfService collectionParamConfService,
108                           SerialNumbersConfService serialNumbersConfService,
109                           EquipmentStatusService equipmentStatusService,
110                           EquipmentAlarmService equipmentAlarmService,
111                           MaterialTraceabilityService materialTraceabilityService,
112                           EquipmentInfoService equipmentInfoService,
113                           RepairManageInfoService repairManageInfoService,
114                           LocationInfoService locationInfoService,
115                           GreaseManageService greaseManageService,
116                           ProductionOrderRecordsService productionOrderRecordsService,
117                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
118         this.miloService = miloService;
119         this.productionOrdeInfoService = productionOrdeInfoService;
120         this.passingStationCollectionService = passingStationCollectionService;
121         this.paramCollectionService = paramCollectionService;
122         this.collectionParamConfService = collectionParamConfService;
123         this.serialNumbersConfService = serialNumbersConfService;
124         this.equipmentStatusService = equipmentStatusService;
125         this.equipmentAlarmService = equipmentAlarmService;
126         this.materialTraceabilityService = materialTraceabilityService;
127         this.equipmentInfoService = equipmentInfoService;
128         this.repairManageInfoService = repairManageInfoService;
129         this.locationInfoService = locationInfoService;
130         this.greaseManageService = greaseManageService;
131         this.productionOrderRecordsService = productionOrderRecordsService;
132         this.productionOrderBatchInfoService = productionOrderBatchInfoService;
133     }
134
135     public void handleOrder() throws Exception{
136
137         IN_TIME = DateTool.getLocalTimeForDate();
138         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
139         param.setProductionLine("");//产线
140         param.setOrderStatus("3");//工单状态
141         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
142
143         if(list.size()>0) {
144             ProductionOrdeInfoResult result = list.get(0);
145
146             S_ORDER_CODE = result.getWorkOrderNo();
147             S_PRODUCT_CODE = result.getMaterialCode();
148             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
149
150             //自动生成唯一码
151             Random random = new Random(System.currentTimeMillis());
152             S_SFC_CODE = "COP"+random.nextLong();
153
154             List<ReadWriteEntity> lists = new ArrayList<>();
155             lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE));
314bc7 156             lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE)));
d43481 157             lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE));
314bc7 158             lists.add(new ReadWriteEntity(OPCElement.COP010_S_NUMBER,Short.parseShort(result.getPlanQty().toString())));
d43481 159             lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true));
C 160             miloService.writeToOpcUa(lists);
161
162             logger.info("COP010工位,handleOrder PC处理完成!2");
163         }else{
164             logger.info("COP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
165         }
166     }
167
168     public void handleFinsh() throws Exception {
169         logger.info("handleFinsh PC处理开始!");
170         String S_PRODUCT_STATE_CODE = miloService.
171                 readFromOpcUa(OPCElement.COP010_S_PRODUCT_STATE_CODE)
172                 .getValue().toString();
73bc06 173         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_J_PC_FINISH,true);
C 174         miloService.writeToOpcUa(entity);//写PC完成
d43481 175         //处理过站信息
C 176         PassingStationCollectionParam param = new PassingStationCollectionParam();
177         param.setWorkOrderNo(S_ORDER_CODE);
178         param.setProductCode(S_PRODUCT_CODE);
179         param.setSfcCode(S_SFC_CODE);
180         param.setProductionLine(PRODUCTION_LINE);
181         param.setLocationCode(LOCATION_CODE);
182         param.setInboundTime(IN_TIME);
183         param.setOutboundTime(DateTool.getLocalTimeForDate());
184         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
185         passingStationCollectionService.add(param);
186
73bc06 187
d43481 188         logger.info("handleFinsh PC处理完成!");
C 189     }
190
191     public void handleMaterial() {
ba1a7a 192         if(S_ORDER_CODE.isEmpty()){
C 193             return;
194         }
d43481 195         //查询批次上料信息
C 196         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
197         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
198         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
199         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
200         for(int i=0;i<list.size();i++){
201             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
202             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
203             if(remainingQuantity>0 ){
204                 //新增物料追溯
205                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
206                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
207                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
208                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
209                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
210                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
211                 materialTraceabilityParam.setAssemblyQty(1);
212                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
213                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
214                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
215
216                 materialTraceabilityService.add(materialTraceabilityParam);
217                 //更新剩余数量
218                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
219                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
220                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
221             }
222         }
223     }
224
225
226     public void handleRepair() throws Exception{
227         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
228         repairManageInfoParam.setLocationCode(LOCATION_CODE);
229         repairManageInfoParam.setManageType("2");
230         repairManageInfoParam.setUpPlc("0");
231         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
232         if(list.size()>0) {
233             RepairManageInfoResult result = list.get(0);
234
235             //自动生成唯一码
236             Random random = new Random(System.currentTimeMillis());
237             S_SFC_CODE = "COP" + random.nextLong();
238
239
240             S_ORDER_CODE = result.getWorkOrderNo();
241             S_PRODUCT_CODE = result.getProductCode();
242             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
243             String  repairLocation = result.getPoorLocationCode();//
244
245             //根据工位编码查询工位表中配置的返修工位号
246             LocationInfoParam param = new LocationInfoParam();
247             param.setLocationCode(repairLocation);
248             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
249             if(results.size()>0) {
250                 LocationInfoResult r = results.get(0);
251                 String repairLocationNo = r.getSpareField2();
252                 if(null != repairLocationNo && "" != repairLocationNo){
253                     List<ReadWriteEntity> lists = new ArrayList<>();
254                     lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE));
314bc7 255                     lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE)));
d43481 256                     lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE));
C 257                     lists.add(new ReadWriteEntity(OPCElement.COP010_P_REPAIR_LOCATION,repairLocationNo));
258                     lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true));
259                     miloService.writeToOpcUa(lists);
260                     //更新为已经返修上线
261                     Long id = result.getId();
262                     repairManageInfoParam.setId(id);
263                     repairManageInfoParam.setUpPlc("1");
264                     repairManageInfoService.update(repairManageInfoParam);
265
266                 }else{
267                     logger.info("COP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
268                 }
269             }else{
270                 logger.info("COP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
271             }
272         }
273     }
274 }