| | |
| | | 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.modular.system.model.SysCouponRecord; |
| | | import com.stylefeng.guns.modular.system.model.TUser; |
| | | import com.stylefeng.guns.modular.system.model.UserCouponRecord; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | 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.Value; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | |
| | | 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.SysCouponActivity; |
| | | import com.stylefeng.guns.modular.system.service.ISysCouponActivityService; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileWriter; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private ISysCouponRecordService couponRecordService; |
| | | |
| | | @Value("${spring.mail.template-path}") |
| | | private String templatePath; |
| | | |
| | | @Autowired |
| | | private TEmailService emailService; |
| | | |
| | | /** |
| | | * 跳转到首页 |
| | |
| | | userCouponRecord.setCouponActivityId(sysCouponActivity.getId()); |
| | | userCouponRecord.setActivityType(1); |
| | | //判断发送类型1=全部用户,2=选择用户 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | if(sysCouponActivity.getSendType()==1){ |
| | | Wrapper wrapper = new EntityWrapper<TUser>(); |
| | | if(sysCouponActivity.getCompanyType()!=1){ |
| | |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | | } |
| | | String email = user.getEmail(); |
| | | if(ToolUtil.isNotEmpty(email)){ |
| | | Date expirationTime = userCouponRecord.getExpirationTime(); |
| | | String e = com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, sdf.format(expirationTime)); |
| | | String s = com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, sdf.format(new Date())); |
| | | |
| | | sendEmail(user, sysCouponActivity.getNumber(), s, e, userCouponRecord.getFullMoney().doubleValue()); |
| | | } |
| | | |
| | | } |
| | | sysCouponActivity.setSendUserNum(list.size()); |
| | | sysCouponActivity.updateById(); |
| | | }else{ |
| | | JSONArray userId = JSON.parseArray(sysCouponActivity.getSendUserId()); |
| | | for(int j=0;j<userId.size();j++){ |
| | | // 获取邮箱 |
| | | TUser tUser = userService.selectById(userId.getJSONObject(j).getInteger("userId")); |
| | | String email = tUser.getEmail(); |
| | | if(ToolUtil.isNotEmpty(email)){ |
| | | Date expirationTime = userCouponRecord.getExpirationTime(); |
| | | String e = com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, sdf.format(expirationTime)); |
| | | String s = com.stylefeng.guns.modular.system.util.DateUtil.conversionFormat(2, sdf.format(new Date())); |
| | | |
| | | sendEmail(tUser, sysCouponActivity.getNumber(), s, e, userCouponRecord.getFullMoney().doubleValue()); |
| | | } |
| | | userCouponRecord.setUserId(userId.getJSONObject(j).getInteger("userId")); |
| | | for (int i=0;i<sysCouponActivity.getNumber();i++){ |
| | | userCouponRecord.insert(); |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | public void sendEmail(TUser userInfo1, Integer num, String startTime, String endTime, Double fullMoney){ |
| | | try { |
| | | if(ToolUtil.isNotEmpty(userInfo1.getEmail())){ |
| | | String path1 = templatePath + "user/coupon.html"; |
| | | Document document1 = Jsoup.parse(new File(path1), "UTF-8"); |
| | | 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 " + startTime + " to " + 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()); |
| | | //开始生成pdf收据和html收据 |
| | | File file = new File("/usr/local/nginx/html/files/html/"); |
| | | if(!file.exists()){ |
| | | file.mkdirs(); |
| | | } |
| | | String randomString = ToolUtil.getRandomString(10); |
| | | file = new File("/usr/local/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 ="http://182.160.16.251:81/files/html/coupon_" + randomString + ".html"; |
| | | TEmail tEmail = new TEmail(); |
| | | tEmail.setLink(link); |
| | | tEmail.setUserId(userInfo1.getId()); |
| | | tEmail.setType(1); |
| | | tEmail.setName("Coupon is in"); |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |