| @@ -149,10 +149,14 @@ public class MallUserInfoController extends BaseController { | |||||
| PasswordHelper passwordHelper = new PasswordHelper(); | PasswordHelper passwordHelper = new PasswordHelper(); | ||||
| passwordHelper.encryptPassword(userInfo); | passwordHelper.encryptPassword(userInfo); | ||||
| } | } | ||||
| // 系统内人员不能设置超级管理员 | |||||
| userInfo.setIsAdmin(null); | |||||
| /* | |||||
| if (!currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | if (!currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | ||||
| // 只有超级管理员才能设置超级管理员 | // 只有超级管理员才能设置超级管理员 | ||||
| userInfo.setIsAdmin(null); | userInfo.setIsAdmin(null); | ||||
| } | } | ||||
| */ | |||||
| if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()) && | if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode()) && | ||||
| currentUser.getId().equals(userInfo.getId())) { | currentUser.getId().equals(userInfo.getId())) { | ||||
| @@ -21,7 +21,16 @@ spring: | |||||
| cache-names: redis_cache #缓存的名字(可以不指定) | cache-names: redis_cache #缓存的名字(可以不指定) | ||||
| redis: | redis: | ||||
| time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | ||||
| mail: | |||||
| host: smtp.exmail.qq.com | |||||
| username: wuguoqiang@iformall.com | |||||
| password: SL4ZBgG3pXWqpAk3 # 授权密码 | |||||
| properties: | |||||
| mail: | |||||
| smtp: | |||||
| auth: true | |||||
| starttls: | |||||
| enable: true | |||||
| # @{link} https://github.com/abel533 | # @{link} https://github.com/abel533 | ||||
| #Mybatis | #Mybatis | ||||
| @@ -13,6 +13,16 @@ spring: | |||||
| date-format: yyyy-MM-dd HH:mm:ss | date-format: yyyy-MM-dd HH:mm:ss | ||||
| time-zone: GMT+8 | time-zone: GMT+8 | ||||
| default-property-inclusion: non_null | default-property-inclusion: non_null | ||||
| mail: | |||||
| host: smtp.exmail.qq.com | |||||
| username: wuguoqiang@iformall.com | |||||
| password: SL4ZBgG3pXWqpAk3 # 授权密码 | |||||
| properties: | |||||
| mail: | |||||
| smtp: | |||||
| auth: true | |||||
| starttls: | |||||
| enable: true | |||||
| # @{link} https://github.com/abel533 | # @{link} https://github.com/abel533 | ||||
| #Mybatis | #Mybatis | ||||
| @@ -12,6 +12,16 @@ spring: | |||||
| date-format: yyyy-MM-dd HH:mm:ss | date-format: yyyy-MM-dd HH:mm:ss | ||||
| time-zone: GMT+8 | time-zone: GMT+8 | ||||
| default-property-inclusion: non_null | default-property-inclusion: non_null | ||||
| mail: | |||||
| host: smtp.exmail.qq.com | |||||
| username: wuguoqiang@iformall.com | |||||
| password: SL4ZBgG3pXWqpAk3 # 授权密码 | |||||
| properties: | |||||
| mail: | |||||
| smtp: | |||||
| auth: true | |||||
| starttls: | |||||
| enable: true | |||||
| # @{link} https://github.com/abel533 | # @{link} https://github.com/abel533 | ||||
| @@ -21,6 +21,16 @@ spring: | |||||
| cache-names: redis_cache #缓存的名字(可以不指定) | cache-names: redis_cache #缓存的名字(可以不指定) | ||||
| redis: | redis: | ||||
| time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | ||||
| mail: | |||||
| host: smtp.exmail.qq.com | |||||
| username: wuguoqiang@iformall.com | |||||
| password: SL4ZBgG3pXWqpAk3 # 授权密码 | |||||
| properties: | |||||
| mail: | |||||
| smtp: | |||||
| auth: true | |||||
| starttls: | |||||
| enable: true | |||||
| # @{link} https://github.com/abel533 | # @{link} https://github.com/abel533 | ||||
| @@ -0,0 +1,68 @@ | |||||
| package com.iformall.common; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.MailService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.ControllerAdvice; | |||||
| import org.springframework.web.bind.annotation.ExceptionHandler; | |||||
| import org.springframework.web.bind.annotation.ResponseBody; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.PrintWriter; | |||||
| import java.io.StringWriter; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Date; | |||||
| import java.util.Enumeration; | |||||
| @ControllerAdvice | |||||
| public class GlobalDefultExceptionHandler { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private MailService mailService; | |||||
| @ExceptionHandler(Exception.class) | |||||
| @ResponseBody | |||||
| public String defultExcepitonHandler(HttpServletRequest request, Exception e) { | |||||
| log(e, request); | |||||
| StringWriter sw = new StringWriter(); | |||||
| PrintWriter pw = new PrintWriter(sw); | |||||
| e.printStackTrace(pw); | |||||
| SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(df.format(new Date())); | |||||
| sb.append("\n"); | |||||
| sb.append(sw.toString()); | |||||
| String[] receivers = new String[] {"hupeng@iformall.com", "wuguoqiang@iformall.com", "gongbiao@iformall.com"}; | |||||
| //发送邮件 | |||||
| mailService.sendSimpleMail(receivers, "请求地址:" + request.getRequestURL() + "异常", sb.toString()); | |||||
| return "发生异常"; | |||||
| } | |||||
| private void log(Exception ex, HttpServletRequest request) { | |||||
| logger.error("************************异常开始*******************************"); | |||||
| logger.error("请求地址:" + request.getRequestURL()); | |||||
| Enumeration enumeration = request.getParameterNames(); | |||||
| logger.error("请求参数"); | |||||
| while (enumeration.hasMoreElements()) { | |||||
| String name = enumeration.nextElement().toString(); | |||||
| logger.error(name + "---" + request.getParameter(name)); | |||||
| } | |||||
| StackTraceElement[] error = ex.getStackTrace(); | |||||
| for (StackTraceElement stackTraceElement : error) { | |||||
| logger.error(stackTraceElement.toString()); | |||||
| } | |||||
| logger.error("************************异常结束*******************************"); | |||||
| } | |||||
| } | |||||
| @@ -16,6 +16,7 @@ public class WxCouponOrderBVo extends WxCouponOrder{ | |||||
| */ | */ | ||||
| private static final long serialVersionUID = 6687954932922444531L; | private static final long serialVersionUID = 6687954932922444531L; | ||||
| @Id | @Id | ||||
| @Excel(name="券码",width = 20) | |||||
| protected Long id; | protected Long id; | ||||
| @Transient | @Transient | ||||
| @@ -64,16 +65,43 @@ public class WxCouponOrderBVo extends WxCouponOrder{ | |||||
| /*该订单对应券的实际过期时间**/ | /*该订单对应券的实际过期时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value = "该订单对应券的实际过期时间 ", name = "expiredTime") | @io.swagger.annotations.ApiModelProperty(value = "该订单对应券的实际过期时间 ", name = "expiredTime") | ||||
| private Date expiredTime; | private Date expiredTime; | ||||
| /*状态:0,待使用 1,已核销 2,已过期 3,已作废 **/ | |||||
| @Excel(name="订单状态",width = 20,replace = { "可以退款_0", "已经使用_1","已经过期_2","已经退款_3"},orderNum = "5") | |||||
| @io.swagger.annotations.ApiModelProperty(value = "状态:0,待使用 1,已核销 2,已过期 3,已作废 ", name = "couponOrderStatus") | |||||
| private Integer couponOrderStatus; | |||||
| /**商户名**/ | |||||
| @Excel(name="商户名",width = 50) | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名",name="merchantName") | |||||
| private String merchantName; | |||||
| /*券名称**/ | |||||
| @Excel(name="券名称",width = 50) | |||||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||||
| private String title; | |||||
| /**c用户绑定的手机号**/ | |||||
| @Excel(name="用户手机号",width = 20) | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户绑定的手机号",name="cUserPhone") | |||||
| private String cUserPhone; | |||||
| /***/ | /***/ | ||||
| @Excel(name="交易时间",width = 20,exportFormat="yyyy-MM-dd HH:mm:ss",orderNum = "4") | |||||
| @Excel(name="交易时间",width = 20,exportFormat="yyyy-MM-dd HH:mm:ss") | |||||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "createDate") | @io.swagger.annotations.ApiModelProperty(value = "", name = "createDate") | ||||
| private Date createDate; | private Date createDate; | ||||
| @Transient | |||||
| @Excel(name="面额",width = 20) | |||||
| private String priceStr; | |||||
| @Transient | |||||
| @Excel(name="交易价格",width = 20) | |||||
| private String salePriceStr; | |||||
| /***/ | /***/ | ||||
| /*状态:0,待使用 1,已核销 2,已过期 3,已作废 **/ | |||||
| @Excel(name="订单状态",width = 20,replace = { "可以退款_0", "已经使用_1","已经过期_2","已经退款_3"}) | |||||
| @io.swagger.annotations.ApiModelProperty(value = "状态:0,待使用 1,已核销 2,已过期 3,已作废 ", name = "couponOrderStatus") | |||||
| private Integer couponOrderStatus; | |||||
| /***/ | |||||
| @Excel(name="核销/过期/退款时间",width = 20,exportFormat="yyyy-MM-dd HH:mm:ss") | |||||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "updateDate") | @io.swagger.annotations.ApiModelProperty(value = "", name = "updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| /*单券实际购买价格**/ | /*单券实际购买价格**/ | ||||
| @@ -84,9 +112,7 @@ public class WxCouponOrderBVo extends WxCouponOrder{ | |||||
| /*券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)**/ | /*券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)",name="type") | @io.swagger.annotations.ApiModelProperty(value="券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券)",name="type") | ||||
| private Integer type; | private Integer type; | ||||
| /*券名称**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||||
| private String title; | |||||
| /*售价(适用于类型2,3,4,5)**/ | /*售价(适用于类型2,3,4,5)**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="售价(适用于类型2,3,4,5)",name="salePrice") | @io.swagger.annotations.ApiModelProperty(value="售价(适用于类型2,3,4,5)",name="salePrice") | ||||
| private Integer salePrice; | private Integer salePrice; | ||||
| @@ -97,28 +123,16 @@ public class WxCouponOrderBVo extends WxCouponOrder{ | |||||
| @io.swagger.annotations.ApiModelProperty(value="面额",name="price") | @io.swagger.annotations.ApiModelProperty(value="面额",name="price") | ||||
| private Integer price; | private Integer price; | ||||
| /**商户名**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名",name="merchantName") | |||||
| private String merchantName; | |||||
| /**b端用户姓名**/ | /**b端用户姓名**/ | ||||
| @Excel(name="商户管理员(核销人)姓名",width = 50) | |||||
| @io.swagger.annotations.ApiModelProperty(value="b端用户姓名",name="bUserName") | @io.swagger.annotations.ApiModelProperty(value="b端用户姓名",name="bUserName") | ||||
| private String bUserName; | private String bUserName; | ||||
| /**b端用户手机号**/ | /**b端用户手机号**/ | ||||
| @Excel(name="商户管理员手机",width = 20) | |||||
| @io.swagger.annotations.ApiModelProperty(value="b端用户手机号",name="bUserPhone") | @io.swagger.annotations.ApiModelProperty(value="b端用户手机号",name="bUserPhone") | ||||
| private String bUserPhone; | private String bUserPhone; | ||||
| /**c用户绑定的手机号**/ | |||||
| @Excel(name="手机号",width = 20,orderNum = "1") | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户绑定的手机号",name="cUserPhone") | |||||
| private String cUserPhone; | |||||
| @Transient | |||||
| @Excel(name="交易价格",width = 20,orderNum = "3") | |||||
| private String salePriceStr; | |||||
| @Transient | |||||
| @Excel(name="面额",width = 20,orderNum = "2") | |||||
| private String priceStr; | |||||
| @Transient | @Transient | ||||
| private Date startDate; | private Date startDate; | ||||
| @@ -0,0 +1,131 @@ | |||||
| package com.iformall.service; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.core.io.FileSystemResource; | |||||
| import org.springframework.mail.SimpleMailMessage; | |||||
| import org.springframework.mail.javamail.JavaMailSender; | |||||
| import org.springframework.mail.javamail.MimeMessageHelper; | |||||
| import org.springframework.stereotype.Service; | |||||
| import javax.mail.MessagingException; | |||||
| import javax.mail.internet.MimeMessage; | |||||
| import java.io.File; | |||||
| @Service | |||||
| public class MailService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private JavaMailSender sender; | |||||
| @Value("${spring.mail.username}") | |||||
| private String from; | |||||
| /** | |||||
| * 发送纯文本的简单邮件 | |||||
| * @param to | |||||
| * @param subject | |||||
| * @param content | |||||
| */ | |||||
| public void sendSimpleMail(String[] to, String subject, String content){ | |||||
| SimpleMailMessage message = new SimpleMailMessage(); | |||||
| message.setFrom(from); | |||||
| message.setTo(to); | |||||
| message.setSubject(subject); | |||||
| message.setText(content); | |||||
| try { | |||||
| sender.send(message); | |||||
| logger.info("简单邮件已经发送。"); | |||||
| } catch (Exception e) { | |||||
| logger.error("发送简单邮件时发生异常!", e); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 发送html格式的邮件 | |||||
| * @param to | |||||
| * @param subject | |||||
| * @param content | |||||
| */ | |||||
| public void sendHtmlMail(String to, String subject, String content){ | |||||
| MimeMessage message = sender.createMimeMessage(); | |||||
| try { | |||||
| //true表示需要创建一个multipart message | |||||
| MimeMessageHelper helper = new MimeMessageHelper(message, true); | |||||
| helper.setFrom(from); | |||||
| helper.setTo(to); | |||||
| helper.setSubject(subject); | |||||
| helper.setText(content, true); | |||||
| sender.send(message); | |||||
| logger.info("html邮件已经发送。"); | |||||
| } catch (MessagingException e) { | |||||
| logger.error("发送html邮件时发生异常!", e); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 发送带附件的邮件 | |||||
| * @param to | |||||
| * @param subject | |||||
| * @param content | |||||
| * @param filePath | |||||
| */ | |||||
| public void sendAttachmentsMail(String to, String subject, String content, String filePath){ | |||||
| MimeMessage message = sender.createMimeMessage(); | |||||
| try { | |||||
| //true表示需要创建一个multipart message | |||||
| MimeMessageHelper helper = new MimeMessageHelper(message, true); | |||||
| helper.setFrom(from); | |||||
| helper.setTo(to); | |||||
| helper.setSubject(subject); | |||||
| helper.setText(content, true); | |||||
| FileSystemResource file = new FileSystemResource(new File(filePath)); | |||||
| String fileName = filePath.substring(filePath.lastIndexOf(File.separator)); | |||||
| helper.addAttachment(fileName, file); | |||||
| sender.send(message); | |||||
| logger.info("带附件的邮件已经发送。"); | |||||
| } catch (MessagingException e) { | |||||
| logger.error("发送带附件的邮件时发生异常!", e); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 发送嵌入静态资源(一般是图片)的邮件 | |||||
| * @param to | |||||
| * @param subject | |||||
| * @param content 邮件内容,需要包括一个静态资源的id,比如:<img src=\"cid:rscId01\" > | |||||
| * @param rscPath 静态资源路径和文件名 | |||||
| * @param rscId 静态资源id | |||||
| */ | |||||
| public void sendInlineResourceMail(String to, String subject, String content, String rscPath, String rscId){ | |||||
| MimeMessage message = sender.createMimeMessage(); | |||||
| try { | |||||
| //true表示需要创建一个multipart message | |||||
| MimeMessageHelper helper = new MimeMessageHelper(message, true); | |||||
| helper.setFrom(from); | |||||
| helper.setTo(to); | |||||
| helper.setSubject(subject); | |||||
| helper.setText(content, true); | |||||
| FileSystemResource res = new FileSystemResource(new File(rscPath)); | |||||
| helper.addInline(rscId, res); | |||||
| sender.send(message); | |||||
| logger.info("嵌入静态资源的邮件已经发送。"); | |||||
| } catch (MessagingException e) { | |||||
| logger.error("发送嵌入静态资源的邮件时发生异常!", e); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -299,7 +299,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| logger.error("券不存在, couponId: " + couponIdStr); | logger.error("券不存在, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | ||||
| } | } | ||||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||||
| if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { | |||||
| logger.error("券已下架, couponId: " + couponIdStr); | logger.error("券已下架, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | ||||
| } | } | ||||
| @@ -309,7 +309,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| logger.error("商户不存在, couponId: " + couponIdStr); | logger.error("商户不存在, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | ||||
| } | } | ||||
| if (wxMerchant.getStatus() == EnumMerchantStatus.NOT_VALID.getCode()) { | |||||
| if (wxMerchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { | |||||
| logger.error("商户已禁用, couponId: " + couponIdStr); | logger.error("商户已禁用, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); | throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); | ||||
| } | } | ||||
| @@ -442,12 +442,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| private WxCouponOrder createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) { | private WxCouponOrder createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) { | ||||
| Date curr = new Date(); | Date curr = new Date(); | ||||
| Date valid_date = null; | Date valid_date = null; | ||||
| if (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode()) | |||||
| if (coupon.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode())){ | |||||
| valid_date = coupon.getValidEndDate(); | valid_date = coupon.getValidEndDate(); | ||||
| } | |||||
| else { | else { | ||||
| Calendar calendar = Calendar.getInstance(); | Calendar calendar = Calendar.getInstance(); | ||||
| calendar.setTime(curr); | calendar.setTime(curr); | ||||
| if (coupon.getType() != EnumCouponType.COUPON_TINGCHE.getCode()) { | |||||
| if (!coupon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) { | |||||
| // 普通券精确到天 | // 普通券精确到天 | ||||
| calendar.set(Calendar.HOUR_OF_DAY, 0); | calendar.set(Calendar.HOUR_OF_DAY, 0); | ||||
| calendar.set(Calendar.MINUTE, 0); | calendar.set(Calendar.MINUTE, 0); | ||||
| @@ -77,6 +77,11 @@ | |||||
| <artifactId>spring-boot-starter-web-services</artifactId> | <artifactId>spring-boot-starter-web-services</artifactId> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-mail</artifactId> | |||||
| </dependency> | |||||
| <dependency> | <dependency> | ||||
| <groupId>org.mybatis.spring.boot</groupId> | <groupId>org.mybatis.spring.boot</groupId> | ||||
| <artifactId>mybatis-spring-boot-starter</artifactId> | <artifactId>mybatis-spring-boot-starter</artifactId> | ||||