nickchange
2023-10-16 cf117814b81e7c2cc33913cea14b95d0364d526a
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
package com.dsh.guns.modular.system.controller.code;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.competition.CompetitionClient;
import com.dsh.course.feignClient.competition.model.Competition;
import com.dsh.course.feignClient.competition.model.CompetitionUser;
import com.dsh.course.feignClient.competition.model.GetPeopleQuery;
import com.dsh.course.feignClient.course.CourseClient;
import com.dsh.course.feignClient.course.CoursePackageDiscountClient;
import com.dsh.course.feignClient.course.CoursePackagePaymentConfigClient;
import com.dsh.course.feignClient.course.model.*;
import com.dsh.course.model.AuditDiscount;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.base.tips.ErrorTip;
import com.dsh.guns.core.base.tips.SuccessTip;
import com.dsh.guns.core.common.constant.factory.PageFactory;
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.model.DiscountUpdateState;
import com.dsh.guns.modular.system.model.TCity;
import com.dsh.guns.modular.system.model.TStore;
import com.dsh.guns.modular.system.model.dto.CoursePackage;
import com.dsh.guns.modular.system.service.ICityService;
import com.dsh.guns.modular.system.service.ICoursePackageService;
import com.dsh.guns.modular.system.service.IStoreService;
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.ResponseBody;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 车辆管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-05 17:25:12
 */
@Controller
@RequestMapping("/tDiscount")
public class TDiscountController extends BaseController {
 
    private String PREFIX = "/system/tDiscount/";
    private String PREFIX1 = "/system/tDiscountAudit/";
 
    @Autowired
    private CompetitionClient competitionClient;
 
    @Autowired
    private IStoreService storeService;
 
    @Autowired
    private ICityService cityService;
 
    @Autowired
    private CourseClient courseClient;
 
