| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.Result; | import com.simple.common.Result; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.CouponInject; | import com.simple.domain.po.CouponInject; | ||||
| import com.simple.enums.EnumCouponInjectSendType; | |||||
| import com.simple.service.CouponInjectService; | import com.simple.service.CouponInjectService; | ||||
| import com.simple.service.WxCUserTagsService; | import com.simple.service.WxCUserTagsService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -51,7 +52,7 @@ public class CouponInjectController extends BaseController { | |||||
| couponInject.setTenantId(getUser().getTenantId()); | couponInject.setTenantId(getUser().getTenantId()); | ||||
| couponInject.setMUserId(getUser().getId()); | couponInject.setMUserId(getUser().getId()); | ||||
| if (couponInject.getSendType() == 0) { | |||||
| if (couponInject.getSendType() == EnumCouponInjectSendType.IMMEDIATE.getCode()) { | |||||
| couponInject.setSendTime(new Date()); | couponInject.setSendTime(new Date()); | ||||
| } | } | ||||
| //Assert.notNull(couponInject.getName(), "角色名不能为空"); | //Assert.notNull(couponInject.getName(), "角色名不能为空"); | ||||
| @@ -8,7 +8,7 @@ import com.simple.domain.po.WxCarCmdLog; | |||||
| import com.simple.domain.po.WxPark; | import com.simple.domain.po.WxPark; | ||||
| import com.simple.enums.EnumCarCmd; | import com.simple.enums.EnumCarCmd; | ||||
| import com.simple.enums.EnumCarVendor; | import com.simple.enums.EnumCarVendor; | ||||
| import com.simple.enums.EnumCouponSendType; | |||||
| import com.simple.enums.EnumCouponSendSendType; | |||||
| import com.simple.enums.EnumETCPCode; | import com.simple.enums.EnumETCPCode; | ||||
| import com.simple.service.*; | import com.simple.service.*; | ||||
| import com.simple.utils.ETCPUtil; | import com.simple.utils.ETCPUtil; | ||||
| @@ -109,7 +109,7 @@ public class WxCarCallBackController extends BaseController { | |||||
| // TODO 可能多用户关联同一张车牌 | // TODO 可能多用户关联同一张车牌 | ||||
| List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ); | List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ); | ||||
| for (WxCUserCar userCar : userCarList) { | for (WxCUserCar userCar : userCarList) { | ||||
| wxCouponSendService.sendCouponToUser(tenantId, userCar.getCUserId(), EnumCouponSendType.CAR_STOP); | |||||
| wxCouponSendService.sendCouponToUser(tenantId, userCar.getCUserId(), EnumCouponSendSendType.CAR_STOP); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,10 +1,13 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.Result; | import com.simple.common.Result; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.po.WxCouponSend; | import com.simple.domain.po.WxCouponSend; | ||||
| import com.simple.enums.EnumCouponSendType; | |||||
| import com.simple.enums.EnumCouponStatus; | |||||
| import com.simple.service.WxCouponSendService; | import com.simple.service.WxCouponSendService; | ||||
| import com.simple.service.WxCouponService; | import com.simple.service.WxCouponService; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -43,19 +46,24 @@ public class WxCouponSendController extends BaseController { | |||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData add(@RequestBody WxCouponSend wxCouponSend) { | public ResultData add(@RequestBody WxCouponSend wxCouponSend) { | ||||
| if (null == wxCouponSend) { | if (null == wxCouponSend) { | ||||
| return new ResultData(Result.ERROR, "参数不对"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | } | ||||
| wxCouponSend.setTenantId(getTenantId()); | wxCouponSend.setTenantId(getTenantId()); | ||||
| wxCouponSend.setStatus(0); | wxCouponSend.setStatus(0); | ||||
| List<WxCouponSend> wxCouponSendList = wxCouponSendService.listAsPage(wxCouponSend, 1, 1).getList(); | List<WxCouponSend> wxCouponSendList = wxCouponSendService.listAsPage(wxCouponSend, 1, 1).getList(); | ||||
| if (wxCouponSendList != null && wxCouponSendList.size() > 0) { | if (wxCouponSendList != null && wxCouponSendList.size() > 0) { | ||||
| return new ResultData(Result.ERROR, "已经添加过该券"); | |||||
| return new ResultData(ErrorCode.COUPON_SEND_IS_EXISTED); | |||||
| } | } | ||||
| WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId()); | WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId()); | ||||
| if (wxCoupon.getStatus() != 0 || wxCoupon.getSendType() != 2) { | |||||
| return new ResultData(Result.ERROR, "该券的状态有问题"); | |||||
| if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()){ | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | } | ||||
| if (wxCoupon.getSendType() != EnumCouponSendType.PASSIVE.getCode()) { | |||||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | |||||
| } | |||||
| wxCouponSend.setMerchantId(wxCoupon.getMerchantId()); | wxCouponSend.setMerchantId(wxCoupon.getMerchantId()); | ||||
| wxCouponSend.setType(wxCoupon.getType()); | wxCouponSend.setType(wxCoupon.getType()); | ||||
| wxCouponSend.setTenantId(wxCoupon.getTenantId()); | wxCouponSend.setTenantId(wxCoupon.getTenantId()); | ||||
| @@ -71,11 +71,19 @@ public enum ErrorCode{ | |||||
| /** | /** | ||||
| * 券 | * 券 | ||||
| */ | */ | ||||
| COUPON_IS_EMPTY(2020, "券不存在"), | |||||
| COUPON_IS_NOT_FREE(2021, "券不免费"), | |||||
| COUPON_IS_EMPTY(2020, "此券不存在"), | |||||
| COUPON_IS_NOT_FREE(2021, "此券不免费"), | |||||
| COUPON_IS_TAKE_OFF(2022, "此券已下架"), | COUPON_IS_TAKE_OFF(2022, "此券已下架"), | ||||
| COUPON_IS_EXPIRED(2023, "此券已过期"), | |||||
| COUPON_IS_SELL_OUT(2024, "此券已售罄"), | |||||
| COUPON_TYPE_IS_NOT_ACTIVE(2025, "此券不能用于主动领取"), | |||||
| COUPON_TYPE_IS_NOT_PASSIVE(2026, "此券不能用于定向投放"), | |||||
| COUPON_CHANNEL_IS_EXISTED(2027, "此券已投放过"), | |||||
| COUPON_SEND_IS_EXISTED(2028, "此券已经添加到该渠道"), | |||||
| COUPON_CHANNEL_IS_EXISTED(2023, "券已投放过"), | |||||
| /** | /** | ||||
| * 车流 2040 | * 车流 2040 | ||||
| */ | */ | ||||
| @@ -0,0 +1,37 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponInjectSendType { | |||||
| // 0:立即发送 1:定时发送 | |||||
| IMMEDIATE(0, "立即发送"), | |||||
| TIMING(1, "定时发送") | |||||
| ; | |||||
| public static EnumCouponInjectSendType getEnum(Integer code) { | |||||
| for (EnumCouponInjectSendType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponInjectSendType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponSendSendType { | |||||
| // 2:停车发券 3:核销发券 | |||||
| CAR_STOP(2, "停车发券"), | |||||
| COUPON_VERIFY(3, "核销发券") | |||||
| ; | |||||
| public static EnumCouponSendSendType getEnum(Integer code) { | |||||
| for (EnumCouponSendSendType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponSendSendType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponSendStatus { | |||||
| // 0:有效 1:无效 | |||||
| VALID(0,"有效"), | |||||
| INVALID(1, "无效") | |||||
| ; | |||||
| public static EnumCouponSendStatus getEnum(Integer code) { | |||||
| for (EnumCouponSendStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponSendStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -5,9 +5,9 @@ package com.simple.enums; | |||||
| */ | */ | ||||
| public enum EnumCouponSendType { | public enum EnumCouponSendType { | ||||
| // 2:停车发券 3:核销发券 | |||||
| CAR_STOP(2, "停车发券"), | |||||
| COUPON_VERIFY(3, "核销发券") | |||||
| // 1:主动领取 2:定向投放 | |||||
| ACTIVE(1,"主动领取"), | |||||
| PASSIVE(2, "定向投放") | |||||
| ; | ; | ||||
| public static EnumCouponSendType getEnum(Integer code) { | public static EnumCouponSendType getEnum(Integer code) { | ||||
| @@ -0,0 +1,38 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponValidType { | |||||
| // 1-时间范围 ;2-领取后时长; | |||||
| BETWEEN_TWO_TIME(1, "时间范围"), | |||||
| DAYS_AFTER_RECEIVING(2, "领取后天数"), | |||||
| ; | |||||
| public static EnumCouponValidType getEnum(Integer code) { | |||||
| for (EnumCouponValidType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponValidType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -1,9 +1,8 @@ | |||||
| package com.simple.service; | package com.simple.service; | ||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCouponSend; | import com.simple.domain.po.WxCouponSend; | ||||
| import com.simple.enums.EnumCouponSendType; | |||||
| import com.simple.enums.EnumCouponSendSendType; | |||||
| public interface WxCouponSendService { | public interface WxCouponSendService { | ||||
| @@ -45,7 +44,7 @@ public interface WxCouponSendService { | |||||
| * @param cUserId | * @param cUserId | ||||
| * @param type 2:停车发券 3:核销发券 | * @param type 2:停车发券 3:核销发券 | ||||
| */ | */ | ||||
| void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendType type); | |||||
| void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendSendType type); | |||||
| void updateStatusByCouponId(Long couponId,String tenantId,int status); | void updateStatusByCouponId(Long couponId,String tenantId,int status); | ||||
| @@ -3,10 +3,14 @@ package com.simple.service.impl; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.IdWorker; | import com.simple.common.IdWorker; | ||||
| import com.simple.common.Result; | import com.simple.common.Result; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.*; | import com.simple.domain.po.*; | ||||
| import com.simple.enums.EnumCouponSendType; | |||||
| import com.simple.enums.EnumCouponStatus; | |||||
| import com.simple.enums.EnumCouponValidType; | |||||
| import com.simple.mapper.CouponInjectMapper; | import com.simple.mapper.CouponInjectMapper; | ||||
| import com.simple.service.*; | import com.simple.service.*; | ||||
| import org.apache.commons.lang.time.DateUtils; | import org.apache.commons.lang.time.DateUtils; | ||||
| @@ -65,17 +69,21 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||||
| @Override | @Override | ||||
| public ResultData add(CouponInject record) { | public ResultData add(CouponInject record) { | ||||
| ResultData resultData = new ResultData(); | |||||
| WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); | WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); | ||||
| if (wxCoupon.getValidType() == 1) { //时间范围 | |||||
| if (wxCoupon.getValidType() == EnumCouponValidType.BETWEEN_TWO_TIME.getCode()) { //时间范围 | |||||
| if (new Date().after(wxCoupon.getValidEndDate())) { | if (new Date().after(wxCoupon.getValidEndDate())) { | ||||
| return new ResultData(Result.ERROR,"已过期"); | |||||
| return new ResultData(ErrorCode.COUPON_IS_EXPIRED); | |||||
| } | } | ||||
| } | } | ||||
| if(wxCoupon.getStatus()!=0||wxCoupon.getSendType()!=1){ | |||||
| return new ResultData(Result.ERROR,"券状态有问题,不能投放"); | |||||
| if(wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()){ | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| if(wxCoupon.getSendType()!=EnumCouponSendType.PASSIVE.getCode()) { | |||||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | |||||
| } | } | ||||
| //解析前台tags,并转换json | //解析前台tags,并转换json | ||||
| String[] arys = record.getTags().split(","); | String[] arys = record.getTags().split(","); | ||||
| List<Long> tagids = new ArrayList<>(); | List<Long> tagids = new ArrayList<>(); | ||||
| @@ -99,7 +107,7 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||||
| } | } | ||||
| int inventory = wxCoupon.getRemainInventory();//库存数量 | int inventory = wxCoupon.getRemainInventory();//库存数量 | ||||
| if(cUsers.size()>inventory){ | if(cUsers.size()>inventory){ | ||||
| return new ResultData(Result.ERROR,"库存不足"); | |||||
| return new ResultData(ErrorCode.COUPON_IS_SELL_OUT); | |||||
| } | } | ||||
| record.setCouponName(wxCoupon.getTitle()); | record.setCouponName(wxCoupon.getTitle()); | ||||
| record.setSendAmount(cUsers.size()); | record.setSendAmount(cUsers.size()); | ||||
| @@ -131,7 +139,7 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||||
| wxCouponOrder.setCUserId(tempCUser.getId()); | wxCouponOrder.setCUserId(tempCUser.getId()); | ||||
| wxCouponOrder.setCouponPrice(0); | wxCouponOrder.setCouponPrice(0); | ||||
| wxCouponOrder.setCreateDate(new Date()); | wxCouponOrder.setCreateDate(new Date()); | ||||
| if (wxCoupon.getValidType() == 1) { //时间范围区间 | |||||
| if (wxCoupon.getValidType() == EnumCouponValidType.BETWEEN_TWO_TIME.getCode()) { //时间范围区间 | |||||
| wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); | wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); | ||||
| } else { | } else { | ||||
| Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); | Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); | ||||
| @@ -26,7 +26,6 @@ import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.autoconfigure.AutoConfigureOrder; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Propagation; | import org.springframework.transaction.annotation.Propagation; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| @@ -383,7 +382,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(couponOrder.getOrderId()); | WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(couponOrder.getOrderId()); | ||||
| if (wxOrder != null) { | if (wxOrder != null) { | ||||
| try { | try { | ||||
| wxCouponSendService.sendCouponToUser(bUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendType.COUPON_VERIFY); | |||||
| wxCouponSendService.sendCouponToUser(bUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendSendType.COUPON_VERIFY); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("核销发券: " + e.getMessage()); | logger.error("核销发券: " + e.getMessage()); | ||||
| } | } | ||||
| @@ -8,12 +8,10 @@ import com.simple.enums.*; | |||||
| import com.simple.mapper.WxCouponOrderMapper; | import com.simple.mapper.WxCouponOrderMapper; | ||||
| import com.simple.mapper.WxCouponSendMapper; | import com.simple.mapper.WxCouponSendMapper; | ||||
| import com.simple.service.*; | import com.simple.service.*; | ||||
| import org.apache.commons.lang.time.DateUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @Service | @Service | ||||
| @@ -66,22 +64,22 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| @Override | @Override | ||||
| @Transactional | @Transactional | ||||
| public void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendType type) { | |||||
| public void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendSendType type) { | |||||
| //查询开关是否打开 | //查询开关是否打开 | ||||
| //查询停车或者核销的券 stopCarCouponSwitch verifyConponSwitch | //查询停车或者核销的券 stopCarCouponSwitch verifyConponSwitch | ||||
| WxCouponSend wxCouponSendQuery = new WxCouponSend(); | WxCouponSend wxCouponSendQuery = new WxCouponSend(); | ||||
| wxCouponSendQuery.setTenantId(tenantId); | wxCouponSendQuery.setTenantId(tenantId); | ||||
| int actionLogType = 0; | int actionLogType = 0; | ||||
| String configKey = ""; | String configKey = ""; | ||||
| if (type == EnumCouponSendType.CAR_STOP) { | |||||
| if (type == EnumCouponSendSendType.CAR_STOP) { | |||||
| //停车 | //停车 | ||||
| wxCouponSendQuery.setSendType(EnumCouponSendType.CAR_STOP.getCode()); | |||||
| wxCouponSendQuery.setSendType(EnumCouponSendSendType.CAR_STOP.getCode()); | |||||
| actionLogType = EnumCouponActionChannelType.CAR.getCode(); | actionLogType = EnumCouponActionChannelType.CAR.getCode(); | ||||
| configKey = "stopCarCouponSwitch"; | configKey = "stopCarCouponSwitch"; | ||||
| } | } | ||||
| if (type == EnumCouponSendType.COUPON_VERIFY) { | |||||
| if (type == EnumCouponSendSendType.COUPON_VERIFY) { | |||||
| //核销 | //核销 | ||||
| wxCouponSendQuery.setSendType(EnumCouponSendType.COUPON_VERIFY.getCode()); | |||||
| wxCouponSendQuery.setSendType(EnumCouponSendSendType.COUPON_VERIFY.getCode()); | |||||
| actionLogType = EnumCouponActionChannelType.VERIFY.getCode(); | actionLogType = EnumCouponActionChannelType.VERIFY.getCode(); | ||||
| configKey = "verifyConponSwitch"; | configKey = "verifyConponSwitch"; | ||||
| } else { | } else { | ||||