| @@ -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<Long> 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<Long> 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); | |||
| @@ -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 = "会员管理-查询会员用户人群") | |||
| @@ -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<WxCUserBasicInfoFilterDto> tagList; | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| public List<WxCUserBasicInfoFilterDto> getTagList() { | |||
| return tagList; | |||
| } | |||
| public void setTagList(List<WxCUserBasicInfoFilterDto> tagList) { | |||
| this.tagList = tagList; | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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<WxTags> tagsList; | |||
| public List<WxTags> getTagsList() { | |||
| return tagsList; | |||
| } | |||
| public void setTagsList(List<WxTags> tagsList) { | |||
| this.tagsList = tagsList; | |||
| @Transient | |||
| List<WxCUserBasicInfoFilterListDto> filterList; | |||
| public List<WxCUserBasicInfoFilterListDto> getFilterList() { | |||
| return filterList; | |||
| } | |||
| public void setFilterList(List<WxCUserBasicInfoFilterListDto> filterList) { | |||
| this.filterList = filterList; | |||
| } | |||
| public static enum Field | |||
| { | |||
| @@ -12,14 +12,8 @@ public interface WxCUserTagsMapper extends CommonMapper<WxCUserTags, String> { | |||
| List<WxCUserTags> findList(WxCUserTags wxCUserTags); | |||
| long findCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); | |||
| long findCUserCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); | |||
| List<Long> findByTags(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId); | |||
| List<Long> 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); | |||
| @@ -16,8 +16,6 @@ public interface WxCUserTagsService { | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param offset | |||
| * @param limit | |||
| * @return | |||
| */ | |||
| PageInfo<WxCUserTags> 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<WxCUserBasicInfo> findByTag(String tenantId, List<Long> tagIds); | |||
| /** | |||
| * | |||
| * tagIds查询用户user信息集合(登陆过C端的用户,并且保有手机号) | |||
| * @param tagIds | |||
| * @return | |||
| */ | |||
| List<WxCUser> findCUserByTag(String tenantId, List<Long> tagIds); | |||
| long countUser(String tenantId, Long tagId, Date startTime, Date endTime ); | |||
| List<WxTags> findTagList(String tenantId, List<Long> tagIds); | |||
| List<WxTags> findTagListFromCUser(String tenantId, List<Long> tagIds); | |||
| List<WxTags> assignTags(List<Long> tagIdList, WxCUserBasicInfo user); | |||
| List<WxTags> triggerAssignTags(EnumAssignTagsTrigger trigger, Object obj); | |||
| @@ -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<WxCUser> findCUserByTag(String tenantId, List<Long> tagIds) { | |||
| if (tagIds == null || tagIds.isEmpty()) | |||
| return new ArrayList<WxCUser>(); | |||
| Set<Long> hs = new HashSet<>(); | |||
| for (Long tagId:tagIds) { | |||
| String str = JSON.toJSONString(tagId); | |||
| hs.addAll(wxCUserTagsMapper.findCUserByTags(str, tenantId)); | |||
| } | |||
| if(hs.isEmpty()){ | |||
| return new ArrayList<WxCUser>(); | |||
| } | |||
| List<Long> userIds = new ArrayList<>(); | |||
| userIds.addAll(hs); | |||
| WxCUser wxCUser = new WxCUser(); | |||
| wxCUser.setTenantId(tenantId); | |||
| wxCUser.setIds(userIds); | |||
| return wxCUserMapper.findList(wxCUser); | |||
| } | |||
| @Override | |||
| public List<WxCUserBasicInfo> findByTag(String tenantId, List<Long> tagIds) { | |||
| if (tagIds == null || tagIds.isEmpty()) | |||
| @@ -145,20 +114,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| wxTags.setIds(tagIds); | |||
| List<WxTags> list = wxTagsMapper.findList(wxTags); | |||
| for (WxTags t : list) { | |||
| t.setCount(findCountByTag(tenantId,t.getId())); | |||
| } | |||
| return list; | |||
| } | |||
| @Override | |||
| public List<WxTags> findTagListFromCUser(String tenantId, List<Long> tagIds) { | |||
| if (tagIds == null || tagIds.isEmpty()) | |||
| return new ArrayList<WxTags>(); | |||
| WxTags wxTags =new WxTags(); | |||
| wxTags.setIds(tagIds); | |||
| List<WxTags> list = wxTagsMapper.findList(wxTags); | |||
| for (WxTags t : list) { | |||
| t.setCount(findCUserCountByTag(tenantId,t.getId())); | |||
| t.setCount(countUser(tenantId,t.getId(),null,null)); | |||
| } | |||
| return list; | |||
| } | |||
| @@ -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<Long> tagids = new ArrayList<>(); | |||
| for (int i = 0; i < arys.length; i++) { | |||
| tagids.add(Long.parseLong(arys[i])); | |||
| } | |||
| HashSet<WxCUserBasicInfo> userSet = new HashSet<>(); | |||
| record.getFilterList().stream().forEach(f->{ | |||
| userSet.addAll(wxCUserBasicInfoService.listByFilter(record.getTenantId(),f.getTagList())); | |||
| }); | |||
| List<WxCUserBasicInfo>userList = new ArrayList<>(userSet); | |||
| List<WxCUser> 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<WxCUser> sentUsers = sendCoupon(wxCoupon, cUsers, record); | |||
| List<WxCUser> 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<WxCUser> sendCoupon(WxCoupon wxCoupon,List<WxCUser> cUsers,WxCouponInject record){ | |||
| private List<WxCUser> sendCoupon(WxCoupon wxCoupon,List<WxCUserBasicInfo> cUsers,WxCouponInject record){ | |||
| //查询标签用户 | |||
| List<WxCUser> sentUsers = new ArrayList<WxCUser>(); | |||
| 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; | |||
| @@ -63,32 +63,12 @@ | |||
| </select> | |||
| <select id="findCountByTags" resultType="java.lang.Long"> | |||
| select count(user_id) from wx_c_user_tags cut | |||
| where JSON_CONTAINS(tags,#{tagIds} ) | |||
| and cut.tenant_id = #{tenantId}; | |||
| </select> | |||
| <select id="findCUserCountByTags" resultType="java.lang.Long"> | |||
| select count(user_id) from wx_c_user_tags cut, wx_c_user cu | |||
| where cut.user_id = cu.id | |||
| and JSON_CONTAINS(tags,#{tagIds} ) | |||
| and cut.tenant_id = #{tenantId}; | |||
| </select> | |||
| <select id="findByTags" resultType="java.lang.Long"> | |||
| select user_id from wx_c_user_tags cut | |||
| where JSON_CONTAINS(tags,#{tagIds} ) | |||
| and cut.tenant_id = #{tenantId}; | |||
| </select> | |||
| <select id="findCUserByTags" resultType="java.lang.Long"> | |||
| select user_id from wx_c_user_tags cut, wx_c_user cu | |||
| where cut.user_id = cu.id | |||
| and JSON_CONTAINS(tags,#{tagIds} ) | |||
| and cut.tenant_id = #{tenantId}; | |||
| </select> | |||
| <update id="updateNewId" parameterType="com.iformall.domain.vo.CUserTagVo"> | |||
| update wx_c_user_tags | |||
| set user_id=#{newUserId} | |||