From f1aac4d77ceb4bfda385e1751cc14cadab67ce00 Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Thu, 11 Aug 2022 10:10:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E7=94=A8=E6=88=B7=E7=BB=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++ .../iasf/controller/CaptchaController.java | 2 +- .../iasf/controller/DeptController.java | 2 +- .../iasf/controller/PermissionController.java | 2 +- .../iasf/controller/RoleController.java | 2 +- .../controller/RolePermissionController.java | 2 +- .../iasf/controller/SysFilesController.java | 6 +- .../iasf/controller/UserController.java | 2 +- .../iasf/controller/UserRoleController.java | 2 +- .../huoran/iasf/entity/SysFilesEntity.java | 4 +- .../huoran/iasf/service/SysFilesService.java | 6 +- .../service/impl/SysFilesServiceImpl.java | 56 +++++++++++-- .../huoran/iasf/vo/req/FileParameters.java | 3 - src/main/resources/application-dev.yml | 4 +- .../com/company/project/CodeGenerator.java | 80 +++++++++++++++++++ 15 files changed, 153 insertions(+), 26 deletions(-) create mode 100644 src/test/java/com/company/project/CodeGenerator.java 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(); + } +} From dbf9b77a120684b4e26d4a4587ab404669b8df0a Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Thu, 11 Aug 2022 10:11:58 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iasf/controller/UserGroupController.java | 103 ++++++++++++++++++ .../com/huoran/iasf/entity/UserGroup.java | 52 +++++++++ .../huoran/iasf/mapper/UserGroupMapper.java | 16 +++ .../iasf/mapper/xml/UserGroupMapper.xml | 5 + .../huoran/iasf/service/UserGroupService.java | 16 +++ .../service/impl/UserGroupServiceImpl.java | 20 ++++ 6 files changed, 212 insertions(+) create mode 100644 src/main/java/com/huoran/iasf/controller/UserGroupController.java create mode 100644 src/main/java/com/huoran/iasf/entity/UserGroup.java create mode 100644 src/main/java/com/huoran/iasf/mapper/UserGroupMapper.java create mode 100644 src/main/java/com/huoran/iasf/mapper/xml/UserGroupMapper.xml create mode 100644 src/main/java/com/huoran/iasf/service/UserGroupService.java create mode 100644 src/main/java/com/huoran/iasf/service/impl/UserGroupServiceImpl.java diff --git a/src/main/java/com/huoran/iasf/controller/UserGroupController.java b/src/main/java/com/huoran/iasf/controller/UserGroupController.java new file mode 100644 index 0000000..ea7fefa --- /dev/null +++ b/src/main/java/com/huoran/iasf/controller/UserGroupController.java @@ -0,0 +1,103 @@ +package com.huoran.iasf.controller; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.huoran.iasf.common.aop.annotation.LogAnnotation; +import com.huoran.iasf.common.utils.R; +import com.huoran.iasf.entity.SysFilesEntity; +import com.huoran.iasf.entity.UserGroup; +import com.huoran.iasf.service.UserGroupService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** + *

+ * 用户组 前端控制器 + *

+ * + * @author cheney + * @since 2022-08-10 + */ +@RestController +@RequestMapping("/sys/userGroup") +@Api(tags = "用户组管理") +public class UserGroupController { + + @Autowired + private UserGroupService userGroupService; + + @PostMapping("/add") + @ApiOperation(value = "新增用户组") + @LogAnnotation(title = "用户组管理", action = "新增用户组") + @RequiresPermissions("sys:userGroup:add") + public R addUserGroup(@RequestBody @Valid UserGroup userGroup) { + UserGroup one = userGroupService.getOne(new QueryWrapper(). + eq("group_name", userGroup.getGroupName())); + if (ObjectUtil.isNotNull(one)){ + R.fail("用户组已存在"); + } + userGroupService.save(userGroup); + return R.success(); + } + + @DeleteMapping("/delete/{id}") + @ApiOperation(value = "删除用户组") + @LogAnnotation(title = "用户组管理", action = "删除用户组") + @RequiresPermissions("sys:userGroup:deleted") + public R deleted(@PathVariable("id") Integer id) { + userGroupService.removeById(id); + return R.success(); + } + + @PutMapping("/update") + @ApiOperation(value = "更新用户组信息") + @LogAnnotation(title = "用户组管理", action = "更新用户组信息") + @RequiresPermissions("sys:userGroup:update") + public R updateUserGroup(@RequestBody UserGroup userGroup) { + if (StringUtils.isEmpty(userGroup.getId())) { + return R.fail("id不能为空"); + } + List groups = userGroupService.list(new QueryWrapper(). + eq("group_name", userGroup.getGroupName())); + if (ObjectUtil.isNotNull(groups) && groups.size()>1){ + R.fail("用户组已存在"); + } + userGroupService.updateById(userGroup); + return R.success(); + } + +/* @GetMapping("/detail/{id}") + @ApiOperation(value = "查询用户组详情接口") + @LogAnnotation(title = "用户组管理", action = "查询用户组详情") + @RequiresPermissions("sys:userGroup:detail") + public R detailInfo(@PathVariable("id") Integer id) { + return R.success(userGroupService.getById(id)); + }*/ + + + @GetMapping("/list") + @ApiOperation(value = "用户组列表") + @LogAnnotation(title = "用户组管理", action = "获取所有用户组机构") + @RequiresPermissions("sys:userGroup:list") + public R getUserGroupAll(@RequestBody UserGroup userGroup) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + if (!StringUtils.isEmpty(userGroup.getGroupName())) { + queryWrapper.like(UserGroup::getGroupName, userGroup.getGroupName()); + } + queryWrapper.orderByDesc(UserGroup::getCreateTime); + IPage iPage = userGroupService.page(userGroup.getQueryPage(),queryWrapper); + return R.success(iPage); + } + +} + diff --git a/src/main/java/com/huoran/iasf/entity/UserGroup.java b/src/main/java/com/huoran/iasf/entity/UserGroup.java new file mode 100644 index 0000000..d04e2c0 --- /dev/null +++ b/src/main/java/com/huoran/iasf/entity/UserGroup.java @@ -0,0 +1,52 @@ +package com.huoran.iasf.entity; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 用户组 + *

+ * + * @author cheney + * @since 2022-08-10 + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("sys_user_group") +@ApiModel(value="UserGroup对象", description="用户组") +public class UserGroup extends BaseEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "名称") + @NotNull(message = "用户组名称不能为空!") + private String groupName; + + @ApiModelProperty(value = "描述") + private String description; + + @TableField(fill = FieldFill.INSERT) + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @TableField(fill = FieldFill.INSERT_UPDATE) + @ApiModelProperty(value = "更新时间") + private Date updateTime; + + @ApiModelProperty(value = "是否删除(1未删除;0已删除)") + private Integer deleted; + +} diff --git a/src/main/java/com/huoran/iasf/mapper/UserGroupMapper.java b/src/main/java/com/huoran/iasf/mapper/UserGroupMapper.java new file mode 100644 index 0000000..f9e5ad8 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/UserGroupMapper.java @@ -0,0 +1,16 @@ +package com.huoran.iasf.mapper; + +import com.huoran.iasf.entity.UserGroup; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 用户组 Mapper 接口 + *

+ * + * @author cheney + * @since 2022-08-10 + */ +public interface UserGroupMapper extends BaseMapper { + +} diff --git a/src/main/java/com/huoran/iasf/mapper/xml/UserGroupMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/UserGroupMapper.xml new file mode 100644 index 0000000..6a9d356 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/UserGroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/huoran/iasf/service/UserGroupService.java b/src/main/java/com/huoran/iasf/service/UserGroupService.java new file mode 100644 index 0000000..e8cbd21 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/UserGroupService.java @@ -0,0 +1,16 @@ +package com.huoran.iasf.service; + +import com.huoran.iasf.entity.UserGroup; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户组 服务类 + *

+ * + * @author cheney + * @since 2022-08-10 + */ +public interface UserGroupService extends IService { + +} diff --git a/src/main/java/com/huoran/iasf/service/impl/UserGroupServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/UserGroupServiceImpl.java new file mode 100644 index 0000000..493289d --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/impl/UserGroupServiceImpl.java @@ -0,0 +1,20 @@ +package com.huoran.iasf.service.impl; + +import com.huoran.iasf.entity.UserGroup; +import com.huoran.iasf.mapper.UserGroupMapper; +import com.huoran.iasf.service.UserGroupService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户组 服务实现类 + *

