huanghongfa
2020-12-20 def38240262b4403377d4c16beac3ea048f1e658
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
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;
 
/**
 * @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 = comMngStructAreaDAO.insert(comMngStructAreaDO);
        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 (ObjectUtils.isEmpty(pageNum)||0==pageNum) {
            pageNum = 1l;
        }
        if (ObjectUtils.isEmpty(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());
    }
 
 
}