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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.ots.project.exam.controller;
 
import com.ots.common.enums.UserTypeEnum;
import com.ots.common.utils.MessageUtils;
import com.ots.common.utils.StringUtils;
import com.ots.common.utils.poi.ExcelUtil;
import com.ots.common.utils.security.ShiroUtils;
import com.ots.framework.aspectj.lang.annotation.Log;
import com.ots.framework.aspectj.lang.enums.BusinessType;
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.EntDemographyParam;
import com.ots.project.exam.domain.EntTestPackage;
import com.ots.project.exam.domain.SysUserExtend;
import com.ots.project.exam.service.IEntDemographyParamService;
import com.ots.project.exam.service.IEntTestPackageService;
import com.ots.project.exam.service.ISysUserExtendService;
import com.ots.project.exam.service.ITReportTemplateService;
import com.ots.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
import static com.ots.common.enums.UserTypeEnum.SYS_USER;
 
/**
 * 测试包管理Controller
 *
 * @author ots
 * @date 2019-11-27
 */
@Controller
@RequestMapping("/exam/test_package")
public class EntTestPackageController extends BaseController {
    private String prefix = "exam/test_package";
 
    @Autowired
    private IEntTestPackageService entTestPackageService;
 
    @Autowired
    private IEntDemographyParamService entDemographyParamService;
 
    @Autowired
    private ISysUserExtendService sysUserExtendService;
 
    @Autowired
    private ITReportTemplateService reportTemplateService;
 
    @RequiresPermissions("exam:test_package:view")
    @GetMapping()
    public String test_package() {
        return prefix + "/test_package";
    }
 
    /**
     * 查询测试包管理列表
     */
    @RequiresPermissions("exam:test_package:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EntTestPackage entTestPackage) {
        startPage();
        if (Objects.isNull(entTestPackage.getUserId())) {
            User sysUser = ShiroUtils.getSysUser();
            String userType = sysUser.getUserType();
            if (UserTypeEnum.ENT_USER.getUserType().equals(userType)) {
                entTestPackage.setUserId(sysUser.getUserId());
            }
            //分销商可以看到分销商下的企业信息
            if (UserTypeEnum.DIS_USER.getUserType().equals(userType)) {
                SysUserExtend sysUserExtend = new SysUserExtend();
                sysUserExtend.setParentUserId(sysUser.getUserId());
                List<SysUserExtend> sysUserExtends = sysUserExtendService.selectSysUserExtendList(sysUserExtend);
                List<Long> collect = sysUserExtends.stream().map(extend -> extend.getUserId()).collect(Collectors.toList());
                collect.add(sysUser.getUserId());
                entTestPackage.setUserIds(collect);
            }
        }
        return getDataTable(entTestPackageService.selectEntTestPackageList(entTestPackage));
    }
 
 
    /**
     * 查询测试包管理列表
     */
    @PostMapping("/listTopTestPackage")
    @ResponseBody
    public TableDataInfo listTopTestPackage(EntTestPackage entTestPackage) {
        startPage();
        User sysUser = ShiroUtils.getSysUser();
        if (!SYS_USER.getUserType().equals(sysUser.getUserType())) {
            entTestPackage.setUserId(sysUser.getUserId());
        }
        return getDataTable(entTestPackageService.selectEntTestPackageMainList(entTestPackage));
    }
 
    /**
     * 导出测试包管理列表
     */
    @RequiresPermissions("exam:test_package:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EntTestPackage entTestPackage) {
        List<EntTestPackage> list = entTestPackageService.selectEntTestPackageList(entTestPackage);
        ExcelUtil<EntTestPackage> util = new ExcelUtil<EntTestPackage>(EntTestPackage.class);
        return util.exportExcel(list, "test_package");
    }
 
    /**
     * 回收人次(回收密码)
     */
    @RequiresPermissions("exam:test_package:recover")
    @PostMapping("/recover/{testId}")
    @ResponseBody
    public AjaxResult recover(@PathVariable Long testId) {
        return toAjax(entTestPackageService.recover(testId));
    }
 