+ * + * @author cheney + * @since 2022-08-10 + */ +@Service +public class UserGroupServiceImpl extends ServiceImpl implements UserGroupService { + +} From b60d97d219182e5f80ced0f1eec35e0dea6f48b1 Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Wed, 17 Aug 2022 10:09:18 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=EF=BC=8C=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 53 +- .../java/com/huoran/iasf/IASFApplication.java | 3 +- .../common/aop/aspect/DataScopeAspect.java | 16 +- .../iasf/common/config/WebMvcConfigurer.java | 3 +- .../common/exception/BusinessException.java | 47 +- .../exception/code/BaseResponseCode.java | 42 +- .../handler/RestExceptionHandler.java | 28 +- .../shiro/CustomAccessControlFilter.java | 16 +- .../iasf/common/utils/ExcelAttribute.java | 25 + .../iasf/common/utils/ExcelImportHelper.java | 183 +++++ .../iasf/common/utils/ExcelStyleUtil.java | 187 +++++ .../huoran/iasf/common/utils/GenUtils.java | 28 +- .../java/com/huoran/iasf/common/utils/R.java | 7 +- .../iasf/common/utils/ValidatorUtils.java | 22 +- .../iasf/controller/DeptController.java | 25 +- .../iasf/controller/PermissionController.java | 9 +- .../iasf/controller/RoleController.java | 85 +-- .../iasf/controller/UserController.java | 89 ++- .../iasf/controller/UserDeptController.java | 21 + .../iasf/controller/UserGroupController.java | 10 +- .../iasf/controller/api/TestController.java | 53 -- .../java/com/huoran/iasf/entity/SysDept.java | 6 +- .../java/com/huoran/iasf/entity/SysRole.java | 21 - .../java/com/huoran/iasf/entity/SysUser.java | 32 +- .../java/com/huoran/iasf/entity/UserDept.java | 42 ++ .../com/huoran/iasf/mapper/SysUserMapper.java | 9 + .../huoran/iasf/mapper/UserDeptMapper.java | 16 + .../huoran/iasf/mapper/xml/SysUserMapper.xml | 149 ++++ .../huoran/iasf/mapper/xml/UserDeptMapper.xml | 5 + .../com/huoran/iasf/service/DeptService.java | 6 +- .../iasf/service/HttpSessionService.java | 54 +- .../com/huoran/iasf/service/RedisService.java | 2 +- .../com/huoran/iasf/service/RoleService.java | 10 +- .../iasf/service/SysRoleDeptService.java | 16 - .../huoran/iasf/service/UserDeptService.java | 16 + .../com/huoran/iasf/service/UserService.java | 20 +- .../iasf/service/impl/DeptServiceImpl.java | 41 +- .../iasf/service/impl/HomeServiceImpl.java | 58 -- .../service/impl/PermissionServiceImpl.java | 8 +- .../iasf/service/impl/RoleServiceImpl.java | 47 +- .../impl/SysDictDetailServiceImpl.java | 3 +- .../service/impl/SysFilesServiceImpl.java | 5 +- .../service/impl/SysGeneratorServiceImpl.java | 6 +- .../service/impl/SysRoleDeptServiceImpl.java | 4 +- .../service/impl/UserDeptServiceImpl.java | 20 + .../iasf/service/impl/UserServiceImpl.java | 700 +++++++++++++++++- .../huoran/iasf/vo/ImportUserFailureVo.java | 55 ++ .../huoran/iasf/vo/req/ExcelImpUserReq.java | 45 ++ .../com/huoran/iasf/vo/req/UserListReq.java | 28 + .../huoran/iasf/vo/resp/DeptRespNodeVO.java | 18 +- .../iasf/vo/resp/PermissionRespNode.java | 3 +- .../com/huoran/iasf/vo/resp/UserListResp.java | 65 ++ .../com/company/project/CodeGenerator.java | 2 +- 53 files changed, 1947 insertions(+), 517 deletions(-) create mode 100644 src/main/java/com/huoran/iasf/common/utils/ExcelAttribute.java create mode 100644 src/main/java/com/huoran/iasf/common/utils/ExcelImportHelper.java create mode 100644 src/main/java/com/huoran/iasf/common/utils/ExcelStyleUtil.java create mode 100644 src/main/java/com/huoran/iasf/controller/UserDeptController.java delete mode 100644 src/main/java/com/huoran/iasf/controller/api/TestController.java create mode 100644 src/main/java/com/huoran/iasf/entity/UserDept.java create mode 100644 src/main/java/com/huoran/iasf/mapper/UserDeptMapper.java create mode 100644 src/main/java/com/huoran/iasf/mapper/xml/SysUserMapper.xml create mode 100644 src/main/java/com/huoran/iasf/mapper/xml/UserDeptMapper.xml delete mode 100644 src/main/java/com/huoran/iasf/service/SysRoleDeptService.java create mode 100644 src/main/java/com/huoran/iasf/service/UserDeptService.java delete mode 100644 src/main/java/com/huoran/iasf/service/impl/HomeServiceImpl.java create mode 100644 src/main/java/com/huoran/iasf/service/impl/UserDeptServiceImpl.java create mode 100644 src/main/java/com/huoran/iasf/vo/ImportUserFailureVo.java create mode 100644 src/main/java/com/huoran/iasf/vo/req/ExcelImpUserReq.java create mode 100644 src/main/java/com/huoran/iasf/vo/req/UserListReq.java create mode 100644 src/main/java/com/huoran/iasf/vo/resp/UserListResp.java diff --git a/pom.xml b/pom.xml index ede90f2..d994f01 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,11 @@ 1.2.74 2.0.2 1.6.2 + 4.0.1 + 4.0.1 + 4.1.3 + 4.1.3 + 4.1.3 @@ -50,11 +55,11 @@
- + org.springframework.boot @@ -173,6 +178,50 @@ 5.3.6 + + + + + cn.afterturn + easypoi-base + ${easypoi-base.version} + + + guava + com.google.guava + + + guava + com.google.guava + + + poi-ooxml-schemas + org.apache.poi + + + + + cn.afterturn + easypoi-web + ${easypoi-web.version} + + + cn.afterturn + easypoi-annotation + ${easypoi-annotation.version} + + + + org.apache.poi + poi-ooxml + ${poi-ooxml.version} + + + org.apache.poi + poi + ${poi.version} + + diff --git a/src/main/java/com/huoran/iasf/IASFApplication.java b/src/main/java/com/huoran/iasf/IASFApplication.java index fab9864..333e112 100644 --- a/src/main/java/com/huoran/iasf/IASFApplication.java +++ b/src/main/java/com/huoran/iasf/IASFApplication.java @@ -1,6 +1,5 @@ package com.huoran.iasf; -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -11,7 +10,7 @@ import org.springframework.core.env.Environment; import java.net.InetAddress; -@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) +@SpringBootApplication @MapperScan("com.huoran.iasf.mapper") @Slf4j @ServletComponentScan(basePackages = {"com.huoran.iasf.common.filter"}) //这一句完成了配置,Springboot的”懒理念“真的厉害。 diff --git a/src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java b/src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java index bfc15cc..3264dd2 100644 --- a/src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java +++ b/src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java @@ -3,10 +3,11 @@ package com.huoran.iasf.common.aop.aspect; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.huoran.iasf.common.exception.BusinessException; +import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.Constant; import com.huoran.iasf.entity.SysRole; +import com.huoran.iasf.entity.SysUser; import com.huoran.iasf.service.HttpSessionService; -import org.apache.commons.lang.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @@ -17,7 +18,6 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -38,8 +38,6 @@ public class DataScopeAspect { @Resource com.huoran.iasf.service.RoleService roleService; @Resource - com.huoran.iasf.service.SysRoleDeptService sysRoleDeptService; - @Resource com.huoran.iasf.service.DeptService deptService; @Resource com.huoran.iasf.service.UserService userService; @@ -90,15 +88,15 @@ public class DataScopeAspect { */ private List getUserIdsByRoles(List sysRoles, String userId) { //本人 - com.huoran.iasf.entity.SysUser sysUser = userService.getById(userId); + SysUser sysUser = userService.getById(userId); //本部门 - com.huoran.iasf.entity.SysDept sysDept = deptService.getById(sysUser.getDeptId()); + // SysDept sysDept = deptService.getById(sysUser.getDeptId()); //部门ids, 定义哪些部门最终拥有权限查看 LinkedList deptList = new LinkedList<>(); //用户ids,定义列表中哪些人创建的可查看 LinkedList userIdList = new LinkedList<>(); //根据数据权限范围分组, 不同的数据范围不同的逻辑处理 - Map> dataScopeMap = sysRoles.parallelStream().collect(Collectors.groupingBy(com.huoran.iasf.entity.SysRole::getDataScope)); + /*Map> dataScopeMap = sysRoles.parallelStream().collect(Collectors.groupingBy(com.huoran.iasf.entity.SysRole::getDataScope)); dataScopeMap.forEach((k, v) -> { if (Constant.DATA_SCOPE_CUSTOM.equals(k)) { //自定义 @@ -121,14 +119,14 @@ public class DataScopeAspect { //自己 userIdList.add(userId); } - }); + });*/ if (!CollectionUtils.isEmpty(deptList)) { QueryWrapper queryWrapper = Wrappers.query().select("id").in("dept_id", deptList); userIdList.addAll(userService.listObjs(queryWrapper)); } //如果配置了角色数据范围, 最终没有查到userId, 那么返回无数据 if (CollectionUtils.isEmpty(userIdList)) { - throw new BusinessException("无数据"); + throw new BusinessException(BaseResponseCode.NOT_ACCOUNT); } return userIdList.parallelStream().map(Object::toString).collect(Collectors.toList()); } diff --git a/src/main/java/com/huoran/iasf/common/config/WebMvcConfigurer.java b/src/main/java/com/huoran/iasf/common/config/WebMvcConfigurer.java index 9795f3e..3eb0fe0 100644 --- a/src/main/java/com/huoran/iasf/common/config/WebMvcConfigurer.java +++ b/src/main/java/com/huoran/iasf/common/config/WebMvcConfigurer.java @@ -105,7 +105,8 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { WebMvcConfigurer.super.addCorsMappings(registry); registry.addMapping("/**") .allowedHeaders("*") - .allowedMethods("POST", "GET", "PUT", "DELETE") + .allowCredentials(true) + .allowedMethods("*") .allowedOrigins("*"); } diff --git a/src/main/java/com/huoran/iasf/common/exception/BusinessException.java b/src/main/java/com/huoran/iasf/common/exception/BusinessException.java index c01cdf3..1b62c57 100644 --- a/src/main/java/com/huoran/iasf/common/exception/BusinessException.java +++ b/src/main/java/com/huoran/iasf/common/exception/BusinessException.java @@ -1,7 +1,9 @@ package com.huoran.iasf.common.exception; import com.huoran.iasf.common.exception.code.BaseResponseCode; -import com.huoran.iasf.common.exception.code.ResponseCodeInterface; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; /** * BusinessException @@ -10,44 +12,9 @@ import com.huoran.iasf.common.exception.code.ResponseCodeInterface; * @version V1.0 * @date 2022年7月28日 */ +@Getter +@NoArgsConstructor +@AllArgsConstructor public class BusinessException extends RuntimeException { - - /** - * 异常编号 - */ - private final int messageCode; - - /** - * 对messageCode 异常信息进行补充说明 - */ - private final String detailMessage; - - public BusinessException(int messageCode, String message) { - super(message); - this.messageCode = messageCode; - this.detailMessage = message; - } - - public BusinessException(String message) { - super(message); - this.messageCode = BaseResponseCode.OPERATION_ERROR.getCode(); - this.detailMessage = message; - } - - /** - * 构造函数 - * - * @param code 异常码 - */ - public BusinessException(ResponseCodeInterface code) { - this(code.getCode(), code.getMsg()); - } - - public int getMessageCode() { - return messageCode; - } - - public String getDetailMessage() { - return detailMessage; - } + private BaseResponseCode baseResponseCode; } diff --git a/src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java b/src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java index d53b54e..bab308c 100644 --- a/src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java +++ b/src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java @@ -1,5 +1,9 @@ package com.huoran.iasf.common.exception.code; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; /** * 错误码 @@ -8,14 +12,29 @@ package com.huoran.iasf.common.exception.code; * @version V1.0 * @date 2022年7月28日 */ +@Getter +@ToString +@NoArgsConstructor +@AllArgsConstructor public enum BaseResponseCode implements ResponseCodeInterface { /** * 错误码 */ - SUCCESS(200, "success"), - SYSTEM_BUSY(10001, "系统繁忙,请稍候再试"), + USERNAME_EXISTS(10008, "用户名已存在!"), + KEY_OR_TOMEUNIT(10009, "key or TomeUnit 不能为空!"), + DICTIONARY_DATA_FAILED(10010, "获取字典数据失败"), + UPLOAD_EMPTY(10011, "上传内容为空"), + UPLOAD_FAILED(10012, "上传失败"), + VERIFICATION_CODE_ERROR(10007, "验证码错误!"), + VERIFICATION_CODE_EXPIRED(10006, "验证码已过期!"), + CANNOT_SAME(10005, "新密码不能与旧密码相同!"), + EXCEL_FILE_INVALID(10004, "上传excel文件错误!"), + VALID_EXCEPTION(10003, "参数格式校验异常!"), OPERATION_ERROR(10002, "操作失败"), + SYSTEM_BUSY(10001, "系统繁忙,请稍候再试"), + SUCCESS(200, "success"), + EXCEL_FILE_FORMAT_ERROR(40007, "请根据模板使用说明录入正确的用户信息!"), TOKEN_ERROR(401001, "登录凭证已过期,请重新登录"), DATA_ERROR(401003, "传入数据异常"), NOT_ACCOUNT(401004, "该用户不存在,请先注册"), @@ -31,29 +50,16 @@ public enum BaseResponseCode implements ResponseCodeInterface { OPERATION_MENU_PERMISSION_BTN_ERROR(401013, "操作后的菜单类型是按钮,所属菜单必须为菜单类型"), OPERATION_MENU_PERMISSION_URL_NOT_NULL(401015, "菜单权限的url不能为空"), OPERATION_MENU_PERMISSION_URL_PERMS_NULL(401016, "菜单权限的标识符不能为空"), + EXCEL_FILE_NULL(40006, "导入失败,导入数据为空!") ; /** * 错误码 */ - private final int code; + private int code; /** * 错误消息 */ - private final String msg; - - BaseResponseCode(int code, String msg) { - this.code = code; - this.msg = msg; - } - - @Override - public int getCode() { - return code; - } + private String msg; - @Override - public String getMsg() { - return msg; - } } diff --git a/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java b/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java index 44ee344..61b1380 100644 --- a/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java +++ b/src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java @@ -1,19 +1,21 @@ package com.huoran.iasf.common.exception.handler; +import com.google.common.collect.Maps; import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.R; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.authz.AuthorizationException; -import org.springframework.validation.ObjectError; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; -import java.util.List; +import java.util.HashMap; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; /** * RestExceptionHandler @@ -41,8 +43,8 @@ public class RestExceptionHandler { @ExceptionHandler(value = BusinessException.class) R businessExceptionHandler(BusinessException e) { log.error("Exception,exception:{}", e, e); - - return new R(e.getMessageCode(), e.getMessage()); + BaseResponseCode em = e.getBaseResponseCode(); + return new R(em.getCode(), em.getMsg()); } /** @@ -56,13 +58,19 @@ public class RestExceptionHandler { } /** - * 处理validation 框架异常 + * 处理参数格式校验异常 */ - @ExceptionHandler(MethodArgumentNotValidException.class) - R methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { - log.error("methodArgumentNotValidExceptionHandler bindingResult.allErrors():{},exception:{}", e.getBindingResult().getAllErrors(), e); - List errors = e.getBindingResult().getAllErrors(); - return R.getResult(BaseResponseCode.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getCode(), errors.get(0).getDefaultMessage()); + @ExceptionHandler(value = MethodArgumentNotValidException.class) + public R handleValidException(MethodArgumentNotValidException e){ + log.error("参数格式校验异常"); + BindingResult bindingResult = e.getBindingResult(); + HashMap errorMap = Maps.newHashMap(); + AtomicReference errorMsg = new AtomicReference<>(""); + bindingResult.getFieldErrors().forEach(fieldError -> { + errorMsg.set(fieldError.getDefaultMessage()); + errorMap.put(fieldError.getField(),fieldError.getDefaultMessage()); + }); + return R.fail(errorMsg); } /** diff --git a/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java b/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java index 10946ff..2fc8449 100644 --- a/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java +++ b/src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java @@ -59,30 +59,30 @@ public class CustomAccessControlFilter extends AccessControlFilter { UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token); getSubject(servletRequest, servletResponse).login(usernamePasswordToken); } catch (BusinessException exception) { - if (HttpContextUtils.isAjaxRequest(request)) { - customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); +/* if (HttpContextUtils.isAjaxRequest(request)) { + customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse); } else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) { servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse); } else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) { servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); } else { servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); - } + }*/ return false; } catch (AuthenticationException e) { - if (HttpContextUtils.isAjaxRequest(request)) { + /*if (HttpContextUtils.isAjaxRequest(request)) { if (e.getCause() instanceof BusinessException) { BusinessException exception = (BusinessException) e.getCause(); - customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); + customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse); } else { customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse); } } else { servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); - } + }*/ return false; } catch (Exception e) { - if (HttpContextUtils.isAjaxRequest(request)) { + /*if (HttpContextUtils.isAjaxRequest(request)) { if (e.getCause() instanceof BusinessException) { BusinessException exception = (BusinessException) e.getCause(); customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); @@ -91,7 +91,7 @@ public class CustomAccessControlFilter extends AccessControlFilter { } } else { servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); - } + }*/ return false; } return true; diff --git a/src/main/java/com/huoran/iasf/common/utils/ExcelAttribute.java b/src/main/java/com/huoran/iasf/common/utils/ExcelAttribute.java new file mode 100644 index 0000000..cf0bd20 --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/utils/ExcelAttribute.java @@ -0,0 +1,25 @@ +package com.huoran.iasf.common.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ExcelAttribute { + /** + * 对应的列名称 + */ + String name() default ""; + + /** + * excel列的索引 + */ + int sort(); + + /** + * 字段类型对应的格式 + */ + String format() default ""; +} diff --git a/src/main/java/com/huoran/iasf/common/utils/ExcelImportHelper.java b/src/main/java/com/huoran/iasf/common/utils/ExcelImportHelper.java new file mode 100644 index 0000000..fd001f8 --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/utils/ExcelImportHelper.java @@ -0,0 +1,183 @@ +package com.huoran.iasf.common.utils; + +import com.huoran.iasf.common.exception.BusinessException; +import com.huoran.iasf.common.exception.code.BaseResponseCode; +import com.huoran.iasf.vo.req.ExcelImpUserReq; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ExcelImportHelper { + + //判断row是否为空 + public static boolean isRowEmpty(Row row) { + if (null == row) { + return true; + } + int firstCellNum = row.getFirstCellNum(); //第一个列位置 + int lastCellNum = row.getLastCellNum(); //最后一列位置 + int nullCellNum = 0; //空列数量 + for (int c = firstCellNum; c < lastCellNum; c++) { + Cell cell = row.getCell(c); + if (null == cell || CellType.BLANK == cell.getCellType()) { + nullCellNum++; + continue; + } + cell.setCellType(CellType.STRING); + String cellValue = cell.getStringCellValue().trim(); + if (StringUtils.isEmpty(cellValue)) { + nullCellNum++; + } + } + //所有列都为空 + if (nullCellNum == (lastCellNum - firstCellNum)) { + return true; + } + return false; + } + + + private static Workbook getWorkbook(MultipartFile file) { + String fileName = file.getOriginalFilename(); + Workbook workbook = null; + + if (fileName.endsWith("xlsx")) { + try { + workbook = new XSSFWorkbook(file.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (fileName.endsWith("xls")) { + try { + workbook = new HSSFWorkbook(file.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + return workbook; + } + + + /** + * @Description : 读取文件数据 + * @Param file + * @Author Rong---2021/10/15 + */ + public static List readUser(MultipartFile file) { + List list = new ArrayList<>(); + + Workbook workbook = getWorkbook(file); + ExcelImpUserReq excelImpUserReq = null; + // 循环工作表Sheet + for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { + Sheet hssfSheet = workbook.getSheetAt(numSheet); + if (hssfSheet == null) { + continue; + } + + int count = 1; + // 循环行Row//开始行2 + for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { + Row row = hssfSheet.getRow(rowNum); + + if (isRowEmpty(row)) { + count++; + if (count == hssfSheet.getLastRowNum()) { + throw new BusinessException(BaseResponseCode.EXCEL_FILE_NULL); + } + continue; + } + + Cell realName;//姓名 + Cell userName;//账号 + Cell jobNumber;//工号 + Cell dept;//所在部门 + Cell roleName;//角色 + Cell phone;//手机号 + Cell email;//邮箱 + Cell groupName;//用户组 + if (row != null) { + + excelImpUserReq = new ExcelImpUserReq(); + + if (row.getCell(7) != null) { + row.getCell(7).setCellType(CellType.STRING); + groupName = row.getCell(7); + } else { + groupName = row.createCell(7); + } + + if (row.getCell(6) != null) { + row.getCell(6).setCellType(CellType.STRING); + email = row.getCell(6); + } else { + email = row.createCell(6); + } + + if (row.getCell(5) != null) { + row.getCell(5).setCellType(CellType.STRING); + phone = row.getCell(5); + } else { + phone = row.createCell(5); + } + + if (row.getCell(4) != null) { + row.getCell(4).setCellType(CellType.STRING); + dept = row.getCell(4); + } else { + dept = row.createCell(4); + } + + if (row.getCell(3) != null) { + row.getCell(3).setCellType(CellType.STRING); + jobNumber = row.getCell(3); + } else { + jobNumber = row.createCell(3); + } + + if (row.getCell(2) != null) { + row.getCell(2).setCellType(CellType.STRING); + roleName = row.getCell(2); + } else { + roleName = row.createCell(3); + } + + if (row.getCell(1) != null) { + row.getCell(1).setCellType(CellType.STRING); + userName = row.getCell(1); + } else { + userName = row.createCell(1); + } + + if (row.getCell(0) != null) { + row.getCell(0).setCellType(CellType.STRING); + realName = row.getCell(0); + } else { + realName = row.createCell(0); + } + + excelImpUserReq.setRealName(realName.getStringCellValue()); + excelImpUserReq.setUserName(userName.getStringCellValue()); + excelImpUserReq.setJobNumber(jobNumber.getStringCellValue()); + excelImpUserReq.setDept(dept.getStringCellValue()); + excelImpUserReq.setRoleName(roleName.getStringCellValue()); + excelImpUserReq.setPhone(phone.getStringCellValue()); + excelImpUserReq.setEmail(email.getStringCellValue()); + excelImpUserReq.setGroupName(groupName.getStringCellValue()); + + list.add(excelImpUserReq); + } + } + + } + + return list; + } + +} diff --git a/src/main/java/com/huoran/iasf/common/utils/ExcelStyleUtil.java b/src/main/java/com/huoran/iasf/common/utils/ExcelStyleUtil.java new file mode 100644 index 0000000..f55b1a0 --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/utils/ExcelStyleUtil.java @@ -0,0 +1,187 @@ +package com.huoran.iasf.common.utils; + +import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; +import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; +import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; +import org.apache.poi.ss.usermodel.*; + +/** + * @ProjectName: huorantech + * @Package: com.huoran.common.utils + * @ClassName: ExcelStyleUtil + * @Description: easy poi导出设置样式 + * @Author: Maureen.Rong + * @CreateDate: 2021/9/1 14:29 + * @UpdateDate: 2021/9/1 14:29 + * @Version: 1.0 + */ +public class ExcelStyleUtil implements IExcelExportStyler { + private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); + private static final short FONT_SIZE_TEN = 9; + private static final short FONT_SIZE_ELEVEN = 10; + private static final short FONT_SIZE_TWELVE = 50; + + /** + * 大标题样式 + */ + private CellStyle headerStyle; + /** + * 每列标题样式 + */ + private CellStyle titleStyle; + /** + * 数据行样式 + */ + private CellStyle styles; + + public ExcelStyleUtil(Workbook workbook) { + this.init(workbook); + } + + /** + * 初始化样式 + * + * @param workbook + */ + private void init(Workbook workbook) { + this.headerStyle = initHeaderStyle(workbook); + this.titleStyle = initTitleStyle(workbook); + this.styles = initStyles(workbook); + } + + /** + * 大标题样式 + * + * @param color + * @return + */ + @Override + public CellStyle getHeaderStyle(short color) { + return headerStyle; + } + + /** + * 每列标题样式 + * + * @param color + * @return + */ + @Override + public CellStyle getTitleStyle(short color) { + return titleStyle; + } + + /** + * 数据行样式 + * + * @param parity 可以用来表示奇偶行 + * @param entity 数据内容 + * @return 样式 + */ + @Override + public CellStyle getStyles(boolean parity, ExcelExportEntity entity) { + return styles; + } + + /** + * 获取样式方法 + * + * @param dataRow 数据行 + * @param obj 对象 + * @param data 数据 + */ + @Override + public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) { + return getStyles(true, entity); + } + + /** + * 模板使用的样式设置 + */ + @Override + public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { + return null; + } + + /** + * 初始化--大标题样式 + * + * @param workbook + * @return + */ + private CellStyle initHeaderStyle(Workbook workbook) { + CellStyle style = getBaseCellStyle(workbook); + style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true)); + return style; + } + + /** + * 初始化--每列标题样式 + * + * @param workbook + * @return + */ + private CellStyle initTitleStyle(Workbook workbook) { + CellStyle style = getBaseCellStyle(workbook); + style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false)); + //背景色 + style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + return style; + } + + /** + * 初始化--数据行样式 + * + * @param workbook + * @return + */ + private CellStyle initStyles(Workbook workbook) { + CellStyle style = getBaseCellStyle(workbook); + style.setFont(getFont(workbook, FONT_SIZE_TEN, false)); + style.setDataFormat(STRING_FORMAT); + return style; + } + + /** + * 基础样式 + * + * @return + */ + private CellStyle getBaseCellStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + //下边框 + style.setBorderBottom(BorderStyle.THIN); + //左边框 + style.setBorderLeft(BorderStyle.THIN); + //上边框 + style.setBorderTop(BorderStyle.THIN); + //右边框 + style.setBorderRight(BorderStyle.THIN); + //水平居中 + style.setAlignment(HorizontalAlignment.CENTER); + //上下居中 + style.setVerticalAlignment(VerticalAlignment.CENTER); + //设置自动换行 + style.setWrapText(true); + return style; + } + + /** + * 字体样式 + * + * @param size 字体大小 + * @param isBold 是否加粗 + * @return + */ + private Font getFont(Workbook workbook, short size, boolean isBold) { + Font font = workbook.createFont(); + //字体样式 + font.setFontName("宋体"); + //是否加粗 + font.setBold(isBold); + //字体大小 + font.setFontHeightInPoints(size); + return font; + } +} diff --git a/src/main/java/com/huoran/iasf/common/utils/GenUtils.java b/src/main/java/com/huoran/iasf/common/utils/GenUtils.java index 4a1098d..c457ad0 100644 --- a/src/main/java/com/huoran/iasf/common/utils/GenUtils.java +++ b/src/main/java/com/huoran/iasf/common/utils/GenUtils.java @@ -1,24 +1,10 @@ package com.huoran.iasf.common.utils; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.huoran.iasf.common.exception.BusinessException; -import com.huoran.iasf.entity.ColumnEntity; -import com.huoran.iasf.entity.TableEntity; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import java.util.ArrayList; +import java.util.List; /** * 代码生成器 工具类 @@ -46,7 +32,7 @@ public class GenUtils { /** * 生成代码 */ - public static void generatorCode(Map table, + /*public static void generatorCode(Map table, List> columns, ZipOutputStream zip) { //配置信息 Configuration config = getConfig(); @@ -144,10 +130,10 @@ public class GenUtils { IOUtils.closeQuietly(sw); zip.closeEntry(); } catch (IOException e) { - throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName()); + // throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName()); } } - } + }*/ /** @@ -184,13 +170,13 @@ public class GenUtils { /** * 获取配置信息 */ - public static Configuration getConfig() { +/* public static Configuration getConfig() { try { return new PropertiesConfiguration("generator.properties"); } catch (ConfigurationException e) { throw new BusinessException("获取配置文件失败"); } - } + }*/ /** * 获取文件名 diff --git a/src/main/java/com/huoran/iasf/common/utils/R.java b/src/main/java/com/huoran/iasf/common/utils/R.java index 85ce28b..8336db6 100644 --- a/src/main/java/com/huoran/iasf/common/utils/R.java +++ b/src/main/java/com/huoran/iasf/common/utils/R.java @@ -15,8 +15,6 @@ import lombok.Data; @Data public class R { - - /** * 请求响应code,0为成功 其他为失败 */ @@ -95,6 +93,11 @@ public class R { return new R(BaseResponseCode.OPERATION_ERROR.getCode(), msg); } + public static R fail(Object data) { + return new R(data); + } + + /** * 自定义返回 data为null */ diff --git a/src/main/java/com/huoran/iasf/common/utils/ValidatorUtils.java b/src/main/java/com/huoran/iasf/common/utils/ValidatorUtils.java index c485355..9e89d41 100644 --- a/src/main/java/com/huoran/iasf/common/utils/ValidatorUtils.java +++ b/src/main/java/com/huoran/iasf/common/utils/ValidatorUtils.java @@ -2,44 +2,38 @@ package com.huoran.iasf.common.utils; import com.huoran.iasf.common.exception.BusinessException; -import org.apache.commons.lang.StringUtils; - -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import java.util.Set; /** * hibernate-validator校验工具类 * */ -public class ValidatorUtils { +/*public class ValidatorUtils { private static Validator validator; static { validator = Validation.buildDefaultValidatorFactory().getValidator(); } - /** + *//** * 校验对象 * @param object 待校验对象 * @param groups 待校验的组 * @throws BusinessException 校验不通过,则报RRException异常 - */ - public static void validateEntity(Object object, Class... groups) + *//* +*//* public static void validateEntity(Object object, Class... groups) throws BusinessException { Set> constraintViolations = validator.validate(object, groups); if (!constraintViolations.isEmpty()) { ConstraintViolation constraint = (ConstraintViolation)constraintViolations.iterator().next(); throw new BusinessException(constraint.getMessage()); } - } + }*//* - /** + *//** * 空判断处理 * @param str * @param message - */ + *//* public static void isBlank(Object str, String message) { if (str == null) { throw new BusinessException(message); @@ -50,4 +44,4 @@ public class ValidatorUtils { } } } -} +}*/ diff --git a/src/main/java/com/huoran/iasf/controller/DeptController.java b/src/main/java/com/huoran/iasf/controller/DeptController.java index 900251b..6d41c22 100644 --- a/src/main/java/com/huoran/iasf/controller/DeptController.java +++ b/src/main/java/com/huoran/iasf/controller/DeptController.java @@ -4,8 +4,10 @@ import com.huoran.iasf.common.aop.annotation.LogAnnotation; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysDept; import com.huoran.iasf.service.DeptService; +import com.huoran.iasf.vo.resp.DeptRespNodeVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.util.StringUtils; @@ -13,7 +15,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; /** * 部门管理 @@ -34,6 +35,10 @@ public class DeptController { @LogAnnotation(title = "机构管理", action = "新增组织") @RequiresPermissions("sys:dept:add") public R addDept(@RequestBody @Valid SysDept vo) { + boolean ok = deptService.checkDeptRepeat(vo); + if (ok) { + return R.fail("同级下已存在相同的名称:" + vo.getName()); + } deptService.addDept(vo); return R.success(); } @@ -55,6 +60,10 @@ public class DeptController { if (StringUtils.isEmpty(vo.getId())) { return R.fail("id不能为空"); } + boolean ok = deptService.checkDeptRepeat(vo); + if (ok) { + return R.fail("同级下已存在相同的名称:" + vo.getName()); + } deptService.updateDept(vo); return R.success(); } @@ -68,14 +77,16 @@ public class DeptController { } @GetMapping("/dept/tree") - @ApiOperation(value = "树型组织列表接口") - @LogAnnotation(title = "机构管理", action = "树型组织列表") + @ApiOperation(value = "树型组织列表接口",response = DeptRespNodeVO.class) + @LogAnnotation(title = "部门管理", action = "树型组织列表") @RequiresPermissions(value = {"sys:user:list", "sys:user:update", "sys:user:add", "sys:dept:add", "sys:dept:update"}, logical = Logical.OR) - public R getTree(@RequestParam(required = false) String deptId) { - return R.success(deptService.deptTreeList(deptId, false)); + public R getTree( + @ApiParam(name = "deptId", value = "部门id",required = false) + @RequestParam(required = false) String deptId) { + return R.success(deptService.deptTreeList(deptId)); } - @GetMapping("/depts") +/* @GetMapping("/depts") @ApiOperation(value = "获取机构列表接口") @LogAnnotation(title = "机构管理", action = "获取所有组织机构") @RequiresPermissions("sys:dept:list") @@ -88,6 +99,6 @@ public class DeptController { } }); return R.success(deptList); - } + }*/ } diff --git a/src/main/java/com/huoran/iasf/controller/PermissionController.java b/src/main/java/com/huoran/iasf/controller/PermissionController.java index 94f29ed..02246ea 100644 --- a/src/main/java/com/huoran/iasf/controller/PermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/PermissionController.java @@ -77,24 +77,23 @@ public class PermissionController { @RequiresPermissions("sys:permission:detail") public R detailInfo(@PathVariable("id") String id) { return R.success(permissionService.getById(id)); - } - @GetMapping("/permissions") + /*@GetMapping("/permissions") @ApiOperation(value = "获取所有菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "获取所有菜单权限") @RequiresPermissions("sys:permission:list") public R getAllMenusPermission() { return R.success(permissionService.selectAll()); - } + }*/ - @GetMapping("/permission/tree") +/* @GetMapping("/permission/tree") @ApiOperation(value = "获取所有目录菜单树接口") @LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树") @RequiresPermissions(value = {"sys:permission:update", "sys:permission:add"}, logical = Logical.OR) public R getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) { return R.success(permissionService.selectAllMenuByTree(permissionId)); - } + }*/ @GetMapping("/permission/tree/all") @ApiOperation(value = "获取所有目录菜单树接口") diff --git a/src/main/java/com/huoran/iasf/controller/RoleController.java b/src/main/java/com/huoran/iasf/controller/RoleController.java index 895c30e..c61765d 100644 --- a/src/main/java/com/huoran/iasf/controller/RoleController.java +++ b/src/main/java/com/huoran/iasf/controller/RoleController.java @@ -1,13 +1,16 @@ package com.huoran.iasf.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.huoran.iasf.common.aop.annotation.LogAnnotation; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysRole; -import com.huoran.iasf.entity.SysRoleDeptEntity; +import com.huoran.iasf.entity.SysRolePermission; +import com.huoran.iasf.service.HttpSessionService; +import com.huoran.iasf.service.RolePermissionService; import com.huoran.iasf.service.RoleService; -import com.huoran.iasf.service.SysRoleDeptService; +import com.huoran.iasf.vo.req.RolePermissionOperationReqVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -34,14 +38,30 @@ public class RoleController { @Resource private RoleService roleService; @Resource - private SysRoleDeptService sysRoleDeptService; + private RolePermissionService rolePermissionService; + @Resource + private HttpSessionService httpSessionService; @PostMapping("/role") @ApiOperation(value = "新增角色接口") @LogAnnotation(title = "角色管理", action = "新增角色") @RequiresPermissions("sys:role:add") public R addRole(@RequestBody @Valid SysRole vo) { + boolean ok = roleService.checkDeptRepeat(vo); + if (ok) { + return R.fail("已存在相同的角色名称:" + vo.getName()); + } roleService.addRole(vo); + //删除角色权限关联 + rolePermissionService.remove(Wrappers.lambdaQuery().eq(SysRolePermission::getRoleId, vo.getId())); + if (!CollectionUtils.isEmpty(vo.getPermissions())) { + RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO(); + reqVO.setRoleId(vo.getId()); + reqVO.setPermissionIds(vo.getPermissions()); + rolePermissionService.addRolePermission(reqVO); + // 刷新权限 + httpSessionService.refreshRolePermission(vo.getId()); + } return R.success(); } @@ -62,39 +82,11 @@ public class RoleController { if (StringUtils.isEmpty(vo.getId())) { return R.fail("id不能为空"); } - roleService.updateRole(vo); - return R.success(); - } - - @PostMapping("/role/bindDept") - @ApiOperation(value = "绑定角色部门接口") - @LogAnnotation(title = "角色管理", action = "绑定角色部门信息") - @RequiresPermissions("sys:role:bindDept") - public R bindDept(@RequestBody SysRole vo) { - if (StringUtils.isEmpty(vo.getId())) { - return R.fail("id不能为空"); - } - if (roleService.getById(vo.getId()) == null) { - return R.fail("获取角色失败"); - } - - //先删除所有绑定 - sysRoleDeptService.remove(Wrappers.lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId())); - //如果不是自定义 - if (vo.getDataScope() != 2) { - vo.setDepts(null); - } - if (!CollectionUtils.isEmpty(vo.getDepts())) { - List list = new ArrayList<>(); - for (String deptId : vo.getDepts()) { - SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity(); - sysRoleDeptEntity.setDeptId(deptId); - sysRoleDeptEntity.setRoleId(vo.getId()); - list.add(sysRoleDeptEntity); - } - sysRoleDeptService.saveBatch(list); + boolean ok = roleService.checkDeptRepeat(vo); + if (ok) { + return R.fail("已存在相同的角色名称:" + vo.getName()); } - roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope())); + roleService.updateRole(vo); return R.success(); } @@ -103,7 +95,19 @@ public class RoleController { @LogAnnotation(title = "角色管理", action = "查询角色详情") @RequiresPermissions("sys:role:detail") public R detailInfo(@PathVariable("id") String id) { - return R.success(roleService.detailInfo(id)); + // return R.success(roleService.detailInfo(id)); + SysRole role = roleService.getById(id); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("role_id", id).select("permission_id"); + List list = rolePermissionService.list(wrapper); + List permissionList = new ArrayList<>(); + list.forEach(rolePermission -> { + permissionList.add(rolePermission.getPermissionId()); + }); + HashMap map = new HashMap<>(); + map.put("role", role); + map.put("permissionList", permissionList); + return R.success(map); } @PostMapping("/roles") @@ -116,15 +120,6 @@ public class RoleController { if (!StringUtils.isEmpty(vo.getName())) { queryWrapper.like(SysRole::getName, vo.getName()); } -/* if (!StringUtils.isEmpty(vo.getStartTime())) { - queryWrapper.gt(SysRole::getCreateTime, vo.getStartTime()); - } - if (!StringUtils.isEmpty(vo.getEndTime())) { - queryWrapper.lt(SysRole::getCreateTime, vo.getEndTime()); - } - if (!StringUtils.isEmpty(vo.getStatus())) { - queryWrapper.eq(SysRole::getStatus, vo.getStatus()); - }*/ queryWrapper.orderByDesc(SysRole::getCreateTime); return R.success(roleService.page(vo.getQueryPage(), queryWrapper)); } diff --git a/src/main/java/com/huoran/iasf/controller/UserController.java b/src/main/java/com/huoran/iasf/controller/UserController.java index 9778380..9d30870 100644 --- a/src/main/java/com/huoran/iasf/controller/UserController.java +++ b/src/main/java/com/huoran/iasf/controller/UserController.java @@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.huoran.iasf.common.aop.annotation.LogAnnotation; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysUser; -import com.huoran.iasf.entity.SysUserRole; import com.huoran.iasf.service.HttpSessionService; import com.huoran.iasf.service.UserRoleService; import com.huoran.iasf.service.UserService; -import com.huoran.iasf.vo.req.UserRoleOperationReqVO; +import com.huoran.iasf.vo.req.UserListReq; +import com.huoran.iasf.vo.resp.UserListResp; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -17,13 +17,17 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.subject.Subject; -import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.IOException; import java.util.List; +import java.util.Map; /** * 用户管理 @@ -50,19 +54,14 @@ public class UserController { return R.success(userService.login(vo)); } - @PostMapping("/user/register") +/* @PostMapping("/user/register") @ApiOperation(value = "用户注册接口") public R register(@RequestBody @Valid SysUser vo) { userService.register(vo); return R.success(); - } - - /*@GetMapping("/user/unLogin") - @ApiOperation(value = "引导客户端去登录") - public R unLogin() { - return R.getResult(BaseResponseCode.TOKEN_ERROR); }*/ + @PutMapping("/user") @ApiOperation(value = "更新用户信息接口") @LogAnnotation(title = "用户管理", action = "更新用户信息") @@ -71,41 +70,26 @@ public class UserController { if (StringUtils.isEmpty(vo.getId())) { return R.fail("id不能为空"); } - userService.updateUserInfo(vo); return R.success(); } - @PutMapping("/user/info") - @ApiOperation(value = "更新用户信息接口") - @LogAnnotation(title = "用户管理", action = "更新用户信息") - public R updateUserInfoById(@RequestBody SysUser vo) { - userService.updateUserInfoMy(vo); - return R.success(); - } @GetMapping("/user/{id}") @ApiOperation(value = "查询用户详情接口") @LogAnnotation(title = "用户管理", action = "查询用户详情") @RequiresPermissions("sys:user:detail") public R detailInfo(@PathVariable("id") String id) { - return R.success(userService.getById(id)); - } - - @GetMapping("/user") - @ApiOperation(value = "查询用户详情接口") - @LogAnnotation(title = "用户管理", action = "查询用户详情") - public R youSelfInfo() { - String userId = httpSessionService.getCurrentUserId(); - return R.success(userService.getById(userId)); + UserListResp userResp = userService.detailInfo(id); + return R.success(userResp); } @PostMapping("/users") @ApiOperation(value = "分页获取用户列表接口") @RequiresPermissions("sys:user:list") @LogAnnotation(title = "用户管理", action = "分页获取用户列表") - public R pageInfo(@RequestBody SysUser vo) { - return R.success(userService.pageInfo(vo)); + public R pageInfo(@RequestBody UserListReq userListReq) { + return userService.pageInfo(userListReq); } @PostMapping("/user") @@ -117,6 +101,34 @@ public class UserController { return R.success(); } + @GetMapping("/checkJobNumber") + @ApiOperation(value = "工号验证") + // @LogAnnotation(title = "用户管理", action = "工号验证") + public R checkJobNumber(@RequestParam String jobNumber) { + SysUser sysUser = userService.getOne(Wrappers.lambdaQuery().eq(SysUser::getJobNumber, jobNumber)); + if (sysUser != null) { + R.fail("工号已存在,请勿重复添加!"); + } + return R.success(); + } + + @GetMapping("/checkUsername") + @ApiOperation(value = "账号验证") + // @LogAnnotation(title = "用户管理", action = "工号验证") + public R checkUsername(@RequestParam String userName) { + SysUser sysUser = userService.getOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, userName)); + if (sysUser != null) { + R.fail("账号已存在,请勿重复添加!"); + } + return R.success(); + } + + @ApiOperation(value = "密码重置", notes = "密码重置") + @GetMapping("/resetPwd") + public R resetPwd(@RequestParam("userId") String userId) { + return userService.resetPwd(userId); + } + @GetMapping("/user/logout") @ApiOperation(value = "退出接口") @LogAnnotation(title = "用户管理", action = "退出") @@ -153,7 +165,7 @@ public class UserController { return R.success(); } - @GetMapping("/user/roles/{userId}") + /*@GetMapping("/user/roles/{userId}") @ApiOperation(value = "赋予角色-获取所有角色接口") @LogAnnotation(title = "用户管理", action = "赋予角色-获取所有角色接口") @RequiresPermissions("sys:user:role:detail") @@ -181,5 +193,22 @@ public class UserController { //刷新权限 httpSessionService.refreshUerId(userId); return R.success(); + }*/ + + + @PostMapping("/importStaff") + @ApiOperation("批量导入员工") + public R importStaff(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request) throws IOException { + Map map = userService.importStaff(file); + return R.success(map); + } + + /** + * 批量导入员工失败数据导出 + */ + @ApiOperation(value = "批量导入员工失败数据导出") + @GetMapping("/exportFailure") + public void exportFailureRecord(HttpServletResponse response, @ApiParam(name = "exportCode", value = "importQuestion接口返回的exportCode", required = true) @RequestParam String exportCode) throws Exception { + userService.exportFailureRecord(response, exportCode); } } diff --git a/src/main/java/com/huoran/iasf/controller/UserDeptController.java b/src/main/java/com/huoran/iasf/controller/UserDeptController.java new file mode 100644 index 0000000..6e48f6a --- /dev/null +++ b/src/main/java/com/huoran/iasf/controller/UserDeptController.java @@ -0,0 +1,21 @@ +package com.huoran.iasf.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 用户员工部门表 前端控制器 + *

+ * + * @author cheney + * @since 2022-08-15 + */ +@RestController +@RequestMapping("//user-dept") +public class UserDeptController { + +} + diff --git a/src/main/java/com/huoran/iasf/controller/UserGroupController.java b/src/main/java/com/huoran/iasf/controller/UserGroupController.java index ea7fefa..265ff78 100644 --- a/src/main/java/com/huoran/iasf/controller/UserGroupController.java +++ b/src/main/java/com/huoran/iasf/controller/UserGroupController.java @@ -67,9 +67,11 @@ public class UserGroupController { if (StringUtils.isEmpty(userGroup.getId())) { return R.fail("id不能为空"); } - List groups = userGroupService.list(new QueryWrapper(). - eq("group_name", userGroup.getGroupName())); - if (ObjectUtil.isNotNull(groups) && groups.size()>1){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("group_name", userGroup.getGroupName()); + queryWrapper.last(" and id != " + userGroup.getId()); + List groups = userGroupService.list(queryWrapper); + if (ObjectUtil.isNotNull(groups) && groups.size()>0){ R.fail("用户组已存在"); } userGroupService.updateById(userGroup); @@ -85,7 +87,7 @@ public class UserGroupController { }*/ - @GetMapping("/list") + @PostMapping("/list") @ApiOperation(value = "用户组列表") @LogAnnotation(title = "用户组管理", action = "获取所有用户组机构") @RequiresPermissions("sys:userGroup:list") diff --git a/src/main/java/com/huoran/iasf/controller/api/TestController.java b/src/main/java/com/huoran/iasf/controller/api/TestController.java deleted file mode 100644 index b4f03b7..0000000 --- a/src/main/java/com/huoran/iasf/controller/api/TestController.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -package com.huoran.iasf.controller.api; - -import com.huoran.iasf.common.utils.R; -import com.huoran.iasf.service.HttpApiSessionService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -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; - - -*/ -/** - * api test示例 - * - * @author cheney - * @version V1.0 - * @date 2020年5月11日 - *//* - -@RestController -@RequestMapping("/app/api") -@Api(tags = "test") -public class TestController { - - @Resource - HttpApiSessionService httpApiSessionService; - - @PostMapping("/login") - @ApiOperation(value = "登录接口") - public R login() { - //TODO 登录 - - //生成token - String token = httpApiSessionService.geneJsonWebToken("123", "测试用户名"); - return R.success(token); - } - - - @GetMapping("/getCurUserInfo") - @ApiOperation(value = "获取当前登录人信息示例") - public R getAppUserInfo() { - //拿userId与userName - String userId = httpApiSessionService.getCurrentUserId(); - String username = httpApiSessionService.getCurrentUsername(); - return R.success(); - } -} -*/ diff --git a/src/main/java/com/huoran/iasf/entity/SysDept.java b/src/main/java/com/huoran/iasf/entity/SysDept.java index 879a929..0ec23c5 100644 --- a/src/main/java/com/huoran/iasf/entity/SysDept.java +++ b/src/main/java/com/huoran/iasf/entity/SysDept.java @@ -25,7 +25,7 @@ public class SysDept implements Serializable { @ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") private String deptNo; - @NotBlank(message = "机构名称不能为空") + @NotBlank(message = "部门名称不能为空") @ApiModelProperty(value = "部门名称") private String name; @@ -43,14 +43,14 @@ public class SysDept implements Serializable { @ApiModelProperty(value = "为了维护更深层级关系") private String relationCode; - @ApiModelProperty(value = "部门经理user_id") +/* @ApiModelProperty(value = "部门经理user_id") private String deptManagerId; @ApiModelProperty(value = "部门经理名称") private String managerName; @ApiModelProperty(value = "部门经理联系电话") - private String phone; + private String phone;*/ @TableField(fill = FieldFill.INSERT) private Date createTime; diff --git a/src/main/java/com/huoran/iasf/entity/SysRole.java b/src/main/java/com/huoran/iasf/entity/SysRole.java index ce5e934..b9aa945 100644 --- a/src/main/java/com/huoran/iasf/entity/SysRole.java +++ b/src/main/java/com/huoran/iasf/entity/SysRole.java @@ -3,8 +3,6 @@ package com.huoran.iasf.entity; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; -import com.huoran.iasf.vo.resp.DeptRespNodeVO; -import com.huoran.iasf.vo.resp.PermissionRespNode; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -54,28 +52,9 @@ public class SysRole extends BaseEntity implements Serializable { @ApiModelProperty(value = "是否删除(1未删除;0已删除)") private Integer deleted; - @TableField(exist = false) - @ApiModelProperty(value = "权限菜单") - private List permissionRespNodes; - - @TableField(exist = false) - @ApiModelProperty(value = "部门列表") - private List deptRespNodes; - -/* @TableField(exist = false) - @ApiModelProperty(value = "开始时间") - private String startTime; - - @TableField(exist = false) - @ApiModelProperty(value = "结束时间") - private String endTime;*/ - @TableField(exist = false) @ApiModelProperty(value = "权限") private List permissions; - @TableField(exist = false) - @ApiModelProperty(value = "部门") - private List depts; } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/entity/SysUser.java b/src/main/java/com/huoran/iasf/entity/SysUser.java index c01d76a..a92e155 100644 --- a/src/main/java/com/huoran/iasf/entity/SysUser.java +++ b/src/main/java/com/huoran/iasf/entity/SysUser.java @@ -33,7 +33,7 @@ public class SysUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "加密盐值") private String salt; - @NotBlank(message = "密码不能为空") + // @NotBlank(message = "密码不能为空") @ApiModelProperty(value = "用户密码") private String password; @@ -48,26 +48,37 @@ public class SysUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "手机号码") private String phone; - @ApiModelProperty(value = "部门id") - private String deptId; + @ApiModelProperty(value = "用户头像路径") + private String userAvatars; - @TableField(exist = false) +/* @TableField(exist = false) @ApiModelProperty(value = "部门名称") private String deptName; @TableField(exist = false) @ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") - private String deptNo; + private String deptNo;*/ + +/* @TableField(exist = false) + @ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") + private String deptNo;*/ @ApiModelProperty(value = "真实名称") private String realName; - @ApiModelProperty(value = "昵称") - private String nickName; + @ApiModelProperty(value = "工号") + private String jobNumber; @ApiModelProperty(value = "邮箱(唯一)") private String email; + @ApiModelProperty(value = "用户组id") + private String groupId; + + @TableField(exist = false) + @ApiModelProperty(value = "用户组名称") + private String groupName; + @ApiModelProperty(value = "账户状态(1.正常 0.锁定 )") private Integer status; @@ -91,6 +102,9 @@ public class SysUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "创建时间") private Date createTime; + @ApiModelProperty(value = "最后登陆时间") + private Date lastLoginTime; + @TableField(fill = FieldFill.INSERT_UPDATE) @ApiModelProperty(value = "更新时间") private Date updateTime; @@ -107,6 +121,10 @@ public class SysUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "角色id") private List roleIds; + @TableField(exist = false) + @ApiModelProperty(value = "组织架构id(多个部门id)") + private List deptArchitectureId; + @TableField(exist = false) @ApiModelProperty("随机数") // @NotNull(message = "随机数不能为空") diff --git a/src/main/java/com/huoran/iasf/entity/UserDept.java b/src/main/java/com/huoran/iasf/entity/UserDept.java new file mode 100644 index 0000000..43cd785 --- /dev/null +++ b/src/main/java/com/huoran/iasf/entity/UserDept.java @@ -0,0 +1,42 @@ +package com.huoran.iasf.entity; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 用户员工部门表 + *

