From 3c1df78d658799f39441a00fcd71be4b41e85cf7 Mon Sep 17 00:00:00 2001 From: Burce Date: Tue, 27 Aug 2019 06:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E6=B3=A8=E5=88=B8->=E6=B3=A8?= =?UTF-8?q?=E5=88=B8=E5=88=97=E8=A1=A8=EF=BC=8C=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCouponSendController.java | 182 +++++++++--------- .../com/iformall/domain/po/WxCouponSend.java | 1 - .../domain/vo/WxCouponActionLogVo.java | 2 + .../iformall/mapper/WxCouponSendMapper.java | 2 +- .../service/impl/WxCouponSendServiceImpl.java | 5 +- .../mapper/WxCouponActionLogMapper.xml | 7 +- .../resources/mapper/WxCouponSendMapper.xml | 43 +++-- 7 files changed, 129 insertions(+), 113 deletions(-) diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java index 1ff6f6d15..988f20990 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponSendController.java @@ -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 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 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 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 params = new HashMap<>(); - if (Objects.nonNull(beginDate)) { - Date begin = DateUtils.stringToDate(beginDate); - params.put("beginDate", begin); - } + List wxCouponSendIds = (List) 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 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 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 data = wxCouponActionLogService.getActionLog(params, pageNum, pageSize); + return new ResultData(data); + } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java index a05388604..90654a8f3 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponSend.java @@ -41,7 +41,6 @@ public class WxCouponSend extends BaseEntity { /** * 商户购券数 */ - @Transient protected Integer merchantLnventory; /**发卷所属商户名**/ diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java index 6da05ed4b..a676206ae 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponActionLogVo.java @@ -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 ; } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java index bef0407fb..04767920c 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponSendMapper.java @@ -8,7 +8,7 @@ import com.iformall.domain.vo.WxCouponSendVo; public interface WxCouponSendMapper extends CommonMapper { List findListVo(WxCouponSend wxCouponSend); - List findListVoByNameAndDate(WxCouponSend wxCouponSend); + List findListVoByValidType(WxCouponSend wxCouponSend); void updateStatusByCouponId(WxCouponSend wxCouponSend); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java index cd398b355..f1c57d16c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java @@ -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 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); diff --git a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml index 8f601cc06..74cd57456 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml @@ -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},'') and cal.create_time >= #{beginDate} - and cal.create_time <= #{endDate} + and cal.create_time < #{endDate} diff --git a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml index 214ba150c..66a0b4c32 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponSendMapper.xml @@ -24,7 +24,7 @@ - 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 @@ - select tt.* from (select from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id ) as tt - where - (tt.valid_type=1 - - - and = now() ]]> - - - and - - - - - ) - or tt.valid_type=2 + where tt.status = 0 + and ((tt.valid_type=1 + + + and = now() ]]> + + + and + + + + + ) + + + or + + + + + or + + + ) - update wx_coupon_send set status=#{status} where coupon_id=#{couponId}