Browse Source

商户注券->注券列表,有效期过滤

release_toaliyun_real
Burce 6 years ago
parent
commit
3c1df78d65
7 changed files with 129 additions and 113 deletions
  1. +96
    -86
      mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java
  2. +0
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java
  3. +2
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java
  4. +1
    -1
      mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java
  5. +1
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java
  6. +3
    -4
      mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml
  7. +26
    -17
      mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml

+ 96
- 86
mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java View File

@@ -17,10 +17,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@@ -31,98 +31,108 @@ import java.util.stream.Collectors;
@RequestMapping("/api/couponSend")
@Api(description = "商户注券相关接口")
public class WxCouponSendController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxCouponSendService wxCouponSendService;
@Autowired
private WxCouponActionLogService wxCouponActionLogService;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxCouponSendService wxCouponSendService;
@Autowired
private WxCouponActionLogService wxCouponActionLogService;

@Resource
private WxCUserMapper wxCUserMapper;
@Resource
private WxCUserMapper wxCUserMapper;

@ApiOperation("查询商户注券列表")
@GetMapping("/list")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData list(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::list");
if (Objects.isNull(wxCouponSend.getSendType())) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setMerchantId(getUser().getMerchantId());
if (Objects.nonNull(wxCouponSend.getExpired()) && Objects.equals(wxCouponSend.getExpired(), 0)) {
wxCouponSend.setMerchantLnventory(0);
}
wxCouponSend.setStatus(wxCouponSend.getStatus());
//库存大于0
wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
final PageInfo<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, 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(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::list");
if (Objects.isNull(wxCouponSend.getSendType())) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setMerchantId(getUser().getMerchantId());
if (Objects.nonNull(wxCouponSend.getExpired()) && Objects.equals(wxCouponSend.getExpired(), 0)) {
wxCouponSend.setMerchantLnventory(0);
}
wxCouponSend.setStatus(wxCouponSend.getStatus());
//库存大于0
if (Objects.isNull(wxCouponSend.getSortColumn())) {
wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
}
final PageInfo<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize);

for (WxCouponSendVo cs : page.getList()) {
cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId()));
}
return new ResultData(page);
}
for (WxCouponSendVo cs : page.getList()) {
cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId()));
}
return new ResultData(page);
}

@ApiOperation("商户注券")
@PostMapping("/handSel")
@ApiImplicitParams({
@ApiImplicitParam(name = "wxCouponSendIds", value = "CouponSend ID数组", dataType = "string",allowMultiple=true, paramType = "query", required = true),
@ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query", required = true),
})
public ResultData handSel(String[] wxCouponSendIds, Long cUserId) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::handSel");
WxCUser cu = wxCUserMapper.selectByPrimaryKey(cUserId);
if (Objects.isNull(cu)) {
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}
if (ArrayUtils.isEmpty(wxCouponSendIds)) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
@ApiOperation("商户注券")
@PostMapping("/handSel")
@ApiImplicitParams({
@ApiImplicitParam(name = "wxCouponSendIds", value = "CouponSend ID数组", dataType = "string", allowMultiple = true, paramType = "query", required = true),
@ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query", required = true),
})
public ResultData handSel(@RequestBody Map<String, Object> params) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::handSel");
if (CollectionUtils.isEmpty(params)) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
WxCUser cu = wxCUserMapper.selectByPrimaryKey(params.get("cUserId"));
if (Objects.isNull(cu)) {
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}

WxCouponSend wxCouponSend = new WxCouponSend();
wxCouponSend.setIds(Arrays.stream(wxCouponSendIds).map(Long::parseLong).collect(Collectors.toList()));
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode());
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode());
wxCouponSendService.handSel(wxCouponSend, cu);
return new ResultData();
}
if (!params.containsKey("wxCouponSendIds")) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}

@ApiOperation("注券记录")
@GetMapping("/actionLog")
@ApiImplicitParams({
@ApiImplicitParam(name = "channelType", value = "注券类型,商户注券=7", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "beginDate", value = "开始日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "endDate", value = "结束日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData sendLog(Integer channelType, String beginDate, String endDate, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::actionLog");
Map<String, Object> params = new HashMap<>();
if (Objects.nonNull(beginDate)) {
Date begin = DateUtils.stringToDate(beginDate);
params.put("beginDate", begin);
}
List<String> wxCouponSendIds = (List<String>) params.get("wxCouponSendIds");
if (CollectionUtils.isEmpty(wxCouponSendIds)) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}

if (Objects.nonNull(endDate)) {
Date end = DateUtils.stringToDate(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(end);
cal.add(Calendar.DATE, 1);
params.put("endDate", cal.getTime());
}
params.put("tenantId", getTenantId());
params.put("channelType", channelType);
params.put("merchantId", getUser().getMerchantId());
PageInfo<WxCouponActionLogVo> data = wxCouponActionLogService.getActionLog(params, pageNum, pageSize);
return new ResultData(data);
}
WxCouponSend wxCouponSend = new WxCouponSend();
wxCouponSend.setIds(wxCouponSendIds.stream().map(Long::parseLong).collect(Collectors.toList()));
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode());
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode());
wxCouponSendService.handSel(wxCouponSend, cu);
return new ResultData();
}

