From d175d9c401fb97ebe6a580005a8c9ad5fedccb6b Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期一, 29 七月 2024 17:02:41 +0800
Subject: [PATCH] add other method
---
pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java | 150 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 140 insertions(+), 10 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 7ca53a1..84f5689 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,23 +1,34 @@
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;
+import com.dy.pmsGlobal.daoPlt.PltProParamsMapper;
import com.dy.pmsGlobal.daoPlt.PltProductFileMapper;
import com.dy.pmsGlobal.daoPlt.PltProductMapper;
+import com.dy.pmsGlobal.daoPlt.PltProductQualityInspectionItemsMapper;
import com.dy.pmsGlobal.dyFile.FileOperate;
import com.dy.pmsGlobal.dyFile.FileRestVo;
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;
+import org.springframework.dao.DuplicateKeyException;
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;
@Slf4j
@Service
@@ -27,9 +38,14 @@
private FileOperate fileOperate;
private OthFileMapper othFileMapper;
+ private PltProductQualityInspectionItemsMapper itemDao;
+ private PltProParamsMapper paramDao;
@Value("${dy.webFile.fmUrl}")
private String fmUrl ;
+
+ private static final String DEFAULT_CODE = "001";
+ private static final String CODE_FORMAT = "%03d";
@Autowired
public void setFileOperate(FileOperate fileOperate){
@@ -48,15 +64,88 @@
public void setPfDao(PltProductFileMapper pfDao) {
this.pfDao = pfDao;
}
+ @Autowired
+ public void setItemDao(PltProductQualityInspectionItemsMapper itemDao) {
+ this.itemDao = itemDao;
+ }
+ @Autowired
+ public void setParamDao(PltProParamsMapper paramDao) {
+ this.paramDao = paramDao;
+ }
+
@Transactional
- public long save(PltProduct p) {
- return dao.insert(p);
+ public int save(PltProduct p) {
+ //鍒ゆ柇浜у搧涓嶈兘閲嶅悕
+ if (dao.exists(p.name, p.id)) {
+ throw new RuntimeException("浜у搧鍚嶇О閲嶅");
+ }
+ int flag=0;
+ do {
+ p.code = getNextCode();
+ try {
+ int count = dao.insertSelective(p);
+ if (count > 0) {
+ saveProRel(p);
+ return count;
+ }
+ } catch (DuplicateKeyException e) {
+ // 濡傛灉鍑虹幇鍞竴绾︽潫杩濆弽寮傚父锛屽皾璇曡幏鍙栨柊鐨刢ode骞堕噸璇�
+ log.warn("鎻掑叆浜у搧鏃堕亣鍒板敮涓�绾︽潫寮傚父锛屽皾璇曡幏鍙栨柊鐨刢ode", e);
+ }
+ flag++;
+ } while (flag<5);
+ return 0;
}
+ private String getNextCode(){
+ log.info("鑾峰彇浜у搧缂栧彿");
+ String maxCode = dao.selectMaxCode();
+ if (StringUtils.isBlank(maxCode)) {
+ return DEFAULT_CODE;
+ } else {
+ int nextCode = Integer.parseInt(maxCode) + 1;
+ // 妫�鏌ユ孩鍑�
+ if (nextCode > 999) {
+ throw new RuntimeException("浜у搧缂栧彿婧㈠嚭");
+ }
+ return String.format(CODE_FORMAT, nextCode);
+ }
+ }
+
@Transactional
public int update(PltProduct p) {
- return dao.updateByPrimaryKeySelective(p);
+ if (dao.exists(p.name, p.id)) {
+ throw new RuntimeException("浜у搧鍚嶇О閲嶅");
+ }
+ int count = dao.updateByPrimaryKeySelective(p);
+ //鍒犻櫎鏃ф暟鎹�,閲嶆柊鎻掑叆
+ pfDao.deleteByProId(p.id);
+ saveProRel(p);
+ return count;
}
+
+
+ private void saveProRel(PltProduct p) {
+ p.params.forEach(param->{
+ param.proId=p.id;
+ if(param.id !=null){
+ paramDao.updateByPrimaryKeySelective(param);
+ }else{
+ param.deleted=false;
+ paramDao.insert(param);
+ }
+ });
+ saveRel(p, p.proFiles);
+ }
+
+ private void saveRel(PltProduct p, List<PltProductFile> docs) {
+ docs.forEach(doc -> {
+ doc.proId = p.id;
+ pfDao.insertSelective(doc);
+ });
+ }
+
+
/**
* 閫昏緫鍒犻櫎瀹炰綋
@@ -74,16 +163,34 @@
return pro;
}
- private PltProduct addWebUrl(PltProduct pro){
- if(pro !=null &&pro.image!=null){
- OthFile file = othFileMapper.selectByPrimaryKey(pro.image);
- FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash );
+ private PltProduct addWebUrl(PltProduct pro) {
+ if (pro != null) {
+ if (pro.image != null) {
+ String filePathWithWebUrl = getFilePathWithWebUrl(pro.image);
+ pro.imageWebPath = filePathWithWebUrl;
+ pro.imageWebPathZip = fileOperate.getImgFileZipPath(filePathWithWebUrl);
+ }
- pro.imageWebPath=fileRestVo.fileWebUrl +file.filePath;
- pro.imageWebPathZip= fileOperate.getImgFileZipPath(fileRestVo.fileWebUrl +file.filePath);
+ 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.fileSysRestUrl + fileRestVo.fileWebDownloadPath + doc.fileId;
+ doc.orgName = file.orgName;
+ doc.extName = file.extName;
+ });
}
return pro;
}
+
+ private String getFilePathWithWebUrl(Long fileId) {
+ OthFile file = othFileMapper.selectByPrimaryKey(fileId);
+ FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
+ return fileRestVo.fileWebUrl + file.filePath;
+ }
+
/**
* 鑾峰彇浜у搧鍒楄〃
@@ -97,6 +204,19 @@
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) {
+ e.printStackTrace();
+ } catch (WriterException e) {
+ e.printStackTrace();
+ }
+ });
+ }
return rsVo ;
}
@@ -106,10 +226,11 @@
* @param fileId 鏂囨。id
* @return 鏇存柊鏁伴噺
*/
- public int addDoc(long proId,long fileId){
+ 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);
}
@@ -123,4 +244,13 @@
}
+ public List<PltProduct> selectAll(QueryVo queryVo) {
+ Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
+ return dao.selectAll(params);
+ }
+
+
+ public void downloadDoc(HttpServletResponse response) {
+ PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(1));
+ }
}
--
Gitblit v1.8.0