|
|
|
@ -1,10 +1,15 @@
|
|
|
|
|
package com.dsic.gj_erp.service.jhgk.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
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.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.dsic.gj_erp.bean.jhgk.DmXbjh;
|
|
|
|
|
import com.dsic.gj_erp.mapper.jhgk.DmXbjhMapper;
|
|
|
|
@ -17,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
@ -40,69 +47,72 @@ public class DmXbjhServiceImpl extends ServiceImpl<DmXbjhMapper, DmXbjh> impleme
|
|
|
|
|
ModelMapper modelMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String,List<DmXbjh>> getList(JSONObject json) {
|
|
|
|
|
QueryWrapper<DmXbjh> queryWrapper=new QueryWrapper<>();
|
|
|
|
|
if(StringUtils.isNotEmpty(json.getString("dcCh"))){
|
|
|
|
|
queryWrapper.eq("dc_ch",json.getString("dcCh"));
|
|
|
|
|
public Map<String, List<DmXbjh>> getList(JSONObject json) {
|
|
|
|
|
QueryWrapper<DmXbjh> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
if (StringUtils.isNotEmpty(json.getString("dcCh"))) {
|
|
|
|
|
queryWrapper.eq("dc_ch", json.getString("dcCh"));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotEmpty(json.getString("Zt"))){
|
|
|
|
|
queryWrapper.eq("zt",json.getString("Zt"));
|
|
|
|
|
if (StringUtils.isNotEmpty(json.getString("Zt"))) {
|
|
|
|
|
queryWrapper.eq("zt", json.getString("Zt"));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotEmpty(json.getString("nf"))){
|
|
|
|
|
String nf=json.getString("nf");
|
|
|
|
|
String startTime=nf.split("~")[0];
|
|
|
|
|
String endTime=nf.split("~")[1];
|
|
|
|
|
queryWrapper.between("nf",startTime,endTime);
|
|
|
|
|
if (StringUtils.isNotEmpty(json.getString("nf"))) {
|
|
|
|
|
String nf = json.getString("nf");
|
|
|
|
|
String startTime = nf.split("~")[0];
|
|
|
|
|
String endTime = nf.split("~")[1];
|
|
|
|
|
queryWrapper.between("nf", startTime, endTime);
|
|
|
|
|
}
|
|
|
|
|
queryWrapper.orderByDesc("zl");
|
|
|
|
|
List<DmXbjh> dmTzjhs=dmXbjhMapper.selectList(queryWrapper);
|
|
|
|
|
Map<String,List<DmXbjh>> map=dmTzjhs.stream()
|
|
|
|
|
List<DmXbjh> dmTzjhs = dmXbjhMapper.selectList(queryWrapper);
|
|
|
|
|
Map<String, List<DmXbjh>> map = dmTzjhs.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(DmXbjh::getDcCh));
|
|
|
|
|
|
|
|
|
|
//对map的value进行排序,并返回降序以后的map集合
|
|
|
|
|
LinkedHashMap<String, List<DmXbjh>> collect = map.entrySet().stream().sorted((entry1, entry2) -> {
|
|
|
|
|
Double zl1=entry1.getValue().stream().filter(l->ObjectUtil.isNotEmpty(l.getZl())).mapToDouble(DmXbjh::getZl).sum();
|
|
|
|
|
Double zl2=entry2.getValue().stream().filter(l->ObjectUtil.isNotEmpty(l.getZl())).mapToDouble(DmXbjh::getZl).sum();
|
|
|
|
|
Double zl1 = entry1.getValue().stream().filter(l -> ObjectUtil.isNotEmpty(l.getZl())).mapToDouble(DmXbjh::getZl).sum();
|
|
|
|
|
Double zl2 = entry2.getValue().stream().filter(l -> ObjectUtil.isNotEmpty(l.getZl())).mapToDouble(DmXbjh::getZl).sum();
|
|
|
|
|
//降序排序
|
|
|
|
|
return zl2.compareTo(zl1);
|
|
|
|
|
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,(oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
|
|
|
|
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
|
|
|
|
|
|
|
|
|
return collect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public JSONObject upload(MultipartFile file) throws IOException {
|
|
|
|
|
// ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
|
|
|
|
|
//List<DmXbjh> dmXbjhs= ExcelUtil.readDmXbjh(file);
|
|
|
|
|
JSONObject dmXbjhs= ExcelUtil.readDmXbjh(file);
|
|
|
|
|
|
|
|
|
|
// List<DmXbjh> list=new ArrayList<>();
|
|
|
|
|
// mapList.forEach(stringObjectMap -> {
|
|
|
|
|
// DmXbjh dmXbjh = modelMapper.map(stringObjectMap, DmXbjh.class);
|
|
|
|
|
// dmXbjh.setZt("0");
|
|
|
|
|
// list.add(dmXbjh);
|
|
|
|
|
// });
|
|
|
|
|
JSONObject dmXbjhs = ExcelUtil.readDmXbjh(file);
|
|
|
|
|
if (dmXbjhs != null) {
|
|
|
|
|
List<DmXbjh> listByNf = list(Wrappers.<DmXbjh>lambdaQuery().eq(DmXbjh::getNf, dmXbjhs.getString("nf")));
|
|
|
|
|
this.save(dmXbjhs);
|
|
|
|
|
|
|
|
|
|
String type = FileUtil.extName(file.getOriginalFilename());
|
|
|
|
|
File uploadFile = new File("./线表计划");
|
|
|
|
|
if (!uploadFile.exists()) {
|
|
|
|
|
uploadFile.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
int version = !listByNf.isEmpty() ? listByNf.get(0).getVersion() + 1 : 1;
|
|
|
|
|
File uploadFiles = new File(StrUtil.format("./线表计划/{}_{}{}{}", dmXbjhs.getString("nf"), version, StrUtil.DOT, type));
|
|
|
|
|
|
|
|
|
|
file.transferTo(uploadFiles);
|
|
|
|
|
}
|
|
|
|
|
return dmXbjhs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void save(JSONObject json) {
|
|
|
|
|
List<DmXbjh> dmXbjhs=new ArrayList<>();
|
|
|
|
|
for (String key:json.keySet()) {
|
|
|
|
|
JSONArray jsonArray=json.getJSONArray(key);
|
|
|
|
|
for (Object object:jsonArray) {
|
|
|
|
|
List<DmXbjh> dmXbjhs = new ArrayList<>();
|
|
|
|
|
for (String key : json.keySet()) {
|
|
|
|
|
JSONArray jsonArray = json.getJSONArray(key);
|
|
|
|
|
for (Object object : jsonArray) {
|
|
|
|
|
// JSONObject dmxb=JSONObject.parseObject(object.toString());
|
|
|
|
|
DmXbjh dmXbjh= modelMapper.map(object,DmXbjh.class);
|
|
|
|
|
DmXbjh dmXbjh = modelMapper.map(object, DmXbjh.class);
|
|
|
|
|
dmXbjh.setDcCh(key);
|
|
|
|
|
dmXbjhs.add(dmXbjh);
|
|
|
|
|
this.remove(new QueryWrapper<DmXbjh>().eq("dc_ch",dmXbjh.getDcCh())
|
|
|
|
|
.eq("nf",dmXbjh.getNf())
|
|
|
|
|
.eq("yf",dmXbjh.getYf())
|
|
|
|
|
this.remove(new QueryWrapper<DmXbjh>().eq("dc_ch", dmXbjh.getDcCh())
|
|
|
|
|
.eq("nf", dmXbjh.getNf())
|
|
|
|
|
.eq("yf", dmXbjh.getYf())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|