nickchange
2023-10-13 f87aa54781ea269e6be1f74d013c18f5091a8c80
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
package com.dsh.guns.modular.system.controller.code;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.account.AppUserClient;
import com.dsh.course.feignClient.account.CityManagerClient;
import com.dsh.course.feignClient.account.StoreStaffClient;
import com.dsh.course.feignClient.account.model.CityManager;
import com.dsh.course.feignClient.account.model.QueryByNamePhone;
import com.dsh.course.feignClient.account.model.TAppUser;
import com.dsh.course.feignClient.account.model.TStoreStaff;
import com.dsh.course.feignClient.activity.CouponClient;
import com.dsh.course.feignClient.activity.PointMercharsClient;
import com.dsh.course.feignClient.activity.model.*;
import com.dsh.guns.config.UserExt;
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.*;
import com.dsh.guns.modular.system.service.ICityService;
import com.dsh.guns.modular.system.service.IRegionService;
import com.dsh.guns.modular.system.service.IStoreService;
import com.dsh.guns.modular.system.util.OBSUploadUtil;
import com.dsh.guns.modular.system.util.ResultUtil;
import net.bytebuddy.asm.Advice;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
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;
 
 
/**
 * 优惠券管理 控制器
 */
 
@Controller
@RequestMapping("/ticket")
public class TicketController {
    private String PREFIX = "/system/ticket/";
    @Resource
    private IRegionService regiService;
    @Resource
    private IStoreService storeService;
 
    @Resource
    private CouponClient client;
 
    @Resource
    private CityManagerClient cmgrClient;
 
    @Autowired
    private AppUserClient appUserClient;
    @Autowired
    private ICityService cityService;
 
    @Resource
    private PointMercharsClient pointMercharsClient;
    @Autowired
    private StoreStaffClient storeStaffClient;
 
    /**
     * 跳转到优惠券管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        return PREFIX + "ticket.html";
    }
    /**
     * 跳转到添加
     */
    @RequestMapping("/add")
    public String add(Model model) {
        Integer objectType = UserExt.getUser().getObjectType();
        System.out.println(objectType);
        model.addAttribute("userType",objectType);
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        return PREFIX + "ticket_add.html";
    }
 
    @RequestMapping("/info/{id}")
    public String info(@PathVariable Integer id,Model model) {
        Coupon coupon = client.queryCouponById(id);
        model.addAttribute("id",id);
        model.addAttribute("type",coupon.getType());
        return PREFIX + "ticket_info.html";
    }
 
    /**
     *
     * @param id
     * @param model
     * @param type = 1 编辑 type=2 查看详情
     * @return
     */
    @RequestMapping("/update/{id}/{type}")
    public String update(@PathVariable("id") Integer id,Model model,@PathVariable("type")Integer type) {
        model.addAttribute("id",id);
        model.addAttribute("type",type);
        return PREFIX + "ticket_edit.html";
    }
 
    /**
     *  1为上架 2为下架
     *
     * @return
     */
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(@RequestBody CoachChangeStateVO vo){
        pointMercharsClient.changeState(vo);
        return ResultUtil.success();
    }
    /**
     * 获取门票列表
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public Object listAll(String name,Integer type,Integer redemptionMethod,
                          Integer userPopulation,Integer activeStatus,Integer state) {
        Page<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
        IntegralGoodsOfSearch integralGoodsOfSearch = new IntegralGoodsOfSearch();
        integralGoodsOfSearch.setName(name);
        integralGoodsOfSearch.setType(type);
        integralGoodsOfSearch.setRedemptionMethod(redemptionMethod);
        integralGoodsOfSearch.setUserPopulation(userPopulation);
        integralGoodsOfSearch.setActiveStatus(activeStatus);
        integralGoodsOfSearch.setState(state);
        integralGoodsOfSearch.setPage(page);
        return pointMercharsClient.ticketList(integralGoodsOfSearch);
    }
 
 
 
 
    /**
     * 跳转到门店管理列表页
     */
    @RequestMapping("/storeList")
    public String storePage(Model model) {
        return PREFIX + "TStoreList.html";
    }
    @RequestMapping("/updateType")
    @ResponseBody
    public Object updateType(Long id) {
        client.updateType(id);
        return new SuccessTip<>();
    }
 
