puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
package com.dsh.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsh.course.feignClient.activity.DriverActivityClient;
import com.dsh.course.feignClient.driver.DriverClient;
import com.dsh.course.feignClient.driver.model.DriverInfoRes;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.base.tips.SuccessTip;
import com.dsh.guns.core.exception.ServiceException;
import com.dsh.guns.core.log.LogObjectHolder;
import com.dsh.guns.core.util.SinataUtil;
import com.dsh.guns.modular.system.enums.ActivityTypeEnum;
import com.dsh.guns.modular.system.enums.RuleStatusEnum;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.service.*;
import com.dsh.guns.modular.system.util.DateUtil;
import com.dsh.guns.modular.system.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
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.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-04-20 10:57:51
 */
@Controller
@RequestMapping("/tEnsureIncomeRule")
public class TEnsureIncomeRuleController extends BaseController {
 
    private String PREFIX = "/system/tEnsureIncomeRule/";
 
    @Autowired
    private ITEnsureIncomeRuleService tEnsureIncomeRuleService;
    @Autowired
    private ITEnsureIncomeFoundationService tEnsureIncomeFoundationService;
    @Autowired
    private ITEnsureIncomeSpecialService tEnsureIncomeSpecialService;
    @Autowired
    private ITEnsureIncomeSpecialTimeSoltService tEnsureIncomeSpecialTimeSoltService;
    @Autowired
    private DriverActivityClient driverActivityClient;
    @Autowired
    private DriverClient driverClient;
    @Autowired
    private ITAuditRecordService auditRecordService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tEnsureIncomeRule.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tEnsureIncomeRule_add")
    public String tEnsureIncomeRuleAdd(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tEnsureIncomeRule_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tEnsureIncomeRule_update/{tEnsureIncomeRuleId}")
    public String tEnsureIncomeRuleUpdate(@PathVariable Integer tEnsureIncomeRuleId, Model model) {
        TEnsureIncomeRule tEnsureIncomeRule = tEnsureIncomeRuleService.getById(tEnsureIncomeRuleId);
        model.addAttribute("item",tEnsureIncomeRule);
        LogObjectHolder.me().set(tEnsureIncomeRule);
        return PREFIX + "tEnsureIncomeRule_edit.html";
    }
 
    /**
     * 跳转到立即处理页面
     */
    @RequestMapping("/tEnsureIncomeRule_immediately/{id}")
    public String sysCouponActivityImmediately(@PathVariable Integer id, Model model) {
        model.addAttribute("id",id);
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tEnsureIncomeRule_immediately.html";
    }
 
    /**
     * 立即处理操作
     */
    @RequestMapping(value = "/immediately")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
        TEnsureIncomeRule tEnsureIncomeRule = tEnsureIncomeRuleService.getById(id);
        if (SinataUtil.isNotEmpty(tEnsureIncomeRule)){
            tEnsureIncomeRule.setState(state);
            tEnsureIncomeRule.setRemark(remark);
 
            if(state == 3){
                if(LocalDateTime.now().isBefore(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime()))){
                    tEnsureIncomeRule.setStatus(RuleStatusEnum.NOT_START.getCode());
                }
                if(LocalDateTime.now().isAfter(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime())) && LocalDateTime.now().isBefore(TimeUtil.getDayEnd(tEnsureIncomeRule.getEndTime()))){
                    tEnsureIncomeRule.setStatus(RuleStatusEnum.STARTED.getCode());
                }
            }
 
            tEnsureIncomeRuleService.updateById(tEnsureIncomeRule);
 
