5 changed files with 334 additions and 0 deletions
@ -0,0 +1,101 @@ |
|||||
|
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.HuzhouPeriodicallab; |
||||
|
import com.easy.admin.modules.huzhou.service.IHuzhouPeriodicallabService; |
||||
|
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; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/huzhouPeriodicallab") |
||||
|
public class HuzhouPeriodicallabController { |
||||
|
@Autowired |
||||
|
private IHuzhouPeriodicallabService periodicallabService; |
||||
|
|
||||
|
/** |
||||
|
* 查询政策法规分页 |
||||
|
* @param periodicallab 条件 |
||||
|
* @param pageNo 分页 |
||||
|
* @param pageSize 页码 |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/periodicallabPageList") |
||||
|
public Result<?> periodicallabPageList(HuzhouPeriodicallab periodicallab, |
||||
|
@RequestParam(name="current", defaultValue="1") Integer pageNo, |
||||
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize){ |
||||
|
|
||||
|
Page<HuzhouPeriodicallab> pageList = periodicallabService.getPeriodicallabPageList(periodicallab, pageNo, pageSize); |
||||
|
return Result.ok(pageList); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据id获取详情政策法规 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/getperiodicallabById") |
||||
|
public Result<?> getperiodicallabById(String id){ |
||||
|
HuzhouPeriodicallab byId = periodicallabService.getById(id); |
||||
|
return Result.ok(byId); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加政策法规 |
||||
|
* @param file |
||||
|
* @param periodicallab |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/addPeriodicallab") |
||||
|
public Result<?> addPeriodicallab(@RequestParam(value = "file") MultipartFile file, HuzhouPeriodicallab periodicallab) throws IOException { |
||||
|
periodicallabService.addPeriodicallab(file,periodicallab); |
||||
|
return Result.ok("上传成功"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改政策法规 |
||||
|
* @param file |
||||
|
* @param periodicallab |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/modifyPeriodicallab") |
||||
|
public Result<?> modifyPeriodicallab(@RequestParam(value = "file",required = false) MultipartFile file, HuzhouPeriodicallab periodicallab) throws IOException { |
||||
|
Boolean aBoolean = periodicallabService.modifyPeriodicallab(file, periodicallab); |
||||
|
if(aBoolean){ |
||||
|
return Result.ok("修改成功"); |
||||
|
} |
||||
|
throw new EasyException("修改失败"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除政策法规 |
||||
|
* @param periodicallab |
||||
|
* @return |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@PostMapping("/deletePeriodicallab") |
||||
|
public Result<?> deletePeriodicallab(@RequestBody HuzhouPeriodicallab periodicallab) throws IOException { |
||||
|
Boolean aBoolean = periodicallabService.deletePeriodicallab(periodicallab); |
||||
|
if(aBoolean){ |
||||
|
return Result.ok("删除成功"); |
||||
|
} |
||||
|
throw new EasyException("删除失败"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量下载 |
||||
|
* @param periodicallab |
||||
|
* @param response |
||||
|
*/ |
||||
|
@GetMapping("/batchdownloadPeriodicallabFiles") |
||||
|
public void batchdownloadPeriodicallabFiles(HuzhouPeriodicallab periodicallab, HttpServletResponse response){ |
||||
|
periodicallabService.batchdownloadPeriodicallabFiles(periodicallab,response); |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
package com.easy.admin.modules.huzhou.dao; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouPeriodicallab; |
||||
|
|
||||
|
public interface HuzhouPeriodicallabMapper extends BaseMapper<HuzhouPeriodicallab> { |
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
package com.easy.admin.modules.huzhou.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* (HuzhouPeriodicallab)实体类 |
||||
|
* |
||||
|
* @author makejava |
||||
|
* @since 2024-02-29 11:03:40 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class HuzhouPeriodicallab extends BaseEntity implements Serializable { |
||||
|
private static final long serialVersionUID = -50005828024123796L; |
||||
|
/** |
||||
|
* 期刊名称 |
||||
|
*/ |
||||
|
private String name; |
||||
|
/** |
||||
|
* 期数 |
||||
|
*/ |
||||
|
private String periods; |
||||
|
/** |
||||
|
|
||||
|
* 发布日期 |
||||
|
*/ |
||||
|
private Date publish_time; |
||||
|
/** |
||||
|
|
||||
|
* id |
||||
|
*/ |
||||
|
private String id; |
||||
|
/** |
||||
|
* 文件名称 |
||||
|
*/ |
||||
|
private String documentName; |
||||
|
/** |
||||
|
* 文件类型 |
||||
|
*/ |
||||
|
private String documentType; |
||||
|
/** |
||||
|
* 文件位置 |
||||
|
*/ |
||||
|
private String documentPath; |
||||
|
/** |
||||
|
* 文件尺寸 |
||||
|
*/ |
||||
|
private Long size; |
||||
|
/** |
||||
|
* 文件状态 |
||||
|
*/ |
||||
|
private String status; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,22 @@ |
|||||
|
package com.easy.admin.modules.huzhou.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouPeriodicallab; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouRegulationlab; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
public interface IHuzhouPeriodicallabService extends IService<HuzhouPeriodicallab> { |
||||
|
Page<HuzhouPeriodicallab> getPeriodicallabPageList(HuzhouPeriodicallab periodicallab, Integer pageNo, |
||||
|
Integer pageSize); |
||||
|
void addPeriodicallab(MultipartFile file,HuzhouPeriodicallab periodicallab) throws IOException; |
||||
|
Boolean modifyPeriodicallab(MultipartFile file, HuzhouPeriodicallab periodicallab) throws IOException; |
||||
|
|
||||
|
Boolean deletePeriodicallab(HuzhouPeriodicallab periodicallab); |
||||
|
|
||||
|
void batchdownloadPeriodicallabFiles(HuzhouPeriodicallab periodicallab,HttpServletResponse response); |
||||
|
} |
@ -0,0 +1,145 @@ |
|||||
|
package com.easy.admin.modules.huzhou.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
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.HuzhouPeriodicallabMapper; |
||||
|
import com.easy.admin.modules.huzhou.entity.HuzhouPeriodicallab; |
||||
|
import com.easy.admin.modules.huzhou.service.IHuzhouPeriodicallabService; |
||||
|
import com.easy.admin.util.ShiroUtil; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
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; |
||||
|
|
||||
|
@Service |
||||
|
public class HuzhouPeriodicallabServiceImpl extends ServiceImpl<HuzhouPeriodicallabMapper, HuzhouPeriodicallab> implements IHuzhouPeriodicallabService { |
||||
|
@Value(value = "${jeecg.path.upload}") |
||||
|
private String uploadpath; |
||||
|
@Override |
||||
|
public Page<HuzhouPeriodicallab> getPeriodicallabPageList(HuzhouPeriodicallab periodicallab, |
||||
|
Integer pageNo, |
||||
|
Integer pageSize) { |
||||
|
LambdaQueryWrapper<HuzhouPeriodicallab> queryWrapper = new LambdaQueryWrapper<>(); |
||||
|
Page<HuzhouPeriodicallab> huzhouPeriodicallabPage = new Page<>(pageNo, pageSize); |
||||
|
String periodicallabName = periodicallab.getName(); |
||||
|
String documentName = periodicallab.getDocumentName(); |
||||
|
|
||||
|
String periodicallabPeriods = periodicallab.getPeriods(); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(periodicallabName),HuzhouPeriodicallab::getName,periodicallabName); |
||||
|
queryWrapper.eq(StringUtils.isNotBlank(periodicallabPeriods),HuzhouPeriodicallab::getPeriods,periodicallabPeriods); |
||||
|
|
||||
|
|
||||
|
queryWrapper.like(StringUtils.isNotBlank(documentName),HuzhouPeriodicallab::getDocumentName,documentName); |
||||
|
Page<HuzhouPeriodicallab> page = this.page(huzhouPeriodicallabPage, queryWrapper); |
||||
|
return page; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void addPeriodicallab(MultipartFile file, HuzhouPeriodicallab periodicallab) throws IOException { |
||||
|
addFile(file,periodicallab); |
||||
|
this.save(periodicallab); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean modifyPeriodicallab(MultipartFile file,HuzhouPeriodicallab periodicallab) throws IOException { |
||||
|
String documentPath = this.getById(periodicallab.getId()).getDocumentPath(); |
||||
|
File periodicallabFile = new File(documentPath); |
||||
|
if(file==null){ |
||||
|
this.updateById(periodicallab); |
||||
|
return true; |
||||
|
} |
||||
|
if(periodicallabFile.delete()){ |
||||
|
addFile(file,periodicallab); |
||||
|
this.updateById(periodicallab); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean deletePeriodicallab(HuzhouPeriodicallab periodicallab) { |
||||
|
String id = periodicallab.getId(); |
||||
|
periodicallab = this.getById(id); |
||||
|
File file = new File(periodicallab.getDocumentPath()); |
||||
|
if(file.delete()){ |
||||
|
this.removeById(id); |
||||
|
return Boolean.TRUE; |
||||
|
} |
||||
|
return Boolean.FALSE; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void batchdownloadPeriodicallabFiles(HuzhouPeriodicallab periodicallab, HttpServletResponse response) { |
||||
|
LambdaQueryWrapper<HuzhouPeriodicallab> queryWrapper = new LambdaQueryWrapper<>(); |
||||
|
String periodicallabName = periodicallab.getName(); |
||||
|
String documentName = periodicallab.getDocumentName(); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(periodicallabName),HuzhouPeriodicallab::getName,periodicallabName); |
||||
|
queryWrapper.like(StringUtils.isNotBlank(documentName),HuzhouPeriodicallab::getDocumentName,documentName); |
||||
|
List<HuzhouPeriodicallab> list = this.list(queryWrapper); |
||||
|
List<String> pathList = list.stream().map(HuzhouPeriodicallab::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,HuzhouPeriodicallab periodicallab) 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+"periodicallab"+ 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);//保存文件
|
||||
|
periodicallab.setDocumentName(originalFilename);//未加工过的文件名称
|
||||
|
periodicallab.setDocumentType(file.getContentType()); |
||||
|
periodicallab.setDocumentPath(savePath); |
||||
|
periodicallab.setSize(file.getSize()); |
||||
|
periodicallab.setStatus("1"); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue