From 57391775d5f5ae8a93b308d0b261b2244eb7579a Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期四, 16 一月 2025 09:24:26 +0800
Subject: [PATCH] 追溯小程序:产品列表,产品详情接口

---
 pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductSv.java   |  112 ++++++++++++++++++++++++++++
 pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductCtrl.java |   53 +++++++++++++
 pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/QueryVo.java     |   17 ++++
 3 files changed, 182 insertions(+), 0 deletions(-)

diff --git a/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductCtrl.java b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductCtrl.java
new file mode 100644
index 0000000..32b6b95
--- /dev/null
+++ b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductCtrl.java
@@ -0,0 +1,53 @@
+package com.dy.pmsWechat.product;
+
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.pmsGlobal.aop.Log;
+import com.dy.pmsGlobal.pojoPlt.PltProduct;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 浜у搧绠$悊
+ */
+@Slf4j
+@RestController
+@RequestMapping(path = "product")
+@SuppressWarnings("unchecked")
+public class ProductCtrl {
+
+
+    private ProductSv proSv;
+    @Autowired
+    public void setProSv(ProductSv proSv){
+        this.proSv = proSv;
+    }
+
+    /**
+     * 鏍规嵁ID鏌ヨ浜у搧淇℃伅
+     * @return
+     */
+    @GetMapping(path="one")
+    @Log("鏍规嵁ID鏌ヨ浜у搧淇℃伅")
+    public BaseResponse<PltProduct> one(String id){
+        PltProduct pro=proSv.selectById(id);
+
+        return BaseResponseUtils.buildSuccess(pro);
+    }
+
+    /**
+     * 鏌ヨ浜у搧淇℃伅
+     * @param vo
+     * @return
+     */
+    @PostMapping(path="some")
+    @Log("鍒嗛〉鏌ヨ浜у搧淇℃伅")
+    public BaseResponse<QueryResultVo<List<PltProduct>>> some(@RequestBody QueryVo vo){
+        QueryResultVo<List<PltProduct>> list = proSv.selectSome(vo);
+        return BaseResponseUtils.buildSuccess(list);
+    }
+}
diff --git a/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductSv.java b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductSv.java
new file mode 100644
index 0000000..e11c7de
--- /dev/null
+++ b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/ProductSv.java
@@ -0,0 +1,112 @@
+package com.dy.pmsWechat.product;
+
+import cn.hutool.core.codec.Base64;
+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.util.QrCodeUtil;
+import com.google.zxing.WriterException;
+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.stereotype.Service;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class ProductSv {
+    private PltProductMapper dao;
+
+    private FileOperate fileOperate;
+    private OthFileMapper othFileMapper;
+
+    @Value("${dy.webFile.fmUrl}")
+    private String fmUrl ;
+
+    @Autowired
+    public void setDao(PltProductMapper dao) {
+        this.dao = dao;
+    }
+    @Autowired
+    public void setFileOperate(FileOperate fileOperate){
+        this.fileOperate = fileOperate;
+    }
+    @Autowired
+    public void setOthFileMapper(OthFileMapper othFileMapper){
+        this.othFileMapper = othFileMapper;
+    }
+    public PltProduct selectById(String proId) {
+        PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(proId));
+        pro=addWebUrl(pro);
+        return pro;
+    }
+
+    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.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;
+    }
+
+    private String getFilePathWithWebUrl(Long fileId) {
+        OthFile file = othFileMapper.selectByPrimaryKey(fileId);
+        FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
+        return fileRestVo.fileWebUrl + file.filePath;
+    }
+
+
+    /**
+     * 鑾峰彇浜у搧鍒楄〃
+     */
+    public QueryResultVo<List<PltProduct>> selectSome(QueryVo queryVo) {
+        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
+        //鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟
+        Long itemTotal = dao.selectSomeCount(params);
+        QueryResultVo<List<PltProduct>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ;
+        //璁$畻鍒嗛〉绛変俊鎭�
+        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 ;
+    }
+}
diff --git a/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/QueryVo.java b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/QueryVo.java
new file mode 100644
index 0000000..81c48b3
--- /dev/null
+++ b/pms-parent/pms-web-wechat/src/main/java/com/dy/pmsWechat/product/QueryVo.java
@@ -0,0 +1,17 @@
+package com.dy.pmsWechat.product;
+
+import com.dy.common.webUtil.QueryConditionVo;
+import lombok.*;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ToString(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class QueryVo extends QueryConditionVo {
+    public String name;
+    public String director;
+    public String dMobile;
+    public String type;
+}

--
Gitblit v1.8.0