Commit 864cc7e7 by 宋珺琪

资源管理模块(重庆)

parent b4e30357
package com.founder.commonutils.model.newPublicEntity.ResourceManager;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sk_resource_manager")
public class ResourceManagerEntity {
@TableId(type = IdType.INPUT)
private String id;
@TableField("file_name")
private String fileName;
@TableField("file_path")
private String filePath;
@TableField("file_source")
private String fileSource;
@TableField("file_size")
private String fileSize;
@TableField("file_type")
private String fileType;
@TableField("ms")
private String ms;
@TableField("cjsj")
private String cjsj;
@TableField("gxsj")
private String gxsj;
@TableField("is_delete")
private String isDelete;
@TableField(exist = false)
private String startTime;
@TableField(exist = false)
private String endTime;
@TableField(exist = false)
private int page;//当前第几页
@TableField(exist = false)
private int limit;//每页多少行
}
package com.founder.publicapi.controller.ResourceManager;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.URLUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.founder.commonutils.model.newPublicEntity.MapRestResult;
import com.founder.commonutils.model.newPublicEntity.ResourceManager.ResourceManagerEntity;
import com.founder.commonutils.util.KeyUtilNaotu;
import com.founder.publicapi.mapper.mysqlMapper.ResourceManagerMapper;
import com.founder.servicebase.logs.OperLog;
import com.founder.servicebase.logs.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
@RestController
@RequestMapping("/Resource")
@Api(tags = "资源管理")
public class ResourceManagerController {
@Value("${ResourceManagerUpload}")
private String RESOURCE_MANAGER_UPLOAD;//文件上传的路径
@Value("${ResourceManagerDownload}")
private String RESOURCE_MANAGER_DOWNLOAD;//文件下载路径
@Autowired
ResourceManagerMapper resourceManagerMapper;
@PostMapping("resourceAdd")
@ApiOperation(value = "资源管理添加")
@OperLog(message = "资源管理添加", operation = OperationType.ADD)
public MapRestResult resourceAdd(ResourceManagerEntity resourceManagerEntity, MultipartFile file ) {
if (file != null) {
String ZyId = KeyUtilNaotu.getJzKey("ZY");
//文件名
String originalFilename = file.getOriginalFilename();
String originalName = file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
// 文件后缀
String postfix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// 类型
// String fileType = file.getContentType();
// 上传文件路径
String path = RESOURCE_MANAGER_UPLOAD + ZyId + postfix;
try {
FileUtil.writeBytes(file.getBytes(), path);
} catch (IOException e) {
e.printStackTrace();
}
resourceManagerEntity.setId(ZyId);
resourceManagerEntity.setFileName(originalFilename);
resourceManagerEntity.setFilePath(RESOURCE_MANAGER_DOWNLOAD+ ZyId + postfix);
resourceManagerEntity.setFileSize(String.valueOf(file.getSize()));
resourceManagerEntity.setFileType(postfix);
resourceManagerEntity.setCjsj(nowTime());
resourceManagerEntity.setGxsj(nowTime());
int insert = resourceManagerMapper.insert(resourceManagerEntity);
if (insert > 0){
return new MapRestResult(200,"上传成功",null);
}else return new MapRestResult(200,"上传失败",null);
}else {
return new MapRestResult().error("请上传文件");
}
}
@PostMapping("resourceDelete")
@ApiOperation(value = "资源管理删除")
@OperLog(message = "资源管理删除", operation = OperationType.DELETE)
public MapRestResult resourceAdd(@RequestBody ResourceManagerEntity resourceManagerEntity){
ResourceManagerEntity byId = resourceManagerMapper.selectById(resourceManagerEntity.getId());
if (byId!=null){
byId.setIsDelete("1");
}else {
return new MapRestResult(200,"删除失败,没有该资源",null);
}
int i = resourceManagerMapper.updateById(byId);
if ( i > 0 ){
return new MapRestResult(200,"删除成功",null);
}else {
return new MapRestResult(200,"删除失败,没有该资源",null);
}
}
@PostMapping("resourceUpdate")
@ApiOperation(value = "资源管理修改")
@OperLog(message = "资源管理修改", operation = OperationType.UPDATE)
public MapRestResult scheduleUpdate(ResourceManagerEntity resourceManagerEntity, MultipartFile file){
if (file != null) {
//文件名
String originalFilename = file.getOriginalFilename();
String originalName = file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
// 文件后缀
String postfix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// 上传文件路径
String path = RESOURCE_MANAGER_UPLOAD + "/" + resourceManagerEntity.getId() + postfix;
try {
FileUtil.writeBytes(file.getBytes(), path);
} catch (IOException e) {
e.printStackTrace();
}
resourceManagerEntity.setId(resourceManagerEntity.getId());
resourceManagerEntity.setFileName(originalFilename);
resourceManagerEntity.setFilePath(RESOURCE_MANAGER_DOWNLOAD+ resourceManagerEntity.getId() + postfix);
resourceManagerEntity.setFileSize(String.valueOf(file.getSize()));
resourceManagerEntity.setFileType(postfix);
resourceManagerEntity.setGxsj(nowTime());
int updateById = resourceManagerMapper.updateById(resourceManagerEntity);
if (updateById > 0){
return new MapRestResult(200,"修改成功",null);
}else return new MapRestResult(200,"修改失败",null);
}else {
resourceManagerEntity.setGxsj(nowTime());
int i = resourceManagerMapper.updateById(resourceManagerEntity);
if (i > 0){
return new MapRestResult(200,"修改成功",null);
}else return new MapRestResult(200,"修改失败",null); }
}
@PostMapping("resourceQuery")
@ApiOperation(value = "资源管理查询")
@OperLog(message = "资源管理查询", operation = OperationType.QUERY)
public MapRestResult resourceQuery(@RequestBody ResourceManagerEntity resourceManagerEntity){
QueryWrapper wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotEmpty(resourceManagerEntity.getFileName()),"file_name", resourceManagerEntity.getFileName());
wrapper.eq(StringUtils.isNotEmpty(resourceManagerEntity.getFileSource()),"file_source", resourceManagerEntity.getFileSource());
if (StringUtils.isNotEmpty(resourceManagerEntity.getStartTime()) && StringUtils.isNotEmpty(resourceManagerEntity.getEndTime())) {
wrapper.apply("cjsj between'" + resourceManagerEntity.getStartTime() + "' and '" + resourceManagerEntity.getEndTime() +"'" );
} else if (StringUtils.isNotEmpty(resourceManagerEntity.getStartTime())) {
wrapper.apply("cjsj >= '" + resourceManagerEntity.getStartTime() +"'" );
} else if (StringUtils.isNotEmpty(resourceManagerEntity.getEndTime())) {
wrapper.apply("cjsj <= '" + resourceManagerEntity.getEndTime() +"'" );
}
wrapper.eq("is_delete","0");
wrapper.orderByDesc("gxsj");
IPage iPage = resourceManagerMapper.selectPage(new Page<>(resourceManagerEntity.getPage(), resourceManagerEntity.getLimit()), wrapper);
return new MapRestResult(200,"ok",iPage.getTotal(),iPage.getRecords());
}
@PostMapping("resourceDetil")
@ApiOperation(value = "资源管理详情")
@OperLog(message = "资源管理详情", operation = OperationType.QUERY)
public MapRestResult resourceDetil(@RequestBody ResourceManagerEntity resourceManagerEntity){
ResourceManagerEntity resourceManagerEntity1 = resourceManagerMapper.selectById(resourceManagerEntity.getId());
return new MapRestResult(200,"ok",resourceManagerEntity1);
}
@GetMapping(value = "download")
@OperLog(message = "文件下载", operation = OperationType.QUERY)
@ApiOperation(value = "文件下载")
public void download (String id ,String fileType, String fileName,HttpServletResponse response) throws IOException {
String path1 = RESOURCE_MANAGER_DOWNLOAD +id + fileType;
String path = URLUtil.encode(path1);
// 读到流中
response.setContentType("text/html;charset=utf-8");
//通知浏览器以下载的方式打开
response.addHeader("Content-Type","application/octet-stream");
response.addHeader("Content-Disposition","attachment;filename="+fileName);
//通过文件输入流读取文件
InputStream fis = URLUtil.getStream(new URL(path));
//通过文件输出流写入文件
OutputStream out=response.getOutputStream();
byte[] bytes=new byte[1024];
int len=0;
//循环将写入流
while ((len=fis.read(bytes))!=-1){
out.write(bytes,0,len);
}
// 关闭资源
out.flush();
out.close();
}
/**
* 当前时间
* @return
*/
public String nowTime(){
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return formatter.format(date);
}
}
package com.founder.publicapi.mapper.mysqlMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.founder.commonutils.model.newPublicEntity.ResourceManager.ResourceManagerEntity;
public interface ResourceManagerMapper extends BaseMapper<ResourceManagerEntity> {
}
......@@ -41,6 +41,12 @@ approvalDownload = http://47.92.48.137:1009/excel/approvalWord/
#\u65B0\u589E\u5377\u5B97\u5927\u6570\u636E\u6A21\u578B\u4E0B\u8F7D\u6A21\u677F\u7684\u8DEF\u5F84
approvalDownloadTemplate = http://47.92.48.137:1009/excel/approvalWord/ApprovalWordTemplate.docx
#\u8D44\u6E90\u7BA1\u7406\u4E0A\u4F20\u8DEF\u5F84
ResourceManagerUpload = /data/excel/ResourceManager/
#\u8D44\u6E90\u7BA1\u7406\u4E0B\u8F7D\u8DEF\u5F84
ResourceManagerDownload = http://47.92.48.137:1009/excel/ResourceManager/
#xml???
mybatis-plus.mapper-locations=classpath*:com/founder/publicapi/mapper/*/xml/*.xml
#es?????????
......
......@@ -41,6 +41,12 @@ approvalDownload = http://47.92.48.137:1009/excel/approvalWord/
#\u65B0\u589E\u5377\u5B97\u5927\u6570\u636E\u6A21\u578B\u4E0B\u8F7D\u6A21\u677F\u7684\u8DEF\u5F84
approvalDownloadTemplate = http://47.92.48.137:1009/excel/approvalWord/ApprovalWordTemplate.docx
#\u8D44\u6E90\u7BA1\u7406\u4E0A\u4F20\u8DEF\u5F84
ResourceManagerUpload = /data/excel/ResourceManager/
#\u8D44\u6E90\u7BA1\u7406\u4E0B\u8F7D\u8DEF\u5F84
ResourceManagerDownload = http://47.92.48.137:1009/excel/ResourceManager/
#xml???
mybatis-plus.mapper-locations=classpath*:com/founder/publicapi/mapper/*/xml/*.xml
#es?????????
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment