ss
jiangping
2025-07-02 f7b760a680397fd0a3de2d8de36a2601de98530d
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
package com.doumee.service.business.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CarouselMapper;
import com.doumee.dao.business.model.Carousel;
import com.doumee.dao.dto.FootDataDTO;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.vo.FootDataVO;
import com.doumee.service.business.CarouselService;
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.doumee.service.system.SystemDictDataService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 轮播图Service实现
 * @author 江蹄蹄
 * @since 2025/06/18 09:30
 */
@Service
public class CarouselServiceImpl implements CarouselService {
 
    @Autowired
    private CarouselMapper carouselMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private SystemDictDataService systemDictDataService;
 
    @Override
    public Integer create(Carousel carousel) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(carousel)
//            || Objects.isNull(carousel.getImgurl())
            || Objects.isNull(carousel.getJumpType())
//            || Objects.isNull(carousel.getSortnum())
            || StringUtils.isEmpty(carousel.getTitle())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        carousel.setType(Constants.ZERO);
        carousel.setIsdeleted(Constants.ZERO);
        carousel.setStatus(Constants.ZERO);
        carousel.setCreateDate(new Date());
        carousel.setCreator(user.getId());
        carouselMapper.insert(carousel);
        return carousel.getId();
    }
 
 
    @Override
    public void deleteById(Integer id) {
        carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getIsdeleted,Constants.ONE).eq(Carousel::getId,id));
    }
 
    @Override
    public void delete(Carousel carousel) {
        UpdateWrapper<Carousel> deleteWrapper = new UpdateWrapper<>(carousel);
        carouselMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        carouselMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Carousel carousel) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(carousel)
                || Objects.isNull(carousel.getId())
                || Objects.isNull(carousel.getImgurl())
                || Objects.isNull(carousel.getJumpType())
                || Objects.isNull(carousel.getSortnum())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        carousel.setIsdeleted(Constants.ZERO);
        carousel.setStatus(Constants.ZERO);
        carousel.setEditDate(new Date());
        carousel.setEditor(user.getId());
        carousel.setType(null);
        carouselMapper.updateById(carousel);
    }
 
    @Override
    public void updateByIdInBatch(List<Carousel> carousels) {
        if (CollectionUtils.isEmpty(carousels)) {
            return;
        }
        for (Carousel carousel: carousels) {
            this.updateById(carousel);
        }
    }
 
 
    @Override
    public void updateStatus(Carousel carousel){
        if(Objects.isNull(carousel)
            || Objects.isNull(carousel.getStatus())
            || Objects.isNull(carousel.getId())
            || !(Constants.equalsInteger(carousel.getStatus(),Constants.ZERO)
            || Constants.equalsInteger(carousel.getStatus(),Constants.ONE))
        ){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getStatus,carousel.getStatus()).eq(Carousel::getId,carousel.getId()));
    }
 
    @Override
    public void updateSortnum(Carousel carousel){
        if(Objects.isNull(carousel)
                || Objects.isNull(carousel.getSortnum())
                || Objects.isNull(carousel.getId())
        ){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getSortnum,carousel.getSortnum()).eq(Carousel::getId,carousel.getId()));
    }
 
 
    @Override
    public Carousel findById(Integer id) {
        Carousel carousel = new Carousel();
        if(Objects.isNull(carousel)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
        this.imgFullPath(fileDir,carousel);
        return carousel;
    }
 
    public void imgFullPath(String fileDir,Carousel carousel){
        if(org.apache.commons.lang3.StringUtils.isNotBlank(carousel.getImgurl())){
            carousel.setFullImgurl(fileDir + carousel.getImgurl());
        }
        if(org.apache.commons.lang3.StringUtils.isNotBlank(carousel.getThumbnailImgurl())){
            carousel.setFullThumbnailImgurl(fileDir + carousel.getThumbnailImgurl());
        }
    }
 
    @Override
    public Carousel findOne(Carousel carousel) {
        QueryWrapper<Carousel> wrapper = new QueryWrapper<>(carousel);
        return carouselMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Carousel> findList() {
        QueryWrapper<Carousel> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Carousel::getIsdeleted,Constants.ZERO)
                .eq(Carousel::getStatus,Constants.ZERO)
                .orderByDesc(Carousel::getSortnum);
        List<Carousel> carouselList =
         carouselMapper.selectList(wrapper);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(carouselList)){
            String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
            for (Carousel carousel:carouselList) {
                this.imgFullPath(fileDir,carousel);
            }
        }
        return carouselList;
    }
  
    @Override
    public PageData<Carousel> findPage(PageWrap<Carousel> pageWrap) {
        IPage<Carousel> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<Carousel> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.lambda().eq(Carousel::getIsdeleted,Constants.ZERO)
                .eq(pageWrap.getModel().getId() != null, Carousel::getId, pageWrap.getModel().getId())
                .eq(pageWrap.getModel().getRemark() != null, Carousel::getRemark, pageWrap.getModel().getRemark())
                .like(pageWrap.getModel().getTitle() != null, Carousel::getTitle, pageWrap.getModel().getTitle())
                .eq(pageWrap.getModel().getType() != null, Carousel::getType, pageWrap.getModel().getType())
                .like(pageWrap.getModel().getDetail() != null, Carousel::getDetail, pageWrap.getModel().getDetail())
                .eq(pageWrap.getModel().getJumpType() != null, Carousel::getJumpType, pageWrap.getModel().getJumpType())
                .like(pageWrap.getModel().getContent() != null, Carousel::getContent, pageWrap.getModel().getContent())
                .eq(pageWrap.getModel().getSortnum() != null, Carousel::getSortnum, pageWrap.getModel().getSortnum())
                .eq(pageWrap.getModel().getStatus() != null, Carousel::getStatus, pageWrap.getModel().getStatus())
                .orderByDesc(Carousel::getSortnum)
 
        ;
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        IPage<Carousel> iPage =  carouselMapper.selectPage(page, queryWrapper);
        String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
        for (Carousel carousel:iPage.getRecords()) {
            this.imgFullPath(fileDir,carousel);
        }
        return PageData.from(iPage);
    }
 
    @Override
    public long count(Carousel carousel) {
        QueryWrapper<Carousel> wrapper = new QueryWrapper<>(carousel);
        return carouselMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public FootDataVO getFoodDataVO(){
        FootDataVO footDataVO = new FootDataVO();
        String path =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
        footDataVO.setFootWords(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_WORDS).getCode());
        footDataVO.setFootImgUrl(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_IMGURL).getCode());
        footDataVO.setFootFullImgUrl(path+
                footDataVO.getFootImgUrl());
        footDataVO.setFootImgUrl2(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_IMGURL2).getCode());
        footDataVO.setFootFullImgUrl2(path +
                footDataVO.getFootImgUrl2());
        footDataVO.setAddress(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ADDRESS).getCode());
        footDataVO.setLinkPhone(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.LINK_PHONE).getCode());
        footDataVO.setLinkMobile(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.LINK_MOBILE).getCode());
        SystemDictData solveScheme = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SOLVE_SCHEME);
        if(Objects.nonNull(solveScheme) & org.apache.commons.lang3.StringUtils.isNotBlank(solveScheme.getCode())){
            footDataVO.setSolveScheme(JSONArray.parseArray(solveScheme.getCode()));
        }
        SystemDictData wisdomSystem = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WISDOM_SYSTEM);
        if(Objects.nonNull(wisdomSystem) & org.apache.commons.lang3.StringUtils.isNotBlank(wisdomSystem.getCode())){
            footDataVO.setWisdomSystem(JSONArray.parseArray(wisdomSystem.getCode()));
        }
        SystemDictData honors = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.HONORS);
        if(Objects.nonNull(wisdomSystem) & org.apache.commons.lang3.StringUtils.isNotBlank(honors.getCode())){
            footDataVO.setHonors(JSONArray.parseArray(honors.getCode()));
        }
        footDataVO.setServerTime(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SERVER_TIME).getCode());
        return footDataVO;
    }
 
 
 
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void updFoodDataVO(FootDataDTO footDataDTO) {
        SystemDictData footWords = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FOOT_WORDS);
        if (Objects.nonNull(footWords)) {
            footWords.setCode(footDataDTO.getFootWords());
            systemDictDataBiz.updateById(footWords);
        }
 
        SystemDictData footImgUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FOOT_IMGURL);
        if (Objects.nonNull(footImgUrl)) {
            footImgUrl.setCode(footDataDTO.getFootImgUrl());
            systemDictDataBiz.updateById(footImgUrl);
        }
 
        SystemDictData linkPhone = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.LINK_PHONE);
        if (Objects.nonNull(linkPhone)) {
            linkPhone.setCode(footDataDTO.getLinkPhone());
            systemDictDataBiz.updateById(linkPhone);
        }
 
        SystemDictData linkMobile = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.LINK_MOBILE);
        if (Objects.nonNull(linkMobile)) {
            linkMobile.setCode(footDataDTO.getLinkMobile());
            systemDictDataBiz.updateById(linkMobile);
        }
 
        SystemDictData serverTime = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SERVER_TIME);
        if (Objects.nonNull(serverTime)) {
            serverTime.setCode(footDataDTO.getServerTime());
            systemDictDataBiz.updateById(serverTime);
        }
 
        SystemDictData address = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.ADDRESS);
        if (Objects.nonNull(address)) {
            address.setCode(footDataDTO.getAddress());
            systemDictDataBiz.updateById(address);
        }
 
        SystemDictData solveScheme = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SOLVE_SCHEME);
        if (Objects.nonNull(solveScheme)&&Objects.nonNull(footDataDTO.getSolveScheme())) {
            solveScheme.setCode(footDataDTO.getSolveScheme().toString());
            systemDictDataBiz.updateById(solveScheme);
        }
 
        SystemDictData wisdomSystem = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.WISDOM_SYSTEM);
        if (Objects.nonNull(wisdomSystem)&&Objects.nonNull(footDataDTO.getWisdomSystem())) {
            wisdomSystem.setCode(footDataDTO.getWisdomSystem().toString());
            systemDictDataBiz.updateById(wisdomSystem);
        }
        SystemDictData honors = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.HONORS);
        if (Objects.nonNull(wisdomSystem)&&Objects.nonNull(footDataDTO.getHonors())) {
            wisdomSystem.setCode(footDataDTO.getHonors().toString());
            systemDictDataBiz.updateById(wisdomSystem);
        }
    }
 
 
 
}