|  |  | 
 |  |  | 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.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.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; | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Transactional | 
 |  |  |     public int save(PltProduct p) { | 
 |  |  |         //判断产品 名称和型号 不能重名 | 
 |  |  |         if (dao.exists(p.name.trim(), p.type.trim() ,p.id)) { | 
 |  |  |             throw new RuntimeException("已经存在相同的产品名称&型号"); | 
 |  |  |         } | 
 |  |  |         int flag=0; | 
 |  |  |         do { | 
 |  |  |             p.code = getNextCode(); | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Transactional | 
 |  |  |     public int update(PltProduct p) { | 
 |  |  |         if (dao.exists(p.name.trim(), p.type.trim(),p.id)) { | 
 |  |  |             throw new RuntimeException("已经存在相同的产品名称&型号"); | 
 |  |  |         } | 
 |  |  |         int count = dao.updateByPrimaryKeySelective(p); | 
 |  |  |         //删除旧数据,重新插入 | 
 |  |  |         pfDao.deleteByProId(p.id); | 
 |  |  | 
 |  |  |                 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); | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 pro.imageWebPathZip = fileOperate.getImgFileZipPath(filePathWithWebUrl); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             Stream.concat( | 
 |  |  |                      pro.userManual.stream(), | 
 |  |  |                      Stream.concat(pro.processDocuments.stream(), pro.materials.stream()) | 
 |  |  |              ) | 
 |  |  |              .forEach(doc -> { | 
 |  |  |             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.fileWebUrl + file.filePath; | 
 |  |  |                  doc.webUrl = fileRestVo.fileWebDownloadPath + doc.fileId; | 
 |  |  |                  doc.orgName = file.orgName; | 
 |  |  |                  doc.extName = file.extName; | 
 |  |  |              }); | 
 |  |  | 
 |  |  |         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 void downloadDoc(HttpServletResponse response) { | 
 |  |  |         PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(1)); | 
 |  |  |     public List<PltProduct> getProduct(Long orderId) { | 
 |  |  |         return dao.selectByOrderId(orderId); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | //    public void downloadDoc(HttpServletResponse response) { | 
 |  |  | //        PltProduct pro=dao.selectByPrimaryKey(Long.valueOf(1)); | 
 |  |  | //    } | 
 |  |  | } |