Pu Zhibing
15 小时以前 821fc2f632f8b974a2c0fc37630e13c5fbe6086c
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/SysCouponActivityController.java
@@ -2,40 +2,36 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
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.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.ISysCouponActivityService;
import com.stylefeng.guns.modular.system.service.ISysCouponRecordService;
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.Autowired;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.service.ISysCouponActivityService;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -197,6 +193,135 @@
        }
        return SUCCESS_TIP;
    }
    public void sendEmail(TUser userInfo1, Integer num, String startTime, String endTime, Double fullMoney){
        try {
            if(ToolUtil.isNotEmpty(userInfo1.getEmail())){
                Integer language = userInfo1.getLanguage();
                String path1 = templatePath +  "user/coupon.html";
                Document document1 = Jsoup.parse(new File(path1), "UTF-8");
                if(1 == language){
                    document1.getElementById("english").remove();
                    document1.getElementById("french").remove();
                    document1.getElementsByTag("title").get(0).text("优惠券到账");
                    Element chinese_user = document1.getElementById("chinese_user");
                    chinese_user.text("您好 " + userInfo1.getNickName() + ",");
                    Element chinese_number = document1.getElementById("chinese_number");
                    chinese_number.text("您有" + num + "张优惠券到账");
                    Element chinese_date = document1.getElementById("chinese_date");
                    chinese_date.text("此活动有效期在" + startTime + "至" + endTime + ",详情请查看I-GO平台");
                    Element chinese_remark = document1.getElementById("chinese_remark");
                    chinese_remark.text("注意:满减活动,每单消费至少GHS " + fullMoney + ",才可享用。");
                    EmailUtil.send(userInfo1.getEmail(), "优惠券到账",  document1.html());
                }
                if(2 == language){
                    document1.getElementById("chinese").remove();
                    document1.getElementById("french").remove();
                    document1.getElementsByTag("title").get(0).text("Coupon is in");
                    Element english_user = document1.getElementById("english_user");
                    english_user.text("Hello " + userInfo1.getNickName() + ",");
                    Element english_number = document1.getElementById("english_number");
                    english_number.text("You have received " + num + " coupons");
                    Element english_date = document1.getElementById("english_date");
                    english_date.text("You could use them from " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, startTime) + " to " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, endTime));
                    Element english_remark = document1.getElementById("english_remark");
                    english_remark.text("NB! Coupon is valid only for the trip fare not less than GHS " + fullMoney + " per ride.");
                    EmailUtil.send(userInfo1.getEmail(), "Coupon is in",  document1.html());
                }
                if(3 == language){
                    document1.getElementById("chinese").remove();
                    document1.getElementById("english").remove();
                    document1.getElementsByTag("title").get(0).text("Le coupon est arrivé");
                    Element french_user = document1.getElementById("french_user");
                    french_user.text("Cher(ère) " + userInfo1.getNickName() + ",");
                    Element french_number = document1.getElementById("french_number");
                    french_number.text("Vous avez reçu " + num + " coupons.");
                    Element french_date = document1.getElementById("french_date");
                    french_date.text("Vous devriez les utiliser du " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(3, startTime) + " au " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(3, endTime) + ", voir le détail sur la plate-forme I-GO.");
                    Element french_remark = document1.getElementById("french_remark");
                    french_remark.text("Remarque! Le coupon n'est valable que pour le tarif d'au moins GHS " + fullMoney + " par trajet.");
                    EmailUtil.send(userInfo1.getEmail(), "Le coupon est arrivé",  document1.html());
                }
                //开始生成pdf收据和html收据
                File file = new File("/data/nginx/html/files/html/");
                if(!file.exists()){
                    file.mkdirs();
                }
                String randomString = ToolUtil.getRandomString(10);
                file = new File("/data/nginx/html/files/html/coupon_" + randomString + ".html");
                if(!file.exists()){
                    file.createNewFile();
                }
                FileWriter fileWriter = new FileWriter(file);
                fileWriter.write(document1.html());
                fileWriter.flush();
                fileWriter.close();
                String link ="https://igo.i-go.group/files/html/coupon_" + randomString + ".html";
                TEmail tEmail = new TEmail();
                tEmail.setLink(link);
                tEmail.setUserId(userInfo1.getId());
                tEmail.setType(1);
                tEmail.setName(language == 1 ? "优惠券到账" : language == 2 ? "Coupon is in" : "Le coupon est arrivé");
                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();
        }
    }
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sysCouponActivityId) {
        SysCouponActivity sysCouponActivity = new SysCouponActivity();
        sysCouponActivity.setId(sysCouponActivityId);
        sysCouponActivity.setStatus(4);
        sysCouponActivityService.updateById(sysCouponActivity);
        return SUCCESS_TIP;
    }
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SysCouponActivity sysCouponActivity,Integer activityId) {
        SysCouponRecord sysCouponRecord = couponRecordService.selectById(activityId);
        sysCouponActivity.setCouponType(sysCouponRecord.getCouponType());
        sysCouponActivity.setCouponUseType(sysCouponRecord.getCouponUseType());
        sysCouponActivity.setMoney(sysCouponRecord.getMoney());
        sysCouponActivity.setFullMoney(sysCouponRecord.getFullMoney());
        sysCouponActivity.setInsertTime(new Date());
        sysCouponActivity.setCouponId(activityId);
        sysCouponActivity.setCompanyId(ShiroKit.getUser().getObjectId());
        sysCouponActivity.setCompanyType(ShiroKit.getUser().getRoleType());
        sysCouponActivity.setStatus(sysCouponActivity.getCompanyType()==1?3:1);
        sysCouponActivityService.updateById(sysCouponActivity);
        return SUCCESS_TIP;
    }
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{sysCouponActivityId}")
    @ResponseBody
    public Object detail(@PathVariable("sysCouponActivityId") Integer sysCouponActivityId) {
        return sysCouponActivityService.selectById(sysCouponActivityId);
    }
    class timerTaskTest extends TimerTask {
        private Integer id;
@@ -267,137 +392,5 @@
            }
        }
    }
    public void sendEmail(TUser userInfo1, Integer num, String startTime, String endTime, Double fullMoney){
        try {
            if(ToolUtil.isNotEmpty(userInfo1.getEmail())){
                Integer language = userInfo1.getLanguage();
                String path1 = templatePath +  "user/coupon.html";
                Document document1 = Jsoup.parse(new File(path1), "UTF-8");
                if(1 == language){
                    document1.getElementById("english").remove();
                    document1.getElementById("french").remove();
                    document1.getElementsByTag("title").get(0).text("优惠券到账");
                    Element chinese_user = document1.getElementById("chinese_user");
                    chinese_user.text("您好 " + userInfo1.getNickName() + ",");
                    Element chinese_number = document1.getElementById("chinese_number");
                    chinese_number.text("您有" + num + "张优惠券到账");
                    Element chinese_date = document1.getElementById("chinese_date");
                    chinese_date.text("此活动有效期在" + startTime + "至" + endTime + ",详情请查看I-GO平台");
                    Element chinese_remark = document1.getElementById("chinese_remark");
                    chinese_remark.text("注意:满减活动,每单消费至少GHS " + fullMoney + ",才可享用。");
                    EmailUtil.send(userInfo1.getEmail(), "优惠券到账",  document1.html());
                }
                if(2 == language){
                    document1.getElementById("chinese").remove();
                    document1.getElementById("french").remove();
                    document1.getElementsByTag("title").get(0).text("Coupon is in");
                    Element english_user = document1.getElementById("english_user");
                    english_user.text("Hello " + userInfo1.getNickName() + ",");
                    Element english_number = document1.getElementById("english_number");
                    english_number.text("You have received " + num + " coupons");
                    Element english_date = document1.getElementById("english_date");
                    english_date.text("You could use them from " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, startTime) + " to " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, endTime));
                    Element english_remark = document1.getElementById("english_remark");
                    english_remark.text("NB! Coupon is valid only for the trip fare not less than GHS " + fullMoney + " per ride.");
                    EmailUtil.send(userInfo1.getEmail(), "Coupon is in",  document1.html());
                }
                if(3 == language){
                    document1.getElementById("chinese").remove();
                    document1.getElementById("english").remove();
                    document1.getElementsByTag("title").get(0).text("Le coupon est arrivé");
                    Element french_user = document1.getElementById("french_user");
                    french_user.text("Cher(ère) " + userInfo1.getNickName() + ",");
                    Element french_number = document1.getElementById("french_number");
                    french_number.text("Vous avez reçu " + num + " coupons.");
                    Element french_date = document1.getElementById("french_date");
                    french_date.text("Vous devriez les utiliser du " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(3, startTime) + " au " + com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(3, endTime) + ", voir le détail sur la plate-forme I-GO.");
                    Element french_remark = document1.getElementById("french_remark");
                    french_remark.text("Remarque! Le coupon n'est valable que pour le tarif d'au moins GHS " + fullMoney + " par trajet.");
                    EmailUtil.send(userInfo1.getEmail(), "Le coupon est arrivé",  document1.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/coupon_" + randomString + ".html");
                if(!file.exists()){
                    file.createNewFile();
                }
                FileWriter fileWriter = new FileWriter(file);
                fileWriter.write(document1.html());
                fileWriter.flush();
                fileWriter.close();
                String link ="https://igo.i-go.group/files/html/coupon_" + randomString + ".html";
                TEmail tEmail = new TEmail();
                tEmail.setLink(link);
                tEmail.setUserId(userInfo1.getId());
                tEmail.setType(1);
                tEmail.setName(language == 1 ? "优惠券到账" : language == 2 ? "Coupon is in" : "Le coupon est arrivé");
                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();
        }
    }
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sysCouponActivityId) {
        SysCouponActivity sysCouponActivity = new SysCouponActivity();
        sysCouponActivity.setId(sysCouponActivityId);
        sysCouponActivity.setStatus(4);
        sysCouponActivityService.updateById(sysCouponActivity);
        return SUCCESS_TIP;
    }
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SysCouponActivity sysCouponActivity,Integer activityId) {
        SysCouponRecord sysCouponRecord = couponRecordService.selectById(activityId);
        sysCouponActivity.setCouponType(sysCouponRecord.getCouponType());
        sysCouponActivity.setCouponUseType(sysCouponRecord.getCouponUseType());
        sysCouponActivity.setMoney(sysCouponRecord.getMoney());
        sysCouponActivity.setFullMoney(sysCouponRecord.getFullMoney());
        sysCouponActivity.setInsertTime(new Date());
        sysCouponActivity.setCouponId(activityId);
        sysCouponActivity.setCompanyId(ShiroKit.getUser().getObjectId());
        sysCouponActivity.setCompanyType(ShiroKit.getUser().getRoleType());
        sysCouponActivity.setStatus(sysCouponActivity.getCompanyType()==1?3:1);
        sysCouponActivityService.updateById(sysCouponActivity);
        return SUCCESS_TIP;
    }
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{sysCouponActivityId}")
    @ResponseBody
    public Object detail(@PathVariable("sysCouponActivityId") Integer sysCouponActivityId) {
        return sysCouponActivityService.selectById(sysCouponActivityId);
    }
}