huanghongfa
2020-12-29 60ba6abd93f8b80c99543fad618f4d62d801d31a
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
package com.panzhihua.service_community.service.impl;
 
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.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.BatchhouseVO;
import com.panzhihua.common.model.vos.community.ComActDynVO;
import com.panzhihua.common.model.vos.community.ComMngStructAreaVO;
import com.panzhihua.service_community.dao.ComMngStructAreaDAO;
import com.panzhihua.service_community.model.dos.ComMngStructAreaDO;
import com.panzhihua.service_community.service.ComMngStructAreaService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 小区
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-12-15 15:48
 **/
@Service
public class ComMngStructAreaServiceImpl implements ComMngStructAreaService {
    @Resource
    private ComMngStructAreaDAO comMngStructAreaDAO;
    /**
     * 新增小区
     *
     * @param comMngStructAreaVO 小区信息
     * @return 新增结果
     */
    @Override
    public R addArea(ComMngStructAreaVO comMngStructAreaVO) {
        ComMngStructAreaDO comMngStructAreaDO=new ComMngStructAreaDO();
        BeanUtils.copyProperties(comMngStructAreaVO,comMngStructAreaDO);
        long areaCode=510000510400000001l;//攀枝花区域地址编码+000001
        ComMngStructAreaDO comMngStructAreaDO1 = comMngStructAreaDAO.selectOne(new QueryWrapper<ComMngStructAreaDO>().lambda().orderByDesc(ComMngStructAreaDO::getAreaCode).last(" limit 1 "));
        if (!ObjectUtils.isEmpty(comMngStructAreaDO1)) {
             areaCode = Long.valueOf(comMngStructAreaDO1.getAreaCode())+1;
        }
        comMngStructAreaDO.setAreaCode(areaCode+"");
        int insert = 0;
        try {
            insert = comMngStructAreaDAO.insert(comMngStructAreaDO);
        } catch (Exception e) {
            if (e.getMessage().contains("unique_address_detail")) {
                return R.fail("小区地址已经存在");
            }
        }
        if (insert>0) {
            return R.ok(areaCode);
        }
        return R.fail();
    }
 
    /**
     * 分页查询小区
     *
     * @param comMngStructAreaVO 查询参数
     * @return 分页结果
     */
    @Override
    public R pageArea(ComMngStructAreaVO comMngStructAreaVO) {
        Page page = new Page<>();
        Long pageNum = comMngStructAreaVO.getPageNum();
        Long pageSize = comMngStructAreaVO.getPageSize();
        if (null==pageNum||0==pageNum) {
            pageNum = 1l;
        }
        if (null==pageSize||0==pageSize) {
            pageSize = 10l;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        IPage<ComActDynVO> iPage = comMngStructAreaDAO.pageArea(page, comMngStructAreaVO);
        return R.ok(iPage);
    }
 
    /**
     * 编辑小区
     *
     * @param comMngStructAreaVO 编辑内容
     * @return 编辑结果
     */
    @Override
    public R putArea(ComMngStructAreaVO comMngStructAreaVO) {
        ComMngStructAreaDO comMngStructAreaDO=new ComMngStructAreaDO();
        BeanUtils.copyProperties(comMngStructAreaVO,comMngStructAreaDO);
        int update = comMngStructAreaDAO.update(comMngStructAreaDO, new UpdateWrapper<ComMngStructAreaDO>().lambda().eq(ComMngStructAreaDO::getAreaCode, comMngStructAreaVO.getAreaCode()));
        if (update>0) {
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 删除小区
     *
     * @param comMngStructAreaVO 地址编码
     * @return 删除结果
     */
    @Override
    public R deleteArea(ComMngStructAreaVO comMngStructAreaVO) {
        int delete = comMngStructAreaDAO.delete(new QueryWrapper<ComMngStructAreaDO>().lambda().eq(ComMngStructAreaDO::getAreaCode, comMngStructAreaVO.getAreaCode()));
        if (delete>0) {
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 查询小区信息
     *
     * @param areaCode 小区地址编码
     * @return 小区信息
     */
    @Override
    public R selectAreaByAreaCode(String areaCode) {
        ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectOne(new QueryWrapper<ComMngStructAreaDO>().lambda().eq(ComMngStructAreaDO::getAreaCode, areaCode));
        if (ObjectUtils.isEmpty(comMngStructAreaDO)) {
            return R.fail();
        }
        return R.ok(comMngStructAreaDO);
    }
 
    /**
     * 获取小区的地址编码
     *
     * @param areaId 小区id
     * @return 小区地址编码
     */
    @Override
    public R selectAreaById(Long areaId) {
        ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(areaId);
        if (ObjectUtils.isEmpty(comMngStructAreaDO)) {
            return R.fail("小区不存在");
        }
        return R.ok(comMngStructAreaDO.getAreaCode());
    }
 
    /**
     * 查询小区
     *
     * @param communityId 社区id
     * @return 小区集合
     */
    @Override
    public R listArea(Long communityId) {
        List<ComMngStructAreaVO> comMngStructAreaVOS=new ArrayList<>();
        List<ComMngStructAreaDO> comMngStructAreaDOS = comMngStructAreaDAO.selectList(new QueryWrapper<ComMngStructAreaDO>().lambda().eq(ComMngStructAreaDO::getCommunityId, communityId));
        if (!ObjectUtils.isEmpty(comMngStructAreaDOS)) {
            comMngStructAreaDOS.forEach(comMngStructAreaDO -> {
                ComMngStructAreaVO comMngStructAreaVO=new ComMngStructAreaVO();
                BeanUtils.copyProperties(comMngStructAreaDO,comMngStructAreaVO);
                comMngStructAreaVOS.add(comMngStructAreaVO);
            });
 
        }
        return R.ok(comMngStructAreaVOS);
    }
 
    /**
     * 小区详情
     *
     * @param areaId 小区id
     * @return 小区信息
     */
    @Override
    public R detailArea(Long areaId) {
        ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(areaId);
        if (ObjectUtils.isEmpty(comMngStructAreaDO)) {
            return R.fail("小区不存在");
        }
        ComMngStructAreaVO comMngStructAreaVO=new ComMngStructAreaVO();
        BeanUtils.copyProperties(comMngStructAreaDO,comMngStructAreaVO);
        return R.ok(comMngStructAreaVO);
    }
 
 
}