nickchange
2023-11-15 331ae50b1cdcb31a4a0c182abb82aec5c1b12f83
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
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.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.account.AppUserClient;
import com.dsh.course.feignClient.account.CityManagerClient;
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.TCityManager;
import com.dsh.course.feignClient.activity.CouponClient;
import com.dsh.course.feignClient.activity.PointMercharsClient;
import com.dsh.course.feignClient.activity.model.*;
import com.dsh.course.feignClient.course.CourseClient;
import com.dsh.guns.config.UserExt;
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.*;
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 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.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
 
/**
 * 优惠券管理 控制器
 */
 
@Controller
@RequestMapping("/tGoods")
public class TGoodsController extends BaseController {
 
 
 
    private String PREFIX = "/system/tGoods/";
    private String PREFIX1 = "/system/tGoodsAudit/";
 
 
    @Resource
    private IRegionService regiService;
 
    @Resource
    private IStoreService storeService;
 
    @Resource
    private CouponClient client;
 
    @Resource
    private CityManagerClient cmgrClient;
 
    @Autowired
    private AppUserClient appUserClient;
    @Autowired
    private ICityService cityService;
 
    @Autowired
    private CourseClient courseClient;
 
    @Resource
    private PointMercharsClient pointMercharsClient;
 
 
 
