cl
2024-02-23 73bc0656dc15cd9cc95c6f4f51949ef0437088ce
提交 | 用户 | 时间
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.service.LocationInfoService;
9 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
10 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
11 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
12 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
13 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
14 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
15 import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
16 import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
17 import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
18 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
19 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
20 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
21 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
22 import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
23 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
24 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
25 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
26 import cn.stylefeng.guns.plcserver.opc.OPCElement;
27 import cn.stylefeng.guns.plcserver.tool.DateTool;
28 import cn.stylefeng.guns.plcserver.tool.LogUtil;
29 import com.kangaroohy.milo.model.ReadWriteEntity;
30 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
31 import com.kangaroohy.milo.service.MiloService;
32 import org.apache.log4j.Logger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 import java.util.ArrayList;
37 import java.util.Date;
38 import java.util.List;
39
40 @Component
73bc06 41 public class EOP040Callback {
d43481 42
C 43     public MiloService miloService;
44
45     @Autowired
46     public ProductionOrdeInfoService productionOrdeInfoService;
47     @Autowired
48     public PassingStationCollectionService passingStationCollectionService;
49     @Autowired
50     public ParamCollectionService paramCollectionService;
51     @Autowired
52     public CollectionParamConfService collectionParamConfService;
53     @Autowired
54     public SerialNumbersConfService serialNumbersConfService;
55     @Autowired
56     private EquipmentStatusService equipmentStatusService;
57
58     @Autowired
59     private EquipmentAlarmService equipmentAlarmService;
60     @Autowired
61     private MaterialTraceabilityService materialTraceabilityService;
62     @Autowired
63     private EquipmentInfoService equipmentInfoService;
64     @Autowired
65     private RepairManageInfoService repairManageInfoService;
66
67     @Autowired
68     private LocationInfoService locationInfoService;
69
70     @Autowired
71     private GreaseManageService greaseManageService;
72
73     @Autowired
74     private ProductionOrderRecordsService productionOrderRecordsService;
75
76     @Autowired
77     private ProductionOrderBatchInfoService productionOrderBatchInfoService;
78
79     private static Logger logger;
80     LogUtil logUtil = new LogUtil();
81     static {
82         logger = Logger.getLogger(EOP040Callback.class);
83     }
84     private static Date IN_TIME = null;
85     private static String S_ORDER_CODE = "";//工单编号
86     private static String S_PRODUCT_CODE = "";//产品编号
87     private static String S_PRODUCT_TYPE= "";//产品类型
88     private static String S_SFC_CODE = "";//总成编码
89     private static String PRODUCTION_LINE  = "EOP";//产线号
90     private static String LOCATION_CODE  = "EOP040";//工位号
91     private static List list = null;
92
93     public EOP040Callback(MiloService miloService,
94                           ProductionOrdeInfoService productionOrdeInfoService,
95                           PassingStationCollectionService passingStationCollectionService,
96                           ParamCollectionService paramCollectionService,
97                           CollectionParamConfService collectionParamConfService,
98                           SerialNumbersConfService serialNumbersConfService,
99                           EquipmentStatusService equipmentStatusService,
100                           EquipmentAlarmService equipmentAlarmService,
101                           MaterialTraceabilityService materialTraceabilityService,
102                           EquipmentInfoService equipmentInfoService,
103                           RepairManageInfoService repairManageInfoService,
104                           LocationInfoService locationInfoService,
105                           GreaseManageService greaseManageService,
106                           ProductionOrderRecordsService productionOrderRecordsService,
107                           ProductionOrderBatchInfoService productionOrderBatchInfoService) {
108         this.miloService = miloService;
109         this.productionOrdeInfoService = productionOrdeInfoService;
110         this.passingStationCollectionService = passingStationCollectionService;
111         this.paramCollectionService = paramCollectionService;
112         this.collectionParamConfService = collectionParamConfService;
113         this.serialNumbersConfService = serialNumbersConfService;
114         this.equipmentStatusService = equipmentStatusService;
115         this.equipmentAlarmService = equipmentAlarmService;
116         this.materialTraceabilityService = materialTraceabilityService;
117         this.equipmentInfoService = equipmentInfoService;
118         this.repairManageInfoService = repairManageInfoService;
119         this.locationInfoService = locationInfoService;
120         this.greaseManageService = greaseManageService;
121         this.productionOrderRecordsService = productionOrderRecordsService;
122         this.productionOrderBatchInfoService = productionOrderBatchInfoService;
123     }
124
125     //PC读工单
126     public void handleOrder() throws Exception {
127         logger.info("handleOrder PC处理开始!");
128         IN_TIME = DateTool.getLocalTimeForDate();
129         List<String> lists = new ArrayList<>();
130         lists.add(OPCElement.EOP040_S_ORDER_CODE);
131         lists.add(OPCElement.EOP040_S_PRODUCT_CODE);
132         lists.add(OPCElement.EOP040_S_SFC_CODE);
133         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
134         returnLists.forEach(element->{
135             switch(element.getIdentifier()){
136                 case OPCElement.EOP040_S_ORDER_CODE:
137                     S_ORDER_CODE = element.getValue().toString();
138                     break;
139                 case OPCElement.EOP040_S_PRODUCT_CODE:
140                     S_PRODUCT_TYPE = element.getValue().toString();
141                     S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
142                     break;
143                 case OPCElement.EOP040_S_SFC_CODE:
144                     S_SFC_CODE = element.getValue().toString();
145                     break;
146                 default:
147                     break;
148             }
149         });
150         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_J_PC_WRITE_ORDER,true);
151         miloService.writeToOpcUa(entity);
152         logger.info("handleOrder PC处理完成!");
153     }
154
155     public void handleFinsh() throws Exception {
156         logger.info("handleFinsh PC处理开始!");
157         String S_PRODUCT_STATE_CODE = miloService.
158                 readFromOpcUa(OPCElement.EOP040_S_PRODUCT_STATE_CODE)
159                 .getValue().toString();
160
73bc06 161         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_J_PC_FINISH,true);
C 162         miloService.writeToOpcUa(entity);//写PC完成
d43481 163         //处理过站信息
C 164         PassingStationCollectionParam param = new PassingStationCollectionParam();
165         param.setWorkOrderNo(S_ORDER_CODE);
166         param.setProductCode(S_PRODUCT_CODE);
167         param.setSfcCode(S_SFC_CODE);
168         param.setProductionLine(PRODUCTION_LINE);
169         param.setLocationCode(LOCATION_CODE);
170         param.setInboundTime(IN_TIME);
171         param.setOutboundTime(DateTool.getLocalTimeForDate());
172         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
173         passingStationCollectionService.add(param);
174
175         logger.info("handleFinsh PC处理完成!");
176     }
177
178     public void handleMaterial() {
179
180         //查询批次上料信息
181         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
182         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
183         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
184         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
185         for(int i=0;i<list.size();i++){
186             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
187             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
188             if(remainingQuantity>0 ){
189                 //新增物料追溯
190                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
191                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
192                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
193                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
194                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
195                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
196                 materialTraceabilityParam.setAssemblyQty(1);
197                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
198                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
199                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
200
201                 materialTraceabilityService.add(materialTraceabilityParam);
202                 //更新剩余数量
203                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
204                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
205                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
206             }
207         }
208     }
209
210     //PC读参数信息
211     public void handleInfo() throws Exception {
212         logger.info("handleInfo START!");
213
214         if(null == list){
215             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
216             collectionParamConfParam.setLocationCode(LOCATION_CODE);
217             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
218         }
219         if(null != list && !list.isEmpty()) {
220             for (int i = 0; i < list.size(); i++) {
221                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
6dadf3 222                 Object value = miloService.
d43481 223                         readFromOpcUa(result.getGatherAddress())
6dadf3 224                         .getValue();//读参数值
C 225                 if(null != value) {
226                     ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
227                     paramCollectionParam.setParamCode(result.getParamCode());
228                     paramCollectionParam.setParamName(result.getParamName());
229                     paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
230                     paramCollectionParam.setSfcCode(S_SFC_CODE);
231                     paramCollectionParam.setProductCode(S_PRODUCT_CODE);
232                     paramCollectionParam.setProductionLine(result.getProductionLine());
233                     paramCollectionParam.setLocationCode(result.getLocationCode());
234                     paramCollectionParam.setParamValue(value.toString());
235                     paramCollectionParam.setParamLower(result.getParamLower());
236                     paramCollectionParam.setParamUpper(result.getParamUpper());
237                     paramCollectionParam.setParamStandard(result.getParamCentral());
238                     paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
239                     paramCollectionParam.setUnit(result.getUnit());
240                     paramCollectionService.add(paramCollectionParam);
241                 }
d43481 242             }
C 243         }
244
245         logger.info("handleInfo END!");
246     }
247
248 }