|
|
|
@ -8,6 +8,8 @@ import com.dsic.gj_erp.annotation.AuthFunction;
|
|
|
|
|
import com.dsic.gj_erp.bean.ResultBean;
|
|
|
|
|
import com.dsic.gj_erp.bean.jcsj.DmBom;
|
|
|
|
|
import com.dsic.gj_erp.bean.jcsj.DmTltpdf;
|
|
|
|
|
import com.dsic.gj_erp.bean.sy.Dm_zhbmp;
|
|
|
|
|
import com.dsic.gj_erp.dao.sy.Dm_zhbmpRepository;
|
|
|
|
|
import com.dsic.gj_erp.exception.CustomException;
|
|
|
|
|
import com.dsic.gj_erp.mapper.jcsj.DmBomMapper;
|
|
|
|
|
import com.dsic.gj_erp.service.jcsj.DmBomService;
|
|
|
|
@ -26,6 +28,7 @@ import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -48,6 +51,9 @@ public class BomUploadController {
|
|
|
|
|
@Autowired
|
|
|
|
|
DmTltpdfService tltpdfService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
Dm_zhbmpRepository dm_zhbmpRepository;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/uploadBom")
|
|
|
|
|
@AuthFunction
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -69,121 +75,132 @@ public class BomUploadController {
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public boolean uploadPDF(MultipartFile[] fileList, String dcCh,String pl,String date)throws IOException {
|
|
|
|
|
List<Dm_zhbmp> kwxxs = dm_zhbmpRepository.findByBMLB("KWXX");
|
|
|
|
|
|
|
|
|
|
Map<String, String> kwxxMap = kwxxs.stream().collect(Collectors.toMap(Dm_zhbmp::getBM, Dm_zhbmp::getBmsm));
|
|
|
|
|
for (MultipartFile file : fileList) {//船号_批量/日期/PDF(ERP)
|
|
|
|
|
String url= com.dsic.gj_erp.util.FileUtil.handlerUpload(file,"/"+dcCh+"_"+pl+"/"+date+"/PDF");
|
|
|
|
|
PDDocument document = PDDocument.load(file.getInputStream());
|
|
|
|
|
int pageNum = document.getNumberOfPages();
|
|
|
|
|
PDFTextStripper stripper = new PDFTextStripper();
|
|
|
|
|
// stripper .setSortByPosition(true); //设置为true 则按照行进行读取,默认是false
|
|
|
|
|
// // 3、获取指定页面的文本内容
|
|
|
|
|
// stripper.setStartPage(1);// 设置起始页面,表示读取第一个页面
|
|
|
|
|
// stripper.setEndPage(1); // 设置结束页面,表示读取第一个页面
|
|
|
|
|
// String[] text = stripper.getText(document).split("\r\n");
|
|
|
|
|
// String dcCh=text[46];
|
|
|
|
|
// String pl=text[38].substring(1,4);
|
|
|
|
|
// String th=text[29];
|
|
|
|
|
stripper.setStartPage(2);// 设置起始页面,表示读取第一个页面
|
|
|
|
|
stripper.setEndPage(2); // 设置结束页面,表示读取第一个页面
|
|
|
|
|
String[] text = stripper.getText(document).split("序号零件编号")[1].split(" ");
|
|
|
|
|
// String dcCh=text[2].split("\r\n")[1];
|
|
|
|
|
// String pl=text[3];
|
|
|
|
|
String th=text[6].substring(0,12);
|
|
|
|
|
//删除导入过的同船、批量、图号的数据,
|
|
|
|
|
tltpdfService.remove(new QueryWrapper<DmTltpdf>()
|
|
|
|
|
.eq("dc_ch",dcCh)
|
|
|
|
|
.eq("pl",pl)
|
|
|
|
|
.eq("th",th)
|
|
|
|
|
);
|
|
|
|
|
List<DmTltpdf> list=new ArrayList<>();
|
|
|
|
|
for (int i = 1; i <= pageNum; i++) {
|
|
|
|
|
try {
|
|
|
|
|
stripper.setStartPage(i);
|
|
|
|
|
stripper.setEndPage(i);
|
|
|
|
|
String s = stripper.getText(document);//本页文字内容
|
|
|
|
|
String[] a=s.split("\r\n");//分行
|
|
|
|
|
String tlth="";
|
|
|
|
|
Double hxcd=0.0;
|
|
|
|
|
Double qgcd=0.0;
|
|
|
|
|
Double hxkc=0.0;
|
|
|
|
|
Double qgkc=0.0;
|
|
|
|
|
if (i>1){
|
|
|
|
|
tlth=s.split("序号零件编号")[1].split(" ")[5];
|
|
|
|
|
String num[]=s.split("序号零件编号")[1].split("\r\n");
|
|
|
|
|
hxcd=new Double(num[2]);
|
|
|
|
|
qgcd=new Double(num[3]);
|
|
|
|
|
hxkc=new Double(num[4]);
|
|
|
|
|
qgkc=new Double(num[5]);
|
|
|
|
|
}
|
|
|
|
|
// System.out.println("第 " + i +"/"+pageNum+ " 页 :" );
|
|
|
|
|
//按页保存
|
|
|
|
|
DmTltpdf tltpdf=new DmTltpdf();
|
|
|
|
|
tltpdf.setDcCh(dcCh);
|
|
|
|
|
tltpdf.setTh(th);
|
|
|
|
|
tltpdf.setPl(pl);
|
|
|
|
|
tltpdf.setTlth(tlth);
|
|
|
|
|
tltpdf.setPageNum(i +"/"+pageNum);
|
|
|
|
|
tltpdf.setContent(s);
|
|
|
|
|
tltpdf.setFilePath(url);
|
|
|
|
|
tltpdf.setHxcd(hxcd);
|
|
|
|
|
tltpdf.setQgcd(qgcd);
|
|
|
|
|
tltpdf.setHxkc(hxkc);
|
|
|
|
|
tltpdf.setQgkc(qgkc);
|
|
|
|
|
list.add(tltpdf);
|
|
|
|
|
if (i==1)continue;
|
|
|
|
|
Double ljzl=0.0;
|
|
|
|
|
String tlth1[]=s.split("DNV\\+CCS")[1].split("\r\n");
|
|
|
|
|
ljzl=new Double(tlth1[1]);
|
|
|
|
|
if (ljzl==0.0)continue;
|
|
|
|
|
//根据当前页数据,修改BOM中零件属性 坡口 打磨 曲
|
|
|
|
|
int ljCount= s.split("\\|")[0].split("\r\n").length;//零件数量
|
|
|
|
|
if (ljCount==11||ljCount==21||ljCount==31){
|
|
|
|
|
//取用下标count-1 至 count*2-2的数组,为属性
|
|
|
|
|
String[] sxArray=getArrayByIndex(a,ljCount-1,ljCount*2-2);
|
|
|
|
|
if(file.getOriginalFilename().contains(".QG")){
|
|
|
|
|
String s = kwxxMap.get(file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("/")+1).substring(4, 7));
|
|
|
|
|
String url= com.dsic.gj_erp.util.FileUtil.handlerUpload(file,"/"+dcCh+"_"+pl+"/"+date+"/QG"+"/"+s);
|
|
|
|
|
|
|
|
|
|
//取用下标count*2-2 至 count*3-3 的数组,为零件号
|
|
|
|
|
String[] ljArray=getArrayByIndex(a,ljCount*2-2,ljCount*3-3);
|
|
|
|
|
bomMapper.insertFile(url,"");
|
|
|
|
|
}else if (file.getOriginalFilename().contains(".pdf")){
|
|
|
|
|
|
|
|
|
|
System.out.println(ljCount);
|
|
|
|
|
System.out.println(i);
|
|
|
|
|
for (int j = 0; j < ljArray.length; j++) {
|
|
|
|
|
String ljbh;//零件号
|
|
|
|
|
String sx;//属性
|
|
|
|
|
if (i==0){
|
|
|
|
|
String[] b= ljArray[j].split("0\\|");
|
|
|
|
|
ljbh=b[b.length-1];
|
|
|
|
|
sx=sxArray[j].split("\\|")[4];
|
|
|
|
|
}else {
|
|
|
|
|
ljbh=ljArray[j];
|
|
|
|
|
sx=sxArray[j].split("\\|")[4];
|
|
|
|
|
}
|
|
|
|
|
updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
}
|
|
|
|
|
}else if (ljCount==1){
|
|
|
|
|
//"1,11,21,31"
|
|
|
|
|
String[] ljxx= a[0].split("\\|");
|
|
|
|
|
String ljbh= ljxx[ljxx.length-1];//零件号
|
|
|
|
|
String sx= ljxx[4];//属性
|
|
|
|
|
updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
}else {
|
|
|
|
|
//取用下标count 至 count*2-1的数组,为属性
|
|
|
|
|
String[] sxArray=getArrayByIndex(a,ljCount,ljCount*2-1);
|
|
|
|
|
//取用下标count*2 至 count*3-1 的数组,为零件号
|
|
|
|
|
String[] ljArray=getArrayByIndex(a,ljCount*2,ljCount*3-1);
|
|
|
|
|
for (int j = 0; j < ljArray.length; j++) {
|
|
|
|
|
String ljbh=ljArray[j];//零件号
|
|
|
|
|
String sx=sxArray[j].split("\\|")[4];//属性
|
|
|
|
|
updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
String logMsg= StrUtil.format("数控套料图pdf读取错误--图号:{},页数:{}",th,i);
|
|
|
|
|
log.error(logMsg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String url= com.dsic.gj_erp.util.FileUtil.handlerUpload(file,"/"+dcCh+"_"+pl+"/"+date+"/PDF");
|
|
|
|
|
// PDDocument document = PDDocument.load(file.getInputStream());
|
|
|
|
|
// int pageNum = document.getNumberOfPages();
|
|
|
|
|
// PDFTextStripper stripper = new PDFTextStripper();
|
|
|
|
|
//// stripper .setSortByPosition(true); //设置为true 则按照行进行读取,默认是false
|
|
|
|
|
//// // 3、获取指定页面的文本内容
|
|
|
|
|
//// stripper.setStartPage(1);// 设置起始页面,表示读取第一个页面
|
|
|
|
|
//// stripper.setEndPage(1); // 设置结束页面,表示读取第一个页面
|
|
|
|
|
//// String[] text = stripper.getText(document).split("\r\n");
|
|
|
|
|
//// String dcCh=text[46];
|
|
|
|
|
//// String pl=text[38].substring(1,4);
|
|
|
|
|
//// String th=text[29];
|
|
|
|
|
// stripper.setStartPage(2);// 设置起始页面,表示读取第一个页面
|
|
|
|
|
// stripper.setEndPage(2); // 设置结束页面,表示读取第一个页面
|
|
|
|
|
// String[] text = stripper.getText(document).split("序号零件编号")[1].split(" ");
|
|
|
|
|
//// String dcCh=text[2].split("\r\n")[1];
|
|
|
|
|
//// String pl=text[3];
|
|
|
|
|
// String th=text[6].substring(0,12);
|
|
|
|
|
// //删除导入过的同船、批量、图号的数据,
|
|
|
|
|
// tltpdfService.remove(new QueryWrapper<DmTltpdf>()
|
|
|
|
|
// .eq("dc_ch",dcCh)
|
|
|
|
|
// .eq("pl",pl)
|
|
|
|
|
// .eq("th",th)
|
|
|
|
|
// );
|
|
|
|
|
// List<DmTltpdf> list=new ArrayList<>();
|
|
|
|
|
// for (int i = 1; i <= pageNum; i++) {
|
|
|
|
|
// try {
|
|
|
|
|
// stripper.setStartPage(i);
|
|
|
|
|
// stripper.setEndPage(i);
|
|
|
|
|
// String s = stripper.getText(document);//本页文字内容
|
|
|
|
|
// String[] a=s.split("\r\n");//分行
|
|
|
|
|
// String tlth="";
|
|
|
|
|
// Double hxcd=0.0;
|
|
|
|
|
// Double qgcd=0.0;
|
|
|
|
|
// Double hxkc=0.0;
|
|
|
|
|
// Double qgkc=0.0;
|
|
|
|
|
// if (i>1){
|
|
|
|
|
// tlth=s.split("序号零件编号")[1].split(" ")[5];
|
|
|
|
|
// String num[]=s.split("序号零件编号")[1].split("\r\n");
|
|
|
|
|
// hxcd=new Double(num[2]);
|
|
|
|
|
// qgcd=new Double(num[3]);
|
|
|
|
|
// hxkc=new Double(num[4]);
|
|
|
|
|
// qgkc=new Double(num[5]);
|
|
|
|
|
// }
|
|
|
|
|
//// System.out.println("第 " + i +"/"+pageNum+ " 页 :" );
|
|
|
|
|
// //按页保存
|
|
|
|
|
// DmTltpdf tltpdf=new DmTltpdf();
|
|
|
|
|
// tltpdf.setDcCh(dcCh);
|
|
|
|
|
// tltpdf.setTh(th);
|
|
|
|
|
// tltpdf.setPl(pl);
|
|
|
|
|
// tltpdf.setTlth(tlth);
|
|
|
|
|
// tltpdf.setPageNum(i +"/"+pageNum);
|
|
|
|
|
// tltpdf.setContent(s);
|
|
|
|
|
// tltpdf.setFilePath(url);
|
|
|
|
|
// tltpdf.setHxcd(hxcd);
|
|
|
|
|
// tltpdf.setQgcd(qgcd);
|
|
|
|
|
// tltpdf.setHxkc(hxkc);
|
|
|
|
|
// tltpdf.setQgkc(qgkc);
|
|
|
|
|
// list.add(tltpdf);
|
|
|
|
|
// if (i==1)continue;
|
|
|
|
|
// Double ljzl=0.0;
|
|
|
|
|
// String tlth1[]=s.split("DNV\\+CCS")[1].split("\r\n");
|
|
|
|
|
// ljzl=new Double(tlth1[1]);
|
|
|
|
|
// if (ljzl==0.0)continue;
|
|
|
|
|
// //根据当前页数据,修改BOM中零件属性 坡口 打磨 曲
|
|
|
|
|
// int ljCount= s.split("\\|")[0].split("\r\n").length;//零件数量
|
|
|
|
|
// if (ljCount==11||ljCount==21||ljCount==31){
|
|
|
|
|
// //取用下标count-1 至 count*2-2的数组,为属性
|
|
|
|
|
// String[] sxArray=getArrayByIndex(a,ljCount-1,ljCount*2-2);
|
|
|
|
|
//
|
|
|
|
|
// //取用下标count*2-2 至 count*3-3 的数组,为零件号
|
|
|
|
|
// String[] ljArray=getArrayByIndex(a,ljCount*2-2,ljCount*3-3);
|
|
|
|
|
//
|
|
|
|
|
// System.out.println(ljCount);
|
|
|
|
|
// System.out.println(i);
|
|
|
|
|
// for (int j = 0; j < ljArray.length; j++) {
|
|
|
|
|
// String ljbh;//零件号
|
|
|
|
|
// String sx;//属性
|
|
|
|
|
// if (i==0){
|
|
|
|
|
// String[] b= ljArray[j].split("0\\|");
|
|
|
|
|
// ljbh=b[b.length-1];
|
|
|
|
|
// sx=sxArray[j].split("\\|")[4];
|
|
|
|
|
// }else {
|
|
|
|
|
// ljbh=ljArray[j];
|
|
|
|
|
// sx=sxArray[j].split("\\|")[4];
|
|
|
|
|
// }
|
|
|
|
|
// updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
// }
|
|
|
|
|
// }else if (ljCount==1){
|
|
|
|
|
// //"1,11,21,31"
|
|
|
|
|
// String[] ljxx= a[0].split("\\|");
|
|
|
|
|
// String ljbh= ljxx[ljxx.length-1];//零件号
|
|
|
|
|
// String sx= ljxx[4];//属性
|
|
|
|
|
// updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
// }else {
|
|
|
|
|
// //取用下标count 至 count*2-1的数组,为属性
|
|
|
|
|
// String[] sxArray=getArrayByIndex(a,ljCount,ljCount*2-1);
|
|
|
|
|
// //取用下标count*2 至 count*3-1 的数组,为零件号
|
|
|
|
|
// String[] ljArray=getArrayByIndex(a,ljCount*2,ljCount*3-1);
|
|
|
|
|
// for (int j = 0; j < ljArray.length; j++) {
|
|
|
|
|
// String ljbh=ljArray[j];//零件号
|
|
|
|
|
// String sx=sxArray[j].split("\\|")[4];//属性
|
|
|
|
|
// updateBom(sx,dcCh,pl,tlth,ljbh);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }catch (Exception e){
|
|
|
|
|
// String logMsg= StrUtil.format("数控套料图pdf读取错误--图号:{},页数:{}",th,i);
|
|
|
|
|
// log.error(logMsg);
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// tltpdfService.saveBatch(list);
|
|
|
|
|
// document.close();
|
|
|
|
|
}
|
|
|
|
|
tltpdfService.saveBatch(list);
|
|
|
|
|
document.close();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -222,6 +239,7 @@ public class BomUploadController {
|
|
|
|
|
.eq("ljbh",ljbh)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|