cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.EOP030.impl;
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.cm.paramCollection.model.params.ParamCollectionParam;
8 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
10 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
cf6bff 11 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
C 12 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
c64c9f 13 import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam;
C 14 import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
15 import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
cf6bff 16 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
C 17 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
18 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
71e81e 19 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
20 import cn.stylefeng.guns.plcserver.opc.OPCComm;
21 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
22
23 import cn.stylefeng.guns.plcserver.server.EOP030.EOP030ServerInterface;
24 import cn.stylefeng.guns.plcserver.tool.DateTool;
25 import cn.stylefeng.guns.plcserver.tool.LogUtil;
26 import org.apache.log4j.Logger;
27 import org.openscada.opc.lib.da.Group;
28 import org.openscada.opc.lib.da.Item;
29
c64c9f 30 import java.time.LocalDate;
C 31 import java.time.temporal.ChronoUnit;
71e81e 32 import java.util.Date;
33 import java.util.List;
34
35
36 public class EOP030ServerInterfaceImpl implements EOP030ServerInterface {
37
38     private static Logger logger;
39     LogUtil logUtil = new LogUtil();
40     static {
41         logger = Logger.getLogger(EOP030ServerInterfaceImpl.class);
42     }
43
44     private OPCComm opc = OPCComm.getInstance();
45     private static Date IN_TIME = null;
46     private static String S_ORDER_CODE = "";//工单编号
47     private static String S_PRODUCT_CODE = "";//产品编号
48     private static String S_PRODUCT_TYPE= "";//产品类型
49     private static String S_PRODUCT_CODE_OLD = "";//产品编号
50     private static String S_SFC_CODE = "";//总成编码
51     private static String S_RIGHT_CODE  = "";//右壳体编码
52     private static String PRODUCTION_LINE  = "EOP";//产线号
53     private static String LOCATION_CODE  = "EOP030";//工位号
54     private static String GROUP_NAME  = "EOP030_P";//组名
55     private static List list = null;
56     private static Group group = null;
cf6bff 57
C 58     private int count = 0;
59
60     /**
61      * 设置心跳标志位,保存到全局变量
62      */
63     public void setHeartbeat(String value) {
64         if ("false".equals(value)) {
65             OPCUnit.write(opc.getEOP030_F_HEART_BEAT(), "true");
66             GlobalVariable.EOP030_F_HEART_BEAT = true;
67             count = 0;
68         } else {
69             count++;
70         }
71         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
72         if (count > GlobalVariable.HEART_MAX_COUNT) {
73             GlobalVariable.EOP030_F_HEART_BEAT = false;
74         }
75     }
76
71e81e 77     @Override
78     public synchronized void monitor() {
79         String ecpStr = "";//异常记录标记
80         try{
e0fac3 81          /*   String isHeartBeat = OPCUnit.read(opc.getEOP030_F_HEART_BEAT());
C 82             setHeartbeat(isHeartBeat);*/
cf6bff 83
71e81e 84             if(GlobalVariable.EOP030_F_HEART_BEAT) {
85                 //PC读工单
86                 String isPLCStart = OPCUnit.read(opc.getEOP030_J_PLC_START());//PLC开始
87                 if(isPLCStart.equals("true")){
88                     String isFinish = OPCUnit.read(opc.getEOP030_J_PC_WRITE_ORDER());//PC下发工单完成
89                     if(isFinish.equals("false")){
90                         handleOrder();
91                     }
92                 }
93
94
95                 //PC完成
96                 String isPLCFinish = OPCUnit.read(opc.getEOP030_J_PLC_FINISH());//PLC完成
97                 if(isPLCFinish.equals("true")){
98                     String isFinish = OPCUnit.read(opc.getEOP030_J_PC_FINISH());//PC操作完成
99                     if(isFinish.equals("false")){
100                         handleFinsh();
e0fac3 101                         handleInfo();
C 102                         handleMaterial();
71e81e 103                     }
104                 }
105
106             }else{
107                 logger.info("EOP030工位与PLC断开,请检查PLC或网络是否异常!");
108             }
109
110         }catch (Exception e) {
111             ecpStr ="出现异常:" + logUtil.getTrace(e);
112         }finally {
113             if(!"".equals(ecpStr)){
114                 logger.info(ecpStr+"\r\n");
115             }
116         }
117     }
118
c64c9f 119
71e81e 120     //PC读工单
121     public void handleOrder() {
122         IN_TIME = DateTool.getLocalTimeForDate();
123         S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
124         S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
125         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
126         S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
127         OPCUnit.write(opc.getEOP030_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
128         logger.info("EOP030工位,handleOrder PC处理完成!");
129     }
130
131     //PC读参数信息
132     public void handleInfo() throws Exception {
133         logger.info("EOP030工位,handleInfo START!");
134
135         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
136             if(group != null){
137                 opc.getServer().removeGroup(group,true);
138             }
139             group = opc.getServer().addGroup(GROUP_NAME);
140
141             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
142             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
143             collectionParamConfParam.setLocationCode(LOCATION_CODE);
144             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
145             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
146
147
148             for(int i=0;i<list.size();i++){
149                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
150                 Item item = group.addItem(result.getGatherAddress());
151                 result.setItem(item);
152                 list.set(i,result);
153             }
154             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
155         }
156
157         if(null != list && list.size()>0) {
158             ParamCollectionService paramCollectionService = opc.paramCollectionService;
159             for (int i = 0; i < list.size(); i++) {
160                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
161                 Item item = result.getItem();
162                 String value = OPCUnit.read(item);//读参数值
163                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
164                 paramCollectionParam.setParamCode(result.getParamCode());
165                 paramCollectionParam.setParamName(result.getParamName());
166                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
167                 paramCollectionParam.setSfcCode(S_SFC_CODE);
168                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
169                 paramCollectionParam.setProductionLine(result.getProductionLine());
170                 paramCollectionParam.setLocationCode(result.getLocationCode());
171                 paramCollectionParam.setParamValue(value);
172                 paramCollectionParam.setParamLower(result.getParamLower());
173                 paramCollectionParam.setParamUpper(result.getParamUpper());
174                 paramCollectionParam.setParamStandard(result.getParamCentral());
175                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
176                 paramCollectionParam.setUnit(result.getUnit());
177                 paramCollectionService.add(paramCollectionParam);
178             }
179         }
180
181         logger.info("EOP030工位,handleInfo END!");
182     }
183
cf6bff 184     public void handleMaterial() {
e0fac3 185
cf6bff 186         //查询批次上料信息
C 187         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
188         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
189         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
190         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
191         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
192         for(int i=0;i<list1.size();i++){
193             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
194
195             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 196             if(remainingQuantity>0 ){
cf6bff 197                 //新增物料追溯
C 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 materialTraceabilityService = opc.materialTraceabilityService;
210                 materialTraceabilityService.add(materialTraceabilityParam);
211                 //更新剩余数量
212                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
213                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
214                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
215             }
216         }
217     }
218
71e81e 219     //PC完成
220     public void handleFinsh() {
221         if("".equals(S_ORDER_CODE)){
222             IN_TIME = DateTool.getLocalTimeForDate();
223             S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
224             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
225             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
226             S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
227         }
228         //处理过站信息
229         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP030_S_PRODUCT_STATE_CODE());
230         PassingStationCollectionParam param = new PassingStationCollectionParam();
231         param.setWorkOrderNo(S_ORDER_CODE);
232         param.setProductCode(S_PRODUCT_CODE);
233         param.setSfcCode(S_SFC_CODE);
234         param.setProductionLine(PRODUCTION_LINE);
235         param.setLocationCode(LOCATION_CODE);
236         param.setInboundTime(IN_TIME);
237         param.setOutboundTime(DateTool.getLocalTimeForDate());
238         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
239         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
240         passingStationCollectionService.add(param);
241
242         OPCUnit.write(opc.getEOP030_J_PC_FINISH(), "true"); //PC完成
243
244         logger.info("EOP030工位,handleFinsh PC处理完成!");
245     }
246
247 }