ss
jiangping
2025-07-10 c14da121eb41234a0a9016596b07592a564a212b
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
package com.doumee.service.business.impl;
 
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.InformationMapper;
import com.doumee.dao.business.model.Carousel;
import com.doumee.dao.business.model.Information;
import com.doumee.service.business.InformationService;
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 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.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 动态咨询Service实现
 * @author 江蹄蹄
 * @since 2025/06/18 09:30
 */
@Service
public class InformationServiceImpl implements InformationService {
 
    @Autowired
    private InformationMapper informationMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Override
    public Integer create(Information information) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(information)
//                || Objects.isNull(information.getSortnum())
//                || Objects.isNull(information.getReleaseDate())
                || StringUtils.isEmpty(information.getTitle())
//                || StringUtils.isEmpty(information.getContent())
//                || StringUtils.isEmpty(information.getDetail())
//                || StringUtils.isEmpty(information.getImgurl())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        information.setType(Constants.formatIntegerNum(information.getType()));
        information.setIsdeleted(Constants.ZERO);
        information.setCreateDate(new Date());
        information.setCreator(user.getId());
        informationMapper.insert(information);
        return information.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        informationMapper.update(new UpdateWrapper<Information>().lambda().set(Information::getIsdeleted,Constants.ONE).eq(Information::getId,id));
    }
 
    @Override
    public void delete(Information information) {
        UpdateWrapper<Information> deleteWrapper = new UpdateWrapper<>(information);
        informationMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }
 
    @Override
    public void updateById(Information information) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(information)
                || Objects.isNull(information.getId())
//                || Objects.isNull(information.getSortnum())
//                || Objects.isNull(information.getReleaseDate())
                || StringUtils.isEmpty(information.getTitle())
//                || StringUtils.isEmpty(information.getContent())
//                || StringUtils.isEmpty(information.getDetail())
//                || StringUtils.isEmpty(information.getImgurl())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        information.setIsdeleted(Constants.ZERO);
        information.setEditDate(new Date());
        information.setEditor(user.getId());
        informationMapper.updateById(information);
    }
 
    @Override
    public void updateByIdInBatch(List<Information> informations) {
        if (CollectionUtils.isEmpty(informations)) {
            return;
        }
        for (Information information: informations) {
            this.updateById(information);
        }
    }
 
    @Override
    public Information findById(Integer id) {
        Information information = informationMapper.selectById(id);
        if(Objects.isNull(information)&& org.apache.commons.lang3.StringUtils.isNotBlank(information.getImgurl())){
            String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
            information.setFullImgurl(fileDir + information.getImgurl());
        }
        return information;
    }
 
    @Override
    public Information findOne(Information information) {
        QueryWrapper<Information> wrapper = new QueryWrapper<>(information);
        return informationMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Information> findList(Information information) {
        QueryWrapper<Information> wrapper = new QueryWrapper<>(information);
        return informationMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<Information> findPage(PageWrap<Information> pageWrap) {
        IPage<Information> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.lambda()
                .eq(Information::getIsdeleted,Constants.ZERO)
                .eq(pageWrap.getModel().getId() != null, Information::getId, pageWrap.getModel().getId())
                .eq(pageWrap.getModel().getModule() != null, Information::getModule, pageWrap.getModel().getModule())
                .eq(pageWrap.getModel().getType() != null, Information::getType, pageWrap.getModel().getType())
                .eq(pageWrap.getModel().getStatus() != null, Information::getStatus, pageWrap.getModel().getStatus())
                .eq(pageWrap.getModel().getRemark() != null, Information::getRemark, pageWrap.getModel().getRemark())
                .like(pageWrap.getModel().getTitle() != null, Information::getTitle, pageWrap.getModel().getTitle())
                .like(pageWrap.getModel().getDetail() != null, Information::getDetail, pageWrap.getModel().getDetail())
                .like(pageWrap.getModel().getContent() != null, Information::getContent, pageWrap.getModel().getContent())
                .ge(pageWrap.getModel().getReleaseDate() != null, Information::getReleaseDate, Utils.Date.getStart(pageWrap.getModel().getReleaseDate()))
                .le(pageWrap.getModel().getReleaseDate() != null, Information::getReleaseDate, Utils.Date.getEnd(pageWrap.getModel().getReleaseDate()))
                .orderByDesc(Information::getSortnum)
        ;
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        IPage<Information> iPage =  informationMapper.selectPage(page, queryWrapper);
        String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
        for (Information information:iPage.getRecords()) {
            if(!Objects.isNull(information)&& org.apache.commons.lang3.StringUtils.isNotBlank(information.getImgurl())){
                information.setFullImgurl(fileDir + information.getImgurl());
            }
        }
        return PageData.from(iPage);
    }
 
    @Override
    public long count(Information information) {
        QueryWrapper<Information> wrapper = new QueryWrapper<>(information);
        return informationMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public void updateStatus(Information information){
        if(Objects.isNull(information)
                || Objects.isNull(information.getStatus())
                || Objects.isNull(information.getId())
                || !(Constants.equalsInteger(information.getStatus(),Constants.ZERO)
                || Constants.equalsInteger(information.getStatus(),Constants.ONE))){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        informationMapper.update(new UpdateWrapper<Information>().lambda().set(Information::getStatus,information.getStatus()).eq(Information::getId,information.getId()));
    }
}