liulin
2025-06-19 6fdafdef5c457cd5fabebcaedd4e9418979468d6
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
#                                                    __----~~~~~~~~~~~------___
#                                   .  .   ~~//====......          __--~ ~~
#                   -.            \_|//     |||\\  ~~~~~~::::... /~
#                ___-==_       _-~o~  \/    |||  \\            _/~~-
#        __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
#    _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
#  .~       .~       |   \\ -_    /  /-   /   ||      \   /
# /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
# |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
#          '         ~-|      /|    |-~\~~       __--~~
#                      |-~~-_/ |    |   ~\_   _-~            /\
#                           /  \     \__   \/~                \__
#                       _--~ _/ | .-~~____--~-/                  ~~==.
#                      ((->/~   '.|||' -_|    ~~-/ ,              . _||
#                                 -_     ~\      ~~---l__i__i__i--~~_/
#                                 _-~-__   ~)  \--______________--~~
#                               //.-~~~-~_--~- |-------~~~~~~~~
#                                      //.-~~~--\
#                  神兽保佑
#                  永无BUG!
*/
package com.fengdu.gas.service;
 
import com.fengdu.gas.common.*;
import com.fengdu.gas.common.enums.*;
import com.fengdu.gas.common.model.Tuple;
import com.fengdu.gas.common.util.*;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
import com.fengdu.gas.repository.impl.CommonParametersMapperImpl;
import com.fengdu.gas.repository.po.CommonParametersPO;
import com.fengdu.gas.entity.request.commonparameters.ReqCreateCommonParameters;
import com.fengdu.gas.entity.request.commonparameters.ReqModifyCommonParameters;
import com.fengdu.gas.entity.search.SearchCommonParameters;
import com.fengdu.gas.repository.vo.CommonParametersVO;
import com.fengdu.gas.service.convert.CommonParametersConvert;
 
/**
 * 公共参数
 * @author zr
 */
@Service
public class CommonParametersService extends BaseService {
    @Autowired
    private CommonParametersMapperImpl mapper;
 
    public ExecutedResult<Long> create(ReqCreateCommonParameters request) {
        // 转换po
        CommonParametersPO item = CommonParametersConvert.INSTANCE.toCreate(request);
        // 设置状态
        //item.setStatus(EState.NORMAL.getValue());
        // 设置记录创建时间
        item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
        // 是否删除(逻辑删除)初始值
        item.setIsDelete(EYesOrNo.NO.getValue());
 
        int rowCount = mapper.insert(item);
        if (rowCount != 1) {
            return ExecutedResult.failed("创建[公共参数]失败。");
        }
        return ExecutedResult.success(item.getId());
    }
 
    public ExecutedResult<String> modify(ReqModifyCommonParameters request) {
        // 验证记录是否存在
        ExecutedResult<CommonParametersPO> checkExists = this.check4Id(request.getId());
        if (checkExists.isFailed()) {
            return ExecutedResult.failed(checkExists.getMsg());
        }
        // 转换po
        CommonParametersPO item = CommonParametersConvert.INSTANCE.toModify(request);
 
        int rowCount = mapper.updateById(item);
        if (rowCount != 1) {
            return ExecutedResult.failed("编辑[公共参数]失败。");
        }
        return ExecutedResult.success();
    }
 
