44323
2023-11-27 aa45df63fa01b2f010560e4157f00bec5150a1fb
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
package com.dsh.guns.modular.system.controller.code;
 
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.competition.model.ListQuery;
import com.dsh.guns.core.base.controller.BaseController;
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.TCity;
import com.dsh.guns.modular.system.model.TStore;
import com.dsh.guns.modular.system.service.ICityService;
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 java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 车辆管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-05 17:25:12
 */
@Controller
@RequestMapping("/tCompetitionAudit")
public class TCompetitionAuditController extends BaseController {
 
    private String PREFIX = "/system/tCompetitionAudit/";
 
    @Autowired
    private CompetitionClient competitionClient;
 
    @Autowired
    private IStoreService storeService;
 
    @Autowired
    private ICityService cityService;
 
 
 
 
    /**
     * 跳转到车辆管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        return PREFIX + "TCompetition.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()));
        String[] split = competition.getImgs().split(",");
        ArrayList<String> strings = new ArrayList<>();
        for (String s : split) {
            strings.add(s);
        }
        // 现金
        model.addAttribute("m1",list);
        // 玩湃币
        model.addAttribute("m2",list);
        // 课时
        model.addAttribute("m3",list);
        model.addAttribute("state",competition.getAuditStatus());
        model.addAttribute("list",list);
        model.addAttribute("list1",list1);
        model.addAttribute("list2",list2);
        model.addAttribute("imgs",strings);
        model.addAttribute("type",2);
        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";
    }
 
 
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String provinceCode, String cityCode, String shopName, String eventName, String time, Integer state, Integer registerCondition) {
        List<Integer> ids = new ArrayList<>();
        List<TStore> list = null;
        // 获取门店id
        if(ToolUtil.isNotEmpty(shopName)){
             list = storeService.list(new LambdaQueryWrapper<TStore>().like(TStore::getName, shopName));
            ids = list.stream().map(TStore::getId).collect(Collectors.toList());
        }else {
            list = storeService.list();
            ids = storeService.list().stream().map(TStore::getId).collect(Collectors.toList());
        }
        if(ids.size()==0){
            ids.add(-1);
        }
        Page<Competition> page = new PageFactory<Competition>().defaultPage();
        ListQuery listQuery = new ListQuery(page.getSize(),page.getCurrent(),provinceCode,cityCode,eventName,time,state,registerCondition,ids,0);
        Page<Competition> competitions = competitionClient.listAudit(listQuery);
        for (Competition competition : competitions.getRecords()) {
            for (TStore tStore : list) {
                String[] split = competition.getStoreId().split(",");
 
                for (String s : split) {
                    if(s.equals(String.valueOf(tStore.getId()))){
                        if (competition.getStoreName()==null){
                        competition.setStoreName(tStore.getName());
                        }else {
                            competition.setStoreName(competition.getStoreName()+","+tStore.getName());
                        }
                    }
                }
 
            }
        }
        return  super.packForBT(competitions);
    }
 
 
    @RequestMapping(value = "/listUser/{id}")
    @ResponseBody
    public Object listUser(@PathVariable 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 = "/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 = "/audit")
    @ResponseBody
    public Object cancel(Integer id,Integer audit,String text) {
        try {
            Competition competition = competitionClient.queryById(id);
            competition.setAuditStatus(audit);
            competition.setAuditRemark(text);
            competitionClient.update(competition);
            return new SuccessTip<>();
        }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;
        }
    }
 
 
}