liuxm
2024-05-14 abc305426c16e7ea9d21c12c41356c18ddb1adef
pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/product/ProductSv.java
@@ -2,8 +2,10 @@
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;
@@ -18,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@Slf4j
@Service
@@ -27,6 +30,8 @@
    private FileOperate fileOperate;
    private OthFileMapper othFileMapper;
    private PltProductQualityInspectionItemsMapper itemDao;
    private PltProParamsMapper paramDao;
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl ;
@@ -48,15 +53,57 @@
    public void setPfDao(PltProductFileMapper pfDao) {
        this.pfDao = pfDao;
    }
    @Autowired
    public void setItemDao(PltProductQualityInspectionItemsMapper itemDao) {
        this.itemDao = itemDao;
    }
    @Autowired
    public void setParamDao(PltProParamsMapper paramDao) {
        this.paramDao = paramDao;
    }
    @Transactional
    public long save(PltProduct p) {
        return dao.insert(p);
    public int save(PltProduct p) {
        int count = dao.insert(p);
        if(count>0){
            saveProRel(p);
        }
        return count;
    }
    @Transactional
    public int update(PltProduct p) {
        return dao.updateByPrimaryKeySelective(p);
        int count = dao.updateByPrimaryKeySelective(p);
        //删除旧数据,重新插入
        pfDao.deleteByProId(p.id);
        saveProRel(p);
        return count;
    }
    private void saveProRel(PltProduct p) {
        p.params.forEach(param->{
            param.proId=p.id;
            if(param.id !=null){
                paramDao.updateByPrimaryKeySelective(param);
            }else{
                paramDao.insert(param);
            }
        });
        saveRel(p, p.processDocuments, "01");
        saveRel(p, p.userManual, "02");
        saveRel(p, p.materials, "03");
    }
    private void saveRel(PltProduct p, List<PltProductFile> docs, String fileType) {
        docs.forEach(doc -> {
            doc.proId = p.id;
            doc.fileType = fileType;
            pfDao.insert(doc);
        });
    }
    /**
     * 逻辑删除实体
@@ -74,16 +121,32 @@
        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 );
    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.imageWebPath=fileRestVo.fileWebUrl +file.filePath;
            pro.imageWebPathZip= fileOperate.getImgFileZipPath(fileRestVo.fileWebUrl +file.filePath);
            Stream.concat(
                     pro.userManual.stream(),
                     Stream.concat(pro.processDocuments.stream(), pro.materials.stream())
             )
             .forEach(doc -> {
                 String webUrl = getFilePathWithWebUrl(doc.fileId);
                 doc.webUrl = webUrl;
             });
        }
        return pro;
    }
    private String getFilePathWithWebUrl(Long fileId) {
        OthFile file = othFileMapper.selectByPrimaryKey(fileId);
        FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
        return fileRestVo.fileWebUrl + file.filePath;
    }
    /**
     * 获取产品列表
@@ -106,10 +169,11 @@
     * @param fileId 文档id
     * @return 更新数量
     */
    public int addDoc(long proId,long fileId){
    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);
    }