refactor: 项目重构之参数校验

This commit is contained in:
郝先瑞 2022-06-12 23:33:29 +08:00
parent 5ea04eae71
commit bc15ee053d
87 changed files with 658 additions and 422 deletions

View File

@ -2,7 +2,7 @@ package com.youlai.mall.oms.controller.app;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.youlai.common.result.Result;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.oms.pojo.dto.CartItemDTO;
import com.youlai.mall.oms.service.ICartService;
import io.swagger.annotations.Api;

View File

@ -7,7 +7,7 @@ import lombok.Data;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/1 19:14
*/
@Data

View File

@ -8,7 +8,7 @@ import java.util.List;
/**
* 订单分页视图对象
*
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/1 20:58
*/
@Data

View File

@ -4,8 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.youlai.common.result.ResultCode;
import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.JwtUtils;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.oms.pojo.dto.CartItemDTO;
import com.youlai.mall.oms.service.ICartService;
@ -13,8 +12,6 @@ import com.youlai.mall.pms.api.SkuFeignClient;
import com.youlai.mall.pms.pojo.dto.SkuInfoDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.oms.mapper.OrderLogMapper;
import com.youlai.mall.oms.pojo.entity.OmsOrderLog;
import com.youlai.mall.oms.service.IOrderLogService;

View File

@ -25,7 +25,7 @@ import com.youlai.common.enums.BusinessTypeEnum;
import com.youlai.common.redis.BusinessNoGenerator;
import com.youlai.common.result.Result;
import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.oms.config.WxPayProperties;
import com.youlai.mall.oms.dto.OrderInfoDTO;
import com.youlai.mall.oms.enums.OrderStatusEnum;

View File

@ -7,7 +7,7 @@ import java.util.List;
/**
* 商品验价传输层实体
*
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/7 22:52
*/
@Data

View File

@ -4,7 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/5 23:09
*/

View File

