Browse Source

Merge branch 'leng_dev' of https://gitee.ltd/pigx/pigx into leng_dev_copy

萌萌哒Sakura酱 6 years ago
parent
commit
304d4897c9

+ 1 - 0
doc/md/modules.md

@@ -8,6 +8,7 @@ pigx
 ├    ├── pigx-common-data -- 数据相关
 ├    ├── pigx-common-job -- 定时任务
 ├    ├── pigx-common-log -- 日志服务
+├    ├── pigx-common-minio -- 文件系统
 ├    └── pigx-common-security -- 安全工具类
 ├    └── pigx-common-swagger -- Swagger Api文档生成
 ├    └── pigx-common-transaction -- 分布式事务工具包

+ 7 - 2
pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java

@@ -80,9 +80,14 @@ public interface CommonConstants {
 	/**
 	 * 成功标记
 	 */
-	Integer SUCCESS=0;
+	Integer SUCCESS = 0;
 	/**
 	 * 失败标记
 	 */
-	Integer FAIL=1;
+	Integer FAIL = 1;
+
+	/**
+	 * 默认存储bucket
+	 */
+	String BUCKET_NAME = "lengleng";
 }

+ 7 - 0
pigx-config/src/main/resources/config/pigx-upms-biz-dev.yml

@@ -33,6 +33,13 @@ swagger:
         description: 'read all'
       - scope: 'write'
         description: 'access all'
+
+# 文件系统
+minio:
+  url: http://139.224.200.249:9090
+  access-key: lengleng
+  secret-key: lengleng
+
 # Logger Config
 logging:
   level:

+ 6 - 0
pigx-upms/pigx-upms-biz/pom.xml

@@ -62,6 +62,12 @@
 			<artifactId>pigx-common-swagger</artifactId>
 			<version>2.0.0</version>
 		</dependency>
+		<!--文件系统-->
+		<dependency>
+			<groupId>com.pig4cloud</groupId>
+			<artifactId>pigx-common-minio</artifactId>
+			<version>2.0.0</version>
+		</dependency>
 		<!--eureka 客户端-->
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>

+ 96 - 0
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/FileController.java

@@ -0,0 +1,96 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.admin.controller;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.pig4cloud.common.minio.service.MinioTemplate;
+import com.pig4cloud.pigx.common.core.constant.CommonConstants;
+import com.pig4cloud.pigx.common.core.util.R;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author lengleng
+ * @date 2018-12-30
+ * <p>
+ * 文件管理
+ */
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/file")
+public class FileController {
+	private final MinioTemplate minioTemplate;
+
+	/**
+	 * 上传文件
+	 *
+	 * @param file 资源
+	 * @return R(bucketName, filename)
+	 */
+	@PostMapping("/upload")
+	public R upload(@RequestParam("file") MultipartFile file) {
+		String originalFilename = file.getOriginalFilename();
+		String newName = RandomUtil.randomString(16) + originalFilename;
+
+		Map<String, String> resultMap = new HashMap<>(4);
+		resultMap.put("bucketName", CommonConstants.BUCKET_NAME);
+		resultMap.put("fileName", newName);
+
+		try {
+			minioTemplate.putObject(CommonConstants.BUCKET_NAME, newName, file.getInputStream());
+		} catch (Exception e) {
+			log.error("上传失败", e);
+			return R.builder().code(CommonConstants.FAIL)
+					.msg(e.getLocalizedMessage()).build();
+		}
+		return R.builder().data(resultMap).build();
+	}
+
+	/**
+	 * 获取文件
+	 *
+	 * @param fileName 文件空间/名称
+	 * @param response
+	 * @return
+	 */
+	@GetMapping("/{fileName}")
+	public R file(@PathVariable String fileName, HttpServletResponse response) {
+		String[] nameArray = StrUtil.split(fileName, StrUtil.DASHED);
+
+		try (InputStream inputStream = minioTemplate.getObject(nameArray[0], nameArray[1])) {
+			response.setContentType("application/octet-stream; charset=UTF-8");
+			IoUtil.copy(inputStream, response.getOutputStream());
+		} catch (Exception e) {
+			log.error("文件读取异常", e);
+			return R.builder().code(CommonConstants.FAIL)
+					.msg(e.getLocalizedMessage()).build();
+		}
+
+		return R.builder().build();
+	}
+}

+ 1 - 4
pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm

@@ -16,8 +16,7 @@
  */
 package ${package}.${moduleName}.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.pigx.common.core.util.R;
 import com.pig4cloud.pigx.common.log.annotation.SysLog;
@@ -26,8 +25,6 @@ import ${package}.${moduleName}.service.${className}Service;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Map;
-
 
 /**
  * ${comments}

+ 1 - 1
pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm

@@ -34,8 +34,8 @@ import java.time.LocalDateTime;
  * @date ${datetime}
  */
 @Data
-@EqualsAndHashCode(callSuper = true)
 @TableName("${tableName}")
+@EqualsAndHashCode(callSuper = true)
 public class ${className} extends Model<${className}> {
 private static final long serialVersionUID = 1L;
 

+ 0 - 2
pigx-visual/pigx-codegen/src/main/resources/template/Service.java.vm

@@ -16,8 +16,6 @@
  */
 package ${package}.${moduleName}.service;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import ${package}.${moduleName}.entity.${className};
 

+ 1 - 2
pigx-visual/pigx-codegen/src/main/resources/template/ServiceImpl.java.vm

@@ -16,10 +16,9 @@
  */
 package ${package}.${moduleName}.service.impl;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import ${package}.${moduleName}.entity.${className};
+import ${package}.${moduleName}.mapper.${className}Mapper;
 import ${package}.${moduleName}.service.${className}Service;
 import org.springframework.stereotype.Service;
 

+ 4 - 4
pigx-visual/pigx-codegen/src/main/resources/template/menu.sql.vm

@@ -1,13 +1,13 @@
 -- 该脚本不要执行,请完善 ID 对应关系,注意层级关系 !!!!
 
 -- 菜单SQL
-insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
+insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
     values ( '父菜单ID', 'views/${moduleName}/${pathName}/index', '', '0', '${pathName}', 'icon-bangzhushouji', '菜单ID', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理');
 
 -- 菜单对应按钮SQL
-insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
+insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
     values ( '菜单ID', null, '${moduleName}_${pathName}_add', '1', null, '1', '子按钮ID1', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增');
-insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
+insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
     values ( '菜单ID', null, '${moduleName}_${pathName}_edit', '1', null, '1', '子按钮ID2', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改');
-insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
+insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
     values ( '菜单ID', null, '${moduleName}_${pathName}_del', '1', null, '1', '子按钮ID3', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除');