@ -4,25 +4,23 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateRange ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.dsic.gj_erp.bean.SpringContextHolder ;
import com.dsic.gj_erp.bean.jcsj.DmBom ;
import com.dsic.gj_erp.bean.jcsj.EmGcrl ;
import com.dsic.gj_erp.bean.jcsj.EmSbcnp ;
import com.dsic.gj_erp.bean.jcsj.EmSbjbb ;
import com.dsic.gj_erp.bean.jcsj.* ;
import com.dsic.gj_erp.bean.jhgk.DmSygdMx ;
import com.dsic.gj_erp.handler.dto.RealCapacity ;
import com.dsic.gj_erp.service.jcsj.EmGcrlService ;
import com.dsic.gj_erp.service.jcsj.EmSbcnpService ;
import com.dsic.gj_erp.service.jcsj.EmSbjbbService ;
import com.dsic.gj_erp.service.jcsj.EmSbjgryService ;
import lombok.Getter ;
import lombok.Setter ;
import java.util.Date ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.stream.Collectors ;
@Getter
@ -35,13 +33,15 @@ public class ComputePlan {
Map < String , EmSbcnp > baseCapacity ;
Map < String , Integer > empSizeByDay ;
Map < String , List< EmSbjgry > > empSizeByDay ;
List < EmGcrl > gcrlList ;
JSONObject realCapacityMap ;
Map< String , List < RealCapacity > > realCapacityMap ;
List < EmSbjbb > deviceList ;
List < EmSbcnp > sbcnList ;
JSONObject realDeviceList ;
@ -65,12 +65,16 @@ public class ComputePlan {
* @param to 结 束 日 期
* /
public static void computeRealCapacity ( Date from , Date to ) {
JSONObject _realCapacity = instance ( ) . realCapacityMap = new JSONObject ( ) ;
Map< String , List < RealCapacity > > _realCapacity = instance ( ) . realCapacityMap = new TreeMap< > ( ) ;
//加载工厂日历
initGcrl ( ) ;
//加载设备信息
initDevice ( ) ;
//加载工作人员
initEmp ( from , to ) ;
//加载产能信息
initSbcn ( ) ;
//计算周期内按天分解的实际可用设备产能
initRealDeviceList ( from , to ) ;
@ -81,9 +85,9 @@ public class ComputePlan {
. filter ( item - > "1" . equals ( item . getXxr ( ) ) )
. filter ( item - > DateUtil . isIn ( DateUtil . parse ( item . getGl ( ) , "yyyy/MM/dd" ) , from , to ) )
. collect ( Collectors . toList ( ) ) ;
// Collections.sort(gcrlList,Comparator.comparing(EmGcrl::getGl,(t1,t2)->t1.compareTo(t2)));
gcrlList . forEach ( gcrl - > {
if ( realDeviceList == null ) {
if ( realDeviceList .size ( ) < 1 | | ObjectUtil . isEmpty ( realDeviceList . getJSONArray ( gcrl . getGl ( ) ) ) ) {
return ;
}
//日可用设备
@ -91,14 +95,21 @@ public class ComputePlan {
JSONObject deviceJson = realDeviceList . getJSONArray ( gcrl . getGl ( ) ) . getJSONObject ( i ) ;
//日实际产能
//todo 设备和产能对应关系,找出当前设备产能
RealCapacity realCapacity = initRealCapacity ( gcrl , deviceJson . getString ( "sbbh" ) , new EmSbcnp ( ) ) ;
//todo 设备和产能对应关系,找出当前设备产能 (日期 产能 工序 图纸名称)
RealCapacity realCapacity = initRealCapacity ( gcrl , deviceJson ) ;
if ( realCapacity . getCapacity ( ) = = 0 ) {
continue ;
}
if ( _realCapacity . containsKey ( gcrl . getGl ( ) ) ) {
_realCapacity . getJSONObject ( gcrl . getGl ( ) ) . put ( realCapacity . getDeviceName ( ) , realCapacity . getCapacity ( ) ) ;
_realCapacity . get ( gcrl . getGl ( ) ) .
// put(realCapacity.getDeviceName(), realCapacity.getCapacity());
add ( realCapacity ) ;
} else {
JSONObject object = new JSONObject ( ) ;
object . put ( realCapacity . getDeviceName ( ) , realCapacity . getCapacity ( ) ) ;
_realCapacity . put ( gcrl . getGl ( ) , object ) ;
// JSONObject object = new JSONObject();
// object.put(realCapacity.getDeviceName(), realCapacity.getCapacity());
List < RealCapacity > list = new ArrayList < > ( ) ;
list . add ( realCapacity ) ;
_realCapacity . put ( gcrl . getGl ( ) , list ) ;
}
}
} ) ;
@ -109,11 +120,21 @@ public class ComputePlan {
* 加 载 工 厂 日 历
* /
public static void initGcrl ( ) {
if ( instance ( ) . gcrlList = = null ) {
// if (instance().gcrlList == null){
instance ( ) . gcrlList = getBean ( EmGcrlService . class ) . getList ( new JSONObject ( ) ) ;
}
// }
}
/ * *
* 加 载 设 备 产 能
* /
public static void initSbcn ( ) {
// if (instance().sbcnList == null){
instance ( ) . sbcnList = getBean ( EmSbcnpService . class ) . getList ( new JSONObject ( ) ) ;
// }
}
public static void initDeviceCapacity ( ) {
if ( instance ( ) . baseCapacity = = null ) {
instance ( ) . baseCapacity = getBean ( EmSbcnpService . class ) . getMap ( ) ;
@ -131,24 +152,38 @@ public class ComputePlan {
* @param flag 强 制 重 置
* /
public static void initRealDeviceList ( Date from , Date to , boolean flag ) {
if ( instance ( ) . realDeviceList = = null | | flag ) {
// if (ObjectUtil.isEmpty(instance().realDeviceList)||flag) {
JSONObject realDeviceList = instance ( ) . realDeviceList = new JSONObject ( ) ;
List < EmSbjbb > list = instance ( ) . deviceList ;
DateRange dateRange = new DateRange ( from , to , DateField . DAY_OF_YEAR ) ;
List < EmSbjbb > canUseDevice = list . stream ( ) . filter ( item - > "0" . equals ( item . getSbyxzt ( ) ) ) . collect ( Collectors . toList ( ) ) ;
//计算可用设备的可用日期
Map < String , Integer > _empSizeByDay = instance ( ) . empSizeByDay ;
Map < String , List < EmSbjgry > > _empSizeByDay = instance ( ) . empSizeByDay ;
canUseDevice . forEach ( item - > {
String [ ] whArr = item . getWhsj ( ) . split ( "_" ) ;
if ( whArr. length < 2 ) {
//未定义图纸及工序的设备,无法参加排产
if ( StrUtil. hasEmpty ( item . getTzbh ( ) , item . getGx ( ) ) ) {
return ;
}
DateRange tmpRange = new DateRange ( DateUtil . parse ( whArr [ 0 ] , "yyyy/MM/dd" ) , DateUtil . parse ( whArr [ 1 ] , "yyyy/MM/dd" ) , DateField . DAY_OF_YEAR ) ;
List < DateTime > dateTimes = DateUtil . rangeNotContains ( dateRange , tmpRange ) ;
//维修时间
List < DateTime > dateTimes ;
if ( StrUtil . isNotEmpty ( item . getWhsj ( ) ) ) {
String [ ] whArr = item . getWhsj ( ) . split ( "_" ) ;
if ( whArr . length < 2 ) {
return ;
}
DateRange dateRange = new DateRange ( from , to , DateField . DAY_OF_YEAR ) ; //需要放到循环内,放外边不能重复使用
DateRange tmpRange = new DateRange ( DateUtil . parse ( whArr [ 0 ] , "yyyy/MM/dd" ) , DateUtil . parse ( whArr [ 1 ] , "yyyy/MM/dd" ) , DateField . DAY_OF_YEAR ) ;
dateTimes = DateUtil . rangeNotContains ( tmpRange , dateRange ) ;
} else {
dateTimes = DateUtil . rangeToList ( from , to , DateField . DAY_OF_YEAR ) ;
}
dateTimes . forEach ( date - > {
String dateStr = date . toString ( "yyyy/MM/dd" ) ;
//todo 根据人员请假情况,计算当前日期设备是否可用
if ( _empSizeByDay . get ( dateStr ) < = 0 ) {
if ( ObjectUtil. isEmpty ( _empSizeByDay ) | | _empSizeByDay. get ( dateStr ) . size ( ) < = 0 ) {
return ;
}
if ( realDeviceList . get ( dateStr ) = = null ) {
@ -160,10 +195,34 @@ public class ComputePlan {
}
} ) ;
} ) ;
}
// }
}
public static void initEmp ( Date from , Date to ) {
//设备编号? 人员 休假日期 状态(在职)
if ( ObjectUtil . isEmpty ( instance ( ) . empSizeByDay ) ) {
Map < String , List < EmSbjgry > > empSizeByDay = instance ( ) . empSizeByDay = new HashMap < > ( ) ;
//1.全部工作人员 状态(在职)
List < EmSbjgry > empList = getBean ( EmSbjgryService . class ) . list ( Wrappers . < EmSbjgry > lambdaQuery ( ) . eq ( EmSbjgry : : getZt , "01" ) ) ;
//2.根据休息时间范围取差集
empList . forEach ( emp - > {
DateRange dateRange = new DateRange ( from , to , DateField . DAY_OF_YEAR ) ; //需要放到循环内,放外边不能重复使用
DateRange tmpRange = new DateRange ( DateUtil . parse ( emp . getXjsjKs ( ) , "yyyy/MM/dd" ) , DateUtil . parse ( emp . getXjsjJs ( ) , "yyyy/MM/dd" ) , DateField . DAY_OF_YEAR ) ;
List < DateTime > dateTimes = DateUtil . rangeNotContains ( tmpRange , dateRange ) ;
dateTimes . forEach ( date - > {
String dateStr = date . toString ( "yyyy/MM/dd" ) ;
if ( ObjectUtil . isEmpty ( empSizeByDay ) | | empSizeByDay . get ( dateStr ) = = null ) {
List < EmSbjgry > arr = new ArrayList < > ( ) ;
arr . add ( emp ) ;
empSizeByDay . put ( dateStr , arr ) ;
} else {
empSizeByDay . get ( dateStr ) . add ( emp ) ;
}
} ) ;
} ) ;
}
}
@ -181,23 +240,38 @@ public class ComputePlan {
return instance ;
}
private static RealCapacity initRealCapacity ( EmGcrl gcrl , String name , EmSbcnp sbcnp ) {
private static RealCapacity initRealCapacity ( EmGcrl gcrl , JSONObject deviceJson ) {
//设备产能,根据图号和工序去重,注意:同图号和工序下,不同组立对应的产能要一致
List < EmSbcnp > list = instance ( ) . sbcnList . stream ( )
. collect ( Collectors . collectingAndThen ( Collectors . toCollection ( ( ) - >
new TreeSet < > ( Comparator . comparing ( o - > o . getTzbh ( ) + o . getGx ( ) ) ) ) , ArrayList : : new ) ) ;
String gx = deviceJson . getString ( "gx" ) ;
String tzbh = deviceJson . getString ( "tzbh" ) ;
RealCapacity capacity = new RealCapacity ( ) ;
if ( "3" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegs ( ) * 7 + sbcnp . getDegsYb ( ) * 7 ) ;
}
if ( "1" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegs ( ) * 7 ) ;
}
if ( "2" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegsYb ( ) * 7 ) ;
}
capacity . setDeviceName ( name ) ;
list . forEach ( sbcnp - > {
if ( sbcnp . getGx ( ) . equals ( gx ) & &
sbcnp . getTzbh ( ) . equals ( tzbh ) ) {
if ( "3" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegs ( ) * 7 + sbcnp . getDegsYb ( ) * 7 ) ;
}
if ( "1" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegs ( ) * 7 ) ;
}
if ( "2" . equals ( gcrl . getPb ( ) ) ) {
capacity . setCapacity ( sbcnp . getDegsYb ( ) * 7 ) ;
}
}
} ) ;
capacity . setDeviceName ( deviceJson . getString ( "sbbh" ) ) ;
capacity . setDate ( gcrl . getGl ( ) ) ;
capacity . setGx ( gx ) ;
capacity . setTzbh ( tzbh ) ;
return capacity ;
}
private static < T > T getBean ( Class < T > clazz ) {
return SpringContextHolder . getBean ( clazz ) ;
}
}