PDF导入,保存到数据库,并且修正BOM中的坡口、打磨、曲标识

master
xiaoning 1 year ago
parent 6ba6bed2be
commit 0f67cd5804

@ -96,10 +96,10 @@ public class DmBom implements Serializable {
@ApiModelProperty(value = "曲标识")
private String qbs;
@ApiModelProperty(value = "坡口長度")
@ApiModelProperty(value = "坡口标识")
private String pkbs;
@ApiModelProperty(value = "坡口标识")
@ApiModelProperty(value = "坡口长度")
private BigDecimal pkcd;
@ApiModelProperty(value = "打磨标识")

@ -28,9 +28,12 @@ public class DmTltpdf implements Serializable {
@ApiModelProperty(value = "船号")
private String dcCh;
@ApiModelProperty(value = "图号(不是图纸编号)")
@ApiModelProperty(value = "批量")
private String pl;
@ApiModelProperty(value = "图号(总图号,不是图纸编号)")
private String th;
@ApiModelProperty(value = "套料图号(每一页的图纸编号)")
private String tlth;
@ApiModelProperty(value = "页码")
private String pageNum;

@ -2,6 +2,7 @@ package com.dsic.gj_erp.controller.jcsj;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dsic.gj_erp.annotation.AuthFunction;
import com.dsic.gj_erp.bean.ResultBean;
import com.dsic.gj_erp.bean.jcsj.DmBom;
@ -18,12 +19,15 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -53,34 +57,41 @@ public class DmBomController {
@PostMapping("/uploadPDF")
@Authorization("")
@Transactional
@ResponseBody
public ResultBean uploadPDF(@RequestParam("file") MultipartFile file)throws IOException {
// String pdfFilePath = "E:/runpeng/1润芃工作日志/第21个月/第3周/钢加项目资料/小池/B046HC103HN第046批量数控套料图2023-05-11.pdf"; // PDF文件路径
public ResultBean uploadPDF(@RequestParam("file") MultipartFile[] fileList)throws IOException {
for (MultipartFile file : fileList) {
PDDocument document = PDDocument.load(file.getInputStream());
int pageNum = document.getNumberOfPages();
//
PDFTextStripper stripper = new PDFTextStripper();
stripper .setSortByPosition(true); //设置为true 则按照行进行读取默认是false
// // 指定页面读取内容
// stripper.setStartPage(12); // 设置起始页面这里设置成0就表示读取第一个页面
// stripper.setEndPage(12); // 设置结束页面这里设置成0就表示读取第一个页面
// stripper .setSortByPosition(true); //设置为true 则按照行进行读取默认是false
// // 3、获取指定页面的文本内容
stripper.setStartPage(2);
stripper.setEndPage(2);
String[] text = stripper.getText(document).split("\r\n")[2].split(" ");
String dcCh=text[1];
String th=text[10];
stripper.setStartPage(1);// 设置起始页面这里设置成2就表示读取第一个页面
stripper.setEndPage(1); // 设置结束页面这里设置成2就表示读取第一个页面
String[] text = stripper.getText(document).split("\r\n");
String dcCh=text[46];
String pl=text[38].substring(1,4);
String th=text[29];
//删除导入过的同船、批量、图号的数据,
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++) {
stripper.setStartPage(i);
stripper.setEndPage(i);
String s = stripper.getText(document);
String[] a=s.split("\r\n");
String s = stripper.getText(document);//本页文字内容
String[] a=s.split("\r\n");//分行
String tlth=i>1?s.split("序号零件编号")[1].split(" ")[5]:"";
// System.out.println("第 " + i +"/"+pageNum+ " 页 :" );
for (int j=0;j<a.length;j++){
DmTltpdf tltpdf=new DmTltpdf();
tltpdf.setDcCh(dcCh);
tltpdf.setTh(th);
tltpdf.setPl(pl);
tltpdf.setTlth(tlth);
tltpdf.setPageNum(i +"/"+pageNum);
tltpdf.setRows((j+1) +"/"+a.length);
tltpdf.setContent(a[j]);
@ -88,11 +99,90 @@ public class DmBomController {
// System.out.println("第 " + (j+1) +"/"+a.length+ " 行 :");
// System.out.println(a[j]);
}
if (i==1)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);
}
}
}
tltpdfService.saveBatch(list);
document.close();
}
return new ResultBean();
}
public String[] getArrayByIndex(String[] oldArray,int startIndex,int endIndex){
int newArraylen=endIndex-startIndex+1;
String[] array=new String[newArraylen];
for (int i = 0; i < newArraylen; i++) {
array[i]=oldArray[i+startIndex];
}
return array;
}
public void updateBom(String sx,String dcCh,String pl,String tlth,String ljbh){
// 坡口K/Y 曲工序D/Q 打磨E/F/G/H
if ("K,Y".indexOf(sx)>-1){
dmBomService.update(new UpdateWrapper<DmBom>().set("pkbs","Y")
.eq("dcch",dcCh)
.eq("pl",pl)
.eq("tzbh",tlth)
.eq("ljbh",ljbh)
);
}
if ("D,Q".indexOf(sx)>-1){
dmBomService.update(new UpdateWrapper<DmBom>().set("qbs","Y")
.eq("dcch",dcCh)
.eq("pl",pl)
.eq("tzbh",tlth)
.eq("ljbh",ljbh)
);
}
if ("E,F,G,H".indexOf(sx)>-1){
dmBomService.update(new UpdateWrapper<DmBom>().set("dmbs","Y")
.eq("dcch",dcCh)
.eq("pl",pl)
.eq("tzbh",tlth)
.eq("ljbh",ljbh)
);
}
}
@PostMapping("/getListBom")
public ResultBean getListBom(HttpServletRequest req, @RequestBody Map map) throws CustomException {
List<BomVO> listBom = dmBomService.getListBom(req,map);

Loading…
Cancel
Save