|
1
2
3
4
5
6
7
|
package com.huaheng.mobile.general;
import com.alibaba.fastjson.JSONException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
8
9
|
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.service.ICompanyService;
|
|
10
11
|
import com.huaheng.pc.system.menu.domain.Menu;
import com.huaheng.pc.system.menu.service.IMenuService;
|
|
12
|
import com.huaheng.pc.system.user.domain.User;
|
|
13
|
import com.huaheng.pc.system.user.service.IUserService;
|
|
14
15
16
17
18
19
20
21
22
|
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
|
|
23
24
|
import java.util.ArrayList;
|
|
25
26
|
import java.util.List;
import java.util.Map;
|
|
27
|
import java.util.stream.Collectors;
|
|
28
29
30
31
32
33
34
35
|
@RestController
@RequestMapping("/mobile/")
@Api(tags = {"MobileUserController"}, description = "移动端用户信息")
public class MobileUserController extends BaseController {
@Autowired
private IMenuService menuService;
|
|
36
37
|
@Autowired
private IUserService userService;
|
|
38
39
|
@Autowired
private ICompanyService companyService;
|
|
40
|
|
|
41
42
|
@PostMapping("/login")
@ApiOperation("用户登陆")
|
|
43
|
public AjaxResult login(@RequestBody @ApiParam(value="code和password的Map集合") Map<String, String> param) {
|
|
44
45
46
47
48
49
|
if (param.get("code") == null)
throw new JSONException("code(用户名)不能为空");
if (param.get("password") == null)
throw new JSONException("password(密码)不能为空");
UsernamePasswordToken token = new UsernamePasswordToken(param.get("code"), param.get("password"), false);
Subject subject = SecurityUtils.getSubject();
|
|
50
|
SecurityUtils.getSubject().getSession().setTimeout(-1000l);
|
|
51
52
53
|
try
{
subject.login(token);
|
|
54
|
List<Map<String, Object>> list = userService.getWarehouseByUserCode(param.get("code"));
|
|
55
|
return AjaxResult.success(list);
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
}
catch (AuthenticationException e)
{
String msg = "用户或密码错误";
if (StringUtils.isNotEmpty(e.getMessage()))
{
msg = e.getMessage();
}
return error(msg);
}
}
@PostMapping("/getModules")
@ApiOperation("获取当前用户模块列表")
|
|
70
|
public AjaxResult getModules(@RequestBody @ApiParam(value="WarehouseId和warehouseCode的Map集合") Map<String, String> param) {
|
|
71
|
if (param.get("warehouseId") == null)
|
|
72
73
74
|
throw new JSONException("warehouseId(仓库id)不能为空");
if (param.get("warehouseCode") == null)
throw new JSONException("warehouseCode(仓库编码)不能为空");
|
|
75
76
77
78
|
User user = ShiroUtils.getUser();
user.setWarehouseId(Integer.valueOf(param.get("warehouseId")));
user.setWarehouseCode(param.get("warehouseCode"));
|
|
79
80
81
82
|
ShiroUtils.setUser(user);
List<Company> companys = companyService.selectCompanyByCurrentUserId();
user.setCompanyIdList(companys.stream().map(X -> X.getId()).collect(Collectors.toList()));
user.setCompanyCodeList(companys.stream().map(X -> X.getCode()).collect(Collectors.toList()));
|
|
83
|
ShiroUtils.setUser(user);
|
|
84
|
List<Menu> menus = menuService.selectMobileMenusByUserId(ShiroUtils.getUserId());
|
|
85
86
87
|
return AjaxResult.success(menus);
}
|
|
88
89
|
@PostMapping("/heartbeat")
@ApiOperation("心跳接口,用于延长cookie有效期")
|
|
90
|
public AjaxResult heartbeat()
|
|
91
|
{
|
|
92
|
return AjaxResult.success("success");
|
|
93
|
}
|
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
@PostMapping("/getCompanyInfo")
@ApiOperation("获取公司信息")
public AjaxResult getCompanyInfo()
{
Company condition = new Company();
condition.setDeleted(false);
List<Company> companies = companyService.selectListEntityByEqual(condition);
List<CompanyInfo> companyInfos = new ArrayList<>();
for(Company company : companies) {
companyInfos.add(new CompanyInfo(company.getId(), company.getCode()));
}
return AjaxResult.success(companyInfos);
}
|
|
108
109
110
|
}
|