package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.newfiber.api.core.commons.CustomException; import com.newfiber.api.core.commons.PageRequestObject; import com.newfiber.api.core.commons.PageResultObject; import com.newfiber.api.pc.dao.MeetPlanFileMapper; import com.newfiber.api.pc.dto.MeetPlanFileDTO; import com.newfiber.api.pc.model.meet.MeetPlanFile; import com.newfiber.api.pc.service.MeetPlanFileService; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.io.File; import java.util.List; /** * @Author:zzh * @CreateDate:2020/11/26 16:44 * @Description: */ @Service @Transactional(rollbackFor = Exception.class) public class MeetPlanFileServiceImpl extends ServiceImpl<MeetPlanFileMapper,MeetPlanFile> implements MeetPlanFileService { /** 节点文件保存路径 */ @Value("${xnFile.path}") private String xnFilePath; @Override public void deleteFiles(List<Integer> ids) { List<MeetPlanFile> meetPlanFiles = this.selectBatchIds(ids); meetPlanFiles.stream().map(MeetPlanFile::getFilePath).forEach( s -> { File file = new File(xnFilePath , s); if(file.exists()){ boolean delete = file.delete(); if(!delete){ throw new CustomException(999,"文件删除失败"); } } } ); } @Override public PageResultObject<MeetPlanFile> queryPage(PageRequestObject<MeetPlanFileDTO> meetPlanFileDTO) { Page<MeetPlanFile> objectPage = new Page<>(meetPlanFileDTO.getCurrent(), meetPlanFileDTO.getSize()); MeetPlanFileDTO object = meetPlanFileDTO.getObject(); EntityWrapper<MeetPlanFile> wrapper = new EntityWrapper<>(); wrapper.eq("plan_id",object.getPlanId()); if(!StringUtils.isEmpty(object.getFileName())){ wrapper.like("file_name",object.getFileName()); } Page<MeetPlanFile> selectPage = this.selectPage(objectPage, wrapper); int count = this.selectCount(wrapper); return new PageResultObject(meetPlanFileDTO.getCurrent(), meetPlanFileDTO.getSize(),(long)count,selectPage.getRecords()); } public String getXnFilePath() { return xnFilePath; } public void setXnFilePath(String xnFilePath) { this.xnFilePath = xnFilePath; } }