add: 新增创建任务策略实现

This commit is contained in:
yanps
2023-12-12 14:02:55 +08:00
parent 52a2d283bd
commit 4960be53d0
8 changed files with 96 additions and 9 deletions

View File

@@ -441,4 +441,12 @@ public class DeviceController {
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("惠氏任务生成选择终点")
@ApiOperation("惠氏任务生成选择终点")
@GetMapping(value = "/endPoint")
public ResponseEntity<Object> selectEndPoint(String start_code) throws Exception {
List<String> endPoints = deviceService.selectEndPoint(start_code);
return new ResponseEntity<>(endPoints, HttpStatus.OK);
}
}

View File

@@ -296,4 +296,12 @@ public interface DeviceService {
List<Device> findCacheDevice();
void updateBarcode(JSONObject json) throws Exception;
/**
* 查询设备终端
*
* @param start_code 设备标识
* @return
*/
List<String> selectEndPoint(String start_code);
}

View File

@@ -34,6 +34,8 @@ import org.nl.acs.device_driver.yzja_special.YzjaSpecialDeviceDriver;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.route.service.dto.RouteLineDto;
import org.nl.acs.task.service.TaskService;
import org.nl.exception.BadRequestException;
import org.nl.modules.system.util.CodeUtil;
@@ -75,6 +77,8 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
private final AcsConfigService acsConfigService;
@Autowired
TaskService taskService;
@Autowired
RouteLineService routeLineService;
List<StorageCellDto> storageCells = new ArrayList<>();
private Map<String, Integer> storage_address = new HashMap();
@@ -496,7 +500,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
@Override
public JSONArray selectDeviceListThree() {
//设备基础信息表【acs_device】
JSONArray arr = WQLObject.getWQLObject("acs_device").query("is_delete= '0' AND is_active= '1' AND region = '1'", "seq_num").getResultJSONArray(0);
JSONArray arr = WQLObject.getWQLObject("acs_device").query("is_delete= '0' AND is_active= '1' AND region IN ('1', '6')", "seq_num").getResultJSONArray(0);
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
@@ -515,6 +519,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
json.put("remark", standardOrdinarySiteDeviceDriver.getRemark());
json.put("islock",standardOrdinarySiteDeviceDriver.getIslock());
json.put("hasGood",standardOrdinarySiteDeviceDriver.getHasGoods());
json.put("next_code",standardOrdinarySiteDeviceDriver.getNext_code());
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@@ -523,6 +528,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
json.put("remark", standardInspectSiteDeviceDriver.getRemark());
json.put("islock",standardInspectSiteDeviceDriver.getIslock());
json.put("hasGood",standardInspectSiteDeviceDriver.getHasGoods());
json.put("next_code",standardInspectSiteDeviceDriver.getNext_code());
}
result.add(json);
}
@@ -1243,6 +1249,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
//物料类型
String material_type = form.optString("material_type");
String remark = form.optString("remark");
String next_code = form.optString("next_code");
Integer hasGoods = 0;
if (!StrUtil.equals(material_type,"")) {
hasGoods = 2;
@@ -1256,10 +1263,12 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
standardOrdinarySiteDeviceDriver.setMaterial(material_type);
standardOrdinarySiteDeviceDriver.setRemark(remark);
standardOrdinarySiteDeviceDriver.setHasGoods(hasGoods);
standardOrdinarySiteDeviceDriver.setNext_code(next_code);
device.setMaterial_type(material_type);
device.setQuantity(quantity);
device.setRemark(remark);
device.setHas_goods(hasGoods);
device.setNext_code(next_code);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@@ -1267,10 +1276,12 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
standardInspectSiteDeviceDriver.setMaterial(material_type);
standardInspectSiteDeviceDriver.setRemark(remark);
standardInspectSiteDeviceDriver.setHasGoods(hasGoods);
standardInspectSiteDeviceDriver.setNext_code(next_code);
device.setMaterial_type(material_type);
device.setQuantity(quantity);
device.setRemark(remark);
device.setHas_goods(hasGoods);
device.setNext_code(next_code);
}
}
@@ -1501,6 +1512,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
standardOrdinarySiteDeviceDriver.setMaterial("");
standardOrdinarySiteDeviceDriver.setQty("");
standardOrdinarySiteDeviceDriver.setRemark("");
standardOrdinarySiteDeviceDriver.setNext_code("");
JSONObject jsonjo = new JSONObject();
jsonjo.put("device_code", device_code);
jsonjo.put("hasGoodStatus", "0");
@@ -1511,6 +1523,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
standardInspectSiteDeviceDriver.setMaterial("");
standardInspectSiteDeviceDriver.setQty("");
standardInspectSiteDeviceDriver.setRemark("");
standardInspectSiteDeviceDriver.setNext_code("");
}
}
}
@@ -2043,4 +2056,18 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
}
}
@Override
public List<String> selectEndPoint(String start_code) {
if(StrUtil.isEmpty(start_code)){
throw new RuntimeException("起点设备为空");
}
List<RouteLineDto> normal = routeLineService.getShortPathLinesByCode(start_code, "normal");
List<String> list = new ArrayList<>();
for (RouteLineDto routeLineDto : normal) {
list.add(routeLineDto.getNext_device_code());
}
return list;
}
}

