admin
2024-01-10 7f291910791bdb9a545dc12ef36c3c359cfa4e59
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP170.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;
11 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
12 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
13 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
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.OP170.OP170ServerInterface;
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
25 import java.util.Date;
26 import java.util.List;
27
28
29 public class OP170ServerInterfaceImpl implements OP170ServerInterface {
30
31     private static Logger logger;
32     LogUtil logUtil = new LogUtil();
33     static {
34         logger = Logger.getLogger(OP170ServerInterfaceImpl.class);
35     }
36
37     private OPCComm opc = OPCComm.getInstance();
38     private static Date IN_TIME = null;
39     private static String S_ORDER_CODE = "";//工单编号
40     private static String S_PRODUCT_CODE = "";//产品编号
41     private static String S_PRODUCT_TYPE= "";//产品类型
42     private static String S_PRODUCT_CODE_OLD = "";//产品编号
43     private static String S_SFC_CODE = "";//总成编码
44     private static String S_RIGHT_CODE  = "";//右壳体编码
45     private static String PRODUCTION_LINE  = "OP";//产线号
46     private static String LOCATION_CODE  = "OP170";//工位号
47     private static String GROUP_NAME  = "OP170_P";//工位号
48     private static List list = null;
49     private static Group group = null;
50     @Override
51     public synchronized void monitor() {
52         String ecpStr = "";//异常记录标记
53         try{
54             if(GlobalVariable.OP170_F_HEART_BEAT) {
55
56                 //PC读工单
57                 String isPLCStart = OPCUnit.read(opc.getOP170_J_PLC_START());//PLC开始
58                 if(isPLCStart.equals("true")){
59                     String isFinish = OPCUnit.read(opc.getOP170_J_PC_WRITE_ORDER());//PC下发工单完成
60                     if(isFinish.equals("false")){
61                         handleOrder();
62                     }
63                 }
64
65
66                 //PC完成
67                 String isPLCFinish = OPCUnit.read(opc.getOP170_J_PLC_FINISH());//PLC完成
68                 if(isPLCFinish.equals("true")){
69                     String isFinish = OPCUnit.read(opc.getOP170_J_PC_FINISH());//PC操作完成
70                     if(isFinish.equals("false")){
71                         handleInfo();
72                         handleFinsh();
73                     }
74                 }
75
76             }else{
77                 logger.info("OP170工位与PLC断开,请检查PLC或网络是否异常!");
78             }
79
80         }catch (Exception e) {
81             ecpStr ="出现异常:" + logUtil.getTrace(e);
82         }finally {
83             if(!"".equals(ecpStr)){
84                 logger.info(ecpStr+"\r\n");
85             }
86         }
87     }
88
89     //PC读工单
90     public void handleOrder() {
91         IN_TIME = DateTool.getLocalTimeForDate();
92         S_ORDER_CODE = OPCUnit.read(opc.getOP170_S_ORDER_CODE());//工单编号
93         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP170_S_PRODUCT_CODE());//产品编号
94         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
95         S_SFC_CODE = OPCUnit.read(opc.getOP170_S_SFC_CODE());//总成编码
96         OPCUnit.write(opc.getOP170_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
97         logger.info("OP170工位,handleOrder PC处理完成!");
98     }
99
100     //PC读参数信息
101     public void handleInfo() throws Exception {
102         logger.info("OP170工位,handleInfo START!");
103
104         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
105             if(group != null){
106                 opc.getServer().removeGroup(group,true);
107             }
108             group = opc.getServer().addGroup(GROUP_NAME);
109
110             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
111             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
112             collectionParamConfParam.setLocationCode(LOCATION_CODE);
113             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
114             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
115
116
117             for(int i=0;i<list.size();i++){
118                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
119                 Item item = group.addItem(result.getGatherAddress());
120                 result.setItem(item);
121                 list.set(i,result);
122             }
123             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
124         }
125
126         if(null != list && list.size()>0) {
127             ParamCollectionService paramCollectionService = opc.paramCollectionService;
128             for (int i = 0; i < list.size(); i++) {
129                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
130                 Item item = result.getItem();
131                 String value = OPCUnit.read(item);//读参数值
132                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
133                 paramCollectionParam.setParamCode(result.getParamCode());
134                 paramCollectionParam.setParamName(result.getParamName());
135                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
136                 paramCollectionParam.setSfcCode(S_SFC_CODE);
137                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
138                 paramCollectionParam.setProductionLine(result.getProductionLine());
139                 paramCollectionParam.setLocationCode(result.getLocationCode());
140                 paramCollectionParam.setParamValue(value);
141                 paramCollectionParam.setParamLower(result.getParamLower());
142                 paramCollectionParam.setParamUpper(result.getParamUpper());
143                 paramCollectionParam.setParamStandard(result.getParamCentral());
144                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
145                 paramCollectionParam.setUnit(result.getUnit());
146                 paramCollectionService.add(paramCollectionParam);
147             }
148         }
149
150         logger.info("OP170工位,handleInfo END!");
151     }
152
153     //PC完成
154     public void handleFinsh() {
155         if("".equals(S_ORDER_CODE)){
156             IN_TIME = DateTool.getLocalTimeForDate();
157             S_ORDER_CODE = OPCUnit.read(opc.getOP170_S_ORDER_CODE());//工单编号
158             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP170_S_PRODUCT_CODE());//产品编号
159             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
160             S_SFC_CODE = OPCUnit.read(opc.getOP170_S_SFC_CODE());//总成编码
161         }
162         //处理过站信息
163         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP170_S_PRODUCT_STATE_CODE());
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 passingStationCollectionService = opc.passingStationCollectionService;
174         passingStationCollectionService.add(param);
175
176
177
178         //更新工单完成数量
179         ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
180         orderParam.setWorkOrderNo(S_ORDER_CODE);
1f3486 181         if(!"".equals(S_ORDER_CODE)&&null!=S_ORDER_CODE){
182             ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
183             List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(orderParam);
184             if(list.size()>0) {
185                 ProductionOrdeInfoResult result = list.get(0);
186                 orderParam.setId(result.getId());
187                 if (null == result.getActualQty() || "".equals(result.getActualQty())){
188                     result.setActualQty(0);
189                 }
190                 orderParam.setActualQty(result.getActualQty()+1);
191                 productionOrdeInfoService.update(orderParam);
731bd9 192             }
71e81e 193         }
194         OPCUnit.write(opc.getOP170_J_PC_FINISH(), "true"); //PC完成
195
196         logger.info("OP170工位,handleFinsh PC处理完成!");
197     }
198
199 }