初始化
This commit is contained in:
20
ygsx-shop-sys/pom.xml
Normal file
20
ygsx-shop-sys/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ygsx-shop-sys</artifactId>
|
||||
|
||||
<parent>
|
||||
<groupId>com.yami.shop</groupId>
|
||||
<artifactId>ygsx-mall</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yami.shop</groupId>
|
||||
<artifactId>ygsx-shop-security-admin</artifactId>
|
||||
<version>${yami.shop.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.aspect;
|
||||
|
||||
import cn.hutool.core.date.SystemClock;
|
||||
import com.yami.shop.common.util.IpHelper;
|
||||
import com.yami.shop.common.util.Json;
|
||||
import com.yami.shop.security.admin.util.SecurityUtils;
|
||||
import com.yami.shop.sys.model.SysLog;
|
||||
import com.yami.shop.sys.service.SysLogService;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author lgh
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class SysLogAspect {
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
private static Logger logger = LoggerFactory.getLogger(SysLogAspect.class);
|
||||
|
||||
@Around("@annotation(sysLog)")
|
||||
public Object around(ProceedingJoinPoint joinPoint,com.yami.shop.common.annotation.SysLog sysLog) throws Throwable {
|
||||
long beginTime = SystemClock.now();
|
||||
//执行方法
|
||||
Object result = joinPoint.proceed();
|
||||
//执行时长(毫秒)
|
||||
long time = SystemClock.now() - beginTime;
|
||||
|
||||
|
||||
SysLog sysLogEntity = new SysLog();
|
||||
if(sysLog != null){
|
||||
//注解上的描述
|
||||
sysLogEntity.setOperation(sysLog.value());
|
||||
}
|
||||
|
||||
//请求的方法名
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
sysLogEntity.setMethod(className + "." + methodName + "()");
|
||||
|
||||
//请求的参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = Json.toJsonString(args[0]);
|
||||
sysLogEntity.setParams(params);
|
||||
|
||||
//设置IP地址
|
||||
sysLogEntity.setIp(IpHelper.getIpAddr());
|
||||
|
||||
//用户名
|
||||
String username = SecurityUtils.getSysUser().getUsername();
|
||||
sysLogEntity.setUsername(username);
|
||||
|
||||
sysLogEntity.setTime(time);
|
||||
sysLogEntity.setCreateDate(new Date());
|
||||
//保存系统日志
|
||||
sysLogService.save(sysLogEntity);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.constant;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
* @author lanhai
|
||||
*/
|
||||
public class Constant {
|
||||
/** 超级管理员ID */
|
||||
public static final int SUPER_ADMIN_ID = 1;
|
||||
|
||||
/** 系统菜单最大id */
|
||||
public static final int SYS_MENU_MAX_ID = 1;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.yami.shop.sys.constant;
|
||||
|
||||
/**
|
||||
* 菜单类型
|
||||
* @author lanhai
|
||||
*/
|
||||
public enum MenuType {
|
||||
/**
|
||||
* 目录
|
||||
*/
|
||||
CATALOG(0),
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
MENU(1),
|
||||
/**
|
||||
* 按钮
|
||||
*/
|
||||
BUTTON(2);
|
||||
|
||||
private int value;
|
||||
|
||||
MenuType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.controller;
|
||||
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yami.shop.sys.model.TzSysConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yami.shop.common.response.ServerResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yami.shop.sys.service.SysConfigService;
|
||||
import com.yami.shop.common.annotation.SysLog;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
* @author lgh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/config")
|
||||
public class SysConfigController{
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* 所有配置列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys:config:page')")
|
||||
public ServerResponseEntity<IPage<TzSysConfig>> page(String paramKey, PageParam<TzSysConfig> page){
|
||||
IPage<TzSysConfig> sysConfigs = sysConfigService.page(page, new LambdaQueryWrapper<TzSysConfig>().like(StrUtil.isNotBlank(paramKey), TzSysConfig::getParamKey,paramKey));
|
||||
return ServerResponseEntity.success(sysConfigs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
@GetMapping("/info/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:config:info')")
|
||||
public ServerResponseEntity<TzSysConfig> info(@PathVariable("id") Long id){
|
||||
TzSysConfig config = sysConfigService.getById(id);
|
||||
return ServerResponseEntity.success(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
@SysLog("保存配置")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:config:save')")
|
||||
public ServerResponseEntity<Void> save(@RequestBody @Valid TzSysConfig config){
|
||||
sysConfigService.save(config);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
*/
|
||||
@SysLog("修改配置")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:config:update')")
|
||||
public ServerResponseEntity<Void> update(@RequestBody @Valid TzSysConfig config){
|
||||
sysConfigService.updateById(config);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除配置
|
||||
*/
|
||||
@SysLog("删除配置")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:config:delete')")
|
||||
public ServerResponseEntity<Void> delete(@RequestBody Long[] configIds){
|
||||
sysConfigService.deleteBatch(configIds);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yami.shop.sys.model.SysLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yami.shop.common.response.ServerResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yami.shop.sys.service.SysLogService;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
* @author lgh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/log")
|
||||
public class SysLogController {
|
||||
@Autowired
|
||||
private SysLogService sysLogService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys:log:page')")
|
||||
public ServerResponseEntity<IPage<SysLog>> page(SysLog sysLog,PageParam<SysLog> page){
|
||||
IPage<SysLog> sysLogs = sysLogService.page(page,
|
||||
new LambdaQueryWrapper<SysLog>()
|
||||
.like(StrUtil.isNotBlank(sysLog.getUsername()),SysLog::getUsername, sysLog.getUsername())
|
||||
.like(StrUtil.isNotBlank(sysLog.getOperation()), SysLog::getOperation,sysLog.getOperation()));
|
||||
return ServerResponseEntity.success(sysLogs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.controller;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yami.shop.common.annotation.SysLog;
|
||||
import com.yami.shop.common.exception.YamiShopBindException;
|
||||
import com.yami.shop.security.admin.util.SecurityUtils;
|
||||
import com.yami.shop.sys.constant.Constant;
|
||||
import com.yami.shop.sys.constant.MenuType;
|
||||
import com.yami.shop.sys.model.SysMenu;
|
||||
import com.yami.shop.sys.service.SysMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import com.yami.shop.common.response.ServerResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
* @author lgh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/menu")
|
||||
@AllArgsConstructor
|
||||
public class SysMenuController{
|
||||
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
|
||||
@GetMapping("/nav")
|
||||
@Operation(summary = "获取用户所拥有的菜单和权限" , description = "通过登陆用户的userId获取用户所拥有的菜单和权限")
|
||||
public ServerResponseEntity<Map<Object, Object>> nav(){
|
||||
List<SysMenu> menuList = sysMenuService.listMenuByUserId(SecurityUtils.getSysUser().getUserId());
|
||||
|
||||
return ServerResponseEntity.success(MapUtil.builder().put("menuList", menuList).put("authorities", SecurityUtils.getSysUser().getAuthorities()).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单页面的表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/table")
|
||||
public ServerResponseEntity<List<SysMenu>> table(){
|
||||
List<SysMenu> sysMenuList = sysMenuService.listMenuAndBtn();
|
||||
return ServerResponseEntity.success(sysMenuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有菜单列表(用于新建、修改角色时 获取菜单的信息)
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取用户所拥有的菜单(不包括按钮)" , description = "通过登陆用户的userId获取用户所拥有的菜单和权限")
|
||||
public ServerResponseEntity<List<SysMenu>> list(){
|
||||
List<SysMenu> sysMenuList= sysMenuService.listSimpleMenuNoButton();
|
||||
return ServerResponseEntity.success(sysMenuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择菜单
|
||||
*/
|
||||
@GetMapping("/listRootMenu")
|
||||
public ServerResponseEntity<List<SysMenu>> listRootMenu(){
|
||||
//查询列表数据
|
||||
List<SysMenu> menuList = sysMenuService.listRootMenu();
|
||||
|
||||
return ServerResponseEntity.success(menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择子菜单
|
||||
*/
|
||||
@GetMapping("/listChildrenMenu")
|
||||
public ServerResponseEntity<List<SysMenu>> listChildrenMenu(Long parentId){
|
||||
//查询列表数据
|
||||
List<SysMenu> menuList = sysMenuService.listChildrenMenuByParentId(parentId);
|
||||
|
||||
return ServerResponseEntity.success(menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单信息
|
||||
*/
|
||||
@GetMapping("/info/{menuId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:menu:info')")
|
||||
public ServerResponseEntity<SysMenu> info(@PathVariable("menuId") Long menuId){
|
||||
SysMenu menu = sysMenuService.getById(menuId);
|
||||
return ServerResponseEntity.success(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@SysLog("保存菜单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:menu:save')")
|
||||
public ServerResponseEntity<Void> save(@Valid @RequestBody SysMenu menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
sysMenuService.save(menu);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@SysLog("修改菜单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:menu:update')")
|
||||
public ServerResponseEntity<String> update(@Valid @RequestBody SysMenu menu){
|
||||
//数据校验
|
||||
verifyForm(menu);
|
||||
|
||||
if(menu.getType() == MenuType.MENU.getValue()){
|
||||
if(StrUtil.isBlank(menu.getUrl())){
|
||||
return ServerResponseEntity.showFailMsg("菜单URL不能为空");
|
||||
}
|
||||
}
|
||||
sysMenuService.updateById(menu);
|
||||
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@SysLog("删除菜单")
|
||||
@DeleteMapping("/{menuId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:menu:delete')")
|
||||
public ServerResponseEntity<String> delete(@PathVariable Long menuId){
|
||||
if(menuId <= Constant.SYS_MENU_MAX_ID){
|
||||
return ServerResponseEntity.showFailMsg("系统菜单,不能删除");
|
||||
}
|
||||
//判断是否有子菜单或按钮
|
||||
List<SysMenu> menuList = sysMenuService.listChildrenMenuByParentId(menuId);
|
||||
if(menuList.size() > 0){
|
||||
return ServerResponseEntity.showFailMsg("请先删除子菜单或按钮");
|
||||
}
|
||||
|
||||
sysMenuService.deleteMenuAndRoleMenu(menuId);
|
||||
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证参数是否正确
|
||||
*/
|
||||
private void verifyForm(SysMenu menu){
|
||||
|
||||
if(menu.getType() == MenuType.MENU.getValue()){
|
||||
if(StrUtil.isBlank(menu.getUrl())){
|
||||
throw new YamiShopBindException("菜单URL不能为空");
|
||||
}
|
||||
}
|
||||
if(Objects.equals(menu.getMenuId(), menu.getParentId())){
|
||||
throw new YamiShopBindException("自己不能是自己的上级");
|
||||
}
|
||||
|
||||
//上级菜单类型
|
||||
int parentType = MenuType.CATALOG.getValue();
|
||||
if(menu.getParentId() != 0){
|
||||
SysMenu parentMenu = sysMenuService.getById(menu.getParentId());
|
||||
parentType = parentMenu.getType();
|
||||
}
|
||||
|
||||
//目录、菜单
|
||||
if(menu.getType() == MenuType.CATALOG.getValue() ||
|
||||
menu.getType() == MenuType.MENU.getValue()){
|
||||
if(parentType != MenuType.CATALOG.getValue()){
|
||||
throw new YamiShopBindException("上级菜单只能为目录类型");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
//按钮
|
||||
if(menu.getType() == MenuType.BUTTON.getValue()){
|
||||
if(parentType != MenuType.MENU.getValue()){
|
||||
throw new YamiShopBindException("上级菜单只能为菜单类型");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yami.shop.sys.model.SysRole;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yami.shop.common.response.ServerResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yami.shop.sys.service.SysMenuService;
|
||||
import com.yami.shop.sys.service.SysRoleService;
|
||||
import com.yami.shop.common.annotation.SysLog;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 角色管理
|
||||
* @author lgh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/role")
|
||||
public class SysRoleController{
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:page')")
|
||||
public ServerResponseEntity<IPage<SysRole>> page(String roleName,PageParam<SysRole> page){
|
||||
IPage<SysRole> sysRoles = sysRoleService.page(page,new LambdaQueryWrapper<SysRole>().like(StrUtil.isNotBlank(roleName),SysRole::getRoleName,roleName));
|
||||
return ServerResponseEntity.success(sysRoles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:list')")
|
||||
public ServerResponseEntity<List<SysRole>> list(){
|
||||
List<SysRole> list = sysRoleService.list();
|
||||
return ServerResponseEntity.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
@GetMapping("/info/{roleId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:info')")
|
||||
public ServerResponseEntity<SysRole> info(@PathVariable("roleId") Long roleId){
|
||||
SysRole role = sysRoleService.getById(roleId);
|
||||
|
||||
//查询角色对应的菜单
|
||||
List<Long> menuList = sysMenuService.listMenuIdByRoleId(roleId);
|
||||
role.setMenuIdList(menuList);
|
||||
|
||||
return ServerResponseEntity.success(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
*/
|
||||
@SysLog("保存角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:save')")
|
||||
public ServerResponseEntity<Void> save(@RequestBody SysRole role){
|
||||
sysRoleService.saveRoleAndRoleMenu(role);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*/
|
||||
@SysLog("修改角色")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:update')")
|
||||
public ServerResponseEntity<Void> update(@RequestBody SysRole role){
|
||||
sysRoleService.updateRoleAndRoleMenu(role);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*/
|
||||
@SysLog("删除角色")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:role:delete')")
|
||||
public ServerResponseEntity<Void> delete(@RequestBody Long[] roleIds){
|
||||
sysRoleService.deleteBatch(roleIds);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yami.shop.common.annotation.SysLog;
|
||||
import com.yami.shop.common.exception.YamiShopBindException;
|
||||
import com.yami.shop.common.util.PageParam;
|
||||
import com.yami.shop.security.admin.util.SecurityUtils;
|
||||
import com.yami.shop.security.common.enums.SysTypeEnum;
|
||||
import com.yami.shop.security.common.manager.PasswordManager;
|
||||
import com.yami.shop.security.common.manager.TokenStore;
|
||||
import com.yami.shop.sys.constant.Constant;
|
||||
import com.yami.shop.sys.dto.UpdatePasswordDto;
|
||||
import com.yami.shop.sys.model.SysUser;
|
||||
import com.yami.shop.sys.service.SysRoleService;
|
||||
import com.yami.shop.sys.service.SysUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yami.shop.common.response.ServerResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author lgh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/user")
|
||||
public class SysUserController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
@Autowired
|
||||
private PasswordManager passwordManager;
|
||||
@Autowired
|
||||
private TokenStore tokenStore;
|
||||
|
||||
/**
|
||||
* 所有用户列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:page')")
|
||||
public ServerResponseEntity<IPage<SysUser>> page(String username,PageParam<SysUser> page){
|
||||
IPage<SysUser> sysUserPage = sysUserService.page(page, new LambdaQueryWrapper<SysUser>()
|
||||
.eq(SysUser::getShopId, SecurityUtils.getSysUser().getShopId())
|
||||
.like(StrUtil.isNotBlank(username), SysUser::getUsername, username));
|
||||
return ServerResponseEntity.success(sysUserPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录的用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public ServerResponseEntity<SysUser> info(){
|
||||
return ServerResponseEntity.success(sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改登录用户密码
|
||||
*/
|
||||
@SysLog("修改密码")
|
||||
@PostMapping("/password")
|
||||
@Operation(summary = "修改密码" , description = "修改当前登陆用户的密码")
|
||||
public ServerResponseEntity<String> password(@RequestBody @Valid UpdatePasswordDto param){
|
||||
Long userId = SecurityUtils.getSysUser().getUserId();
|
||||
|
||||
// 开源版代码,禁止用户修改admin 的账号密码
|
||||
// 正式使用时,删除此部分代码即可
|
||||
if (Objects.equals(1L,userId) && StrUtil.isNotBlank(param.getNewPassword())) {
|
||||
throw new YamiShopBindException("禁止修改admin的账号密码");
|
||||
}
|
||||
SysUser dbUser = sysUserService.getSysUserById(userId);
|
||||
String password = passwordManager.decryptPassword(param.getPassword());
|
||||
if (!passwordEncoder.matches(password, dbUser.getPassword())) {
|
||||
return ServerResponseEntity.showFailMsg("原密码不正确");
|
||||
}
|
||||
//新密码
|
||||
String newPassword = passwordEncoder.encode(passwordManager.decryptPassword(param.getNewPassword()));
|
||||
// 更新密码
|
||||
sysUserService.updatePasswordByUserId(userId, newPassword);
|
||||
tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ADMIN.value()),String.valueOf(userId));
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@GetMapping("/info/{userId}")
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:info')")
|
||||
public ServerResponseEntity<SysUser> info(@PathVariable("userId") Long userId){
|
||||
SysUser user = sysUserService.getSysUserById(userId);
|
||||
user.setUserId(null);
|
||||
if (!Objects.equals(user.getShopId(), SecurityUtils.getSysUser().getShopId())) {
|
||||
throw new YamiShopBindException("没有权限获取该用户信息");
|
||||
}
|
||||
//获取用户所属的角色列表
|
||||
List<Long> roleIdList = sysRoleService.listRoleIdByUserId(userId);
|
||||
user.setRoleIdList(roleIdList);
|
||||
return ServerResponseEntity.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
*/
|
||||
@SysLog("保存用户")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:save')")
|
||||
public ServerResponseEntity<String> save(@Valid @RequestBody SysUser user){
|
||||
String username = user.getUsername();
|
||||
SysUser dbUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
||||
.eq(SysUser::getUsername, username));
|
||||
if (dbUser!=null) {
|
||||
return ServerResponseEntity.showFailMsg("该用户已存在");
|
||||
}
|
||||
user.setShopId(SecurityUtils.getSysUser().getShopId());
|
||||
user.setPassword(passwordEncoder.encode(passwordManager.decryptPassword(user.getPassword())));
|
||||
sysUserService.saveUserAndUserRole(user);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@SysLog("修改用户")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:update')")
|
||||
public ServerResponseEntity<String> update(@Valid @RequestBody SysUser user){
|
||||
String password = passwordManager.decryptPassword(user.getPassword());
|
||||
SysUser dbUser = sysUserService.getSysUserById(user.getUserId());
|
||||
|
||||
if (!Objects.equals(dbUser.getShopId(), SecurityUtils.getSysUser().getShopId())) {
|
||||
throw new YamiShopBindException("没有权限修改该用户信息");
|
||||
}
|
||||
SysUser dbUserNameInfo = sysUserService.getByUserName(user.getUsername());
|
||||
|
||||
if (dbUserNameInfo != null && !Objects.equals(dbUserNameInfo.getUserId(),user.getUserId())) {
|
||||
return ServerResponseEntity.showFailMsg("该用户已存在");
|
||||
}
|
||||
if (StrUtil.isBlank(password)) {
|
||||
user.setPassword(null);
|
||||
}else {
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
}
|
||||
// 开源版代码,禁止用户修改admin 的账号密码密码
|
||||
// 正式使用时,删除此部分代码即可
|
||||
boolean is = Objects.equals(1L,dbUser.getUserId()) && (StrUtil.isNotBlank(password) || !StrUtil.equals("admin",user.getUsername()));
|
||||
if (is) {
|
||||
throw new YamiShopBindException("禁止修改admin的账号密码");
|
||||
}
|
||||
|
||||
if (Objects.equals(1L,user.getUserId()) && user.getStatus()==0) {
|
||||
throw new YamiShopBindException("admin用户不可以被禁用");
|
||||
}
|
||||
sysUserService.updateUserAndUserRole(user);
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@SysLog("删除用户")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys:user:delete')")
|
||||
public ServerResponseEntity<String> delete(@RequestBody Long[] userIds){
|
||||
if (userIds.length == 0) {
|
||||
return ServerResponseEntity.showFailMsg("请选择需要删除的用户");
|
||||
}
|
||||
if(ArrayUtil.contains(userIds, Constant.SUPER_ADMIN_ID)){
|
||||
return ServerResponseEntity.showFailMsg("系统管理员不能删除");
|
||||
}
|
||||
if(ArrayUtil.contains(userIds, SecurityUtils.getSysUser().getUserId())){
|
||||
return ServerResponseEntity.showFailMsg("当前用户不能删除");
|
||||
}
|
||||
sysUserService.deleteBatch(userIds,SecurityUtils.getSysUser().getShopId());
|
||||
return ServerResponseEntity.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysLog;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
* @author lanhai
|
||||
*/
|
||||
public interface SysLogMapper extends BaseMapper<SysLog> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu>{
|
||||
|
||||
/**
|
||||
* 根据角色id获取菜单列表
|
||||
* @param roleId 角色id
|
||||
* @return 菜单id列表
|
||||
*/
|
||||
List<Long> listMenuIdByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有菜单ID
|
||||
* @param userId 用户id
|
||||
* @return 该用户所有可用的菜单
|
||||
*/
|
||||
List<SysMenu> listMenuByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取系统的所有菜单
|
||||
* @return 系统的所有菜单
|
||||
*/
|
||||
List<SysMenu> listMenu();
|
||||
|
||||
/**
|
||||
* 获取简单的menu tree 用于在 ele-ui tree中显示,根据orderNum排序
|
||||
* @return ztreeDto列表
|
||||
*/
|
||||
List<SysMenu> listSimpleMenuNoButton();
|
||||
|
||||
/**
|
||||
* 获取一级菜单
|
||||
* @return 一级菜单列表
|
||||
*/
|
||||
List<SysMenu> listRootMenu();
|
||||
|
||||
/**
|
||||
* 根据一级菜单id 获取二级菜单
|
||||
* @param parentId 一级菜单id
|
||||
* @return 二级菜单列表
|
||||
*/
|
||||
List<SysMenu> listChildrenMenuByParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 获取菜单和按钮列表
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> listMenuAndBtn();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lanhai
|
||||
* 角色管理
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole>{
|
||||
/**
|
||||
* 批量删除
|
||||
* @param roleIds
|
||||
*/
|
||||
void deleteBatch(@Param("roleIds") Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 根据用户id获取角色id列表
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Long> listRoleIdByUserId(Long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysRoleMenu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lanhai
|
||||
* 角色与菜单对应关系
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
int deleteBatch(Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 根据菜单id 删除菜单关联角色信息
|
||||
* @param menuId
|
||||
*/
|
||||
void deleteByMenuId(Long menuId);
|
||||
|
||||
/**
|
||||
* 根据角色id 批量添加角色与菜单关系
|
||||
* @param roleId
|
||||
* @param menuIdList
|
||||
*/
|
||||
void insertRoleAndRoleMenu(@Param("roleId") Long roleId, @Param("menuIdList") List<Long> menuIdList);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lanhai
|
||||
* 系统用户
|
||||
*/
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
List<String> queryAllPerms(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户id 批量删除用户
|
||||
* @param userIds
|
||||
* @param shopId
|
||||
*/
|
||||
void deleteBatch(@Param("userIds") Long[] userIds, @Param("shopId") Long shopId);
|
||||
|
||||
/**
|
||||
* 根据用户名获取管理员用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
SysUser selectByUsername(@Param("username") String username);
|
||||
|
||||
SysUser selectWxUserByOpenId(String openid);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysUserRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
* @author lanhai
|
||||
*/
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
||||
|
||||
/**
|
||||
* 根据角色ID数组,批量删除
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
int deleteBatch(@Param("roleIds") Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 根据用户id删除用户与角色关系
|
||||
* @param userId
|
||||
*/
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户id 批量添加用户角色关系
|
||||
* @param userId
|
||||
* @param roleIdList
|
||||
*/
|
||||
void insertUserAndUserRole(@Param("userId") Long userId, @Param("roleIdList") List<Long> roleIdList);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yami.shop.sys.model.SysConfig;
|
||||
import com.yami.shop.sys.model.TzSysConfig;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
* @author lgh
|
||||
*/
|
||||
public interface TzSysConfigMapper extends BaseMapper<TzSysConfig> {
|
||||
|
||||
/**
|
||||
* 根据key,查询系统配置信息
|
||||
* @param key key
|
||||
* @return SysConfig
|
||||
*/
|
||||
TzSysConfig queryByKey(@Param("key") String key);
|
||||
|
||||
SysConfig queryOneByKey(@Param("key") String key);
|
||||
|
||||
/**
|
||||
* 根据key,更新value
|
||||
* @param key
|
||||
* @param value
|
||||
* @return 更新成功条数
|
||||
*/
|
||||
int updateValueByKey(@Param("key") String key, @Param("value") String value);
|
||||
|
||||
/**
|
||||
* 批量删除系统配置
|
||||
* @param ids 系统配置信息数组
|
||||
*/
|
||||
void deleteBatch(@Param("ids") Long[] ids);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
/**
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新密码参数")
|
||||
public class UpdatePasswordDto {
|
||||
|
||||
@NotBlank(message="旧密码不能为空")
|
||||
@Size(max = 50)
|
||||
@Schema(description = "旧密码" ,required=true)
|
||||
private String password;
|
||||
|
||||
@NotBlank(message="新密码不能为空")
|
||||
@Size(max = 50)
|
||||
@Schema(description = "新密码" ,required=true)
|
||||
private String newPassword;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_config")
|
||||
public class SysConfig {
|
||||
@TableId
|
||||
private Long id;
|
||||
private Long configId;
|
||||
|
||||
/** 参数名称 */
|
||||
private String configName;
|
||||
|
||||
/** 参数键名 */
|
||||
private String configKey;
|
||||
|
||||
/** 参数键值 */
|
||||
private String configValue;
|
||||
|
||||
/** 系统内置(Y是 N否) */
|
||||
private String configType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_log")
|
||||
public class SysLog implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 用户操作
|
||||
*/
|
||||
private String operation;
|
||||
/**
|
||||
* 请求方法
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private String params;
|
||||
/**
|
||||
* 执行时长(毫秒)
|
||||
*/
|
||||
private Long time;
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createDate;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_menu")
|
||||
public class SysMenu implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@TableId
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父菜单ID,一级菜单为0
|
||||
*/
|
||||
@NotNull(message="上级菜单不能为空")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 父菜单名称
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private String parentName;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
@NotBlank(message="菜单名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 授权(多个用逗号分隔,如:user:list,user:create)
|
||||
*/
|
||||
private String perms;
|
||||
|
||||
/**
|
||||
* 类型 0:目录 1:菜单 2:按钮
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer orderNum;
|
||||
|
||||
@TableField(exist=false)
|
||||
private List<?> list;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_role")
|
||||
public class SysRole implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@NotBlank(message="角色名称不能为空")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
@TableField(exist=false)
|
||||
private List<Long> menuIdList;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 角色与菜单对应关系
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_role_menu")
|
||||
public class SysRoleMenu implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_user")
|
||||
public class SysUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message="用户名不能为空")
|
||||
@Size(min = 2,max = 20,message = "用户名长度要在2-20之间")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@NotBlank(message="邮箱不能为空")
|
||||
@Email(message="邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@Pattern(regexp="0?1[0-9]{10}",message = "请输入正确的手机号")
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 状态 0:禁用 1:正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 用户所在店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 角色ID列表
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private List<Long> roleIdList;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
private String openid;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户与角色对应关系
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_user_role")
|
||||
public class SysUserRole implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
* @author lanhai
|
||||
*/
|
||||
@Data
|
||||
@TableName("tz_sys_config")
|
||||
public class TzSysConfig {
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message="参数名不能为空")
|
||||
private String paramKey;
|
||||
|
||||
@NotBlank(message="参数值不能为空")
|
||||
private String paramValue;
|
||||
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.sys.model.TzSysConfig;
|
||||
|
||||
/**
|
||||
* 系统配置信息
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysConfigService extends IService<TzSysConfig> {
|
||||
|
||||
/**
|
||||
* 根据key,更新value
|
||||
* @param key 参数key
|
||||
* @param value 参数value
|
||||
*/
|
||||
public void updateValueByKey(String key, String value);
|
||||
|
||||
/**
|
||||
* 删除配置信息
|
||||
* @param ids 配置项id列表
|
||||
*/
|
||||
public void deleteBatch(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据key,获取配置的value值
|
||||
* @param key 参数key
|
||||
* @return value
|
||||
*/
|
||||
public String getValue(String key);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.sys.model.SysLog;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysLogService extends IService<SysLog> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.sys.model.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取用户菜单列表
|
||||
* @param userId 用户id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> listMenuByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 删除 菜单,与角色菜单之间的关系
|
||||
* @param menuId 菜单id
|
||||
*/
|
||||
void deleteMenuAndRoleMenu(Long menuId);
|
||||
|
||||
/**
|
||||
* 根据角色ID,获取菜单列表
|
||||
* @param roleId 角色id
|
||||
* @return 角色所拥有的菜单id列表
|
||||
*/
|
||||
List<Long> listMenuIdByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 获取简单的menu tree 用于在ele-ui tree中显示,根据orderNum排序
|
||||
* @return 所有的菜单
|
||||
*/
|
||||
List<SysMenu> listSimpleMenuNoButton();
|
||||
|
||||
/**
|
||||
* 获取一级菜单
|
||||
* @return 一级菜单列表
|
||||
*/
|
||||
List<SysMenu> listRootMenu();
|
||||
|
||||
/**
|
||||
* 根据一级菜单id 获取二级菜单
|
||||
* @param parentId 一级菜单id
|
||||
* @return 二级菜单列表
|
||||
*/
|
||||
List<SysMenu> listChildrenMenuByParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 获取菜单和按钮列表
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> listMenuAndBtn();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.sys.model.SysRole;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysRoleService extends IService<SysRole> {
|
||||
|
||||
/**
|
||||
* 根据id批量删除
|
||||
* @param roleIds
|
||||
*/
|
||||
void deleteBatch(Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 保存角色 与 角色菜单关系
|
||||
* @param role
|
||||
*/
|
||||
void saveRoleAndRoleMenu(SysRole role);
|
||||
|
||||
/**
|
||||
* 更新角色 与 角色菜单关系
|
||||
* @param role
|
||||
*/
|
||||
void updateRoleAndRoleMenu(SysRole role);
|
||||
|
||||
/**
|
||||
* 根据用户ID,获取角色ID列表
|
||||
* @param userId 用户id
|
||||
* @return 角色id列表
|
||||
*/
|
||||
List<Long> listRoleIdByUserId(Long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.sys.model.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author lgh
|
||||
*/
|
||||
public interface SysUserService extends IService<SysUser> {
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param userId 用户ID
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
void updatePasswordByUserId(Long userId, String newPassword);
|
||||
|
||||
/**
|
||||
* 保存用户与用户角色关系
|
||||
* @param user
|
||||
*/
|
||||
void saveUserAndUserRole(SysUser user);
|
||||
|
||||
|
||||
/**
|
||||
* 更新用户与用户角色关系
|
||||
* @param user
|
||||
*/
|
||||
void updateUserAndUserRole(SysUser user);
|
||||
|
||||
/**
|
||||
* 根据用户id 批量删除用户
|
||||
* @param userIds
|
||||
* @param shopId
|
||||
*/
|
||||
void deleteBatch(Long[] userIds,Long shopId);
|
||||
|
||||
/**
|
||||
* 根据用户名获取用户信息
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
SysUser getByUserName(String username);
|
||||
|
||||
/**
|
||||
* 根据用户id获取用户信息
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
SysUser getSysUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的所有权限
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
List<String> queryAllPerms(Long userId);
|
||||
|
||||
SysUser selectWxUserByOpenId(String openid);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.sys.dao.TzSysConfigMapper;
|
||||
import com.yami.shop.sys.model.TzSysConfig;
|
||||
import com.yami.shop.sys.service.SysConfigService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lgh
|
||||
*/
|
||||
@Service("sysConfigService")
|
||||
@AllArgsConstructor
|
||||
public class SysConfigServiceImpl extends ServiceImpl<TzSysConfigMapper, TzSysConfig> implements SysConfigService {
|
||||
|
||||
private final TzSysConfigMapper sysConfigMapper;
|
||||
|
||||
@Override
|
||||
public void updateValueByKey(String key, String value) {
|
||||
sysConfigMapper.updateValueByKey(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] ids) {
|
||||
sysConfigMapper.deleteBatch(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
TzSysConfig config = sysConfigMapper.queryByKey(key);
|
||||
return config == null ? null : config.getParamValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.sys.dao.SysLogMapper;
|
||||
import com.yami.shop.sys.model.SysLog;
|
||||
import com.yami.shop.sys.service.SysLogService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lgh
|
||||
*/
|
||||
@Service("sysLogService")
|
||||
@AllArgsConstructor
|
||||
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
|
||||
|
||||
private final SysLogMapper sysLogMapper;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.sys.constant.Constant;
|
||||
import com.yami.shop.sys.dao.SysMenuMapper;
|
||||
import com.yami.shop.sys.dao.SysRoleMenuMapper;
|
||||
import com.yami.shop.sys.model.SysMenu;
|
||||
import com.yami.shop.sys.service.SysMenuService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lgh
|
||||
*/
|
||||
@Service("sysMenuService")
|
||||
@AllArgsConstructor
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
private final SysRoleMenuMapper sysRoleMenuMapper;
|
||||
|
||||
private final SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Override
|
||||
public List<SysMenu> listMenuByUserId(Long userId) {
|
||||
// 用户的所有菜单信息
|
||||
List<SysMenu> sysMenus ;
|
||||
//系统管理员,拥有最高权限
|
||||
if(userId == Constant.SUPER_ADMIN_ID){
|
||||
sysMenus = sysMenuMapper.listMenu();
|
||||
}else {
|
||||
sysMenus = sysMenuMapper.listMenuByUserId(userId);
|
||||
}
|
||||
|
||||
Map<Long, List<SysMenu>> sysMenuLevelMap = sysMenus.stream()
|
||||
.sorted(Comparator.comparing(SysMenu::getOrderNum))
|
||||
.collect(Collectors.groupingBy(SysMenu::getParentId));
|
||||
|
||||
// 一级菜单
|
||||
List<SysMenu> rootMenu = sysMenuLevelMap.get(0L);
|
||||
if (CollectionUtil.isEmpty(rootMenu)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 二级菜单
|
||||
for (SysMenu sysMenu : rootMenu) {
|
||||
sysMenu.setList(sysMenuLevelMap.get(sysMenu.getMenuId()));
|
||||
}
|
||||
return rootMenu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMenuAndRoleMenu(Long menuId){
|
||||
//删除菜单
|
||||
this.removeById(menuId);
|
||||
//删除菜单与角色关联
|
||||
sysRoleMenuMapper.deleteByMenuId(menuId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> listMenuIdByRoleId(Long roleId) {
|
||||
return sysMenuMapper.listMenuIdByRoleId(roleId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SysMenu> listSimpleMenuNoButton() {
|
||||
return sysMenuMapper.listSimpleMenuNoButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> listRootMenu() {
|
||||
return sysMenuMapper.listRootMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> listChildrenMenuByParentId(Long parentId) {
|
||||
return sysMenuMapper.listChildrenMenuByParentId(parentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> listMenuAndBtn() {
|
||||
return sysMenuMapper.listMenuAndBtn();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.sys.dao.SysRoleMapper;
|
||||
import com.yami.shop.sys.dao.SysRoleMenuMapper;
|
||||
import com.yami.shop.sys.dao.SysUserRoleMapper;
|
||||
import com.yami.shop.sys.model.SysRole;
|
||||
import com.yami.shop.sys.service.SysRoleService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 角色
|
||||
* @author lgh
|
||||
*/
|
||||
@Service("sysRoleService")
|
||||
@AllArgsConstructor
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
||||
private final SysRoleMenuMapper sysRoleMenuMapper;
|
||||
private final SysUserRoleMapper sysUserRoleMapper;
|
||||
private final SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveRoleAndRoleMenu(SysRole role) {
|
||||
role.setCreateTime(new Date());
|
||||
this.save(role);
|
||||
if (CollectionUtil.isEmpty(role.getMenuIdList())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//保存角色与菜单关系
|
||||
sysRoleMenuMapper.insertRoleAndRoleMenu(role.getRoleId(), role.getMenuIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateRoleAndRoleMenu(SysRole role) {
|
||||
// 更新角色
|
||||
sysRoleMapper.updateById(role);
|
||||
//先删除角色与菜单关系
|
||||
sysRoleMenuMapper.deleteBatch(new Long[]{role.getRoleId()});
|
||||
if (CollectionUtil.isEmpty(role.getMenuIdList())) {
|
||||
return;
|
||||
}
|
||||
//保存角色与菜单关系
|
||||
sysRoleMenuMapper.insertRoleAndRoleMenu(role.getRoleId(), role.getMenuIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatch(Long[] roleIds) {
|
||||
//删除角色
|
||||
sysRoleMapper.deleteBatch(roleIds);
|
||||
|
||||
//删除角色与菜单关联
|
||||
sysRoleMenuMapper.deleteBatch(roleIds);
|
||||
|
||||
//删除角色与用户关联
|
||||
sysUserRoleMapper.deleteBatch(roleIds);
|
||||
}
|
||||
@Override
|
||||
public List<Long> listRoleIdByUserId(Long userId) {
|
||||
return sysRoleMapper.listRoleIdByUserId(userId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.yami.shop.sys.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.sys.dao.SysUserMapper;
|
||||
import com.yami.shop.sys.dao.SysUserRoleMapper;
|
||||
import com.yami.shop.sys.model.SysUser;
|
||||
import com.yami.shop.sys.service.SysUserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
* @author lgh
|
||||
*/
|
||||
@Service("sysUserService")
|
||||
@AllArgsConstructor
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveUserAndUserRole(SysUser user) {
|
||||
user.setCreateTime(new Date());
|
||||
sysUserMapper.insert(user);
|
||||
if(CollUtil.isEmpty(user.getRoleIdList())){
|
||||
return ;
|
||||
}
|
||||
//保存用户与角色关系
|
||||
sysUserRoleMapper.insertUserAndUserRole(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUserAndUserRole(SysUser user) {
|
||||
// 更新用户
|
||||
sysUserMapper.updateById(user);
|
||||
|
||||
//先删除用户与角色关系
|
||||
sysUserRoleMapper.deleteByUserId(user.getUserId());
|
||||
|
||||
if(CollUtil.isEmpty(user.getRoleIdList())){
|
||||
return ;
|
||||
}
|
||||
//保存用户与角色关系
|
||||
sysUserRoleMapper.insertUserAndUserRole(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePasswordByUserId(Long userId, String newPassword) {
|
||||
SysUser user = new SysUser();
|
||||
user.setPassword(newPassword);
|
||||
user.setUserId(userId);
|
||||
sysUserMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] userIds,Long shopId) {
|
||||
sysUserMapper.deleteBatch(userIds,shopId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getByUserName(String username) {
|
||||
return sysUserMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getSysUserById(Long userId) {
|
||||
return sysUserMapper.selectById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return sysUserMapper.queryAllPerms(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser selectWxUserByOpenId(String openid) {
|
||||
return sysUserMapper.selectWxUserByOpenId(openid);
|
||||
}
|
||||
}
|
||||
27
ygsx-shop-sys/src/main/resources/mapper/SysConfigMapper.xml
Normal file
27
ygsx-shop-sys/src/main/resources/mapper/SysConfigMapper.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yami.shop.sys.dao.TzSysConfigMapper">
|
||||
|
||||
<!-- 根据key,更新value -->
|
||||
<update id="updateValueByKey" parameterType="map">
|
||||
update tz_sys_config set param_value = #{value} where param_key = #{key}
|
||||
</update>
|
||||
|
||||
<!-- 根据key,查询value -->
|
||||
<select id="queryByKey" parameterType="string" resultType="com.yami.shop.sys.model.TzSysConfig">
|
||||
select * from tz_sys_config where param_key = #{key}
|
||||
</select>
|
||||
|
||||
<!-- 根据key,查询value -->
|
||||
<select id="queryOneByKey" parameterType="string" resultType="com.yami.shop.sys.model.SysConfig">
|
||||
select * from sys_config where config_key = #{key}
|
||||
</select>
|
||||
|
||||
<delete id="deleteBatch" parameterType="Long">
|
||||
delete from tz_sys_config where id in
|
||||
<foreach collection="ids" item="id" index="no" open="("
|
||||
separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
7
ygsx-shop-sys/src/main/resources/mapper/SysLogMapper.xml
Normal file
7
ygsx-shop-sys/src/main/resources/mapper/SysLogMapper.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysLogMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
36
ygsx-shop-sys/src/main/resources/mapper/SysMenuMapper.xml
Normal file
36
ygsx-shop-sys/src/main/resources/mapper/SysMenuMapper.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysMenuMapper">
|
||||
|
||||
<select id="listMenuIdByRoleId" resultType="Long">
|
||||
select menu_id from tz_sys_role_menu where role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
<!-- 查询用户的所有菜单 -->
|
||||
<select id="listMenuByUserId" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
SELECT DISTINCT m.menu_id AS menu_id,m.parent_id,m.name,url,m.type,m.icon,m.order_num FROM tz_sys_user_role ur
|
||||
LEFT JOIN tz_sys_role_menu rm ON ur.role_id = rm.role_id LEFT JOIN tz_sys_menu m ON m.`menu_id` = rm.`menu_id`
|
||||
WHERE ur.user_id = #{userId} and m.type != 2 order by order_num
|
||||
</select>
|
||||
<!-- 查询所有菜单 -->
|
||||
<select id="listMenu" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
select * from tz_sys_menu where `type` != 2 order by order_num
|
||||
</select>
|
||||
|
||||
<select id="listSimpleMenuNoButton" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
select menu_id ,parent_id ,`name` from tz_sys_menu where `type` != 2 order by order_num
|
||||
</select>
|
||||
|
||||
<select id="listRootMenu" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
select menu_id,`name` from tz_sys_menu where `type` = 0
|
||||
</select>
|
||||
|
||||
<select id="listChildrenMenuByParentId" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
select menu_id,`name` from tz_sys_menu where parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="listMenuAndBtn" resultType="com.yami.shop.sys.model.SysMenu">
|
||||
select * from tz_sys_menu order by order_num
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysRoleMenuMapper">
|
||||
<delete id="deleteBatch">
|
||||
delete from tz_sys_role_menu where role_id in
|
||||
<foreach item="roleId" collection="array" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByMenuId">
|
||||
delete from tz_sys_role_menu where menu_id = #{menuId}
|
||||
</delete>
|
||||
|
||||
<insert id="insertRoleAndRoleMenu">
|
||||
insert into tz_sys_role_menu (role_id,menu_id) values
|
||||
<foreach collection="menuIdList" item="menuId" separator=",">
|
||||
(#{roleId},#{menuId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
30
ygsx-shop-sys/src/main/resources/mapper/SysUserMapper.xml
Normal file
30
ygsx-shop-sys/src/main/resources/mapper/SysUserMapper.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysUserMapper">
|
||||
|
||||
<!-- 查询用户的所有权限 -->
|
||||
<select id="queryAllPerms" resultType="string">
|
||||
select m.perms from tz_sys_user_role ur
|
||||
LEFT JOIN tz_sys_role_menu rm on ur.role_id = rm.role_id
|
||||
LEFT JOIN tz_sys_menu m on rm.menu_id = m.menu_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteBatch">
|
||||
delete from tz_sys_user where user_id in
|
||||
<foreach collection="userIds" item="userId" index="no" open="("
|
||||
separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
and shop_id = #{shopId}
|
||||
</delete>
|
||||
|
||||
<select id="selectByUsername" resultType="com.yami.shop.sys.model.SysUser">
|
||||
select * from tz_sys_user where username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="selectWxUserByOpenId" resultType="com.yami.shop.sys.model.SysUser">
|
||||
select * from tz_sys_user where openid = #{openid}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysUserRoleMapper">
|
||||
|
||||
<delete id="deleteBatch">
|
||||
delete from tz_sys_user_role where role_id in
|
||||
<foreach item="roleId" collection="roleIds" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserId">
|
||||
delete from tz_sys_user_role where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<insert id="insertUserAndUserRole">
|
||||
insert into tz_sys_user_role (user_id,role_id) values
|
||||
<foreach collection="roleIdList" item="roleId" separator=",">
|
||||
(#{userId},#{roleId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.yami.shop.sys.dao.SysRoleMapper">
|
||||
|
||||
<delete id="deleteBatch" parameterType="Long">
|
||||
delete from tz_sys_role where role_id in
|
||||
<foreach collection="roleIds" item="roleId" index="no" open="("
|
||||
separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="listRoleIdByUserId" resultType="Long">
|
||||
select role_id from tz_sys_user_role where user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user