    @RequestMapping("/storeDetailsOfSearch")
    @ResponseBody
    public Object listOfStore(Integer provinceId,Integer cityId,Integer cityManagerId,String storeName){
        System.out.println("provinceId"+provinceId);
        System.out.println("cityId"+cityId);
        System.out.println("cityManagerId"+cityManagerId);
        System.out.println("storeName"+storeName);
        String provinceCode = null;
        String cityCode = null;
        if (ToolUtil.isNotEmpty(provinceId)){
            Region provinceRegion = regiService.getById(provinceId);
            provinceCode = provinceRegion.getCode();
        }
        if (ToolUtil.isNotEmpty(cityId)){
            Region cityRegion = regiService.getById(cityId);
            cityCode = cityRegion.getCode();
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<Map<String,Object>> storeList = storeService.queryListOfpage(provinceCode,cityCode,cityManagerId,storeName,page);
        if (storeList.size() > 0 ){
            for (Map<String, Object> stringObjectMap : storeList) {
                String provinceName = (String) stringObjectMap.get("province");
                String cityName = (String) stringObjectMap.get("city");
                stringObjectMap.put("provinceCity",provinceName+cityName);
                Integer managerId = (Integer) stringObjectMap.get("cityManagerId");
                CityManager cityManager = cmgrClient.queryCityManagerById(managerId);
                if (ToolUtil.isNotEmpty(cityManager)){
                    stringObjectMap.put("accountName",cityManager.getName()+"+"+cityManager.getPhone());
                }
            }
        }
        return storeList;
    }
 
    @RequestMapping(value = "/listRecord")
    @ResponseBody
    public Object listRecord(Integer id,String name, Integer type, String phone) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        List<TAppUser> tAppUsers = appUserClient.queryByNamePhone(new QueryByNamePhone(name, phone));
        if(tAppUsers.size()==0){
            return new ArrayList<>();
        }
        CouponRecordQuery ofSearch = new CouponRecordQuery();
        ofSearch.setId(id);
        ofSearch.setLimit(page.getSize());
        ofSearch.setOffset(page.getCurrent());
        ofSearch.setIds(tAppUsers.stream().map(TAppUser::getId).collect(Collectors.toList()));
        ofSearch.setType(type);
        List<Map<String, Object>> maps = client.listRecord(ofSearch);
        for (Map<String, Object> map : maps) {
            map.put("id",map.get("id").toString());
            for (TAppUser tAppUser : tAppUsers) {
                if(map.get("userId").equals(tAppUser.getId())){
                    map.put("name",tAppUser.getName());
                    map.put("phone",tAppUser.getPhone());
                }
            }
        }
        return maps;
    }
 
    @RequestMapping(value = "/getProvince")
    @ResponseBody
    public Object getProvince(){
        return regiService.list(new LambdaQueryWrapper<Region>()
                .eq(Region::getParentId,0));
    }
 
    @RequestMapping(value = "/onShelf")
    @ResponseBody
    public Object onShelf(Integer id,Integer type){
        Coupon coupon = client.queryCouponById(id);
        coupon.setState(type);
        client.updateCouponData(coupon);
        return new SuccessTip<>();
    }
 
 
    @RequestMapping(value = "/getCity")
    @ResponseBody
    public Object getCity(Integer province){
        return regiService.list(new LambdaQueryWrapper<Region>()
                .eq(Region::getParentId,province));
    }
 
    @RequestMapping(value = "/uploadPic")
    @ResponseBody
    public Object add(@RequestParam("file") MultipartFile imgFile) throws IOException {
        String originalFilename = imgFile.getOriginalFilename();
        String newName = originalFilename.substring(imgFile.getOriginalFilename().lastIndexOf("."));
        String url = OBSUploadUtil.inputStreamUpload(imgFile);
        Map<String, String> map = new HashMap<String, String>();
        //是否上传成功
        map.put("state", "SUCCESS");
        //现在文件名称
        map.put("title", newName);
        //文件原名称
        map.put("original", originalFilename);
        //文件类型 .+后缀名
        map.put("type", originalFilename.substring(imgFile.getOriginalFilename().lastIndexOf(".")));
        //文件路径
        map.put("url", url);
        //文件大小(字节数)
        map.put("size", imgFile.getSize() + "");
        System.out.println(map);
        return url;
    }
 