    public ExecutedResult<CommonParametersVO> get(Long id) {
        CommonParametersVO result = new CommonParametersVO();
 
        CommonParametersPO find = mapper.get(id);
        if (null != find) {
            // 转换vo
            result = CommonParametersConvert.INSTANCE.toVo(find);
        }
        return ExecutedResult.success(result);
    }
 
//    public ExecutedResult<String> stop(Long id) {
//        // 验证记录是否存在
//        ExecutedResult<CommonParametersPO> checkExists = this.check4Id(id);
//        if (checkExists.isFailed()) {
//            return ExecutedResult.failed(checkExists.getMsg());
//        }
//        CommonParametersPO item = new CommonParametersPO();
//        item.setId(id);
//        item.setStatus(EState.DISABLED.getValue());
//
//        int rowCount = mapper.updateById(item);
//        if (rowCount != 1) {
//           return ExecutedResult.failed("停用[公共参数]失败。");
//       }
//       return ExecutedResult.success();
//   }
//
//    public ExecutedResult<String> enable(Long id) {
//        // 验证记录是否存在
//        ExecutedResult<CommonParametersPO> checkExists = this.check4Id(id);
//        if (checkExists.isFailed()) {
//            return ExecutedResult.failed(checkExists.getMsg());
//        }
//        CommonParametersPO item = new CommonParametersPO();
//        item.setId(id);
//        item.setStatus(EState.NORMAL.getValue());
//
//        int rowCount = mapper.updateById(item);
//        if (rowCount != 1) {
//            return ExecutedResult.failed("启用[公共参数]失败。");
//        }
//        return ExecutedResult.success();
//    }
//
//    public ExecutedResult<String> setSort(ReqSetSort request) {
//        // 验证记录是否存在
//        ExecutedResult<CommonParametersPO> checkExists = this.check4Id(request.getId());
//        if (checkExists.isFailed()) {
//            return ExecutedResult.failed(checkExists.getMsg());
//        }
//        CommonParametersPO item = new CommonParametersPO();
//        item.setId(request.getId());
//        item.setSort(request.getSort());
//
//        int rowCount = mapper.updateById(item);
//        if (rowCount != 1) {
//            return ExecutedResult.failed("设置[公共参数]排序值失败。");
//        }
//        return ExecutedResult.success();
//    }
//
//    public ExecutedResult<String> listSetSort(ReqListSetSort request) {
//        // id列表
//        List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList());
//        // 验证记录是否存在
//        ExecutedResult<List<CommonParametersPO>> checkExists = this.check4Id(listId);
//        if (checkExists.isFailed()) {
//            return ExecutedResult.failed(checkExists.getMsg());
//        }
//
//        List<CommonParametersPO> listUpdate = request.getList().stream()
//                .map(c -> {
//                    CommonParametersPO item = new CommonParametersPO();
//                    item.setId(c.getId());
//                    item.setSort(c.getSort());
//                    return item;
//                })
//                .collect(Collectors.toList());
//        Boolean result = mapper.modifyList(listUpdate);
//        if (result) {
//            return ExecutedResult.success();
//        }
//        return ExecutedResult.failed("[公共参数]设置排序值失败");
//    }
//
//    public ExecutedResult<String> remove(Long id) {
//        Boolean result = mapper.deleteLogic(id);
//        if (BooleanUtils.isFalse(result)) {
//            return ExecutedResult.failed("删除[公共参数]失败。");
//        }
//        return ExecutedResult.success();
//    }
//
//    public ExecutedResult<String> removeList(List<Long> ids) {
//        Boolean result = mapper.deleteLogic(ids);
//        if (BooleanUtils.isFalse(result)) {
//            return ExecutedResult.failed("删除[公共参数]失败。");
//        }
//        return ExecutedResult.success();
//    }
 
    public ExecutedResult<List<CommonParametersVO>> getList(List<Long> listId) {
        List<CommonParametersVO> result = new ArrayList<>();
 
        List<CommonParametersPO> list = mapper.getList(listId);
        if (ListUtil.isNotNullOrEmpty(list)) {
            // 转换vo
            result = CommonParametersConvert.INSTANCE.toVo(list);
        }
        return ExecutedResult.success(result);
    }
 
    public ExecutedResult<PagerResult<CommonParametersVO>> search(SearchCommonParameters search) {
        // 处理创建时间范围-查询参数
        Tuple<String, String> createTimeRange = ParameterUtil.getTimeRange(search.getCreateTimeRange());
        if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem1())) {
            search.setCreateTimeStart(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem1()).getTime());
        }
        if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem2())) {
            search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime());
        }
 
        PagerResult<CommonParametersPO> pageList = mapper.search(search);
        List<CommonParametersVO> listVo = new ArrayList<>();
        List<CommonParametersPO> list = pageList.getList();
        if (ListUtil.isNotNullOrEmpty(list)) {
            pageList.setLastId(list.get(list.size() - 1).getId());
            // 转换vo
            listVo = CommonParametersConvert.INSTANCE.toVo(list);
        }
        PagerResult<CommonParametersVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
        result.setLastId(pageList.getLastId());
        return ExecutedResult.success(result);
    }
 
    protected ExecutedResult<CommonParametersPO> check4Id(Long id) {
        CommonParametersPO exists = mapper.get(id);
        if (Objects.isNull(exists)) {
            return ExecutedResult.failed("[公共参数]不存在:" + id);
        }
        return ExecutedResult.success(exists);
    }
    protected ExecutedResult<List<CommonParametersPO>> check4Id(List<Long> listId) {
        // 从数据库查找公共参数
        List<CommonParametersPO> list = mapper.getList(listId);
        if (ListUtil.isNullOrEmpty(list)) {
            return ExecutedResult.failed("[公共参数]不存在." + listId);
        }
        // 数据库找到的id列表
        List<Long> listIdFind = list.stream().map(CommonParametersPO::getId).collect(Collectors.toList());
        // 数量不一致
        if (listId.size() != listIdFind.size()) {
            // 筛选数据库不存在的公共参数
            List<Long> listIdNotFound = listId.stream().filter(c -> !listIdFind.contains(c)).collect(Collectors.toList());
            if (ListUtil.isNullOrEmpty(list)) {
                return ExecutedResult.failed("[公共参数]不存在." + listIdNotFound);
            }
        }
        return ExecutedResult.success(list);
    }}