View File

@@ -73,6 +73,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
int last_task = 0;
Boolean isonline = true;
int hasGoods = 0;
String next_code = "";
String message = null;
Boolean iserror = false;

View File

@@ -47,6 +47,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
Integer hasGoods = 0;
String next_code = "";
int error = 0;
Boolean iserror = false;
Boolean islock = false;
@@ -107,8 +108,8 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
hasGoods = this.getDevice().getHas_goods();
batch = this.getDevice().getBatch();
devicecode = this.getDeviceCode();
if (branchProtocol != last_branchProtocol) {
requireSucess = false;
if("WLFZW05".equals(devicecode)){
hasGoods = 1;
}
switch (branchProtocol) {
case 1:

View File

@@ -12,6 +12,7 @@ public class DeviceManageDto {
private Boolean is_require_task;
private String location;
private Integer has_goods = 0;
private String next_code;
private String material_type;
private String quantity;
private String remark;

View File

@@ -155,7 +155,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
InstructionDto instdto = instructionservice.findByTaskid(entity.getTask_id(), "instruction_status <2 ");
if(!ObjectUtil.isEmpty(instdto)){
if (!ObjectUtil.isEmpty(instdto)) {
instructionService.cancel(instdto.getInstruction_id());
}
@@ -282,7 +282,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
WQLObject wo = WQLObject.getWQLObject("acs_task");
JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0);
final TaskDto obj = (TaskDto) JSONObject.toBean(json, TaskDto.class);
if(ObjectUtil.isEmpty(obj)){
if (ObjectUtil.isEmpty(obj)) {
return false;
}
return true;
@@ -626,7 +626,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void hssavetask(JSONObject json) throws Exception {
public synchronized void hssavetask(JSONObject json) throws Exception {
JSONArray array = json.optJSONArray("data");
if (array.size() == 0) {
@@ -673,11 +673,29 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
// if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) {
// throw new RuntimeException("设备:" + device_code + " 已存在该起点的任务");
// }
list.sort(new Comparator<RouteLineDto>() {
@Override
public int compare(RouteLineDto o1, RouteLineDto o2) {
String s1 = o1.getNext_device_code().substring(o1.getNext_device_code().length() - 2);
String s2 = o2.getNext_device_code().substring(o2.getNext_device_code().length() - 2);
return Integer.compare(Integer.parseInt(s1), Integer.parseInt(s2));
}
});
String next_code = arrjo.getString("next_code");
Boolean isFirst = true;
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
for (int j = 0; j < list.size(); j++) {
RouteLineDto routeLineDto = list.get(j);
next_device_code = routeLineDto.getNext_device_code();
//包材接驳位策略
//包材取货位放到物料放置位的策略
String prefix = "BCQHW";
boolean result = StrUtil.startWithIgnoreCase(device_code, prefix);
if (result && StrUtil.isNotEmpty(next_code) && isFirst) {
next_device_code = next_code;
}
//物料放置位货物放到成品放置位策略
Device device = deviceAppService.findDeviceByCode(next_device_code);
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
@@ -688,6 +706,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
break;
} else {
next_device_code = "";
isFirst = false;
}
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
@@ -723,7 +742,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
try {
create(dto);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("任务生成失败");
// e.printStackTrace();
}
}
}
@@ -825,7 +845,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code))
|| ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) {
|| ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) {
throw new WDKException("已存在该起点或终点的任务!");
}
if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) {