新增客户标签与群标签功能

1 parent 9d502922
......@@ -49,7 +49,6 @@ public class WeTagGroupController extends BaseController
public TableDataInfo list(WeTagGroup weTagGroup)
{
startPage();
//synchWeTags();
return getDataTable(
weTagGroupService.selectWeTagGroupList(weTagGroup)
);
......@@ -70,7 +69,6 @@ public class WeTagGroupController extends BaseController
if(StrUtil.isNotBlank(weTagGroup.getGourpName())){
List<WeTag> weTags = weTagGroup.getWeTags();
if(CollectionUtil.isNotEmpty(weTags)){
if(weTags.stream().filter(m -> m.getName().equals(weTagGroup.getGourpName())).findAny().isPresent()){
return AjaxResult.error("标签组名称与标签名不可重复");
}
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.core.domain.BaseEntity;
......@@ -28,21 +29,21 @@ public class WeTag implements Serializable
{
/** 标签组id */
private String groupId;
private String groupId;
/** 标签名 */
private String name;
/** 标签名 */
private String name;
/** 帐号状态(0正常 2删除) */
private String status;
/** 微信端返回的id */
@TableId
private String tagId;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime=new Date();
@TableLogic
private Integer delFlag;
......
......@@ -2,10 +2,12 @@ package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
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.models.auth.In;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.Data;
......@@ -25,7 +27,7 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@TableName("we_tag_group")
public class WeTagGroup
public class WeTagGroup extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -38,20 +40,20 @@ public class WeTagGroup
@TableField(exist = false)
private List<WeTag> weTags;
/** 帐号状态(0正常 1删除) */
private String status=new String("0");
/** 分组id */
@TableId
private String groupId;
/** 创建者 */
private String createBy;
@TableLogic
private Integer delFlag;
/**标签分组类型(1:客户标签;2:群标签)*/
private Integer groupTagType=new Integer(1);
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime=new Date();
......
......@@ -41,11 +41,11 @@ public class WeCropGroupTagDto {
.group_id(weTagGroup.getGroupId())
.group_name(weTagGroup.getGourpName())
.build();
List<WeTag> weTags = weTagGroup.getWeTags();
if(CollectionUtil.isNotEmpty(weTags)){
List<WeTag> newAddWeTag = weTagGroup.getWeTags();
if(CollectionUtil.isNotEmpty(newAddWeTag)){
//新增的标签
List<WeTag> newAddWeTag
= weTags.stream().filter(v -> StringUtils.isEmpty(v.getTagId())).collect(Collectors.toList());
// List<WeTag> newAddWeTag
// = weTags.stream().filter(v -> StringUtils.isEmpty(v.getTagId())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(newAddWeTag)){
......
......@@ -490,10 +490,10 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
.build()
);
});
iWeFlowerCustomerTagRelService.saveOrUpdateBatch(tagRels);
}
......@@ -714,7 +714,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
WeTagGroup.builder()
.groupId(tagGroup.getGroup_id())
.gourpName(tagGroup.getGroup_name())
.createBy(kk.getUserid())
.build()
);
......
......@@ -66,21 +66,28 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
@Transactional(rollbackFor = Exception.class)
public void insertWeTagGroup(WeTagGroup weTagGroup) {
List<WeTag> weTags = weTagGroup.getWeTags();
if (CollectionUtil.isEmpty(weTags)) {
this.save(weTagGroup);
} else {
WeCropGropTagDtlDto weCropGropTagDtlDto = weCropTagClient.addCorpTag(WeCropGroupTagDto.transformAddTag(weTagGroup));
if (weCropGropTagDtlDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) {
this.batchSaveOrUpdateTagGroupAndTag(ListUtil.toList(weCropGropTagDtlDto.getTag_group()), false);
//个人标签同步,企业微信
if(weTagGroup.getGroupTagType().equals(new Integer(1))){
WeCropGropTagDtlDto weCropGropTagDtlDto = weCropTagClient.addCorpTag(WeCropGroupTagDto.transformAddTag(weTagGroup));
if (weCropGropTagDtlDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) {
this.batchSaveOrUpdateTagGroupAndTag(ListUtil.toList(weCropGropTagDtlDto.getTag_group()), false);
}
}else{
iWeTagService.saveBatch(weTags);
}
}
}
/**
......@@ -108,7 +115,6 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
.collect(Collectors.toMap(weCropTagDto -> weCropTagDto.getName(), weCropTagDto -> weCropTagDto.getId()));
filterWeTags.stream().forEach(tag -> {
tag.setTagId(weCropTagMap.get(tag.getName()));
tag.setCreateTime(new Date());
});
}
}
......@@ -116,8 +122,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
//获取需要删除的数据
List<WeTag> removeWeTags = iWeTagService.list(new LambdaQueryWrapper<WeTag>().notIn(WeTag::getTagId,
weTags.stream().map(WeTag::getTagId).collect(Collectors.toList())).eq(WeTag::getGroupId, weTagGroup.getGroupId())
.eq(WeTag::getStatus, Constants.NORMAL_CODE));
weTags.stream().map(WeTag::getTagId).collect(Collectors.toList())).eq(WeTag::getGroupId, weTagGroup.getGroupId()));
if (CollectionUtil.isNotEmpty(removeWeTags)) {
//同步删除微信端的标签
......@@ -128,8 +133,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
.build());
//移除本地
removeWeTags.stream().forEach(v -> v.setStatus(Constants.DELETE_CODE));
iWeTagService.updateBatchById(removeWeTags);
iWeTagService.removeByIds(removeWeTags.stream().map(WeTag::getTagId).collect(Collectors.toList()));
}
......@@ -202,11 +206,9 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
List<WeTagGroup> weTagGroups = new ArrayList<>();
if (CollectionUtil.isNotEmpty(tagGroup)) {
tagGroup.stream().forEach(k -> {
WeTagGroup weTagGroup = new WeTagGroup();
weTagGroup.setCreateBy(SecurityUtils.getUsername());
weTagGroup.setGourpName(k.getGroup_name());
weTagGroup.setGroupId(k.getGroup_id());
List<WeCropTagDto> tag = k.getTag();
......@@ -236,8 +238,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
= this.list(new LambdaQueryWrapper<WeTagGroup>().notIn(WeTagGroup::getGroupId, weTagGroups.stream().map(WeTagGroup::getGroupId).collect(Collectors.toList())));
//企业微信端删除得标签
if (CollectionUtil.isNotEmpty(noExist)) {
noExist.stream().forEach(k -> k.setStatus(Constants.DELETE_CODE));
this.updateBatchById(noExist);
this.removeByIds(noExist.stream().map(WeTagGroup::getGroupId).collect(Collectors.toList()));
}
}
......@@ -254,8 +255,9 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
List<WeTag> noExistWeTags
= iWeTagService.list(new LambdaQueryWrapper<WeTag>().notIn(WeTag::getTagId, weTags.stream().map(WeTag::getTagId).collect(Collectors.toList())));
if (CollectionUtil.isNotEmpty(noExistWeTags)) {
noExistWeTags.stream().forEach(k -> k.setStatus(Constants.DELETE_CODE));
iWeTagService.updateBatchById(noExistWeTags);
iWeTagService.removeByIds(
noExistWeTags.stream().map(WeTag::getTagId).collect(Collectors.toList())
);
}
}
......@@ -270,17 +272,16 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
if (isSync) {
List<WeTagGroup> weTagGroupList
= this.list(new LambdaQueryWrapper<WeTagGroup>().eq(WeTagGroup::getStatus, Constants.NORMAL_CODE));
= this.list();
if (CollectionUtil.isNotEmpty(weTagGroupList)) {
weTagGroupList.stream().forEach(k -> k.setStatus(Constants.DELETE_CODE));
this.updateBatchById(weTagGroupList);
this.removeByIds(weTagGroupList.stream().map(WeTagGroup::getGroupId).collect(Collectors.toList()));
}
List<WeTag> weTags
= iWeTagService.list(new LambdaQueryWrapper<WeTag>().eq(WeTag::getStatus, Constants.NORMAL_CODE));
= iWeTagService.list();
if (CollectionUtil.isNotEmpty(weTags)) {
weTags.stream().forEach(k -> k.setStatus(Constants.DELETE_CODE));
iWeTagService.updateBatchById(weTags);
iWeTagService.removeByIds(weTags.stream().map(WeTag::getTagId).collect(Collectors.toList()));
}
}
......@@ -298,11 +299,9 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
List<WeTagGroup> tagGroupsList = new ArrayList<>();
tag_group.stream().forEach(k -> {
WeTagGroup tagGroupInfo = this.baseMapper.selectOne(new LambdaQueryWrapper<WeTagGroup>()
.eq(WeTagGroup::getGroupId, k.getGroup_id())
.eq(WeTagGroup::getStatus,0));
.eq(WeTagGroup::getGroupId, k.getGroup_id()));
if (tagGroupInfo == null) {
WeTagGroup weTagGroup = new WeTagGroup();
weTagGroup.setCreateBy("sys");
weTagGroup.setGourpName(k.getGroup_name());
weTagGroup.setGroupId(k.getGroup_id());
tagGroupsList.add(weTagGroup);
......@@ -328,7 +327,6 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper, WeTagGr
List<WeTagGroup> tagGroupsList = new ArrayList<>();
WeTagGroup weTagGroup = new WeTagGroup();
tag_group.stream().forEach(k -> {
weTagGroup.setCreateBy("sys");
weTagGroup.setGourpName(k.getGroup_name());
weTagGroup.setGroupId(k.getGroup_id());
tagGroupsList.add(weTagGroup);
......
......@@ -72,7 +72,6 @@ public class WeTagServiceImpl extends ServiceImpl<WeTagMapper,WeTag> implements
@Override
public int insertWeTag(WeTag weTag)
{
weTag.setCreateTime(DateUtils.getNowDate());
return weTagMapper.insertWeTag(weTag);
}
......
......@@ -32,8 +32,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
we_tag_group wtg
LEFT JOIN we_tag wt ON wtg.group_id = wt.group_id
where
wtg.status=0 and wt.status=0 or wt.status IS NULL
wtg.del_flag=0 and wt.del_flag=0
<if test="gourpName != null and gourpName != ''"> and gourp_name like concat('%', #{gourpName}, '%')</if>
<if test="groupTagType != null">and wtg.group_tag_type=#{groupTagType}</if>
</select>
<select id="getWeTagGroupByIds" resultMap="WeTagGroupResult">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!