| @@ -56,58 +56,57 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| //TODO 待优化数据 | |||
| // @ApiOperation("分页列表接口") | |||
| // @GetMapping("list") | |||
| // @ApiImplicitParams({ | |||
| // @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| // @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| // public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer dataType) { | |||
| // logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||
| // if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| // wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| // if(null == wxCoupon.getSourceType()){ | |||
| // wxCoupon.setSourceType(EnumCouponSourceType.COUPONSource_Bapi.getCode()); | |||
| // } | |||
| // wxCoupon.setMerchantId(getLoginBUser().getMerchantId()); | |||
| // | |||
| // if(StringUtils.isNotBlank(wxCoupon.getSortColumn())){ | |||
| // String coryColumn = "c."+wxCoupon.getSortColumns(); | |||
| // wxCoupon.setSortColumns(coryColumn); | |||
| // wxCoupon.setSortColumn(null); | |||
| // } | |||
| // | |||
| // return wxCouponService.list(wxCoupon,wxCoupon, pageNum, pageSize); //全列表 | |||
| // } | |||
| // | |||
| // @ApiOperation("分页列表接口") | |||
| // @GetMapping("listWithTypePress") | |||
| // @ApiImplicitParams({ | |||
| // @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| // @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| // public ResultData listWithTypePress(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| // logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||
| // if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| // wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| // Integer[] typeArray = { | |||
| // EnumCouponType.COUPON_MANJIAN.getCode(), | |||
| // EnumCouponType.COUPON_DAIJIN.getCode(), | |||
| // EnumCouponType.COUPON_TUANGOU.getCode(), | |||
| // EnumCouponType.COUPON_LIPIN.getCode(), | |||
| // EnumCouponType.COUPON_TINGCHE.getCode(), | |||
| // EnumCouponType.COUPON_MULTIMCH.getCode(), | |||
| // EnumCouponType.COUPON_PRESS.getCode(), | |||
| // EnumCouponType.COUPON_PREORDER.getCode()}; | |||
| // | |||
| // wxCoupon.setTypes(Arrays.asList(typeArray)); | |||
| // wxCoupon.setMerchantId(getLoginBUser().getMerchantId()); | |||
| // if(StringUtils.isNotBlank(wxCoupon.getSortColumn())){ | |||
| // String coryColumn = "c."+wxCoupon.getSortColumns(); | |||
| // wxCoupon.setSortColumns(coryColumn); | |||
| // wxCoupon.setSortColumn(null); | |||
| // } | |||
| // return wxCouponService.list(wxCoupon,wxCoupon, pageNum, pageSize); //全列表 | |||
| // } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer dataType) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| if(null == wxCoupon.getSourceType()){ | |||
| wxCoupon.setSourceType(EnumCouponSourceType.COUPONSource_Bapi.getCode()); | |||
| } | |||
| wxCoupon.setMerchantId(getLoginBUser().getMerchantId()); | |||
| if(StringUtils.isNotBlank(wxCoupon.getSortColumn())){ | |||
| String coryColumn = "c."+wxCoupon.getSortColumns(); | |||
| wxCoupon.setSortColumns(coryColumn); | |||
| wxCoupon.setSortColumn(null); | |||
| } | |||
| return wxCouponService.list(wxCoupon,wxCoupon, pageNum, pageSize); //全列表 | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("listWithTypePress") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData listWithTypePress(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| Integer[] typeArray = { | |||
| EnumCouponType.COUPON_MANJIAN.getCode(), | |||
| EnumCouponType.COUPON_DAIJIN.getCode(), | |||
| EnumCouponType.COUPON_TUANGOU.getCode(), | |||
| EnumCouponType.COUPON_LIPIN.getCode(), | |||
| EnumCouponType.COUPON_TINGCHE.getCode(), | |||
| EnumCouponType.COUPON_MULTIMCH.getCode(), | |||
| EnumCouponType.COUPON_PRESS.getCode(), | |||
| EnumCouponType.COUPON_PREORDER.getCode()}; | |||
| wxCoupon.setTypes(Arrays.asList(typeArray)); | |||
| wxCoupon.setMerchantId(getLoginBUser().getMerchantId()); | |||
| if(StringUtils.isNotBlank(wxCoupon.getSortColumn())){ | |||
| String coryColumn = "c."+wxCoupon.getSortColumns(); | |||
| wxCoupon.setSortColumns(coryColumn); | |||
| wxCoupon.setSortColumn(null); | |||
| } | |||
| return wxCouponService.list(wxCoupon,wxCoupon, pageNum, pageSize); //全列表 | |||
| } | |||
| private Map<String,Object> generateFlowParams(EnumFlowKey flowType,EnumCouponAppType approvalType, WxCoupon wxCoupon,String remark,String phone) { | |||
| Map<String,Object> map = new HashMap<String,Object>(); | |||
| @@ -44,7 +44,6 @@ public class WxCouponSendController extends BaseController { | |||
| @Resource | |||
| private WxCUserMapper wxCUserMapper; | |||
| //TODO 待优化数据 | |||
| @ApiOperation("查询商户注券列表") | |||
| @GetMapping("/list") | |||
| @ApiImplicitParams({ | |||
| @@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| @@ -50,8 +51,9 @@ public class CouponSendSchedule { | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Lazy | |||
| @Autowired | |||
| private WxCouponSendMapper wxCouponSendMapper; | |||
| private WxCouponSendService wxCouponSendService; | |||
| @Autowired | |||
| private WxCouponActionLogMapper wxCouponActionLogMapper; | |||
| @@ -65,8 +67,6 @@ public class CouponSendSchedule { | |||
| @Autowired | |||
| private WxCouponSendConfigMapper couponSendConfigMapper; | |||
| @Autowired | |||
| private WxCouponSendService wxCouponSendService; | |||
| @Autowired | |||
| private WxScoreRulesService wxScoreRulesService; | |||
| @@ -147,7 +147,7 @@ public class CouponSendSchedule { | |||
| wxCouponSend.updateTenantInfo(tenantEntity); | |||
| wxCouponSend.setSendType(EnumCouponSendSendType.TIMED.getCode()); | |||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend); | |||
| List<WxCouponSendVo> couponSendList = wxCouponSendService.findListVo(wxCouponSend); | |||
| int remain = couponSendList.stream().map(cs -> { | |||
| int count = cs.getRemainInventory(); | |||
| logger.info("定时发券:给[" + cu.getNickName() + | |||
| @@ -256,7 +256,7 @@ public class CouponSendSchedule { | |||
| wxCouponSend.updateTenantInfo(tenantEntity); | |||
| wxCouponSend.setSendType(EnumCouponSendSendType.BIRTHDAY.getCode()); | |||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend); | |||
| List<WxCouponSendVo> couponSendList = wxCouponSendService.findListVo(wxCouponSend); | |||
| if (CollectionUtils.isEmpty(couponSendList)) { | |||
| logger.info("生日发券: 会员生日券投放列表为空 couponSendList = {}, 任务跳过不执行", couponSendList); | |||
| return; | |||
| @@ -1,5 +1,7 @@ | |||
| package com.iformall.domain.po; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.fasterxml.jackson.annotation.JsonIgnore; | |||
| @@ -12,126 +14,125 @@ import lombok.ToString; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @TableName(value = "wx_coupon_send") | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class WxCouponSend extends TenantEntity { | |||
| /** | |||
| * 卡券ids | |||
| */ | |||
| private static final long serialVersionUID = 1169744095647819041L; | |||
| protected Long id; | |||
| @io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId") | |||
| private Long couponId; | |||
| @TableField(exist = false) | |||
| public static final String KEY_COUPONIDS = "couponIds" ; | |||
| /** | |||
| * beforeDays | |||
| */ | |||
| private List<Long> couponIds; | |||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||
| private String title; | |||
| @io.swagger.annotations.ApiModelProperty(value="2:停车发券 3:核销发券 4: B端刷卡发券 5:商户发券 6:定时发券 7:商户发券",name="sendType") | |||
| private Integer sendType; | |||
| @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") | |||
| private String conditions; | |||
| @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效,全部时不传",name="status") | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value = "1是0否", name = "是否发送短信1是0否") | |||
| private Integer sendSms; | |||
| @JsonIgnore | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人ID",name="operatorId") | |||
| private Long operatorId; | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人",name="operator") | |||
| @TableField(exist = false) | |||
| public static final String KEY_BEFOREDAYS = "beforeDays" ; | |||
| private String operator; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
| private Date updateDate; | |||
| /** | |||
| * limit 商户购券数 | |||
| * 商户购券数 | |||
| */ | |||
| //@TableField(exist = false) | |||
| //protected Integer merchantLnventory; | |||
| @JsonIgnore | |||
| @TableField(exist = false) | |||
| public static final String KEY_MERCHANT_LNVENTORY = "merchantLnventory" ; | |||
| public Integer getMerchantLnventory() { | |||
| return (Integer)getConditonsValue(KEY_MERCHANT_LNVENTORY); | |||
| } | |||
| /** | |||
| * limit 商户注券数 | |||
| * 商户注券数 | |||
| */ | |||
| //@TableField(exist = false) | |||
| //protected Integer merchantSend; | |||
| @JsonIgnore | |||
| @TableField(exist = false) | |||
| public static final String KEY_MERCHANT_SEND = "merchantSend" ; | |||
| public Integer getMerchantSend() { | |||
| return (Integer)getConditonsValue(KEY_MERCHANT_SEND); | |||
| } | |||
| /** | |||
| * limit 商户注券数 | |||
| * 商户剩余数 | |||
| */ | |||
| @JsonIgnore | |||
| @TableField(exist = false) | |||
| public static final String KEY_MERCHANT_REMAIN = "merchantRemain" ; | |||
| public Integer getMerchantRemain() { | |||
| return (Integer)getConditonsValue(KEY_MERCHANT_REMAIN); | |||
| } | |||
| @TableField(exist = false) | |||
| public static final String KEY_COUPONIDS = "couponIds" ; | |||
| @TableField(exist = false) | |||
| public static final String KEY_BEFOREDAYS = "beforeDays" ; | |||
| /** | |||
| * 排序-商户购券数 | |||
| */ | |||
| @JsonIgnore | |||
| public static final String SORT_MERCHANT_LNVENTORY = "merchantLnventory" ; | |||
| /** | |||
| * 排序-商户已发数 | |||
| */ | |||
| @JsonIgnore | |||
| public static final String SORT_MERCHANT_SEND = "merchantSend" ; | |||
| /** | |||
| * 排序-商户剩余数 | |||
| */ | |||
| @JsonIgnore | |||
| public static final String SORT_REMAIN = "merchantRemain" ; | |||
| protected Long id; | |||
| private Object getConditonsValue(String key) { | |||
| if (!StringUtils.isBlank(conditions)) { | |||
| JSONObject object = JSON.parseObject(conditions); | |||
| if (null != object) { | |||
| return object.get(key); | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| @TableField(exist = false) | |||
| protected List<Long> ids; | |||
| /** | |||
| * 商户购券数 | |||
| */ | |||
| @TableField(exist = false) | |||
| protected Integer merchantLnventory; | |||
| /** | |||
| * 商户已发数 | |||
| */ | |||
| @TableField(exist = false) | |||
| protected Integer merchantSend; | |||
| /** | |||
| * 商户剩余数 | |||
| */ | |||
| @TableField(exist = false) | |||
| protected Integer merchantRemain; | |||
| /**发券所属商户名**/ | |||
| @TableField(exist = false) | |||
| private String merchantName; | |||
| /** | |||
| * 商户ID | |||
| */ | |||
| @TableField(exist = false) | |||
| private Long merchantId; | |||
| @io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId") | |||
| private Long couponId; | |||
| @io.swagger.annotations.ApiModelProperty(value="券名称",name="title") | |||
| private String title; | |||
| @io.swagger.annotations.ApiModelProperty(value="2:停车发券 3:核销发券 4: B端刷卡发券 5:商户发券 6:定时发券 7:商户发券",name="sendType") | |||
| private Integer sendType; | |||
| @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") | |||
| private String conditions; | |||
| @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效,全部时不传",name="status") | |||
| private Integer status; | |||
| @JsonIgnore | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人ID",name="operatorId") | |||
| private Long operatorId; | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人",name="operator") | |||
| @TableField(exist = false) | |||
| private String operator; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
| private Date updateDate; | |||
| protected Integer merchantRemain; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="场景发券计数",name="sendCount") | |||
| protected int sendCount; | |||
| @io.swagger.annotations.ApiModelProperty(value = "1是0否", name = "是否发送短信1是0否") | |||
| private Integer sendSms; | |||
| @io.swagger.annotations.ApiModelProperty(value = "0未过期1已过期,全部时不传", name = "expired" ) | |||
| @TableField(exist = false) | |||
| private Integer expired; | |||
| @@ -23,6 +23,9 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> { | |||
| List<Long> findIdList(WxCoupon wxCoupon); | |||
| List<WxCoupon> findCouponList(WxCoupon wxCoupon); | |||
| List<WxCoupon> findSendCouponList(WxCoupon wxCoupon); | |||
| List<Long> findSendCouponIds(@Param("expired")Integer expired,@Param("tenantId")String tenantId); | |||
| WxCoupon selectById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| @@ -3,7 +3,6 @@ package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxCouponSend; | |||
| import com.iformall.domain.vo.WxCouponSendVo; | |||
| import org.apache.ibatis.annotations.Param; | |||
| public interface WxCouponSendMapper extends CommonMapper<WxCouponSend, String> { | |||
| @@ -12,8 +11,7 @@ public interface WxCouponSendMapper extends CommonMapper<WxCouponSend, String> { | |||
| int deleteById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| List<WxCouponSendVo> findListVo(WxCouponSend wxCouponSend); | |||
| List<WxCouponSendVo> findListVoByValidType(WxCouponSend wxCouponSend); | |||
| List<WxCouponSend> findList(WxCouponSend wxCouponSend); | |||
| void updateStatusByCouponId(WxCouponSend wxCouponSend); | |||
| @@ -1,5 +1,7 @@ | |||
| package com.iformall.service; | |||
| import java.util.List; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.WxCouponSend; | |||
| @@ -97,6 +99,9 @@ public interface WxCouponSendService { | |||
| * @param wxCouponSend | |||
| */ | |||
| void handSel(WxCouponSend wxCouponSend,Long cUserId,EnumPayWay payWay,Long merchantId,Long bUserId) ; | |||
| List<WxCouponSendVo> findListVo(WxCouponSend record); | |||
| } | |||
| @@ -22,6 +22,8 @@ import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.apache.commons.beanutils.BeanUtils; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -31,6 +33,8 @@ import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| @@ -93,6 +97,12 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| @Lazy | |||
| @Autowired | |||
| private WxMsgService wxMsgService; | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| MallUserInfoMapper mallUserInfoMapper; | |||
| @Override | |||
| public PageInfo<WxCouponSendVo> listAsPage(WxCouponSend record, Integer pageIndex, Integer pageSize) { | |||
| @@ -112,30 +122,147 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| } | |||
| record.setSortColumn(null); | |||
| record.setSortCol(sortStr); | |||
| pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoByValidType(record)); | |||
| for (WxCouponSendVo cs : pageInfo.getList()) { | |||
| JSONObject jo = JSONObject.parseObject(cs.getConditions()); | |||
| int inventory = jo.getIntValue(WxCouponSend.KEY_MERCHANT_LNVENTORY); | |||
| cs.setInventory(inventory); | |||
| int expired = 0; | |||
| if (!DateUtils.isDateBefore(cs.getValidEndDate())) { | |||
| expired = 1; | |||
| } | |||
| cs.setExpired(expired); | |||
| } | |||
| record.setCouponIds(wxCouponMapper.findSendCouponIds(record.getExpired(),record.getTenantId())); | |||
| PageInfo<WxCouponSend> sendPageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findList(record)); | |||
| pageInfo = new PageInfo<WxCouponSendVo>(); | |||
| pageInfo.setPageNum(sendPageInfo.getPageNum()); | |||
| pageInfo.setPageSize(sendPageInfo.getPageSize()); | |||
| pageInfo.setPages(sendPageInfo.getPages()); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),true,false)); | |||
| } else { | |||
| record.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| record.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVo(record)); | |||
| List<Long> couponIds = pageInfo.getList().stream().map(cs -> cs.getCouponId()).collect(Collectors.toList()); | |||
| Map<Long, String> couponMerchantMap = wxCouponService.getCouponMerchantMap(couponIds,record); | |||
| for (WxCouponSendVo cs:pageInfo.getList()){ | |||
| cs.setMerchantName(couponMerchantMap.get(cs.getCouponId())); | |||
| cs.setSendCount(wxCouponActionLogService.getCountByChannelId(record, cs.getSendType(), cs.getId())); | |||
| } | |||
| PageInfo<WxCouponSend> sendPageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findList(record)); | |||
| pageInfo = new PageInfo<WxCouponSendVo>(); | |||
| pageInfo.setPageNum(sendPageInfo.getPageNum()); | |||
| pageInfo.setPageSize(sendPageInfo.getPageSize()); | |||
| pageInfo.setPages(sendPageInfo.getPages()); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),false,true)); | |||
| } | |||
| return pageInfo; | |||
| } | |||
| @Override | |||
| public List<WxCouponSendVo> findListVo(WxCouponSend record) { | |||
| List<WxCouponSend> couponSendList = wxCouponSendMapper.findList(record); | |||
| return couponSendToVoList(record,couponSendList,false,false); | |||
| } | |||
| private List<WxCouponSendVo> couponSendToVoList(TenantEntity tenantEntity,List<WxCouponSend> couponSendList,boolean setInventoryAndExpired,boolean setMerchantNameAndSendCount) { | |||
| if (null != couponSendList) { | |||
| List<Long> couponIdList = new ArrayList<>(); | |||
| List<Long> mallUserInfoIdList = new ArrayList<Long>(); | |||
| for (int i = 0 ; i <couponSendList.size() ; i++) { | |||
| WxCouponSend cs = couponSendList.get(i); | |||
| Long couponId = cs.getCouponId(); | |||
| if (null != couponId && (!couponIdList.contains(couponId))) { | |||
| couponIdList.add(couponId); | |||
| } | |||
| Long mallUserId = cs.getOperatorId(); | |||
| if (null != mallUserId && (!mallUserInfoIdList.contains(mallUserId))) { | |||
| mallUserInfoIdList.add(mallUserId); | |||
| } | |||
| } | |||
| //获取coupon | |||
| Map<Long,WxCoupon> couponMap = new HashMap<Long,WxCoupon>(); | |||
| if (couponIdList.size() > 0 ) { | |||
| WxCoupon couponQ = new WxCoupon(); | |||
| couponQ.updateTenantInfo(tenantEntity); | |||
| couponQ.setIds(couponIdList); | |||
| List<WxCoupon> couponList = wxCouponMapper.findSendCouponList(couponQ); | |||
| if (null != couponList) { | |||
| for (int k = 0 ; k < couponList.size() ; k++) { | |||
| WxCoupon c = couponList.get(k); | |||
| couponMap.put(c.getId(), c); | |||
| } | |||
| } | |||
| } | |||
| //获取mallUserInfo | |||
| Map<Long,MallUserInfo> mallUserMap = new HashMap<Long,MallUserInfo>(); | |||
| if (mallUserInfoIdList.size() > 0 ) { | |||
| MallUserInfo mallUserInfoQ = new MallUserInfo(); | |||
| mallUserInfoQ.updateTenantInfo(tenantEntity); | |||
| mallUserInfoQ.setIds(mallUserInfoIdList); | |||
| List<MallUserInfo> userInfoList = mallUserInfoMapper.findList(mallUserInfoQ); | |||
| if (null != userInfoList) { | |||
| for (int k = 0 ; k < userInfoList.size() ; k++) { | |||
| MallUserInfo ui = userInfoList.get(k); | |||
| mallUserMap.put(ui.getId(), ui); | |||
| } | |||
| } | |||
| } | |||
| //couponMerchant | |||
| Map<Long, String> couponMerchantMap = null; | |||
| if (setMerchantNameAndSendCount) { | |||
| couponMerchantMap = wxCouponService.getCouponMerchantMap(couponIdList,tenantEntity); | |||
| } | |||
| List<WxCouponSendVo> retList = new ArrayList<WxCouponSendVo>(); | |||
| for (int i = 0 ; i <couponSendList.size() ; i++) { | |||
| WxCouponSend cs = couponSendList.get(i); | |||
| WxCouponSendVo vo = couponSendToVo(cs,couponMap,mallUserMap,couponMerchantMap,setInventoryAndExpired,setMerchantNameAndSendCount); | |||
| if (null != vo) { | |||
| retList.add(vo); | |||
| } | |||
| } | |||
| return retList; | |||
| } | |||
| return null; | |||
| } | |||
| private WxCouponSendVo couponSendToVo(WxCouponSend cs,Map<Long,WxCoupon> couponMap,Map<Long,MallUserInfo> mallUserMap,Map<Long, String> couponMerchantMap, | |||
| boolean setInventoryAndExpired,boolean setMerchantNameAndSendCount) { | |||
| if (null == cs) { | |||
| return null; | |||
| } | |||
| WxCouponSendVo vo = new WxCouponSendVo(); | |||
| try { | |||
| BeanUtils.copyProperties(vo, cs); | |||
| Long couponId = vo.getCouponId(); | |||
| if (null != couponId ) { | |||
| WxCoupon coupon = couponMap.get(couponId); | |||
| if (null != coupon) { | |||
| vo.setRemainInventory(coupon.getRemainInventory()); | |||
| vo.setUseLimitRule(coupon.getUseLimitRule()); | |||
| vo.setUseLimitQuantity(coupon.getUseLimitQuantity()); | |||
| if (setInventoryAndExpired) { | |||
| vo.setInventory(cs.getMerchantLnventory()); | |||
| int expired = 0; | |||
| if (!DateUtils.isDateBefore(coupon.getValidEndDate())) { | |||
| expired = 1; | |||
| } | |||
| cs.setExpired(expired); | |||
| }else { | |||
| vo.setInventory(coupon.getInventory()); | |||
| } | |||
| vo.setValidStartDate(coupon.getValidStartDate()); | |||
| vo.setValidEndDate(coupon.getValidEndDate()); | |||
| vo.setValidDays(coupon.getValidDays()); | |||
| } | |||
| } | |||
| Long mallUserId = vo.getOperatorId(); | |||
| if (null != mallUserId ) { | |||
| MallUserInfo user = mallUserMap.get(couponId); | |||
| if (null != user) { | |||
| vo.setOperator(user.getName()); | |||
| } | |||
| } | |||
| if (setMerchantNameAndSendCount) { | |||
| vo.setMerchantName(couponMerchantMap.get(vo.getCouponId())); | |||
| vo.setSendCount(wxCouponActionLogService.getCountByChannelId(vo, vo.getSendType(), vo.getId())); | |||
| } | |||
| return vo; | |||
| } catch (IllegalAccessException e) { | |||
| e.printStackTrace(); | |||
| } catch (InvocationTargetException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public WxCouponSend getById(Long id,String tenantId) { | |||
| @@ -419,7 +546,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| wxCouponSendQuery.setSendType(type.getCode()); | |||
| wxCouponSendQuery.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| List<WxCouponSendVo> wxCouponSends = wxCouponSendMapper.findListVo(wxCouponSendQuery); | |||
| List<WxCouponSendVo> wxCouponSends = findListVo(wxCouponSendQuery); | |||
| for (WxCouponSend send : wxCouponSends) { | |||
| boolean checkLimit = false; | |||
| // 检查疲劳度 | |||
| @@ -737,7 +864,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||
| } | |||
| List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend); | |||
| List<WxCouponSendVo> couponSendList = findListVo(wxCouponSend); | |||
| if (CollectionUtils.isEmpty(couponSendList)) { | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| @@ -980,7 +980,6 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), merchantIds); | |||
| // Map<Long,String> couponMerchantMap = new HashMap<Long,String>(); | |||
| if (null != merchantProductVos) { | |||
| for (int i = 0 ; i < merchantProductVos.size(); i ++) { | |||
| WxMerchantProductVo mp = merchantProductVos.get(i); | |||
| @@ -274,7 +274,7 @@ | |||
| </select> | |||
| <select id="getCountByChannelId" resultType="java.lang.Integer"> | |||
| select COUNT(*) FROM wx_coupon_action_log | |||
| select COUNT(1) FROM wx_coupon_action_log | |||
| where channel_type = #{channelType} | |||
| and channel_id = #{channelId} | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| @@ -366,6 +366,46 @@ | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="findSendCouponIds" parameterType="java.util.HashMap" resultType="Long"> | |||
| select id | |||
| from wx_coupon where `tenant_id` = #{tenantId} | |||
| and ((valid_type=1 | |||
| <choose> | |||
| <when test="expired == 0"> | |||
| and <![CDATA[ valid_end_date >= now() ]]> | |||
| </when> | |||
| <when test="expired == 1"> | |||
| and <![CDATA[ valid_end_date < now() ]]> | |||
| </when> | |||
| <otherwise> | |||
| </otherwise> | |||
| </choose> | |||
| ) | |||
| <choose> | |||
| <when test="expired == 0"> | |||
| or <![CDATA[ valid_type = 2 ]]> | |||
| </when> | |||
| <when test="expired == 1"> | |||
| </when> | |||
| <otherwise> | |||
| or <![CDATA[ valid_type = 2 ]]> | |||
| </otherwise> | |||
| </choose> | |||
| ) | |||
| </select> | |||
| <select id="findSendCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap"> | |||
| select | |||
| c.id,c.remain_inventory, c.use_limit_rule,c.use_limit_quantity, c.inventory, c.valid_start_date, c.valid_end_date,c.valid_type,c.valid_days | |||
| from wx_coupon c where c.`tenant_id` = #{tenantId} | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <delete id="deleteById" parameterType="java.util.HashMap"> | |||
| update wx_coupon set is_del = 1 where id = #{id} and tenant_id = #{tenantId} | |||
| </delete> | |||
| @@ -565,58 +605,6 @@ | |||
| and cm.`merchant_id` = #{merchantId} | |||
| </if> | |||
| <!--<!–如果配置了审批模板,需要过滤投放审批状态–> | |||
| <if test="0 != filterCanPut or null ==filterCanPut "> | |||
| <if test=" null != pressModelId and 0l != pressModelId"> | |||
| and if(c.type=8,c.put_apply_status =2 or c.id in ( | |||
| select coupon_id from wx_coupon_channel | |||
| where status=0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| ) ,1=1) | |||
| </if> | |||
| <if test=" null != groupModelId and 0l != groupModelId"> | |||
| and if(c.type=9,c.put_apply_status =2 or c.id in ( | |||
| select coupon_id from wx_coupon_channel | |||
| where status=0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| ),1=1) | |||
| </if> | |||
| <if test=" null != cardModelId and 0l != cardModelId"> | |||
| and if(c.type=100,c.put_apply_status =2 or c.id in ( | |||
| select coupon_id from wx_coupon_channel | |||
| where status=0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| ),1=1) | |||
| </if> | |||
| <if test=" null != couponModelId and 0l != couponModelId"> | |||
| and if(c.type !=8 and c.type !=9 and c.type!=100, c.put_apply_status =2 or c.id in ( | |||
| select coupon_id from wx_coupon_channel | |||
| where status=0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| ),1=1) | |||
| </if> | |||
| </if>--> | |||
| <if test=" null != giftList"> | |||
| and JSON_CONTAINS(c.gift_list,json_array(#{giftList})) | |||
| </if> | |||
| @@ -1287,4 +1275,5 @@ | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -1,7 +1,7 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxCouponSendMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.vo.WxCouponSendVo"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponSend"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| @@ -12,30 +12,16 @@ | |||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||
| <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" /> | |||
| <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/> | |||
| <result column="inventory" jdbcType="INTEGER" property="inventory"/> | |||
| <result column="use_limit_rule" jdbcType="INTEGER" property="useLimitRule" /> | |||
| <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/> | |||
| <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/> | |||
| <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/> | |||
| <result column="send_sms" jdbcType="INTEGER" property="sendSms"/> | |||
| <result column="valid_days" jdbcType="INTEGER" property="validDays"/> | |||
| <result column="send_sms" jdbcType="INTEGER" property="sendSms" /> | |||
| <result column="operator_id" jdbcType="INTEGER" property="operatorId" /> | |||
| </resultMap> | |||
| <sql id="columns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`coupon_id`,`title`,`send_type`,`conditions`,`status`,`create_date`,`update_date`,`send_sms`,`operator_id` | |||
| </sql> | |||
| <sql id="allColumns"> | |||
| cs.id,cs.tenant_id,cs.parent_tenant_id,cs.coupon_id,cs.title,cs.send_type,cs.conditions,cs.status,cs.create_date,cs.update_date, | |||
| cs.conditions -> '$.merchantSend' as merchantSend, | |||
| cs.conditions -> '$.merchantLnventory' as merchantLnventory, | |||
| cs.conditions -> '$.merchantRemain' as merchantRemain, | |||
| c.remain_inventory, c.use_limit_rule,c.use_limit_quantity, c.inventory, c.valid_start_date, c.valid_end_date,c.valid_type,cs.send_sms,c.valid_days | |||
| cs.conditions -> '$.merchantRemain' as merchantRemain | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| @@ -82,6 +68,12 @@ | |||
| <if test=" null != merchantRemain"> | |||
| and cs.conditions -> '$.merchantRemain'> #{merchantRemain} | |||
| </if> | |||
| <if test=" null != couponIds "> | |||
| and cs.coupon_id in | |||
| <foreach collection="couponIds" index="index" item="couponIdItem" open="(" separator="," close=")"> | |||
| #{couponIdItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and cs.id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -94,6 +86,9 @@ | |||
| <if test=" null != sortColumns"> | |||
| order by ${sortColumns} | |||
| </if> | |||
| <if test=" null != sortCol"> | |||
| order by ${sortCol} | |||
| </if> | |||
| </sql> | |||
| <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||
| @@ -104,49 +99,12 @@ | |||
| delete from wx_coupon_send cs where cs.id = #{id} and cs.tenant_id = #{tenantId} | |||
| </delete> | |||
| <select id="findListVo" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> | |||
| from wx_coupon_send cs | |||
| left join wx_coupon c on c.id = cs.coupon_id | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="findListVoByValidType" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap"> | |||
| select tt.* from (select | |||
| <include refid="allColumns"/> | |||
| , mui.name as operator | |||
| from wx_coupon_send cs | |||
| left join wx_coupon c on c.id = cs.coupon_id | |||
| left join mall_user_info mui on mui.id = cs.operator_id | |||
| <include refid="dynamicWhereConditions"/>) as tt | |||
| where 1=1 | |||
| and ((tt.valid_type=1 | |||
| <choose> | |||
| <when test="expired == 0"> | |||
| and <![CDATA[ tt.valid_end_date >= now() ]]> | |||
| </when> | |||
| <when test="expired == 1"> | |||
| and <![CDATA[ tt.valid_end_date < now() ]]> | |||
| </when> | |||
| <otherwise> | |||
| </otherwise> | |||
| </choose> | |||
| ) | |||
| <choose> | |||
| <when test="expired == 0"> | |||
| or <![CDATA[ tt.valid_type = 2 ]]> | |||
| </when> | |||
| <when test="expired == 1"> | |||
| </when> | |||
| <otherwise> | |||
| or <![CDATA[ tt.valid_type = 2 ]]> | |||
| </otherwise> | |||
| </choose> | |||
| ) | |||
| <if test=" null != sortCol"> | |||
| order by ${sortCol} | |||
| </if> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponSend" resultMap="BaseResultMap"> | |||
| select <include refid="columns" /> | |||
| from wx_coupon_send cs | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <update id="updateStatusByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel"> | |||
| update wx_coupon_send set status=#{status} | |||
| where coupon_id=#{couponId} | |||