From b77dc6ce34633189f8ab94cc86c9d9d2e1cf6cec Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Fri, 20 Sep 2019 20:15:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8D=A1=E5=AF=86/=E5=81=9C=E8=BD=A6][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]:merge=20=E6=9B=B4=E6=94=B9=20from=20dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/WxCouponPresentController.java | 67 +++++++++++++++++-- .../WxCouponPasswordController.java | 25 ++++--- .../java/com/iformall/common/ErrorCode.java | 4 +- .../service/WxCouponPasswordService.java | 2 + .../service/WxCouponPresentService.java | 6 +- .../impl/WxCouponPasswordServiceImpl.java | 21 +++--- .../impl/WxCouponPresentServiceImpl.java | 54 ++------------- .../controller/sys/DataInitController.java | 20 +++--- 8 files changed, 112 insertions(+), 87 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java index c07cc5c23..ddfcadbd1 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java @@ -5,10 +5,15 @@ import com.iformall.annotation.SystemControllerLog; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; -import com.iformall.domain.po.BaseEntity; -import com.iformall.domain.po.MallUserInfo; -import com.iformall.domain.po.WxCouponPresent; +import com.iformall.domain.po.*; +import com.iformall.enums.EnumCouponPasswordStatus; +import com.iformall.enums.EnumCouponStatus; +import com.iformall.enums.EnumCouponValidType; +import com.iformall.exception.MallinkException; +import com.iformall.service.PushLimitService; +import com.iformall.service.WxCouponPasswordService; import com.iformall.service.WxCouponPresentService; +import com.iformall.service.WxCouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -18,6 +23,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * @author gongbiao */ @@ -30,6 +40,15 @@ public class WxCouponPresentController extends BaseController { @Autowired private WxCouponPresentService wxCouponPresentService; + @Autowired + PushLimitService pushLimitService; + + @Autowired + WxCouponService wxCouponService; + + @Autowired + WxCouponPasswordService wxCouponPasswordService; + @ApiOperation("分页列表接口") @GetMapping("/list") @ApiImplicitParams({ @@ -67,12 +86,48 @@ public class WxCouponPresentController extends BaseController { if (wxCouponPresent.getPhones().isEmpty()) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号"); } - MallUserInfo user = getUser(); - wxCouponPresent.setTenantId(user.getTenantId()); wxCouponPresent.setUserId(user.getId()); + wxCouponPresent.setTenantId(user.getTenantId()); + try { + pushLimitService.checkSendTime(user.getTenantId()); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + WxCoupon wxCoupon = wxCouponService.getById(wxCouponPresent.getCouponId()); + if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围 + if (new Date().after(wxCoupon.getValidEndDate())) { + return new ResultData(ErrorCode.COUPON_IS_EXPIRED); + } + } + if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { + return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); + } + + //获取手机号 + String phones = wxCouponPresent.getPhones(); + String[] phoneSplit = phones.split(","); + Set phoneSet = new HashSet<>(phoneSplit.length); + for (String phone : phoneSplit) { + if (!phone.isEmpty()) { + phoneSet.add(phone); + } + } + //查询有效券数量 + WxCouponPassword wxCouponPassword = new WxCouponPassword(); + wxCouponPassword.setTenantId(user.getTenantId()); + wxCouponPassword.setCouponId(wxCouponPresent.getCouponId()); + wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); + List list = wxCouponPasswordService.findList(wxCouponPassword); + if (phoneSet.size() > list.size()) { + logger.info(ErrorCode.REMAIN_IS_EMPTY.getMessage()); + return new ResultData(ErrorCode.REMAIN_IS_EMPTY); + } - return wxCouponPresentService.add(wxCouponPresent); + wxCouponPresent.setCouponName(wxCoupon.getTitle()); + wxCouponPresentService.add(wxCouponPresent, list, phoneSet); + return new ResultData(); } } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java index ce0d8aad0..c859b4c4c 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java @@ -68,28 +68,31 @@ public class WxCouponPasswordController extends BaseController { return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); } - // 2. 设置已使用 - try { - WxCouponPassword updateCouponPwd = new WxCouponPassword(); - updateCouponPwd.setId(couponPassword.getId()); - updateCouponPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); - couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); - couponPasswordService.saveOrUpdate(updateCouponPwd); - } catch (Exception e) { - logger.error(e.getMessage()); - return new ResultData(ErrorCode.DB_FAIL); - } + // 卡密领取卡券 + Integer pwdStatus = couponPassword.getStatus(); + setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.USED); + couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); // 3. 领取free coupon try { WxOrder order = orderService.saveFreeOrderForCoupon(cuUser, coupon, null, formId, couponPassword.getId()); } catch (MallinkException e) { + setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); logger.error(e.getMessage()); return new ResultData(e.getErrorCode(), e.getMessage()); } catch (Exception e) { + setCouponPasswordStatus(couponPassword, EnumCouponPasswordStatus.getEnum(pwdStatus)); logger.error(e.getMessage()); return new ResultData(500, e.getMessage()); } return new ResultData(); } + + private void setCouponPasswordStatus(WxCouponPassword couponPassword, EnumCouponPasswordStatus pwdStatus) { + WxCouponPassword updateCouponPwd = new WxCouponPassword(); + updateCouponPwd.setId(couponPassword.getId()); + updateCouponPwd.setStatus(pwdStatus.getCode()); + couponPasswordService.saveOrUpdate(updateCouponPwd); + } + } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 1e478befe..6beab9dc7 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -223,8 +223,8 @@ public enum ErrorCode{ * 卡密 */ COUPON_PASSWORD_NOT_FOUND(9501, "兑换码未找到"), - COUPON_PASSWORD_HAD_USED(9502, "兑换码已失效"), - COUPON_PASSWORD_IS_CANCELED(9503, "兑换码已失效"), + COUPON_PASSWORD_HAD_USED(9502, "兑换码已使用"), + COUPON_PASSWORD_IS_CANCELED(9503, "兑换码已作废"), /** * 微信 diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java index 6eb6d0651..aae959129 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java @@ -6,6 +6,7 @@ import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; public interface WxCouponPasswordService { @@ -67,4 +68,5 @@ public interface WxCouponPasswordService { PageInfo findCouponList(WxCouponPassword wxCouponPassword, Integer pageNum, Integer pageSize); + List findList(WxCouponPassword wxCouponPassword); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponPresentService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponPresentService.java index e54cb7dc7..8c4ca3d1d 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponPresentService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponPresentService.java @@ -2,8 +2,12 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxCouponPassword; import com.iformall.domain.po.WxCouponPresent; +import java.util.List; +import java.util.Set; + /** * @author gongbiao */ @@ -14,6 +18,6 @@ public interface WxCouponPresentService { WxCouponPresent findById(Long id); - ResultData add(WxCouponPresent wxCouponPresent); + ResultData add(WxCouponPresent wxCouponPresent, List list, Set phoneSet); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java index 9dcad6b7c..7862771ba 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java @@ -47,10 +47,13 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { @Override public WxCouponPassword getByObj(WxCouponPassword obj) { + String errMsg = "兑换码已失效"; List pwdList = wxCouponPasswordMapper.findList(obj); if (pwdList.size() <= 0) { - throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND); + logger.error(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getMessage()); + throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND.getCode(), errMsg); } + WxCouponPassword password = null; Integer errCode = EnumCouponPasswordStatus.INIT.getCode(); for( WxCouponPassword pwd: pwdList) { @@ -65,11 +68,11 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { } if (password == null) { if (errCode.equals(EnumCouponPasswordStatus.USED.getCode())) { - logger.error("卡券已使用"); - throw new MallinkException(ErrorCode.COUPON_PASSWORD_HAD_USED); + logger.error(ErrorCode.COUPON_PASSWORD_HAD_USED.getMessage()); + throw new MallinkException(ErrorCode.COUPON_PASSWORD_HAD_USED.getCode(), errMsg); } else { - logger.error("卡券已过期或已作废"); - throw new MallinkException(ErrorCode.COUPON_PASSWORD_IS_CANCELED); + logger.error(ErrorCode.COUPON_PASSWORD_IS_CANCELED.getMessage()); + throw new MallinkException(ErrorCode.COUPON_PASSWORD_IS_CANCELED.getCode(), errMsg); } } return password; @@ -149,9 +152,6 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { @Override public void exportData(HttpServletRequest request, HttpServletResponse response, WxCouponPassword couponPassword) { List pwdList = wxCouponPasswordMapper.findAvaPasswordListByCouponId(couponPassword); - if (pwdList.isEmpty()) { - throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND); - } excelService.exportExcel(pwdList, null, "兑换码", WxCouponPassword.class, "卡兑换码.xlsx", response, false); } @@ -161,6 +161,11 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponPasswordMapper.findCouponCountInfo(record)); } + @Override + public List findList(WxCouponPassword wxCouponPassword) { + return wxCouponPasswordMapper.findList(wxCouponPassword); + } + /* public static void main(String[] args) { WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java index 50ed29221..3ddd247e4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java @@ -2,26 +2,22 @@ package com.iformall.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; import com.iformall.domain.po.WxAppinfo; -import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponPassword; import com.iformall.domain.po.WxCouponPresent; import com.iformall.domain.po.msg.WxMsgRecord; import com.iformall.enums.*; -import com.iformall.exception.MallinkException; import com.iformall.mapper.WxCouponPasswordMapper; import com.iformall.mapper.WxCouponPresentMapper; import com.iformall.mq.MqBaseProducer; -import com.iformall.service.PushLimitService; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxCouponPresentService; -import com.iformall.service.WxCouponService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.*; @@ -36,12 +32,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { @Autowired WxCouponPresentMapper wxCouponPresentMapper; - @Autowired - PushLimitService pushLimitService; - - @Autowired - WxCouponService wxCouponService; - @Autowired WxCouponPasswordMapper wxCouponPasswordMapper; @@ -61,56 +51,22 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { return wxCouponPresentMapper.selectById(id); } + @Async @Override - public ResultData add(WxCouponPresent record) { + public ResultData add(WxCouponPresent record, List list, Set phoneSet) { String tenantId = record.getTenantId(); - try { - pushLimitService.checkSendTime(tenantId); - } catch (MallinkException e) { - logger.error(e.getMessage()); - return new ResultData(e.getErrorCode(), e.getMessage()); - } - WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); - if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围 - if (new Date().after(wxCoupon.getValidEndDate())) { - return new ResultData(ErrorCode.COUPON_IS_EXPIRED); - } - } - if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { - return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); - } - //获取手机号 - record.setCouponName(wxCoupon.getTitle()); - String phones = record.getPhones(); - String[] phoneSplit = phones.split(","); - Set phoneSet = new HashSet<>(phoneSplit.length); - for (String phone : phoneSplit) { - if (!phone.isEmpty()) { - phoneSet.add(phone); - } - } - //查询有效券数量 - WxCouponPassword wxCouponPassword = new WxCouponPassword(); - wxCouponPassword.setTenantId(tenantId); - wxCouponPassword.setCouponId(record.getCouponId()); - wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); - List list = wxCouponPasswordMapper.findList(wxCouponPassword); - if (phoneSet.size() > list.size()) { - return new ResultData(ErrorCode.REMAIN_IS_EMPTY); - } //添加记录 final IdWorker idWorker = IdWorker.get(); long id = idWorker.nextId(); record.setId(id); - record.setCouponName(wxCoupon.getTitle()); record.setSendAmount(phoneSet.size()); wxCouponPresentMapper.insert(record); //小程序 WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); - String title = wxCoupon.getTitle(); + String title = record.getCouponName(); String name = appInfo.getName(); - List tempList = wxCouponPasswordMapper.findList(wxCouponPassword); + List tempList = new ArrayList<>(); //循环发送 int i = 0; for (String phone : phoneSet) { diff --git a/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java b/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java index e50e30326..a7858181f 100644 --- a/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java +++ b/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java @@ -11,13 +11,9 @@ import com.iformall.enums.EnumScoreType; import com.iformall.enums.EnumUserType; import com.iformall.mapper.*; import com.iformall.service.WxCreditHistoryService; -import io.swagger.annotations.ApiImplicitParam; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.*; @@ -35,6 +31,8 @@ public class DataInitController extends BaseController { @Resource private WxMallMapper mallMapper; @Resource + private WxMsgSignatureMapper signatureMapper; + @Resource private WxMsgValidationcodeModelMapper modelMapper; @Resource private WxCreditHistoryMapper creditHistoryMapper; @@ -55,14 +53,16 @@ public class DataInitController extends BaseController { @Resource private WxMerchantBUserMapper merchantBUserMapper; + @Resource + private WxMerchantMapper wxMerchantMapper; + @PostMapping("/createMsgModel") - @ApiImplicitParam(name = "content", value = "content", dataType = "Long", paramType = "query", required = true) - public ResultData createMsgModel(String content) { + public ResultData createMsgModel(@RequestParam String content, @RequestParam Integer code) { try { MallUserInfo userInfo = getUser(); if (userInfo.isFmSuperAdmin()) { - addMsgModel(content); + addMsgModel(content, code); return new ResultData(); } } catch (Exception e) { @@ -163,9 +163,9 @@ public class DataInitController extends BaseController { } @Transactional(rollbackFor = Exception.class) - public void addMsgModel(String context) { + public void addMsgModel(String context, Integer code) { IdWorker idWorker = IdWorker.get(); - addBirthDayMsgModelToMall(EnumMsgModel.COUPON_BIRTHDAY_OPENED, idWorker, context); + addBirthDayMsgModelToMall(EnumMsgModel.getEnum(code), idWorker, context); } /**