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