@@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor ;
import lombok.Synchronized ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.ObjectUtils ;
import org.nl.acs.AcsConfig ;
import org.nl.acs.agv.server.XianGongAgvService ;
import org.nl.acs.auto.initial.ApplicationAutoInitial ;
@@ -100,6 +101,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
}
@Override
public synchronized void reload ( ) {
List list = this . queryAll ( " task_status <2 and is_delete =0 order by create_time " ) ;
@@ -373,6 +375,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return list ;
}
@Override
public List < TaskDto > queryTaskByStartAndIntStatus ( String head_start_device_code ) {
List < TaskDto > list = new ArrayList < > ( ) ;
Iterator < TaskDto > iterator = tasks . iterator ( ) ;
@@ -393,6 +396,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return list ;
}
@Override
public List < TaskDto > queryTaskByNextAndIntStatus ( String back_start_device_code ) {
List < TaskDto > list = new ArrayList < > ( ) ;
Iterator < TaskDto > iterator = tasks . iterator ( ) ;
@@ -732,10 +736,14 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
@Transactional ( rollbackFor = Exception . class )
public void finish ( String id ) {
TaskDto entity = this . findById ( id ) ;
if ( entity = = null ) throw new BadRequestException ( " 被删除或无权限,操作失败! " ) ;
if ( entity = = null ) {
throw new BadRequestException ( " 被删除或无权限,操作失败! " ) ;
}
InstructionService instructionservice = SpringContextHolder . getBean ( " instructionServiceImpl " ) ;
InstructionDto instdto = instructionservice . findByTaskid ( id , " instruction_status <2 " ) ;
if ( instdto ! = null ) throw new BadRequestException ( " 有指令未完成! " ) ;
if ( instdto ! = null ) {
throw new BadRequestException ( " 有指令未完成! " ) ;
}
String currentUsername = SecurityUtils . getCurrentUsername ( ) ;
String now = DateUtil . now ( ) ;
entity . setUpdate_time ( now ) ;
@@ -782,6 +790,161 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
}
public void finish1 ( String id ) {
TaskDto entity = this . findById ( id ) ;
if ( entity = = null ) {
throw new BadRequestException ( " 被删除或无权限,操作失败! " ) ;
}
InstructionService instructionservice = SpringContextHolder . getBean ( " instructionServiceImpl " ) ;
InstructionDto instdto = instructionservice . findByTaskid ( id , " instruction_status <2 " ) ;
if ( instdto ! = null ) {
throw new BadRequestException ( " 有指令未完成! " ) ;
}
String currentUsername = SecurityUtils . getCurrentUsername ( ) ;
String now = DateUtil . now ( ) ;
entity . setUpdate_time ( now ) ;
entity . setUpdate_by ( currentUsername ) ;
entity . setTask_status ( " 2 " ) ;
WQLObject wo = WQLObject . getWQLObject ( " acs_task " ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( entity ) ;
wo . update ( json ) ;
removeByCodeFromCache ( entity . getTask_code ( ) ) ;
// 判断是否为WMS下发的任务, 如果是反馈任务状态给WMS
// String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
// if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) {
// TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code());
// System.out.println(feefbackdto == null);
// JSONObject feed_jo = new JSONObject();
// feed_jo.put("task_id", entity.getTask_id());
// feed_jo.put("task_code", entity.getTask_code());
// feed_jo.put("task_status", entity.getTask_status());
// JSONArray ja = new JSONArray();
// ja.add(feed_jo);
//
// try {
// JSONObject request1 = new JSONObject();
// request1.put("REQCODE", entity.getExt_task_id());
// request1.put("TASKCODE", entity.getTask_code());
// request1.put("PODCODE", entity.getVehicle_code());
// request1.put("TASKTYPE", entity.getTask_type());
// request1.put("METHOD", "3");
// request1.put("REQTIME", DateUtil.now());
// log.info("atrAgvCallback 请求参数:" + request1.toString());
// String str1 = new RTMSAGVSERVICE().getBasicHttpBindingIRTMSAGVSERVICE().atrAgvCallback(request1.toJSONString());
// log.info("atrAgvCallback 返回参数:" + str1);
//
// JSONObject request = new JSONObject();
// request.put("REQCODE", entity.getExt_task_id());
// request.put("TASKCODE", entity.getTask_code());
// request.put("PODCODE", entity.getVehicle_code());
// request.put("TASKTYPE", entity.getTask_type());
// request.put("METHOD", "5");
// request.put("REQTIME", DateUtil.now());
// log.info("atrAgvCallback 请求参数:" + request.toString());
// String str = new RTMSAGVSERVICE().getBasicHttpBindingIRTMSAGVSERVICE().atrAgvCallback(request.toJSONString());
// log.info("atrAgvCallback 返回参数:" + str);
// } catch (Exception e) {
// e.printStackTrace();
// throw new BadRequestException(e.getMessage());
// }
// }
// 如果属于先知AGV, 关闭运单序列
if ( StrUtil . equals ( paramService . findByCode ( AcsConfig . AGVTYPE ) . getValue ( ) , " 3 " ) ) {
try {
agvService . markComplete ( entity . getTask_code ( ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
}
@Override
public void forceFinish ( String ids ) throws Exception {
TaskDto dto = this . findById ( ids ) ;
if ( dto = = null ) {
throw new BadRequestException ( " 权限不足,操作失败 " ) ;
}
Instruction entity = instructionService . findByTaskid ( ids , " instruction_status <2 " ) ;
if ( entity ! = null ) {
String currentUsername = SecurityUtils . getCurrentUsername ( ) ;
String now = DateUtil . now ( ) ;
entity . setUpdate_time ( now ) ;
entity . setUpdate_by ( currentUsername ) ;
entity . setInstruction_status ( " 2 " ) ;
WQLObject wo = WQLObject . getWQLObject ( " acs_instruction " ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( entity ) ;
wo . update ( json ) ;
removeByCodeFromCache ( entity . getInstruction_code ( ) ) ;
}
String instnextdevice = dto . getNext_device_code ( ) ;
WQLObject taskwo = WQLObject . getWQLObject ( " acs_task " ) ;
DeviceAppService appService = SpringContextHolder . getBean ( DeviceAppServiceImpl . class ) ;
Device startdevice = appService . findDeviceByCode ( entity . getStart_device_code ( ) ) ;
if ( ObjectUtils . isEmpty ( startdevice ) ) {
log . debug ( " 地址对应设备未找到 " ) ;
throw new BadRequestException ( " 地址对应设备未找到 " ) ;
}
if ( instnextdevice . indexOf ( " . " ) ! = - 1 ) {
instnextdevice = instnextdevice . substring ( 0 , instnextdevice . indexOf ( " . " ) ) ;
}
Device device = appService . findDeviceByCode ( instnextdevice ) ;
if ( device = = null ) {
log . debug ( " 地址对应设备未找到 " ) ;
throw new BadRequestException ( " 地址对应设备未找到 " ) ;
}
DeviceService deviceService = SpringContextHolder . getBean ( DeviceServiceImpl . class ) ;
JSONObject jo1 = new JSONObject ( ) ;
jo1 . put ( " device_code " , instnextdevice ) ;
String start_device_code = entity . getStart_device_code ( ) ;
Device deviceByCode = deviceAppService . findDeviceByCode ( start_device_code ) ;
if ( deviceByCode = = null ) {
log . debug ( " 地址对应设备未找到 " ) ;
throw new BadRequestException ( " 地址对应设备未找到 " ) ;
}
jo1 . put ( " hasGoodStatus " , " 1 " ) ;
jo1 . put ( " material_type " , startdevice . getMaterial_type ( ) ) ;
jo1 . put ( " quantity " , startdevice . getQuantity ( ) ) ;
jo1 . put ( " remark " , startdevice . getRemark ( ) ) ;
jo1 . put ( " batch " , startdevice . getBatch ( ) ) ;
jo1 . put ( " vehicle_code " , entity . getVehicle_code ( ) ) ;
jo1 . put ( " islock " , " 0 " ) ;
jo1 . put ( " barrels_code " , startdevice . getBarrels_code ( ) ) ;
jo1 . put ( " cooperate_code " , startdevice . getCooperate_code ( ) ) ;
jo1 . put ( " powder_name " , startdevice . getPowder_name ( ) ) ;
jo1 . put ( " barrels_status " , startdevice . getBarrels_status ( ) ) ;
deviceService . changeDeviceStatus ( jo1 ) ;
// 如果是无光电的设备 指令完成变更起点、终点状态
JSONObject jo = new JSONObject ( ) ;
jo . put ( " device_code " , entity . getStart_device_code ( ) ) ;
jo . put ( " hasGoodStatus " , " 0 " ) ;
jo . put ( " material_type " , " " ) ;
jo . put ( " quantity " , " " ) ;
jo . put ( " remark " , " " ) ;
jo . put ( " batch " , " " ) ;
jo . put ( " islock " , " 0 " ) ;
deviceService . changeDeviceStatus ( jo ) ;
JSONObject taskjson = taskwo . query ( " task_id =' " + ids + " ' " ) . uniqueResult ( 0 ) ;
TaskDto obj = taskjson . toJavaObject ( TaskDto . class ) ;
// =0 则不用再次请求
if ( StrUtil . equals ( obj . getRequest_again ( ) , " 0 " ) ) {
if ( StrUtil . equals ( obj . getNext_device_code ( ) , instnextdevice ) ) {
this . finish1 ( obj . getTask_id ( ) ) ;
} else {
instructionService . finishAndCreateNextInst ( entity ) ;
}
}
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void cancel ( String id ) {
@@ -1164,6 +1327,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return tasks ;
}
@Override
public TaskDto findByContainer ( String container_code ) {
Iterator var3 = tasks . iterator ( ) ;
@@ -1177,6 +1341,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return null ;
}
@Override
public TaskDto findByCodeFromCache ( String task_code ) {
Iterator var3 = tasks . iterator ( ) ;