cl
2024-01-16 cf6bff3922bbd0624b98834f6ea85c8e619e564f
提交 | 用户 | 时间
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{
cf6bff 81             String isHeartBeat = OPCUnit.read(opc.getEOP030_F_HEART_BEAT());
C 82             setHeartbeat(isHeartBeat);
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")){
cf6bff 100                         handleMaterial();
71e81e 101                         handleInfo();
102                         handleFinsh();
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() {
C 185         if("".equals(S_ORDER_CODE)){
186             IN_TIME = DateTool.getLocalTimeForDate();
187             S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
188             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
189             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
190             S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
191         }
192         //查询批次上料信息
193         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
194         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
195         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
196         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
197         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
198         for(int i=0;i<list1.size();i++){
199             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
200
201             //判断是否有该工位
202             String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/");
203             logger.info("当前工位:"+locationCodes.toString());
204             boolean isLocationCode = false;
205             if(locationCodes.length>0)
206             {
207                 for (int j=0;j<locationCodes.length;j++){
208                     String location = locationCodes[j];
209                     if(location.equals(LOCATION_CODE)){
210                         isLocationCode = true;
211                     }
212                 }
213             }
214
215             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
216             if(remainingQuantity>0 && isLocationCode){
217                 //新增物料追溯
218                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
219                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
220                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
221                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
222                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
223                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
224                 materialTraceabilityParam.setAssemblyQty(1);
225                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
226                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
227                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
228
229                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
230                 materialTraceabilityService.add(materialTraceabilityParam);
231                 //更新剩余数量
232                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
233                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
234                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
235             }
236         }
237     }
238
71e81e 239     //PC完成
240     public void handleFinsh() {
241         if("".equals(S_ORDER_CODE)){
242             IN_TIME = DateTool.getLocalTimeForDate();
243             S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
244             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
245             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
246             S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
247         }
248         //处理过站信息
249         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP030_S_PRODUCT_STATE_CODE());
250         PassingStationCollectionParam param = new PassingStationCollectionParam();
251         param.setWorkOrderNo(S_ORDER_CODE);
252         param.setProductCode(S_PRODUCT_CODE);
253         param.setSfcCode(S_SFC_CODE);
254         param.setProductionLine(PRODUCTION_LINE);
255         param.setLocationCode(LOCATION_CODE);
256         param.setInboundTime(IN_TIME);
257         param.setOutboundTime(DateTool.getLocalTimeForDate());
258         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
259         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
260         passingStationCollectionService.add(param);
261
262         OPCUnit.write(opc.getEOP030_J_PC_FINISH(), "true"); //PC完成
263
264         logger.info("EOP030工位,handleFinsh PC处理完成!");
265     }
266
267 }