|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.flossom.system.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@ -7,10 +9,12 @@ import java.util.stream.Collectors;
|
|
|
|
|
import com.flossom.common.core.domain.entity.SysTag;
|
|
|
|
|
import com.flossom.common.core.domain.entity.WxScriptTag;
|
|
|
|
|
import com.flossom.common.core.domain.entity.WxScriptTemplate;
|
|
|
|
|
import com.flossom.common.core.domain.vo.TreeSelect;
|
|
|
|
|
import com.flossom.common.core.mapper.SysTagMapper;
|
|
|
|
|
import com.flossom.common.core.mapper.WxScriptTagMapper;
|
|
|
|
|
import com.flossom.common.core.mapper.WxScriptTemplateMapper;
|
|
|
|
|
import com.flossom.common.core.utils.DateUtils;
|
|
|
|
|
import com.flossom.common.core.utils.SpringUtils;
|
|
|
|
|
import com.flossom.common.core.utils.StringUtils;
|
|
|
|
|
import com.flossom.common.security.utils.SecurityUtils;
|
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
@ -26,14 +30,14 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
* @date 2023-12-18
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
{
|
|
|
|
|
public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxScriptTemplateMapper wxScriptTemplateMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxScriptTagMapper wxScriptTagMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysTagMapper sysTagMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询话术模板
|
|
|
|
|
*
|
|
|
|
|
@ -41,8 +45,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 话术模板
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public WxScriptTemplate selectWxScriptTemplateById(Long id)
|
|
|
|
|
{
|
|
|
|
|
public WxScriptTemplate selectWxScriptTemplateById(Long id) {
|
|
|
|
|
return wxScriptTemplateMapper.selectWxScriptTemplateById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -53,8 +56,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 话术模板
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<WxScriptTemplate> selectWxScriptTemplateList(WxScriptTemplate wxScriptTemplate)
|
|
|
|
|
{
|
|
|
|
|
public List<WxScriptTemplate> selectWxScriptTemplateList(WxScriptTemplate wxScriptTemplate) {
|
|
|
|
|
return wxScriptTemplateMapper.selectWxScriptTemplateList(wxScriptTemplate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -65,15 +67,14 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int insertWxScriptTemplate(WxScriptTemplate wxScriptTemplate)
|
|
|
|
|
{
|
|
|
|
|
public int insertWxScriptTemplate(WxScriptTemplate wxScriptTemplate) {
|
|
|
|
|
wxScriptTemplate.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
wxScriptTemplate.setCreateBy(SecurityUtils.getLoginUser().getUsername());
|
|
|
|
|
List<SysTag> sysTags = Lists.newArrayList();
|
|
|
|
|
// 处理标签在字段的展示
|
|
|
|
|
List<Long> tagIds = wxScriptTemplate.getTagIdArray();
|
|
|
|
|
if(!CollectionUtils.isEmpty(tagIds)) {
|
|
|
|
|
for (long tagId:tagIds) {
|
|
|
|
|
if (!CollectionUtils.isEmpty(tagIds)) {
|
|
|
|
|
for (long tagId : tagIds) {
|
|
|
|
|
SysTag sysTag = sysTagMapper.selectDeptById(tagId);
|
|
|
|
|
if (Objects.nonNull(sysTag)) {
|
|
|
|
|
sysTags.add(sysTag);
|
|
|
|
|
@ -90,7 +91,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
|
|
|
|
|
int i = wxScriptTemplateMapper.insertWxScriptTemplate(wxScriptTemplate);
|
|
|
|
|
|
|
|
|
|
for(SysTag tag : sysTags) {
|
|
|
|
|
for (SysTag tag : sysTags) {
|
|
|
|
|
// 增加关联关系
|
|
|
|
|
WxScriptTag scriptTag = new WxScriptTag();
|
|
|
|
|
scriptTag.setScriptId(wxScriptTemplate.getId());
|
|
|
|
|
@ -110,8 +111,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int updateWxScriptTemplate(WxScriptTemplate wxScriptTemplate)
|
|
|
|
|
{
|
|
|
|
|
public int updateWxScriptTemplate(WxScriptTemplate wxScriptTemplate) {
|
|
|
|
|
wxScriptTemplate.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
wxScriptTemplate.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
|
|
|
|
|
wxScriptTemplate.setTagIds("");
|
|
|
|
|
@ -119,8 +119,8 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
List<SysTag> sysTags = Lists.newArrayList();
|
|
|
|
|
// 处理标签在字段的展示
|
|
|
|
|
List<Long> tagIds = wxScriptTemplate.getTagIdArray();
|
|
|
|
|
if(!CollectionUtils.isEmpty(tagIds)) {
|
|
|
|
|
for (long tagId:tagIds) {
|
|
|
|
|
if (!CollectionUtils.isEmpty(tagIds)) {
|
|
|
|
|
for (long tagId : tagIds) {
|
|
|
|
|
SysTag sysTag = sysTagMapper.selectDeptById(tagId);
|
|
|
|
|
if (Objects.nonNull(sysTag)) {
|
|
|
|
|
sysTags.add(sysTag);
|
|
|
|
|
@ -138,7 +138,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
// 先删除原本的关系
|
|
|
|
|
wxScriptTagMapper.deleteWxScriptByScriptId(wxScriptTemplate.getId());
|
|
|
|
|
|
|
|
|
|
for(SysTag tag : sysTags) {
|
|
|
|
|
for (SysTag tag : sysTags) {
|
|
|
|
|
// 增加关联关系
|
|
|
|
|
WxScriptTag scriptTag = new WxScriptTag();
|
|
|
|
|
scriptTag.setScriptId(wxScriptTemplate.getId());
|
|
|
|
|
@ -158,8 +158,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int deleteWxScriptTemplateByIds(Long[] ids)
|
|
|
|
|
{
|
|
|
|
|
public int deleteWxScriptTemplateByIds(Long[] ids) {
|
|
|
|
|
return wxScriptTemplateMapper.deleteWxScriptTemplateByIds(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -170,8 +169,7 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int deleteWxScriptTemplateById(Long id)
|
|
|
|
|
{
|
|
|
|
|
public int deleteWxScriptTemplateById(Long id) {
|
|
|
|
|
// 先删除原本的关系
|
|
|
|
|
int i = wxScriptTagMapper.deleteWxScriptByScriptId(id);
|
|
|
|
|
return wxScriptTemplateMapper.deleteWxScriptTemplateById(id);
|
|
|
|
|
@ -182,4 +180,68 @@ public class WxScriptTemplateServiceImpl implements IWxScriptTemplateService
|
|
|
|
|
int result = wxScriptTemplateMapper.hasChildByScriptId(id);
|
|
|
|
|
return result > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TreeSelect> scriptTree(WxScriptTemplate wxScriptTemplate) {
|
|
|
|
|
List<WxScriptTemplate> wxScriptTemplateList = this.selectWxScriptTemplateList(wxScriptTemplate);
|
|
|
|
|
return buildTree(wxScriptTemplateList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<TreeSelect> buildTree(List<WxScriptTemplate> wxScriptTemplateList) {
|
|
|
|
|
List<WxScriptTemplate> deptTrees = buildDeptTree(wxScriptTemplateList);
|
|
|
|
|
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<WxScriptTemplate> buildDeptTree(List<WxScriptTemplate> wxScriptTemplateList) {
|
|
|
|
|
List<WxScriptTemplate> returnList = new ArrayList<>();
|
|
|
|
|
List<Long> tempList = wxScriptTemplateList.stream().map(WxScriptTemplate::getId).collect(Collectors.toList());
|
|
|
|
|
for (WxScriptTemplate wxScriptTemplate : wxScriptTemplateList) {
|
|
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
|
|
if (!tempList.contains(wxScriptTemplate.getParentId())) {
|
|
|
|
|
recursionFn(wxScriptTemplateList, wxScriptTemplate);
|
|
|
|
|
returnList.add(wxScriptTemplate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (returnList.isEmpty()) {
|
|
|
|
|
returnList = wxScriptTemplateList;
|
|
|
|
|
}
|
|
|
|
|
return returnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归列表
|
|
|
|
|
*/
|
|
|
|
|
private void recursionFn(List<WxScriptTemplate> list, WxScriptTemplate t) {
|
|
|
|
|
// 得到子节点列表
|
|
|
|
|
List<WxScriptTemplate> childList = getChildList(list, t);
|
|
|
|
|
t.setScriptTemplateChildren(childList);
|
|
|
|
|
for (WxScriptTemplate tChild : childList) {
|
|
|
|
|
if (hasChild(list, tChild)) {
|
|
|
|
|
recursionFn(list, tChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 得到子节点列表
|
|
|
|
|
*/
|
|
|
|
|
private List<WxScriptTemplate> getChildList(List<WxScriptTemplate> list, WxScriptTemplate t) {
|
|
|
|
|
List<WxScriptTemplate> tlist = new ArrayList<>();
|
|
|
|
|
Iterator<WxScriptTemplate> it = list.iterator();
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
WxScriptTemplate n = (WxScriptTemplate) it.next();
|
|
|
|
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) {
|
|
|
|
|
tlist.add(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tlist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否有子节点
|
|
|
|
|
*/
|
|
|
|
|
private boolean hasChild(List<WxScriptTemplate> list, WxScriptTemplate t) {
|
|
|
|
|
return getChildList(list, t).size() > 0 ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|