提交 7c805ce2 编写于 作者: 孙喜旺

客户列表

上级 e4d09dc3
package com.linkwechat.wecom.domain;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
......@@ -8,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.wecom.domain.vo.customer.WeFlowerCustomerRelVo;
import com.linkwechat.wecom.domain.vo.tag.WeTagVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -136,7 +137,14 @@ public class WeCustomer extends BaseEntity {
* 添加人员
*/
@TableField(exist = false)
private List<WeFlowerCustomerRel> weFlowerCustomerRels;
private List<WeFlowerCustomerRelVo> weFlowerCustomerRels;
/**
* 客户标签
*/
/** 微信用户添加的标签 */
@TableField(exist = false)
private List<WeTagVo> weTags;
/**
* 添加人id
......
......@@ -5,6 +5,7 @@ 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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -29,7 +30,7 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@TableName("we_flower_customer_rel")
public class WeFlowerCustomerRel
public class WeFlowerCustomerRel extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -49,14 +50,6 @@ public class WeFlowerCustomerRel
@TableField("user_id")
private String userId;
/**
* 成员名称
*/
@ApiModelProperty(value = "成员名称")
@TableField(exist = false)
private String userName;
/**
* 该成员对此外部联系人的描述
*/
......@@ -120,23 +113,6 @@ public class WeFlowerCustomerRel
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date addTime;
/** 微信用户添加的标签 */
@TableField(exist = false)
private List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels;
@ApiModelProperty(value = "部门")
@TableField(exist = false)
private String department;
@TableField(exist = false)
private String beginTime;
@TableField(exist = false)
private String endTime;
/** 备注 */
private String remark;
......@@ -152,8 +128,4 @@ public class WeFlowerCustomerRel
/**地址*/
private String address;
}
......@@ -51,8 +51,4 @@ public class WeFlowerCustomerTagRel extends BaseEntity
@ApiModelProperty(value = "标签id")
@TableField("tag_id")
private String tagId;
@ApiModelProperty(value = "标签名")
@TableField(exist = false)
private String tagName;
}
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;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -28,22 +30,29 @@ import java.util.Date;
public class WeTag extends BaseEntity
{
/** 标签组id */
@ApiModelProperty(value = "主键")
@TableId(type = IdType.AUTO)
@TableField("id")
private Long id;
@ApiModelProperty(value = "企业id")
@TableField("corp_id")
private String corpId;
@ApiModelProperty(value = "标签组id")
@TableField("group_id")
private String groupId;
/** 标签名 */
@ApiModelProperty(value = "标签名")
@TableField("name")
private String name;
/** 微信端返回的id */
@TableId
@ApiModelProperty(value = "微信端返回的标签id")
@TableField("tag_id")
private String tagId;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime=new Date();
/**(0正常 1删除)**/
@ApiModelProperty(value = "状态(0正常 1删除)")
@TableField("del_flag")
private Integer delFlag;
......
package com.linkwechat.wecom.domain.vo.customer;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author sxw
* @description 客户关联关系出参对象
* @date 2021/6/17 0:26
**/
@ApiModel
@Data
public class WeFlowerCustomerRelVo {
@ApiModelProperty(value = "主键")
private Long id;
@ApiModelProperty(value = "企业id")
private String corpId;
/**
* 添加了此外部联系人的企业成员userid
*/
@ApiModelProperty(value = "添加了此外部联系人的企业成员userid")
private String userId;
/**
* 成员名称
*/
@ApiModelProperty(value = "成员名称")
private String userName;
/**
* 该成员对此外部联系人的描述
*/
@ApiModelProperty(value = "该成员对此外部联系人的描述")
private String description;
/**
* 该成员对此客户备注的企业名称
*/
@ApiModelProperty(value = "该成员对此客户备注的企业名称")
private String remarkCorpName;
/**
* 该成员对此客户备注的手机号码
*/
@ApiModelProperty(value = "该成员对此客户备注的手机号码")
private String remarkMobiles;
/**
* 发起添加的userid,如果成员主动添加,为成员的userid;如果是客户主动添加,则为客户的外部联系人userid;如果是内部成员共享/管理员分配,则为对应的成员/管理员userid
*/
@ApiModelProperty(value = "发起添加的userid")
private String operUserId;
/**
* 该成员添加此客户的来源,
*/
@ApiModelProperty(value = "该成员添加此客户的来源")
private Integer addWay;
/**
* 企业自定义的state参数,用于区分客户具体是通过哪个「联系我」添加,由企业通过创建「联系我」方式指定
*/
@ApiModelProperty(value = "企业自定义的state参数")
private String state;
/**
* 客户id
*/
@ApiModelProperty(value = "客户id")
private String externalUserid;
/**
* 状态(0正常 1删除)
*/
@ApiModelProperty(value = "状态(0正常 1删除)")
private Integer delFlag;
/**
* 该成员添加此外部联系人的时间
*/
@ApiModelProperty(value = "该成员添加此外部联系人的时间")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date addTime;
@ApiModelProperty(value = "部门")
private String department;
/** 备注 */
@ApiModelProperty(value = "备注")
private String remark;
/** 邮件 */
@ApiModelProperty(value = "邮件")
private String email;
/** qq */
@ApiModelProperty(value = "QQ")
private String qq;
/**地址*/
@ApiModelProperty(value = "地址")
private String address;
}
package com.linkwechat.wecom.domain.vo.tag;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 客户标签出参对象
* @date 2021/6/17 0:22
**/
@ApiModel
@Data
public class WeTagVo {
@ApiModelProperty(value = "标签id")
private String tagId;
@ApiModelProperty(value = "标签名")
private String tagName;
}
......@@ -102,5 +102,5 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
* 批量新增
* @param customerList
*/
void saveBatch(List<WeCustomer> customerList);
void saveBatch(@Param("weCustomerList") List<WeCustomer> customerList);
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
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.linkwechat.common.constant.Constants;
......@@ -154,7 +155,8 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
*/
private void weFlowerCustomerHandle(String userId) {
//当前登录人的企业id
String corpId = SecurityUtils.getLoginUser().getUser().getCorpId();
String corpId = SecurityUtils.getLoginUser().getUser().getWeCorpAccount().getCorpId();
//String corpId = "ww38152475d1bca752";
List<ExternalUserDetail> list = new ArrayList<>(16);
getByUser(userId, null, list);
List<WeCustomer> customerList = new ArrayList<>(16);
......@@ -194,11 +196,16 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
}
});
this.weCustomerMapper.saveBatch(customerList);
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRels);
if(CollectionUtil.isNotEmpty(customerList)){
this.weCustomerMapper.saveBatch(customerList);
}
iWeFlowerCustomerTagRelService.saveBatch(weFlowerCustomerTagRels);
if(CollectionUtil.isNotEmpty(weFlowerCustomerRels)){
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRels);
}
if(CollectionUtil.isNotEmpty(weFlowerCustomerTagRels)){
iWeFlowerCustomerTagRelService.saveBatch(weFlowerCustomerTagRels);
}
});
}
......@@ -479,11 +486,17 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
});
}
});
this.weCustomerMapper.saveBatch(customerList);
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRels);
if(CollectionUtil.isNotEmpty(customerList)){
this.weCustomerMapper.saveBatch(customerList);
}
iWeFlowerCustomerTagRelService.saveBatch(weFlowerCustomerTagRels);
if(CollectionUtil.isNotEmpty(weFlowerCustomerRels)){
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRels);
}
if(CollectionUtil.isNotEmpty(weFlowerCustomerTagRels)){
iWeFlowerCustomerTagRelService.saveBatch(weFlowerCustomerTagRels);
}
}
......
......@@ -17,35 +17,13 @@
<result property="corpName" column="corp_name"/>
<result property="corpFullName" column="corp_full_name"/>
<result property="position" column="position"/>
<result property="userName" column="user_name"/>
<result property="userId" column="user_id"/>
<result property="isOpenChat" column="is_open_chat" jdbcType="INTEGER"/>
<collection property="weFlowerCustomerRels" ofType="com.linkwechat.wecom.domain.WeFlowerCustomerRel">
<result property="id" column="wfcrId"/>
<result property="userId" column="user_id"/>
<result property="remark" column="remark"/>
<result property="description" column="description"/>
<result property="addTime" column="add_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="delFlag" column="del_flag"/>
<result property="userName" column="user_name"/>
<result property="department" column="department"/>
<collection property="weFlowerCustomerTagRels" javaType="ArrayList"
column="{id = wfcrId}" select="selectWeCustomerTags">
</collection>
<collection property="weFlowerCustomerRels" javaType="ArrayList"
column="{corpId = corp_id, externalUserid = external_userid}" select="selectWeCustomerUserRels">
</collection>
<collection property="weTags" javaType="ArrayList"
column="{corpId = corp_id, externalUserid = external_userid}" select="selectWeCustomerTags">
</collection>
</resultMap>
<resultMap id="weFlowerCustomerRelsMapper" type="com.linkwechat.wecom.domain.WeFlowerCustomerTagRel">
<result property="flowerCustomerRelId" column="flower_customer_rel_id"/>
<result property="tagId" column="tag_id"/>
<result property="createTime" column="create_time"/>
<result property="tagName" column="tagName"/>
</resultMap>
......@@ -80,10 +58,6 @@
<select id="selectWeCustomerList" parameterType="WeCustomer" resultMap="WeCustomerResult">
SELECT
*
FROM
(
SELECT
DISTINCT
wc.id,
......@@ -97,27 +71,14 @@
wc.birthday,
wc.corp_name,
wc.corp_full_name,
wc.position,
wc.is_open_chat,
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.del_flag,
wu.user_name,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE FIND_IN_SET(wd.dept_id,wu.department)) as department
wc.position
FROM
we_customer wc
LEFT JOIN we_flower_customer_rel wfcr ON wc.corp_id = wfcr.corp_id and wc.external_userid = wfcr.external_userid
LEFT JOIN we_user wu ON wu.corp_id = wfcr.corp_id and 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
LEFT JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.corp_id = wfcr.corp_id and wfcrf.external_userid =
wfcr.external_userid
LEFT JOIN we_tag wt ON wt.corp_id = wfcrf.corp_id and wt.tag_id = wfcrf.tag_id
<where>
<if test="name != null and name !=''">
AND wc.name like concat('%', #{name}, '%')
......@@ -134,11 +95,11 @@
</if>
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
AND date_format(wfcr.add_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
AND date_format(wfcr.add_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="tagIds != null and tagIds !=''">
<if test="tagIds.indexOf(',') != -1">
......@@ -158,20 +119,40 @@
AND wc.is_open_chat=#{isOpenChat}
</if>
</where>
ORDER BY wfcr.create_time ASC
) aa GROUP BY aa.corp_id, aa.external_userid
ORDER BY wfcr.add_time ASC
</select>
<select id="selectWeCustomerUserRels" resultType="com.linkwechat.wecom.domain.vo.customer.WeFlowerCustomerRelVo">
select
wfcr.id,
wfcr.corp_id,
wfcr.user_id,
wfcr.external_userid,
wfcr.remark,
wfcr.description,
wfcr.add_time,
wfcr.remark_corp_name,
wfcr.remark_mobiles,
wfcr.oper_userid,
wfcr.add_way,
wfcr.state,
wfcr.status,
wu.user_name,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE FIND_IN_SET(wd.dept_id,wu.department)) as department
from
we_flower_customer_rel wfcr
LEFT JOIN we_user wu ON wu.corp_id = wfcr.corp_id and wu.user_id=wfcr.user_id
where wfcr.corp_id = #{corpId} and wfcr.external_userid = #{externalUserid}
</select>
<select id="selectWeCustomerTags" resultMap="weFlowerCustomerRelsMapper">
<select id="selectWeCustomerTags" resultType="com.linkwechat.wecom.domain.vo.tag.WeTagVo">
SELECT
wfcrf.flower_customer_rel_id,
wt.tag_id,
wt.`name` as tagName
wt.`name` as tagName
FROM
we_flower_customer_tag_rel wfcrf
LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id
where wt.status=0 and wfcrf.flower_customer_rel_id=#{id}
where wt.del_flag=0 and wfcrf.corp_id =#{corpId} and wfcrf.external_userid = #{externalUserid}
</select>
......@@ -283,7 +264,7 @@
LEFT JOIN we_user wu ON wu.corp_id = wfcr.corp_id and 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
WHERE wc.id=#{id}
WHERE wc.id= #{id}
<if test="userId != null and userId !=''">
AND wfcr.user_id=#{userId}
</if>
......@@ -356,12 +337,12 @@
<insert id="saveBatch">
insert into we_customer
(corp_id, external_userid, `name`, avatar, `type`, gender, unionid, birthday, corp_name, corp_full_name,
position)
`position`) values
<foreach collection="weCustomerList" item="weCustomer" index="index" separator=",">
(
#{weCustomer.corpId},#{weCustomer.externalUserid},#{weCustomer.name},#{weCustomer.avatar},
#{weCustomer.type},#{weCustomer.gender},#{weCustomer.unionid},#{weCustomer.birthday},
#{weCustomer.corp_name},#{weCustomer.corp_full_name},#{weCustomer.position}
#{weCustomer.corpName},#{weCustomer.corpFullName},#{weCustomer.position}
)
</foreach>
on duplicate key update corp_id = values(corp_id), external_userid= values(external_userid),
......@@ -369,7 +350,7 @@
`type`= values(`type`),gender= values(gender),
unionid= values(unionid),birthday= values(birthday),
corp_name= values(corp_name),corp_full_name= values(corp_full_name),
position= values(position)
`position`= values(`position`)
</insert>
</mapper>
\ No newline at end of file
......@@ -144,10 +144,10 @@
<insert id="saveBatch">
insert into we_flower_customer_rel (corp_id, user_id, external_userid, remark, description, add_time, remark_corp_name,
remark_mobiles, oper_userid, add_way, `state`,)
remark_mobiles, oper_userid, add_way, `state`)
values
<foreach collection="customerRelList" item="item" index="index" separator=",">
(#{item.corpId},#{item.userId},#{item.externalUserid},#{item.remark},#{item.description},#{item.addTime}
(#{item.corpId},#{item.userId},#{item.externalUserid},#{item.remark},#{item.description},#{item.addTime},
#{item.remarkCorpName},#{item.remarkMobiles},#{item.operUserId},#{item.addWay}
,#{item.state})
</foreach>
......@@ -156,6 +156,6 @@
description= values(description),add_time= values(add_time),
add_time= values(add_time),remark_corp_name= values(remark_corp_name),
remark_mobiles= values(remark_mobiles),oper_userid= values(oper_userid),
add_way= values(add_way),`state`= values(`state`),
add_way= values(add_way),`state`= values(`state`)
</insert>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册