@@ -4,15 +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.JSONObject ;
import com.alibaba.fastjson.serializer.SerializerFeature ;
import org.nl.modules.common.exception.BadRequestException ;
import org.nl.modules.common.utils.RedisUtils ;
import org.nl.modules.common.utils.SecurityUtils ;
import org.nl.modules.system.util.CodeUtil ;
import org.nl.modules.wql.WQL ;
import org.nl.modules.wql.core.bean.WQLObject ;
import org.nl.modules.wql.util.SpringContextHolder ;
import org.nl.wms.cockpit.constant.CockpitConstants ;
import org.nl.wms.common.PickType ;
import org.nl.wms.sch.manage.* ;
import java.util.regex.Pattern ;
/**
* 辽宁晟华任务工具类
*
@@ -21,12 +28,6 @@ import org.nl.wms.sch.manage.*;
*/
public class TaskUtils {
public static void isEmptyPoint ( JSONObject point ) {
if ( PointStatus . NOT_EMPTY . value ( ) . equals ( point . getString ( " point_status " ) ) ) {
throw new BadRequestException ( " [ " + point . getString ( " point_code " ) + " ] 上有货! " ) ;
}
}
public static void isNotEmptyPoint ( JSONObject point ) {
if ( PointStatus . EMPTY . value ( ) . equals ( point . getString ( " point_status " ) ) ) {
throw new BadRequestException ( " [ " + point . getString ( " point_code " ) + " ] 上无货! " ) ;
@@ -233,4 +234,95 @@ public class TaskUtils {
regionIn . put ( " cBatch " , order_code ) ;
return regionIn ;
}
// 字母表
static String [ ] alphabet = { " A " , " B " , " C " , " D " , " E " , " F " , " G " , " H " , " I " , " J " , " K " , " L " , " M " , " N " , " O " , " P " , " Q " , " R " , " S " , " T " , " U " , " V " , " W " , " X " , " Y " , " Z " } ;
// 喷码月份映射数组
static String [ ] month = { " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 0 " , " N " , " D " } ;
/**
* 生成喷码内容,祥见 SVN 项目文档信息。
*
* @param vd 组盘对象
* @param yjCode 压机编码
* @return 喷码内容
*/
public static String codingCode ( JSONObject vd , String yjCode ) {
try {
JSONObject material = WQLObject . getWQLObject ( " md_me_materialbase " ) . query ( " material_id = " + vd . getString ( " material_id " ) ) . uniqueResult ( 0 ) ;
// 使用部位2位。从物料编码截取使用部位。
String partUsed = material . getString ( " material_code " ) . substring ( 21 , 23 ) ;
// 砖型5位。一般砖型如"22/30"不需要处理,但如果'/'右边到达了3位数, 需要特殊处理成"1H"。
String brickType = material . getString ( " brick_type " ) ;
int slashIndex = brickType . lastIndexOf ( " / " ) ;
int brickTypeRight = Integer . parseInt ( brickType . substring ( slashIndex + 1 ) ) ;
if ( brickTypeRight > = 100 ) {
int brickTypeLeft = Integer . parseInt ( brickType . substring ( 0 , slashIndex ) ) ;
brickType = brickTypeLeft + " / " + " 1H " ;
}
// 压机号1位, A代表1号压机, 以此类推。从压机设备编码截取数字, 例如"YJ07"截取"07", 转换成数字后减去1即是压机对应字母在 alphabet 数组中的索引位置。
yjCode = alphabet [ Integer . parseInt ( Pattern . compile ( " [^0-9] " ) . matcher ( yjCode ) . replaceAll ( " " ) . trim ( ) ) - 1 ] ;
// 混料机号1位, A代表1号混料机, 以此类推。从混料机设备编码截取数字, 例如"HLJ07"截取"07", 转换成数字后减去1即是压机对应字母在 alphabet 数组中的索引位置。
JSONObject workOrder = WQLObject . getWQLObject ( " pdm_bd_workorder " ) . query ( " workorder_id = " + vd . getString ( " workorder_id " ) ) . uniqueResult ( 0 ) ;
String hljCode = alphabet [ Integer . parseInt ( Pattern . compile ( " [^0-9] " ) . matcher ( workOrder . getString ( " device_code " ) ) . replaceAll ( " " ) . trim ( ) ) - 1 ] ;
// 碾次2位。表里存储的是整数, 对于少于2位的数字 String 简单格式化即可。
String mixNum = String . format ( " %02d " , vd . getIntValue ( " mix_num " ) ) ;
// 日期3位, 第1位表示月, 超过1位的'0'表示10月, 'N'表示11月, 'D'表示12月, 后2位表示日, 对于少于2位的日 String 简单格式化即可。
String date = month [ DateUtil . thisMonth ( ) ] + String . format ( " %02d " , DateUtil . thisDayOfMonth ( ) ) ;
// 拼接字符串返回。
return partUsed + brickType + yjCode + hljCode + mixNum + date ;
} catch ( Exception ignore ) {
// 如果报错返回 null。
return null ;
}
}
public static void inKiln ( String vehicleCode ) {
if ( StrUtil . isBlank ( CockpitConstants . kilnData . get ( 0 ) ) ) {
CockpitConstants . kilnData . set ( 0 , vehicleCode ) ;
SpringContextHolder . getBean ( RedisUtils . class ) . set ( CockpitConstants . KILN_DATA_KEY , JSON . toJSONString ( CockpitConstants . kilnData , SerializerFeature . WriteMapNullValue ) ) ;
} else {
for ( int i = CockpitConstants . kilnData . size ( ) - 1 ; i > 0 ; i - - ) {
CockpitConstants . kilnData . set ( i , CockpitConstants . kilnData . get ( i - 1 ) ) ;
}
CockpitConstants . kilnData . set ( 0 , vehicleCode ) ;
SpringContextHolder . getBean ( RedisUtils . class ) . set ( CockpitConstants . KILN_DATA_KEY , JSON . toJSONString ( CockpitConstants . kilnData , SerializerFeature . WriteMapNullValue ) ) ;
}
}
public static void outKiln ( String vehicleCode ) {
if ( vehicleCode . equals ( CockpitConstants . kilnData . get ( CockpitConstants . kilnData . size ( ) - 1 ) ) ) {
for ( int i = CockpitConstants . kilnData . size ( ) - 1 ; i > 0 ; i - - ) {
CockpitConstants . kilnData . set ( i , CockpitConstants . kilnData . get ( i - 1 ) ) ;
}
CockpitConstants . kilnData . set ( 0 , null ) ;
SpringContextHolder . getBean ( RedisUtils . class ) . set ( CockpitConstants . KILN_DATA_KEY , JSON . toJSONString ( CockpitConstants . kilnData , SerializerFeature . WriteMapNullValue ) ) ;
}
}
public static void inCooling ( String vehicleCode ) {
for ( int i = CockpitConstants . coolingData . size ( ) - 1 ; i > 0 ; i - - ) {
CockpitConstants . coolingData . set ( i , CockpitConstants . coolingData . get ( i - 1 ) ) ;
}
CockpitConstants . coolingData . set ( 0 , vehicleCode ) ;
SpringContextHolder . getBean ( RedisUtils . class ) . set ( CockpitConstants . COOLING_DATA_KEY , JSON . toJSONString ( CockpitConstants . coolingData , SerializerFeature . WriteMapNullValue ) ) ;
}
public static void outCooling ( String vehicleCode ) {
if ( vehicleCode . equals ( CockpitConstants . coolingData . get ( CockpitConstants . coolingData . size ( ) - 1 ) ) ) {
for ( int i = CockpitConstants . coolingData . size ( ) - 1 ; i > 0 ; i - - ) {
CockpitConstants . coolingData . set ( i , CockpitConstants . coolingData . get ( i - 1 ) ) ;
}
CockpitConstants . coolingData . set ( 0 , null ) ;
SpringContextHolder . getBean ( RedisUtils . class ) . set ( CockpitConstants . COOLING_DATA_KEY , JSON . toJSONString ( CockpitConstants . coolingData , SerializerFeature . WriteMapNullValue ) ) ;
}
}
}