admin
2024-01-10 7f291910791bdb9a545dc12ef36c3c359cfa4e59
提交 | 用户 | 时间
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;
c64c9f 11 import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam;
C 12 import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
13 import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
71e81e 14 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
15 import cn.stylefeng.guns.plcserver.opc.OPCComm;
16 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
17
18 import cn.stylefeng.guns.plcserver.server.EOP030.EOP030ServerInterface;
19 import cn.stylefeng.guns.plcserver.tool.DateTool;
20 import cn.stylefeng.guns.plcserver.tool.LogUtil;
21 import org.apache.log4j.Logger;
22 import org.openscada.opc.lib.da.Group;
23 import org.openscada.opc.lib.da.Item;
24
c64c9f 25 import java.time.LocalDate;
C 26 import java.time.temporal.ChronoUnit;
71e81e 27 import java.util.Date;
28 import java.util.List;
29
30
31 public class EOP030ServerInterfaceImpl implements EOP030ServerInterface {
32
33     private static Logger logger;
34     LogUtil logUtil = new LogUtil();
35     static {
36         logger = Logger.getLogger(EOP030ServerInterfaceImpl.class);
37     }
38
39     private OPCComm opc = OPCComm.getInstance();
40     private static Date IN_TIME = null;
41     private static String S_ORDER_CODE = "";//工单编号
42     private static String S_PRODUCT_CODE = "";//产品编号
43     private static String S_PRODUCT_TYPE= "";//产品类型
44     private static String S_PRODUCT_CODE_OLD = "";//产品编号
45     private static String S_SFC_CODE = "";//总成编码
46     private static String S_RIGHT_CODE  = "";//右壳体编码
47     private static String PRODUCTION_LINE  = "EOP";//产线号
48     private static String LOCATION_CODE  = "EOP030";//工位号
49     private static String GROUP_NAME  = "EOP030_P";//组名
50     private static List list = null;
51     private static Group group = null;
52     @Override
53     public synchronized void monitor() {
54         String ecpStr = "";//异常记录标记
55         try{
56             if(GlobalVariable.EOP030_F_HEART_BEAT) {
57                 //PC读工单
58                 String isPLCStart = OPCUnit.read(opc.getEOP030_J_PLC_START());//PLC开始
59                 if(isPLCStart.equals("true")){
60                     String isFinish = OPCUnit.read(opc.getEOP030_J_PC_WRITE_ORDER());//PC下发工单完成
61                     if(isFinish.equals("false")){
62                         handleOrder();
63                     }
64                 }
65
66
67                 //PC完成
68                 String isPLCFinish = OPCUnit.read(opc.getEOP030_J_PLC_FINISH());//PLC完成
69                 if(isPLCFinish.equals("true")){
70                     String isFinish = OPCUnit.read(opc.getEOP030_J_PC_FINISH());//PC操作完成
71                     if(isFinish.equals("false")){
72                         handleInfo();
73                         handleFinsh();
74                     }
75                 }
76
77             }else{
78                 logger.info("EOP030工位与PLC断开,请检查PLC或网络是否异常!");
79             }
80
81         }catch (Exception e) {
82             ecpStr ="出现异常:" + logUtil.getTrace(e);
83         }finally {
84             if(!"".equals(ecpStr)){
85                 logger.info(ecpStr+"\r\n");
86             }
87         }
88     }
89
c64c9f 90
71e81e 91     //PC读工单
92     public void handleOrder() {
93         IN_TIME = DateTool.getLocalTimeForDate();
94         S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
95         S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
96         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
97         S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
98         OPCUnit.write(opc.getEOP030_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
99         logger.info("EOP030工位,handleOrder PC处理完成!");
100     }
101
102     //PC读参数信息
103     public void handleInfo() throws Exception {
104         logger.info("EOP030工位,handleInfo START!");
105
106         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
107             if(group != null){
108                 opc.getServer().removeGroup(group,true);
109             }
110             group = opc.getServer().addGroup(GROUP_NAME);
111
112             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
113             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
114             collectionParamConfParam.setLocationCode(LOCATION_CODE);
115             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
116             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
117
118
119             for(int i=0;i<list.size();i++){
120                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
121                 Item item = group.addItem(result.getGatherAddress());
122                 result.setItem(item);
123                 list.set(i,result);
124             }
125             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
126         }
127
128         if(null != list && list.size()>0) {
129             ParamCollectionService paramCollectionService = opc.paramCollectionService;
130             for (int i = 0; i < list.size(); i++) {
131                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
132                 Item item = result.getItem();
133                 String value = OPCUnit.read(item);//读参数值
134                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
135                 paramCollectionParam.setParamCode(result.getParamCode());
136                 paramCollectionParam.setParamName(result.getParamName());
137                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
138                 paramCollectionParam.setSfcCode(S_SFC_CODE);
139                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
140                 paramCollectionParam.setProductionLine(result.getProductionLine());
141                 paramCollectionParam.setLocationCode(result.getLocationCode());
142                 paramCollectionParam.setParamValue(value);
143                 paramCollectionParam.setParamLower(result.getParamLower());
144                 paramCollectionParam.setParamUpper(result.getParamUpper());
145                 paramCollectionParam.setParamStandard(result.getParamCentral());
146                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
147                 paramCollectionParam.setUnit(result.getUnit());
148                 paramCollectionService.add(paramCollectionParam);
149             }
150         }
151
152         logger.info("EOP030工位,handleInfo END!");
153     }
154
155     //PC完成
156     public void handleFinsh() {
157         if("".equals(S_ORDER_CODE)){
158             IN_TIME = DateTool.getLocalTimeForDate();
159             S_ORDER_CODE = OPCUnit.read(opc.getEOP030_S_ORDER_CODE());//工单编号
160             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP030_S_PRODUCT_CODE());//产品编号
161             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
162             S_SFC_CODE = OPCUnit.read(opc.getEOP030_S_SFC_CODE());//总成编码
163         }
164         //处理过站信息
165         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP030_S_PRODUCT_STATE_CODE());
166         PassingStationCollectionParam param = new PassingStationCollectionParam();
167         param.setWorkOrderNo(S_ORDER_CODE);
168         param.setProductCode(S_PRODUCT_CODE);
169         param.setSfcCode(S_SFC_CODE);
170         param.setProductionLine(PRODUCTION_LINE);
171         param.setLocationCode(LOCATION_CODE);
172         param.setInboundTime(IN_TIME);
173         param.setOutboundTime(DateTool.getLocalTimeForDate());
174         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
175         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
176         passingStationCollectionService.add(param);
177
178         OPCUnit.write(opc.getEOP030_J_PC_FINISH(), "true"); //PC完成
179
180         logger.info("EOP030工位,handleFinsh PC处理完成!");
181     }
182
183 }