mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
package com.sinata.modular.mall.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Lists;
import com.sinata.common.enums.EnumIsDelete;
import com.sinata.common.enums.mall.EnumMallGoodsGroupType;
import com.sinata.common.enums.mall.EnumMallGoodsState;
import com.sinata.common.model.GroupSpecGoodsSkuJsonVo;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.base.tips.ErrorTip;
import com.sinata.core.common.annotion.BussinessLog;
import com.sinata.core.common.annotion.Permission;
import com.sinata.core.common.constant.factory.PageFactory;
import com.sinata.core.common.exception.BizExceptionEnum;
import com.sinata.core.log.LogObjectHolder;
import com.sinata.core.shiro.ShiroKit;
import com.sinata.core.util.Convert;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import com.sinata.core.util.SpringContextHolder;
import com.sinata.modular.mall.model.*;
import com.sinata.modular.mall.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 商品信息控制器
 *
 * @author goku
 */
@Controller
@RequestMapping("/mallGoods")
public class MallGoodsController extends BaseController {
 
    private String PREFIX = "/mall/mallGoods/";
 
    @Autowired
    private IMallGoodsService mallGoodsService;
 
    @Autowired
    private IMallGroupSpecService groupSpecService;
 
    @Autowired
    private IMallGoodsSkuService mallGoodsSkuService;
 
    @Autowired
    private IMallClassifyOneService mallClassifyOneService;
 
    @Autowired
    private IMallGoodsSpecService mallGoodsSpecService;
 
    @Autowired
    private IMallGoodsDetailService mallGoodsDetailService;
    @Autowired
    private IMallGoodsSetService mallGoodsSetService;
 
    @Resource
    private IMallGoodsSpecService goodsSpecService;
 
    @Resource
    private IMallGoodsSpecValueService goodsSpecValueService;
 
    @Resource
    private IMallTagService mallTagService;
 
 
    /**
     * 跳转到商品信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "mallGoods.html";
    }
 
    /**
     * 跳转到添加商品信息
     */
    @RequestMapping("/mallGoods_add")
    public String mallGoodsAdd(Model model) {
        // 查询所有标签
        List<MallTag> mallTags = mallTagService.getMallTags();
        model.addAttribute("mallTags", mallTags);
        return PREFIX + "mallGoods_add.html";
    }
 
    /**
     * 跳转到修改商品信息
     */
    @RequestMapping("/mallGoods_update/{mallGoodsId}")
    public String mallGoodsUpdate(@PathVariable Integer mallGoodsId, Model model) {
        MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
 
        MallGoodsDetail goodsDetail = mallGoodsDetailService.selectById(mallGoodsId);
        mallGoods.setIntroH5(goodsDetail.getIntroH5());
        mallGoods.setIntroImage(goodsDetail.getIntroImage());
        mallGoods.setPurchaseH5(goodsDetail.getPurchaseH5());
        model.addAttribute("item", mallGoods);
 
        MallGoodsSet goodsSet = mallGoodsSetService.selectById(mallGoodsId);
        model.addAttribute("goodsSet", goodsSet);
 
        // 查询所有标签
        List<MallTag> mallTags = mallTagService.getMallTags();
        model.addAttribute("mallTags", mallTags);
 
        LogObjectHolder.me().set(mallGoods);
        return PREFIX + "mallGoods_edit.html";
    }
 
    @ResponseBody
    @GetMapping(value = "/getGoodsSpecData")
    public List<MallGoodsSku> getGoodsSpecData(Integer goodsId) {
        List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(
                new EntityWrapper<MallGoodsSku>()
                        .setSqlSelect("spec_ids id, grep_name, stock,price_sale,price_member")
                        .eq("goods_id", goodsId)
                        .eq("merchant_id", 0)
        );
 
        MallGoods mallGoods = mallGoodsService.selectById(goodsId);
 
        String classifyName = "";
        MallClassifyOne classifyOne = mallClassifyOneService.selectById(mallGoods.getClassifyIdOne());
        if (classifyOne != null) {
            classifyName = classifyOne.getClassifyName();
        }
        for (MallGoodsSku sku : skuList) {
            sku.setClassifyName(classifyName);
        }
        return skuList;
    }
 
