提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.OP050.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; |
cf6bff
|
10 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult; |
71e81e
|
11 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; |
cf6bff
|
12 |
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam; |
C |
13 |
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService; |
c64c9f
|
14 |
import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam; |
C |
15 |
import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult; |
|
16 |
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService; |
cf6bff
|
17 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam; |
C |
18 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult; |
|
19 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService; |
|
20 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam; |
|
21 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult; |
|
22 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService; |
71e81e
|
23 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
懒 |
24 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
25 |
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; |
|
26 |
|
|
27 |
import cn.stylefeng.guns.plcserver.server.OP050.OP050ServerInterface; |
|
28 |
import cn.stylefeng.guns.plcserver.tool.DateTool; |
|
29 |
import cn.stylefeng.guns.plcserver.tool.LogUtil; |
|
30 |
import org.apache.log4j.Logger; |
|
31 |
import org.openscada.opc.lib.da.Group; |
|
32 |
import org.openscada.opc.lib.da.Item; |
|
33 |
|
21fde8
|
34 |
import java.text.SimpleDateFormat; |
c64c9f
|
35 |
import java.time.LocalDate; |
21fde8
|
36 |
import java.time.format.DateTimeFormatter; |
c64c9f
|
37 |
import java.time.temporal.ChronoUnit; |
71e81e
|
38 |
import java.util.Date; |
懒 |
39 |
import java.util.List; |
|
40 |
|
|
41 |
|
|
42 |
public class OP050ServerInterfaceImpl implements OP050ServerInterface { |
|
43 |
|
|
44 |
private static Logger logger; |
|
45 |
LogUtil logUtil = new LogUtil(); |
|
46 |
static { |
|
47 |
logger = Logger.getLogger(OP050ServerInterfaceImpl.class); |
|
48 |
} |
|
49 |
|
|
50 |
private OPCComm opc = OPCComm.getInstance(); |
|
51 |
private static Date IN_TIME = null; |
|
52 |
private static String S_ORDER_CODE = "";//工单编号 |
|
53 |
private static String S_PRODUCT_CODE = "";//产品编号 |
|
54 |
private static String S_PRODUCT_TYPE= "";//产品类型 |
|
55 |
private static String S_PRODUCT_CODE_OLD = "";//产品编号 |
|
56 |
private static String S_SFC_CODE = "";//总成编码 |
|
57 |
private static String S_RIGHT_CODE = "";//右壳体编码 |
|
58 |
private static String PRODUCTION_LINE = "OP";//产线号 |
|
59 |
private static String LOCATION_CODE = "OP050";//工位号 |
|
60 |
private static String GROUP_NAME = "OP050_P";//组名 |
|
61 |
private static List list = null; |
|
62 |
private static Group group = null; |
cf6bff
|
63 |
|
C |
64 |
private int count = 0; |
|
65 |
|
|
66 |
/** |
|
67 |
* 设置心跳标志位,保存到全局变量 |
|
68 |
*/ |
|
69 |
public void setHeartbeat(String value) { |
|
70 |
if ("false".equals(value)) { |
|
71 |
OPCUnit.write(opc.getOP050_F_HEART_BEAT(), "true"); |
|
72 |
GlobalVariable.OP050_F_HEART_BEAT = true; |
|
73 |
count = 0; |
|
74 |
} else { |
|
75 |
count++; |
|
76 |
} |
|
77 |
// 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时 |
|
78 |
if (count > GlobalVariable.HEART_MAX_COUNT) { |
|
79 |
GlobalVariable.OP050_F_HEART_BEAT = false; |
|
80 |
} |
|
81 |
} |
|
82 |
|
71e81e
|
83 |
@Override |
懒 |
84 |
public synchronized void monitor() { |
|
85 |
String ecpStr = "";//异常记录标记 |
|
86 |
try{ |
cf6bff
|
87 |
|
e0fac3
|
88 |
/* String isHeartBeat = OPCUnit.read(opc.getOP050_F_HEART_BEAT()); |
C |
89 |
setHeartbeat(isHeartBeat);*/ |
cf6bff
|
90 |
|
71e81e
|
91 |
if(GlobalVariable.OP050_F_HEART_BEAT) { |
懒 |
92 |
//PC读工单 |
|
93 |
String isPLCStart = OPCUnit.read(opc.getOP050_J_PLC_START());//PLC开始 |
|
94 |
if(isPLCStart.equals("true")){ |
|
95 |
String isFinish = OPCUnit.read(opc.getOP050_J_PC_WRITE_ORDER());//PC下发工单完成 |
|
96 |
if(isFinish.equals("false")){ |
|
97 |
handleOrder(); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
//PC完成 |
|
103 |
String isPLCFinish = OPCUnit.read(opc.getOP050_J_PLC_FINISH());//PLC完成 |
|
104 |
if(isPLCFinish.equals("true")){ |
|
105 |
String isFinish = OPCUnit.read(opc.getOP050_J_PC_FINISH());//PC操作完成 |
|
106 |
if(isFinish.equals("false")){ |
e0fac3
|
107 |
logger.info("handleFinsh开始时间:"+new Date()); |
71e81e
|
108 |
handleFinsh(); |
e0fac3
|
109 |
logger.info("handleFinsh完成时间:"+new Date()); |
C |
110 |
logger.info("handleInfo开始时间:"+new Date()); |
|
111 |
handleInfo(); |
|
112 |
logger.info("handleInfo完成时间:"+new Date()); |
|
113 |
logger.info("handleMaterial开始时间:"+new Date()); |
|
114 |
handleMaterial(); |
|
115 |
logger.info("handleMaterial完成时间:"+new Date()); |
71e81e
|
116 |
} |
懒 |
117 |
} |
|
118 |
|
c64c9f
|
119 |
handleOilState(); |
C |
120 |
|
71e81e
|
121 |
}else{ |
懒 |
122 |
logger.info("OP050工位与PLC断开,请检查PLC或网络是否异常!"); |
|
123 |
} |
|
124 |
|
|
125 |
}catch (Exception e) { |
|
126 |
ecpStr ="出现异常:" + logUtil.getTrace(e); |
|
127 |
}finally { |
|
128 |
if(!"".equals(ecpStr)){ |
|
129 |
logger.info(ecpStr+"\r\n"); |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
|
c64c9f
|
134 |
|
C |
135 |
public void handleOilState(){ |
|
136 |
GreaseManageParam param = new GreaseManageParam(); |
|
137 |
GreaseManageService greaseManageService = opc.greaseManageService; |
|
138 |
param.setLocationCode(LOCATION_CODE); |
|
139 |
List<GreaseManageResult> list = greaseManageService.findListBySpec(param); |
|
140 |
if(list.size()>0) { |
|
141 |
String duaDate = list.get(0).getDuaDate(); |
|
142 |
|
21fde8
|
143 |
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); |
懒 |
144 |
String currentDate = format.format(new Date()); |
|
145 |
long daysBetween = getRemainder(currentDate,duaDate); |
c64c9f
|
146 |
if(daysBetween>0){ |
C |
147 |
OPCUnit.write(opc.getOP050_OIL_STATE(), "false"); //写油脂状态 |
|
148 |
}else{ |
|
149 |
OPCUnit.write(opc.getOP050_OIL_STATE(), "true"); //写油脂状态 |
|
150 |
} |
cf6bff
|
151 |
//logger.info("到期日期:"+duaDate+"当前日期:"+currentDate+"剩余天数::"+daysBetween); |
c64c9f
|
152 |
} |
C |
153 |
} |
|
154 |
|
21fde8
|
155 |
public static long getRemainder(String currentDate,String tableDate){ |
懒 |
156 |
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); |
|
157 |
LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter); |
|
158 |
LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter); |
|
159 |
long days = ChronoUnit.DAYS.between(localDate1, localDate2); |
|
160 |
return days; |
|
161 |
} |
71e81e
|
162 |
//PC读工单 |
懒 |
163 |
public void handleOrder() { |
|
164 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
165 |
S_ORDER_CODE = OPCUnit.read(opc.getOP050_S_ORDER_CODE());//工单编号 |
|
166 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP050_S_PRODUCT_CODE());//产品编号 |
|
167 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
168 |
S_SFC_CODE = OPCUnit.read(opc.getOP050_S_SFC_CODE());//总成编码 |
|
169 |
OPCUnit.write(opc.getOP050_J_PC_WRITE_ORDER(), "true"); //PC读工单完成 |
|
170 |
logger.info("OP050工位,handleOrder PC处理完成!"); |
cf6bff
|
171 |
} |
C |
172 |
|
|
173 |
public void handleMaterial() { |
e0fac3
|
174 |
|
cf6bff
|
175 |
//查询批次上料信息 |
C |
176 |
ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); |
|
177 |
productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); |
|
178 |
productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); |
|
179 |
ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService; |
|
180 |
List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); |
|
181 |
for(int i=0;i<list1.size();i++){ |
|
182 |
ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i); |
|
183 |
|
|
184 |
int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//剩余数量 |
e0fac3
|
185 |
if(remainingQuantity>0){ |
cf6bff
|
186 |
//新增物料追溯 |
C |
187 |
MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam(); |
|
188 |
materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE); |
|
189 |
materialTraceabilityParam.setProductCode(S_PRODUCT_CODE); |
|
190 |
materialTraceabilityParam.setProductNo(S_SFC_CODE); |
|
191 |
materialTraceabilityParam.setLineCode(PRODUCTION_LINE); |
|
192 |
materialTraceabilityParam.setLocationCode(LOCATION_CODE); |
|
193 |
materialTraceabilityParam.setAssemblyQty(1); |
|
194 |
materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate()); |
|
195 |
materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码 |
|
196 |
materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次 |
|
197 |
|
|
198 |
MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService; |
|
199 |
materialTraceabilityService.add(materialTraceabilityParam); |
|
200 |
//更新剩余数量 |
|
201 |
productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId()); |
|
202 |
productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量 |
|
203 |
productionOrderBatchInfoService.update(productionOrderBatchInfoParam); |
|
204 |
} |
|
205 |
} |
71e81e
|
206 |
} |
懒 |
207 |
|
|
208 |
//PC读参数信息 |
|
209 |
public void handleInfo() throws Exception { |
|
210 |
logger.info("OP050工位,handleInfo START!"); |
|
211 |
|
|
212 |
if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){ |
|
213 |
if(group != null){ |
|
214 |
opc.getServer().removeGroup(group,true); |
|
215 |
} |
|
216 |
group = opc.getServer().addGroup(GROUP_NAME); |
|
217 |
|
|
218 |
CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam(); |
|
219 |
//collectionParamConfParam.setProductCode(S_PRODUCT_CODE); |
|
220 |
collectionParamConfParam.setLocationCode(LOCATION_CODE); |
|
221 |
CollectionParamConfService collectionParamConfService = opc.collectionParamConfService; |
|
222 |
list = collectionParamConfService.findListBySpec(collectionParamConfParam); |
|
223 |
|
|
224 |
|
|
225 |
for(int i=0;i<list.size();i++){ |
|
226 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
227 |
Item item = group.addItem(result.getGatherAddress()); |
|
228 |
result.setItem(item); |
|
229 |
list.set(i,result); |
|
230 |
} |
|
231 |
//S_PRODUCT_CODE_OLD = S_PRODUCT_CODE; |
|
232 |
} |
|
233 |
|
|
234 |
if(null != list && list.size()>0) { |
|
235 |
ParamCollectionService paramCollectionService = opc.paramCollectionService; |
|
236 |
for (int i = 0; i < list.size(); i++) { |
|
237 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
238 |
Item item = result.getItem(); |
|
239 |
String value = OPCUnit.read(item);//读参数值 |
|
240 |
ParamCollectionParam paramCollectionParam = new ParamCollectionParam(); |
|
241 |
paramCollectionParam.setParamCode(result.getParamCode()); |
|
242 |
paramCollectionParam.setParamName(result.getParamName()); |
|
243 |
paramCollectionParam.setWorkOrderNo(S_ORDER_CODE); |
|
244 |
paramCollectionParam.setSfcCode(S_SFC_CODE); |
|
245 |
paramCollectionParam.setProductCode(S_PRODUCT_CODE); |
|
246 |
paramCollectionParam.setProductionLine(result.getProductionLine()); |
|
247 |
paramCollectionParam.setLocationCode(result.getLocationCode()); |
|
248 |
paramCollectionParam.setParamValue(value); |
|
249 |
paramCollectionParam.setParamLower(result.getParamLower()); |
|
250 |
paramCollectionParam.setParamUpper(result.getParamUpper()); |
|
251 |
paramCollectionParam.setParamStandard(result.getParamCentral()); |
|
252 |
paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate()); |
|
253 |
paramCollectionParam.setUnit(result.getUnit()); |
|
254 |
paramCollectionService.add(paramCollectionParam); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
logger.info("OP050工位,handleInfo END!"); |
|
259 |
} |
|
260 |
|
|
261 |
//PC完成 |
|
262 |
public void handleFinsh() { |
|
263 |
|
|
264 |
if("".equals(S_ORDER_CODE)){ |
|
265 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
266 |
S_ORDER_CODE = OPCUnit.read(opc.getOP050_S_ORDER_CODE());//工单编号 |
|
267 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP050_S_PRODUCT_CODE());//产品编号 |
|
268 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
269 |
S_SFC_CODE = OPCUnit.read(opc.getOP050_S_SFC_CODE());//总成编码 |
|
270 |
} |
|
271 |
|
|
272 |
//处理过站信息 |
|
273 |
String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP050_S_PRODUCT_STATE_CODE()); |
cf6bff
|
274 |
|
71e81e
|
275 |
PassingStationCollectionParam param = new PassingStationCollectionParam(); |
懒 |
276 |
param.setWorkOrderNo(S_ORDER_CODE); |
|
277 |
param.setProductCode(S_PRODUCT_CODE); |
|
278 |
param.setSfcCode(S_SFC_CODE); |
|
279 |
param.setProductionLine(PRODUCTION_LINE); |
|
280 |
param.setLocationCode(LOCATION_CODE); |
|
281 |
param.setInboundTime(IN_TIME); |
|
282 |
param.setOutboundTime(DateTool.getLocalTimeForDate()); |
|
283 |
param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 |
|
284 |
PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService; |
|
285 |
passingStationCollectionService.add(param); |
|
286 |
|
cf6bff
|
287 |
|
C |
288 |
|
71e81e
|
289 |
String copSfcCode = OPCUnit.read(opc.getOP050_S_SFC_CODE_COP());//COP分总成 |
懒 |
290 |
String bopSfcCode = OPCUnit.read(opc.getOP050_S_SFC_CODE_BOP());//BOP分总成 |
cf6bff
|
291 |
|
C |
292 |
//根据分总成编码,将EOP物料数据绑定关系修改为总成编码 |
|
293 |
MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService; |
|
294 |
materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode); |
|
295 |
materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode); |
|
296 |
|
|
297 |
//根据分总成编码,将EOP过站数据绑定关系修改为总成编码 |
71e81e
|
298 |
passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode); |
懒 |
299 |
passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode); |
|
300 |
|
|
301 |
|
|
302 |
//根据分总成编码,将EOP采集数据绑定关系修改为总成编码 |
|
303 |
ParamCollectionService paramCollectionService = opc.paramCollectionService; |
|
304 |
paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode); |
|
305 |
paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode); |
|
306 |
|
cf6bff
|
307 |
logger.info("S_SFC_CODE:"+S_SFC_CODE); |
C |
308 |
logger.info("copSfcCode:"+copSfcCode); |
|
309 |
logger.info("bopSfcCode:"+bopSfcCode); |
|
310 |
|
|
311 |
//查询COP和BOP是否合格 |
|
312 |
PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam(); |
|
313 |
passingStationCollectionParam.setSfcCode(S_SFC_CODE); |
|
314 |
List<PassingStationCollectionResult> passingStationCollectionResultList = |
|
315 |
opc.passingStationCollectionService.findListBySpec(passingStationCollectionParam); |
|
316 |
|
|
317 |
String isProductState = "true"; |
|
318 |
for(int i=0;i<passingStationCollectionResultList.size();i++){ |
|
319 |
PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i); |
|
320 |
if("false".equals(passingStationCollectionResult.getOutRsSign())){ |
|
321 |
isProductState = "false"; |
|
322 |
break; |
|
323 |
} |
|
324 |
} |
|
325 |
//修改报工记录 |
|
326 |
if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){ |
|
327 |
ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); |
|
328 |
productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); |
|
329 |
productionOrderRecordsParam.setProductNo(S_SFC_CODE); |
|
330 |
ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService; |
|
331 |
|
|
332 |
List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); |
|
333 |
if(list.size()>0){ |
|
334 |
ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); |
|
335 |
productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); |
|
336 |
productionOrderRecordsParam.setWhetherPass("false"); |
|
337 |
productionOrderRecordsService.update(productionOrderRecordsParam); |
|
338 |
} |
|
339 |
} |
|
340 |
|
71e81e
|
341 |
|
懒 |
342 |
OPCUnit.write(opc.getOP050_J_PC_FINISH(), "true"); //PC完成 |
|
343 |
|
|
344 |
logger.info("OP050工位,handleFinsh PC处理完成!"); |
|
345 |
} |
|
346 |
|
|
347 |
} |