| @@ -89,7 +89,7 @@ public class CouponInjectController extends BaseController { | |||||
| CouponInject couponInject = couponInjectService.getById(id); | CouponInject couponInject = couponInjectService.getById(id); | ||||
| if (couponInject != null) { | if (couponInject != null) { | ||||
| List<Long> tagids = JSON.parseArray(couponInject.getTags(), Long.class); | List<Long> tagids = JSON.parseArray(couponInject.getTags(), Long.class); | ||||
| couponInject.setWxChooseTagVo(wxCUserTagsService.findChooseTag(tagids)); | |||||
| couponInject.setWxChooseTagVo(wxCUserTagsService.findChooseTag(getTenantId(), tagids)); | |||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", couponInject); | return new ResultData(Result.SUCCESS, "查询成功", couponInject); | ||||
| } | } | ||||
| @@ -159,7 +159,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||||
| if (StringUtils.isNoneBlank(tagIds)) { | if (StringUtils.isNoneBlank(tagIds)) { | ||||
| info.setTagIds(tagIds.substring(0, tagIds.length() - 1)); | info.setTagIds(tagIds.substring(0, tagIds.length() - 1)); | ||||
| } | } | ||||
| long count = wxCUserTagsService.findCountByTag(tagIdList); | |||||
| long count = wxCUserTagsService.findCountByTag(getTenantId(), tagIdList); | |||||
| info.setCount(count); | info.setCount(count); | ||||
| } | } | ||||
| } | } | ||||
| @@ -113,7 +113,7 @@ public class WxTagsController extends BaseController { | |||||
| // } | // } | ||||
| // map.put("names",endName ); | // map.put("names",endName ); | ||||
| // map.put("tagIds", ids); | // map.put("tagIds", ids); | ||||
| long count = wxCUserTagsService.findCountByTag(Arrays.asList(tagIds)); | |||||
| long count = wxCUserTagsService.findCountByTag(getTenantId(), Arrays.asList(tagIds)); | |||||
| return new ResultData(Result.SUCCESS,"查询成功",count); | return new ResultData(Result.SUCCESS,"查询成功",count); | ||||
| } | } | ||||
| @@ -207,7 +207,13 @@ public enum ErrorCode{ | |||||
| /** | /** | ||||
| * 会员 | * 会员 | ||||
| */ | */ | ||||
| MEM_IMPORT_ERR(13000, "模板导入失败") | |||||
| MEM_IMPORT_ERR(13000, "模板导入失败"), | |||||
| /** | |||||
| * 标签 | |||||
| */ | |||||
| TAGS_MATCHED_NULL(14000, "此标签没命中用户") | |||||
| ; | ; | ||||
| private int code; | private int code; | ||||
| @@ -0,0 +1,40 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponInjectStatus { | |||||
| //0:待发送1:发送中2:已发送3:发送失败4已作废 | |||||
| PENDING(0, "待发送"), | |||||
| SENDING(1, "发送中"), | |||||
| HAS_SENT(2, "已发送"), | |||||
| SEND_FAILED(3, "发送失败"), | |||||
| INVALID(4, "已作废") | |||||
| ; | |||||
| public static EnumCouponInjectStatus getEnum(Integer code) { | |||||
| for (EnumCouponInjectStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponInjectStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -10,10 +10,11 @@ public interface WxCUserTagsMapper extends CommonMapper<WxCUserTags, String> { | |||||
| List<WxCUserTags> findList(WxCUserTags wxCUserTags); | List<WxCUserTags> findList(WxCUserTags wxCUserTags); | ||||
| List<Long> findUserByTag(@Param("tagIds")String tagIds); | |||||
| long findCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); | |||||
| long findCountByTags(@Param("tagIds")String tagIds); | |||||
| long findCUserCountByTags(@Param("tagIds")String tagIds, @Param("tenantId")String tenantId); | |||||
| List<Long> findUserByTags(@Param("tagIds")String tagIds); | |||||
| List<Long> findByTags(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId); | |||||
| List<Long> findCUserByTags(@Param("tagIds")String tagIds,@Param("tenantId")String tenantId); | |||||
| } | } | ||||
| @@ -4,6 +4,7 @@ import java.util.List; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCUserTags; | import com.iformall.domain.po.WxCUserTags; | ||||
| import com.iformall.domain.vo.WxChooseTagVo; | import com.iformall.domain.vo.WxChooseTagVo; | ||||
| @@ -42,25 +43,41 @@ public interface WxCUserTagsService { | |||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | /** | ||||
| * tagIds查询 用户数量 | |||||
| * tagIds查询 用户数量(会员列表中的user) | |||||
| * @param tagIds | * @param tagIds | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| long findCountByTag(List<Long> tagIds); | |||||
| long findCountByTag(String tenantId, List<Long> tagIds); | |||||
| /** | |||||
| /** | |||||
| * | |||||
| * tagIds查询用户user信息集合(会员列表中的user) | |||||
| * @param tagIds | |||||
| * @return | |||||
| */ | |||||
| List<WxCUserBasicInfo> findByTag(String tenantId, List<Long> tagIds); | |||||
| /** | |||||
| * tagIds查询 用户数量(登陆过C端的用户,并且保有手机号) | |||||
| * @param tagIds | |||||
| * @return | |||||
| */ | |||||
| long findCUserCountByTag(String tenantId, List<Long> tagIds); | |||||
| /** | |||||
| * | * | ||||
| * tagIds查询用户user信息集合 | |||||
| * tagIds查询用户user信息集合(登陆过C端的用户,并且保有手机号) | |||||
| * @param tagIds | * @param tagIds | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| List<WxCUser> findUserByTag(List<Long> tagIds); | |||||
| List<WxCUser> findCUserByTag(String tenantId, List<Long> tagIds); | |||||
| /** | /** | ||||
| * 获取用户数量和tags name | |||||
| * 获取用户数量和tags name(登陆过C端的用户,并且保有手机号) | |||||
| * @param tagIds | * @param tagIds | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| WxChooseTagVo findChooseTag(List<Long> tagIds); | |||||
| WxChooseTagVo findChooseTag(String tenantId, List<Long> tagIds); | |||||
| } | } | ||||
| @@ -8,9 +8,7 @@ import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumCouponSendType; | |||||
| import com.iformall.enums.EnumCouponStatus; | |||||
| import com.iformall.enums.EnumCouponValidType; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.mapper.CouponInjectMapper; | import com.iformall.mapper.CouponInjectMapper; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import org.apache.commons.lang3.time.DateUtils; | import org.apache.commons.lang3.time.DateUtils; | ||||
| @@ -77,36 +75,38 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||||
| if(wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()){ | if(wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()){ | ||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | ||||
| } | } | ||||
| if(wxCoupon.getSendType()!=EnumCouponSendType.PASSIVE.getCode()) { | |||||
| if(wxCoupon.getSendType()!= EnumCouponSendType.PASSIVE.getCode()) { | |||||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | ||||
| } | } | ||||
| //解析前台tags,并转换json | //解析前台tags,并转换json | ||||
| String[] arys = record.getTags().split(","); | String[] arys = record.getTags().split(","); | ||||
| List<Long> tagids = new ArrayList<>(); | List<Long> tagids = new ArrayList<>(); | ||||
| for (int i = 0; i < arys.length; i++) { | for (int i = 0; i < arys.length; i++) { | ||||
| tagids.add(Long.parseLong(arys[i])); | tagids.add(Long.parseLong(arys[i])); | ||||
| } | } | ||||
| List<WxCUser> cUsers = wxCUserTagsService.findCUserByTag(record.getTenantId(), tagids); | |||||
| if(cUsers.isEmpty()){ | |||||
| return new ResultData(ErrorCode.TAGS_MATCHED_NULL); | |||||
| } | |||||
| int inventory = wxCoupon.getRemainInventory();//库存数量 | |||||
| if(cUsers.size()>inventory){ | |||||
| return new ResultData(ErrorCode.COUPON_IS_SELL_OUT); | |||||
| } | |||||
| record.setTags(JSON.toJSONString(arys)); | record.setTags(JSON.toJSONString(arys)); | ||||
| //生成雪花id | //生成雪花id | ||||
| final IdWorker idWorker = new IdWorker(0, 0); | final IdWorker idWorker = new IdWorker(0, 0); | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| if(record.getSendType()==0){ | |||||
| record.setStatus(1); | |||||
| if(record.getSendType() == EnumCouponInjectSendType.IMMEDIATE.getCode()){ | |||||
| record.setStatus(EnumCouponInjectStatus.SENDING.getCode()); | |||||
| record.setSendTime(new Date()); | record.setSendTime(new Date()); | ||||
| }else{ | }else{ | ||||
| record.setStatus(0); | |||||
| } | |||||
| List<WxCUser> cUsers = wxCUserTagsService.findUserByTag(tagids); | |||||
| if(cUsers.isEmpty()){ | |||||
| return new ResultData(Result.ERROR,"标签下没有用户"); | |||||
| } | |||||
| int inventory = wxCoupon.getRemainInventory();//库存数量 | |||||
| if(cUsers.size()>inventory){ | |||||
| return new ResultData(ErrorCode.COUPON_IS_SELL_OUT); | |||||
| record.setStatus(EnumCouponInjectStatus.PENDING.getCode()); | |||||
| } | } | ||||
| record.setCouponName(wxCoupon.getTitle()); | record.setCouponName(wxCoupon.getTitle()); | ||||
| record.setSendAmount(cUsers.size()); | record.setSendAmount(cUsers.size()); | ||||
| couponInjectMapper.insertSelective(record); | couponInjectMapper.insertSelective(record); | ||||
| @@ -4,6 +4,8 @@ import java.util.ArrayList; | |||||
| import java.util.List; | import java.util.List; | ||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.mapper.WxCUserBasicInfoMapper; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| @@ -25,9 +27,12 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||||
| @Autowired | @Autowired | ||||
| WxCUserTagsMapper wxCUserTagsMapper; | WxCUserTagsMapper wxCUserTagsMapper; | ||||
| @Autowired | |||||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||||
| @Autowired | @Autowired | ||||
| WxCUserMapper wxCUserMapper; | WxCUserMapper wxCUserMapper; | ||||
| @Autowired | @Autowired | ||||
| WxTagsMapper wxTagsMapper; | WxTagsMapper wxTagsMapper; | ||||
| @@ -60,25 +65,46 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public long findCountByTag(List<Long> tagIds) { | |||||
| public long findCountByTag(String tenantId, List<Long> tagIds) { | |||||
| String str = JSON.toJSONString(tagIds); | String str = JSON.toJSONString(tagIds); | ||||
| return wxCUserTagsMapper.findCountByTags(str); | |||||
| return wxCUserTagsMapper.findCountByTags(str,tenantId); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxCUser> findUserByTag(List<Long> tagIds) { | |||||
| public long findCUserCountByTag(String tenantId, List<Long> tagIds) { | |||||
| String str = JSON.toJSONString(tagIds); | String str = JSON.toJSONString(tagIds); | ||||
| List<Long> userIds = wxCUserTagsMapper.findUserByTags(str); | |||||
| return wxCUserTagsMapper.findCUserCountByTags(str,tenantId); | |||||
| } | |||||
| @Override | |||||
| public List<WxCUser> findCUserByTag(String tenantId, List<Long> tagIds) { | |||||
| String str = JSON.toJSONString(tagIds); | |||||
| List<Long> userIds = wxCUserTagsMapper.findCUserByTags(str,tenantId); | |||||
| if(userIds.size()==0) { | if(userIds.size()==0) { | ||||
| return new ArrayList<>(); | return new ArrayList<>(); | ||||
| } | } | ||||
| WxCUser wxCUser = new WxCUser(); | WxCUser wxCUser = new WxCUser(); | ||||
| wxCUser.setIds(userIds); | wxCUser.setIds(userIds); | ||||
| return wxCUserMapper.findList(wxCUser); | return wxCUserMapper.findList(wxCUser); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxChooseTagVo findChooseTag(List<Long> tagIds) { | |||||
| public List<WxCUserBasicInfo> findByTag(String tenantId, List<Long> tagIds) { | |||||
| String str = JSON.toJSONString(tagIds); | |||||
| List<Long> userIds = wxCUserTagsMapper.findByTags(str,tenantId); | |||||
| if(userIds.size()==0) { | |||||
| return new ArrayList<>(); | |||||
| } | |||||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||||
| wxCUserBasicInfo.setIds(userIds); | |||||
| return wxCUserBasicInfoMapper.findList(wxCUserBasicInfo); | |||||
| } | |||||
| @Override | |||||
| public WxChooseTagVo findChooseTag(String tenantId, List<Long> tagIds) { | |||||
| WxTags wxTags =new WxTags(); | WxTags wxTags =new WxTags(); | ||||
| wxTags.setIds(tagIds); | wxTags.setIds(tagIds); | ||||
| List<WxTags> list = wxTagsMapper.findList(wxTags); | List<WxTags> list = wxTagsMapper.findList(wxTags); | ||||
| @@ -92,7 +118,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||||
| } | } | ||||
| WxChooseTagVo vo =new WxChooseTagVo(); | WxChooseTagVo vo =new WxChooseTagVo(); | ||||
| vo.setNames(endName); | vo.setNames(endName); | ||||
| vo.setUserCount(findCountByTag(tagIds)); | |||||
| vo.setUserCount(findCUserCountByTag(tenantId,tagIds)); | |||||
| return vo; | return vo; | ||||
| } | } | ||||
| @@ -9,12 +9,12 @@ import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxMsg; | import com.iformall.domain.po.WxMsg; | ||||
| import com.iformall.domain.po.WxMsgConfig; | import com.iformall.domain.po.WxMsgConfig; | ||||
| import com.iformall.mapper.WxCUserMapper; | |||||
| import com.iformall.mapper.WxCUserTagsMapper; | |||||
| import com.iformall.mapper.WxMsgConfigMapper; | |||||
| import com.iformall.mapper.WxMsgMapper; | |||||
| import com.iformall.mapper.*; | |||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxCUserTagsService; | |||||
| import com.iformall.service.WxMsgService; | import com.iformall.service.WxMsgService; | ||||
| import com.iformall.utils.AesUtil; | import com.iformall.utils.AesUtil; | ||||
| import com.iformall.utils.HMACSHA256; | import com.iformall.utils.HMACSHA256; | ||||
| @@ -35,10 +35,10 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| WxMsgConfigMapper wxMsgConfigMapper; | WxMsgConfigMapper wxMsgConfigMapper; | ||||
| @Autowired | @Autowired | ||||
| WxCUserTagsMapper wxCUserTagsMapper; | |||||
| WxCUserTagsService wxCUserTagsService; | |||||
| @Autowired | @Autowired | ||||
| WxCUserMapper wxCUserMapper; | |||||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -60,9 +60,9 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| String phones=wxMsg.getPhones(); | String phones=wxMsg.getPhones(); | ||||
| if(phones.equals("")){ | if(phones.equals("")){ | ||||
| if(null!=wxMsg.getExcelpath() && !wxMsg.getExcelpath().equals("")) | if(null!=wxMsg.getExcelpath() && !wxMsg.getExcelpath().equals("")) | ||||
| phones=parseexcle(wxMsg.getExcelpath()); | |||||
| phones=parseexcle(wxMsg.getTenantId(), wxMsg.getExcelpath()); | |||||
| else | else | ||||
| phones=parselabel(wxMsg.getLabel()); | |||||
| phones=parselabel(wxMsg.getTenantId(), wxMsg.getLabel()); | |||||
| } | } | ||||
| if(phones.equals("")){ | if(phones.equals("")){ | ||||
| @@ -118,30 +118,25 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| private String parselabel(String label) { | |||||
| private String parselabel(String tenantId, String label) { | |||||
| String[] arys = label.split(","); | String[] arys = label.split(","); | ||||
| List<Long> tagids = new ArrayList<>(); | List<Long> tagids = new ArrayList<>(); | ||||
| for (int i = 0; i < arys.length; i++) { | for (int i = 0; i < arys.length; i++) { | ||||
| tagids.add(Long.parseLong(arys[i])); | tagids.add(Long.parseLong(arys[i])); | ||||
| } | } | ||||
| List<Long> userIds = wxCUserTagsMapper.findUserByTag(JSON.toJSONString(tagids)); | |||||
| if(userIds.size()==0) { | |||||
| return ""; | |||||
| } | |||||
| WxCUser wxCUser = new WxCUser(); | |||||
| wxCUser.setIds(userIds); | |||||
| List<WxCUser> list = wxCUserMapper.findList(wxCUser); | |||||
| List<WxCUserBasicInfo> list = wxCUserTagsService.findByTag(tenantId,tagids); | |||||
| StringBuilder sb=new StringBuilder(); | StringBuilder sb=new StringBuilder(); | ||||
| if(list.size()>0){ | if(list.size()>0){ | ||||
| for(WxCUser cuser:list){ | |||||
| sb.append(cuser.getPhone()).append(","); | |||||
| for(WxCUserBasicInfo cUserInfo:list){ | |||||
| sb.append(cUserInfo.getPhone()).append(","); | |||||
| } | } | ||||
| return sb.toString(); | return sb.toString(); | ||||
| } | } | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| private String parseexcle(String excelpath) { | |||||
| private String parseexcle(String tenantId, String excelpath) { | |||||
| return null; | return null; | ||||
| } | } | ||||
| @@ -59,17 +59,32 @@ | |||||
| select <include refid="allColumns" /> from wx_c_user_tags | select <include refid="allColumns" /> from wx_c_user_tags | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id ="findUserByTag" resultType="java.lang.Long"> | |||||
| select user_id from wx_c_user_tags where JSON_CONTAINS(tags,#{tagIds} ); | |||||
| </select> | |||||
| <select id ="findCountByTags" resultType="java.lang.Long"> | <select id ="findCountByTags" resultType="java.lang.Long"> | ||||
| select count(user_id) from wx_c_user_tags where JSON_CONTAINS(tags,#{tagIds} ); | |||||
| select count(user_id) from wx_c_user_tags cut | |||||
| where JSON_CONTAINS(tags,#{tagIds} ) | |||||
| and cut.tenant_id = #{tenantId}; | |||||
| </select> | </select> | ||||
| <select id ="findUserByTags" resultType="java.lang.Long"> | |||||
| select user_id from wx_c_user_tags where JSON_CONTAINS(tags,#{tagIds} ); | |||||
| <select id ="findCUserCountByTags" resultType="java.lang.Long"> | |||||
| select count(user_id) from wx_c_user_tags cut, wx_c_user cu | |||||
| where cut.id = cu.id | |||||
| and JSON_CONTAINS(tags,#{tagIds} ) | |||||
| and cut.tenant_id = #{tenantId}; | |||||
| </select> | </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> | |||||
| </mapper> | </mapper> | ||||