相关bug修复

1 parent 9303401b
......@@ -8,6 +8,7 @@ import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.*;
......@@ -93,7 +94,12 @@ public class WeCustomerController extends BaseController
@GetMapping("/synchWeCustomer")
public AjaxResult synchWeCustomer() {
weCustomerService.synchWeCustomer();
try {
weCustomerService.synchWeCustomer();
}catch (CustomException e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success(WeConstans.SYNCH_TIP);
......
......@@ -5,6 +5,7 @@ import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeGroupMember;
......@@ -87,7 +88,12 @@ public class WeGroupController extends BaseController {
// @PreAuthorize("@ss.hasPermi('customerManage:group:sync')")
@GetMapping({"/synchWeGroup"})
public AjaxResult synchWeGroup(){
weGroupService.synchWeGroup();
try {
weGroupService.synchWeGroup();
}catch (CustomException e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
......
......@@ -4,6 +4,7 @@ import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.wecom.client.WeMomentsClient;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeMoments;
......@@ -90,11 +91,17 @@ public class WeMomentsController extends BaseController {
@GetMapping("/synchMoments")
public AjaxResult synchMoments(@RequestParam(defaultValue = "0") Integer filterType){
if(filterType.equals(new Integer(0))){
iWeMomentsService.synchEnterpriseMoments(filterType);
}else if(filterType.equals(new Integer(1))){
iWeMomentsService.synchPersonMoments(filterType);
try {
if(filterType.equals(new Integer(0))){
iWeMomentsService.synchEnterpriseMoments(filterType);
}else if(filterType.equals(new Integer(1))){
iWeMomentsService.synchPersonMoments(filterType);
}
}catch (CustomException e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
......
......@@ -9,8 +9,11 @@ import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeTag;
import com.linkwechat.wecom.service.IWeSynchRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
......@@ -41,6 +44,9 @@ public class WeTagGroupController extends BaseController
@Autowired
private IWeTagGroupService weTagGroupService;
@Autowired
private IWeSynchRecordService iWeSynchRecordService;
/**
* 查询标签组列表(分页)
*/
......@@ -49,9 +55,13 @@ public class WeTagGroupController extends BaseController
public TableDataInfo list(WeTagGroup weTagGroup)
{
startPage();
return getDataTable(
weTagGroupService.selectWeTagGroupList(weTagGroup)
);
TableDataInfo dataTable = getDataTable(weTagGroupService.selectWeTagGroupList(weTagGroup));
dataTable.setLastSyncTime(
iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER)
);//最近同步时间
return dataTable;
}
......@@ -126,16 +136,12 @@ public class WeTagGroupController extends BaseController
@GetMapping("/synchWeTags")
public AjaxResult synchWeTags(){
SecurityContext securityContext = SecurityContextHolder.getContext();
try {
weTagGroupService.synchWeTags();
}catch (CustomException e){
return AjaxResult.error(e.getMessage());
}
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
weTagGroupService.synchWeTags();
}
});
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.aspectj;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.domain.WeSynchRecord;
......@@ -41,10 +42,12 @@ public class SynchRecordAop {
if(null != annotationLog){
List<WeSynchRecord> weSynchRecords = iWeSynchRecordService.list(new LambdaQueryWrapper<WeSynchRecord>()
.eq(WeSynchRecord::getSynchType,annotationLog.synchType())
.apply("date_format (synch_time,'%Y-%m-%d HH:mm:ss') >= date_format('" + DateUtils.getBeforeByHourTime(2) + "','%Y-%m-%d HH:mm:ss')")
.apply("date_format (synch_time,'%Y-%m-%d HH:mm:ss') <= date_format('" + DateUtils.getBeforeByHourTime(0) + "','%Y-%m-%d HH:mm:ss')"));
.between(WeSynchRecord::getSynchTime,DateUtils.getBeforeByHourTime(2)
,DateUtils.getBeforeByHourTime(0)));
if(CollectionUtil.isEmpty(weSynchRecords)||weSynchRecords.size()<=1){
joinPoint.proceed();
}else{
throw new CustomException("由于企业微信开放平台的限制,两小时内不得重复同步操作");
}
}
......
......@@ -10,4 +10,5 @@ public class SynchRecordConstants {
public static final int SYNCH_CUSTOMER_GROUP=3;//客户群同步
public static final int SYNCH_CUSTOMER_PERSON_MOMENTS=4;//个人朋友圈
public static final int SYNCH_CUSTOMER_ENTERPRISE_MOMENTS=5;//企业朋友圈
public static final int SYNCH_CUSTOMER_TAG=6;//企业标签同步
}
......@@ -11,6 +11,7 @@ import com.linkwechat.common.enums.TrajectorySceneType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.client.WeCustomerClient;
......@@ -21,12 +22,15 @@ import com.linkwechat.wecom.domain.dto.AllocateWeCustomerDto;
import com.linkwechat.wecom.domain.dto.WeCustomerDto;
import com.linkwechat.wecom.domain.dto.WeWelcomeMsg;
import com.linkwechat.wecom.domain.dto.customer.*;
import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagListDto;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.mapper.WeCustomerMapper;
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;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
......@@ -92,31 +96,43 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
* @return
*/
@Override
@Async
@Transactional(rollbackFor = Exception.class)
@SynchRecord(synchType = SynchRecordConstants.SYNCH_CUSTOMER)
public void synchWeCustomer() {
//获取所有可以添加客户的企业员工
FollowUserList followUserList = weCustomerClient.getFollowUserList();
if (WeConstans.WE_SUCCESS_CODE.equals(followUserList.getErrcode())
&& ArrayUtil.isNotEmpty(followUserList.getFollow_user())) {
String[] follow_user = followUserList.getFollow_user();
if(ArrayUtil.isNotEmpty(follow_user)){
List<ExternalUserDetail> externalUserDetails = new ArrayList<>();
getByUser(follow_user, null, externalUserDetails);
if(CollectionUtil.isNotEmpty(externalUserDetails)){
this.weFlowerCustomerHandle(
externalUserDetails
);
public void synchWeCustomer() {
SecurityContext securityContext = SecurityContextHolder.getContext();
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
//获取所有可以添加客户的企业员工
FollowUserList followUserList = weCustomerClient.getFollowUserList();
if (WeConstans.WE_SUCCESS_CODE.equals(followUserList.getErrcode())
&& ArrayUtil.isNotEmpty(followUserList.getFollow_user())) {
String[] follow_user = followUserList.getFollow_user();
if(ArrayUtil.isNotEmpty(follow_user)){
List<ExternalUserDetail> externalUserDetails = new ArrayList<>();
getByUser(follow_user, null, externalUserDetails);
if(CollectionUtil.isNotEmpty(externalUserDetails)){
weFlowerCustomerHandle(
externalUserDetails
);
}
}
}
}
}
});
}
/**
* 客户同步业务处理
*
......
......@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.client.WeCustomerClient;
import com.linkwechat.wecom.client.WeCustomerGroupClient;
......@@ -17,9 +18,7 @@ import com.linkwechat.wecom.domain.WeCustomerAddGroup;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeGroupMember;
import com.linkwechat.wecom.domain.dto.AllocateWeGroupDto;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupDetail;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupList;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupMember;
import com.linkwechat.wecom.domain.dto.customer.*;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.mapper.WeGroupMapper;
import com.linkwechat.wecom.service.IWeAllocateGroupService;
......@@ -27,6 +26,8 @@ import com.linkwechat.wecom.service.IWeGroupMemberService;
import com.linkwechat.wecom.service.IWeGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -118,67 +119,80 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
* 客户群同步
*/
@Override
@Async
@Transactional(rollbackFor = Exception.class)
@SynchRecord(synchType = SynchRecordConstants.SYNCH_CUSTOMER_GROUP)
public void synchWeGroup() {
CustomerGroupList customerGroupList =
weCustomerGroupClient.groupChatLists(new CustomerGroupList().new Params());
if (customerGroupList.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
&& CollectionUtil.isNotEmpty(customerGroupList.getGroupChatList())) {
SecurityContext securityContext = SecurityContextHolder.getContext();
List<WeGroup> weGroups = new ArrayList<>();
List<WeGroupMember> weGroupMembers = new ArrayList<>();
customerGroupList.getGroupChatList().stream().forEach(k -> {
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(
new CustomerGroupDetail().new Params(k.getChatId(), 1)
);
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
if (customerGroupDetail.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
&& CollectionUtil.isNotEmpty(customerGroupDetail.getGroupChat())) {
CustomerGroupList customerGroupList =
weCustomerGroupClient.groupChatLists(new CustomerGroupList().new Params());
if (customerGroupList.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
&& CollectionUtil.isNotEmpty(customerGroupList.getGroupChatList())) {
customerGroupDetail.getGroupChat().stream().forEach(kk -> {
weGroups.add(
WeGroup.builder()
.chatId(kk.getChatId())
.groupName(StringUtils.isNotEmpty(kk.getName())? kk.getName() : "@微信群")
.notice(kk.getNotice())
.owner(kk.getOwner())
.addTime(new Date(kk.getCreateTime() * 1000L))
.status(k.getStatus())
.delFlag(new Integer(0))
.adminUserId(Optional.ofNullable(kk.getAdminList()).orElseGet(ArrayList::new).stream().map(admin -> admin.getString("userid")).collect(Collectors.joining(",")))
.build()
List<WeGroup> weGroups = new ArrayList<>();
List<WeGroupMember> weGroupMembers = new ArrayList<>();
customerGroupList.getGroupChatList().stream().forEach(k -> {
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient.groupChatDetail(
new CustomerGroupDetail().new Params(k.getChatId(), 1)
);
List<CustomerGroupMember> memberLists = kk.getMemberList();
if (CollectionUtil.isNotEmpty(memberLists)) {
memberLists.stream().forEach(member -> {
weGroupMembers.add(
WeGroupMember.builder()
if (customerGroupDetail.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)
&& CollectionUtil.isNotEmpty(customerGroupDetail.getGroupChat())) {
customerGroupDetail.getGroupChat().stream().forEach(kk -> {
weGroups.add(
WeGroup.builder()
.chatId(kk.getChatId())
.userId(member.getUserId())
.joinTime(new Date(member.getJoinTime() * 1000L))
.joinScene(member.getJoinScene())
.type(member.getType())
.unionId(member.getUnionId())
.groupNickName(member.getGroupNickName())
.name(member.getName())
.groupName(StringUtils.isNotEmpty(kk.getName())? kk.getName() : "@微信群")
.notice(kk.getNotice())
.owner(kk.getOwner())
.addTime(new Date(kk.getCreateTime() * 1000L))
.status(k.getStatus())
.delFlag(new Integer(0))
.invitorUserId(member.getInvitor() == null ? null : member.getInvitor().getString("userid"))
.adminUserId(Optional.ofNullable(kk.getAdminList()).orElseGet(ArrayList::new).stream().map(admin -> admin.getString("userid")).collect(Collectors.joining(",")))
.build()
);
List<CustomerGroupMember> memberLists = kk.getMemberList();
if (CollectionUtil.isNotEmpty(memberLists)) {
memberLists.stream().forEach(member -> {
weGroupMembers.add(
WeGroupMember.builder()
.chatId(kk.getChatId())
.userId(member.getUserId())
.joinTime(new Date(member.getJoinTime() * 1000L))
.joinScene(member.getJoinScene())
.type(member.getType())
.unionId(member.getUnionId())
.groupNickName(member.getGroupNickName())
.name(member.getName())
.delFlag(new Integer(0))
.invitorUserId(member.getInvitor() == null ? null : member.getInvitor().getString("userid"))
.build()
);
});
}
});
}
});
insertBatchGroupAndMember(weGroups, weGroupMembers);
}
}
});
});
}
});
insertBatchGroupAndMember(weGroups, weGroupMembers);
}
}
......
......@@ -267,8 +267,8 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
};
try {
return this.uploadWeMaterialFile(file1,fileType).getMaterialUrl();
WeMaterialFileVO weMaterialFileVO = this.uploadWeMaterialFile(file1, fileType);
return weMaterialFileVO.getMaterialUrl()+weMaterialFileVO.getMaterialName();
}catch (Exception e){
log.error("朋友圈资源获取失败:"+e.getMessage());
}
......
......@@ -9,7 +9,10 @@ import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.client.WeCropTagClient;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeTag;
import com.linkwechat.wecom.domain.WeTagGroup;
import com.linkwechat.wecom.domain.dto.tag.*;
......@@ -17,6 +20,9 @@ import com.linkwechat.wecom.mapper.WeTagGroupMapper;
import com.linkwechat.wecom.service.IWeTagGroupService;
import com.linkwechat.wecom.service.IWeTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -253,18 +259,32 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
* 同步标签
*/
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
@SynchRecord(synchType = SynchRecordConstants.SYNCH_CUSTOMER_TAG)
public void synchWeTags() {
WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getAllCorpTagList();
SecurityContext securityContext = SecurityContextHolder.getContext();
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getAllCorpTagList();
if (weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) {
batchSaveOrUpdateTagGroupAndTag(weCropGroupTagListDto.getTag_group(), true);
}
}
});
if (weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) {
this.batchSaveOrUpdateTagGroupAndTag(weCropGroupTagListDto.getTag_group(), true);
}
}
/**
* 来自微信端批量保存或者更新标签组和标签
*
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!