diff --git a/pom.xml b/pom.xml index 9d765b5..ede90f2 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,12 @@ mybatis-plus-boot-starter ${mybatis-plus.version} + + + com.baomidou + mybatis-plus-generator + ${mybatis-plus.version} + mysql mysql-connector-java diff --git a/src/main/java/com/huoran/iasf/controller/CaptchaController.java b/src/main/java/com/huoran/iasf/controller/CaptchaController.java index b6b4a16..02d97a7 100644 --- a/src/main/java/com/huoran/iasf/controller/CaptchaController.java +++ b/src/main/java/com/huoran/iasf/controller/CaptchaController.java @@ -25,7 +25,7 @@ import java.io.IOException; * @version V1.0 * @date 2022年7月28日 */ -@Api(tags = "验证码相关") +@Api(tags = "登录验证码") @RestController @Slf4j @RequestMapping("/sys") diff --git a/src/main/java/com/huoran/iasf/controller/DeptController.java b/src/main/java/com/huoran/iasf/controller/DeptController.java index eaff5e8..900251b 100644 --- a/src/main/java/com/huoran/iasf/controller/DeptController.java +++ b/src/main/java/com/huoran/iasf/controller/DeptController.java @@ -24,7 +24,7 @@ import java.util.List; */ @RequestMapping("/sys") @RestController -@Api(tags = "组织模块-机构管理") +@Api(tags = "部门管理") public class DeptController { @Resource private DeptService deptService; diff --git a/src/main/java/com/huoran/iasf/controller/PermissionController.java b/src/main/java/com/huoran/iasf/controller/PermissionController.java index dace6ff..94f29ed 100644 --- a/src/main/java/com/huoran/iasf/controller/PermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/PermissionController.java @@ -25,7 +25,7 @@ import javax.validation.Valid; */ @RequestMapping("/sys") @RestController -@Api(tags = "组织模块-菜单权限管理") +@Api(tags = "菜单权限管理") public class PermissionController { @Resource diff --git a/src/main/java/com/huoran/iasf/controller/RoleController.java b/src/main/java/com/huoran/iasf/controller/RoleController.java index 19b0a49..895c30e 100644 --- a/src/main/java/com/huoran/iasf/controller/RoleController.java +++ b/src/main/java/com/huoran/iasf/controller/RoleController.java @@ -29,7 +29,7 @@ import java.util.List; */ @RequestMapping("/sys") @RestController -@Api(tags = "组织模块-角色管理") +@Api(tags = "角色管理") public class RoleController { @Resource private RoleService roleService; diff --git a/src/main/java/com/huoran/iasf/controller/RolePermissionController.java b/src/main/java/com/huoran/iasf/controller/RolePermissionController.java index a3ad721..46d5f4e 100644 --- a/src/main/java/com/huoran/iasf/controller/RolePermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/RolePermissionController.java @@ -25,7 +25,7 @@ import javax.validation.Valid; */ @RequestMapping("/sys") @RestController -@Api(tags = "组织管理-角色和菜单关联接口") +@Api(tags = "角色菜单关联接口") public class RolePermissionController { @Resource private RolePermissionService rolePermissionService; diff --git a/src/main/java/com/huoran/iasf/controller/SysFilesController.java b/src/main/java/com/huoran/iasf/controller/SysFilesController.java index 7ccd62b..8b2f4d3 100644 --- a/src/main/java/com/huoran/iasf/controller/SysFilesController.java +++ b/src/main/java/com/huoran/iasf/controller/SysFilesController.java @@ -49,20 +49,20 @@ public class SysFilesController { @ApiOperation(value = "文件预览") @GetMapping("/preview/{id}") - public void preview(@PathVariable Integer id, HttpServletRequest req, HttpServletResponse res) { + public void preview(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) { sysFilesService.preview(id, req, res); } @ApiOperation(value = "文件下载") @GetMapping("/download/{id}") - public void download(@PathVariable Integer id, HttpServletRequest req, HttpServletResponse res) { + public void download(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) { sysFilesService.download(id, req, res); } @ApiOperation(value = "删除") @DeleteMapping("/delete") @RequiresPermissions("sysFiles:delete") - public R delete(@RequestBody @ApiParam(value = "id集合") List ids) { + public R delete(@RequestBody @ApiParam(value = "id集合") List ids) { sysFilesService.removeByIdsAndFiles(ids); return R.success(); } diff --git a/src/main/java/com/huoran/iasf/controller/UserController.java b/src/main/java/com/huoran/iasf/controller/UserController.java index 336e554..9778380 100644 --- a/src/main/java/com/huoran/iasf/controller/UserController.java +++ b/src/main/java/com/huoran/iasf/controller/UserController.java @@ -33,7 +33,7 @@ import java.util.List; * @date 2022年7月28日 */ @RestController -@Api(tags = "组织模块-用户管理") +@Api(tags = "用户管理") @RequestMapping("/sys") @Slf4j public class UserController { diff --git a/src/main/java/com/huoran/iasf/controller/UserRoleController.java b/src/main/java/com/huoran/iasf/controller/UserRoleController.java index 7225825..d4d3e1a 100644 --- a/src/main/java/com/huoran/iasf/controller/UserRoleController.java +++ b/src/main/java/com/huoran/iasf/controller/UserRoleController.java @@ -23,7 +23,7 @@ import javax.validation.Valid; */ @RequestMapping("/sys") @RestController -@Api(tags = "组织管理-用户和角色关联接口") +@Api(tags = "用户角色关联接口") public class UserRoleController { @Resource private UserRoleService userRoleService; diff --git a/src/main/java/com/huoran/iasf/entity/SysFilesEntity.java b/src/main/java/com/huoran/iasf/entity/SysFilesEntity.java index b3e6960..6090b4e 100644 --- a/src/main/java/com/huoran/iasf/entity/SysFilesEntity.java +++ b/src/main/java/com/huoran/iasf/entity/SysFilesEntity.java @@ -22,8 +22,8 @@ public class SysFilesEntity extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "主键") - @TableId(value = "id", type = IdType.AUTO) - private int id; + @TableId(value = "id") + private String id; @ApiModelProperty(value = "url地址") private String url; diff --git a/src/main/java/com/huoran/iasf/service/SysFilesService.java b/src/main/java/com/huoran/iasf/service/SysFilesService.java index 96b3172..b2d481d 100644 --- a/src/main/java/com/huoran/iasf/service/SysFilesService.java +++ b/src/main/java/com/huoran/iasf/service/SysFilesService.java @@ -21,10 +21,10 @@ public interface SysFilesService extends IService { R saveFile(MultipartFile file, FileParameters fileParameters); - void removeByIdsAndFiles(List ids); + void removeByIdsAndFiles(List ids); - void preview(Integer id, HttpServletRequest req, HttpServletResponse res); + void preview(String id, HttpServletRequest req, HttpServletResponse res); - void download(Integer id, HttpServletRequest req, HttpServletResponse res); + void download(String id, HttpServletRequest req, HttpServletResponse res); } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java index f09924f..9611d70 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java @@ -2,6 +2,7 @@ package com.huoran.iasf.service.impl; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.common.config.FileUploadProperties; import com.huoran.iasf.common.exception.BusinessException; @@ -15,6 +16,8 @@ import org.apache.commons.io.FileUtils; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; @@ -24,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.URLEncoder; import java.util.*; +import java.util.regex.Pattern; /** * 文件上传 服务类 @@ -41,6 +45,9 @@ public class SysFilesServiceImpl extends ServiceImpl resultMap = new HashMap<>(); resultMap.put("url", url); return R.success(resultMap); @@ -87,8 +96,43 @@ public class SysFilesServiceImpl extends ServiceImpl ids) { + public void removeByIdsAndFiles(List ids) { List list = this.listByIds(ids); list.forEach(entity -> { //如果之前的文件存在,删除 diff --git a/src/main/java/com/huoran/iasf/vo/req/FileParameters.java b/src/main/java/com/huoran/iasf/vo/req/FileParameters.java index c2faa85..76725b4 100644 --- a/src/main/java/com/huoran/iasf/vo/req/FileParameters.java +++ b/src/main/java/com/huoran/iasf/vo/req/FileParameters.java @@ -20,7 +20,4 @@ public class FileParameters { @ApiModelProperty(value = "引用地方",example = "某某文章") private String quote; - @ApiModelProperty(value = "文件类型",example = "图片") - private String type; - } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index e1bbb43..9ba3bf3 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -26,5 +26,5 @@ file: #文件上传目录 绝对路径 末尾请加 / path: D:/files/ #windows #path: /data/files/ #linux - #文件预览、下载的url, 末尾请勿加 / - url: http://localhost:10000/iasf/sysFiles + #文件预览url + url: :10000/iasf/sysFiles/preview/ diff --git a/src/test/java/com/company/project/CodeGenerator.java b/src/test/java/com/company/project/CodeGenerator.java new file mode 100644 index 0000000..28bac19 --- /dev/null +++ b/src/test/java/com/company/project/CodeGenerator.java @@ -0,0 +1,80 @@ +package com.company.project; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.config.DataSourceConfig; +import com.baomidou.mybatisplus.generator.config.GlobalConfig; +import com.baomidou.mybatisplus.generator.config.PackageConfig; +import com.baomidou.mybatisplus.generator.config.StrategyConfig; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import org.junit.Test; + +/** + * @Author chen + * @DATE 2021/8/10 15:42 + * @Version 1.0 + */ +public class CodeGenerator { + + @Test + public void run() { + + // 1、创建代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 2、全局配置 + GlobalConfig gc = new GlobalConfig(); + String projectPath = System.getProperty("user.dir"); + gc.setOutputDir(projectPath + "/src/main/java"); + + gc.setAuthor("cheney");//设置作者 + gc.setOpen(false); //生成后是否打开资源管理器 + gc.setFileOverride(false); //重新生成时文件是否覆盖 + gc.setServiceName("%sService"); //去掉Service接口的首字母I + gc.setIdType(IdType.AUTO); //主键策略 + gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型 + gc.setSwagger2(true);//开启Swagger2模式 + + mpg.setGlobalConfig(gc); + + // 3、数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setUrl("jdbc:mysql://139.9.47.170:3306/iasf?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8"); + dsc.setDriverName("com.mysql.cj.jdbc.Driver"); + dsc.setUsername("root"); + dsc.setPassword("HuoRan@2021"); + dsc.setDbType(DbType.MYSQL); + mpg.setDataSource(dsc); + + // 4、包配置 + PackageConfig pc = new PackageConfig(); + pc.setParent("com.huoran.iasf"); + //pc.setModuleName("occupationlab"); //模块名 + pc.setController("controller"); + pc.setEntity("entity"); + pc.setService("service"); + pc.setServiceImpl("service.impl"); + pc.setMapper("mapper"); + mpg.setPackageInfo(pc); + + // 5、策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setInclude("sys_user_group"); + strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 + strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀 + + strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略 + strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作 + + strategy.setRestControllerStyle(true); //restful api风格控制器 + strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符 + + mpg.setStrategy(strategy); + + + // 6、执行 + mpg.execute(); + } +}