| @@ -2,9 +2,11 @@ package com.iformall.controller.market; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.BaseEntity; | import com.iformall.domain.po.BaseEntity; | ||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxCouponPresent; | import com.iformall.domain.po.WxCouponPresent; | ||||
| import com.iformall.service.WxCouponPresentService; | import com.iformall.service.WxCouponPresentService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -51,4 +53,26 @@ public class WxCouponPresentController extends BaseController { | |||||
| return new ResultData(wxCouponPresentService.findById(id)); | return new ResultData(wxCouponPresentService.findById(id)); | ||||
| } | } | ||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| @SystemControllerLog(description = "新增") | |||||
| public ResultData add(@RequestBody WxCouponPresent wxCouponPresent) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponInjectController::add"); | |||||
| if (wxCouponPresent.getCouponId() == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请选择卡"); | |||||
| } | |||||
| if (wxCouponPresent.getPhones().isEmpty()) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxCouponPresent.setTenantId(user.getTenantId()); | |||||
| wxCouponPresent.setUserId(user.getId()); | |||||
| return wxCouponPresentService.add(wxCouponPresent); | |||||
| } | |||||
| } | } | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.domain.po; | package com.iformall.domain.po; | ||||
| import io.swagger.annotations.ApiModelProperty; | |||||
| import lombok.Data; | import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||
| @@ -20,21 +21,22 @@ public class WxCouponPresent extends BaseEntity { | |||||
| @Transient | @Transient | ||||
| protected List<Long> ids; | protected List<Long> ids; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") | |||||
| @ApiModelProperty(value = "租户ID", name = "tenantId") | |||||
| private String tenantId; | private String tenantId; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "userId") | |||||
| @ApiModelProperty(value = "用户ID", name = "userId") | |||||
| private Long userId; | private Long userId; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "卡券ID", name = "couponId") | |||||
| @ApiModelProperty(value = "卡券ID", name = "couponId") | |||||
| private Long couponId; | private Long couponId; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "卡券名称", name = "couponName") | |||||
| @ApiModelProperty(value = "卡券名称", name = "couponName") | |||||
| private String couponName; | private String couponName; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "手机", name = "phones") | |||||
| @ApiModelProperty(value = "手机", name = "phones") | |||||
| private String phones; | private String phones; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createDate") | |||||
| @ApiModelProperty(value = "创建时间", name = "createDate") | |||||
| private Date createTime; | private Date createTime; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updateDate") | |||||
| @ApiModelProperty(value = "更新时间", name = "updateDate") | |||||
| private Date updateTime; | private Date updateTime; | ||||
| @ApiModelProperty(value = "发送数量", name = "sendAmount") | |||||
| private Integer sendAmount; | |||||
| @Transient | @Transient | ||||
| protected Date sendTimeStart; | protected Date sendTimeStart; | ||||
| @@ -42,5 +44,4 @@ public class WxCouponPresent extends BaseEntity { | |||||
| @Transient | @Transient | ||||
| protected Date sendTimeEnd; | protected Date sendTimeEnd; | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCouponPresent; | import com.iformall.domain.po.WxCouponPresent; | ||||
| /** | /** | ||||
| @@ -12,4 +13,7 @@ public interface WxCouponPresentService { | |||||
| PageInfo<WxCouponPresent> listAsPage(WxCouponPresent wxCouponPresent, Integer pageNum, Integer pageSize); | PageInfo<WxCouponPresent> listAsPage(WxCouponPresent wxCouponPresent, Integer pageNum, Integer pageSize); | ||||
| WxCouponPresent findById(Long id); | WxCouponPresent findById(Long id); | ||||
| ResultData add(WxCouponPresent wxCouponPresent); | |||||
| } | } | ||||
| @@ -2,21 +2,50 @@ package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | 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.WxCoupon; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.po.WxCouponPresent; | import com.iformall.domain.po.WxCouponPresent; | ||||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||||
| import com.iformall.enums.EnumCouponStatus; | |||||
| import com.iformall.enums.EnumCouponValidType; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxCouponPasswordMapper; | |||||
| import com.iformall.mapper.WxCouponPresentMapper; | import com.iformall.mapper.WxCouponPresentMapper; | ||||
| import com.iformall.service.PushLimitService; | |||||
| import com.iformall.service.WxCouponPresentService; | 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.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Arrays; | |||||
| import java.util.Date; | |||||
| import java.util.HashSet; | |||||
| import java.util.Set; | |||||
| import java.util.stream.Collectors; | |||||
| /** | /** | ||||
| * @author gongbiao | * @author gongbiao | ||||
| */ | */ | ||||
| @Service | @Service | ||||
| public class WxCouponPresentServiceImpl implements WxCouponPresentService { | public class WxCouponPresentServiceImpl implements WxCouponPresentService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | @Autowired | ||||
| WxCouponPresentMapper wxCouponPresentMapper; | WxCouponPresentMapper wxCouponPresentMapper; | ||||
| @Autowired | |||||
| PushLimitService pushLimitService; | |||||
| @Autowired | |||||
| WxCouponService wxCouponService; | |||||
| @Autowired | |||||
| WxCouponPasswordMapper wxCouponPasswordMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxCouponPresent> listAsPage(WxCouponPresent record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxCouponPresent> listAsPage(WxCouponPresent record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -28,4 +57,50 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { | |||||
| return wxCouponPresentMapper.selectByPrimaryKey(id); | return wxCouponPresentMapper.selectByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public ResultData add(WxCouponPresent record) { | |||||
| try { | |||||
| pushLimitService.checkSendTime(record.getTenantId()); | |||||
| } 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<String> phoneSetTemp = new HashSet<>(Arrays.asList(phoneSplit)); | |||||
| Set<String> phoneSet = phoneSetTemp.stream().filter(p -> !p.isEmpty()).collect(Collectors.toSet()); | |||||
| WxCouponPassword wxCouponPassword = new WxCouponPassword(); | |||||
| wxCouponPassword.setTenantId(record.getTenantId()); | |||||
| wxCouponPassword.setCouponId(record.getCouponId()); | |||||
| wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); | |||||
| int inventory = wxCouponPasswordMapper.selectCount(wxCouponPassword); | |||||
| if (phoneSet.size() > inventory) { | |||||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| record.setCouponName(wxCoupon.getTitle()); | |||||
| record.setSendAmount(phoneSet.size()); | |||||
| wxCouponPresentMapper.insertSelective(record); | |||||
| //发送短信 | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||