k94314517
2024-07-26 34486b14dd302b23d4baea8194f45cff9a429d73
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
package com.doumee.service.business.impl;
 
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BjParamMapper;
import com.doumee.dao.business.model.BjParam;
import com.doumee.dao.business.model.News;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.response.BjParamConfigResponse;
import com.doumee.service.business.BjParamService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * 志邦家选计算器配置信息表报价Service实现
 * @author 江蹄蹄
 * @date 2024/07/05 15:39
 */
@Service
public class BjParamServiceImpl implements BjParamService {
 
    @Autowired
    private BjParamMapper bjParamMapper;
 
    @Override
    public Long create(BjParam bjParam) {
        LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        bjParam.setIsdeleted(Constants.ZERO);
        bjParam.setEditor(userInfo.getId());
        bjParam.setCreator(userInfo.getId());
        bjParam.setCreateDate(new Date());
        bjParam.setEditDate(bjParam.getCreateDate());
        bjParamMapper.insert(bjParam);
        return bjParam.getId();
    }
 
    @Override
    public void deleteById(Long id) {
        LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        bjParamMapper.update(null,new UpdateWrapper<BjParam>().lambda()
                .set(BjParam::getIsdeleted,Constants.ONE )
                .set(BjParam::getEditor,userInfo.getId() )
                .set(BjParam::getEditDate,new Date() )
                .eq(BjParam::getParentId,id)
                .or().eq(BjParam::getId,id));
    }
 
    @Override
    public void delete(BjParam bjParam) {
        UpdateWrapper<BjParam> deleteWrapper = new UpdateWrapper<>(bjParam);
        bjParamMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for(Long id : ids){
            deleteById(id);
        }
    }
 
    @Override
    public void updateById(BjParam bjParam) {
        LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        bjParam.setEditor(userInfo.getId());
        bjParam.setEditDate(new Date());
        bjParamMapper.updateById(bjParam);
    }
 
    @Override
    public void updateByIdInBatch(List<BjParam> bjParams) {
        if (CollectionUtils.isEmpty(bjParams)) {
            return;
        }
        for (BjParam bjParam: bjParams) {
            this.updateById(bjParam);
        }
    }
 
    @Override
    public BjParam findById(Long id) {
        return bjParamMapper.selectById(id);
    }
 
    @Override
    public BjParam findOne(BjParam bjParam) {
        QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam);
        return bjParamMapper.selectOne(wrapper);
    }
 
    @Override
    public List<BjParam> findList(BjParam bjParam) {
        QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam);
        return bjParamMapper.selectList(wrapper);
    }
 
    @Override
    public   List<BjParam> findTree() {
        BjParam param = new BjParam();
        param.setIsdeleted(Constants.ZERO);
        MPJLambdaWrapper<BjParam> wrapper = new MPJLambdaWrapper<BjParam>();
        wrapper.selectAll(BjParam.class)
                .selectAs(SystemUser::getRealname,BjParam::getEditorName)
                .leftJoin(SystemUser.class,SystemUser::getId,BjParam::getEditor)
                .eq(BjParam::getIsdeleted,Constants.ZERO )
                .orderByAsc(BjParam::getSortnum);
        List<BjParam> list =  bjParamMapper.selectJoinList(BjParam.class,wrapper);
        List<BjParam> treeList = new ArrayList<>();
        if(list!=null && list.size()>0){
            for(BjParam model : list){
                if(model.getParentId() == null){
                    initModelChildData(model,list);
                    treeList.add(model);
                }
            }
        }
 
        return treeList;
    }
 
    private void initModelChildData(BjParam param, List<BjParam> list) {
        List<BjParam> clist = new ArrayList<>();
        param.setHasChildren(Boolean.TRUE);
        if(list!=null && list.size()>0){
            for(BjParam model : list){
                if(model.getParentId() != null &&  param.getId()!=null && param.getId().equals(model.getParentId())){
                    param.setHasChildren(Boolean.FALSE);
                    model.setHasChildren(Boolean.TRUE);
                    clist.add(model);
                }
            }
        }
        param.setChildren(clist);
    }
 
    @Override
    public PageData<BjParam> findPage(PageWrap<BjParam> pageWrap) {
        IPage<BjParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<BjParam> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(BjParam::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(BjParam::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(BjParam::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(BjParam::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(BjParam::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(BjParam::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(BjParam::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(BjParam::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.lambda().eq(BjParam::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getInfo() != null) {
            queryWrapper.lambda().eq(BjParam::getInfo, pageWrap.getModel().getInfo());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().eq(BjParam::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRate() != null) {
            queryWrapper.lambda().eq(BjParam::getRate, pageWrap.getModel().getRate());
        }
        if (pageWrap.getModel().getParentId() != null) {
            queryWrapper.lambda().eq(BjParam::getParentId, pageWrap.getModel().getParentId());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(BjParam::getSortnum, pageWrap.getModel().getSortnum());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(bjParamMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(BjParam bjParam) {
        QueryWrapper<BjParam> wrapper = new QueryWrapper<>(bjParam);
        return bjParamMapper.selectCount(wrapper);
    }
 
 
    @Override
    public BjParamConfigResponse getBjParamConfig(){
        BjParamConfigResponse bjParamConfigResponse = new BjParamConfigResponse();
        List<BjParam> bjParamList =  bjParamMapper.selectList(new QueryWrapper<BjParam>()
               .lambda().eq(BjParam::getIsdeleted,Constants.ZERO).orderByAsc(BjParam::getSortnum));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(bjParamList)){
            List<BjParam> roughList = bjParamList.stream().filter(i->i.getType().equals(Constants.ZERO+"")&& StringUtils.isEmpty(i.getParentId())).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(roughList)){
                for (BjParam bjParam:roughList) {
                    bjParam.setChildren(
                            bjParamList.stream().filter(i->i.getType().equals(Constants.ZERO+"")
                                    && Objects.nonNull(i.getParentId())
                                    && i.getParentId().equals(bjParam.getId())).collect(Collectors.toList())
                    );
                }
            }
            List<BjParam> exquisiteList = bjParamList.stream().filter(i->i.getType().equals(Constants.ONE+"")&& StringUtils.isEmpty(i.getParentId())).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(exquisiteList)){
                for (BjParam bjParam:exquisiteList) {
                    bjParam.setChildren(
                            bjParamList.stream().filter(i->i.getType().equals(Constants.ONE+"")
                                    && Objects.nonNull(i.getParentId())
                                    && i.getParentId().equals(bjParam.getId())).collect(Collectors.toList())
                    );
                }
            }
            bjParamConfigResponse.setRoughList(roughList);
            bjParamConfigResponse.setExquisiteList(exquisiteList);
        }
        return bjParamConfigResponse;
    }
 
 
 
}