@ -17,6 +17,7 @@ import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver ;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver ;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver ;
import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver ;
import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver ;
import org.nl.acs.ext.wms.service.AcsToWmsService ;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl ;
@ -25,11 +26,14 @@ import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.opc.Device ;
import org.nl.acs.opc.DeviceAppService ;
import org.nl.acs.opc.DeviceAppServiceImpl ;
import org.nl.acs.opc.WcsConfig ;
import org.nl.acs.route.service.RouteLineService ;
import org.nl.acs.route.service.dto.RouteLineDto ;
import org.nl.acs.task.service.TaskService ;
import org.nl.acs.task.service.dto.TaskDto ;
import org.nl.modules.system.util.CodeUtil ;
import org.nl.utils.SpringContextHolder ;
import org.nl.wql.core.bean.WQLObject ;
import org.openscada.opc.lib.da.Server ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -57,7 +61,8 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
DeviceAppService appService = SpringContextHolder . getBean ( DeviceAppServiceImpl . class ) ;
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder . getBean ( AcsToWmsServiceImpl . class ) ;
@Autowired
DeviceAppService deviceAppservice = SpringContextHolder . getBean ( DeviceAppService . class ) ;
String container ;
String container_type_desc ;
String last_container_type_desc ;
@ -105,7 +110,7 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
Instruction inst = null ;
//上次指令
Instruction last_inst = null ;
int max_emptypalletnum ;
//触摸屏手动触发任务
private Boolean is_has_task = false ;
@ -120,7 +125,7 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
try {
String device_code = this . getDeviceCode ( ) ;
int max_emptypalletnum = Integer . parseInt ( this . getDevice ( ) . getExtraValue ( ) . get ( "max_emptypalletnum" ) . toString ( ) ) ;
max_emptypalletnum = Integer . parseInt ( this . getDevice ( ) . getExtraValue ( ) . get ( "max_emptypalletnum" ) . toString ( ) ) ;
mode = this . itemProtocol . getMode ( ) ;
error = this . itemProtocol . getError ( ) ;
@ -141,6 +146,9 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
}
}
if ( number ! = last_number ) {
if ( number = = max_emptypalletnum ) {
requireSucess = false ;
}
this . execute_log . setResource ( this . getDevicecode ( ) , this . getDevice ( ) . getDevice_name ( ) ) ;
this . execute_log . log ( "设备:" + device_code + ",last_number -> number:" + last_number + "->" + number ) ;
}
@ -183,7 +191,13 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
log . debug ( "设备运转模式:等待工作" ) ;
return ;
case 2 :
String apply_task = "" ;
if ( ! requireSucess ) {
if ( move > 0 ) {
this . execute_log . log ( "设备:" + devicecode + ",move:" + move ) ;
this . apply_take_empty ( container ) ;
}
}
/ * String apply_task = "" ;
if ( ObjectUtil . isNotEmpty ( this . getDevice ( ) . getExtraValue ( ) . get ( "apply_task" ) ) ) {
apply_task = this . getDevice ( ) . getExtraValue ( ) . get ( "apply_task" ) . toString ( ) ;
}
@ -227,7 +241,7 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
}
}
}
} * /
break ;
default :
@ -343,6 +357,119 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
instruction_finished ( instruction ) ;
}
public synchronized boolean apply_take_empty ( String container_code ) {
return apply_take_empty ( container_code , WcsConfig . task_container_type_default_desc ) ;
}
/ * *
* 请求指令
*
* @param container_code
* @param container_type
* /
public synchronized boolean apply_take_empty ( String container_code , String container_type ) {
WQLObject runpointwo = WQLObject . getWQLObject ( "acs_device_runpoint" ) ;
Date date = new Date ( ) ;
Boolean flag = false ;
if ( date . getTime ( ) - this . instruction_require_time . getTime ( ) < ( long ) this . instruction_require_time_out ) {
log . trace ( "触发时间因为小于{}毫秒,而被无视" , this . instruction_require_time_out ) ;
return false ;
} else {
this . instruction_require_time = date ;
if ( number ! = max_emptypalletnum ) {
return true ;
}
//查询该设备所有路由
List < RouteLineDto > pathLinesByCode = routelineserver . getSuperiorShortPathLinesByCode ( this . getDevice ( ) . getDevice_code ( ) , "normal" ) ;
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver ;
for ( int i = 0 ; i < pathLinesByCode . size ( ) ; i + + ) {
RouteLineDto routeLineDto = pathLinesByCode . get ( i ) ;
//获取该路由的起点设备编码
String start_device_code = routeLineDto . getDevice_code ( ) ;
//获取该路由的终点设备编码
String next_device_code = routeLineDto . getNext_device_code ( ) ;
//获取该路由终点设备信息
Device route_link_device = deviceAppservice . findDeviceByCode ( next_device_code ) ;
//判断终点设备驱动是否为检测站点驱动
if ( route_link_device . getDeviceDriver ( ) instanceof StandardInspectSiteDeviceDriver ) {
standardInspectSiteDeviceDriver = ( StandardInspectSiteDeviceDriver ) route_link_device . getDeviceDriver ( ) ;
//判断该终点设备是否有货,有货就结束循环
if ( standardInspectSiteDeviceDriver . getMove ( ) ! = 0 | | standardInspectSiteDeviceDriver . getMode ( ) ! = 2 ) {
continue ;
}
//判断是否已经有该起点设备的任务,如果有就结束循环
int num1 = taskserver . querySameOriginTask ( start_device_code ) ;
if ( num1 ! = 0 ) {
continue ;
}
//判断是否有相同终点的任务,有就结束本次循环
int num = taskserver . querySameDestinationTask ( next_device_code ) ;
if ( num ! = 0 ) {
continue ;
}
/ * //判断检测站点是否锁定,如果锁定就结束本次循环
JSONObject jsonObject = runpointwo . query ( "device_code = '" + start_device_code + "' and islock = 'true'" ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isNotEmpty ( jsonObject ) ) {
this . execute_log . log ( "设备:" + devicecode + "" , "" , "对应路由设备," + devicecode + "已锁定" ) ;
continue ;
} * /
//创建任务
TaskDto dto = new TaskDto ( ) ;
String now = DateUtil . now ( ) ;
dto . setTask_id ( IdUtil . simpleUUID ( ) ) ;
dto . setCreate_by ( this . getDevice ( ) . getDevice_code ( ) ) ;
dto . setUpdate_by ( this . getDevice ( ) . getDevice_code ( ) ) ;
dto . setVehicle_code ( container_code ) ;
dto . setVehicle_type ( container_type ) ;
String taskcode = CodeUtil . getNewCode ( "TASK_NO" ) ;
dto . setTask_code ( "-" + taskcode ) ;
dto . setTask_status ( "0" ) ;
dto . setPriority ( "101" ) ;
dto . setUpdate_time ( now ) ;
dto . setCreate_time ( now ) ;
dto . setStart_device_code ( start_device_code ) ;
dto . setStart_point_code ( start_device_code ) ;
dto . setNext_device_code ( next_device_code ) ;
dto . setNext_point_code ( next_device_code ) ;
try {
//判断是否已经有该起点设备的任务,如果有就结束循环
int num3 = taskserver . querySameOriginTask ( start_device_code ) ;
if ( num3 ! = 0 ) {
continue ;
}
//判断是否有相同终点的任务,有就结束本次循环
int num4 = taskserver . querySameDestinationTask ( next_device_code ) ;
if ( num4 ! = 0 ) {
continue ;
}
taskserver . create ( dto ) ;
//任务创建成功 锁定起点设备
/ * JSONObject map = new JSONObject ( ) ;
map . put ( "islock" , "true" ) ;
map . put ( "update_by" , "auto" ) ;
map . put ( "update_time" , DateUtil . now ( ) ) ;
runpointwo . update ( map , "device_code = '" + start_device_code + "'" ) ; * /
flag = true ;
break ;
} catch ( Exception e ) {
this . execute_log . log ( "设备:" + devicecode + "" , "" , "创建任务失败" ) ;
}
}
}
//生成任务成功
if ( flag ) {
requireSucess = true ;
this . execute_log . log ( "设备:" + devicecode + "" , "" , "对应路由设备,生成任务成功已锁定" ) ;
}
return true ;
}
}
/ * *
* 完成指令
*