From 7833bfc77ede410b3fbef0f756c57434bb163709 Mon Sep 17 00:00:00 2001 From: hupeng Date: Wed, 17 Apr 2019 19:58:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=A0=87=E7=AD=BE][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E6=A0=87=E7=AD=BE=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCouponInjectController.java | 13 +---- .../iformall/controller/WxTagsController.java | 8 --- .../dto/WxCUserBasicInfoFilterListDto.java | 36 ++++++++++++ .../iformall/domain/po/WxCUserBasicInfo.java | 21 +++++++ .../iformall/domain/po/WxCouponInject.java | 18 ++++-- .../iformall/mapper/WxCUserTagsMapper.java | 6 -- .../iformall/service/WxCUserTagsService.java | 19 +------ .../service/impl/WxCUserTagsServiceImpl.java | 46 +--------------- .../impl/WxCouponInjectServiceImpl.java | 55 +++++++++++-------- .../resources/mapper/WxCUserTagsMapper.xml | 20 ------- 10 files changed, 106 insertions(+), 136 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/dto/WxCUserBasicInfoFilterListDto.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponInjectController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponInjectController.java index 5aeae3818..531e17ebd 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponInjectController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponInjectController.java @@ -69,12 +69,8 @@ public class WxCouponInjectController extends BaseController { @SystemControllerLog(description = "精准投放-更新") public ResultData update(@RequestBody WxCouponInject couponInject) { logger.debug("[" + getIpAddr() + "] WxCouponInjectController::update"); - String[] arys = couponInject.getTags().split(","); - List tagids = new ArrayList<>(); - for (int i = 0; i < arys.length; i++) { - tagids.add(Long.parseLong(arys[i])); - } - couponInject.setTags(JSON.toJSONString(arys)); + + couponInject.setTags(JSON.toJSONString(couponInject.getFilterList())); wxCouponInjectService.saveOrUpdate(couponInject); return new ResultData(); } @@ -97,11 +93,6 @@ public class WxCouponInjectController extends BaseController { logger.debug("[" + getIpAddr() + "] WxCouponInjectController::findById"); WxCouponInject couponInject = wxCouponInjectService.getById(id); if (couponInject != null) { - List tagids = JSON.parseArray(couponInject.getTags(), Long.class); - if (!tagids.isEmpty()) { - couponInject.setTagsList(wxCUserTagsService.findTagList(getTenantId(), tagids)); - } - couponInject.setMsgModel(wxMsgModelService.getById(couponInject.getModelId())); } return new ResultData(Result.SUCCESS, "查询成功", couponInject); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxTagsController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxTagsController.java index b6dc11f35..b0ea4e04a 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxTagsController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxTagsController.java @@ -48,14 +48,6 @@ public class WxTagsController extends BaseController { return new ResultData(wxTagsService.listAllVo()); } - @ApiOperation("查询微信用户人群") - @GetMapping("findCUserCountByTag") - @SystemControllerLog(description = "会员管理-查询微信用户人群") - public Result findCUserCountByTag(Long[] tagIds) { - logger.debug("[" + getIpAddr() + "] WxTagsController::findCUserCountByTag"); - return new ResultData(wxCUserTagsService.findTagListFromCUser(getTenantId(), Arrays.asList(tagIds))); - } - @ApiOperation("查询会员用户人群") @GetMapping("findCountByTag") @SystemControllerLog(description = "会员管理-查询会员用户人群") diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserBasicInfoFilterListDto.java b/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserBasicInfoFilterListDto.java new file mode 100644 index 000000000..db89ff99d --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/dto/WxCUserBasicInfoFilterListDto.java @@ -0,0 +1,36 @@ +package com.iformall.domain.dto; + +import java.io.Serializable; +import java.util.List; + +/** + * 用户查询dto + * @author jinguo + * + */ +public class WxCUserBasicInfoFilterListDto implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -1116465873573690766L; + + String name; + List tagList; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTagList() { + return tagList; + } + + public void setTagList(List tagList) { + this.tagList = tagList; + } +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java index adfb83cdf..5367212a5 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java @@ -10,6 +10,7 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; import java.util.List; +import java.util.Objects; @Table(name = "wx_c_user_basic_info") public class WxCUserBasicInfo implements Serializable { @@ -385,4 +386,24 @@ public class WxCUserBasicInfo implements Serializable { this.setSortColumns(Field.valueOf(sortColumns)); } } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + final WxCUserBasicInfo user = (WxCUserBasicInfo) obj; + if (this == user) { + return true; + } else { + return (this.id.equals(user.id)); + } + } + + @Override + + public int hashCode() { + return Objects.hash(this.phone); + } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponInject.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponInject.java index 9da11bad3..44bd77c3c 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponInject.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponInject.java @@ -1,5 +1,8 @@ package com.iformall.domain.po; +import com.iformall.domain.dto.WxCUserBasicInfoFilterDto; +import com.iformall.domain.dto.WxCUserBasicInfoFilterListDto; + import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; @@ -91,6 +94,7 @@ public class WxCouponInject implements Serializable { /*发送人群标签**/ @io.swagger.annotations.ApiModelProperty(value="发送人群标签",name="tags") private String tags; + @io.swagger.annotations.ApiModelProperty(value="",name="modelId") private Long modelId; /*创建时间**/ @@ -220,16 +224,18 @@ public class WxCouponInject implements Serializable { this.msgId = msgId; } - List tagsList; - public List getTagsList() { - return tagsList; - } - public void setTagsList(List tagsList) { - this.tagsList = tagsList; + @Transient + List filterList; + + public List getFilterList() { + return filterList; } + public void setFilterList(List filterList) { + this.filterList = filterList; + } public static enum Field { diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCUserTagsMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCUserTagsMapper.java index 0691e259f..0261c145e 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCUserTagsMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCUserTagsMapper.java @@ -12,14 +12,8 @@ public interface WxCUserTagsMapper extends CommonMapper { List findList(WxCUserTags wxCUserTags); - long findCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); - - long findCUserCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); - List findByTags(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId); - List findCUserByTags(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId); - long countUser(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId, @Param("startTime")Date startTime,@Param("endTime")Date endTime); diff --git a/mallinkService/src/main/java/com/iformall/service/WxCUserTagsService.java b/mallinkService/src/main/java/com/iformall/service/WxCUserTagsService.java index b2e243a13..9422a9e7c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCUserTagsService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCUserTagsService.java @@ -16,8 +16,6 @@ public interface WxCUserTagsService { * 根据实体查询分页列表 * * @param record - * @param offset - * @param limit * @return */ PageInfo listAsPage(WxCUserTags record, Integer pageIndex, Integer pageSize); @@ -45,27 +43,12 @@ public interface WxCUserTagsService { void deleteById(Long id); - /** - * - * tagIds查询用户user信息集合(会员列表中的user) - * @param tagIds - * @return - */ List findByTag(String tenantId, List tagIds); - /** - * - * tagIds查询用户user信息集合(登陆过C端的用户,并且保有手机号) - * @param tagIds - * @return - */ - List findCUserByTag(String tenantId, List tagIds); - - long countUser(String tenantId, Long tagId, Date startTime, Date endTime ); List findTagList(String tenantId, List tagIds); - List findTagListFromCUser(String tenantId, List tagIds); + List assignTags(List tagIdList, WxCUserBasicInfo user); List triggerAssignTags(EnumAssignTagsTrigger trigger, Object obj); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserTagsServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserTagsServiceImpl.java index 52ced667b..167eda959 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserTagsServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserTagsServiceImpl.java @@ -79,43 +79,12 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { } - private long findCountByTag(String tenantId, Long tagId) { - String str = JSON.toJSONString(tagId); - return wxCUserTagsMapper.findCountByTags(str,tenantId); - } - - private long findCUserCountByTag(String tenantId, Long tagId) { - String str = JSON.toJSONString(tagId); - return wxCUserTagsMapper.findCUserCountByTags(str,tenantId); - } - @Override public long countUser(String tenantId, Long tagId, Date startTime, Date endTime ) { String str = JSON.toJSONString(tagId); return wxCUserTagsMapper.countUser(str, tenantId, startTime, endTime); } - @Override - public List findCUserByTag(String tenantId, List tagIds) { - if (tagIds == null || tagIds.isEmpty()) - return new ArrayList(); - Set hs = new HashSet<>(); - - for (Long tagId:tagIds) { - String str = JSON.toJSONString(tagId); - hs.addAll(wxCUserTagsMapper.findCUserByTags(str, tenantId)); - } - if(hs.isEmpty()){ - return new ArrayList(); - } - List userIds = new ArrayList<>(); - userIds.addAll(hs); - WxCUser wxCUser = new WxCUser(); - wxCUser.setTenantId(tenantId); - wxCUser.setIds(userIds); - return wxCUserMapper.findList(wxCUser); - } - @Override public List findByTag(String tenantId, List tagIds) { if (tagIds == null || tagIds.isEmpty()) @@ -145,20 +114,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { wxTags.setIds(tagIds); List list = wxTagsMapper.findList(wxTags); for (WxTags t : list) { - t.setCount(findCountByTag(tenantId,t.getId())); - } - return list; - } - - @Override - public List findTagListFromCUser(String tenantId, List tagIds) { - if (tagIds == null || tagIds.isEmpty()) - return new ArrayList(); - WxTags wxTags =new WxTags(); - wxTags.setIds(tagIds); - List list = wxTagsMapper.findList(wxTags); - for (WxTags t : list) { - t.setCount(findCUserCountByTag(tenantId,t.getId())); + t.setCount(countUser(tenantId,t.getId(),null,null)); } return list; } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java index 7037147ea..df7cc1370 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponInjectServiceImpl.java @@ -17,9 +17,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; @Service public class WxCouponInjectServiceImpl implements WxCouponInjectService { @@ -27,16 +26,25 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { @Autowired WxCouponInjectMapper couponInjectMapper; + @Autowired WxCouponOrderService wxCouponOrderService; + @Autowired WxCouponService wxCouponService; + @Autowired - WxCUserTagsService wxCUserTagsService; + WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + WxCUserService wxCUserService; + @Autowired WxCouponActionLogService wxCouponActionLogService; + @Autowired WxMsgService wxMsgService; + @Autowired WxMsgModelService wxMsgModelService; @@ -100,23 +108,23 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); } - //解析前台tags,并转换json - String[] arys = record.getTags().split(","); - List tagids = new ArrayList<>(); - for (int i = 0; i < arys.length; i++) { - tagids.add(Long.parseLong(arys[i])); - } + HashSet userSet = new HashSet<>(); + + record.getFilterList().stream().forEach(f->{ + userSet.addAll(wxCUserBasicInfoService.listByFilter(record.getTenantId(),f.getTagList())); + }); + + ListuserList = new ArrayList<>(userSet); - List cUsers = wxCUserTagsService.findCUserByTag(record.getTenantId(), tagids); - if(cUsers.isEmpty()){ + if(userList.isEmpty()){ return new ResultData(ErrorCode.TAGS_MATCHED_NULL); } int inventory = wxCoupon.getRemainInventory();//库存数量 - if(cUsers.size()>inventory){ + if(userList.size()>inventory){ return new ResultData(ErrorCode.COUPON_IS_SELL_OUT); } - record.setTags(JSON.toJSONString(arys)); + record.setTags(JSON.toJSONString(record.getFilterList())); //生成雪花id final IdWorker idWorker = IdWorker.get(); @@ -129,15 +137,15 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { } record.setCouponName(wxCoupon.getTitle()); - record.setSendAmount(cUsers.size()); + record.setSendAmount(userList.size()); couponInjectMapper.insertSelective(record); if(record.getSendType().equals(EnumCouponInjectSendType.IMMEDIATE.getCode())) { - List sentUsers = sendCoupon(wxCoupon, cUsers, record); + List sentUsers = sendCoupon(wxCoupon, userList, record); if (sentUsers.size() > 0) { record.setStatus(EnumCouponInjectStatus.HAS_SENT.getCode()); //发送短信 - sendMsg(record, sentUsers); + //sendMsg(record, sentUsers); } else { record.setStatus(EnumCouponInjectStatus.SEND_FAILED.getCode()); } @@ -209,14 +217,17 @@ public class WxCouponInjectServiceImpl implements WxCouponInjectService { return new ResultData(); } - private List sendCoupon(WxCoupon wxCoupon,List cUsers,WxCouponInject record){ + private List sendCoupon(WxCoupon wxCoupon,List cUsers,WxCouponInject record){ //查询标签用户 List sentUsers = new ArrayList(); - for (WxCUser tempCUser : cUsers) { - boolean bResult = sendCouponToUser(tempCUser,wxCoupon,record.getId()); - if (bResult) { - sentUsers.add(tempCUser); + for (WxCUserBasicInfo tempCUserBasicInfo : cUsers) { + WxCUser tempCUser = wxCUserService.getById(tempCUserBasicInfo.getId()); + if (tempCUser != null) { + boolean bResult = sendCouponToUser(tempCUser, wxCoupon, record.getId()); + if (bResult) { + sentUsers.add(tempCUser); + } } } return sentUsers; diff --git a/mallinkService/src/main/resources/mapper/WxCUserTagsMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserTagsMapper.xml index 9f310200a..ff6f6c2e8 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserTagsMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserTagsMapper.xml @@ -63,32 +63,12 @@ - - - - - - update wx_c_user_tags set user_id=#{newUserId}