    /**
     * 跳转到车辆管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        return PREFIX + "TDiscount.html";
    }
    @RequestMapping("/audit")
    public String indexAudit(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        return PREFIX1 + "TDiscount.html";
    }
 
    /**
     * 跳转到添加车辆管理
     */
    @RequestMapping("/tCompetition_add")
    public String tCompetitionAdd(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        return PREFIX + "TCompetition_add.html";
    }
 
 
    /**
     * 跳转到修改车辆管理
     */
    @RequestMapping("/tCompetition_update/{id}")
    public String tCarUpdate(@PathVariable Integer id, Model model) {
        Competition competition = competitionClient.queryById(id);
        model.addAttribute("item",competition);
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getProvinceCode()));
        List<TCity> list1 = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId,one.getId()));
 
        List<TStore> list2 = storeService.list(new LambdaQueryWrapper<TStore>().eq(TStore::getCityCode,competition.getCityCode()));
        model.addAttribute("list",list);
        model.addAttribute("list1",list1);
        model.addAttribute("list2",list2);
        model.addAttribute("type",1);
        return PREFIX + "TCompetition_edit.html";
    }
    @RequestMapping("/tCompetition_info/{id}")
    public String tCarInfo(@PathVariable Integer id, Model model) {
        Competition competition = competitionClient.queryById(id);
        model.addAttribute("item",competition);
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getProvinceCode()));
        List<TCity> list1 = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId,one.getId()));
 
        List<TStore> list2 = storeService.list(new LambdaQueryWrapper<TStore>().eq(TStore::getCityCode,competition.getCityCode()));
        model.addAttribute("list",list);
        model.addAttribute("list1",list1);
        model.addAttribute("list2",list2);
        model.addAttribute("type",2);
 
        return PREFIX + "TCompetition_edit.html";
    }
    @RequestMapping("/tCompetition_user/{id}")
    public String tCarUser(@PathVariable Integer id, Model model) {
        model.addAttribute("id",id);
        return PREFIX + "TCompetitionUser.html";
    }
 
    @Autowired
    private ICoursePackageService coursePackageService;
 
    @Resource
    private CoursePackagePaymentConfigClient coursePackagePaymentConfigClient;
 
    @Resource
    private CoursePackageDiscountClient coursePackageDiscountClient;
    @RequestMapping("/info")
    public String info( Integer id, Model model) {
        TCoursePackage tCoursePackage1 = courseClient.queryByDiscountId(id);
        TCoursePackage tCoursePackage = coursePackageService.queryById(tCoursePackage1.getId());
        model.addAttribute("item", tCoursePackage);
        List<CoursePackagePaymentConfig> list4 = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(id);
        List<Map<String, Object>> list = new ArrayList<>();
        for (CoursePackagePaymentConfig coursePackagePaymentConfig : list4) {
            if(coursePackagePaymentConfig.getCashPayment() == 0){
                continue;
            }
            Map<String, Object> map = new HashMap<>();
            map.put("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId());
            map.put("classHours", coursePackagePaymentConfig.getClassHours());
            String payment = "";
            if(coursePackagePaymentConfig.getCashPayment() > 0){
                payment += "现金支付";
            }
            if(coursePackagePaymentConfig.getPlayPaiCoin() > 0){
                payment += (ToolUtil.isNotEmpty(payment) ? "、" : "") + "玩湃币支付";
            }
            map.put("payment",  payment);
            map.put("cashPayment", coursePackagePaymentConfig.getCashPayment());
            List<TCoursePackageDiscount> tCoursePackageDiscounts = coursePackageDiscountClient.queryCoursePackageDiscount(coursePackagePaymentConfig.getId());
            map.put("coursePackageDiscount", tCoursePackageDiscounts);
            list.add(map);
        }
        model.addAttribute("coursePackagePaymentConfig", JSON.toJSONString(list));
        return PREFIX + "coursePackageDiscount.html";
    }
    @RequestMapping("/infoOne")
    public String infoOne( Integer id, Model model) {
        Integer state = courseClient.queryDiscountById(id);
        if(state==1){
            model.addAttribute("stateStr","待审核");
            model.addAttribute("state",1);
        }else {
            model.addAttribute("stateStr","未通过");
            model.addAttribute("state",3);
        }
 
        TCoursePackage tCoursePackage1 = courseClient.queryByDiscountId(id);
        TCoursePackage tCoursePackage = coursePackageService.queryById(tCoursePackage1.getId());
        model.addAttribute("item", tCoursePackage);
        List<CoursePackagePaymentConfig> list4 = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(id);
        List<Map<String, Object>> list = new ArrayList<>();
        for (CoursePackagePaymentConfig coursePackagePaymentConfig : list4) {
            if(coursePackagePaymentConfig.getCashPayment() == 0){
                continue;
            }
            Map<String, Object> map = new HashMap<>();
            map.put("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId());
            map.put("classHours", coursePackagePaymentConfig.getClassHours());
            String payment = "";
            if(coursePackagePaymentConfig.getCashPayment() > 0){
                payment += "现金支付";
            }
            if(coursePackagePaymentConfig.getPlayPaiCoin() > 0){
                payment += (ToolUtil.isNotEmpty(payment) ? "、" : "") + "玩湃币支付";
            }
            map.put("payment",  payment);
            map.put("cashPayment", coursePackagePaymentConfig.getCashPayment());
            List<TCoursePackageDiscount> tCoursePackageDiscounts = coursePackageDiscountClient.queryCoursePackageDiscountOne(coursePackagePaymentConfig.getId());
            map.put("coursePackageDiscount", tCoursePackageDiscounts);
            list.add(map);
        }
        model.addAttribute("coursePackagePaymentConfig", JSON.toJSONString(list));
        return PREFIX1 + "coursePackageDiscount.html";
    }
 
 
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String provinceCode, String cityCode, String shopName, String name, Integer type) {
        LambdaQueryWrapper<TStore> wrapper = new LambdaQueryWrapper<>();
        if(ToolUtil.isNotEmpty(shopName)){
            wrapper.like(TStore::getName, shopName);
        }
        List<TStore> list = storeService.list(wrapper);
        Page<DiscountList> page = new PageFactory<DiscountList>().defaultPage();
        List<DiscountList> discountLists = courseClient.queryDiscountList(new QueryDiscountList(page.getCurrent(),page.getSize(),provinceCode,cityCode,name,type,list.stream().map(TStore::getId).collect(Collectors.toList())));
        for (DiscountList discountList : discountLists) {
            for (TStore tStore : list) {
                if(discountList.getStoreId().equals(tStore.getId())){
                    discountList.setShopName(tStore.getName());
                }
            }
        }
        page.setRecords(discountLists);
        return  super.packForBT(page);
    }
    @RequestMapping(value = "/listAudit")
    @ResponseBody
    public Object listAudit(String provinceCode, String cityCode, String shopName, String name, Integer type) {
        LambdaQueryWrapper<TStore> wrapper = new LambdaQueryWrapper<>();
        if(ToolUtil.isNotEmpty(shopName)){
            wrapper.like(TStore::getName, shopName);
        }
        List<TStore> list = storeService.list(wrapper);
        Page<DiscountList> page = new PageFactory<DiscountList>().defaultPage();
        List<DiscountList> discountLists = courseClient.queryDiscountListAudit(new QueryDiscountList(page.getCurrent(),page.getSize(),provinceCode,cityCode,name,type,list.stream().map(TStore::getId).collect(Collectors.toList())));
        for (DiscountList discountList : discountLists) {
            for (TStore tStore : list) {
                if(discountList.getStoreId().equals(tStore.getId())){
                    discountList.setShopName(tStore.getName());
                }
            }
        }
        page.setRecords(discountLists);
        return  super.packForBT(page);
    }
 
 
    @RequestMapping(value = "/updateState")
    @ResponseBody
    public Object updateState( Integer id,Integer status) {
        try {
            Boolean b = courseClient.updateState(new DiscountUpdateState(id,status));
            if(b){
                return new SuccessTip<>();
            }
            return  new ErrorTip(500,"");
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
    @RequestMapping(value = "/auditDiscount")
    @ResponseBody
    public Object auditDiscount(Integer id,Integer audit,String text) {
        try {
            Boolean b = courseClient.auditDiscount(new AuditDiscount(id,audit,text));
            if(b){
                return new SuccessTip<>();
            }
            return  new ErrorTip(500,"");
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
 
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object list(Competition competition) {
        try {
            if(ToolUtil.isNotEmpty(competition.getProvinceCode())) {
                TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getProvinceCode()));
                competition.setProvince(one.getName());
                TCity one1 = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getCityCode()));
                competition.setCity(one1.getName());
            }
            competition.setAuditStatus(1);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            competition.setStartTime(format.parse(competition.getSTime()));
            competition.setEndTime(format.parse(competition.getETime()));
            competition.setRegisterEndTime(format.parse(competition.getREndTime()));
            competitionClient.add(competition);
            return new SuccessTip<>();
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Competition competition) {
        try {
            Competition competition1 = competitionClient.queryById(competition.getId());
            if(ToolUtil.isNotEmpty(competition.getProvinceCode())) {
                TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getProvinceCode()));
                competition.setProvince(one.getName());
                TCity one1 = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, competition.getCityCode()));
                competition.setCity(one1.getName());
            }
            if(ToolUtil.isEmpty(competition.getCoverDrawing())){
                competition.setCoverDrawing(competition1.getCoverDrawing());
            }
            if(ToolUtil.isEmpty(competition.getRegistrationNotes())){
                competition.setRegistrationNotes(competition1.getRegistrationNotes());
            }
            competitionClient.update(competition);
            return new SuccessTip<>();
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
 
    @RequestMapping(value = "/cancel")
    public Object cancel(Integer id) {
        try {
            competitionClient.cancel(id);
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
    @RequestMapping(value = "/getPeopleFromId")
    public Object getPeopleFromId(Integer id,Integer state) {
        try {
            Page<Object> page = new PageFactory<>().defaultPage();
            Page<CompetitionUser> data =   competitionClient.getPeopleFromId(new GetPeopleQuery(page.getSize(),page.getCurrent(),id,state));
            return  super.packForBT(data);
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
    @RequestMapping(value = "/onChange")
    @ResponseBody
    public Object onChange(Integer oneId) {
        try {
            TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, oneId));
            return cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId,one.getId()));
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
    @RequestMapping(value = "/oneChangeNext")
    @ResponseBody
    public Object oneChangeNext(Integer oneId) {
        try {
            return storeService.list(new LambdaQueryWrapper<TStore>().eq(TStore::getCityCode, oneId));
        }catch (Exception e){
            e.printStackTrace();
            return ERROR;
        }
    }
 
 
}