linzhijie
2021-03-11 93af1c6ffb9ae0e894689ad3a37b548e57d54cff
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
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
 *
 * @author ots
 * @date 2020-03-19
 */
@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("/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));
                    }
                }
        );
//        //报告模板编码  t_report_template
//        mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser()));
        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);
        mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser()));
        return prefix + "/edit";
    }
}