6 changed files with 332 additions and 2 deletions
@ -0,0 +1,105 @@ |
|||||
|
package com.easy.admin.modules.huzhou.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.easy.admin.common.api.vo.Result; |
||||
|
import com.easy.admin.common.core.exception.EasyException; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouInformationMaterial; |
||||
|
import com.easy.admin.modules.huzhou.service.IHuzhouInformationMaterialService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
/** |
||||
|
* @author gjh |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/huzhouInformationMaterial") |
||||
|
public class HuzhouInformationMaterialController { |
||||
|
@Autowired |
||||
|
private IHuzhouInformationMaterialService informationMaterialService; |
||||
|
|
||||
|
/** |
||||
|
* 查询信息材料分页 |
||||
|
* @param informationMaterial 条件 |
||||
|
* @param pageNo 分页 |
||||
|
* @param pageSize 页码 |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/informationMaterialPageList") |
||||
|
public Result<?> informationMaterialPageList(HuzhouInformationMaterial informationMaterial, |
||||
|
@RequestParam(name="current", defaultValue="1") Integer pageNo, |
||||
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize){ |
||||
|
|
||||
|
Page<HuzhouInformationMaterial> pageList = informationMaterialService.getInformationMaterialPageList(informationMaterial, pageNo, pageSize); |
||||
|
return Result.ok(pageList); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据id获取详情信息材料 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/getInformationMaterialById") |
||||
|
public Result<?> getInformationMaterialById(String id){ |
||||
|
HuzhouInformationMaterial byId = informationMaterialService.getById(id); |
||||
|
return Result.ok(byId); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加信息材料 |
||||
|
* @param file |
||||
|
* @param informationMaterial |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/addInformationMaterial") |
||||
|
public Result<?> addInformationMaterial(@RequestParam(value = "file") MultipartFile file, HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
informationMaterialService.addInformationMaterial(file,informationMaterial); |
||||
|
return Result.ok("上传成功"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改信息材料 |
||||
|
* @param file |
||||
|
* @param informationMaterial |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/modifyInformationMaterial") |
||||
|
public Result<?> modifyInformationMaterial(@RequestParam(value = "file",required = false) MultipartFile file, HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
Boolean aBoolean = informationMaterialService.modifyInformationMaterial(file, informationMaterial); |
||||
|
if(aBoolean){ |
||||
|
return Result.ok("修改成功"); |
||||
|
} |
||||
|
throw new EasyException("修改失败"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除信息材料 |
||||
|
* @param informationMaterial |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/deleteInformationMaterial") |
||||
|
public Result<?> deleteInformationMaterial(@RequestBody HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
Boolean aBoolean = informationMaterialService.deleteInformationMaterial(informationMaterial); |
||||
|
if(aBoolean){ |
||||
|
return Result.ok("删除成功"); |
||||
|
} |
||||
|
throw new EasyException("删除失败"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量下载 |
||||
|
* @param informationMaterial |
||||
|
* @param response |
||||
|
*/ |
||||
|
@GetMapping("/batchdownloadInformationMaterialFiles") |
||||
|
public void batchdownloadInformationMaterialFiles(HuzhouInformationMaterial informationMaterial, HttpServletResponse response){ |
||||
|
informationMaterialService.batchdownloadInformationMaterialFiles(informationMaterial,response); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package com.easy.admin.modules.huzhou.dao; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouInformationMaterial; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouPeriodicallab; |
||||
|
|
||||
|
/** |
||||
|
* @author gjh |
||||
|
*/ |
||||
|
public interface HuzhouInformationMaterialMapper extends BaseMapper<HuzhouInformationMaterial> { |
||||
|
|
||||
|
|
||||
|
} |
@ -1,11 +1,16 @@ |
|||||
package com.easy.admin.modules.huzhou.entity; |
package com.easy.admin.modules.huzhou.entity; |
||||
|
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.Data; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
import java.util.Date; |
import java.util.Date; |
||||
|
|
||||
public class InformationMaterials { |
/** |
||||
|
* @author gjh |
||||
|
*/ |
||||
|
@Data |
||||
|
public class HuzhouInformationMaterial { |
||||
|
|
||||
private static final long serialVersionUID = -50005828024123796L; |
private static final long serialVersionUID = -50005828024123796L; |
||||
/** |
/** |
@ -0,0 +1,23 @@ |
|||||
|
package com.easy.admin.modules.huzhou.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouInformationMaterial; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
public interface IHuzhouInformationMaterialService extends IService<HuzhouInformationMaterial> { |
||||
|
Page<HuzhouInformationMaterial> getInformationMaterialPageList(HuzhouInformationMaterial informationMaterial, Integer pageNo, |
||||
|
Integer pageSize); |
||||
|
void addInformationMaterial(MultipartFile file,HuzhouInformationMaterial informationMaterial) throws IOException; |
||||
|
|
||||
|
Boolean modifyInformationMaterial(MultipartFile file, HuzhouInformationMaterial informationMaterial) throws IOException; |
||||
|
|
||||
|
Boolean deleteInformationMaterial(HuzhouInformationMaterial informationMaterial); |
||||
|
|
||||
|
void batchdownloadInformationMaterialFiles(HuzhouInformationMaterial informationMaterial,HttpServletResponse response); |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,160 @@ |
|||||
|
package com.easy.admin.modules.huzhou.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.easy.admin.auth.model.SysUser; |
||||
|
import com.easy.admin.common.util.CommonUtils; |
||||
|
import com.easy.admin.modules.huzhou.dao.HuzhouInformationMaterialMapper; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouInformationMaterial; |
||||
|
import com.easy.admin.modules.huzhou.service.IHuzhouInformationMaterialService; |
||||
|
import com.easy.admin.util.ShiroUtil; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
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 org.springframework.util.FileCopyUtils; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.File; |
||||
|
import java.io.FileInputStream; |
||||
|
import java.io.IOException; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
import java.util.zip.ZipEntry; |
||||
|
import java.util.zip.ZipOutputStream; |
||||
|
|
||||
|
/** |
||||
|
* @author gjh |
||||
|
*/ |
||||
|
@Service |
||||
|
@Transactional |
||||
|
|
||||
|
public class HuzhouInformationMaterialServiceImpl extends ServiceImpl<HuzhouInformationMaterialMapper, HuzhouInformationMaterial> implements IHuzhouInformationMaterialService { |
||||
|
@Value(value = "${jeecg.path.upload}") |
||||
|
private String uploadPath; |
||||
|
|
||||
|
@Autowired |
||||
|
HuzhouInformationMaterialMapper informationMaterialMapper; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public Page<HuzhouInformationMaterial> getInformationMaterialPageList(HuzhouInformationMaterial informationMaterial, |
||||
|
Integer pageNo, |
||||
|
Integer pageSize) { |
||||
|
String informationMaterialName = informationMaterial.getName(); |
||||
|
String type = informationMaterial.getType(); |
||||
|
Date publishTime = informationMaterial.getPublishTime(); |
||||
|
|
||||
|
LambdaQueryWrapper<HuzhouInformationMaterial> queryWrapper = new LambdaQueryWrapper<>(); |
||||
|
Page<HuzhouInformationMaterial> informationMaterialPage = new Page<>(pageNo, pageSize); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(informationMaterialName),HuzhouInformationMaterial::getName,informationMaterialName); |
||||
|
queryWrapper.eq(StringUtils.isNotBlank(type),HuzhouInformationMaterial::getType,type); |
||||
|
if(publishTime!=null){ |
||||
|
queryWrapper.eq(HuzhouInformationMaterial::getPublishTime,publishTime); |
||||
|
} |
||||
|
|
||||
|
Page<HuzhouInformationMaterial> page = this.page(informationMaterialPage, queryWrapper); |
||||
|
return page; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void addInformationMaterial(MultipartFile file, HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
addFile(file,informationMaterial); |
||||
|
this.save(informationMaterial); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean modifyInformationMaterial(MultipartFile file,HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
String documentPath = this.getById(informationMaterial.getId()).getDocumentPath(); |
||||
|
File informationMaterialFile = new File(documentPath); |
||||
|
if(file==null){ |
||||
|
this.updateById(informationMaterial); |
||||
|
return true; |
||||
|
} |
||||
|
if(informationMaterialFile.delete()){ |
||||
|
addFile(file,informationMaterial); |
||||
|
this.updateById(informationMaterial); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean deleteInformationMaterial(HuzhouInformationMaterial informationMaterial) { |
||||
|
String id = informationMaterial.getId(); |
||||
|
informationMaterial = this.getById(id); |
||||
|
File file = new File(informationMaterial.getDocumentPath()); |
||||
|
if(file.delete()){ |
||||
|
this.removeById(id); |
||||
|
return Boolean.TRUE; |
||||
|
|
||||
|
} |
||||
|
return Boolean.FALSE; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void batchdownloadInformationMaterialFiles(HuzhouInformationMaterial informationMaterial, HttpServletResponse response) { |
||||
|
LambdaQueryWrapper<HuzhouInformationMaterial> queryWrapper = new LambdaQueryWrapper<>(); |
||||
|
String informationMaterialName = informationMaterial.getName(); |
||||
|
String documentName = informationMaterial.getDocumentName(); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(informationMaterialName),HuzhouInformationMaterial::getName,informationMaterialName); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(documentName),HuzhouInformationMaterial::getDocumentName,documentName); |
||||
|
List<HuzhouInformationMaterial> list = this.list(queryWrapper); |
||||
|
List<String> pathList = list.stream().map(HuzhouInformationMaterial::getDocumentPath).collect(Collectors.toList()); |
||||
|
response.addHeader("Content-Type", "application/zip"); |
||||
|
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream()); ) { |
||||
|
for (String fileName : pathList) { //循环往zip中放入文件
|
||||
|
File file = new File(fileName); |
||||
|
FileInputStream fileIn = new FileInputStream(file); |
||||
|
ZipEntry zipEntry = new ZipEntry(file.getName()); |
||||
|
zipOut.putNextEntry(zipEntry); |
||||
|
byte[] buffer = new byte[1024]; |
||||
|
int len; |
||||
|
while ((len = fileIn.read(buffer)) > 0) { |
||||
|
zipOut.write(buffer, 0, len); |
||||
|
} |
||||
|
fileIn.close(); |
||||
|
zipOut.closeEntry(); |
||||
|
} |
||||
|
zipOut.finish(); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("文件批量下载有误.", e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private void addFile(MultipartFile file,HuzhouInformationMaterial informationMaterial) throws IOException { |
||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); |
||||
|
String currentDay = dateFormat.format(new Date()); |
||||
|
SysUser currentUser = ShiroUtil.getCurrentUser(); |
||||
|
String nickname = currentUser.getNickname(); |
||||
|
File filePath = new File(uploadPath +File.separator+"informationMaterial"+ File.separator+nickname+ File.separator+currentDay+File.separator); |
||||
|
//文件夹不存在则创建
|
||||
|
if (!filePath.exists()) { |
||||
|
// 创建文件根目录
|
||||
|
filePath.mkdirs(); |
||||
|
} |
||||
|
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(); |
||||
|
} |
||||
|
String savePath = filePath.getPath() + File.separator + fileName; |
||||
|
File savefile = new File(savePath); |
||||
|
FileCopyUtils.copy(file.getBytes(), savefile);//保存文件
|
||||
|
informationMaterial.setDocumentName(originalFilename);//未加工过的文件名称
|
||||
|
informationMaterial.setDocumentType(file.getContentType()); |
||||
|
informationMaterial.setDocumentPath(savePath); |
||||
|
informationMaterial.setSize(file.getSize()); |
||||
|
informationMaterial.setStatus("1"); |
||||
|
informationMaterial.setDutyWorkplace(currentUser.getWorkplace()); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue