@ -35,6 +35,7 @@ import org.nl.hand.amb.service.HFHandService;
import org.nl.modules.common.config.RsaProperties ;
import org.nl.modules.common.exception.BadRequestException ;
import org.nl.modules.common.utils.RsaUtils ;
import org.nl.modules.system.service.DictService ;
import org.nl.modules.system.service.UserService ;
import org.nl.modules.system.service.dto.UserDto ;
import org.nl.modules.system.util.CodeUtil ;
@ -59,6 +60,7 @@ public class HFHandServiceImpl implements HFHandService {
private final UserService userService ;
private final DeviceService deviceService ;
private final DeviceAppService deviceAppService ;
private final DictService dictService ;
InstructionService instructionService = null ;
@ -73,123 +75,41 @@ public class HFHandServiceImpl implements HFHandService {
}
@Override
public Map < String , Object > queryPointByArea ( String dict_id ) {
JSONArray resultArr = new JSONArray ( ) ;
JSONObject resultJson = new JSONObject ( ) ;
JSONObject jo = new JSONObject ( ) ;
public Map < String , Object > queryPointByArea ( String region ) {
if ( StrUtil . isEmpty ( dict_id ) ) {
throw new BadRequestException ( "区域id不能为空!" ) ;
}
String value = "" ;
String move = "" ;
String status = "" ;
String input_material = "0" ;
String allow_update = "" ;
String material = "" ;
String batch = "" ;
//再字典中查询出value
//JSONObject valuejo = WQLObject.getWQLObject("sys_dict_detail").query("detail_id='" + dict_id + "'").uniqueResult(0);
JSONObject valuejo = WQL . getWO ( "QJN_QUERY001" ) . addParam ( "flag" , "3" ) . addParam ( "detail_id" , dict_id ) . process ( ) . uniqueResult ( 0 ) ;
if ( ! ObjectUtil . isEmpty ( valuejo ) ) {
value = valuejo . getString ( "value" ) ;
}
//根据value值去查所有的设备
JSONArray acs_deviceja = WQLObject . getWQLObject ( "ACS_DEVICE" ) . query ( "region='" + value + "' and device_type='conveyor' and is_config='true' " , "seq_num,device_name" ) . getResultJSONArray ( 0 ) ;
for ( int i = 0 ; i < acs_deviceja . size ( ) ; i + + ) {
JSONObject devicejo = acs_deviceja . getJSONObject ( i ) ;
String device_code = devicejo . getString ( "device_code" ) ;
DeviceAppService appService = SpringContextHolder . getBean ( DeviceAppServiceImpl . class ) ;
Device device = appService . findDeviceByCode ( device_code ) ;
//无光电普通站点
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver ;
//检测站点
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver ;
if ( device . getDeviceDriver ( ) instanceof StandardOrdinarySiteDeviceDriver ) {
standardOrdinarySiteDeviceDriver = ( StandardOrdinarySiteDeviceDriver ) device . getDeviceDriver ( ) ;
if ( StrUtil . equals ( device . getIslock ( ) , "true" ) ) {
status = "3" ;
move = "有任务" ;
} else {
if ( standardOrdinarySiteDeviceDriver . getHasGoods ( ) = = 0 ) {
status = "0" ;
move = "无货" ;
} else if ( standardOrdinarySiteDeviceDriver . getHasGoods ( ) = = 1 ) {
status = "1" ;
move = "有托盘" ;
} else if ( standardOrdinarySiteDeviceDriver . getHasGoods ( ) = = 2 ) {
status = "2" ;
move = "有托盘有货" ;
}
}
if ( StrUtil . isEmpty ( region ) ) {
throw new BadRequestException ( "区域不能为空!" ) ;
}
material = device . getMaterial_type ( ) ;
//material = standardOrdinarySiteDeviceDriver.getMaterial();
if ( StrUtil . isNullOrUndefined ( material ) ) {
material = "" ;
}
batch = device . getBatch ( ) ;
//batch = standardOrdinarySiteDeviceDriver.getBatch();
if ( StrUtil . isNullOrUndefined ( batch ) ) {
batch = "" ;
}
String input_materialflag = ( String ) device . getExtraValue ( ) . get ( "input_material" ) ;
if ( ! StrUtil . isEmpty ( input_materialflag ) & & input_materialflag . equals ( "false" ) ) {
input_material = "0" ;
}
if ( ! StrUtil . isEmpty ( input_materialflag ) & & input_materialflag . equals ( "true" ) ) {
input_material = "1" ;
}
jo . put ( "material_type" , material ) ;
jo . put ( "batch" , batch ) ;
jo . put ( "islock" , device . getIslock ( ) ) ;
jo . put ( "status_name" , move ) ;
jo . put ( "status" , status ) ;
jo . put ( "device_id" , devicejo . getString ( "device_id" ) ) ;
jo . put ( "device_code" , devicejo . getString ( "device_code" ) ) ;
jo . put ( "device_name" , devicejo . getString ( "device_name" ) ) ;
jo . put ( "allow_update" , "1" ) ;
jo . put ( "input_material" , input_material ) ;
// 特殊驱动
}
//检测站点
else if ( device . getDeviceDriver ( ) instanceof StandardInspectSiteDeviceDriver ) {
standardInspectSiteDeviceDriver = ( StandardInspectSiteDeviceDriver ) device . getDeviceDriver ( ) ;
if ( StrUtil . equals ( device . getIslock ( ) , "true" ) ) {
status = "3" ;
move = "有任务" ;
} else {
if ( standardInspectSiteDeviceDriver . getHasGoods ( ) = = 0 ) {
status = "0" ;
move = "无货" ;
} else if ( standardInspectSiteDeviceDriver . getHasGoods ( ) = = 1 ) {
status = "1" ;
move = "有托盘" ;
} else if ( standardInspectSiteDeviceDriver . getHasGoods ( ) = = 2 ) {
status = "2" ;
move = "有托盘有货" ;
}
JSONArray devices = WQLObject . getWQLObject ( "acs_device" ) . query ( "region = '" + region + "' AND device_type = 'station' AND is_config = 'true' " , "seq_num" ) . getResultJSONArray ( 0 ) ;
JSONArray resultArr = new JSONArray ( ) ;
for ( int i = 0 ; i < devices . size ( ) ; i + + ) {
JSONObject device = devices . getJSONObject ( i ) ;
String deviceCode = device . getString ( "device_code" ) ;
Device deviceCache = this . deviceAppService . findDeviceByCode ( deviceCode ) ;
JSONObject row = new JSONObject ( ) ;
row . put ( "device_code" , deviceCode ) ;
row . put ( "device_name" , device . getString ( "device_name" ) ) ;
String status = "0" ;
if ( "true" . equals ( deviceCache . getExtraValue ( ) . get ( "station_manager" ) ) ) {
if ( "1" . equals ( deviceCache . getIslock ( ) ) ) {
status = "2" ;
} else if ( 1 = = deviceCache . getHas_goods ( ) ) {
status = "1" ;
}
jo . put ( "material_type" , standardInspectSiteDeviceDriver . getMaterial ( ) ) ;
jo . put ( "status_name" , move ) ;
jo . put ( "status" , status ) ;
jo . put ( "device_id" , devicejo . getString ( "device_id" ) ) ;
jo . put ( "device_code" , devicejo . getString ( "device_code" ) ) ;
jo . put ( "device_name" , devicejo . getString ( "device_name" ) ) ;
jo . put ( "allow_update" , "1" ) ;
jo . put ( "batch" , standardInspectSiteDeviceDriver . getBatch ( ) ) ;
jo . put ( "input_material" , input_material ) ;
row . put ( "material_type" , deviceCache . getMaterial_type ( ) ) ;
row . put ( "qty" , deviceCache . getBatch ( ) ) ;
}
resultArr . add ( jo ) ;
row . put ( "status" , status ) ;
resultArr . add ( row ) ;
}
resultJson . put ( "code" , "1" ) ;
resultJson . put ( "desc" , "查询成功" ) ;
resultJson . put ( "result" , resultArr ) ;
return resultJson ;
JSONObject result = new JSONObject ( ) ;
result . put ( "code" , "1" ) ;
result . put ( "desc" , "查询成功" ) ;
result . put ( "result" , resultArr ) ;
return result ;
}
@Override
@ -778,4 +698,96 @@ public class HFHandServiceImpl implements HFHandService {
jo . put ( "desc" , "操作成功!" ) ;
return jo ;
}
@Override
public JSONObject material ( ) {
JSONArray materialType = WQLObject . getWQLObject ( "sys_dict_detail" ) . query ( "`name` = 'material_type'" ) . getResultJSONArray ( 0 ) ;
JSONObject result = new JSONObject ( ) ;
result . put ( "code" , "1" ) ;
result . put ( "desc" , "查询成功" ) ;
result . put ( "result" , materialType ) ;
return result ;
}
@Override
public JSONObject pointOpt ( JSONObject param ) {
JSONObject result = new JSONObject ( ) ;
String type = param . getString ( "type" ) ;
if ( StrUtil . isBlank ( type ) ) {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "未知操作!" ) ;
return result ;
}
String deviceCode = param . getString ( "device_code" ) ;
if ( StrUtil . isBlank ( deviceCode ) ) {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "未知点位!" ) ;
return result ;
}
Device device = this . deviceAppService . findDeviceByCode ( deviceCode ) ;
if ( "1" . equals ( device . getIslock ( ) ) ) {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "当前点位有正在执行的任务,禁止操作!" ) ;
return result ;
}
if ( "1" . equals ( type ) ) {
// 确认
String materialType = param . getString ( "material_type" ) ;
if ( StrUtil . isBlank ( materialType ) | | "0" . equals ( materialType ) ) {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "物料不能为空!" ) ;
return result ;
}
int qty = param . getIntValue ( "qty" ) ;
if ( qty < = 0 ) {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "数量必须大于零!" ) ;
return result ;
}
if ( "true" . equals ( device . getExtraValue ( ) . get ( "station_manager" ) ) ) {
device . setHas_goods ( 1 ) ;
device . setMaterial_type ( materialType ) ;
device . setBatch ( String . valueOf ( qty ) ) ;
JSONObject rpUpdate = new JSONObject ( ) ;
rpUpdate . put ( "hasgoods" , "1" ) ;
rpUpdate . put ( "material_type" , materialType ) ;
rpUpdate . put ( "batch" , qty ) ;
rpUpdate . put ( "update_by" , "sc" ) ;
rpUpdate . put ( "update_time" , DateUtil . now ( ) ) ;
WQLObject . getWQLObject ( "acs_device_runpoint" ) . update ( rpUpdate , "device_code = '" + deviceCode + "'" ) ;
} else {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "此点位在设备配置中未开启点位管理,无法保存物料等信息!" ) ;
return result ;
}
} else if ( "2" . equals ( type ) ) {
// 清空
if ( "true" . equals ( device . getExtraValue ( ) . get ( "station_manager" ) ) ) {
device . setHas_goods ( 0 ) ;
device . setMaterial_type ( "0" ) ;
device . setBatch ( "0" ) ;
JSONObject rpUpdate = new JSONObject ( ) ;
rpUpdate . put ( "hasgoods" , "0" ) ;
rpUpdate . put ( "material_type" , "0" ) ;
rpUpdate . put ( "batch" , "0" ) ;
rpUpdate . put ( "update_by" , "sc" ) ;
rpUpdate . put ( "update_time" , DateUtil . now ( ) ) ;
WQLObject . getWQLObject ( "acs_device_runpoint" ) . update ( rpUpdate , "device_code = '" + deviceCode + "'" ) ;
}
} else {
result . put ( "code" , "0" ) ;
result . put ( "desc" , "未知操作!" ) ;
return result ;
}
result . put ( "code" , "1" ) ;
result . put ( "desc" , "操作成功!" ) ;
return result ;
}
}