|
@@ -0,0 +1,98 @@
|
|
|
+package com.sf.admin.controller;
|
|
|
+
|
|
|
+import com.sf.admin.dto.CommonResult;
|
|
|
+import com.sf.admin.dto.req.AdminLoginReqDto;
|
|
|
+import com.sf.admin.dto.resp.AdminInfoRespDto;
|
|
|
+import com.sf.admin.dto.resp.AdminLoginRespDto;
|
|
|
+import com.sf.admin.dto.resp.UmsMenuRespDto;
|
|
|
+import com.sf.admin.entity.UmsAdmin;
|
|
|
+import com.sf.admin.entity.UmsAdminRoleRelation;
|
|
|
+import com.sf.admin.entity.UmsDept;
|
|
|
+import com.sf.admin.entity.UmsRole;
|
|
|
+import com.sf.admin.service.*;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 后台用户表 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author baomidou
|
|
|
+ * @since 2024-08-12
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class UmsAdminController {
|
|
|
+
|
|
|
+ private final IUmsAdminService umsAdminService;
|
|
|
+ private final IUmsDeptService umsDeptService;
|
|
|
+ private final IUmsMenuService umsMenuService;
|
|
|
+ private final IUmsAdminRoleRelationService adminRoleRelationService;
|
|
|
+ private final IUmsRoleMenuRelationService roleMenuRelationService;
|
|
|
+
|
|
|
+ // http://localhost:8013/ums/admin/list
|
|
|
+// @GetMapping("/ums/admin/list")
|
|
|
+// public List<UmsAdmin> list(){
|
|
|
+// return umsAdminService.list();
|
|
|
+// }
|
|
|
+
|
|
|
+ @PostMapping("/admin/login")
|
|
|
+ public CommonResult<AdminLoginRespDto> login(@RequestBody AdminLoginReqDto loginReqDto){
|
|
|
+ String logined = umsAdminService.login(loginReqDto);
|
|
|
+ if(logined == null){
|
|
|
+ return CommonResult.failed("用户名或密码错误");
|
|
|
+ }
|
|
|
+ AdminLoginRespDto adminLoginRespDto = AdminLoginRespDto.builder()
|
|
|
+ .token(logined).tokenHead("SFCC ").build();
|
|
|
+ return CommonResult.success(adminLoginRespDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/admin/info")
|
|
|
+ public CommonResult<AdminInfoRespDto> getAdminInfo(@RequestHeader("Authorization") String token){
|
|
|
+ if(token == null){
|
|
|
+ return CommonResult.unauthorized(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户id
|
|
|
+ // token = "SFCC token_3"
|
|
|
+ String id = token.substring(11);
|
|
|
+ // 获取用户信息
|
|
|
+ UmsAdmin umsAdmin = umsAdminService.getById(Long.parseLong(id));
|
|
|
+ // 获取用户对应的部门信息
|
|
|
+ // ums_admin表中的dept_id 对应 ums_dept表中的id
|
|
|
+ UmsDept umsDept = umsDeptService.getById(umsAdmin.getDeptId());
|
|
|
+ // 获取用户对应的角色信息
|
|
|
+ List<UmsRole> roleList = adminRoleRelationService.getRolesByUserId(umsAdmin.getId());
|
|
|
+ String[] roles = new String[roleList.size()];
|
|
|
+ for (int i = 0; i < roleList.size(); i++) {
|
|
|
+ roles[i] = roleList.get(i).getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取角色所对应的菜单信息
|
|
|
+ List<Long> roleIds = new ArrayList<>();
|
|
|
+ for (UmsRole umsRole : roleList) {
|
|
|
+ roleIds.add(umsRole.getId());
|
|
|
+ }
|
|
|
+ List<Long> menuIds = roleMenuRelationService.queryMenusByRoleId(roleIds);
|
|
|
+ List<UmsMenuRespDto> menus = umsMenuService.getMenuInfoByIds(menuIds);
|
|
|
+
|
|
|
+ AdminInfoRespDto adminInfoRespDto = AdminInfoRespDto.builder()
|
|
|
+ .username(umsAdmin.getUsername())
|
|
|
+ .id(umsAdmin.getId())
|
|
|
+ .code(umsAdmin.getCode())
|
|
|
+ .exNum(umsAdmin.getExNum())
|
|
|
+ .nickName(umsAdmin.getNickName())
|
|
|
+ .headImg(umsAdmin.getHeadImg())
|
|
|
+ .deptName(umsDept.getDeptName())
|
|
|
+ .roles(roles)
|
|
|
+ .menus(menus)
|
|
|
+ .build();
|
|
|
+ return CommonResult.success(adminInfoRespDto);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|