提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.OP120.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; |
cf6bff
|
11 |
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam; |
C |
12 |
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService; |
|
13 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam; |
|
14 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult; |
|
15 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService; |
|
16 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam; |
|
17 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult; |
|
18 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService; |
71e81e
|
19 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
懒 |
20 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
21 |
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; |
|
22 |
|
|
23 |
import cn.stylefeng.guns.plcserver.server.OP120.OP120ServerInterface; |
|
24 |
import cn.stylefeng.guns.plcserver.tool.DateTool; |
|
25 |
import cn.stylefeng.guns.plcserver.tool.LogUtil; |
|
26 |
import org.apache.log4j.Logger; |
|
27 |
import org.openscada.opc.lib.da.Group; |
|
28 |
import org.openscada.opc.lib.da.Item; |
|
29 |
|
|
30 |
import java.util.Date; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
|
|
34 |
public class OP120ServerInterfaceImpl implements OP120ServerInterface { |
|
35 |
|
|
36 |
private static Logger logger; |
|
37 |
LogUtil logUtil = new LogUtil(); |
|
38 |
static { |
|
39 |
logger = Logger.getLogger(OP120ServerInterfaceImpl.class); |
|
40 |
} |
|
41 |
|
|
42 |
private OPCComm opc = OPCComm.getInstance(); |
|
43 |
private static Date IN_TIME = null; |
|
44 |
private static String S_ORDER_CODE = "";//工单编号 |
|
45 |
private static String S_PRODUCT_CODE = "";//产品编号 |
|
46 |
private static String S_PRODUCT_TYPE= "";//产品类型 |
|
47 |
private static String S_PRODUCT_CODE_OLD = "";//产品编号 |
|
48 |
private static String S_SFC_CODE = "";//总成编码 |
|
49 |
private static String S_RIGHT_CODE = "";//右壳体编码 |
|
50 |
private static String PRODUCTION_LINE = "OP";//产线号 |
|
51 |
private static String LOCATION_CODE = "OP120";//工位号 |
|
52 |
private static String GROUP_NAME = "OP120_P";//工位号 |
|
53 |
private static List list = null; |
|
54 |
private static Group group = null; |
cf6bff
|
55 |
|
C |
56 |
private int count = 0; |
|
57 |
|
|
58 |
/** |
|
59 |
* 设置心跳标志位,保存到全局变量 |
|
60 |
*/ |
|
61 |
public void setHeartbeat(String value) { |
|
62 |
if ("false".equals(value)) { |
|
63 |
OPCUnit.write(opc.getOP120_F_HEART_BEAT(), "true"); |
|
64 |
GlobalVariable.OP120_F_HEART_BEAT = true; |
|
65 |
count = 0; |
|
66 |
} else { |
|
67 |
count++; |
|
68 |
} |
|
69 |
// 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时 |
|
70 |
if (count > GlobalVariable.HEART_MAX_COUNT) { |
|
71 |
GlobalVariable.OP120_F_HEART_BEAT = false; |
|
72 |
} |
|
73 |
} |
|
74 |
|
71e81e
|
75 |
@Override |
懒 |
76 |
public synchronized void monitor() { |
|
77 |
String ecpStr = "";//异常记录标记 |
|
78 |
try{ |
cf6bff
|
79 |
|
e0fac3
|
80 |
/*String isHeartBeat = OPCUnit.read(opc.getOP120_F_HEART_BEAT()); |
C |
81 |
setHeartbeat(isHeartBeat);*/ |
cf6bff
|
82 |
|
71e81e
|
83 |
if(GlobalVariable.OP120_F_HEART_BEAT) { |
懒 |
84 |
//PC读工单 |
|
85 |
String isPLCStart = OPCUnit.read(opc.getOP120_J_PLC_START());//PLC开始 |
|
86 |
if(isPLCStart.equals("true")){ |
|
87 |
String isFinish = OPCUnit.read(opc.getOP120_J_PC_WRITE_ORDER());//PC下发工单完成 |
|
88 |
if(isFinish.equals("false")){ |
|
89 |
handleOrder(); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
//PC完成 |
|
95 |
String isPLCFinish = OPCUnit.read(opc.getOP120_J_PLC_FINISH());//PLC完成 |
|
96 |
if(isPLCFinish.equals("true")){ |
|
97 |
String isFinish = OPCUnit.read(opc.getOP120_J_PC_FINISH());//PC操作完成 |
|
98 |
if(isFinish.equals("false")){ |
e0fac3
|
99 |
logger.info("handleFinsh开始时间:"+new Date()); |
71e81e
|
100 |
handleFinsh(); |
e0fac3
|
101 |
logger.info("handleFinsh完成时间:"+new Date()); |
C |
102 |
logger.info("handleInfo开始时间:"+new Date()); |
|
103 |
handleInfo(); |
|
104 |
logger.info("handleInfo完成时间:"+new Date()); |
|
105 |
logger.info("handleMaterial开始时间:"+new Date()); |
|
106 |
handleMaterial(); |
|
107 |
logger.info("handleMaterial完成时间:"+new Date()); |
71e81e
|
108 |
} |
懒 |
109 |
} |
|
110 |
|
|
111 |
}else{ |
|
112 |
logger.info("OP120工位与PLC断开,请检查PLC或网络是否异常!"); |
|
113 |
} |
|
114 |
|
|
115 |
}catch (Exception e) { |
|
116 |
ecpStr ="出现异常:" + logUtil.getTrace(e); |
|
117 |
}finally { |
|
118 |
if(!"".equals(ecpStr)){ |
|
119 |
logger.info(ecpStr+"\r\n"); |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
//PC读工单 |
|
125 |
public void handleOrder() { |
|
126 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
127 |
S_ORDER_CODE = OPCUnit.read(opc.getOP120_S_ORDER_CODE());//工单编号 |
|
128 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP120_S_PRODUCT_CODE());//产品编号 |
|
129 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
130 |
S_SFC_CODE = OPCUnit.read(opc.getOP120_S_SFC_CODE());//总成编码 |
|
131 |
OPCUnit.write(opc.getOP120_J_PC_WRITE_ORDER(), "true"); //PC读工单完成 |
|
132 |
logger.info("OP120工位,handleOrder PC处理完成!"); |
cf6bff
|
133 |
} |
C |
134 |
|
|
135 |
public void handleMaterial() { |
e0fac3
|
136 |
|
cf6bff
|
137 |
//查询批次上料信息 |
C |
138 |
ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); |
|
139 |
productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); |
|
140 |
productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); |
|
141 |
ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService; |
|
142 |
List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); |
|
143 |
for(int i=0;i<list1.size();i++){ |
|
144 |
ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i); |
|
145 |
|
|
146 |
int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//剩余数量 |
e0fac3
|
147 |
if(remainingQuantity>0){ |
cf6bff
|
148 |
//新增物料追溯 |
C |
149 |
MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam(); |
|
150 |
materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE); |
|
151 |
materialTraceabilityParam.setProductCode(S_PRODUCT_CODE); |
|
152 |
materialTraceabilityParam.setProductNo(S_SFC_CODE); |
|
153 |
materialTraceabilityParam.setLineCode(PRODUCTION_LINE); |
|
154 |
materialTraceabilityParam.setLocationCode(LOCATION_CODE); |
|
155 |
materialTraceabilityParam.setAssemblyQty(1); |
|
156 |
materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate()); |
|
157 |
materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码 |
|
158 |
materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次 |
|
159 |
|
|
160 |
MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService; |
|
161 |
materialTraceabilityService.add(materialTraceabilityParam); |
|
162 |
//更新剩余数量 |
|
163 |
productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId()); |
|
164 |
productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量 |
|
165 |
productionOrderBatchInfoService.update(productionOrderBatchInfoParam); |
|
166 |
} |
|
167 |
} |
71e81e
|
168 |
} |
懒 |
169 |
|
|
170 |
//PC读参数信息 |
|
171 |
public void handleInfo() throws Exception { |
|
172 |
logger.info("OP120工位,handleInfo START!"); |
|
173 |
|
|
174 |
if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){ |
|
175 |
if(group != null){ |
|
176 |
opc.getServer().removeGroup(group,true); |
|
177 |
} |
|
178 |
group = opc.getServer().addGroup(GROUP_NAME); |
|
179 |
|
|
180 |
CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam(); |
|
181 |
//collectionParamConfParam.setProductCode(S_PRODUCT_CODE); |
|
182 |
collectionParamConfParam.setLocationCode(LOCATION_CODE); |
|
183 |
CollectionParamConfService collectionParamConfService = opc.collectionParamConfService; |
|
184 |
list = collectionParamConfService.findListBySpec(collectionParamConfParam); |
|
185 |
|
|
186 |
|
|
187 |
for(int i=0;i<list.size();i++){ |
|
188 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
189 |
Item item = group.addItem(result.getGatherAddress()); |
|
190 |
result.setItem(item); |
|
191 |
list.set(i,result); |
|
192 |
} |
|
193 |
//S_PRODUCT_CODE_OLD = S_PRODUCT_CODE; |
|
194 |
} |
|
195 |
|
|
196 |
if(null != list && list.size()>0) { |
|
197 |
ParamCollectionService paramCollectionService = opc.paramCollectionService; |
|
198 |
for (int i = 0; i < list.size(); i++) { |
|
199 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
200 |
Item item = result.getItem(); |
|
201 |
String value = OPCUnit.read(item);//读参数值 |
|
202 |
ParamCollectionParam paramCollectionParam = new ParamCollectionParam(); |
|
203 |
paramCollectionParam.setParamCode(result.getParamCode()); |
|
204 |
paramCollectionParam.setParamName(result.getParamName()); |
|
205 |
paramCollectionParam.setWorkOrderNo(S_ORDER_CODE); |
|
206 |
paramCollectionParam.setSfcCode(S_SFC_CODE); |
|
207 |
paramCollectionParam.setProductCode(S_PRODUCT_CODE); |
|
208 |
paramCollectionParam.setProductionLine(result.getProductionLine()); |
|
209 |
paramCollectionParam.setLocationCode(result.getLocationCode()); |
|
210 |
paramCollectionParam.setParamValue(value); |
|
211 |
paramCollectionParam.setParamLower(result.getParamLower()); |
|
212 |
paramCollectionParam.setParamUpper(result.getParamUpper()); |
|
213 |
paramCollectionParam.setParamStandard(result.getParamCentral()); |
|
214 |
paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate()); |
|
215 |
paramCollectionParam.setUnit(result.getUnit()); |
|
216 |
paramCollectionService.add(paramCollectionParam); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
logger.info("OP120工位,handleInfo END!"); |
|
221 |
} |
|
222 |
|
|
223 |
//PC完成 |
|
224 |
public void handleFinsh() { |
|
225 |
if("".equals(S_ORDER_CODE)){ |
|
226 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
227 |
S_ORDER_CODE = OPCUnit.read(opc.getOP120_S_ORDER_CODE());//工单编号 |
|
228 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP120_S_PRODUCT_CODE());//产品编号 |
|
229 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
230 |
S_SFC_CODE = OPCUnit.read(opc.getOP120_S_SFC_CODE());//总成编码 |
|
231 |
} |
|
232 |
//处理过站信息 |
|
233 |
String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP120_S_PRODUCT_STATE_CODE()); |
cf6bff
|
234 |
|
C |
235 |
//修改报工记录 |
|
236 |
if("false".equals(S_PRODUCT_STATE_CODE)){ |
|
237 |
ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); |
|
238 |
productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); |
|
239 |
productionOrderRecordsParam.setProductNo(S_SFC_CODE); |
|
240 |
ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService; |
|
241 |
|
|
242 |
List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); |
|
243 |
if(list.size()>0){ |
|
244 |
ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); |
|
245 |
productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); |
|
246 |
productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); |
|
247 |
productionOrderRecordsService.update(productionOrderRecordsParam); |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
|
71e81e
|
252 |
PassingStationCollectionParam param = new PassingStationCollectionParam(); |
懒 |
253 |
param.setWorkOrderNo(S_ORDER_CODE); |
|
254 |
param.setProductCode(S_PRODUCT_CODE); |
|
255 |
param.setSfcCode(S_SFC_CODE); |
|
256 |
param.setProductionLine(PRODUCTION_LINE); |
|
257 |
param.setLocationCode(LOCATION_CODE); |
|
258 |
param.setInboundTime(IN_TIME); |
|
259 |
param.setOutboundTime(DateTool.getLocalTimeForDate()); |
|
260 |
param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 |
|
261 |
PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService; |
|
262 |
passingStationCollectionService.add(param); |
|
263 |
|
|
264 |
OPCUnit.write(opc.getOP120_J_PC_FINISH(), "true"); //PC完成 |
|
265 |
|
|
266 |
logger.info("OP120工位,handleFinsh PC处理完成!"); |
|
267 |
} |
|
268 |
|
|
269 |
} |