@@ -0,0 +1,18 @@ | |||||
package com.ningdatech.pmapi.common.constant; | |||||
/** | |||||
* <p> | |||||
* 创建人修改人基础字段 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 17:17 2023/01/29 | |||||
*/ | |||||
public interface BaseFieldConst { | |||||
String CREATE_BY = "createBy"; | |||||
String UPDATE_BY = "updateBy"; | |||||
String CREATE_ON = "createOn"; | |||||
String UPDATE_ON = "updateOn"; | |||||
} |
@@ -0,0 +1,48 @@ | |||||
package com.ningdatech.pmapi.common.handler; | |||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | |||||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.ibatis.reflection.MetaObject; | |||||
import org.springframework.stereotype.Component; | |||||
import java.time.LocalDateTime; | |||||
import static com.ningdatech.pmapi.common.constant.BaseFieldConst.*; | |||||
/** | |||||
* <p> | |||||
* 字段自动填充处理 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 17:20 2022/11/24 | |||||
*/ | |||||
@Slf4j | |||||
@Component | |||||
public class BaseFieldFillHandler implements MetaObjectHandler { | |||||
private Long getUserId() { | |||||
if (LoginUserUtil.isLogin()) { | |||||
return LoginUserUtil.getUserId(); | |||||
} | |||||
return 0L; | |||||
} | |||||
@Override | |||||
public void insertFill(MetaObject metaObject) { | |||||
long userId = getUserId(); | |||||
LocalDateTime now = LocalDateTime.now(); | |||||
this.fillStrategy(metaObject, CREATE_BY, userId); | |||||
this.fillStrategy(metaObject, CREATE_ON, now); | |||||
this.fillStrategy(metaObject, UPDATE_BY, userId); | |||||
this.fillStrategy(metaObject, UPDATE_ON, now); | |||||
} | |||||
@Override | |||||
public void updateFill(MetaObject metaObject) { | |||||
this.fillStrategy(metaObject, UPDATE_BY, getUserId()); | |||||
this.fillStrategy(metaObject, UPDATE_ON, LocalDateTime.now()); | |||||
} | |||||
} |
@@ -16,6 +16,7 @@ import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; | |||||
import com.ningdatech.pmapi.sys.entity.vo.MenuVO; | import com.ningdatech.pmapi.sys.entity.vo.MenuVO; | ||||
import com.ningdatech.pmapi.sys.manage.MenuManage; | import com.ningdatech.pmapi.sys.manage.MenuManage; | ||||
import com.ningdatech.pmapi.sys.service.IMenuService; | import com.ningdatech.pmapi.sys.service.IMenuService; | ||||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | |||||
import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
@@ -70,8 +71,7 @@ public class MenuController { | |||||
@GetMapping("/myMenu") | @GetMapping("/myMenu") | ||||
public List<MenuRoleVO> currentUserMenu() { | public List<MenuRoleVO> currentUserMenu() { | ||||
List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | ||||
// TODO:登录用户信息 | |||||
return menuManage.buildUserMenu(list, null); | |||||
return menuManage.buildUserMenu(list, LoginUserUtil.loginUserDetail()); | |||||
} | } | ||||
@ApiOperation(value = "查询菜单", notes = "查询菜单") | @ApiOperation(value = "查询菜单", notes = "查询菜单") | ||||
@@ -85,8 +85,7 @@ public class MenuController { | |||||
@PostMapping("/save") | @PostMapping("/save") | ||||
@WebLog("保存菜单") | @WebLog("保存菜单") | ||||
public MenuVO handlerSave(@Valid @RequestBody MenuSaveDTO data) { | public MenuVO handlerSave(@Valid @RequestBody MenuSaveDTO data) { | ||||
// todo:创建人ID | |||||
menuService.save(data, 0L); | |||||
menuService.save(data, LoginUserUtil.getUserId()); | |||||
return BeanUtil.toBean(data, MenuVO.class); | return BeanUtil.toBean(data, MenuVO.class); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
package com.ningdatech.pmapi.sys.controller; | package com.ningdatech.pmapi.sys.controller; | ||||
import cn.hutool.core.bean.BeanUtil; | import cn.hutool.core.bean.BeanUtil; | ||||
import com.ningdatech.basic.auth.AbstractLoginUserUtil; | |||||
import cn.hutool.core.lang.Assert; | |||||
import com.ningdatech.basic.model.PageVo; | import com.ningdatech.basic.model.PageVo; | ||||
import com.ningdatech.log.annotation.WebLog; | import com.ningdatech.log.annotation.WebLog; | ||||
import com.ningdatech.pmapi.sys.entity.Role; | import com.ningdatech.pmapi.sys.entity.Role; | ||||
@@ -11,6 +11,7 @@ import com.ningdatech.pmapi.sys.entity.dto.RoleUpdateDTO; | |||||
import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | ||||
import com.ningdatech.pmapi.sys.manage.RoleManage; | import com.ningdatech.pmapi.sys.manage.RoleManage; | ||||
import com.ningdatech.pmapi.sys.service.IRoleService; | import com.ningdatech.pmapi.sys.service.IRoleService; | ||||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | |||||
import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
@@ -20,7 +21,6 @@ import org.springframework.web.bind.annotation.*; | |||||
import javax.validation.Valid; | import javax.validation.Valid; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Objects; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
@@ -58,34 +58,32 @@ public class RoleController { | |||||
@GetMapping("/details") | @GetMapping("/details") | ||||
public RoleVO getDetails(@Valid @RequestParam Long id) { | public RoleVO getDetails(@Valid @RequestParam Long id) { | ||||
Role role = roleService.getById(id); | Role role = roleService.getById(id); | ||||
Assert.notNull(role, "角色不存在"); | |||||
RoleVO query = BeanUtil.toBean(role, RoleVO.class); | RoleVO query = BeanUtil.toBean(role, RoleVO.class); | ||||
if (Objects.isNull(query)) { | |||||
return null; | |||||
} | |||||
//菜单 | |||||
// 菜单 | |||||
roleManage.buildMenu(query); | roleManage.buildMenu(query); | ||||
return query; | return query; | ||||
} | } | ||||
@ApiOperation(value = "保存新角色", notes = "保存新角色") | @ApiOperation(value = "保存新角色", notes = "保存新角色") | ||||
@PostMapping("/save") | @PostMapping("/save") | ||||
@WebLog | |||||
@WebLog("保存新角色") | |||||
public RoleVO handlerSave(@Valid @RequestBody RoleSaveDTO data) { | public RoleVO handlerSave(@Valid @RequestBody RoleSaveDTO data) { | ||||
roleService.saveRole(data, null); | |||||
roleService.saveRole(data, LoginUserUtil.getUserId()); | |||||
return BeanUtil.toBean(data, RoleVO.class); | return BeanUtil.toBean(data, RoleVO.class); | ||||
} | } | ||||
@ApiOperation(value = "编辑角色", notes = "编辑角色") | @ApiOperation(value = "编辑角色", notes = "编辑角色") | ||||
@PostMapping("/modify") | @PostMapping("/modify") | ||||
@WebLog | |||||
@WebLog("编辑角色") | |||||
public RoleVO handlerUpdate(@Valid @RequestBody RoleUpdateDTO data) { | public RoleVO handlerUpdate(@Valid @RequestBody RoleUpdateDTO data) { | ||||
roleService.updateRole(data, AbstractLoginUserUtil.getUserId()); | |||||
roleService.updateRole(data, LoginUserUtil.getUserId()); | |||||
return BeanUtil.toBean(data, RoleVO.class); | return BeanUtil.toBean(data, RoleVO.class); | ||||
} | } | ||||
@ApiOperation(value = "删除角色", notes = "删除角色") | @ApiOperation(value = "删除角色", notes = "删除角色") | ||||
@PostMapping("/remove") | @PostMapping("/remove") | ||||
@WebLog | |||||
@WebLog("删除角色") | |||||
public Boolean handlerDelete(@Valid @RequestBody List<Long> ids) { | public Boolean handlerDelete(@Valid @RequestBody List<Long> ids) { | ||||
return roleService.removeByIdWithCache(ids); | return roleService.removeByIdWithCache(ids); | ||||
} | } | ||||
@@ -9,7 +9,7 @@ import com.ningdatech.pmapi.sys.entity.Menu; | |||||
import com.ningdatech.pmapi.sys.entity.RoleMenu; | import com.ningdatech.pmapi.sys.entity.RoleMenu; | ||||
import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; | import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; | ||||
import com.ningdatech.pmapi.sys.service.IRoleMenuService; | import com.ningdatech.pmapi.sys.service.IRoleMenuService; | ||||
import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; | |||||
import com.ningdatech.pmapi.user.model.UserInfoDetails; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
@@ -40,6 +40,8 @@ public class UserInfoDetails extends AbstractLoginUser implements UserDetails { | |||||
private String regionName; | private String regionName; | ||||
private List<Long> roleIdList; | |||||
/** | /** | ||||
* 获取用户权限 | * 获取用户权限 | ||||
*/ | */ | ||||