parent
450f8ce1c9
commit
0f2c1a3e95
|
|
@ -0,0 +1,94 @@
|
|||
package com.bonus.imgTool.imgUpload.controller;
|
||||
|
||||
import com.bonus.imgTool.annotation.DecryptAndVerify;
|
||||
import com.bonus.imgTool.annotation.LogAnnotation;
|
||||
import com.bonus.imgTool.basic.vo.dto.ProDto;
|
||||
import com.bonus.imgTool.basic.vo.dto.ProcessDto;
|
||||
import com.bonus.imgTool.imgUpload.service.SafetyViolationService;
|
||||
import com.bonus.imgTool.imgUpload.vo.SafetyViolationVo;
|
||||
import com.bonus.imgTool.imgUpload.vo.dto.SafetyViolationDto;
|
||||
import com.bonus.imgTool.system.vo.EncryptedReq;
|
||||
import com.bonus.imgTool.system.vo.UserDto;
|
||||
import com.bonus.imgTool.utils.ServerResponse;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fly
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/imgUpload/safetyViolation/")
|
||||
@Slf4j
|
||||
public class SafetyViolationController {
|
||||
|
||||
@Resource
|
||||
private SafetyViolationService service;
|
||||
|
||||
@GetMapping(value = "getList")
|
||||
@DecryptAndVerify(decryptedClass = SafetyViolationDto.class)//加解密统一管理
|
||||
@LogAnnotation(operModul = "安全违章", operation = "查询列表", operDesc = "系统级事件",operType="查询")
|
||||
// @PreAuthorize("@pms.hasPermission('sys:safetyViolation:query')" )
|
||||
public ServerResponse getList(EncryptedReq<SafetyViolationDto> data) {
|
||||
PageHelper.startPage(data.getData().getPage(), data.getData().getLimit());
|
||||
try {
|
||||
List<SafetyViolationVo> list = service.getList(data.getData());
|
||||
PageInfo<SafetyViolationVo> pageInfo = new PageInfo<>(list);
|
||||
return ServerResponse.createSuccessPage(pageInfo,data.getData().getPage(),data.getData().getLimit());
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErrorPage(data.getData().getPage(),data.getData().getLimit());
|
||||
}
|
||||
|
||||
@PostMapping(value = "insertSafetyViolation")
|
||||
@DecryptAndVerify(decryptedClass = SafetyViolationDto.class)//加解密统一管理
|
||||
@LogAnnotation(operModul = "安全违章", operation = "新增数据", operDesc = "系统级事件",operType="新增")
|
||||
// @PreAuthorize("@pms.hasPermission('sys:safetyViolation:query')" )
|
||||
public ServerResponse insertSafetyViolation(EncryptedReq<SafetyViolationDto> data) {
|
||||
try {
|
||||
SafetyViolationDto bean = data.getData();
|
||||
return service.insertSafetyViolation(bean);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("操作失败");
|
||||
}
|
||||
|
||||
@PostMapping(value = "getSafetyViolationById")
|
||||
@DecryptAndVerify(decryptedClass = SafetyViolationDto.class)//加解密统一管理
|
||||
@LogAnnotation(operModul = "安全违章", operation = "查询单个数据", operDesc = "系统级事件",operType="查询")
|
||||
// @PreAuthorize("@pms.hasPermission('sys:safetyViolation:query')" )
|
||||
public ServerResponse getSafetyViolationById(EncryptedReq<SafetyViolationDto> data) {
|
||||
try {
|
||||
SafetyViolationVo safetyViolation = service.getSafetyViolationById(data.getData().getId());
|
||||
return ServerResponse.createSuccess(safetyViolation);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("操作失败");
|
||||
}
|
||||
|
||||
@PostMapping(value = "updateSafetyViolationById")
|
||||
@DecryptAndVerify(decryptedClass = SafetyViolationDto.class)//加解密统一管理
|
||||
@LogAnnotation(operModul = "安全违章", operation = "修改单个数据", operDesc = "系统级事件",operType="修改")
|
||||
// @PreAuthorize("@pms.hasPermission('sys:safetyViolation:query')" )
|
||||
public ServerResponse updateSafetyViolationById(EncryptedReq<SafetyViolationDto> data) {
|
||||
try {
|
||||
SafetyViolationDto bean = data.getData();
|
||||
return service.updateSafetyViolationById(bean);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return ServerResponse.createErroe("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.bonus.imgTool.imgUpload.dao;
|
||||
|
||||
import com.bonus.imgTool.basic.vo.dto.ProDto;
|
||||
import com.bonus.imgTool.imgUpload.vo.SafetyViolationVo;
|
||||
import com.bonus.imgTool.imgUpload.vo.dto.SafetyViolationDto;
|
||||
import com.bonus.imgTool.system.vo.dto.FileStorageDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SafetyViolationDao {
|
||||
|
||||
List<SafetyViolationVo> getList(SafetyViolationDto data);
|
||||
|
||||
int insertSafetyViolation(SafetyViolationDto bean);
|
||||
|
||||
int insertImgPhoto(List<FileStorageDto> fileList);
|
||||
|
||||
SafetyViolationVo getSafetyViolationById(Long id);
|
||||
|
||||
List<FileStorageDto> getImgPhotoList(FileStorageDto bean);
|
||||
|
||||
int updateSafetyViolationById(SafetyViolationDto bean);
|
||||
|
||||
int delImgPhoto(List<FileStorageDto> delFileList);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.bonus.imgTool.imgUpload.service;
|
||||
|
||||
|
||||
|
||||
import com.bonus.imgTool.basic.vo.dto.ProDto;
|
||||
import com.bonus.imgTool.imgUpload.vo.SafetyViolationVo;
|
||||
import com.bonus.imgTool.imgUpload.vo.dto.SafetyViolationDto;
|
||||
import com.bonus.imgTool.utils.ServerResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SafetyViolationService {
|
||||
|
||||
List<SafetyViolationVo> getList(SafetyViolationDto data);
|
||||
|
||||
ServerResponse insertSafetyViolation(SafetyViolationDto bean);
|
||||
|
||||
SafetyViolationVo getSafetyViolationById(Long id);
|
||||
|
||||
ServerResponse updateSafetyViolationById(SafetyViolationDto bean);
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package com.bonus.imgTool.imgUpload.service.impl;
|
||||
|
||||
import com.bonus.imgTool.basic.vo.dto.ProDto;
|
||||
import com.bonus.imgTool.imgUpload.dao.SafetyViolationDao;
|
||||
import com.bonus.imgTool.imgUpload.service.SafetyViolationService;
|
||||
import com.bonus.imgTool.imgUpload.vo.SafetyViolationVo;
|
||||
import com.bonus.imgTool.imgUpload.vo.dto.SafetyViolationDto;
|
||||
import com.bonus.imgTool.system.vo.LoginUser;
|
||||
import com.bonus.imgTool.system.vo.dto.FileStorageDto;
|
||||
import com.bonus.imgTool.task.job.ProPullTask;
|
||||
import com.bonus.imgTool.utils.ServerResponse;
|
||||
import com.bonus.imgTool.utils.UserUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class SafetyViolationServiceImpl implements SafetyViolationService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger("SafetyViolationServiceImpl");
|
||||
|
||||
@Resource
|
||||
private SafetyViolationDao dao;
|
||||
|
||||
@Override
|
||||
public List<SafetyViolationVo> getList(SafetyViolationDto data) {
|
||||
return dao.getList(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ServerResponse insertSafetyViolation(SafetyViolationDto bean) {
|
||||
LoginUser loginUser = UserUtil.getLoginUser();
|
||||
bean.setCreateUserId(loginUser.getId());
|
||||
bean.setCreateUserName(loginUser.getUsername());
|
||||
//基础数据存入库
|
||||
int i = dao.insertSafetyViolation(bean);
|
||||
if (i > 0) {
|
||||
List<FileStorageDto> fileList = bean.getFileList();
|
||||
fileList.forEach(item -> {
|
||||
item.setSourceId(bean.getId());
|
||||
item.setCreateUser(bean.getCreateUserId());
|
||||
item.setCreateUserName(bean.getCreateUserName());
|
||||
});
|
||||
//照片入库
|
||||
if (!bean.getFileList().isEmpty()) {
|
||||
int j = dao.insertImgPhoto(bean.getFileList());
|
||||
}
|
||||
//存入总库 TODO
|
||||
|
||||
return ServerResponse.createSuccess("新增成功");
|
||||
}
|
||||
return ServerResponse.createErroe("新增失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SafetyViolationVo getSafetyViolationById(Long id) {
|
||||
SafetyViolationVo bean = dao.getSafetyViolationById(id);
|
||||
//照片查询
|
||||
FileStorageDto fileStorageDto = new FileStorageDto();
|
||||
fileStorageDto.setSourceId(id);
|
||||
fileStorageDto.setSourceType("1");
|
||||
bean.setVioPhotoList(dao.getImgPhotoList(fileStorageDto));
|
||||
fileStorageDto.setSourceType("2");
|
||||
bean.setRectPhotoList(dao.getImgPhotoList(fileStorageDto));
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse updateSafetyViolationById(SafetyViolationDto bean) {
|
||||
LoginUser loginUser = UserUtil.getLoginUser();
|
||||
bean.setUpdateUserId(loginUser.getId());
|
||||
bean.setUpdateUserName(loginUser.getUsername());
|
||||
int num = dao.updateSafetyViolationById(bean);
|
||||
if (num > 0) {
|
||||
List<FileStorageDto> fileList = bean.getFileList();
|
||||
List<FileStorageDto> delFileList = bean.getDelFileList();
|
||||
fileList.forEach(item -> {
|
||||
item.setSourceId(bean.getId());
|
||||
item.setCreateUser(bean.getUpdateUserId());
|
||||
item.setCreateUserName(bean.getUpdateUserName());
|
||||
});
|
||||
delFileList.forEach(item -> {
|
||||
item.setSourceId(bean.getId());
|
||||
item.setCreateUser(bean.getUpdateUserId());
|
||||
item.setCreateUserName(bean.getUpdateUserName());
|
||||
});
|
||||
//照片入库
|
||||
if (!bean.getFileList().isEmpty()) {
|
||||
int j = dao.insertImgPhoto(bean.getFileList());
|
||||
}
|
||||
//照片删除
|
||||
if (!bean.getDelFileList().isEmpty()) {
|
||||
int j = dao.delImgPhoto(bean.getDelFileList());
|
||||
}
|
||||
//总库修改 TODO
|
||||
|
||||
return ServerResponse.createSuccess("修改成功");
|
||||
} else {
|
||||
|
||||
return ServerResponse.createErroe("修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
package com.bonus.imgTool.imgUpload.vo;
|
||||
|
||||
import com.bonus.imgTool.base.entity.PageEntity;
|
||||
import com.bonus.imgTool.system.vo.dto.FileStorageDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SafetyViolations
|
||||
*/
|
||||
@Data
|
||||
public class SafetyViolationVo extends PageEntity {
|
||||
/**
|
||||
* 检查人
|
||||
*/
|
||||
private String checkUserName;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUserId;
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
private String createUserName;
|
||||
/**
|
||||
* 数据来源 1.web 2.app
|
||||
*/
|
||||
private String dataSource;
|
||||
/**
|
||||
* 工序id
|
||||
*/
|
||||
private Long gxId;
|
||||
/**
|
||||
* 工序名称
|
||||
*/
|
||||
private String gxName;
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private long id;
|
||||
/**
|
||||
* 是否可用 1.可用 0.不可用
|
||||
*/
|
||||
private String isActive;
|
||||
/**
|
||||
* 专业id
|
||||
*/
|
||||
private Long majorId;
|
||||
/**
|
||||
* 专业名称
|
||||
*/
|
||||
private String majorName;
|
||||
/**
|
||||
* 工程id
|
||||
*/
|
||||
private Long proId;
|
||||
/**
|
||||
* 工程名称
|
||||
*/
|
||||
private String proName;
|
||||
/**
|
||||
* 整改期限
|
||||
*/
|
||||
private String rectDate;
|
||||
/**
|
||||
* 整改说明
|
||||
*/
|
||||
private String rectDesc;
|
||||
/**
|
||||
* 整改状态 0.待整改 1.已整改
|
||||
*/
|
||||
private String rectStatus;
|
||||
/**
|
||||
* 整改时间
|
||||
*/
|
||||
private String rectTime;
|
||||
/**
|
||||
* 整改人
|
||||
*/
|
||||
private String rectUserName;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private Long updateUserId;
|
||||
/**
|
||||
* 修改人姓名
|
||||
*/
|
||||
private String updateUserName;
|
||||
/**
|
||||
* 违章时间
|
||||
*/
|
||||
private String vioDate;
|
||||
/**
|
||||
* 违章描述
|
||||
*/
|
||||
private String vioDesc;
|
||||
/**
|
||||
* 违章地点
|
||||
*/
|
||||
private String vioPlace;
|
||||
/**
|
||||
* 违章照片数量
|
||||
*/
|
||||
private String vioPhotoNum;
|
||||
/**
|
||||
* 整改照片数量
|
||||
*/
|
||||
private String rectPhotoNum;
|
||||
|
||||
/**
|
||||
* 违章照片
|
||||
*/
|
||||
private List<FileStorageDto> vioPhotoList;
|
||||
/**
|
||||
* 整改照片
|
||||
*/
|
||||
private List<FileStorageDto> rectPhotoList;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package com.bonus.imgTool.imgUpload.vo.dto;
|
||||
|
||||
import com.bonus.imgTool.base.entity.PageEntity;
|
||||
import com.bonus.imgTool.system.vo.dto.FileStorageDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SafetyViolations
|
||||
*/
|
||||
@Data
|
||||
public class SafetyViolationDto extends PageEntity {
|
||||
/**
|
||||
* 检查人
|
||||
*/
|
||||
private String checkUserName;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUserId;
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
private String createUserName;
|
||||
/**
|
||||
* 数据来源 1.web 2.app
|
||||
*/
|
||||
private String dataSource;
|
||||
/**
|
||||
* 工序id
|
||||
*/
|
||||
private Long gxId;
|
||||
/**
|
||||
* 工序名称
|
||||
*/
|
||||
private String gxName;
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 是否可用 1.可用 0.不可用
|
||||
*/
|
||||
private String isActive;
|
||||
/**
|
||||
* 专业id
|
||||
*/
|
||||
private Long majorId;
|
||||
/**
|
||||
* 专业名称
|
||||
*/
|
||||
private String majorName;
|
||||
/**
|
||||
* 工程id
|
||||
*/
|
||||
private Long proId;
|
||||
/**
|
||||
* 工程名称
|
||||
*/
|
||||
private String proName;
|
||||
/**
|
||||
* 整改期限
|
||||
*/
|
||||
private String rectDate;
|
||||
/**
|
||||
* 整改说明
|
||||
*/
|
||||
private String rectDesc;
|
||||
/**
|
||||
* 整改状态 0.待整改 1.已整改
|
||||
*/
|
||||
private String rectStatus;
|
||||
/**
|
||||
* 整改时间
|
||||
*/
|
||||
private String rectTime;
|
||||
/**
|
||||
* 整改人
|
||||
*/
|
||||
private String rectUserName;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private Long updateUserId;
|
||||
/**
|
||||
* 修改人姓名
|
||||
*/
|
||||
private String updateUserName;
|
||||
/**
|
||||
* 违章时间
|
||||
*/
|
||||
private String vioDate;
|
||||
/**
|
||||
* 违章描述
|
||||
*/
|
||||
private String vioDesc;
|
||||
/**
|
||||
* 违章地点
|
||||
*/
|
||||
private String vioPlace;
|
||||
|
||||
|
||||
/**
|
||||
* 文件集合
|
||||
*/
|
||||
private List<FileStorageDto> fileList;
|
||||
|
||||
/**
|
||||
* 删除文件集合
|
||||
*/
|
||||
private List<FileStorageDto> delFileList;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package com.bonus.imgTool.system.controller;
|
||||
|
||||
import com.bonus.imgTool.utils.DateTimeHelper;
|
||||
import com.bonus.imgTool.utils.IDUtils;
|
||||
import com.bonus.imgTool.utils.SystemUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bonus.imgTool.system.vo.dto.FileStorageDto;
|
||||
import com.bonus.imgTool.utils.*;
|
||||
import com.bonus.imgTool.webResult.AjaxResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -12,11 +12,17 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @className:FileUploadController
|
||||
|
|
@ -26,38 +32,94 @@ import java.util.Map;
|
|||
* @description:文件上传
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/common/file/")
|
||||
@RequestMapping("/sys/file/")
|
||||
@Slf4j
|
||||
public class FileUploadController {
|
||||
|
||||
private static final Set<String> imageExtensions = new HashSet<>(Arrays.asList(".jpg", ".jpeg", ".png", ".gif"));
|
||||
private static long desFileSize = 500; // 目标大小,单位kb
|
||||
|
||||
@ApiOperation(value = "文件上传")
|
||||
@PostMapping("uploadFile")
|
||||
public AjaxResult appUploadFile(@RequestParam(value = "files") MultipartFile[] files) {
|
||||
public AjaxResult appUploadFile(@RequestParam(value = "files") MultipartFile[] files,@RequestParam(value = "params")String params) {
|
||||
try {
|
||||
List<Map<String,Object>> fileList = new ArrayList<>();
|
||||
for (MultipartFile file : files) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
String suffix = IDUtils.getSuffix(fileName);
|
||||
String fileMbSize = IDUtils.getFileMbSize(file.getSize());
|
||||
String path = File.separator + DateTimeHelper.getNowYMD() + File.separator + IDUtils.createID() + suffix;
|
||||
String newPath = SystemUtils.getUploadPath() + path;
|
||||
File uploadFile = new File(newPath);
|
||||
//生成文件夹
|
||||
if (!uploadFile.getParentFile().exists()) {
|
||||
uploadFile.getParentFile().mkdirs();
|
||||
}
|
||||
// 存入临时文件
|
||||
file.transferTo(uploadFile);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("filePath", path);
|
||||
map.put("fileName", fileName);
|
||||
map.put("fileSize", fileMbSize);
|
||||
fileList.add(map);
|
||||
if (files.length == 0) {
|
||||
return AjaxResult.error("未接收到文件");
|
||||
}
|
||||
return AjaxResult.success("上传成功", fileList);
|
||||
FileStorageDto fileStorageDto = FastJsonHelper.jsonStrToBean(params, FileStorageDto.class);
|
||||
String uploadType = fileStorageDto.getUploadType();
|
||||
String sourceType = fileStorageDto.getSourceType();
|
||||
String sourceTypeName = fileStorageDto.getSourceTypeName();
|
||||
List<FileStorageDto> fileInfoList = new ArrayList<>();
|
||||
for (MultipartFile file : files) {
|
||||
if (file.isEmpty()) {
|
||||
//忽略空文件
|
||||
continue;
|
||||
}
|
||||
//获取文件名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String fileName;
|
||||
String fileSuffix;
|
||||
if (originalFilename != null && originalFilename.contains(".")) {
|
||||
fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")); // 获取文件名
|
||||
fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(".")); // 获取后缀
|
||||
} else {
|
||||
// 如果没有".",则表示没有后缀,整个字符串视为文件名
|
||||
fileName = originalFilename;
|
||||
fileSuffix = ""; // 或者根据实际情况设置默认值
|
||||
}
|
||||
//获取文件大小
|
||||
Double fileMbSize = IDUtils.getFileMbSizeToDouble(file.getSize());
|
||||
// 创建年月/日文件夹
|
||||
SimpleDateFormat yearMonthFormat = new SimpleDateFormat("yyyyMM");
|
||||
SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
|
||||
String yearMonthPath = yearMonthFormat.format(new Date());
|
||||
String day = dayFormat.format(new Date());
|
||||
//文件新名字
|
||||
String path = IDUtils.createID() + fileSuffix;
|
||||
//文件存储新路径
|
||||
String savePath = SystemUtils.getUploadPath() + "/" + yearMonthPath + "/" + day;
|
||||
File uploadFile = new File(savePath);
|
||||
//生成文件夹
|
||||
if (!uploadFile.exists()) {
|
||||
uploadFile.mkdirs();
|
||||
}
|
||||
// 存入临时文件(方法1)
|
||||
// file.transferTo(uploadFile);
|
||||
// 保存文件(方法2)
|
||||
byte[] bytes = file.getBytes();
|
||||
Path writePath = Paths.get(savePath, path);
|
||||
Files.write(writePath, bytes);
|
||||
FileStorageDto fileDto = new FileStorageDto();
|
||||
fileDto.setFileType("2");
|
||||
// 如果是图片,生成压缩图
|
||||
if (imageExtensions.contains(fileSuffix)) {
|
||||
String compressedPath = SystemUtils.getUploadPath() + "/compressed/" + yearMonthPath + "/" + day;
|
||||
File compressedFile = new File(compressedPath);
|
||||
//生成文件夹
|
||||
if (!compressedFile.exists()) {
|
||||
compressedFile.mkdirs();
|
||||
}
|
||||
Path compressedFilePath = Paths.get(compressedPath, "compressed_" + path);
|
||||
byte[] compressedImageBytes = PicUtils.compressPicForScale(file.getBytes(), desFileSize);
|
||||
Files.write(compressedFilePath, compressedImageBytes);
|
||||
fileDto.setCompressFilePath(compressedPath + "/compressed_" + path);
|
||||
fileDto.setFileType("1");
|
||||
}
|
||||
fileDto.setFileName(fileName);
|
||||
fileDto.setFileSuffix(fileSuffix);
|
||||
fileDto.setFileSize(fileMbSize);
|
||||
fileDto.setOriginalFilePath(savePath+"/"+path);
|
||||
fileDto.setUploadType(uploadType);
|
||||
fileDto.setSourceType(sourceType);
|
||||
fileDto.setSourceTypeName(sourceTypeName);
|
||||
fileInfoList.add(fileDto);
|
||||
}
|
||||
return AjaxResult.success("上传成功", fileInfoList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
return AjaxResult.error("文件上传异常");
|
||||
return AjaxResult.error("文件上传异常",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
package com.bonus.imgTool.system.vo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @className:FileStorageDto
|
||||
* @author:fly
|
||||
* @version:1.0
|
||||
* @description:文件存储字段
|
||||
*/
|
||||
@Data
|
||||
public class FileStorageDto {
|
||||
|
||||
/**
|
||||
* 文件ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文件名称(不含后缀)
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件后缀名(如:.jpg, .png)
|
||||
*/
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 文件大小( Mb单位)
|
||||
*/
|
||||
private Double fileSize;
|
||||
|
||||
/**
|
||||
* 原图图片路径
|
||||
*/
|
||||
private String originalFilePath;
|
||||
|
||||
/**
|
||||
* 压缩文件路径
|
||||
*/
|
||||
private String compressFilePath;
|
||||
|
||||
/**
|
||||
* 水印文件路径
|
||||
*/
|
||||
private String watermarkFilePath;
|
||||
|
||||
/**
|
||||
* 文件类型(文件类型 1.图片 2.文件)
|
||||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
* 资源id(安全违章ID、质量检查ID、3.安全措施落实ID、协调照片ID、重要事项及宣传照片ID)
|
||||
*/
|
||||
private Long sourceId;
|
||||
|
||||
/**
|
||||
* 上传类型 1.安全违章、2.质量检查、3.安全措施落实、4.协调照片、5.重要事项及宣传照片
|
||||
*/
|
||||
private String uploadType;
|
||||
|
||||
/**
|
||||
* 照片类型阶段id
|
||||
*/
|
||||
private String sourceType;
|
||||
|
||||
/**
|
||||
* 照片类型阶段名称
|
||||
*/
|
||||
private String sourceTypeName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 创建用户ID
|
||||
*/
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 创建用户名
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 是否激活(1: 是, 0: 否)
|
||||
*/
|
||||
private Integer isActive;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package com.bonus.imgTool.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fly
|
||||
* @version 1
|
||||
* json与jsonArray所有自定义bean嵌套的相关操作
|
||||
* 将fastjson2简单的封装和添加注释而成
|
||||
* <dependency>
|
||||
* <groupId>com.alibaba.fastjson</groupId>
|
||||
* <artifactId>fastjson2</artifactId>
|
||||
* <version>2.0.30</version>
|
||||
* </dependency>
|
||||
* 修改时间:2021-09-30
|
||||
*/
|
||||
public class FastJsonHelper {
|
||||
|
||||
/**
|
||||
* 将任意bean转换成json字符串
|
||||
* fastjson2
|
||||
* @param bean
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> String beanToJsonStr(T bean) {
|
||||
return JSON.toJSONString(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个json字符串转换成bean对象
|
||||
* fastjson2
|
||||
* @param str
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T jsonStrToBean(String str, Class<T> clazz) {
|
||||
return JSON.parseObject(str, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个jsonObj转换成bean对象
|
||||
* fastjson2
|
||||
* @param jsonObj
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T jsonObjToBean(JSONObject jsonObj, Class<T> clazz) {
|
||||
return jsonObj.toJavaObject(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个bean对象转换成jsonObj
|
||||
* fastjson2
|
||||
* @param bean
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> JSONObject beanToJsonObj(T bean) {
|
||||
return (JSONObject) JSON.toJSON(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个jsonStr转换成jsonObj
|
||||
* fastjson2
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject jsonStrToJsonObj(String str) {
|
||||
return JSON.parseObject(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个jsonObj转换成jsonStr
|
||||
* fastjson2
|
||||
* @param jsonObj
|
||||
* @return
|
||||
*/
|
||||
public static String jsonObjToJsonStr(JSONObject jsonObj) {
|
||||
return jsonObj.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个beanList对象转换成jsonArrStr
|
||||
* fastjson2
|
||||
* @param beanList
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> String beanListToJsonArrStr(List<T> beanList) {
|
||||
JSONArray jsonArray = (JSONArray) JSON.toJSON(beanList);
|
||||
return jsonArray.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个jsonArrStr转换成beanList对象
|
||||
* fastjson2
|
||||
* @param jsonArrStr
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> jsonArrStrToBeanList(String jsonArrStr, Class<T> clazz) {
|
||||
return JSON.parseArray(jsonArrStr, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个JsonArr转换成JsonArrStr
|
||||
* fastjson2
|
||||
* @param jsonArr
|
||||
* @return
|
||||
*/
|
||||
public static String jsonArrToJsonArrStr(JSONArray jsonArr) {
|
||||
return jsonArr.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个JsonArrStr文本转换成JsonArr
|
||||
* fastjson2
|
||||
* @param jsonArrStr
|
||||
* @return
|
||||
*/
|
||||
public static JSONArray jsonArrStrToJsonArr(String jsonArrStr) {
|
||||
return JSON.parseArray(jsonArrStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个JsonArr转换成beanList
|
||||
* fastjson2
|
||||
* @param jsonArr
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> jsonArrToBeanList(JSONArray jsonArr, Class<T> clazz) {
|
||||
return jsonArr.toJavaList(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个beanList文本转换成JsonArr
|
||||
* fastjson2
|
||||
* @param beanList
|
||||
* @return
|
||||
*/
|
||||
public static <T> JSONArray beanListToJsonArr(List<T> beanList) {
|
||||
return (JSONArray) JSON.toJSON(beanList);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,4 +40,12 @@ public class IDUtils {
|
|||
return String.format("%.2f", mb);
|
||||
}
|
||||
|
||||
public static Double getFileMbSizeToDouble(long bytes){
|
||||
double mb = bytes / (1024.0 * 1024.0);
|
||||
System.out.println("文件大小: " + String.format("%.2f MB", mb));
|
||||
double scale = Math.pow(10, 2); // 想保留几位小数,这里的2就是保留两位小数
|
||||
double result = Math.round(mb * scale) / scale;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ zhly.aq.file.html=login.html,index.html,pages/user/updateMyself.html,pages/user/
|
|||
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mybatis.configuration.mapUnderscoreToCamelCase=true
|
||||
|
||||
file.windwos.upload_path=L:/imgTool/files/
|
||||
file.linux.upload_path=L:/imgTool/files/
|
||||
file.windwos.upload_path=D:/files/imgTool
|
||||
file.linux.upload_path=/data/imgTool
|
||||
|
||||
#????
|
||||
quartz.scan=false
|
||||
|
|
|
|||
|
|
@ -0,0 +1,235 @@
|
|||
<?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.bonus.imgTool.imgUpload.dao.SafetyViolationDao">
|
||||
|
||||
<insert id="insertSafetyViolation" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
|
||||
INSERT INTO tb_safety_violations
|
||||
(
|
||||
pro_id,
|
||||
pro_name,
|
||||
major_id,
|
||||
major_name,
|
||||
gx_id,
|
||||
gx_name,
|
||||
check_user_name,
|
||||
vio_date,
|
||||
vio_place,
|
||||
vio_desc,
|
||||
rect_date,
|
||||
rect_user_name,
|
||||
rect_time,
|
||||
rect_desc,
|
||||
rect_status,
|
||||
data_source,
|
||||
create_user_id,
|
||||
create_user_name,
|
||||
create_time
|
||||
)values (
|
||||
#{proId},
|
||||
#{proName},
|
||||
#{majorId},
|
||||
#{majorName},
|
||||
#{gxId},
|
||||
#{gxName},
|
||||
#{checkUserName},
|
||||
#{vioDate},
|
||||
#{vioPlace},
|
||||
#{vioDesc},
|
||||
#{rectDate},
|
||||
#{rectUserName},
|
||||
#{rectTime},
|
||||
#{rectDesc},
|
||||
#{rectStatus},
|
||||
#{dataSource},
|
||||
#{createUserId},
|
||||
#{createUserName},
|
||||
#{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<insert id="insertImgPhoto">
|
||||
INSERT INTO sys_file_resource
|
||||
(
|
||||
file_name,
|
||||
file_suffix,
|
||||
file_size,
|
||||
original_file_path,
|
||||
compress_file_path,
|
||||
file_type,
|
||||
source_id,
|
||||
upload_type,
|
||||
source_type,
|
||||
source_type_name,
|
||||
create_user,
|
||||
create_user_name
|
||||
)values
|
||||
<foreach collection="fileList" item="item" separator=",">
|
||||
(
|
||||
#{item.fileName},
|
||||
#{item.fileSuffix},
|
||||
#{item.fileSize},
|
||||
#{item.originalFilePath},
|
||||
#{item.compressFilePath},
|
||||
#{item.fileType},
|
||||
#{item.sourceId},
|
||||
#{item.uploadType},
|
||||
#{item.sourceType},
|
||||
#{item.sourceTypeName},
|
||||
#{item.createUser},
|
||||
#{item.createUserName}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateSafetyViolationById">
|
||||
UPDATE tb_safety_violations
|
||||
<set>
|
||||
<if test="proId != null">
|
||||
pro_id = #{proId},
|
||||
</if>
|
||||
<if test="proName != null">
|
||||
pro_name = #{proName},
|
||||
</if>
|
||||
<if test="majorId != null">
|
||||
major_id = #{majorId},
|
||||
</if>
|
||||
<if test="majorName != null">
|
||||
major_name = #{majorName},
|
||||
</if>
|
||||
<if test="gxId != null">
|
||||
gx_id = #{gxId},
|
||||
</if>
|
||||
<if test="gxName != null">
|
||||
gx_name = #{gxName},
|
||||
</if>
|
||||
<if test="checkUserName != null">
|
||||
check_user_name = #{checkUserName},
|
||||
</if>
|
||||
<if test="vioDate != null">
|
||||
vio_date = #{vioDate},
|
||||
</if>
|
||||
<if test="vioPlace != null">
|
||||
vio_place = #{vioPlace},
|
||||
</if>
|
||||
<if test="vioDesc != null">
|
||||
vio_desc = #{vioDesc},
|
||||
</if>
|
||||
<if test="rectDate != null">
|
||||
rect_date = #{rectDate},
|
||||
</if>
|
||||
<if test="rectUserName != null">
|
||||
rect_user_name = #{rectUserName},
|
||||
</if>
|
||||
<if test="rectTime != null">
|
||||
rect_time = #{rectTime},
|
||||
</if>
|
||||
<if test="rectDesc != null">
|
||||
rect_desc = #{rectDesc},
|
||||
</if>
|
||||
<if test="rectStatus != null">
|
||||
rect_status = #{rectStatus},
|
||||
</if>
|
||||
<if test="dataSource != null">
|
||||
data_source = #{dataSource},
|
||||
</if>
|
||||
<if test="updateUserId != null">
|
||||
update_user_id = #{updateUserId},
|
||||
</if>
|
||||
<if test="updateUserName != null">
|
||||
update_user_name = #{updateUserName}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<delete id="delImgPhoto">
|
||||
update sys_file_resource set is_active = '0'
|
||||
WHERE id IN
|
||||
<foreach collection="delFileList" item="item" separator=",">
|
||||
#{item.id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
<select id="getList" resultType="com.bonus.imgTool.imgUpload.vo.SafetyViolationVo">
|
||||
SELECT
|
||||
tsv.id,
|
||||
tsv.pro_id,
|
||||
tsv.pro_name,
|
||||
tsv.major_id,
|
||||
tsv.major_name,
|
||||
tsv.gx_id,
|
||||
tsv.gx_name,
|
||||
tsv.check_user_name,
|
||||
tsv.vio_date,
|
||||
tsv.vio_place,
|
||||
tsv.vio_desc,
|
||||
tsv.rect_date,
|
||||
tsv.rect_user_name,
|
||||
tsv.rect_time,
|
||||
tsv.rect_desc,
|
||||
tsv.rect_status,
|
||||
tsv.data_source,
|
||||
count(DISTINCT sfr.id) as vioPhotoNum,
|
||||
count(DISTINCT sfr2.id) as rectPhotoNum
|
||||
FROM
|
||||
tb_safety_violations tsv
|
||||
LEFT JOIN sys_file_resource sfr ON sfr.source_id = tsv.id
|
||||
AND sfr.source_type = '1'
|
||||
LEFT JOIN sys_file_resource sfr2 ON sfr2.source_id = tsv.id
|
||||
AND sfr2.source_type = '2'
|
||||
<where>
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
and locate(#{keyWord},pro_name)
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY tsv.id
|
||||
</select>
|
||||
<select id="getSafetyViolationById" resultType="com.bonus.imgTool.imgUpload.vo.SafetyViolationVo">
|
||||
SELECT
|
||||
tsv.id,
|
||||
tsv.pro_id,
|
||||
tsv.pro_name,
|
||||
tsv.major_id,
|
||||
tsv.major_name,
|
||||
tsv.gx_id,
|
||||
tsv.gx_name,
|
||||
tsv.check_user_name,
|
||||
tsv.vio_date,
|
||||
tsv.vio_place,
|
||||
tsv.vio_desc,
|
||||
tsv.rect_date,
|
||||
tsv.rect_user_name,
|
||||
tsv.rect_time,
|
||||
tsv.rect_desc,
|
||||
tsv.rect_status,
|
||||
tsv.data_source
|
||||
FROM
|
||||
tb_safety_violations tsv
|
||||
WHERE tsv.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getImgPhotoList" resultType="com.bonus.imgTool.system.vo.dto.FileStorageDto">
|
||||
SELECT
|
||||
sfr.id,
|
||||
sfr.file_name,
|
||||
sfr.file_suffix,
|
||||
sfr.file_size,
|
||||
sfr.original_file_path,
|
||||
sfr.compress_file_path,
|
||||
sfr.watermark_file_path,
|
||||
sfr.file_type,
|
||||
sfr.source_id,
|
||||
sfr.upload_type,
|
||||
sfr.source_type,
|
||||
sfr.source_type_name,
|
||||
sfr.create_user,
|
||||
sfr.create_user_name
|
||||
FROM
|
||||
sys_file_resource sfr
|
||||
WHERE sfr.source_id = #{sourceId}
|
||||
AND sfr.source_type = #{sourceType}
|
||||
And sfr.is_active= '1'
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue