dji-cloud-api module add
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tourist-center</artifactId>
|
||||
<description>区域中心</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>search-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||
<imageTags>
|
||||
<imageTag>${project.version}</imageTag>
|
||||
<imageTag>latest</imageTag>
|
||||
</imageTags>
|
||||
<forceTags>true</forceTags>
|
||||
<baseImage>${docker.baseImage}</baseImage>
|
||||
<volumes>${docker.volumes}</volumes>
|
||||
<env>
|
||||
<JAVA_OPTS>${docker.java.opts}</JAVA_OPTS>
|
||||
</env>
|
||||
<entryPoint>["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"]</entryPoint>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.central;
|
||||
|
||||
import com.central.common.lb.annotation.EnableFeignInterceptor;
|
||||
import com.central.search.annotation.EnableSearchClient;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableSearchClient
|
||||
@EnableTransactionManagement
|
||||
@EnableFeignInterceptor
|
||||
@SpringBootApplication
|
||||
public class TouristCenterApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TouristCenterApp.class, args);
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.user.service.ISysMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@RestController
|
||||
@Tag(name = "菜单模块api")
|
||||
@Slf4j
|
||||
@RequestMapping("/menus")
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
private ISysMenuService menuService;
|
||||
|
||||
/**
|
||||
* 两层循环实现建树
|
||||
*
|
||||
* @param sysMenus
|
||||
* @return
|
||||
*/
|
||||
public static List<SysMenu> treeBuilder(List<SysMenu> sysMenus) {
|
||||
List<SysMenu> menus = new ArrayList<>();
|
||||
for (SysMenu sysMenu : sysMenus) {
|
||||
if (ObjectUtil.equal(-1L, sysMenu.getParentId())) {
|
||||
menus.add(sysMenu);
|
||||
}
|
||||
for (SysMenu menu : sysMenus) {
|
||||
if (menu.getParentId().equals(sysMenu.getId())) {
|
||||
if (sysMenu.getSubMenus() == null) {
|
||||
sysMenu.setSubMenus(new ArrayList<>());
|
||||
}
|
||||
sysMenu.getSubMenus().add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Operation(summary = "删除菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
try {
|
||||
menuService.removeById(id);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("memu-delete-error", ex);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "根据roleId获取对应的菜单")
|
||||
@GetMapping("/{roleId}/menus")
|
||||
public List<Map<String, Object>> findMenusByRoleId(@PathVariable Long roleId) {
|
||||
Set<Long> roleIds = new HashSet<>();
|
||||
roleIds.add(roleId);
|
||||
//获取该角色对应的菜单
|
||||
List<SysMenu> roleMenus = menuService.findByRoles(roleIds);
|
||||
//全部的菜单列表
|
||||
List<SysMenu> allMenus = menuService.findAll();
|
||||
List<Map<String, Object>> authTrees = new ArrayList<>();
|
||||
|
||||
Map<Long, SysMenu> roleMenusMap = roleMenus.stream().collect(Collectors.toMap(SysMenu::getId, SysMenu -> SysMenu));
|
||||
|
||||
for (SysMenu sysMenu : allMenus) {
|
||||
Map<String, Object> authTree = new HashMap<>();
|
||||
authTree.put("id", sysMenu.getId());
|
||||
authTree.put("name", sysMenu.getName());
|
||||
authTree.put("pId", sysMenu.getParentId());
|
||||
authTree.put("open", true);
|
||||
authTree.put("checked", false);
|
||||
if (roleMenusMap.get(sysMenu.getId()) != null) {
|
||||
authTree.put("checked", true);
|
||||
}
|
||||
authTrees.add(authTree);
|
||||
}
|
||||
return authTrees;
|
||||
}
|
||||
|
||||
@Operation(summary = "根据roleCodes获取对应的权限")
|
||||
@SuppressWarnings("unchecked")
|
||||
@Cacheable(value = "menu", key ="#roleCodes")
|
||||
@GetMapping("/{roleCodes}")
|
||||
public List<SysMenu> findMenuByRoles(@PathVariable String roleCodes) {
|
||||
List<SysMenu> result = null;
|
||||
if (StringUtils.isNotEmpty(roleCodes)) {
|
||||
Set<String> roleSet = (Set<String>)Convert.toCollection(HashSet.class, String.class, roleCodes);
|
||||
result = menuService.findByRoleCodes(roleSet, CommonConstant.PERMISSION);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给角色分配菜单
|
||||
*/
|
||||
@Operation(summary = "角色分配菜单")
|
||||
@PostMapping("/granted")
|
||||
public Result setMenuToRole(@RequestBody SysMenu sysMenu) {
|
||||
menuService.setMenuToRole(sysMenu.getRoleId(), sysMenu.getMenuIds());
|
||||
return Result.succeed("操作成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "查询所有菜单")
|
||||
@GetMapping("/findAlls")
|
||||
public PageResult<SysMenu> findAlls() {
|
||||
List<SysMenu> list = menuService.findAll();
|
||||
return PageResult.<SysMenu>builder().data(list).code(0).count((long) list.size()).build();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取菜单以及顶级菜单")
|
||||
@GetMapping("/findOnes")
|
||||
public PageResult<SysMenu> findOnes() {
|
||||
List<SysMenu> list = menuService.findOnes();
|
||||
return PageResult.<SysMenu>builder().data(list).code(0).count((long) list.size()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单 或者 更新
|
||||
*
|
||||
* @param menu
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新增菜单")
|
||||
@PostMapping("saveOrUpdate")
|
||||
public Result saveOrUpdate(@RequestBody SysMenu menu) {
|
||||
try {
|
||||
if (menu.getId() == null) {
|
||||
menu.setCreatorId(LoginUserContextHolder.getUser().getId());
|
||||
}
|
||||
menuService.saveOrUpdate(menu);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("memu-saveOrUpdate-error", ex);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录用户的菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/current")
|
||||
@Operation(summary = "查询当前用户菜单")
|
||||
public List<SysMenu> findMyMenu() {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
List<SysMenu> menus = menuService.findByUserId(user.getId(), CommonConstant.MENU);
|
||||
return treeBuilder(menus);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.user.service.ISysRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
* 角色管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "角色模块api")
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
/**
|
||||
* 后台管理查询角色
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "后台管理查询角色")
|
||||
@GetMapping("/roles")
|
||||
public PageResult<SysRole> findRoles(@RequestParam Map<String, Object> params) {
|
||||
return sysRoleService.findRoles(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户管理查询所有角色
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "后台管理查询角色")
|
||||
@GetMapping("/allRoles")
|
||||
public Result<List<SysRole>> findAll() {
|
||||
List<SysRole> result = sysRoleService.findAll();
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色新增或者更新
|
||||
*
|
||||
* @param sysRole
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/roles/saveOrUpdate")
|
||||
public Result saveOrUpdate(@RequestBody SysRole sysRole) throws Exception {
|
||||
return sysRoleService.saveOrUpdateRole(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台管理删除角色
|
||||
* delete /role/1
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Operation(summary = "后台管理删除角色")
|
||||
@DeleteMapping("/roles/{id}")
|
||||
public Result deleteRole(@PathVariable Long id) {
|
||||
try {
|
||||
if (id == 1L) {
|
||||
return Result.failed("管理员不可以删除");
|
||||
}
|
||||
sysRoleService.deleteRole(id);
|
||||
return Result.succeed("操作成功");
|
||||
} catch (Exception e) {
|
||||
log.error("role-deleteRole-error", e);
|
||||
return Result.failed("操作失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.model.UserType;
|
||||
import com.central.common.utils.ExcelUtil;
|
||||
import com.central.common.utils.LoginUserUtils;
|
||||
import com.central.log.annotation.AuditLog;
|
||||
import com.central.search.client.service.IQueryService;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import com.central.user.service.ISysUserService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
* 用户
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "用户模块api")
|
||||
public class SysUserController {
|
||||
private static final String ADMIN_CHANGE_MSG = "超级管理员不给予修改";
|
||||
|
||||
/**
|
||||
* 全文搜索逻辑删除Dto
|
||||
*/
|
||||
private static final LogicDelDto SEARCH_LOGIC_DEL_DTO = new LogicDelDto("isDel", "否");
|
||||
|
||||
@Autowired
|
||||
private ISysUserService appUserService;
|
||||
|
||||
@Autowired
|
||||
private IQueryService queryService;
|
||||
|
||||
/**
|
||||
* 当前登录用户 LoginAppUser
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "根据access_token当前登录用户")
|
||||
@GetMapping("/users/current")
|
||||
public Result<SysUser> getLoginAppUser() {
|
||||
return Result.succeed(LoginUserUtils.getCurrentSysUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户实体对象SysUser
|
||||
*/
|
||||
@GetMapping(value = "/users/name/{username}")
|
||||
@Operation(summary = "根据用户名查询用户实体")
|
||||
@Cacheable(value = "user", key = "#username")
|
||||
public SysUser selectByUsername(@PathVariable String username) {
|
||||
return appUserService.selectByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户登录对象LoginAppUser
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/login", params = "username")
|
||||
@Operation(summary = "根据用户名查询用户")
|
||||
public SysUser findByUsername(String username) {
|
||||
return appUserService.findByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号查询用户、角色信息
|
||||
*
|
||||
* @param mobile 手机号
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/mobile", params = "mobile")
|
||||
@Operation(summary = "根据手机号查询用户")
|
||||
public SysUser findByMobile(String mobile) {
|
||||
return appUserService.findByMobile(mobile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据OpenId查询用户信息
|
||||
*
|
||||
* @param openId openId
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/openId", params = "openId")
|
||||
@Operation(summary = "根据OpenId查询用户")
|
||||
public SysUser findByOpenId(String openId) {
|
||||
return appUserService.findByOpenId(openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据WxOpenId查询用户信息
|
||||
*
|
||||
* @param openId openId
|
||||
*/
|
||||
@GetMapping(value = "/users-anon/wxOpenId", params = "openId")
|
||||
@Operation(summary = "根据WxOpenId查询用户")
|
||||
public SysUser findByWxOpenId(String openId) throws Exception {
|
||||
return appUserService.findByWxOpenid(openId);
|
||||
}
|
||||
|
||||
@GetMapping("/users/{id}")
|
||||
public SysUser findUserById(@PathVariable Long id) {
|
||||
return appUserService.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台修改用户
|
||||
*
|
||||
* @param sysUser
|
||||
*/
|
||||
@PutMapping("/users")
|
||||
@CachePut(value = "user", key = "#sysUser.username", unless="#result == null")
|
||||
//@AuditLog(operation = "'更新用户:' + #sysUser")
|
||||
public void updateSysUser(@RequestBody SysUser sysUser) {
|
||||
appUserService.updateById(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台给用户分配角色
|
||||
*
|
||||
* @param id
|
||||
* @param roleIds
|
||||
*/
|
||||
@PostMapping("/users/{id}/roles")
|
||||
public void setRoleToUser(@PathVariable Long id, @RequestBody Set<Long> roleIds) {
|
||||
appUserService.setRoleToUser(id, roleIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的角色
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/users/{id}/roles")
|
||||
public List<SysRole> findRolesByUserId(@PathVariable Long id) {
|
||||
return appUserService.findRolesByUserId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户查询
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "用户查询列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in= ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/users")
|
||||
public PageResult<SysUser> findUsers(@RequestParam Map<String, Object> params) {
|
||||
return appUserService.findUsers(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改用户状态")
|
||||
@GetMapping("/users/updateEnabled")
|
||||
@Parameters({
|
||||
@Parameter(name = "id",description = "用户id",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "enabled",description = "是否启用",required = true,in= ParameterIn.QUERY)
|
||||
})
|
||||
public Result updateEnabled(@RequestParam Map<String, Object> params) {
|
||||
Long id = MapUtils.getLong(params, "id");
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
}
|
||||
return appUserService.updateEnabled(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台,给用户重置密码
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@PutMapping(value = "/users/{id}/password")
|
||||
//@AuditLog(operation = "'重置用户密码:' + #id")
|
||||
public Result resetPassword(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
}
|
||||
appUserService.updatePassword(id, null, null);
|
||||
return Result.succeed("重置成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自己修改密码
|
||||
*/
|
||||
@PutMapping(value = "/users/password")
|
||||
public Result resetPassword(@RequestBody SysUser sysUser) {
|
||||
if (checkAdmin(sysUser.getId())) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
}
|
||||
appUserService.updatePassword(sysUser.getId(), sysUser.getOldPassword(), sysUser.getNewPassword());
|
||||
return Result.succeed("重置成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@DeleteMapping(value = "/users/{id}")
|
||||
//@AuditLog(operation = "'删除用户:' + #id")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
}
|
||||
appUserService.delUser(id);
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增or更新
|
||||
*
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@CacheEvict(value = "user", key = "#sysUser.username")
|
||||
@PostMapping("/users/saveOrUpdate")
|
||||
@AuditLog(operation = "'新增或更新用户:' + #sysUser.username")
|
||||
public Result saveOrUpdate(@RequestBody SysUser sysUser) throws Exception {
|
||||
return appUserService.saveOrUpdateUser(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/users/export")
|
||||
public void exportUser(@RequestParam Map<String, Object> params, HttpServletResponse response) throws IOException {
|
||||
List<SysUserExcel> result = appUserService.findAllUsers(params);
|
||||
//导出操作
|
||||
ExcelUtil.exportExcel(result, null, "用户", SysUserExcel.class, "user", response);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/users/import")
|
||||
public Result importExcl(@RequestParam("file") MultipartFile excl) throws Exception {
|
||||
int rowNum = 0;
|
||||
if(!excl.isEmpty()) {
|
||||
List<SysUserExcel> list = ExcelUtil.importExcel(excl, 0, 1, SysUserExcel.class);
|
||||
rowNum = list.size();
|
||||
if (rowNum > 0) {
|
||||
List<SysUser> users = new ArrayList<>(rowNum);
|
||||
list.forEach(u -> {
|
||||
SysUser user = new SysUser();
|
||||
BeanUtil.copyProperties(u, user);
|
||||
user.setPassword(CommonConstant.DEF_USER_PASSWORD);
|
||||
user.setType(UserType.BACKEND.name());
|
||||
users.add(user);
|
||||
});
|
||||
appUserService.saveBatch(users);
|
||||
}
|
||||
}
|
||||
return Result.succeed("导入数据成功,一共【"+rowNum+"】行");
|
||||
}
|
||||
|
||||
@Operation(summary = "用户全文搜索列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in= ParameterIn.QUERY),
|
||||
@Parameter(name = "queryStr",description = "搜索关键字",in= ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/users/search")
|
||||
public PageResult<JsonNode> search(SearchDto searchDto) {
|
||||
searchDto.setIsHighlighter(true);
|
||||
searchDto.setSortCol("createTime");
|
||||
return queryService.strQuery("sys_user", searchDto, SEARCH_LOGIC_DEL_DTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户并返回角色列表
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/users/roleUser/{username}")
|
||||
@Operation(summary = "查询用户-带角色信息")
|
||||
@Cacheable(value = "userRoles", key = "#username")
|
||||
public SysUser selectRoleUser(@PathVariable("username") String username){
|
||||
SysUser sysUser = selectByUsername(username);
|
||||
if(ObjectUtil.isNotNull(sysUser)){
|
||||
List<SysRole> roleList = findRolesByUserId(sysUser.getId());
|
||||
sysUser.setRoles(roleList);
|
||||
}
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否超级管理员
|
||||
*/
|
||||
private boolean checkAdmin(long id) {
|
||||
return id == 1L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysMenuMapper extends SuperMapper<SysMenu> {
|
||||
List<SysMenu> findByUserId(@Param("userId") Long userId, @Param("type") Integer type);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends SuperMapper<SysRole> {
|
||||
List<SysRole> findList(Page<SysRole> page, @Param("r") Map<String, Object> params);
|
||||
|
||||
List<SysRole> findAll();
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.user.model.SysRoleMenu;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 角色菜单
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper extends SuperMapper<SysRoleMenu> {
|
||||
@Insert("insert into sys_role_menu(role_id, menu_id) values(#{roleId}, #{menuId})")
|
||||
int save(@Param("roleId") Long roleId, @Param("menuId") Long menuId);
|
||||
|
||||
int delete(@Param("roleId") Long roleId, @Param("menuId") Long menuId);
|
||||
|
||||
List<SysMenu> findMenusByRoleIds(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
||||
|
||||
List<SysMenu> findMenusByRoleCodes(@Param("roleCodes") Set<String> roleCodes, @Param("type") Integer type);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户表 Mapper 接口
|
||||
*
|
||||
* @author zlt
|
||||
* @data 2018-10-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserMapper extends SuperMapper<SysUser> {
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
* @param page
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<SysUser> findList(Page<SysUser> page, @Param("u") Map<String, Object> params);
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.central.user.mapper;
|
||||
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.user.model.SysRoleUser;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* 用户角色关系
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends SuperMapper<SysRoleUser> {
|
||||
int deleteUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
@Insert("insert into sys_role_user(user_id, role_id) values(#{userId}, #{roleId})")
|
||||
int saveUserRoles(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findRolesByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ids 获取
|
||||
*
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
@Select("<script>select r.*,ru.user_id from sys_role_user ru inner join sys_role r on r.id = ru.role_id where ru.user_id IN " +
|
||||
" <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'> " +
|
||||
" #{item} " +
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
List<SysRole> findRolesByUserIds(List<Long> userIds);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.central.user.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/7/30
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_role_menu")
|
||||
public class SysRoleMenu extends Model<SysRoleMenu> {
|
||||
private Long roleId;
|
||||
private Long menuId;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.central.user.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/7/30
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_role_user")
|
||||
public class SysRoleUser extends Model<SysRoleUser> {
|
||||
private Long userId;
|
||||
private Long roleId;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.central.user.model;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户导出实例
|
||||
* @Author: zlt
|
||||
*/
|
||||
@Data
|
||||
public class SysUserExcel implements Serializable {
|
||||
private static final long serialVersionUID = -5886012896705137070L;
|
||||
|
||||
@Excel(name = "用户姓名", height = 20, width = 30, isImportField = "true_st")
|
||||
private String username;
|
||||
|
||||
@Excel(name = "用户昵称", height = 20, width = 30, isImportField = "true_st")
|
||||
private String nickname;
|
||||
|
||||
@Excel(name = "手机号码", height = 20, width = 30, isImportField = "true_st")
|
||||
private String mobile;
|
||||
|
||||
@Excel(name = "性别", replace = { "男_0", "女_1" }, isImportField = "true_st")
|
||||
private Integer sex;
|
||||
|
||||
@Excel(name = "创建时间", format = CommonConstant.DATETIME_FORMAT, isImportField = "true_st", width = 20)
|
||||
private Date createTime;
|
||||
|
||||
@Excel(name = "修改时间", format = CommonConstant.DATETIME_FORMAT, isImportField = "true_st", width = 20)
|
||||
private Date updateTime;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.ISuperService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysMenuService extends ISuperService<SysMenu> {
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*/
|
||||
List<SysMenu> findAll();
|
||||
|
||||
/**
|
||||
* 查询所有一级菜单
|
||||
*/
|
||||
List<SysMenu> findOnes();
|
||||
|
||||
/**
|
||||
* 角色分配菜单
|
||||
* @param roleId
|
||||
* @param menuIds
|
||||
*/
|
||||
void setMenuToRole(Long roleId, Set<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoles(Set<Long> roleIds);
|
||||
|
||||
List<SysMenu> findByUserId(Long userId, Integer type);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @param roleIds 是否菜单
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoles(Set<Long> roleIds, Integer type);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleCodes
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findByRoleCodes(Set<String> roleCodes, Integer type);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.user.model.SysRoleMenu;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysRoleMenuService extends ISuperService<SysRoleMenu> {
|
||||
int save(Long roleId, Long menuId);
|
||||
|
||||
int delete(Long roleId, Long menuId);
|
||||
|
||||
List<SysMenu> findMenusByRoleIds(Set<Long> roleIds, Integer type);
|
||||
|
||||
List<SysMenu> findMenusByRoleCodes(Set<String> roleCodes, Integer type);
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.service.ISuperService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* <p>
|
||||
* Blog: http://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
public interface ISysRoleService extends ISuperService<SysRole> {
|
||||
void saveRole(SysRole sysRole) throws Exception;
|
||||
|
||||
void deleteRole(Long id);
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageResult<SysRole> findRoles(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 新增或更新角色
|
||||
* @param sysRole
|
||||
* @return Result
|
||||
*/
|
||||
Result saveOrUpdateRole(SysRole sysRole) throws Exception;
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findAll();
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.user.model.SysRoleUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
public interface ISysRoleUserService extends ISuperService<SysRoleUser> {
|
||||
int deleteUserRole(Long userId, Long roleId);
|
||||
|
||||
int saveUserRoles(Long userId, Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ids 获取
|
||||
*
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findRolesByUserIds(List<Long> userIds);
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* <p>
|
||||
* Blog: http://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
public interface ISysUserService extends ISuperService<SysUser> {
|
||||
/**
|
||||
* 获取UserDetails对象
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
SysUser findByUsername(String username);
|
||||
|
||||
SysUser findByOpenId(String username);
|
||||
|
||||
SysUser findByMobile(String username);
|
||||
|
||||
SysUser findByWxOpenid(String wxOpenid) throws Exception;
|
||||
|
||||
/**
|
||||
* 通过SysUser 把roles和permissions也查询出来
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
void setUserPermission(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByUsername(String username);
|
||||
/**
|
||||
* 根据手机号查询用户
|
||||
* @param mobile
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByMobile(String mobile);
|
||||
/**
|
||||
* 根据openId查询用户
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByOpenId(String openId);
|
||||
|
||||
|
||||
/**
|
||||
* 用户分配角色
|
||||
* @param id
|
||||
* @param roleIds
|
||||
*/
|
||||
void setRoleToUser(Long id, Set<Long> roleIds);
|
||||
|
||||
/**
|
||||
* 更新密码
|
||||
* @param id
|
||||
* @param oldPassword
|
||||
* @param newPassword
|
||||
* @return
|
||||
*/
|
||||
Result updatePassword(Long id, String oldPassword, String newPassword);
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
PageResult<SysUser> findUsers(Map<String, Object> params);
|
||||
|
||||
|
||||
/**
|
||||
* 用户角色列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<SysRole> findRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 状态变更
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Result updateEnabled(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 查询全部用户
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<SysUserExcel> findAllUsers(Map<String, Object> params);
|
||||
|
||||
Result saveOrUpdateUser(SysUser sysUser) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
boolean delUser(Long id);
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysMenuMapper;
|
||||
import com.central.user.model.SysRoleMenu;
|
||||
import com.central.user.service.ISysMenuService;
|
||||
import com.central.user.service.ISysRoleMenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends SuperServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
|
||||
@Resource
|
||||
private ISysRoleMenuService roleMenuService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void setMenuToRole(Long roleId, Set<Long> menuIds) {
|
||||
roleMenuService.delete(roleId, null);
|
||||
|
||||
if (!CollectionUtils.isEmpty(menuIds)) {
|
||||
List<SysRoleMenu> roleMenus = new ArrayList<>(menuIds.size());
|
||||
menuIds.forEach(menuId -> roleMenus.add(new SysRoleMenu(roleId, menuId)));
|
||||
roleMenuService.saveBatch(roleMenus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findByRoles(Set<Long> roleIds) {
|
||||
return roleMenuService.findMenusByRoleIds(roleIds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
* @param roleIds 角色ids
|
||||
* @param roleIds 是否菜单
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findByRoles(Set<Long> roleIds, Integer type) {
|
||||
return roleMenuService.findMenusByRoleIds(roleIds, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findByRoleCodes(Set<String> roleCodes, Integer type) {
|
||||
return roleMenuService.findMenusByRoleCodes(roleCodes, type);
|
||||
}
|
||||
@Override
|
||||
public List<SysMenu> findByUserId(Long userId, Integer type) {
|
||||
return baseMapper.findByUserId(userId, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有菜单
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findAll() {
|
||||
return baseMapper.selectList(
|
||||
new QueryWrapper<SysMenu>().orderByAsc("sort")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有一级菜单
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findOnes() {
|
||||
return baseMapper.selectList(
|
||||
new QueryWrapper<SysMenu>()
|
||||
.eq("type", 1)
|
||||
.orderByAsc("sort")
|
||||
);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.model.SysRoleMenu;
|
||||
import com.central.user.service.ISysRoleMenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends SuperServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {
|
||||
@Resource
|
||||
private SysRoleMenuMapper sysRoleMenuMapper;
|
||||
|
||||
@Override
|
||||
public int save(Long roleId, Long menuId) {
|
||||
return sysRoleMenuMapper.save(roleId, menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long roleId, Long menuId) {
|
||||
return sysRoleMenuMapper.delete(roleId, menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findMenusByRoleIds(Set<Long> roleIds, Integer type) {
|
||||
return sysRoleMenuMapper.findMenusByRoleIds(roleIds, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> findMenusByRoleCodes(Set<String> roleCodes, Integer type) {
|
||||
return sysRoleMenuMapper.findMenusByRoleCodes(roleCodes, type);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysRoleMapper;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.mapper.SysUserRoleMapper;
|
||||
import com.central.user.service.ISysRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends SuperServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
||||
private final static String LOCK_KEY_ROLECODE = "rolecode:";
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Autowired
|
||||
private DistributedLock lock;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveRole(SysRole sysRole) throws Exception {
|
||||
String roleCode = sysRole.getCode();
|
||||
super.saveIdempotency(sysRole, lock
|
||||
, LOCK_KEY_ROLECODE+roleCode, new QueryWrapper<SysRole>().eq("code", roleCode), "角色code已存在");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deleteRole(Long id) {
|
||||
baseMapper.deleteById(id);
|
||||
roleMenuMapper.delete(id, null);
|
||||
userRoleMapper.deleteUserRole(null, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysRole> findRoles(Map<String, Object> params) {
|
||||
Integer curPage = MapUtils.getInteger(params, "page");
|
||||
Integer limit = MapUtils.getInteger(params, "limit");
|
||||
Page<SysRole> page = new Page<>(curPage == null ? 0 : curPage, limit == null ? -1 : limit);
|
||||
List<SysRole> list = baseMapper.findList(page, params);
|
||||
return PageResult.<SysRole>builder().data(list).code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result saveOrUpdateRole(SysRole sysRole) throws Exception {
|
||||
if (sysRole.getId() == null) {
|
||||
sysRole.setCreatorId(LoginUserContextHolder.getUser().getId());
|
||||
this.saveRole(sysRole);
|
||||
} else {
|
||||
baseMapper.updateById(sysRole);
|
||||
}
|
||||
return Result.succeed("操作成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findAll() {
|
||||
return baseMapper.findAll();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysUserRoleMapper;
|
||||
import com.central.user.model.SysRoleUser;
|
||||
import com.central.user.service.ISysRoleUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysRoleUserServiceImpl extends SuperServiceImpl<SysUserRoleMapper, SysRoleUser> implements ISysRoleUserService {
|
||||
@Resource
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public int deleteUserRole(Long userId, Long roleId) {
|
||||
return sysUserRoleMapper.deleteUserRole(userId, roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveUserRoles(Long userId, Long roleId) {
|
||||
return sysUserRoleMapper.saveUserRoles(userId, roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findRolesByUserId(Long userId) {
|
||||
return sysUserRoleMapper.findRolesByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findRolesByUserIds(List<Long> userIds) {
|
||||
return sysUserRoleMapper.findRolesByUserIds(userIds);
|
||||
}
|
||||
}
|
||||
+279
@@ -0,0 +1,279 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.mapper.SysUserMapper;
|
||||
import com.central.user.model.SysRoleUser;
|
||||
import com.central.user.model.SysUserExcel;
|
||||
import com.central.user.service.ISysRoleUserService;
|
||||
import com.central.user.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
private final static String LOCK_KEY_USERNAME = "username:";
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Resource
|
||||
private ISysRoleUserService roleUserService;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Autowired
|
||||
private DistributedLock lock;
|
||||
|
||||
@Override
|
||||
public SysUser findByUsername(String username) {
|
||||
SysUser sysUser = this.selectByUsername(username);
|
||||
setUserPermission(sysUser);
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser findByOpenId(String openId) {
|
||||
SysUser sysUser = this.selectByOpenId(openId);
|
||||
setUserPermission(sysUser);
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser findByMobile(String username) {
|
||||
SysUser sysUser = this.selectByMobile(username);
|
||||
setUserPermission(sysUser);
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser findByWxOpenid(String wxOpenid) throws Exception {
|
||||
SysUser sysUser = this.selectByOpenId(wxOpenid);
|
||||
if (ObjectUtils.isEmpty(sysUser)) {
|
||||
sysUser = new SysUser();
|
||||
sysUser.setOpenId(wxOpenid);
|
||||
sysUser.setUsername(wxOpenid);
|
||||
sysUser.setType(UserType.APP.name());
|
||||
sysUser.setPassword(wxOpenid);
|
||||
sysUser.setEnabled(Boolean.TRUE);
|
||||
}
|
||||
String username = sysUser.getUsername();
|
||||
boolean result = super.saveOrUpdateIdempotency(sysUser, lock
|
||||
, LOCK_KEY_USERNAME+username, new QueryWrapper<SysUser>().eq("username", username)
|
||||
, username+"已存在");
|
||||
return result ? sysUser : new SysUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserPermission(SysUser sysUser) {
|
||||
if (sysUser != null) {
|
||||
List<SysRole> sysRoles = roleUserService.findRolesByUserId(sysUser.getId());
|
||||
sysUser.setRoles(sysRoles);
|
||||
|
||||
Set<String> permissions;
|
||||
if (!CollectionUtils.isEmpty(sysRoles)) {
|
||||
Set<Long> roleIds = sysRoles.stream().map(SuperEntity::getId).collect(Collectors.toSet());
|
||||
List<SysMenu> menus = roleMenuMapper.findMenusByRoleIds(roleIds, CommonConstant.PERMISSION);
|
||||
if (!CollectionUtils.isEmpty(menus)) {
|
||||
permissions = menus.stream().map(p -> p.getPath())
|
||||
.collect(Collectors.toSet());
|
||||
sysUser.setPermissions(permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByUsername(String username) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("username", username)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户
|
||||
* @param mobile
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByMobile(String mobile) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("mobile", mobile)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openId查询用户
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectByOpenId(String openId) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("open_id", openId)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
|
||||
private SysUser getUser(List<SysUser> users) {
|
||||
SysUser user = null;
|
||||
if (users != null && !users.isEmpty()) {
|
||||
user = users.get(0);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户设置角色
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void setRoleToUser(Long id, Set<Long> roleIds) {
|
||||
SysUser sysUser = baseMapper.selectById(id);
|
||||
if (sysUser == null) {
|
||||
throw new IllegalArgumentException("用户不存在");
|
||||
}
|
||||
|
||||
roleUserService.deleteUserRole(id, null);
|
||||
if (!CollectionUtils.isEmpty(roleIds)) {
|
||||
List<SysRoleUser> roleUsers = new ArrayList<>(roleIds.size());
|
||||
roleIds.forEach(roleId -> roleUsers.add(new SysRoleUser(id, roleId)));
|
||||
roleUserService.saveBatch(roleUsers);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Result updatePassword(Long id, String oldPassword, String newPassword) {
|
||||
SysUser sysUser = baseMapper.selectById(id);
|
||||
if (StrUtil.isNotBlank(oldPassword)) {
|
||||
if (!passwordEncoder.matches(oldPassword, sysUser.getPassword())) {
|
||||
return Result.failed("旧密码错误");
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(newPassword)) {
|
||||
newPassword = CommonConstant.DEF_USER_PASSWORD;
|
||||
}
|
||||
SysUser user = new SysUser();
|
||||
user.setId(id);
|
||||
user.setPassword(passwordEncoder.encode(newPassword));
|
||||
baseMapper.updateById(user);
|
||||
return Result.succeed("修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysUser> findUsers(Map<String, Object> params) {
|
||||
Page<SysUser> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<SysUser> list = baseMapper.findList(page, params);
|
||||
long total = page.getTotal();
|
||||
if (total > 0) {
|
||||
List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList());
|
||||
|
||||
List<SysRole> sysRoles = roleUserService.findRolesByUserIds(userIds);
|
||||
list.forEach(u -> u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId()))
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
return PageResult.<SysUser>builder().data(list).code(0).count(total).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findRolesByUserId(Long userId) {
|
||||
return roleUserService.findRolesByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateEnabled(Map<String, Object> params) {
|
||||
Long id = MapUtils.getLong(params, "id");
|
||||
Boolean enabled = MapUtils.getBoolean(params, "enabled");
|
||||
|
||||
SysUser appUser = baseMapper.selectById(id);
|
||||
if (appUser == null) {
|
||||
return Result.failed("用户不存在");
|
||||
}
|
||||
appUser.setEnabled(enabled);
|
||||
appUser.setUpdateTime(new Date());
|
||||
|
||||
int i = baseMapper.updateById(appUser);
|
||||
log.info("修改用户:{}", appUser);
|
||||
|
||||
return i > 0 ? Result.succeed(appUser, "更新成功") : Result.failed("更新失败");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Result saveOrUpdateUser(SysUser sysUser) throws Exception {
|
||||
if (sysUser.getId() == null) {
|
||||
if (StringUtils.isBlank(sysUser.getType())) {
|
||||
sysUser.setType(UserType.BACKEND.name());
|
||||
}
|
||||
sysUser.setPassword(passwordEncoder.encode(CommonConstant.DEF_USER_PASSWORD));
|
||||
sysUser.setEnabled(Boolean.TRUE);
|
||||
sysUser.setCreatorId(LoginUserContextHolder.getUser().getId());
|
||||
}
|
||||
String username = sysUser.getUsername();
|
||||
boolean result = super.saveOrUpdateIdempotency(sysUser, lock
|
||||
, LOCK_KEY_USERNAME+username, new QueryWrapper<SysUser>().eq("username", username)
|
||||
, username+"已存在");
|
||||
//更新角色
|
||||
if (result && StrUtil.isNotEmpty(sysUser.getRoleId())) {
|
||||
roleUserService.deleteUserRole(sysUser.getId(), null);
|
||||
List roleIds = Arrays.asList(sysUser.getRoleId().split(","));
|
||||
if (!CollectionUtils.isEmpty(roleIds)) {
|
||||
List<SysRoleUser> roleUsers = new ArrayList<>(roleIds.size());
|
||||
roleIds.forEach(roleId -> roleUsers.add(new SysRoleUser(sysUser.getId(), Long.parseLong(roleId.toString()))));
|
||||
roleUserService.saveBatch(roleUsers);
|
||||
}
|
||||
}
|
||||
return result ? Result.succeed(sysUser, "操作成功") : Result.failed("操作失败");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delUser(Long id) {
|
||||
roleUserService.deleteUserRole(id, null);
|
||||
return baseMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserExcel> findAllUsers(Map<String, Object> params) {
|
||||
List<SysUserExcel> sysUserExcels = new ArrayList<>();
|
||||
List<SysUser> list = baseMapper.findList(new Page<>(1, -1), params);
|
||||
|
||||
for (SysUser sysUser : list) {
|
||||
SysUserExcel sysUserExcel = new SysUserExcel();
|
||||
BeanUtils.copyProperties(sysUser, sysUserExcel);
|
||||
sysUserExcels.add(sysUserExcel);
|
||||
}
|
||||
return sysUserExcels;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/user-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.central.common.model
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
|
||||
springdoc:
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: com.central.tourist.controller
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
swagger-model-name: 用户中心接口文档
|
||||
|
||||
zlt:
|
||||
cache-manager:
|
||||
configs:
|
||||
- key: menu
|
||||
second: 300
|
||||
- key: user
|
||||
second: 1800
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: true
|
||||
ignoreTables:
|
||||
- sys_user
|
||||
- sys_role_user
|
||||
- sys_role_menu
|
||||
ignoreSqls:
|
||||
# 用户关联角色时,显示所有角色
|
||||
- com.central.user.mapper.SysRoleMapper.findAll
|
||||
# 用户列表显示用户所关联的所有角色
|
||||
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
|
||||
# 数据权限
|
||||
datascope:
|
||||
enabled: false
|
||||
ignoreTables:
|
||||
- sys_role_user
|
||||
- sys_role_menu
|
||||
includeSqls:
|
||||
# 用户列表
|
||||
- com.central.user.mapper.SysUserMapper.findList
|
||||
# 角色列表
|
||||
- com.central.user.mapper.SysRoleMapper.findList
|
||||
# 菜单列表
|
||||
- com.central.user.mapper.SysMenuMapper.selectList
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
# log-type: db
|
||||
# datasource:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/logger-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
# username: ${zlt.datasource.username}
|
||||
# password: ${zlt.datasource.password}
|
||||
@@ -0,0 +1,11 @@
|
||||
server:
|
||||
port: 7000
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: user-center
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# metadata:
|
||||
# version: zlt
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysMenuMapper">
|
||||
<select id="findByUserId" resultType="com.central.common.model.SysMenu">
|
||||
select distinct t.* from sys_menu t
|
||||
inner join sys_role_menu r on r.menu_id = t.id
|
||||
inner join sys_role_user ru on ru.role_id = r.role_id
|
||||
where ru.user_id = #{userId}
|
||||
<if test="type != null">
|
||||
and t.type = #{type}
|
||||
</if>
|
||||
and t.hidden = 0
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysRoleMapper">
|
||||
<sql id="Column_List">
|
||||
id,
|
||||
code,
|
||||
name,
|
||||
create_time,
|
||||
update_time,
|
||||
tenant_id,
|
||||
data_scope
|
||||
</sql>
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="r.name != null and r.name != ''">
|
||||
and t.name like concat('%', #{r.name}, '%')
|
||||
</if>
|
||||
|
||||
<if test="r.searchKey != null and r.searchKey != '' and r.searchKey=='name'">
|
||||
and t.name like concat('%', #{r.searchValue}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.common.model.SysRole">
|
||||
select <include refid="Column_List"/>
|
||||
from sys_role t
|
||||
<include refid="where" />
|
||||
order by t.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultType="com.central.common.model.SysRole">
|
||||
select <include refid="Column_List"/>
|
||||
from sys_role
|
||||
order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysRoleMenuMapper">
|
||||
|
||||
<update id="delete">
|
||||
delete from sys_role_menu
|
||||
<where>
|
||||
<if test="roleId != null">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
<if test="menuId != null">
|
||||
and menu_id = #{menuId}
|
||||
</if>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<select id="findMenusByRoleIds" resultType="com.central.common.model.SysMenu">
|
||||
select distinct t.* from sys_menu t
|
||||
inner join sys_role_menu r on r.menu_id = t.id
|
||||
where
|
||||
r.role_id in
|
||||
<foreach collection="roleIds" index="index" item="roleId"
|
||||
open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
<if test="type != null">
|
||||
and t.type = #{type}
|
||||
</if>
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
|
||||
<select id="findMenusByRoleCodes" resultType="com.central.common.model.SysMenu">
|
||||
select distinct t.* from sys_menu t
|
||||
inner join sys_role_menu r on r.menu_id = t.id
|
||||
inner join sys_role rl on rl.id = r.role_id
|
||||
where
|
||||
rl.code in
|
||||
<foreach collection="roleCodes" index="index" item="roleCode"
|
||||
open="(" separator="," close=")">
|
||||
#{roleCode}
|
||||
</foreach>
|
||||
<if test="type != null">
|
||||
and t.type = #{type}
|
||||
</if>
|
||||
and t.hidden = 0
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysUserMapper">
|
||||
<sql id="where">
|
||||
<where>
|
||||
t.is_del=0
|
||||
<if test="u.id != null and u.id != ''">
|
||||
and t.id like concat('%', #{u.id}, '%')
|
||||
</if>
|
||||
<if test="u.username != null and u.username != ''">
|
||||
and t.username like concat('%', #{u.username}, '%')
|
||||
</if>
|
||||
<if test="u.nickname != null and u.nickname != ''">
|
||||
and t.nickname like concat('%', #{u.nickname}, '%')
|
||||
</if>
|
||||
<if test="u.enabled != null and u.enabled != ''">
|
||||
and t.enabled = #{u.enabled}
|
||||
</if>
|
||||
<if test="u.type != null and u.type != ''">
|
||||
and t.type = #{u.type}
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='user_id'">
|
||||
and t.id like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='username'">
|
||||
and t.username like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='nick_name'">
|
||||
and t.nickname like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
<if test="u.searchKey != null and u.searchKey != '' and u.searchKey=='mobile'">
|
||||
and t.mobile like concat('%', #{u.searchValue}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="findList" resultType="com.central.common.model.SysUser">
|
||||
select * from sys_user t
|
||||
<include refid="where" />
|
||||
order by t.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.user.mapper.SysUserRoleMapper">
|
||||
<delete id="deleteUserRole">
|
||||
delete from sys_role_user
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="roleId != null">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<select id="findRolesByUserId" resultType="com.central.common.model.SysRole">
|
||||
select r.* from sys_role r
|
||||
inner join sys_role_user ru on r.id = ru.role_id and ru.user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user