|
|
|
@ -9,7 +9,6 @@ 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,18 +16,16 @@ import com.dsic.gj_erp.service.jhgk.DmXbjhService;
|
|
|
|
|
import com.dsic.gj_erp.util.ExcelUtil;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.modelmapper.ModelMapper;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
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;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -46,6 +43,9 @@ public class DmXbjhServiceImpl extends ServiceImpl<DmXbjhMapper, DmXbjh> impleme
|
|
|
|
|
@Resource
|
|
|
|
|
ModelMapper modelMapper;
|
|
|
|
|
|
|
|
|
|
@Value("${xbjh-path}")
|
|
|
|
|
String xbjhPath;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, List<DmXbjh>> getList(JSONObject json) {
|
|
|
|
|
QueryWrapper<DmXbjh> queryWrapper = new QueryWrapper<>();
|
|
|
|
@ -83,18 +83,31 @@ public class DmXbjhServiceImpl extends ServiceImpl<DmXbjhMapper, DmXbjh> impleme
|
|
|
|
|
public JSONObject upload(MultipartFile file) throws IOException {
|
|
|
|
|
JSONObject dmXbjhs = ExcelUtil.readDmXbjh(file);
|
|
|
|
|
if (dmXbjhs != null) {
|
|
|
|
|
List<DmXbjh> listByNf = list(Wrappers.<DmXbjh>lambdaQuery().eq(DmXbjh::getNf, dmXbjhs.getString("nf")));
|
|
|
|
|
this.save(dmXbjhs);
|
|
|
|
|
File[] files = FileUtil.ls(xbjhPath);
|
|
|
|
|
AtomicInteger maxVersion= new AtomicInteger(0);
|
|
|
|
|
if (files.length > 0) {
|
|
|
|
|
HashSet<String> names = new HashSet<>();
|
|
|
|
|
for (File file1 : files) {
|
|
|
|
|
String name = FileUtil.getPrefix(file1.getName());
|
|
|
|
|
String[] s = name.split("_");
|
|
|
|
|
names.add(s[s.length - 1]);
|
|
|
|
|
}
|
|
|
|
|
String tmpVersion=names.stream().max(String::compareTo).get();
|
|
|
|
|
Optional.of(tmpVersion).ifPresent(item->{
|
|
|
|
|
String v = item.replace("v", "");
|
|
|
|
|
maxVersion.set(Integer.parseInt(v));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String type = FileUtil.extName(file.getOriginalFilename());
|
|
|
|
|
File uploadFile = new File("./线表计划");
|
|
|
|
|
File uploadFile = new File(xbjhPath);
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
int version = maxVersion.incrementAndGet();
|
|
|
|
|
File uploadFiles = new File(StrUtil.format("{}/{}_{}{}{}{}", xbjhPath,DateUtil.thisYear(), "v",version, StrUtil.DOT, type));
|
|
|
|
|
file.transferTo(uploadFiles);
|
|
|
|
|
this.save(dmXbjhs);
|
|
|
|
|
}
|
|
|
|
|
return dmXbjhs;
|
|
|
|
|
}
|
|
|
|
|