@ -5,7 +5,7 @@ import lombok.Data;
import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
*/
@Data
public class GoodsFormDTO {

View File

@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
*/
@Data
@Accessors(chain = true)

View File

@ -11,7 +11,7 @@ import java.util.List;
/**
* 商品详情视图对象
*
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/3/13
*/
@Data

View File

@ -1,7 +1,7 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.common.web.vo.OptionVO;
import com.youlai.common.web.domain.Option;
import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.pojo.vo.CategoryVO;
@ -28,7 +28,7 @@ public interface IPmsCategoryService extends IService<PmsCategory> {
* 分类列表级联
* @return
*/
List<OptionVO> listCascadeCategories();
List<Option> listCascadeCategories();
/**

View File

@ -14,7 +14,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
*/
@Service
public class PmsAttributeServiceImpl extends ServiceImpl<PmsAttributeMapper, PmsAttribute> implements IPmsAttributeService {

View File

@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.pms.common.constant.PmsConstants;
import com.youlai.mall.pms.common.enums.AttributeTypeEnum;
import com.youlai.mall.pms.mapper.PmsSpuMapper;

View File

@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2021/7/17
*/
@SpringBootTest

View File

@ -29,10 +29,9 @@ public class SmsCouponController {
@ApiOperation("新增优惠券")
@PostMapping
public Result saveCoupon(@RequestBody CouponForm couponForm){
boolean result = smsCouponService.saveCoupon(couponForm);
return Result.judge(result);
public Result saveCoupon(@RequestBody CouponForm couponForm) {
boolean result = smsCouponService.saveCoupon(couponForm);
return Result.judge(result);
}
}

View File

@ -5,7 +5,7 @@ import lombok.Data;
/**
* 会员地址传输层对象
*
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/12 15:57
*/
@Data

View File

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.dto.MemberAuthInfoDTO;
import com.youlai.mall.ums.dto.MemberDTO;

View File

@ -7,9 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Positive;
/**
* 地址表单对象

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import com.youlai.mall.ums.mapper.UmsAddressMapper;
import com.youlai.mall.ums.pojo.entity.UmsAddress;

View File

@ -8,10 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.result.ResultCode;
import com.youlai.common.web.exception.BizException;
import com.youlai.common.web.util.MemberUtils;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.constant.UmsConstants;
import com.youlai.mall.ums.dto.MemberAuthInfoDTO;

19
pom.xml
View File

@ -29,7 +29,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@ -44,7 +44,7 @@
<docker.image.prefix>youlai</docker.image.prefix>
<!-- spring boot -->
<spring-boot.version>2.6.7</spring-boot.version>
<spring-boot.version>2.7.0</spring-boot.version>
<!-- spring cloud -->
<spring-cloud.version>2021.0.2</spring-cloud.version>
@ -62,11 +62,11 @@
<!-- tools -->
<lombok.version>1.18.18</lombok.version>
<hutool.version>5.7.21</hutool.version>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<mapstruct.version>1.5.0.RC1</mapstruct.version>
<weixin-java.version>4.1.5.B</weixin-java.version>
<easyexcel.version>3.0.5</easyexcel.version>
<easy-captcha.version>1.6.2</easy-captcha.version>
<nimbus-jose-jwt.version>9.16.1</nimbus-jose-jwt.version>
<!-- elastic stack -->
<elasticsearch.version>7.10.1</elasticsearch.version>
@ -156,12 +156,6 @@
<version>${weixin-java.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
@ -338,6 +332,13 @@
<version>${mapstruct.version}</version>
</dependency>
<!-- JWT工具 -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>${nimbus-jose-jwt.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -72,13 +72,6 @@
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- JWT库 -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.16.1</version>
</dependency>
<!-- 分布式对象存储 -->
<dependency>
<groupId>io.minio</groupId>

View File

@ -1,4 +1,4 @@
package com.youlai.admin.component.cache;
package com.youlai.admin.cache;
import com.youlai.admin.service.SysPermissionService;
import lombok.AllArgsConstructor;

View File

@ -1,6 +1,7 @@
package com.youlai.admin.controller;
import com.youlai.admin.pojo.entity.SysDept;
import com.youlai.admin.pojo.query.DeptQuery;
import com.youlai.admin.pojo.vo.dept.DeptVO;
import com.youlai.admin.service.SysDeptService;
import com.youlai.common.result.Result;
@ -25,32 +26,23 @@ public class SysDeptController {
private final SysDeptService deptService;
@ApiOperation(value = "部门表格(Table)列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "部门名称", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "status", value = "部门状态", paramType = "query", dataType = "Long"),
})
@GetMapping("/table")
public Result listTableDepartments(
Integer status,
String name
) {
List<DeptVO> list = deptService.listTableDepartments(status, name);
@ApiOperation(value = "部门列表")
@GetMapping
public Result<List<DeptVO>> listDepartments(DeptQuery queryParams) {
List<DeptVO> list = deptService.listDepartments(queryParams);
return Result.success(list);
}
@ApiOperation(value = "部门树形下拉(TreeSelect)列表")
@GetMapping("/select")
@ApiOperation(value = "部门下拉列表")
@GetMapping("/select_list")
public Result listTreeSelectDepartments() {
List<Option> list = deptService.listTreeSelectDepartments();
return Result.success(list);
}
@ApiOperation(value = "部门详情")
@GetMapping("/{deptId}")
public Result getDeptDetail(
@ApiParam("部门ID") @PathVariable Long deptId
) {
@ApiOperation(value = "部门表单数据")
@GetMapping("/{deptId}/form_data")
public Result getDeptDetail(@ApiParam("部门ID") @PathVariable Long deptId) {
SysDept sysDept = deptService.getById(deptId);
return Result.success(sysDept);
}
@ -64,19 +56,14 @@ public class SysDeptController {
@ApiOperation(value = "修改部门")
@PutMapping(value = "/{deptId}")
public Result updateDept(
@ApiParam("部门ID") @PathVariable Long deptId,
@RequestBody SysDept dept
) {
public Result updateDept(@ApiParam("部门ID") @PathVariable Long deptId, @RequestBody SysDept dept) {
deptId = deptService.saveDept(dept);
return Result.success(deptId);
}
@ApiOperation(value = "删除部门")
@DeleteMapping("/{ids}")
public Result deleteDepartments(
@ApiParam("部门ID多个以英文逗号(,)分割") @PathVariable("ids") String ids
) {
public Result deleteDepartments(@ApiParam("部门ID多个以英文逗号(,)分割") @PathVariable("ids") String ids) {
boolean result = deptService.deleteByIds(ids);
return Result.judge(result);
}

View File

@ -7,13 +7,16 @@ import com.youlai.admin.pojo.vo.dict.DictItemPageVO;
import com.youlai.admin.service.SysDictItemService;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.common.web.domain.Option;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@Api(tags = "字典数据项")
import java.util.List;
@Api(tags = "字典数据项接口")
@RestController
@RequestMapping("/api/v1/dict-items")
@RequiredArgsConstructor
@ -22,19 +25,17 @@ public class SysDictItemController {
private final SysDictItemService dictItemService;
@ApiOperation(value = "字典数据项分页列表")
@GetMapping("/page_list")
@GetMapping
public PageResult<DictItemPageVO> listPageDictItems(DictItemPageQuery queryParams) {
Page<DictItemPageVO> result = dictItemService.listPageDictItems(queryParams);
return PageResult.success(result);
}
@ApiOperation(value = "字典数据项表单详情")
@GetMapping("/{id}/form_detail")
public Result<DictItemForm> getDictItemFormDetail(
@ApiParam("字典ID") @PathVariable Long id
) {
DictItemForm DictItemForm = dictItemService.getDictItemFormDetail(id);
return Result.success(DictItemForm);
@ApiOperation(value = "字典数据项表单")
@GetMapping("/{id}/form_data")
public Result<DictItemForm> getDictItemFormData(@ApiParam("字典ID") @PathVariable Long id) {
DictItemForm formData = dictItemService.getDictItemFormData(id);
return Result.success(formData);
}
@ApiOperation(value = "新增字典数据项")
@ -46,18 +47,23 @@ public class SysDictItemController {
@ApiOperation(value = "修改字典数据项")
@PutMapping("/{id}")
public Result updateDict(@PathVariable Long id, @RequestBody DictItemForm DictItemForm) {
public Result updateDictItem(@PathVariable Long id, @RequestBody DictItemForm DictItemForm) {
boolean status = dictItemService.updateDictItem(id, DictItemForm);
return Result.judge(status);
}
@ApiOperation(value = "删除字典")
@DeleteMapping("/{ids}")
public Result deleteDict(
@ApiParam("字典ID多个以英文逗号(,)分割") @PathVariable String ids
) {
public Result deleteDictItems(@ApiParam("字典ID多个以英文逗号(,)分割") @PathVariable String ids) {
boolean result = dictItemService.deleteDictItems(ids);
return Result.judge(result);
}
@ApiOperation(value = "根据字典类型编码获取字典数据项")
@GetMapping("/select_list")
public Result<List<Option>> getDictItemsByTypeCode(@ApiParam("字典类型编码") @RequestParam String typeCode) {
List<Option> list = dictItemService.listDictItemsByTypeCode(typeCode);
return Result.success(list);
}
}

View File

@ -22,18 +22,18 @@ public class SysDictTypeController {
private final SysDictTypeService dictTypeService;
@ApiOperation(value = "字典类型分页列表")
@GetMapping("/page_list")
@GetMapping
public PageResult<DictTypePageVO> listPageDictTypes(DictTypePageQuery queryParams) {
Page<DictTypePageVO> result = dictTypeService.listPageDictTypes(queryParams);
return PageResult.success(result);
}
@ApiOperation(value = "字典类型表单详情")
@GetMapping("/{id}/form_detail")
public Result<DictTypeForm> getDictTypeFormDetail(
@GetMapping("/{id}/form_data")
public Result<DictTypeForm> getDictTypeFormData(
@ApiParam("字典ID") @PathVariable Long id
) {
DictTypeForm dictTypeForm = dictTypeService.getDictTypeFormDetail(id);
DictTypeForm dictTypeForm = dictTypeService.getDictTypeFormData(id);
return Result.success(dictTypeForm);
}

View File

@ -1,9 +1,8 @@
package com.youlai.admin.controller;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.youlai.admin.pojo.entity.SysMenu;
import com.youlai.admin.pojo.vo.menu.ResourceVO;
import com.youlai.admin.pojo.vo.menu.TableMenuVO;
import com.youlai.admin.pojo.vo.menu.MenuVO;
import com.youlai.admin.pojo.vo.menu.RouteVO;
import com.youlai.admin.service.SysMenuService;
import com.youlai.admin.service.SysPermissionService;
@ -35,31 +34,31 @@ public class SysMenuController {
private final SysPermissionService permissionService;
@ApiOperation(value = "资源树形列表")
@GetMapping("/resource")
public Result<ResourceVO> getResource( ) {
@GetMapping("/resources")
public Result<ResourceVO> getResource() {
ResourceVO resource = menuService.getResource();
return Result.success(resource);
}
@ApiOperation(value = "菜单表格树形列表")
@GetMapping("/table")
public Result listTableMenus(
@ApiOperation(value = "菜单列表")
@GetMapping
public Result listMenus(
@ApiParam(value = "菜单名称", type = "query") String name
) {
List<TableMenuVO> menuList = menuService.listTableMenus(name);
List<MenuVO> menuList = menuService.listMenus(name);
return Result.success(menuList);
}
@ApiOperation(value = "菜单下拉列表")
@GetMapping("/select")
@ApiOperation(value = "菜单下拉列表")
@GetMapping("/select_list")
public Result listSelectMenus() {
List<Option> menus = menuService.listMenus();
List<Option> menus = menuService.listSelectMenus();
return Result.success(menus);
}
@ApiOperation(value = "菜单路由列表")
@GetMapping("/route")
public Result getRouteList() {
@ApiOperation(value = "路由列表")
@GetMapping("/route_list")
public Result listRoutes() {
List<RouteVO> routeList = menuService.listRoutes();
return Result.success(routeList);
}
@ -94,8 +93,9 @@ public class SysMenuController {
@ApiOperation(value = "删除菜单")
@DeleteMapping("/{ids}")
@CacheEvict(cacheNames = "system", key = "'routes'")
public Result delete(
@ApiParam("菜单ID多个以英文(,)分割") @PathVariable("ids") String ids) {
public Result deleteMenus(
@ApiParam("菜单ID多个以英文(,)分割") @PathVariable("ids") String ids
) {
boolean result = menuService.removeByIds(Arrays.asList(ids.split(",")));
if (result) {
permissionService.refreshPermRolesRules();
@ -103,16 +103,17 @@ public class SysMenuController {
return Result.judge(result);
}
@ApiOperation(value = "选择性修改菜单")
@PatchMapping(value = "/{id}")
@CacheEvict(cacheNames = "system", key = "'routes'")
public Result patch(@PathVariable Integer id, @RequestBody SysMenu menu) {
LambdaUpdateWrapper<SysMenu> updateWrapper = new LambdaUpdateWrapper<SysMenu>().eq(SysMenu::getId, id);
updateWrapper.set(menu.getVisible() != null, SysMenu::getVisible, menu.getVisible());
boolean result = menuService.update(updateWrapper);
if (result) {
permissionService.refreshPermRolesRules();
}
@ApiOperation(value = "修改菜单显示状态")
@PatchMapping("/{menuId}")
public Result updateMenuVisible(
@ApiParam(value = "菜单ID") @PathVariable Long menuId,
@ApiParam(value = "是否显示(1->显示2->隐藏)") Integer visible
) {
boolean result =menuService.updateMenuVisible(menuId, visible);
return Result.judge(result);
}
}

View File

@ -2,21 +2,16 @@ package com.youlai.admin.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.admin.dto.ClientAuthDTO;
import com.youlai.admin.pojo.entity.SysOauthClient;
import com.youlai.admin.pojo.query.ClientPageQuery;
import com.youlai.admin.pojo.vo.client.ClientPageVO;
import com.youlai.admin.service.SysOauthClientService;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@ -24,69 +19,58 @@ import java.util.Arrays;
@Api(tags = "客户端接口")
@RestController
@RequestMapping("/api/v1/oauth-clients")
@Slf4j
@AllArgsConstructor
@RequiredArgsConstructor
public class SysOauthClientController {
private SysOauthClientService sysOauthClientService;
private final SysOauthClientService clientService;
@ApiOperation(value = "列表分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageSize", value = "页码", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "pageNum", value = "每页数量", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "clientId", value = "客户端ID", paramType = "query", dataType = "String")
})
@ApiOperation(value = "客户端分页列表")
@GetMapping
public PageResult<SysOauthClient> list(long pageNum, long pageSize, String clientId) {
IPage<SysOauthClient> result = sysOauthClientService.page(
new Page<>(pageNum, pageSize),
new LambdaQueryWrapper<SysOauthClient>()
.like(StrUtil.isNotBlank(clientId), SysOauthClient::getClientId, clientId));
public PageResult<ClientPageVO> listPageClients(ClientPageQuery queryParams) {
IPage<ClientPageVO> result = clientService.listPageClients(queryParams);
return PageResult.success(result);
}
@ApiOperation(value = "客户端详情")
@ApiImplicitParam(name = "clientId", value = "客户端id", required = true, paramType = "path", dataType = "String")
@GetMapping("/{clientId}")
public Result detail(@PathVariable String clientId) {
SysOauthClient client = sysOauthClientService.getById(clientId);
public Result detail(
@ApiParam("客户端ID") @PathVariable String clientId) {
SysOauthClient client = clientService.getById(clientId);
return Result.success(client);
}
@ApiOperation(value = "新增客户端")
@ApiImplicitParam(name = "client", value = "实体JSON对象", required = true, paramType = "body", dataType = "OauthClientDetails")
@PostMapping
public Result add(@RequestBody SysOauthClient client) {
boolean status = sysOauthClientService.save(client);
boolean status = clientService.save(client);
return Result.judge(status);
}
@ApiOperation(value = "修改客户端")
@ApiImplicitParams({
@ApiImplicitParam(name = "clientId", value = "客户端id", required = true, paramType = "path", dataType = "String"),
@ApiImplicitParam(name = "client", value = "实体JSON对象", required = true, paramType = "body", dataType = "OauthClientDetails")
})
@PutMapping(value = "/{clientId}")
public Result update(
@PathVariable String clientId,
@ApiParam("客户端ID") @PathVariable String clientId,
@RequestBody SysOauthClient client) {
boolean status = sysOauthClientService.updateById(client);
boolean status = clientService.updateById(client);
return Result.judge(status);
}
@ApiOperation(value = "删除客户端")
@ApiImplicitParam(name = "ids", value = "id集合,以,拼接字符串", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}")
public Result delete(@PathVariable("ids") String ids) {
boolean status = sysOauthClientService.removeByIds(Arrays.asList(ids.split(",")));
public Result delete(
@ApiParam("客户端ID多个以英文逗号(,)分割") @PathVariable("ids") String ids
) {
boolean status = clientService.removeByIds(Arrays.asList(ids.split(",")));
return Result.judge(status);
}
@ApiOperation(hidden = true, value = "获取 OAuth2 客户端认证信息", notes = "Feign 调用")
@ApiOperation(value = "获取 OAuth2 客户端认证信息", notes = "Feign 调用", hidden = true)
@GetMapping("/getOAuth2ClientById")
public Result<ClientAuthDTO> getOAuth2ClientById(@RequestParam String clientId) {
SysOauthClient client = sysOauthClientService.getById(clientId);
public Result<ClientAuthDTO> getOAuth2ClientById(
@ApiParam("客户端ID") @RequestParam String clientId) {
SysOauthClient client = clientService.getById(clientId);
Assert.isTrue(client != null, "OAuth2 客户端不存在");
ClientAuthDTO clientAuthDTO = new ClientAuthDTO();
BeanUtil.copyProperties(client, clientAuthDTO);

View File

@ -25,15 +25,16 @@ public class SysPermissionController {
@ApiOperation(value = "权限分页列表")
@GetMapping("/page")
public PageResult<PermPageVO> listPermsPage(PermPageQuery permPageQuery
) {
IPage<PermPageVO> result = sysPermissionService.listPermsPage(permPageQuery);
public PageResult<PermPageVO> listPagePerms(PermPageQuery permPageQuery) {
IPage<PermPageVO> result = sysPermissionService.listPagePerms(permPageQuery);
return PageResult.success(result);
}
@ApiOperation(value = "权限列表")
@GetMapping
public Result listPermissions(@ApiParam(value = "菜单ID") @RequestParam(required = false) Long menuId) {
public Result listPermissions(
@ApiParam(value = "菜单ID") @RequestParam(required = false) Long menuId
) {
List<SysPermission> list = sysPermissionService.list(
new LambdaQueryWrapper<SysPermission>()
.eq(menuId != null, SysPermission::getMenuId, menuId)

View File

@ -29,7 +29,7 @@ public class SysRoleController {
private final SysRoleService sysRoleService;
@ApiOperation(value = "角色分页列表")
@GetMapping("/page_list")
@GetMapping
public PageResult<RolePageVO> listPageRoles(RolePageQuery queryParams) {
Page<RolePageVO> result = sysRoleService.listPageRoles(queryParams);
return PageResult.success(result);

View File

@ -1,6 +1,5 @@
package com.youlai.admin.controller;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -12,16 +11,15 @@ import com.youlai.admin.pojo.form.UserForm;
import com.youlai.admin.pojo.query.UserPageQuery;
import com.youlai.admin.pojo.vo.user.LoginUserVO;
import com.youlai.admin.pojo.vo.user.UserExportVO;
import com.youlai.admin.pojo.vo.user.UserPageVO;
import com.youlai.admin.service.SysPermissionService;
import com.youlai.admin.pojo.vo.user.UserVO;
import com.youlai.admin.service.SysUserService;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.common.web.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
@ -45,90 +43,74 @@ import java.util.List;
public class SysUserController {
private final SysUserService userService;
private final SysPermissionService sysPermissionService;
@ApiOperation(value = "用户列表")
@ApiOperation(value = "用户分页列表")
@GetMapping
public PageResult<UserPageVO> listPageUsers(UserPageQuery queryParams) {
IPage<UserPageVO> result = userService.listPageUsers(queryParams);
public PageResult<UserVO> listPageUsers(UserPageQuery queryParams) {
IPage<UserVO> result = userService.listPageUsers(queryParams);
return PageResult.success(result);
}
@ApiOperation(value = "用户表单数据")
@GetMapping("/{userId}/form_data")
public Result<UserForm> getUserFormData(
@ApiParam(value = "用户ID") @PathVariable Long userId
) {
public Result<UserForm> getUserFormData(@ApiParam(value = "用户ID") @PathVariable Long userId) {
UserForm userForm = userService.getUserFormData(userId);
return Result.success(userForm);
}
@ApiOperation(value = "新增用户")
@PostMapping
public Result saveUser(@RequestBody UserForm userForm) {
public Result saveUser(@RequestBody @Validated UserForm userForm) {
boolean result = userService.saveUser(userForm);
return Result.judge(result);
}
@ApiOperation(value = "修改用户")
@PutMapping(value = "/{userId}")
public Result updateUser(
@ApiParam("用户ID") @PathVariable Long userId,
@RequestBody UserForm userForm
) {
public Result updateUser(@ApiParam("用户ID") @PathVariable Long userId, @RequestBody @Validated UserForm userForm) {
boolean result = userService.updateUser(userId, userForm);
return Result.judge(result);
}
@ApiOperation(value = "删除用户")
@DeleteMapping("/{ids}")
public Result deleteUsers(
@ApiParam("用户ID多个以英文逗号(,)分割") @PathVariable String ids
) {
public Result deleteUsers(@ApiParam("用户ID多个以英文逗号(,)分割") @PathVariable String ids) {
boolean result = userService.deleteUsers(ids);
return Result.judge(result);
}
@ApiOperation(value = "修改用户密码")
@PatchMapping(value = "/{userId}/password")
public Result updateUserPassword(
@ApiParam("用户ID") @PathVariable Long userId,
@RequestParam String password
) {
public Result updateUserPassword(@ApiParam("用户ID") @PathVariable Long userId, @RequestParam String password) {
boolean result = userService.updateUserPassword(userId, password);
return Result.judge(result);
}
@ApiOperation(value = "修改用户状态")
@PatchMapping(value = "/{userId}/status")
public Result updateUserPassword(
@ApiParam("用户ID") @PathVariable Long userId,
@RequestParam Integer status
) {
boolean result = userService.update(
new LambdaUpdateWrapper<SysUser>().eq(SysUser::getId, userId)
.set(SysUser::getStatus, status)
public Result updateUserPassword(@ApiParam("用户ID") @PathVariable Long userId, @RequestParam Integer status) {
boolean result = userService.update(new LambdaUpdateWrapper<SysUser>()
.eq(SysUser::getId, userId)
.set(SysUser::getStatus, status)
);
return Result.judge(result);
}
@ApiOperation(value = "根据用户名获取认证信息", notes = "提供用于用户登录认证信息")
@GetMapping("/username/{username}")
public Result<UserAuthDTO> getAuthInfoByUsername(
@ApiParam("用户名") @PathVariable String username) {
UserAuthDTO user = userService.getAuthInfoByUsername(username);
return Result.success(user);
}
@ApiOperation(value = "获取当前登陆的用户信息")
@ApiOperation(value = "获取登录用户信息")
@GetMapping("/me")
public Result<LoginUserVO> getLoginUserInfo() {
LoginUserVO loginUserVO = userService.getLoginUserInfo();
LoginUserVO loginUserVO = userService.getLoginUserInfo();
return Result.success(loginUserVO);
}
@ApiOperation(value = "根据用户名获取认证信息", notes = "提供用于用户登录认证信息", hidden = true)
@GetMapping("/username/{username}")
public Result<UserAuthDTO> getAuthInfoByUsername(@ApiParam("用户名") @PathVariable String username) {
UserAuthDTO user = userService.getAuthInfoByUsername(username);
return Result.success(user);
}
@ApiOperation("用户导入模板下载")
@GetMapping("/template")
public void downloadTemplate(HttpServletResponse response) throws IOException {
@ -160,9 +142,6 @@ public class SysUserController {
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
List<UserExportVO> exportUserList = userService.listExportUsers(queryParams);
EasyExcel.write(response.getOutputStream(), UserExportVO.class)
.sheet("用户列表")
.doWrite(exportUserList);
EasyExcel.write(response.getOutputStream(), UserExportVO.class).sheet("用户列表").doWrite(exportUserList);
}
}

View File

@ -0,0 +1,20 @@
package com.youlai.admin.convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.admin.pojo.entity.SysOauthClient;
import com.youlai.admin.pojo.vo.client.ClientPageVO;
import org.mapstruct.Mapper;
/**
* 客户端实体转换器
*
* @author haoxr
* @date 2022/6/11
*/
@Mapper(componentModel = "spring")
public interface ClientConvert {
ClientPageVO entity2PageVO(SysOauthClient entity);
Page<ClientPageVO> entity2PageVO(Page<SysOauthClient> entityPage);
}

View File

@ -6,14 +6,14 @@ import com.youlai.admin.pojo.form.UserForm;
import com.youlai.admin.pojo.po.UserFormPO;
import com.youlai.admin.pojo.po.UserPO;
import com.youlai.admin.pojo.vo.user.LoginUserVO;
import com.youlai.admin.pojo.vo.user.UserPageVO;
import com.youlai.admin.pojo.vo.user.UserVO;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
/**
* 用户对象转换器
* 用户实体转换器
*
* @author haoxr
* @date 2022/6/8
@ -21,7 +21,12 @@ import org.mapstruct.Mappings;
@Mapper(componentModel = "spring")
public interface UserConvert {
Page<UserPageVO> po2PageVO(Page<UserPO> page);
@Mappings({
@Mapping(target = "genderLabel", expression = "java(com.youlai.common.base.IBaseEnum.getLabelByValue(po.getGender(), com.youlai.common.enums.GenderEnum.class))")
})
UserVO po2Vo(UserPO po);
Page<UserVO> po2Vo(Page<UserPO> po);
UserForm po2Form(UserFormPO po);

View File

@ -1,4 +1,4 @@
package com.youlai.admin.component.handler;
package com.youlai.admin.handler;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.component.handler;
package com.youlai.admin.handler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.youlai.admin.pojo.vo.user.LoginUserVO;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.component.listener.excel;
package com.youlai.admin.listener.excel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

View File

@ -1,9 +1,9 @@
package com.youlai.admin.component.listener;
package com.youlai.admin.listener.rabbitmq;
import com.youlai.admin.service.SysMenuService;
import com.youlai.admin.service.SysOauthClientService;
import com.youlai.admin.service.SysPermissionService;
import com.youlai.common.dto.CanalMessage;
import com.youlai.common.web.domain.CanalMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
@ -27,7 +27,6 @@ public class CanalListener {
private final SysOauthClientService oauthClientService;
private final SysMenuService menuService;
@RabbitListener(queues = "canal.queue")
public void handleDataChange(@Payload CanalMessage message) {
String tableName = message.getTable();

View File

@ -19,7 +19,7 @@ public interface SysPermissionMapper extends BaseMapper<SysPermission> {
* @param queryParams
* @return
*/
List<PermPageVO> listPermsPage(Page<PermPageVO> page, PermPageQuery queryParams);
List<PermPageVO> listPagePerms(Page<PermPageVO> page, PermPageQuery queryParams);
/**
* 权限<->有权限的角色集合

View File

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.youlai.admin.common.enums.MenuTypeEnum;
import com.youlai.common.enums.MenuTypeEnum;
import com.youlai.common.base.BaseEntity;
import lombok.Data;

View File

@ -2,47 +2,71 @@ package com.youlai.admin.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 客户端实体
*
* @author haoxr
* @date 2022/6/11
*/
@Data
public class SysOauthClient {
/**
* 客户端ID
*/
@TableId(type = IdType.INPUT)
@ApiModelProperty(value = "客户端ID")
private String clientId;
@ApiModelProperty(value = "客户端密钥")
/**
* 客户端密钥
*/
private String clientSecret;
@ApiModelProperty(value = "资源id列表")
/**
* 资源id集合
*/
private String resourceIds;
@ApiModelProperty(value = "")
/**
* 作用域
*/
private String scope;
@ApiModelProperty(value = "授权方式")
/**
* 授权方式
*/
private String authorizedGrantTypes;
@ApiModelProperty("回调地址")
/**
* 回调地址
*/
private String webServerRedirectUri;
@ApiModelProperty(value = "权限列表")
/**
* 权限集合
*/
private String authorities;
@ApiModelProperty(value = "认证令牌时效")
/**
* 认证令牌时效()
*/
private Integer accessTokenValidity;
@ApiModelProperty(value = "刷新令牌时效")
/**
* 刷新令牌时效(单位:)
*/
private Integer refreshTokenValidity;
@ApiModelProperty(value = "扩展信息")
/**
* 扩展信息
*/
private String additionalInformation;
@ApiModelProperty(value = "是否自动放行")
/**
* 是否自动放行
*/
private String autoapprove;
}

View File

@ -35,7 +35,7 @@ public class SysUser extends BaseEntity {
private Long deptId;
@ApiModelProperty("逻辑删除标识 0-未删除 1-已删除")
@ApiModelProperty("逻辑删除标识(1:删除;0:正常)")
@TableLogic(value = "0", delval = "1")
private Integer deleted;

View File

@ -1,10 +1,11 @@
package com.youlai.admin.pojo.form;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.util.List;
/**
@ -13,15 +14,19 @@ import java.util.List;
* @author haoxr
* @date 2022/4/12 11:04
*/
@ApiModel
@Data
public class UserForm {
private Long id;
@NotBlank(message = "用户名不能为空")
private String username;
@NotBlank(message = "用户昵称不能为空")
private String nickname;
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "{phone.valid}")
private String mobile;
private Integer gender;
@ -36,6 +41,7 @@ public class UserForm {
private Long deptId;
@NotEmpty(message = "用户角色不能为空")
private List<Long> roleIds;

View File

@ -35,7 +35,7 @@ public class UserPO {
private String mobile;
/**
* 性别
* 性别(1->2->)
*/
private Integer gender;

View File

@ -0,0 +1,14 @@
package com.youlai.admin.pojo.query;
import com.youlai.common.base.BasePageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("客户端分页查询对象")
@Data
public class ClientPageQuery extends BasePageQuery {
@ApiModelProperty("关键字(客户端ID)")
private String keywords;
}

View File

@ -0,0 +1,24 @@
package com.youlai.admin.pojo.query;
import com.youlai.common.base.BasePageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 部门分页查询对象
*
* @author haoxr
* @date 2022/6/11
*/
@ApiModel("部门分页查询对象")
@Data
public class DeptQuery {
@ApiModelProperty("关键字(部门名称)")
private String keywords;
@ApiModelProperty("状态(1->正常0->禁用)")
private Integer status;
}

View File

@ -0,0 +1,64 @@
package com.youlai.admin.pojo.vo.client;
import lombok.Data;
@Data
public class ClientPageVO {
/**
* 客户端ID
*/
private String clientId;
/**
* 客户端密钥
*/
private String clientSecret;
/**
* 资源id集合
*/
private String resourceIds;
/**
* 作用域
*/
private String scope;
/**
* 授权方式
*/
private String authorizedGrantTypes;
/**
* 回调地址
*/
private String webServerRedirectUri;
/**
* 权限集合
*/
private String authorities;
/**
* 认证令牌时效()
*/
private Integer accessTokenValidity;
/**
* 刷新令牌时效(单位:)
*/
private Integer refreshTokenValidity;
/**
* 扩展信息
*/
private String additionalInformation;
/**
* 是否自动放行
*/
private String autoapprove;
}

View File

@ -16,7 +16,7 @@ public class DictItemPageVO {
private String name;
@ApiModelProperty("")
private String code;
private String value;
@ApiModelProperty("类型状态1->启用;0->禁用")
private Integer status;

View File

@ -5,7 +5,7 @@ import lombok.Data;
import java.util.List;
@Data
public class TableMenuVO {
public class MenuVO {
private Long id;
@ -28,6 +28,6 @@ public class TableMenuVO {
private String redirect;
@JsonInclude(value = JsonInclude.Include.NON_NULL)
private List<TableMenuVO> children;
private List<MenuVO> children;
}

View File

@ -15,7 +15,7 @@ import java.util.Date;
*/
@ApiModel("用户分页视图对象")
@Data
public class UserPageVO {
public class UserVO {
@ApiModelProperty("用户ID")
private Long id;
@ -30,7 +30,7 @@ public class UserPageVO {
private String mobile;
@ApiModelProperty("性别")
private String gender;
private String genderLabel;
@ApiModelProperty("用户头像地址")
private String avatar;

View File

@ -2,6 +2,7 @@ package com.youlai.admin.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.admin.pojo.entity.SysDept;
import com.youlai.admin.pojo.query.DeptQuery;
import com.youlai.admin.pojo.vo.dept.DeptVO;
import com.youlai.common.web.domain.Option;
@ -15,13 +16,11 @@ import java.util.List;
*/
public interface SysDeptService extends IService<SysDept> {
/**
* 部门表格Table层级列表
* 部门列表
*
* @param status 部门状态 1-开启 0-禁用
* @param name
* @return
*/
List<DeptVO> listTableDepartments(Integer status, String name);
List<DeptVO> listDepartments(DeptQuery queryParams);
/**
* 部门树形下拉TreeSelect层级列表

View File

@ -6,6 +6,9 @@ import com.youlai.admin.pojo.entity.SysDictItem;
import com.youlai.admin.pojo.form.DictItemForm;
import com.youlai.admin.pojo.query.DictItemPageQuery;
import com.youlai.admin.pojo.vo.dict.DictItemPageVO;
import com.youlai.common.web.domain.Option;
import java.util.List;
/**
@ -30,7 +33,7 @@ public interface SysDictItemService extends IService<SysDictItem> {
* @param id 字典数据项ID
* @return
*/
DictItemForm getDictItemFormDetail(Long id);
DictItemForm getDictItemFormData(Long id);
/**
* 新增字典数据项
@ -56,4 +59,12 @@ public interface SysDictItemService extends IService<SysDictItem> {
* @return
*/
boolean deleteDictItems(String idsStr);
/**
* 根据字典类型编码获取字典数据项
*
* @param typeCode 字典类型编码
* @return
*/
List<Option> listDictItemsByTypeCode(String typeCode);
}

View File

@ -31,7 +31,7 @@ public interface SysDictTypeService extends IService<SysDictType> {
* @param id 字典类型ID
* @return
*/
DictTypeForm getDictTypeFormDetail(Long id);
DictTypeForm getDictTypeFormData(Long id);
/**

View File

@ -3,13 +3,15 @@ package com.youlai.admin.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.admin.pojo.entity.SysMenu;
import com.youlai.admin.pojo.vo.menu.ResourceVO;
import com.youlai.admin.pojo.vo.menu.TableMenuVO;
import com.youlai.admin.pojo.vo.menu.MenuVO;
import com.youlai.admin.pojo.vo.menu.RouteVO;
import com.youlai.common.web.domain.Option;
import java.util.List;
/**
* 菜单业务接口
*
* @author haoxr
* @date 2020/11/06
*/
@ -21,7 +23,7 @@ public interface SysMenuService extends IService<SysMenu> {
* @param name 菜单名称
* @return
*/
List<TableMenuVO> listTableMenus(String name);
List<MenuVO> listMenus(String name);
/**
@ -29,7 +31,7 @@ public interface SysMenuService extends IService<SysMenu> {
*
* @return
*/
List<Option> listMenus();
List<Option> listSelectMenus();
/**
* 新增菜单
@ -57,4 +59,13 @@ public interface SysMenuService extends IService<SysMenu> {
* @return
*/
ResourceVO getResource();
/**
* 修改菜单显示状态
*
* @param menuId 菜单ID
* @param visible 是否显示(1->显示2->隐藏)
* @return
*/
boolean updateMenuVisible(Long menuId, Integer visible);
}

View File

@ -1,8 +1,27 @@
package com.youlai.admin.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.admin.pojo.entity.SysOauthClient;
import com.youlai.admin.pojo.query.ClientPageQuery;
import com.youlai.admin.pojo.vo.client.ClientPageVO;
/**
* OAuth2客户端接口
*
* @author haoxr
* @date 2022/6/11
*/
public interface SysOauthClientService extends IService<SysOauthClient> {
/**
* 客户端分页列表
*
* @param queryParams
* @return
*/
IPage<ClientPageVO> listPageClients(ClientPageQuery queryParams);
void cleanCache();
}

View File

@ -42,5 +42,5 @@ public interface SysPermissionService extends IService<SysPermission> {
* @param permPageQuery
* @return
*/
IPage<PermPageVO> listPermsPage(PermPageQuery permPageQuery);
IPage<PermPageVO> listPagePerms(PermPageQuery permPageQuery);
}

View File

@ -10,7 +10,7 @@ import com.youlai.admin.pojo.dto.UserImportDTO;
import com.youlai.admin.pojo.query.UserPageQuery;
import com.youlai.admin.pojo.vo.user.LoginUserVO;
import com.youlai.admin.pojo.vo.user.UserExportVO;
import com.youlai.admin.pojo.vo.user.UserPageVO;
import com.youlai.admin.pojo.vo.user.UserVO;
import java.io.IOException;
import java.util.List;
@ -28,7 +28,7 @@ public interface SysUserService extends IService<SysUser> {
*
* @return
*/
IPage<UserPageVO> listPageUsers(UserPageQuery queryParams);
IPage<UserVO> listPageUsers(UserPageQuery queryParams);
/**
@ -84,7 +84,6 @@ public interface SysUserService extends IService<SysUser> {
*/
UserAuthDTO getAuthInfoByUsername(String username);
/**
* 导入用户
*
@ -103,7 +102,7 @@ public interface SysUserService extends IService<SysUser> {
/**
* 获取当前登录用户信息
* 获取登录用户信息
*
* @return
*/

View File

@ -7,12 +7,12 @@ import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.admin.common.constant.SystemConstants;
import com.youlai.common.constant.SystemConstants;
import com.youlai.admin.mapper.SysDeptMapper;
import com.youlai.admin.pojo.entity.SysDept;
import com.youlai.admin.pojo.query.DeptQuery;
import com.youlai.admin.pojo.vo.dept.DeptVO;
import com.youlai.admin.service.SysDeptService;
import com.youlai.admin.service.SysUserService;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.web.domain.Option;
import lombok.RequiredArgsConstructor;
@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/**
* 部门业务
* 部门业务实现
*
* @author haoxr
* @date 2021-08-22
@ -33,23 +33,26 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
private final SysUserService sysUserService;
/**
* 部门表格Table层级列表
* 部门列表
*
* @param name 部门名称
* @return
*/
@Override
public List<DeptVO> listTableDepartments(Integer status, String name) {
public List<DeptVO> listDepartments(DeptQuery queryParams) {
// 查询参数
String keywords = queryParams.getKeywords();
Integer status = queryParams.getStatus();
// 查询数据
List<SysDept> deptList = this.list(
new LambdaQueryWrapper<SysDept>()
.like(StrUtil.isNotBlank(name), SysDept::getName, name)
.like(StrUtil.isNotBlank(keywords), SysDept::getName, keywords)
.eq(Validator.isNotNull(status), SysDept::getStatus, status)
.orderByAsc(SysDept::getSort)
);
return recursion(deptList);
return recurDepartments(deptList);
}
/**
@ -58,7 +61,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
* @param deptList 部门列表
* @return 部门列表
*/
private static List<DeptVO> recursion(List<SysDept> deptList) {
private static List<DeptVO> recurDepartments(List<SysDept> deptList) {
List<DeptVO> deptTableList = new ArrayList<>();
// 保存所有节点的 id
Set<Long> nodeIdSet = deptList.stream()
@ -68,7 +71,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
// 不在节点 id 集合中存在的 id 即为顶级节点 id, 递归生成列表
Long parentId = sysDept.getParentId();
if (!nodeIdSet.contains(parentId)) {
deptTableList.addAll(recurTableMenus(parentId, deptList));
deptTableList.addAll(recurTableDepts(parentId, deptList));
nodeIdSet.add(parentId);
}
}
@ -92,7 +95,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
* @param deptList
* @return
*/
public static List<DeptVO> recurTableMenus(Long parentId, List<SysDept> deptList) {
public static List<DeptVO> recurTableDepts(Long parentId, List<SysDept> deptList) {
List<DeptVO> deptTableList = new ArrayList<>();
Optional.ofNullable(deptList).orElse(new ArrayList<>())
.stream()
@ -100,7 +103,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
.forEach(dept -> {
DeptVO deptVO = new DeptVO();
BeanUtil.copyProperties(dept, deptVO);
List<DeptVO> children = recurTableMenus(dept.getId(), deptList);
List<DeptVO> children = recurTableDepts(dept.getId(), deptList);
deptVO.setChildren(children);
deptTableList.add(deptVO);
});

View File

@ -12,11 +12,11 @@ import com.youlai.admin.pojo.form.DictItemForm;
import com.youlai.admin.pojo.query.DictItemPageQuery;
import com.youlai.admin.pojo.vo.dict.DictItemPageVO;
import com.youlai.admin.service.SysDictItemService;
import com.youlai.common.web.domain.Option;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@ -51,8 +51,8 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
new Page<>(pageNum, pageSize),
new LambdaQueryWrapper<SysDictItem>()
.like(StrUtil.isNotBlank(keywords), SysDictItem::getName, keywords)
.eq(StrUtil.isNotBlank(keywords), SysDictItem::getTypeCode, typeCode)
.select(SysDictItem::getId, SysDictItem::getName, SysDictItem::getTypeCode, SysDictItem::getStatus)
.eq(StrUtil.isNotBlank(typeCode), SysDictItem::getTypeCode, typeCode)
.select(SysDictItem::getId, SysDictItem::getName, SysDictItem::getValue, SysDictItem::getStatus)
);
// 实体转换
@ -67,7 +67,7 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
* @return
*/
@Override
public DictItemForm getDictItemFormDetail(Long id) {
public DictItemForm getDictItemFormData(Long id) {
// 获取entity
SysDictItem entity = this.getOne(new LambdaQueryWrapper<SysDictItem>()
.eq(SysDictItem::getId, id)
@ -135,4 +135,28 @@ public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDi
boolean result = this.removeByIds(ids);
return result;
}
/**
* 根据字典类型编码获取字典数据项
*
* @param typeCode 字典类型编码
* @return
*/
@Override
public List<Option> listDictItemsByTypeCode(String typeCode) {
// 数据字典项
List<SysDictItem> dictItems = this.list(new LambdaQueryWrapper<SysDictItem>()
.eq(SysDictItem::getTypeCode, typeCode)
.select(SysDictItem::getValue, SysDictItem::getName)
);
// 转换下拉数据
List<Option> options = Optional.ofNullable(dictItems).orElse(new ArrayList<>()).stream()
.map(dictItem -> new Option(dictItem.getValue(), dictItem.getName()))
.collect(Collectors.toList());
return options;
}
}

View File

@ -72,7 +72,7 @@ public class SysDictTypeTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, S
* @return
*/
@Override
public DictTypeForm getDictTypeFormDetail(Long id) {
public DictTypeForm getDictTypeFormData(Long id) {
// 获取entity
SysDictType entity = this.getOne(new LambdaQueryWrapper<SysDictType>()
.eq(SysDictType::getId, id)

View File

@ -5,15 +5,16 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.admin.common.constant.SystemConstants;
import com.youlai.admin.common.enums.MenuTypeEnum;
import com.youlai.common.constant.SystemConstants;
import com.youlai.common.enums.MenuTypeEnum;
import com.youlai.admin.mapper.SysMenuMapper;
import com.youlai.admin.pojo.entity.SysMenu;
import com.youlai.admin.pojo.entity.SysPermission;
import com.youlai.admin.pojo.vo.menu.ResourceVO;
import com.youlai.admin.pojo.vo.menu.RouteVO;
import com.youlai.admin.pojo.vo.menu.TableMenuVO;
import com.youlai.admin.pojo.vo.menu.MenuVO;
import com.youlai.admin.service.SysMenuService;
import com.youlai.admin.service.SysPermissionService;
import com.youlai.common.constant.GlobalConstants;
@ -43,7 +44,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
* 菜单表格树形列表
*/
@Override
public List<TableMenuVO> listTableMenus(String name) {
public List<MenuVO> listMenus(String name) {
List<SysMenu> menus = this.list(new LambdaQueryWrapper<SysMenu>()
.like(StrUtil.isNotBlank(name), SysMenu::getName, name)
.orderByAsc(SysMenu::getSort)
@ -51,14 +52,14 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
Set<Long> cacheMenuIds = menus.stream().map(menu -> menu.getId()).collect(Collectors.toSet());
List<TableMenuVO> tableMenus = menus.stream().map(menu -> {
List<MenuVO> tableMenus = menus.stream().map(menu -> {
Long parentId = menu.getParentId();
// parentId不在当前菜单ID的列表说明为顶级菜单ID根据此ID作为递归的开始条件节点
if (!cacheMenuIds.contains(parentId)) {
cacheMenuIds.add(parentId);
return recurTableMenus(parentId, menus);
}
return new LinkedList<TableMenuVO>();
return new LinkedList<MenuVO>();
}).collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);
return tableMenus;
}
@ -93,7 +94,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
* 菜单下拉数据
*/
@Override
public List<Option> listMenus() {
public List<Option> listSelectMenus() {
List<SysMenu> menuList = this.list(new LambdaQueryWrapper<SysMenu>().orderByAsc(SysMenu::getSort));
List<Option> menus = recurMenus(SystemConstants.ROOT_MENU_ID, menuList);
return menus;
@ -164,7 +165,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
List<SysMenu> menuList = this.list(new LambdaQueryWrapper<SysMenu>().orderByAsc(SysMenu::getSort));
List<SysPermission> permList = permissionService.list();
ResourceVO resource=new ResourceVO();
ResourceVO resource = new ResourceVO();
List<ResourceVO.MenuOption> menus = recurResources(SystemConstants.ROOT_MENU_ID, menuList, permList);
resource.setMenus(menus);
@ -176,6 +177,25 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
return resource;
}
/**
* 修改菜单显示状态
*
* @param menuId 菜单ID
* @param visible 是否显示(1->显示2->隐藏)
* @return
*/
@Override
public boolean updateMenuVisible(Long menuId, Integer visible) {
boolean result = this.update(new LambdaUpdateWrapper<SysMenu>()
.eq(SysMenu::getId, menuId)
.set(SysMenu::getVisible, visible)
);
if (result) {
permissionService.refreshPermRolesRules();
}
return result;
}
/**
* 递归生成菜单表格层级列表
*
@ -183,16 +203,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
* @param menuList 菜单列表
* @return
*/
private static List<TableMenuVO> recurTableMenus(Long parentId, List<SysMenu> menuList) {
List<TableMenuVO> tableMenus = Optional.ofNullable(menuList).orElse(new ArrayList<>())
private static List<MenuVO> recurTableMenus(Long parentId, List<SysMenu> menuList) {
List<MenuVO> tableMenus = Optional.ofNullable(menuList).orElse(new ArrayList<>())
.stream()
.filter(menu -> menu.getParentId().equals(parentId))
.map(menu -> {
TableMenuVO tableMenuVO = new TableMenuVO();
BeanUtil.copyProperties(menu, tableMenuVO);
List<TableMenuVO> children = recurTableMenus(menu.getId(), menuList);
tableMenuVO.setChildren(children);
return tableMenuVO;
MenuVO menuVO = new MenuVO();
BeanUtil.copyProperties(menu, menuVO);
List<MenuVO> children = recurTableMenus(menu.getId(), menuList);
menuVO.setChildren(children);
return menuVO;
}).collect(Collectors.toList());
return tableMenus;
}
@ -223,17 +243,17 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
List<ResourceVO.MenuOption> menus = Optional.ofNullable(menuList).orElse(new ArrayList<>()).stream()
.filter(menu -> menu.getParentId().equals(parentId))
.map(menu -> {
Long menuId= menu.getId();
Long menuId = menu.getId();
ResourceVO.MenuOption menuOption = new ResourceVO.MenuOption();
menuOption.setValue( menu.getId());
menuOption.setValue(menu.getId());
menuOption.setLabel(menu.getName());
List< ResourceVO.MenuOption> children = recurResources(menu.getId(), menuList, permList);
List<ResourceVO.MenuOption> children = recurResources(menu.getId(), menuList, permList);
long count = permList.stream().filter(perm -> perm.getMenuId().equals(menuId)).count();
// 如果该菜单下有权限添加一个节点存放权限数据
if(count>0){
if (count > 0) {
ResourceVO.MenuOption permOption = new ResourceVO.MenuOption();
permOption.setIsPerm(true);
permOption.setValue(-1l);

View File

@ -1,9 +1,16 @@
package com.youlai.admin.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.admin.pojo.entity.SysOauthClient;
import com.youlai.admin.convert.ClientConvert;
import com.youlai.admin.mapper.SysOauthClientMapper;
import com.youlai.admin.pojo.entity.SysOauthClient;
import com.youlai.admin.pojo.query.ClientPageQuery;
import com.youlai.admin.pojo.vo.client.ClientPageVO;
import com.youlai.admin.service.SysOauthClientService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -12,7 +19,7 @@ import org.springframework.stereotype.Service;
import java.util.Set;
/**
* OAuth2 客户端业务类
* OAuth2客户端业务实现
*
* @author haoxr
* @date 2020-11-06
@ -22,6 +29,35 @@ import java.util.Set;
public class SysOauthClientServiceImpl extends ServiceImpl<SysOauthClientMapper, SysOauthClient> implements SysOauthClientService {
private final StringRedisTemplate stringRedisTemplate;
private final ClientConvert clientConvert;
/**
* 客户端分页列表
*
* @param queryParams
* @return
*/
@Override
public IPage<ClientPageVO> listPageClients(ClientPageQuery queryParams) {
// 参数构建
int pageNum = queryParams.getPageNum();
int pageSize = queryParams.getPageSize();
String keywords = queryParams.getKeywords();
Page<SysOauthClient> page = new Page<>(pageNum, pageSize);
// 查询数据
Page<SysOauthClient> entityPage = this.page(page,
new LambdaQueryWrapper<SysOauthClient>()
.like(StrUtil.isNotBlank(keywords), SysOauthClient::getClientId,keywords)
);
// 实体转换
Page<ClientPageVO> voPage = clientConvert.entity2PageVO(entityPage);
return voPage;
}
/**
* 清理客户端缓存

View File

@ -41,9 +41,9 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
* @return
*/
@Override
public IPage<PermPageVO> listPermsPage(PermPageQuery queryParams) {
public IPage<PermPageVO> listPagePerms(PermPageQuery queryParams) {
Page<PermPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
List<PermPageVO> list = this.baseMapper.listPermsPage(page, queryParams);
List<PermPageVO> list = this.baseMapper.listPagePerms(page, queryParams);
page.setRecords(list);
return page;
}

View File

@ -1,6 +1,5 @@
package com.youlai.admin.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
@ -14,9 +13,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.youlai.admin.common.constant.SystemConstants;
import com.youlai.admin.common.enums.GenderEnum;
import com.youlai.admin.component.listener.excel.UserImportListener;
import com.youlai.admin.pojo.vo.user.UserVO;
import com.youlai.common.constant.SystemConstants;
import com.youlai.common.enums.GenderEnum;
import com.youlai.admin.listener.excel.UserImportListener;
import com.youlai.admin.convert.UserConvert;
import com.youlai.admin.dto.UserAuthDTO;
import com.youlai.admin.mapper.SysUserMapper;
@ -29,7 +29,6 @@ import com.youlai.admin.pojo.po.UserPO;
import com.youlai.admin.pojo.query.UserPageQuery;
import com.youlai.admin.pojo.vo.user.LoginUserVO;
import com.youlai.admin.pojo.vo.user.UserExportVO;
import com.youlai.admin.pojo.vo.user.UserPageVO;
import com.youlai.admin.service.SysPermissionService;
import com.youlai.admin.service.SysUserRoleService;
import com.youlai.admin.service.SysUserService;
@ -59,7 +58,7 @@ import java.util.stream.Collectors;
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
private final PasswordEncoder passwordEncoder;
private final SysUserRoleService sysUserRoleService;
private final SysUserRoleService userRoleService;
private final UserImportListener userImportListener;
private final SysPermissionService permissionService;
private final UserConvert userConvert;
@ -71,7 +70,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return
*/
@Override
public IPage<UserPageVO> listPageUsers(UserPageQuery queryParams) {
public IPage<UserVO> listPageUsers(UserPageQuery queryParams) {
// 参数构建
int pageNum = queryParams.getPageNum();
@ -79,12 +78,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
Page<UserPO> page = new Page<>(pageNum, pageSize);
// 查询数据
Page<UserPO> userPagePO = this.baseMapper.listPageUsers(page, queryParams);
Page<UserPO> userPoPage = this.baseMapper.listPageUsers(page, queryParams);
// 实体转换
Page<UserPageVO> voPage = userConvert.po2PageVO(userPagePO);
Page<UserVO> userVoPage = userConvert.po2Vo(userPoPage);
return voPage;
return userVoPage;
}
/**
@ -110,19 +109,26 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
public boolean saveUser(UserForm userForm) {
SysUser user = new SysUser();
BeanUtil.copyProperties(userForm, user);
// 实体转换 form->entity
SysUser entity = userConvert.form2Entity(userForm);
// 设置默认加密密码
String defaultEncryptPwd = passwordEncoder.encode(SystemConstants.DEFAULT_USER_PASSWORD);
entity.setPassword(defaultEncryptPwd);
// 新增用户
boolean result = this.save(entity);
user.setPassword(passwordEncoder.encode(SystemConstants.DEFAULT_USER_PASSWORD)); // 初始化默认密码
boolean result = this.save(user);
if (result) {
Long userId = user.getId();
List<Long> roleIds = user.getRoleIds();
List<SysUserRole> sysUserRoles = Optional.ofNullable(roleIds).orElse(new ArrayList<>())
.stream().map(roleId -> new SysUserRole(userId, roleId))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(sysUserRoles)) {
sysUserRoleService.saveBatch(sysUserRoles);
// 保存用户角色关联信息
Long userId = entity.getId();
List<Long> roleIds = userForm.getRoleIds();
if (CollectionUtil.isNotEmpty(roleIds)) {
List<SysUserRole> userRoles = roleIds
.stream()
.map(roleId -> new SysUserRole(userId, roleId))
.collect(Collectors.toList());
userRoleService.saveBatch(userRoles);
}
}
return result;
@ -138,39 +144,39 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
public boolean updateUser(Long userId, UserForm userForm) {
SysUser user = this.getById(userId);
Assert.isTrue(user != null, "用户不存在或已被删除");
// 用户旧角色ID集合
List<Long> oldRoleIds = sysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>()
// 用户的旧角色ID集合
List<Long> oldRoleIds = userRoleService.list(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getUserId, userId))
.stream()
.map(item -> item.getRoleId())
.collect(Collectors.toList());
// 用户新角色ID集合
// 用户新角色ID集合
List<Long> newRoleIds = userForm.getRoleIds();
// 新增用户角色
// 新增用户角色
List<Long> addRoleIds = newRoleIds.stream().filter(roleId -> !oldRoleIds.contains(roleId)).collect(Collectors.toList());
List<SysUserRole> addUserRoles = Optional.ofNullable(addRoleIds).orElse(new ArrayList<>())
.stream().map(roleId -> new SysUserRole(userId, roleId))
.collect(Collectors.toList());
sysUserRoleService.saveBatch(addUserRoles);
userRoleService.saveBatch(addUserRoles);
// 删除用户角色
// 删除用户角色
List<Long> removeRoleIds = oldRoleIds.stream().filter(roleId -> !newRoleIds.contains(roleId)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(removeRoleIds)) {
sysUserRoleService.remove(new LambdaQueryWrapper<SysUserRole>()
userRoleService.remove(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getUserId, userId)
.in(SysUserRole::getRoleId, removeRoleIds)
);
}
BeanUtil.copyProperties(userForm, user);
boolean updateRes = this.updateById(user);
return updateRes;
// form -> entity
SysUser entity = userConvert.form2Entity(userForm);
// 修改用户
boolean result = this.updateById(entity);
return result;
}
/**
@ -181,8 +187,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/
@Override
public boolean deleteUsers(String idsStr) {
return false;
Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的用户数据为空");
// 逻辑删除
List<Long> ids = Arrays.asList(idsStr.split(",")).stream().map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
boolean result = this.removeByIds(ids);
return result;
}
@ -216,7 +225,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return userAuthInfo;
}
/**
* 导入用户
*
@ -299,7 +307,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
});
}
sysUserRoleService.saveBatch(userRoleList);
userRoleService.saveBatch(userRoleList);
}
errMsg.append(StrUtil.format("一共{}条数据,成功导入{}条数据,导入失败数据{}条", list.size(), saveUserList.size(), list.size() - saveUserList.size()));
@ -320,27 +328,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
/**
* 获取当前登录用户信息
* 获取登录用户信息
*
* @return
*/
@Override
public LoginUserVO getLoginUserInfo() {
// 用户基本信息
Long userId = UserUtils.getUserId();
// 登录用户entity
SysUser user = this.getOne(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getId,userId)
.select(SysUser::getId,SysUser::getNickname, SysUser::getAvatar)
);
.eq(SysUser::getId, UserUtils.getUserId())
.select(
SysUser::getId,
SysUser::getNickname,
SysUser::getAvatar
)
);
// entity->VO
LoginUserVO loginUserVO = userConvert.entity2LoginUser(user);
LoginUserVO loginUserVO = userConvert.entity2LoginUser(user);
BeanUtil.copyProperties(user, loginUserVO);
// 用户角色信息
// 用户角色集合
List<String> roles = UserUtils.getRoles();
loginUserVO.setRoles(roles);
// 用户按钮权限信息
// 用户按钮权限集合
List<String> perms = permissionService.listBtnPermByRoles(roles);
loginUserVO.setPerms(perms);

View File

@ -18,7 +18,7 @@
</resultMap>
<!-- 获取权限分页列表 -->
<select id="listPermsPage" resultType="com.youlai.admin.pojo.vo.permission.PermPageVO">
<select id="listPagePerms" resultType="com.youlai.admin.pojo.vo.permission.PermPageVO">
SELECT
t1.id,
t1.menu_id,

View File

@ -11,11 +11,7 @@
u.username,
u.nickname,
u.mobile,
CASE u.gender
WHEN 1 THEN '男'
WHEN 2 THEN '女'
ELSE '未知'
END gender,
u.gender,
u.avatar,
u.STATUS,
d.NAME AS dept_name,

View File

@ -6,8 +6,8 @@ import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import com.youlai.common.constant.SecurityConstants;
import com.youlai.common.result.Result;
import com.youlai.common.web.util.JwtUtils;
import com.youlai.common.web.util.RequestUtils;
import com.youlai.common.web.utils.JwtUtils;
import com.youlai.common.web.utils.RequestUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.clientdetails;
import com.youlai.admin.api.OAuthClientFeignClient;
import com.youlai.admin.dto.AuthClientDTO;
import com.youlai.admin.dto.ClientAuthDTO;
import com.youlai.auth.common.enums.PasswordEncoderTypeEnum;
import com.youlai.common.result.Result;
import lombok.RequiredArgsConstructor;
@ -26,9 +26,9 @@ public class ClientDetailsServiceImpl implements ClientDetailsService {
@Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId")
public ClientDetails loadClientByClientId(String clientId) {
try {
Result<AuthClientDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId);
Result<ClientAuthDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId);
if (Result.success().getCode().equals(result.getCode())) {
AuthClientDTO client = result.getData();
ClientAuthDTO client = result.getData();
BaseClientDetails clientDetails = new BaseClientDetails(
client.getClientId(),
client.getResourceIds(),

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.userdetails.user;
import cn.hutool.core.collection.CollectionUtil;
import com.youlai.admin.dto.AuthUserDTO;
import com.youlai.admin.dto.UserAuthDTO;
import com.youlai.auth.common.enums.PasswordEncoderTypeEnum;
import com.youlai.common.constant.GlobalConstants;
import lombok.Data;
@ -50,7 +50,7 @@ public class SysUserDetails implements UserDetails {
/**
* 系统管理用户
*/
public SysUserDetails(AuthUserDTO user) {
public SysUserDetails(UserAuthDTO user) {
this.setUserId(user.getUserId());
this.setUsername(user.getUsername());
this.setDeptId(user.getDeptId());

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.userdetails.user;
import com.youlai.admin.api.UserFeignClient;
import com.youlai.admin.dto.AuthUserDTO;
import com.youlai.admin.dto.UserAuthDTO;
import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
@ -29,9 +29,9 @@ public class SysUserDetailsServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
SysUserDetails userDetails = null;
Result<AuthUserDTO> result = userFeignClient.getUserByUsername(username);
Result<UserAuthDTO> result = userFeignClient.getUserByUsername(username);
if (Result.isSuccess(result)) {
AuthUserDTO user = result.getData();
UserAuthDTO user = result.getData();
if (null != user) {
userDetails = new SysUserDetails(user);
}

View File

@ -4,7 +4,7 @@ import com.youlai.auth.security.core.userdetails.member.MemberUserDetailsService
import com.youlai.common.base.IBaseEnum;
import com.youlai.common.constant.SecurityConstants;
import com.youlai.common.enums.AuthenticationIdentityEnum;
import com.youlai.common.web.util.RequestUtils;
import com.youlai.common.web.utils.RequestUtils;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.Authentication;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.common.constant;
package com.youlai.common.constant;
/**
* 系统常量

View File

@ -1,4 +1,4 @@
package com.youlai.admin.common.enums;
package com.youlai.common.enums;
import com.youlai.common.base.IBaseEnum;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.common.enums;
package com.youlai.common.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.youlai.common.base.IBaseEnum;

View File

@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.mybatis.annotation.DataPermission;
import com.youlai.common.web.util.JwtUtils;
import com.youlai.common.web.util.UserUtils;
import com.youlai.common.web.utils.JwtUtils;
import com.youlai.common.web.utils.UserUtils;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;

View File

@ -19,7 +19,7 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
@Slf4j
public class RabbitConfig {
public class RabbitMQConfig {
/**
* 消息序列化配置

View File

@ -1,3 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.youlai.common.rabbitmq.config.RabbitConfig,\
com.youlai.common.rabbitmq.config.RabbitMQConfig,\
com.youlai.common.rabbitmq.dynamic.RabbitModuleProperties

View File

@ -53,13 +53,12 @@
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<!-- JWT工具 -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.16.1</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>

View File

@ -5,11 +5,17 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.List;
@ -29,11 +35,25 @@ public class WebMvcConfig implements WebMvcConfigurer {
// 后台Long值传递给前端精度丢失问题JS最大精度整数是Math.pow(2,53)
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
// simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
converters.add(0, jackson2HttpMessageConverter);
}
@Bean
public Validator validator() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
.failFast(true) // failFast=true 不校验所有参数只要出现校验失败情况直接返回不再进行后续参数校验
.buildValidatorFactory();
return validatorFactory.getValidator();
}
@Override
public org.springframework.validation.Validator getValidator() {
return new SpringValidatorAdapter(validator());
}
}

View File

@ -1,4 +1,4 @@
package com.youlai.common.dto;
package com.youlai.common.web.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

View File

@ -33,7 +33,7 @@ public class Option<T> {
@ApiModelProperty("选项的值")
private T value;
@ApiModelProperty("选项的标签若不设置则默认与value相同")
@ApiModelProperty("选项的标签")
private String label;
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)

View File

@ -1,17 +1,17 @@
package com.youlai.common.web.exception;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.TypeMismatchException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
@ -20,12 +20,13 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
import org.springframework.web.servlet.NoHandlerFoundException;
import javax.servlet.ServletException;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.sql.SQLSyntaxErrorException;
import java.util.concurrent.CompletionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 全局系统异常处理
@ -39,53 +40,45 @@ import java.util.regex.Pattern;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/**
* 表单绑定到 java bean 出错时抛出 BindException 异常
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BindException.class)
public <T> Result<T> processException(BindException e) {
log.error(e.getMessage(), e);
JSONObject msg = new JSONObject();
e.getAllErrors().forEach(error -> {
if (error instanceof FieldError) {
FieldError fieldError = (FieldError) error;
msg.set(fieldError.getField(),
fieldError.getDefaultMessage());
} else {
msg.set(error.getObjectName(),
error.getDefaultMessage());
}
});
return Result.failed(ResultCode.PARAM_ERROR, msg.toString());
log.error("BindException:{}", e.getMessage());
String msg = e.getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(""));
return Result.failed(ResultCode.PARAM_ERROR, msg);
}
/**
* 普通参数( java bean)校验出错时抛出 ConstraintViolationException 异常
* RequestParam参数的校验
*
* @param e
* @param <T>
* @return
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ConstraintViolationException.class)
public <T> Result<T> processException(ConstraintViolationException e) {
log.error(e.getMessage(), e);
JSONObject msg = new JSONObject();
e.getConstraintViolations().forEach(constraintViolation -> {
String template = constraintViolation.getMessage();
String path = constraintViolation.getPropertyPath().toString();
msg.set(path, template);
});
return Result.failed(ResultCode.PARAM_ERROR, msg.toString());
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public <T> Result<T> processException(ValidationException e) {
log.error(e.getMessage(), e);
return Result.failed(ResultCode.PARAM_ERROR, "参数校验失败");
log.error("ConstraintViolationException:{}", e.getMessage());
String msg = e.getConstraintViolations().stream().map(ConstraintViolation::getMessage).collect(Collectors.joining(""));
return Result.failed(ResultCode.PARAM_ERROR, msg);
}
/**
* NoHandlerFoundException
* RequestBody参数的校验
*
* @param e
* @param <T>
* @return
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public <T> Result<T> processException(MethodArgumentNotValidException e) {
log.error("MethodArgumentNotValidException:{}", e.getMessage());
String msg = e.getBindingResult().getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(""));
return Result.failed(ResultCode.PARAM_ERROR, msg);
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public <T> Result<T> processException(NoHandlerFoundException e) {
@ -220,9 +213,7 @@ public class GlobalExceptionHandler {
String group = "";
if (matcher.find()) {
String matchString = matcher.group();
matchString = matchString
.replace("[", "")
.replace("]", "");
matchString = matchString.replace("[", "").replace("]", "");
matchString = matchString.replaceAll("\\\"", "") + "字段类型错误";
group += matchString;
}

View File

@ -1,4 +1,4 @@
package com.youlai.common.web.util;
package com.youlai.common.web.utils;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;

View File

@ -1,10 +1,10 @@
package com.youlai.common.web.util;
package com.youlai.common.web.utils;
import cn.hutool.json.JSONObject;
import com.youlai.common.constant.SecurityConstants;
/**
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @author haoxr
* @date 2022/2/12 20:14
*/
public class MemberUtils {

View File

@ -1,4 +1,4 @@
package com.youlai.common.web.util;
package com.youlai.common.web.utils;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;

View File

@ -1,4 +1,4 @@
package com.youlai.common.web.util;
package com.youlai.common.web.utils;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;

View File

@ -155,7 +155,6 @@ public class GatewayLogFilter implements GlobalFilter, Ordered {
httpHeaders.setContentLength(headers.getContentLength());
return httpHeaders;
}
@Override
public Flux<DataBuffer> getBody() {
return outputMessage.getBody();