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

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