kimi42345
2020-03-23 5bac93baf5659ce013163f884c9dce41990a860e
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
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
115
116
117
118
119
120
121
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package com.highdatas.mdm.controller;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.highdatas.mdm.entity.Flows;
import com.highdatas.mdm.entity.Maintain;
import com.highdatas.mdm.entity.MaintainDetail;
import com.highdatas.mdm.entity.TUser;
import com.highdatas.mdm.mapper.TableInfoMapper;
import com.highdatas.mdm.pojo.ActivitiStatus;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.Operate;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2019-12-16
 */
@RestController
@RequestMapping("/maintain")
public class MaintainController {
    @Autowired
    IMaintainService maintainService;
    @Autowired
    ITUserService userService;
    @Autowired
    IMaintainDetailService maintainDetailService;
    @Autowired
    TableInfoMapper tableInfoMapper;
    @Autowired
    IFlowsService  flowsService;
    @Autowired
    IMaintainFieldService maintainFieldService;
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result get(@PathVariable String id) {
        Maintain maintain = maintainService.selectById(id);
        if (maintain == null) {
            return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
        }
        return Result.success(maintain);
    }
 
    @RequestMapping(value = "{tableName}/unSubmit/{pageNo}", method = RequestMethod.GET)
    public Result unSubmit(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) throws UnsupportedEncodingException {
        String pageSize = request.getParameter("pageSize");
        String whereSegment = request.getParameter("whereSegment");
 
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        return maintainService.getUnSubmitData(tableName, pageNo, pageSize, whereSegment);
    }
 
