@ -3,6 +3,7 @@ package org.nl.wms.sch.task_manage.task.tasks.fj;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.IdUtil ;
import cn.hutool.core.util.ObjectUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import org.nl.common.exception.BadRequestException ;
@ -22,6 +23,7 @@ import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.enums.* ;
import org.nl.wms.sch.task_manage.task.TaskType ;
import org.nl.wms.sch.task_manage.task.core.TaskStatus ;
import org.nl.wms.sch.task_manage.task.tasks.fj.mapper.FJMapper ;
import org.nl.wms.util.PointUtils ;
import org.nl.wms.util.TaskUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -53,6 +55,8 @@ public class FJRKTask extends AbstractTask {
private IPdmBdWorkorderService workorderService ;
@Autowired
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService ;
@Autowired
private FJMapper fjMapper ;
@Override
protected void create ( ) throws BadRequestException {
// 最后一坨不需要呼叫空盘
@ -95,25 +99,91 @@ public class FJRKTask extends AbstractTask {
// 配置信息
SchBaseTaskconfig taskConfig = taskConfigService . getOne ( new LambdaQueryWrapper < SchBaseTaskconfig > ( )
. eq ( SchBaseTaskconfig : : getConfig_code , TASK_CONFIG_CODE ) ) ;
String requestParam = task . getRequest_param ( ) ; // 任务的其他数据
JSONObject jsonObject = JSONObject . parseObject ( requestParam ) ;
String workOrderCode = jsonObject . getString ( "workorder_code" ) ; // 工单
PdmBdWorkorder workorder = workorderService . getByCode ( workOrderCode ) ;
TaskUtils . setUpdateByAcs ( task ) ;
List < String > nextRegionStr = Arrays . stream ( taskConfig . getNext_region_str ( ) . split ( "," ) ) . collect ( Collectors . toList ( ) ) ;
List < String > startRegionStr = Arrays . stream ( taskConfig . getStart_region_str ( ) . split ( "," ) ) . collect ( Collectors . toList ( ) ) ;
// 找终点
SchBasePoint point = findNextPoint ( nextRegionStr ) ;
if ( ObjectUtil . isEmpty ( point ) ) {
SchBasePoint packageP oint = findNextPoint ( nextRegionStr ) ;
if ( ObjectUtil . isEmpty ( packageP oint ) ) {
// 消息通知
noticeService . createNotice ( "找不到可用的包装位!" , TASK_CONFIG_CODE + task . getPoint_code1 ( ) ,
NoticeTypeEnum . WARN . getCode ( ) ) ;
throw new BadRequestException ( "找不到可用的包装位!" ) ;
}
// 设置终点并修改创建成功状态
task . setPoint_code2 ( point . getPoint_code ( ) ) ;
task . setPoint_code2 ( packagePoint . getPoint_code ( ) ) ;
// 1 剩余量
Integer surplusQuantity = jsonObject . getInteger ( "surplus_quantity" ) ; // 码垛上剩余数量
// 2 获取库存量 surplusNumber
int surplusNumber = fjMapper . getInventoryQuantity ( workorder . getMaterial_id ( ) ) ;
// 3 现有总数 total
int total = surplusNumber + surplusQuantity ;
// 4 获取木托盘需要多少块 needFullNumber
String needFullNumberStr = fjMapper . getNeedFullNumber ( workorder . getMaterial_id ( ) ) ;
int needFullNumber = TaskUtils . convertMultiply ( needFullNumberStr ) ;
// 5 校验是否够码满一托
// 大于等于1就可以码
if ( total / needFullNumber > = 1 ) {
/** 覆膜机木托盘位 */
SchBasePoint LaminatePoint = findStartPoint ( startRegionStr , jsonObject ) ;
if ( ObjectUtil . isEmpty ( LaminatePoint ) ) {
noticeService . createNotice ( "覆膜区不可用!" , TASK_CONFIG_CODE + task . getPoint_code1 ( ) ,
NoticeTypeEnum . WARN . getCode ( ) ) ;
// 消息通知
throw new BadRequestException ( "覆膜区不可用!" ) ;
}
// 把这个设备位放到任务中
JSONObject response = new JSONObject ( ) ;
String responseParam = task . getResponse_param ( ) ;
if ( ObjectUtil . isNotEmpty ( responseParam ) ) {
response = JSON . parseObject ( responseParam ) ;
}
response . put ( "fmj_device" , LaminatePoint . getPoint_code ( ) ) ;
// 生产木托盘编码
// 设置终点并修改创建成功状态
task . setPoint_code3 ( LaminatePoint . getParent_point_code ( ) ) ;
task . setPoint_code4 ( task . getPoint_code1 ( ) ) ;
task . setResponse_param ( response . toJSONString ( ) ) ;
// 覆膜机对接位上锁
SchBasePoint basePoint = pointService . getById ( LaminatePoint . getParent_point_code ( ) ) ;
basePoint . setIng_task_code ( task . getTask_code ( ) ) ;
PointUtils . setUpdateByAcs ( basePoint ) ;
pointService . updateById ( basePoint ) ;
}
task . setTask_status ( TaskStatus . CREATED . getCode ( ) ) ;
task . setRemark ( "" ) ;
taskService . save ( task ) ;
// todo 判断是否够码满一垛,够就叫空盘,否则就是两点任务
point . setIng_task_code ( task . getTask_code ( ) ) ;
PointUtils . setUpdateByAcs ( point ) ;
pointService . updateById ( point ) ;
// 包装线上锁
packagePoint . setIng_task_code ( task . getTask_code ( ) ) ;
PointUtils . setUpdateByAcs ( packagePoint ) ;
pointService . updateById ( packagePoint ) ;
}
/ * *
* 从覆膜区找个空木托盘
* @param startRegionStr
* @param extData
* @return
* /
private SchBasePoint findStartPoint ( List < String > startRegionStr , JSONObject extData ) {
// 当前设备的工单
String workorderCode = extData . getString ( "workorder_code" ) ;
PdmBdWorkorder one = ObjectUtil . isNotEmpty ( workorderCode )
? workorderService . getOne ( new LambdaQueryWrapper < PdmBdWorkorder > ( )
. eq ( PdmBdWorkorder : : getWorkorder_code , workorderCode ) )
: null ;
if ( one = = null ) {
throw new BadRequestException ( "工单不能为空!" ) ;
}
String vehicleType = one . getVehicle_type ( ) ;
// 向ACS请求所需木托盘在那个栈拆盘机?已经实时更新,故只需要自己查询即可
SchBasePoint endPointObj = fjMapper . findPointForFJQK ( startRegionStr , new JSONObject ( )
. fluentPut ( "vehicleType" , vehicleType ) . fluentPut ( "pointType" , GeneralDefinition . DEVICE_POINT ) ) ;
// 这个点的父点位为起点
return ObjectUtil . isNotEmpty ( endPointObj ) ? endPointObj : null ;
}
/ * *