Blame view

src/main/java/com/huaheng/mobile/general/MobileUserController.java 6.41 KB
mahuandong authored
1
2
3
4
5
6
7
8
package com.huaheng.mobile.general;

import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
游杰 authored
9
10
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
mahuandong authored
11
12
13
14
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
游杰 authored
15
16
17
18
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.receipt.reservation.domain.Reservation;
import com.huaheng.pc.receipt.reservation.service.ReservationService;
mahuandong authored
19
20
21
22
23
24
25
26
27
28
29
30
import com.huaheng.pc.system.menu.domain.Menu;
import com.huaheng.pc.system.menu.service.IMenuService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
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;
游杰 authored
31
import org.springframework.web.bind.annotation.*;
mahuandong authored
32
33

import javax.annotation.Resource;
游杰 authored
34
35
36
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
mahuandong authored
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 * @author Enzo Cotter
 * @date 2019/12/15
 */
@RestController
@RequestMapping("/mobile/")
xqs authored
49
@Api(tags = {"移动端用户信息"}, value = "移动端用户信息MobileUserController")
mahuandong authored
50
51
52
53
54
55
56
57
public class MobileUserController extends BaseController {

    @Resource
    private IMenuService menuService;
    @Resource
    private IUserService userService;
    @Resource
    private CompanyService companyService;
游杰 authored
58
59
60
61
    @Resource
    private WarehouseService warehouseService;
    @Resource
    private ReservationService reservationService;
mahuandong authored
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

    @PostMapping("/login")
    @ApiOperation("用户登陆")
    public AjaxResult login(@RequestBody @ApiParam(value="code和password的Map集合") Map<String, String> param) {
        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();
        SecurityUtils.getSubject().getSession().setTimeout(-1000L);
        try {
            subject.login(token);
            List<Map<String, Object>> list = userService.getWarehouseByUserCode(param.get("code"));
            return AjaxResult.success(list);
        } catch (AuthenticationException e) {
            String msg = "用户或密码错误";
            if (StringUtils.isNotEmpty(e.getMessage())) {
                msg = e.getMessage();
            }
            return error(msg);
        }
    }

    @PostMapping("/getModules")
    @ApiOperation("获取当前用户模块列表")
    public AjaxResult  getModules(@RequestBody @ApiParam(value="WarehouseId和warehouseCode的Map集合") Map<String, String> param) {
        if  (param.get("warehouseCode") == null) {
            throw new JSONException("warehouseCode(仓库编码)不能为空");
        }
        User user = ShiroUtils.getUser();
        user.setWarehouseCode(param.get("warehouseCode"));
        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()));
        ShiroUtils.setUser(user);
        List<Menu> menus = menuService.selectMobileMenusByUserId(ShiroUtils.getUserId());
        return AjaxResult.success(menus);
    }

    @PostMapping("/heartbeat")
    @ApiOperation("心跳接口,用于延长cookie有效期")
    public AjaxResult heartbeat()
    {
        return AjaxResult.success("success");
    }

    @PostMapping("/getCompanyInfo")
    @ApiOperation("获取公司信息")
    public AjaxResult getCompanyInfo() {
115
        List<Company> companies = companyService.selectCompanyByCurrentUserId();
mahuandong authored
116
117
        List<CompanyInfo> companyInfos = new ArrayList<>();
        for(Company company : companies) {
mahuandong authored
118
            companyInfos.add(new CompanyInfo(company.getId(), company.getCode(), company.getName()));
mahuandong authored
119
120
121
        }
        return AjaxResult.success(companyInfos);
    }
游杰 authored
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

    @PostMapping("/getWarehouseList")
    @ApiOperation("获取公司信息")
    public AjaxResult getWarehouseList() {
        Warehouse warehouse = new Warehouse();
        List<Warehouse> warehouseList = warehouseService.selectListEntityByEqual(warehouse);
        return AjaxResult.success(warehouseList);
    }

    @PostMapping("/reservation")
    public AjaxResult reservation(String localDate, String warehouseCode) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date2 = LocalDate.parse(localDate, fmt);
        return AjaxResult.success(reservationService.reservationTime(date2, warehouseCode));
    }

    /**
     * 新增保存预约
     */
    @ApiOperation(value = "新增预约 ", notes = "新增预约 ", httpMethod = "POST")
    @Log(title = "预约 ", operating = "新增预约 ", action = BusinessType.INSERT)
    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(@RequestBody @ApiParam(value="WarehouseId和warehouseCode的Map集合") Reservation reservation) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
        reservation.setBeginTime(LocalDateTime.parse(reservation.getUserDef1()));
        reservation.setEndTime(LocalDateTime.parse(reservation.getUserDef2()));
        reservation.setUserDef1(null);
        reservation.setUserDef2(null);
        return toAjax(reservationService.save(reservation));
    }
mahuandong authored
153
}