群发bug,修复

1 parent 381938be
Showing 18 changed files with 114 additions and 82 deletions
......@@ -2,9 +2,8 @@ package com.linkwechat.framework.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeGroup;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
......@@ -22,7 +21,7 @@ import java.util.List;
//支持的java对象
@SuppressWarnings("all")
@Slf4j
@MappedTypes(value = {WeCustomer.class,WeGroup.class})
@MappedTypes(value = {WeGroup.class, WeCustomerList.class})
@MappedJdbcTypes({JdbcType.VARCHAR})
public class ListTypeHandler<T extends Object> implements TypeHandler<List<T>> {
......@@ -33,7 +32,7 @@ public class ListTypeHandler<T extends Object> implements TypeHandler<List<T>> {
}
if(filedName!=null && "customers_info".equals(filedName)){
return JSONObject.parseArray(content, WeCustomer.class);
return JSONObject.parseArray(content, WeCustomerList.class);
}
if(filedName!=null && "groups_info".equals(filedName)){
......
......@@ -30,8 +30,8 @@ public class GroupMessageTask {
*/
public void messageTask() {
//获的当前时间的毫秒数
List<WeCustomerMessageTimeTask> weCustomerMessageTimeTasks = customerMessageTimeTaskMapper.selectWeCustomerMessageTimeTaskGteSettingTime(DateUtils.getDateTime().getTime(),System.currentTimeMillis());
//customerMessageTimeTaskMapper
List<WeCustomerMessageTimeTask> weCustomerMessageTimeTasks = customerMessageTimeTaskMapper.selectWeCustomerMessageTimeTaskGteSettingTime(System.currentTimeMillis());
if (CollectionUtils.isNotEmpty(weCustomerMessageTimeTasks)) {
weCustomerMessageTimeTasks.forEach(
s -> {
......
package com.linkwechat.quartz.task;
import com.linkwechat.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 定时任务调度测试
*
* @author ruoyi
*/
@Slf4j
@Component("ryTask")
public class RyTask {
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
}
public void ryParams(String params) {
System.out.println("执行有参方法:" + params);
}
public void ryNoParams() {
System.out.println("执行无参方法");
}
}
package com.linkwechat.wecom.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WeCustomerList {
......@@ -59,6 +65,9 @@ public class WeCustomerList {
@JsonFormat(pattern = "yyyy-MM-dd")
private Date birthday;
......@@ -74,6 +83,9 @@ public class WeCustomerList {
//查询结束时间
private String endTime;
//所属部门id,多个用逗号隔开
private String departmentIds;
//0正常;1:删除;
private Integer delFlag=new Integer(0);
......
......@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
......@@ -17,7 +18,7 @@ import java.util.List;
@TableName("we_customer_messageTimeTask")
public class WeCustomerMessageTimeTask extends BaseEntity {
public WeCustomerMessageTimeTask(Long messageId, CustomerMessagePushDto messageInfo, List<WeCustomer> customersInfo, List<WeGroup> groupsInfo, Long settingTime) {
public WeCustomerMessageTimeTask(Long messageId, CustomerMessagePushDto messageInfo, List<WeCustomerList> customersInfo, List<WeGroup> groupsInfo, Long settingTime) {
this.messageId = messageId;
this.messageInfo = messageInfo;
this.customersInfo = customersInfo;
......@@ -46,7 +47,7 @@ public class WeCustomerMessageTimeTask extends BaseEntity {
/**
* 客户信息列表
*/
private List<WeCustomer> customersInfo;
private List<WeCustomerList> customersInfo;
/**
* 客户群组信息列表
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
......@@ -26,6 +27,7 @@ public class WeEmpleCode extends BaseEntity {
/**
* $column.columnComment
*/
@TableId
private Long id = SnowFlakeUtil.nextId();
/**
......
......@@ -23,7 +23,7 @@ public class WeEmpleCodeTag
/** $column.columnComment */
@TableId
private Long id;
private Long id=SnowFlakeUtil.nextId();
/** 标签id */
@ApiModelProperty("标签id")
......
......@@ -122,7 +122,7 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
* @param weCustomerList
* @return
*/
List<WeCustomerList> findWeCustomerList(WeCustomerList weCustomerList);
List<WeCustomerList> findWeCustomerList(@Param("weCustomerList") WeCustomerList weCustomerList);
/**
......
......@@ -21,7 +21,7 @@ public interface WeCustomerMessageTimeTaskMapper extends BaseMapper<WeCustomerMe
* @param timeMillis 当前时间毫秒数
* @return {@link WeCustomerMessageTimeTask}s
*/
List<WeCustomerMessageTimeTask> selectWeCustomerMessageTimeTaskGteSettingTime(@Param("beginTime") Long beginTime,@Param("endTime") Long endTime);
List<WeCustomerMessageTimeTask> selectWeCustomerMessageTimeTaskGteSettingTime(@Param("timeMillis") long timeMillis);
/**
* 保存群发任务
......
......@@ -3,6 +3,7 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
......@@ -50,6 +51,6 @@ public interface IWeCustomerMessageService extends IService<WeCustomerMessage> {
* @param messageId
* @throws JsonProcessingException
*/
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) throws JsonProcessingException;
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomerList> customers, List<WeGroup> groups) throws JsonProcessingException;
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeCustomerMessgaeResult;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
......@@ -34,6 +35,6 @@ public interface IWeCustomerMessgaeResultService extends IService<WeCustomerMess
* @param messageId
* @return
*/
int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomer> customers, List<WeGroup> groups);
int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomerList> customers, List<WeGroup> groups);
}
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.enums.WeEmpleCodeType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.WeCommunityNewGroupDto;
......@@ -215,6 +216,7 @@ public class WeCommunityNewGroupServiceImpl extends ServiceImpl<WeCommunityNewGr
WeEmpleCode weEmpleCode = new WeEmpleCode();
weEmpleCode.setId(SnowFlakeUtil.nextId());
// 设置员工和扫码标签
setScopsAndTags(weEmpleCode, communityNewGroupDto);
......
......@@ -14,6 +14,7 @@ import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeCustomerMessageTimeTask;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
......@@ -114,7 +115,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
}
List<WeCustomer> customers = Lists.newArrayList();
List<WeCustomerList> customers = Lists.newArrayList();
List<WeGroup> groups = new ArrayList<>();
// 0 发给客户
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
......@@ -165,7 +166,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
private void sendMessage(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomer> customers,List<WeGroup> groups ) throws ParseException, JsonProcessingException {
private void sendMessage(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomerList> customers,List<WeGroup> groups ) throws ParseException, JsonProcessingException {
//发送群发消息
//调用微信api发送消息
......@@ -176,6 +177,9 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
} else {
WeCustomerMessageTimeTask timeTask = new WeCustomerMessageTimeTask(messageId, customerMessagePushDto, customers, groups
, DateUtils.getMillionSceondsBydate(customerMessagePushDto.getSettingTime()));
customerMessageTimeTaskMapper.saveWeCustomerMessageTimeTask(timeTask);
}
......@@ -197,34 +201,53 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
* @param tag 客户标签id列表
* @return {@link List}s 客户的外部联系人id列表
*/
public List<WeCustomer> externalUserIds(String pushRange, String staffId, String department, String tag) {
public List<WeCustomerList> externalUserIds(String pushRange, String staffId, String department, String tag) {
if (pushRange.equals(WeConstans.SEND_MESSAGE_CUSTOMER_ALL)) {
//从redis中读取数据
List<WeCustomer> customers = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
if (CollectionUtils.isEmpty(customers)) {
WeCustomer weCustomer = new WeCustomer();
weCustomer.setUserIds(staffId);
weCustomer.setDepartmentIds(department);
customers = weCustomerService.selectWeCustomerAllList(weCustomer);
redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
redisCache.expire(WeConstans.WECUSTOMERS_KEY,2 * 60L);
}else{
return customers;
}
// List<WeCustomer> customers = redisCache.getCacheList(WeConstans.WECUSTOMERS_KEY);
// if (CollectionUtils.isEmpty(customers)) {
// WeCustomer weCustomer = new WeCustomer();
// weCustomer.setUserIds(staffId);
// weCustomer.setDepartmentIds(department);
// customers = weCustomerService.selectWeCustomerAllList(weCustomer);
// redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
// redisCache.expire(WeConstans.WECUSTOMERS_KEY,2 * 60L);
// }else{
// return customers;
// }
//
// WeCustomer weCustomer = new WeCustomer();
// weCustomer.setUserIds(staffId);
// weCustomer.setDepartmentIds(department);
// return weCustomerService.selectWeCustomerListNoRel(weCustomer);
return weCustomerService.findWeCustomerList(WeCustomerList.builder()
.userIds(staffId)
.departmentIds(department)
.build());
WeCustomer weCustomer = new WeCustomer();
weCustomer.setUserIds(staffId);
weCustomer.setDepartmentIds(department);
return weCustomerService.selectWeCustomerListNoRel(weCustomer);
} else {
//按条件查询客户
//通过部门id查询所有的员工
//通过员工列表查询该员工的外部联系人列表
WeCustomer weCustomer = new WeCustomer();
weCustomer.setUserIds(staffId);
weCustomer.setTagIds(tag);
weCustomer.setDepartmentIds(department);
return weCustomerService.selectWeCustomerListNoRel(weCustomer);
return weCustomerService.findWeCustomerList(WeCustomerList.builder()
.userIds(staffId)
.tagIds(tag)
.departmentIds(department)
.build());
// WeCustomer weCustomer = new WeCustomer();
// weCustomer.setUserIds(staffId);
// weCustomer.setTagIds(tag);
// weCustomer.setDepartmentIds(department);
//
//
//
// return weCustomerService.selectWeCustomerListNoRel(weCustomer);
}
}
......
......@@ -14,6 +14,7 @@ import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeCustomerMessage;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
......@@ -94,14 +95,14 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
}
@Override
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) throws JsonProcessingException {
public void sendMessgae(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomerList> customers, List<WeGroup> groups) throws JsonProcessingException {
List<String> msgid = new ArrayList<>();
//发给客户
if(CollectionUtils.isNotEmpty(customers)){
customers.stream().filter(customer -> StringUtils.isNotEmpty(customer.getFirstUserId()))
.collect(Collectors.groupingBy(WeCustomer::getFirstUserId)).forEach((k,v)->{
.collect(Collectors.groupingBy(WeCustomerList::getFirstUserId)).forEach((k,v)->{
customerMessagePushDto.setStaffId(k);
//发送群发消息
......@@ -111,7 +112,7 @@ public class WeCustomerMessageServiceImpl extends ServiceImpl<WeCustomerMessageM
WeCustomerMessagePushDto messagePushDto = new WeCustomerMessagePushDto();
messagePushDto.setChat_type(ChatType.of(customerMessagePushDto.getPushType()).getName());
List<String> externalUserIds = v.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList());
List<String> externalUserIds = v.stream().map(WeCustomerList::getExternalUserid).collect(Collectors.toList());
messagePushDto.setExternal_userid(externalUserIds);
messagePushDto.setSender(customerMessagePushDto.getStaffId());
......
......@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
import com.linkwechat.wecom.domain.WeCustomerMessgaeResult;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
......@@ -36,7 +37,7 @@ public class WeCustomerMessgaeResultServiceImpl extends ServiceImpl<WeCustomerMe
}
@Override
public int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId,List<WeCustomer> customers,List<WeGroup> groups) {
public int workerMappingCustomer(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomerList> customers, List<WeGroup> groups) {
int size = 0;
// 0 发给客户
......@@ -57,7 +58,7 @@ public class WeCustomerMessgaeResultServiceImpl extends ServiceImpl<WeCustomerMe
customerMessgaeResult.setSendType(customerMessgaeResult.getSettingTime() == null ? customerMessagePushDto.getPushType() : "2");
customerMessgaeResult.setExternalUserid(customer.getExternalUserid());
customerMessgaeResult.setExternalName(customer.getName());
customerMessgaeResult.setUserid(customer.getUserId());
customerMessgaeResult.setUserid(customer.getFirstUserId());
customerMessgaeResult.setUserName(customer.getUserName());
customerMessgaeResult.setStatus("0");
customerMessgaeResult.setSettingTime(customerMessagePushDto.getSettingTime());
......
......@@ -291,6 +291,9 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
List<WeTag> addTag = weMakeCustomerTag.getAddTag();
if(CollectionUtil.isNotEmpty(addTag)){
//校验是否有标签在库里不存在
CutomerTagEdit cutomerTagEdit = CutomerTagEdit.builder()
.external_userid(weMakeCustomerTag.getExternalUserid())
......
......@@ -288,29 +288,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN we_flower_customer_tag_rel wfctr ON wfctr.del_flag=0 AND wfctr.external_userid=wc.external_userid AND wfctr.user_id=wc.first_user_id
LEFT JOIN we_tag wt ON wt.tag_id=wfctr.tag_id
<where>
<if test="gender !=null">
wc.gender=#{gender}
<if test="weCustomerList.gender !=null">
AND wc.gender=#{weCustomerList.gender}
</if>
<if test="delFlag != null">
wc.del_flag = #{delFlag}
<if test="weCustomerList.departmentIds != null and weCustomerList.departmentIds !=''">
<if test="weCustomerList.departmentIds.indexOf(',') != -1">
OR wu.department in
<foreach item="item" index="index" collection="weCustomerList.departmentIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</if>
<if test="name != null and name !=''">
AND wc.`name` like concat('%',#{name,jdbcType=VARCHAR},'%')
<if test="weCustomerList.delFlag != null">
wc.del_flag = #{weCustomerList.delFlag}
</if>
<if test="weCustomerList.name != null and weCustomerList.name !=''">
AND wc.`name` like concat('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
</if>
<if test="userIds !=null and userIds !=''">
<if test="weCustomerList.userIds !=null and weCustomerList.userIds !=''">
AND wc.first_user_id in
<foreach collection="userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
<foreach collection="weCustomerList.userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="tagIds !=null and tagIds !=''">
<if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
AND wt.tag_id in
<foreach collection="tagIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
<foreach collection="weCustomerList.tagIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="beginTime !=null and beginTime != '' and endTime !='' and endTime != null">
AND date_format(wc.first_add_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
<if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
AND date_format(wc.first_add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.beginTime.endTime}
</if>
</where>
GROUP BY wc.external_userid,wc.first_user_id
......
......@@ -52,6 +52,7 @@
</where>
</update>
<select id="selectWeCustomerMessageTimeTaskGteSettingTime" resultMap="tasks">
SELECT
task_id,
......@@ -62,7 +63,9 @@
setting_time
FROM
we_customer_messageTimeTask
WHERE solved=0 and setting_time BETWEEN #{beginTime} AND #{endTime}
<where>
setting_time <![CDATA[<=]]> #{timeMillis} AND solved=0
</where>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!