提交 70ae4164 编写于 作者: 水库浪子

修改客户列表error

上级 d4197c7e
......@@ -28,11 +28,21 @@ public interface WeCropTagClient {
* @return
*/
@Request(url = "/externalcontact/get_corp_tag_list",
type = "POST"
type = "POST"
)
WeCropGroupTagListDto getAllCorpTagList();
/**
* 根据指定标签的id,获取标签详情
* @return
*/
@Request(url = "/externalcontact/get_corp_tag_list",
type = "POST"
)
WeCropGroupTagListDto getCorpTagListByTagIds(@DataObject WeFindCropTagParam weFindCropTagParam);
/**
* 删除企业客户标签
* @param weCropDelDto
......
......@@ -67,7 +67,7 @@ public class WeCustomer
/** 添加人员 */
@TableField(exist = false)
private List<WeFlowerCustomerRel> weFlowerCustomerRels;
private List<WeFlowerCustomerRel> weFlowerCustomerRels;
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
......@@ -28,9 +29,11 @@ public class WeFlowerCustomerRel
{
private static final long serialVersionUID = 1L;
@TableId
private Long id= SnowFlakeUtil.nextId();
/** 添加了此外部联系人的企业成员userid */
@TableId
private String userId;
/** 外部联系人名称 */
......@@ -57,7 +60,7 @@ public class WeFlowerCustomerRel
private String state;
/** 客户id */
private Long customerId;
private String externalUserid;
/** 状态(0正常 1删除) */
private String status;
......@@ -66,6 +69,8 @@ public class WeFlowerCustomerRel
private Date createTime;
/** 微信用户添加的标签 */
@TableField(exist = false)
private List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels;
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
......@@ -11,21 +21,30 @@ import lombok.Data;
* @date 2020-09-19
*/
@Data
public class WeFlowerCustomerTagRel extends BaseEntity
@TableName("we_flower_customer_tag_rel")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WeFlowerCustomerTagRel
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
@TableId
private Long id= SnowFlakeUtil.nextId();
/** 添加客户的企业微信用户 */
private Long flowerCustomerRelId;
/** 标签id */
private Long tagId;
private String tagId;
/** 标签名 */
@TableField(exist = false)
private String tagName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}
package com.linkwechat.wecom.domain.dto.tag;
import lombok.Builder;
import lombok.Data;
/**
* @description: 获取标签接口参数实体
* @author: HaoN
* @create: 2020-10-20 13:03
**/
@Data
@Builder
public class WeFindCropTagParam {
private String[] tag_id;
}
package com.linkwechat.wecom.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
/**
......@@ -9,7 +11,7 @@ import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
* @author ruoyi
* @date 2020-09-19
*/
public interface WeFlowerCustomerTagRelMapper
public interface WeFlowerCustomerTagRelMapper extends BaseMapper<WeFlowerCustomerTagRel>
{
/**
* 查询客户标签关系
......
package com.linkwechat.wecom.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
/**
......@@ -9,7 +11,7 @@ import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
* @author ruoyi
* @date 2020-09-19
*/
public interface IWeFlowerCustomerTagRelService
public interface IWeFlowerCustomerTagRelService extends IService<WeFlowerCustomerTagRel>
{
/**
* 查询客户标签关系
......
......@@ -2,28 +2,33 @@ 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.SecurityUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
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.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.dto.customer.ExternalUserDetail;
import com.linkwechat.wecom.domain.dto.customer.ExternalUserList;
import com.linkwechat.wecom.domain.dto.customer.ExternalUserTag;
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;
import com.linkwechat.wecom.domain.dto.tag.WeFindCropTagParam;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.mapper.WeCustomerMapper;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import com.linkwechat.wecom.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -46,6 +51,20 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
@Autowired
private IWeFlowerCustomerRelService iWeFlowerCustomerRelService;
@Autowired
private WeCropTagClient weCropTagClient;
@Autowired
private IWeTagService iWeTagService;
@Autowired
private IWeTagGroupService iWeTagGroupService;
@Autowired
private IWeFlowerCustomerTagRelService iWeFlowerCustomerTagRelService;
// @Autowired
// private WeUserClient weUserClient;
......@@ -162,41 +181,112 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper,WeCustom
this.saveOrUpdate(weCustomer);
//客户与通讯录客户关系
List<WeTag> weTags=new ArrayList<>();
List<WeTagGroup> weGroups=new ArrayList<>();
List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels=new ArrayList<>();
List<WeFlowerCustomerRel> weFlowerCustomerRel=new ArrayList<>();
externalUserDetail.getFollow_user().stream().forEach(kk->{
WeFlowerCustomerRel weFlowerCustomerRelOne=new WeFlowerCustomerRel();
BeanUtils.copyPropertiesignoreOther(kk,weFlowerCustomerRelOne);
Long weFlowerCustomerRelId=SnowFlakeUtil.nextId();
weFlowerCustomerRelOne.setId(weFlowerCustomerRelId);
weFlowerCustomerRelOne.setExternalUserid(weCustomer.getExternalUserid());
weFlowerCustomerRel.add(weFlowerCustomerRelOne);
List<ExternalUserTag> 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<WeCropGroupTagDto> 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<WeCropTagDto> weCropTagDtos= tagGroup.getTag();
if(CollectionUtil.isNotEmpty(weCropTagDtos)){
Set<String> 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()
);
}
});
}
});
}
}
}
});
iWeFlowerCustomerRelService.saveOrUpdateBatch(weFlowerCustomerRel);
List<WeFlowerCustomerRel> weFlowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper<WeFlowerCustomerRel>()
.eq(WeFlowerCustomerRel::getExternalUserid, weCustomer.getExternalUserid()));
if(CollectionUtil.isNotEmpty(weFlowerCustomerRels)){
List<Long> weFlowerCustomerRelIds = weFlowerCustomerRels.stream().map(WeFlowerCustomerRel::getId).collect(Collectors.toList());
iWeFlowerCustomerTagRelService.remove(
new LambdaQueryWrapper<WeFlowerCustomerTagRel>().in(WeFlowerCustomerTagRel::getFlowerCustomerRelId,
weFlowerCustomerRelIds)
);
iWeFlowerCustomerRelService.removeByIds(
weFlowerCustomerRelIds
);
}
//设置标签跟客户关系,根据标签id获取到标签组,saveOrUpdate标签,建立标签与添加人关系
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRel);
//设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系
if(CollectionUtil.isNotEmpty(weTags)&&CollectionUtil.isNotEmpty(weGroups)){
iWeTagService.saveOrUpdateBatch(weTags);
iWeTagGroupService.saveOrUpdateBatch(weGroups);
iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels);
}
}
// if(WeConstans.WE_SUCCESS_CODE.equals(externalContact.getErrcode())){
//
// WeCustomer weCustomer
// = externalContact.transformWeCustomer();
//
// if(null != weCustomer){
//
// this.insertWeCustomer(weCustomer);
//
// if(CollectionUtil.isNotEmpty(weCustomer.getWeFlowerCustomerRels())){
//
// iWeFlowerCustomerRelService.batchInsetWeFlowerCustomerRel(weCustomer.getWeFlowerCustomerRels());
//
//
//
// }
//
// }
//
//
// }
});
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -16,7 +17,7 @@ import com.linkwechat.wecom.service.IWeFlowerCustomerTagRelService;
* @date 2020-09-19
*/
@Service
public class WeFlowerCustomerTagRelServiceImpl implements IWeFlowerCustomerTagRelService
public class WeFlowerCustomerTagRelServiceImpl extends ServiceImpl<WeFlowerCustomerTagRelMapper,WeFlowerCustomerTagRel> implements IWeFlowerCustomerTagRelService
{
@Autowired
private WeFlowerCustomerTagRelMapper weFlowerCustomerTagRelMapper;
......
......@@ -5,8 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.linkwechat.wecom.mapper.WeCustomerMapper">
<resultMap type="WeCustomer" id="WeCustomerResult">
<result property="id" column="id" />
<result property="externalUserid" column="external_userid" />
<id property="externalUserid" column="external_userid" />
<result property="name" column="name" />
<result property="avatar" column="avatar" />
<result property="type" column="type" />
......@@ -23,14 +22,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="description" column="description" />
<result property="createTime" column="create_time" />
<result property="remarkCorpName" column="remark_corp_name" />
<!-- <result property="remarkMobiles" column="remark_mobiles" />-->
<result property="operUserid" column="oper_userid" />
<result property="addWay" column="add_way" />
<result property="state" column="state" />
<result property="customerId" column="customer_id" />
<!-- <result property="customerId" column="customer_id" />-->
<result property="userName" column="user_name"/>
<collection property="weFlowerCustomerTagRels" ofType="com.linkwechat.wecom.domain.WeFlowerCustomerTagRel">
<result property="id" column="tagRelid" />
<result property="flowerCustomerRelId" column="flower_customer_rel_id" />
<result property="tagId" column="tag_id" />
<result property="createTime" column="create_time" />
......@@ -44,41 +41,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectWeCustomerList" parameterType="WeCustomer" resultMap="WeCustomerResult">
SELECT
wc.id,
wc.external_userid,
wc.`name`,
wc.avatar,
wc.type,
wc.gender,
wc.unionid,
wc.birthday,
wc.position,
wc.corp_name,
wc.corp_full_name,
wfcr.id as wfcrId,
wfcr.user_id,
wfcr.remark,
wfcr.description,
wfcr.create_time,
wfcr.remark_corp_name,
wfcr.remark_mobiles,
wfcr.oper_userid,
wfcr.add_way,
wfcr.state,
wfcr.customer_id,
wfcrf.id as tagRelid,
wfcrf.flower_customer_rel_id,
wfcrf.tag_id,
wfcrf.create_time,
wt.`name` as tagName,
wu.user_name
SELECT
wc.external_userid,
wc.`name`,
wc.avatar,
wc.type,
wc.gender,
wc.unionid,
wc.birthday,
wc.corp_name,
wc.corp_full_name,
wc.position,
wfcr.id as wfcrId,
wfcr.user_id,
wfcr.remark,
wfcr.description,
wfcr.create_time,
wfcr.remark_corp_name,
wfcr.oper_userid,
wfcr.add_way,
wfcr.state,
wu.user_name,
wfcrf.flower_customer_rel_id,
wt.tag_id,
wt.create_time,
wt.`name` as tagName
FROM
we_customer wc
INNER JOIN we_flower_customer_rel wfcr ON wc.id = wfcr.customer_id
INNER JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.flower_customer_rel_id = wfcr.id
INNER JOIN we_tag wt ON wt.id = wfcrf.tag_id
INNER JOIN we_user wu ON wu.user_id=wfcr.user_id
we_customer wc
LEFT JOIN we_flower_customer_rel wfcr ON wc.external_userid=wfcr.external_userid
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
</select>
<select id="selectWeCustomerById" parameterType="Long" resultMap="WeCustomerResult">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册