kimi
2020-03-19 807e2c7a2ca8283ba6d6f764c83320ad5e023349
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.highdatas.mdm.controller;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.highdatas.mdm.entity.Flows;
import com.highdatas.mdm.entity.SysMenu;
import com.highdatas.mdm.pojo.ActivitiStatus;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.IFlowsService;
import com.highdatas.mdm.service.ITUserService;
import com.sun.tools.javac.jvm.Code;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2019-12-16
 */
@RestController
@RequestMapping("/flows")
public class FlowsController {
    @Autowired
    IFlowsService flowsService;
    @Autowired
    ITUserService userService;
    @RequestMapping(value = "/{pageno}", method = RequestMethod.GET)
    public Result<Page<Flows>> getAll(@PathVariable int pageno, HttpServletRequest request) {
        String pageSize = request.getParameter("pageSize");
        if (StringUtils.isEmpty(pageSize)) {
            pageSize = "15";
        }
        EntityWrapper<Flows> flowsEntityWrapper = new EntityWrapper<>();
 
        String userId = request.getParameter("userId");
        if (!StringUtils.isEmpty(userId)) {
            flowsEntityWrapper.eq("user_id", userId);
        }
        String status = request.getParameter("status");
        if (!StringUtils.isEmpty(status)) {
            flowsEntityWrapper.eq("status", status);
        }
        Integer size = Integer.valueOf(pageSize);
        Page page = new Page(pageno, size);
        Page<Flows> menuPage = flowsService.selectPage(page, flowsEntityWrapper);
        List<Flows> records = menuPage.getRecords();
        List<Flows> recordsStr = records.stream().map(flows -> flows.setBusinessTypeStr(flows.getBusinessType().toString()).setUserName(userService.selectById(flows.getUserId()).getUserName())).collect(Collectors.toList());
        menuPage.setRecords(recordsStr);
        return Result.success(menuPage);
    }
 
    @RequestMapping(value = "close/{id}", method = RequestMethod.GET)
    public Result close(@PathVariable String id, HttpServletRequest request) {
        Flows flows = flowsService.selectById(id);
        if (flows == null) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        flows.setStatus(ActivitiStatus.close);
 
        flowsService.aduitFinish(flows);
 
        boolean update = flows.updateById();
        if (update) {
            return Result.success(flows);
        }else {
            return Result.error(CodeMsg.UPDATE_ERROR);
        }
 
    }
}