    /**
     * 新增测试包管理
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        //多语言选择
        EntDemographyParam entDemographyParam = new EntDemographyParam();
        entDemographyParam.setParamStatus("1");
        List<EntDemographyParam> list = entDemographyParamService.selectEntDemographyParamList(entDemographyParam);
        mmap.put("roles", list);
        //报告模板编码  t_report_template
//        mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser()));
        mmap.put("template", getTemplate());
        SysUserExtend sysUserExtend = sysUserExtendService.selectSysUserExtendById(ShiroUtils.getUserId());
        String mailContent = sysUserExtend.getMailContent();
        if (StringUtils.isBlank(mailContent)) {
            mailContent = getHrTemplate();
        }
        mmap.put("hrTemplate", mailContent);
        return prefix + "/add";
    }
 
    @NotNull
    private String getHrTemplate() {
        String template = "亲爱的{Company}人力资源部,\n" +
                "Dear HR Staff at {Company},\n" +
                "เรียนฝ่ายบุคคลของ {Company}\n" +
                "\n" +
                "附件是{FullName} 最近完成的{prodName}测评报告。\n" +
                "Attached please find the assessment report on {prodName} of {FullName}\n" +
                "กรุณาตรวจสอบเอกสารแนบ ของ {FullName} ของ {prodName}. \n" +
                "\n" +
                "如有疑问,请与客服联系,邮箱是:support@tai-online.com。\n" +
                "Should you have questions, please contact our customer service at support@tai-online.com. \n" +
                "หากมีข้อสงสัยหรือคำถามเพิ่มเติม กรุณาติดต่อฝ่ายบริการลูกค้าสัมพันธ์ ที่ support@tai-online.com\n" +
                "\n" +
                "\n" +
                "谢谢!\n" +
                "All the best,\n" +
                "ขอขอบคุณเป็นอย่างยิ่ง\n" +
                "\n" +
                "\n" +
                "TAI公司客户服务部\n" +
                "Customer Service Dept., TAI, LLC\n" +
                "ฝ่ายบริการลูกค้าสัมพันธ์บริษท TAI";
        return template;
    }
 
    @NotNull
    private String getTemplate() {
        String template = "亲爱的{FullName},\n" +
                "<br>Dear {FullName},\n" +
                "<br>เรียน {FullName},\n" +
                "<br>\n" +
                "<br>{Company} 邀请您完成一份测试,大概需要20-25分钟时间。您可以直接点击下面的链接开始该测试。如果不能直接访问,请复制地址到浏览器中直接打开。\n" +
                "<br>You've been invited to take an assessment by {Company}, which shall take about 20-25 minutes to complete. Please click the link below, or copy the link to your browser, to begin the assessment.\n" +
                "<br>คุณได้รับเชิญให้ทำแบบประเมินจาก {Company} กรุณาใช้ลิงค์ด้านล่างเพื่อเริ่มดำเนินการ โดยคุณสามารถคลิกที่ลิงค์ด้านล่างโดยตรง หรือจะคัดลอกแล้วนำลิงค์ไปวางบนเบราว์เซอร์ของคุณก็ได้\n" +
                "<br>链接地址是:<a href='{url}' target='_blank'>{url}</a>\n" +
                "<br>The link is: <a href='{url}' target='_blank'>{url}</a>\n" +
                "<br>ตามลิงค์นี้: <a href='{url}' target='_blank'>{url}</a>\n" +
                "<br>\n" +
                "<br>如有疑问,请与客服联系,邮箱是:support@tai-online.com。\n" +
                "<br>Should you have problem assessing the above link, please contact our customer service at support@tai-online.com.\n" +
                "<br>หากคุณมีปัญหาในการเข้าสู่ลิงค์ข้างต้น โปรดติดต่อฝ่ายบริการลูกค้าของเราที่ support@tai-online.com\n" +
                "<br>\n" +
                "<br>\n" +
                "<br>谢谢!\n" +
                "<br>All the best,\n" +
                "<br>ด้วยความเคารพ\n" +
                "<br>\n" +
                "<br>{Company}\n" +
                "<br>";
        return template;
    }
 
    /**
     * 根据产品包ID获取模板编码
     */
    @PostMapping("/prodTemplate")
    @ResponseBody
    public AjaxResult changeTemplate(Long prodId) {
        return AjaxResult.success(MessageUtils.message("basis.successfulOperation"), reportTemplateService.getReportTemplates(ShiroUtils.getSysUser(), prodId));
    }
 
    /**
     * 新增保存测试包管理
     */
    @RequiresPermissions("exam:test_package:add")
    @Log(title = "测试包管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EntTestPackage entTestPackage) {
        return toAjax(entTestPackageService.insertEntTestPackage(entTestPackage));
    }
 
    /**
     * 修改测试包管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        EntTestPackage entTestPackage = entTestPackageService.selectEntTestPackageById(id);
        mmap.put("entTestPackage", entTestPackage);
 
        EntDemographyParam entDemographyParam = new EntDemographyParam();
        List<EntDemographyParam> list = entDemographyParamService.selectEntDemographyParamList(entDemographyParam);
 
        String paramCodes = entTestPackage.getParamCodes();
        /**
         * 默认全部为false
         */
        if (Objects.nonNull(paramCodes)) {
            String[] split = paramCodes.split(",");
            list.forEach(p -> {
                Arrays.asList(split).forEach(t -> {
                    p.setFlag(false);
                });
            });
        }
        /**
         * 存在数据则更新为true
         */
        if (Objects.nonNull(paramCodes)) {
            String[] split = paramCodes.split(",");
            list.forEach(p -> {
                Arrays.asList(split).forEach(t -> {
                    if (Objects.equals(String.valueOf(p.getParamId()), t)) {
                        p.setFlag(true);
                    }
                });
            });
        }
        mmap.put("roles", list);
 
        //报告模板编码  t_report_template
        mmap.put("templateList", reportTemplateService.getReportTemplates(ShiroUtils.getSysUser(), entTestPackage.getProdId()));
        return prefix + "/edit";
    }
 
    /**
     * 修改保存测试包管理
     */
    @RequiresPermissions("exam:test_package:edit")
    @Log(title = "测试包管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EntTestPackage entTestPackage) {
        return toAjax(entTestPackageService.updateEntTestPackage(entTestPackage));
    }
 
    /**
     * 删除测试包管理
     */
    @RequiresPermissions("exam:test_package:remove")
    @Log(title = "测试包管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(entTestPackageService.deleteEntTestPackageByIds(ids));
    }
 
 
}