@ -4,18 +4,22 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.nl.modules.common.exception.BadRequestException ;
import org.nl.modules.common.utils.SecurityUtils ;
import org.nl.modules.system.util.CodeUtil ;
import org.nl.modules.wql.core.bean.WQLObject ;
import org.nl.modules.wql.util.SpringContextHolder ;
import org.nl.wms.basedata.service.dto.VehicleDto ;
import org.nl.wms.ext.acs.service.AcsToWmsService ;
import org.nl.wms.log.LokiLog ;
import org.nl.wms.log.LokiLogType ;
import org.nl.wms.sch.manage.TaskStatusEnum ;
import org.nl.wms.sch.manage.WorkOrderEnum ;
import org.nl.wms.sch.service.TaskService ;
import org.nl.wms.sch.tasks.callEmpty.FjCallEmptyVehicleTask ;
import org.nl.wms.sch.tasks.callEmpty.HnCallEmptyVehicleTask ;
@ -391,6 +395,169 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
this . apply ( ( JSONObject ) jsonObject ) ;
}
/ * *
* ACS给WMS请求是否优先包装
*
* @param jsonObject
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public Map < String , Object > ispackage ( Map jsonObject ) {
String vehicle_code = ( String ) jsonObject . get ( "vehicle_code" ) ;
if ( StrUtil . isEmpty ( vehicle_code ) ) {
throw new BadRequestException ( "托盘条码不能为空!" ) ;
}
// 组盘表
JSONObject vehicleObj = WQLObject . getWQLObject ( "st_buss_vehiclegroup" ) . query ( "vehicle_code='" + vehicle_code + "'" ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( vehicleObj ) ) {
throw new BadRequestException ( "未找到托盘号为'" + vehicle_code + "'的组盘信息!" ) ;
}
// 获取工单
String workorder_id = vehicleObj . getString ( "producetask_id" ) ;
JSONObject taskObj = WQLObject . getWQLObject ( "PDM_BD_WorkOrder" ) . query ( "workorder_id='" + workorder_id + "'" ) . uniqueResult ( 0 ) ;
//1代表去出窑,2 是优先包装
String is_package = "1" ;
if ( StrUtil . equals ( taskObj . getString ( "is_package" ) , "1" ) ) {
is_package = "2" ;
}
JSONObject returnjo = new JSONObject ( ) ;
returnjo . put ( "is_package" , is_package ) ;
return returnjo ;
}
/ * *
* 获取空木托盘号
*
* @param jsonObject
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public Map < String , Object > getEmptyVehicle_code ( Map jsonObject ) {
//获取一个空的托盘号
String code = "VEHICCLE_CODE_MTP" ;
String vehicle_type = "03" ; // todo
WQLObject vehicle_table = WQLObject . getWQLObject ( "MD_PB_Vehicle" ) ;
VehicleDto dto = new VehicleDto ( ) ;
dto . setVehicle_id ( IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
String vehicle_code = CodeUtil . getNewCode ( code ) ;
Long currentUserId = SecurityUtils . getCurrentUserId ( ) ;
String nickName = SecurityUtils . getCurrentNickName ( ) ;
String now = DateUtil . now ( ) ;
dto . setVehicle_code ( vehicle_code ) ;
dto . setCreate_id ( currentUserId ) ;
dto . setVehicle_name ( vehicle_code ) ;
dto . setCreate_name ( nickName ) ;
dto . setUpdate_optid ( currentUserId ) ;
dto . setUpdate_optname ( nickName ) ;
dto . setUpdate_time ( now ) ;
dto . setCreate_time ( now ) ;
dto . setVehicle_type ( vehicle_type ) ;
JSONObject json = JSONObject . parseObject ( JSON . toJSONString ( dto ) ) ;
vehicle_table . insert ( json ) ;
JSONObject returnjo = new JSONObject ( ) ;
returnjo . put ( "vehicle_code" , vehicle_code ) ;
returnjo . put ( "status" , HttpStatus . OK . value ( ) ) ;
//将起点终点确定不下发的任务查出来,将木托盘点位解锁,起点改为扫描点,is_auto_issue 改为1,
String device_code = ( String ) jsonObject . get ( "device_code" ) ;
WQLObject task_Table = WQLObject . getWQLObject ( "SCH_BASE_Task" ) ;
JSONObject taskObj = task_Table . query ( "task_status='" + TaskStatusEnum . START_AND_POINT . getCode ( ) + "' and is_auto_issue='0'" , "create_time desc" ) . uniqueResult ( 0 ) ;
String start_point_code = taskObj . getString ( "point_code1" ) ;
WQLObject pointTable = WQLObject . getWQLObject ( "sch_base_point" ) ;
JSONObject startObj = pointTable . query ( "point_code ='" + start_point_code + "'" ) . uniqueResult ( 0 ) ;
startObj . put ( "lock_type" , "1" ) ;
pointTable . update ( startObj ) ;
taskObj . put ( "point_code1" , device_code ) ;
taskObj . put ( "is_auto_issue" , "1" ) ;
taskObj . put ( "vehicle_code" , vehicle_code ) ;
task_Table . update ( taskObj ) ;
return returnjo ;
}
/ * *
* 排产单确认
*
* @param jsonObject
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public Map < String , Object > sureWorkOrder ( Map jsonObject ) {
// 工单编号、设备编号、物料编号、数量、类型
String workorder_code = ( String ) jsonObject . get ( "workorder_code" ) ;
String device_code = ( String ) jsonObject . get ( "device_code" ) ;
String material_code = ( String ) jsonObject . get ( "material_code" ) ;
String qty = String . valueOf ( jsonObject . get ( "qty" ) ) ;
String type = ( String ) jsonObject . get ( "type" ) ;
if ( StrUtil . isEmpty ( type ) ) {
throw new BadRequestException ( "类型不能为空!" ) ;
}
WQLObject taskTable = WQLObject . getWQLObject ( "PDM_BD_WorkOrder" ) ;
JSONObject orderObj = taskTable . query ( "workorder_code = '" + workorder_code + "'" ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( orderObj ) ) {
throw new BadRequestException ( "未找到工单号为'" + workorder_code + "'的工单信息!" ) ;
}
JSONObject materialObj = WQLObject . getWQLObject ( "MD_ME_MaterialBase" ) . query ( "material_code = '" + material_code + "'" ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( materialObj ) ) throw new BadRequestException ( "当前物料不存在!" ) ;
//1为确认
//2为生产中
//3为完成
if ( StrUtil . equals ( type , "1" ) ) {
if ( StrUtil . isEmpty ( workorder_code ) ) {
throw new BadRequestException ( "工单号不能为空!" ) ;
}
if ( StrUtil . isEmpty ( device_code ) ) {
throw new BadRequestException ( "设备点位不能为空!" ) ;
}
if ( StrUtil . isEmpty ( material_code ) ) {
throw new BadRequestException ( "物料编码不能为空!" ) ;
}
if ( ! StrUtil . equals ( materialObj . getString ( "material_id" ) , orderObj . getString ( "material_id" ) ) ) {
throw new BadRequestException ( "物料标识不一样!" ) ;
}
orderObj . put ( "order_status" , WorkOrderEnum . ORDER_STATUS_DELIVERED . getCode ( ) ) ;
}
if ( StrUtil . equals ( "2" , type ) ) {
orderObj . put ( "producetask_status" , WorkOrderEnum . ORDER_STATUS_PRODUCING . getCode ( ) ) ;
}
if ( StrUtil . equals ( "3" , type ) ) {
orderObj . put ( "producetask_status" , WorkOrderEnum . ORDER_STATUS_FINISH . getCode ( ) ) ;
orderObj . put ( "real_qty" , qty ) ;
}
taskTable . update ( orderObj ) ;
JSONObject result = new JSONObject ( ) ;
result . put ( "status" , HttpStatus . OK . value ( ) ) ;
result . put ( "message" , "任务状态反馈成功!" ) ;
result . put ( "data" , new JSONObject ( ) ) ;
return result ;
}
/ * *
* 根据木托盘类型获取对应所在的点位
*
* @param jsonObject 条件
* @return Map < String , Object >
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public Map < String , Object > getDeviceCodeByVehicleType ( Map jsonObject ) {
String vehicle_type = ( String ) jsonObject . get ( "vehicle_type" ) ;
if ( StrUtil . isEmpty ( vehicle_type ) ) {
throw new BadRequestException ( "托盘类型不能为空!" ) ;
}
WQLObject point_table = WQLObject . getWQLObject ( "sch_base_point" ) ;
JSONObject pointObj = point_table . query ( "vehicle_type='" + vehicle_type + "' and region_code = 'FMQ'" ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( pointObj ) ) {
throw new BadRequestException ( "为找到类型为'" + vehicle_type + "' 的设备点位" ) ;
}
JSONObject returnjo = new JSONObject ( ) ;
returnjo . put ( "device_code" , pointObj . getString ( "point_code" ) ) ;
return returnjo ;
}
private JSONObject getProduceInfoByCode ( String code ) {
//根据 设备点位去找生产任务信息
//1 根据点位去找设备,去找对应的设备信息