package com.stylefeng.guns.modular.system.controller; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.common.constant.factory.PageFactory; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.model.TEmail; import com.stylefeng.guns.modular.system.model.TUser; import com.stylefeng.guns.modular.system.service.ITUserService; import com.stylefeng.guns.modular.system.service.TEmailService; import com.stylefeng.guns.modular.system.util.EmailUtil; import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.beans.factory.annotation.Autowired; import com.stylefeng.guns.core.log.LogObjectHolder; import org.springframework.web.bind.annotation.RequestParam; import com.stylefeng.guns.modular.system.model.TReportLoss; import com.stylefeng.guns.modular.system.service.ITReportLossService; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.util.Date; import java.util.Map; /** * 控制器 * * @author fengshuonan * @Date 2022-09-29 11:05:28 */ @Controller @RequestMapping("/tReportLoss") public class TReportLossController extends BaseController { private String PREFIX = "/system/tReportLoss/"; @Autowired private ITReportLossService tReportLossService; @Autowired private ITUserService userService; @Value("${spring.mail.template-path}") private String templatePath; @Autowired private TEmailService emailService; /** * 跳转到首页 */ @RequestMapping("") public String index() { return PREFIX + "tReportLoss.html"; } /** * 跳转到添加 */ @RequestMapping("/tReportLoss_add") public String tReportLossAdd() { return PREFIX + "tReportLoss_add.html"; } /** * 跳转到修改 */ @RequestMapping("/tReportLoss_update/{tReportLossId}") public String tReportLossUpdate(@PathVariable Integer tReportLossId, Model model) { TReportLoss tReportLoss = tReportLossService.selectById(tReportLossId); model.addAttribute("item",tReportLoss); LogObjectHolder.me().set(tReportLoss); return PREFIX + "tReportLoss_edit.html"; } /** * 获取列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime,String phone,Integer status) { String beginTime = null; String endTime = null; if (SinataUtil.isNotEmpty(insertTime)){ String[] timeArray = insertTime.split(" - "); beginTime = timeArray[0]; endTime = timeArray[1]; } // Page> page = new PageFactory>().defaultPage(); // if (ShiroKit.getUser().getRoleType() != 1){ // page.setRecords(null); // }else{ // page.setRecords(tReportLossService.getReportLossList(beginTime,endTime,phone,status)); // } return tReportLossService.getReportLossList(beginTime,endTime,phone,status); } /** * 新增 */ @RequestMapping(value = "/add") @ResponseBody public Object add(TReportLoss tReportLoss) { tReportLossService.insert(tReportLoss); return SUCCESS_TIP; } /** * 删除 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tReportLossId) { tReportLossService.deleteById(tReportLossId); return SUCCESS_TIP; } /** * 修改 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TReportLoss tReportLoss) { tReportLossService.updateById(tReportLoss); return SUCCESS_TIP; } /** * 详情 */ @RequestMapping(value = "/detail/{tReportLossId}") @ResponseBody public Object detail(@PathVariable("tReportLossId") Integer tReportLossId) { return tReportLossService.selectById(tReportLossId); } @RequestMapping(value = "/dispose") @ResponseBody public Object dispose(Integer id,String info) { TReportLoss tReportLoss = tReportLossService.selectById(id); tReportLoss.setDisposeInfo(info); tReportLoss.setStatus(2); tReportLoss.setHandleTime(new Date()); tReportLoss.setHandleUserId(ShiroKit.getUser().getId()); boolean b = tReportLossService.updateById(tReportLoss); if(b){ try { TUser userInfo = userService.selectById(tReportLoss.getUserId()); if(ToolUtil.isNotEmpty(userInfo.getEmail())){ Integer language = userInfo.getLanguage(); String path = templatePath + "user/reportLossResult.html"; Document document = Jsoup.parse(new File(path), "UTF-8"); if(1 == language){ document.getElementById("english").remove(); document.getElementById("french").remove(); document.getElementsByTag("title").get(0).text("物品报失处理结果"); Element chinese_user = document.getElementById("chinese_user"); chinese_user.text("您好 " + userInfo.getNickName() + ","); Element chinese_content = document.getElementById("chinese_content"); chinese_content.text(info); EmailUtil.send(userInfo.getEmail(), "物品报失处理结果", document.html()); } if(2 == language){ document.getElementById("chinese").remove(); document.getElementById("french").remove(); document.getElementsByTag("title").get(0).text("Solutions for reporting lost items"); Element english_user = document.getElementById("english_user"); english_user.text("Hello " + userInfo.getNickName() + ","); Element english_content = document.getElementById("english_content"); english_content.text(info); EmailUtil.send(userInfo.getEmail(), "Solutions for reporting lost items", document.html()); } if(3 == language){ document.getElementById("chinese").remove(); document.getElementById("english").remove(); document.getElementsByTag("title").get(0).text("Solutions pour signaler les objets perdus"); Element french_user = document.getElementById("french_user"); french_user.text("Bonjour " + userInfo.getNickName() + ","); Element french_content = document.getElementById("french_content"); french_content.text(info); EmailUtil.send(userInfo.getEmail(), "Solutions pour signaler les objets perdus", document.html()); } //开始生成pdf收据和html收据 File file = new File("/home/igotechgh/nginx/html/files/html/"); if(!file.exists()){ file.mkdirs(); } String randomString = ToolUtil.getRandomString(10); file = new File("/home/igotechgh/nginx/html/files/html/reportLossResult_" + randomString + ".html"); if(!file.exists()){ file.createNewFile(); } FileWriter fileWriter = new FileWriter(file); fileWriter.write(document.html()); fileWriter.flush(); fileWriter.close(); String link ="https://igo.i-go.group/files/html/reportLossResult_" + randomString + ".html"; TEmail tEmail = new TEmail(); tEmail.setLink(link); tEmail.setUserId(userInfo.getId()); tEmail.setType(1); tEmail.setName(language == 1 ? "物品报失处理结果" : language == 2 ? "Solutions for reporting lost items" : "Solutions pour signaler les objets perdus"); tEmail.setCreateTime(new Date()); int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date())-1; tEmail.setWeek(EmailUtil.getWeek(2,i)); boolean am = cn.hutool.core.date.DateUtil.isAM(new Date()); if(am){ tEmail.setAmOrPm("AM"); }else { tEmail.setAmOrPm("PM"); } emailService.insert(tEmail); } }catch (Exception e){ e.printStackTrace(); } return SUCCESS_TIP; } return ERROR; } }