diff --git a/linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java b/linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java index 6fab8b7a20f2191431fdaaaa0c49e71002cb06c2..7b9fcf416ce8a4c826d8461c7d4dc25a6c922abe 100644 --- a/linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java +++ b/linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeCustomerController.java @@ -1,27 +1,23 @@ package com.linkwechat.web.controller.wecom; -import java.util.List; - import com.linkwechat.common.annotation.Log; 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.enums.BusinessType; -import com.linkwechat.common.utils.poi.ExcelUtil; -import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.linkwechat.common.utils.Threads; import com.linkwechat.wecom.domain.WeCustomer; +import com.linkwechat.wecom.domain.WeCustomerQuery; +import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag; import com.linkwechat.wecom.service.IWeCustomerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * 企业微信客户Controller @@ -40,11 +36,12 @@ public class WeCustomerController extends BaseController * 查询企业微信客户列表 */ @PreAuthorize("@ss.hasPermi('customerManage:customer:list')") - @GetMapping("/list") - public TableDataInfo list(WeCustomer weCustomer) + @PostMapping("/list") + public TableDataInfo list(@RequestBody WeCustomerQuery weCustomerQuery) { startPage(); - List list = weCustomerService.selectWeCustomerList(weCustomer); + List list = weCustomerService.selectWeCustomerList(weCustomerQuery); + return getDataTable(list); } @@ -106,9 +103,18 @@ public class WeCustomerController extends BaseController @Log(title = "企业微信客户同步接口", businessType = BusinessType.DELETE) @GetMapping("/synchWeCustomer") public AjaxResult synchWeCustomer(){ - - weCustomerService.synchWeCustomer(); - + SecurityContext securityContext = SecurityContextHolder.getContext(); + try { + Threads.SINGLE_THREAD_POOL.execute(new Runnable() { + @Override + public void run() { + SecurityContextHolder.setContext(securityContext); + weCustomerService.synchWeCustomer(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } return AjaxResult.success(WeConstans.SYNCH_TIP); } diff --git a/linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java b/linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java index e735681f54dae87976de014c77b0dcd552e3fc51..a527ded646f44e749b7748cd0ab95e2be69ad1f5 100644 --- a/linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java +++ b/linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java @@ -167,7 +167,8 @@ public class WeConstans { */ public static final Integer NOT_EXIST_CONTACT=84061; - + public static final String USER_ID = "userid"; + public static final String CURSOR = "cursor"; } diff --git a/linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java b/linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java index ec9257dc92c75467dccfe0603ccab9afc16f4f89..167474be76ea3bdef5f42fc0ce3983e2be8b0eff 100644 --- a/linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java +++ b/linkwe-common/src/main/java/com/linkwechat/common/utils/Threads.java @@ -1,10 +1,8 @@ package com.linkwechat.common.utils; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +15,16 @@ public class Threads { private static final Logger logger = LoggerFactory.getLogger(Threads.class); + private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors(); + + private static final ThreadFactory NAMED_THREAD_FACTORY = new ThreadFactoryBuilder().setNameFormat("common-pool-%d").build(); + /** + * 创建线程池 + */ + public static final ThreadPoolExecutor SINGLE_THREAD_POOL = new ThreadPoolExecutor(CORE_POOL_SIZE, CORE_POOL_SIZE+1, 10l, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(1024),NAMED_THREAD_FACTORY); + + /** * sleep等待,单位为毫秒 */ diff --git a/linkwe-ui/src/api/customer/index.js b/linkwe-ui/src/api/customer/index.js index b1f8fd90cf8bcd8d12bc698abcdf3b997b5b07d0..83fa0978255444fdec059dfbeb424e36702397f1 100644 --- a/linkwe-ui/src/api/customer/index.js +++ b/linkwe-ui/src/api/customer/index.js @@ -14,10 +14,12 @@ const service = config.services.wecom + '/customer' "endTime": "结束时间" } */ +console.log(request) export function getList(params) { return request({ url: service + '/list', - params + method: 'post', + data: params }) } diff --git a/linkwe-ui/src/views/customerManage/customer.vue b/linkwe-ui/src/views/customerManage/customer.vue index 8c9bc1b3362c4690e8442f57076bace200c1bb23..1324c3ca01b1113800d5d2be2c92389760308fe2 100644 --- a/linkwe-ui/src/views/customerManage/customer.vue +++ b/linkwe-ui/src/views/customerManage/customer.vue @@ -12,13 +12,15 @@ export default { data() { return { query: { - pageNum: 1, - pageSize: 10, name: "", // "客户名称", - userId: "", // "添加人id", - tagIds: "", // "标签id,多个标签,id使用逗号隔开", - beginTime: "", // "开始时间", - endTime: "", // "结束时间" + params:{ + pageNum: 1, + pageSize: 10, + beginTime: "", // "开始时间", + endTime: "", // "结束时间", + userId: "", // "添加人id", + tagIds: "", // "标签id,多个标签,id使用逗号隔开", + } }, queryTag: [], // 搜索框选择的标签 queryUser: [], // 搜索框选择的添加人 @@ -92,12 +94,14 @@ export default { mounted() {}, methods: { getList(page) { - // console.log(this.dateRange); if (this.dateRange[0]) { - this.query.beginTime = this.dateRange[0]; - this.query.endTime = this.dateRange[1]; + this.query.params.beginTime = this.dateRange[0]; + this.query.params.endTime = this.dateRange[1]; + }else { + this.query.params.beginTime = ""; + this.query.params.endTime = ""; } - page && (this.query.pageNum = page); + page && (this.query.params.pageNum = page); this.loading = true; api .getList(this.query) @@ -173,15 +177,18 @@ export default { api.sync().then(() => { loading.close(); this.msgSuccess("后台开始同步数据,请稍后关注进度"); + }).catch(fail => { + loading.close(); + console.log(fail) }); }, selectedUser(list) { this.queryUser = list; - this.query.userId = list.map((d) => d.id) + ""; + this.query.params.userId = list.map((d) => d.id) + ""; }, submitSelectTag(formName) { if (this.tagDialogType.type === "query") { - this.query.tagIds = this.selectedTag.map((d) => d.tagId) + ""; + this.query.params.tagIds = this.selectedTag.map((d) => d.tagId) + ""; // debugger; this.queryTag = this.selectedTag; this.dialogVisible = false; @@ -366,8 +373,8 @@ export default { diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java index eb221c73a1f9b62c5f1b50074847956374aa2200..fe3e71e38014c9665e5041e14a70ae27d4d8ea06 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java @@ -10,6 +10,8 @@ import com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail; import com.linkwechat.wecom.domain.dto.customer.ExternalUserList; import com.linkwechat.wecom.domain.dto.customer.FollowUserList; +import java.util.Map; + /** * @description: 获取配置客户联系人功能的成员 * @author: HaoN @@ -33,6 +35,14 @@ public interface WeCustomerClient { @Request(url = "/externalcontact/list") ExternalUserList list(@Query("userid") String userId); + /** + * 根据企业成员id批量获取客户详情 + * @param query + * @return + */ + @Request(url = "/externalcontact/batch/get_by_user", type = "POST") + ExternalUserList getByUser(@DataObject Map query); + /** * 根据客户id获取客户详情 diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java index 01ef177cc8a05fed6a59d888cc4b14e04fa56045..f6824cace934acbf7d7a4fc79a01eb58921e8bdd 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomer.java @@ -27,10 +27,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; @AllArgsConstructor @NoArgsConstructor @TableName("we_customer") -public class WeCustomer -{ - private static final long serialVersionUID = 1L; - +public class WeCustomer{ /** 外部联系人的userid */ @TableId diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomerQuery.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomerQuery.java new file mode 100644 index 0000000000000000000000000000000000000000..a53cd66df327104c392e8031398a18a96521301e --- /dev/null +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomerQuery.java @@ -0,0 +1,74 @@ +package com.linkwechat.wecom.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.linkwechat.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author sunxiwang + * @description 客户查询入参实体 + * @date 2020/11/2 11:38 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class WeCustomerQuery extends BaseEntity { + + /** + * 外部联系人的userid + */ + private String externalUserid; + + /** + * 外部联系人名称 + */ + private String name; + + /** + * 外部联系人头像 + */ + private String avatar; + + /** + * 外部联系人的类型,1表示该外部联系人是微信用户,2表示该外部联系人是企业微信用户 + */ + private Integer type; + + /** + * 外部联系人性别 0-未知 1-男性 2-女性 + */ + private Integer gender; + + /** + * 外部联系人在微信开放平台的唯一身份标识,通过此字段企业可将外部联系人与公众号/小程序用户关联起来。 + */ + private String unionid; + + /** + * 生日 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date birthday; + + + /** + * 客户企业简称 + */ + private String corpName; + + /** + * 客户企业全称 + */ + private String corpFullName; + + /** + * 职位 + */ + private String position; +} diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java index 2b646f7541e204945a1ba502e6a0f8346c7f4f01..b7ed0d83cc169eb18a97db0a43ce358fff2894a3 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserDetail.java @@ -21,6 +21,7 @@ public class ExternalUserDetail extends WeResultDto { /** 客户联系人 */ private List follow_user; + private List follow_info; @Data @@ -68,4 +69,24 @@ public class ExternalUserDetail extends WeResultDto { private List tags; } + @Data + public class FollowInfo{ + /**该成员对此外部联系人的备注*/ + private String remark; + /**该成员对此外部联系人的描述*/ + private String description; + /**该成员添加此外部联系人的时间*/ + private long createtime; + /**该成员对此客户备注的企业名称*/ + private String remark_company; + /**该成员对此客户备注的手机号码*/ + private String[] remark_mobiles; + /**该成员添加此客户的来源*/ + private Integer add_way; + /**发起添加的userid,如果成员主动添加,为成员的userid;如果是客户主动添加,则为客户的外部联系人userid;如果是内部成员共享/管理员分配,则为对应的成员/管理员userid*/ + private String oper_userid; + /**标签**/ + private String[] tag_id; + } + } diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java index 55571d47c5f67c0d9b38fc5784443532d4534db9..ef5cd3e94d06006485a635774d30a8b9da0a54d2 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/dto/customer/ExternalUserList.java @@ -3,6 +3,8 @@ package com.linkwechat.wecom.domain.dto.customer; import com.linkwechat.wecom.domain.dto.WeResultDto; import lombok.Data; +import java.util.List; + /** * @description: 客户列表 * @author: HaoN @@ -11,4 +13,6 @@ import lombok.Data; @Data public class ExternalUserList extends WeResultDto { private String[] external_userid; + private List external_contact_list; + private String next_cursor; } diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java index 8484e0827eca745dcb83dd74fbf71e745a9eb391..8303eecee8253a88a12641207569db2001630c19 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.linkwechat.wecom.domain.WeCustomer; +import com.linkwechat.wecom.domain.WeCustomerQuery; import com.linkwechat.wecom.domain.WeUser; import org.apache.ibatis.annotations.Param; @@ -26,10 +27,10 @@ public interface WeCustomerMapper extends BaseMapper /** * 查询企业微信客户列表 * - * @param weCustomer 企业微信客户 + * @param weCustomerQuery 企业微信客户 * @return 企业微信客户集合 */ - public List selectWeCustomerList(WeCustomer weCustomer); + public List selectWeCustomerList(WeCustomerQuery weCustomerQuery); /** * 新增企业微信客户 diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java index 1a289a31f026798a4710ea2fe86964b3a7fbd00c..0b7452f0bdf8785dae128187062b13d39066effc 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeCustomerService.java @@ -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.WeCustomerQuery; import com.linkwechat.wecom.domain.WeUser; import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo; import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag; @@ -27,10 +28,10 @@ public interface IWeCustomerService extends IService /** * 查询企业微信客户列表 * - * @param weCustomer 企业微信客户 + * @param weCustomerQuery 企业微信客户 * @return 企业微信客户集合 */ - public List selectWeCustomerList(WeCustomer weCustomer); + public List selectWeCustomerList(WeCustomerQuery weCustomerQuery); /** diff --git a/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java b/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java index 04a9232628823b3e87280e4b15fc5c6803de16a1..f4e902844566094ea3619aa5b576f24ccd0a715b 100644 --- a/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java +++ b/linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerServiceImpl.java @@ -3,21 +3,22 @@ package com.linkwechat.wecom.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.linkwechat.common.constant.WeConstans; -import com.linkwechat.common.utils.DateUtils; import com.linkwechat.common.utils.SecurityUtils; import com.linkwechat.common.utils.SnowFlakeUtil; +import com.linkwechat.common.utils.StringUtils; +import com.linkwechat.common.utils.Threads; import com.linkwechat.common.utils.bean.BeanUtils; -import com.linkwechat.framework.web.domain.server.Sys; import com.linkwechat.wecom.client.WeCropTagClient; import com.linkwechat.wecom.client.WeCustomerClient; import com.linkwechat.wecom.client.WeUserClient; import com.linkwechat.wecom.domain.*; import com.linkwechat.wecom.domain.dto.AllocateWeCustomerDto; -import com.linkwechat.wecom.domain.dto.WeResultDto; -import com.linkwechat.wecom.domain.dto.customer.*; +import com.linkwechat.wecom.domain.dto.customer.CutomerTagEdit; +import com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail; +import com.linkwechat.wecom.domain.dto.customer.ExternalUserList; +import com.linkwechat.wecom.domain.dto.customer.FollowUserList; import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagDto; import com.linkwechat.wecom.domain.dto.tag.WeCropGroupTagListDto; import com.linkwechat.wecom.domain.dto.tag.WeCropTagDto; @@ -27,21 +28,24 @@ 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.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.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * 企业微信客户Service业务层处理 - * + * * @author ruoyi * @date 2020-09-13 */ @Service -public class WeCustomerServiceImpl extends ServiceImpl implements IWeCustomerService -{ +public class WeCustomerServiceImpl extends ServiceImpl implements IWeCustomerService { @Autowired private WeCustomerMapper weCustomerMapper; @@ -76,38 +80,32 @@ public class WeCustomerServiceImpl extends ServiceImpl selectWeCustomerList(WeCustomer weCustomer) - { - return weCustomerMapper.selectWeCustomerList(weCustomer); + public List selectWeCustomerList(WeCustomerQuery weCustomerQuery) { + return weCustomerMapper.selectWeCustomerList(weCustomerQuery); } - /** * 客户同步接口 + * * @return */ @Override @@ -116,164 +114,173 @@ public class WeCustomerServiceImpl extends ServiceImpl{ - - //获取指定联系人对应的客户 - ExternalUserList externalUsers = weCustomerClient.list(k); - if(WeConstans.WE_SUCCESS_CODE.equals(externalUsers.getErrcode()) - || WeConstans.NOT_EXIST_CONTACT.equals(externalUsers.getErrcode()) - && ArrayUtil.isNotEmpty(externalUsers.getExternal_userid())){ - - Arrays.asList(externalUsers.getExternal_userid()).forEach(v->{ - - //获取指定客户的详情 - ExternalUserDetail externalUserDetail = weCustomerClient.get(v); - - if(WeConstans.WE_SUCCESS_CODE.equals(externalUserDetail.getErrcode())){ - //客户入库 - WeCustomer weCustomer=new WeCustomer(); - BeanUtils.copyPropertiesignoreOther( externalUserDetail.getExternal_contact(),weCustomer); - this.saveOrUpdate(weCustomer); - - //客户与通讯录客户关系 - List weTags=new ArrayList<>(); - List weGroups=new ArrayList<>(); - List weFlowerCustomerTagRels=new ArrayList<>(); - List weFlowerCustomerRel=new ArrayList<>(); - externalUserDetail.getFollow_user().stream().forEach(kk->{ + .stream().forEach(k -> { + try { + Threads.SINGLE_THREAD_POOL.execute(new Runnable() { + @Override + public void run() { + SecurityContextHolder.setContext(securityContext); + weFlowerCustomerHandle(k); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + }); + Threads.shutdownAndAwaitTermination(Threads.SINGLE_THREAD_POOL); + } + } + + /** + * 客户同步业务处理 + * + * @param userId 开通权限的企业成员id + */ + private void weFlowerCustomerHandle(String userId) { + System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>"+Thread.currentThread().getName()); + List list = new ArrayList<>(); + getByUser(userId, null, list); + list.forEach(userDetail -> { + //客户入库 + WeCustomer weCustomer = new WeCustomer(); + BeanUtils.copyPropertiesignoreOther(userDetail.getExternal_contact(), weCustomer); + this.saveOrUpdate(weCustomer); + + //客户与通讯录客户关系 + List weTags = new ArrayList<>(); + List weGroups = new ArrayList<>(); + List weFlowerCustomerTagRels = new ArrayList<>(); + List weFlowerCustomerRel = new ArrayList<>(); + userDetail.getFollow_info().stream().forEach(kk -> { // WeFlowerCustomerRel weFlowerCustomerRelOne=new WeFlowerCustomerRel(); // BeanUtils.copyPropertiesignoreOther(kk,weFlowerCustomerRelOne); - Long weFlowerCustomerRelId=SnowFlakeUtil.nextId(); + Long weFlowerCustomerRelId = SnowFlakeUtil.nextId(); // weFlowerCustomerRelOne.setId(weFlowerCustomerRelId); // weFlowerCustomerRelOne.setExternalUserid(weCustomer.getExternalUserid()); - weFlowerCustomerRel.add(WeFlowerCustomerRel.builder() - .id(weFlowerCustomerRelId) - .userId(kk.getUserid()) - .description(kk.getDescription()) - .remarkCorpName(kk.getRemark_company()) - .remarkMobiles(kk.getRemark_mobiles()) - .operUserid(kk.getOper_userid()) - .addWay(kk.getAdd_way()) - .externalUserid(weCustomer.getExternalUserid()) - .createTime(new Date(kk.getCreatetime() * 1000L)) - .build()); - - List tags = kk.getTags(); - if(CollectionUtil.isNotEmpty(tags)){ - - //获取相关标签组 - WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getCorpTagListByTagIds(WeFindCropTagParam.builder() - .tag_id(ArrayUtil.toArray(tags.stream().map(ExternalUserTag::getTag_id).collect(Collectors.toList()), String.class)) - .build()); - - if(weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){ - List tagGroups = weCropGroupTagListDto.getTag_group(); - if(CollectionUtil.isNotEmpty(tagGroups)){ - tagGroups.stream().forEach(tagGroup->{ - weGroups.add( - WeTagGroup.builder() - .groupId(tagGroup.getGroup_id()) - .gourpName(tagGroup.getGroup_name()) - .createBy(SecurityUtils.getUsername()) - .build() - ); - - List weCropTagDtos= tagGroup.getTag(); - - if(CollectionUtil.isNotEmpty(weCropTagDtos)){ - Set tagIdsSet = weCropTagDtos.stream().map(WeCropTagDto::getId).collect(Collectors.toSet()); - - tags.stream().forEach(tag->{ - - if(tagIdsSet.contains(tag.getTag_id())){ - - weTags.add( - WeTag.builder() - .groupId(tagGroup.getGroup_id()) - .tagId(tag.getTag_id()) - .name(tag.getTag_name()) - .build() - ); - - weFlowerCustomerTagRels.add( - WeFlowerCustomerTagRel.builder() - .flowerCustomerRelId(weFlowerCustomerRelId) - .tagId(tag.getTag_id()) - .createTime(new Date()) - .build() - ); - - - } - - - - }); - - - } - - - }); - - - + weFlowerCustomerRel.add(WeFlowerCustomerRel.builder() + .id(weFlowerCustomerRelId) + .userId(userId) + .description(kk.getDescription()) + .remarkCorpName(kk.getRemark_company()) + .remarkMobiles(kk.getRemark_mobiles()) + .operUserid(kk.getOper_userid()) + .addWay(kk.getAdd_way()) + .externalUserid(weCustomer.getExternalUserid()) + .createTime(new Date(kk.getCreatetime() * 1000L)) + .build()); + + List tags = Stream.of(kk.getTag_id()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(tags)) { + + //获取相关标签组 + WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getCorpTagListByTagIds(WeFindCropTagParam.builder() + .tag_id(kk.getTag_id()) + .build()); + + if (weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) { + List tagGroups = weCropGroupTagListDto.getTag_group(); + if (CollectionUtil.isNotEmpty(tagGroups)) { + tagGroups.stream().forEach(tagGroup -> { + weGroups.add( + WeTagGroup.builder() + .groupId(tagGroup.getGroup_id()) + .gourpName(tagGroup.getGroup_name()) + .createBy(SecurityUtils.getUsername()) + .build() + ); + List weCropTagDtos = tagGroup.getTag(); + if (CollectionUtil.isNotEmpty(weCropTagDtos)) { + Map map = weCropTagDtos.stream().collect(Collectors.toMap(WeCropTagDto::getId, WeCropTagDto::getName)); + tags.forEach(tag -> { + if (map.containsKey(tag)) { + weTags.add( + WeTag.builder() + .groupId(tagGroup.getGroup_id()) + .tagId(tag) + .name(map.get(tag)) + .build() + ); + + weFlowerCustomerTagRels.add( + WeFlowerCustomerTagRel.builder() + .flowerCustomerRelId(weFlowerCustomerRelId) + .tagId(tag) + .createTime(new Date()) + .build() + ); } - } - - + }); } - }); - List weFlowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper() - .eq(WeFlowerCustomerRel::getExternalUserid, weCustomer.getExternalUserid())); - - if(CollectionUtil.isNotEmpty(weFlowerCustomerRels)){ - List weFlowerCustomerRelIds = weFlowerCustomerRels.stream().map(WeFlowerCustomerRel::getId).collect(Collectors.toList()); - iWeFlowerCustomerTagRelService.remove( - new LambdaQueryWrapper().in(WeFlowerCustomerTagRel::getFlowerCustomerRelId, - weFlowerCustomerRelIds) - ); - - iWeFlowerCustomerRelService.removeByIds( - weFlowerCustomerRelIds - ); - } + }); - iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRel); - - //设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系 - if(CollectionUtil.isNotEmpty(weTags)&&CollectionUtil.isNotEmpty(weGroups)){ - iWeTagService.saveOrUpdateBatch(weTags); - iWeTagGroupService.saveOrUpdateBatch(weGroups); - iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels); - } } + } - - }); - } - }); + List weFlowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper() + .eq(WeFlowerCustomerRel::getExternalUserid, weCustomer.getExternalUserid())); + + if (CollectionUtil.isNotEmpty(weFlowerCustomerRels)) { + List weFlowerCustomerRelIds = weFlowerCustomerRels.stream().map(WeFlowerCustomerRel::getId).collect(Collectors.toList()); + iWeFlowerCustomerTagRelService.remove( + new LambdaQueryWrapper().in(WeFlowerCustomerTagRel::getFlowerCustomerRelId, + weFlowerCustomerRelIds) + ); + iWeFlowerCustomerRelService.removeByIds( + weFlowerCustomerRelIds + ); + } - } + iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRel); + + //设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系 + if (CollectionUtil.isNotEmpty(weTags) && CollectionUtil.isNotEmpty(weGroups)) { + iWeTagService.saveOrUpdateBatch(weTags); + iWeTagGroupService.saveOrUpdateBatch(weGroups); + iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels); + } + }); } + /** + * 批量获取客户详情 + * + * @param userId 企业成员的userid + * @param nextCursor 用于分页查询的游标 + * @param list 返回结果 + */ + private void getByUser(String userId, String nextCursor, List list) { + Map query = new HashMap<>(16); + query.put(WeConstans.USER_ID, userId); + query.put(WeConstans.CURSOR, nextCursor); + ExternalUserList externalUserList = weCustomerClient.getByUser(query); + if (WeConstans.WE_SUCCESS_CODE.equals(externalUserList.getErrcode()) + || WeConstans.NOT_EXIST_CONTACT.equals(externalUserList.getErrcode()) + && ArrayUtil.isNotEmpty(externalUserList.getExternal_contact_list())) { + list.addAll(externalUserList.getExternal_contact_list()); + if (StringUtils.isNotEmpty(externalUserList.getNext_cursor())) { + getByUser(userId, externalUserList.getNext_cursor(), list); + } + } + } /** * 分配离职员工客户 + * * @param weLeaveUserInfoAllocateVo */ @Override @@ -283,12 +290,11 @@ public class WeCustomerServiceImpl extends ServiceImpl weFlowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper() .eq(WeFlowerCustomerRel::getUserId, weLeaveUserInfoAllocateVo.getHandoverUserid())); - if(CollectionUtil.isNotEmpty(weFlowerCustomerRels)){ - + if (CollectionUtil.isNotEmpty(weFlowerCustomerRels)) { - List weAllocateCustomers=new ArrayList<>(); - weFlowerCustomerRels.stream().forEach(k->{ + List weAllocateCustomers = new ArrayList<>(); + weFlowerCustomerRels.stream().forEach(k -> { k.setUserId(weLeaveUserInfoAllocateVo.getTakeoverUserid()); weAllocateCustomers.add( WeAllocateCustomer.builder() @@ -304,12 +310,12 @@ public class WeCustomerServiceImpl extends ServiceImpl{ + weAllocateCustomers.stream().forEach(v -> { weUserClient.allocateCustomer(AllocateWeCustomerDto.builder() .external_userid(v.getExternalUserid()) .handover_userid(v.getHandoverUserid()) @@ -322,8 +328,6 @@ public class WeCustomerServiceImpl extends ServiceImpl flowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper() .eq(WeFlowerCustomerRel::getExternalUserid, weMakeCustomerTag.getExternalUserid())); - if(CollectionUtil.isNotEmpty(flowerCustomerRels)){ - + if (CollectionUtil.isNotEmpty(flowerCustomerRels)) { List addTags = weMakeCustomerTag.getAddTag(); - - if(CollectionUtil.isNotEmpty(addTags)){ + if (CollectionUtil.isNotEmpty(addTags)) { addTags.removeAll(Collections.singleton(null)); - List tagRels=new ArrayList<>(); - - List cutomerTagEdits=new ArrayList<>(); - flowerCustomerRels.stream().forEach(customer->{ - CutomerTagEdit cutomerTagEdit = CutomerTagEdit.builder() - .userid(customer.getUserId()) - .external_userid(customer.getExternalUserid()) - .build(); - List tags=new ArrayList<>(); - addTags.stream().forEach(tag->{ - tags.add(tag.getTagId()); - tagRels.add( - WeFlowerCustomerTagRel.builder() - .flowerCustomerRelId(customer.getId()) - .tagId(tag.getTagId()) - .createTime(new Date()) - .build() - ); - }); - - cutomerTagEdit.setAdd_tag(ArrayUtil.toArray(tags,String.class)); - cutomerTagEdits.add(cutomerTagEdit); + List tagRels = new ArrayList<>(); + + List cutomerTagEdits = new ArrayList<>(); + flowerCustomerRels.stream().forEach(customer -> { + CutomerTagEdit cutomerTagEdit = CutomerTagEdit.builder() + .userid(customer.getUserId()) + .external_userid(customer.getExternalUserid()) + .build(); + List tags = new ArrayList<>(); + addTags.stream().forEach(tag -> { + tags.add(tag.getTagId()); + tagRels.add( + WeFlowerCustomerTagRel.builder() + .flowerCustomerRelId(customer.getId()) + .tagId(tag.getTagId()) + .createTime(new Date()) + .build() + ); }); - if(iWeFlowerCustomerTagRelService.saveOrUpdateBatch(tagRels)){ - if(CollectionUtil.isNotEmpty(cutomerTagEdits)){ - cutomerTagEdits.stream().forEach(k->{ + cutomerTagEdit.setAdd_tag(ArrayUtil.toArray(tags, String.class)); + cutomerTagEdits.add(cutomerTagEdit); + }); + + if (iWeFlowerCustomerTagRelService.saveOrUpdateBatch(tagRels)) { + if (CollectionUtil.isNotEmpty(cutomerTagEdits)) { + cutomerTagEdits.stream().forEach(k -> { weCustomerClient.makeCustomerLabel( k ); @@ -387,12 +390,12 @@ public class WeCustomerServiceImpl extends ServiceImpl addTags = weMakeCustomerTag.getAddTag(); - if(CollectionUtil.isNotEmpty(addTags)){ + if (CollectionUtil.isNotEmpty(addTags)) { //获取当前客户需要移除的标签 List removeTag = iWeFlowerCustomerTagRelService.list(new LambdaQueryWrapper() @@ -415,15 +418,15 @@ public class WeCustomerServiceImpl extends ServiceImpl flowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper() .eq(WeFlowerCustomerRel::getExternalUserid, weMakeCustomerTag.getExternalUserid())); - if(CollectionUtil.isNotEmpty(flowerCustomerRels) ){ + if (CollectionUtil.isNotEmpty(flowerCustomerRels)) { - if(iWeFlowerCustomerTagRelService.remove( + if (iWeFlowerCustomerTagRelService.remove( new LambdaQueryWrapper() .in(WeFlowerCustomerTagRel::getFlowerCustomerRelId, flowerCustomerRels.stream().map(WeFlowerCustomerRel::getId).collect(Collectors.toList())) .in(WeFlowerCustomerTagRel::getTagId, removeTag.stream().map(WeFlowerCustomerTagRel::getTagId).collect(Collectors.toList())) - )){ + )) { - flowerCustomerRels.stream().forEach(k->{ + flowerCustomerRels.stream().forEach(k -> { weCustomerClient.makeCustomerLabel( CutomerTagEdit.builder() .external_userid(k.getExternalUserid()) @@ -443,14 +446,12 @@ public class WeCustomerServiceImpl extends ServiceImpl - SELECT wc.external_userid, wc.`name`, @@ -73,6 +73,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN we_user wu ON wu.user_id=wfcr.user_id LEFT JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.flower_customer_rel_id = wfcr.id LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id + + + AND wc.name like concat('%', #{name}, '%') + + + AND wfcr.user_id = #{params.userId} + + + + + and wt.tag_id in + + #{item} + + + + and wt.tag_id=#{params.tagIds} + + + + AND date_format(wfcr.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(wfcr.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + +