package com.dy.pmsPlatform.product; import com.dy.common.webUtil.QueryResultVo; import com.dy.pmsGlobal.daoOth.OthFileMapper; import com.dy.pmsGlobal.daoPlt.PltProductFileMapper; import com.dy.pmsGlobal.daoPlt.PltProductMapper; 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.pojoPlt.PltProductFile; import lombok.extern.slf4j.Slf4j; 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.util.List; import java.util.Map; @Slf4j @Service public class ProductSv { private PltProductMapper dao; private PltProductFileMapper pfDao; private FileOperate fileOperate; private OthFileMapper othFileMapper; @Value("${dy.webFile.fmUrl}") private String fmUrl ; @Autowired public void setFileOperate(FileOperate fileOperate){ this.fileOperate = fileOperate; } @Autowired public void setOthFileMapper(OthFileMapper othFileMapper){ this.othFileMapper = othFileMapper; } @Autowired public void setDao(PltProductMapper dao) { this.dao = dao; } @Autowired public void setPfDao(PltProductFileMapper pfDao) { this.pfDao = pfDao; } @Transactional public long save(PltProduct p) { return dao.insert(p); } @Transactional public int update(PltProduct p) { return dao.updateByPrimaryKeySelective(p); } /** * 逻辑删除实体 * @param id 实体ID * @return 影响记录数量 */ @Transactional public int delete(Long id) { return dao.deleteLogicById(id); } 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 &&pro.image!=null){ OthFile file = othFileMapper.selectByPrimaryKey(pro.image); FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash ); pro.imageWebPath=fileRestVo.fileWebUrl +file.filePath; pro.imageWebPathZip= fileOperate.getImgFileZipPath(fileRestVo.fileWebUrl +file.filePath); } return pro; } /** * 获取产品列表 */ public QueryResultVo> selectSome(QueryVo queryVo) { Map params = (Map) PojoUtils.generalize(queryVo); //查询符合条件的记录总数 Long itemTotal = dao.selectSomeCount(params); QueryResultVo> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; //计算分页等信息 rsVo.calculateAndSet(itemTotal, params); //查询符合条件的记录 rsVo.obj = dao.selectSome(params) ; return rsVo ; } /** * 添加产品文档关联 * @param proId 产品id * @param fileId 文档id * @return 更新数量 */ public int addDoc(long proId,long fileId){ PltProductFile pf=new PltProductFile(); pf.fileId = fileId; pf.proId = proId; return pfDao.insertSelective(pf); } /** * 查询产品关联文档 * @param proId 产品id * @return 返回关联文档集合 */ public List selectDoc(long proId){ return othFileMapper.selectByProId(proId); } }