+ * + * @author cheney + * @since 2022-08-15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_user_dept") +@ApiModel(value="UserDept对象", description="用户员工部门表") +public class UserDept implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "用户员工id") + private String userId; + + @ApiModelProperty(value = "部门id") + private String deptId; + + @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) + private Date createTime; + +} diff --git a/src/main/java/com/huoran/iasf/mapper/SysUserMapper.java b/src/main/java/com/huoran/iasf/mapper/SysUserMapper.java index 608aba2..51f2b37 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysUserMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysUserMapper.java @@ -1,7 +1,12 @@ package com.huoran.iasf.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.huoran.iasf.entity.SysUser; +import com.huoran.iasf.vo.req.UserListReq; +import com.huoran.iasf.vo.resp.UserListResp; +import org.apache.ibatis.annotations.Param; /** * 用户 Mapper @@ -11,4 +16,8 @@ import com.huoran.iasf.entity.SysUser; * @date 2022年7月28日 */ public interface SysUserMapper extends BaseMapper { + + IPage userList(Page page,@Param("req") UserListReq userListReq); + + UserListResp detailInfo(String id); } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/UserDeptMapper.java b/src/main/java/com/huoran/iasf/mapper/UserDeptMapper.java new file mode 100644 index 0000000..b174a1c --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/UserDeptMapper.java @@ -0,0 +1,16 @@ +package com.huoran.iasf.mapper; + +import com.huoran.iasf.entity.UserDept; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 用户员工部门表 Mapper 接口 + *

