a
jiangping
2023-10-16 a69578ed877252e70d45d4753258b3d7b6937606
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
package doumeemes.service.ext.impl;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import doumeemes.core.model.LoginUserInfo;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.redis.RedisUtil;
import doumeemes.dao.ext.CategoryExtMapper;
import doumeemes.dao.ext.CompanyExtMapper;
import doumeemes.dao.ext.dto.QueryBarcodeParamExtDTO;
import doumeemes.dao.ext.dto.QueryCategoryExtDTO;
import doumeemes.dao.ext.dto.QueryCompanyExtDTO;
import doumeemes.dao.ext.vo.BarcodeParamExtListVO;
import doumeemes.dao.ext.vo.CategoryExtListVO;
import doumeemes.dao.ext.vo.CompanyExtListVO;
import doumeemes.service.business.CategoryService;
import doumeemes.service.ext.CategoryExtService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 设置类分类信息表Service实现
 * @author 江蹄蹄
 * @date 2022/04/27 16:15
 */
@Service
public class CategoryExtServiceImpl implements CategoryExtService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private CompanyExtMapper companyExtMapper;
    @Autowired
    private CategoryExtMapper categoryExtMapper;
 
 
    @Override
    public PageData<CategoryExtListVO> findPage(PageWrap<QueryCategoryExtDTO> pageWrap) {
        PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
        List<CategoryExtListVO> result = categoryExtMapper.selectList(pageWrap.getModel());
        return PageData.from(new PageInfo<>(result));
    }
 
    @Override
    public List<CategoryExtListVO> findList(QueryCategoryExtDTO queryCategoryExtDTO) {
        List<CategoryExtListVO> result = categoryExtMapper.selectList(queryCategoryExtDTO);
        return result;
    }
 
    @Override
    public List<CategoryExtListVO> getListByType(String type,Integer rootDepartId,String cateType,String id) {
        QueryCategoryExtDTO queryCategoryExtDTO=new QueryCategoryExtDTO();
        queryCategoryExtDTO.setDeleted(Constants.ZERO);
        queryCategoryExtDTO.setType(type);
        queryCategoryExtDTO.setRootDepartId(rootDepartId);
        queryCategoryExtDTO.setCateType(cateType);
        if(StringUtils.isNotEmpty(id)){
            queryCategoryExtDTO.setParentId(Integer.valueOf(id));
        }
        List<CategoryExtListVO> result = categoryExtMapper.selectList(queryCategoryExtDTO);
        return result;
    }
 
    @Override
    public  void loadCom(CompanyExtListVO com ) {
        QueryCategoryExtDTO d = new QueryCategoryExtDTO();
        d.setDeleted(Constants.ZERO);
        d.setCompanyId(com.getId());
        //查询全部企业部门信息
        List<CategoryExtListVO> clist = categoryExtMapper.selectList(d);
        //加入redis缓存,以企业id为编码,缓存企业分类
        RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+com.getId(),clist);
    }
    @Override
    public  CategoryExtListVO getByCategoryId(Integer comId, Integer id){
        if(comId==null || id == null){
            return null;
        }
        //查询缓存数据
        List<CategoryExtListVO> clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+comId,ArrayList.class);
        if(clist!=null){
            for(CategoryExtListVO model:clist){
                if(Constants.equalsInteger(id,model.getId())){
                    return model;
                }
            }
        }
        return null;
    }
    @Override
    public     CategoryExtListVO getByCategoryId(Integer comId, Integer id,List<CategoryExtListVO> clist){
        if(comId==null || id == null){
            return null;
        }
        //查询缓存数据
        if(clist!=null){
            for(CategoryExtListVO model:clist){
                if(Constants.equalsInteger(id,model.getId())){
                    return model;
                }
            }
        }
        return null;
    }
    @Override
    public List<CategoryExtListVO> treeCategoryList(QueryCategoryExtDTO param) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        param.setDeleted(Constants.ZERO);
        param.setRootDepartId(user.getRootDepartment().getId());
        param.setCateType("0");
        List<CategoryExtListVO> list = categoryExtMapper.selectList(param);
        List<CategoryExtListVO> bigAllList = getAllListByParentId("0",list);
 
            //查询所有的大类
            getCategoryDhildrenTree(bigAllList,list);
 
        return bigAllList;
    }
    private void getCategoryDhildrenTree(List<CategoryExtListVO> blist, List<CategoryExtListVO> list) {
        if(blist!=null && blist.size()>0){
            for(CategoryExtListVO d : blist){
                    List<CategoryExtListVO> clist = getDepartListByParentId(d.getId(),list);
                    d.setChildrenList(clist);
                getCategoryDhildrenTree(clist,list);
            }
 
        }
    }
 
 
    private List<CategoryExtListVO> getDepartListByParentId(Integer pId, List<CategoryExtListVO> clist) {
        List<CategoryExtListVO> list = null;
        if(clist!= null){
            for(CategoryExtListVO d :clist){
                if(Constants.equalsInteger(d.getParentId(),pId)){
                    if(list == null){
                        list = new ArrayList<>();
                    }
                    list.add(d);
                }
            }
        }
        return  list;
    }
 
 
    private List<CategoryExtListVO> getAllListByParentId(String type, List<CategoryExtListVO> clist) {
        List<CategoryExtListVO> list = null;
        if(clist!= null){
            for(CategoryExtListVO d :clist){
                if(StringUtils.equals(type ,d.getType())){
                    if(list == null){
                        list = new ArrayList<>();
                    }
                    list.add(d);
                }
            }
        }
        return  list;
    }
 
    @Override
    public  void loadAll() {
        QueryCompanyExtDTO dto = new QueryCompanyExtDTO();
        dto.setDeleted(Constants.ZERO);
        //查询全部企业信息
        List<CompanyExtListVO> list =    companyExtMapper.selectList(dto);
        if(list != null && list.size()>0){
            QueryCategoryExtDTO d = new QueryCategoryExtDTO();
            d.setDeleted(Constants.ZERO);
            //查询全部企业信息
            List<CategoryExtListVO> codeList =    categoryExtMapper.selectList(d);
            for(CompanyExtListVO com : list){
                //当前企业的全部分类信息
                List<CategoryExtListVO> clist = getAllByComId(com.getId(),codeList);
                //加入redis缓存,以企业id为编码,缓存企业二维码
                RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+com.getId(),clist);
            }
        }
    }
 
    private List<CategoryExtListVO> getAllByComId(Integer id, List<CategoryExtListVO> alllist) {
        List<CategoryExtListVO> list = null;
        if(alllist!= null){
            for(CategoryExtListVO d :alllist){
                if(d.getCompanyId()!=null && Constants.equalsInteger(id,d.getCompanyId())){
                    if(list == null){
                        list = new ArrayList<>();
                    }
                    list.add(d);
                }
            }
        }
        return  list;
    }
}