liuxm
2024-06-04 eeee3d8fa04aff41db6ee2418468e7371ecad57d
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,6 +13,8 @@
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;
@@ -22,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;
@@ -72,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();
@@ -106,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);
@@ -166,8 +177,7 @@
                     return;
                 }
                 FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
                 doc.webUrl = fileRestVo.fileWebUrl + file.filePath;
                 doc.webUrl = fileRestVo.fileSysRestUrl + fileRestVo.fileWebDownloadPath + doc.fileId;
                 doc.orgName = file.orgName;
                 doc.extName = file.extName;
             });
@@ -195,8 +205,16 @@
        //查询符合条件的记录
        rsVo.obj = dao.selectSome(params) ;
        if(CollectionUtils.isNotEmpty(rsVo.obj)){
            rsVo.obj.forEach(pro->{
                pro = addWebUrl(pro);
            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 ;