From d8c8530752a3f19f082560f767b04471b2dd1085 Mon Sep 17 00:00:00 2001 From: Fancy <Fancy.fx@outlook.com> Date: 星期三, 21 八月 2024 14:20:06 +0800 Subject: [PATCH] get product by orderId --- pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java | 101 +++++++++++++++++++++++++++++++++----------------- 1 files changed, 66 insertions(+), 35 deletions(-) diff --git a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java index 0ee58f1..d2e57f8 100644 --- a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java +++ b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java @@ -1,5 +1,6 @@ package com.dy.pmsPlatform.product; +import cn.hutool.core.codec.Base64; import com.alibaba.excel.util.StringUtils; import com.dy.common.webUtil.QueryResultVo; import com.dy.pmsGlobal.daoOth.OthFileMapper; @@ -12,7 +13,11 @@ import com.dy.pmsGlobal.pojoOth.OthFile; import com.dy.pmsGlobal.pojoPlt.PltProduct; import com.dy.pmsGlobal.pojoPlt.PltProductFile; +import com.dy.pmsGlobal.util.QrCodeUtil; +import com.google.zxing.WriterException; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -20,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -70,6 +76,10 @@ @Transactional public int save(PltProduct p) { + //鍒ゆ柇浜у搧涓嶈兘閲嶅悕 + if (dao.exists(p.name, p.id)) { + throw new RuntimeException("浜у搧鍚嶇О閲嶅"); + } int flag=0; do { p.code = getNextCode(); @@ -104,6 +114,9 @@ @Transactional public int update(PltProduct p) { + if (dao.exists(p.name, p.id)) { + throw new RuntimeException("浜у搧鍚嶇О閲嶅"); + } int count = dao.updateByPrimaryKeySelective(p); //鍒犻櫎鏃ф暟鎹�,閲嶆柊鎻掑叆 pfDao.deleteByProId(p.id); @@ -118,19 +131,17 @@ if(param.id !=null){ paramDao.updateByPrimaryKeySelective(param); }else{ + param.deleted=false; paramDao.insert(param); } }); - saveRel(p, p.processDocuments, "01"); - saveRel(p, p.userManual, "02"); - saveRel(p, p.materials, "03"); + saveRel(p, p.proFiles); } - private void saveRel(PltProduct p, List<PltProductFile> docs, String fileType) { + private void saveRel(PltProduct p, List<PltProductFile> docs) { docs.forEach(doc -> { doc.proId = p.id; - doc.fileType = fileType; - pfDao.insert(doc); + pfDao.insertSelective(doc); }); } @@ -160,13 +171,15 @@ pro.imageWebPathZip = fileOperate.getImgFileZipPath(filePathWithWebUrl); } - Stream.concat( - pro.userManual.stream(), - Stream.concat(pro.processDocuments.stream(), pro.materials.stream()) - ) - .forEach(doc -> { - String webUrl = getFilePathWithWebUrl(doc.fileId); - doc.webUrl = webUrl; + pro.proFiles.stream().forEach(doc -> { + OthFile file = othFileMapper.selectByPrimaryKey(doc.fileId); + if (file == null) { + return; + } + FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash); + doc.webUrl = fileRestVo.fileWebDownloadPath + doc.fileId; + doc.orgName = file.orgName; + doc.extName = file.extName; }); } return pro; @@ -191,37 +204,55 @@ rsVo.calculateAndSet(itemTotal, params); //鏌ヨ绗﹀悎鏉′欢鐨勮褰� rsVo.obj = dao.selectSome(params) ; + if(CollectionUtils.isNotEmpty(rsVo.obj)){ + rsVo.obj.parallelStream().forEach(item->{ + try { + byte[] codes = QrCodeUtil.genQrCode(item.code); + item.qrCode = "data:image/jpeg;base64," + Base64.encode(codes); + item = addWebUrl(item); + } catch (IOException e) { + log.error("IOException:",e); + } catch (WriterException e) { + log.error("WriterException:",e); + } + }); + } return rsVo ; } - /** - * 娣诲姞浜у搧鏂囨。鍏宠仈 - * @param proId 浜у搧id - * @param fileId 鏂囨。id - * @return 鏇存柊鏁伴噺 - */ - public int addDoc(long proId,long fileId,String fileType){ - PltProductFile pf=new PltProductFile(); - pf.fileId = fileId; - pf.proId = proId; - pf.fileType = fileType; - return pfDao.insertSelective(pf); - } +// /** +// * 娣诲姞浜у搧鏂囨。鍏宠仈 +// * @param proId 浜у搧id +// * @param fileId 鏂囨。id +// * @return 鏇存柊鏁伴噺 +// */ +// public int addDoc(long proId,long fileId,String fileType){ +// PltProductFile pf=new PltProductFile(); +// pf.fileId = fileId; +// pf.proId = proId; +// pf.fileType = fileType; +// return pfDao.insertSelective(pf); +// } - /** - * 鏌ヨ浜у搧鍏宠仈鏂囨。 - * @param proId 浜у搧id - * @return 杩斿洖鍏宠仈鏂囨。闆嗗悎 - */ - public List<OthFile> selectDoc(long proId){ - return othFileMapper.selectByProId(proId); - } +// /** +// * 鏌ヨ浜у搧鍏宠仈鏂囨。 +// * @param proId 浜у搧id +// * @return 杩斿洖鍏宠仈鏂囨。闆嗗悎 +// */ +// public List<OthFile> selectDoc(long proId){ +// return othFileMapper.selectByProId(proId); +// } public List<PltProduct> selectAll(QueryVo queryVo) { Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); return dao.selectAll(params); } + public List<PltProduct> selectByOrderId(Long orderId) { + return dao.selectByOrderId(orderId); + } - +// public void downloadDoc(HttpServletResponse response) { +// PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(1)); +// } } -- Gitblit v1.8.0