Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -144,7 +144,9 @@ public class MpsSaleOrderServiceImpl extends ServiceImpl<MpsSaleOrderMapper,MpsS
|
|||||||
if(ObjectUtil.isEmpty(list)) {
|
if(ObjectUtil.isEmpty(list)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MpsSaleOrder mpsSaleOrder = new MpsSaleOrder();
|
MpsSaleOrder mpsSaleOrder = new MpsSaleOrder();
|
||||||
|
mpsSaleOrder.setSale_id(IdUtil.getStringId());
|
||||||
mpsSaleOrder.setSale_type("01");
|
mpsSaleOrder.setSale_type("01");
|
||||||
mpsSaleOrder.setStatus("10");
|
mpsSaleOrder.setStatus("10");
|
||||||
mpsSaleOrder.setCreate_time(DateUtil.now());
|
mpsSaleOrder.setCreate_time(DateUtil.now());
|
||||||
|
|||||||
@@ -97,6 +97,14 @@ public class IStivtlostorivnCpOutController {
|
|||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/setPointAll")
|
||||||
|
@Log("一键设置")
|
||||||
|
//("设置站点")
|
||||||
|
public ResponseEntity<Object> setPointAll(@RequestBody JSONObject whereJson){
|
||||||
|
iStIvtIostorinvCpOutService.setPointAll(whereJson);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/confirm")
|
@PostMapping("/confirm")
|
||||||
@Log("强制确认")
|
@Log("强制确认")
|
||||||
//("强制确认")
|
//("强制确认")
|
||||||
|
|||||||
@@ -118,6 +118,15 @@ public interface IStIvtIostorinvCpOutService extends IService<StIvtIostorinvCp>
|
|||||||
*/
|
*/
|
||||||
void setPoint(JSONObject whereJson);
|
void setPoint(JSONObject whereJson);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一键设置
|
||||||
|
* @param whereJson
|
||||||
|
* {
|
||||||
|
* mst : 出入库主表
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
void setPointAll(JSONObject whereJson);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 强制确认
|
* 强制确认
|
||||||
* @param whereJson
|
* @param whereJson
|
||||||
@@ -196,4 +205,5 @@ public interface IStIvtIostorinvCpOutService extends IService<StIvtIostorinvCp>
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
JSONArray queryStructAll(Map whereJson);
|
JSONArray queryStructAll(Map whereJson);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.nl.wms.storage_manage.productmanage.service.iostorInv.IStIvtIostorinv
|
|||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.IStIvtIostorinvdtlCpService;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.IStIvtIostorinvdtlCpService;
|
||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvCp;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvCp;
|
||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvdisCp;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvdisCp;
|
||||||
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvdisdtlCp;
|
||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvdtlCp;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.StIvtIostorinvdtlCp;
|
||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.mapper.StIvtIostorinvCpMapper;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dao.mapper.StIvtIostorinvCpMapper;
|
||||||
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dto.IostorInvQuery;
|
import org.nl.wms.storage_manage.productmanage.service.iostorInv.dto.IostorInvQuery;
|
||||||
@@ -494,6 +495,99 @@ public class StIvtIostorinvCpOutServiceImpl extends ServiceImpl<StIvtIostorinvCp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void setPointAll(JSONObject whereJson) {
|
||||||
|
/*
|
||||||
|
* 1.校验明细是否都为分配完
|
||||||
|
* 2.找出库点位
|
||||||
|
* 3.生成任务
|
||||||
|
* 4.下发任务
|
||||||
|
* 5.更新分配状态
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 1.校验明细是否都为分配完
|
||||||
|
List<StIvtIostorinvdtlCp> dtlDao = iostorinvdtlCpService.list(
|
||||||
|
new QueryWrapper<StIvtIostorinvdtlCp>().lambda()
|
||||||
|
.eq(StIvtIostorinvdtlCp::getIostorinv_id, whereJson.getString("iostorinv_id"))
|
||||||
|
);
|
||||||
|
|
||||||
|
boolean is_true = dtlDao.stream()
|
||||||
|
.allMatch(row -> row.getBill_status().equals(IOSEnum.BILL_STATUS.code("分配完")));
|
||||||
|
|
||||||
|
if (!is_true) throw new BadRequestException("请先分配完所有明细!");
|
||||||
|
|
||||||
|
// 2.找出库点
|
||||||
|
// 根据托盘进行分组
|
||||||
|
Map<String, List<StIvtIostorinvdisCp>> disMapList = iostorinvdisCpService.list(
|
||||||
|
new QueryWrapper<StIvtIostorinvdisCp>().lambda()
|
||||||
|
.eq(StIvtIostorinvdisCp::getIostorinv_id, whereJson.getString("iostorinv_id"))
|
||||||
|
.and(qr -> qr.eq(StIvtIostorinvdisCp::getPoint_id,"")
|
||||||
|
.or().isNull(StIvtIostorinvdisCp::getPoint_id)
|
||||||
|
)
|
||||||
|
).stream()
|
||||||
|
.collect(Collectors.groupingBy(StIvtIostorinvdisCp::getStruct_code));
|
||||||
|
|
||||||
|
// 出库点位集合
|
||||||
|
List<SchBasePoint> pointList = iSchBasePointService.list(
|
||||||
|
new QueryWrapper<SchBasePoint>().lambda()
|
||||||
|
.eq(SchBasePoint::getIs_delete, IOSEnum.IS_USED.code("否"))
|
||||||
|
.eq(SchBasePoint::getIs_used, IOSEnum.IS_USED.code("是"))
|
||||||
|
.eq(SchBasePoint::getRegion_code, PDAEnum.REGION_CODE.code("发货区域"))
|
||||||
|
.orderByAsc(SchBasePoint::getPoint_code)
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
for (String struct_code : disMapList.keySet()) {
|
||||||
|
StIvtIostorinvdisCp disDao = disMapList.get(struct_code).get(0);
|
||||||
|
|
||||||
|
for (SchBasePoint dao : pointList) {
|
||||||
|
// 校验此点位是否有未完成的任务
|
||||||
|
SchBaseTask taskDao = iSchBaseTaskService.getOne(
|
||||||
|
new QueryWrapper<SchBaseTask>().lambda()
|
||||||
|
.eq(SchBaseTask::getPoint_code3, dao.getPoint_code())
|
||||||
|
.eq(SchBaseTask::getIs_delete, IOSEnum.IS_USED.code("否"))
|
||||||
|
.notIn(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED.getCode(), TaskStatusEnum.CANCEL.getCode())
|
||||||
|
, false
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(taskDao)) {
|
||||||
|
// 3.生成任务
|
||||||
|
PointEvent event = PointEvent.builder()
|
||||||
|
.type(AcsTaskEnum.TASK_STRUCT_CP_OUT)
|
||||||
|
.acs_task_type("8")
|
||||||
|
.task_group_id(IdUtil.getStringId())
|
||||||
|
.point_code1(struct_code)
|
||||||
|
.point_code3(dao.getPoint_code())
|
||||||
|
.vehicle_code(disDao.getStoragevehicle_code())
|
||||||
|
.product_area("A1") // 暂时写死
|
||||||
|
.callback((Consumer<String>) disDao::setTask_id)
|
||||||
|
.build();
|
||||||
|
BussEventMulticaster.Publish(event);
|
||||||
|
|
||||||
|
// 4.下发任务
|
||||||
|
whereJson.put("task_id", disDao.getTask_id());
|
||||||
|
sendTask(whereJson);
|
||||||
|
|
||||||
|
// 5.更新分配状态
|
||||||
|
iostorinvdisCpService.update(
|
||||||
|
new UpdateWrapper<StIvtIostorinvdisCp>().lambda()
|
||||||
|
.set(StIvtIostorinvdisCp::getPoint_id, dao.getPoint_id())
|
||||||
|
.set(StIvtIostorinvdisCp::getPoint_code, dao.getPoint_code())
|
||||||
|
.set(StIvtIostorinvdisCp::getPoint_name, dao.getPoint_name())
|
||||||
|
.set(StIvtIostorinvdisCp::getWork_status, IOSEnum.WORK_STATUS.code("生成"))
|
||||||
|
.set(StIvtIostorinvdisCp::getTask_id, disDao.getTask_id())
|
||||||
|
.eq(StIvtIostorinvdisCp::getIostorinv_id, disDao.getIostorinv_id())
|
||||||
|
.eq(StIvtIostorinvdisCp::getStoragevehicle_code, disDao.getStoragevehicle_code())
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void confirm(JSONObject whereJson) {
|
public void confirm(JSONObject whereJson) {
|
||||||
|
|||||||
@@ -90,6 +90,17 @@
|
|||||||
>
|
>
|
||||||
手工分配
|
手工分配
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
slot="left"
|
||||||
|
class="filter-item"
|
||||||
|
:loading="loadingSetAllPoint"
|
||||||
|
type="warning"
|
||||||
|
icon="el-icon-check"
|
||||||
|
size="mini"
|
||||||
|
@click="setPointAll"
|
||||||
|
>
|
||||||
|
一键设置
|
||||||
|
</el-button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<el-card class="box-card" shadow="never" :body-style="{padding:'0'}">
|
<el-card class="box-card" shadow="never" :body-style="{padding:'0'}">
|
||||||
@@ -466,6 +477,17 @@ export default {
|
|||||||
this.loadingSetAllPoint = false
|
this.loadingSetAllPoint = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
setPointAll() {
|
||||||
|
this.loadingSetAllPoint = true
|
||||||
|
productOut.setPointAll(this.mstrow).then(res => {
|
||||||
|
this.crud.notify('设置成功!', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
|
this.queryTableDtl()
|
||||||
|
this.tabledis = []
|
||||||
|
this.form2.point_code = ''
|
||||||
|
}).finally(() => {
|
||||||
|
this.loadingSetAllPoint = false
|
||||||
|
})
|
||||||
|
},
|
||||||
cellStyle({ row, column, rowIndex, columnIndex }) {
|
cellStyle({ row, column, rowIndex, columnIndex }) {
|
||||||
const assign_qty = parseFloat(row.assign_qty)
|
const assign_qty = parseFloat(row.assign_qty)
|
||||||
const plan_qty = parseFloat(row.plan_qty)
|
const plan_qty = parseFloat(row.plan_qty)
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ export function setPoint(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setPointAll(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/productOut/setPointAll',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function confirm(data) {
|
export function confirm(data) {
|
||||||
return request({
|
return request({
|
||||||
url: 'api/productOut/confirm',
|
url: 'api/productOut/confirm',
|
||||||
@@ -129,6 +137,7 @@ export default {
|
|||||||
allDivIvt,
|
allDivIvt,
|
||||||
allCancel,
|
allCancel,
|
||||||
setPoint,
|
setPoint,
|
||||||
|
setPointAll,
|
||||||
confirm,
|
confirm,
|
||||||
getStructIvt,
|
getStructIvt,
|
||||||
manualDiv,
|
manualDiv,
|
||||||
|
|||||||
@@ -58,28 +58,60 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
//下发信号
|
//下发信号
|
||||||
control( itemValues);
|
try{
|
||||||
Map<String, Object> read = new HashMap();
|
if(i == 0){
|
||||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
control( itemValues);
|
||||||
Set<Item> items = itemStatus.keySet();
|
} else {
|
||||||
Iterator var15 = items.iterator();
|
controlByNewConn( itemValues);
|
||||||
|
|
||||||
while(var15.hasNext()) {
|
|
||||||
Item item = (Item)var15.next();
|
|
||||||
ItemState itemState = (ItemState)itemStatus.get(item);
|
|
||||||
Object value = OpcUtl.getValue(item, itemState);
|
|
||||||
read.put(item.getId(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean check = true;
|
|
||||||
Iterator var24 = itemsString.iterator();
|
|
||||||
|
|
||||||
while(var24.hasNext()) {
|
|
||||||
String itemString = (String)var24.next();
|
|
||||||
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
|
|
||||||
check = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Map<String, Object> read = new HashMap();
|
||||||
|
Map<Item, ItemState> itemStatus = null;
|
||||||
|
boolean check = true;
|
||||||
|
try{
|
||||||
|
if(i>0){
|
||||||
|
group = opcServerService.getServer(this.getOpcServer());
|
||||||
|
itemsString = new ArrayList<> (itemValues.keySet());
|
||||||
|
Iterator nis = itemsString.iterator();
|
||||||
|
|
||||||
|
while (nis.hasNext()) {
|
||||||
|
String string = (String) nis.next();
|
||||||
|
try {
|
||||||
|
readitems.put(string, group.addItem(string));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||||
|
}
|
||||||
|
Set<Item> items = itemStatus.keySet();
|
||||||
|
Iterator var15 = items.iterator();
|
||||||
|
while(var15.hasNext()) {
|
||||||
|
Item item = (Item)var15.next();
|
||||||
|
ItemState itemState = (ItemState)itemStatus.get(item);
|
||||||
|
Object value = OpcUtl.getValue(item, itemState);
|
||||||
|
read.put(item.getId(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator var24 = itemsString.iterator();
|
||||||
|
|
||||||
|
while(var24.hasNext()) {
|
||||||
|
String itemString = (String)var24.next();
|
||||||
|
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
|
||||||
|
check = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
check = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (check) {
|
if (check) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -95,6 +127,85 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean controlByNewConn(Map<String, Object> itemValues) {
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||||
|
|
||||||
|
ItemValue p2[];
|
||||||
|
p2 = new ItemValue[itemValues.size()];
|
||||||
|
int i=0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, Object> entry = it.next();
|
||||||
|
System.out.println("即将写入值:"+entry.getKey() + ":" + entry.getValue());
|
||||||
|
p2[i] = new ItemValue();
|
||||||
|
p2[i].setItem_code(entry.getKey());
|
||||||
|
p2[i].setItem_value(entry.getValue());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.controlByNewConn(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean controlByNewConn(ItemValue[] itemValues) {
|
||||||
|
if (itemValues != null && itemValues.length != 0) {
|
||||||
|
String this_items = JsonUtl.parseWithoutException(itemValues);
|
||||||
|
boolean need_write = false;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
ItemValue[] var5 = itemValues;
|
||||||
|
int var6 = itemValues.length;
|
||||||
|
|
||||||
|
// for (int var7 = 0; var7 < var6; ++var7) {
|
||||||
|
// ItemValue itemValue = var5[var7];
|
||||||
|
// String code = itemValue.getItem_code();
|
||||||
|
// Object udw_value = this.getUdwValue(code);
|
||||||
|
// Object write_value = itemValue.getItem_value();
|
||||||
|
// sb.append(code);
|
||||||
|
// sb.append(":");
|
||||||
|
// sb.append(JsonUtl.parseWithoutException(udw_value));
|
||||||
|
// sb.append(";");
|
||||||
|
// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
|
||||||
|
// need_write = true;
|
||||||
|
// } else {
|
||||||
|
// log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
need_write = true;
|
||||||
|
if (need_write) {
|
||||||
|
Date date = new Date();
|
||||||
|
/*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) {
|
||||||
|
log.trace("发送时间因为小于{}毫秒,而被无视", WcsConfig.opc_write_repeat_check);
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
this.last_items = this_items;
|
||||||
|
this.sendTime = date;
|
||||||
|
/* this.execute_log.setResource(this.getDevice().getCode(), this.getDevice().getName());
|
||||||
|
this.execute_log.log("原始记录{}->变更为{}", new Object[]{sb, this_items});
|
||||||
|
OpcServerService opcServerService = OpcServerFactory.getOpcServerService();*/
|
||||||
|
|
||||||
|
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||||
|
|
||||||
|
opcServerService.writeIntegerByNewConn(this.getOpcServer(), itemValues);
|
||||||
|
|
||||||
|
|
||||||
|
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||||
|
ItemValue[] var17 = itemValues;
|
||||||
|
int var18 = itemValues.length;
|
||||||
|
|
||||||
|
for (int var19 = 0; var19 < var18; ++var19) {
|
||||||
|
ItemValue itemValue = var17[var19];
|
||||||
|
String code = itemValue.getItem_code();
|
||||||
|
Object value = itemValue.getItem_value();
|
||||||
|
opcValueAccessor.setValue(code, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new WDKException("下发 无内容");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean control(Map<String, Object> itemValues) {
|
public boolean control(Map<String, Object> itemValues) {
|
||||||
|
|
||||||
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ public interface OpcServerService {
|
|||||||
|
|
||||||
Group getServer(String var1);
|
Group getServer(String var1);
|
||||||
|
|
||||||
|
Group getServerByNewConn(String var1);
|
||||||
|
|
||||||
void writeInteger(String var1, ItemValue... var2);
|
void writeInteger(String var1, ItemValue... var2);
|
||||||
|
|
||||||
|
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
||||||
|
|
||||||
void clearServer(String var1);
|
void clearServer(String var1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package org.nl.acs.opc;
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.jinterop.dcom.common.JIException;
|
import org.jinterop.dcom.common.JIException;
|
||||||
import org.nl.acs.auto.initial.ApplicationAutoInitial;
|
import org.nl.acs.auto.initial.ApplicationAutoInitial;
|
||||||
import org.nl.acs.device_driver.driver.ItemValue;
|
import org.nl.acs.device_driver.driver.ItemValue;
|
||||||
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
import org.nl.modules.wql.exception.WDKException;
|
import org.nl.modules.wql.exception.WDKException;
|
||||||
import org.openscada.opc.lib.common.NotConnectedException;
|
import org.openscada.opc.lib.common.NotConnectedException;
|
||||||
import org.openscada.opc.lib.da.Group;
|
import org.openscada.opc.lib.da.Group;
|
||||||
@@ -40,22 +42,22 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
this.reload();
|
this.reload();
|
||||||
if (OpcConfig.auto_start_opc) {
|
if (OpcConfig.auto_start_opc) {
|
||||||
Thread t =
|
Thread t =
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
|
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
|
||||||
|
|
||||||
while (var1.hasNext()) {
|
while (var1.hasNext()) {
|
||||||
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
|
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
||||||
//OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
||||||
} catch (Exception var4) {
|
} catch (Exception var4) {
|
||||||
//OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,79 +67,128 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Group getServer(String code) {
|
public Group getServer(String code) {
|
||||||
Group group = null;
|
synchronized(this.buildLock(code)) {
|
||||||
group = (Group) this.groups.get(code);
|
Group group = null;
|
||||||
if (group != null) {
|
group = (Group)this.groups.get(code);
|
||||||
try {
|
if (group != null) {
|
||||||
if (group.isActive()) {
|
label68: {
|
||||||
return group;
|
Group var10000;
|
||||||
|
try {
|
||||||
|
if (!group.isActive()) {
|
||||||
|
break label68;
|
||||||
|
}
|
||||||
|
|
||||||
|
var10000 = group;
|
||||||
|
} catch (JIException var14) {
|
||||||
|
log.error(code, var14);
|
||||||
|
break label68;
|
||||||
|
}
|
||||||
|
|
||||||
|
return var10000;
|
||||||
}
|
}
|
||||||
} catch (JIException var9) {
|
|
||||||
var9.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Server server = (Server) this.servers.get(code);
|
Server server = (Server)this.servers.get(code);
|
||||||
boolean needcreate = false;
|
boolean needcreate = false;
|
||||||
if (server == null) {
|
String groupName = code;
|
||||||
needcreate = true;
|
if (server == null) {
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
group = server.findGroup(OpcConfig.opc_server_default_group);
|
|
||||||
} catch (UnknownHostException
|
|
||||||
| JIException
|
|
||||||
| UnknownGroupException
|
|
||||||
| NotConnectedException
|
|
||||||
| IllegalArgumentException var8) {
|
|
||||||
var8.printStackTrace();
|
|
||||||
needcreate = true;
|
needcreate = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
group = server.findGroup(groupName);
|
||||||
|
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | IllegalArgumentException var13) {
|
||||||
|
log.error(code, var13);
|
||||||
|
needcreate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needcreate) {
|
||||||
|
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
|
||||||
|
if (dto == null) {
|
||||||
|
throw new RuntimeException(code+"不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (server!=null){
|
||||||
|
// server.disconnect();
|
||||||
|
// server=null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); }
|
||||||
|
|
||||||
|
try {
|
||||||
|
group = server.addGroup(groupName);
|
||||||
|
} catch (Exception var12) {
|
||||||
|
this.clearServer(code);
|
||||||
|
ThreadUtl.sleep(5000L);
|
||||||
|
log.warn("获取opc出错重新获取", code, var12);
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||||
|
try {
|
||||||
|
group = server.addGroup(groupName);
|
||||||
|
} catch (Exception var11) {
|
||||||
|
throw new RuntimeException(var12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.servers.put(code, server);
|
||||||
|
this.groups.put(code, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (needcreate) {
|
public Group getServerByNewConn(String code) {
|
||||||
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
|
synchronized(this.buildLock(code)) {
|
||||||
if (dto == null) {
|
|
||||||
throw new WDKException("code 不存在");
|
Server server = (Server)this.servers.get(code);
|
||||||
|
if (server!=null){
|
||||||
|
this.clearServer(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
server = OpcServerUtl.getServerWithOutException(
|
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
|
||||||
dto.getOpc_host(),
|
if (dto == null) {
|
||||||
dto.getCls_id(),
|
throw new RuntimeException(code+"不存在");
|
||||||
dto.getUser(),
|
}
|
||||||
dto.getPassword(),
|
|
||||||
dto.getDomain());
|
|
||||||
|
|
||||||
// server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
|
||||||
|
|
||||||
|
// if (server == null) {
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||||
|
// }
|
||||||
|
String groupName = code;
|
||||||
|
Group group = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
group = server.addGroup(OpcConfig.opc_server_default_group);
|
group = server.addGroup(groupName);
|
||||||
} catch (Exception var7) {
|
} catch (Exception var12) {
|
||||||
throw new WDKException(var7);
|
this.clearServer(code);
|
||||||
|
ThreadUtl.sleep(2000L);
|
||||||
|
log.warn("获取opc出错重新获取", code, var12);
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||||
|
try {
|
||||||
|
group = server.addGroup(groupName);
|
||||||
|
} catch (Exception var11) {
|
||||||
|
throw new RuntimeException(var12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.servers.put(code, server);
|
this.servers.put(code, server);
|
||||||
this.groups.put(code, group);
|
this.groups.put(code, group);
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void clearServer(String code) {
|
public void clearServer(String code) {
|
||||||
try {
|
synchronized(this.buildLock(code)) {
|
||||||
Server server = (Server) this.servers.get(code);
|
try {
|
||||||
if (server!=null){
|
Server server = (Server)this.servers.get(code);
|
||||||
server.disconnect();
|
server.disconnect();
|
||||||
|
} catch (Exception var5) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
this.servers.remove(code);
|
||||||
e.printStackTrace();
|
this.groups.remove(code);
|
||||||
log.error("清理server异常,",e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.servers.remove(code);
|
|
||||||
this.groups.remove(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeInteger(String code, ItemValue... values) {
|
public void writeInteger(String code, ItemValue... values) {
|
||||||
@@ -146,9 +197,32 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
OpcUtl.writeValue(group, values);
|
OpcUtl.writeValue(group, values);
|
||||||
} catch (Exception var4) {
|
} catch (Exception var4) {
|
||||||
this.clearServer(code);
|
this.clearServer(code);
|
||||||
log.warn("写入出错opc server {} 重新加载", code, var4);
|
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||||
ThreadUtl.sleep(5000L);
|
ThreadUtl.sleep(1000L);
|
||||||
throw var4;
|
throw var4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeIntegerByNewConn(String code, ItemValue... values) {
|
||||||
|
try {
|
||||||
|
Group group = this.getServerByNewConn(code);
|
||||||
|
OpcUtl.writeValue(group, values);
|
||||||
|
} catch (Exception var4) {
|
||||||
|
this.clearServer(code);
|
||||||
|
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||||
|
ThreadUtl.sleep(1000L);
|
||||||
|
throw var4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildLock(String key) {
|
||||||
|
if (StrUtil.isEmpty(key)) {
|
||||||
|
key = "";
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("OpcServerService.");
|
||||||
|
builder.append(key);
|
||||||
|
String lock = builder.toString().intern();
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user