linzhijie
2021-04-12 c632636e2f5b4188b430f5efc9d9f68c8dbe3d6d
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
package com.ots.project.exam.controller;
import com.ots.common.enums.UserTypeEnum;
import com.ots.common.utils.security.ShiroUtils;
import com.ots.framework.web.controller.BaseController;
import com.ots.framework.web.domain.AjaxResult;
import com.ots.framework.web.page.TableDataInfo;
import com.ots.project.exam.domain.SysUserExtend;
import com.ots.project.exam.domain.SysUserPaper;
import com.ots.project.exam.domain.TExamPaper;
import com.ots.project.exam.domain.TReportTemplate;
import com.ots.project.exam.service.ISysUserExtendService;
import com.ots.project.exam.service.ISysUserPaperService;
import com.ots.project.exam.service.ITExamPaperService;
import com.ots.project.exam.service.ITReportTemplateService;
import com.ots.project.system.user.domain.User;
import com.ots.project.system.user.service.IUserService;
import com.ots.project.tool.exam.JsonUtil;
import com.ots.project.tool.gen.service.IExamUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
@Controller
@RequestMapping("/exam/paper")
public class SysUserPaperController extends BaseController {
    private String prefix = "exam/userpaper";
    @Autowired
    private IUserService userService;
    @Autowired
    private ISysUserPaperService userPaperService;
    @Autowired
    private ITExamPaperService tExamPaperService;
    @Autowired
    private ISysUserExtendService sysUserExtendService;
    @Autowired
    private IExamUtilService examUtilService;
    @Autowired
    private ITReportTemplateService reportTemplateService;
    @Autowired
    private ITReportTemplateService itReportTemplateService;
    @GetMapping("/dis")
    public String dispaper() {
        return prefix + "/userPaper";
    }
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(User user) {
        User sysUser = ShiroUtils.getSysUser();
        
        user.setStatus("0");
        List<User> users = new ArrayList<User>();
        
        if (Objects.equals(UserTypeEnum.SYS_USER.getUserType(), sysUser.getUserType())) {
            startPage();
            user.setUserTypes(Arrays.asList(UserTypeEnum.DIS_USER.getUserType(), UserTypeEnum.ENT_USER.getUserType()));
            users = userService.selectUserList(user);
        }
        
        if (Objects.equals(UserTypeEnum.DIS_USER.getUserType(), sysUser.getUserType())) {
            user.setUserTypes(Arrays.asList(UserTypeEnum.DIS_USER.getUserType(), UserTypeEnum.ENT_USER.getUserType()));
            SysUserExtend sysUserExtend = new SysUserExtend();
            sysUserExtend.setParentUserId(sysUser.getUserId());
            List<SysUserExtend> sysUserExtends = sysUserExtendService.selectSysUserExtendList(sysUserExtend);
            List<Long> userList = sysUserExtends.stream().map(p -> p.getUserId()).collect(Collectors.toList());
            user.setUserList(userList);
            startPage();
            user.setDeptId(null);
            user.setDept(null);
            users = userService.selectUserList2(user);
        }
        return getDataTable(users);
    }
    @PostMapping("/reportTemplateText/{arr}")
    @ResponseBody
    public String reportTemplateText(@PathVariable String arr) {
        String[] split = arr.split(",");
        List<String> templateIds = Arrays.asList(split);
        List<TReportTemplate> reportTemplates = reportTemplateService.getReportTemplates(ShiroUtils.getSysUser());
        StringBuilder reportTemplateText = new StringBuilder();
        for (int i = 0; i < reportTemplates.size(); i++) {
            TReportTemplate tReportTemplate = reportTemplates.get(i);
            if (templateIds.contains(String.valueOf(tReportTemplate.getId()))) {
                reportTemplateText.append(tReportTemplate.getReportType()).append(",");
            }
        }
        return reportTemplateText.substring(0,reportTemplateText.length()-1);
    }
    @PostMapping("/listCodes")
    @ResponseBody
    public TableDataInfo listCodes(User user) {
        startPage();
        User sysUser = ShiroUtils.getSysUser();
        if (Objects.isNull(user.getUserId()) && !Objects.equals(UserTypeEnum.SYS_USER.getUserType(), sysUser.getUserType())) {
            user.setUserId(sysUser.getUserId());
        }
        SysUserPaper sysUserPaper = new SysUserPaper();
        sysUserPaper.setUserId(user.getUserId());
        List<SysUserPaper> sysUserPapers = userPaperService.selectSysUserPaperList(sysUserPaper);
        
        sysUserPapers.stream().forEach(p -> {
                    p.setProdName(examUtilService.getLangOrLocalLangString("", p.getProdName()));
                    List<TReportTemplate> tReportTemplateList = itReportTemplateService.selectTReportTemplates(p.getReportTemplateId());
                    StringBuilder stringBuilder = new StringBuilder();
                    tReportTemplateList.stream().forEach(item -> stringBuilder.append(item.getReportType() + "-" + item.getTemplateType() + "-" + item.getLangType() + ","));
                    if (stringBuilder.length() > 0) {
                        p.setReportTemplateText(stringBuilder.substring(0, stringBuilder.length() - 1));
                    }
                }
        );
 
 
        return getDataTable(sysUserPapers);
    }
    
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysUserPaper sysUserPaper) {
        List<SysUserPaper> list = JsonUtil.toJsonListObject(sysUserPaper.getProdCodes(), SysUserPaper.class);
        userPaperService.deleteSysUserPaperById(sysUserPaper.getUserId());
        list.stream().forEach(item -> {
            item.setUserId(sysUserPaper.getUserId());
            userPaperService.insertSysUserPaper(item);
        });
        return toAjax(1);
    }
    
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap) {
        List<TExamPaper> list = tExamPaperService.getUserPapers();
        
        list.stream().forEach(p ->
                p.setName(examUtilService.getLangOrLocalLangString("", p.getName()))
        );
        mmap.put("userId", userId);
        mmap.put("userProds", list);
        List<TReportTemplate> reportTemplates = reportTemplateService.getReportTemplates(ShiroUtils.getSysUser());
        List<TReportTemplate> collect = reportTemplates.stream().filter(v -> {
            String reportType = v.getReportType();
            String[] split = reportType.split("-");
            List<String> strings = Arrays.asList(split);
            TExamPaper tExamPaper = list.get(0);
            String name = tExamPaper.getName();
            if (Objects.equals("睿邻", name)) {
                name = "RuiLin";
            }
            if (strings.contains(name)) {
                return true;
            }
            return false;
        }).collect(Collectors.toList());
        mmap.put("templateList", collect);
        mmap.put("templateListAll", reportTemplates);
        return prefix + "/edit";
    }
    
    @RequestMapping("/filterTemplate/{prodName}")
    @ResponseBody
    public List<TReportTemplate> filterTemplate(@PathVariable("prodName") String prodName) {
        if (Objects.equals("睿邻", prodName)) {
            prodName = "RuiLin";
        }
        List<String> prods = Arrays.asList(prodName);
        List<TReportTemplate> reportTemplates = reportTemplateService.getReportTemplates(ShiroUtils.getSysUser());
        List<TReportTemplate> collect = reportTemplates.stream().filter(v -> {
            String reportType = v.getReportType();
            String[] split = reportType.split("-");
            List<String> strings = Arrays.asList(split);
            if (strings.contains(prods.get(0))) {
                return true;
            }
            return false;
        }).collect(Collectors.toList());
        return collect;
    }
}