    /**
     * 获取商品信息列表
     *
     * @param id    商品id
     * @param state 商品状态
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
 
        page.setRecords(
                wrapperList(page, beginTime, endTime, goodsName, id, state, goodsNo)
        );
 
        return super.packForBT(page);
    }
 
    public List<Map<String, Object>> wrapperList(Page<Map<String, Object>> page, String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo) {
        Wrapper wrapper = new EntityWrapper<MallGoods>()
                .eq("group_type", EnumMallGoodsGroupType.GOODS.index)
                .eq("is_delete", 0)
                .orderBy("id", false);
 
        // 时间搜索
        if (!StringUtils.isEmpty(beginTime)) {
            wrapper.ge("create_time", beginTime + " 00:00:00");
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.le("create_time", endTime + " 23:59:59");
        }
 
        if (!StringUtils.isEmpty(goodsName)) {
            wrapper.like("goods_name", goodsName);
        }
        if (!StringUtils.isEmpty(id)) {
            if (id.indexOf("sp") != -1) {
                String idd = id.substring(id.indexOf("sp") + 2);
                wrapper.eq("id", Integer.parseInt(idd));
            } else {
                wrapper.eq("id", Integer.parseInt(id));
            }
        }
        if (state != null) {
            wrapper.eq("state", state);
        }
        if (StrUtil.isNotBlank(goodsNo)) {
            wrapper.like("goods_no", goodsNo);
        }
 
        // 查询所有标签
        List<MallTag> mallTags = mallTagService.getMallTags();
 
        // 查询数据列表
        List<Map<String, Object>> list;
        if (page != null) {
            list = mallGoodsService.selectMapsPage(page, wrapper).getRecords();
        } else {
            list = mallGoodsService.selectMaps(wrapper);
        }
 
        // 规格列表
        List<MallGoodsSpec> selectList = mallGoodsSpecService.selectList(new EntityWrapper<MallGoodsSpec>().setSqlSelect("id, spec_name"));
 
        return list.stream().peek(m -> {
            Object classObj = m.get("classifyIdOne");
            if (classObj != null) {
                m.put("classifyName", mallClassifyOneService.selectById(Convert.toInt(classObj)).getClassifyName());
            }
 
            // 封装规格名
            List<String> specNameList = new ArrayList<>();
            List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(new EntityWrapper<MallGoodsSku>().eq("goods_id", m.get("id")).eq("merchant_id", 0));
            for (MallGoodsSku sku : skuList) {
                String[] spIds = sku.getSpecGrep().split(",");
                for (String spId : spIds) {
                    for (MallGoodsSpec spec : selectList) {
                        if (spec.getId().toString().equals(spId)) {
                            specNameList.add(spec.getSpecName());
                        }
                    }
                }
            }
            m.put("specNames", specNameList.stream().distinct().collect(Collectors.joining(",")));
 
            m.put("merchantCount", mallGoodsSkuService.selectCount(
                    new EntityWrapper<MallGoodsSku>()
                            .eq("goods_id", m.get("id"))
                            .ne("merchant_id", 0)
                            .groupBy("goods_id")
            ));
 
            Object tagIds = m.get("tagIds");
            if (tagIds != null) {
                m.put("tagIds", mallTagService.getTagListByGoodsId(mallTags, tagIds.toString()).stream().collect(Collectors.joining("、")));
            }
        }).collect(Collectors.toList());
    }
 
    @ResponseBody
    @RequestMapping(value = "/export")
    public void export(String beginTime, String endTime, String goodsName, String id, Integer state, String goodsNo, HttpServletResponse response) {
        List<Map<String, Object>> list = wrapperList(null, beginTime, endTime, goodsName, id, state, goodsNo);
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("创建时间");
        shellList.add("商品编号");
        shellList.add("商品分类");
        shellList.add("商品名称");
        shellList.add("商品副标题");
        shellList.add("商品标签");
        shellList.add("规格");
        shellList.add("销售量");
        shellList.add("商品库存");
        shellList.add("售卖门店数");
        shellList.add("销售价");
        shellList.add("会员价");
        shellList.add("商品状态");
        dataList.add(shellList);
 
        // 详细数据列【封装】
        for (Map<String, Object> map : list) {
            shellList = new ArrayList<>();
            shellList.add(map.get("createTime"));
            shellList.add(map.get("goodsNo"));
            shellList.add(map.get("classifyName"));
            shellList.add(map.get("goodsName"));
            shellList.add(map.get("goodsTitle"));
            shellList.add(map.get("tagIds"));
            shellList.add(map.get("specNames"));
            shellList.add(map.get("buyCount"));
            shellList.add(map.get("stock"));
            shellList.add(map.get("merchantCount"));
            shellList.add(map.get("priceSale"));
            shellList.add(map.get("priceMember"));
            shellList.add(EnumMallGoodsState.getMarkByIndex((Integer) map.get("state")));
            dataList.add(shellList);
        }
        try {
            String title = "商品信息";
            // 调用工具类进行导出
            ExcelExportUtil.easySheet(title + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), title, dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @ResponseBody
    @BussinessLog(value = "新增商品信息")
    @RequestMapping(value = "/add")
    public Object add(MallGoods mallGoods) {
        if (mallGoods.getState() == null) {
            mallGoods.setState(EnumMallGoodsState.FOR_SALE.getIndex());
        }
 
        if (StrUtil.isNotBlank(mallGoods.getIntroImage())) {
            mallGoods.setGoodsImage(mallGoods.getIntroImage().split(",")[0]);
        }
        mallGoods.setGoodsSkus(JSONUtil.toList(mallGoods.getGoodsSkusJson(), MallGoodsSku.class));
        if (mallGoods.getGoodsSkus() == null || CollUtil.isEmpty(mallGoods.getGoodsSkus())) {
            return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "请添加商品规格不存在");
        }
        mallGoods.setGoodsSet(JSONUtil.toBean(mallGoods.getGoodsSetJson(), MallGoodsSet.class));
        mallGoodsService.saveMallGoods(mallGoods);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改商品信息
     */
    @ResponseBody
    @BussinessLog(value = "修改商品信息")
    @RequestMapping(value = "/update")
    public Object update(MallGoods mallGoods) {
        MallGoods oldGoods = this.mallGoodsService.selectById(mallGoods.getId());
        if (oldGoods == null) {
            return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "商品不存在");
        }
//        MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
//        if (oldGoods.getState() == EnumMallGoodsState.CMS_REFUSE_SALE.getIndex()
//                || !StrUtil.equals(oldGoods.getGoodsName(),mallGoods.getGoodsName())
//                || !StrUtil.equals(oldGoods.getGoodsImage(),mallGoods.getGoodsImage())
//                || !StrUtil.equals(goodsDetail.getIntroImage(),mallGoods.getIntroImage())
//                || !StrUtil.equals(goodsDetail.getIntroH5(),mallGoods.getIntroH5())) {
//            mallGoods.setState(EnumMallGoodsState.WAIT_AUDIT.getIndex());
//        }
        if (StrUtil.isNotBlank(mallGoods.getIntroImage())) {
            mallGoods.setGoodsImage(mallGoods.getIntroImage().split(",")[0]);
        }
        mallGoods.setGoodsSkus(JSONUtil.toList(mallGoods.getGoodsSkusJson(), MallGoodsSku.class));
        if (mallGoods.getGoodsSkus() == null || CollUtil.isEmpty(mallGoods.getGoodsSkus())) {
            return new ErrorTip(BizExceptionEnum.REQUEST_INVALIDATE.getCode(), "请添加商品规格不存在");
        }
        mallGoods.setGoodsSet(JSONUtil.toBean(mallGoods.getGoodsSetJson(), MallGoodsSet.class));
        mallGoodsService.updateMallGoods(mallGoods);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除/批量删除
     */
    @Permission
    @ResponseBody
    @BussinessLog(value = "删除/批量删除商品信息")
    @RequestMapping(value = "/delete")
    public Object delete(@RequestParam String ids) {
        String[] idArray = ids.split(",");
        // 逻辑删除
        mallGoodsService.updateForSet("is_delete = 1", new EntityWrapper<MallGoods>().in("id", idArray));
 
        mallGoodsSkuService.delete(
                new EntityWrapper<MallGoodsSku>()
                        .in("goods_id", idArray)
        );
        return SUCCESS_TIP;
    }
 