    /**
     * 跳转到优惠券管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
 
        return PREFIX + "TGoods.html";
    }
    @RequestMapping("/audit")
    public String audit(Model model) {
        return PREFIX1 + "TGoodsAudit.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tGoods_add")
    public String memberCouponAdd(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);
        List<Map<String,Object>> listOne =  courseClient.getPageageType();
        model.addAttribute("courseType",listOne);
 
 
        return PREFIX + "TGoods_add.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tGoods_info")
    public String tGoodsInfo(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 + "TGoods_detail_one.html";
    }
 
    @RequestMapping("/goods_info/{id}")
    public String memberCouponInfo(@PathVariable Integer id, Model model) {
        PointsMerchandise pointMercharsVo = pointMercharsClient.queryPointMerchaseById(id);
        model.addAttribute("item",pointMercharsVo);
        if(pointMercharsVo.getType()==2){
            Date startTime = pointMercharsVo.getStartTime();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            model.addAttribute("sTime",format.format(startTime));
            model.addAttribute("eTime",format.format(pointMercharsVo.getEndTime()));
            Integer shopId = pointMercharsClient.getshopName(id);
            TStore byId = storeService.getById(shopId);
            model.addAttribute("shopName",byId.getName());
            Integer coursePackageId = pointMercharsVo.getCoursePackageId();
            List<String> name = courseClient.queryPackageById(coursePackageId);
            Integer coursePackageId1 = pointMercharsVo.getCoursePackageId();
            List<Integer> classHours = courseClient.getHours(coursePackageId1);
            model.addAttribute("typeName",name.get(0));
            model.addAttribute("pageName",name.get(1));
            model.addAttribute("classHours",classHours);
            String productImages = pointMercharsVo.getProductImages();
            ArrayList<String> strings = new ArrayList<>();
            for (String s : productImages.split(",")) {
                strings.add(s);
            }
            model.addAttribute("pictures",strings);
            return PREFIX + "TGoods_detail_two.html";
        }else {
            GoodsInfoOneVo infoOneVo = pointMercharsClient.queryDetailsOfGoods(id);
            System.out.println("pointMercharsVo:"+infoOneVo);
            model.addAttribute("item",infoOneVo);
            String[] split = infoOneVo.getPics().split(",");
            List<String> list = Arrays.asList(split);
            if (infoOneVo.getUseScope() == 2){
                List<StoreVos> provinces = pointMercharsClient.getProvinces(id);
                model.addAttribute("city",provinces);
            }
            if (infoOneVo.getUseScope() == 3){
                List<StoreVos> storeVos = pointMercharsClient.getStoreList(id);
                model.addAttribute("store",storeVos);
            }
            model.addAttribute("pictures",list);
            model.addAttribute("exchangeMethod",infoOneVo.getExchangeMethod());
            return PREFIX + "TGoods_detail_one.html";
        }
 
 
    }
 
 
    @RequestMapping("/coupon_record/{id}")
    public String memberCouponAdd(@PathVariable Integer id,Model model) {
        Coupon coupon = client.queryCouponById(id);
 
        model.addAttribute("id",id);
        model.addAttribute("type",coupon.getType());
        return PREFIX + "TCouponRecord.html";
    }
 
 
 
    @RequestMapping("/coupon_detail/{id}")
    public String memberCouponDetail(@PathVariable Integer id,Model model) {
        Coupon coupon = client.queryCouponById(id);
        String content = coupon.getContent();
        JSONObject jsonObject = JSONObject.parseObject(content);
        String one ="";
        String two ="";
        String three ="";
        if(coupon.getType()==1){
            one = jsonObject.get("conditionalAmount").toString();
            two = jsonObject.get("deductionAmount").toString();
        }
        if(coupon.getType()==2){
            one = jsonObject.get("conditionalAmount").toString();
        }
        if(coupon.getType()==3){
            three = jsonObject.get("experienceName").toString();
        }
        List<CouponCity> list = new ArrayList<>();
        List<Integer> list1=null;
        List<TStore> list2=new ArrayList<>();
        if(coupon.getUseScope()==2){
            list = client.queryCity(coupon.getId());
        }
        if(coupon.getUseScope()==3){
            list1 = client.queryStore(coupon.getId());
            list2 = storeService.list(new LambdaQueryWrapper<TStore>().in(TStore::getId, list1));
            for (TStore tStore : list2) {
                CityManager cityManager = cmgrClient.queryCityManagerById(tStore.getCityManagerId());
                if (ToolUtil.isNotEmpty(cityManager)){
                    tStore.setProvince(tStore.getProvince()+tStore.getCity());
                    tStore.setPhone(cityManager.getName()+"-"+cityManager.getPhone());
                }
            }
 
        }
        model.addAttribute("city",list);
        model.addAttribute("store",list2);
        model.addAttribute("s",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getStartTime()));
        model.addAttribute("e",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getEndTime()));
        model.addAttribute("one",one);
        model.addAttribute("two",two);
        model.addAttribute("three",three);
        ArrayList<String> strings = new ArrayList<>();
        String productImages = coupon.getProductImages();
        for (String s : productImages.split(",")) {
            strings.add(s);
        }
 
        model.addAttribute("img",strings);
        Integer objectType = UserExt.getUser().getObjectType();
        System.out.println(objectType);
        model.addAttribute("item",coupon);
        return PREFIX + "TCouponInfo.html";
    }
 
 
 
    /**
     * 跳转到门店管理列表页
     */
    @RequestMapping("/storeList")
    public String storePage(Model model) {
        List<TCity> provinceList = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",provinceList);
        return PREFIX + "TStoreList.html";
    }
 
 
    /**
     * 跳转到门店管理列表页
     */
    @RequestMapping("/storeList1")
    public String storePage1(Model model) {
        List<TCity> provinceList = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",provinceList);
        return PREFIX + "TStoreListOne.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<>();
    }
 
