@ -10,6 +10,12 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.nl.acs.device_driver.electric_fence.ElectricFenceDeviceDriver ;
import org.nl.acs.device_driver.hailiang.hailiang_feeding_trunk.HaiLiangFeedingTrunkDeviceDriver ;
import org.nl.acs.opc.Device ;
import org.nl.acs.opc.DeviceAppService ;
import org.nl.acs.opc.DeviceAppServiceImpl ;
import org.nl.acs.opc.DeviceType ;
import org.nl.acs.order.service.ProduceshiftorderService ;
import org.nl.acs.order.service.dto.CustomerbaseDto ;
import org.nl.acs.order.service.dto.ProduceshiftorderDto ;
@ -19,6 +25,7 @@ import org.nl.exception.BadRequestException;
import org.nl.modules.system.util.CodeUtil ;
import org.nl.start.auto.initial.ApplicationAutoInitial ;
import org.nl.utils.SecurityUtils ;
import org.nl.utils.SpringContextHolder ;
import org.nl.wql.WQL ;
import org.nl.wql.core.bean.ResultBean ;
import org.nl.wql.core.bean.WQLObject ;
@ -54,14 +61,17 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
private final MongoTemplate mongoTemplate ;
DeviceAppService deviceAppService = SpringContextHolder . getBean ( DeviceAppServiceImpl . class ) ;
@Override
public void autoInitial ( ) throws Exception {
this . reload ( ) ;
}
public synchronized void reload ( ) {
this . order = this . queryAllOrder ( "order_status <2 and is_deleted =0" ) ;
this . detail = this . queryAllOrderDteail ( "order_detail_status <2 and is_deleted =0" ) ;
this . order = this . queryAllOrder ( "(order_status !='04' or order_status !='05' ) and is_deleted =0" ) ;
this . detail = this . queryAllOrderDteail ( " (order_detail_status != '04' or order_detail_status != '05') and is_deleted =0" ) ;
}
@Override
@ -278,16 +288,31 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
@Transactional ( rollbackFor = Exception . class )
public void send ( String id ) {
ProduceshiftorderDto entity = this . findById ( id ) ;
if ( entity = = null ) throw new BadRequestException ( "被删除或无权限,操作失败!" ) ;
entity . setIs_deleted ( "1" ) ;
WQLObject wo = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( entity ) ;
wo . update ( json ) ;
if ( entity = = null ) throw new BadRequestException ( "被删除或无权限,操作失败!" ) ;
if ( ! StrUtil . equals ( entity . getOrder_status ( ) , "00" ) ) {
throw new BadRequestException ( "该工单非就绪状态,无法下发!" ) ;
}
JSONObject checkone = wo . query ( "order_status = '01' " ) . uniqueResult ( 0 ) ;
if ( ! ObjectUtil . isEmpty ( checkone ) ) {
throw new BadRequestException ( "存在已确认的工单,请先暂停或完成!" ) ;
}
HashMap < String , String > map = new HashMap < > ( ) ;
map . put ( "is_deleted" , "1" ) ;
WQLObject . getWQLObject ( "acs_produceshiftorderdetail" ) . update ( map , "order_id = '" + id + "'" ) ;
HaiLiangFeedingTrunkDeviceDriver haiLiangFeedingTrunkDeviceDriver ;
List < Device > deviceAll = deviceAppService . findDevice ( DeviceType . conveyor ) ;
for ( int i = 0 ; i < deviceAll . size ( ) ; i + + ) {
Device device = deviceAll . get ( 0 ) ;
if ( device . getDeviceDriver ( ) instanceof HaiLiangFeedingTrunkDeviceDriver ) {
haiLiangFeedingTrunkDeviceDriver = ( HaiLiangFeedingTrunkDeviceDriver ) device . getDeviceDriver ( ) ;
if ( haiLiangFeedingTrunkDeviceDriver . getReady ( ) ! = 1 ) {
throw new BadRequestException ( "设备未就绪,无法下发!" ) ;
}
}
}
entity . setOrder_status ( "01" ) ;
JSONObject json = ( JSONObject ) JSONObject . toJSON ( entity ) ;
wo . update ( json ) ;
}
@ -309,4 +334,51 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
return arr ;
}
@Override
public Map < String , Object > querySorting ( Map whereJson , Pageable page ) {
WQLObject wo = WQLObject . getWQLObject ( "acs_produceshiftorder" ) ;
String where = "1=1 and (order_status !='00' or order_status !='04' or order_status !='05' ) and is_deleted= '0'" ;
ResultBean rb = wo . pagequery ( WqlUtil . getHttpContext ( page ) , where , "order_id desc" ) ;
final JSONObject json = rb . pageResult ( ) ;
JSONArray newja = new JSONArray ( ) ;
JSONArray ja = json . getJSONArray ( "content" ) ;
for ( int i = 0 ; i < ja . size ( ) ; i + + ) {
JSONObject jo = ( JSONObject ) ja . get ( i ) ;
JSONArray orderDteail_ja = WQLObject . getWQLObject ( "acs_produceshiftorderdetail" ) . query ( "is_deleted= '0' and order_id ='" + jo . getString ( "order_id" ) + "'" ) . getResultJSONArray ( 0 ) ;
if ( orderDteail_ja . size ( ) > 0 ) {
JSONArray children = new JSONArray ( ) ;
for ( int j = 0 ; j < orderDteail_ja . size ( ) ; j + + ) {
JSONObject orderDteail_jo = orderDteail_ja . getJSONObject ( j ) ;
JSONObject new_jo = new JSONObject ( ) ;
new_jo . put ( "order_id" , orderDteail_jo . getString ( "order_detail_id" ) ) ;
new_jo . put ( "order_code" , orderDteail_jo . getString ( "order_detail_code" ) ) ;
new_jo . put ( "order_status" , orderDteail_jo . getString ( "order_detail_status" ) ) ;
new_jo . put ( "is_active" , orderDteail_jo . getString ( "is_active" ) ) ;
new_jo . put ( "is_delete" , orderDteail_jo . getString ( "is_delete" ) ) ;
new_jo . put ( "create_by" , orderDteail_jo . getString ( "create_by" ) ) ;
new_jo . put ( "create_time" , orderDteail_jo . getString ( "create_time" ) ) ;
new_jo . put ( "update_by" , orderDteail_jo . getString ( "update_by" ) ) ;
new_jo . put ( "update_time" , orderDteail_jo . getString ( "update_time" ) ) ;
new_jo . put ( "cust_id" , orderDteail_jo . getString ( "cust_id" ) ) ;
new_jo . put ( "cust_code" , orderDteail_jo . getString ( "cust_code" ) ) ;
new_jo . put ( "cust_name" , orderDteail_jo . getString ( "cust_name" ) ) ;
new_jo . put ( "qty" , orderDteail_jo . getString ( "order_detail_qty" ) ) ;
new_jo . put ( "type" , "orderDteail" ) ;
jo . put ( "is_flag" , "0" ) ;
children . add ( new_jo ) ;
}
jo . put ( "children" , children ) ;
}
jo . put ( "type" , "order" ) ;
//区分工单明细
jo . put ( "is_flag" , "1" ) ;
newja . add ( jo ) ;
}
json . put ( "content" , newja ) ;
System . out . println ( "json:" + json ) ;
return json ;
}
}