    @RequestMapping(value = "{tableName}/unflow/{pageNo}", method = RequestMethod.GET)
    public Result unflow(@PathVariable String tableName, @PathVariable Integer pageNo, HttpServletRequest request) throws UnsupportedEncodingException {
        String pageSize = request.getParameter("pageSize");
        String whereSegment = request.getParameter("whereSegment");
 
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }else  {
            whereSegment = URLDecoder.decode(whereSegment, "UTF-8");
        }
        if (StringUtils.isEmpty(pageSize)) {
            return maintainService.getInvalidVerionData(tableName, whereSegment, pageNo, null);
        } else {
            return maintainService.getInvalidVerionData(tableName, whereSegment, pageNo, Integer.valueOf(pageSize));
        }
    }
 
    @RequestMapping(value = "/version/{tableName}", method = RequestMethod.GET)
    public Result getHistory(@PathVariable String tableName, HttpServletRequest request) {
        TUser user = (TUser) request.getSession().getAttribute("user");
        String userId = user.getUserId();
 
        Maintain maxVersion = maintainService.getMaxVersion(tableName);
        if (maxVersion == null) {
            return Result.error(new CodeMsg(100001,"无当前版本"));
        }
        Maintain nowVersion = maintainService.getNowVersion(tableName);
 
        List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no",false));
        List<Maintain> result = new ArrayList<>();
        int count = 0;
        for (Maintain maintain : maintainList) {
            String flowId = maintain.getFlowId();
            if (StringUtils.isEmpty(flowId)) {
                continue;
            }
 
            Flows flows = flowsService.selectById(maintain.getFlowId());
            if (flows.getStatus().equals(ActivitiStatus.close)) {
                continue;
            }
            if (flows.getStatus().equals(ActivitiStatus.working) || flows.getStatus().equals(ActivitiStatus.refuse)) {
                boolean nextAudit = flowsService.isNextAudit(flows, userId);
                if (nextAudit) {
                    count++;
                }
//                count++;
                continue;
            }else if(flows.getStatus().equals(ActivitiStatus.open)){
                maintain.setMaintainType(1);
            }
            if (nowVersion != null  && maintain.getId().equalsIgnoreCase(nowVersion.getId())) {
                maintain.setMaintainType(0);
            }
            result.add(maintain);
        }
        //
        int cnt = maintainFieldService.getUnFlowCount(tableName, userId);
        count += cnt;
        if (count > 0) {
            Maintain maintain = new Maintain();
            maintain.setMaintainType(-1);
            maintain.setVersion("待审核");
            maintain.setTableName(tableName);
            maintain.setRecordCount(count);
            result.add(maintain);
        }
 
        Collections.sort(result, new Comparator<Maintain>() {
            @Override
            public int compare(Maintain o1, Maintain o2) {
                return o1.getMaintainType().compareTo(o2.getMaintainType());
            }
        });
        return Result.success(result);
}
 
    @RequestMapping(value = "/detail/{id}/{pageNo}", method = RequestMethod.GET)
    public Result detail(@PathVariable String id, @PathVariable int pageNo) {
        Maintain maintain = maintainService.selectById(id);
        String tableName = maintain.getTableName();
        String tableTempName = tableName + Constant.RECORD;
 
        List<MaintainDetail> maintainDetailList = maintainDetailService.selectList(new EntityWrapper<MaintainDetail>().eq("parent_id", id));
 
        return Result.success(maintain);
    }
 
    @RequestMapping(value = "/all/{pageno}", method = RequestMethod.GET)
    public Result all(@PathVariable int pageno, HttpServletRequest request) {
        String tableName = request.getParameter("tableName");
        String s = tableInfoMapper.selectTableByName(tableName);
 
        Page<Maintain> result;
        String pageSize = request.getParameter("pageSize");
        Page<Maintain> maintainPage;
        if (StringUtils.isEmpty(pageSize)) {
            maintainPage = new Page<Maintain>(pageno, 20);
 
        } else {
            maintainPage = new Page<Maintain>(pageno, Integer.valueOf(pageSize));
        }
        if (StringUtils.isEmpty(tableName)) {
            result = maintainService.selectPage(maintainPage);
        } else {
            Wrapper<Maintain> tableNameWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName);
            tableNameWrapper.orderBy("order_no desc");
            result = maintainService.selectPage(maintainPage, tableNameWrapper);
        }
        List<Maintain> records = result.getRecords();
        List<Maintain> resultObj = new ArrayList<>();
 
        for (Maintain record : records) {
            String flowId = record.getFlowId();
            if (StringUtils.isEmpty(flowId)) {
                continue;
            }
            Flows flows = flowsService.selectById(flowId);
            if (flows == null || !flows.getStatus().equals(ActivitiStatus.open)) {
                continue;
            }
            String chargeId = record.getChargeId();
            TUser user = userService.selectOne(new EntityWrapper<TUser>().eq("user_id", chargeId));
            record.setChargeId(user.getUserName());
            resultObj.add(record);
        }
        result.setRecords(resultObj);
        return  Result.success(result);
    }
 
    @RequestMapping(value = "/compare/{maintainId1}/{maintainId2}", method = RequestMethod.GET)
    public Result compare(@PathVariable String maintainId1, @PathVariable String maintainId2) {
        HashMap<Operate, Object> compare = maintainService.compare(maintainId1, maintainId2);
        return Result.success(compare);
    }
 
    @RequestMapping(value = "/canUpload/{tableName}", method = RequestMethod.GET)
    public Result canUpload(@PathVariable String tableName) {
        Maintain nowVersion = maintainService.getNowVersion(tableName);
        if (nowVersion == null) {
            return Result.success(true);
        }else {
            return Result.success(false);
        }
    }
 
    @RequestMapping(value = "/detail/{pageNo}", method = RequestMethod.GET)
    public Result setFlowId(@RequestParam String flowId,@PathVariable Integer pageNo, HttpServletRequest request) {
        String whereSegment = request.getParameter("whereSegment");
        String pageSize = request.getParameter("pageSize");
        if (StringUtils.isEmpty(whereSegment)) {
            whereSegment = Constant.WHERE_DEFAULT;
        }
        if (StringUtils.isEmpty(pageSize)) {
            return maintainService.tempDataByVersionByFlow(flowId, whereSegment, pageNo, null);
        }
        return maintainService.tempDataByVersionByFlow(flowId, whereSegment, pageNo, Integer.valueOf(pageSize));
    }
 
 
    @RequestMapping(value = "/set/{id}", method = RequestMethod.GET)
    public Result setFlowId(@PathVariable String id, @RequestParam String flowid) {
        Maintain maintain = maintainService.selectById(id);
        if (maintain == null) {
            return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
        }
        maintain.setFlowId(flowid);
        maintain.updateById();
        return Result.success(maintain);
    }
}