package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.FileDirPath;
|
import com.whyc.dto.Response;
|
import com.whyc.dto.ZipUtils;
|
import com.whyc.mapper.ProductBomMapper;
|
import com.whyc.pojo.ProductBom;
|
import com.whyc.pojo.ProductBomHistory;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.util.Date;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
@Service
|
public class ProductBomService {
|
|
@Autowired(required = false)
|
private ProductBomMapper mapper;
|
//图纸分类检索
|
public Response searchCadDrawer(ProductBom productBom,int pageCurr,int pageSize) {
|
PageHelper.startPage(pageCurr,pageSize);
|
List list=mapper.searchCadDrawer(productBom);
|
PageInfo pageInfo=new PageInfo(list);
|
return new Response().setII(1,list.size()>0?true:false,pageInfo,"数据返回");
|
}
|
//图纸文件下载
|
public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp) {
|
String fileDirName = FileDirPath.getFileDirName();
|
String rootFace=fileDirName+ File.separator+"face";
|
String timeStr= ActionUtil.sdfwithFTP.format(new Date());
|
try {
|
File file=new File(rootFace+".zip");
|
FileOutputStream forootFace = new FileOutputStream(file);
|
ZipUtils.toZip(rootFace, forootFace,true);
|
// 转码防止乱码
|
resp.addHeader("Content-Disposition", "attachment;filename="
|
+ new String(timeStr.getBytes("UTF-8"), "ISO8859-1")
|
+ ".zip");
|
OutputStream out = resp.getOutputStream();
|
FileInputStream in = new FileInputStream(rootFace+".zip");
|
int len=0;
|
byte[] buffer =new byte[1024];
|
//7. 将缓冲区中的数据输出
|
while ((len=in.read(buffer))>0){
|
out.write(buffer,0,len);
|
}
|
in.close();
|
out.close();
|
file.delete();
|
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
//根据子件code获取最终的信息
|
public Response getBomBySubcode(String scode) {
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("sub_code",scode);
|
wrapper.last("limit 1");
|
ProductBom productBom=mapper.selectOne(wrapper);
|
return new Response().setII(1,productBom!=null?true:false,productBom,"返回数据");
|
}
|
|
/**获取产品的信息(不包含子料)*/
|
public ProductBom getProduct(String parentModel){
|
QueryWrapper<ProductBom> query = Wrappers.query();
|
query.eq("parent_model",parentModel).last(" limit 1");
|
return mapper.selectOne(query);
|
}
|
|
/** 删除旧的bom,增加新的bom*/
|
@Transactional
|
public void updateNewBom(List<ProductBomHistory> newBomHistoryList) {
|
UpdateWrapper<ProductBom> update = Wrappers.update();
|
update.eq("parent_model",newBomHistoryList.get(0).getParentModel());
|
mapper.delete(update);
|
|
List<ProductBom> newBomList = new LinkedList<>();
|
newBomHistoryList.forEach(newBomHis->{
|
ProductBom newBom = new ProductBom();
|
newBom.setCategory(newBomHis.getCategory());
|
newBom.setCreateDate(newBomHis.getCreateDate());
|
newBom.setDwgUrl(newBomHis.getDwgUrl());
|
newBom.setFileUrl(newBomHis.getFileUrl());
|
newBom.setMaterial(newBomHis.getMaterial());
|
newBom.setNotes(newBomHis.getNotes());
|
newBom.setParentCode(newBomHis.getParentCode());
|
newBom.setParentModel(newBomHis.getParentModel());
|
newBom.setParentName(newBomHis.getParentName());
|
newBom.setParentVersion(newBomHis.getParentVersion());
|
newBom.setPictureUrl(newBomHis.getPictureUrl());
|
newBom.setProducer(newBomHis.getProducer());
|
newBom.setQuantity(newBomHis.getQuantity());
|
newBom.setSubCode(newBomHis.getSubCode());
|
newBom.setSubModel(newBomHis.getSubModel());
|
newBom.setSubName(newBomHis.getSubName());
|
newBom.setSurfaceDetail(newBomHis.getSurfaceDetail());
|
newBom.setThickness(newBomHis.getThickness());
|
newBom.setType(newBomHis.getType());
|
newBom.setUnit(newBomHis.getUnit());
|
newBom.setUpdateDate(newBomHis.getUpdateDate());
|
newBom.setUpUser(newBomHis.getUpUser());
|
newBom.setVersion(newBomHis.getEVersion());
|
|
newBomList.add(newBom);
|
});
|
mapper.insertBatchSomeColumn(newBomList);
|
}
|
}
|