@ -3,16 +3,25 @@ package org.nl.b_lms.sch.tasks;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.IdUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper ;
import org.apache.commons.lang3.StringUtils ;
import org.nl.b_lms.sch.task.dao.SchBaseTask ;
import org.nl.b_lms.sch.task.dto.SchBaseTaskVO ;
import org.nl.b_lms.sch.task.service.IschBaseTaskService ;
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum ;
import org.nl.common.enums.PackageInfoIvtEnum ;
import org.nl.common.utils.SecurityUtils ;
import org.nl.modules.common.exception.BadRequestException ;
import org.nl.modules.wql.core.bean.WQLObject ;
import org.nl.wms.sch.AcsTaskDto ;
import org.nl.wms.sch.manage.AbstractAcsTask ;
import org.nl.wms.sch.manage.TaskStatusEnum ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
@ -29,6 +38,9 @@ import static org.nl.wms.util.TaskUtil.getRoutePlanCode;
@Service
public class TwoInBoxTrussTask extends AbstractAcsTask {
@Autowired
private IschBaseTaskService ischBaseTaskService ;
/ * *
* 处理类
* /
@ -39,29 +51,31 @@ public class TwoInBoxTrussTask extends AbstractAcsTask {
/ *
* 下发给ACS时需要特殊处理
* /
JSONArray arr = WQLObject . getWQLObject ( "SCH_BASE_Task" ) . query ( "handle_class = '" + THIS_CLASS + "' and task_status = '" + TaskStatusEnum . START_AND_POINT . getCode ( ) + "' and is_delete ='0'" ) . getResultJSONArray ( 0 ) ;
List < SchBaseTask > task_list = ischBaseTaskService . list ( new LambdaQueryWrapper < SchBaseTask > ( )
. eq ( SchBaseTask : : getHandle_class , THIS_CLASS )
. eq ( SchBaseTask : : getTask_status , TaskStatusEnum . START_AND_POINT . getCode ( ) )
. eq ( SchBaseTask : : getIs_delete , "0" ) ) ;
ArrayList < AcsTaskDto > resultList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < arr . size ( ) ; i + + ) {
JSONObject json = arr . getJSONObject ( i ) ;
//JSONObject params = json.getJSONObject("params");
char dtl_type = json . getString ( "task_type" ) . charAt ( json . getString ( "task_type" ) . length ( ) - 1 ) ;
for ( int i = 0 ; i < task_list . size ( ) ; i + + ) {
SchBaseTask task = task_list . get ( i ) ;
char dtl_type = task . getTask_type ( ) . charAt ( task . getTask_type ( ) . length ( ) - 1 ) ;
AcsTaskDto dto = AcsTaskDto . builder ( )
. ext_task_id ( json . getString ( "task_id" ) )
. task_code ( json . getString ( "task_code" ) )
. task_type ( json . getString ( "acs_task_type" ) )
. start_device_code ( json . getString ( "point_code1" ) )
. next_device_code ( json . getString ( "point_code2" ) )
. route_plan_code ( getRoutePlanCode ( json . getString ( "point_code2" ) ) )
. vehicle_code ( json . getString ( "vehicle_code" ) )
. priority ( json . getString ( "priority" ) )
. ext_task_id ( task . getTask_id ( ) )
. task_code ( task . getTask_code ( ) )
. task_type ( task . getAcs_task_type ( ) )
. start_device_code ( task . getPoint_code1 ( ) )
. next_device_code ( task . getPoint_code2 ( ) )
. route_plan_code ( getRoutePlanCode ( task . getPoint_code2 ( ) ) )
. vehicle_code ( task . getVehicle_code ( ) )
. priority ( task . getPriority ( ) )
. class_type ( IOSEnum . ACS_TYPE . code ( "木箱入库行架任务" ) )
. dtl_type ( String . valueOf ( dtl_type ) )
. interaction_json ( json . getJSONObject ( "request_param" ) )
. remark ( json . getString ( "remark" ) )
. interaction_json ( ( JSONObject ) JSONObject . parse ( task . getRequest_param ( ) ) )
. remark ( task . getRemark ( ) )
. product_area ( IOSEnum . PRODUCT_AREA . code ( "BLK" ) )
. build ( ) ;
dto . setClass_type ( json . getString ( "point_code1" ) . equals ( IOSEnum . POINT_CODE . code ( "退货入库位" ) )
dto . setClass_type ( task . getPoint_code1 ( ) . equals ( IOSEnum . POINT_CODE . code ( "退货入库位" ) )
? IOSEnum . ACS_TYPE . code ( "退货入库行架任务" ) : IOSEnum . ACS_TYPE . code ( "木箱入库行架任务" )
) ;
@ -73,43 +87,34 @@ public class TwoInBoxTrussTask extends AbstractAcsTask {
@Override
@Transactional ( rollbackFor = Exception . class )
public void updateTaskStatus ( JSONObject taskObj , String status ) {
// 任务表
WQLObject taskTab = WQLObject . getWQLObject ( "sch_base_task" ) ;
// 更新任务的参数
JSONObject map = new JSONObject ( ) ;
SchBaseTask task = new SchBaseTask ( ) ;
/ *
* 1 - 执行中 , 2 - 完成 , 0 - acs取消
* /
// 执行中
if ( status . equals ( TaskStatusEnum . EXECUTING . getCode ( ) ) ) {
map . put ( "task_status" , TaskStatusEnum . EXECUTING . getCode ( ) ) ;
task . setTask_status ( TaskStatusEnum . EXECUTING . getCode ( ) ) ;
}
// 完成
if ( status . equals ( TaskStatusEnum . FINISHED . getCode ( ) ) ) {
map . put ( "task_status" , TaskStatusEnum . FINISHED . getCode ( ) ) ;
task . setTask_status ( TaskStatusEnum . FINISHED . getCode ( ) ) ;
}
// 取消
if ( status . equals ( IOSEnum . IS_NOTANDYES . code ( "否" ) ) ) {
if ( taskObj . getIntValue ( "task_status" ) > Integer . valueOf ( TaskStatusEnum . ISSUE . getCode ( ) ) ) {
throw new BadRequestException ( "任务已执行不能取消" ) ;
}
// 更新任务表删除字段
map . put ( "is_delete" , IOSEnum . IS_NOTANDYES . code ( "是" ) ) ;
task . setIs_delete ( IOSEnum . IS_NOTANDYES . code ( "是" ) ) ;
}
map . put ( "update_optid" , SecurityUtils . getCurrentUserId ( ) ) ;
map . put ( "update_optname" , SecurityUtils . getCurrentNickName ( ) ) ;
map . put ( "update_time" , DateUtil . now ( ) ) ;
WQLObject . getWQLObject ( "SCH_BASE_Task" ) . update ( map , "task_id = '" + taskObj . getString ( "task_id" ) + "'" ) ;
task . setUpdate_optid ( SecurityUtils . getCurrentUserId ( ) ) ;
task . setUpdate_optname ( SecurityUtils . getCurrentNickName ( ) ) ;
task . setUpdate_time ( DateUtil . now ( ) ) ;
ischBaseTaskService . update ( task , new LambdaUpdateWrapper < SchBaseTask > ( ) . eq ( SchBaseTask : : getTask_id , task . getTask_id ( ) ) ) ;
}
@Override
@ -138,39 +143,44 @@ public class TwoInBoxTrussTask extends AbstractAcsTask {
throw new BadRequestException ( "终点不能为空!" ) ;
}
JSONObject json = new JSONObject ( ) ;
json . put ( "task_id" , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
json . put ( "task_code" , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
json . put ( "task_type" , form . getString ( "task_type" ) ) ;
json . put ( "vehicle_code" , form . getString ( "vehicle_code" ) ) ;
json . put ( "vehicle_code2" , form . getString ( "vehicle_code2" ) ) ;
json . put ( "vehicle_type" , form . getString ( "vehicle_type" ) ) ;
json . put ( "task_status" , TaskStatusEnum . START_AND_POINT . getCode ( ) ) ;
json . put ( "task_group_id" , form . getLongValue ( "task_group_id" ) ) ;
json . put ( "point_code1" , form . getString ( "start_device_code" ) ) ;
json . put ( "point_code2" , form . getString ( "next_device_code" ) ) ;
json . put ( "product_area" , "BLK" ) ;
json . put ( "handle_class" , this . getClass ( ) . getName ( ) ) ;
json . put ( "create_id" , SecurityUtils . getCurrentUserId ( ) ) ;
json . put ( "create_name" , SecurityUtils . getCurrentUsername ( ) ) ;
json . put ( "create_time" , DateUtil . now ( ) ) ;
json . put ( "priority" , "1" ) ;
json . put ( "acs_task_type" , "6" ) ;
json . put ( "request_param" , form . getString ( "request_param" ) ) ;
WQLObject . getWQLObject ( "SCH_BASE_Task" ) . insert ( json ) ;
return json . getString ( "task_id" ) ;
SchBaseTaskVO schBaseTaskVo = SchBaseTaskVO . builder ( )
. task_id ( org . nl . common . utils . IdUtil . getStringId ( ) )
. task_code ( org . nl . common . utils . IdUtil . getStringId ( ) )
. task_type ( form . getString ( "task_type" ) )
. vehicle_code ( form . getString ( "vehicle_code" ) )
//二次分配要用的类型
. vehicle_code2 ( form . getString ( "vehicle_code2" ) )
. vehicle_type ( form . getString ( "vehicle_type" ) )
. task_status ( TaskStatusEnum . START_AND_POINT . getCode ( ) )
. task_group_id ( form . getString ( "task_group_id" ) )
. point_code1 ( form . getString ( "start_device_code" ) )
. point_code2 ( form . getString ( "next_device_code" ) )
. product_area ( "BLK" )
. handle_class ( THIS_CLASS )
. create_id ( SecurityUtils . getCurrentUserId ( ) )
. create_name ( SecurityUtils . getCurrentUsername ( ) )
. create_time ( DateUtil . now ( ) )
. priority ( "1" )
. acs_task_type ( StrUtil . isEmpty ( form . getString ( "acs_task_type" ) ) ? PackageInfoIvtEnum . ACS_TASK_TYPE . code ( "桁架任务" ) : form . getString ( "acs_task_type" ) )
. request_param ( form . getString ( "request_param" ) )
. build ( ) ;
SchBaseTask task = new SchBaseTask ( ) ;
BeanUtils . copyProperties ( schBaseTaskVo , task ) ;
ischBaseTaskService . save ( task ) ;
return task . getTask_id ( ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void forceFinish ( String task_id ) {
JSONObject taskObj = WQLObject . getWQLObject ( "SCH_BASE_Task" ) . query ( "task_id = '" + task_id + "'" ) . uniqueResult ( 0 ) ;
this . updateTaskStatus ( taskObj , TaskStatusEnum . FINISHED . getCode ( ) ) ;
SchBaseTask task_jo = ischBaseTaskService . getOne ( new LambdaQueryWrapper < SchBaseTask > ( ) . eq ( SchBaseTask : : getTask_id , task_id ) ) ;
updateTaskStatus ( JSONObject . parseObject ( JSON . toJSONString ( task_jo ) ) , TaskStatusEnum . FINISHED . getCode ( ) ) ;
}
@Override
public void cancel ( String task_id ) {
JSONObject taskObj = WQLObject . getWQLObject ( "SCH_BASE_Task" ) . query ( "task_id = '" + task_id + "'" ) . uniqueResult ( 0 ) ;
this . updateTaskStatus ( taskObj , IOSEnum . ACS_RESULT . code ( "取消" ) ) ;
SchBaseTask task_jo = ischBaseTaskService . getOne ( new LambdaQueryWrapper < SchBaseTask > ( ) . eq ( SchBaseTask : : getTask_id , task_id ) ) ;
updateTaskStatus ( JSONObject . parseObject ( JSON . toJSONString ( task_jo ) ) , IOSEnum . ACS_RESULT . code ( "取消" ) ) ;
}
}