    /**
     * 提交添加
     */
    @PostMapping(value = "/commitData")
    @ResponseBody
    public Object commitData( CouponDataVo dataVo){
        System.out.println(dataVo);
        Integer objectType = UserExt.getUser().getObjectType();
        dataVo.setUserType(objectType);
        client.insertIntoData(dataVo);
        return new SuccessTip<>();
    }
    @PostMapping(value = "/update")
    @ResponseBody
    public Object update( Integer id,Integer num,Integer num1,String text){
        Coupon coupon = client.queryCouponById(id);
        coupon.setQuantityIssued(num);
        coupon.setPickUpQuantity(num1);
        coupon.setIllustrate(text);
        client.updateCouponData(coupon);
        return new SuccessTip<>();
    }
 
 
    /**
     * 获取 积分商品列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object listOfIntegralGoods(String name, Integer type, Integer redemptionMethod , Integer userPopulation, Integer activeStatus, Integer state) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
 
        IntegralGoodsOfSearch ofSearch = new IntegralGoodsOfSearch();
        ofSearch.setPage(page);
        ofSearch.setName(name);
        ofSearch.setType(type);
        ofSearch.setRedemptionMethod(redemptionMethod);
        ofSearch.setUserPopulation(userPopulation);
        ofSearch.setActiveStatus(activeStatus);
        ofSearch.setState(state);
        System.out.println(ofSearch);
        return pointMercharsClient.getIntegralGoodsListOfSearch(ofSearch);
    }
 
 
 
    /**
     * 跳转到修改车辆管理
     */
    @RequestMapping("/tGoods_update/{id}")
    public String tCityUpdate(@PathVariable Integer id, Model model) {
        System.out.println("id:"+id);
        PointMercharsVo pointMercharsVo = pointMercharsClient.queryPointMerchaseDetailOfId(id);
        System.out.println("pointMercharsVo:"+pointMercharsVo);
        String[] split = pointMercharsVo.getPics().split(",");
        model.addAttribute("item",pointMercharsVo);
        model.addAttribute("pictures",split);
        return PREFIX + "TGoods_edit.html";
    }
 
    /**
     *  上下架处理操作
     * @param id 商品id
     * @param type 1=上架操作 2=下架操作
     * @return
     */
    @RequestMapping("/grounding")
    @ResponseBody
    public Object updateGrounding(Integer id,Integer type) {
        System.out.println(id);
        System.out.println(type);
        Map<String,Integer> map = new HashMap<>();
        map.put("id",id);
        map.put("type",type);
        boolean b = pointMercharsClient.updateGoodsGroudingStatus(map);
        System.out.println(b);
        return new SuccessTip<>();
    }
    /**
     *  上下架处理操作
     * @return
     */
    @RequestMapping("/writeOff")
    @ResponseBody
    public Object writeOff(String id) {
        Long aLong = Long.valueOf(id);
        WriteOffDTO dto = new WriteOffDTO();
        // 核销人员id
        Integer objectId = UserExt.getUser().getId();
        if (UserExt.getUser().getObjectType() == 1){
            dto.setVerifiStoreId(null);
        }else if (UserExt.getUser().getObjectType() == 2){
            storeService.getOne(new QueryWrapper<TStore>().eq("cityManagerId",objectId));
        }else{
            TStoreStaff storeByStoreStaffId = storeStaffClient.getStoreByStoreStaffId(objectId);
            dto.setVerifiStoreId(storeByStoreStaffId.getStoreId());
        }
        dto.setId(aLong);
        dto.setVerificationUserId(objectId);
        pointMercharsClient.writeOff(dto);
        return new SuccessTip<>();
    }
 
    /**
     *  购买详情
     * @param id 商品id
     * @return
     */
    @RequestMapping("/tPay_detail/{id}")
    public String payOfDetails(@PathVariable(value = "id") Integer id,Model model) {
        System.out.println(id);
        model.addAttribute("id",id);
        return PREFIX + "TGoods_pay.html";
    }
 
 
    /**
     * 获取 购买记录列表
     */
    @ResponseBody
    @RequestMapping(value = "/payList/{id}")
    public Object payList(@PathVariable(value = "id") Integer id, String name, String phone, Integer status) {
        PointMercharsPayedVo  payedVo = new PointMercharsPayedVo();
        payedVo.setId(id);
        payedVo.setName(name);
        payedVo.setPhone(phone);
        payedVo.setStatus(status);
        List<Map<String,Object>> points = pointMercharsClient.queryUserPayedGoodsList(payedVo);
        System.out.println(points);
        if (points.size() > 0 ){
            for (Map<String, Object> point : points) {
                Integer userId = (Integer) point.get("userId");
                TAppUser tAppUser = appUserClient.queryById(userId);
                if (ToolUtil.isNotEmpty(tAppUser)){
                    point.put("name",tAppUser.getName());
                    point.put("phone",tAppUser.getPhone());
                }
            }
            if (ToolUtil.isNotEmpty(name)){
                points = points.stream()
                        .filter(data -> {
                            String obtName = (String) data.get("name");
                            return obtName != null && obtName.contains(name);
                        })
                        .collect(Collectors.toList());
            }
            if (ToolUtil.isNotEmpty(phone)){
                points = points.stream()
                        .filter(data -> {
                            String obtPhone = (String) data.get("phone");
                            return obtPhone != null && obtPhone.contains(phone);
                        })
                        .collect(Collectors.toList());
            }
        }
        return points;
    }
 
    /**
     *  核销操作
     * @param id 商品id
     * @return
     */
    @RequestMapping("/write_off")
    @ResponseBody
    public Object GoodsWriteOff(Integer id){
        System.out.println(id);
        // TODO: 2023/8/15 核销操作
        return new SuccessTip<>();
    }
 
 
}