liusheng
2025-04-10 1967693c5d760ade002f8a5fbea10b51aef5693f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.smartor.service.impl;
 
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.smartor.domain.IvrLibaTargetAssort;
import com.smartor.domain.SvyLibScriptCategory;
import com.smartor.domain.SvyLibScriptCategoryVO;
import com.smartor.mapper.SvyLibScriptCategoryMapper;
import com.smartor.service.ISvyLibScriptCategoryService;
import io.jsonwebtoken.lang.Collections;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 问卷题目分类Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Slf4j
@Service
public class SvyLibScriptCategoryServiceImpl implements ISvyLibScriptCategoryService {
    @Autowired
    private SvyLibScriptCategoryMapper svyLibScriptCategoryMapper;
 
    /**
     * 查询问卷题目分类
     *
     * @param id 问卷题目分类主键
     * @return 问卷题目分类
     */
    @Override
    public SvyLibScriptCategory selectSvyLibScriptCategoryById(Long id) {
        return svyLibScriptCategoryMapper.selectSvyLibScriptCategoryById(id);
    }
 
    /**
     * 查询问卷题目分类列表
     *
     * @param svyLibScriptCategory 问卷题目分类
     * @return 问卷题目分类
     */
    @Override
    public List<SvyLibScriptCategoryVO> selectSvyLibScriptCategoryList(SvyLibScriptCategory svyLibScriptCategory) {
        List<SvyLibScriptCategory> svyLibScriptCategories = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory);
//        //将pid为空的,过滤掉
//        svyLibScriptCategories = svyLibScriptCategories.stream().filter(assort -> assort.getPid() != null).collect(Collectors.toList());
 
        List<SvyLibScriptCategoryVO> SvyLibScriptCategoryVO = DtoConversionUtils.sourceToTarget(svyLibScriptCategories, SvyLibScriptCategoryVO.class);
        //遍历查出来的数据,通过 id=pid 获取他们的子数据
        for (SvyLibScriptCategoryVO svyLibScriptCategoryVO : SvyLibScriptCategoryVO) {
//            if (svyLibScriptCategoryVO.getPid() != null) {
//                continue;
//            }
            SvyLibScriptCategory svyLibScriptCategory1 = new SvyLibScriptCategory();
            svyLibScriptCategory1.setPid(svyLibScriptCategoryVO.getId());
            List<SvyLibScriptCategory> svyLibScriptCategories1 = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory1);
            if (!Collections.isEmpty(svyLibScriptCategories1)) {
                svyLibScriptCategoryVO.setSvyLibScriptCategoryList(svyLibScriptCategories1);
            }
        }
        return SvyLibScriptCategoryVO;
    }
 
    /**
     * 新增问卷题目分类
     *
     * @param svyLibScriptCategory 问卷题目分类
     * @return 结果
     */
    @Override
    public int insertSvyLibScriptCategory(SvyLibScriptCategory svyLibScriptCategory) {
        svyLibScriptCategory.setCreateTime(DateUtils.getNowDate());
        return svyLibScriptCategoryMapper.insertSvyLibScriptCategory(svyLibScriptCategory);
    }
 
    /**
     * 修改问卷题目分类
     *
     * @param svyLibScriptCategory 问卷题目分类
     * @return 结果
     */
    @Override
    public int updateSvyLibScriptCategory(SvyLibScriptCategory svyLibScriptCategory) {
        svyLibScriptCategory.setUpdateTime(DateUtils.getNowDate());
        return svyLibScriptCategoryMapper.updateSvyLibScriptCategory(svyLibScriptCategory);
    }
 
    /**
     * 批量删除问卷题目分类
     *
     * @param ids 需要删除的问卷题目分类主键
     * @return 结果
     */
    @Override
    public int deleteSvyLibScriptCategoryByIds(Long[] ids) {
        Integer i = null;
        for (Long id : ids) {
            if (id < 0) {
                log.info("小于0的值为默认值不能删除:{}", id);
                continue;
            }
            i = svyLibScriptCategoryMapper.deleteSvyLibScriptCategoryById(id);
            SvyLibScriptCategory svyLibScriptCategory = new SvyLibScriptCategory();
            svyLibScriptCategory.setPid(id);
            List<SvyLibScriptCategory> svyLibScriptCategories = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory);
            if (CollectionUtils.isNotEmpty(svyLibScriptCategories)) {
                for (SvyLibScriptCategory svyLibScriptCategory1 : svyLibScriptCategories) {
                    svyLibScriptCategory1.setPid(-1L);
                    svyLibScriptCategoryMapper.updateSvyLibScriptCategory(svyLibScriptCategory1);
                }
            }
        }
        return i;
    }
 
    @Override
    public int insertSvyLibScriptCategoryTree(SvyLibScriptCategoryVO svyLibScriptCategoryVO) {
        Integer i = null;
        if (ObjectUtils.isEmpty(svyLibScriptCategoryVO)) {
            throw new BaseException("入参为空,请检查后,再新增");
        }
        Integer seqMax = null;
        try {
            seqMax = svyLibScriptCategoryMapper.selectSeqMax();
        } catch (Exception e) {
            seqMax = 0;
        }
 
        SvyLibScriptCategory svyLibScriptCategory = DtoConversionUtils.sourceToTarget(svyLibScriptCategoryVO, SvyLibScriptCategory.class);
        svyLibScriptCategory.setSeqno(1);
        if (seqMax != null) {
            svyLibScriptCategory.setSeqno(seqMax + 1);
        }
        svyLibScriptCategory.setUpdateTime(new Date());
        svyLibScriptCategory.setCreateTime(new Date());
        if (svyLibScriptCategory.getPid() == null) svyLibScriptCategory.setPid((long) -1);
        i = svyLibScriptCategoryMapper.insertSvyLibScriptCategory(svyLibScriptCategory);
        log.info("问题话术分类库一级树的主键:{}", svyLibScriptCategory.getId());
 
        //新增二级树
        if (CollectionUtils.isNotEmpty(svyLibScriptCategoryVO.getSvyLibScriptCategoryList())) {
            for (SvyLibScriptCategory svyLibScriptCategory1 : svyLibScriptCategoryVO.getSvyLibScriptCategoryList()) {
                Integer seqMax1 = null;
                try {
                    seqMax1 = svyLibScriptCategoryMapper.selectSeqMax();
                } catch (Exception e) {
                    seqMax1 = 0;
                }
                svyLibScriptCategory1.setPid(svyLibScriptCategory.getId());
                svyLibScriptCategory1.setSeqno(1);
                if (seqMax1 != null) {
                    svyLibScriptCategory1.setSeqno(seqMax1 + 1);
                }
                svyLibScriptCategory1.setGuid(svyLibScriptCategoryVO.getGuid());
                svyLibScriptCategory1.setOrgid(svyLibScriptCategoryVO.getOrgid());
                svyLibScriptCategoryMapper.insertSvyLibScriptCategory(svyLibScriptCategory1);
            }
        }
        return i;
    }
 
    /**
     * 删除问卷题目分类信息
     *
     * @param id 问卷题目分类主键
     * @return 结果
     */
    @Override
    public int deleteSvyLibScriptCategoryById(Long id) {
        return svyLibScriptCategoryMapper.deleteSvyLibScriptCategoryById(id);
    }
}