修复离职继承等相关bug

1 parent 1988de28
Showing 34 changed files with 446 additions and 177 deletions
......@@ -86,13 +86,18 @@ public class WeCommunityPresTagGroupController extends BaseController {
@PutMapping(path = "/{id}")
@ApiOperation(value = "更新任务信息", httpMethod = "PUT")
public AjaxResult update(@PathVariable("id") Long id, @RequestBody @Validated WePresTagGroupTask task) {
// 保存新任务
task.setTaskId(id);
task.setUpdateBy(SecurityUtils.getUsername());
task.setUpdateTime(new Date());
int rows = taskService.updateTask(task);
if (rows > 0) taskService.sendMessage(task);
return toAjax(rows);
try {
// 保存新任务
task.setTaskId(id);
task.setUpdateBy(SecurityUtils.getUsername());
task.setUpdateTime(new Date());
taskService.updateTaskAndSendMsg(task);
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success();
}
/**
......
......@@ -50,11 +50,11 @@ public class WeMaterialController extends BaseController {
@GetMapping("/list")
@ApiOperation("查询素材列表")
public TableDataInfo list(@RequestParam(value = "categoryId", required = false) String categoryId
, @RequestParam(value = "search", required = false) String search,@RequestParam(value = "mediaType") String mediaType) {
, @RequestParam(value = "search", required = false) String search,@RequestParam(value = "mediaType") String mediaType,Integer status) {
startPage();
return getDataTable(
StringUtils.isNotBlank(mediaType) && mediaType.equals(MediaType.POSTER.getType())?
wePosterService.findWePosterToWeMaterial(categoryId,search):
wePosterService.findWePosterToWeMaterial(categoryId,search,status):
materialService.findWeMaterials(categoryId, search,mediaType)
);
}
......
......@@ -2,6 +2,7 @@ package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.enums.MediaType;
......
......@@ -167,6 +167,18 @@ public class Constants
/**
* 正常状态(未删除)
*/
public static final Integer COMMON_STATE = 0;
/**
* 删除移除状态
*/
public static final Integer DELETE_STATE = 1;
......
......@@ -126,4 +126,13 @@ public interface WeUserClient {
*/
@Request(url = "/user/getuserinfo",interceptor = WeAppAccessTokenInterceptor.class)
WeUserInfoDto getUserInfo(@Query("code")String code,@Header("agentId")String agentId);
/**
* 获取离职成员待分配客户
* @param checkParm
* @return
*/
@Post(url = "/externalcontact/get_unassigned_list",interceptor = WeAccessTokenInterceptor.class)
AllocateWeCustomerDto getUnassignedList(@JSONBody AllocateWeCustomerDto.CheckParm checkParm);
}
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
......@@ -24,8 +25,6 @@ public class WeAllocateCustomer
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/** 接替成员的userid */
private String takeoverUserid;
......
......@@ -25,8 +25,6 @@ public class WeAllocateGroup
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id= SnowFlakeUtil.nextId();
/** 分配的群id */
private String chatId;
......
......@@ -6,6 +6,8 @@ import lombok.experimental.SuperBuilder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @description: 分配客户
* @author: HaoN
......@@ -15,7 +17,7 @@ import lombok.NoArgsConstructor;
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class AllocateWeCustomerDto{
public class AllocateWeCustomerDto extends WeResultDto{
/**外部联系人的userid,注意不是企业成员的帐号*/
private String handover_userid;
......@@ -31,4 +33,38 @@ public class AllocateWeCustomerDto{
private List<Info> info;
//是否是最后一条记录
private Boolean is_last;
private String next_cursor;
@Data
@Builder
public static class CheckParm{
private Integer page_id;
private Integer page_size;
private String cursor;
}
@Data
public static class Info{
//离职成员的userid
private String handover_userid;
//外部联系人userid
private String external_userid;
//成员离职时间
private Long dimission_time;
}
}
......@@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
......@@ -53,11 +55,13 @@ public class CustomerGroupDetail extends WeResultDto {
*/
@AllArgsConstructor
@Data
public class Params{
@Builder
@NoArgsConstructor
public static class Params{
private String chat_id;
//是否需要返回群成员的名字group_chat.member_list.name。0-不返回;1-返回。默认不返回
private Integer need_name;
}
......
package com.linkwechat.wecom.domain.dto.customer;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
......@@ -19,12 +22,17 @@ public class CustomerGroupList extends WeResultDto {
*/
private List<GroupChat> groupChatList;
private String next_cursor;
/**
* 请求参数
*/
@Data
public class Params{
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class Params{
/**群状态过滤: 0 - 所有列表;1 - 离职待继承;2 - 离职继承中;3 - 离职继承完成; */
......@@ -36,6 +44,10 @@ public class CustomerGroupList extends WeResultDto {
/**分页,预期请求的数据量,取值范围 1 ~ 1000 */
private Integer limit=new Integer(1000);
private String cursor;
private String owner_filter;
}
......
......@@ -28,4 +28,9 @@ public class WeAllocateCustomersVo extends BaseEntity {
/**原拥有着*/
private String handoverUserId;
private String externalUserid;
private String userId;
}
......@@ -2,6 +2,9 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeAllocateCustomer;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 离职分配的客户列Mapper接口
......@@ -12,4 +15,5 @@ import com.linkwechat.wecom.domain.WeAllocateCustomer;
public interface WeAllocateCustomerMapper extends BaseMapper<WeAllocateCustomer>
{
void batchAddOrUpdate(@Param("weAllocateCustomers") List<WeAllocateCustomer> weAllocateCustomer);
}
......@@ -2,6 +2,9 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeAllocateGroup;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 分配的群租Mapper接口
......@@ -11,5 +14,5 @@ import com.linkwechat.wecom.domain.WeAllocateGroup;
*/
public interface WeAllocateGroupMapper extends BaseMapper<WeAllocateGroup>
{
void batchAddOrUpdate(@Param("weAllocateGroupList") List<WeAllocateGroup> weAllocateGroupList);
}
......@@ -13,5 +13,5 @@ import java.util.List;
* @author ws
*/
public interface WePosterMapper extends BaseMapper<WePoster> {
List<WeMaterial> findWePosterToWeMaterial(@Param("categoryId") String categoryId,@Param("name") String name);
List<WeMaterial> findWePosterToWeMaterial(@Param("categoryId") String categoryId,@Param("name") String name,@Param("status") Integer status);
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeAllocateCustomer;
import java.util.List;
/**
* 离职分配的客户列Service接口
......@@ -11,5 +12,5 @@ import com.linkwechat.wecom.domain.WeAllocateCustomer;
*/
public interface IWeAllocateCustomerService extends IService<WeAllocateCustomer>
{
void batchAddOrUpdate(List<WeAllocateCustomer> weAllocateCustomer);
}
......@@ -2,6 +2,9 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeAllocateGroup;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 分配的群租Service接口
......@@ -11,5 +14,5 @@ import com.linkwechat.wecom.domain.WeAllocateGroup;
*/
public interface IWeAllocateGroupService extends IService<WeAllocateGroup>
{
void batchAddOrUpdate(List<WeAllocateGroup> weAllocateGroupList);
}
......@@ -37,6 +37,6 @@ public interface IWePosterService extends IService<WePoster> {
public String generateSimpleImg(WePoster poster);
List<WeMaterial> findWePosterToWeMaterial(String categoryId,String name);
List<WeMaterial> findWePosterToWeMaterial(String categoryId,String name,Integer status);
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.wecom.domain.WePresTagGroupTask;
import com.linkwechat.wecom.domain.WePresTagGroupTaskStat;
import com.linkwechat.wecom.domain.vo.WeCommunityTaskEmplVo;
......@@ -58,6 +59,10 @@ public interface IWePresTagGroupTaskService extends IService<WePresTagGroupTask>
*/
int updateTask(WePresTagGroupTask task);
void updateTaskAndSendMsg(WePresTagGroupTask task) throws WeComException;
/**
* 根据查询条件获取任务的统计结果
*
......@@ -101,7 +106,7 @@ public interface IWePresTagGroupTaskService extends IService<WePresTagGroupTask>
*
* @param task 标签建群任务id
*/
void sendMessage(WePresTagGroupTask task);
void sendMessage(WePresTagGroupTask task) throws WeComException;
/**
* 任务名是否已占用
......
......@@ -150,4 +150,8 @@ public interface IWeUserService extends IService<WeUser>
List<WeCustomerAddUser> findWeUserByCustomerId(String externalUserid);
void synchLeaveUserData();
}
......@@ -6,6 +6,8 @@ import com.linkwechat.wecom.mapper.WeAllocateCustomerMapper;
import com.linkwechat.wecom.service.IWeAllocateCustomerService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 离职分配的客户列Service业务层处理
*
......@@ -16,4 +18,8 @@ import org.springframework.stereotype.Service;
public class WeAllocateCustomerServiceImpl extends ServiceImpl<WeAllocateCustomerMapper,WeAllocateCustomer> implements IWeAllocateCustomerService
{
@Override
public void batchAddOrUpdate(List<WeAllocateCustomer> weAllocateCustomer) {
this.baseMapper.batchAddOrUpdate(weAllocateCustomer);
}
}
......@@ -6,6 +6,8 @@ import com.linkwechat.wecom.mapper.WeAllocateGroupMapper;
import com.linkwechat.wecom.service.IWeAllocateGroupService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 分配的群租Service业务层处理
*
......@@ -16,4 +18,8 @@ import org.springframework.stereotype.Service;
public class WeAllocateGroupServiceImpl extends ServiceImpl<WeAllocateGroupMapper,WeAllocateGroup> implements IWeAllocateGroupService
{
@Override
public void batchAddOrUpdate(List<WeAllocateGroup> weAllocateGroupList) {
this.baseMapper.batchAddOrUpdate(weAllocateGroupList);
}
}
......@@ -6,6 +6,7 @@ import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.*;
import com.linkwechat.common.exception.wecom.WeComException;
......@@ -123,7 +124,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
if (CollectionUtil.isNotEmpty(externalUserDetails)) {
weFlowerCustomerHandle(
externalUserDetails
externalUserDetails,true
);
}
}
......@@ -138,7 +139,7 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
/**
* 客户同步业务处理
*/
private void weFlowerCustomerHandle(List<ExternalUserDetail> list) {
private void weFlowerCustomerHandle(List<ExternalUserDetail> list,boolean isSynchCustomerTagRel) {
List<WeCustomer> weCustomerList = new ArrayList<>();
......@@ -160,22 +161,27 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
weCustomer.setFirstAddTime(new Date(followInfo.getCreatetime() * 1000L));
weCustomer.setAddMethod(followInfo.getAdd_way());
weCustomerList.add(weCustomer);
List<String> tags = Stream.of(followInfo.getTag_id()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(tags)) {
tags.stream().forEach(tag -> {
weFlowerCustomerTagRels.add(
WeFlowerCustomerTagRel.builder()
.userId(followInfo.getUserid())
.externalUserid(weCustomer.getExternalUserid())
.tagId(tag)
.delFlag(new Integer(0))
.isCompanyTag(true)
.build()
);
});
if(isSynchCustomerTagRel){
List<String> tags = Stream.of(followInfo.getTag_id()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(tags)) {
tags.stream().forEach(tag -> {
weFlowerCustomerTagRels.add(
WeFlowerCustomerTagRel.builder()
.userId(followInfo.getUserid())
.externalUserid(weCustomer.getExternalUserid())
.tagId(tag)
.delFlag(new Integer(0))
.isCompanyTag(true)
.build()
);
});
}
}
});
});
......@@ -230,63 +236,55 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
@Transactional(rollbackFor = Exception.class)
public void allocateWeCustomer(WeLeaveUserInfoAllocateVo weLeaveUserInfoAllocateVo) {
//所需分配的客户
List<WeCustomer> allocateWeCustomers = this.list(new LambdaQueryWrapper<WeCustomer>()
.eq(WeCustomer::getFirstUserId, weLeaveUserInfoAllocateVo.getHandoverUserid()));
if (CollectionUtil.isNotEmpty(allocateWeCustomers)) {
List<WeAllocateCustomer> weAllocateCustomerList = iWeAllocateCustomerService.list(new LambdaQueryWrapper<WeAllocateCustomer>()
.eq(WeAllocateCustomer::getHandoverUserid, weLeaveUserInfoAllocateVo.getHandoverUserid()));
//设置客户的接手人
allocateWeCustomers.stream().forEach(k->{
k.setTakeoverUserId(weLeaveUserInfoAllocateVo.getTakeoverUserid());
});
if(CollectionUtil.isNotEmpty(weAllocateCustomerList)){
//所需分配的客户
List<WeCustomer> allocateWeCustomers = this.list(new LambdaQueryWrapper<WeCustomer>()
.in(WeCustomer::getExternalUserid, weAllocateCustomerList.stream().map(WeAllocateCustomer::getExternalUserid).collect(Collectors.toList()))
.eq(WeCustomer::getFirstUserId,weLeaveUserInfoAllocateVo.getHandoverUserid()));
// JobExtendsCustomer jobExtendsCustomer = weUserClient.transferCustomer(
// AllocateWeCustomerDto.builder()
// .external_userid(
// allocateWeCustomers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList()).stream().toArray(String[]::new)
// )
// .handover_userid(weLeaveUserInfoAllocateVo.getHandoverUserid())
// .takeover_userid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
// .build()
// );
if (CollectionUtil.isNotEmpty(allocateWeCustomers)) {
WeResultDto weResultDto = weUserClient.allocateCustomer(
AllocateWeCustomerDto.builder()
.external_userid(
allocateWeCustomers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList()).stream().toArray(String[]::new)
)
.handover_userid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeover_userid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
//设置客户的接手人和状态设置为删除
allocateWeCustomers.stream().forEach(k -> {
k.setTakeoverUserId(weLeaveUserInfoAllocateVo.getTakeoverUserid());
k.setDelFlag(Constants.DELETE_STATE);
});
if(weResultDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
this.baseMapper.batchAddOrUpdate(allocateWeCustomers);
List<WeAllocateCustomer> weAllocateCustomers=new ArrayList<>();
allocateWeCustomers.stream().forEach(k->{
weAllocateCustomers.add(
WeAllocateCustomer.builder()
.allocateTime(new Date())
.extentType(new Integer(1))
.externalUserid(k.getExternalUserid())
.handoverUserid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeoverUserid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.failReason("离职继承")
.build()
);
WeResultDto weResultDto = weUserClient.allocateCustomer(
AllocateWeCustomerDto.builder()
.external_userid(
allocateWeCustomers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList()).stream().toArray(String[]::new)
)
.handover_userid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeover_userid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
iWeAllocateCustomerService.saveBatch(weAllocateCustomers);
if(weResultDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
this.baseMapper.batchAddOrUpdate(allocateWeCustomers);
weAllocateCustomerList.stream().forEach(k->{
k.setAllocateTime(new Date());
k.setTakeoverUserid(weLeaveUserInfoAllocateVo.getTakeoverUserid());
});
iWeAllocateCustomerService.batchAddOrUpdate(weAllocateCustomerList);
}
});
}
}
}
......
......@@ -82,32 +82,32 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
@Override
@Transactional
public void allocateWeGroup(WeLeaveUserInfoAllocateVo weLeaveUserInfoAllocateVo) {
List<WeGroup> weGroups
= this.list(new LambdaQueryWrapper<WeGroup>().eq(WeGroup::getOwner, weLeaveUserInfoAllocateVo.getHandoverUserid()));
if(CollectionUtil.isNotEmpty(weGroups)){
//同步企业微信端
AllocateGroupDto allocateGroup = weUserClient.allocateGroup(
AllocateWeGroupDto.builder()
.chat_id_list(ArrayUtil.toArray(weGroups.stream().map(WeGroup::getChatId).collect(Collectors.toList()), String.class))
.new_owner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
//构建分配记录
List<WeAllocateGroup> weAllocateGroups = new ArrayList<>();
//更改本地群主
weGroups.stream().forEach(k -> {
k.setOwner(weLeaveUserInfoAllocateVo.getTakeoverUserid());
weAllocateGroups.add(WeAllocateGroup.builder()
.allocateTime(new Date())
.chatId(k.getChatId())
.status(AllocateGroupStatus.ALLOCATE_GROUP_STATUS_BJTCG.getKey())
.newOwner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.oldOwner(weLeaveUserInfoAllocateVo.getHandoverUserid())
.build());
});
List<WeAllocateGroup> weAllocateGroupList = iWeAllocateGroupService.list(new LambdaQueryWrapper<WeAllocateGroup>()
.eq(WeAllocateGroup::getOldOwner, weLeaveUserInfoAllocateVo.getHandoverUserid()));
if(CollectionUtil.isNotEmpty(weAllocateGroupList)){
List<WeGroup> weGroups
= this.list(new LambdaQueryWrapper<WeGroup>().in(WeGroup::getChatId,
weAllocateGroupList.stream().map(WeAllocateGroup::getChatId).collect(Collectors.toList())));
if(CollectionUtil.isNotEmpty(weGroups)){
//同步企业微信端
AllocateGroupDto allocateGroup = weUserClient.allocateGroup(
AllocateWeGroupDto.builder()
.chat_id_list(ArrayUtil.toArray(weGroups.stream().map(WeGroup::getChatId).collect(Collectors.toList()), String.class))
.new_owner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
//更改本地群主
weAllocateGroupList.stream().forEach(kk->{
kk.setAllocateTime(new Date());
kk.setNewOwner(weLeaveUserInfoAllocateVo.getTakeoverUserid());
});
//处理接替失败的群
......@@ -121,7 +121,7 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
.setOwner(weLeaveUserInfoAllocateVo.getHandoverUserid());
WeAllocateGroup weAllocateGroup
= weAllocateGroups.stream().filter(kk -> kk.getChatId().equals(k.getChat_id())).findFirst().get();
= weAllocateGroupList.stream().filter(kk -> kk.getChatId().equals(k.getChat_id())).findFirst().get();
if(null != weAllocateGroup){
weAllocateGroup.setStatus(AllocateGroupStatus.ALLOCATE_GROUP_STATUS_JTSB.getKey());
weAllocateGroup.setErrMsg(weAllocateGroup.getErrMsg());
......@@ -130,12 +130,19 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
});
}
if(this.saveOrUpdateBatch(weGroups)){
iWeAllocateGroupService
.saveOrUpdateBatch(weAllocateGroups);
if(this.saveOrUpdateBatch(weGroups)){
iWeAllocateGroupService
.batchAddOrUpdate(weAllocateGroupList);
}
}
}
}
......@@ -156,7 +163,7 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
SecurityContextHolder.setContext(securityContext);
CustomerGroupList customerGroupList =
weCustomerGroupClient.groupChatLists(new CustomerGroupList().new Params());
weCustomerGroupClient.groupChatLists(CustomerGroupList.Params.builder().build());
if (customerGroupList.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
&& CollectionUtil.isNotEmpty(customerGroupList.getGroupChatList())) {
......@@ -164,7 +171,7 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<WeGroupMember> weGroupMembers = new ArrayList<>();
customerGroupList.getGroupChatList().stream().forEach(k -> {
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(
new CustomerGroupDetail().new Params(k.getChatId(), 1)
CustomerGroupDetail.Params.builder().chat_id(k.getChatId()).need_name(1).build()
);
if (customerGroupDetail.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
......@@ -227,7 +234,7 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<WeGroup> weGroups = new ArrayList<>();
List<WeGroupMember> weGroupMembers = new ArrayList<>();
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(
new CustomerGroupDetail().new Params(chatId, 1)
CustomerGroupDetail.Params.builder().chat_id(chatId).need_name(1).build()
);
if (CollectionUtil.isNotEmpty(customerGroupDetail.getGroupChat())) {
customerGroupDetail.getGroupChat().stream().forEach(kk -> {
......@@ -272,7 +279,7 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<WeGroup> weGroups = new ArrayList<>();
List<WeGroupMember> weGroupMembers = new ArrayList<>();
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(
new CustomerGroupDetail().new Params(chatId, 1)
CustomerGroupDetail.Params.builder().chat_id(chatId).need_name(1).build()
);
if (CollectionUtil.isNotEmpty(customerGroupDetail.getGroupChat())) {
customerGroupDetail.getGroupChat().stream().forEach(kk -> {
......@@ -323,8 +330,6 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<List<WeGroup>> lists = Lists.partition(weGroups, 500);
for (List<WeGroup> groupList : lists) {
this.baseMapper.insertBatch(groupList);
// this.remove(new LambdaQueryWrapper<WeGroup>()
// .notIn(WeGroup::getChatId, groupList.stream().map(WeGroup::getChatId).collect(Collectors.toList())));
}
}else{
List<WeGroup> oldWeGroups = this.list();
......@@ -351,12 +356,6 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
iWeGroupMemberService.insertBatch(groupMemberList);
// iWeGroupMemberService.remove(
// new LambdaQueryWrapper<WeGroupMember>()
// .notIn(WeGroupMember::getUserId,groupMemberList.stream().map(WeGroupMember::getUserId).collect(Collectors.toList()))
//
// );
}
......
......@@ -207,7 +207,7 @@ public class WePosterServiceImpl extends ServiceImpl<WePosterMapper, WePoster> i
}
@Override
public List<WeMaterial> findWePosterToWeMaterial(String categoryId, String name) {
return this.baseMapper.findWePosterToWeMaterial(categoryId, name);
public List<WeMaterial> findWePosterToWeMaterial(String categoryId, String name,Integer status) {
return this.baseMapper.findWePosterToWeMaterial(categoryId, name,status);
}
}
......@@ -199,6 +199,23 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
return rows;
}
/**
* 更新任务同时推送消息
* @param task
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTaskAndSendMsg(WePresTagGroupTask task) throws WeComException {
try {
this.updateTask(task);
this.sendMessage(task);
}catch (WeComException e){
throw e;
}
}
@Override
public List<WePresTagGroupTaskStat> getTaskStat(Long id, String customerName, Integer isInGroup, Integer isSent, Integer sendType) {
......@@ -245,8 +262,7 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
}
@Override
@Async
public void sendMessage(WePresTagGroupTask task) {
public void sendMessage(WePresTagGroupTask task) throws WeComException{
Integer sendType = task.getSendType();
try {
// 企业群发逻辑
......@@ -334,6 +350,7 @@ public class WePresTagGroupTaskServiceImpl extends ServiceImpl<WePresTagGroupTas
} catch (Exception e) {
log.error("============> 老客标签建群任务发送失败, 任务明细: {}", task);
log.error("错误信息: {}", e.getMessage());
throw new WeComException(e.getMessage());
}
}
......
......@@ -18,20 +18,23 @@ import com.linkwechat.common.utils.Threads;
import com.linkwechat.common.utils.spring.SpringUtils;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.client.WeCustomerClient;
import com.linkwechat.wecom.client.WeCustomerGroupClient;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeAllocateCustomer;
import com.linkwechat.wecom.domain.WeAllocateGroup;
import com.linkwechat.wecom.domain.WeCustomerAddUser;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.AllocateWeCustomerDto;
import com.linkwechat.wecom.domain.dto.WeUserInfoDto;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupDetail;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupList;
import com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail;
import com.linkwechat.wecom.domain.dto.customer.FollowUserList;
import com.linkwechat.wecom.domain.dto.msgaudit.WeMsgAuditDto;
import com.linkwechat.wecom.domain.vo.*;
import com.linkwechat.wecom.mapper.WeUserMapper;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeDepartmentService;
import com.linkwechat.wecom.service.IWeGroupService;
import com.linkwechat.wecom.service.IWeUserService;
import com.linkwechat.wecom.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.context.SecurityContext;
......@@ -70,7 +73,17 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
@Autowired
private WeCustomerClient weCustomerClient;
@Autowired
private IWeAllocateCustomerService iWeAllocateCustomerService;
@Autowired
private WeCustomerGroupClient weCustomerGroupClient;
@Autowired
private IWeAllocateGroupService iWeAllocateGroupService;
@Autowired
private IWeGroupService iWeGroupService;
@Override
public WeUser getById(Long id) {
......@@ -196,7 +209,7 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
public void allocateLeaveUserAboutData(WeLeaveUserInfoAllocateVo weLeaveUserInfoAllocateVo) {
try {
//分配客户
SpringUtils.getBean(IWeCustomerService.class).allocateWeCustomer(weLeaveUserInfoAllocateVo);
// SpringUtils.getBean(IWeCustomerService.class).allocateWeCustomer(weLeaveUserInfoAllocateVo);
//分配群组
SpringUtils.getBean(IWeGroupService.class).allocateWeGroup(weLeaveUserInfoAllocateVo);
//更新员工状态为已分配
......@@ -282,6 +295,7 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Async
public void deleteUser(String[] userIds) {
List<WeUser> weUsers=new ArrayList<>();
CollectionUtil.newArrayList(userIds).forEach(userId-> {
......@@ -307,6 +321,8 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
);
if(this.updateBatchById(weUsers)){
weUsers.forEach(k-> weUserClient.deleteUserByUserId(k.getUserId()));
//同步离职成员相关信息分配
this.synchLeaveUserData();
}
}
......@@ -365,4 +381,104 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
}
/**
* 同步离职成员的相关数据(待分配客户,待分配群)。
*/
@Override
@Async
public void synchLeaveUserData() {
//同步所需要分配的客户
List<AllocateWeCustomerDto.Info> infos=new ArrayList<>();
getLeaveUserCustomer(null,infos);
if(CollectionUtil.isNotEmpty(infos)){
//过滤掉不存在的外部联系人
List<WeAllocateCustomer> allocateCustomers=new ArrayList<>();
infos.stream().forEach(kk->{
allocateCustomers.add(
WeAllocateCustomer.builder()
.allocateTime(new Date())
.extentType(new Integer(1))
.externalUserid(kk.getExternal_userid())
.handoverUserid(kk.getHandover_userid())
.status(new Integer(2))
.failReason("离职继承")
.build()
);
});
iWeAllocateCustomerService.batchAddOrUpdate(allocateCustomers);
}
//同步所需分配的客户群
List<CustomerGroupList.GroupChat> groupChats=new ArrayList<>();
getLeaveUserGroup(null,groupChats);
if(CollectionUtil.isNotEmpty(groupChats)){
List<WeAllocateGroup> weAllocateGroups=new ArrayList<>();
groupChats.stream().forEach(k->{
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(CustomerGroupDetail.Params.builder()
.chat_id(k.getChatId())
.need_name(new Integer(0))
.build());
if(WeConstans.WE_SUCCESS_CODE.equals(customerGroupDetail.getErrcode())
&&ArrayUtil.isNotEmpty(customerGroupDetail.getGroupChat())){
weAllocateGroups.add(WeAllocateGroup.builder()
.chatId(k.getChatId())
.oldOwner(customerGroupDetail.getGroupChat().stream().findFirst().get().getOwner())
.status(new Integer(3))
.build());
}
});
iWeAllocateGroupService.batchAddOrUpdate(weAllocateGroups);
}
}
private void getLeaveUserCustomer(String nextCursor, List<AllocateWeCustomerDto.Info> list){
AllocateWeCustomerDto unassignedList = weUserClient.getUnassignedList(AllocateWeCustomerDto.CheckParm.builder()
.cursor(nextCursor)
.build());
if (WeConstans.WE_SUCCESS_CODE.equals(unassignedList.getErrcode())
&& ArrayUtil.isNotEmpty(unassignedList.getInfo())) {
list.addAll(unassignedList.getInfo());
if (StringUtils.isNotEmpty(unassignedList.getNext_cursor())) {
getLeaveUserCustomer(unassignedList.getNext_cursor(),list);
}
}
}
private void getLeaveUserGroup(String nextCursor,List<CustomerGroupList.GroupChat> groupChats){
CustomerGroupList customerGroupList =
weCustomerGroupClient.groupChatLists(CustomerGroupList.Params.builder()
.status_filter(new Integer(1))
.cursor(nextCursor)
.limit(new Integer(1000))
.build());
if (WeConstans.WE_SUCCESS_CODE.equals(customerGroupList.getErrcode())
&& ArrayUtil.isNotEmpty(customerGroupList.getGroupChatList())) {
groupChats.addAll(customerGroupList.getGroupChatList());
if (StringUtils.isNotEmpty(customerGroupList.getNext_cursor())) {
getLeaveUserGroup(customerGroupList.getNext_cursor(),groupChats);
}
}
}
}
......@@ -5,22 +5,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.linkwechat.wecom.mapper.WeAllocateCustomerMapper">
<!-- <select id="getAllocateCustomers" resultType="com.linkwechat.wecom.domain.vo.WeAllocateCustomer">-->
<!-- -->
<!-- SELECT-->
<!-- wc.`name` as customerName,-->
<!-- wu.user_name as userName,-->
<!-- (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,-->
<!-- wac.allocate_time-->
<!-- FROM-->
<!-- we_allocate_customer wac-->
<!-- INNER JOIN we_customer wc ON wc.external_userid=wac.external_userid-->
<!-- INNER JOIN we_user wu ON wu.user_id=wac.takeover_userid-->
<!-- WHERE wac.handover_userid=1232-->
<!-- AND -->
<!-- -->
<!-- </select>-->
<insert id="batchAddOrUpdate" >
INSERT INTO we_allocate_customer(
takeover_userid,
external_userid,
allocate_time,
handover_userid,
status,
takeover_time,
fail_reason
) values
<foreach collection="weAllocateCustomers" item="item" index="index" separator=",">
(#{item.takeoverUserid},#{item.externalUserid},#{item.allocateTime},#{item.handoverUserid},#{item.status},#{item.takeoverTime},#{item.failReason})
</foreach>
ON DUPLICATE KEY UPDATE
takeover_userid=IF(TRIM(VALUES(takeover_userid)) != '',VALUES(takeover_userid),we_allocate_customer.takeover_userid),
allocate_time=IF(VALUES(allocate_time), VALUES(allocate_time), we_allocate_customer.allocate_time),
takeover_time=IF(VALUES(takeover_time), VALUES(takeover_time), we_allocate_customer.takeover_time),
status=IF(VALUES(status), VALUES(status),we_allocate_customer.status),
fail_reason=IF(TRIM(VALUES(fail_reason)) !='',VALUES(fail_reason),we_allocate_customer.fail_reason);
</insert>
......
......@@ -3,7 +3,23 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeAllocateGroupMapper">
<insert id="batchAddOrUpdate" >
INSERT INTO we_allocate_group(
chat_id,
new_owner,
err_msg,
status,
old_owner,
allocate_time
) values
<foreach collection="weAllocateGroupList" item="item" index="index" separator=",">
(#{item.chatId},#{item.newOwner},#{item.errMsg},#{item.status},#{item.oldOwner},#{item.allocateTime})
</foreach>
ON DUPLICATE KEY UPDATE
new_owner=IF(TRIM(VALUES(new_owner)) != '',VALUES(new_owner), we_allocate_group.new_owner),
allocate_time=IF(VALUES(allocate_time),VALUES(allocate_time),we_allocate_group.allocate_time),
status=IF(VALUES(status), VALUES(status), we_allocate_group.status);
</insert>
</mapper>
\ No newline at end of file
......@@ -220,24 +220,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</foreach>
ON DUPLICATE KEY UPDATE
NAME=IF(we_customer.NAME != null,we_customer.NAME, VALUES(NAME)),
avatar=IF(we_customer.avatar != null, VALUES(avatar), we_customer.avatar),
customer_type=IF(we_customer.customer_type != null, we_customer.customer_type,VALUES(customer_type)),
gender=IF(we_customer.gender != null, VALUES(gender), we_customer.gender),
unionid=IF(we_customer.unionid != null, VALUES(unionid), we_customer.unionid),
birthday=IF(we_customer.birthday != null,VALUES(birthday), we_customer.birthday),
corp_name=IF(we_customer.corp_name != null, VALUES(corp_name), we_customer.corp_name),
position=IF(we_customer.position != null, VALUES(position), we_customer.position),
is_open_chat=IF(we_customer.is_open_chat != null, VALUES(is_open_chat), we_customer.is_open_chat),
first_user_id=IF(we_customer.first_user_id != null, VALUES(first_user_id), we_customer.first_user_id),
first_add_time=IF(we_customer.first_add_time != null, VALUES(first_add_time), we_customer.first_add_time),
qq=IF(we_customer.qq != null, VALUES(qq), we_customer.qq),
email=IF(we_customer.email != null, VALUES(email), we_customer.email),
address=IF(we_customer.address != null, VALUES(address), we_customer.address),
phone=IF(we_customer.phone != null, VALUES(phone), we_customer.phone),
add_method=IF(we_customer.add_method != null, we_customer.add_method, VALUES(add_method)),
del_flag=IF(we_customer.del_flag != null, we_customer.del_flag, VALUES(del_flag)),
state=IF(we_customer.state != null and we_customer.state !='',we_customer.state, VALUES(state));
NAME=IF(TRIM(VALUES(NAME)) !='',VALUES(NAME),we_customer.NAME),
avatar=IF(TRIM(VALUES(avatar)) !='', VALUES(avatar), we_customer.avatar),
customer_type=IF(VALUES(customer_type),VALUES(customer_type),we_customer.customer_type),
gender=IF(VALUES(gender), VALUES(gender), we_customer.gender),
unionid=IF(TRIM(VALUES(unionid)) !='', VALUES(unionid), we_customer.unionid),
birthday=IF(VALUES(birthday),VALUES(birthday), we_customer.birthday),
corp_name=IF(TRIM(VALUES(corp_name)) !='', VALUES(corp_name), we_customer.corp_name),
position=IF(TRIM(VALUES(position)) != '',VALUES(position) , we_customer.position),
is_open_chat=IF(VALUES(is_open_chat), VALUES(is_open_chat), we_customer.is_open_chat),
first_user_id=IF(TRIM(VALUES(first_user_id)) !='', VALUES(first_user_id), we_customer.first_user_id),
first_add_time=IF(VALUES(first_add_time), VALUES(first_add_time), we_customer.first_add_time),
qq=IF(TRIM(VALUES(qq)) !='', VALUES(qq), we_customer.qq),
email=IF(TRIM(VALUES(email)) != '', VALUES(email), we_customer.email),
address=IF(TRIM(VALUES(address)) != '', VALUES(address), we_customer.address),
phone=IF(TRIM(VALUES(phone)) != '', VALUES(phone), we_customer.phone),
add_method=IF(VALUES(add_method), VALUES(add_method), we_customer.add_method),
del_flag=IF(VALUES(del_flag),VALUES(del_flag),we_customer.del_flag),
state=IF(TRIM(VALUES(state)) != '',VALUES(state),we_customer.state);
</insert>
......
......@@ -85,10 +85,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(#{item.userId},#{item.externalUserid},#{item.tagId},NOW(),#{item.isCompanyTag},#{item.delFlag})
</foreach>
ON DUPLICATE KEY UPDATE
user_id=IF(we_flower_customer_tag_rel.user_id != null, VALUES(user_id), we_flower_customer_tag_rel.user_id),
external_userid=IF(we_flower_customer_tag_rel.external_userid != null, VALUES(external_userid), we_flower_customer_tag_rel.external_userid),
tag_id=IF(we_flower_customer_tag_rel.tag_id != null, VALUES(tag_id), we_flower_customer_tag_rel.tag_id),
del_flag=IF(we_flower_customer_tag_rel.del_flag != null, we_flower_customer_tag_rel.del_flag, VALUES(del_flag));
user_id=IF(TRIM(VALUES(user_id)) !='', VALUES(user_id), we_flower_customer_tag_rel.user_id),
external_userid=IF(TRIM(VALUES(external_userid)) !='', VALUES(external_userid), we_flower_customer_tag_rel.external_userid),
tag_id=IF(TRIM(VALUES(tag_id)) !='', VALUES(tag_id), we_flower_customer_tag_rel.tag_id),
del_flag=IF( VALUES(del_flag), VALUES(del_flag),we_flower_customer_tag_rel.del_flag);
</insert>
</mapper>
\ No newline at end of file
......@@ -304,12 +304,12 @@
END
AND CASE
WHEN ( SELECT cus_begin_time is not null FROM we_pres_tag_group WHERE task_id = #{taskId} )
THEN cu.first_add_time &gt;= ( SELECT t.cus_begin_time FROM we_pres_tag_group t WHERE t.task_id = #{taskId} )
THEN cu.first_add_time &gt;= ( SELECT t.cus_begin_time FROM we_pres_tag_group t WHERE t.task_id = #{taskId} )
ELSE 1 = 1
END
AND CASE
WHEN ( SELECT cus_end_time is not null FROM we_pres_tag_group WHERE task_id = #{taskId} )
THEN cu.first_add_time &lt;= (SELECT t.cus_end_time FROM we_pres_tag_group t WHERE t.task_id = #{taskId} )
THEN cu.first_add_time &lt;= (SELECT t.cus_begin_time FROM we_pres_tag_group t WHERE t.task_id = #{taskId} )
WHEN (SELECT update_time is not null FROM we_pres_tag_group WHERE task_id = #{taskId})
THEN cu.first_add_time &lt;= ( SELECT t.update_time FROM we_pres_tag_group t WHERE t.task_id = #{taskId} )
WHEN (SELECT create_time is not null FROM we_pres_tag_group WHERE task_id = #{taskId})
......
......@@ -108,8 +108,10 @@
wu.user_name,
wu.dimission_time,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
(SELECT COUNT(*) FROM we_customer wc WHERE wc.first_user_id=wu.user_id) as allocateCustomerNum,
(SELECT COUNT(*) FROM we_group wg WHERE wg.`owner`=wu.user_id) as allocateGroupNum
(SELECT count(*) FROM we_allocate_customer wac
INNER JOIN we_customer wc ON wac.external_userid=wc.external_userid
and wac.handover_userid=wc.first_user_id WHERE wac.handover_userid=wu.user_id) as allocateCustomerNum,
(SELECT COUNT(*) FROM we_allocate_group wg WHERE wg.old_owner=wu.user_id) as allocateGroupNum
FROM
we_user wu
<where>
......@@ -156,6 +158,8 @@
wc.`name` as customerName,
wu.user_name as takeUserName,
wac.allocate_time,
wc.external_userid as externalUserid,
wc.first_user_id as userId,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department
FROM
we_allocate_customer wac
......@@ -175,7 +179,7 @@
SELECT
wu.user_name as newOwnerName,
wg.chat_id,
wg.group_name,
IF(wg.group_name,wg.group_name,"群聊") as group_name,
(SELECT count(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
wag.allocate_time
......
......@@ -18,7 +18,9 @@
<if test="name !=null and name !=''">
AND title like concat('%',#{name,jdbcType=VARCHAR},'%')
</if>
and status = 0
<if test="status !=null">
AND status = #{status}
</if>
and del_flag=0
ORDER BY create_time DESC
</select>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!