    /**
     *  编辑 商品详情
     * @param pointMerchandiseId 商品Id
     * @param quantityIssued 发放数量
     * @param pickUpQuantity 限领数量
     * @param redemptionInstructions 说明
     * @param cover 封面图
     * @param productImages 商品图片
     * @param sort 排序
     * @return
     */
    @PostMapping(value = "/update")
    @ResponseBody
    public Object update( Integer pointMerchandiseId,Integer quantityIssued,Integer pickUpQuantity,String redemptionInstructions,String cover,String productImages,Integer sort){
        Map<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("pointMerchandiseId",pointMerchandiseId);
        stringObjectHashMap.put("quantityIssued",quantityIssued);
        stringObjectHashMap.put("pickUpQuantity",pickUpQuantity);
        stringObjectHashMap.put("redemptionInstructions",redemptionInstructions);
        stringObjectHashMap.put("cover",cover);
        stringObjectHashMap.put("productImages",productImages);
        stringObjectHashMap.put("sort",sort);
        stringObjectHashMap.put("type",UserExt.getUser().getObjectType());
        System.out.println(stringObjectHashMap);
        pointMercharsClient.updateGoodsDetail(stringObjectHashMap);
        return new SuccessTip<>();
    }
    /*
    ajax.set("typeAll",typeAll);
        ajax.set("provinceCode",pCode);
        ajax.set("cityCode",cCode);
        ajax.set("storeId",storeId);
        ajax.set("coursePackageTypeId",coursePackageTypeId);
        ajax.set("coursePackageId",coursePackageId);
        ajax.set("coursePackageConfigId",coursePackageConfigId);
        ajax.set("price",price);
        ajax.set("type",type);
        ajax.set("integral",integral);
        ajax.set("cash",cash);
        ajax.set("cover",cover1);
        ajax.set("imgOne",imgOne);
        ajax.set("userPopulation",userPopulation);
        ajax.set("quantityIssued",quantityIssued);
        ajax.set("pickUpQuantity",pickUpQuantity);
        ajax.set("startTime",startTime);
        ajax.set("text",text);
        ajax.set("sort",sort);
        ajax.set("useScope",company);
        ajax.set("cityIds",cts);
        ajax.set("storeIds",stores);
     */
    @PostMapping(value = "/add")
    @ResponseBody
    public Object add( Integer typeAll,String provinceCode,String cityCode,Integer storeId,Integer coursePackageTypeId,Integer coursePackageId,Integer coursePackageConfigId,
                       Double price,Integer type,Integer integral,Double cash,String cover,String imgOne,Integer userPopulation,Integer quantityIssued,Integer pickUpQuantity,
                       String startTime,String text,Integer sort,String name,Integer useScope,String cityIds,String storeIds,Integer cardType
    ) throws ParseException {
        PointsMerchandise pointsMerchandise = new PointsMerchandise();
        pointsMerchandise.setType(typeAll);
        pointsMerchandise.setName(name);
        pointsMerchandise.setCoursePackageId(coursePackageId);
        pointsMerchandise.setPrice(new BigDecimal(price));
        pointsMerchandise.setRedemptionMethod(type);
        if(type==2 || type==3){
            pointsMerchandise.setCash(new BigDecimal(cash));
        }
        if(type==1 || type==2){
            pointsMerchandise.setIntegral(integral);
        }
        pointsMerchandise.setCover(cover);
        pointsMerchandise.setProductImages(imgOne);
        pointsMerchandise.setUserPopulation(userPopulation);
        pointsMerchandise.setCardType(cardType);
        pointsMerchandise.setQuantityIssued(quantityIssued);
        pointsMerchandise.setPickUpQuantity(pickUpQuantity);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        pointsMerchandise.setStartTime(format.parse(startTime.split(" - ")[0]));
        pointsMerchandise.setEndTime(format.parse(startTime.split(" - ")[1]));
        pointsMerchandise.setUseScope(useScope);
        if(ToolUtil.isNotEmpty(provinceCode)){
            TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, provinceCode));
            pointsMerchandise.setProvinceCode(provinceCode);
            pointsMerchandise.setProvince(one.getName());
        }
        if(ToolUtil.isNotEmpty(cityCode)){
            TCity one = cityService.getOne(new LambdaQueryWrapper<TCity>().eq(TCity::getCode, cityCode));
            pointsMerchandise.setCityCode(cityCode);
            pointsMerchandise.setCity(one.getName());
        }
        pointsMerchandise.setRedemptionInstructions(text);
        pointsMerchandise.setSort(sort);
        pointsMerchandise.setState(1);
        pointsMerchandise.setInsertTime(new Date());
        pointsMerchandise.setCoursePackageConfigId(coursePackageConfigId);
        if(UserExt.getUser().getObjectType()!=1){
            pointsMerchandise.setStatus(2);
        }
        // 代替storeId
        pointsMerchandise.setShelves(1);
        if(typeAll!=2){
            if(useScope==2){
                ArrayList<Map<String,String>> objects = new ArrayList<>();
                for (String s : cityIds.split(",")) {
                    TCity tCity = cityService.getById(Integer.valueOf(s));
                    HashMap<String, String> map = new HashMap<>();
                    TCity pCity = cityService.getById(tCity.getParentId());
                    map.put("pName",pCity.getName());
                    map.put("pCode",pCity.getCode());
                    map.put("cName",tCity.getName());
                    map.put("cCode",tCity.getCode());
                    map.put("id","0");
                    objects.add(map);
                }
                pointMercharsClient.addCitys(objects);
            }else if(useScope==3){
                if(UserExt.getUser().getObjectType()==3){
                    storeIds=UserExt.getUser().getObjectId().toString();
                }
                Integer oid=null;
                String[] split = storeIds.split(",");
                for (int i = 0; i < split.length; i++) {
                    if(i==0){
                        Integer operatorId = storeService.getById(split[0]).getOperatorId();
                        oid=operatorId;
                    }
                    Integer operatorId = storeService.getById(split[i]).getOperatorId();
                    if(oid!=operatorId){
                        return "5003";
                    }
                }
                Integer id = pointMercharsClient.add(pointsMerchandise);
                String pam = id+"_"+storeIds;
                // 添加多个城市 门店
                try{
                    pointMercharsClient.addOther(pam);
 
                }catch (Exception e){
                    e.printStackTrace();
                }
            }else if(useScope==1){
                Integer id = pointMercharsClient.add(pointsMerchandise);
            }
 
 
 
        }else {
            // ?
            pointsMerchandise.setShelves(storeId);
            pointsMerchandise.setUseScope(3);
 
            Integer id = pointMercharsClient.add(pointsMerchandise);
        }
        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(value = "/listAudit")
    @ResponseBody
    public Object listOfIntegralGoodsAudit(String name, Integer type, Integer redemptionMethod , Integer userPopulation, Integer activeStatus) {
        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);
        return pointMercharsClient.getIntegralGoodsListOfSearchAudit(ofSearch);
    }
 
 
 
 
 
 
 
 
    @RequestMapping(value = "/updateTypeOne")
    @ResponseBody
    public Object updateTypeOne(Integer id, Integer type, String remark) {
        Object o = pointMercharsClient.updateType(id + "_" + type + "_" + remark);
        return SUCCESS_TIP;
    }
 
 
 
    /**
     * 跳转到修改商品详情
     */
    @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(",");
        StringBuilder concatenatedString = new StringBuilder();
        for (String element : split) {
            concatenatedString.append(element).append(",");
        }
        // 去除末尾的逗号
        if (concatenatedString.length() > 0) {
            concatenatedString.setLength(concatenatedString.length() - 1);
        }
        String result = concatenatedString.toString();
        model.addAttribute("id",id);
        model.addAttribute("item",pointMercharsVo);
        model.addAttribute("pictures",result);
        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<>();
    }
 
 
 
    /**
     *  购买详情
     * @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);
        PointsMerchandise byId = pointMercharsClient.getById(id);
        model.addAttribute("type",byId.getType());
        return PREFIX + "TGoods_pay.html";
    }
    /**
     *  购买详情
     * @param id 商品id
     * @return
     */
    @RequestMapping("/tPay_detail1/{id}")
    public String payOfDetailsOne(@PathVariable(value = "id") Integer id,Model model) {
        System.out.println(id);
        model.addAttribute("id",id);
        return PREFIX + "TGoods_payOne.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) {
                Object id1 = point.get("id");
                String idAsString = String.valueOf(id1);
 
                // 移除原始的 "id" 键
                point.remove("id");
 
                // 将字符串类型的 "id" 放回 Map 对象中
                point.put("id", idAsString);
                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(String id){
        Integer objectType = UserExt.getUser().getObjectType();
        Map<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("goodsId",id);
        stringObjectHashMap.put("managerId",objectType);
        boolean b = pointMercharsClient.writeOffGoodsStatus(stringObjectHashMap);
        System.out.println(b);
        if (b){
            return new SuccessTip<>();
        }else {
            return ERROR;
        }
 
    }
 
 
 
 
 
}