diff --git a/pom.xml b/pom.xml index 39624f8..e1921b4 100644 --- a/pom.xml +++ b/pom.xml @@ -171,7 +171,7 @@ cn.hutool hutool-all - 5.8.15 + 5.8.25 diff --git a/src/main/java/com/dsic/gj_erp/bean/SpringContextHolder.java b/src/main/java/com/dsic/gj_erp/bean/SpringContextHolder.java new file mode 100644 index 0000000..faf42d7 --- /dev/null +++ b/src/main/java/com/dsic/gj_erp/bean/SpringContextHolder.java @@ -0,0 +1,59 @@ +package com.dsic.gj_erp.bean; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.stereotype.Component; + +@Component +public class SpringContextHolder implements ApplicationContextAware { + + private static ApplicationContext springContext; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringContextHolder.springContext = applicationContext; + } + + /** + * 返回spring上下文环境对象 + * + * @return ApplicationContext + */ + public static ApplicationContext getSpringContext() { + return springContext; + } + + + /** + * 按名称获取spring bean + * + */ + public static Object getBean(String name) { + return springContext.getBean(name); + } + + /** + * 按类型获取spring bean + * + */ + public static T getBean(Class requiredType) { + return springContext.getBean(requiredType); + } + + + + /** + * 发布事件到spring + */ + public static void pushEvent(ApplicationEvent event) { + springContext.publishEvent(event); + } + + /** + * 发布事件到spring + */ + public static void pushEvent(Object event) { + springContext.publishEvent(event); + } +} \ No newline at end of file diff --git a/src/main/java/com/dsic/gj_erp/bean/jcsj/EmGcrl.java b/src/main/java/com/dsic/gj_erp/bean/jcsj/EmGcrl.java index ec7bb3f..6496e93 100644 --- a/src/main/java/com/dsic/gj_erp/bean/jcsj/EmGcrl.java +++ b/src/main/java/com/dsic/gj_erp/bean/jcsj/EmGcrl.java @@ -60,4 +60,7 @@ public class EmGcrl implements Serializable { private String gzlr; @ApiModelProperty(value = "最近的工作日") private String gzr; + + @ApiModelProperty(value = "排班:1:早;2:晚班;3:双班") + private String pb; } diff --git a/src/main/java/com/dsic/gj_erp/bean/jcsj/EmSbcnp.java b/src/main/java/com/dsic/gj_erp/bean/jcsj/EmSbcnp.java index 4be7769..e14cb7c 100644 --- a/src/main/java/com/dsic/gj_erp/bean/jcsj/EmSbcnp.java +++ b/src/main/java/com/dsic/gj_erp/bean/jcsj/EmSbcnp.java @@ -59,4 +59,7 @@ public class EmSbcnp implements Serializable { @TableId(value = "id", type = IdType.ASSIGN_UUID) private String id; + @ApiModelProperty(value = "夜班定额工时") + private Double degsYb; + } diff --git a/src/main/java/com/dsic/gj_erp/handler/ComputePlan.java b/src/main/java/com/dsic/gj_erp/handler/ComputePlan.java new file mode 100644 index 0000000..6b1a048 --- /dev/null +++ b/src/main/java/com/dsic/gj_erp/handler/ComputePlan.java @@ -0,0 +1,175 @@ +package com.dsic.gj_erp.handler; + +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 com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.dsic.gj_erp.bean.SpringContextHolder; +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.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 lombok.Getter; +import lombok.Setter; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Getter +@Setter +public class ComputePlan { + + private static ComputePlan instance = null; + + List workerList; + + Map baseCapacity; + + List gcrlList; + + JSONObject realCapacityMap; + + List deviceList; + + JSONObject realDeviceList; + + List sygdMxList; + + /** + * 计算实际产能,默认未来三个月 + */ + public static void computeRealCapacity() { + Date from = DateUtil.beginOfMonth(DateUtil.offsetMonth(new Date(), 1)); + Date to = DateUtil.beginOfMonth(DateUtil.offsetMonth(new Date(), 4)); + computeRealCapacity(from, to); + } + + /** + * 计算制定日期范围内每天实际产能 + * + * @param from 开始日期 + * @param to 结束日期 + */ + public static void computeRealCapacity(Date from, Date to) { + JSONObject _realCapacity = instance().realCapacityMap = new JSONObject(); + + initGcrl(); + initDevice(); + initRealDeviceList(from, to); + + //可用设备 + JSONObject realDeviceList = instance().realDeviceList; + + List gcrlList = instance().gcrlList.stream() + .filter(item -> "1".equals(item.getXxr())) + .filter(item -> DateUtil.isIn(DateUtil.parse(item.getGl(), "yyyy/MM/dd"), from, to)) + .collect(Collectors.toList()); + + gcrlList.forEach(gcrl -> { + if (realDeviceList == null) { + return; + } + //日可用设备 + for (int i = 0; i < realDeviceList.getJSONArray(gcrl.getGl()).size(); i++) { + JSONObject deviceJson = realDeviceList.getJSONArray(gcrl.getGl()).getJSONObject(i); + + //日实际产能 + //todo 设备和产能对应关系,找出当前设备产能 + RealCapacity realCapacity = initRealCapacity(gcrl, deviceJson.getString("sbbh"), new EmSbcnp()); + if (_realCapacity.containsKey(gcrl.getGl())) { + _realCapacity.getJSONObject(gcrl.getGl()).put(realCapacity.getDeviceName(), realCapacity.getCapacity()); + } else { + JSONObject object = new JSONObject(); + object.put(realCapacity.getDeviceName(), realCapacity.getCapacity()); + _realCapacity.put(gcrl.getGl(), object); + } + } + }); + + } + + /** + * 加载工厂日历 + */ + public static void initGcrl() { + if (instance().gcrlList == null){ + instance().gcrlList = getBean(EmGcrlService.class).getList(new JSONObject()); + } + } + + public static void initDeviceCapacity() { + if (instance().baseCapacity == null) { + instance().baseCapacity = getBean(EmSbcnpService.class).getMap(); + } + } + + public static void initRealDeviceList(Date from, Date to) { + if (instance().realDeviceList == null) { + JSONObject realDeviceList = instance().realDeviceList = new JSONObject(); + List list = instance().deviceList; + DateRange dateRange = new DateRange(from, to, DateField.DAY_OF_YEAR); + List canUseDevice = list.stream().filter(item -> "0".equals(item.getSbyxzt())).collect(Collectors.toList()); + //计算可用设备的可用日期 + canUseDevice.forEach(item -> { + String[] whArr = item.getWhsj().split("_"); + if (whArr.length < 2) { + return; + } + DateRange tmpRange = new DateRange(DateUtil.parse(whArr[0], "yyyy/MM/dd"), DateUtil.parse(whArr[1], "yyyy/MM/dd"), DateField.DAY_OF_YEAR); + List dateTimes = DateUtil.rangeNotContains(dateRange, tmpRange); + dateTimes.forEach(date -> { + String dateStr = date.toString("yyyy/MM/dd"); + if (realDeviceList.get(dateStr) == null) { + JSONArray arr = new JSONArray(); + arr.add(item); + realDeviceList.put(dateStr, arr); + } else { + realDeviceList.getJSONArray(dateStr).add(item); + } + }); + }); + } + } + + /** + * 加载设备信息表 + */ + public static void initDevice() { + instance().deviceList = getBean(EmSbjbbService.class).list(); + } + + public synchronized static ComputePlan instance() { + if (instance == null) { + instance = new ComputePlan(); + } + return instance; + } + + private static RealCapacity initRealCapacity(EmGcrl gcrl, String name, EmSbcnp sbcnp) { + 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); + capacity.setDate(gcrl.getGl()); + return capacity; + } + + private static T getBean(Class clazz) { + return SpringContextHolder.getBean(clazz); + } +} diff --git a/src/main/java/com/dsic/gj_erp/handler/dto/RealCapacity.java b/src/main/java/com/dsic/gj_erp/handler/dto/RealCapacity.java new file mode 100644 index 0000000..7fe5410 --- /dev/null +++ b/src/main/java/com/dsic/gj_erp/handler/dto/RealCapacity.java @@ -0,0 +1,14 @@ +package com.dsic.gj_erp.handler.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class RealCapacity { + + String deviceName; + String date; + Double capacity; + +} diff --git a/src/main/java/com/dsic/gj_erp/mapper/jcsj/EmSbcnpMapper.java b/src/main/java/com/dsic/gj_erp/mapper/jcsj/EmSbcnpMapper.java index d32eb72..85974bf 100644 --- a/src/main/java/com/dsic/gj_erp/mapper/jcsj/EmSbcnpMapper.java +++ b/src/main/java/com/dsic/gj_erp/mapper/jcsj/EmSbcnpMapper.java @@ -3,6 +3,9 @@ package com.dsic.gj_erp.mapper.jcsj; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dsic.gj_erp.bean.jcsj.EmSbcnp; +import org.apache.ibatis.annotations.MapKey; + +import java.util.Map; /** *

@@ -13,5 +16,6 @@ import com.dsic.gj_erp.bean.jcsj.EmSbcnp; * @since 2023-09-15 */ public interface EmSbcnpMapper extends BaseMapper { - + @MapKey("sbbh") + Map getMap(); } diff --git a/src/main/java/com/dsic/gj_erp/service/jcsj/EmSbcnpService.java b/src/main/java/com/dsic/gj_erp/service/jcsj/EmSbcnpService.java index 127f60f..b6ee0f5 100644 --- a/src/main/java/com/dsic/gj_erp/service/jcsj/EmSbcnpService.java +++ b/src/main/java/com/dsic/gj_erp/service/jcsj/EmSbcnpService.java @@ -20,6 +20,8 @@ import java.util.Map; * @since 2023-09-15 */ public interface EmSbcnpService extends IService { + Map getMap(); + List getList(JSONObject json); diff --git a/src/main/java/com/dsic/gj_erp/service/jcsj/impl/EmSbcnpServiceImpl.java b/src/main/java/com/dsic/gj_erp/service/jcsj/impl/EmSbcnpServiceImpl.java index e7843d9..02e48f7 100644 --- a/src/main/java/com/dsic/gj_erp/service/jcsj/impl/EmSbcnpServiceImpl.java +++ b/src/main/java/com/dsic/gj_erp/service/jcsj/impl/EmSbcnpServiceImpl.java @@ -2,6 +2,7 @@ package com.dsic.gj_erp.service.jcsj.impl; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dsic.gj_erp.bean.jcsj.EmSbcnp; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -30,6 +32,12 @@ public class EmSbcnpServiceImpl extends ServiceImpl impl // @Resource // EmSbcnpRepository emSbcnpRepository; + + @Override + public Map getMap() { + return baseMapper.getMap(); + } + @Override public List getList(JSONObject json) { QueryWrapper queryWrapper=new QueryWrapper<>(); diff --git a/src/main/java/com/dsic/gj_erp/service/jhgk/impl/DmQfxqServiceImpl.java b/src/main/java/com/dsic/gj_erp/service/jhgk/impl/DmQfxqServiceImpl.java index 94b30a3..fd0a70d 100644 --- a/src/main/java/com/dsic/gj_erp/service/jhgk/impl/DmQfxqServiceImpl.java +++ b/src/main/java/com/dsic/gj_erp/service/jhgk/impl/DmQfxqServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dsic.gj_erp.bean.jhgk.DmQfxq; +import com.dsic.gj_erp.bean.jhgk.DmSygdMx; import com.dsic.gj_erp.bean.jhgk.DmYdjh; import com.dsic.gj_erp.mapper.jhgk.DmQfxqMapper; import com.dsic.gj_erp.service.jhgk.DmQfxqService; @@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -136,13 +138,44 @@ public class DmQfxqServiceImpl extends ServiceImpl impleme if (ydjhList.size() < 1) { System.out.println("当前导入的前方需求没有对应的三月滚动计划!"); } - for (DmYdjh dmYdjh : ydjhList) { - ydjhService.remove(new QueryWrapper() - .eq("Dc_Ch",dmYdjh.getDcCh()) - .eq("Dc_Pl",dmYdjh.getDcPl()) - .eq("Tzbh",dmYdjh.getTzbh())); - } +// for (DmYdjh dmYdjh : ydjhList) { +// ydjhService.remove(new QueryWrapper() +// .eq("Dc_Ch",dmYdjh.getDcCh()) +// .eq("Dc_Pl",dmYdjh.getDcPl()) +// .eq("Tzbh",dmYdjh.getTzbh())); +// } + Map> map = ydjhList.stream().collect(Collectors.groupingBy(mx -> mx.getDcCh() +"@"+ mx.getDcPl())); + this.removeByMulti(map); ydjhService.saveBatch(ydjhList); + + + } + + private void removeByMulti(Map> map){ + map.forEach((key,list)->{ + String[] str= key.split("@"); + this.removeByMulti(list,str[0],str[1],200); + }); + } + + private void removeByMulti(List list,String dcCh,String dcPl,int size){ + List tzbhList = list.stream().map(DmYdjh::getTzbh).collect(Collectors.toList()); + AtomicInteger index=new AtomicInteger(tzbhList.size()/size); + do { + int i = index.decrementAndGet(); + int i1 = tzbhList.size() % ((index.get()) * size); + int last=i1>0?i1:i*size; + List list1 = tzbhList.subList((index.get())*size, last); + this.remove(list1,dcCh,dcPl); + }while (index.get()>0); + } + + private void remove(List list,String dcCh,String dcPl){ + ydjhService.remove(Wrappers.lambdaQuery() + .eq(DmYdjh::getDcCh,dcCh) + .eq(DmYdjh::getDcPl,dcPl) + .in(DmYdjh::getTzbh,list) + ); } } diff --git a/src/main/resources/mappers/jcsj/EmSbcnpMapper.xml b/src/main/resources/mappers/jcsj/EmSbcnpMapper.xml index 5403089..0646c43 100644 --- a/src/main/resources/mappers/jcsj/EmSbcnpMapper.xml +++ b/src/main/resources/mappers/jcsj/EmSbcnpMapper.xml @@ -3,5 +3,7 @@ - +