|
|
@@ -1,20 +1,33 @@
|
|
|
package com.zhongzheng.controller.system;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.controller.BaseController;
|
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
+import com.zhongzheng.common.core.domain.entity.store.StoreMenu;
|
|
|
+import com.zhongzheng.common.core.domain.entity.store.StoreUser;
|
|
|
+import com.zhongzheng.common.core.domain.model.LoginBody;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.framework.web.service.StoreLoginService;
|
|
|
+import com.zhongzheng.framework.web.service.StorePermissionService;
|
|
|
+import com.zhongzheng.framework.web.service.StoreTokenService;
|
|
|
+import com.zhongzheng.modules.store.service.IStoreMenuService;
|
|
|
import com.zhongzheng.modules.store.service.IStoreUserService;
|
|
|
+import com.zhongzheng.modules.system.service.ISysTenantService;
|
|
|
+import com.zhongzheng.modules.system.vo.SysTenantVo;
|
|
|
import com.zhongzheng.modules.user.bo.UserAppAccountLoginBo;
|
|
|
import com.zhongzheng.modules.user.bo.UserAppSmsLoginBo;
|
|
|
+import com.zhongzheng.common.core.domain.model.StoreLoginUser;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 客户端用户Controller
|
|
|
@@ -25,11 +38,15 @@ import java.util.Map;
|
|
|
@Api(value = "短信控制器", tags = {"登录控制器"})
|
|
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
|
@RestController
|
|
|
-@RequestMapping("/app/store/common")
|
|
|
+@RequestMapping()
|
|
|
public class LoginController extends BaseController {
|
|
|
|
|
|
private final IStoreUserService iUserService;
|
|
|
-
|
|
|
+ private final StoreTokenService tokenService;
|
|
|
+ private final StorePermissionService permissionService;
|
|
|
+ private final ISysTenantService tenantService;
|
|
|
+ private final StoreLoginService storeLoginService;
|
|
|
+ private final IStoreMenuService storeMenuService;
|
|
|
|
|
|
@ApiOperation("短信登录")
|
|
|
@PostMapping("/sms_login")
|
|
|
@@ -44,4 +61,64 @@ public class LoginController extends BaseController {
|
|
|
Map<String,Object> map = iUserService.accountLogin(bo);
|
|
|
return AjaxResult.success(map);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录方法
|
|
|
+ *
|
|
|
+ * @param loginBody 登录信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @ApiOperation("登录")
|
|
|
+ @PostMapping("/login")
|
|
|
+ public AjaxResult login(@RequestBody LoginBody loginBody)
|
|
|
+ {
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ // 生成令牌
|
|
|
+ String token = storeLoginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
|
|
+ loginBody.getUuid());
|
|
|
+ ajax.put(Constants.TOKEN, token);
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取路由信息
|
|
|
+ *
|
|
|
+ * @return 路由信息
|
|
|
+ */
|
|
|
+ @ApiOperation("路由菜单信息")
|
|
|
+ @GetMapping("/getRouters")
|
|
|
+ public AjaxResult getRouters()
|
|
|
+ {
|
|
|
+ StoreLoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
+ // 用户信息
|
|
|
+ StoreUser user = loginUser.getUser();
|
|
|
+ List<StoreMenu> menus = storeMenuService.selectMenuTreeByUserId(user.getUserId());
|
|
|
+ return AjaxResult.success(storeMenuService.buildMenus(menus));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息
|
|
|
+ *
|
|
|
+ * @return 用户信息
|
|
|
+ */
|
|
|
+ @ApiOperation("登录用户信息")
|
|
|
+ @GetMapping("/getInfo")
|
|
|
+ public AjaxResult getInfo()
|
|
|
+ {
|
|
|
+ StoreLoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
+ StoreUser user = iUserService.getOne(new LambdaQueryWrapper<StoreUser>()
|
|
|
+ .eq(StoreUser::getUserId, loginUser.getUser().getUserId()).last("limit 1"));
|
|
|
+ // 角色集合
|
|
|
+ Set<String> roles = permissionService.getRolePermission(user);
|
|
|
+ // 权限集合
|
|
|
+ Set<String> permissions = permissionService.getMenuPermission(user);
|
|
|
+ String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ SysTenantVo sysTenantVo = tenantService.queryById(Long.parseLong(tenantId));
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("user", user);
|
|
|
+ map.put("roles", roles);
|
|
|
+ map.put("permissions", permissions);
|
|
|
+ map.put("tenant", sysTenantVo);
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
}
|