package com.dy.pmsOther.fileManage; import com.dy.common.webUtil.QueryResultVo; import com.dy.pmsGlobal.daoOth.OthFileMapper; import com.dy.pmsGlobal.daoOth.OthFileManageMapper; import com.dy.pmsGlobal.dyFile.FileOperate; import com.dy.pmsGlobal.dyFile.FileRestVo; import com.dy.pmsGlobal.pojoOth.OthFile; import com.dy.pmsGlobal.pojoOth.OthFileManage; 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.Date; import java.util.List; import java.util.Map; @Slf4j @Service public class FileManageSv { private OthFileManageMapper dao; private FileOperate fileOperate; private OthFileMapper othFileMapper; @Value("${dy.webFile.fmUrl}") private String fmUrl ; @Autowired public void setDao(OthFileManageMapper dao) { this.dao = dao; } @Autowired public void setFileOperate(FileOperate fileOperate) { this.fileOperate = fileOperate; } @Autowired public void setOthFileMapper(OthFileMapper othFileMapper) { this.othFileMapper = othFileMapper; } public OthFileManage one(Long fileId) { OthFileManage uploadFile =dao.selectByPrimaryKey(fileId); addUrl(List.of(uploadFile)); return uploadFile; } private void addUrl(List fileList){ fileList.forEach(uploadFile -> { if(uploadFile != null){ OthFile othFile = othFileMapper.selectByPrimaryKey(uploadFile.fileId); if (othFile != null) { FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, othFile.hash); uploadFile.webUrl = fileRestVo.fileWebDownloadPath + uploadFile.fileId; uploadFile.orgName = othFile.orgName; uploadFile.extName = othFile.extName; } } }); } /** * 获取列表 */ 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) ; addUrl(rsVo.obj); return rsVo ; } @Transactional public int save(OthFileManage uploadFile) { int count=0; if(uploadFile.id==null){ uploadFile.deleted = false; uploadFile.dt = new Date(); count = dao.insertSelective(uploadFile); }else{ uploadFile.dt = new Date(); count = dao.updateByPrimaryKeySelective(uploadFile); } return count; } @Transactional public int delete(Long id) { int count=0; count = dao.deleteLogicById(id); return count; } }