1.增加首页看板

2.增加实际产能计算
master
董哲奇 1 year ago
parent 189581056d
commit ada139b164

@ -171,7 +171,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.15</version>
<version>5.8.25</version>
</dependency>
<dependency>

@ -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);
}
}

@ -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;
}

@ -59,4 +59,7 @@ public class EmSbcnp implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@ApiModelProperty(value = "夜班定额工时")
private Double degsYb;
}

@ -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;
}

@ -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;
/**
* <p>
@ -13,5 +16,6 @@ import com.dsic.gj_erp.bean.jcsj.EmSbcnp;
* @since 2023-09-15
*/
public interface EmSbcnpMapper extends BaseMapper<EmSbcnp> {
@MapKey("sbbh")
Map<String,EmSbcnp> getMap();
}

@ -20,6 +20,8 @@ import java.util.Map;
* @since 2023-09-15
*/
public interface EmSbcnpService extends IService<EmSbcnp> {
Map<String, EmSbcnp> getMap();
List<EmSbcnp> getList(JSONObject json);

@ -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<EmSbcnpMapper, EmSbcnp> impl
// @Resource
// EmSbcnpRepository emSbcnpRepository;
@Override
public Map<String, EmSbcnp> getMap() {
return baseMapper.getMap();
}
@Override
public List<EmSbcnp> getList(JSONObject json) {
QueryWrapper<EmSbcnp> queryWrapper=new QueryWrapper<>();

@ -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<DmQfxqMapper, DmQfxq> impleme
if (ydjhList.size() < 1) {
System.out.println("当前导入的前方需求没有对应的三月滚动计划!");
}
for (DmYdjh dmYdjh : ydjhList) {
ydjhService.remove(new QueryWrapper<DmYdjh>()
.eq("Dc_Ch",dmYdjh.getDcCh())
.eq("Dc_Pl",dmYdjh.getDcPl())
.eq("Tzbh",dmYdjh.getTzbh()));
}
// for (DmYdjh dmYdjh : ydjhList) {
// ydjhService.remove(new QueryWrapper<DmYdjh>()
// .eq("Dc_Ch",dmYdjh.getDcCh())
// .eq("Dc_Pl",dmYdjh.getDcPl())
// .eq("Tzbh",dmYdjh.getTzbh()));
// }
Map<String, List<DmYdjh>> map = ydjhList.stream().collect(Collectors.groupingBy(mx -> mx.getDcCh() +"@"+ mx.getDcPl()));
this.removeByMulti(map);
ydjhService.saveBatch(ydjhList);
}
private void removeByMulti(Map<String, List<DmYdjh>> map){
map.forEach((key,list)->{
String[] str= key.split("@");
this.removeByMulti(list,str[0],str[1],200);
});
}
private void removeByMulti(List<DmYdjh> list,String dcCh,String dcPl,int size){
List<String> 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<String> list1 = tzbhList.subList((index.get())*size, last);
this.remove(list1,dcCh,dcPl);
}while (index.get()>0);
}
private void remove(List<String> list,String dcCh,String dcPl){
ydjhService.remove(Wrappers.<DmYdjh>lambdaQuery()
.eq(DmYdjh::getDcCh,dcCh)
.eq(DmYdjh::getDcPl,dcPl)
.in(DmYdjh::getTzbh,list)
);
}
}

@ -3,5 +3,7 @@
<mapper namespace="com.dsic.gj_erp.mapper.jcsj.EmSbcnpMapper">
<select id="getMap" resultType="com.dsic.gj_erp.bean.jcsj.EmSbcnp">
select * from em_sbcnp
</select>
</mapper>

Loading…
Cancel
Save