企业客群;企业标签相关代码提交

1 parent c3359e5f
......@@ -9,11 +9,13 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeCustomerTrajectoryService;
import com.linkwechat.wecom.service.IWeSynchRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
......@@ -41,6 +43,10 @@ public class WeCustomerController extends BaseController
private IWeCustomerTrajectoryService iWeCustomerTrajectoryService;
@Autowired
private IWeSynchRecordService iWeSynchRecordService;
/**********************************************************************************
**************************************客户列表*************************************
*********************************************************************************/
......@@ -55,7 +61,9 @@ public class WeCustomerController extends BaseController
startPage();
List<WeCustomerList> list = weCustomerService.findWeCustomerList(weCustomerList);
TableDataInfo dataTable = getDataTable(list);
dataTable.setLastSyncTime(new Date());//最近同步时间
dataTable.setLastSyncTime(
iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER)
);//最近同步时间
dataTable.setNoRepeatCustomerTotal(
weCustomerService.noRepeatCountCustomer()
);//去重客户数
......
......@@ -5,12 +5,14 @@ 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.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeGroupMember;
import com.linkwechat.wecom.domain.vo.WeMakeGroupTagVo;
import com.linkwechat.wecom.service.IWeGroupMemberService;
import com.linkwechat.wecom.service.IWeGroupService;
import com.linkwechat.wecom.service.IWeGroupTagRelService;
import com.linkwechat.wecom.service.IWeSynchRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -40,15 +42,35 @@ public class WeGroupController extends BaseController {
@Autowired
private IWeGroupTagRelService iWeGroupTagRelService;
@Autowired
private IWeSynchRecordService iWeSynchRecordService;
// @PreAuthorize("@ss.hasPermi('customerManage:group:list')")
@GetMapping({"/list"})
public TableDataInfo list(WeGroup weGroup) {
startPage();
List<WeGroup> list = this.weGroupService.selectWeGroupList(weGroup);
return getDataTable(list);
TableDataInfo dataTable = getDataTable(list);
dataTable.setLastSyncTime(
iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER_GROUP)
);//最近同步时间
return dataTable;
}
/**
* 获取所有群接口(不分页)
* @param weGroup
* @return
*/
@GetMapping({"/allList"})
public AjaxResult allList(WeGroup weGroup) {
return AjaxResult.success(
this.weGroupService.selectWeGroupList(weGroup)
);
}
// @PreAuthorize("@ss.hasPermi('customerManage:group:view')")
@GetMapping({"/members"})
......@@ -65,14 +87,7 @@ public class WeGroupController extends BaseController {
// @PreAuthorize("@ss.hasPermi('customerManage:group:sync')")
@GetMapping({"/synchWeGroup"})
public AjaxResult synchWeGroup(){
try {
SecurityContext context = SecurityContextHolder.getContext();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
SecurityContextHolder.setContext(context);
weGroupService.synchWeGroup();
} catch (Exception e) {
e.printStackTrace();
}
weGroupService.synchWeGroup();
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
......
......@@ -42,7 +42,7 @@ public class WeTagGroupController extends BaseController
private IWeTagGroupService weTagGroupService;
/**
* 查询标签组列表
* 查询标签组列表(分页)
*/
// @PreAuthorize("@ss.hasPermi('customerManage:tag:list')")
@GetMapping("/list")
......@@ -55,6 +55,19 @@ public class WeTagGroupController extends BaseController
}
/**
* 查询标签组列表(不分页)
* @param weTagGroup
* @return
*/
@GetMapping("/allList")
public AjaxResult allList(WeTagGroup weTagGroup)
{
return AjaxResult.success(
weTagGroupService.selectWeTagGroupList(weTagGroup)
);
}
/**
* 新增标签组
......
......@@ -11,6 +11,6 @@ import java.lang.annotation.*;
@Documented
public @interface SynchRecord {
int synchType() default 1; //1:默认客户模块;2:员工与部门;
int synchType(); //1:默认客户模块;2:通讯录(员工与部门);3:客户群
}
......@@ -40,6 +40,7 @@ public class SynchRecordAop {
SynchRecord annotationLog = getAnnotationLog(joinPoint);
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')"));
if(CollectionUtil.isEmpty(weSynchRecords)||weSynchRecords.size()<=1){
......
package com.linkwechat.wecom.constants;
import lombok.Data;
@Data
public class SynchRecordConstants {
public static final int SYNCH_CUSTOMER=1;//客户同步
public static final int SYNCH_MAIL_LIST=2;//通讯录同步(组织架构和员工)
public static final int SYNCH_CUSTOMER_GROUP=3;//客户群同步
}
......@@ -116,6 +116,19 @@ public class WeGroup extends BaseEntity{
*/
private String adminUserId;
/**
* 客户数量
*/
@TableField(exist = false)
private Integer customerNum;
/**
* 今日进群数
*/
@TableField(exist = false)
private Integer toDayMemberNum;
@TableLogic
private Integer delFlag=new Integer(0);
}
......@@ -55,7 +55,7 @@ public class WeTagGroup extends BaseEntity
/**标签分组类型(1:客户标签;2:群标签)*/
private Integer groupTagType=new Integer(1);
private Integer groupTagType;
......
......@@ -3,5 +3,8 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeSynchRecord;
import java.util.Date;
public interface IWeSynchRecordService extends IService<WeSynchRecord> {
Date findUpdateLatestTime(int synchType);
}
......@@ -3,32 +3,24 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSONObject;
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.TrajectorySceneType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.annotation.SynchRecord;
import com.linkwechat.wecom.client.WeCropTagClient;
import com.linkwechat.wecom.client.WeCustomerClient;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.*;
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.WeCropGroupTagDto;
import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagListDto;
import com.linkwechat.wecom.domain.dto.tag.WeCropTagDto;
import com.linkwechat.wecom.domain.dto.tag.WeFindCropTagParam;
import com.linkwechat.wecom.domain.vo.WeCustomerDetailVo;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.mapper.WeCustomerMapper;
......@@ -37,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -57,13 +48,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
private WeCustomerClient weCustomerClient;
@Autowired
private IWeTagGroupService iWeTagGroupService;
@Autowired
private IWeFlowerCustomerTagRelService iWeFlowerCustomerTagRelService;
......@@ -110,26 +94,25 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
@Override
@Async
@Transactional(rollbackFor = Exception.class)
@SynchRecord
@SynchRecord(synchType = SynchRecordConstants.SYNCH_CUSTOMER)
public void synchWeCustomer() {
//获取所有可以添加客户的企业员工
log.warn("客户同步");
// 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
// );
// }
// }
// }
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
);
}
}
}
}
......
......@@ -7,9 +7,11 @@ 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.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.WeAllocateGroup;
import com.linkwechat.wecom.domain.WeCustomerAddGroup;
import com.linkwechat.wecom.domain.WeGroup;
......@@ -118,6 +120,7 @@ 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 =
......
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.wecom.domain.WeSynchRecord;
import com.linkwechat.wecom.mapper.WeSynchRecordMapper;
import com.linkwechat.wecom.service.IWeSynchRecordService;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class WeSynchRecordServiceImpl extends ServiceImpl<WeSynchRecordMapper, WeSynchRecord> implements IWeSynchRecordService {
@Override
public Date findUpdateLatestTime(int synchType) {
List<WeSynchRecord> records = this.list(new LambdaQueryWrapper<WeSynchRecord>()
.eq(WeSynchRecord::getSynchType, synchType)
.orderByDesc(WeSynchRecord::getSynchTime));
if(CollectionUtil.isNotEmpty(records)){
return records.stream().findFirst().get().getSynchTime();
}
return null;
}
}
......@@ -13,13 +13,17 @@
wg.notice,
wu.user_name as groupLeaderName,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id and wgm.type=2) as customerNum,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id and to_days(wgm.join_time) = to_days(now())) as toDayMemberNum,
wg.status,
wg.`owner`,
(SELECT GROUP_CONCAT(wt.`name`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tags,
(SELECT GROUP_CONCAT(wt.`tag_id`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tagIds
GROUP_CONCAT(wt.`name`) as tags,
GROUP_CONCAT(wt.`tag_id`) as tagIds
FROM
we_group wg
LEFT JOIN we_user wu ON wg.`owner`=wu.user_id
LEFT JOIN we_group_tag_rel wgtr ON wg.chat_id=wgtr.chat_id
LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id
<where>
<if test="delFlag !=null"> wg.del_flag=#{delFlag}</if>
<if test="groupName != null and groupName != ''"> and wg.group_name like concat('%', #{groupName}, '%')</if>
......@@ -27,7 +31,6 @@
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wg.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wg.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
......@@ -42,7 +45,14 @@
AND wg.`owner`=#{userIds}
</if>
</if>
<if test="tagIds !=null and tagIds !=''">
AND wt.tag_id in
<foreach item="item" index="index" collection="tagIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
GROUP BY wg.chat_id
</select>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!