mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
package com.sinata.modular.system.controller;
 
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sinata.common.enums.EnumIsDelete;
import com.sinata.common.enums.EnumIsSystemNotice;
import com.sinata.common.enums.EnumSystemSetKey;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.base.tips.ErrorTip;
import com.sinata.core.common.annotion.BussinessLog;
import com.sinata.core.common.annotion.Permission;
import com.sinata.core.common.constant.factory.ConstantFactory;
import com.sinata.core.shiro.ShiroKit;
import com.sinata.modular.system.model.SystemNotice;
import com.sinata.modular.system.model.TSystemSet;
import com.sinata.modular.system.model.TSystemSetAudit;
import com.sinata.modular.system.service.ISystemNoticeService;
import com.sinata.modular.system.service.ITSystemSetAuditService;
import com.sinata.modular.system.service.ITSystemSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 系统设置控制器
 */
@Controller
@RequestMapping("/tSystemSet")
public class TSystemSetController extends BaseController {
 
    private String PREFIX = "/system/tSystemSet/";
 
    @Autowired
    private ITSystemSetService tSystemSetService;
 
    @Autowired
    private ITSystemSetAuditService tSystemSetAuditService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    /**
     * 跳转到系统设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tSystemSet.html";
    }
 
    @RequestMapping("/set_1")
    public String set_4(Model model) {
        Integer[] idArray = new Integer[]{
                EnumSystemSetKey.PLATFORM_TELEPHONE.index
        };
        // 封装Model数据
        getModelByIdArray(model, idArray);
 
        return PREFIX + "tSystemSet_1.html";
    }
    @BussinessLog(value = "修改平台客服联系电话")
    @ResponseBody
    @RequestMapping(value = "/update_1")
    public Object update_1(String val) {
        TSystemSet set = new TSystemSet()
                .setId(EnumSystemSetKey.PLATFORM_TELEPHONE.index)
                .setValueStr(val);
        set.updateById();
        return SUCCESS_TIP;
    }
 
    @RequestMapping("/set_100")
    public String set_100(Model model) {
        List<TSystemSet> list = tSystemSetService.selectList(
                new EntityWrapper<TSystemSet>()
                        .in("id", Arrays.asList(
                                EnumSystemSetKey.SET_101.index,
                                EnumSystemSetKey.SET_102.index,
                                EnumSystemSetKey.SET_103.index,
                                EnumSystemSetKey.SET_104.index,
                                EnumSystemSetKey.SET_105.index,
                                EnumSystemSetKey.SET_106.index
                        ))
        );
        for (TSystemSet o : list) {
            model.addAttribute("t_" + o.getId(), o.getValueStr());
        }
        return PREFIX + "tSystemSet_100.html";
    }
    @BussinessLog(value = "修改积分规则")
    @ResponseBody
    @RequestMapping(value = "/update_100")
    public Object update_100(String t_101, String t_102, String t_103, String t_104, String t_105, String t_106) {
        List<TSystemSet> list = Arrays.asList(
                new TSystemSet().setId(EnumSystemSetKey.SET_101.index).setValueStr(t_101),
                new TSystemSet().setId(EnumSystemSetKey.SET_102.index).setValueStr(t_102),
                new TSystemSet().setId(EnumSystemSetKey.SET_103.index).setValueStr(t_103),
                new TSystemSet().setId(EnumSystemSetKey.SET_104.index).setValueStr(t_104),
                new TSystemSet().setId(EnumSystemSetKey.SET_105.index).setValueStr(t_105),
                new TSystemSet().setId(EnumSystemSetKey.SET_106.index).setValueStr(t_106)
        );
 
        tSystemSetService.updateBatchById(list);
        return SUCCESS_TIP;
    }
 
    @RequestMapping("/set_200")
    public String set_200(Model model) {
        Integer[] idArray = new Integer[]{
                EnumSystemSetKey.SET_201.index, EnumSystemSetKey.SET_204.index,
                EnumSystemSetKey.SET_211.index, EnumSystemSetKey.SET_212.index, EnumSystemSetKey.SET_214.index, EnumSystemSetKey.SET_215.index, EnumSystemSetKey.SET_217.index,
                EnumSystemSetKey.SET_221.index, EnumSystemSetKey.SET_222.index, EnumSystemSetKey.SET_223.index, EnumSystemSetKey.SET_224.index, EnumSystemSetKey.SET_225.index, EnumSystemSetKey.SET_226.index, EnumSystemSetKey.SET_227.index
        };
        // 封装Model数据
        getModelByIdArray(model, idArray);
 
        return PREFIX + "tSystemSet_200.html";
    }
    @BussinessLog(value = "修改职级佣金设置")
    @Permission
    @ResponseBody
    @RequestMapping(value = "/update_200")
    public Object update_200(
            String t_201, String t_204,
            String t_211, String t_212, String t_214, String t_215, String t_217,
            String t_221, String t_222, String t_223, String t_224, String t_225, String t_226, String t_227
    ) {
        List<TSystemSet> list = Arrays.asList(
                new TSystemSet().setId(EnumSystemSetKey.SET_201.index).setValueStr(t_201),
                new TSystemSet().setId(EnumSystemSetKey.SET_204.index).setValueStr(t_204),
 
                new TSystemSet().setId(EnumSystemSetKey.SET_211.index).setValueStr(t_211),
                new TSystemSet().setId(EnumSystemSetKey.SET_212.index).setValueStr(t_212),
                new TSystemSet().setId(EnumSystemSetKey.SET_214.index).setValueStr(t_214),
                new TSystemSet().setId(EnumSystemSetKey.SET_215.index).setValueStr(t_215),
                new TSystemSet().setId(EnumSystemSetKey.SET_217.index).setValueStr(t_217),
 
                new TSystemSet().setId(EnumSystemSetKey.SET_221.index).setValueStr(t_221),
                new TSystemSet().setId(EnumSystemSetKey.SET_222.index).setValueStr(t_222),
                new TSystemSet().setId(EnumSystemSetKey.SET_223.index).setValueStr(t_223),
                new TSystemSet().setId(EnumSystemSetKey.SET_224.index).setValueStr(t_224),
                new TSystemSet().setId(EnumSystemSetKey.SET_225.index).setValueStr(t_225),
                new TSystemSet().setId(EnumSystemSetKey.SET_226.index).setValueStr(t_226),
                new TSystemSet().setId(EnumSystemSetKey.SET_227.index).setValueStr(t_227)
        );
 
        // 是否为超级管理员
        if (ShiroKit.hasRole("administrator")) {
            // 直接修改
            tSystemSetService.updateBatchById(list);
 
            // 添加后台通知
            SystemNotice.builder()
                    .param(0)
                    .type(EnumIsSystemNotice.TYPE_3.index)
                    .adminId(ShiroKit.getUser().getId())
                    .content(ShiroKit.getUser().getName() + " 已调整职级佣金设置!")
                    .build()
                    .insert();
 
            return SUCCESS_TIP;
        }
 
        int count = systemNoticeService.selectCount(
                new EntityWrapper<SystemNotice>()
                        .eq("type", EnumIsSystemNotice.TYPE_2.index)
                        .eq("is_delete", EnumIsDelete.EXISTED.index)
        );
        if (count != 0) {
            return new ErrorTip(500, "职级佣金设置审核中,请稍后再试!");
        }
 
        // 系统设置审核信息
        TSystemSetAudit o = TSystemSetAudit.builder()
                .adminId(ShiroKit.getUser().getId())
                .type(1)
                .setJson(JSONUtil.toJsonStr(list))
                .build();
        o.insert();
 
        // 添加后台通知
        SystemNotice.builder()
                .param(o.getId())
                .type(EnumIsSystemNotice.TYPE_2.index)
                .adminId(ShiroKit.getUser().getId())
                .content(ShiroKit.getUser().getName() + " 申请调整职级佣金设置,请核实审核!")
                .build()
                .insert();
        return SUCCESS_TIP;
    }
    @RequestMapping("/set_200_audit/{id}")
    public String set_200_audit(@PathVariable("id") Integer id, Model model) {
        TSystemSetAudit o = tSystemSetAuditService.selectById(id);
 
        // 封装Model数据
        model.addAttribute("id", id);
        List<TSystemSet> list = JSONUtil.toList(o.getSetJson(), TSystemSet.class);
        for (TSystemSet t : list) {
            model.addAttribute("t_" + t.getId(), t == null ? "0" : t.getValueStr());
        }
 
        return PREFIX + "tSystemSet_200_audit.html";
    }
    @BussinessLog(value = "职级佣金设置-审核")
    @Permission
    @ResponseBody
    @RequestMapping(value = "/update_200_audit")
    public Object update_200_audit(Integer id, Integer state, String remark) {
        Object result = updateAudit(id, state, remark);
 
        SystemNotice systemNotice = systemNoticeService.selectOne(
                new EntityWrapper<SystemNotice>()
                        .eq("param", id)
                        .eq("type", EnumIsSystemNotice.TYPE_2.index)
        );
        // 修改后台通知
        systemNotice
                .setId(systemNotice.getId())
                .setType(state == 1 ? EnumIsSystemNotice.TYPE_3.index : EnumIsSystemNotice.TYPE_4.index)
                .setContent(ConstantFactory.me().getUserNameById(systemNotice.getAdminId()) + " 申请调整职级佣金系数,已审核" + (state == 1 ? "通过" : "拒绝") + "!")
                .updateById();
        return result;
    }
 
    @RequestMapping("/set_300")
    public String set_300(Model model) {
        Integer[] idArray = new Integer[]{
                EnumSystemSetKey.SET_301.index, EnumSystemSetKey.SET_302.index, EnumSystemSetKey.SET_303.index, EnumSystemSetKey.SET_304.index, EnumSystemSetKey.SET_305.index,
                EnumSystemSetKey.SET_306.index,EnumSystemSetKey.SET_321.index, EnumSystemSetKey.SET_322.index, EnumSystemSetKey.SET_323.index, EnumSystemSetKey.SET_324.index,
                EnumSystemSetKey.SET_325.index,EnumSystemSetKey.SET_326.index, EnumSystemSetKey.SET_327.index, EnumSystemSetKey.SET_328.index, EnumSystemSetKey.SET_341.index,
                EnumSystemSetKey.SET_342.index, EnumSystemSetKey.SET_343.index, EnumSystemSetKey.SET_344.index, EnumSystemSetKey.SET_345.index,EnumSystemSetKey.SET_346.index,
                EnumSystemSetKey.SET_347.index, EnumSystemSetKey.SET_348.index
        };
        // 封装Model数据
        getModelByIdArray(model, idArray);
 
        return PREFIX + "tSystemSet_300.html";
    }
    @BussinessLog(value = "修改人员职级晋升维持设置")
    @ResponseBody
    @RequestMapping(value = "/update_300")
    public Object update_300(
            String t_301, String t_302, String t_303, String t_304, String t_305,String t_306,
            String t_321, String t_322, String t_323, String t_324, String t_325,
            String t_326, String t_327, String t_328,
            String t_341, String t_342, String t_343, String t_344, String t_345,
            String t_346, String t_347, String t_348
    ) {
        List<TSystemSet> list = Arrays.asList(
                new TSystemSet().setId(EnumSystemSetKey.SET_301.index).setValueStr(t_301),
                new TSystemSet().setId(EnumSystemSetKey.SET_302.index).setValueStr(t_302),
                new TSystemSet().setId(EnumSystemSetKey.SET_303.index).setValueStr(t_303),
                new TSystemSet().setId(EnumSystemSetKey.SET_304.index).setValueStr(t_304),
                new TSystemSet().setId(EnumSystemSetKey.SET_305.index).setValueStr(t_305),
                new TSystemSet().setId(EnumSystemSetKey.SET_306.index).setValueStr(t_306),
 
                new TSystemSet().setId(EnumSystemSetKey.SET_321.index).setValueStr(t_321),
                new TSystemSet().setId(EnumSystemSetKey.SET_322.index).setValueStr(t_322),
                new TSystemSet().setId(EnumSystemSetKey.SET_323.index).setValueStr(t_323),
                new TSystemSet().setId(EnumSystemSetKey.SET_324.index).setValueStr(t_324),
                new TSystemSet().setId(EnumSystemSetKey.SET_325.index).setValueStr(t_325),
                new TSystemSet().setId(EnumSystemSetKey.SET_326.index).setValueStr(t_326),
                new TSystemSet().setId(EnumSystemSetKey.SET_327.index).setValueStr(t_327),
                new TSystemSet().setId(EnumSystemSetKey.SET_328.index).setValueStr(t_328),
 
                new TSystemSet().setId(EnumSystemSetKey.SET_341.index).setValueStr(t_341),
                new TSystemSet().setId(EnumSystemSetKey.SET_342.index).setValueStr(t_342),
                new TSystemSet().setId(EnumSystemSetKey.SET_343.index).setValueStr(t_343),
                new TSystemSet().setId(EnumSystemSetKey.SET_344.index).setValueStr(t_344),
                new TSystemSet().setId(EnumSystemSetKey.SET_345.index).setValueStr(t_345),
                new TSystemSet().setId(EnumSystemSetKey.SET_346.index).setValueStr(t_346),
                new TSystemSet().setId(EnumSystemSetKey.SET_347.index).setValueStr(t_347),
                new TSystemSet().setId(EnumSystemSetKey.SET_348.index).setValueStr(t_348)
        );
 
        // 系统设置审核信息
        TSystemSetAudit o = TSystemSetAudit.builder()
                .adminId(ShiroKit.getUser().getId())
                .type(2)
                .setJson(JSONUtil.toJsonStr(list))
                .build();
 
        o.insert();
 
        // 添加后台通知
        SystemNotice.builder()
                .param(o.getId())
                .type(EnumIsSystemNotice.TYPE_5.index)
                .adminId(ShiroKit.getUser().getId())
                .content(ShiroKit.getUser().getName() + " 申请调整人员职级晋升维持设置,请核实审核!")
                .build()
                .insert();
 
        return SUCCESS_TIP;
    }
    @RequestMapping("/set_300_audit/{id}")
    public String set_300_audit(@PathVariable("id") Integer id, Model model) {
        TSystemSetAudit o = tSystemSetAuditService.selectById(id);
 
        // 封装Model数据
        model.addAttribute("id", id);
        List<TSystemSet> list = JSONUtil.toList(o.getSetJson(), TSystemSet.class);
        for (TSystemSet t : list) {
            model.addAttribute("t_" + t.getId(), t == null ? "0" : t.getValueStr());
        }
 
        return PREFIX + "tSystemSet_300_audit.html";
    }
    @BussinessLog(value = "人员职级晋升维持设置-审核")
    @Permission
    @ResponseBody
    @RequestMapping(value = "/update_300_audit")
    public Object update_300_audit(Integer id, Integer state, String remark) {
        SystemNotice systemNotice = systemNoticeService.selectOne(
                new EntityWrapper<SystemNotice>()
                        .eq("param", id)
                        .eq("type", EnumIsSystemNotice.TYPE_5.index)
        );
        if (systemNotice != null) {
            // 修改后台通知
            systemNotice
                    .setId(systemNotice.getId())
                    .setType(state == 1 ? EnumIsSystemNotice.TYPE_6.index : EnumIsSystemNotice.TYPE_7.index)
                    .setContent(ConstantFactory.me().getUserNameById(systemNotice.getAdminId()) + " 申请调整人员职级晋升维持设置,审核" + (state == 1 ? "通过" : "拒绝") + "!")
                    .updateById();
        }
 
        return updateAudit(id, state, remark);
    }
 
    public Object updateAudit(Integer id, Integer state, String remark) {
        TSystemSetAudit o = tSystemSetAuditService.selectById(id);
        if (state != null && state == 1) {
            tSystemSetService.updateBatchById(JSONUtil.toList(o.getSetJson(), TSystemSet.class));
        }
        o.setState(state);
        o.setRemark(remark);
        o.updateById();
 
        return SUCCESS_TIP;
    }
 
    private void getModelByIdArray(Model model, Object[] idArray) {
        List<TSystemSet> list = tSystemSetService.selectList(new EntityWrapper<TSystemSet>().in("id", idArray));
        for (TSystemSet t : list) {
            model.addAttribute("t_" + t.getId(), t == null ? "0" : t.getValueStr());
        }
    }
 
    /**
     * 获取系统设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        Wrapper wrapper = new EntityWrapper<TSystemSet>();
        return tSystemSetService.selectList(wrapper);
    }
 
    /**
     * 修改系统设置
     */
    @ResponseBody
    @RequestMapping(value = "/TSystemSetUpdate")
    public Object TSystemSetUpdate(String sys_1, String sys_2, String sys_3) {
        List<TSystemSet> list = new ArrayList<>();
        list.add(new TSystemSet(1, sys_1));
        list.add(new TSystemSet(2, sys_2));
        list.add(new TSystemSet(3, sys_3));
 
        tSystemSetService.updateBatchById(list);
        return SUCCESS_TIP;
    }
 
    /**
     * 新增系统设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TSystemSet tSystemSet) {
        tSystemSetService.insert(tSystemSet);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除系统设置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tSystemSetId) {
        tSystemSetService.deleteById(tSystemSetId);
//        tSystemSetService.updateById(new TSystemSet(tSystemSetId, 1));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改系统设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TSystemSet tSystemSet) {
        tSystemSetService.updateById(tSystemSet);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改系统设置状态
     */
    @RequestMapping(value = "/updateState")
    @ResponseBody
    public Object updateState(@RequestParam Integer tSystemSetId) {
//        TSystemSet obj = tSystemSetService.selectById(tSystemSetId);
//        if (obj != null) {
//            if(obj.getState() == 0) {
//                obj.setState(1);
//            } else {
//                obj.setState(0);
//            }
//            tSystemSetService.updateById(obj);
//        }
        return SUCCESS_TIP;
    }
 
 
    /**
     * 系统设置详情
     */
    @RequestMapping(value = "/detail/{tSystemSetId}")
    @ResponseBody
    public Object detail(@PathVariable("tSystemSetId") Integer tSystemSetId) {
        return tSystemSetService.selectById(tSystemSetId);
    }
 
}