parent
189581056d
commit
ada139b164
@ -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> T getBean(Class<T> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<Object> workerList;
|
||||||
|
|
||||||
|
Map<String, EmSbcnp> baseCapacity;
|
||||||
|
|
||||||
|
List<EmGcrl> gcrlList;
|
||||||
|
|
||||||
|
JSONObject realCapacityMap;
|
||||||
|
|
||||||
|
List<EmSbjbb> deviceList;
|
||||||
|
|
||||||
|
JSONObject realDeviceList;
|
||||||
|
|
||||||
|
List<DmSygdMx> 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<EmGcrl> 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<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());
|
||||||
|
//计算可用设备的可用日期
|
||||||
|
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<DateTime> 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> T getBean(Class<T> clazz) {
|
||||||
|
return SpringContextHolder.getBean(clazz);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue