DESKTOP-71BH0QO\L、ming
2021-04-29 35cc85225a4acfda180f67af1865eac51f3844a6
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
package com.panzhihua.service_community.service.impl;
 
import java.util.Date;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.neighbor.*;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.neighbor.*;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActNeighborCircleCommentDAO;
import com.panzhihua.common.model.vos.user.AdministratorsUserVO;
import com.panzhihua.service_community.dao.ComActNeighborCircleDAO;
import com.panzhihua.service_community.model.dos.ComActNeighborCircleDO;
import com.panzhihua.service_community.service.ComActNeighborCircleBrowseService;
import com.panzhihua.service_community.dao.*;
import com.panzhihua.service_community.model.dos.*;
import com.panzhihua.service_community.service.ComActNeighborCircleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
/**
 * @auther lyq
 * @create 2021-04-28 09:20:49
 * @describe 邻里圈表服务实现类
 */
@Slf4j
@Service
public class ComActNeighborCircleServiceImpl extends ServiceImpl<ComActNeighborCircleDAO, ComActNeighborCircleDO> implements ComActNeighborCircleService {
 
    @Resource
    private ComActNeighborCircleBrowseService comActNeighborCircleBrowseService;
 
    @Resource
    ComActNeighborCircleFabulousDAO neighborCircleFabulousDAO;
 
    @Resource
    ComActNeighborCircleBrowseDAO neighborCircleBrowseDAO;
 
    @Resource
    ComActNeighborCircleCommentDAO neighborCircleCommentDAO;
 
    @Resource
    ComActNeighborCircleCommentReplyDAO neighborCircleCommentReplyDAO;
 
    /**
     * 分页查询邻里圈列表
     *
     * @param neighborCircleAppDTO 请求参数
     * @return 邻里圈列表
     */
    @Override
    public R pageNeighborByApp(ComActNeighborCircleAppDTO neighborCircleAppDTO) {
        Page userPage = new Page(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize());
        IPage<ComActNeighborCircleAppVO> doPager = this.baseMapper.pageNeighborByApp(userPage, neighborCircleAppDTO);
        return R.ok(doPager);
    }
 
    /**
     * 用户发布邻里圈审核
     *
     * @param addNeighborCircleAppDTO 邻里圈请求参数
     * @return 发布结果
     */
    @Override
    public R addNeighborByApp(AddComActNeighborCircleAppDTO addNeighborCircleAppDTO) {
        //新增邻里圈审核
        ComActNeighborCircleDO neighborCircleDO = new ComActNeighborCircleDO();
        BeanUtils.copyProperties(addNeighborCircleAppDTO, neighborCircleDO);
        if (addNeighborCircleAppDTO.getUserId() != null) {
            neighborCircleDO.setReleaseId(addNeighborCircleAppDTO.getUserId());
        }
        if (addNeighborCircleAppDTO.getCommunityId() != null) {
            neighborCircleDO.setCommunityId(addNeighborCircleAppDTO.getCommunityId());
        }
        if (StringUtils.isNotEmpty(addNeighborCircleAppDTO.getPhone())) {
            neighborCircleDO.setReleasePhone(addNeighborCircleAppDTO.getPhone());
        }
        if (this.baseMapper.insert(neighborCircleDO) > 0) {
            return R.ok();
        } else {
            return R.fail("发布失败");
        }
    }
 
