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 sysUserExtends = sysUserExtendService.selectSysUserExtendList(sysUserExtend); List 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 list = entTestPackageService.selectEntTestPackageList(entTestPackage); ExcelUtil util = new ExcelUtil(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 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" + "
Dear {FullName},\n" + "
เรียน {FullName},\n" + "
\n" + "
{Company} 邀请您完成一份测试,大概需要20-25分钟时间。您可以直接点击下面的链接开始该测试。如果不能直接访问,请复制地址到浏览器中直接打开。\n" + "
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" + "
คุณได้รับเชิญให้ทำแบบประเมินจาก {Company} กรุณาใช้ลิงค์ด้านล่างเพื่อเริ่มดำเนินการ โดยคุณสามารถคลิกที่ลิงค์ด้านล่างโดยตรง หรือจะคัดลอกแล้วนำลิงค์ไปวางบนเบราว์เซอร์ของคุณก็ได้\n" + "
链接地址是:{url}\n" + "
The link is: {url}\n" + "
ตามลิงค์นี้: {url}\n" + "
\n" + "
如有疑问,请与客服联系,邮箱是:support@tai-online.com。\n" + "
Should you have problem assessing the above link, 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" + "
{Company}\n" + "
"; 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 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)); } }