    /**
     * 修改商品信息状态上下架和商品审核接口
     */
    @ResponseBody
    @BussinessLog(value = "修改商品信息状态")
    @RequestMapping(value = "/updateState")
    public Object updateState(Integer mallGoodsId, Integer state, String auditRemark) {
        mallGoodsService.updateForSet("state = " + state + ",audit_remark = '" + auditRemark + "'", new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
        return SUCCESS_TIP;
    }
 
    @RequestMapping("/to_buyCount/{mallGoodsId}")
    public String to_buyCount(@PathVariable Integer mallGoodsId, Model model) {
        MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
        model.addAttribute("item", mallGoods);
        return PREFIX + "mallGoods_buyCount.html";
    }
 
    @ResponseBody
    @BussinessLog(value = "修改销售量")
    @RequestMapping(value = "/updateBuyCount")
    public Object updateBuyCount(Integer mallGoodsId, Integer buyCount) {
        mallGoodsService.updateForSet("buy_count = " + buyCount, new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改商品信息推荐
     */
    @ResponseBody
    @BussinessLog(value = "修改商品信息推荐")
    @RequestMapping(value = "/updateRecommend")
    public Object updateRecommend(Integer mallGoodsId, Integer isRecommend, Integer sort) {
        mallGoodsService.updateForSet("is_recommend = " + isRecommend + ",sort=" + sort, new EntityWrapper<MallGoods>().eq("id", mallGoodsId));
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转商品信息详情
     */
    @RequestMapping(value = "/detail/{mallGoodsId}")
    public Object detail(@PathVariable("mallGoodsId") Integer mallGoodsId, Model model) {
        MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
        mallGoods.setMallClassifyOne(this.mallClassifyOneService.selectById(mallGoods.getClassifyIdOne()));
 
        MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
        if (goodsDetail == null) {
            goodsDetail = new MallGoodsDetail();
        }
 
        // 查询所有标签
        List<MallTag> mallTags = mallTagService.getMallTags();
        mallGoods.setTagIds(mallTagService.getTagListByGoodsId(mallTags, mallGoods.getTagIds()).stream().collect(Collectors.joining("、")));
 
        model.addAttribute("item", mallGoods);
        model.addAttribute("mallGoodsState", EnumMallGoodsState.getMarkByIndex(mallGoods.getState()));
        model.addAttribute("mallGoodsDetail", goodsDetail);
        model.addAttribute("introImageList", goodsDetail.getIntroImage().split(","));
 
        return PREFIX + "mallGoods_detail.html";
    }
 
 
    @RequestMapping(value = "/appView/{mallGoodsId}")
    public Object appView(@PathVariable("mallGoodsId") Integer mallGoodsId, Model model) {
        MallGoods mallGoods = mallGoodsService.selectById(mallGoodsId);
        mallGoods.setMallClassifyOne(this.mallClassifyOneService.selectById(mallGoods.getClassifyIdOne()));
 
        MallGoodsDetail goodsDetail = this.mallGoodsDetailService.selectById(mallGoods.getId());
        if (goodsDetail == null) {
            goodsDetail = new MallGoodsDetail();
        }
 
        model.addAttribute("item", mallGoods);
        model.addAttribute("mallGoodsDetail", goodsDetail);
 
        return PREFIX + "mallGoods_appView.html";
    }
 
    @RequestMapping("/mallGoodsList")
    @ResponseBody
    public Object mallGoodsList(Integer groupType) {
        Wrapper wrapper = new EntityWrapper<MallGoods>().eq("is_delete", 0).orderBy("id", false);
        if (Objects.nonNull(groupType) && groupType == -1) {
            wrapper.ne("group_type", 0);
        } else if (Objects.nonNull(groupType)) {
            wrapper.eq("group_type", groupType);
        }
        List<MallGoods> goodsList = mallGoodsService.selectList(wrapper);
        Set<Integer> goodsIdList = goodsList.stream().map(MallGoods::getId).collect(Collectors.toSet());
        Wrapper skuWrapper = new EntityWrapper<MallGoodsSku>().in("goods_id", goodsIdList)
                .eq("merchant_id", 0).orderBy("id", false);
        List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(skuWrapper);
        List<HashMap<String, Object>> result = new ArrayList<>();
        goodsList.forEach(goods -> {
            List<MallGoodsSku> goodsSkuList = skuList.stream()
                    .filter(sku -> sku.getGoodsId().equals(goods.getId()))
                    .collect(Collectors.toList());
            List<HashMap<String, Object>> goodsMapList = goodsSkuList.stream().map(sku -> {
                HashMap<String, Object> goodMap = new HashMap<>();
                //商品编号
                goodMap.put("aGoodsNo", goods.getGoodsNo());
                goodMap.put("bName", goods.getGoodsName());
                goodMap.put("bbGrepName", sku.getGrepName());
                goodMap.put("cGroupType", goods.getGroupType());
                String groupTypName = goods.getGroupType() > 0 ? (goods.getGroupType() == 1 ? "黄金套餐"
                        : "钻石套餐") : "普通商品";
                goodMap.put("cGroupTypeName", groupTypName);
                goodMap.put("dPrice", goods.getPrice());
                goodMap.put("dPriceDale", sku.getPriceSale());
                goodMap.put("ePriceMember", sku.getPriceMember());
                goodMap.put("fStock", sku.getStock());
                goodMap.put("gBuyCount", goods.getBuyCount());
                goodMap.put("hId", goods.getId());
                goodMap.put("iSpecIds", sku.getSpecIds());
                goodMap.put("jSkuId", sku.getId());
                return goodMap;
            }).collect(Collectors.toList());
            result.addAll(goodsMapList);
        });
        /*for (int i = 0; i < result.size(); i++) {
            for (int j = i+1; j < result.size(); j++) {
                if (result.get(i).get("hId").equals(result.get(j).get("hId"))) {
                    result.get(j).put("bName","");
                }
            }
        }*/
        return new HashMap<String, Object>() {{
            put("code", 200);
            put("value", result);
        }};
    }
 
    @ResponseBody
    @BussinessLog(value = "获取商品分类")
    @RequestMapping(value = "/getClassify")
    public Object getClassify(@RequestParam(required = false) Integer oneClassifyId) {
        if (oneClassifyId == null) {
            return this.mallClassifyOneService.selectList(new EntityWrapper<MallClassifyOne>().eq("is_delete", EnumIsDelete.EXISTED.index));
        } else {
            return new ArrayList<>();
        }
    }
 
    @BussinessLog(value = "获取商品规格")
    @RequestMapping(value = "/getGoodsSpecs")
    public Object getGoodsSpecs(Integer oneClassifyId, Integer twoClassifyId,@RequestParam(required = false) List<String> selectedItems, Model model) {
        Wrapper<MallGoodsSpec> wrapper = new EntityWrapper<MallGoodsSpec>()
                .eq("is_delete", EnumIsDelete.EXISTED.index)
                .addFilter("concat(',',classify_id_one,',') like concat( '%,', {0}, ',%' )", oneClassifyId);
        List<MallGoodsSpec> goodsSpecs = this.goodsSpecService.selectList(wrapper);
        if (CollectionUtils.isEmpty(goodsSpecs)) {
            goodsSpecs = Lists.newArrayList();
        }
        if (!selectedItems.isEmpty()) {
            goodsSpecs = goodsSpecs.stream()
                    .filter(specs -> !selectedItems.contains(specs.getSpecName())).collect(
                            Collectors.toList());
        }
        model.addAttribute("goodsSpecs", goodsSpecs);
        return PREFIX + "add_specs.html";
    }
 
    @ResponseBody
    @BussinessLog(value = "获取商品规格的值")
    @RequestMapping(value = "/getGoodsSpecValues")
    public Object getGoodsSpecs(@RequestParam Integer specId) {
        return this.goodsSpecValueService.selectList(new EntityWrapper<MallGoodsSpecValue>()
                .eq("spec_id", specId));
    }
 
    @ResponseBody
    @BussinessLog(value = "获取商品列表")
    @GetMapping(value = "/goodsByClassList")
    public List<MallGoods> goodsByClassList(@RequestParam Integer classId) {
        return mallGoodsService.selectList(
                new EntityWrapper<MallGoods>()
                        .eq("is_delete", 0)
                        .eq("group_type", EnumMallGoodsGroupType.GOODS.index)
                        .in("state", Arrays.asList(
                                EnumMallGoodsState.FOR_SALE.index
                        ))
        );
    }
 
    @ResponseBody
    @BussinessLog(value = "获取商品列表")
    @GetMapping(value = "/goodsByIdsList")
    public List<MallGoods> goodsByIdsList(@RequestParam String ids) {
        return mallGoodsService.selectList(
                new EntityWrapper<MallGoods>()
                        .eq("group_type", EnumMallGoodsGroupType.GOODS.index)
                        .in("id", ids.split(","))
        );
    }
 
    @ResponseBody
    @BussinessLog(value = "获取商品列表")
    @GetMapping(value = "/goodsByGoodsSpecId")
    public List<Map<String, Object>> goodsByIdsList(String goodsIds, Integer groupSpecId, String oldGoodsSkuJson) {
        List<MallGoods> goodsList = mallGoodsService.selectList(
                new EntityWrapper<MallGoods>()
                        .eq("group_type", EnumMallGoodsGroupType.GOODS.index)
                        .in("id", goodsIds.split(","))
        );
 
        List<Map<String, Object>> list;
        if (groupSpecId != null) {
            String goodsSkuJson = oldGoodsSkuJson;
            if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) {
                // 查询套餐规格组信息
                MallGroupSpec groupSpec = groupSpecService.selectById(groupSpecId);
                goodsSkuJson = groupSpec.getGoodsSkuJson();
            }
 
            // 格式化套餐规格组数据
            List<GroupSpecGoodsSkuJsonVo> groupSpecGoodsSkuJsonVoList;
            if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) {
                groupSpecGoodsSkuJsonVoList = null;
            } else {
                groupSpecGoodsSkuJsonVoList = JSONUtil.parseArray(goodsSkuJson).toList(GroupSpecGoodsSkuJsonVo.class);
            }
 
            list = goodsList.stream().map(o -> {
                Map<String, Object> map = BeanUtil.beanToMap(o);
                Integer goodsNum = 1;
                if (groupSpecGoodsSkuJsonVoList != null) {
                    // 匹配商品数量
                    for (GroupSpecGoodsSkuJsonVo groupSpecGoodsSkuJsonVo : groupSpecGoodsSkuJsonVoList) {
                        if (o.getId().equals(groupSpecGoodsSkuJsonVo.getGoodsId())) {
                            goodsNum = groupSpecGoodsSkuJsonVo.getGoodsNum();
                        }
                    }
                }
                map.put("goodsNum", goodsNum);
                return map;
            }).collect(Collectors.toList());
        } else {
            list = goodsList.stream().map(o -> {
                Map<String, Object> map = BeanUtil.beanToMap(o);
                map.put("goodsNum", 1);
                return map;
            }).collect(Collectors.toList());
        }
        return list;
    }
}