From 7165632fcb7b3b782b8959cfe1e7e1c51872e228 Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期二, 25 六月 2024 16:34:18 +0800
Subject: [PATCH] station used list and delete
---
pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java | 100 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 83 insertions(+), 17 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 55d1449..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,5 +1,7 @@
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;
@@ -11,13 +13,19 @@
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;
@@ -35,6 +43,9 @@
@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){
@@ -65,14 +76,47 @@
@Transactional
public int save(PltProduct p) {
- int count = dao.insert(p);
- if(count>0){
- saveProRel(p);
+ //鍒ゆ柇浜у搧涓嶈兘閲嶅悕
+ if (dao.exists(p.name, p.id)) {
+ throw new RuntimeException("浜у搧鍚嶇О閲嶅");
}
- return count;
+ 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) {
+ if (dao.exists(p.name, p.id)) {
+ throw new RuntimeException("浜у搧鍚嶇О閲嶅");
+ }
int count = dao.updateByPrimaryKeySelective(p);
//鍒犻櫎鏃ф暟鎹�,閲嶆柊鎻掑叆
pfDao.deleteByProId(p.id);
@@ -87,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);
});
}
@@ -129,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.fileSysRestUrl + fileRestVo.fileWebDownloadPath + doc.fileId;
+ doc.orgName = file.orgName;
+ doc.extName = file.extName;
});
}
return pro;
@@ -160,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 ;
}
@@ -187,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