    @Override
    public R neighborDetailByApp(ComActNeighborCircleDetailAppDTO neighborCircleAppDTO) {
 
        //添加邻里圈浏览记录
        comActNeighborCircleBrowseService.addBrowseRecord(neighborCircleAppDTO.getCircleId(), neighborCircleAppDTO.getUserId());
 
        //查询邻里圈详情
        ComActNeighborCircleDetailAppVO circleDetailAppVO = this.baseMapper.neighborDetailByApp(neighborCircleAppDTO.getCircleId());
 
        //查询邻里圈下评论列表
        IPage<ComActNeighborCircleCommentAppVO> circleCommentAppPage = neighborCircleCommentDAO.pageNeighborCommentByApp(
                new Page(neighborCircleAppDTO.getPageNum(), neighborCircleAppDTO.getPageSize()), neighborCircleAppDTO.getCircleId());
        if (!circleCommentAppPage.getRecords().isEmpty()) {
            for (ComActNeighborCircleCommentAppVO circleCommentVo : circleCommentAppPage.getRecords()) {
                //查询评论下评论回复
 
 
            }
        }
 
 
        return R.ok(circleDetailAppVO);
    }
 
    @Override
    public R pageNeighborByAdmin(ComActNeighborCircleAdminDTO neighborCircleAdminDTO) {
        Page page = new Page(neighborCircleAdminDTO.getPageNum(), neighborCircleAdminDTO.getPageSize());
        IPage<ComActNeighborCircleAdminVO> doPager = this.baseMapper.pageNeighborByAdmin(page, neighborCircleAdminDTO);
        return R.ok(doPager);
    }
 
    @Override
    public R addNeighborByAdmin(AddNeighborCircleAdminVO addVO) {
        ComActNeighborCircleDO comActNeighborCircleDO = new ComActNeighborCircleDO();
        AdministratorsUserVO adminUser = this.baseMapper.selectUserByUserId(addVO.getUserId());
        if (adminUser == null) {
            return R.fail("请登录重试");
        }
        comActNeighborCircleDO.setReleaseId(addVO.getUserId());
        comActNeighborCircleDO.setReleasePhone(adminUser.getPhone());
        comActNeighborCircleDO.setCommunityId(adminUser.getCommunityId());
        comActNeighborCircleDO.setReleaseContent(addVO.getReleaseContent());
        comActNeighborCircleDO.setReleaseImages(addVO.getReleaseImages());
        comActNeighborCircleDO.setStatus(1);
        comActNeighborCircleDO.setCommentNum(0);
        comActNeighborCircleDO.setFabulousNum(0);
        comActNeighborCircleDO.setForwardNum(0);
        comActNeighborCircleDO.setViewsNum(0);
        comActNeighborCircleDO.setIsBoutique(2);
        comActNeighborCircleDO.setCreateAt(new Date());
        comActNeighborCircleDO.setLastCommentNum(0);
        comActNeighborCircleDO.setLastFabulousNum(0);
        comActNeighborCircleDO.setLastViewsNum(0);
        this.baseMapper.insert(comActNeighborCircleDO);
        return R.ok();
    }
 
    @Override
    public R changeStatusByAdmin(EditNeighborCircleAdminVO editVO) {
        ComActNeighborCircleDO neighborCircleDO = this.baseMapper.selectById(editVO.getId());
        if (neighborCircleDO == null) {
            return R.fail("id有误!");
        }
        neighborCircleDO.setStatus(editVO.getStatus());
        neighborCircleDO.setRefuseReason(editVO.getRefuseReason());
        this.baseMapper.updateById(neighborCircleDO);
        return R.ok();
    }
 
    @Override
    public R deleteByAdmin(Long id) {
        ComActNeighborCircleDO comActNeighborCircleDO = this.baseMapper.selectById(id);
        if (comActNeighborCircleDO == null) {
            return R.fail();
        }
        if (comActNeighborCircleDO.getStatus() == 1) {
            return R.fail("待审核的邻里圈不能删除");
        }
        //邻里圈删除
        this.baseMapper.deleteById(id);
        //邻里圈评论删除
        neighborCircleCommentDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleCommentDO>()
                .eq(ComActNeighborCircleCommentDO::getCircleId, id));
        //邻里圈回复删除
        neighborCircleCommentReplyDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleCommentReplyDO>()
                .eq(ComActNeighborCircleCommentReplyDO::getCircleId, id));
        //邻里圈浏览器记录
        neighborCircleBrowseDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleBrowseDO>()
                .eq(ComActNeighborCircleBrowseDO::getNeighborId, id));
        //邻里圈点赞删除 需要一层一层删
