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