Commit e2f5415d by 水库浪子

修改标签组相关bug;增加标签删除自动解除标签与客户绑定得关系;欢迎语返回素材url;

1 parent dee159df
......@@ -63,7 +63,7 @@ public class WeMsgTlpController extends BaseController
* 新增欢迎语模板
*/
@PreAuthorize("@ss.hasPermi('wecom:tlp:add')")
@Log(title = "欢迎语模板", businessType = BusinessType.INSERT)
@Log(title = "新增欢迎语模板", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WeMsgTlp weMsgTlp)
{
......@@ -74,7 +74,7 @@ public class WeMsgTlpController extends BaseController
* 修改欢迎语模板
*/
@PreAuthorize("@ss.hasPermi('wecom:tlp:edit')")
@Log(title = "欢迎语模板", businessType = BusinessType.UPDATE)
@Log(title = "修改欢迎语模板", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WeMsgTlp weMsgTlp)
{
......@@ -85,7 +85,7 @@ public class WeMsgTlpController extends BaseController
* 删除欢迎语模板
*/
@PreAuthorize("@ss.hasPermi('wecom:tlp:remove')")
@Log(title = "欢迎语模板", businessType = BusinessType.DELETE)
@Log(title = "删除欢迎语模板", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
......
......@@ -44,19 +44,7 @@ public class WeTagGroupController extends BaseController
public TableDataInfo list(WeTagGroup weTagGroup)
{
startPage();
SecurityContext securityContext = SecurityContextHolder.getContext();
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
weTagGroupService.synchWeTags();
}
});
synchWeTags();
return getDataTable(
weTagGroupService.selectWeTagGroupList(weTagGroup)
);
......@@ -109,7 +97,16 @@ public class WeTagGroupController extends BaseController
@GetMapping("/synchWeTags")
public AjaxResult synchWeTags(){
weTagGroupService.synchWeTags();
SecurityContext securityContext = SecurityContextHolder.getContext();
//异步同步一下标签库,解决标签不同步问题
Threads.SINGLE_THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
SecurityContextHolder.setContext(securityContext);
weTagGroupService.synchWeTags();
}
});
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
......
package com.linkwechat.common.constant;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import java.io.IOException;
import java.util.HashMap;
......@@ -269,38 +267,38 @@ public class WeConstans {
}
}
public static XContentBuilder getFinanceTextMapping() throws IOException {
// 创建 会话文本Mapping
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("msgid")
.field("type", "keyword")
.endObject()
.startObject("action")
.field("type", "keyword")
.endObject()
.startObject("from")
.field("type", "keyword")
.endObject()
.startObject("tolist")
.field("type", "text")
.endObject()
.startObject("roomid")
.field("type", "keyword")
.endObject()
.startObject("msgtime")
.field("type", "long")
.endObject()
.startObject("msgtype")
.field("type", "keyword")
.endObject()
.startObject("content")
.field("type", "text")
.endObject()
.endObject()
.endObject();
return xContentBuilder;
}
//
// public static XContentBuilder getFinanceTextMapping() throws IOException {
// // 创建 会话文本Mapping
// XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
// .startObject()
// .startObject("properties")
// .startObject("msgid")
// .field("type", "keyword")
// .endObject()
// .startObject("action")
// .field("type", "keyword")
// .endObject()
// .startObject("from")
// .field("type", "keyword")
// .endObject()
// .startObject("tolist")
// .field("type", "text")
// .endObject()
// .startObject("roomid")
// .field("type", "keyword")
// .endObject()
// .startObject("msgtime")
// .field("type", "long")
// .endObject()
// .startObject("msgtype")
// .field("type", "keyword")
// .endObject()
// .startObject("content")
// .field("type", "text")
// .endObject()
// .endObject()
// .endObject();
// return xContentBuilder;
// }
}
......@@ -37,6 +37,8 @@ public class WeMsgTlp extends BaseEntity
/** 欢迎语模板使用范围 */
private List<WeMsgTlpScope> weMsgTlpScopes;
private String materialUrl;
}
......@@ -60,6 +60,7 @@ public interface IWeTagGroupService extends IService<WeTagGroup>
/**
* 来自微信端批量保存或者更新标签组和标签
* @param tagGroup
* @param isSync
*/
public void batchSaveOrUpdateTagGroupAndTag(List<WeCropGroupTagDto> tagGroup);
public void batchSaveOrUpdateTagGroupAndTag(List<WeCropGroupTagDto> tagGroup,Boolean isSync);
}
......@@ -5,6 +5,7 @@ import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.domain.WeMsgTlpScope;
import com.linkwechat.wecom.service.IWeMsgTlpScopeService;
......@@ -61,33 +62,32 @@ public class WeMsgTlpServiceImpl implements IWeMsgTlpService
* @return 结果
*/
@Override
@Transactional
public int insertWeMsgTlp(WeMsgTlp weMsgTlp)
{
int returnCode = weMsgTlpMapper.insertWeMsgTlp(weMsgTlp);
if(returnCode>0){
List<WeMsgTlpScope> weMsgTlpScopess = weMsgTlp.getWeMsgTlpScopes();
if(CollectionUtil.isNotEmpty(weMsgTlpScopess)){
List<WeMsgTlpScope> weMsgTlpScopes=weMsgTlp.getWeMsgTlpScopes().stream().filter(c -> c.getUseUserId() != null).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(weMsgTlpScopes)){
weMsgTlpScopes.forEach(v->{
v.setMsgTlpId(weMsgTlp.getId());
v.setId(SnowFlakeUtil.nextId());
});
iWeMsgTlpScopeService.batchInsetWeMsgTlpScope(weMsgTlpScopes);
}
}
}
return returnCode;
weMsgTlp.setCreateBy(SecurityUtils.getUsername());
return weMsgTlpMapper.insertWeMsgTlp(weMsgTlp);
// if(returnCode>0){
// List<WeMsgTlpScope> weMsgTlpScopess = weMsgTlp.getWeMsgTlpScopes();
// if(CollectionUtil.isNotEmpty(weMsgTlpScopess)){
//
// List<WeMsgTlpScope> weMsgTlpScopes=weMsgTlp.getWeMsgTlpScopes().stream().filter(c -> c.getUseUserId() != null).collect(Collectors.toList());
// if(CollectionUtil.isNotEmpty(weMsgTlpScopes)){
//
// weMsgTlpScopes.forEach(v->{
// v.setMsgTlpId(weMsgTlp.getId());
// v.setId(SnowFlakeUtil.nextId());
// });
//
// iWeMsgTlpScopeService.batchInsetWeMsgTlpScope(weMsgTlpScopes);
// }
//
// }
// }
// return returnCode;
}
/**
......@@ -97,22 +97,21 @@ public class WeMsgTlpServiceImpl implements IWeMsgTlpService
* @return 结果
*/
@Override
@Transactional
public int updateWeMsgTlp(WeMsgTlp weMsgTlp)
{
int returnCode = weMsgTlpMapper.updateWeMsgTlp(weMsgTlp);
if(returnCode>0){
iWeMsgTlpScopeService.batchRemoveWeMsgTlpScopesByMsgTlpIds(ListUtil.toList(weMsgTlp.getId()));
List<WeMsgTlpScope> weMsgTlpScopes = weMsgTlp.getWeMsgTlpScopes().stream().filter(c -> c.getUseUserId() != null).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(weMsgTlpScopes)){
weMsgTlpScopes.stream().forEach(v->v.setMsgTlpId(weMsgTlp.getId()));
iWeMsgTlpScopeService.batchInsetWeMsgTlpScope(weMsgTlpScopes);
}
}
// int returnCode = weMsgTlpMapper.updateWeMsgTlp(weMsgTlp);
//
// if(returnCode>0){
// iWeMsgTlpScopeService.batchRemoveWeMsgTlpScopesByMsgTlpIds(ListUtil.toList(weMsgTlp.getId()));
// List<WeMsgTlpScope> weMsgTlpScopes = weMsgTlp.getWeMsgTlpScopes().stream().filter(c -> c.getUseUserId() != null).collect(Collectors.toList());
//
// if(CollectionUtil.isNotEmpty(weMsgTlpScopes)){
// weMsgTlpScopes.stream().forEach(v->v.setMsgTlpId(weMsgTlp.getId()));
// iWeMsgTlpScopeService.batchInsetWeMsgTlpScope(weMsgTlpScopes);
// }
//
// }
return weMsgTlpMapper.updateWeMsgTlp(weMsgTlp);
}
......
......@@ -4,24 +4,16 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.bean.BeanUtils;
import com.linkwechat.wecom.client.WeCropTagClient;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeTag;
import com.linkwechat.wecom.domain.WeTagGroup;
import com.linkwechat.wecom.domain.dto.tag.*;
import com.linkwechat.wecom.mapper.WeTagGroupMapper;
import com.linkwechat.wecom.mapper.WeTagMapper;
import com.linkwechat.wecom.service.IWeTagGroupService;
import com.linkwechat.wecom.service.IWeTagService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,9 +24,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 标签组Service业务层处理
......@@ -92,7 +82,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
WeCropGropTagDtlDto weCropGropTagDtlDto = weCropTagClient.addCorpTag(WeCropGroupTagDto.transformAddTag(weTagGroup));
if(weCropGropTagDtlDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
this.batchSaveOrUpdateTagGroupAndTag(ListUtil.toList(weCropGropTagDtlDto.getTag_group()));
this.batchSaveOrUpdateTagGroupAndTag(ListUtil.toList(weCropGropTagDtlDto.getTag_group()),false);
}
}
......@@ -116,6 +106,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
//获取新增的集合
if(CollectionUtil.isNotEmpty(weTags)) {
List<WeTag> filterWeTags = weTags.stream().filter(v -> StringUtils.isEmpty(v.getTagId())).collect(Collectors.toList());
//同步新增标签到微信端
if(CollectionUtil.isNotEmpty(WeCropGroupTagDto.transformAddTag(weTagGroup).getTag())){
WeCropGropTagDtlDto
......@@ -134,7 +125,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())
.eq(WeTag::getStatus,Constants.NORMAL_CODE));
......@@ -207,7 +198,7 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getAllCorpTagList();
if(weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
this.batchSaveOrUpdateTagGroupAndTag(weCropGroupTagListDto.getTag_group());
this.batchSaveOrUpdateTagGroupAndTag(weCropGroupTagListDto.getTag_group(),true);
}
}
......@@ -216,10 +207,11 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
/**
* 来自微信端批量保存或者更新标签组和标签
* @param tagGroup
* @param isSync 是否同步
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void batchSaveOrUpdateTagGroupAndTag(List<WeCropGroupTagDto> tagGroup) {
public void batchSaveOrUpdateTagGroupAndTag(List<WeCropGroupTagDto> tagGroup,Boolean isSync) {
List<WeTagGroup> weTagGroups=new ArrayList<>();
......@@ -252,14 +244,17 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
//先逻辑删除不存在得组
if(CollectionUtil.isNotEmpty(weTagGroups)){
List<WeTagGroup> noExist
= 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);
if(isSync){
List<WeTagGroup> noExist
= 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.saveOrUpdateBatch(weTagGroups);
List<WeTag> weTags =
......@@ -267,18 +262,42 @@ public class WeTagGroupServiceImpl extends ServiceImpl<WeTagGroupMapper,WeTagGr
if(CollectionUtil.isNotEmpty(weTags)){
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);
if(isSync){
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.saveOrUpdateBatch(weTags);
}
}else{//不存在删除所有标签组,以标签
if(isSync){
List<WeTagGroup> weTagGroupList
= this.list(new LambdaQueryWrapper<WeTagGroup>().eq(WeTagGroup::getStatus, Constants.NORMAL_CODE));
if(CollectionUtil.isNotEmpty(weTagGroupList)){
weTagGroupList.stream().forEach(k->k.setStatus(Constants.DELETE_CODE));
this.updateBatchById(weTagGroupList);
}
List<WeTag> weTags
= iWeTagService.list(new LambdaQueryWrapper<WeTag>().eq(WeTag::getStatus, Constants.NORMAL_CODE));
if(CollectionUtil.isNotEmpty(weTags)){
weTags.stream().forEach(k->k.setStatus(Constants.DELETE_CODE));
iWeTagService.updateBatchById(weTags);
}
}
}
......
......@@ -112,80 +112,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND wt.tag_id=#{tagIds}
</if>
</if>
</where>
ORDER BY wfcr.create_time DESC
<!-- 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,-->
<!-- wfcr.status,-->
<!-- wu.user_name,-->
<!-- wfcrf.flower_customer_rel_id,-->
<!-- wt.tag_id,-->
<!-- wt.`name` as tagName,-->
<!-- (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department-->
<!-- FROM-->
<!-- 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-->
<!-- INNER JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id-->
<!-- <where>-->
<!-- <if test="name != null and name !=''">-->
<!-- AND wc.name like concat('%', #{name}, '%')-->
<!-- </if>-->
<!-- <if test="userIds != null and userIds !=''">-->
<!-- <if test="userIds.indexOf(',') != -1">-->
<!-- and wfcr.user_id in-->
<!-- <foreach item="item" index="index" collection="userIds.split(',')" open="(" separator="," close=")">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="userIds.indexOf(',') == -1">-->
<!-- and wfcr.user_id=#{userIds}-->
<!-- </if>-->
<!-- </if>-->
<!-- <if test="tagIds != null and tagIds !=''">-->
<!-- <if test="tagIds.indexOf(',') != -1">-->
<!-- and wt.tag_id in-->
<!-- <foreach item="item" index="index" collection="tagIds.split(',')" open="(" separator="," close=")">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="tagIds.indexOf(',') == -1">-->
<!-- and wt.tag_id=#{tagIds}-->
<!-- </if>-->
<!-- </if>-->
<!-- <if test="beginTime != null and beginTime != ''">&lt;!&ndash; 开始时间检索 &ndash;&gt;-->
<!-- AND date_format(wfcr.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')-->
<!-- </if>-->
<!-- <if test="endTime != null and endTime != ''">&lt;!&ndash; 结束时间检索 &ndash;&gt;-->
<!-- AND date_format(wfcr.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')-->
<!-- </if>-->
<!-- <if test="status != null and status !=''">-->
<!-- AND wfcr.status = #{status}-->
<!-- </if>-->
<!-- </where>-->
</select>
......@@ -197,7 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM
we_flower_customer_tag_rel wfcrf
LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id
where wfcrf.flower_customer_rel_id=#{id}
where wt.status=0 and wfcrf.flower_customer_rel_id=#{id}
</select>
......
......@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="welcomeMsgTplType" column="welcome_msg_tpl_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="materialUrl" column="material_url"/>
</resultMap>
<sql id="selectWeMsgTlpVo">
......@@ -19,14 +20,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectWeMsgTlpList" parameterType="WeMsgTlp" resultMap="WeMsgTlpResult">
<include refid="selectWeMsgTlpVo"/>
SELECT
wmt.id,
wmt.welcome_msg,
wmt.media_id,
wmt.del_flag,
wmt.welcome_msg_tpl_type,
wmt.create_by,
wmt.create_time,
wm.material_url
FROM
we_msg_tlp wmt
INNER JOIN we_material wm ON wmt.media_id=wm.id
<where>
<if test="welcomeMsg != null and welcomeMsg != ''"> and welcome_msg like CONCAT('%',#{welcomeMsg,jdbcType=VARCHAR},'%') </if>
<if test="mediaId != null "> and media_id = #{mediaId}</if>
<if test="welcomeMsgTplType != null "> and welcome_msg_tpl_type = #{welcomeMsgTplType}</if>
<if test="delFlag != null ">and del_flag = #{delFlag}</if>
<if test="welcomeMsg != null and welcomeMsg != ''"> and wmt.welcome_msg like CONCAT('%',#{welcomeMsg,jdbcType=VARCHAR},'%') </if>
</where>
</select>
<select id="selectWeMsgTlpById" parameterType="Long" resultMap="WeMsgTlpResult">
<include refid="selectWeMsgTlpVo"/>
......@@ -41,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mediaId != null">media_id,</if>
<if test="delFlag != null">del_flag,</if>
<if test="welcomeMsgTplType != null">welcome_msg_tpl_type,</if>
<if test="createBy != null ">create_by,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
......@@ -48,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mediaId != null">#{mediaId},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="welcomeMsgTplType != null">#{welcomeMsgTplType},</if>
<if test="createBy != null ">#{createBy},</if>
</trim>
</insert>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!