|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.easy.admin.auth.model.SysUser; |
|
|
|
import com.easy.admin.modules.huzhou.dao.HuzhouRegulationlabMapper; |
|
|
|
import com.easy.admin.util.ShiroUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import com.easy.admin.common.util.CommonUtils; |
|
|
|
import com.easy.admin.modules.huzhou.entity.HuzhouRegulationlab; |
|
|
@ -29,7 +30,7 @@ import java.util.zip.ZipOutputStream; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Transactional |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class HuzhouRegulationlabServiceImpl extends ServiceImpl<HuzhouRegulationlabMapper, HuzhouRegulationlab> implements IHuzhouRegulationlabService { |
|
|
|
@Value(value = "${jeecg.path.upload}") |
|
|
|
private String uploadpath; |
|
|
@ -77,6 +78,7 @@ public class HuzhouRegulationlabServiceImpl extends ServiceImpl<HuzhouRegulation |
|
|
|
public Boolean deleteRegulationlab(HuzhouRegulationlab regulationlab) { |
|
|
|
String id = regulationlab.getId(); |
|
|
|
regulationlab = this.getById(id); |
|
|
|
// 根据路径删除
|
|
|
|
File file = new File(regulationlab.getDocumentPath()); |
|
|
|
if(file.delete()){ |
|
|
|
this.removeById(id); |
|
|
@ -120,21 +122,29 @@ public class HuzhouRegulationlabServiceImpl extends ServiceImpl<HuzhouRegulation |
|
|
|
String currentDay = dateFormat.format(new Date()); |
|
|
|
SysUser currentUser = ShiroUtil.getCurrentUser(); |
|
|
|
String nickname = currentUser.getNickname(); |
|
|
|
String separator = File.separator; |
|
|
|
log.info(separator); |
|
|
|
File filePath = new File(uploadpath +File.separator+"regulationlab"+ File.separator+nickname+ File.separator+currentDay+File.separator); |
|
|
|
//文件夹不存在则创建
|
|
|
|
if (!filePath.exists()) { |
|
|
|
// 创建文件根目录
|
|
|
|
filePath.mkdirs(); |
|
|
|
} |
|
|
|
log.info("文件根目录{}",filePath); |
|
|
|
String fileName =null; |
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
originalFilename = CommonUtils.getFileName(originalFilename); |
|
|
|
if(originalFilename.indexOf(".")!=-1){ |
|
|
|
fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")) + "_" + System.currentTimeMillis() + originalFilename.substring(originalFilename.lastIndexOf(".")); |
|
|
|
}else{ |
|
|
|
fileName = originalFilename+ "_" + System.currentTimeMillis(); |
|
|
|
if (originalFilename != null){ |
|
|
|
originalFilename = CommonUtils.getFileName(originalFilename); |
|
|
|
if(originalFilename.contains(".")){ |
|
|
|
fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")) + "_" + System.currentTimeMillis() + originalFilename.substring(originalFilename.lastIndexOf(".")); |
|
|
|
}else{ |
|
|
|
fileName = originalFilename+ "_" + System.currentTimeMillis(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String savePath = filePath.getPath() + File.separator + fileName; |
|
|
|
log.info("文件保存路径{}",savePath); |
|
|
|
|
|
|
|
File savefile = new File(savePath); |
|
|
|
FileCopyUtils.copy(file.getBytes(), savefile);//保存文件
|
|
|
|
regulationlab.setDocumentName(originalFilename);//未加工过的文件名称
|
|
|
|