/*        neighborCircleFabulousDAO.delete(new LambdaQueryWrapper<ComActNeighborCircleFabulousDO>()
                .eq(ComActNeighborCircleFabulousDO::get))*/
        return R.ok();
 
    }
 
    @Override
    public R detailNeighborByAdmin(Long id) {
        ComActNeighborCircleDO comActNeighborCircleDO = this.baseMapper.selectById(id);
        if (comActNeighborCircleDO == null) {
            return R.fail("id有误");
        }
        DetailNeighborCircleAdminVO vo = new DetailNeighborCircleAdminVO();
        BeanUtils.copyProperties(comActNeighborCircleDO, vo);
        return R.ok(vo);
    }
 
    @Override
    public R detailNeighborAllCommentByAdmin(DetailNeighborAllCommentByAdminDTO dto) {
        ComActNeighborCircleDO comActNeighborCircleDO = this.baseMapper.selectById(dto.getId());
        if (comActNeighborCircleDO == null) {
            return R.fail("id有误");
        }
        Page<ComActNeighborCircleCommentDO> page = new Page<>(dto.getPageNum(),dto.getPageSize());
        //1、先查询所有该邻里圈_的评论
        IPage<ComActNeighborCommentByAdminVO> commentDOIPage = neighborCircleCommentDAO.selectPageDetailNeighborComment(page,dto);
        return R.ok(commentDOIPage);
    }
 
    @Override
    public R changeCommentStatusByAdmin(ChangeCommentStatusByAdminVO dto) {
        ComActNeighborCircleCommentDO commentDO = neighborCircleCommentDAO.selectById(dto.getId());
        if(commentDO==null){
            return R.fail("id有误!");
        }
        commentDO.setStatus(dto.getStatus());
        neighborCircleCommentDAO.updateById(commentDO);
        return R.ok();
    }
 
    @Override
    public R detailNeighborCommentByAdmin(Long id) {
        ComActNeighborCircleCommentDO commentDO = neighborCircleCommentDAO.selectById(id);
        if(commentDO==null){
            return R.fail("id有误!");
        }
        ComActNeighborCommentByAdminVO vo = new ComActNeighborCommentByAdminVO();
        BeanUtils.copyProperties(commentDO,vo);
        return R.ok(vo);
    }
 
    @Override
    public R detailNeighborCommentAllReply(DetailNeighborCommentReplyByAdminDTO dto) {
        Page<ComActNeighborCircleCommentReplyDO> page = new Page<>(dto.getPageNum(),dto.getPageSize());
        Page<ComActNeighborCommentReplyByAdminVO> replyPage = neighborCircleCommentReplyDAO.selectListByComment(page, dto);
        return R.ok(replyPage);
    }
 
    @Override
    public R detailNeighborCommentReply(Long id) {
        ComActNeighborCircleCommentReplyDO replyDO = neighborCircleCommentReplyDAO.selectById(id);
        if(replyDO==null){
            return R.fail("id有误!");
        }
        ComActNeighborCircleCommentReplyDO vo = new ComActNeighborCircleCommentReplyDO();
        BeanUtils.copyProperties(replyDO,vo);
        return R.ok(vo);
    }
 
    @Override
    public R changeCommentReplyStatusByAdmin(ChangeCommentReplyStatusByAdminVO changeStatusReplyVO) {
        ComActNeighborCircleCommentReplyDO replyDO = neighborCircleCommentReplyDAO.selectById(changeStatusReplyVO.getId());
        if(replyDO==null){
            return R.fail("id有误!");
        }
        replyDO.setStatus(changeStatusReplyVO.getStatus());
        neighborCircleCommentReplyDAO.updateById(replyDO);
        return R.ok();
    }
}