@ApiOperation("注券记录")
@GetMapping("/actionLog")
@ApiImplicitParams({
@ApiImplicitParam(name = "channelType", value = "注券类型,商户注券=7", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "beginDate", value = "开始日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "endDate", value = "结束日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData sendLog(Integer channelType, String beginDate, String endDate, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::actionLog");
Map<String, Object> params = new HashMap<>();
if (Objects.nonNull(beginDate)) {
Date begin = DateUtils.stringToDate(beginDate);
params.put("beginDate", begin);
}

if (Objects.nonNull(endDate)) {
Date end = DateUtils.stringToDate(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(end);
cal.add(Calendar.DATE, 1);
params.put("endDate", cal.getTime());
}
params.put("tenantId", getTenantId());
params.put("channelType", channelType);
params.put("merchantId", getUser().getMerchantId());
PageInfo<WxCouponActionLogVo> data = wxCouponActionLogService.getActionLog(params, pageNum, pageSize);
return new ResultData(data);
}


}

+ 0
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java View File

@@ -41,7 +41,6 @@ public class WxCouponSend extends BaseEntity {
/**
* 商户购券数
*/
@Transient
protected Integer merchantLnventory;

/**发卷所属商户名**/


+ 2
- 0
mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java View File

@@ -27,4 +27,6 @@ public class WxCouponActionLogVo implements Serializable{
private Long couponId ;
@io.swagger.annotations.ApiModelProperty(value="couponSend ID",name="couponSendId")
private Long couponSendId ;
//@io.swagger.annotations.ApiModelProperty(value="tenantId",name="tenantId")
//private String tenantId ;
}

+ 1
- 1
mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java View File

@@ -8,7 +8,7 @@ import com.iformall.domain.vo.WxCouponSendVo;
public interface WxCouponSendMapper extends CommonMapper<WxCouponSend, String> {

List<WxCouponSendVo> findListVo(WxCouponSend wxCouponSend);
List<WxCouponSendVo> findListVoByNameAndDate(WxCouponSend wxCouponSend);
List<WxCouponSendVo> findListVoByValidType(WxCouponSend wxCouponSend);

void updateStatusByCouponId(WxCouponSend wxCouponSend);



+ 1
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java View File

@@ -1,6 +1,5 @@
package com.iformall.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -13,7 +12,6 @@ import com.iformall.domain.po.msg.MpAppMsg;
import com.iformall.domain.po.msg.WxMsgRecord;
import com.iformall.domain.vo.WxCouponSendVo;
import com.iformall.enums.*;
import com.iformall.exception.BizMessageException;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;
import com.iformall.mq.MqBaseProducer;
@@ -25,7 +23,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@@ -72,7 +69,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {
PageInfo<WxCouponSendVo> pageInfo;
//设置商户购买券数
if (Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), record.getSendType())) {
pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoByNameAndDate(record));
pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSendMapper.findListVoByValidType(record));
for (WxCouponSendVo cs : pageInfo.getList()) {
JSONObject jo = JSONObject.parseObject(cs.getConditions());
int inventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY);


+ 3
- 4
mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml View File

@@ -227,14 +227,13 @@
LEFT JOIN wx_coupon c ON cal.coupon_id = c.id
LEFT JOIN wx_c_user cu ON cu.id = co.c_user_id
LEFT JOIN wx_merchant_b_user mbu ON co.b_user_id = mbu.id
WHERE cal.tenant_id = #{tenantId}
AND cal.channel_type = #{channelType}
AND mbu.merchant_id = #{merchantId}
WHERE cal.channel_type = #{channelType}
AND cs.conditions -> '$.id' = concat(#{merchantId},'')
<if test=" null != beginDate ">
and cal.create_time &gt;= #{beginDate}
</if>
<if test=" null != endDate ">
and cal.create_time &lt;= #{endDate}
and cal.create_time &lt; #{endDate}
</if>
</select>



+ 26
- 17
mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml View File

@@ -24,7 +24,7 @@
</resultMap>

<sql id="allColumns">
cs.id,cs.tenant_id,cs.coupon_id,cs.title,cs.send_type,cs.conditions,cs.status,cs.create_date,cs.update_date,
cs.id,cs.tenant_id,cs.coupon_id,cs.title,cs.send_type,cs.conditions,cs.status,cs.create_date,cs.update_date,JSON_EXTRACT(cs.conditions,'$.merchantLnventory') as merchantLnventory,
(case when
(select count(*) from wx_coupon_merchant xcm where xcm.product_id = cs.coupon_id and xcm.status = 0)=1
then
@@ -104,27 +104,36 @@
<include refid="dynamicWhereConditions" />
</select>

<select id="findListVoByNameAndDate" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap">
<select id="findListVoByValidType" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap">
select tt.* from (select
<include refid="allColumns"/>
from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id
<include refid="dynamicWhereConditions"/>) as tt
where
(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>
)
or tt.valid_type=2
where tt.status = 0
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>
)
</select>

<update id="updateStatusByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel">
update wx_coupon_send set status=#{status}
where coupon_id=#{couponId}


Loading…
Cancel
Save