+ * + * @author cheney + * @since 2022-08-15 + */ +public interface UserDeptMapper extends BaseMapper { + +} diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysUserMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysUserMapper.xml new file mode 100644 index 0000000..bbe95ac --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysUserMapper.xml @@ -0,0 +1,149 @@ + + + + + + + + diff --git a/src/main/java/com/huoran/iasf/mapper/xml/UserDeptMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/UserDeptMapper.xml new file mode 100644 index 0000000..35fd249 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/UserDeptMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/huoran/iasf/service/DeptService.java b/src/main/java/com/huoran/iasf/service/DeptService.java index 7a86e24..cdb80dd 100644 --- a/src/main/java/com/huoran/iasf/service/DeptService.java +++ b/src/main/java/com/huoran/iasf/service/DeptService.java @@ -40,8 +40,10 @@ public interface DeptService extends IService { * 部门树形列表 * * @param deptId deptId - * @param disabled 最顶级是否可用 * @return 树形列表 */ - List deptTreeList(String deptId, Boolean disabled); + List deptTreeList(String deptId); + + + boolean checkDeptRepeat(SysDept sysDept); } diff --git a/src/main/java/com/huoran/iasf/service/HttpSessionService.java b/src/main/java/com/huoran/iasf/service/HttpSessionService.java index cc11be1..def61e7 100644 --- a/src/main/java/com/huoran/iasf/service/HttpSessionService.java +++ b/src/main/java/com/huoran/iasf/service/HttpSessionService.java @@ -181,25 +181,25 @@ public class HttpSessionService { * @param userId userId */ public void refreshUerId(String userId) { -// redisService.delKeys(userTokenPrefix + "*#" + userId); - - -// Set keys = redisService.keys("#" + userId); -// //如果修改了角色/权限, 那么刷新权限 -// for (String key : keys) { -// JSONObject redisSession = JSON.parseObject(redisService.get(key)); -// -// List roleNames = getRolesByUserId(userId); -// if (!CollectionUtils.isEmpty(roleNames)) { -// redisSession.put(Constant.ROLES_KEY, roleNames); -// } -// Set permissions = getPermissionsByUserId(userId); -// redisSession.put(Constant.PERMISSIONS_KEY, permissions); -// Long redisTokenKeyExpire = redisService.getExpire(key); -// //刷新token绑定的角色权限 -// redisService.setAndExpire(key, redisSession.toJSONString(), redisTokenKeyExpire); -// -// } + redisService.delKeys(userTokenPrefix + "*#" + userId); + + + Set keys = redisService.keys("#" + userId); + //如果修改了角色/权限, 那么刷新权限 + for (String key : keys) { + JSONObject redisSession = JSON.parseObject(redisService.get(key)); + + List roleNames = getRolesByUserId(userId); + if (!CollectionUtils.isEmpty(roleNames)) { + redisSession.put(Constant.ROLES_KEY, roleNames); + } + Set permissions = getPermissionsByUserId(userId); + redisSession.put(Constant.PERMISSIONS_KEY, permissions); + Long redisTokenKeyExpire = redisService.getExpire(key); + //刷新token绑定的角色权限 + redisService.setAndExpire(key, redisSession.toJSONString(), redisTokenKeyExpire); + + } } /** @@ -208,10 +208,10 @@ public class HttpSessionService { * @param roleId roleId */ public void refreshRolePermission(String roleId) { -// List userIds = userRoleService.getUserIdsByRoleId(roleId); -// if (!CollectionUtils.isEmpty(userIds)) { -// userIds.parallelStream().forEach(this::refreshUerId); -// } + List userIds = userRoleService.getUserIdsByRoleId(roleId); + if (!CollectionUtils.isEmpty(userIds)) { + userIds.parallelStream().forEach(this::refreshUerId); + } } /** @@ -220,10 +220,10 @@ public class HttpSessionService { * @param permissionId permissionId */ public void refreshPermission(String permissionId) { -// List userIds = permissionService.getUserIdsById(permissionId); -// if (!CollectionUtils.isEmpty(userIds)) { -// userIds.parallelStream().forEach(this::refreshUerId); -// } + List userIds = permissionService.getUserIdsById(permissionId); + if (!CollectionUtils.isEmpty(userIds)) { + userIds.parallelStream().forEach(this::refreshUerId); + } } diff --git a/src/main/java/com/huoran/iasf/service/RedisService.java b/src/main/java/com/huoran/iasf/service/RedisService.java index fbe002c..73e4b79 100644 --- a/src/main/java/com/huoran/iasf/service/RedisService.java +++ b/src/main/java/com/huoran/iasf/service/RedisService.java @@ -31,7 +31,7 @@ public class RedisService { public Long getExpire(String key) { if (null == key) { - throw new BusinessException(BaseResponseCode.DATA_ERROR.getCode(), "key or TomeUnit 不能为空"); + throw new BusinessException(BaseResponseCode.KEY_OR_TOMEUNIT); } return redisTemplate.getExpire(key, TimeUnit.SECONDS); } diff --git a/src/main/java/com/huoran/iasf/service/RoleService.java b/src/main/java/com/huoran/iasf/service/RoleService.java index 0904c29..c291f7b 100644 --- a/src/main/java/com/huoran/iasf/service/RoleService.java +++ b/src/main/java/com/huoran/iasf/service/RoleService.java @@ -28,14 +28,6 @@ public interface RoleService extends IService { */ void updateRole(SysRole vo); - /** - * 根据id获取角色详情 - * - * @param id id - * @return SysRole - */ - SysRole detailInfo(String id); - /** * 根据id删除 * @@ -58,4 +50,6 @@ public interface RoleService extends IService { * @return List */ List getRoleNames(String userId); + + boolean checkDeptRepeat(SysRole vo); } diff --git a/src/main/java/com/huoran/iasf/service/SysRoleDeptService.java b/src/main/java/com/huoran/iasf/service/SysRoleDeptService.java deleted file mode 100644 index 07b1f53..0000000 --- a/src/main/java/com/huoran/iasf/service/SysRoleDeptService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.huoran.iasf.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.huoran.iasf.entity.SysRoleDeptEntity; - -/** - * 角色部门 - * - * @author cheney - * @email *****@mail.com - * @date 2020-09-27 17:30:15 - */ -public interface SysRoleDeptService extends IService { - -} - diff --git a/src/main/java/com/huoran/iasf/service/UserDeptService.java b/src/main/java/com/huoran/iasf/service/UserDeptService.java new file mode 100644 index 0000000..b25966b --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/UserDeptService.java @@ -0,0 +1,16 @@ +package com.huoran.iasf.service; + +import com.huoran.iasf.entity.UserDept; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 用户员工部门表 服务类 + *

+ * + * @author cheney + * @since 2022-08-15 + */ +public interface UserDeptService extends IService { + +} diff --git a/src/main/java/com/huoran/iasf/service/UserService.java b/src/main/java/com/huoran/iasf/service/UserService.java index 5949061..bdb47ad 100644 --- a/src/main/java/com/huoran/iasf/service/UserService.java +++ b/src/main/java/com/huoran/iasf/service/UserService.java @@ -1,10 +1,17 @@ package com.huoran.iasf.service; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysUser; +import com.huoran.iasf.vo.req.UserListReq; import com.huoran.iasf.vo.resp.LoginRespVO; +import com.huoran.iasf.vo.resp.UserListResp; import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; /** * 用户 服务类 @@ -40,10 +47,9 @@ public interface UserService extends IService { /** * 分页 * - * @param vo vo * @return IPage */ - IPage pageInfo(SysUser vo); + R pageInfo(UserListReq userListReq); /** * 添加用户 @@ -73,4 +79,12 @@ public interface UserService extends IService { * @param vo vo */ void updateUserInfoMy(SysUser vo); + + UserListResp detailInfo(String id); + + R resetPwd(String userId); + + Map importStaff(MultipartFile file); + + void exportFailureRecord(HttpServletResponse response, String exportCode) throws IOException; } diff --git a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java index 4fc26a3..59de614 100644 --- a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java @@ -1,21 +1,24 @@ package com.huoran.iasf.service.impl; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.entity.SysDept; -import com.huoran.iasf.entity.SysUser; +import com.huoran.iasf.entity.UserDept; import com.huoran.iasf.mapper.SysDeptMapper; import com.huoran.iasf.mapper.SysUserMapper; +import com.huoran.iasf.mapper.UserDeptMapper; import com.huoran.iasf.service.DeptService; import com.huoran.iasf.vo.resp.DeptRespNodeVO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.annotation.Resource; @@ -37,6 +40,8 @@ public class DeptServiceImpl extends ServiceImpl impleme @Resource private SysDeptMapper sysDeptMapper; @Resource + private UserDeptMapper userDeptMapper; + @Resource private SysUserMapper sysUserMapper; @Override @@ -57,6 +62,18 @@ public class DeptServiceImpl extends ServiceImpl impleme sysDeptMapper.insert(vo); } + @Override + public boolean checkDeptRepeat(SysDept sysDept){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("name", sysDept.getName()); + queryWrapper.eq("pid", sysDept.getPid()); + if (StrUtil.isNotEmpty(sysDept.getId())) { + queryWrapper.last(" and id != " + sysDept.getId()); + } + List sysDepts = baseMapper.selectList(queryWrapper); + return sysDepts.size() > 0; + } + @Override @Transactional(rollbackFor = Exception.class) public void updateDept(SysDept vo) { @@ -104,7 +121,11 @@ public class DeptServiceImpl extends ServiceImpl impleme throw new BusinessException(BaseResponseCode.DATA_ERROR); } List deptIds = sysDeptMapper.selectObjs(Wrappers.lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode())); - List list = sysUserMapper.selectList(Wrappers.lambdaQuery().in(SysUser::getDeptId, deptIds)); + /*List list = sysUserMapper.selectList(Wrappers.lambdaQuery().in(SysUser::getDeptId, deptIds)); + if (!CollectionUtils.isEmpty(list)) { + throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); + }*/ + List list = userDeptMapper.selectList(Wrappers.lambdaQuery().in(UserDept::getDeptId, deptIds)); if (!CollectionUtils.isEmpty(list)) { throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); } @@ -112,7 +133,7 @@ public class DeptServiceImpl extends ServiceImpl impleme } @Override - public List deptTreeList(String deptId, Boolean disabled) { + public List deptTreeList(String deptId) { List list; if (StringUtils.isEmpty(deptId)) { list = sysDeptMapper.selectList(Wrappers.emptyWrapper()); @@ -127,10 +148,10 @@ public class DeptServiceImpl extends ServiceImpl impleme } // 默认加一个顶级方便新增顶级部门 DeptRespNodeVO respNodeVO = new DeptRespNodeVO(); - respNodeVO.setTitle("默认顶级部门"); + respNodeVO.setName("默认顶级部门"); respNodeVO.setId("0"); - respNodeVO.setSpread(true); - respNodeVO.setDisabled(disabled); +/* respNodeVO.setSpread(true); + respNodeVO.setDisabled(false);*/ respNodeVO.setChildren(getTree(list)); List result = new ArrayList<>(); result.add(respNodeVO); @@ -143,8 +164,8 @@ public class DeptServiceImpl extends ServiceImpl impleme if ("0".equals(sysDept.getPid())) { DeptRespNodeVO deptTree = new DeptRespNodeVO(); BeanUtils.copyProperties(sysDept, deptTree); - deptTree.setTitle(sysDept.getName()); - deptTree.setSpread(true); + deptTree.setName(sysDept.getName()); + // deptTree.setSpread(true); deptTree.setChildren(getChild(sysDept.getId(), all)); list.add(deptTree); } @@ -158,7 +179,7 @@ public class DeptServiceImpl extends ServiceImpl impleme if (sysDept.getPid().equals(id)) { DeptRespNodeVO deptTree = new DeptRespNodeVO(); BeanUtils.copyProperties(sysDept, deptTree); - deptTree.setTitle(sysDept.getName()); + deptTree.setName(sysDept.getName()); deptTree.setChildren(getChild(sysDept.getId(), all)); list.add(deptTree); } diff --git a/src/main/java/com/huoran/iasf/service/impl/HomeServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/HomeServiceImpl.java deleted file mode 100644 index cb5ba9b..0000000 --- a/src/main/java/com/huoran/iasf/service/impl/HomeServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.huoran.iasf.service.impl; - -import com.huoran.iasf.entity.SysDept; -import com.huoran.iasf.entity.SysUser; -import com.huoran.iasf.service.DeptService; -import com.huoran.iasf.service.HomeService; -import com.huoran.iasf.service.PermissionService; -import com.huoran.iasf.service.UserService; -import com.huoran.iasf.vo.resp.HomeRespVO; -import com.huoran.iasf.vo.resp.PermissionRespNode; -import com.huoran.iasf.vo.resp.UserInfoRespVO; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.List; - -/** - * 首页 - * - * @author cheney - * @version V1.0 - * @date 2022年7月28日 - */ -@Service -public class HomeServiceImpl implements HomeService { - @Resource - private UserService userService; - @Resource - private DeptService deptService; - @Resource - private PermissionService permissionService; - - @Override - public HomeRespVO getHomeInfo(String userId) { - - - SysUser sysUser = userService.getById(userId); - UserInfoRespVO vo = new UserInfoRespVO(); - - if (sysUser != null) { - BeanUtils.copyProperties(sysUser, vo); - SysDept sysDept = deptService.getById(sysUser.getDeptId()); - if (sysDept != null) { - vo.setDeptId(sysDept.getId()); - vo.setDeptName(sysDept.getName()); - } - } - - List menus = permissionService.permissionTreeList(userId); - - HomeRespVO respVO = new HomeRespVO(); - respVO.setMenus(menus); - respVO.setUserInfo(vo); - - return respVO; - } -} diff --git a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java index 7c4024f..c2971a3 100644 --- a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java @@ -163,7 +163,7 @@ public class PermissionServiceImpl extends ServiceImpl impleme @Resource private RolePermissionService rolePermissionService; @Resource - private PermissionService permissionService; - @Resource private HttpSessionService httpSessionService; - @Resource - private DeptService deptService; - @Resource - private SysRoleDeptService sysRoleDeptService; + @Transactional(rollbackFor = Exception.class) @Override @@ -85,33 +79,11 @@ public class RoleServiceImpl extends ServiceImpl impleme } } - @Override - public SysRole detailInfo(String id) { - SysRole sysRole = sysRoleMapper.selectById(id); - if (sysRole == null) { - log.error("传入 的 id:{}不合法", id); - throw new BusinessException(BaseResponseCode.DATA_ERROR); - } - List permissionRespNodes = permissionService.selectAllByTree(); - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId()); - Set checkList = - new HashSet<>(rolePermissionService.listObjs(queryWrapper)); - setChecked(permissionRespNodes, checkList); - sysRole.setPermissionRespNodes(permissionRespNodes); - - LambdaQueryWrapper queryWrapperDept = Wrappers.lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId()); - List deptRespNodes = deptService.deptTreeList(null, true); - Set checkDeptList = - new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept)); - setCheckedDept(deptRespNodes, checkDeptList); - sysRole.setDeptRespNodes(deptRespNodes); - return sysRole; - } private void setCheckedDept(List deptRespNodes, Set checkDeptList) { for (DeptRespNodeVO node : deptRespNodes) { if (checkDeptList.contains(node.getId())) { - node.setChecked(true); + // node.setChecked(true); } setCheckedDept((List) node.getChildren(), checkDeptList); } @@ -163,4 +135,15 @@ public class RoleServiceImpl extends ServiceImpl impleme } return sysRoles.stream().map(SysRole::getName).collect(Collectors.toList()); } + + @Override + public boolean checkDeptRepeat(SysRole vo) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("name", vo.getName()); + if (StrUtil.isNotEmpty(vo.getId())) { + queryWrapper.last(" and id != " + vo.getId()); + } + List sysRoles = baseMapper.selectList(queryWrapper); + return sysRoles.size() > 0; + } } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysDictDetailServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysDictDetailServiceImpl.java index ab539b1..463721c 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysDictDetailServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysDictDetailServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.common.exception.BusinessException; +import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.entity.SysDictDetailEntity; import com.huoran.iasf.entity.SysDictEntity; import com.huoran.iasf.mapper.SysDictDetailMapper; @@ -36,7 +37,7 @@ public class SysDictDetailServiceImpl extends ServiceImpl wrapper = Wrappers.lambdaQuery(); 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 9611d70..bea9c4a 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java @@ -6,6 +6,7 @@ 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; +import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.utils.DateUtils; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysFilesEntity; @@ -46,7 +47,7 @@ public class SysFilesServiceImpl extends ServiceImpl implements SysRoleDeptService { +public class SysRoleDeptServiceImpl extends ServiceImpl implements IService { } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/impl/UserDeptServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/UserDeptServiceImpl.java new file mode 100644 index 0000000..e303ea7 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/impl/UserDeptServiceImpl.java @@ -0,0 +1,20 @@ +package com.huoran.iasf.service.impl; + +import com.huoran.iasf.entity.UserDept; +import com.huoran.iasf.mapper.UserDeptMapper; +import com.huoran.iasf.service.UserDeptService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 用户员工部门表 服务实现类 + *

+ * + * @author cheney + * @since 2022-08-15 + */ +@Service +public class UserDeptServiceImpl extends ServiceImpl implements UserDeptService { + +} diff --git a/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java index 3a9d141..63b3fb3 100644 --- a/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java @@ -1,30 +1,59 @@ package com.huoran.iasf.service.impl; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Maps; import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.code.BaseResponseCode; +import com.huoran.iasf.common.utils.ExcelImportHelper; +import com.huoran.iasf.common.utils.ExcelStyleUtil; import com.huoran.iasf.common.utils.PasswordUtils; -import com.huoran.iasf.entity.SysDept; -import com.huoran.iasf.entity.SysRole; -import com.huoran.iasf.entity.SysUser; +import com.huoran.iasf.common.utils.R; +import com.huoran.iasf.entity.*; import com.huoran.iasf.mapper.SysDeptMapper; import com.huoran.iasf.mapper.SysUserMapper; +import com.huoran.iasf.mapper.UserDeptMapper; +import com.huoran.iasf.mapper.UserGroupMapper; import com.huoran.iasf.service.*; +import com.huoran.iasf.vo.ImportUserFailureVo; +import com.huoran.iasf.vo.req.ExcelImpUserReq; +import com.huoran.iasf.vo.req.UserListReq; import com.huoran.iasf.vo.req.UserRoleOperationReqVO; import com.huoran.iasf.vo.resp.LoginRespVO; +import com.huoran.iasf.vo.resp.PermissionRespNode; +import com.huoran.iasf.vo.resp.UserListResp; import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import java.util.List; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * 用户 服务类 @@ -45,6 +74,9 @@ public class UserServiceImpl extends ServiceImpl impleme private PermissionService permissionService; @Resource private UserRoleService userRoleService; + @Resource + private UserDeptMapper userDeptMapper; + @Resource private SysDeptMapper sysDeptMapper; @Resource @@ -53,6 +85,12 @@ public class UserServiceImpl extends ServiceImpl impleme @Resource private RedisService redisService; + @Resource + private UserGroupMapper userGroupMapper; + + @Resource + StringRedisTemplate stringRedisTemplate; + @Value("${spring.redis.allowMultipleLogin}") private Boolean allowMultipleLogin; @Value("${spring.profiles.active}") @@ -62,7 +100,7 @@ public class UserServiceImpl extends ServiceImpl impleme public void register(SysUser sysUser) { SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername())); if (sysUserOne != null) { - throw new BusinessException("用户名已存在!"); + throw new BusinessException(BaseResponseCode.USERNAME_EXISTS); } sysUser.setSalt(PasswordUtils.getSalt()); String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt()); @@ -85,6 +123,8 @@ public class UserServiceImpl extends ServiceImpl impleme throw new BusinessException(BaseResponseCode.PASSWORD_ERROR); } LoginRespVO respVO = new LoginRespVO(); + sysUser.setLastLoginTime(new Date()); + sysUserMapper.updateById(sysUser); BeanUtils.copyProperties(sysUser, respVO); //是否删除之前token, 此处控制是否支持多登陆端; @@ -92,15 +132,11 @@ public class UserServiceImpl extends ServiceImpl impleme if (!allowMultipleLogin) { httpSessionService.abortUserById(sysUser.getId()); } - if (StringUtils.isNotBlank(sysUser.getDeptId())) { - SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); - if (sysDept != null) { - sysUser.setDeptNo(sysDept.getDeptNo()); - } - } + List menus = permissionService.permissionTreeList(sysUser.getId()); + String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); respVO.setAccessToken(token); - + respVO.setList(menus); return respVO; } @@ -115,11 +151,11 @@ public class UserServiceImpl extends ServiceImpl impleme String value = redisService.get(random); //验证码已过期 if (StringUtils.isEmpty(value)) { - throw new BusinessException(10004, "验证码已过期"); + throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_EXPIRED); } //验证码错误 if (!code.equals(value)) { - throw new BusinessException(10005, "验证码错误"); + throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_ERROR); } redisService.del(random); } @@ -127,7 +163,6 @@ public class UserServiceImpl extends ServiceImpl impleme @Override public void updateUserInfo(SysUser vo) { - SysUser sysUser = sysUserMapper.selectById(vo.getId()); if (null == sysUser) { throw new BusinessException(BaseResponseCode.DATA_ERROR); @@ -137,7 +172,7 @@ public class UserServiceImpl extends ServiceImpl impleme if (!sysUser.getUsername().equals(vo.getUsername())) { SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); if (sysUserOne != null) { - throw new BusinessException("用户名已存在!"); + throw new BusinessException(BaseResponseCode.USERNAME_EXISTS); } } @@ -155,6 +190,30 @@ public class UserServiceImpl extends ServiceImpl impleme } else { vo.setPassword(null); } + //删除所有部门 + userDeptMapper.delete(Wrappers.lambdaQuery().eq(UserDept::getUserId, vo.getId())); + //更新部门 + if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { + List deptArchitectureId = vo.getDeptArchitectureId(); + for (String deptId : deptArchitectureId) { + UserDept userDept = new UserDept(); + userDept.setUserId(vo.getId()); + userDept.setDeptId(deptId); + } + } + + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysUserRole::getUserId, vo.getId()); + userRoleService.remove(queryWrapper); + if (!CollectionUtils.isEmpty(vo.getRoleIds())) { + UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); + reqVO.setUserId(vo.getId()); + reqVO.setRoleIds(vo.getRoleIds()); + userRoleService.addUserRoleInfo(reqVO); + } + //刷新权限 + httpSessionService.refreshUerId(vo.getId()); + vo.setUpdateId(httpSessionService.getCurrentUserId()); sysUserMapper.updateById(vo); @@ -180,55 +239,85 @@ public class UserServiceImpl extends ServiceImpl impleme } @Override - public IPage pageInfo(SysUser vo) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + public UserListResp detailInfo(String id) { + return baseMapper.detailInfo(id); + } + + @Override + public R resetPwd(String userId) { + SysUser sysUser = baseMapper.selectById(userId); + sysUser.setSalt(PasswordUtils.getSalt()); + String encode = PasswordUtils.encode("111aaa", sysUser.getSalt()); + sysUser.setPassword(encode); + int update = baseMapper.updateById(sysUser); + return update>0 ? R.success("重置成功") : R.fail("重置失败"); + } + + @Override + public R pageInfo(UserListReq userListReq) { + /*LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); if (!StringUtils.isEmpty(vo.getUsername())) { queryWrapper.like(SysUser::getUsername, vo.getUsername()); } -/* if (!StringUtils.isEmpty(vo.getStartTime())) { +*//* if (!StringUtils.isEmpty(vo.getStartTime())) { queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime()); } if (!StringUtils.isEmpty(vo.getEndTime())) { queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime()); - }*/ - if (!StringUtils.isEmpty(vo.getNickName())) { + }*//* +*//* if (!StringUtils.isEmpty(vo.getNickName())) { queryWrapper.like(SysUser::getNickName, vo.getNickName()); - } + }*//* if (null != vo.getStatus()) { queryWrapper.eq(SysUser::getStatus, vo.getStatus()); } - if (!StringUtils.isEmpty(vo.getDeptNo())) { - LambdaQueryWrapper queryWrapperDept = Wrappers.lambdaQuery(); - queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo()); - List list = sysDeptMapper.selectObjs(queryWrapperDept); - queryWrapper.in(SysUser::getDeptId, list); - } + // if (!StringUtils.isEmpty(vo.getDeptNo())) { + // LambdaQueryWrapper queryWrapperDept = Wrappers.lambdaQuery(); + // queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo()); + // List list = sysDeptMapper.selectObjs(queryWrapperDept); + // queryWrapper.in(SysUser::getDeptId, list); + // } queryWrapper.orderByDesc(SysUser::getCreateTime); IPage iPage = sysUserMapper.selectPage(vo.getQueryPage(), queryWrapper); if (!CollectionUtils.isEmpty(iPage.getRecords())) { for (SysUser sysUser : iPage.getRecords()) { - SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); + *//*SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); if (sysDept != null) { sysUser.setDeptName(sysDept.getName()); - } + }*//* } + }*/ + //查询未加入部门的员工,部门id一定清空 + if (userListReq.getType()==2){ + userListReq.setDeptArchitectureId(null); } - return iPage; + + Page page = new Page(userListReq.getPageNum(), userListReq.getPageSize()); + IPage userList = baseMapper.userList(page, userListReq); + return R.success(userList); } @Override public void addUser(SysUser vo) { - SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); - if (sysUserOne != null) { - throw new BusinessException("用户已存在,请勿重复添加!"); - } vo.setSalt(PasswordUtils.getSalt()); - String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt()); + String encode = PasswordUtils.encode("111aaa", vo.getSalt()); vo.setPassword(encode); vo.setStatus(1); vo.setCreateWhere(1); sysUserMapper.insert(vo); + + if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) { + List deptArchitectureId = vo.getDeptArchitectureId(); + for (String deptId : deptArchitectureId) { + UserDept userDept = new UserDept(); + userDept.setUserId(vo.getId()); + userDept.setDeptId(deptId); + userDeptMapper.insert(userDept); + } + } + + //用户账号赋予角色 if (!CollectionUtils.isEmpty(vo.getRoleIds())) { UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); reqVO.setUserId(vo.getId()); @@ -252,7 +341,7 @@ public class UserServiceImpl extends ServiceImpl impleme throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR); } if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) { - throw new BusinessException("新密码不能与旧密码相同"); + throw new BusinessException(BaseResponseCode.CANNOT_SAME); } sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt())); sysUserMapper.updateById(sysUser); @@ -270,4 +359,541 @@ public class UserServiceImpl extends ServiceImpl impleme vo.setOwnRoles(roleIdsByUserId); return vo; } + + @Override + @Transactional + public Map importStaff(MultipartFile file) { + List impStaffReqList = ExcelImportHelper.readUser(file); + if (impStaffReqList.size() <= 0) { + //小于等于0为上传空模板的情况下 抛出异常 + throw new BusinessException(BaseResponseCode.EXCEL_FILE_FORMAT_ERROR); + } + int count = 0; + List failVo1 = new ArrayList(); + // 参数合法性校验,只能上传.xlsx后缀的文件 + if (org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename()) + || !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(".xlsx")) { + throw new BusinessException(BaseResponseCode.EXCEL_FILE_INVALID); + } + int size = impStaffReqList.size(); + Map map = new HashMap<>(); + Long ii = 1L;//用于记录序列号 + Integer countNum = 0;//用于失败原因排序 eg:1、XXXXX 2、XXXXXXX + try { + Integer countSuccess = 0;//统计成功次数 + Integer countError = 0;//统计失败次数 + + List workNumberList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有学号用于excel中的数据判重 + List accountList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有账号用于excel中的数据判重 + for (int i = 0; i < impStaffReqList.size(); i++) { + boolean ret = true; + ++ii; + ExcelImpUserReq req = impStaffReqList.get(i); + + ImportUserFailureVo vo1 = new ImportUserFailureVo(); + + String errMsg = ""; + //去除Excel中的全角半角空格 + String realName = req.getRealName().replaceAll("\\u00A0", "").trim(); + String username = req.getUserName().replaceAll("\\u00A0", "").trim(); + String getRoleName = req.getRoleName().replaceAll("\\u00A0", "").trim(); + String jobNumber = req.getJobNumber().replaceAll("\\u00A0", "").trim(); + String dept = req.getDept().replaceAll("\\u00A0", "").trim(); + String getPhone = req.getPhone().replaceAll("\\u00A0", "").trim(); + String getEmail = req.getEmail().replaceAll("\\u00A0", "").trim(); + String groupName = req.getGroupName().replaceAll("\\u00A0", "").trim(); + + if (!workNumberList.contains(req.getJobNumber())) { + workNumberList.add(req.getJobNumber()); + } else { + //包含excel数据中存在相同学号 + ++countNum; + vo1.setJobNumber(jobNumber + " *必填项:(当前Excel数据中该工号已存在重复的!)"); + errMsg += countNum + " *必填项:(当前Excel数据中该工号号已存在重复的)"; + ret = false; + } + + if (!accountList.contains(req.getUserName())) { + accountList.add(req.getUserName()); + } else { + //包含excel数据中存在相同账号 + ++countNum; + vo1.setUserName(username + " *必填项:(当前Excel数据中该账号已存在重复的)"); + errMsg += countNum + " *必填项:(当前Excel数据中该账号已存在重复的)"; + ret = false; + } + + //账号id + String usernameId = "0"; + + vo1.setIndex(ii); + //检验姓名 + if ("".equals(realName)) { + ++countNum; + vo1.setUserName(realName + " *必填项:(姓名不能为空) "); + errMsg += countNum + "必填项:(姓名不能为空)"; + ret = false; + } else { + vo1.setUserName(realName); + } + //检验账号 + if ("".equals(username)) { + ++countNum; + vo1.setUserName(username + " *必填项:(账号不能为空)"); + errMsg += countNum + " *必填项:(账号不能为空)"; + ret = false; + } else { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysUser::getUsername, username); + SysUser selectOne = baseMapper.selectOne(queryWrapper); + //账号存在,验证该账号相关信息 + if (ObjectUtil.isNotNull(selectOne)) { + if (username.equals(selectOne.getUsername())&&jobNumber.equals(selectOne.getJobNumber())){ + usernameId=selectOne.getId(); + }else { + ++countNum; + vo1.setUserName(username + " *必填项:(账号已有重复的)"); + errMsg += countNum + " *必填项:(账号已有重复的)"; + ret = false; + } + } else { + vo1.setUserName(username + ""); + } + } + + List roleIds = new ArrayList<>(); + + //检验角色 + if ("".equals(getRoleName)) { + ++countNum; + vo1.setRoleName(getRoleName + " *必填项:(角色不能为空)"); + errMsg += countNum + " *必填项:(角色不能为空)"; + ret = false; + } else { + //分隔多个角色 + String[] roleNames = getRoleName.split("/"); + for (int r = 0; r < roleNames.length; r++) { + // 查询多个角色是否存在 + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysRole::getName, roleNames[r]); + SysRole role = roleService.getOne(queryWrapper); + if (role != null && !"超级管理员".equals(role.getName())) { + roleIds.add(role.getId()); + //存在 + vo1.setRoleName(getRoleName); + } else { + //不存在 + vo1.setRoleName(getRoleName + " *必填项:(请输入系统中存在的角色)"); + errMsg += countNum + " *必填项:(请输入系统中存在的角色)"; + ret = false; + } + } + + } + + //检验工号 + if ("".equals(jobNumber)) { + ++countNum; + vo1.setJobNumber(jobNumber + " *必填项:(工号不能为空)"); + errMsg += countNum + " *必填项:(工号不能为空)"; + ret = false; + } else { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysUser::getJobNumber, jobNumber); + SysUser selectOne = baseMapper.selectOne(queryWrapper); + if (ObjectUtil.isNotNull(selectOne)) { + ++countNum; + vo1.setJobNumber(jobNumber + " *必填项:(工号已经存在重复的)"); + errMsg += countNum + " *必填项:(工号已经存在重复的)"; + ret = false; + } else { + vo1.setJobNumber(jobNumber + ""); + } + } + + Integer groupId = 0; + //检验用户组 + if (!"".equals(groupName)) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(UserGroup::getGroupName, groupName); + UserGroup userGroup1 = userGroupMapper.selectOne(queryWrapper); + if (ObjectUtil.isNotNull(userGroup1)) { + groupId=userGroup1.getId(); + }else { + UserGroup userGroup = new UserGroup(); + userGroup.setGroupName(groupName); + int insert = userGroupMapper.insert(userGroup); + groupId=userGroup.getId(); + } + } + + if (!"".equals(getPhone)) { + //校验手机号格式 + if (!validPhoneNum("0", getPhone)) { + ++countNum; + vo1.setPhone(getPhone + " *请输入正确的手机号!"); + errMsg += countNum + " *请输入正确的手机号!"; + ret = false; + } else { + //用户账号存在,手机号邮箱则跳过效验 + if ("0".equals(usernameId)){ + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysUser::getPhone, getPhone); + SysUser selectOne = baseMapper.selectOne(queryWrapper); + if (ObjectUtil.isNotNull(selectOne)) { + ++countNum; + vo1.setPhone(getPhone + " *该手机号已被绑定!"); + errMsg += countNum + " *该手机号已被绑定!"; + ret = false; + } + vo1.setPhone(getPhone); + } + } + + } else { + vo1.setPhone(getPhone); + } + + if (!"".equals(getEmail)) { + //校验邮箱格式 + if (!isValidEmail(getEmail)) { + ++countNum; + vo1.setEmail(getEmail + "*请输入正确的邮箱格式!"); + errMsg += countNum + " *请输入正确的邮箱格式!"; + ret = false; + } else { + if ("0".equals(usernameId)){ + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(SysUser::getEmail, getEmail); + SysUser selectOne = baseMapper.selectOne(queryWrapper); + if (ObjectUtil.isNotNull(selectOne)) { + ++countNum; + vo1.setEmail(getEmail + " *该邮箱已被绑定!"); + errMsg += countNum + " *该邮箱已被绑定!"; + ret = false; + } + vo1.setEmail(getEmail); + } + } + + } else { + vo1.setEmail(getEmail); + } + + ArrayList architectureIds = new ArrayList<>(); + //检验所在部门 + if ("".equals(dept)) { + ++countNum; + vo1.setDept(dept + " *必填项:(请输入正确的员工架构!)"); + errMsg += countNum + " *必填项:(请输入正确的员工架构!)"; + ret = false; + } else { + if (ret){ + //检验是否有多部门 + String[] multi = dept.split(","); + //多部门进行循环添加每个部门 + if (multi.length>1){ + for (int d = 0; d < multi.length; d++) { + HashMap hashMap = automaticAddArchitecture(multi[d], countNum, dept, vo1); + + Object countNum1 = hashMap.get("countNum"); + //存在错误数据 + if (countNum1!=null){ + countNum = (Integer) countNum1; + Object vo11 = hashMap.get("vo1"); + vo1 = (ImportUserFailureVo) vo11; + Object errMsg1 = hashMap.get("errMsg"); + errMsg = (String) errMsg1; + Object ret1 = hashMap.get("ret"); + ret = (boolean) ret1; + }else { + //保存架构id + Object architectureId = hashMap.get("architectureId"); + String id = "0"; + if (architectureId!=null){ + id = (String) architectureId; + architectureIds.add(id); + } + } + } + + }else{ + HashMap hashMap = automaticAddArchitecture(dept, countNum, dept, vo1); + + Object countNum1 = hashMap.get("countNum"); + //存在错误数据 + if (countNum1!=null){ + countNum = (Integer) countNum1; + Object vo11 = hashMap.get("vo1"); + vo1 = (ImportUserFailureVo) vo11; + Object errMsg1 = hashMap.get("errMsg"); + errMsg = (String) errMsg1; + Object ret1 = hashMap.get("ret"); + ret = (boolean) ret1; + }else { + //保存架构id + Object architectureId = hashMap.get("architectureId"); + String id = "0"; + if (architectureId!=null){ + id = (String) architectureId; + architectureIds.add(id); + } + } + } + } + } + + vo1.setFailureMsg(errMsg); + countNum = 0; + + failVo1.add(vo1); + + //ret判断 新增成功的插入到数据库 否则则不新增至数据库 + if (ret) { + //用户账号不存在 + if ("0".equals(usernameId)){ + SysUser vo = new SysUser(); + vo.setSalt(PasswordUtils.getSalt()); + String encode = PasswordUtils.encode("111aaa", vo.getSalt()); + vo.setPassword(encode); + vo.setStatus(1); + vo.setCreateWhere(1); + if (groupId!=0){ + vo.setGroupId(groupId.toString()); + } + sysUserMapper.insert(vo); + + if (!CollectionUtils.isEmpty(architectureIds)) { + for (String deptId : architectureIds) { + UserDept userDept = new UserDept(); + userDept.setUserId(vo.getId()); + userDept.setDeptId(deptId); + userDeptMapper.insert(userDept); + } + } + + //用户账号赋予角色 + UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); + reqVO.setUserId(vo.getId()); + reqVO.setRoleIds(roleIds); + userRoleService.addUserRoleInfo(reqVO); + + }else { + //导入新部门、赋予新角色 + List userDepts = userDeptMapper. + selectList(new QueryWrapper().eq("user_id", usernameId)); + + ArrayList staffDepartmentIds = new ArrayList<>(); + for ( UserDept userDept : userDepts) { + staffDepartmentIds.add(userDept.getDeptId()); + } + for (String architectureId : architectureIds) { + if (!staffDepartmentIds.contains(architectureId)){ + UserDept userDept = new UserDept(); + userDept.setUserId(usernameId); + userDept.setDeptId(architectureId); + userDeptMapper.insert(userDept); + } + } + + //用户账号赋予角色 + UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); + reqVO.setUserId(usernameId); + reqVO.setRoleIds(roleIds); + userRoleService.addUserRoleInfo(reqVO); + + } + //countSuccess:统计累计成功次数 + countSuccess++; + } else { + //countError:累计失败次数 + countError++; + } + } + String exportCode = ""; + + // 有导入失败的数据,才会存入redis + if (countError > 0) { + //生成token + exportCode = "FAILURE_IMPORT" + UUID.randomUUID().toString().replace("-", ""); + ValueOperations ops = stringRedisTemplate.opsForValue(); + + List collect = failVo1.stream().filter(importStaffFailureVo -> { + return !importStaffFailureVo.getFailureMsg().equals(""); + }).collect(Collectors.toList()); + + String failureVOJson = JSON.toJSONString(collect); + ops.set(exportCode, failureVOJson, 30 * 60, TimeUnit.SECONDS); + } + map.put("exportCode", exportCode);//返回导出code + map.put("successNum", countSuccess + "");//本次新增成功数量 + map.put("failureNum", countError + "");//本次新增失败数量 + return map; + } catch (RuntimeException e) { + System.err.println(e.getMessage()); + throw new RuntimeException(); + } + } + + /** + * 组织架构判重,返回下一层级的父id + * + */ + public String checkArchitectureRepeat(String name ,String pid){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("name",name).eq("pid",pid); + SysDept sysDept = sysDeptMapper.selectOne(queryWrapper); + if (sysDept!=null){ + return sysDept.getId(); + } + return null; + } + + /** + * 根据导入部门自动添加组织架构 + */ + public HashMap automaticAddArchitecture(String architectureName,Integer countNum, + String dept,ImportUserFailureVo vo1){ + HashMap map = Maps.newHashMap(); + //获取部门层级 + String[] split = architectureName.split("/"); + if (split.length>6){ + map.put("countNum",++countNum); + map.put("vo1",vo1.setDept(dept + " 员工架构暂不支持第7层级")); + map.put("errMsg",countNum + " 员工架构暂不支持第7层级"); + map.put("ret",false); + return map; + } + // 检验输入的一级部门是否存在 + //查询一级部门信息 + QueryWrapper queryWrapper1 = new QueryWrapper<>(); + queryWrapper1.eq("name", split[0]); + SysDept sysDept = sysDeptMapper.selectOne(queryWrapper1); + if (sysDept == null) { + //为空表示不存在该部门,一级部门不存在,表示子级部门都能直接新增,达底端返回部门id + String pid = "0"; + for (int j = 0; j < split.length; j++) { + SysDept sysDept1 = new SysDept(); + sysDept1.setName(split[j]); + sysDept1.setPid(pid); + int insert = sysDeptMapper.insert(sysDept1); + //添加成功后id赋值给下一层级父id + if (insert>0){ + pid = sysDept1.getId(); + } + //最后返回部门id + if (split.length-1==j){ + map.put("architectureId",pid); + } + } + } else { + String nextLevelPid = sysDept.getId(); + //存在一级部门,循环查询下一层级,存在则继续向下判断,否则进行新增,到达底端返回部门id + int pid = 1; + for (int j = 1; j < split.length; j++) { + String nextPid = checkArchitectureRepeat(split[j],nextLevelPid); + //都存在,最后一次循环返回部门id + if (split.length-1==j){ + map.put("architectureId",nextPid); + } + //层级已存在,进入下次循环 + if (nextPid!=null){ + nextLevelPid = nextPid; + continue; + } + //该层级不存在,进行新增 + SysDept sysDept1 = new SysDept(); + sysDept1.setName(split[j]); + sysDept1.setPid(nextLevelPid); + int insert = sysDeptMapper.insert(sysDept1); + //添加成功后id赋值给下一层级父id + if (insert>0){ + nextLevelPid = sysDept1.getId(); + } + //最后返回部门id + if (split.length-1==j){ + map.put("architectureId",nextLevelPid); + } + } + } + return map; + } + + /** + * @Description : 校验手机号 + * @Param checkType 校验类型:0校验手机号码,1校验座机号码,2两者都校验满足其一就可 + * @Param phoneNum + * @Author Rong---2021/10/18 + */ + public static boolean validPhoneNum(String checkType, String phoneNum) { + boolean flag = false; + Pattern p1 = null; + Pattern p2 = null; + Matcher m = null; + p1 = Pattern.compile("^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\\d{8})?$"); + p2 = Pattern.compile("^(0[0-9]{2,3}\\-)?([1-9][0-9]{6,7})$"); + if ("0".equals(checkType)) { + System.out.println(phoneNum.length()); + if (phoneNum.length() != 11) { + return false; + } else { + m = p1.matcher(phoneNum); + flag = m.matches(); + } + } else if ("1".equals(checkType)) { + if (phoneNum.length() < 11 || phoneNum.length() >= 16) { + return false; + } else { + m = p2.matcher(phoneNum); + flag = m.matches(); + } + } else if ("2".equals(checkType)) { + if (!((phoneNum.length() == 11 && p1.matcher(phoneNum).matches()) || (phoneNum.length() < 16 && p2.matcher(phoneNum).matches()))) { + return false; + } else { + flag = true; + } + } + return flag; + } + + /** + * @Description : 校验邮箱 + * @Param email + * @Author Rong---2021/10/18 + */ + public static boolean isValidEmail(String email) { + if ((email != null) && (!email.isEmpty())) { + return Pattern.matches("^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$", email); + } + return false; + } + + @Override + public void exportFailureRecord(HttpServletResponse response, String token) throws IOException { + if (StringUtils.isEmpty(token)) { + return; + } + ValueOperations ops = stringRedisTemplate.opsForValue(); + //获取数据 + String record = ops.get(token); + if (StringUtils.isEmpty(record)) { + return; + } + List parse = JSON.parseObject(record, new TypeReference>() { + }); + + parse.sort(Comparator.comparing(ImportUserFailureVo::getIndex)); + + // 告诉浏览器用什么软件可以打开此文件 + response.setHeader("content-Type", "application/vnd.ms-excel"); + // 下载文件的默认名称 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("员工导入失败数据表", "UTF-8") + ".xls"); + //编码 + response.setCharacterEncoding("UTF-8"); + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ImportUserFailureVo.class, parse); + ExportParams exportParams = new ExportParams(null, "delivery", ExcelType.XSSF); + exportParams.setStyle(ExcelStyleUtil.class); + workbook.write(response.getOutputStream()); + } } diff --git a/src/main/java/com/huoran/iasf/vo/ImportUserFailureVo.java b/src/main/java/com/huoran/iasf/vo/ImportUserFailureVo.java new file mode 100644 index 0000000..a92fa7f --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/ImportUserFailureVo.java @@ -0,0 +1,55 @@ +package com.huoran.iasf.vo; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.afterturn.easypoi.excel.annotation.ExcelTarget; +import com.huoran.iasf.common.utils.ExcelAttribute; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@ToString +@Accessors(chain = true) +@ExcelTarget("ImportStaffFailureVo") +public class ImportUserFailureVo { + + //第几行 + private Long index; + + @Excel(name = "姓名", orderNum = "1", isImportField = "id", width = 30) + @ApiModelProperty(value = "姓名") + private String realName; + + @ApiModelProperty(value = "账号") + @Excel(name = "账号", orderNum = "2", mergeVertical = false, isImportField = "account", width = 30) + private String userName; + + @ApiModelProperty(value = "角色") + @Excel(name = "角色", orderNum = "3", isImportField = "roleName", width = 30) + private String roleName; + + @ApiModelProperty(value = "工号") + @Excel(name = "工号", orderNum = "4", isImportField = "workNumber", width = 30) + private String jobNumber; + + @ApiModelProperty(value = "所在部门") + @Excel(name = "所在部门", orderNum = "5", isImportField = "dept", width = 30) + private String dept; + + @ApiModelProperty(value = "手机号码") + @Excel(name = "手机号码", orderNum = "6", isImportField = "phone", width = 20) + private String phone; + + @ApiModelProperty(value = "邮箱") + @Excel(name = "邮箱", orderNum = "7", isImportField = "email", width = 20) + private String email; + + @ApiModelProperty(value = "用户组") + @Excel(name = "用户组", orderNum = "8", isImportField = "groupName", width = 20) + private String groupName; + + @ExcelAttribute(sort = 9) + @Excel(name = "失败原因", orderNum = "9", isImportField = "failureMsg", width = 50) + private String failureMsg; +} diff --git a/src/main/java/com/huoran/iasf/vo/req/ExcelImpUserReq.java b/src/main/java/com/huoran/iasf/vo/req/ExcelImpUserReq.java new file mode 100644 index 0000000..9511862 --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/req/ExcelImpUserReq.java @@ -0,0 +1,45 @@ +package com.huoran.iasf.vo.req; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @Author chen + * @DATE 2022/8/15 17:20 + * @Version 1.0 + */ +@Data +@ApiModel(value = "批量导入用户数据") +public class ExcelImpUserReq { + + @ApiModelProperty(value = "姓名") + @NotNull(message = "姓名不能为空!") + private String realName; + + @NotNull(message = "账号不能为空!") + @ApiModelProperty(value = "账号") + private String userName; + + @ApiModelProperty(value = "角色") + @NotNull(message = "角色不能为空!") + private String roleName; + + @ApiModelProperty(value = "工号") + @NotNull(message = "工号不能为空!") + private String jobNumber; + + @ApiModelProperty(value = "所在部门") + private String dept; + + @ApiModelProperty(value = "手机号码") + private String phone; + + @ApiModelProperty(value = "邮箱") + private String email; + + @ApiModelProperty(value = "用户组") + private String groupName; +} diff --git a/src/main/java/com/huoran/iasf/vo/req/UserListReq.java b/src/main/java/com/huoran/iasf/vo/req/UserListReq.java new file mode 100644 index 0000000..c7e78f3 --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/req/UserListReq.java @@ -0,0 +1,28 @@ +package com.huoran.iasf.vo.req; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Author chen + * @DATE 2022/8/15 15:27 + * @Version 1.0 + */ +@Data +public class UserListReq { + + @ApiModelProperty(value = "类型:必填一个(1.所有员工 2.未加入部门的员工)", required = true, example = "1") + private Integer type; + + @ApiModelProperty(value = "搜索关键词", example = "1") + private String keyWord; + + @ApiModelProperty(value = "员工部门主键ID", example = "2") + private String deptArchitectureId; + + @ApiModelProperty(value = "当前页数", name = "pageNum", example = "1", required = true) + private Integer pageNum; + + @ApiModelProperty(value = "当前页需要显示的数量", name = "pageSize", example = "10", required = true) + private Integer pageSize; +} diff --git a/src/main/java/com/huoran/iasf/vo/resp/DeptRespNodeVO.java b/src/main/java/com/huoran/iasf/vo/resp/DeptRespNodeVO.java index e9ee4a5..5e46a66 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/DeptRespNodeVO.java +++ b/src/main/java/com/huoran/iasf/vo/resp/DeptRespNodeVO.java @@ -20,11 +20,11 @@ public class DeptRespNodeVO { @ApiModelProperty(value = "组织编码") private String deptNo; - @ApiModelProperty(value = "组织名称") - private String title; + @ApiModelProperty(value = "部门名称") + private String name; - @ApiModelProperty(value = "组织名称") - private String label; + // @ApiModelProperty(value = "组织名称") + // private String label; @ApiModelProperty(value = "组织父级id") private String pid; @@ -35,19 +35,19 @@ public class DeptRespNodeVO { @ApiModelProperty(value = "组织关系id") private String relationCode; - @ApiModelProperty(value = "是否展开 默认不展开(false)") +/* @ApiModelProperty(value = "是否展开 默认不展开(false)") private boolean spread = true; @ApiModelProperty(value = "是否选中") private boolean checked = false; - private boolean disabled = false; + private boolean disabled = false;*/ @ApiModelProperty(value = "子集") private List children; - public String getLabel() { - return title; - } + // public String getLabel() { + // return title; + // } } diff --git a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java index b7593f0..d317938 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java +++ b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java @@ -16,8 +16,9 @@ import java.util.List; public class PermissionRespNode { @ApiModelProperty(value = "id") private String id; + @ApiModelProperty(value = "菜单权限名称") - private String title; + private String name; @ApiModelProperty(value = "菜单权限标识,shiro 适配restful") private String perms; diff --git a/src/main/java/com/huoran/iasf/vo/resp/UserListResp.java b/src/main/java/com/huoran/iasf/vo/resp/UserListResp.java new file mode 100644 index 0000000..f8b957e --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/resp/UserListResp.java @@ -0,0 +1,65 @@ +package com.huoran.iasf.vo.resp; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * @Author chen + * @DATE 2022/8/15 15:34 + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "UserListResp", description = "用户列表") +public class UserListResp { + + @ApiModelProperty(value = "组织架构ID") + private String deptArchitectureId; + + @ApiModelProperty(value = "组织架构名称(部门名称)") + private String deptArchitectureName; + + @ApiModelProperty(value = "用户组id") + private String groupId; + + @ApiModelProperty(value = "用户组名称") + private String groupName; + + @ApiModelProperty(value = "职工姓名") + private String realName; + + @ApiModelProperty(value = "账户状态(1.正常 0.锁定 )") + private Integer status; + + @ApiModelProperty(value = "工号") + private String jobNumber; + + @ApiModelProperty(value = "电话") + private String phone; + + @ApiModelProperty(value = "邮箱") + private String email; + + //用于列表逗号隔开展示 + @ApiModelProperty(value = "角色") + private String roleName; + + @ApiModelProperty(value = "角色id") + private String roleId; + + @ApiModelProperty(value = "账号") + private String username; + + @ApiModelProperty(value = "用户id") + private String id; + + @ApiModelProperty(value = "创建时间") + private String createTime; + + @ApiModelProperty(value = "最后登陆时间") + private String lastLoginTime; +} diff --git a/src/test/java/com/company/project/CodeGenerator.java b/src/test/java/com/company/project/CodeGenerator.java index 28bac19..ceba114 100644 --- a/src/test/java/com/company/project/CodeGenerator.java +++ b/src/test/java/com/company/project/CodeGenerator.java @@ -61,7 +61,7 @@ public class CodeGenerator { // 5、策略配置 StrategyConfig strategy = new StrategyConfig(); - strategy.setInclude("sys_user_group"); + strategy.setInclude("sys_user_dept"); strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀 From e6fc950c7b45c35bcd723ebafa24f7913c2e3096 Mon Sep 17 00:00:00 2001 From: chen <1251790704@qq.com> Date: Wed, 17 Aug 2022 16:01:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9D=83=E9=99=90=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iasf/controller/PermissionController.java | 8 +-- .../com/huoran/iasf/entity/SysPermission.java | 9 +++- .../iasf/service/PermissionService.java | 2 +- .../service/impl/PermissionServiceImpl.java | 50 +++++++++++++++++-- .../iasf/service/impl/RoleServiceImpl.java | 2 +- .../iasf/vo/resp/PermissionRespNode.java | 23 ++++----- 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/huoran/iasf/controller/PermissionController.java b/src/main/java/com/huoran/iasf/controller/PermissionController.java index 02246ea..af4bf09 100644 --- a/src/main/java/com/huoran/iasf/controller/PermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/PermissionController.java @@ -51,7 +51,7 @@ public class PermissionController { return R.success(); } - @PutMapping("/permission") +/* @PutMapping("/permission") @ApiOperation(value = "更新菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "更新菜单权限") @RequiresPermissions("sys:permission:update") @@ -69,15 +69,15 @@ public class PermissionController { } permissionService.updatePermission(vo); return R.success(); - } + }*/ - @GetMapping("/permission/{id}") +/* @GetMapping("/permission/{id}") @ApiOperation(value = "查询菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "查询菜单权限") @RequiresPermissions("sys:permission:detail") public R detailInfo(@PathVariable("id") String id) { return R.success(permissionService.getById(id)); - } + }*/ /*@GetMapping("/permissions") @ApiOperation(value = "获取所有菜单权限接口") diff --git a/src/main/java/com/huoran/iasf/entity/SysPermission.java b/src/main/java/com/huoran/iasf/entity/SysPermission.java index cdef760..3fb88a2 100644 --- a/src/main/java/com/huoran/iasf/entity/SysPermission.java +++ b/src/main/java/com/huoran/iasf/entity/SysPermission.java @@ -10,6 +10,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 权限菜单 @@ -63,8 +64,12 @@ public class SysPermission implements Serializable { @TableField(fill = FieldFill.INSERT) private Integer deleted; + @ApiModelProperty(value = "层级") @TableField(exist = false) - @ApiModelProperty(value = "父级菜单权限名称") - private String pidName; + private Integer level; + + @ApiModelProperty(value = "下级") + @TableField(exist = false) + private List children; } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/PermissionService.java b/src/main/java/com/huoran/iasf/service/PermissionService.java index 6a5d4bf..87e76e1 100644 --- a/src/main/java/com/huoran/iasf/service/PermissionService.java +++ b/src/main/java/com/huoran/iasf/service/PermissionService.java @@ -59,7 +59,7 @@ public interface PermissionService extends IService { * * @return List */ - List selectAllByTree(); + List selectAllByTree(); /** * 根据目录树 diff --git a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java index c2971a3..dd700db 100644 --- a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java @@ -114,7 +114,7 @@ public class PermissionServiceImpl extends ServiceImpl selectAllByTree() { + public List selectAllByTree() { - List list = selectAll(); - return getTree(list, false); + // List list = selectAll(); + // return getTree(list, false); + + List permissionList = baseMapper.selectList(null); + return build(permissionList); + } + + /** + * 使用递归方法建菜单 + * @param treeNodes 权限菜单 + * @return 权限菜单 + */ + private static List build(List treeNodes) { + List trees = new ArrayList<>(); + for (SysPermission treeNode : treeNodes) { + if ("0".equals(treeNode.getPid())) { + treeNode.setLevel(1); + trees.add(findChildren(treeNode,treeNodes)); + } + } + return trees; + } + + /** + * 递归查找子节点 + * @param treeNodes 权限子菜单 + * @return 权限子菜单 + */ + private static SysPermission findChildren(SysPermission treeNode,List treeNodes) { + treeNode.setChildren(new ArrayList()); + + for (SysPermission it : treeNodes) { + if(treeNode.getId().equals(it.getPid())) { + int level = treeNode.getLevel() + 1; + it.setLevel(level); + if (treeNode.getChildren() == null) { + treeNode.setChildren(new ArrayList<>()); + } + treeNode.getChildren().add(findChildren(it,treeNodes)); + } + } + return treeNode; } /** @@ -247,7 +287,7 @@ public class PermissionServiceImpl extends ServiceImpl impleme for (PermissionRespNode node : list) { if (checkList.contains(node.getId()) && CollectionUtils.isEmpty(node.getChildren())) { - node.setChecked(true); + // node.setChecked(true); } setChecked((List) node.getChildren(), checkList); } diff --git a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java index d317938..5f3c667 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java +++ b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java @@ -26,28 +26,23 @@ public class PermissionRespNode { @ApiModelProperty(value = "接口地址") private String url; - @ApiModelProperty(value = "icon") - private String icon; +/* @ApiModelProperty(value = "icon") + private String icon;*/ - private String target; + // private String target; @ApiModelProperty(value = "父级id") private String pid; - @ApiModelProperty(value = "父级名称") - private String pidName; + // @ApiModelProperty(value = "父级名称") + // private String pidName; - @ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") - private Integer type; +/* @ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") + private Integer type;*/ - @ApiModelProperty(value = "排序码") - private Integer orderNum; +/* @ApiModelProperty(value = "排序码") + private Integer orderNum;*/ - @ApiModelProperty(value = "是否展开 默认不展开(false)") - private boolean spread = true; - - @ApiModelProperty(value = "是否选中 默认false") - private boolean checked; private List children;