zbj//1.资源管理(上传资源)
This commit is contained in:
@@ -72,4 +72,9 @@ public interface OssPath {
|
||||
* 资源管理文件
|
||||
*/
|
||||
String RESOURCEADMINISTRATION = "resourceAdministration/";
|
||||
|
||||
/***
|
||||
* 资源文件
|
||||
*/
|
||||
String RESOURCEDATA = "resourceData/";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.njcn.device.pq.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author zbj
|
||||
* @since 2023-05-25
|
||||
*/
|
||||
@Data
|
||||
@TableName("pqs_resourcedata")
|
||||
public class ResourceData {
|
||||
|
||||
/**
|
||||
* 资源序号
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 资源名称
|
||||
*/
|
||||
@TableField(value = "resource_name")
|
||||
private String resourceName;
|
||||
|
||||
/**
|
||||
* 资源路径
|
||||
*/
|
||||
@TableField(value = "res_url")
|
||||
private String resUrl;
|
||||
|
||||
/**
|
||||
* 图片路径
|
||||
*/
|
||||
@TableField(value = "pic_url")
|
||||
private String picUrl;
|
||||
|
||||
/**
|
||||
* 数据上传时间
|
||||
*/
|
||||
@TableField(value = "upload_time")
|
||||
private LocalDateTime uploadTime;
|
||||
|
||||
/**
|
||||
* 数据修改时间
|
||||
*/
|
||||
@TableField(value = "update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 数据状态(0: 展示; 1: 不展示)
|
||||
*/
|
||||
@TableField(value = "state")
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 数据类型(0: 文件; 1: 视频)
|
||||
*/
|
||||
@TableField(value = "type")
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
@@ -45,6 +45,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-oss</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.njcn.device.pq.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.MonitoringPointScaleVO;
|
||||
import com.njcn.device.pq.service.LargeScreenService;
|
||||
import com.njcn.device.pq.service.ResourceService;
|
||||
import com.njcn.system.pojo.po.Resinformation;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/05/25
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "资源管理")
|
||||
@RestController
|
||||
@RequestMapping("/resource")
|
||||
@RequiredArgsConstructor
|
||||
public class ResourceController extends BaseController {
|
||||
|
||||
private final ResourceService iResourceAdministrationService;
|
||||
|
||||
/**
|
||||
* 上传资源
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/uploadFile")
|
||||
@ApiOperation("上传资源")
|
||||
public HttpResult<Boolean> uploadFile(@ApiParam(value = "文件", required = true) @RequestPart("multipartFile") MultipartFile multipartFile,
|
||||
@ApiParam(value = "文件", required = false) @RequestPart("picture") MultipartFile picture,
|
||||
@ApiParam(value = "资源名称", required = true) String name,
|
||||
@ApiParam(value = "资源类型", required = true) Integer type) {
|
||||
String methodDescribe = getMethodDescribe("uploadFile");
|
||||
Boolean flag = iResourceAdministrationService.uploadFile(multipartFile, picture, name, type);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||
}
|
||||
/*
|
||||
*//**
|
||||
* 查询数据
|
||||
*//*
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/queryData")
|
||||
@ApiOperation("查询数据")
|
||||
@ApiImplicitParam(name = "resinformation", value = "查询数据", required = true)
|
||||
public HttpResult<List<Resinformation>> queryData(@RequestBody Resinformation resinformation) {
|
||||
String methodDescribe = getMethodDescribe("queryData");
|
||||
List<Resinformation> result = iResourceAdministrationService.queryData(resinformation);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 修改资源
|
||||
*//*
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/updateFile")
|
||||
@ApiOperation("修改资源")
|
||||
public HttpResult<Boolean> updateFile(@ApiParam(value = "文件", required = false) MultipartFile multipartFile,
|
||||
@ApiParam(value = "id", required = true) String id,
|
||||
@ApiParam(value = "资源名称", required = true) String name,
|
||||
@ApiParam(value = "资源类型", required = true) String type,
|
||||
@ApiParam(value = "资源描述", required = true) String description,
|
||||
@ApiParam(value = "系统类型Guid", required = false) String systemType) {
|
||||
String methodDescribe = getMethodDescribe("updateFile");
|
||||
Boolean flag = iResourceAdministrationService.updateFile(multipartFile, id, name, type, description, systemType);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 删除资源
|
||||
*//*
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/deleteFile")
|
||||
@ApiOperation("删除资源")
|
||||
@ApiImplicitParam(name = "id",value = "id",required = true)
|
||||
public HttpResult<Boolean> deleteFile(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("deleteFile");
|
||||
Boolean flag = iResourceAdministrationService.deleteFile(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 下载资源
|
||||
*//*
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/downloadFile")
|
||||
@ApiOperation("下载资源")
|
||||
@ApiImplicitParam(name = "id",value = "id",required = true)
|
||||
public HttpResult<Object> downloadFile(@RequestParam("id")String id, HttpServletResponse response) throws IOException {
|
||||
String methodDescribe = getMethodDescribe("downloadFile");
|
||||
iResourceAdministrationService.downloadFile(id,response);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "下载成功", methodDescribe);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 导出数据
|
||||
*//*
|
||||
*//*@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/exportData")
|
||||
@ApiOperation("导出数据")
|
||||
public HttpResult<Object> exportData() {
|
||||
String methodDescribe = getMethodDescribe("exportData");
|
||||
iResourceAdministrationService.exportData();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "成功", methodDescribe);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.device.pq.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.device.pq.pojo.po.ResourceData;
|
||||
import com.njcn.system.pojo.po.ResinformationParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/05/25
|
||||
*/
|
||||
public interface ResourceMapper extends BaseMapper<ResourceData> {
|
||||
List<ResinformationParam> listAll();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.device.pq.mapper.ResourceMapper">
|
||||
<select id="listAll" resultType="com.njcn.system.pojo.po.ResinformationParam">
|
||||
SELECT pr.`NAME` "name", sdd.`Name` "type", pr.DESCRIPTION "description", pr.UPDATETIME "time"
|
||||
FROM pqs_resinformation pr
|
||||
left join sys_dict_data sdd on sdd.Id = pr.TYPE
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.device.pq.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.po.ResourceData;
|
||||
import com.njcn.device.pq.pojo.vo.MonitoringPointScaleVO;
|
||||
import com.njcn.system.pojo.po.Resinformation;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/05/25
|
||||
*/
|
||||
public interface ResourceService extends IService<ResourceData> {
|
||||
|
||||
Boolean uploadFile(MultipartFile multipartFile, MultipartFile picture, String name, Integer type);
|
||||
|
||||
/* List<Resinformation> queryData(Resinformation resinformation);
|
||||
|
||||
Boolean updateFile(MultipartFile multipartFile, String id, String name, String type, String description, String systemType);
|
||||
|
||||
Boolean deleteFile(String id);
|
||||
|
||||
void downloadFile(String id, HttpServletResponse response) throws IOException;
|
||||
|
||||
void exportData();*/
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.njcn.device.pq.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.dto.SimpleDTO;
|
||||
import com.njcn.device.pq.mapper.LargeScreenMapper;
|
||||
import com.njcn.device.pq.mapper.ResourceMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.param.MonitoringPointScaleParam;
|
||||
import com.njcn.device.pq.pojo.po.ResourceData;
|
||||
import com.njcn.device.pq.pojo.vo.MonitoringPointScaleVO;
|
||||
import com.njcn.device.pq.service.LargeScreenService;
|
||||
import com.njcn.device.pq.service.ResourceService;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.system.pojo.enums.StatisticsEnum;
|
||||
import com.njcn.system.pojo.po.Resinformation;
|
||||
import com.njcn.system.pojo.po.ResinformationParam;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/05/25
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, ResourceData> implements ResourceService {
|
||||
|
||||
private final ResourceMapper resourceMapper;
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
//private final GeneralInfo generalInfo;
|
||||
|
||||
@Override
|
||||
public Boolean uploadFile(MultipartFile multipartFile, MultipartFile picture, String name, Integer type) {
|
||||
String resUrl = "";
|
||||
String picUrl = "";
|
||||
//通过封装好的文件工具类来传入文件和文件夹名称来获取文件路径
|
||||
resUrl = fileStorageUtil.uploadMultipart(multipartFile, OssPath.RESOURCEDATA);
|
||||
//判断图片文件对象是否为空,不为空获取图片路径
|
||||
if (null != picture && !picture.isEmpty()) {
|
||||
picUrl = fileStorageUtil.uploadMultipart(picture, OssPath.RESOURCEDATA);
|
||||
}
|
||||
//创建对象
|
||||
ResourceData resourceData = new ResourceData();
|
||||
resourceData.setResourceName(name);
|
||||
resourceData.setResUrl(resUrl);
|
||||
resourceData.setPicUrl(picUrl);
|
||||
resourceData.setUploadTime(LocalDateTime.now());
|
||||
resourceData.setState(1);
|
||||
resourceData.setType(type);
|
||||
return this.save(resourceData);
|
||||
}
|
||||
/*
|
||||
|
||||
@Override
|
||||
public List<Resinformation> queryData(Resinformation resinformation) {
|
||||
|
||||
if (StringUtils.isNotBlank(resinformation.getType()) && StringUtils.isNotBlank(resinformation.getSystemType())) {
|
||||
LambdaQueryWrapper<Resinformation> wrapper = new LambdaQueryWrapper<>();
|
||||
//type
|
||||
wrapper.eq(Resinformation::getType, resinformation.getType());
|
||||
//sysType
|
||||
wrapper.eq(Resinformation::getSystemType, resinformation.getSystemType());
|
||||
return resourceAdministrationMapper.selectList(wrapper);
|
||||
|
||||
} else if (StringUtils.isBlank(resinformation.getType()) && StringUtils.isBlank(resinformation.getSystemType())) {
|
||||
|
||||
return this.list();
|
||||
|
||||
} else if (StringUtils.isNotBlank(resinformation.getType()) && StringUtils.isBlank(resinformation.getSystemType())) {
|
||||
LambdaQueryWrapper<Resinformation> wrapper = new LambdaQueryWrapper<>();
|
||||
//type
|
||||
wrapper.eq(Resinformation::getType, resinformation.getType());
|
||||
return resourceAdministrationMapper.selectList(wrapper);
|
||||
} else {
|
||||
LambdaQueryWrapper<Resinformation> wrapper = new LambdaQueryWrapper<>();
|
||||
//sysType
|
||||
wrapper.eq(Resinformation::getSystemType, resinformation.getSystemType());
|
||||
return resourceAdministrationMapper.selectList(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateFile(MultipartFile multipartFile, String id, String name, String type, String description, String systemType) {
|
||||
Resinformation resinformation = resourceAdministrationMapper.selectById(id);
|
||||
if (null != multipartFile && !multipartFile.isEmpty()) {
|
||||
//删除文件
|
||||
fileStorageUtil.deleteFile(resinformation.getUrl());
|
||||
//获取路径
|
||||
String url = fileStorageUtil.uploadMultipart(multipartFile, OssPath.RESOURCEADMINISTRATION);
|
||||
resinformation.setUrl(url);
|
||||
resinformation.setFileName(multipartFile.getOriginalFilename());
|
||||
}
|
||||
resinformation.setName(name);
|
||||
resinformation.setDescription(description);
|
||||
//获取用户id
|
||||
String userIndex = RequestUtil.getUserIndex();
|
||||
//String userIndex = "123456";
|
||||
resinformation.setUpdateUser(userIndex);
|
||||
resinformation.setUpdateTime(LocalDateTime.now());
|
||||
resinformation.setState(1);
|
||||
if (StringUtils.isNotBlank(systemType)) {
|
||||
resinformation.setSystemType(systemType);
|
||||
}
|
||||
resinformation.setType(type);
|
||||
int i = resourceAdministrationMapper.updateById(resinformation);
|
||||
return i > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteFile(String id) {
|
||||
Resinformation resinformation = resourceAdministrationMapper.selectById(id);
|
||||
//删除文件
|
||||
fileStorageUtil.deleteFile(resinformation.getUrl());
|
||||
//删除数据
|
||||
int i = resourceAdministrationMapper.deleteById(id);
|
||||
return i > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFile(String id, HttpServletResponse response) throws IOException {
|
||||
Resinformation resinformation = resourceAdministrationMapper.selectById(id);
|
||||
//下载文件
|
||||
fileStorageUtil.downloadStream(response, resinformation.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportData() {
|
||||
String fileName = "资源列表.csv";
|
||||
//String targetDir = generalInfo.getBusinessTempPath() + File.separator + RequestUtil.getUserIndex();
|
||||
String targetDir = "C:\\Users\\User\\Desktop\\1";
|
||||
File excel = new File(targetDir, fileName);
|
||||
List<ResinformationParam> list = resourceAdministrationMapper.listAll();
|
||||
ExcelUtil.exportExcelWithTargetFile(excel, ResinformationParam.class, list);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user