            // 添加审核记录
            TAuditRecord tAuditRecord = new TAuditRecord();
            tAuditRecord.setActivityId(id);
            tAuditRecord.setActivityName(tEnsureIncomeRule.getRuleName());
            if(state == 2){
                tAuditRecord.setAuditStatus(3);
            }
            if(state == 3){
                tAuditRecord.setAuditStatus(2);
            }
            tAuditRecord.setAuditTime(new Date());
            tAuditRecord.setAuditUserId(Objects.requireNonNull(UserExt.getUser()).getId());
            tAuditRecord.setRemark(remark);
            tAuditRecord.setActivityType(ActivityTypeEnum.INCOME_RULE.getCode());
            auditRecordService.save(tAuditRecord);
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转到详情
     */
    @RequestMapping("/tEnsureIncomeRuleDetail/{tEnsureIncomeRuleId}")
    public String tEnsureIncomeRuleDetail(@PathVariable Integer tEnsureIncomeRuleId, Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        model.addAttribute("tEnsureIncomeRuleId", tEnsureIncomeRuleId);
        TEnsureIncomeRule tEnsureIncomeRule = tEnsureIncomeRuleService.getById(tEnsureIncomeRuleId);
        tEnsureIncomeRule.setExpireTime(tEnsureIncomeRule.getStartTime().toLocalDate() + "-" +tEnsureIncomeRule.getEndTime().toLocalDate());
        model.addAttribute("item",tEnsureIncomeRule);
        LogObjectHolder.me().set(tEnsureIncomeRule);
        // 查询基础时间段配置
        List<TEnsureIncomeFoundation> foundationList = tEnsureIncomeFoundationService.list(Wrappers.lambdaQuery(TEnsureIncomeFoundation.class)
                .eq(TEnsureIncomeFoundation::getEnsureIncomeId, tEnsureIncomeRuleId));
        model.addAttribute("foundationList",foundationList);
        // 查询特殊时间段配置
        List<TEnsureIncomeSpecial> specialList = tEnsureIncomeSpecialService.list(Wrappers.lambdaQuery(TEnsureIncomeSpecial.class)
                .eq(TEnsureIncomeSpecial::getEnsureIncomeId, tEnsureIncomeRuleId));
        for (TEnsureIncomeSpecial tEnsureIncomeSpecial : specialList) {
            tEnsureIncomeSpecial.setStartTimeString(new SimpleDateFormat("yyyy-MM-dd").format(tEnsureIncomeSpecial.getStartTime()));
            List<TEnsureIncomeSpecialTimeSolt> specialTimeSoltList = tEnsureIncomeSpecialTimeSoltService.list(Wrappers.lambdaQuery(TEnsureIncomeSpecialTimeSolt.class)
                    .eq(TEnsureIncomeSpecialTimeSolt::getEnsureIncomeSpecialId, tEnsureIncomeSpecial.getId()));
            tEnsureIncomeSpecial.setSpecialTimeSoltList(specialTimeSoltList);
        }
        model.addAttribute("specialList",specialList);
        return PREFIX + "tEnsureIncomeRuleDetail.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String ruleName,String createTime) {
        LambdaQueryWrapper<TEnsureIncomeRule> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.hasLength(ruleName)){
            wrapper.like(TEnsureIncomeRule::getRuleName,ruleName);
        }
        Date startTimes = null;
        Date endTimes = null;
        if (StringUtils.hasLength(createTime)){
            String[] timeArray = createTime.split(" - ");
            startTimes = DateUtil.getDate_str3(timeArray[0]+" 00:00:00");
            endTimes = DateUtil.getDate_str3(timeArray[1]+" 23:59:59");
            wrapper.between(TEnsureIncomeRule::getCreateTime,startTimes,endTimes);
        }
        Integer objectId = Objects.requireNonNull(UserExt.getUser()).getObjectId();
        if(objectId != 1){
            wrapper.eq(TEnsureIncomeRule::getCompanyId, Objects.requireNonNull(UserExt.getUser()).getObjectId());
        }
        wrapper.orderByDesc(TEnsureIncomeRule::getCreateTime);
        List<TEnsureIncomeRule> list = tEnsureIncomeRuleService.list(wrapper);
        for (TEnsureIncomeRule tEnsureIncomeRule : list) {
            tEnsureIncomeRule.setExpireTime(tEnsureIncomeRule.getStartTime().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))
                                            + "-" + tEnsureIncomeRule.getEndTime().format(DateTimeFormatter.ofPattern("yyyy.MM.dd")));
            // 计算参与人次
            Integer count = driverActivityClient.queryJoinCount(tEnsureIncomeRule.getId());
            tEnsureIncomeRule.setJoinCount(count);
        }
        return list;
    }
 
    /**
     * 获取司机保底收入列表
     */
    @RequestMapping(value = "/incomeList")
    @ResponseBody
    public Object incomeList(Integer tEnsureIncomeRuleId) {
        if(Objects.isNull(tEnsureIncomeRuleId)){
            return null;
        }
        List<Map<String, Object>> list = driverActivityClient.queryDriverIncomeMoney(tEnsureIncomeRuleId);
        for (Map<String, Object> map : list) {
            DriverInfoRes driver = driverClient.getDriver(Integer.valueOf(String.valueOf(map.get("driverId"))));
            map.put("driverName",driver.getName());
            map.put("driverPhone",driver.getPhone());
        }
        return list;
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public Object add(TEnsureIncomeRule tEnsureIncomeRule,String incomeFoundation,String incomeSpecial){
        Integer language = UserExt.getLanguage();
        if(Objects.isNull(language)){
            language = 1;
        }
 
        int count = tEnsureIncomeRuleService.count(Wrappers.lambdaQuery(TEnsureIncomeRule.class)
                .eq(TEnsureIncomeRule::getRuleName, tEnsureIncomeRule.getRuleName()));
        if(count > 0){
            if(1 == language){
                throw new ServiceException(500,"该活动名称已存在!");
            }
            if(2 == language){
                throw new ServiceException(500,"The activity name already exists!");
            }
            if(3 == language){
                throw new ServiceException(500,"Nama aktivitas sudah ada!");
            }
        }
 
        tEnsureIncomeRule.setStartTime(TimeUtil.getDayStart(TimeUtil.getLocalDateTime(tEnsureIncomeRule.getStartTimeString())));
        Date date_str3 = new Date();
        try {
            Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(tEnsureIncomeRule.getEndTimeString());
            Map<String, Date> monthDate = TimeUtil.getMonthDate(parse);
            Date last = monthDate.get("last");
            String format = new SimpleDateFormat("yyyy-MM-dd").format(last);
            date_str3 = DateUtil.getDate_str3(format + " 23:59:59");
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        tEnsureIncomeRule.setEndTime(TimeUtil.dateToLocalDateTime(date_str3));
 
        tEnsureIncomeRule.setCreateTime(LocalDateTime.now());
 
//        if(LocalDateTime.now().isBefore(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime()))){
//            tEnsureIncomeRule.setStatus(RuleStatusEnum.NOT_START.getCode());
//        }
//        if(LocalDateTime.now().isAfter(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime())) && LocalDateTime.now().isBefore(TimeUtil.getDayEnd(tEnsureIncomeRule.getEndTime()))){
//            tEnsureIncomeRule.setStatus(RuleStatusEnum.STARTED.getCode());
//        }
        if(LocalDateTime.now().isAfter(TimeUtil.getDayEnd(tEnsureIncomeRule.getEndTime()))){
            if(1 == language){
                throw new ServiceException(500,"有效期无效,请选择正确的有效期!");
            }
            if(2 == language){
                throw new ServiceException(500,"The validity period is invalid. Please select the correct validity period!");
            }
            if(3 == language){
                throw new ServiceException(500,"Periode validitas tidak valid. Please select the correct validity period!");
            }
        }
        tEnsureIncomeRule.setCompanyId(UserExt.getUser().getObjectId());
        // 活动主数据
        tEnsureIncomeRuleService.save(tEnsureIncomeRule);
 
        // 活动基础时间配置
        JSONArray jsonArray = JSONObject.parseArray(incomeFoundation);
        List<TEnsureIncomeFoundation> foundationList = new ArrayList<>();
        Map<String,String> incomeMap = new HashMap<>();
        Map<String,LocalTime> incomeTimeMap = new HashMap<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            String startTime1 = jsonArray.getJSONObject(i).getString("startTime");
            String endTime1 = jsonArray.getJSONObject(i).getString("endTime");
            String startTime = incomeMap.get(startTime1);
            String endTime = incomeMap.get(endTime1);
 
            if(StringUtils.hasLength(startTime) && StringUtils.hasLength(endTime)){
                if(1 == language){
                    throw new ServiceException(500,"基础时间段配置存在重复时间段!");
                }
                if(2 == language){
                    throw new ServiceException(500,"There are duplicate time periods in the basic time period configuration!");
                }
                if(3 == language){
                    throw new ServiceException(500,"Ada periode waktu duplikasi dalam konfigurasi periode waktu dasar!");
                }
            }
 
            LocalTime localStart= LocalTime.parse(startTime1+":00");
            LocalTime localEnd= LocalTime.parse(endTime1+":00");
            for (int j = 0; j < incomeTimeMap.entrySet().size(); j++) {
                LocalTime localStartTime = incomeTimeMap.get("startTime" + j);
                LocalTime localEndTime = incomeTimeMap.get("endTime" + j);
                if(Objects.nonNull(localStartTime) && Objects.nonNull(localEndTime)){
                    if((localStart.isAfter(localStartTime) && localStart.isBefore(localEndTime))
                    || (localEnd.isAfter(localStartTime) && localEnd.isBefore(localEndTime))
                    || (localStart.isAfter(localStartTime) && localEnd.isBefore(localEndTime))
                    || (localStart.isBefore(localStartTime) && localEnd.isAfter(localEndTime))
                    || (localStart.compareTo(localStartTime) == 0)
                    || (localEnd.compareTo(localEndTime) == 0)){
                        if(1 == language){
                            throw new ServiceException(500,"基础时间段配置存在重合时间段!");
                        }
                        if(2 == language){
                            throw new ServiceException(500,"The basic time period configuration has overlapping time periods!");
                        }
                        if(3 == language){
                            throw new ServiceException(500,"Konfigurasi peristiwa waktu dasar memiliki peristiwa waktu yang meliputi!");
                        }
                    }
                }
            }
 
            TEnsureIncomeFoundation tEnsureIncomeFoundation = new TEnsureIncomeFoundation();
            tEnsureIncomeFoundation.setEnsureIncomeId(tEnsureIncomeRule.getId());
            tEnsureIncomeFoundation.setCreateTime(new Date());
            tEnsureIncomeFoundation.setStartTime(jsonArray.getJSONObject(i).getString("startTime"));
            tEnsureIncomeFoundation.setEndTime(jsonArray.getJSONObject(i).getString("endTime"));
            tEnsureIncomeFoundation.setAmount(jsonArray.getJSONObject(i).getBigDecimal("amount"));
            tEnsureIncomeFoundation.setOnLineTime(jsonArray.getJSONObject(i).getInteger("onLineTime"));
            foundationList.add(tEnsureIncomeFoundation);
 
            incomeMap.put(jsonArray.getJSONObject(i).getString("startTime"),jsonArray.getJSONObject(i).getString("startTime"));
            incomeMap.put(jsonArray.getJSONObject(i).getString("endTime"),jsonArray.getJSONObject(i).getString("endTime"));
            incomeTimeMap.put("startTime"+i,localStart);
            incomeTimeMap.put("endTime"+i,localEnd);
        }
        tEnsureIncomeFoundationService.saveBatch(foundationList);
 
        // 活动特殊时间配置
        if(StringUtils.hasLength(incomeSpecial)){
            JSONArray jsonArray1 = JSONObject.parseArray(incomeSpecial);
            Map<String,String> specialMap = new HashMap<>();
            for (int i = 0; i < jsonArray1.size(); i++) {
                String dayTime = specialMap.get(jsonArray1.getJSONObject(i).getString("dayTime"));
                if(StringUtils.hasLength(dayTime)){
                    if(1 == language){
                        throw new ServiceException(500,"特殊时间段基础配置存在重复日期!");
                    }
                    if(2 == language){
                        throw new ServiceException(500,"Special time period basic configuration has duplicate dates!");
                    }
                    if(3 == language){
                        throw new ServiceException(500,"Konfigurasi dasar periode waktu khusus memiliki tanggal duplikasi!");
                    }
                }
 
                TEnsureIncomeSpecial tEnsureIncomeSpecial = new TEnsureIncomeSpecial();
                tEnsureIncomeSpecial.setEnsureIncomeId(tEnsureIncomeRule.getId());
                tEnsureIncomeSpecial.setCreateTime(new Date());
                tEnsureIncomeSpecial.setStartTime(DateUtil.parse(jsonArray1.getJSONObject(i).getString("dayTime"),"yyyy-MM-dd"));
                tEnsureIncomeSpecial.setPeriodDayAmount(jsonArray1.getJSONObject(i).getBigDecimal("periodDaySpecialAmount"));
                tEnsureIncomeSpecialService.save(tEnsureIncomeSpecial);
 
                JSONArray incomeSpecialTimeArr = jsonArray1.getJSONObject(i).getJSONArray("incomeSpecialTimeArr");
                List<TEnsureIncomeSpecialTimeSolt> specialTimeSoltList = new ArrayList<>(incomeSpecialTimeArr.size());
                Map<String,String> specialSoltMap = new HashMap<>();
                Map<String,LocalTime> incomeTimeSpecialMap = new HashMap<>();
                for (int j = 0; j < incomeSpecialTimeArr.size(); j++) {
                    String startSpecialTime1 = incomeSpecialTimeArr.getJSONObject(j).getString("startSpecialTime");
                    String endSpecialTime1 = incomeSpecialTimeArr.getJSONObject(j).getString("endSpecialTime");
                    String startSpecialTime = specialSoltMap.get(startSpecialTime1);
                    String endSpecialTime = specialSoltMap.get(endSpecialTime1);
                    if(StringUtils.hasLength(startSpecialTime) && StringUtils.hasLength(endSpecialTime)){
                        if(1 == language){
                            throw new ServiceException(500,"特殊时间段日期为-"+jsonArray1.getJSONObject(i).getString("dayTime")+"-存在重复时间段!");
                        }
                        if(2 == language){
                            throw new ServiceException(500,"Special time period dates are-"+jsonArray1.getJSONObject(i).getString("dayTime")+"-There are duplicate time periods!");
                        }
                        if(3 == language){
                            throw new ServiceException(500,"Tanggal periode waktu khusus adalah-"+jsonArray1.getJSONObject(i).getString("dayTime")+"-Ada periode waktu duplikasi!");
                        }
                    }
 
                    LocalTime localStart= LocalTime.parse(startSpecialTime1+":00");
                    LocalTime localEnd= LocalTime.parse(endSpecialTime1+":00");
                    for (int a = 0; a < incomeTimeSpecialMap.entrySet().size(); a++) {
                        LocalTime localStartTime = incomeTimeSpecialMap.get("startSpecialTime" + a);
                        LocalTime localEndTime = incomeTimeSpecialMap.get("endSpecialTime" + a);
                        if(Objects.nonNull(localStartTime) && Objects.nonNull(localEndTime)){
                            if((localStart.isAfter(localStartTime) && localStart.isBefore(localEndTime))
                                    || (localEnd.isAfter(localStartTime) && localEnd.isBefore(localEndTime))
                                    || (localStart.isAfter(localStartTime) && localEnd.isBefore(localEndTime))
                                    || (localStart.isBefore(localStartTime) && localEnd.isAfter(localEndTime))
                                    || (localStart.compareTo(localStartTime) == 0)
                                    || (localEnd.compareTo(localEndTime) == 0)){
                                if(1 == language){
                                    throw new ServiceException(500,"特殊时间段配置存在重合时间段!");
                                }
                                if(2 == language){
                                    throw new ServiceException(500,"Special time period configuration with overlapping time periods!");
                                }
                                if(3 == language){
                                    throw new ServiceException(500,"Konfigurasi peristiwa waktu khusus dengan peristiwa waktu yang saling bertindak!");
                                }
                            }
                        }
                    }
 
                    incomeTimeSpecialMap.put("startSpecialTime"+j,localStart);
                    incomeTimeSpecialMap.put("endSpecialTime"+j,localEnd);
 
                    TEnsureIncomeSpecialTimeSolt specialTimeSolt = new TEnsureIncomeSpecialTimeSolt();
                    specialTimeSolt.setEnsureIncomeSpecialId(tEnsureIncomeSpecial.getId());
                    specialTimeSolt.setCreateTime(new Date());
                    specialTimeSolt.setStartTime(incomeSpecialTimeArr.getJSONObject(j).getString("startSpecialTime"));
                    specialTimeSolt.setEndTime(incomeSpecialTimeArr.getJSONObject(j).getString("endSpecialTime"));
                    specialTimeSolt.setAmount(incomeSpecialTimeArr.getJSONObject(j).getBigDecimal("specialAmount"));
                    specialTimeSolt.setOnLineTime(incomeSpecialTimeArr.getJSONObject(j).getInteger("specialOnLineTime"));
                    specialTimeSoltList.add(specialTimeSolt);
 
                    specialSoltMap.put(incomeSpecialTimeArr.getJSONObject(j).getString("startSpecialTime"),incomeSpecialTimeArr.getJSONObject(j).getString("startSpecialTime"));
                    specialSoltMap.put(incomeSpecialTimeArr.getJSONObject(j).getString("endSpecialTime"),incomeSpecialTimeArr.getJSONObject(j).getString("endSpecialTime"));
                }
                specialMap.put(jsonArray1.getJSONObject(i).getString("dayTime"),jsonArray1.getJSONObject(i).getString("dayTime"));
                tEnsureIncomeSpecialTimeSoltService.saveBatch(specialTimeSoltList);
            }
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tEnsureIncomeRuleId) {
        tEnsureIncomeRuleService.removeById(tEnsureIncomeRuleId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TEnsureIncomeRule tEnsureIncomeRule) {
        tEnsureIncomeRuleService.updateById(tEnsureIncomeRule);
        return SUCCESS_TIP;
    }
 
    /**
     * 暂停,开启
     */
    @RequestMapping(value = "/stopOrStart")
    @ResponseBody
    public Object stopOrStart(@RequestParam Integer tEnsureIncomeRuleId) {
        Integer language = UserExt.getLanguage();
        if(Objects.isNull(language)){
            language = 1;
        }
        TEnsureIncomeRule tEnsureIncomeRule = tEnsureIncomeRuleService.getById(tEnsureIncomeRuleId);
        if(tEnsureIncomeRule.getState() == 1){
            if(1==language){
                return new SuccessTip(500,"请先审核该数据!");
            }
            if(2==language){
                return new SuccessTip(500,"Please review the data first!");
            }
            if(3==language){
                return new SuccessTip(500,"Please review the data first!");
            }
        }
        if(RuleStatusEnum.PAUSED.getCode() != tEnsureIncomeRule.getStatus()){
            // 不是暂停中的状态,点击按钮变为暂停中的状态
            tEnsureIncomeRule.setStatus(RuleStatusEnum.PAUSED.getCode());
            tEnsureIncomeRuleService.updateById(tEnsureIncomeRule);
            return SUCCESS_TIP;
        }
        if(RuleStatusEnum.PAUSED.getCode() == tEnsureIncomeRule.getStatus()){
            // 是暂停中的状态,判断单签时间是否在有效期内已开始
            if(LocalDateTime.now().isBefore(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime()))){
                tEnsureIncomeRule.setStatus(RuleStatusEnum.NOT_START.getCode());
            }
            if(LocalDateTime.now().isAfter(TimeUtil.getDayStart(tEnsureIncomeRule.getStartTime())) && LocalDateTime.now().isBefore(TimeUtil.getDayEnd(tEnsureIncomeRule.getEndTime()))){
                tEnsureIncomeRule.setStatus(RuleStatusEnum.STARTED.getCode());
            }
            if(LocalDateTime.now().isAfter(TimeUtil.getDayEnd(tEnsureIncomeRule.getEndTime()))){
                return new SuccessTip(500,"已结束活动不可开启!");
            }
            tEnsureIncomeRuleService.updateById(tEnsureIncomeRule);
            return SUCCESS_TIP;
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tEnsureIncomeRuleId}")
    @ResponseBody
    public Object detail(@PathVariable("tEnsureIncomeRuleId") Integer tEnsureIncomeRuleId) {
        return tEnsureIncomeRuleService.getById(tEnsureIncomeRuleId);
    }
}