long
2023-09-02 e379948bb83ebcc9ce0c467a7b970f74bc00e9a1
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP080.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.bs.locationInfo.model.params.LocationInfoParam;
8 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
9 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
10 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
11 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
12 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
13 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
14 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
15 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
16 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
17 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
18 import cn.stylefeng.guns.plcserver.opc.OPCComm;
19 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
20
21 import cn.stylefeng.guns.plcserver.server.OP080.OP080ServerInterface;
22 import cn.stylefeng.guns.plcserver.tool.DateTool;
23 import cn.stylefeng.guns.plcserver.tool.LogUtil;
24 import org.apache.log4j.Logger;
25 import org.openscada.opc.lib.da.Group;
26 import org.openscada.opc.lib.da.Item;
27
28 import java.util.Date;
29 import java.util.List;
30
31
32 public class OP080ServerInterfaceImpl implements OP080ServerInterface {
33
34     private static Logger logger;
35     LogUtil logUtil = new LogUtil();
36     static {
37         logger = Logger.getLogger(OP080ServerInterfaceImpl.class);
38     }
39
40     private OPCComm opc = OPCComm.getInstance();
41     private static Date IN_TIME = null;
42     private static String S_ORDER_CODE = "";//工单编号
43     private static String S_PRODUCT_CODE = "";//产品编号
44     private static String S_PRODUCT_TYPE= "";//产品类型
45     private static String S_PRODUCT_CODE_OLD = "";//产品编号
46     private static String S_SFC_CODE = "";//总成编码
47     private static String S_RIGHT_CODE  = "";//右壳体编码
48     private static String PRODUCTION_LINE  = "OP";//产线号
49     private static String LOCATION_CODE  = "OP080";//工位号
50     private static String GROUP_NAME  = "OP080_P";//组名
51     private static List list = null;
52     private static Group group = null;
53     @Override
54     public synchronized void monitor() {
55         String ecpStr = "";//异常记录标记
56         try{
57             if(GlobalVariable.OP080_F_HEART_BEAT) {
58                 //PC读工单
59                 String isPLCStart = OPCUnit.read(opc.getOP080_J_PLC_START());//PLC开始
60                 if(isPLCStart.equals("true")){
61                     String isFinish = OPCUnit.read(opc.getOP080_J_PC_WRITE_ORDER());//PC下发工单完成
62                     if(isFinish.equals("false")){
63
64                         String isRepair = OPCUnit.read(opc.getOP080_P_REPAIR());//是否返修
65                         if(isRepair.equals("true")){
66                             handleRepair();
67                         }else{
68                             handleOrder();
69                         }
70                     }
71                 }
72
73
74                 //PC完成
75                 String isPLCFinish = OPCUnit.read(opc.getOP080_J_PLC_FINISH());//PLC完成
76                 if(isPLCFinish.equals("true")){
77                     String isFinish = OPCUnit.read(opc.getOP080_J_PC_FINISH());//PC操作完成
78                     if(isFinish.equals("false")){
79                         handleInfo();
80                         handleFinsh();
81                     }
82                 }
83
84             }else{
85                 logger.info("OP080工位与PLC断开,请检查PLC或网络是否异常!");
86             }
87
88         }catch (Exception e) {
89             ecpStr ="出现异常:" + logUtil.getTrace(e);
90         }finally {
91             if(!"".equals(ecpStr)){
92                 logger.info(ecpStr+"\r\n");
93             }
94         }
95     }
96
97     public void handleRepair() {
98         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
99         repairManageInfoParam.setLocationCode(LOCATION_CODE);
100         repairManageInfoParam.setManageType("2");
101         repairManageInfoParam.setUpPlc("0");
102         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
103         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
104         if(list.size()>0) {
105             RepairManageInfoResult result = list.get(0);
106
107             S_SFC_CODE = result.getSfc();
108             S_ORDER_CODE = result.getWorkOrderNo();
109             S_PRODUCT_CODE = result.getProductCode();
110             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
111             String  repairLocation = result.getPoorLocationCode();//
112
113             //根据工位编码查询工位表中配置的返修工位号
114             LocationInfoParam param = new LocationInfoParam();
115             param.setLocationCode(repairLocation);
116             LocationInfoService locationInfoService = opc.locationInfoService;
117             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
118             if(results.size()>0) {
119                 LocationInfoResult r = results.get(0);
120                 String repairLocationNo = r.getSpareField2();
121                 if(null != repairLocationNo && "" != repairLocationNo){
122                     OPCUnit.write(opc.getOP080_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
123                     OPCUnit.write(opc.getOP080_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
124                     OPCUnit.write(opc.getOP080_S_SFC_CODE(), S_SFC_CODE); //总成编码
125                     OPCUnit.write(opc.getOP080_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
126                     OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
127
128                     //更新为已经返修上线
129                     Long id = result.getId();
130                     repairManageInfoParam.setId(id);
131                     repairManageInfoParam.setUpPlc("1");
132                     repairManageInfoService.update(repairManageInfoParam);
133
134                 }else{
135                     logger.info("OP080工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
136                 }
137             }else{
138                 logger.info("OP080工位,handleRepair 无法查询到"+repairLocation+"工位!");
139             }
140         }
141     }
142
143     //PC读工单
144     public void handleOrder() {
145         IN_TIME = DateTool.getLocalTimeForDate();
146         S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号
147         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号
148         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
149         S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码
150         OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
151         logger.info("OP080工位,handleOrder PC处理完成!");
152     }
153
154     //PC读参数信息
155     public void handleInfo() throws Exception {
156         logger.info("OP080工位,handleInfo START!");
157
158         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
159             if(group != null){
160                 opc.getServer().removeGroup(group,true);
161             }
162             group = opc.getServer().addGroup(GROUP_NAME);
163
164             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
165             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
166             collectionParamConfParam.setLocationCode(LOCATION_CODE);
167             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
168             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
169
170
171             for(int i=0;i<list.size();i++){
172                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
173                 Item item = group.addItem(result.getGatherAddress());
174                 result.setItem(item);
175                 list.set(i,result);
176             }
177             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
178         }
179
180         if(null != list && list.size()>0) {
181             ParamCollectionService paramCollectionService = opc.paramCollectionService;
182             for (int i = 0; i < list.size(); i++) {
183                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
184                 Item item = result.getItem();
185                 String value = OPCUnit.read(item);//读参数值
186                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
187                 paramCollectionParam.setParamCode(result.getParamCode());
188                 paramCollectionParam.setParamName(result.getParamName());
189                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
190                 paramCollectionParam.setSfcCode(S_SFC_CODE);
191                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
192                 paramCollectionParam.setProductionLine(result.getProductionLine());
193                 paramCollectionParam.setLocationCode(result.getLocationCode());
194                 paramCollectionParam.setParamValue(value);
195                 paramCollectionParam.setParamLower(result.getParamLower());
196                 paramCollectionParam.setParamUpper(result.getParamUpper());
197                 paramCollectionParam.setParamStandard(result.getParamCentral());
198                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
199                 paramCollectionParam.setUnit(result.getUnit());
200                 paramCollectionService.add(paramCollectionParam);
201             }
202         }
203
204         logger.info("OP080工位,handleInfo END!");
205     }
206
207     //PC完成
208     public void handleFinsh() {
209         if("".equals(S_ORDER_CODE)){
210             IN_TIME = DateTool.getLocalTimeForDate();
211             S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号
212             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号
213             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
214             S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码
215         }
216         //处理过站信息
217         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP080_S_PRODUCT_STATE_CODE());
218         PassingStationCollectionParam param = new PassingStationCollectionParam();
219         param.setWorkOrderNo(S_ORDER_CODE);
220         param.setProductCode(S_PRODUCT_CODE);
221         param.setSfcCode(S_SFC_CODE);
222         param.setProductionLine(PRODUCTION_LINE);
223         param.setLocationCode(LOCATION_CODE);
224         param.setInboundTime(IN_TIME);
225         param.setOutboundTime(DateTool.getLocalTimeForDate());
226         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
227         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
228         passingStationCollectionService.add(param);
229
230         OPCUnit.write(opc.getOP080_J_PC_FINISH(), "true"); //PC完成
231
232         logger.info("OP080工位,handleFinsh PC处理完成!");
233     }
234
235 }