| @@ -19,8 +19,8 @@ public interface WxCouponMerchantMapper extends CommonMapper<WxCouponMerchant, L | |||
| List<WxMerchantVo> findMerchantNameList(@Param("productId")Long productId,@Param("tenantId")String tenantId); | |||
| List<WxMerchantVo> findMerchantBaseList(@Param("productId")Long productId,@Param("tenantId")String tenantId); | |||
| List<WxMerchantProductVo> findMerchantProduct(@Param("tenantId")String tenantId,@Param("merchantIdList")List<Long> merchantIdList); | |||
| List<WxMerchantProductVo> findOnlyMerchantProduct(@Param("tenantId")String tenantId,@Param("merchantIdList")List<Long> merchantIdList); | |||
| List<Long> findMerchantProductIds(@Param("tenantId")String tenantId,@Param("merchantIdList")List<Long> merchantIdList,@Param("status")Integer status); | |||
| List<Long> findOneMerchantProductIds(@Param("tenantId")String tenantId,@Param("merchantId")Long merchantId); | |||
| List<Long> findMerchantByProductIds(@Param("tenantId")String tenantId,@Param("productIds")List<Long> productIds); | |||
| List<Long> findMerchantByProductId(@Param("tenantId")String tenantId,@Param("productId")Long productId); | |||
| List<Long> findOnlyMerchantByProductIds(@Param("tenantId")String tenantId,@Param("productIds")List<Long> productIds); | |||
| } | |||
| @@ -259,7 +259,7 @@ public interface WxCouponService { | |||
| * 获取券商户map | |||
| * | |||
| */ | |||
| Map<Long,String> getCouponMerchantMap(List<Long> couponIds,TenantEntity tenantEntity); | |||
| Map<Long,String> getCouponMerchantMap(List<Long> couponIds,TenantEntity tenantEntity,boolean onlyOneMerchantCoupons); | |||
| Map<Long, WxCoupon> getCouponMap(List<Long> couponIds, TenantEntity tenantEntity); | |||
| } | |||
| @@ -317,7 +317,9 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||
| return; | |||
| } | |||
| if(wxCouponChannel.getMerchantId() != null){ | |||
| List<Long> mcids = wxCouponMerchantMapper.findOneMerchantProductIds(wxCouponChannel.getTenantId(), wxCouponChannel.getMerchantId()); | |||
| List<Long> merchantIds = new ArrayList<Long>(); | |||
| merchantIds.add(wxCouponChannel.getMerchantId()); | |||
| List<Long> mcids = wxCouponMerchantMapper.findMerchantProductIds(wxCouponChannel.getTenantId(), merchantIds,0); | |||
| if(mcids == null || mcids.isEmpty()){ | |||
| wxCouponChannel.setId(-999L); | |||
| return; | |||
| @@ -291,22 +291,25 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| dateMap.put("endDateTimes", endDate.getTime()); | |||
| List<Long> merchantIdList = new ArrayList<Long>(); | |||
| merchantIdList.add(wxMerchant.getId()); | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(wxMerchant.getTenantId(), merchantIdList); | |||
| if (null != merchantProductVos) { | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findOnlyMerchantProduct(wxMerchant.getTenantId(), merchantIdList); | |||
| if (null != merchantProductVos && merchantProductVos.size() > 0 ){ | |||
| List<Long> couponIds = new ArrayList<Long>(); | |||
| for (int i = 0 ; i < merchantProductVos.size(); i ++) { | |||
| WxMerchantProductVo mp = merchantProductVos.get(i); | |||
| if (mp.getMc() == 1) { | |||
| if (!couponIds.contains(mp.getProductId())) { | |||
| couponIds.add(mp.getProductId()); | |||
| } | |||
| } | |||
| if (!couponIds.contains(mp.getProductId())) { | |||
| couponIds.add(mp.getProductId()); | |||
| } | |||
| } | |||
| if (couponIds.size() > 0 ) { | |||
| dateMap.put("couponIds", couponIds); | |||
| list = wxCouponOrderMapper.findListOfOrderedByDate(dateMap); | |||
| }else { | |||
| list = new ArrayList<WxCouponOrder>(); | |||
| } | |||
| }else { | |||
| list = new ArrayList<WxCouponOrder>(); | |||
| } | |||
| list = wxCouponOrderMapper.findListOfOrderedByDate(dateMap); | |||
| } | |||
| //logger.info("find " + list.size() + " coupon order from " + /startDate + " to " + new Date()); | |||
| resultMap.put("amount", list.stream().mapToInt(p -> p.getCouponPrice()).sum()); | |||
| @@ -350,29 +353,35 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| dateMap.put("endDateTimes", endDate.getTime()); | |||
| List<Long> merchantIdList = new ArrayList<Long>(); | |||
| merchantIdList.add(merchantId); | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), merchantIdList); | |||
| if (null != merchantProductVos) { | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findOnlyMerchantProduct(tenantEntity.getTenantId(), merchantIdList); | |||
| PageInfo<WxCouponOrder> couponOrderPage = null; | |||
| if (null != merchantProductVos && merchantProductVos.size() > 0 ) { | |||
| List<Long> couponIds = new ArrayList<Long>(); | |||
| for (int i = 0 ; i < merchantProductVos.size(); i ++) { | |||
| WxMerchantProductVo mp = merchantProductVos.get(i); | |||
| if (mp.getMc() == 1) { | |||
| if (!couponIds.contains(mp.getProductId())) { | |||
| couponIds.add(mp.getProductId()); | |||
| } | |||
| } | |||
| if (!couponIds.contains(mp.getProductId())) { | |||
| couponIds.add(mp.getProductId()); | |||
| } | |||
| } | |||
| if (couponIds.size() > 0 ) { | |||
| dateMap.put("couponIds", couponIds); | |||
| couponOrderPage = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() ->wxCouponOrderMapper.findListOfOrderedByDateForBUser(dateMap)); | |||
| } | |||
| } | |||
| PageInfo<WxCouponOrder> couponOrderPage = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() ->wxCouponOrderMapper.findListOfOrderedByDateForBUser(dateMap)); | |||
| PageInfo<WxCouponOrderBVo> pageInfo = new PageInfo<WxCouponOrderBVo>(); | |||
| pageInfo.setList(handleToCouponOrderBVoList(tenantEntity,couponOrderPage.getList(),false,false)); | |||
| pageInfo.setPageNum(couponOrderPage.getPageNum()); | |||
| pageInfo.setPageSize(couponOrderPage.getPageSize()); | |||
| pageInfo.setPages(couponOrderPage.getPages()); | |||
| pageInfo.setTotal(couponOrderPage.getTotal()); | |||
| if (null != couponOrderPage) { | |||
| pageInfo.setList(handleToCouponOrderBVoList(tenantEntity,couponOrderPage.getList(),false,false)); | |||
| pageInfo.setPageNum(couponOrderPage.getPageNum()); | |||
| pageInfo.setPageSize(couponOrderPage.getPageSize()); | |||
| pageInfo.setPages(couponOrderPage.getPages()); | |||
| pageInfo.setTotal(couponOrderPage.getTotal()); | |||
| }else { | |||
| pageInfo.setList(null); | |||
| pageInfo.setPageNum(pageIndex); | |||
| pageInfo.setPageSize(pageSize); | |||
| pageInfo.setPages(0); | |||
| pageInfo.setTotal(0); | |||
| } | |||
| return pageInfo; | |||
| } | |||
| @@ -129,7 +129,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| pageInfo.setPageSize(sendPageInfo.getPageSize()); | |||
| pageInfo.setPages(sendPageInfo.getPages()); | |||
| pageInfo.setTotal(sendPageInfo.getTotal()); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),true,false)); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),true,false,true)); | |||
| } else { | |||
| record.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| record.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||
| @@ -139,7 +139,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| pageInfo.setPageSize(sendPageInfo.getPageSize()); | |||
| pageInfo.setPages(sendPageInfo.getPages()); | |||
| pageInfo.setTotal(sendPageInfo.getTotal()); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),false,true)); | |||
| pageInfo.setList(couponSendToVoList(record,sendPageInfo.getList(),false,true,true)); | |||
| } | |||
| return pageInfo; | |||
| } | |||
| @@ -147,10 +147,10 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| @Override | |||
| public List<WxCouponSendVo> findListVo(WxCouponSend record) { | |||
| List<WxCouponSend> couponSendList = wxCouponSendMapper.findList(record); | |||
| return couponSendToVoList(record,couponSendList,false,false); | |||
| return couponSendToVoList(record,couponSendList,false,false,false); | |||
| } | |||
| private List<WxCouponSendVo> couponSendToVoList(TenantEntity tenantEntity,List<WxCouponSend> couponSendList,boolean setInventoryAndExpired,boolean setMerchantNameAndSendCount) { | |||
| private List<WxCouponSendVo> couponSendToVoList(TenantEntity tenantEntity,List<WxCouponSend> couponSendList,boolean setInventoryAndExpired,boolean setMerchantNameAndSendCount,boolean onlyOneMerchantCoupons) { | |||
| if (null != couponSendList) { | |||
| List<Long> couponIdList = new ArrayList<>(); | |||
| List<Long> mallUserInfoIdList = new ArrayList<Long>(); | |||
| @@ -199,7 +199,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||
| //couponMerchant | |||
| Map<Long, String> couponMerchantMap = null; | |||
| if (setMerchantNameAndSendCount) { | |||
| couponMerchantMap = wxCouponService.getCouponMerchantMap(couponIdList,tenantEntity); | |||
| couponMerchantMap = wxCouponService.getCouponMerchantMap(couponIdList,tenantEntity,onlyOneMerchantCoupons); | |||
| } | |||
| List<WxCouponSendVo> retList = new ArrayList<WxCouponSendVo>(); | |||
| for (int i = 0 ; i <couponSendList.size() ; i++) { | |||
| @@ -962,11 +962,18 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| @Override | |||
| public Map<Long, String> getCouponMerchantMap(List<Long> couponIds, TenantEntity tenantEntity) { | |||
| public Map<Long, String> getCouponMerchantMap(List<Long> couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) { | |||
| Map<Long,String> couponMerchantMap = new HashMap<Long,String>(); | |||
| if(null != couponIds && couponIds.size() > 0){ | |||
| List<Long> merchantIds = wxCouponMerchantMapper.findMerchantByProductIds(tenantEntity.getTenantId(),couponIds); | |||
| List<Long> merchantIds = null; | |||
| if (onlyOneMerchantCoupons) { | |||
| merchantIds = wxCouponMerchantMapper.findOnlyMerchantByProductIds(tenantEntity.getTenantId(),couponIds); | |||
| }else { | |||
| merchantIds = wxCouponMerchantMapper.findMerchantByProductIds(tenantEntity.getTenantId(),couponIds); | |||
| } | |||
| if (null == merchantIds) { | |||
| return couponMerchantMap; | |||
| } | |||
| WxMerchant merchantQ = new WxMerchant(); | |||
| merchantQ.updateTenantInfo(tenantEntity); | |||
| merchantQ.setIds(merchantIds); | |||
| @@ -979,8 +986,13 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| } | |||
| } | |||
| List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), merchantIds); | |||
| if (null != merchantProductVos) { | |||
| List<WxMerchantProductVo> merchantProductVos = null; | |||
| if (onlyOneMerchantCoupons) { | |||
| merchantProductVos = wxCouponMerchantMapper.findOnlyMerchantProduct(tenantEntity.getTenantId(), merchantIds); | |||
| }else { | |||
| merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), merchantIds); | |||
| } | |||
| if (null != merchantProductVos && merchantProductVos.size() > 0 ) { | |||
| for (int i = 0 ; i < merchantProductVos.size(); i ++) { | |||
| WxMerchantProductVo mp = merchantProductVos.get(i); | |||
| if(couponIds.contains(mp.getProductId())){ | |||
| @@ -186,26 +186,48 @@ | |||
| </if> | |||
| </select> | |||
| <select id = "findOneMerchantProductIds" parameterType="java.util.Map" resultType="Long"> | |||
| SELECT wcm.product_id | |||
| <select id = "findMerchantByProductIds" parameterType="java.util.Map" resultType="Long"> | |||
| SELECT distinct wcm.merchant_id | |||
| FROM wx_coupon_merchant wcm | |||
| WHERE wcm.STATUS = 0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and wcm.`tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != merchantId"> | |||
| and wcm.merchant_id = #{merchantId} | |||
| <if test=" null != productIds"> | |||
| and wcm.product_id in | |||
| <foreach collection="productIds" index="index" item="productIdItem" open="(" separator="," close=")"> | |||
| #{productIdItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <select id = "findMerchantByProductIds" parameterType="java.util.Map" resultType="Long"> | |||
| <select id = "findOnlyMerchantProduct" parameterType="java.util.Map" resultMap="MerchantProductVoResultMap"> | |||
| SELECT wcm.product_id,wcm.merchant_id,COUNT(1) AS mc | |||
| FROM wx_coupon_merchant wcm | |||
| WHERE wcm.STATUS = 0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and wcm.`tenant_id` = #{tenantId} | |||
| </if> | |||
| GROUP BY product_id | |||
| HAVING mc = 1 | |||
| <if test=" null != merchantIdList"> | |||
| and wcm.merchant_id in | |||
| <foreach collection="merchantIdList" index="index" item="merchantIdItem" open="(" separator="," close=")"> | |||
| #{merchantIdItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <select id = "findOnlyMerchantByProductIds" parameterType="java.util.Map" resultType="Long"> | |||
| SELECT distinct wcm.merchant_id | |||
| FROM wx_coupon_merchant wcm | |||
| WHERE wcm.STATUS = 0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and wcm.`tenant_id` = #{tenantId} | |||
| </if> | |||
| GROUP BY product_id | |||
| HAVING COUNT(merchant_id) = 1 | |||
| <if test=" null != productIds"> | |||
| and wcm.product_id in | |||
| <foreach collection="productIds" index="index" item="productIdItem" open="(" separator="," close=")"> | |||
| @@ -213,17 +235,5 @@ | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <select id = "findMerchantByProductId" parameterType="java.util.Map" resultType="Long"> | |||
| SELECT merchant_id | |||
| FROM wx_coupon_merchant | |||
| WHERE STATUS = 0 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != productId"> | |||
| and product_id = #{productId} | |||
| </if> | |||
| </select> | |||
| </mapper> | |||