New file |
| | |
| | | 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 ; |
| | | } |
| | | } |