jtoms 4 лет назад
Родитель
Сommit
489814e39b

+ 26 - 25
src/main/java/com/zhiqiyun/open/config/OauthInterceptor.java

@@ -105,32 +105,33 @@ public class OauthInterceptor implements HandlerInterceptor {
 
     private void saveOperateLogToRedis(Permission permission, OauthInfo oauthInfo) {
         try {
-            String requestId = ServletContext.getRequestId();
-            String requestIp = ServletContext.getRemoteIPAddress();
-            String fromSource = ServletContext.getFromSource();
-
-            String requestUrl = ServletContext.getRequest().getRequestURI();
-            String jsonParam = "";
-            if (ServletContext.isJson()) {
-                jsonParam = new RequestWrapper(ServletContext.getRequest()).getBodyString();
-            }
-
-            Map<String, String> requestParam = ServletContext.getRequestParamMap();
-
-            UserOperateLog userOperateLog = new UserOperateLog();
-            userOperateLog.setTags(permission.tags());
-            userOperateLog.setUid(oauthInfo.getId());
-            userOperateLog.setId(requestId);
-            userOperateLog.setFromSource(fromSource);
-            userOperateLog.setRequestIp(requestIp);
-            userOperateLog.setRequestUrl(requestUrl);
-            userOperateLog.setRequestParams(objectMapper.writeValueAsString(requestParam));
-            userOperateLog.setRequestData(jsonParam);
-            userOperateLog.setRequestTime(DateUtil.current());
-
-            String redisKey = String.format(RedisKeys.USER_OPERATE_LOG_TEMP, requestId);
-            this.redisTemplate.boundValueOps(redisKey).set(userOperateLog, 60, TimeUnit.SECONDS);
+            if (permission.writeLog()) {
+                String requestId = ServletContext.getRequestId();
+                String requestIp = ServletContext.getRemoteIPAddress();
+                String fromSource = ServletContext.getFromSource();
+
+                String requestUrl = ServletContext.getRequest().getRequestURI();
+                String jsonParam = "";
+                if (ServletContext.isJson()) {
+                    jsonParam = new RequestWrapper(ServletContext.getRequest()).getBodyString();
+                }
 
+                Map<String, String> requestParam = ServletContext.getRequestParamMap();
+
+                UserOperateLog userOperateLog = new UserOperateLog();
+                userOperateLog.setTags(permission.tags());
+                userOperateLog.setUid(oauthInfo.getId());
+                userOperateLog.setId(requestId);
+                userOperateLog.setFromSource(fromSource);
+                userOperateLog.setRequestIp(requestIp);
+                userOperateLog.setRequestUrl(requestUrl);
+                userOperateLog.setRequestParams(objectMapper.writeValueAsString(requestParam));
+                userOperateLog.setRequestData(jsonParam);
+                userOperateLog.setRequestTime(DateUtil.current());
+
+                String redisKey = String.format(RedisKeys.USER_OPERATE_LOG_TEMP, requestId);
+                this.redisTemplate.boundValueOps(redisKey).set(userOperateLog, 60, TimeUnit.SECONDS);
+            }
         } catch (Exception e) {
             log.error("", e);
         }

+ 9 - 0
src/main/java/com/zhiqiyun/open/core/mapper/statistics/ComplaintInfoMapper.java

@@ -0,0 +1,9 @@
+package com.zhiqiyun.open.core.mapper.statistics;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zhiqiyun.open.core.models.statistics.ComplaintInfo;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ComplaintInfoMapper extends BaseMapper<ComplaintInfo> {
+}

+ 9 - 0
src/main/java/com/zhiqiyun/open/core/mapper/statistics/UploadFileInfoMapper.java

@@ -0,0 +1,9 @@
+package com.zhiqiyun.open.core.mapper.statistics;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zhiqiyun.open.core.models.statistics.UploadFileInfo;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface UploadFileInfoMapper extends BaseMapper<UploadFileInfo> {
+}

+ 7 - 8
src/main/java/com/zhiqiyun/open/core/models/UploadResult.java

@@ -19,14 +19,6 @@ public class UploadResult implements Serializable {
 
 	private String mimeType;
 
-	public String getDomain() {
-		return domain;
-	}
-
-	public void setDomain(String domain) {
-		this.domain = domain;
-	}
-
 	private long size;
 
 	private String originalFileName;
@@ -95,4 +87,11 @@ public class UploadResult implements Serializable {
 		this.originalFileName = originalFileName;
 	}
 
+	public String getDomain() {
+		return domain;
+	}
+
+	public void setDomain(String domain) {
+		this.domain = domain;
+	}
 }

+ 16 - 0
src/main/java/com/zhiqiyun/open/core/models/statistics/ComplaintInfo.java

@@ -0,0 +1,16 @@
+package com.zhiqiyun.open.core.models.statistics;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@TableName("statistics_complaint_info")
+public class ComplaintInfo {
+    private String title;
+    private String category;
+    private String channel;
+    private String content;
+    private List<String> litpics;
+}

+ 25 - 0
src/main/java/com/zhiqiyun/open/core/models/statistics/UploadFileInfo.java

@@ -0,0 +1,25 @@
+package com.zhiqiyun.open.core.models.statistics;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@TableName("statistics_upload_file_info")
+public class UploadFileInfo {
+
+    private Long id;
+
+    private String src;
+
+    private String extension;
+
+    private String mimeType;
+
+    private long size;
+
+    private String originalFileName;
+
+    private Date createdTime;
+}

+ 7 - 0
src/main/java/com/zhiqiyun/open/core/service/ComplaintInfoService.java

@@ -0,0 +1,7 @@
+package com.zhiqiyun.open.core.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zhiqiyun.open.core.models.statistics.ComplaintInfo;
+
+public interface ComplaintInfoService extends IService<ComplaintInfo> {
+}

+ 7 - 0
src/main/java/com/zhiqiyun/open/core/service/UploadFileInfoService.java

@@ -0,0 +1,7 @@
+package com.zhiqiyun.open.core.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zhiqiyun.open.core.models.statistics.UploadFileInfo;
+
+public interface UploadFileInfoService extends IService<UploadFileInfo> {
+}

+ 11 - 0
src/main/java/com/zhiqiyun/open/core/service/impl/ComplaintInfoServiceImpl.java

@@ -0,0 +1,11 @@
+package com.zhiqiyun.open.core.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zhiqiyun.open.core.mapper.statistics.ComplaintInfoMapper;
+import com.zhiqiyun.open.core.models.statistics.ComplaintInfo;
+import com.zhiqiyun.open.core.service.ComplaintInfoService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ComplaintInfoServiceImpl extends ServiceImpl<ComplaintInfoMapper, ComplaintInfo> implements ComplaintInfoService {
+}

+ 11 - 0
src/main/java/com/zhiqiyun/open/core/service/impl/UploadFileInfoServiceImpl.java

@@ -0,0 +1,11 @@
+package com.zhiqiyun.open.core.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zhiqiyun.open.core.mapper.statistics.UploadFileInfoMapper;
+import com.zhiqiyun.open.core.models.statistics.UploadFileInfo;
+import com.zhiqiyun.open.core.service.UploadFileInfoService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper, UploadFileInfo> implements UploadFileInfoService {
+}

+ 121 - 102
src/main/java/com/zhiqiyun/open/mvc/controller/UploaderController.java

@@ -3,6 +3,9 @@ package com.zhiqiyun.open.mvc.controller;
 
 import com.zhiqiyun.open.annotation.Permission;
 import com.zhiqiyun.open.core.models.UploadResult;
+import com.zhiqiyun.open.core.models.statistics.UploadFileInfo;
+import com.zhiqiyun.open.core.service.SequenceService;
+import com.zhiqiyun.open.core.service.UploadFileInfoService;
 import com.zhiqiyun.open.exception.UploadException;
 import com.zhiqiyun.open.mvc.Result;
 import com.zhiqiyun.open.mvc.params.UploaderBase64Param;
@@ -14,8 +17,13 @@ import net.sf.jmimemagic.MagicMatch;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
@@ -30,105 +38,116 @@ import java.util.List;
 @RequestMapping
 public class UploaderController {
 
-	@Value("${uploader.max-size}")
-	private long maxSize;
-
-	@Value("${uploader.file-host}")
-	private String fileHost;
-
-	@Value("${uploader.allow-file-types}")
-	private String[] allowExtensions;
-
-	@Value("${uploader.save-path}")
-	private String savePath;
-
-
-	@Permission(tags = "上传图片")
-	@PostMapping(value = "/uploader/handle/base64File")
-	public Object handleBase64File(@RequestBody UploaderBase64Param param) throws IOException {
-
-		if (StringUtils.isBlank(param.getBase64File())) {
-			log.warn("没有添加上传文件");
-			return Result.instance("没有添加上传文件");
-		}
-		byte[] fileBuff = Base64.decodeBase64(param.getBase64File());
-
-		String originalFilename = param.getFilename();
-		if (StringUtils.isBlank(originalFilename)) {
-			originalFilename = String.format("%s.%s", DigestUtils.md5Hex(fileBuff), "png");
-		}
-
-		UploadResult uploadResult = this.handle(originalFilename, fileBuff);
-		if (uploadResult.isSuccess()) {
-			return Result.instance(Result.Code.SUCCESS).setData(uploadResult);
-		} else {
-			return Result.instance(Result.Code.MESSAGE_ERROR, uploadResult.getMessage());
-		}
-	}
-
-	public UploadResult handle(String originalFilename, byte[] fileBuff) {
-		UploadResult result = new UploadResult();
-		result.setSuccess(false);
-		result.setOriginalFileName(originalFilename);
-		try {
-			// 验证文件件大小
-			if (fileBuff.length > maxSize * 1024) {
-				throw new UploadException("上传文件大小不能超过" + (maxSize / 1024) + "M");
-			}
-
-			MagicMatch magicMatch = Magic.getMagicMatch(fileBuff);
-
-			String extension = magicMatch.getExtension();
-			String mimeType = magicMatch.getMimeType();
-
-			// 验证文件类型
-			if (extension == null) {
-				throw new UploadException("无的文件扩展名,请重新上传");
-			}
-
-			extension = extension.toLowerCase();
-			List<String> listAllowExtensions = Arrays.asList(allowExtensions);
-			if (!listAllowExtensions.contains(extension)) {
-				throw new UploadException(String.format("只能上传%s类型的文件", String.join(",", allowExtensions)));
-			}
-
-			String filePath = String.format("%s/%s", savePath, DateUtil.format("yyyy/MM/dd"));
-			File fileDir = new File(filePath);
-			if (!fileDir.exists()) {
-				boolean mkdirResult = fileDir.mkdirs();
-				if (!mkdirResult) {
-					log.warn("mkdir save file path error {}", filePath);
-					throw new UploadException("创建上传目录失败");
-				}
-			}
-			filePath = String.format("%s/%s.%s", filePath, DigestUtils.md5Hex(fileBuff), extension);
-			File file = new File(filePath);
-
-
-			try {
-				ByteArrayInputStream in = new ByteArrayInputStream(fileBuff);
-				BufferedImage bi = ImageIO.read(in);
-				Thumbnails.of(bi).size(1200, 1200).toFile(file);
-			} catch (IOException e) {
-				log.warn("upload is not image file", e);
-				throw new UploadException("只能上传图片文件");
-			}
-
-			result.setSuccess(true);
-			result.setMessage("上传文件成功");
-			result.setMimeType(mimeType);
-			// 获取服务地址和端口
-			String url = filePath.replaceFirst(this.savePath, "");
-			result.setSrc(url);
-			result.setSize(fileBuff.length);
-			result.setExtension(extension);
-			result.setId(0L);
-		} catch (UploadException e) {
-			result.setMessage(e.getMessage());
-		} catch (Exception e) {
-			log.error("upload file error", e);
-			result.setMessage("服务异常,请稍后再试");
-		}
-		return result;
-	}
+    @Value("${uploader.max-size}")
+    private long maxSize;
+
+//	@Value("${uploader.file-host}")
+//	private String fileHost;
+
+    @Value("${uploader.allow-file-types}")
+    private String[] allowExtensions;
+
+    @Value("${uploader.save-path}")
+    private String savePath;
+
+    @Autowired
+    private UploadFileInfoService uploadFileInfoService;
+
+    @Autowired
+    private SequenceService sequenceService;
+
+
+    @Permission(tags = "上传图片", writeLog = false)
+    @PostMapping(value = "/uploader/handle/base64File")
+    public Object handleBase64File(@RequestBody UploaderBase64Param param) throws IOException {
+
+        if (StringUtils.isBlank(param.getBase64File())) {
+            log.warn("没有添加上传文件");
+            return Result.instance("没有添加上传文件");
+        }
+        byte[] fileBuff = Base64.decodeBase64(param.getBase64File());
+
+        String originalFilename = param.getFilename();
+        if (StringUtils.isBlank(originalFilename)) {
+            originalFilename = String.format("%s.%s", DigestUtils.md5Hex(fileBuff), "png");
+        }
+
+        UploadResult uploadResult = this.handle(originalFilename, fileBuff);
+        if (uploadResult.isSuccess()) {
+            return Result.instance(Result.Code.SUCCESS).setData(uploadResult);
+        } else {
+            return Result.instance(Result.Code.MESSAGE_ERROR, uploadResult.getMessage());
+        }
+    }
+
+    public UploadResult handle(String originalFilename, byte[] fileBuff) {
+        UploadResult result = new UploadResult();
+        result.setSuccess(false);
+        result.setOriginalFileName(originalFilename);
+        try {
+            // 验证文件件大小
+            if (fileBuff.length > maxSize * 1024) {
+                throw new UploadException("上传文件大小不能超过" + (maxSize / 1024) + "M");
+            }
+
+            MagicMatch magicMatch = Magic.getMagicMatch(fileBuff);
+
+            String extension = magicMatch.getExtension();
+            String mimeType = magicMatch.getMimeType();
+
+            // 验证文件类型
+            if (extension == null) {
+                throw new UploadException("无的文件扩展名,请重新上传");
+            }
+
+            extension = extension.toLowerCase();
+            List<String> listAllowExtensions = Arrays.asList(allowExtensions);
+            if (!listAllowExtensions.contains(extension)) {
+                throw new UploadException(String.format("只能上传%s类型的文件", String.join(",", allowExtensions)));
+            }
+
+            String filePath = String.format("%s/%s", savePath, DateUtil.format("yyyy/MM/dd"));
+            File fileDir = new File(filePath);
+            if (!fileDir.exists()) {
+                boolean mkdirResult = fileDir.mkdirs();
+                if (!mkdirResult) {
+                    log.warn("mkdir save file path error {}", filePath);
+                    throw new UploadException("创建上传目录失败");
+                }
+            }
+            filePath = String.format("%s/%s.%s", filePath, DigestUtils.md5Hex(fileBuff), extension);
+            File file = new File(filePath);
+
+
+            try {
+                ByteArrayInputStream in = new ByteArrayInputStream(fileBuff);
+                BufferedImage bi = ImageIO.read(in);
+                Thumbnails.of(bi).size(1200, 1200).toFile(file);
+            } catch (IOException e) {
+                log.warn("upload is not image file", e);
+                throw new UploadException("只能上传图片文件");
+            }
+
+            result.setSuccess(true);
+            result.setMessage("上传文件成功");
+            result.setMimeType(mimeType);
+            // 获取服务地址和端口
+            String url = filePath.replaceFirst(this.savePath, "");
+            result.setSrc(url);
+            result.setSize(fileBuff.length);
+            result.setExtension(extension);
+            result.setId(this.sequenceService.nextId());
+
+            UploadFileInfo fileInfo = new UploadFileInfo();
+            BeanUtils.copyProperties(result, fileInfo);
+            fileInfo.setCreatedTime(DateUtil.current());
+            this.uploadFileInfoService.save(fileInfo);
+        } catch (UploadException e) {
+            result.setMessage(e.getMessage());
+        } catch (Exception e) {
+            log.error("upload file error", e);
+            result.setMessage("服务异常,请稍后再试");
+        }
+        return result;
+    }
 }

+ 13 - 0
src/main/resources/db/migration/V1.0.5__statistics.sql

@@ -4,3 +4,16 @@ VALUES (2100, 0, 'statistics', '数据统计分析'),
        (2101, 2100, 'statistics.complaint', '客诉信息管理'),
        (2102, 2100, 'statistics.file.manage', '多媒体信息管理'),
        (2103, 2100, 'statistics.gis.map.base', 'GIS地图分布');
+
+DROP TABLE IF EXISTS `statistics_upload_file_info`;
+CREATE TABLE `statistics_upload_file_info`
+(
+    `id`                 BIGINT(20) NOT NULL COMMENT 'ID',
+    `src`                VARCHAR(200) NULL DEFAULT NULL COMMENT '路径',
+    `extension`          VARCHAR(32) NULL DEFAULT NULL COMMENT '扩展名',
+    `mime_type`          VARCHAR(32) NULL DEFAULT NULL COMMENT '类型',
+    `size`               BIGINT(20) NULL DEFAULT NULL COMMENT '大小',
+    `original_file_name` VARCHAR(100) NULL DEFAULT NULL COMMENT '文件名',
+    `created_time`       DATETIME NULL DEFAULT NULL COMMENT '创建时间',
+    PRIMARY KEY (`id`)
+) COMMENT ='上传文件管理' ENGINE = InnoDB;