修改上传BOOM
parent
854e4286de
commit
d33f950ffe
|
|
@ -1,17 +1,11 @@
|
|||
package com.youchain.basicdata.service.impl;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.youchain.basicdata.domain.*;
|
||||
import com.youchain.basicdata.repository.*;
|
||||
import com.youchain.basicdata.service.*;
|
||||
import com.youchain.businessdata.domain.Asn;
|
||||
import com.youchain.businessdata.domain.AsnDetail;
|
||||
import com.youchain.businessdata.inputJson.imports.BaseImport;
|
||||
import com.youchain.businessdata.inputJson.imports.BomAccountImport;
|
||||
import com.youchain.businessdata.inputJson.imports.invoicePackingImport;
|
||||
import com.youchain.businessdata.repository.AsnDetailRepository;
|
||||
import com.youchain.businessdata.repository.AsnRepository;
|
||||
import com.youchain.businessdata.service.AsnService;
|
||||
import com.youchain.domain.Log;
|
||||
import com.youchain.exception.BadRequestException;
|
||||
import com.youchain.utils.*;
|
||||
import lombok.Data;
|
||||
|
|
@ -22,7 +16,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -52,7 +45,64 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
@Transactional
|
||||
public void baseImportTemplate(MultipartFile file) {
|
||||
// 读取sheet数据
|
||||
List<BomAccountImport> dataList = FastExcelUtil.readExcelData(file, BomAccountImport.class, 0, 1);
|
||||
//13个开始4个一循环
|
||||
|
||||
|
||||
List<Map<Integer, Object>> list=FastExcelUtil.readExcelData2(file);
|
||||
log.info("开始导入list:"+list.size());
|
||||
List<BomEntity> dataList =new ArrayList<>();
|
||||
|
||||
for (Map<Integer, Object> map: list ) {
|
||||
|
||||
|
||||
BomEntity bomAccountImport=new BomEntity();
|
||||
bomAccountImport.setPf(map.get(0) != null ? map.get(0).toString() : "");
|
||||
bomAccountImport.setNs(map.get(1) != null ? map.get(1).toString() : "");
|
||||
bomAccountImport.setPm(map.get(2) != null ? map.get(2).toString() : "");
|
||||
bomAccountImport.setGys(map.get(3) != null ? map.get(3).toString() : "");
|
||||
bomAccountImport.setAc(map.get(4) != null ? map.get(4).toString() : "");
|
||||
bomAccountImport.setJgnr(map.get(5) != null ? map.get(5).toString() : "");
|
||||
bomAccountImport.setZcfq(map.get(6) != null ? map.get(6).toString() : "");
|
||||
bomAccountImport.setHw(map.get(7) != null ? map.get(7).toString() : "");
|
||||
bomAccountImport.setXz(map.get(8) != null ? map.get(8).toString() : "");
|
||||
bomAccountImport.setSrs(map.get(9) != null ? Integer.parseInt(map.get(9).toString()) : 0);
|
||||
bomAccountImport.setTckw(map.get(10) != null ? map.get(10).toString() : "");
|
||||
bomAccountImport.setDxw(map.get(11) != null ? map.get(11).toString() : "");
|
||||
bomAccountImport.setSb(map.get(12) != null ? map.get(12).toString() : "");
|
||||
|
||||
|
||||
for (int ccc=0;ccc<50;ccc++){
|
||||
BomEntity bomAccountImport_new=new BomEntity();
|
||||
int index=ccc*4+12;
|
||||
bomAccountImport_new.setJx((map.get((index+1)) != null ? map.get((index+1)).toString() : ""));
|
||||
bomAccountImport_new.setJxdm((map.get((index+2)) != null ? map.get((index+2)).toString() : ""));
|
||||
bomAccountImport_new.setKyh((map.get((index+3)) != null ? map.get((index+3)).toString() : ""));
|
||||
bomAccountImport_new.setTyl((map.get((index+4)) != null ? map.get((index+4)).toString() : ""));
|
||||
|
||||
log.error(bomAccountImport_new.getJx()+"---"+bomAccountImport_new.getTyl());
|
||||
|
||||
bomAccountImport_new.setPf(bomAccountImport.getPf());
|
||||
bomAccountImport_new.setNs(bomAccountImport.getNs());
|
||||
bomAccountImport_new.setPm(bomAccountImport.getPm());
|
||||
bomAccountImport_new.setGys(bomAccountImport.getGys());
|
||||
bomAccountImport_new.setAc(bomAccountImport.getAc());
|
||||
bomAccountImport_new.setJgnr(bomAccountImport.getJgnr());
|
||||
bomAccountImport_new.setZcfq(bomAccountImport.getZcfq());
|
||||
bomAccountImport_new.setHw(bomAccountImport.getHw());
|
||||
bomAccountImport_new.setXz(bomAccountImport.getXz());
|
||||
bomAccountImport_new.setSrs(bomAccountImport.getSrs());
|
||||
bomAccountImport_new.setTckw(bomAccountImport.getTckw());
|
||||
bomAccountImport_new.setDxw(bomAccountImport.getDxw());
|
||||
bomAccountImport_new.setSb(bomAccountImport.getSb());
|
||||
|
||||
if(bomAccountImport_new.getTyl().length()>0){
|
||||
dataList.add(bomAccountImport_new);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error(JSONUtil.toJsonStr(dataList));
|
||||
|
||||
// List<BomAccountImport> dataList = FastExcelUtil.readExcelData(file, BomAccountImport.class, 0, 1);
|
||||
|
||||
//批量导入
|
||||
importBomAccountData(dataList);
|
||||
|
|
@ -63,20 +113,20 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
* 处理批量导入
|
||||
*/
|
||||
@Transactional
|
||||
public void importBomAccountData(List<BomAccountImport> dataList) {
|
||||
public void importBomAccountData(List<BomEntity> bomEntitys) {
|
||||
// TODO: 实现批量导入逻辑
|
||||
// log.info("处理批量导入,数据条数: {}", dataList.size());
|
||||
Map<String,ItemEntity> itemEntitys=new HashMap<>();
|
||||
List<BomEntity> bomEntitys=new ArrayList<>();
|
||||
for (BomAccountImport data : dataList) {
|
||||
|
||||
for (BomEntity data : bomEntitys) {
|
||||
ItemEntity it=new ItemEntity();
|
||||
it.setAc(data.getAc());
|
||||
it.setPf(data.getPf());
|
||||
it.setXz(data.getXz());
|
||||
it.setPm(data.getPm());
|
||||
it.setSrs(data.getSrs());
|
||||
it.setSrs(data.getSrs()+"");
|
||||
itemEntitys.put(data.getPf(),it);
|
||||
bomEntitys=batchBomEntitys(data,bomEntitys);
|
||||
|
||||
|
||||
}
|
||||
//验证品番
|
||||
|
|
@ -87,7 +137,7 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
//验证完成品品番
|
||||
Map<String, BigItem> existBigItemMap = validateBigItem(bigItemNames);
|
||||
//获取文件中所有的库位
|
||||
List<String> hwCodes = dataList.stream().map(BomAccountImport::getHw).collect(Collectors.toList());
|
||||
List<String> hwCodes = bomEntitys.stream().map(BomEntity::getHw).collect(Collectors.toList());
|
||||
hwCodes = hwCodes.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
//验证库位
|
||||
Map<String, Point> existPointMap = validatePoint(hwCodes);
|
||||
|
|
@ -101,22 +151,24 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
Point point=existPointMap.get(entity.getHw());
|
||||
//完成品品番
|
||||
BigItem bigItem=existBigItemMap.get(entity.getJx());
|
||||
|
||||
|
||||
BomAccount existBom = bomAccountRepository.findByQnique(bigItem.getId(), item.getId(),entity.ns, point.getId());
|
||||
if(existBom==null){
|
||||
existBom=new BomAccount();
|
||||
BomAccount ba=this.BaEntity(existBom,entity,bigItem,item,point,entity.tyl,null);
|
||||
BomAccount ba=this.BaEntity(existBom,entity,bigItem,item,point,Integer.parseInt(entity.tyl),null);
|
||||
updateBomList.add(ba);
|
||||
}else {
|
||||
BomAccount ba = this.BaEntity(existBom, entity, bigItem,item, point, entity.tyl,null);
|
||||
BomAccount ba = this.BaEntity(existBom, entity, bigItem,item, point, Integer.parseInt(entity.tyl),null);
|
||||
createBomList.add(ba);
|
||||
}
|
||||
// if (isNew) {
|
||||
// bomAccountService.create(bomAccount);
|
||||
// bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_add");
|
||||
// } else {
|
||||
// bomAccountService.update(bomAccount);
|
||||
// bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_update");
|
||||
// }
|
||||
/* if (isNew) {
|
||||
bomAccountService.create(bomAccount);
|
||||
bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_add");
|
||||
} else {
|
||||
bomAccountService.update(bomAccount);
|
||||
bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_update");
|
||||
}*/
|
||||
if(CollectionUtils.isNotEmpty(createBomList)){
|
||||
bomAccountRepository.saveAll(createBomList);
|
||||
}
|
||||
|
|
@ -229,15 +281,6 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
"机型代码",
|
||||
"组顺/刻印号前2位",
|
||||
"台用量"
|
||||
// // 机型1-38 及对应的台用量
|
||||
// "机型1", "台用量1", "机型2", "台用量2", "机型3", "台用量3", "机型4", "台用量4", "机型5", "台用量5",
|
||||
// "机型6", "台用量6", "机型7", "台用量7", "机型8", "台用量8", "机型9", "台用量9", "机型10", "台用量10",
|
||||
// "机型11", "台用量11", "机型12", "台用量12", "机型13", "台用量13", "机型14", "台用量14", "机型15", "台用量15",
|
||||
// "机型16", "台用量16", "机型17", "台用量17", "机型18", "台用量18", "机型19", "台用量19", "机型20", "台用量20",
|
||||
// "机型21", "台用量21", "机型22", "台用量22", "机型23", "台用量23", "机型24", "台用量24", "机型25", "台用量25",
|
||||
// "机型26", "台用量26", "机型27", "台用量27", "机型28", "台用量28", "机型29", "台用量29", "机型30", "台用量30",
|
||||
// "机型31", "台用量31", "机型32", "台用量32", "机型33", "台用量33", "机型34", "台用量34", "机型35", "台用量35",
|
||||
// "机型36", "台用量36", "机型37", "台用量37", "机型38", "台用量38"
|
||||
);
|
||||
List<String> headers = FastExcelUtil.readHeadContent(file, requiredColumns, 0, 0);
|
||||
if (!SmartStringUtil.containsAllIgnoreCase(requiredColumns, headers)) {
|
||||
|
|
@ -279,8 +322,11 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
private String tckw;
|
||||
private String dxw;
|
||||
private String sb;
|
||||
|
||||
private String jx;
|
||||
private int tyl;
|
||||
private String jxdm;
|
||||
private String kyh;
|
||||
private String tyl;
|
||||
}
|
||||
|
||||
public BomAccount BaEntity(BomAccount ba,BomEntity data,BigItem bigItem,Item it,Point point,int dyl,Area outArea){
|
||||
|
|
@ -324,11 +370,11 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
entity.setDxw(data.getDxw());
|
||||
entity.setSb(data.getSb());
|
||||
entity.setJx(jx);
|
||||
entity.setTyl(tyl);
|
||||
//entity.setTyl(tyl);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public List<BomEntity> batchBomEntitys(BomAccountImport data, List<BomEntity> bomEntitys){
|
||||
/*public List<BomEntity> batchBomEntitys(BomAccountImport data, List<BomEntity> bomEntitys){
|
||||
if(data.getZcfq().equals("制造库位")) {
|
||||
if (StringUtils.isNotEmpty(data.getTyl1())) {
|
||||
BomEntity entity = createBomEntity(data, data.getJx1(), Integer.parseInt(data.getTyl1()));
|
||||
|
|
@ -487,6 +533,6 @@ public class ImportBomAccountServiceImpl implements ImportBomAccountService {
|
|||
bomEntitys.add(entity);
|
||||
}
|
||||
return bomEntitys;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 发票箱单导入
|
||||
* @author: youzhi.gao
|
||||
|
|
@ -57,232 +59,10 @@ public class BomAccountImport {
|
|||
@ExcelProperty("税别")
|
||||
private String sb;
|
||||
|
||||
@ExcelProperty("机型1")
|
||||
private String jx1;
|
||||
|
||||
@ExcelProperty("机型2")
|
||||
private String jx2;
|
||||
|
||||
@ExcelProperty("机型3")
|
||||
private String jx3;
|
||||
|
||||
@ExcelProperty("机型4")
|
||||
private String jx4;
|
||||
|
||||
@ExcelProperty("机型5")
|
||||
private String jx5;
|
||||
|
||||
@ExcelProperty("机型6")
|
||||
private String jx6;
|
||||
|
||||
@ExcelProperty("机型7")
|
||||
private String jx7;
|
||||
|
||||
@ExcelProperty("机型8")
|
||||
private String jx8;
|
||||
|
||||
@ExcelProperty("机型9")
|
||||
private String jx9;
|
||||
|
||||
@ExcelProperty("机型10")
|
||||
private String jx10;
|
||||
|
||||
@ExcelProperty("机型11")
|
||||
private String jx11;
|
||||
|
||||
@ExcelProperty("机型12")
|
||||
private String jx12;
|
||||
|
||||
@ExcelProperty("机型13")
|
||||
private String jx13;
|
||||
|
||||
@ExcelProperty("机型14")
|
||||
private String jx14;
|
||||
|
||||
@ExcelProperty("机型15")
|
||||
private String jx15;
|
||||
|
||||
@ExcelProperty("机型16")
|
||||
private String jx16;
|
||||
|
||||
@ExcelProperty("机型17")
|
||||
private String jx17;
|
||||
|
||||
@ExcelProperty("机型18")
|
||||
private String jx18;
|
||||
|
||||
@ExcelProperty("机型19")
|
||||
private String jx19;
|
||||
|
||||
@ExcelProperty("机型20")
|
||||
private String jx20;
|
||||
|
||||
@ExcelProperty("机型21")
|
||||
private String jx21;
|
||||
|
||||
@ExcelProperty("机型22")
|
||||
private String jx22;
|
||||
|
||||
@ExcelProperty("机型23")
|
||||
private String jx23;
|
||||
|
||||
@ExcelProperty("机型24")
|
||||
private String jx24;
|
||||
|
||||
@ExcelProperty("机型25")
|
||||
private String jx25;
|
||||
|
||||
@ExcelProperty("机型26")
|
||||
private String jx26;
|
||||
|
||||
@ExcelProperty("机型27")
|
||||
private String jx27;
|
||||
|
||||
@ExcelProperty("机型28")
|
||||
private String jx28;
|
||||
|
||||
@ExcelProperty("机型29")
|
||||
private String jx29;
|
||||
|
||||
@ExcelProperty("机型30")
|
||||
private String jx30;
|
||||
|
||||
@ExcelProperty("机型31")
|
||||
private String jx31;
|
||||
|
||||
@ExcelProperty("机型32")
|
||||
private String jx32;
|
||||
|
||||
@ExcelProperty("机型33")
|
||||
private String jx33;
|
||||
|
||||
@ExcelProperty("机型34")
|
||||
private String jx34;
|
||||
|
||||
@ExcelProperty("机型35")
|
||||
private String jx35;
|
||||
|
||||
@ExcelProperty("机型36")
|
||||
private String jx36;
|
||||
|
||||
@ExcelProperty("机型37")
|
||||
private String jx37;
|
||||
|
||||
@ExcelProperty("机型38")
|
||||
private String jx38;
|
||||
@ExcelProperty("台用量1")
|
||||
private String tyl1;
|
||||
|
||||
@ExcelProperty("台用量2")
|
||||
private String tyl2;
|
||||
|
||||
@ExcelProperty("台用量3")
|
||||
private String tyl3;
|
||||
|
||||
@ExcelProperty("台用量4")
|
||||
private String tyl4;
|
||||
|
||||
@ExcelProperty("台用量5")
|
||||
private String tyl5;
|
||||
|
||||
@ExcelProperty("台用量6")
|
||||
private String tyl6;
|
||||
|
||||
@ExcelProperty("台用量7")
|
||||
private String tyl7;
|
||||
|
||||
@ExcelProperty("台用量8")
|
||||
private String tyl8;
|
||||
|
||||
@ExcelProperty("台用量9")
|
||||
private String tyl9;
|
||||
|
||||
@ExcelProperty("台用量10")
|
||||
private String tyl10;
|
||||
|
||||
@ExcelProperty("台用量11")
|
||||
private String tyl11;
|
||||
|
||||
@ExcelProperty("台用量12")
|
||||
private String tyl12;
|
||||
|
||||
@ExcelProperty("台用量13")
|
||||
private String tyl13;
|
||||
|
||||
@ExcelProperty("台用量14")
|
||||
private String tyl14;
|
||||
|
||||
@ExcelProperty("台用量15")
|
||||
private String tyl15;
|
||||
|
||||
@ExcelProperty("台用量16")
|
||||
private String tyl16;
|
||||
|
||||
@ExcelProperty("台用量17")
|
||||
private String tyl17;
|
||||
|
||||
@ExcelProperty("台用量18")
|
||||
private String tyl18;
|
||||
|
||||
@ExcelProperty("台用量19")
|
||||
private String tyl19;
|
||||
|
||||
@ExcelProperty("台用量20")
|
||||
private String tyl20;
|
||||
|
||||
@ExcelProperty("台用量21")
|
||||
private String tyl21;
|
||||
|
||||
@ExcelProperty("台用量22")
|
||||
private String tyl22;
|
||||
|
||||
@ExcelProperty("台用量23")
|
||||
private String tyl23;
|
||||
|
||||
@ExcelProperty("台用量24")
|
||||
private String tyl24;
|
||||
|
||||
@ExcelProperty("台用量25")
|
||||
private String tyl25;
|
||||
|
||||
@ExcelProperty("台用量26")
|
||||
private String tyl26;
|
||||
|
||||
@ExcelProperty("台用量27")
|
||||
private String tyl27;
|
||||
|
||||
@ExcelProperty("台用量28")
|
||||
private String tyl28;
|
||||
|
||||
@ExcelProperty("台用量29")
|
||||
private String tyl29;
|
||||
|
||||
@ExcelProperty("台用量30")
|
||||
private String tyl30;
|
||||
|
||||
@ExcelProperty("台用量31")
|
||||
private String tyl31;
|
||||
|
||||
@ExcelProperty("台用量32")
|
||||
private String tyl32;
|
||||
|
||||
@ExcelProperty("台用量33")
|
||||
private String tyl33;
|
||||
|
||||
@ExcelProperty("台用量34")
|
||||
private String tyl34;
|
||||
|
||||
@ExcelProperty("台用量35")
|
||||
private String tyl35;
|
||||
|
||||
@ExcelProperty("台用量36")
|
||||
private String tyl36;
|
||||
|
||||
@ExcelProperty("台用量37")
|
||||
private String tyl37;
|
||||
|
||||
@ExcelProperty("台用量38")
|
||||
private String tyl38;
|
||||
private String jx;
|
||||
private String jxdm;
|
||||
private String kyh;
|
||||
private String tyl;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -169,6 +169,18 @@ public class FastExcelUtil {
|
|||
return dataList;
|
||||
}
|
||||
|
||||
|
||||
public static List<Map<Integer, Object>> readExcelData2(MultipartFile file) {
|
||||
try {
|
||||
return FastExcel.read(file.getInputStream())
|
||||
.sheet() // 默认读取第一个Sheet
|
||||
.doReadSync();
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("数据格式存在问题,无法读取");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取Excel文件中指定位置的单元格值
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue