|
@@ -1,19 +1,25 @@
|
1
|
1
|
package com.community.huiju.service.impl;
|
2
|
2
|
|
3
|
3
|
import com.alibaba.fastjson.JSONObject;
|
4
|
|
-import com.baomidou.mybatisplus.core.conditions.query.EmptyWrapper;
|
5
|
4
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
6
|
5
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
6
|
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
7
|
7
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
8
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
9
|
+import com.baomidou.mybatisplus.core.toolkit.Constants;
|
8
|
10
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
9
|
11
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
10
|
12
|
import com.community.commom.mode.ResponseBean;
|
11
|
13
|
import com.community.commom.utils.BeanTools;
|
12
|
14
|
import com.community.huiju.dao.BuildingOwnerInfoMapper;
|
|
15
|
+import com.community.huiju.exception.WisdomException;
|
13
|
16
|
import com.community.huiju.model.BuildingOwnerInfo;
|
14
|
17
|
import com.community.huiju.service.IBuildingOwnerInfoService;
|
15
|
18
|
import com.google.common.collect.Lists;
|
16
|
19
|
import com.google.common.collect.Maps;
|
|
20
|
+import lombok.extern.slf4j.Slf4j;
|
|
21
|
+import org.apache.ibatis.binding.MapperMethod;
|
|
22
|
+import org.apache.ibatis.session.SqlSession;
|
17
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
24
|
import org.springframework.stereotype.Service;
|
19
|
25
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -21,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
21
|
27
|
import java.time.LocalDateTime;
|
22
|
28
|
import java.util.List;
|
23
|
29
|
import java.util.Map;
|
|
30
|
+import java.util.stream.Collectors;
|
24
|
31
|
|
25
|
32
|
/**
|
26
|
33
|
* <p>
|
|
@@ -31,6 +38,7 @@ import java.util.Map;
|
31
|
38
|
* @since 2018-12-18
|
32
|
39
|
*/
|
33
|
40
|
@Service("iBuildingOwnerInfoService")
|
|
41
|
+@Slf4j
|
34
|
42
|
public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoMapper, BuildingOwnerInfo> implements IBuildingOwnerInfoService {
|
35
|
43
|
|
36
|
44
|
@Autowired
|
|
@@ -62,6 +70,7 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
|
62
|
70
|
QueryWrapper<BuildingOwnerInfo> queryWrapper = new QueryWrapper<>();
|
63
|
71
|
queryWrapper.allEq(map,false);
|
64
|
72
|
queryWrapper.like(buildingOwnerInfo.getOwnerName() != null,"owner_name",buildingOwnerInfo.getOwnerName());
|
|
73
|
+
|
65
|
74
|
// 分页查询
|
66
|
75
|
IPage<BuildingOwnerInfo> infoIPage = buildingOwnerInfoMapper.selectPage(page, queryWrapper);
|
67
|
76
|
|
|
@@ -83,25 +92,23 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
|
83
|
92
|
|
84
|
93
|
@Override
|
85
|
94
|
@Transactional(rollbackFor = Exception.class)
|
86
|
|
- public ResponseBean update(String parameter) {
|
|
95
|
+ public ResponseBean update(String parameter, Integer userId) {
|
87
|
96
|
ResponseBean responseBean = new ResponseBean();
|
88
|
97
|
|
89
|
98
|
BuildingOwnerInfo buildingOwnerInfo = JSONObject.parseObject(parameter, BuildingOwnerInfo.class);
|
90
|
99
|
BuildingOwnerInfo oldBuildingOwnerInfo = buildingOwnerInfoMapper.selectById(buildingOwnerInfo.getId());
|
91
|
100
|
if (null == oldBuildingOwnerInfo) {
|
92
|
|
- responseBean.addError("数据不存在!");
|
93
|
|
- return responseBean;
|
|
101
|
+ throw new WisdomException("%s 数据不存在!", buildingOwnerInfo.getId());
|
94
|
102
|
}
|
95
|
103
|
|
96
|
104
|
BeanTools.copyProperties(buildingOwnerInfo, oldBuildingOwnerInfo);
|
97
|
105
|
|
98
|
106
|
oldBuildingOwnerInfo.setUpdateDate(LocalDateTime.now());
|
99
|
|
- // 用户
|
100
|
|
- // oldBuildingOwnerInfo.setUpdateUser();
|
|
107
|
+ oldBuildingOwnerInfo.setUpdateUser(userId);
|
101
|
108
|
|
102
|
109
|
int row = buildingOwnerInfoMapper.updateById(oldBuildingOwnerInfo);
|
103
|
110
|
if (row <= 0) {
|
104
|
|
- responseBean.addError("操作失败!");
|
|
111
|
+ throw new WisdomException("操作失败!");
|
105
|
112
|
} else {
|
106
|
113
|
responseBean.addSuccess("操作成功!");
|
107
|
114
|
}
|
|
@@ -110,15 +117,20 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
|
110
|
117
|
|
111
|
118
|
@Override
|
112
|
119
|
@Transactional(rollbackFor = Exception.class)
|
113
|
|
- public ResponseBean add(String parameter) {
|
|
120
|
+ public ResponseBean add(String parameter, Integer userId) {
|
114
|
121
|
ResponseBean responseBean = new ResponseBean();
|
115
|
122
|
|
116
|
123
|
BuildingOwnerInfo buildingOwnerInfo = JSONObject.parseObject(parameter, BuildingOwnerInfo.class);
|
|
124
|
+ // 主键是自增的, 所以设置为 null
|
117
|
125
|
buildingOwnerInfo.setId(null);
|
|
126
|
+ buildingOwnerInfo.setUpdateUser(userId);
|
|
127
|
+ buildingOwnerInfo.setUpdateDate(LocalDateTime.now());
|
|
128
|
+ buildingOwnerInfo.setCreateDate(LocalDateTime.now());
|
|
129
|
+ buildingOwnerInfo.setCreateUser(userId);
|
118
|
130
|
|
119
|
131
|
int row = buildingOwnerInfoMapper.insert(buildingOwnerInfo);
|
120
|
132
|
if (row <= 0) {
|
121
|
|
- responseBean.addError("操作失败!");
|
|
133
|
+ throw new WisdomException("操作失败!");
|
122
|
134
|
} else {
|
123
|
135
|
responseBean.addSuccess("操作成功!");
|
124
|
136
|
}
|
|
@@ -127,16 +139,56 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
|
127
|
139
|
}
|
128
|
140
|
|
129
|
141
|
@Override
|
130
|
|
- @Transactional(rollbackFor = Exception.class)
|
131
|
|
- public ResponseBean deleteByIdDatch(List<Integer> ids) {
|
132
|
|
-
|
|
142
|
+ public ResponseBean getBuildingOrUnitOrNumber(String parameter,Integer communityId) {
|
|
143
|
+
|
133
|
144
|
ResponseBean responseBean = new ResponseBean();
|
134
|
|
- int row = buildingOwnerInfoMapper.deleteBatchIds(ids);
|
135
|
|
- if (row <= 0) {
|
136
|
|
- responseBean.addError("操作失败!");
|
137
|
|
- } else {
|
138
|
|
- responseBean.addSuccess("操作成功!");
|
|
145
|
+ if (null == communityId || "".equals(communityId)) {
|
|
146
|
+ throw new WisdomException("编号:%s 小区不存在!", communityId);
|
139
|
147
|
}
|
140
|
|
- return null;
|
|
148
|
+
|
|
149
|
+ BuildingOwnerInfo buildingOwnerInfo = JSONObject.parseObject(parameter, BuildingOwnerInfo.class);
|
|
150
|
+
|
|
151
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
152
|
+
|
|
153
|
+ // 小区
|
|
154
|
+ map.put("community_id", communityId);
|
|
155
|
+ // 栋
|
|
156
|
+ map.put("building",buildingOwnerInfo.getBuilding());
|
|
157
|
+ // 单元
|
|
158
|
+ map.put("unit",buildingOwnerInfo.getUnit());
|
|
159
|
+ // 楼层
|
|
160
|
+ map.put("level",buildingOwnerInfo.getLevel());
|
|
161
|
+
|
|
162
|
+ QueryWrapper<BuildingOwnerInfo> queryWrapper = new QueryWrapper<>();
|
|
163
|
+ queryWrapper.allEq(map, false);
|
|
164
|
+
|
|
165
|
+ /**
|
|
166
|
+ * 1.如果 楼栋值不存在表示根据小区Id查询时查询楼栋!
|
|
167
|
+ * 2.如果 楼栋存在表示查询单元
|
|
168
|
+ * 3.如果 单元存在表示查询楼层
|
|
169
|
+ * 4.如果 楼层存在表示查询户号
|
|
170
|
+ *
|
|
171
|
+ * 查询户号, 依赖于前面的查询条件成立!
|
|
172
|
+ *
|
|
173
|
+ * 这里的查询都依赖于, 前面的查询条件成立! 比如 要使用条件2, 那么条件1 必须成立!
|
|
174
|
+ *
|
|
175
|
+ */
|
|
176
|
+
|
|
177
|
+ String column = null;
|
|
178
|
+ if (null == buildingOwnerInfo.getBuilding()) {
|
|
179
|
+ column = "building";
|
|
180
|
+ } else if (null == buildingOwnerInfo.getUnit()) {
|
|
181
|
+ column = "unit";
|
|
182
|
+ } else if (null == buildingOwnerInfo.getLevel()){
|
|
183
|
+ column = "level";
|
|
184
|
+ } else if (null == buildingOwnerInfo.getRoomNo()) {
|
|
185
|
+ column = "room_no";
|
|
186
|
+ }
|
|
187
|
+ queryWrapper.groupBy(column);
|
|
188
|
+ List<BuildingOwnerInfo> selectList = buildingOwnerInfoMapper.selectList(queryWrapper);
|
|
189
|
+
|
|
190
|
+ responseBean.addSuccess(selectList);
|
|
191
|
+
|
|
192
|
+ return responseBean;
|
141
|
193
|
}
|
142
|
194
|
}
|