This commit is contained in:
clay
2024-03-06 17:44:09 +08:00
commit adaec0eadd
1493 changed files with 219939 additions and 0 deletions

View File

@@ -0,0 +1 @@
字典模块添加布隆过滤器

74
admin/admin-biz/pom.xml Normal file
View File

@@ -0,0 +1,74 @@
<?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">
<parent>
<artifactId>admin</artifactId>
<groupId>cn.fateverse</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>admin-biz</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<dependencies>
<!--通用模块-->
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-security</artifactId>
</dependency>
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-swagger</artifactId>
</dependency>
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-log</artifactId>
</dependency>
<!--文件组件-->
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-file</artifactId>
</dependency>
<!--seata 分布式事务-->
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-seata</artifactId>
</dependency>
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.fateverse</groupId>
<artifactId>common-decrypt</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.3</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,22 @@
package cn.fateverse.admin;
import cn.fateverse.common.security.annotation.EnableSecurity;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author Clay
* @date 2022/10/27
*/
@EnableSecurity
@EnableDiscoveryClient
@SpringBootApplication
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class,args);
System.out.println("admin模块启动成功");
}
}

View File

@@ -0,0 +1,102 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.ConfigDto;
import cn.fateverse.admin.query.ConfigQuery;
import cn.fateverse.admin.vo.ConfigVo;
import cn.fateverse.admin.service.ConfigService;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.excel.utils.ExcelUtil;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 参数配置表 Controller
*
* @author clay
* @date 2023-06-09
*/
@Api(value = "参数配置表管理",tags = "参数配置表管理")
@RestController
@RequestMapping("/config")
public class ConfigController {
private final ConfigService configService;
public ConfigController(ConfigService configService) {
this.configService = configService;
}
@ApiOperation("获取参数配置表列表")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:config:list')")
public Result<TableDataInfo<ConfigVo>> list(ConfigQuery query) {
TableDataInfo<ConfigVo> dataInfo = configService.searchList(query);
return Result.ok(dataInfo);
}
@ApiOperation("获取参数配置表列表Page")
@GetMapping("/page")
@PreAuthorize("@ss.hasPermission('admin:config:list')")
public Result<TableDataInfo<ConfigVo>> listPage(ConfigQuery query) {
TableDataInfo<ConfigVo> dataInfo = configService.searchListPage(query);
return Result.ok(dataInfo);
}
@ApiOperation("导出excel数据")
@GetMapping("/export")
@PreAuthorize("@ss.hasPermission('admin:config:export')")
public void export(ConfigQuery query){
List<ConfigVo> list = configService.exportList(query);
ExcelUtil.exportExcel(list,ConfigVo.class);
}
@ApiOperation("获取参数配置表详细信息")
@GetMapping("/{configId}")
@PreAuthorize("@ss.hasPermission('admin:config:info')")
public Result<ConfigVo> info(@PathVariable Integer configId) {
ObjectUtils.checkPk(configId);
ConfigVo config = configService.searchById(configId);
return Result.ok(config);
}
@ApiOperation("新增参数配置表")
@PostMapping
@Log(title = "新增参数配置表",businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('admin:config:add')")
public Result<Void> add(@RequestBody @Validated ConfigDto config){
configService.save(config);
return Result.ok();
}
@ApiOperation("修改参数配置表")
@PutMapping
@Log(title = "修改参数配置表",businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:config:edit')")
public Result<Void> edit(@RequestBody @Validated ConfigDto config){
ObjectUtils.checkPk(config.getConfigId());
configService.edit(config);
return Result.ok();
}
@ApiOperation("删除参数配置表")
@DeleteMapping("/{configIdList}")
@Log(title = "删除参数配置表",businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('admin:config:del')")
public Result<Void> batchDel(@PathVariable List<Integer> configIdList){
ObjectUtils.checkPkList(configIdList);
configService.removeBatch(configIdList);
return Result.ok();
}
}

View File

@@ -0,0 +1,134 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.DeptDto;
import cn.fateverse.admin.vo.DeptVo;
import cn.fateverse.admin.service.DeptService;
import cn.fateverse.common.core.constant.UserConstants;
import cn.fateverse.admin.entity.Dept;
import cn.fateverse.common.core.entity.OptionTree;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2022/11/2
*/
@Api(tags = "部门接口")
@RestController
@RequestMapping("/dept")
public class DeptController {
private final DeptService deptService;
public DeptController(DeptService deptService) {
this.deptService = deptService;
}
@ApiOperation("获取列表信息")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:dept:list')")
public Result<List<DeptVo>> list(
@ApiParam(name="deptName",value="部门名称") String deptName,
@ApiParam(name="state",value="状态(1: 正常 0 : 停用)") Integer state){
List<DeptVo> deptVoList = deptService.searchTree(deptName, state);
return Result.ok(deptVoList);
}
@ApiOperation("获取部门详情")
@GetMapping("/{deptId}")
@PreAuthorize("@ss.hasPermission('admin:dept:info')")
public Result<DeptVo> info(
@ApiParam(name="deptId",value="部门id")
@PathVariable Long deptId){
checkDeptId(deptId);
DeptVo deptVo = deptService.searchById(deptId);
return Result.ok(deptVo);
}
@ApiOperation("获取树形接口的option")
@GetMapping("/option")
public Result<List<OptionTree>> option(){
List<OptionTree> optionTreeList = deptService.searchTreeOption();
return Result.ok(optionTreeList);
}
@ApiOperation("获取修改时的部门列表")
@GetMapping("/option/exclude/{deptId}")
public Result<List<OptionTree>> exclude(@PathVariable Long deptId){
checkDeptId(deptId);
List<OptionTree> deptVoList = deptService.searchExcludeTree(deptId);
return Result.ok(deptVoList);
}
@ApiOperation("新增部门")
@PostMapping
@PreAuthorize("@ss.hasPermission('admin:dept:add')")
@Log(title = "新增部门",businessType = BusinessType.INSERT)
public Result<Void> add(@RequestBody @Validated DeptDto deptDto){
Dept dept = new Dept();
BeanUtils.copyProperties(deptDto,dept);
if (UserConstants.DEPT_DISABLE.equals(deptService.checkNameUnique(dept))){
return Result.error("新增部门: "+ dept.getDeptName() +"'失败,部门名称以存在!");
}
deptService.save(dept);
return Result.ok();
}
@ApiOperation("修改部门")
@PutMapping
@PreAuthorize("@ss.hasPermission('admin:dept:edit')")
@Log(title = "修改部门",businessType = BusinessType.UPDATE)
public Result<Void> edit(@RequestBody @Validated DeptDto deptDto){
Dept dept = new Dept();
BeanUtils.copyProperties(deptDto,dept);
if (UserConstants.DEPT_DISABLE.equals(deptService.checkNameUnique(dept))){
return Result.error("修改部门: "+ dept.getDeptName() +"'失败,部门名称以存在!");
}else if (dept.getDeptId().equals(dept.getParentId())){
return Result.error("修改部门: "+ dept.getDeptName() +"'失败,上级部门不能为自己!");
}
checkDeptId(dept.getDeptId());
deptService.edit(dept);
return Result.ok();
}
@ApiOperation("删除部门")
@DeleteMapping("/{deptId}")
@PreAuthorize("@ss.hasPermission('admin:dept:del')")
@Log(title = "删除部门",businessType = BusinessType.DELETE)
public Result<Void> delete(@PathVariable Long deptId){
checkDeptId(deptId);
if (deptService.hasChildById(deptId)){
return Result.error("存在下级部门,不允许删除");
}else if (deptService.checkExistUser(deptId)){
return Result.error("该部门下存在用户,不允许删除");
}
deptService.remove(deptId);
return Result.ok();
}
/**
* 检查部门id是都为空
*/
private void checkDeptId(Long deptId){
if (null == deptId){
throw new CustomException("部门id不能为空!");
}
}
}

View File

@@ -0,0 +1,121 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.DictDataDto;
import cn.fateverse.admin.query.DictDataQuery;
import cn.fateverse.admin.vo.DictDataSimpVo;
import cn.fateverse.admin.vo.DictDataVo;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.service.DictDataService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @author Clay
* @date 2022/11/9
*/
@Api(tags = "字典数据管理")
@RestController
@RequestMapping("/dict/data")
public class DictDataController {
private final DictDataService dictDataService;
public DictDataController(DictDataService dictDataService) {
this.dictDataService = dictDataService;
}
@ApiOperation("根据type名称获取缓存字典数据")
@GetMapping("/type/{cacheKeys}")
public Result<Map<String,List<DictDataSimpVo>>> cacheType(@PathVariable List<String> cacheKeys){
if (ObjectUtils.isEmpty(cacheKeys)){
return Result.error("关键参数不能为空!");
}
Map<String,List<DictDataSimpVo>> dictData = dictDataService.get(cacheKeys);
return Result.ok(dictData);
}
@ApiOperation("根据type名称获取缓存字典数据")
@GetMapping("/option/{cacheKey}")
public Result<List<Option>> cacheOption(@PathVariable String cacheKey){
if (StrUtil.isEmpty(cacheKey)){
return Result.error("关键参数不能为空!");
}
List<Option> optionList = dictDataService.option(cacheKey);
return Result.ok(optionList);
}
@ApiOperation("获取字典数据")
@GetMapping
@PreAuthorize("@ss.hasPermission('dict:data:list')")
public Result<TableDataInfo<DictDataVo>> list(DictDataQuery query){
if (StrUtil.isEmpty(query.getDictType())){
return Result.error("字典名称不能为空!");
}
TableDataInfo<DictDataVo> tableData = dictDataService.searchList(query);
return Result.ok(tableData);
}
@ApiOperation("查询字典数据详情")
@GetMapping("/{dictCode}")
@PreAuthorize("@ss.hasPermission('dict:data:info')")
public Result<DictDataVo> info(@PathVariable Long dictCode){
LongUtils.checkId(dictCode);
DictDataVo dictData = dictDataService.searchByCode(dictCode);
return Result.ok(dictData);
}
@ApiOperation("新增字典数据")
@PostMapping
@Log(title = "新增字典类型",businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('dict:data:add')")
public Result<Void> add(@RequestBody @Validated DictDataDto dto){
dictDataService.save(dto);
return Result.ok();
}
@ApiOperation("修改字典数据")
@PutMapping
@Log(title = "修改字典类型",businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('dict:data:edit')")
public Result<Void> edit(@RequestBody @Validated DictDataDto dto){
LongUtils.checkId(dto.getDictCode());
dictDataService.edit(dto);
return Result.ok();
}
@ApiOperation("删除字典数据")
@DeleteMapping("/{dictCode}")
@Log(title = "删除字典类型",businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('dict:data:del')")
public Result<Void> del(@PathVariable Long dictCode){
LongUtils.checkId(dictCode);
dictDataService.removeByCode(dictCode);
return Result.ok();
}
@ApiOperation("删除字典数据")
@DeleteMapping
@Log(title = "删除字典类型",businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('dict:data:del')")
public Result<Void> batchDel(@RequestParam List<Long> dictCodeList){
if (null == dictCodeList|| dictCodeList.isEmpty()){
return Result.error("缺少必要参数!");
}
dictDataService.removeBatch(dictCodeList);
return Result.ok();
}
}

View File

@@ -0,0 +1,99 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.DictTypeDto;
import cn.fateverse.admin.query.DictTypeQuery;
import cn.fateverse.admin.entity.DictType;
import cn.fateverse.admin.service.DictTypeService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import cn.fateverse.common.mybatis.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2022/11/9
*/
@Api(tags = "字典类型管理")
@RestController
@RequestMapping("/dict/type")
public class DictTypeController {
private final DictTypeService dictTypeService;
public DictTypeController(DictTypeService dictTypeService) {
this.dictTypeService = dictTypeService;
}
@ApiOperation("获取字典类型")
@GetMapping
@PreAuthorize("@ss.hasPermission('dict:type:list')")
public Result<TableDataInfo<DictType>> list(DictTypeQuery query){
PageUtils.startPage();
List<DictType> dictTypeList = dictTypeService.searchList(query);
TableDataInfo<DictType> dataTable = PageUtils.getDataTable(dictTypeList);
return Result.ok(dataTable);
}
@ApiOperation("查询字典类型Option")
@GetMapping("/option")
public Result<List<Option>> option(){
List<Option> optionList = dictTypeService.searchOption();
return Result.ok(optionList);
}
@ApiOperation("查询字典类型详情")
@GetMapping("/{dictId}")
@PreAuthorize("@ss.hasPermission('dict:type:info')")
public Result<DictType> info(@PathVariable Long dictId){
LongUtils.checkId(dictId);
DictType dictType = dictTypeService.searchById(dictId);
return Result.ok(dictType);
}
@ApiOperation("新增字典类型")
@PostMapping
@Log(title = "新增字典类型",businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('dict:type:add')")
public Result<Void> add(@RequestBody @Validated DictType dictType){
dictTypeService.save(dictType);
return Result.ok();
}
@ApiOperation("修改字典类型")
@PutMapping
@Log(title = "修改字典类型",businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('dict:type:edit')")
public Result<Void> edit(@RequestBody @Validated DictTypeDto dictTypeDto){
DictType dictType = new DictType();
BeanUtils.copyProperties(dictTypeDto,dictType);
LongUtils.checkId(dictType.getDictId());
dictTypeService.edit(dictType);
return Result.ok();
}
@ApiOperation("删除字典类型")
@DeleteMapping("/{dictId}")
@Log(title = "删除字典类型",businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('dict:type:del')")
public Result<Void> del(@PathVariable Long dictId){
LongUtils.checkId(dictId);
dictTypeService.removeById(dictId);
return Result.ok();
}
}

View File

@@ -0,0 +1,95 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.IpBackDto;
import cn.fateverse.admin.query.IpBackQuery;
import cn.fateverse.admin.service.IpBackService;
import cn.fateverse.admin.vo.ConfigVo;
import cn.fateverse.admin.vo.IpBackVo;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.excel.utils.ExcelUtil;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2023-10-22
*/
@Api(value = "ip黑名单", tags = "ip黑名单")
@RestController
@RequestMapping("/ip/back")
public class IpBackController {
private final IpBackService ipBackService;
public IpBackController(IpBackService ipBackService) {
this.ipBackService = ipBackService;
}
@ApiOperation("获取ip黑名单")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:ipback:list')")
public Result<TableDataInfo<IpBackVo>> list(IpBackQuery query) {
TableDataInfo<IpBackVo> search = ipBackService.search(query);
return Result.ok(search);
}
@ApiOperation("导出excel数据")
@GetMapping("/export")
@PreAuthorize("@ss.hasPermission('admin:ipback:export')")
public void export(IpBackQuery query) {
List<IpBackVo> list = ipBackService.exportList(query);
ExcelUtil.exportExcel(list, IpBackVo.class);
}
@ApiOperation("获取ip黑名单详细信息")
@GetMapping("/{id}")
@PreAuthorize("@ss.hasPermission('admin:ipback:info')")
public Result<IpBackVo> info(@PathVariable Long id) {
ObjectUtils.checkPk(id);
IpBackVo ipBackVo = ipBackService.searchById(id);
return Result.ok(ipBackVo);
}
@ApiOperation("新增ip黑名单")
@PostMapping
@Log(title = "新增ip黑名单", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('admin:ipback:add')")
public Result<Void> add(@RequestBody @Validated IpBackDto ipBackDto) {
ipBackService.save(ipBackDto);
return Result.ok();
}
@ApiOperation("修改ip黑名单")
@PutMapping
@Log(title = "修改ip黑名单", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:ipback:edit')")
public Result<Void> edit(@RequestBody @Validated IpBackDto ipBackDto) {
ObjectUtils.checkPk(ipBackDto.getId());
ipBackService.edit(ipBackDto);
return Result.ok();
}
@ApiOperation("删除ip黑名单")
@DeleteMapping("/{ids}")
@Log(title = "删除ip黑名单", businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('admin:ipback:del')")
public Result<Void> batchDel(@PathVariable List<Long> ids) {
ObjectUtils.checkPkList(ids);
ipBackService.delete(ids);
return Result.ok();
}
}

View File

@@ -0,0 +1,54 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.MappingSwitchDto;
import cn.fateverse.admin.entity.vo.MappingSwitchVo;
import cn.fateverse.admin.query.MappingSwitchQuery;
import cn.fateverse.admin.service.MappingSwitchService;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.decrypt.annotation.Encrypt;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author Clay
* @date 2024/2/5 14:19
*/
@Api(tags = "接口开关")
@RestController
@RequestMapping("/mapping/switch")
public class MapperSwitchController {
private final MappingSwitchService mappingSwitchService;
public MapperSwitchController(MappingSwitchService mappingSwitchService) {
this.mappingSwitchService = mappingSwitchService;
}
@ApiOperation("获取接口开关列表")
@GetMapping
@Encrypt
@PreAuthorize("@ss.hasPermission('mapping:switch:list')")
public Result<TableDataInfo<MappingSwitchVo>> list(MappingSwitchQuery query) {
TableDataInfo<MappingSwitchVo> search = mappingSwitchService.search(query);
return Result.ok(search);
}
@ApiOperation("修改开关状态")
@PutMapping
@Encrypt
@PreAuthorize("@ss.hasPermission('mapping:switch:update')")
@Log(title = "修改开关状态", businessType = BusinessType.UPDATE)
public Result<Void> update(@RequestBody @Validated MappingSwitchDto dto) {
mappingSwitchService.update(dto);
return Result.ok();
}
}

View File

@@ -0,0 +1,128 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.MenuDto;
import cn.fateverse.admin.vo.MenuSimpVo;
import cn.fateverse.admin.vo.MenuVo;
import cn.fateverse.admin.vo.OptionMenuVo;
import cn.fateverse.admin.service.MenuService;
import cn.fateverse.admin.vo.RoleVo;
import cn.fateverse.common.core.entity.OptionTree;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.MenuTypeUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2022/10/30
*/
@Api(tags = "菜单管理")
@RestController
@RequestMapping("/menu")
public class MenuController {
private final MenuService menuService;
public MenuController(MenuService menuService) {
this.menuService = menuService;
}
/**
* 获取到菜单list数据,tree格式输出
*
* @return
*/
@ApiOperation("获取到菜单list数据,tree格式输出")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:menu:list')")
public Result<List<MenuSimpVo>> list(@ApiParam(value = "菜单名称", name = "menuName", required = false) String menuName,
@ApiParam(value = "状态(1:正常,0:失效)", name = "state", required = false) String state) {
List<MenuSimpVo> menuList = menuService.searchTree(menuName, state);
return Result.ok(menuList);
}
@ApiOperation("获取树形接口的option")
@GetMapping("/option/{excludeId}")
public Result<List<OptionTree>> option(@PathVariable Long excludeId) {
if (null != excludeId && excludeId.equals(0L)){
excludeId = null;
}
List<OptionTree> optionTreeList = menuService.searchTreeOption(excludeId);
return Result.ok(optionTreeList);
}
@ApiOperation("获取树形接口的option")
@GetMapping("/option/role/{roleId}")
public Result<OptionMenuVo> optionRole(@PathVariable Long roleId) {
OptionMenuVo optionMenuVo = menuService.searchOptionRoleByRoleId(roleId);
return Result.ok(optionMenuVo);
}
@ApiOperation("获取树形接口的option")
@GetMapping("/info/{menuId}")
public Result<MenuVo> info(@PathVariable Long menuId) {
ObjectUtils.checkPk(menuId);
MenuVo menu = menuService.searchByMenuId(menuId);
return Result.ok(menu);
}
@ApiOperation("新增菜单")
@PostMapping
@Log(title = "新增菜单", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('admin:menu:add')")
public Result<Void> add(@RequestBody @Validated MenuDto menu) {
checkMenuType(menu);
menuService.save(menu);
return Result.ok();
}
@ApiOperation("更新菜单")
@PutMapping
@Log(title = "更新菜单", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:menu:edit')")
public Result<Void> edit(@RequestBody @Validated MenuDto menu) {
checkMenuId(menu.getMenuId());
checkMenuType(menu);
menuService.edit(menu);
return Result.ok();
}
@ApiOperation("删除菜单")
@DeleteMapping("/{menuId}")
@Log(title = "删除菜单", businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('admin:menu:del')")
public Result<Void> del(@PathVariable Long menuId) {
checkMenuId(menuId);
menuService.removeById(menuId);
return Result.ok();
}
public void checkMenuType(MenuDto menu) {
if (MenuTypeUtils.checkMenuTypeLegal(menu.getMenuType())) {
throw new CustomException("菜单类型不合法!");
}
}
public void checkMenuId(Long menuId) {
if (LongUtils.isNull(menuId)) {
throw new CustomException("id不能为空");
}
}
}

View File

@@ -0,0 +1,59 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.entity.OnlineUser;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.service.OnlineUserService;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2022/11/12
*/
@Api(tags = "在线用户")
@RestController
@RequestMapping("/online/user")
public class OnlineUserController {
private final OnlineUserService onlineUserService;
public OnlineUserController(OnlineUserService onlineUserService) {
this.onlineUserService = onlineUserService;
}
@GetMapping
@ApiOperation("获取在线用户信息")
@PreAuthorize("@ss.hasPermission('admin:online:list')")
public Result<TableDataInfo<OnlineUser>> list(
@ApiParam(name="place",value="登录地点") String place,
@ApiParam(name="username",value="登录名称") String username){
TableDataInfo<OnlineUser> tableDataInfo = onlineUserService.searchList(place, username);
return Result.ok(tableDataInfo);
}
@DeleteMapping("/{tokenId}")
@ApiOperation("强制退出用户")
@PreAuthorize("@ss.hasPermission('admin:online:force')")
@Log(title = "强制退出用户",businessType = BusinessType.FORCE)
public Result<Void> force(@PathVariable String tokenId){
if (StrUtil.isEmpty(tokenId)){
return Result.error("必要参数为空!");
}
onlineUserService.force(tokenId);
return Result.ok();
}
}

View File

@@ -0,0 +1,104 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.PostDto;
import cn.fateverse.admin.query.PostQuery;
import cn.fateverse.admin.service.PostService;
import cn.fateverse.admin.vo.PostVo;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Clay
* @date 2022/11/26
*/
@Api(tags = "岗位管理")
@Slf4j
@RestController
@RequestMapping("/post")
public class PostController {
private final PostService postService;
public PostController(PostService postService) {
this.postService = postService;
}
@ApiOperation("查询岗位列表")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:dict:list')")
public Result<TableDataInfo<PostVo>> list(PostQuery query) {
TableDataInfo<PostVo> dataTable = postService.searchList(query);
return Result.ok(dataTable);
}
@ApiOperation("查询岗位列表")
@GetMapping("/info/{postId}")
@PreAuthorize("@ss.hasPermission('admin:dict:info')")
public Result<PostVo> info(@PathVariable Long postId) {
checkPostId(postId);
PostVo post = postService.searchById(postId);
return Result.ok(post);
}
@ApiOperation("获取select下拉框数据")
@GetMapping("/option")
public Result<List<Option>> option() {
List<Option> optionList = postService.searchOption();
return Result.ok(optionList);
}
@ApiOperation("新增岗位")
@PostMapping
@PreAuthorize("@ss.hasPermission('admin:dict:add')")
@Log(title = "新增岗位", businessType = BusinessType.INSERT)
public Result<Void> add(@RequestBody @Validated PostDto postDto) {
postService.save(postDto);
return Result.ok();
}
@ApiOperation("编辑岗位")
@PutMapping
@PreAuthorize("@ss.hasPermission('admin:dict:edit')")
@Log(title = "编辑岗位", businessType = BusinessType.UPDATE)
public Result<Void> edit(@RequestBody @Validated PostDto postDto) {
checkPostId(postDto.getPostId());
postService.edit(postDto);
return Result.ok();
}
@ApiOperation("删除岗位")
@DeleteMapping("/{postId}")
@PreAuthorize("@ss.hasPermission('admin:dict:del')")
@Log(title = "删除岗位", businessType = BusinessType.DELETE)
public Result<Void> del(@PathVariable Long postId) {
checkPostId(postId);
postService.removeById(postId);
return Result.ok();
}
private void checkPostId(Long postId) {
if (LongUtils.isNull(postId)) {
throw new CustomException("id不能为空!");
}
}
}

View File

@@ -0,0 +1,243 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.RoleDto;
import cn.fateverse.admin.entity.Role;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.query.RoleQuery;
import cn.fateverse.admin.vo.RoleVo;
import cn.fateverse.common.core.entity.IdWrapper;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.service.MenuService;
import cn.fateverse.admin.service.RoleService;
import cn.fateverse.admin.service.UserService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.security.entity.LoginUser;
import cn.fateverse.common.security.service.TokenService;
import cn.fateverse.common.security.utils.SecurityUtils;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jetbrains.annotations.NotNull;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2022/11/4
*/
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {
private final RoleService roleService;
private final UserService userService;
private final MenuService menuService;
private final TokenService tokenService;
public RoleController(RoleService roleService, UserService userService, MenuService menuService, TokenService tokenService) {
this.roleService = roleService;
this.userService = userService;
this.menuService = menuService;
this.tokenService = tokenService;
}
@ApiOperation("获取角色列表")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:role:list')")
public Result<TableDataInfo<RoleVo>> list(RoleQuery query) {
TableDataInfo<RoleVo> dataInfo = roleService.searchList(query);
return Result.ok(dataInfo);
}
@ApiOperation("查询角色信息")
@GetMapping("/{roleId}")
@PreAuthorize("@ss.hasPermission('admin:role:info')")
public Result<RoleVo> info(@PathVariable Long roleId) {
checkRoleId(roleId);
RoleVo vo = roleService.searchById(roleId);
return Result.ok(vo);
}
@ApiOperation("根据菜单id获取角色列表")
@GetMapping("/menu/list")
public Result<TableDataInfo<RoleVo>> roleExcludeMenuId(Long menuId, String roleName, String roleKey) {
if (ObjectUtils.isEmpty(menuId)) {
return Result.error("菜单id不能为空!");
}
TableDataInfo<RoleVo> dataInfo = roleService.searchListExcludeMenuId(menuId, roleName, roleKey);
return Result.ok(dataInfo);
}
@ApiOperation("根据菜单id获取分配的角色信息")
@GetMapping("/menu")
public Result<TableDataInfo<RoleVo>> menuRole(Long menuId, String roleName, String roleKey) {
if (ObjectUtils.isEmpty(menuId)) {
return Result.error("菜单id不能为空!");
}
TableDataInfo<RoleVo> dataInfo = roleService.searchListByMenuId(menuId, roleName, roleKey);
return Result.ok(dataInfo);
}
@ApiOperation("建立角色菜单绑定关系")
@PutMapping("/bind/menu")
@PreAuthorize("@ss.hasPermission('admin:user:bindMenu')")
@Log(title = "建立角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> bindRole(@RequestBody IdWrapper wrapper) {
checkRoleIds(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
roleService.bindMenu(wrapper.getId(), wrapper.getIds());
return Result.ok();
}
@ApiOperation("解除角色与菜单之间的绑定状态")
@PutMapping("/unbind/menu")
@PreAuthorize("@ss.hasPermission('admin:role:unBindMenu')")
@Log(title = "解除角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindMenu(@RequestBody IdWrapper wrapper) {
checkRoleIds(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
roleService.unBindMenu(wrapper.getId(), wrapper.getIds());
return Result.ok();
}
@ApiOperation("解除当前角色对应的所有菜单的绑定关系")
@PutMapping("/all/unbind/menu")
@PreAuthorize("@ss.hasPermission('admin:role:unBindMenu')")
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindAllMenu(@RequestBody IdWrapper wrapper) {
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
roleService.unBindAllMenu(wrapper.getId());
return Result.ok();
}
@ApiOperation("查询角色信息")
@GetMapping("/option")
public Result<List<Option>> option() {
List<Option> option = roleService.searchOption();
return Result.ok(option);
}
@ApiOperation("新增角色")
@PostMapping
@Log(title = "新增角色", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('admin:role:add')")
public Result<Void> add(@RequestBody @Validated RoleDto role) {
checkNameAndKey(role);
roleService.save(role);
return Result.ok();
}
@ApiOperation("修改角色")
@PutMapping
@Log(title = "修改角色", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:role:edit')")
public Result<Void> edit(@NotNull @RequestBody @Validated RoleDto role) {
checkRoleId(role.getRoleId());
checkNameAndKey(role);
roleService.edit(role);
checkUserRoleUpdate(role);
return Result.ok();
}
@ApiOperation("修改角色状态")
@PutMapping("/state")
@Log(title = "修改角色状态", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:role:edit')")
public Result<Void> state(@RequestBody RoleDto role) {
if (LongUtils.isNull(role.getRoleId())) {
return Result.error("角色id不能为空!");
}
if (StrUtil.isEmpty(role.getState())) {
return Result.error("状态不能为空!");
}
roleService.editState(role.getRoleId(), role.getState());
checkUserRoleUpdate(role);
return Result.ok();
}
@ApiOperation("删除角色")
@DeleteMapping("/{roleId}")
@Log(title = "删除角色", businessType = BusinessType.DELETE)
@PreAuthorize("@ss.hasPermission('admin:role:del')")
public Result<Void> delete(@PathVariable Long roleId) {
checkRoleId(roleId);
roleService.remove(roleId);
return Result.ok();
}
private void checkRoleIds(List<Long> roleIds) {
if (roleIds == null || roleIds.isEmpty()) {
throw new CustomException("角色id不能为空!");
}
long count = roleIds.stream().filter(roleId -> !ObjectUtils.isEmpty(roleId)).count();
if (count == 0) {
throw new CustomException("角色id不能为空!");
}
}
/**
* 检查角色id
*/
private void checkRoleId(Long roleId) {
if (LongUtils.isNull(roleId)) {
throw new CustomException("id不能为空");
}
}
/**
* 检查角色名称和角色关键词
*/
private void checkNameAndKey(RoleDto dto) {
if (roleService.checkNameUnique(dto)) {
throw new CustomException("角色名称已存在!");
}
if (roleService.checkRoleKeyUnique(dto)) {
throw new CustomException("角色权限名称已存在!");
}
}
private void checkUserRoleUpdate(RoleDto role) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtils.isEmpty(loginUser) || loginUser.getUser().isAdmin()) {
return;
}
List<Role> roles = loginUser.getUser().getRoles();
boolean checked = roles.stream().anyMatch(info -> info.getRoleId().equals(role.getRoleId()));
if (!checked) {
return;
}
User user = userService.searchByUserName(loginUser.getUser().getUserName());
Set<String> permsSet = menuService.searchPermsByUserId(user.getUserId());
loginUser.setUser(user);
loginUser.setPermissions(permsSet);
tokenService.setLoginUser(loginUser);
}
}

View File

@@ -0,0 +1,292 @@
package cn.fateverse.admin.controller;
import cn.fateverse.admin.dto.UserDto;
import cn.fateverse.admin.query.UserQuery;
import cn.fateverse.admin.vo.UserChooseVo;
import cn.fateverse.admin.vo.UserDetailVo;
import cn.fateverse.admin.vo.UserVo;
import cn.fateverse.common.core.entity.IdWrapper;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.service.PostService;
import cn.fateverse.admin.service.RoleService;
import cn.fateverse.admin.service.UserService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.security.annotation.Anonymity;
import cn.fateverse.common.log.annotation.Log;
import cn.fateverse.common.log.enums.BusinessType;
import cn.fateverse.common.mybatis.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.regex.Pattern;
/**
* @author Clay
* @date 2022/10/29
*/
@Api(tags = "用户管理")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
private final UserService userService;
private final RoleService roleService;
private final PostService postService;
public UserController(UserService userService,
RoleService roleService,
PostService postService) {
this.userService = userService;
this.roleService = roleService;
this.postService = postService;
}
@ApiOperation("获取用户列表")
@GetMapping
@PreAuthorize("@ss.hasPermission('admin:user:list')")
public Result<TableDataInfo<UserVo>> list(UserQuery userQuery) {
PageUtils.startPage();
List<UserVo> userVos = userService.searchList(userQuery);
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userVos);
return Result.ok(dataTable);
}
@ApiOperation("根据角色或者部门获取到对应的数据")
@GetMapping("/choose/{type}/{chooseId}")
@Anonymity
public Result<List<UserChooseVo>> choose(@PathVariable Integer type, @PathVariable Long chooseId) {
if (null == type || null == chooseId || type > 1 || type < 0) {
return Result.error("参数异常!");
}
List<UserChooseVo> userChooseList = userService.searchUserChooseRoleOrDept(type, chooseId);
return Result.ok(userChooseList);
}
@ApiOperation("获取用户列表")
@GetMapping("/info/{userId}")
@PreAuthorize("@ss.hasPermission('admin:user:info')")
public Result<UserDetailVo> info(@PathVariable Long userId) {
checkUserId(userId);
UserDetailVo userDetail = userService.searchByUserId(userId);
List<Option> roleOption = roleService.searchOption();
List<Option> postOption = postService.searchOption();
userDetail.setRoleList(roleOption);
userDetail.setPostList(postOption);
return Result.ok(userDetail);
}
@ApiOperation("根据角色id获取用户信息")
@GetMapping("/role/{roleId}")
public Result<TableDataInfo<UserVo>> role(@PathVariable Long roleId, String userName, String phoneNumber) {
LongUtils.checkId(roleId, "角色id不能为空!");
PageUtils.startPage();
List<UserVo> userList = userService.searchListByRoleId(roleId, userName, phoneNumber);
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
return Result.ok(dataTable);
}
@ApiOperation("排除角色id获取用户信息")
@GetMapping("/role/exclude/{roleId}")
public Result<TableDataInfo<UserVo>> excludeRole(@PathVariable Long roleId, String userName, String phoneNumber) {
LongUtils.checkId(roleId, "角色id不能为空!");
TableDataInfo<UserVo> table = userService.searchUserListByExcludeRoleId(roleId, userName, phoneNumber);
return Result.ok(table);
}
@ApiOperation("建立角色用户绑定关系")
@PutMapping("/bind/role")
@PreAuthorize("@ss.hasPermission('admin:user:bindRole')")
@Log(title = "建立角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> bindRole(@RequestBody IdWrapper wrapper) {
checkUserId(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
userService.bindRole(wrapper.getIds(), wrapper.getId());
return Result.ok();
}
@ApiOperation("解除角色与用户之间的绑定状态")
@PutMapping("/unbind/role")
@PreAuthorize("@ss.hasPermission('admin:user:unBindRole')")
@Log(title = "解除角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindRole(@RequestBody IdWrapper wrapper) {
checkUserId(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
userService.unBindRole(wrapper.getIds(), wrapper.getId());
return Result.ok();
}
@ApiOperation("解除当前角色对应的所有用户的绑定关系")
@PutMapping("/all/unbind/role")
@PreAuthorize("@ss.hasPermission('admin:user:unBindRole')")
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindAllRole(@RequestBody IdWrapper wrapper) {
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
userService.unBindAllRole(wrapper.getId());
return Result.ok();
}
// @ApiOperation("根据角色id获取用户信息")
// @GetMapping("/dept/{roleId}")
public Result<TableDataInfo<UserVo>> dept(@PathVariable Long deptId, String userName, String phoneNumber) {
LongUtils.checkId(deptId, "角色id不能为空!");
PageUtils.startPage();
List<UserVo> userList = userService.searchListByDeptId(deptId, userName, phoneNumber);
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
return Result.ok(dataTable);
}
// @ApiOperation("排除角色id获取用户信息")
// @GetMapping("/dept/exclude/{deptId}")
public Result<TableDataInfo<UserVo>> excludeDept(@PathVariable Long deptId, String userName, String phoneNumber) {
LongUtils.checkId(deptId, "角色id不能为空!");
TableDataInfo<UserVo> table = userService.searchUserListByExcludeDeptId(deptId, userName, phoneNumber);
return Result.ok(table);
}
// @ApiOperation("解除角色与用户之间的绑定状态")
// @PutMapping("/unbind/{userIds}/dept/{deptId}")
// @PreAuthorize("@ss.hasPermission('admin:user:unBindRole')")
// @Log(title = "解除角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindDept(@PathVariable List<Long> userIds, @PathVariable Long deptId) {
checkUserId(userIds);
LongUtils.checkId(deptId, "角色id不能为空");
userService.unBindDept(userIds, deptId);
return Result.ok();
}
// @ApiOperation("解除当前角色对应的所有用户的绑定关系")
// @PutMapping("/unbind/dept/{deptId}")
// @PreAuthorize("@ss.hasPermission('admin:user:unBindRole')")
// @Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindAllDept(@PathVariable Long deptId) {
LongUtils.checkId(deptId, "角色id不能为空");
userService.unBindAllDept(deptId);
return Result.ok();
}
@ApiOperation("根据岗位id获取用户信息")
@GetMapping("/post/{postId}")
public Result<TableDataInfo<UserVo>> post(@PathVariable Long postId, String userName, String phoneNumber) {
if (LongUtils.isNull(postId)) {
return Result.error("岗位id不能为空!");
}
PageUtils.startPage();
List<UserVo> userList = userService.searchListByPostId(postId, userName, phoneNumber);
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
return Result.ok(dataTable);
}
@ApiOperation("排除岗位id获取用户信息")
@GetMapping("/post/exclude/{postId}")
public Result<TableDataInfo<UserVo>> excludePost(@PathVariable Long postId, String userName, String phoneNumber) {
LongUtils.checkId(postId, "角色id不能为空!");
TableDataInfo<UserVo> table = userService.searchUserListByExcludePostId(postId, userName, phoneNumber);
return Result.ok(table);
}
@ApiOperation("建立角色用户绑定关系")
@PutMapping("/bind/post")
@PreAuthorize("@ss.hasPermission('admin:user:bindPost')")
@Log(title = "建立角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> bindPost(@RequestBody IdWrapper wrapper) {
checkUserId(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
userService.bindPost(wrapper.getIds(), wrapper.getId());
return Result.ok();
}
@ApiOperation("解除岗位与用户之间的绑定状态")
@PutMapping("/unbind/post")
@PreAuthorize("@ss.hasPermission('admin:user:unbindPost')")
@Log(title = "解除角色用户绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindPost(@RequestBody IdWrapper wrapper) {
checkUserId(wrapper.getIds());
LongUtils.checkId(wrapper.getId(), "岗位id不能为空");
userService.unBindPost(wrapper.getIds(), wrapper.getId());
return Result.ok();
}
@ApiOperation("解除当前岗位对应的所有用户的绑定关系")
@PutMapping("/all/unbind/post")
@PreAuthorize("@ss.hasPermission('admin:user:unbindPost')")
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
public Result<Void> unBindAllPost(@RequestBody IdWrapper wrapper) {
LongUtils.checkId(wrapper.getId(), "岗位id不能为空");
userService.unBindAllPost(wrapper.getId());
return Result.ok();
}
@ApiOperation("新增用户")
@PostMapping
@Log(title = "新增用户", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermission('admin:user:add')")
public Result<Void> add(@NotNull @RequestBody @Validated UserDto user) {
if (StrUtil.isEmpty(user.getPassword())) {
return Result.error("初始密码不能为空");
}
checkPhone(user.getPhoneNumber());
userService.save(user);
return Result.ok();
}
@ApiOperation("修改用户")
@PutMapping
@Log(title = "修改用户", businessType = BusinessType.UPDATE)
@PreAuthorize("@ss.hasPermission('admin:user:edit')")
public Result<Void> edit(@NotNull @RequestBody @Validated UserDto user) {
checkUserId(user.getUserId());
checkPhone(user.getPhoneNumber());
userService.edit(user);
return Result.ok();
}
@ApiOperation("删除用户")
@DeleteMapping("/{userId}")
@PreAuthorize("@ss.hasPermission('admin:user:del')")
@Log(title = "删除用户", businessType = BusinessType.DELETE)
public Result<Void> del(@PathVariable Long userId) {
checkUserId(userId);
userService.remove(userId);
return Result.ok();
}
/**
* 检查用户id是都为空
*/
private void checkUserId(List<Long> userIds) {
if (userIds == null || userIds.isEmpty()) {
throw new CustomException("用户id不能为空!");
}
}
private void checkUserId(Long userId) {
if (LongUtils.isNull(userId)) {
throw new CustomException("用户id不能为空!");
}
}
private void checkPhone(String phone) {
if (!StrUtil.isEmpty(phone) && !Pattern.matches("^1[0-9]{10}$", phone)) {
throw new CustomException("手机号格式错误!");
}
}
}

View File

@@ -0,0 +1,80 @@
package cn.fateverse.admin.controller.test;
import cn.fateverse.common.security.annotation.Anonymity;
import cn.fateverse.common.security.annotation.MappingSwitch;
import org.springframework.web.bind.annotation.*;
/**
* @author Clay
* @date 2024/2/5 15:03
*/
@RestController
@RequestMapping("/test")
public class TestController {
@MappingSwitch
@Anonymity
@GetMapping
public String test() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test1")
public String test1() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test2")
public String test2() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test3")
public String test3() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test4")
public String test4() {
return "test";
}
@MappingSwitch
@Anonymity
@PostMapping("/test5")
public String test5() {
return "test";
}
@MappingSwitch
@Anonymity
@PutMapping("/test6")
public String test6() {
return "test";
}
@MappingSwitch
@Anonymity
@DeleteMapping("/test7")
public String test7() {
return "test";
}
}

View File

@@ -0,0 +1,80 @@
package cn.fateverse.admin.controller.test;
import cn.fateverse.common.security.annotation.Anonymity;
import cn.fateverse.common.security.annotation.MappingSwitch;
import org.springframework.web.bind.annotation.*;
/**
* @author Clay
* @date 2024/2/5 15:03
*/
@RestController
@RequestMapping("/test1")
public class TestController1 {
@MappingSwitch("测试开关")
@Anonymity
@GetMapping
public String test() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test1")
public String test1() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test2")
public String test2() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test3")
public String test3() {
return "test";
}
@MappingSwitch
@Anonymity
@GetMapping("/test4")
public String test4() {
return "test";
}
@MappingSwitch
@Anonymity
@PostMapping("/test5")
public String test5() {
return "test";
}
@MappingSwitch
@Anonymity
@PutMapping("/test6")
public String test6() {
return "test";
}
@MappingSwitch
@Anonymity
@DeleteMapping("/test7")
public String test7() {
return "test";
}
}

View File

@@ -0,0 +1,24 @@
package cn.fateverse.admin.controller.test;
import cn.fateverse.common.security.annotation.Anonymity;
import cn.fateverse.common.security.annotation.MappingSwitch;
import org.springframework.web.bind.annotation.*;
/**
* @author Clay
* @date 2024/2/5 15:03
*/
@MappingSwitch("测试类开关")
@RestController
@RequestMapping("/test2")
public class TestController2 {
@Anonymity
@GetMapping
public String test() {
return "test";
}
}

View File

@@ -0,0 +1,28 @@
package cn.fateverse.admin.dubbo;
import cn.fateverse.admin.service.DeptService;
import cn.fateverse.admin.vo.DeptVo;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
/**
* @author Clay
* @date 2023-02-20
*/
@DubboService
public class DubboDeptServiceImpl implements DubboDeptService {
private final DeptService deptService;
public DubboDeptServiceImpl(DeptService deptService) {
this.deptService = deptService;
}
@Override
public List<DeptVo> searchDeptByDeptId(List<Long> deptIds) {
return deptService.searchByIds(deptIds);
}
}

View File

@@ -0,0 +1,27 @@
package cn.fateverse.admin.dubbo;
import cn.fateverse.admin.service.DictDataService;
import cn.fateverse.admin.vo.DictDataVo;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
import java.util.Map;
/**
* @author Clay
* @date 2023-02-20
*/
@DubboService
public class DubboDictDataServiceImpl implements DubboDictDataService {
private final DictDataService dictDataService;
public DubboDictDataServiceImpl(DictDataService dictDataService) {
this.dictDataService = dictDataService;
}
@Override
public Map<String, Map<String, DictDataVo>> searchDictDataCacheKeys(List<String> cacheKeys) {
return dictDataService.searchCacheKeys(cacheKeys);
}
}

View File

@@ -0,0 +1,59 @@
package cn.fateverse.admin.dubbo;
import cn.fateverse.admin.dto.MenuDto;
import cn.fateverse.admin.service.MenuService;
import cn.fateverse.admin.vo.MenuVo;
import cn.fateverse.admin.vo.RouterVo;
import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.core.utils.MenuTypeUtils;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2023-02-20
*/
@DubboService
public class DubboMenuServiceImpl implements DubboMenuService {
private final MenuService menuService;
public DubboMenuServiceImpl(MenuService menuService) {
this.menuService = menuService;
}
@Override
public Set<String> selectMenuPermsByUserId(Long userId) {
return menuService.searchPermsByUserId(userId);
}
@Override
public List<RouterVo> selectMenuRouterByUserId(Long userId) {
return menuService.searchRouterByUserId(userId);
}
@Override
public Result<Long> insertMenu(MenuDto menuDto) {
if (MenuTypeUtils.checkMenuTypeLegal(menuDto.getMenuType())) {
return Result.error("菜单类型错误");
}
menuService.saveRPC(menuDto);
return Result.ok(menuDto.getMenuId());
}
@Override
public void removeMenu(Long menuId) {
menuService.removeMenu(menuId);
}
@Override
public Result<MenuVo> selectMenuByMenuId(Long menuId) {
MenuVo menu = menuService.searchByMenuId(menuId);
return Result.ok(menu);
}
}

View File

@@ -0,0 +1,37 @@
package cn.fateverse.admin.dubbo;
import cn.fateverse.admin.entity.Role;
import cn.fateverse.admin.mapper.RoleMapper;
import cn.fateverse.admin.query.RoleQuery;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2023-05-06
*/
@DubboService
public class DubboRoleServiceImpl implements DubboRoleService {
private final RoleMapper roleMapper;
public DubboRoleServiceImpl(RoleMapper roleMapper) {
this.roleMapper = roleMapper;
}
@Override
public List<String> searchRoleNameByIds(List<Long> roleIds) {
RoleQuery query = new RoleQuery();
query.setState("0");
List<Role> roleList = roleMapper.selectByIds(roleIds);
if (null == roleList||roleList.isEmpty()){
return new ArrayList<>();
}
return roleList.stream().map(Role::getRoleName).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,66 @@
package cn.fateverse.admin.dubbo;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.service.UserService;
import cn.fateverse.admin.vo.UserVo;
import cn.fateverse.common.core.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
/**
* @author Clay
* @date 2023-02-20
*/
@Slf4j
@DubboService
public class DubboUserServiceImpl implements DubboUserService {
private final UserService userService;
public DubboUserServiceImpl(UserService userService) {
this.userService = userService;
}
@Override
public User getUserByUsername(String username) {
log.info("用户登录:{}", username);
return userService.searchByUserName(username);
}
@Override
public User getUserByUserId(Long userId) {
return userService.searchUserInfoByUserId(userId);
}
@Override
public List<UserVo> searchUserListByRoleIds(List<Long> roleIds) {
if (roleIds.isEmpty()) {
throw new CustomException("角色id不能为空");
}
return userService.searchListByRoleIds(roleIds);
}
@Override
public List<UserVo> searchUserListByUserIds(List<Long> userIds) {
if (userIds.isEmpty()) {
throw new CustomException("用户id不能为空");
}
return userService.searchByUserIds(userIds);
}
@Override
public List<UserVo> searchUserByDeptIds(List<Long> deptIds) {
if (deptIds.isEmpty()) {
throw new CustomException("部门id不能为空");
}
return userService.searchByDeptIds(deptIds);
}
@Override
public List<Long> searchAllUserIds() {
return userService.searchAllUserIds();
}
}

View File

@@ -0,0 +1,106 @@
package cn.fateverse.admin.entity.vo;
import cn.fateverse.common.decrypt.annotation.EncryptField;
import cn.fateverse.common.security.entity.MappingSwitchInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
import java.util.Set;
/**
* @author Clay
* @date 2024/2/5 14:23
*/
@Data
@Builder
@ApiModel("接口开关返回对象")
public class MappingSwitchVo {
/**
* key作为唯一编号
*/
@EncryptField
@ApiModelProperty("key作为唯一编号")
private String key;
/**
* 应用名称
*/
@ApiModelProperty("应用名称")
private String applicationName;
/**
* 类名
*/
@ApiModelProperty("类名")
private String className;
/**
* 方法名称
*/
@ApiModelProperty("方法名称")
private String methodName;
/**
* 描述MappingSwitch注解的value可以为空
*/
@ApiModelProperty("描述MappingSwitch注解的value可以为空")
private String description;
/**
* HandlerMethod中的uri
*/
@ApiModelProperty("HandlerMethod中的uri")
private Set<String> uris;
/**
* 当前开关类型
*/
@ApiModelProperty("当前开关类型")
private String type;
/**
* 当前方法请求类型
*/
@ApiModelProperty("当前方法请求类型")
private Set<String> httpMethods;
/**
* 当前方法的状态,true为正常放行,false为关闭
*/
@ApiModelProperty("当前方法的状态,true为正常放行,false为关闭")
private Boolean state;
/**
* 操作时间
*/
@ApiModelProperty("变更时间")
private Date operTime;
/**
* 操作人员
*/
@ApiModelProperty("操作人员")
private String operName;
public static MappingSwitchVo toMappingSwitchVo(MappingSwitchInfo mappingSwitchInfo) {
return MappingSwitchVo.builder()
.key(mappingSwitchInfo.getKey())
.applicationName(mappingSwitchInfo.getApplicationName())
.className(mappingSwitchInfo.getClassName())
.description(mappingSwitchInfo.getDescription())
.methodName(mappingSwitchInfo.getMethodName())
.uris(mappingSwitchInfo.getUris())
.type(mappingSwitchInfo.getType().toString())
.httpMethods(mappingSwitchInfo.getHttpMethods())
.state(mappingSwitchInfo.getState())
.operName(mappingSwitchInfo.getOperName())
.operTime(mappingSwitchInfo.getOperTime())
.build();
}
}

View File

@@ -0,0 +1,70 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.query.ConfigQuery;
import cn.fateverse.admin.entity.Config;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 参数配置表 Mapper
*
* @author clay
* @date 2023-06-09
*/
public interface ConfigMapper {
/**
* 查询参数配置表
*
* @param configId 参数配置表Id
* @return 参数配置表
*/
Config selectById(Integer configId);
/**
* 查询参数配置表列表
*
* @param query 参数配置表查询
* @return 参数配置表集合
*/
List<Config> selectListPage(@Param("query") ConfigQuery query, @Param("start") Integer start, @Param("size") Integer size);
Long selectCount(@Param("query") ConfigQuery query);
List<Config> selectList(ConfigQuery query);
/**
* 新增参数配置表
*
* @param config 参数配置表
* @return 结果
*/
int insert(Config config);
/**
* 修改参数配置表
*
* @param config 参数配置表
* @return 结果
*/
int update(Config config);
/**
* 删除参数配置表
*
* @param configId 需要删除的参数配置表Id
* @return 结果
*/
int deleteById(Integer configId);
/**
* 批量删除参数配置表
*
* @param configIdList 需要删除的参数配置表Id 集合
* @return 结果
*/
int deleteBatchByIdList(List<Integer> configIdList);
}

View File

@@ -0,0 +1,137 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.Dept;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2022/11/2
*/
public interface DeptMapper {
/**
* 查询部门列表
*
* @param deptName 部门名称
* @param state 部门状态
* @return 部门集合
*/
List<Dept> selectList(@Param("deptName") String deptName, @Param("state") Integer state);
/**
* 通过id查询部门信息
*
* @param deptId 部门id
* @return 返回对象
*/
Dept selectById(Long deptId);
/**
* 获取排除自身的部门列表
*
* @param deptId 部门id
* @return 部门集合
*/
List<Dept> selectExclude(Long deptId);
/**
* 查询所有的子节点
*
* @param deptId 部门id
* @return 部门集合
*/
List<Dept> selectChildrenById(Long deptId);
/**
* 校验部门名称是否唯一
*
* @param deptName 部门名称
* @param parentId 父部门ID
* @return 结果
*/
Dept selectByDeptNameAndParentId(@Param("deptName") String deptName, @Param("parentId") Long parentId);
/**
* 根据父id查询部门信息
* @param parentId 父级部门id
* @return 部门集合
*/
List<Dept> selectListByDeptParentId(Long parentId);
/**
* 通过parentId查询子列表
*
* @param parentId 父级id
* @return 部门名称集合
*/
Set<String> selectDeptNameListByParentId(Long parentId);
/**
* 查找是否存在子节点
*
* @param deptId 部门id
* @return 数量
*/
int selectChildCountByDeptId(Long deptId);
/**
* 查询部门是否存在用户
*
* @param deptId 部门id
* @return 数量
*/
int selectExistUserCount(Long deptId);
/**
* 根据ids获取到部门
*
* @param deptIds 部门id列表
* @return 部门集合对象
*/
List<Dept> selectByIds(List<Long> deptIds);
/**
* 新增部门
*
* @param dept 部门对象
* @return 影响条数
*/
int insert(Dept dept);
/**
* 更新部门信息
*
* @param dept 部门对象
* @return 影响条数
*/
int update(Dept dept);
/**
* 修改部门的状态;
*
* @param dept 部门对象
* @return 影响条数
*/
int updateState(Dept dept);
/**
* 批量修改子元素之前的关系
*
* @param depts 子元素
* @return 结果
*/
int updateChildren(@Param("depts") List<Dept> depts);
/**
* 删除部门
*
* @param deptId 部门id
* @return 运行结构
*/
int delete(Long deptId);
}

View File

@@ -0,0 +1,93 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.query.DictDataQuery;
import cn.fateverse.admin.entity.DictData;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2022/11/9
*/
public interface DictDataMapper {
/**
* 查询字典信息
*
* @param query
* @return
*/
List<DictData> selectList(DictDataQuery query);
/**
* 根据字典类型查询数据
*
* @param dictType
* @return
*/
List<DictData> selectByType(String dictType);
/**
* 查询字典数据需要缓存的列表
*
* @return
*/
List<DictData> selectCacheList();
/**
* 根据code查询字典数据
*
* @param dictCode
* @return
*/
DictData selectByCode(Long dictCode);
/**
* 通过类型查询下方的数据量
*
* @param dictType
* @return
*/
int selectCountByType(String dictType);
/**
* 新增字典数据
*
* @param dictData
* @return
*/
int insert(DictData dictData);
/**
* 修改字典数据
*
* @param dictData
* @return
*/
int update(DictData dictData);
/**
* 删除字典数据
*
* @param dictCode
* @return
*/
int deleteByCode(Long dictCode);
/**
* 批量删除字典数据
* @param dictCodeList
* @return
*/
int deleteBatch(List<Long> dictCodeList);
/**
* 更新DictData的dictType
*
* @param dictType
* @param newDictType
* @return
*/
int updateByDictType(@Param("dictType") String dictType, @Param("newDictType") String newDictType);
}

View File

@@ -0,0 +1,63 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.query.DictTypeQuery;
import cn.fateverse.admin.entity.DictType;
import java.util.List;
/**
* @author Clay
* @date 2022/11/9
*/
public interface DictTypeMapper {
/**
* 查询字典类型列表
*
* @param query
* @return
*/
List<DictType> selectList(DictTypeQuery query);
/**
* 通过字典类型id查询字典信息
*
* @param dictId
* @return
*/
DictType selectByDictId(Long dictId);
/**
* 根据dictType查询字典类型
* @param dictType
* @return
*/
DictType selectByDictType(String dictType);
/**
* 新增字典类型
*
* @param dictType
* @return
*/
int insert(DictType dictType);
/**
* 修改字典类型
*
* @param dictType
* @return
*/
int update(DictType dictType);
/**
* 删除字典信息
*
* @param dictId
* @return
*/
int deleteById(Long dictId);
}

View File

@@ -0,0 +1,68 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.IpBack;
import cn.fateverse.admin.query.IpBackQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2023-10-22
*/
public interface IpBackMapper {
/**
* 查询ip黑名单列表
*
* @param query 查询对象
* @return 查询结果
*/
List<IpBack> selectList(IpBackQuery query);
IpBack selectByIdaddr(String ipAddr);
IpBack selectIpv4Count();
/**
* 根据id查询
*
* @param id id
* @return ip黑名单
*/
IpBack selectById(Long id);
/**
* 根据id查询
*
* @param ids id
* @return ip黑名单
*/
List<IpBack> selectByIds(List<Long> ids);
/**
* 新增数据
*
* @param ipBack ip黑名单
* @return 执行结果
*/
int insert(IpBack ipBack);
/**
* 更新数据
*
* @param ipBack ip黑名单
* @return 执行结果
*/
int update(IpBack ipBack);
/**
* 删除ip
*
* @param ids ip列表
* @return 删除结果
*/
int delete(List<Long> ids);
List<IpBack> selectListStartEnd(@Param("start") int start, @Param("end") int end);
}

View File

@@ -0,0 +1,145 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.Menu;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2022/10/30
*/
public interface MenuMapper {
/**
* 查询菜单列表
*
* @param menuName
* @param state
* @param excludeId
* @param button
* @return
*/
List<Menu> selectList(@Param("menuName") String menuName,
@Param("state") String state,
@Param("excludeId") Long excludeId,
@Param("button") Boolean button);
/**
* 根据用户id获取到用户的菜单信息
*
* @param userId
* @param excludeId
* @return
*/
List<Menu> selectListByUserId(@Param("userId") Long userId,
@Param("menuName") String menuName,
@Param("state") String state,
@Param("excludeId") Long excludeId,
@Param("button") Boolean button);
/**
* 通过id查询菜单详细信息
*
* @param menuId
* @return
*/
Menu selectById(Long menuId);
/**
* 根据用户ID查询权限
*
* @param userId 用户ID
* @return 权限列表
*/
Set<String> selectMenuPermsByUserId(Long userId);
/**
* 获取当前角色拥有的菜单权限
*
* @param roleId
* @return
*/
Set<Long> selectCheckedMenuIdByRoleId(Long roleId);
/**
* 根据用户id查询当前用户拥有的菜单权限集合
*
* @param userId
* @return
*/
Set<Long> selectCheckedMenuIdByUserId(Long userId);
/**
* 获取所有的菜单id,管理员专用
*
* @return
*/
Set<Long> selectAllMenuId();
/**
* 获取全部的树形结构的菜单列表(为超级管理员所放行的权限),这里获取的将是路由信息,则不现实按钮
*
* @return
*/
List<Menu> selectRouterMenuList();
/**
* 通过用户id查询到所有用的权限,这里则获取到对应用户可以选择的option
*
* @param userId 用户ID
* @return
*/
List<Menu> selectRouterMenuListByUserId(@Param("userId") Long userId);
/**
* 通过用户id查询到当前用户所拥有的的权限
*
* @param userId
* @return
*/
List<Menu> selectByUserId(Long userId);
/**
* 新增菜单
*
* @param menu
* @return
*/
int insert(Menu menu);
/**
* 更新菜单信息
*
* @param menu
* @return
*/
int update(Menu menu);
/**
* 根据id删除菜单
*
* @param menuId
* @return
*/
int deleteById(Long menuId);
/**
* 获取到子节点数量
*
* @param menuId 菜单id
* @return 统计数量
*/
Integer selectCountByParentId(Long menuId);
/**
* 通过权限字符查询到菜单信息
*
* @param perms 权限字符
* @return 返回结果
*/
List<Menu> selectByPerms(String perms);
}

View File

@@ -0,0 +1,78 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.query.PostQuery;
import cn.fateverse.admin.entity.Post;
import java.util.List;
/**
* @author Clay
* @date 2022/11/26
*/
public interface PostMapper {
/**
* 查询岗位列表
*
* @param query
* @return
*/
List<Post> selectList(PostQuery query);
/**
* 根据id查询岗位信息
*
* @param id
* @return
*/
Post selectById(Long id);
/**
* 根据岗位code查询岗位信息
*
* @param postCode
* @return
*/
Post selectByPostCode(String postCode);
/**
* 根据岗位名称查询岗位信息
*
* @param postName
* @return
*/
Post selectByPostName(String postName);
/**
* 查询当前岗位下有多少用户
*
* @param postId
* @return
*/
int hasUserByPostId(Long postId);
/**
* 新增岗位
*
* @param post
* @return
*/
int insert(Post post);
/**
* 更新岗位
*
* @param post
* @return
*/
int update(Post post);
/**
* 删除岗位
*
* @param id
* @return
*/
int deleteById(Long id);
}

View File

@@ -0,0 +1,110 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.Role;
import cn.fateverse.admin.query.RoleQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2022/11/4
*/
public interface RoleMapper {
/**
* 查询角色列表
*
* @param query
* @return
*/
List<Role> selectList(RoleQuery query);
/**
* 根据菜单ID搜索角色信息
*
* @param menuId 菜单ID
* @param roleName 角色名称
* @param roleKey 角色关键字
* @return 角色信息列表
*/
List<Role> selectListByMenuId(@Param("menuId") Long menuId, @Param("roleName") String roleName, @Param("roleKey") String roleKey);
/**
* 根据菜单ID排除条件搜索角色列表
*
* @param menuId 菜单ID
* @param roleName 角色名称
* @param roleKey 角色关键字
* @return 符合排除条件的角色列表
*/
List<Role> searchListExcludeMenuId(@Param("menuId") Long menuId, @Param("roleName") String roleName, @Param("roleKey") String roleKey);
/**
* 根据用户id查询用户信息
*
* @param roleId
* @return
*/
Role selectById(Long roleId);
/**
* 新增角色
*
* @param role
* @return
*/
int insert(Role role);
/**
* 更新角色
*
* @param role
* @return
*/
int update(Role role);
/**
* 删除角色
*
* @param roleId
* @return
*/
int delete(Long roleId);
/**
* 检查当前角色下是否还拥有用户
*
* @param roleId
* @return
*/
int hasUserByRoleId(Long roleId);
/**
* 检查角色名称是否唯一
*
* @param roleName
* @return
*/
Role selectByRoleName(String roleName);
/**
* 检查角色权限是否唯一
*
* @param roleKey
* @return
*/
Role selectByRoleKey(String roleKey);
/**
* 根据角色id数组获取到角色信息
*
* @param roleIds
* @return
*/
List<Role> selectByIds(List<Long> roleIds);
}

View File

@@ -0,0 +1,63 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.RoleMenu;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2022/11/6
*/
public interface RoleMenuMapper {
/**
* 根据角色id获取到菜单列表
*
* @param roleId 角色id
* @return 菜单列表
*/
Set<Long> selectMenuIdsByRoleId(Long roleId);
/**
* 批量新增roleMenu映射关系
*
* @param list
* @return
*/
int batch(List<RoleMenu> list);
/**
* 根据角色id删除角色菜单映射表
*
* @param roleId
* @return
*/
int deleteByRoleId(Long roleId);
/**
* 根据菜单id删除角色菜单映射表
*
* @param menuId
* @return
*/
int deleteByMenuId(Long menuId);
/**
* 取消菜单绑定
*
* @param menuId 菜单id
* @param roleIds 角色ids
* @return 执行结果
*/
int unBindMenu(@Param("menuId") Long menuId, @Param("roleIds") List<Long> roleIds);
/**
* 取消当前菜单绑定的所有角色信息
*
* @param menuId 菜单id
* @return 执行结果
*/
int unBindAllMenu(Long menuId);
}

View File

@@ -0,0 +1,193 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.entity.UserBase;
import cn.fateverse.admin.query.UserQuery;
import cn.fateverse.admin.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2022/10/30
*/
public interface UserMapper {
/**
* 通过用户名查询用户
*
* @param userName 用户名
* @return 用户对象信息
*/
User selectByUserName(String userName);
/**
* 获取所有的用户id
*
* @return 所有用的id
*/
List<Long> selectAllUserIds();
/**
* 查询用户列表
*
* @param query 用户查询信息
* @return 用户信息
*/
List<UserVo> selectList(UserQuery query);
/**
* 排除角色id
*
* @param roleId 角色id
* @return 表格数据信息
*/
List<UserVo> selectUserListByExcludeRoleId(@Param("roleId") Long roleId, @Param("userName") String userName, @Param("phoneNumber") String phoneNumber);
/**
* 根据排除的帖子ID、用户名和手机号码查询用户列表
*
* @param postId 排除的帖子ID
* @param userName 用户名
* @param phoneNumber 手机号码
* @return 用户列表
*/
List<UserVo> selectUserListByExcludePostId(@Param("postId") Long postId, @Param("userName") String userName, @Param("phoneNumber") String phoneNumber);
/**
* 根据角色id查询用户信息
*
* @param roleId 角色id
* @return 用户信息
*/
List<UserVo> selectUserListByRoleId(@Param("roleId") Long roleId, @Param("userName") String userName, @Param("phoneNumber") String phoneNumber);
/**
* 根据角色id list 查询用户信息
*
* @param roleIds 角色id列表
* @return 用户信息
*/
List<UserVo> selectUserListByRoleIds(List<Long> roleIds);
/**
* 根据用户id查询用户信息
*
* @param userIds 用户id列表
* @return 用户信息
*/
List<UserVo> selectUserByUserIds(List<Long> userIds);
/**
* 根据部门id列表查询用户信息
*
* @param deptIds 部门id列表
* @return 用户信息
*/
List<UserVo> selectUserByDeptIds(List<Long> deptIds);
/**
* 根据岗位id查询用户信息
*
* @param postId 岗位名称
* @return 用户信息列表
*/
List<UserVo> selectUserListByPostId(@Param("postId") Long postId, @Param("userName") String userName, @Param("phoneNumber") String phoneNumber);
/**
* 通过用户id查询用户信息
*
* @param userId 用户id
* @return 用户信息
*/
User selectUserByUserId(Long userId);
/**
* 校验用户是否唯一
*
* @param userName 用户名称
* @return 用户信息
*/
User selectUserInfoByUserName(String userName);
/**
* 校验手机号是否唯一
*
* @param phoneNumber 电话号码
* @return 用户信息
*/
User selectByPhoneNum(String phoneNumber);
/**
* 校验邮箱是否唯一
*
* @param email 邮箱
* @return 用户信息
*/
User selectByEmail(String email);
/**
* 新增用户
*
* @param user 用户信息
* @return 结果
*/
int insert(UserBase user);
/**
* 更新用户
*
* @param user 用户信息
* @return 结果
*/
int update(UserBase user);
/**
* 删除用户
*
* @param userId 用户id
* @return 结果
*/
int deleteByUserId(Long userId);
/**
* 根据部门ID、用户名和手机号码搜索用户列表
*
* @param deptId 部门ID
* @param userName 用户名
* @param phoneNumber 手机号码
* @return 搜索结果列表
*/
List<UserVo> searchListByDeptId(Long deptId, String userName, String phoneNumber);
/**
* 根据部门ID、用户名和手机号码搜索排除指定部门的用户列表
*
* @param deptId 部门ID
* @param userName 用户名
* @param phoneNumber 手机号码
* @return 搜索结果列表
*/
List<UserVo> searchUserListByExcludeDeptId(Long deptId, String userName, String phoneNumber);
/**
* 解除用户与部门的绑定关系
*
* @param userIds 用户ID列表
* @param deptId 部门ID
*/
void unBindDept(List<Long> userIds, Long deptId);
/**
* 解除部门的所有绑定关系
*
* @param deptId 部门ID
*/
void unBindAllDept(Long deptId);
}

View File

@@ -0,0 +1,53 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.UserPost;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2022/11/26
*/
public interface UserPostMapper {
/**
* 批量新增用户角色映射关系
*
* @param list
* @return
*/
int batchInsert(List<UserPost> list);
/**
* 获取用户对应的岗位id
*
* @param userId
* @return
*/
List<Long> selectPostIdListByUserId(Long userId);
/**
* 根据用户id删除角色菜单映射表
*
* @param userId
* @return
*/
int deleteByUserId(Long userId);
/**
* 解除用户于角色之前的绑定关系
*
* @param userIds
* @param postId
* @return
*/
int removeBind(@Param("userIds") List<Long> userIds, @Param("postId") Long postId);
/**
* 接触当前岗位与所有用户的绑定关系
*
* @param postId 岗位id
* @return 执行结果
*/
int removeBindByPostId(Long postId);
}

View File

@@ -0,0 +1,57 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.UserRole;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Clay
* @date 2022/11/6
*/
public interface UserRoleMapper {
/**
* 批量新增用户角色映射关系
*
* @param list
* @return
*/
int batchInsert(List<UserRole> list);
/**
* 根据用户id删除角色菜单映射表
*
* @param userId
* @return
*/
int deleteByUserId(Long userId);
/**
* 根据角色删除映射关系
*
* @param roleId
* @return
*/
int deleteByRoleId(Long roleId);
/**
* 解除用户于角色之前的绑定关系
*
* @param userIds
* @param roleId
* @return
*/
int unBind(@Param("userIds") List<Long> userIds, @Param("roleId") Long roleId);
/**
* 用户于角色之前的绑定关系
*
* @param userIds
* @param roleId
* @return
*/
int bind(@Param("userIds") List<Long> userIds, @Param("roleId") Long roleId);
}

View File

@@ -0,0 +1,83 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.ConfigDto;
import cn.fateverse.admin.query.ConfigQuery;
import cn.fateverse.admin.vo.ConfigVo;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
/**
* 参数配置表 Service
*
* @author clay
* @date 2023-06-09
*/
public interface ConfigService {
/**
* 查询参数配置表
*
* @param configId 参数配置表Id
* @return 参数配置表
*/
ConfigVo searchById(Integer configId);
/**
* 查询参数配置表列表
*
* @param query 参数配置表
* @return 参数配置表集合
*/
TableDataInfo<ConfigVo> searchList(ConfigQuery query);
TableDataInfo<ConfigVo> searchListPage(ConfigQuery query);
/**
* 查询参数配置表option
*
* @return 选项集合
*/
/**
* 导出参数配置表列表
*
* @param query query 参数配置表
* @return 参数配置表集合
*/
List<ConfigVo> exportList(ConfigQuery query);
/**
* 新增参数配置表
*
* @param config 参数配置表
* @return 结果
*/
int save(ConfigDto config);
/**
* 修改参数配置表
*
* @param config 参数配置表
* @return 结果
*/
int edit(ConfigDto config);
/**
* 删除参数配置表
*
* @param configId 需要删除的参数配置表Id
* @return 结果
*/
int removeById(Integer configId);
/**
* 批量删除参数配置表
*
* @param configIdList 需要删除的参数配置表Id 集合
* @return 结果
*/
int removeBatch(List<Integer> configIdList);
}

View File

@@ -0,0 +1,102 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.vo.DeptVo;
import cn.fateverse.admin.entity.Dept;
import cn.fateverse.common.core.entity.OptionTree;
import java.util.List;
/**
* @author Clay
* @date 2022/11/2
*/
public interface DeptService {
/**
* 查询部门树形结构数据
*
* @param deptName 部门名称
* @param state 部门状态
* @return 部门集合
*/
List<DeptVo> searchTree(String deptName, Integer state);
/**
* 部门id查询部门信息
*
* @param deptId 部门id
* @return 返回对象
*/
DeptVo searchById(Long deptId);
/**
* 获取排除自身的部门树形结构
*
* @param deptId 部门id
* @return 部门树形选择对象
*/
List<OptionTree> searchExcludeTree(Long deptId);
/**
* 获取部门选择的树形结构
*
* @return 部门树形选择对象
*/
List<OptionTree> searchTreeOption();
/**
* 通过ids获取到部门数据
*
* @param deptIds 部门id列表
* @return 部门集合对象
*/
List<DeptVo> searchByIds(List<Long> deptIds);
/**
* 校验部门名称是否唯一
*
* @param dept 部门对象
* @return 结果
*/
String checkNameUnique(Dept dept);
/**
* 是否存在部门子节点
*
* @param deptId 部门ID
* @return 结果
*/
boolean hasChildById(Long deptId);
/**
* 查询部门是否存在用户
*
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
boolean checkExistUser(Long deptId);
/**
* 新增部门
*
* @param dept 部门对象
* @return 影响条数
*/
int save(Dept dept);
/**
* 更新部门信息
*
* @param dept 部门对象
* @return 影响条数
*/
int edit(Dept dept);
/**
* 删除部门
*
* @param deptId 部门id
* @return 影响条数
*/
int remove(Long deptId);
}

View File

@@ -0,0 +1,66 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.entity.DictData;
import cn.fateverse.common.core.constant.CacheConstants;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author Clay
* @date 2022/11/9
*/
@Component
public class DictCacheService {
@Resource
private RedisTemplate<String, List<DictData>> redisTemplate;
public void set(String key, List<DictData> dictDataList) {
redisTemplate.opsForValue().set(getCacheKey(key), dictDataList);
}
public void setInit(String key, List<DictData> dictDataList) {
String cacheKey = getCacheKey(key);
List<DictData> dictData = redisTemplate.opsForValue().get(cacheKey);
if (null == dictData) {
redisTemplate.opsForValue().set(cacheKey, dictDataList);
}
}
public void setTime(String key, List<DictData> dictDataList) {
redisTemplate.opsForValue().set(getCacheKey(key), dictDataList, 30L, TimeUnit.MINUTES);
}
public List<DictData> get(String key) {
return redisTemplate.opsForValue().get(getCacheKey(key));
}
public String getCacheKey(String key) {
return CacheConstants.DICT_KEY + key;
}
public void remove(String key) {
String cacheKey = getCacheKey(key);
redisTemplate.delete(cacheKey);
}
public void clear() {
Set<String> keys = redisTemplate.keys(CacheConstants.DICT_KEY + "*");
if (keys != null && !keys.isEmpty()) {
redisTemplate.delete(keys);
}
}
@Async("fateverseExecutor")
public void asyncRemove(String key) {
remove(key);
}
}

View File

@@ -0,0 +1,89 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.DictDataDto;
import cn.fateverse.admin.query.DictDataQuery;
import cn.fateverse.admin.vo.DictDataSimpVo;
import cn.fateverse.admin.vo.DictDataVo;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
import java.util.Map;
/**
* @author Clay
* @date 2022/11/9
*/
public interface DictDataService {
/**
* 查询字典信息
*
* @param query 查询对象
* @return 表格信息数据
*/
TableDataInfo<DictDataVo> searchList(DictDataQuery query);
/**
* 根据code查询字典数据
*
* @param dictCode 字典code
* @return 字典数据信息
*/
DictDataVo searchByCode(Long dictCode);
/**
* 新增字典数据
*
* @param dto 字典数据
*/
void save(DictDataDto dto);
/**
* 修改字典数据
*
* @param dto 字典数据
*/
void edit(DictDataDto dto);
/**
* 删除字典数据
*
* @param dictCode 字典数据code
*/
void removeByCode(Long dictCode);
/**
* 批量删除字典数据
*
* @param dictCodeList 字典数据code list
*/
void removeBatch(List<Long> dictCodeList);
/**
* 获取到option的字典数据
*
* @param cacheKey 字典缓存key
* @return option选项列表
*/
List<Option> option(String cacheKey);
/**
* 批量获取缓存字典
*
* @param cacheKeys 字典缓存列表
* @return 映射完成后的字典对象
*/
Map<String, Map<String, DictDataVo>> searchCacheKeys(List<String> cacheKeys);
/**
* 获取到完整的字典数据
*
* @param cacheKeys 字典缓存key
* @return 字典数据简单返回对象
*/
Map<String,List<DictDataSimpVo>> get(List<String> cacheKeys);
}

View File

@@ -0,0 +1,85 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.query.DictTypeQuery;
import cn.fateverse.admin.entity.DictType;
import cn.fateverse.common.core.entity.Option;
import java.util.List;
/**
* @author Clay
* @date 2022/11/9
*/
public interface DictTypeService {
/**
* 记载字段缓存数据
*/
void loadingDictCache();
/**
* 清除缓存记录
*/
void clearDictCache();
/**
* 重置字典缓存数据
*/
void resetDictCache();
/**
* 查询字典类型列表
*
* @param query 字典类型查询
* @return 字典类型列表
*/
List<DictType> searchList(DictTypeQuery query);
/**
* 获取到字典类型的option
*
* @return 选项列表
*/
List<Option> searchOption();
/**
* 通过id查询字典类型信息
*
* @param dictId 字典类型id
* @return 字典类型数据
*/
DictType searchById(Long dictId);
/**
* 检查dictType是否唯一
*
* @param dictType 字典类型
* @return 检查结果
*/
boolean checkUnique(DictType dictType);
/**
* 新增字典类型
*
* @param dictType 字典类型
*/
void save(DictType dictType);
/**
* 更新字典类型
*
* @param dictType 字典类型
*/
void edit(DictType dictType);
/**
* 删除字典类型
*
* @param dictId 字典id
*/
void removeById(Long dictId);
}

View File

@@ -0,0 +1,63 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.IpBackDto;
import cn.fateverse.admin.query.IpBackQuery;
import cn.fateverse.admin.vo.IpBackVo;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
/**
* @author Clay
* @date 2023-10-22
*/
public interface IpBackService {
/**
* 查询ip黑名单列表
*
* @param query 查询对象
* @return 查询结果
*/
TableDataInfo<IpBackVo> search(IpBackQuery query);
/**
* 校验ip是否为黑名单
*
* @param ipAddress 校验的ip地址
* @return 结果
*/
Boolean match(String ipAddress);
/**
* 根据id查询
*
* @param id id
* @return ip黑名单
*/
IpBackVo searchById(Long id);
/**
* 新增数据
*
* @param dto ip黑名单
*/
void save(IpBackDto dto);
/**
* 更新数据
*
* @param dto ip黑名单
*/
void edit(IpBackDto dto);
/**
* 删除ip
*
* @param ids ip列表
*/
void delete(List<Long> ids);
List<IpBackVo> exportList(IpBackQuery query);
}

View File

@@ -0,0 +1,28 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.MappingSwitchDto;
import cn.fateverse.admin.entity.vo.MappingSwitchVo;
import cn.fateverse.admin.query.MappingSwitchQuery;
import cn.fateverse.common.core.result.page.TableDataInfo;
/**
* @author Clay
* @date 2024/2/5 14:21
*/
public interface MappingSwitchService {
/**
* 查询列表信息
*
* @param query 查询对象
* @return 查询结果
*/
TableDataInfo<MappingSwitchVo> search(MappingSwitchQuery query);
/**
* 更新状态
*
* @param dto 更新对象
*/
void update(MappingSwitchDto dto);
}

View File

@@ -0,0 +1,106 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.MenuDto;
import cn.fateverse.admin.vo.MenuSimpVo;
import cn.fateverse.admin.vo.MenuVo;
import cn.fateverse.admin.vo.OptionMenuVo;
import cn.fateverse.admin.vo.RouterVo;
import cn.fateverse.common.core.entity.OptionTree;
import java.util.List;
import java.util.Set;
/**
* @author Clay
* @date 2022/10/30
*/
public interface MenuService {
/**
* 根据用户ID查询权限
*
* @param userId 用户ID
* @return 权限列表
*/
Set<String> searchPermsByUserId(Long userId);
/**
* 获取用户路由信息
*
* @param userId 用户id
* @return 路由信息
*/
List<RouterVo> searchRouterByUserId(Long userId);
/**
* 获取到菜单的树形结构
*
* @param menuName 菜单名称
* @param state 状态
* @return tree简单vo
*/
List<MenuSimpVo> searchTree(String menuName, String state);
/**
* 根据菜单id查询菜单信息
*
* @param menuId 菜单id
* @return 菜单返回信息
*/
MenuVo searchByMenuId(Long menuId);
/**
* 获取树形结构的选项
*
* @param excludeId 需要排除的id
* @return 菜单选项
*/
List<OptionTree> searchTreeOption(Long excludeId);
/**
* 通过角色id获取到已选择的菜单列表和当前角色已经选择的菜单
*
* @param roleId 角色id
* @return 菜单选项vo
*/
OptionMenuVo searchOptionRoleByRoleId(Long roleId);
/**
* 新增菜单
*
* @param menu 菜单对象
* @return 影响行数
*/
int save(MenuDto menu);
/**
* rpc请求新增菜单
*
* @param menu 菜单信息
*/
void saveRPC(MenuDto menu);
/**
* 修改菜单
*
* @param menu 菜单对象
* @return 影响行数
*/
int edit(MenuDto menu);
/**
* 删除菜单
*
* @param menuId 菜单id
* @return 影响行数
*/
int removeById(Long menuId);
/**
* 取消自自定义查询id
*
* @param menuId 菜单id
*/
void removeMenu(Long menuId);
}

View File

@@ -0,0 +1,30 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.entity.OnlineUser;
import cn.fateverse.common.core.result.page.TableDataInfo;
/**
* @author Clay
* @date 2022/11/12
*/
public interface OnlineUserService {
/**
* 查询在线用户列表
*
* @param place
* @param username
* @return
*/
TableDataInfo<OnlineUser> searchList(String place, String username);
/**
* 强制退出用户
*
* @param tokenId
*/
void force(String tokenId);
}

View File

@@ -0,0 +1,69 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.PostDto;
import cn.fateverse.admin.query.PostQuery;
import cn.fateverse.admin.vo.PostVo;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
/**
* @author Clay
* @date 2022/11/26
*/
public interface PostService {
/**
* 查询岗位列表
*
* @param query
* @return
*/
TableDataInfo<PostVo> searchList(PostQuery query);
/**
* 获取岗位的选择option选项
*
* @return
*/
List<Option> searchOption();
/**
* 根据岗位id查询岗位信息
*
* @param id
* @return
*/
PostVo searchById(Long id);
/**
* 当前岗位下时候还有用户
* @param postId
* @return
*/
boolean hasUserByRoleId(Long postId);
/**
* 保存岗位信息
*
* @param postDto@return
*/
int save(PostDto postDto);
/**
* 编辑岗位信息
*
* @param postDto@return
*/
int edit(PostDto postDto);
/**
* 删除岗位信息
*
* @param postId
* @return
*/
int removeById(Long postId);
}

View File

@@ -0,0 +1,144 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.RoleDto;
import cn.fateverse.admin.query.RoleQuery;
import cn.fateverse.admin.vo.RoleVo;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
/**
* @author Clay
* @date 2022/11/4
*/
public interface RoleService {
/**
* 查询角色列表
*
* @param query
* @return
*/
TableDataInfo<RoleVo> searchList(RoleQuery query);
/**
* 根据菜单ID搜索角色信息
*
* @param menuId 菜单ID
* @param roleName 角色名称
* @param roleKey 角色关键字
* @return 角色信息列表
*/
TableDataInfo<RoleVo> searchListByMenuId(Long menuId, String roleName, String roleKey);
/**
* 根据菜单ID排除条件搜索角色列表
*
* @param menuId 菜单ID
* @param roleName 角色名称
* @param roleKey 角色关键字
* @return 符合排除条件的角色列表
*/
TableDataInfo<RoleVo> searchListExcludeMenuId(Long menuId, String roleName, String roleKey);
/**
* 根据id查询角色信息
*
* @param roleId
* @return
*/
RoleVo searchById(Long roleId);
/**
* 返回角色的option list
*
* @return
*/
List<Option> searchOption();
/**
* 新增角色
*
* @param dto
* @return
*/
int save(RoleDto dto);
/**
* 更新角色
*
* @param dto
* @return
*/
int edit(RoleDto dto);
/**
* 修改角色的状态
*
* @param roleId
* @param state
* @return
*/
int editState(Long roleId, String state);
/**
* 删除角色
*
* @param roleId
* @return
*/
int remove(Long roleId);
/**
* 当前角色是否还拥有用户
*
* @param roleId
* @return
*/
boolean hasUserByRoleId(Long roleId);
/**
* 检查角色名称是否唯一
*
* @param dto
* @return
*/
boolean checkNameUnique(RoleDto dto);
/**
* 检查角色权限是否唯一
*
* @param dto
* @return
*/
boolean checkRoleKeyUnique(RoleDto dto);
/**
* 绑定角色与菜单
*
* @param menuId 菜单id
* @param roleIds 角色id
* @return 执行结果
*/
int bindMenu(Long menuId, List<Long> roleIds);
/**
* 取消角色的绑定
*
* @param menuId 菜单id
* @param roleIds 角色id
* @return 执行结果
*/
int unBindMenu(Long menuId, List<Long> roleIds);
/**
* 取消当前菜单下的所有角色
*
* @param menuId
* @return
*/
int unBindAllMenu(Long menuId);
}

View File

@@ -0,0 +1,266 @@
package cn.fateverse.admin.service;
import cn.fateverse.admin.dto.UserDto;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.query.UserQuery;
import cn.fateverse.admin.vo.UserChooseVo;
import cn.fateverse.admin.vo.UserDetailVo;
import cn.fateverse.admin.vo.UserVo;
import cn.fateverse.common.core.result.page.TableDataInfo;
import java.util.List;
/**
* @author Clay
* @date 2022/10/30
*/
public interface UserService {
/**
* 通过用户名查询用户信息
*
* @param username
* @return
*/
User searchByUserName(String username);
/**
* 根据用户ID搜索用户信息
*
* @param userId 用户ID
* @return 用户对象
*/
User searchUserInfoByUserId(Long userId);
/**
* 查询用户列表
*
* @param user
* @return
*/
List<UserVo> searchList(UserQuery user);
/**
* 根据角色或者是部门获取到用户信息
*
* @param type
* @param chooseId
* @return
*/
List<UserChooseVo> searchUserChooseRoleOrDept(Integer type, Long chooseId);
/**
* 通过id list查询用户信息
*
* @param roleIds
* @return
*/
List<UserVo> searchListByRoleIds(List<Long> roleIds);
/**
* 根据userId获取用户信息
*
* @param userIds
* @return
*/
List<UserVo> searchByUserIds(List<Long> userIds);
/**
* 根据部门ids获取到用户信息
*
* @param deptIds
* @return
*/
List<UserVo> searchByDeptIds(List<Long> deptIds);
/**
* 通过用户id查询用户信息
*
* @param userId
* @return
*/
UserDetailVo searchByUserId(Long userId);
/**
* 校验用户是否唯一
*
* @param user@return
*/
boolean checkUserNameUnique(UserDto user);
/**
* 校验手机号是否唯一
*
* @param user@return
*/
boolean checkPhoneNumberUnique(UserDto user);
/**
* 校验邮箱是否唯一
*
* @param user@return
*/
boolean checkEmailUnique(UserDto user);
/**
* 根据角色id获取到对应的用户
*
* @param roleId
* @param userName
* @param phoneNumber
* @return
*/
List<UserVo> searchListByRoleId(Long roleId, String userName, String phoneNumber);
/**
* 根据排除的角色id搜索用户列表
*
* @param roleId 角色id
* @param userName 用户名
* @param phoneNumber 电话号码
* @return 表格数据信息
*/
TableDataInfo<UserVo> searchUserListByExcludeRoleId(Long roleId, String userName, String phoneNumber);
/**
* 绑定用户与角色之间的关联关系
*
* @param userIds
* @param roleId
*/
void bindRole(List<Long> userIds, Long roleId);
/**
* 解除角色和用户之间的绑定关系
*
* @param userIds
* @param roleId
* @return
*/
int unBindRole(List<Long> userIds, Long roleId);
/**
* 解除当前角色对应的所有用户的绑定关系
*
* @param roleId
*/
void unBindAllRole(Long roleId);
/**
* 根据岗位id获取对应用户
*
* @param postId
* @return
*/
List<UserVo> searchListByPostId(Long postId, String userName, String phoneNumber);
/**
* 根据排除的帖子ID、角色ID和用户信息搜索用户列表
*
* @param postId 角色ID
* @param userName 用户名
* @param phoneNumber 电话号码
* @return 用户数据信息
*/
TableDataInfo<UserVo> searchUserListByExcludePostId(Long postId, String userName, String phoneNumber);
/**
* 绑定用户与帖子关系
*
* @param userIds 用户ID列表
* @param postId 帖子ID
*/
void bindPost(List<Long> userIds, Long postId);
/**
* 解除岗位和用户之间的绑定关系
*
* @param userIds
* @param postId
* @return
*/
int unBindPost(List<Long> userIds, Long postId);
/**
* 接触当前岗位与所有用户的绑定关系
*
* @param postId 岗位id
* @return 执行结果
*/
int unBindAllPost(Long postId);
/**
* 根据部门ID、用户名和手机号码搜索用户列表
*
* @param deptId 部门ID
* @param userName 用户名
* @param phoneNumber 手机号码
* @return 搜索结果列表
*/
List<UserVo> searchListByDeptId(Long deptId, String userName, String phoneNumber);
/**
* 根据排除部门ID、用户名和手机号码搜索用户列表
*
* @param deptId 部门ID
* @param userName 用户名
* @param phoneNumber 手机号码
* @return 搜索结果用户数据信息
*/
TableDataInfo<UserVo> searchUserListByExcludeDeptId(Long deptId, String userName, String phoneNumber);
/**
* 解绑用户和部门
*
* @param userIds 用户ID列表
* @param deptId 部门ID
*/
void unBindDept(List<Long> userIds, Long deptId);
/**
* 解绑所有部门和用户
*
* @param deptId 部门ID
*/
void unBindAllDept(Long deptId);
/**
* 新增用户信息
*
* @param dto
* @return
*/
int save(UserDto dto);
/**
* 更新用户信息
*
* @param dto
* @return
*/
int edit(UserDto dto);
/**
* 删除用户信息
*
* @param userId
* @return
*/
int remove(Long userId);
/**
* 获取所有的用户id
*
* @return
*/
List<Long> searchAllUserIds();
}

View File

@@ -0,0 +1,102 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.ConfigDto;
import cn.fateverse.admin.query.ConfigQuery;
import cn.fateverse.admin.vo.ConfigVo;
import cn.fateverse.admin.entity.Config;
import cn.fateverse.admin.mapper.ConfigMapper;
import cn.fateverse.admin.service.ConfigService;
import cn.fateverse.common.core.entity.PageInfo;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.core.utils.TableSupport;
import cn.fateverse.common.mybatis.utils.PageUtils;
import cn.fateverse.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* 参数配置表 Controller
*
* @author clay
* @date 2023-06-09
*/
@Slf4j
@Service
public class ConfigServiceImpl implements ConfigService {
private final ConfigMapper configMapper;
public ConfigServiceImpl(ConfigMapper configMapper) {
this.configMapper = configMapper;
}
@Override
public ConfigVo searchById(Integer configId) {
Config config = configMapper.selectById(configId);
return ConfigVo.toConfigVo(config);
}
@Override
public TableDataInfo<ConfigVo> searchList(ConfigQuery query) {
long startTime = System.currentTimeMillis();
PageUtils.startPage();
List<Config> list = configMapper.selectList(query);
log.info("query time :{}", (System.currentTimeMillis() - startTime));
return PageUtils.convertDataTable(list, ConfigVo::toConfigVo);
}
@Override
public TableDataInfo<ConfigVo> searchListPage(ConfigQuery query) {
long startTime = System.currentTimeMillis();
PageInfo pageInfo = TableSupport.buildPageRequest();
Integer start = (pageInfo.getPageNum() - 1) * pageInfo.getPageSize();
List<Config> list = configMapper.selectListPage(query, start, pageInfo.getPageSize());
List<ConfigVo> result = list.stream().filter(item -> !ObjectUtils.isEmpty(item)).map(ConfigVo::toConfigVo).collect(Collectors.toList());
Long count = configMapper.selectCount(query);
log.info("page query time :{}", (System.currentTimeMillis() - startTime));
return PageUtils.convertDataTable(result, count);
}
@Override
public List<ConfigVo> exportList(ConfigQuery query) {
List<Config> list = configMapper.selectList(query);
return list.stream().map(ConfigVo::toConfigVo)
.collect(Collectors.toList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(ConfigDto config) {
Config info = config.toConfig();
info.setCreateBy(SecurityUtils.getUsername());
return configMapper.insert(info);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(ConfigDto config) {
Config info = config.toConfig();
info.setUpdateBy(SecurityUtils.getUsername());
return configMapper.update(info);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int removeById(Integer configId) {
return configMapper.deleteById(configId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int removeBatch(List<Integer> configIdList) {
return configMapper.deleteBatchByIdList(configIdList);
}
}

View File

@@ -0,0 +1,181 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.vo.DeptVo;
import cn.fateverse.admin.mapper.DeptMapper;
import cn.fateverse.admin.service.DeptService;
import cn.fateverse.common.core.constant.UserConstants;
import cn.fateverse.admin.entity.Dept;
import cn.fateverse.common.core.entity.OptionTree;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.core.utils.convert.TreeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/2
*/
@Slf4j
@Service
public class DeptServiceImpl implements DeptService {
private final DeptMapper deptMapper;
public DeptServiceImpl(DeptMapper deptMapper) {
this.deptMapper = deptMapper;
}
@Override
public List<DeptVo> searchTree(String deptName, Integer state) {
List<Dept> deptList = deptMapper.selectList(deptName, state);
return TreeUtil.build(deptList, DeptVo.class, (config) -> {
config.setIdField("deptId");
config.setExclude("phone");
});
}
@Override
public DeptVo searchById(Long deptId) {
Dept dept = deptMapper.selectById(deptId);
DeptVo deptVo = new DeptVo();
BeanUtils.copyProperties(dept, deptVo);
return deptVo;
}
@Override
public List<OptionTree> searchExcludeTree(Long deptId) {
Dept dept = deptMapper.selectById(deptId);
if (0L == dept.getParentId()) {
return new ArrayList<>();
}
List<Dept> deptList = deptMapper.selectExclude(deptId);
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
config.setIdField("deptId");
config.setOption("deptId", "deptName");
});
}
@Override
public List<OptionTree> searchTreeOption() {
List<Dept> deptList = deptMapper.selectList(null, null);
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
config.setIdField("deptId");
config.setOption("deptId", "deptName");
});
}
@Override
public List<DeptVo> searchByIds(List<Long> deptIds) {
List<Dept> deptList = deptMapper.selectByIds(deptIds);
return deptList.stream().map(dept ->
DeptVo.builder()
.deptId(dept.getDeptId())
.parentId(dept.getParentId())
.deptName(dept.getDeptName())
.email(dept.getEmail())
.orderNum(dept.getOrderNum())
.leader(dept.getLeader())
.leaderId(dept.getLeaderId())
.phone(dept.getPhone())
.state(dept.getState())
.createTime(dept.getCreateTime())
.build()
).collect(Collectors.toList());
}
@Override
public String checkNameUnique(Dept dept) {
Long deptId = LongUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
Dept info = deptMapper.selectByDeptNameAndParentId(dept.getDeptName(), deptId);
if (!ObjectUtils.isEmpty(info) && !info.getDeptId().equals(deptId)) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
@Override
public boolean hasChildById(Long deptId) {
return deptMapper.selectChildCountByDeptId(deptId) > 0;
}
@Override
public boolean checkExistUser(Long deptId) {
return deptMapper.selectExistUserCount(deptId) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(Dept dept) {
Set<String> deptNameSet = deptMapper.selectDeptNameListByParentId(dept.getParentId());
Dept info = deptMapper.selectById(dept.getParentId());
if (deptNameSet.contains(dept.getDeptName())) {
throw new CustomException(info.getDeptName() + "下已经存在" + dept.getDeptName() + "部门");
}
if (UserConstants.DEPT_DISABLE.equals(info.getState())) {
throw new CustomException("上级部门停用,不允许添加");
}
dept.setAncestors(info.getAncestors() + "," + info.getDeptId());
return deptMapper.insert(dept);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(Dept dept) {
Dept newParentDept = deptMapper.selectById(dept.getParentId());
Dept oldDept = deptMapper.selectById(dept.getDeptId());
if (null != newParentDept && null != oldDept) {
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
String oldAncestors = oldDept.getAncestors();
dept.setAncestors(newAncestors);
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
}
if (null != newParentDept && UserConstants.DEPT_DISABLE.equals(newParentDept.getState())) {
updateParentDept(dept);
}
return deptMapper.update(dept);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int remove(Long deptId) {
return deptMapper.delete(deptId);
}
/**
* 更新父级部门的状态
*
* @param dept
*/
public void updateParentDept(Dept dept) {
dept = deptMapper.selectById(dept.getDeptId());
deptMapper.updateState(dept);
}
/**
* 更新字元素的ancestors
*
* @param deptId
* @param newAncestors
* @param odlAncestors
*/
public void updateDeptChildren(Long deptId, String newAncestors, String odlAncestors) {
List<Dept> children = deptMapper.selectChildrenById(deptId);
List<Dept> newChildren = children.stream().peek(child -> {
child.setAncestors(child.getAncestors().replace(odlAncestors, newAncestors));
}).collect(Collectors.toList());
if (newChildren.size() > 0) {
deptMapper.updateChildren(newChildren);
}
}
}

View File

@@ -0,0 +1,203 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.DictDataDto;
import cn.fateverse.admin.query.DictDataQuery;
import cn.fateverse.admin.vo.DictDataSimpVo;
import cn.fateverse.admin.vo.DictDataVo;
import cn.fateverse.admin.entity.DictData;
import cn.fateverse.admin.mapper.DictDataMapper;
import cn.fateverse.admin.service.DictCacheService;
import cn.fateverse.admin.service.DictDataService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.mybatis.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/9
*/
@Slf4j
@Service
public class DictDataServiceImpl implements DictDataService {
private final DictDataMapper dictDataMapper;
private final DictCacheService dictCacheService;
private final RedissonClient redissonClient;
public DictDataServiceImpl(DictDataMapper dictDataMapper,
DictCacheService dictCacheService, RedissonClient redissonClient) {
this.dictDataMapper = dictDataMapper;
this.dictCacheService = dictCacheService;
this.redissonClient = redissonClient;
}
@Override
public TableDataInfo<DictDataVo> searchList(DictDataQuery query) {
PageUtils.startPage();
List<DictData> list = dictDataMapper.selectList(query);
return PageUtils.convertDataTable(list, DictData::toDictDataListVo);
}
@Override
public DictDataVo searchByCode(Long dictCode) {
DictData dictData = dictDataMapper.selectByCode(dictCode);
return DictData.toDictDataVo(dictData);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(DictDataDto dto) {
DictData dictData = DictData.toDictData(dto);
deleteCache(dictData.getDictType());
updateDictDataSupplier(dictData.getDictType(), () -> {
dictDataMapper.insert(dictData);
DictData dictDataDB = dictDataMapper.selectByCode(dictData.getDictCode());
return dictDataDB != null;
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(DictDataDto dto) {
DictData dictData = DictData.toDictData(dto);
updateDictDataSupplier(dictData.getDictType(), () -> {
dictDataMapper.update(dictData);
return Boolean.TRUE;
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public void removeByCode(Long dictCode) {
DictData dictData = dictDataMapper.selectByCode(dictCode);
updateDictDataSupplier(dictData.getDictType(), () -> {
dictDataMapper.deleteByCode(dictCode);
DictData dictDataDB = dictDataMapper.selectByCode(dictCode);
return dictDataDB == null;
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public void removeBatch(List<Long> dictCodeList) {
DictData dictData = dictDataMapper.selectByCode(dictCodeList.get(0));
updateDictDataSupplier(dictData.getDictType(), () -> {
dictDataMapper.deleteBatch(dictCodeList);
return Boolean.TRUE;
});
}
/**
* 更新字典信息
*
* @param dictType 字典类型
* @param supplier 函数方法
*/
private void updateDictDataSupplier(String dictType, Supplier<Boolean> supplier) {
deleteCache(dictType);
Boolean result = supplier.get();
if (result) {
asyncDeleteCache(dictType);
}
}
@Override
public List<Option> option(String dictType) {
List<DictData> dictData = refreshCacheList(dictType);
return dictData.stream()
.map(DictData::dictDataToOption).collect(Collectors.toList());
}
@Override
public Map<String, Map<String, DictDataVo>> searchCacheKeys(List<String> dictType) {
Map<String, Map<String, DictDataVo>> mapData = new ConcurrentHashMap<>(8);
dictType.forEach(key -> {
List<DictData> dictData = refreshCacheList(key);
mapData.put(key, dictData.stream().collect(Collectors.toMap(DictData::getDictValue, DictData::toDictDataListVo)));
});
return mapData;
}
@Override
public Map<String, List<DictDataSimpVo>> get(List<String> dictType) {
Map<String, List<DictDataSimpVo>> resultMap = new HashMap<>(dictType.size());
dictType.forEach(cacheKey -> {
List<DictDataSimpVo> list = refreshCacheList(cacheKey).stream()
.map(DictData::toDictDataSimpVo).collect(Collectors.toList());
resultMap.put(cacheKey, list);
});
return resultMap;
}
/**
* 双重检查锁机制去获取并刷新缓存数据
*
* @param cacheKey 缓存key
* @return 字典数据
*/
private List<DictData> refreshCacheList(String cacheKey) {
List<DictData> dictCache = dictCacheService.get(cacheKey);
if (null == dictCache) {
RLock lock = redissonClient.getLock(dictCacheService.getCacheKey(cacheKey) + ":lock");
try {
if (lock.tryLock(2, TimeUnit.SECONDS)) {
dictCache = dictCacheService.get(cacheKey);
if (null == dictCache) {
dictCache = dictDataMapper.selectByType(cacheKey);
if (null == dictCache || dictCache.isEmpty()) {
dictCacheService.setTime(cacheKey, new ArrayList<>());
} else {
dictCacheService.set(cacheKey, dictCache);
}
}
} else {
dictCache = new ArrayList<>();
}
} catch (InterruptedException e) {
log.info("数据获取失败 {}", e.getMessage(), e);
return new ArrayList<>();
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
}
return dictCache;
}
/**
* 删除字典
*
* @param dictType 字典类型
*/
private void deleteCache(String dictType) {
dictCacheService.remove(dictType);
}
/**
* 异步删除字典
*
* @param dictType 字典类型
*/
private void asyncDeleteCache(String dictType) {
dictCacheService.asyncRemove(dictType);
}
}

View File

@@ -0,0 +1,155 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.query.DictTypeQuery;
import cn.fateverse.admin.entity.DictData;
import cn.fateverse.admin.entity.DictType;
import cn.fateverse.admin.mapper.DictDataMapper;
import cn.fateverse.admin.mapper.DictTypeMapper;
import cn.fateverse.admin.service.DictTypeService;
import cn.fateverse.admin.service.DictCacheService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.enums.StateEnum;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/9
*/
@Slf4j
@Service
public class DictTypeServiceImpl implements DictTypeService {
private final DictTypeMapper dictTypeMapper;
private final DictCacheService dictCacheService;
private final DictDataMapper dictDataMapper;
private final ThreadPoolTaskExecutor executor;
public DictTypeServiceImpl(DictTypeMapper dictTypeMapper,
DictCacheService dictCacheService,
DictDataMapper dictDataMapper, ThreadPoolTaskExecutor executor) {
this.dictTypeMapper = dictTypeMapper;
this.dictCacheService = dictCacheService;
this.dictDataMapper = dictDataMapper;
this.executor = executor;
}
@PostConstruct
private void init() {
executor.execute(this::loadingDictCache);
}
@Override
public void loadingDictCache() {
Map<String, List<DictData>> dictDataMap = dictDataMapper.selectCacheList().stream().collect(Collectors.groupingBy(DictData::getDictType));
dictDataMap.forEach(dictCacheService::setInit);
}
@Override
public void clearDictCache() {
dictCacheService.clear();
}
@Override
public void resetDictCache() {
dictCacheService.clear();
loadingDictCache();
}
@Override
public List<DictType> searchList(DictTypeQuery query) {
return dictTypeMapper.selectList(query);
}
@Override
public List<Option> searchOption() {
DictTypeQuery query = new DictTypeQuery();
query.setState(StateEnum.NORMAL.getCode());
List<DictType> dictTypeList = dictTypeMapper.selectList(query);
return dictTypeList.stream().map(dictType ->
Option.builder()
.value(dictType.getDictType())
.label(dictType.getDictName())
.build()
).collect(Collectors.toList());
}
@Override
public DictType searchById(Long dictId) {
return dictTypeMapper.selectByDictId(dictId);
}
@Override
public boolean checkUnique(DictType dictType) {
Long dictId = LongUtils.isNull(dictType.getDictId()) ? -1L : dictType.getDictId();
DictType info = dictTypeMapper.selectByDictType(dictType.getDictType());
return checkDictType(info, dictId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(DictType dictType) {
checkDictType(dictType);
dictTypeMapper.insert(dictType);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(DictType dictType) {
checkDictType(dictType);
DictType old = dictTypeMapper.selectByDictId(dictType.getDictId());
if (null == old) {
log.info("字典类型 id :{} 不存在!", dictType.getDictId());
throw new CustomException("字典类型不存在,操作失败!");
}
dictCacheService.remove(old.getDictType());
if (!old.getDictType().equals(dictType.getDictType())) {
dictDataMapper.updateByDictType(old.getDictType(), dictType.getDictType());
}
dictTypeMapper.update(dictType);
dictCacheService.asyncRemove(old.getDictType());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void removeById(Long dictId) {
DictType dictType = searchById(dictId);
if (null == dictType) {
log.info("字典类型 id :{} 不存在!", dictId);
throw new CustomException("系统异常!");
}
if (dictDataMapper.selectCountByType(dictType.getDictType()) > 0) {
throw new CustomException(dictType.getDictName() + "已经分配,如果需要删除,请清除对应的数据!");
}
dictCacheService.remove(dictType.getDictType());
dictTypeMapper.deleteById(dictId);
dictCacheService.asyncRemove(dictType.getDictType());
}
private boolean checkDictType(DictType info, Long dictId) {
return (!ObjectUtils.isEmpty(info) && !info.getDictId().equals(dictId));
}
private void checkDictType(DictType dictType){
if (checkUnique(dictType)){
throw new CustomException("当前字典类型:"+dictType.getDictType()+"已存在!");
}
}
}

View File

@@ -0,0 +1,198 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.IpBackDto;
import cn.fateverse.admin.entity.IpBack;
import cn.fateverse.admin.mapper.IpBackMapper;
import cn.fateverse.admin.query.IpBackQuery;
import cn.fateverse.admin.service.IpBackService;
import cn.fateverse.admin.vo.IpBackVo;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.IpBackUtils;
import cn.fateverse.common.mybatis.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2023-10-22
*/
@Slf4j
@Service
public class IpBackServiceImpl implements IpBackService {
private final IpBackMapper ipBackMapper;
private final RedisTemplate<String, String> redisTemplate;
private final ThreadPoolTaskExecutor executor;
public IpBackServiceImpl(IpBackMapper ipBackMapper,
RedisTemplate<String, String> redisTemplate, ThreadPoolTaskExecutor executor) {
this.ipBackMapper = ipBackMapper;
this.redisTemplate = redisTemplate;
this.executor = executor;
}
@PostConstruct
public void init() {
executor.execute(this::loadIpBackList);
}
public void loadIpBackList() {
Set<String> keys = redisTemplate.keys(IpBackUtils.BLACK_LIST_IP);
if (keys != null && keys.size() == 1) {
return;
}
int pageSize = 100;
int pageNum = 1;
int count = pageSize;
while (pageSize == count) {
List<IpBack> list = ipBackMapper.selectListStartEnd((pageNum - 1) * pageSize, pageNum * pageSize);
for (IpBack back : list) {
refreshCache(back);
}
count = list.size();
pageNum++;
}
}
@Override
public TableDataInfo<IpBackVo> search(IpBackQuery query) {
PageUtils.startPage();
List<IpBack> list = ipBackMapper.selectList(query);
return PageUtils.convertDataTable(list, IpBack::toIPBackVo);
}
@Override
public Boolean match(String ipAddress) {
//String ipType = IpBackUtils.getIpType(ipAddress);
//switch (ipType) {
// case IPV_4:
// return checkIpv4(ipAddress);
// case IPV_6:
// return checkIpv6(ipAddress);
//}
return redisTemplate.opsForSet().isMember(IpBackUtils.BLACK_LIST_IP, ipAddress);
}
private Boolean checkIpv4(String ipAddress) {
long ip = IpBackUtils.ipToDecimal(ipAddress);
//return redisTemplate.opsForValue().getBit(IpBackUtils.BLACK_LIST_IPV_4, ip);
return redisTemplate.opsForSet().isMember(IpBackUtils.BLACK_LIST_IPV_4, ipAddress);
}
private Boolean checkIpv6(String ipAddress) {
return redisTemplate.opsForSet().isMember(IpBackUtils.BLACK_LIST_IPV_6, ipAddress);
}
@Override
public IpBackVo searchById(Long id) {
IpBack ipBack = ipBackMapper.selectById(id);
if (null == ipBack) {
throw new CustomException("查询结果为空");
}
return ipBack.toIPBackVo();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(IpBackDto dto) {
IpBack ipBack = ipBackMapper.selectByIdaddr(dto.getIpAddr());
if (ipBack != null) {
throw new CustomException("该ip已经存在");
}
String ipType = IpBackUtils.getIpType(dto.getIpAddr());
IpBack back = new IpBack();
back.setType(ipType);
back.setIpAddr(dto.getIpAddr());
ipBackMapper.insert(back);
IpBack newItem = ipBackMapper.selectById(back.getId());
if (newItem != null) {
refreshCache(back);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(IpBackDto dto) {
IpBack oldItem = ipBackMapper.selectById(dto.getId());
if (oldItem == null) {
throw new CustomException("更新失败");
}
String ipType = IpBackUtils.getIpType(dto.getIpAddr());
IpBack back = new IpBack();
back.setId(dto.getId());
back.setType(ipType);
back.setIpAddr(dto.getIpAddr());
ipBackMapper.update(back);
IpBack newItem = ipBackMapper.selectById(dto.getId());
if (newItem.getIpAddr().equals(dto.getIpAddr())) {
removeCache(oldItem);
refreshCache(back);
} else {
throw new CustomException("更新失败");
}
}
private void refreshCache(IpBack back) {
//switch (back.getType()) {
// case IPV_4:
// long ip = IpBackUtils.ipToDecimal(back.getIpAddr());
// //redisTemplate.opsForValue().setBit(IpBackUtils.BLACK_LIST_IPV_4, ip, true);
// redisTemplate.opsForSet().add(IpBackUtils.BLACK_LIST_IPV_4, back.getIpAddr());
// break;
// case IPV_6:
redisTemplate.opsForSet().add(IpBackUtils.BLACK_LIST_IP, back.getIpAddr());
//redisTemplate.opsForSet().add(IpBackUtils.BLACK_LIST_IP, new String(back.getIpAddr().getBytes(StandardCharsets.UTF_8)));
//break;
//}
}
private void removeCache(IpBack oldItem) {
//switch (oldItem.getType()) {
//case IPV_4:
// long oldIp = IpBackUtils.ipToDecimal(oldItem.getIpAddr());
// //redisTemplate.opsForValue().setBit(IpBackUtils.BLACK_LIST_IPV_4, oldIp, false);
// redisTemplate.opsForSet().remove(IpBackUtils.BLACK_LIST_IPV_4, oldItem.getIpAddr());
// break;
//case IPV_6:
redisTemplate.opsForSet().remove(IpBackUtils.BLACK_LIST_IP, oldItem.getIpAddr());
// break;
//}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List<Long> ids) {
List<IpBack> ipBacks = ipBackMapper.selectByIds(ids);
ipBackMapper.delete(ids);
if (ipBacks != null && !ipBacks.isEmpty()) {
for (IpBack ipBack : ipBacks) {
removeCache(ipBack);
}
}
}
public List<IpBackVo> exportList(IpBackQuery query){
List<IpBack> list = ipBackMapper.selectList(query);
return list.stream().map(IpBackVo::toIpBackVo).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,110 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.MappingSwitchDto;
import cn.fateverse.admin.entity.vo.MappingSwitchVo;
import cn.fateverse.admin.query.MappingSwitchQuery;
import cn.fateverse.admin.service.MappingSwitchService;
import cn.fateverse.common.core.constant.UserConstants;
import cn.fateverse.common.core.entity.PageInfo;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.ReflectUserUtils;
import cn.fateverse.common.core.utils.TableSupport;
import cn.fateverse.common.log.enums.OperateType;
import cn.fateverse.common.mybatis.utils.PageUtils;
import cn.fateverse.common.security.entity.MappingSwitchInfo;
import cn.fateverse.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2024/2/5 14:21
*/
@Slf4j
@Service
public class MappingSwitchServiceImpl implements MappingSwitchService {
@Resource
private RedisTemplate<String, MappingSwitchInfo> redisTemplate;
@Override
public TableDataInfo<MappingSwitchVo> search(MappingSwitchQuery query) {
String pattern = getPattern(query);
PageInfo pageInfo = TableSupport.buildPageRequest();
int start = (pageInfo.getPageNum() - 1) * pageInfo.getPageSize();
int end = start + pageInfo.getPageSize();
long total = 0L;
Set<String> keys = new HashSet<>();
try (Cursor<String> scanCursor = redisTemplate.scan(ScanOptions.scanOptions()
.match(pattern).build())) {
while (scanCursor.hasNext()) {
String key = scanCursor.next();
if (total >= start && total < end) {
keys.add(key);
}
total++;
}
}
List<MappingSwitchInfo> switchInfoList = redisTemplate.opsForValue().multiGet(keys);
if (switchInfoList == null || switchInfoList.isEmpty()) {
return PageUtils.getDataTable(new ArrayList<>());
}
List<MappingSwitchVo> result = switchInfoList.stream().map(MappingSwitchVo::toMappingSwitchVo).collect(Collectors.toList());
return PageUtils.convertDataTable(result, total);
}
@NotNull
private String getPattern(MappingSwitchQuery query) {
String mappingSwitchKey = MappingSwitchInfo.MappingSwitchConstant.MAPPING_SWITCH;
String applicationNameKey = "";
if (!ObjectUtils.isEmpty(query.getApplicationName())) {
applicationNameKey = "*" + query.getApplicationName() + "*";
} else {
applicationNameKey = "*";
}
String classNameKey = "";
if (!ObjectUtils.isEmpty(query.getClassName())) {
classNameKey = ":*" + query.getClassName() + "*";
} else {
classNameKey = "";
}
String methodNameKey = "";
if (!ObjectUtils.isEmpty(query.getMethodName())) {
methodNameKey = ":*" + query.getMethodName() + "*";
} else {
methodNameKey = "";
}
if (!ObjectUtils.isEmpty(methodNameKey) && ObjectUtils.isEmpty(classNameKey)) {
classNameKey = ":*";
}
return mappingSwitchKey + applicationNameKey + classNameKey + methodNameKey;
}
@Override
public void update(MappingSwitchDto dto) {
MappingSwitchInfo mappingSwitchInfo = redisTemplate.opsForValue().get(dto.getKey());
if (mappingSwitchInfo == null) {
throw new CustomException("无当前数据信息");
}
if (mappingSwitchInfo.getState() != dto.getState()) {
mappingSwitchInfo.setState(dto.getState());
mappingSwitchInfo.setOperName(SecurityUtils.getUsername());
mappingSwitchInfo.setOperTime(new Date());
redisTemplate.opsForValue().set(mappingSwitchInfo.getKey(), mappingSwitchInfo);
}
}
}

View File

@@ -0,0 +1,290 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.MenuDto;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.vo.MenuSimpVo;
import cn.fateverse.admin.vo.MenuVo;
import cn.fateverse.admin.vo.OptionMenuVo;
import cn.fateverse.admin.vo.RouterVo;
import cn.fateverse.admin.entity.Menu;
import cn.fateverse.admin.utils.MenuTree;
import cn.fateverse.admin.mapper.MenuMapper;
import cn.fateverse.admin.mapper.RoleMenuMapper;
import cn.fateverse.admin.service.MenuService;
import cn.fateverse.common.core.constant.CacheConstants;
import cn.fateverse.common.core.entity.OptionTree;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.utils.convert.TreeUtil;
import cn.fateverse.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/10/30
*/
@Slf4j
@Service
public class MenuServiceImpl implements MenuService {
private final MenuMapper menuMapper;
private final RoleMenuMapper roleMenuMapper;
@Resource
private RedisTemplate<String, Object> redisTemplate;
private final ThreadPoolTaskExecutor executor;
public MenuServiceImpl(MenuMapper menuMapper,
RoleMenuMapper roleMenuMapper,
ThreadPoolTaskExecutor executor) {
this.menuMapper = menuMapper;
this.roleMenuMapper = roleMenuMapper;
this.executor = executor;
}
@Override
public Set<String> searchPermsByUserId(Long userId) {
Set<String> menuSet = menuMapper.selectMenuPermsByUserId(userId);
return menuSet.stream()
.filter(menu -> (!"".equals(menu)))
.collect(Collectors.toSet());
}
@Override
public List<RouterVo> searchRouterByUserId(Long userId) {
List<Menu> menuList = null;
if (User.isAdmin(userId)) {
menuList = menuMapper.selectRouterMenuList();
} else {
menuList = menuMapper.selectRouterMenuListByUserId(userId);
}
return MenuTree.getTree(menuList);
}
@Override
public List<MenuSimpVo> searchTree(String menuName, String state) {
List<Menu> menuList = null;
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
if (User.isAdmin(user.getUserId())) {
menuList = menuMapper.selectList(menuName, state, null, false);
} else {
menuList = menuMapper.selectListByUserId(user.getUserId(), menuName, state, null, false);
}
return TreeUtil.build(menuList, MenuSimpVo.class, (config) -> {
config.setIdField("menuId");
config.setSortOrder(true, "orderNum");
});
}
@Override
public MenuVo searchByMenuId(Long menuId) {
Menu menu = menuMapper.selectById(menuId);
MenuVo menuVo = new MenuVo();
BeanUtils.copyProperties(menu, menuVo);
return menuVo;
}
@Override
public List<OptionTree> searchTreeOption(Long excludeId) {
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
List<Menu> menuList = null;
if (User.isAdmin(user.getUserId())) {
menuList = menuMapper.selectList(null, null, excludeId, true);
} else {
menuList = menuMapper.selectListByUserId(user.getUserId(), null, null, excludeId, true);
}
return TreeUtil.build(menuList, OptionTree.class, (config) -> {
config.setIdField("menuId");
config.setOption("menuId", "menuName");
config.setSortOrder(true, "orderNum");
});
}
@Override
public OptionMenuVo searchOptionRoleByRoleId(Long roleId) {
Set<Long> checkedSet = new HashSet<>();
if (null == roleId || roleId.equals(0L)) {
checkedSet = menuMapper.selectCheckedMenuIdByRoleId(roleId);
}
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
List<Menu> menuList = null;
if (User.isAdmin(user.getUserId())) {
menuList = menuMapper.selectList(null, null, null, true);
} else {
menuList = menuMapper.selectListByUserId(user.getUserId(), null, null, null, true);
}
return OptionMenuVo.builder()
.checked(checkedSet)
.menuOption(TreeUtil.build(menuList, OptionTree.class, (config) -> {
config.setIdField("menuId");
config.setOption("menuId", "menuName");
}))
.build();
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(MenuDto dto) {
return updateMenuAndCache(() -> {
Menu menu = initMenuByType(dto);
menu.setMenuId(null);
return menuMapper.insert(menu);
});
}
@Override
public void saveRPC(MenuDto dto) {
List<Menu> info = menuMapper.selectByPerms(dto.getPerms());
if (info != null && !info.isEmpty()) {
dto.setMenuId(info.get(0).getMenuId());
return;
}
updateMenuAndCache(() -> {
Menu menu = initMenuByType(dto);
menuMapper.insert(menu);
dto.setMenuId(menu.getMenuId());
return null;
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(MenuDto dto) {
return updateMenuAndCache(() -> {
Menu menu = initMenuByType(dto);
return menuMapper.update(menu);
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public int removeById(Long menuId) {
Integer count = menuMapper.selectCountByParentId(menuId);
if (count > 0) {
throw new CustomException("当前菜单还有子项,不允许删除");
}
return updateMenuAndCache(() -> {
roleMenuMapper.deleteByMenuId(menuId);
return menuMapper.deleteById(menuId);
});
}
/**
* 取消自定义查询的菜单
*
* @param menuId 菜单id
*/
@Override
public void removeMenu(Long menuId) {
updateMenuAndCache(() -> {
roleMenuMapper.deleteByMenuId(menuId);
menuMapper.deleteById(menuId);
return null;
});
}
/**
* 函数式编程异步删除缓存
*
* @param supplier 自定义函数方法
* @param <T> 泛型类
* @return 处理结果
*/
public <T> T updateMenuAndCache(Supplier<T> supplier) {
deleteRouteCache();
T result = supplier.get();
asyncDeleteRouteCache();
return result;
}
/**
* 异步删除route缓存信息
*/
public void asyncDeleteRouteCache() {
executor.execute(this::deleteRouteCache);
}
/**
* 删除route缓存信息
*/
public void deleteRouteCache() {
Set<String> keys = redisTemplate.keys(CacheConstants.ROUTE_CACHE_KEY + "*");
if (null != keys && !keys.isEmpty()) {
redisTemplate.delete(keys);
}
}
/**
* 根据菜单类型初始化菜单
*
* @param dto 菜单dto对象
* @return 菜单对象
*/
private Menu initMenuByType(MenuDto dto) {
Menu menu = new Menu();
BeanUtils.copyProperties(dto, menu);
switch (menu.getMenuType()) {
case "C":
initDirectory(menu);
break;
case "M":
initMenu(menu);
break;
case "B":
initButton(menu);
break;
default:
break;
}
return menu;
}
/**
* 初始化目录
*
* @param menu 菜单对象
*/
private void initDirectory(Menu menu) {
menu.setComponent(null);
menu.setPerms(null);
}
/**
* 初始化菜单项
*
* @param menu 菜单对象
*/
private void initMenu(Menu menu) {
}
/**
* 初始化按钮
*
* @param menu 菜单对象
*/
private void initButton(Menu menu) {
menu.setComponent(null);
menu.setPath(null);
menu.setIsFrame(Boolean.FALSE);
menu.setIsCache(Boolean.TRUE);
menu.setVisible("0");
menu.setIcon(null);
}
}

View File

@@ -0,0 +1,111 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.common.core.entity.PageInfo;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.TableSupport;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.entity.OnlineUser;
import cn.fateverse.admin.service.OnlineUserService;
import cn.fateverse.common.core.constant.CacheConstants;
import cn.fateverse.common.security.entity.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/12
*/
@Slf4j
@Service
public class OnlineUserServiceImpl implements OnlineUserService {
@Resource
private RedisTemplate<String, LoginUser> redisTemplate;
/**
* todo 现阶段一次性将所有用户全部返回,后期想办法进行分页操作
*
* @param place
* @param username
* @return
*/
@Override
public TableDataInfo<OnlineUser> searchList(String place, String username) {
Cursor<String> scan = redisTemplate.scan(ScanOptions.scanOptions().match(CacheConstants.LOGIN_TOKEN_KEY + "*").count(1000).build());
List<String> keys = scan.stream().collect(Collectors.toList());
if (keys.isEmpty()) {
return new TableDataInfo<>(new ArrayList<>(), 0);
}
PageInfo pageInfo = TableSupport.buildPageRequest();
Integer pageNum = pageInfo.getPageNum();
Integer pageSize = pageInfo.getPageSize();
int startNum = (pageNum - 1) * pageSize;
int endNum = pageNum * pageSize;
List<String> search;
if (keys.size() < startNum) {
return new TableDataInfo<>(new ArrayList<>(), keys.size());
} else if (keys.size() > startNum && keys.size() < endNum) {
search = keys.subList(startNum, keys.size());
} else {
search = keys.subList(startNum, endNum);
}
List<LoginUser> multiCacheMapValue = redisTemplate.opsForValue().multiGet(search);
if (multiCacheMapValue == null || multiCacheMapValue.isEmpty()) {
return new TableDataInfo<>(new ArrayList<>(), keys.size());
}
List<OnlineUser> list = multiCacheMapValue.stream()
//.filter(user -> checkQuery(user, place, username))
.map(this::toOnlineUser)
.collect(Collectors.toList());
return new TableDataInfo<>(list, keys.size());
}
@Override
public void force(String tokenId) {
redisTemplate.delete(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
}
private OnlineUser toOnlineUser(LoginUser user) {
return OnlineUser.builder()
.tokenId(user.getUuid())
.username(user.getUsername())
.deptName(user.getUser().getDept().getDeptName())
.ipAddr(user.getIpddr())
.loginLocation(user.getLoginLocation())
.browser(user.getBrowser())
.os(user.getOs())
.loginTime(new Date(user.getLoginTime()))
.build();
}
/**
* 过滤用户信息
*
* @param user
* @param place
* @param username
* @return
*/
private boolean checkQuery(LoginUser user, String place, String username) {
if (!StrUtil.isEmpty(place) && !StrUtil.isEmpty(username)) {
return user.getLoginLocation().contains(place) && user.getUsername().contains(username);
} else if (!StrUtil.isEmpty(place)) {
return user.getLoginLocation().contains(place);
} else if (!StrUtil.isEmpty(username)) {
return user.getUsername().contains(username);
}
return true;
}
}

View File

@@ -0,0 +1,119 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.PostDto;
import cn.fateverse.admin.query.PostQuery;
import cn.fateverse.admin.entity.Post;
import cn.fateverse.admin.mapper.PostMapper;
import cn.fateverse.admin.service.PostService;
import cn.fateverse.admin.vo.PostVo;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.enums.StateEnum;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.mybatis.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/26
*/
@Slf4j
@Service
public class PostServiceImpl implements PostService {
private final PostMapper postMapper;
public PostServiceImpl(PostMapper postMapper) {
this.postMapper = postMapper;
}
@Override
public TableDataInfo<PostVo> searchList(PostQuery query) {
List<Post> list = postMapper.selectList(query);
return PageUtils.convertDataTable(list, PostVo::toPostVo);
}
@Override
public List<Option> searchOption() {
PostQuery query = new PostQuery();
query.setState(StateEnum.NORMAL.getCode());
List<Post> postList = postMapper.selectList(query);
return postList.stream().map(post -> Option.builder()
.value(post.getPostId())
.label(post.getPostName())
.build()).collect(Collectors.toList());
}
@Override
public PostVo searchById(Long id) {
Post post = postMapper.selectById(id);
if (post == null){
throw new CustomException("查询结果为空!");
}
return PostVo.toPostVo(post);
}
private boolean checkCodeUnique(Long postId,String postCode) {
Post info = postMapper.selectByPostCode(postCode);
return checkDictType(info, postId);
}
private boolean checkNameUnique(Long postId,String postName) {
Post info = postMapper.selectByPostName(postName);
return checkDictType(info, postId);
}
@Override
public boolean hasUserByRoleId(Long postId) {
return postMapper.hasUserByPostId(postId) == 1;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(PostDto postDto) {
checkPostInfo(postDto, "新增");
Post post = new Post();
BeanUtils.copyProperties(postDto, post);
return postMapper.insert(post);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(PostDto postDto) {
checkPostInfo(postDto, "修改");
Post post = new Post();
BeanUtils.copyProperties(postDto, post);
return postMapper.update(post);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int removeById(Long postId) {
if (hasUserByRoleId(postId)) {
throw new CustomException("当前岗位下还存在用户,不允许删除!");
}
return postMapper.deleteById(postId);
}
private boolean checkDictType(Post info, Long postId) {
return (!ObjectUtils.isEmpty(info) && !info.getPostId().equals(postId));
}
private void checkPostInfo(PostDto post, String type) {
if (checkCodeUnique(post.getPostId(),post.getPostCode())) {
throw new CustomException(type + post.getPostName() + "岗位名称失败,岗位代码已存在!");
}
if (checkNameUnique(post.getPostId(),post.getPostName())) {
throw new CustomException(type + post.getPostName() + "岗位名称失败,岗位名称已存在!");
}
}
}

View File

@@ -0,0 +1,222 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.RoleDto;
import cn.fateverse.admin.entity.Role;
import cn.fateverse.admin.query.RoleQuery;
import cn.fateverse.admin.vo.RoleVo;
import cn.fateverse.admin.entity.RoleMenu;
import cn.fateverse.admin.mapper.MenuMapper;
import cn.fateverse.admin.mapper.RoleMapper;
import cn.fateverse.admin.mapper.RoleMenuMapper;
import cn.fateverse.admin.service.RoleService;
import cn.fateverse.common.core.entity.Option;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.core.utils.StateUtils;
import cn.fateverse.common.security.utils.SecurityUtils;
import cn.fateverse.common.mybatis.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/4
*/
@Slf4j
@Service
public class RoleServiceImpl implements RoleService {
private final RoleMapper roleMapper;
private final RoleMenuMapper roleMenuMapper;
public RoleServiceImpl(RoleMapper roleMapper,
RoleMenuMapper roleMenuMapper) {
this.roleMapper = roleMapper;
this.roleMenuMapper = roleMenuMapper;
}
@Override
public TableDataInfo<RoleVo> searchList(RoleQuery query) {
PageUtils.startPage();
List<Role> list = roleMapper.selectList(query);
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
}
@Override
public TableDataInfo<RoleVo> searchListByMenuId(Long menuId, String roleName, String roleKey) {
PageUtils.startPage();
List<Role> list = roleMapper.selectListByMenuId(menuId, roleName, roleKey);
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
}
@Override
public TableDataInfo<RoleVo> searchListExcludeMenuId(Long menuId, String roleName, String roleKey) {
PageUtils.startPage();
List<Role> list = roleMapper.searchListExcludeMenuId(menuId,roleName,roleKey);
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
}
@Override
public RoleVo searchById(Long roleId) {
Role role = roleMapper.selectById(roleId);
RoleVo roleVo = RoleVo.toRoleVo(role);
Set<Long> menuIds = roleMenuMapper.selectMenuIdsByRoleId(roleId);
roleVo.setMenuIds(menuIds);
return roleVo;
}
@Override
public List<Option> searchOption() {
RoleQuery query = new RoleQuery();
query.setState("1");
List<Role> roleList = roleMapper.selectList(query);
return roleList.stream().map(role -> Option.builder()
.value(role.getRoleId())
.label(role.getRoleName())
.build()).collect(Collectors.toList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(RoleDto dto) {
Role role = dto.toRole();
checkState(role.getState());
int result = roleMapper.insert(role);
dto.setRoleId(role.getRoleId());
batchRoleMenu(dto, Boolean.FALSE);
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(RoleDto dto) {
Role role = dto.toRole();
checkRoleAllowed(role);
checkState(dto.getState());
batchRoleMenu(dto, Boolean.TRUE);
return roleMapper.update(role);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int editState(Long roleId, String state) {
checkState(state);
Role roleUpdate = Role.builder()
.roleId(roleId)
.state(state)
.build();
checkRoleAllowed(roleUpdate);
return roleMapper.update(roleUpdate);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int remove(Long roleId) {
if (hasUserByRoleId(roleId)) {
throw new CustomException("当前角色拥有用户,删除失败!");
}
checkRoleAllowed(new Role(roleId));
roleMenuMapper.deleteByRoleId(roleId);
return roleMapper.delete(roleId);
}
@Override
public boolean hasUserByRoleId(Long roleId) {
return roleMapper.hasUserByRoleId(roleId) > 0;
}
@Override
public boolean checkNameUnique(RoleDto dto) {
Long roleId = LongUtils.isNull(dto.getRoleId()) ? -1L : dto.getRoleId();
Role info = roleMapper.selectByRoleName(dto.getRoleName());
return chickRole(info, roleId);
}
@Override
public boolean checkRoleKeyUnique(RoleDto dto) {
Long roleId = LongUtils.isNull(dto.getRoleId()) ? -1L : dto.getRoleId();
Role info = roleMapper.selectByRoleKey(dto.getRoleKey());
return chickRole(info, roleId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int bindMenu(Long menuId, List<Long> roleIds) {
List<RoleMenu> roleMenuList = roleIds.stream().filter(LongUtils::isNotNull).map(roleId -> RoleMenu.builder().roleId(roleId)
.menuId(menuId).build()).collect(Collectors.toList());
if (roleMenuList.isEmpty()){
throw new CustomException("角色id不能为空");
}
return roleMenuMapper.batch(roleMenuList);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unBindMenu(Long menuId, List<Long> roleIds) {
return roleMenuMapper.unBindMenu(menuId, roleIds);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unBindAllMenu(Long menuId) {
return roleMenuMapper.unBindAllMenu(menuId);
}
public void checkRoleAllowed(Role role) {
if (!ObjectUtils.isEmpty(role.getRoleId()) && role.isAdmin()) {
throw new CustomException("不允许操作超级管理员角色");
}
}
private void batchRoleMenu(RoleDto role, boolean updateFlag) {
Set<Long> menuIds = role.getMenuIds();
if (updateFlag) {
// Set<Long> checkedSet = null;
// if (role.getRoleId().equals(1L)) {
// checkedSet = menuMapper.selectAllMenuId();
// } else {
// checkedSet = menuMapper.selectCheckedMenuIdByRoleId(role.getRoleId());
// }
// Set<Long> userMenuIds = menuMapper.selectCheckedMenuIdByUserId(SecurityUtils.getUserId());
// Set<Long> other = checkedSet.stream().filter(check -> !userMenuIds.contains(check)).collect(Collectors.toSet());
// menuIds.addAll(other);
roleMenuMapper.deleteByRoleId(role.getRoleId());
}
if (!menuIds.isEmpty()) {
List<RoleMenu> roleMenuList = menuIds.stream()
.filter(menuId -> 0L != menuId)
.map(menuId -> RoleMenu.builder()
.menuId(menuId)
.roleId(role.getRoleId())
.build()).collect(Collectors.toList());
if (roleMenuList.isEmpty()) {
return;
}
roleMenuMapper.batch(roleMenuList);
}
}
private void checkState(String state) {
if (!StateUtils.checkStateLegal(state)) {
throw new CustomException("状态值不合法!");
}
}
private boolean chickRole(Role role, Long roleId) {
return (!ObjectUtils.isEmpty(role) && !role.getRoleId().equals(roleId));
}
}

View File

@@ -0,0 +1,419 @@
package cn.fateverse.admin.service.impl;
import cn.fateverse.admin.dto.UserDto;
import cn.fateverse.admin.entity.*;
import cn.fateverse.admin.mapper.*;
import cn.fateverse.admin.query.RoleQuery;
import cn.fateverse.admin.query.UserQuery;
import cn.fateverse.admin.vo.UserChooseVo;
import cn.fateverse.admin.vo.UserDetailVo;
import cn.fateverse.admin.vo.UserVo;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.entity.User;
import cn.fateverse.admin.service.UserService;
import cn.fateverse.common.core.exception.CustomException;
import cn.fateverse.common.core.result.page.TableDataInfo;
import cn.fateverse.common.core.utils.LongUtils;
import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.mybatis.utils.PageUtils;
import cn.fateverse.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/10/30
*/
@Slf4j
@Service
public class UserServiceImpl implements UserService {
private final UserMapper userMapper;
private final UserRoleMapper userRoleMapper;
private final UserPostMapper userPostMapper;
private final RoleMapper roleMapper;
private final DeptMapper deptMapper;
public UserServiceImpl(UserMapper userMapper,
UserRoleMapper userRoleMapper,
UserPostMapper userPostMapper,
RoleMapper roleMapper, DeptMapper deptMapper) {
this.userMapper = userMapper;
this.userRoleMapper = userRoleMapper;
this.userPostMapper = userPostMapper;
this.roleMapper = roleMapper;
this.deptMapper = deptMapper;
}
@Override
public User searchByUserName(String username) {
return userMapper.selectByUserName(username);
}
@Override
public User searchUserInfoByUserId(Long userId) {
return userMapper.selectUserByUserId(userId);
}
@Override
public List<UserVo> searchList(UserQuery user) {
return userMapper.selectList(user);
}
@Override
public List<UserChooseVo> searchUserChooseRoleOrDept(Integer type, Long chooseId) {
List<UserChooseVo> result;
switch (type) {
// 0代表角色
case 0:
result = chooseRole(chooseId);
break;
// 1代表部门
case 1:
result = chooseDept(chooseId);
break;
default:
throw new CustomException("参数异常");
}
return result;
}
@Override
public List<UserVo> searchListByRoleIds(List<Long> roleIds) {
return userMapper.selectUserListByRoleIds(roleIds);
}
@Override
public List<UserVo> searchByUserIds(List<Long> userIds) {
return userMapper.selectUserByUserIds(userIds);
}
@Override
public List<UserVo> searchByDeptIds(List<Long> deptIds) {
return userMapper.selectUserByDeptIds(deptIds);
}
@Override
public UserDetailVo searchByUserId(Long userId) {
User user = userMapper.selectUserByUserId(userId);
List<Long> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
user.setDept(null);
user.setRoles(null);
user.setPassword(null);
List<Long> postIds = userPostMapper.selectPostIdListByUserId(userId);
return UserDetailVo.builder()
.user(user)
.postIds(postIds)
.roleIds(roleIds)
.build();
}
@Override
public boolean checkUserNameUnique(UserDto user) {
Long userId = getUserId(user);
User info = userMapper.selectUserInfoByUserName(user.getUserName());
return checkUser(info, userId);
}
@Override
public boolean checkPhoneNumberUnique(UserDto user) {
if (StrUtil.isEmpty(user.getPhoneNumber())) {
return false;
}
Long userId = getUserId(user);
User info = userMapper.selectUserInfoByUserName(user.getPhoneNumber());
return checkUser(info, userId);
}
@Override
public boolean checkEmailUnique(UserDto user) {
if (StrUtil.isEmpty(user.getEmail())) {
return false;
}
Long userId = getUserId(user);
User info = userMapper.selectByEmail(user.getEmail());
return checkUser(info, userId);
}
@Override
public List<UserVo> searchListByRoleId(Long roleId, String userName, String phoneNumber) {
return userMapper.selectUserListByRoleId(roleId, userName, phoneNumber);
}
@Override
public TableDataInfo<UserVo> searchUserListByExcludeRoleId(Long roleId, String userName, String phoneNumber) {
PageUtils.startPage();
List<UserVo> list = userMapper.selectUserListByExcludeRoleId(roleId, userName, phoneNumber);
Long total = PageUtils.getTotal(list);
return PageUtils.convertDataTable(list, total);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void bindRole(List<Long> userIds, Long roleId) {
List<UserRole> userRoleList = userIds.stream().filter(LongUtils::isNotNull)
.map(userId -> UserRole.builder().roleId(roleId).userId(userId).build())
.collect(Collectors.toList());
if (!userRoleList.isEmpty()) {
userRoleMapper.batchInsert(userRoleList);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unBindRole(List<Long> userIds, Long roleId) {
return userRoleMapper.unBind(userIds, roleId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void unBindAllRole(Long roleId) {
userRoleMapper.deleteByRoleId(roleId);
}
@Override
public List<UserVo> searchListByPostId(Long postId, String userName, String phoneNumber) {
return userMapper.selectUserListByPostId(postId, userName, phoneNumber);
}
@Override
public TableDataInfo<UserVo> searchUserListByExcludePostId(Long postId, String userName, String phoneNumber) {
PageUtils.startPage();
List<UserVo> list = userMapper.selectUserListByExcludePostId(postId, userName, phoneNumber);
Long total = PageUtils.getTotal(list);
return PageUtils.convertDataTable(list, total);
}
@Override
public void bindPost(List<Long> userIds, Long postId) {
List<UserPost> userPostList = userIds.stream().filter(LongUtils::isNotNull)
.map(userId -> UserPost.builder().userId(userId).postId(postId).build())
.collect(Collectors.toList());
if (!userPostList.isEmpty()) {
userPostMapper.batchInsert(userPostList);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unBindPost(List<Long> userIds, Long postId) {
return userPostMapper.removeBind(userIds, postId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unBindAllPost(Long postId) {
return userPostMapper.removeBindByPostId(postId);
}
/**
* 选择部门
*
* @param deptId
* @return
*/
private List<UserChooseVo> chooseDept(Long deptId) {
List<Dept> deptList = deptMapper.selectListByDeptParentId(deptId);
List<UserChooseVo> result = deptList.stream().map(dept -> UserChooseVo.toUserChooseByDept(dept, deptId)).collect(Collectors.toList());
List<UserVo> userList = userMapper.selectUserByDeptIds(Collections.singletonList(deptId));
userList.forEach(user -> result.add(UserChooseVo.toUserChooseByUser(user, deptId)));
return result;
}
/**
* 选择角色
*
* @param roleId 角色id
* @return 选择成功的用户信息
*/
private List<UserChooseVo> chooseRole(Long roleId) {
if (roleId.equals(0L)) {
List<Role> roleList = roleMapper.selectList(new RoleQuery());
return roleList.stream().map(UserChooseVo::toUserChooseByRole).collect(Collectors.toList());
} else {
List<UserVo> userList = userMapper.selectUserListByRoleId(roleId, null, null);
return userList.stream().map(user ->
UserChooseVo.toUserChooseByUser(user, roleId)
).collect(Collectors.toList());
}
}
@Override
public List<UserVo> searchListByDeptId(Long deptId, String userName, String phoneNumber) {
return userMapper.searchListByDeptId(deptId, userName, phoneNumber);
}
@Override
public TableDataInfo<UserVo> searchUserListByExcludeDeptId(Long deptId, String userName, String phoneNumber) {
PageUtils.startPage();
Dept dept = deptMapper.selectById(deptId);
if (null == dept) {
throw new CustomException("当前部门不存在");
}
// dept.getAncestors()
List<UserVo> list = userMapper.searchUserListByExcludeDeptId(deptId, userName, phoneNumber);
Long total = PageUtils.getTotal(list);
return PageUtils.convertDataTable(list, total);
}
@Override
public void unBindDept(List<Long> userIds, Long deptId) {
userMapper.unBindDept(userIds, deptId);
}
@Override
public void unBindAllDept(Long deptId) {
userMapper.unBindAllDept(deptId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int save(UserDto dto) {
checkUser(dto);
UserBase user = insertInitUser(dto);
int result = userMapper.insert(user);
dto.setUserId(user.getUserId());
batchUserRole(dto, Boolean.FALSE);
batchUserPost(dto, Boolean.FALSE);
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(UserDto dto) {
if (dto.getUserId().equals(1L)) {
throw new RuntimeException("超级管理员不允许操作!");
}
checkUser(dto);
batchUserRole(dto, Boolean.TRUE);
batchUserPost(dto, Boolean.TRUE);
dto.setPassword(null);
UserBase user = dto.toUser();
return userMapper.update(user);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int remove(Long userId) {
if (userId.equals(1L)) {
throw new RuntimeException("超级管理员不允许操作!");
}
userRoleMapper.deleteByUserId(userId);
userPostMapper.deleteByUserId(userId);
return userMapper.deleteByUserId(userId);
}
@Override
public List<Long> searchAllUserIds() {
return userMapper.selectAllUserIds();
}
/**
* 批量处理用户与角色之间的对应关系
*/
private void batchUserRole(UserDto userDto, boolean updateFlag) {
Set<Long> roleIds = new HashSet<>(userDto.getRoleIds());
if (!roleIds.isEmpty()) {
if (updateFlag) {
userRoleMapper.deleteByUserId(userDto.getUserId());
}
List<UserRole> userRoleList = roleIds.stream().filter(LongUtils::isNotNull)
.map(roleId -> UserRole.builder().roleId(roleId).userId(userDto.getUserId()).build())
.collect(Collectors.toList());
if (userRoleList.isEmpty()) {
return;
}
userRoleMapper.batchInsert(userRoleList);
}
}
/**
* 批量处理用户与岗位之间的对应关系
*/
private void batchUserPost(UserDto userDto, boolean updateFlag) {
Set<Long> postIds = new HashSet<>(userDto.getPostIds());
if (!postIds.isEmpty()) {
if (updateFlag) {
userPostMapper.deleteByUserId(userDto.getUserId());
}
List<UserPost> userPostList = postIds.stream().filter(LongUtils::isNotNull)
.map(postId -> UserPost.builder().postId(postId).userId(userDto.getUserId()).build())
.collect(Collectors.toList());
if (userPostList.isEmpty()) {
return;
}
userPostMapper.batchInsert(userPostList);
}
}
/**
* 初始化新增用户
*
* @param dto
*/
private UserBase insertInitUser(UserDto dto) {
UserBase user = dto.toUser();
user.setPassword(SecurityUtils.encryptPassword(dto.getPassword()));
return user;
}
/**
* 获取到用户id
*
* @param user
* @return
*/
private Long getUserId(UserDto user) {
return LongUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
}
/**
* 检查用户知否运行被更改
*
* @param user
* @param userId
* @return
*/
private boolean checkUser(User user, Long userId) {
return (!ObjectUtils.isEmpty(user) && !user.getUserId().equals(userId));
}
/**
* 检查用户id是都为空
*/
private void checkUser(UserDto user) {
if (checkUserNameUnique(user)) {
throw new CustomException("用户名已存在!");
} else if (checkPhoneNumberUnique(user)) {
throw new CustomException("电话号码已存在");
} else if (checkEmailUnique(user)) {
throw new CustomException("邮箱已存在");
}
}
}

View File

@@ -0,0 +1,175 @@
package cn.fateverse.admin.utils;
import cn.fateverse.admin.vo.MetaVo;
import cn.fateverse.admin.vo.RouterVo;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.fateverse.admin.entity.Menu;
import cn.fateverse.common.core.enums.MenuEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2022/11/5
*/
public class MenuTree {
/**
* 获取树形结构
*
* @param menuList 菜单list
* @return 菜单路由
*/
public static List<RouterVo> getTree(List<Menu> menuList) {
if (chickMenuList(menuList)) {
return null;
}
Map<Long, List<Menu>> menuMap = menuList.stream().collect(Collectors.groupingBy(Menu::getParentId));
RouterVo routerVo = new RouterVo();
routerVo.setPath("");
return getChildrenRouterVo(0L, menuMap, routerVo);
}
private static boolean chickMenuList(List<Menu> menuList) {
return null == menuList || menuList.isEmpty();
}
/**
* 获取子节点
*
* @param parentId 父级id
* @param menuMap 菜单映射对象
* @return 路由信息
*/
private static List<RouterVo> getChildrenRouterVo(Long parentId, Map<Long, List<Menu>> menuMap, RouterVo parent) {
List<Menu> menuList = menuMap.get(parentId);
if (chickMenuList(menuList)) {
return null;
}
menuList = menuList.stream().sorted(Comparator.comparing(menu -> {
if (null == menu.getOrderNum()) {
return 0;
} else {
return menu.getOrderNum();
}
})).collect(Collectors.toList());
List<RouterVo> result = new ArrayList<>();
for (Menu menu : menuList) {
if (MenuEnum.BUTTON.getCode().equals(menu.getMenuType())) {
continue;
}
MetaVo meta = new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getIsCache(), menu.getNoRedirect(), menu.getBreadcrumb(), menu.getIsFrame());
RouterVo router = RouterVo.builder()
.name(getRouteName(menu))
.path(getRouterPath(menu, parent))
.pathParams(menu.getPathParams())
.hidden("0".equals(menu.getVisible()))
.component(getComponent(menu))
.meta(meta)
.build();
router.setChildren(getChildrenRouterVo(menu.getMenuId(), menuMap, router));
if (null != router.getChildren() && router.getChildren().size() > 0
&& MenuEnum.DIRECTORY.getCode().equals(menu.getMenuType())) {
menu.setNoRedirect(Boolean.TRUE);
router.setMeta(meta);
router.setAlwaysShow(Boolean.TRUE);
} else if (isMenuFrame(menu)) {
List<RouterVo> childrenList = new ArrayList<>();
RouterVo children = RouterVo.builder()
.pathParams(menu.getPathParams())
.path(menu.getPath())
.component(menu.getComponent())
.name(StringUtils.capitalize(menu.getMenuName()))
.meta(meta)
.build();
childrenList.add(children);
router.setChildren(childrenList);
}
result.add(router);
}
if (result.isEmpty()) {
return null;
}
return result;
}
/**
* 获取到路径名称
*
* @param menu 菜单对象
* @return 路由名称
*/
private static String getRouteName(Menu menu) {
String routerName = StringUtils.capitalize(menu.getPath());
if (isMenuFrame(menu)) {
routerName = null;
}
return routerName;
}
/**
* 是否是一级菜单
*
* @param menu 菜单对象
* @return 正确性
*/
private static boolean isMenuFrame(Menu menu) {
return menu.getParentId().equals(0L) && MenuEnum.MENU.getCode().equals(menu.getMenuType()) && !menu.getIsFrame();
}
/**
* 获取前端组件
*
* @param menu 菜单对象
* @return 组件
*/
private static String getComponent(Menu menu) {
String component = MenuEnum.LAYOUT.getInfo();
if (MenuEnum.DIRECTORY.getCode().equals(menu.getMenuType())) {
if (menu.getParentId().equals(0L)) {
return component;
} else {
return MenuEnum.PARENT_VIEW.getInfo();
}
}
if (!StrUtil.isEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
component = menu.getComponent();
}
return component;
}
/**
* 获取路由
*
* @param menu 菜单对象
* @param parent 父级路由
* @return 返回路由path
*/
public static String getRouterPath(Menu menu, RouterVo parent) {
String routerPath = menu.getPath();
// 非外链并且是一级目录(类型为目录)
if (0 == menu.getParentId().intValue() && MenuEnum.DIRECTORY.getCode().equals(menu.getMenuType())
&& !menu.getIsFrame()) {
routerPath = "/" + menu.getPath();
}
// 非外链并且是一级目录(类型为菜单)
else if (isMenuFrame(menu)) {
routerPath = "/";
} else if (MenuEnum.MENU.getCode().equals(menu.getMenuType()) || MenuEnum.DIRECTORY.getCode().equals(menu.getMenuType())) {
routerPath = parent.getPath() + "/" + menu.getPath();
}
return routerPath;
}
}

View File

@@ -0,0 +1,28 @@
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
# server-addr: 10.7.127.185:38848
server-addr: 162.14.111.170:8848
namespace: gary
dubbo:
registry:
parameters:
namespace: dubbo-gary
seata:
service:
grouplist:
seata-server: 10.7.127.185:8091
registry:
nacos:
namespace: dev
config:
apollo:
namespace: seata-config

View File

@@ -0,0 +1,22 @@
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: nacos.fateverse.svc.cluster.local:8848
seata:
service:
grouplist:
seata-server: seataio.fateverse.svc.cluster.local:8091
registry:
nacos:
namespace: pro
config:
apollo:
namespace: seata-pro
management:
server:
port: 9595

View File

@@ -0,0 +1,75 @@
# Tomcat
server:
port: 9010
# Spring
spring:
application:
# 应用名称
name: admin
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.101.108:8848
username: nacos
password: nacos
namespace: ${spring.profiles.active}
config:
# 配置中心地址
server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml
namespace: ${spring.profiles.active}
shared-configs:
- data-id: application-${spring.profiles.active}.yaml
refresh: true
encrypt:
secretKey: 1234567890abcdef
dubbo:
application:
name: dubbo-${spring.application.name}
protocol:
name: dubbo
port: -1
registry:
address: nacos://${spring.cloud.nacos.discovery.server-addr}
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
parameters:
namespace: dubbo-${spring.profiles.active}
seata:
application-id: ${spring.application.name}
tx-service-group: default_tx_group
service:
grouplist:
seata-server: 10.7.127.185:8091
registry:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
group: SEATA_GROUP
namespace: dev
config:
type: nacos
nacos:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
group: SEATA_GROUP
namespace: seata-config
client:
undo:
log-serialization: kryo
data-validation: true
rm:
report-retry-count: 5
table-meta-check-enable: false

View File

@@ -0,0 +1,112 @@
<?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="cn.fateverse.admin.mapper.ConfigMapper">
<resultMap id="ConfigResult" type="cn.fateverse.admin.entity.Config">
<id column="config_id" property="configId"/>
<result column="config_name" property="configName"/>
<result column="config_key" property="configKey"/>
<result column="config_value" property="configValue"/>
<result column="config_type" property="configType"/>
<result column="create_by" property="createBy"/>
<result column="create_time" property="createTime"/>
<result column="update_by" property="updateBy"/>
<result column="update_time" property="updateTime"/>
<result column="remark" property="remark"/>
</resultMap>
<sql id="selectConfigVo">
select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config
</sql>
<select id="selectList" resultMap="ConfigResult">
<include refid="selectConfigVo"/>
<where>
<if test="configName != null and configName != ''"> and config_name like concat('%', #{configName}, '%')</if>
<if test="configKey != null and configKey != ''"> and config_key like concat('%', #{configKey}, '%')</if>
<if test="configType != null "> and config_type = #{configType}</if>
</where>
</select>
<select id="selectListPage" resultType="cn.fateverse.admin.entity.Config">
<include refid="selectConfigVo"/>
<where>
config_id >= (select config_id from sys_config
<where>
<if test="query.configName != null and query.configName != ''"> and config_name like concat('%', #{query.configName}, '%')</if>
<if test="query.configKey != null and query.configKey != ''"> and config_key like concat('%', #{query.configKey}, '%')</if>
<if test="query.configType != null "> and config_type = #{query.configType}</if>
</where> limit #{start},1)
<if test="query.configName != null and query.configName != ''"> and config_name like concat('%', #{query.configName}, '%')</if>
<if test="query.configKey != null and query.configKey != ''"> and config_key like concat('%', #{query.configKey}, '%')</if>
<if test="query.configType != null "> and config_type = #{query.configType}</if>
limit #{size}
</where>
</select>
<select id="selectById" resultMap="ConfigResult">
<include refid="selectConfigVo"/>
where config_id = #{configId}
</select>
<select id="selectCount" resultType="java.lang.Long">
select count(*) from sys_config
<where>
<if test="query.configName != null and query.configName != ''"> and config_name like concat('%', #{query.configName}, '%')</if>
<if test="query.configKey != null and query.configKey != ''"> and config_key like concat('%', #{query.configKey}, '%')</if>
<if test="query.configType != null "> and config_type = #{query.configType}</if>
</where>
</select>
<insert id="insert" >
insert into sys_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="configName != null">config_name,</if>
<if test="configKey != null">config_key,</if>
<if test="configValue != null">config_value,</if>
<if test="configType != null">config_type,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null ">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="configName != null">#{configName},</if>
<if test="configKey != null">#{configKey},</if>
<if test="configValue != null">#{configValue},</if>
<if test="configType != null">#{configType},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null ">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_config
<set>
<if test="configName != null">config_name = #{configName},</if>
<if test="configKey != null">config_key = #{configKey},</if>
<if test="configValue != null">config_value = #{configValue},</if>
<if test="configType != null">config_type = #{configType},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
</set>
where config_id = #{configId}
</update>
<delete id="deleteById">
delete from sys_config
where config_id = #{configId}
</delete>
<delete id="deleteBatchByIdList" parameterType="Integer">
delete from sys_config
where config_id in
<foreach collection="list" open="(" close=")" separator="," item="configId">
#{configId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,183 @@
<?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="cn.fateverse.admin.mapper.DeptMapper">
<sql id="selectSql">
select dept_id,
parent_id,
ancestors,
dept_name,
order_num,
leader,
leader_id,
phone,
email,
state,
del_flag,
create_by,
create_time,
update_by,
update_time
from sys_dept
</sql>
<select id="selectList" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
<where>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%',#{deptName},'%')</if>
<if test="state != null"> and `state` = #{state}</if>
</where>
order by parent_id, order_num
</select>
<select id="selectById" resultType="cn.fateverse.admin.entity.Dept">
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.leader_id,
d.phone,
d.email,
d.state,
d.del_flag,
d.create_by,
d.create_time,
d.update_by,
d.update_time
from sys_dept d
left join sys_dept p on p.dept_id = d.parent_id
where d.dept_id = #{deptId}
</select>
<select id="selectExclude" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
where dept_id != #{deptId} and parent_id != #{deptId}
</select>
<select id="selectChildrenById" parameterType="Long" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
where find_in_set(#{deptId}, ancestors)
</select>
<select id="selectByDeptNameAndParentId" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
where dept_name = #{deptName} and parent_id = #{parentId} limit 1
</select>
<select id="selectListByDeptParentId" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
where parent_id = #{parentId}
</select>
<select id="selectChildCountByDeptId" resultType="java.lang.Integer">
select count(1)
from sys_dept
where parent_id = #{deptId}
and del_flag = '0'
limit 1
</select>
<select id="selectExistUserCount" resultType="java.lang.Integer">
select count(1)
from sys_user
where dept_id = #{deptId}
and del_flag = '0'
limit 1
</select>
<select id="selectDeptNameListByParentId" resultType="java.lang.String">
select dept_name from sys_dept where parent_id = #{parentId}
</select>
<select id="selectByIds" resultType="cn.fateverse.admin.entity.Dept">
<include refid="selectSql"/>
where dept_id in
<foreach collection="list" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<insert id="insert">
insert into sys_dept
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
<if test="deptName != null and deptName != ''">dept_name,</if>
<if test="ancestors != null and ancestors != ''">ancestors,</if>
<if test="orderNum != null and orderNum != ''">order_num,</if>
<if test="leader != null and leader != ''">leader,</if>
<if test="leaderId != null ">leader_id,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="email != null and email != ''">email,</if>
<if test="state != null">state,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptId != null and deptId != 0">#{deptId},</if>
<if test="parentId != null and parentId != 0">#{parentId},</if>
<if test="deptName != null and deptName != ''">#{deptName},</if>
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
<if test="orderNum != null and orderNum != ''">#{orderNum},</if>
<if test="leader != null and leader != ''">#{leader},</if>
<if test="leaderId != null ">#{leaderId},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="state != null">#{state},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_dept
<set>
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
<if test="ancestors != null">ancestors = #{ancestors},</if>
<if test="orderNum != null">order_num = #{orderNum},</if>
<if test="leader != null">leader = #{leader},</if>
<if test="leaderId != null">leader_id = #{leaderId},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="email != null">email = #{email},</if>
<if test="state != null">state = #{state},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where dept_id = #{deptId}
</update>
<update id="updateChildren" parameterType="java.util.List">
update sys_dept set ancestors =
<foreach collection="depts" item="item" index="index"
separator=" " open="case dept_id" close="end">
when #{item.deptId} then #{item.ancestors}
</foreach>
where dept_id in
<foreach collection="depts" item="item" index="index"
separator="," open="(" close=")">
#{item.deptId}
</foreach>
</update>
<update id="updateState">
update sys_dept
<set>
<if test="state != null and state != ''">state = #{state},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where dept_id in (${ancestors})
</update>
<delete id="delete">
delete
from sys_dept
where dept_id = #{deptId}
</delete>
</mapper>

View File

@@ -0,0 +1,127 @@
<?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="cn.fateverse.admin.mapper.DictDataMapper">
<resultMap id="DictDataResult" type="cn.fateverse.admin.entity.DictData">
<id column="dict_code" property="dictCode"/>
<result column="dict_sort" property="dictSort"/>
<result column="dict_label" property="dictLabel"/>
<result column="dict_value" property="dictValue"/>
<result column="dict_type" property="dictType"/>
<result column="is_type" property="isType"/>
<result column="list_class" property="listClass"/>
<result column="theme" property="theme"/>
<result column="is_default" property="isDefault"/>
<result column="state" property="state"/>
<result column="create_by" property="createBy"/>
<result column="create_time" property="createTime"/>
<result column="update_by" property="updateBy"/>
<result column="update_time" property="updateTime"/>
<result column="remark" property="remark"/>
</resultMap>
<sql id="selectDictData">
select dict_code, dict_sort, dict_label, dict_value, dict_type, is_type, list_class, theme, is_default, state, create_by, create_time, update_by, update_time, remark
from sys_dict_data
</sql>
<select id="selectList" resultMap="DictDataResult">
<include refid="selectDictData"/>
<where>
<if test="dictType != null and dictType != ''">and dict_type = #{dictType} </if>
<if test="dictLabel != null and dictLabel != ''">and dict_label like concat('%', #{dictLabel},'%')</if>
<if test="state != null and state != ''">and state = #{state}</if>
</where>
order by dict_sort asc
</select>
<select id="selectByCode" resultMap="DictDataResult">
<include refid="selectDictData"/>
where dict_code = #{dictCode}
</select>
<select id="selectCacheList" resultMap="DictDataResult">
select dd.dict_code, dd.dict_sort, dd.dict_label, dd.dict_value, dd.dict_type, dd.is_type, dd.list_class, dd.theme, dd.is_default, dd.state, dd.create_by, dd.create_time, dd.update_by, dd.update_time, dd.remark
from sys_dict_data dd
left join sys_dict_type dt on dd.dict_type = dt.dict_type
where dd.state = '1' and dt.state = '1'
order by dd.dict_sort asc
</select>
<select id="selectByType" resultType="cn.fateverse.admin.entity.DictData">
<include refid="selectDictData"/>
where dict_type = #{dictType} and state = '1'
</select>
<select id="selectCountByType" resultType="java.lang.Integer">
select count(1) from sys_dict_data where dict_type = #{dictType}
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="dictCode" keyColumn="dict_code">
insert into sys_dict_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dictSort != null">dict_sort,</if>
<if test="dictLabel != null and dictLabel != ''">dict_label,</if>
<if test="dictValue != null and dictValue != ''">dict_value,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="isType != null and isType != ''">is_type,</if>
<if test="listClass != null and listClass != ''">list_class,</if>
<if test="theme != null and theme != ''">theme,</if>
<if test="isDefault != null and isDefault != ''">is_default,</if>
<if test="state != null and state != ''">state,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="dictSort != null">#{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="isType != null and isType != ''">#{isType},</if>
<if test="listClass != null and listClass != ''">#{listClass},</if>
<if test="theme != null and theme != ''">#{theme},</if>
<if test="isDefault != null and isDefault != ''">#{isDefault},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_dict_data
<set>
<if test="dictSort != null">dict_sort = #{dictSort},</if>
<if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
<if test="dictValue != null and dictValue != ''">dict_value = #{dictValue},</if>
<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
<if test="isType != null">is_type = #{isType},</if>
<if test="listClass != null and listClass != ''">list_class = #{listClass},</if>
<if test="theme != null and theme != ''">theme = #{theme},</if>
<if test="isDefault != null">is_default = #{isDefault},</if>
<if test="state != null and state != ''">state = #{state},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where dict_code = #{dictCode}
</update>
<update id="updateByDictType">
update sys_dict_data set dict_type = #{dictType} where dict_type = #{newDictType}
</update>
<delete id="deleteByCode">
delete
from sys_dict_data
where dict_code = #{dictCode}
</delete>
<delete id="deleteBatch">
delete
from sys_dict_data
where dict_code in
<foreach collection="list" open="(" close=")" separator="," item="dictCode">
#{dictCode}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,94 @@
<?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="cn.fateverse.admin.mapper.DictTypeMapper">
<resultMap id="DictTypeResult" type="cn.fateverse.admin.entity.DictType">
<id property="dictId" column="dict_id"/>
<result property="dictName" column="dict_name"/>
<result property="dictType" column="dict_type"/>
<result property="state" column="state"/>
<result property="remark" column="remark"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectDict">
select dict_id,
dict_name,
dict_type,
state,
create_by,
create_time,
update_by,
update_time,
remark
from sys_dict_type
</sql>
<select id="selectList" resultMap="DictTypeResult">
<include refid="selectDict"/>
<where>
<if test="dictName != null and dictName != ''">and dict_name like concat('%',#{dictName},'%')</if>
<if test="dictType != null and dictType != ''">and dict_type like concat('%',#{dictType},'%')</if>
<if test="state != null and state != ''">and state = #{state}</if>
<if test="startTime != null and endTime != null">
and create_time &gt;= #{startTime}
</if>
<if test="startTime != null and endTime != null">
and create_time &gt;= #{endTime}
</if>
</where>
</select>
<select id="selectByDictId" resultMap="DictTypeResult">
<include refid="selectDict"/>
where dict_id = #{dictId}
</select>
<select id="selectByDictType" resultMap="DictTypeResult">
<include refid="selectDict"/>
where dict_type = #{dictType}
</select>
<insert id="insert">
insert into sys_dict_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dictName != null and dictName != ''"> dict_name, </if>
<if test="dictType != null and dictType != ''"> dict_type, </if>
<if test="state != null and state != ''"> state, </if>
<if test="remark != null and remark != ''"> remark, </if>
<if test="createBy != null and createBy != ''"> create_by, </if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="dictName != null and dictName != ''"> #{dictName}, </if>
<if test="dictType != null and dictType != ''"> #{dictType}, </if>
<if test="state != null and state != ''"> #{state}, </if>
<if test="remark != null and remark != ''"> #{remark}, </if>
<if test="createBy != null and createBy != ''"> #{createBy}, </if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_dict_type
<set>
<if test="dictName != null and dictName != ''"> dict_name = #{dictName}, </if>
<if test="dictType != null and dictType != ''"> dict_type = #{dictType}, </if>
<if test="state != null and state != ''"> state = #{state}, </if>
<if test="remark != null and remark != ''"> remark = #{remark}, </if>
<if test="updateBy != null and updateBy != ''"> update_by = #{updateBy}, </if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where dict_id = #{dictId}
</update>
<delete id="deleteById">
delete from sys_dict_type where dict_id = #{dictId}
</delete>
</mapper>

View File

@@ -0,0 +1,89 @@
<?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="cn.fateverse.admin.mapper.IpBackMapper">
<sql id="selectIPBack">
select id,
ip_addr,
type,
mark,
create_by,
create_time,
update_by,
update_time
from sys_ip_back
</sql>
<select id="selectList" resultType="cn.fateverse.admin.entity.IpBack">
<include refid="selectIPBack"/>
<where>
<if test="ipAddr != null and ipAddr != ''">ip_addr like concat('%', #{ipAddr}, '%')</if>
<if test="type != null and type != ''">type = type</if>
<if test="startTime != null and endTime != null">
and create_time between #{startTime} and #{endTime}
</if>
</where>
</select>
<select id="selectById" resultType="cn.fateverse.admin.entity.IpBack">
<include refid="selectIPBack"/>
where id = #{id}
</select>
<select id="selectByIds" resultType="cn.fateverse.admin.entity.IpBack">
<include refid="selectIPBack"/>
where id in
<foreach collection="list" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</select>
<select id="selectListStartEnd" resultType="cn.fateverse.admin.entity.IpBack">
<include refid="selectIPBack"/>
limit #{start} , #{end}
</select>
<select id="selectByIdaddr" resultType="cn.fateverse.admin.entity.IpBack">
<include refid="selectIPBack"/>
where ip_addr = #{ipAddr}
</select>
<select id="selectIpv4Count" resultType="cn.fateverse.admin.entity.IpBack">
select count(*) from sys_ip_back where type = 'ipv4'
</select>
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
insert into sys_ip_back
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ipAddr != null and ipAddr != ''">ip_addr ,</if>
<if test="type != null and type != ''">type ,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ipAddr != null and ipAddr != ''">#{ipAddr},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_ip_back
<set>
<if test="ipAddr != null and ipAddr != ''">ip_addr = #{ipAddr},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete
from sys_ip_back
where id in
<foreach collection="list" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,268 @@
<?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="cn.fateverse.admin.mapper.MenuMapper">
<resultMap type="cn.fateverse.admin.entity.Menu" id="MenuResult">
<id property="menuId" column="menu_id"/>
<result property="menuName" column="menu_name"/>
<result property="parentId" column="parent_id"/>
<result property="orderNum" column="order_num"/>
<result property="path" column="path"/>
<result property="component" column="component"/>
<result property="isFrame" column="is_frame"/>
<result property="isCache" column="is_cache"/>
<result property="menuType" column="menu_type"/>
<result property="visible" column="visible"/>
<result property="state" column="state"/>
<result property="perms" column="perms"/>
<result property="icon" column="icon"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="updateBy" column="update_by"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectMenuVo">
select menu_id,
menu_name,
parent_id,
menu_type,
order_num,
`path`,
path_params,
is_frame,
component,
is_cache,
no_redirect,
breadcrumb,
`visible`,
state,
ifnull(perms, '') as perms,
icon,
create_by,
create_time,
update_by,
update_time,
remark
from sys_menu
</sql>
<select id="selectList" resultMap="MenuResult">
<include refid="selectMenuVo"/>
<where>
<if test="menuName != null and menuName != ''">and menu_name like concat('%',#{menuName},'%')</if>
<if test="state != null and state != ''">and state = #{state}</if>
<if test="excludeId != null ">and menu_id != #{excludeId} and parent_id != #{excludeId}</if>
<if test="button">and menu_type in ('D', 'M')</if>
</where>
</select>
<select id="selectListByUserId" resultType="cn.fateverse.admin.entity.Menu">
<include refid="selectMenuVo"/>
<where>
<if test="userId != null">and user_id = #{userId}</if>
<if test="menuName != null and menuName != ''">and menu_name like concat('%',#{menuName},'%')</if>
<if test="state != null and state != ''">and state = #{state}</if>
<if test="excludeId != null ">and menu_id != #{excludeId} and parent_id != #{excludeId}</if>
<if test="button">and menu_type in ('D', 'M')</if>
</where>
</select>
<select id="selectMenuPermsByUserId" parameterType="Long" resultType="java.lang.String">
select distinct m.perms
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
left join sys_role r on r.role_id = ur.role_id
where m.state = '1'
and r.state = '1'
and ur.user_id = #{userId}
</select>
<select id="selectById" resultMap="MenuResult">
<include refid="selectMenuVo"/>
where menu_id = #{menuId}
</select>
<!--第一个select则是通过sys_role_menu,映射表获取到角色对应的菜单列表,第二个select则是去除掉里面的parentId,去除原因为前端组件联动效果影响-->
<select id="selectCheckedMenuIdByRoleId" resultType="java.lang.Long">
select distinct m.menu_id
from sys_menu m
left join sys_role_menu rm on rm.menu_id = m.menu_id
where rm.role_id = #{roleId}
and m.menu_id not in
(select distinct m.parent_id
from sys_menu m
left join sys_role_menu rm on rm.menu_id = m.menu_id
where rm.role_id = #{roleId})
</select>
<select id="selectRouterMenuList" resultType="cn.fateverse.admin.entity.Menu">
select menu_id, menu_name, parent_id, menu_type, order_num, `path`, path_params, component,is_frame, is_cache, no_redirect,
breadcrumb, `visible`, state, perms ,order_num, icon, create_by, create_time, update_by, update_time, remark
from sys_menu
where menu_type in ('D', 'M')
and state = '1'
</select>
<select id="selectRouterMenuListByUserId" resultType="cn.fateverse.admin.entity.Menu">
select distinct m.menu_id,
m.menu_name,
m.parent_id,
m.order_num,
m.path,
m.path_params,
m.component,
m.no_redirect,
m.breadcrumb,
m.is_frame,
m.is_cache,
m.menu_type,
m.visible,
m.state,
m.order_num,
ifnull(m.perms, '') as perms,
m.icon,
m.create_by,
m.create_time,
m.update_by,
m.update_time,
m.remark
from sys_menu m
left join sys_role_menu rm on rm.menu_id = m.menu_id
left join sys_role r on r.role_id = rm.role_id
left join sys_user_role ur on ur.role_id = r.role_id
where
ur.user_id = #{userId}
and m.menu_type in ('D', 'M')
and m.state = '1'
and r.state = '1'
order by m.parent_id, m.order_num
</select>
<select id="selectByUserId" resultType="cn.fateverse.admin.entity.Menu">
select distinct m.menu_id,
m.menu_name,
m.parent_id,
m.order_num,
m.path,
m.path_params,
m.component,
m.is_frame,
m.is_cache,
m.no_redirect,
m.breadcrumb,
m.menu_type,
m.visible,
m.state,
ifnull(m.perms, '') as perms,
m.icon,
m.create_by,
m.create_time,
m.update_by,
m.update_time,
m.remark
from sys_menu m
left join sys_role_menu rm on rm.menu_id = m.menu_id
left join sys_role r on r.role_id = rm.role_id
left join sys_user_role ur on ur.role_id = rm.role_id
where ur.user_id = #{userId}
and r.state = '1'
order by m.parent_id, m.order_num
</select>
<select id="selectCheckedMenuIdByUserId" resultType="java.lang.Long">
select distinct rm.menu_id
from sys_role_menu rm
left join sys_role r on r.role_id = rm.role_id
left join sys_user_role ur on ur.role_id = rm.role_id
where ur.user_id = #{userId}
and r.state = '1'
</select>
<select id="selectAllMenuId" resultType="java.lang.Long">
select menu_id
from sys_menu
</select>
<select id="selectCountByParentId" resultType="java.lang.Integer">
select count(*) from sys_menu where parent_id = #{menuId}
</select>
<select id="selectByPerms" resultType="cn.fateverse.admin.entity.Menu">
<include refid="selectMenuVo"/>
where perms = #{perms}
</select>
<insert id="insert" useGeneratedKeys="true" keyColumn="menu_id" keyProperty="menuId">
insert into sys_menu
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menuName != null and menuName != ''">menu_name,</if>
<if test="parentId != null">parent_id,</if>
<if test="orderNum != null">order_num,</if>
<if test="path != null and path != ''">`path`,</if>
<if test="pathParams != null and pathParams != ''">path_params,</if>
<if test="component != null and component != ''">component,</if>
<if test="isFrame != null and isFrame != ''">is_frame,</if>
<if test="isCache != null and isCache != ''">is_cache,</if>
<if test="menuType != null and menuType != ''">menu_type,</if>
<if test="state != null and state != ''">state,</if>
<if test="visible != null and visible != ''">`visible`,</if>
<if test="perms != null and perms != ''">perms,</if>
<if test="icon != null and icon != ''">icon,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menuName != null and menuName != ''">#{menuName},</if>
<if test="parentId != null">#{parentId},</if>
<if test="orderNum != null">#{orderNum},</if>
<if test="path != null and path != ''">#{path},</if>
<if test="pathParams != null and pathParams != ''">#{pathParams},</if>
<if test="component != null and component != ''">#{component},</if>
<if test="isFrame != null and isFrame != ''">#{isFrame},</if>
<if test="isCache != null and isCache != ''">#{isCache},</if>
<if test="menuType != null and menuType != ''">#{menuType},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="visible != null and visible != ''">#{visible},</if>
<if test="perms != null and perms != ''">#{perms},</if>
<if test="icon != null and icon != ''">#{icon},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_menu
<set>
<if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="orderNum != null">order_num = #{orderNum},</if>
<if test="path != null and path != ''">`path` = #{path},</if>
<if test="pathParams != null and pathParams != ''">path_params = #{pathParams},</if>
<if test="component != null and component != ''">component = #{component},</if>
<if test="isFrame != null and isFrame != ''">is_frame = #{isFrame},</if>
<if test="isCache != null and isCache != ''">is_cache = #{isCache},</if>
<if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
<if test="state != null and state != ''">state = #{state},</if>
<if test="visible != null and visible != ''">`visible` = #{visible},</if>
<if test="perms != null and perms != ''">perms = #{perms},</if>
<if test="icon != null and icon != ''">icon = #{icon},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where menu_id = #{menuId}
</update>
<delete id="deleteById">
delete
from sys_menu
where menu_id = #{menuId}
</delete>
</mapper>

View File

@@ -0,0 +1,86 @@
<?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="cn.fateverse.admin.mapper.PostMapper">
<sql id="PostList">
select post_id,
post_code,
post_name,
post_sort,
state,
create_by,
create_time,
update_by,
update_time,
remark
from sys_post
</sql>
<select id="selectList" resultType="cn.fateverse.admin.entity.Post">
<include refid="PostList"/>
<where>
<if test="postCode != null and postCode != ''">and post_code like concat('%',#{postCode},'%')</if>
<if test="postName != null and postName != ''">and post_name like concat('%',#{postName},'%')</if>
<if test="state != null and state != ''">and state = #{state}</if>
</where>
order by post_sort
</select>
<select id="selectById" resultType="cn.fateverse.admin.entity.Post">
<include refid="PostList"/>
where post_id = #{id}
</select>
<select id="selectByPostCode" resultType="cn.fateverse.admin.entity.Post">
<include refid="PostList"/>
where post_code = #{postCode} limit 1
</select>
<select id="selectByPostName" resultType="cn.fateverse.admin.entity.Post">
<include refid="PostList"/>
where post_name = #{postName} limit 1
</select>
<select id="hasUserByPostId" resultType="java.lang.Integer">
select count(*) from sys_user_post where post_id = #{postId}
</select>
<insert id="insert">
insert into sys_post
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="postCode != null and postCode != ''">post_code,</if>
<if test="postName != null and postName != ''">post_name,</if>
<if test="postSort != null and postSort != ''">post_sort,</if>
<if test="state != null and state != ''">state,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="postCode != null and postCode != ''">#{postCode},</if>
<if test="postName != null and postName != ''">#{postName},</if>
<if test="postSort != null and postSort != ''">#{postSort},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_post
<set>
<if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
<if test="postName != null and postName != ''">post_name = #{postName},</if>
<if test="postSort != null and postSort != ''">post_sort = #{postSort},</if>
<if test="state != null and state != ''">state = #{state},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where post_id = #{postId}
</update>
<delete id="deleteById">
delete from sys_post where post_id = #{postId}
</delete>
</mapper>

View File

@@ -0,0 +1,133 @@
<?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="cn.fateverse.admin.mapper.RoleMapper">
<sql id="selectSql">
select role_id,
role_name,
role_key,
role_sort,
data_scope,
`state`,
del_flag,
create_by,
create_time,
update_by,
update_time,
remark,
role_type
from sys_role
</sql>
<select id="selectList" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
<where>
<if test="roleName != null and roleName != ''"> and role_name like concat('%',#{roleName} ,'%')</if>
<if test="roleKey != null and roleKey != ''"> and role_key like concat('%',#{roleKey} ,'%')</if>
<if test="state != null and state != ''"> and state = #{state}</if>
<if test="startTime != null and endTime != null">
and create_time &gt;= #{startTime}
</if>
<if test="startTime != null and endTime != null">
and create_time &lt;= #{endTime}
</if>
</where>
</select>
<select id="selectById" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
where role_id = #{roleId}
</select>
<select id="hasUserByRoleId" resultType="java.lang.Integer">
select count(1)
from sys_role r
inner join sys_user_role ur on ur.role_id = r.role_id
where r.role_id = #{roleId}
limit 1
</select>
<select id="selectByRoleName" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
where role_name = #{roleName} limit 0,1
</select>
<select id="selectByRoleKey" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
where role_key = #{roleKey} limit 0,1
</select>
<select id="selectByIds" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
where role_id in
<foreach collection="list" open="(" separator="," close=")" item="roleId">
#{roleId}
</foreach>
</select>
<select id="selectListByMenuId" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
<where>
<if test="roleName != null and roleName != ''">and role_name like concat('%',#{roleName} ,'%')</if>
<if test="roleKey != null and roleKey != ''">and role_key like concat('%',#{roleKey} ,'%')</if>
<if test="menuId != null"> and role_id in (select role_id from sys_role_menu where menu_id = #{menuId})</if>
</where>
</select>
<select id="searchListExcludeMenuId" resultType="cn.fateverse.admin.entity.Role">
<include refid="selectSql"/>
<where>
<if test="roleName != null and roleName != ''">and role_name like concat('%',#{roleName} ,'%')</if>
<if test="roleKey != null and roleKey != ''">and role_key like concat('%',#{roleKey} ,'%')</if>
<if test="menuId != null"> and role_id not in (select role_id from sys_role_menu where menu_id = #{menuId})</if>
</where>
</select>
<insert id="insert" useGeneratedKeys="true" keyColumn="role_id" keyProperty="roleId">
insert into sys_role
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="roleName != null and roleName != ''">role_name,</if>
<if test="roleKey != null and roleKey != ''">role_key,</if>
<if test="roleSort != null">role_sort,</if>
<if test="state != null and state != ''">state,</if>
<if test="dataScope != null and dataScope != ''">data_scope,</if>
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="roleName != null and roleName != ''">#{roleName},</if>
<if test="roleKey != null and roleKey != ''">#{roleKey},</if>
<if test="roleSort != null">#{roleSort},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="dataScope != null and dataScope != ''">#{dataScope},</if>
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_role
<set>
<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
<if test="roleSort != null">role_sort = #{roleSort},</if>
<if test="state != null and state != ''">state=#{state},</if>
<if test="dataScope != null and dataScope != ''">data_scope=#{dataScope},</if>
<if test="delFlag != null and delFlag != ''">del_flag=#{delFlag},</if>
<if test="remark != null and remark != ''">remark=#{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="createTime != null">#{createTime},</if>
</set>
where role_id = #{roleId}
</update>
<delete id="delete">
delete from sys_role where role_id = #{roleId}
</delete>
</mapper>

View File

@@ -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="cn.fateverse.admin.mapper.RoleMenuMapper">
<select id="selectMenuIdsByRoleId" resultType="java.lang.Long">
select menu_id from sys_role_menu where role_id = #{roleId}
</select>
<insert id="batch">
insert into sys_role_menu (role_id, menu_id)
values
<foreach collection="list" item="roleMenu" separator=",">
(#{roleMenu.roleId},#{roleMenu.menuId})
</foreach>
</insert>
<delete id="deleteByRoleId">
delete from sys_role_menu where role_id = #{roleId}
</delete>
<delete id="deleteByMenuId">
delete from sys_role_menu where menu_id = #{menuId}
</delete>
<delete id="unBindMenu">
delete from sys_role_menu
where menu_id = #{menuId}
and role_id in
<foreach collection="roleIds" item="roleId" separator="," open="(" close=")">
#{roleId}
</foreach>
</delete>
<delete id="unBindAllMenu">
delete from sys_role_menu where menu_id = #{menuId}
</delete>
</mapper>

View File

@@ -0,0 +1,327 @@
<?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="cn.fateverse.admin.mapper.UserMapper">
<resultMap type="cn.fateverse.admin.entity.User" id="UserResult">
<id property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/>
<result property="userName" column="user_name"/>
<result property="nickName" column="nick_name"/>
<result property="email" column="email"/>
<result property="phoneNumber" column="phone_number"/>
<result property="sex" column="sex"/>
<result property="avatar" column="avatar"/>
<result property="password" column="password"/>
<result property="state" column="state"/>
<result property="delFlag" column="del_flag"/>
<result property="loginIp" column="login_ip"/>
<result property="loginDate" column="login_date"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="userType" column="user_type"/>
<result property="openId" column="open_id"/>
<result property="unionId" column="union_id"/>
<association property="dept" column="dept_id" javaType="cn.fateverse.admin.entity.Dept" resultMap="deptResult"/>
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
</resultMap>
<resultMap id="deptResult" type="cn.fateverse.admin.entity.Dept">
<id property="deptId" column="dept_id"/>
<result property="parentId" column="parent_id"/>
<result property="deptName" column="dept_name"/>
<result property="ancestors" column="ancestors"/>
<result property="orderNum" column="order_num"/>
<result property="leader" column="leader"/>
<result property="leaderId" column="leader_id"/>
<result property="state" column="dept_state"/>
</resultMap>
<resultMap id="RoleResult" type="cn.fateverse.admin.entity.Role">
<id property="roleId" column="role_id"/>
<result property="roleName" column="role_name"/>
<result property="roleKey" column="role_key"/>
<result property="roleSort" column="role_sort"/>
<result property="dataScope" column="data_scope"/>
<result property="state" column="role_state"/>
</resultMap>
<sql id="selectUserDetail">
select u.user_id,
u.dept_id,
u.user_name,
u.nick_name,
u.email,
u.avatar,
u.phone_number,
u.password,
u.sex,
u.state,
u.del_flag,
u.login_ip,
u.login_date,
u.create_by,
u.create_time,
u.remark,
u.union_id,
u.open_id,
u.user_type,
d.dept_id,
d.parent_id,
d.dept_name,
d.order_num,
d.ancestors,
d.leader,
d.leader_id,
d.state as dept_state,
r.role_id,
r.role_name,
r.role_key,
r.role_sort,
r.data_scope,
r.state as role_state
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
</sql>
<sql id="selectUserVo">
select u.user_id,
u.user_name,
u.nick_name,
u.phone_number,
u.state,
u.create_time,
u.email,
d.dept_name,
u.user_type,
u.sex,
u.avatar
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
</sql>
<sql id="selectUser">
select user_id,
dept_id,
user_name,
nick_name,
user_type,
email,
phone_number,
sex,
avatar,
state,
del_flag,
login_ip,
login_date,
open_id,
union_id,
create_by,
create_time,
update_by,
update_time,
remark
from sys_user
</sql>
<select id="selectByUserName" parameterType="String" resultMap="UserResult">
<include refid="selectUserDetail"/>
where u.user_name = #{userName} limit 0,1
</select>
<select id="selectList" resultType="cn.fateverse.admin.vo.UserVo">
<include refid="selectUserVo"/>
<where>
u.del_flag = '0'
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
concat('%',#{phoneNumber},'%')
</if>
<if test="state != null and state != ''">and u.state = #{state}</if>
<if test="startTime != null and endTime != null">
and u.create_time between #{startTime} and #{endTime}
</if>
<if test="deptId != null">
and (u.dept_id = #{deptId} or u.dept_id in ( select t.dept_id from sys_dept t where
find_in_set(#{deptId}, ancestors) ))
</if>
</where>
</select>
<select id="selectUserByUserId" resultMap="UserResult">
<include refid="selectUserDetail"/>
where u.user_id = #{userId}
</select>
<select id="selectUserListByExcludeRoleId" resultType="cn.fateverse.admin.vo.UserVo">
<include refid="selectUserVo"/>
<where>
and u.user_id not in (select user_id from sys_user_role where role_id = #{roleId})
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
concat('%',#{phoneNumber},'%')
</if>
</where>
</select>
<select id="selectUserListByExcludePostId" resultType="cn.fateverse.admin.vo.UserVo">
<include refid="selectUserVo"/>
<where>
and u.user_id not in (select user_id from sys_user_post where post_id = #{postId})
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
concat('%',#{phoneNumber},'%')
</if>
</where>
</select>
<select id="selectUserListByRoleId" resultType="cn.fateverse.admin.vo.UserVo">
<include refid="selectUserVo"/>
left join sys_user_role ur on ur.user_id = u.user_id
<where>
and ur.role_id = #{roleId}
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
concat('%',#{phoneNumber},'%')
</if>
</where>
</select>
<select id="selectUserListByRoleIds" resultType="cn.fateverse.admin.vo.UserVo">
select distinct u.user_id,u.user_name,u.nick_name,u.phone_number,u.state,u.create_time,u.email,
d.dept_name,u.user_type,u.sex,u.avatar,ur.role_id
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on ur.user_id = u.user_id
where ur.role_id in
<foreach collection="list" item="roleId" index="index" open="(" separator="," close=")">
#{roleId}
</foreach>
</select>
<select id="selectUserListByPostId" resultType="cn.fateverse.admin.vo.UserVo">
<include refid="selectUserVo"/>
left join sys_user_post up on up.user_id = u.user_id
<where>
<if test="postId != null">and up.post_id = #{postId}</if>
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
concat('%',#{phoneNumber},'%')
</if>
</where>
</select>
<select id="selectUserInfoByUserName" resultType="cn.fateverse.admin.entity.User">
<include refid="selectUser"/>
where user_name = #{userName}
</select>
<select id="selectByPhoneNum" resultType="cn.fateverse.admin.entity.User">
<include refid="selectUser"/>
where phone_number = #{phoneNumber}
</select>
<select id="selectByEmail" resultType="cn.fateverse.admin.entity.User">
<include refid="selectUser"/>
where email = #{email} limit 0,1
</select>
<select id="selectUserByUserIds" resultType="cn.fateverse.admin.vo.UserVo">
select distinct u.user_id,u.user_name,u.nick_name,u.phone_number,u.state,u.create_time,u.email,
d.dept_name,u.user_type,u.sex,u.avatar
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.user_id in
<foreach collection="list" item="userId" index="index" open="(" separator="," close=")">
#{userId}
</foreach>
</select>
<select id="selectUserByDeptIds" resultType="cn.fateverse.admin.vo.UserVo">
select distinct u.user_id,u.user_name,u.nick_name,u.phone_number,u.state,u.create_time,
d.dept_name,u.user_type,u.sex,u.avatar,d.dept_id as leaderDeptId
from sys_user u
left join sys_dept d on u.user_id = d.leader_id
where d.dept_id in
<foreach collection="list" item="deptId" index="index" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<select id="selectAllUserIds" resultType="java.lang.Long">
select user_id
from sys_user
</select>
<insert id="insert" parameterType="cn.fateverse.admin.entity.UserBase" useGeneratedKeys="true" keyProperty="userId"
keyColumn="user_id">
insert into sys_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptId != null">dept_id ,</if>
<if test="userName != null and userName != ''">user_name,</if>
<if test="nickName != null and nickName != ''">nick_name,</if>
<if test="email != null and email != ''">email,</if>
<if test="phoneNumber != null and phoneNumber != ''">phone_number,</if>
<if test="sex != null and sex != ''">sex,</if>
<if test="avatar != null and avatar != ''">avatar,</if>
<if test="password != null and password != ''">`password`,</if>
<if test="state != null and state != ''">state,</if>
<if test="unionId != null and unionId != ''">union_id,</if>
<if test="openId != null and openId != ''">open_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptId != null">#{deptId},</if>
<if test="userName != null and userName != ''">#{userName},</if>
<if test="nickName != null and nickName != ''">#{nickName},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="phoneNumber != null and phoneNumber != ''">#{phoneNumber},</if>
<if test="sex != null and sex != ''">#{sex},</if>
<if test="avatar != null and avatar != ''">#{avatar},</if>
<if test="password != null and password != ''">#{password},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="unionId != null and unionId != ''">#{unionId},</if>
<if test="openId != null and openId != ''">#{openId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="update">
update sys_user
<set>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if>
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
<if test="email != null and email != ''">email = #{email},</if>
<if test="phoneNumber != null and phoneNumber != ''">phone_number = #{phoneNumber},</if>
<if test="sex != null and sex != ''">sex = #{sex},</if>
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
<if test="password != null and password != ''">`password` = #{password},</if>
<if test="state != null and state != ''">state = #{state},</if>
<if test="unionId != null and unionId != ''">union_id = #{unionId},</if>
<if test="openId != null and openId != ''">open_id = #{openId},</if>
<if test="city != null and city != ''">city = #{city},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where user_id = #{userId}
</update>
<!-- update sys_user set state = '2', del_flag = '1' where user_id = #{userId} -->
<update id="deleteByUserId">
delete
from sys_user
where user_id = #{userId}
</update>
</mapper>

View File

@@ -0,0 +1,34 @@
<?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="cn.fateverse.admin.mapper.UserPostMapper">
<insert id="batchInsert">
insert into sys_user_post (user_id, post_id) VALUES
<foreach collection="list" separator="," item="userPost">
(#{userPost.userId},#{userPost.postId})
</foreach>
</insert>
<delete id="deleteByUserId">
delete from sys_user_post where user_id = #{userId}
</delete>
<delete id="removeBind">
delete from sys_user_post where post_id = #{postId}
and user_id in
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
<delete id="removeBindByPostId">
delete from sys_user_post where post_id = #{postId}
</delete>
<select id="selectPostIdListByUserId" resultType="java.lang.Long">
select post_id from sys_user_post where user_id = #{userId}
</select>
</mapper>

View File

@@ -0,0 +1,35 @@
<?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="cn.fateverse.admin.mapper.UserRoleMapper">
<insert id="batchInsert">
insert into sys_user_role (user_id, role_id) values
<foreach collection="list" separator="," item="userRole">
(#{userRole.userId},#{userRole.roleId})
</foreach>
</insert>
<insert id="bind">
insert into sys_user_role (user_id, role_id) values
(#{userId},#{roleId})
</insert>
<delete id="deleteByUserId">
delete from sys_user_role where user_id = #{userId}
</delete>
<delete id="deleteByRoleId">
delete from sys_user_role where role_id = #{roleId}
</delete>
<delete id="unBind">
delete from sys_user_role where role_id = #{roleId}
and user_id in
<foreach collection="userIds" item="userId" separator="," open="(" close=")">
#{userId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,90 @@
package cn.fateverse.admin;
import cn.fateverse.admin.entity.Menu;
import cn.fateverse.admin.mapper.BackMenuMapper;
import cn.fateverse.common.core.utils.convert.TreeUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Clay
* @date 2024/2/19 14:10
*/
@SpringBootTest(classes = AdminApplication.class)
public class ApplicationTest {
@Resource
private BackMenuMapper backMenuMapper;
private Long d = 1L;
private Long m = 100L;
private Long b = 1000L;
private List<Menu> backList = new ArrayList<>();
@Test
public void test() {
List<Menu> menuList = backMenuMapper.selectAll();
System.out.println(menuList.size());
// List<MenuBack> menuBackList = TreeUtil.build(menuList, MenuBack.class, (config) -> {
// config.setIdField("menuId");
// });
Map<Long, List<Menu>> listMap = menuList.stream().collect(Collectors.groupingBy(Menu::getParentId));
getChildren(listMap, 0L, 0L);
System.out.println(backList.size());
for (Menu menu : backList) {
backMenuMapper.insert(menu);
}
}
private void getChildren(Map<Long, List<Menu>> listMap, Long parentId, Long newParentId) {
if (!listMap.containsKey(parentId)) {
return;
}
List<Menu> collect = listMap.get(parentId).stream()
.filter(Objects::nonNull)
.sorted(Comparator.comparing(menu -> {
if (null == menu.getOrderNum()) {
return 0;
} else {
return Convert.toInt(menu.getOrderNum());
}
})).collect(Collectors.toList());
collect
.forEach(menu -> {
Menu newMenu = new Menu();
BeanUtils.copyProperties(menu, newMenu);
switch (newMenu.getMenuType()) {
case "D":
newMenu.setMenuId(d++);
break;
case "M":
newMenu.setMenuId(m++);
break;
case "B":
newMenu.setPath(null);
newMenu.setMenuId(b++);
break;
}
newMenu.setParentId(newParentId);
backList.add(newMenu);
getChildren(listMap, menu.getMenuId(), newMenu.getMenuId());
});
}
}

View File

@@ -0,0 +1,19 @@
package cn.fateverse.admin.mapper;
import cn.fateverse.admin.entity.Menu;
import java.util.List;
/**
* @author Clay
* @date 2024/2/19 14:07
*/
public interface BackMenuMapper {
List<Menu> selectAll();
int insert(Menu menu);
}

View File

@@ -0,0 +1,51 @@
<?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="cn.fateverse.admin.mapper.BackMenuMapper">
<select id="selectAll" resultType="cn.fateverse.admin.entity.Menu">
select * from sys_menu
</select>
<insert id="insert" useGeneratedKeys="true" keyColumn="menu_id" keyProperty="menuId">
insert into sys_menu_back1
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menuId != null">menu_id,</if>
<if test="menuName != null and menuName != ''">menu_name,</if>
<if test="parentId != null">parent_id,</if>
<if test="orderNum != null">order_num,</if>
<if test="path != null">`path`,</if>
<if test="pathParams != null and pathParams != ''">path_params,</if>
<if test="component != null and component != ''">component,</if>
<if test="isFrame != null and isFrame != ''">is_frame,</if>
<if test="isCache != null and isCache != ''">is_cache,</if>
<if test="menuType != null and menuType != ''">menu_type,</if>
<if test="state != null and state != ''">state,</if>
<if test="visible != null and visible != ''">`visible`,</if>
<if test="perms != null and perms != ''">perms,</if>
<if test="icon != null and icon != ''">icon,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menuId != null">#{menuId},</if>
<if test="menuName != null and menuName != ''">#{menuName},</if>
<if test="parentId != null">#{parentId},</if>
<if test="orderNum != null">#{orderNum},</if>
<if test="path != null">#{path},</if>
<if test="pathParams != null and pathParams != ''">#{pathParams},</if>
<if test="component != null and component != ''">#{component},</if>
<if test="isFrame != null and isFrame != ''">#{isFrame},</if>
<if test="isCache != null and isCache != ''">#{isCache},</if>
<if test="menuType != null and menuType != ''">#{menuType},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="visible != null and visible != ''">#{visible},</if>
<if test="perms != null and perms != ''">#{perms},</if>
<if test="icon != null and icon != ''">#{icon},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
</mapper>