xiaoyong931011
2021-06-22 38609ee05255ce5c36f308fe8d595555a86f9ba3
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
package com.xzx.gc.shop.service;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.dto.log.OperationAppLog;
import com.xzx.gc.common.utils.MqUtil;
import com.xzx.gc.entity.CoreUser;
import com.xzx.gc.entity.ScoreGoodsCategory;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.model.admin.GoodsCategoryModel;
import com.xzx.gc.shop.dto.QueryGoodsCategoryListDto;
import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper;
import com.xzx.gc.shop.vo.QueryGoodsCategoryListVo;
import com.xzx.gc.shop.vo.ViewGoodsCategoryVo;
import com.xzx.gc.util.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Transactional
@Slf4j
public class GoodsService {
 
    @Resource
    ScoreGoodsCategoryMapper scoreGoodsCategoryMapper;
 
    @Autowired
    private MqUtil mqUtil;
 
    public Map<String, Object> queryGoodsCategoryList(QueryGoodsCategoryListDto model) {
        String name = model.getName();
        GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel();
        goodsCategoryModel.setName(name);
        PageHelper.startPage(model.getPage(), model.getLimit());
 
        List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel);
        PageInfo pageInfo = new PageInfo(maps);
        int count = Convert.toInt(pageInfo.getTotal());
        Map<String, Object> map = new HashMap<>();
        map.put("data", maps);
        map.put("count", count);
        map.put("code", 0);
        return map;
    }
 
    public Long addGoodsCategory(GoodsCategoryModel model) {
        ScoreGoodsCategory scoreGoodsCategory = new ScoreGoodsCategory();
        scoreGoodsCategory.setName(model.getName());
        scoreGoodsCategory.setCategoryIden(model.getCategoryIden());
        scoreGoodsCategory.setParentId(model.getParentId());
        scoreGoodsCategory.setCreatedBy(model.getCreatedBy());
        scoreGoodsCategory.setCreatedTime(model.getCreatedTime());
        scoreGoodsCategoryMapper.insert(scoreGoodsCategory);
        return scoreGoodsCategory.getId();
    }
 
    public void deleteGoodsCategory(long id) {
        scoreGoodsCategoryMapper.deleteByPrimaryKey(id);
    }
 
    public ViewGoodsCategoryVo viewGoodsCategoryById(long id) {
        ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id);
        ViewGoodsCategoryVo viewGoodsCategoryVo = new ViewGoodsCategoryVo();
        viewGoodsCategoryVo.setId(scoreGoodsCategory.getId());
        viewGoodsCategoryVo.setName(scoreGoodsCategory.getName());
        viewGoodsCategoryVo.setCategoryIden(scoreGoodsCategory.getCategoryIden());
        viewGoodsCategoryVo.setParentId(scoreGoodsCategory.getParentId());
        return viewGoodsCategoryVo;
    }
 
    public void updateGoodsCategory(GoodsCategoryModel model) {
        long id = model.getId();
        ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id);
        scoreGoodsCategory.setName(model.getName());
        scoreGoodsCategory.setCategoryIden(model.getCategoryIden());
        scoreGoodsCategory.setParentId(model.getParentId());
        scoreGoodsCategoryMapper.updateByPrimaryKey(scoreGoodsCategory);
    }
}