mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
package com.panzhihua.service_community.service.impl;
 
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.panzhihua.common.model.vos.community.ComMngVillageVO;
import com.panzhihua.common.utlis.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.ComPropertyPublicityDTO;
import com.panzhihua.common.model.dtos.community.PageComPropertyPublicityDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngStructAreaVO;
import com.panzhihua.service_community.dao.ComMngStructAreaDAO;
import com.panzhihua.service_community.dao.ComPropertyDao;
import com.panzhihua.service_community.dao.ComPropertyPublicityDAO;
import com.panzhihua.service_community.entity.ComProperty;
import com.panzhihua.service_community.model.dos.ComMngStructAreaDO;
import com.panzhihua.service_community.model.dos.ComPropertyPublicityDO;
import com.panzhihua.service_community.service.ComPropertyPublicityService;
 
import lombok.extern.slf4j.Slf4j;
 
/**
 * @title: ComPropertyPublicityServiceImpl
 * @projectName: 成都呐喊信息技术有限公司-智慧社区项目
 * @description: 物业宣传服务实现类
 * @author: hans
 * @date: 2021/11/11 13:57
 */
@Service
@Slf4j
public class ComPropertyPublicityServiceImpl extends ServiceImpl<ComPropertyPublicityDAO, ComPropertyPublicityDO> implements ComPropertyPublicityService {
 
    @Resource
    private ComPropertyDao comPropertyDao;
    @Resource
    private ComMngStructAreaDAO comMngStructAreaDAO;
 
    /**
     * 分页查询物业宣传
     * @param pageComPropertyPublicityDTO
     * @return
     */
    @Override
    public R pageComPropertyPublicity(PageComPropertyPublicityDTO pageComPropertyPublicityDTO) {
        Long userId = pageComPropertyPublicityDTO.getUserId();
        ComProperty comProperty = comPropertyDao.selectOne(new QueryWrapper<ComProperty>().lambda().eq(ComProperty::getUserId, userId));
        if (nonNull(comProperty)) {
            //用户为物业
            pageComPropertyPublicityDTO.setPropertyId(comProperty.getId());
            pageComPropertyPublicityDTO.setVillageId(comProperty.getAreaId());
        } else {
            //非物业用户查看是否拥有菜单权限
            List<String> menuList = this.baseMapper.retrieveUserMenuList(userId);
            if (menuList.isEmpty() || !menuList.contains("物业宣传栏")) {
                return R.fail("暂无权限");
            }
        }
        Page page = new Page<>();
        page.setSize(pageComPropertyPublicityDTO.getPageSize());
        page.setCurrent(pageComPropertyPublicityDTO.getPageNum());
        return R.ok(this.baseMapper.pageComPropertyPublicity(page, pageComPropertyPublicityDTO));
    }
 
    /**
     * 新增物业宣传
     * @param comPropertyPublicityDTO
     * @return
     */
    @Override
    public R addComPropertyPublicity(ComPropertyPublicityDTO comPropertyPublicityDTO) {
        Long userId = comPropertyPublicityDTO.getUserId();
        ComProperty comProperty = comPropertyDao.selectOne(new QueryWrapper<ComProperty>().lambda().eq(ComProperty::getUserId, userId));
        if (isNull(comProperty)) {
            return R.fail("暂无权限");
        }
        comPropertyPublicityDTO.setPropertyId(comProperty.getId());
        ComPropertyPublicityDO publicityDO = new ComPropertyPublicityDO();
        BeanUtils.copyProperties(comPropertyPublicityDTO, publicityDO);
        Date nowDate = new Date();
        publicityDO.setCreatedAt(nowDate);
        publicityDO.setUpdatedAt(nowDate);
        int result = this.baseMapper.insert(publicityDO);
        if (result > 0) {
            return R.ok();
        }
        return R.fail("添加失败");
    }
 
    /**
     * 修改物业宣传
     * @param comPropertyPublicityDTO
     * @return
     */
    @Override
    public R updateComPropertyPublicity(ComPropertyPublicityDTO comPropertyPublicityDTO) {
        ComPropertyPublicityDO comPropertyPublicityDO = this.baseMapper.selectById(comPropertyPublicityDTO.getId());
        if (isNull(comPropertyPublicityDO)) {
            return R.fail("信息不存在");
        }
        BeanUtils.copyProperties(comPropertyPublicityDTO, comPropertyPublicityDO);
        comPropertyPublicityDO.setUpdatedAt(new Date());
        int result = this.baseMapper.updateById(comPropertyPublicityDO);
        if (result > 0) {
            return R.ok();
        }
        return R.fail("修改失败");
    }
 
    /**
     * 查看物业宣传信息
     * @param id
     * @return
     */
    @Override
    public R getComPropertyPublicity(Long id) {
        return R.ok(this.baseMapper.selectDetail(id));
    }
 
    /**
     * 删除物业宣传
     * @param id
     * @return
     */
    @Override
    public R deleteComPropertyPublicity(Long id) {
        this.baseMapper.deleteById(id);
        return R.ok();
    }
 
    /**
     * 物业公司列表
     *
     * @param villageId
     * @param communityId
     * @return
     */
    @Override
    public R listProperty(Long villageId, Long communityId) {
        List<ComProperty> propertyList;
        if (nonNull(villageId)) {
            propertyList = comPropertyDao.selectList(new QueryWrapper<ComProperty>().lambda()
                    .eq(ComProperty::getCommunityId, communityId).eq(ComProperty::getAreaId, villageId));
        } else {
            propertyList = comPropertyDao.selectList(new QueryWrapper<ComProperty>().lambda().eq(ComProperty::getCommunityId, communityId));
        }
        return R.ok(propertyList);
    }
 
    /**
     * 分页查询物业宣传-小程序
     * @param pageComPropertyPublicityDTO
     * @return
     */
    @Override
    public R pageComPropertyPublicityApplet(PageComPropertyPublicityDTO pageComPropertyPublicityDTO) {
        Page page = new Page<>();
        page.setSize(pageComPropertyPublicityDTO.getPageSize());
        page.setCurrent(pageComPropertyPublicityDTO.getPageNum());
        return R.ok(this.baseMapper.pageComPropertyPublicityApplet(page, pageComPropertyPublicityDTO));
    }
 
    /**
     * 增加物业宣传浏览量
     * @param id
     * @return
     */
    @Override
    public R incrView(Long id) {
        this.baseMapper.incrView(id);
        return R.ok();
    }
}