瀏覽代碼

楼栋资料库 完成!

weiximei 6 年之前
父節點
當前提交
a4d261a88e

+ 3
- 0
CODE/smart-community/community-common/src/main/java/com/community/commom/session/UserElement.java 查看文件

@@ -20,6 +20,9 @@ public class UserElement implements Serializable {
20 20
     /** 用户唯一标识符 **/
21 21
     private Integer id;
22 22
 
23
+    /** 小区id **/
24
+    private Integer communityId;
25
+
23 26
     /** 用户名 **/
24 27
     private String userName;
25 28
 

+ 11
- 1
CODE/smart-community/property-api/src/main/java/com/community/huiju/common/base/BaseController.java 查看文件

@@ -2,6 +2,7 @@ package com.community.huiju.common.base;
2 2
 
3 3
 import com.community.commom.constant.Constant;
4 4
 import com.community.commom.session.UserElement;
5
+import com.community.huiju.exception.WisdomException;
5 6
 
6 7
 import javax.servlet.http.HttpSession;
7 8
 
@@ -11,8 +12,17 @@ import javax.servlet.http.HttpSession;
11 12
  */
12 13
 public class BaseController {
13 14
 
15
+    /**
16
+     * 获取 UserElement
17
+     * @param session
18
+     * @return
19
+     */
14 20
     protected UserElement getUserElement(HttpSession session){
15
-        session.getAttribute(Constant.)
21
+        UserElement userElement = (UserElement) session.getAttribute(Constant.WEB_PROPERTY_USER_SESSION);
22
+        if (null == userElement) {
23
+            throw new WisdomException("用户凭证不存在!");
24
+        }
25
+        return userElement;
16 26
     }
17 27
 
18 28
 }

+ 37
- 7
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java 查看文件

@@ -2,6 +2,7 @@ package com.community.huiju.controller;
2 2
 
3 3
 
4 4
 import com.community.commom.mode.ResponseBean;
5
+import com.community.commom.session.UserElement;
5 6
 import com.community.huiju.common.base.BaseController;
6 7
 import com.community.huiju.model.BuildingOwnerInfo;
7 8
 import com.community.huiju.service.IBuildingOwnerInfoService;
@@ -15,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
15 16
 import org.springframework.web.bind.annotation.RequestMethod;
16 17
 import org.springframework.web.bind.annotation.RestController;
17 18
 
19
+import javax.servlet.http.HttpSession;
18 20
 import java.util.List;
21
+import java.util.stream.Collectors;
19 22
 
20 23
 /**
21 24
  * <p>
@@ -56,9 +59,10 @@ public class BuildingOwnerInfoController extends BaseController {
56 59
             @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
57 60
     })
58 61
     @RequestMapping(value = "/building/update", method = RequestMethod.PUT)
59
-    public ResponseBean update(@RequestBody String parameter){
62
+    public ResponseBean update(@RequestBody String parameter, HttpSession session){
60 63
         ResponseBean responseBean = new ResponseBean();
61
-        responseBean = iBuildingOwnerInfoService.update(parameter);
64
+        UserElement userElement = getUserElement(session);
65
+        responseBean = iBuildingOwnerInfoService.update(parameter,userElement.getId());
62 66
         return responseBean;
63 67
     }
64 68
 
@@ -71,21 +75,47 @@ public class BuildingOwnerInfoController extends BaseController {
71 75
             @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
72 76
     })
73 77
     @RequestMapping(value = "/building/add", method = RequestMethod.POST)
74
-    public ResponseBean add(String parameter){
78
+    public ResponseBean add(@RequestBody String parameter, HttpSession session){
75 79
         ResponseBean responseBean = new ResponseBean();
76
-        responseBean = iBuildingOwnerInfoService.add(parameter);
80
+        UserElement userElement = getUserElement(session);
81
+        responseBean = iBuildingOwnerInfoService.add(parameter,userElement.getId());
77 82
         return responseBean;
78 83
     }
79 84
 
80 85
     @ApiOperation(value = "批量删除楼栋业主信息", notes = "批量删除楼栋业主信息")
81 86
     @ApiImplicitParams({
82
-            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "ids"),
87
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "ids",value = "id集合"),
83 88
             @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
84 89
     })
85 90
     @RequestMapping(value = "/building/delete", method = RequestMethod.DELETE)
86
-    public ResponseBean delete(@RequestBody List<Integer> ids){
91
+    public ResponseBean delete(@RequestBody List<Integer> ids, HttpSession session){
87 92
         ResponseBean responseBean = new ResponseBean();
88
-        responseBean = iBuildingOwnerInfoService.deleteByIdDatch(ids);
93
+        UserElement userElement = getUserElement(session);
94
+        List<BuildingOwnerInfo> infoList = ids.stream().map(e->{
95
+            BuildingOwnerInfo buildingOwnerInfo = new BuildingOwnerInfo();
96
+            buildingOwnerInfo.setId(e);
97
+            buildingOwnerInfo.setVerifyStatus("2");
98
+            buildingOwnerInfo.setUpdateUser(userElement.getId());
99
+            return buildingOwnerInfo;
100
+        }).collect(Collectors.toList());
101
+        boolean result = iBuildingOwnerInfoService.updateBatchById(infoList);
102
+        if (result) {
103
+            responseBean.addSuccess("操作成功!");
104
+        }else {
105
+            responseBean.addError("操作失败!");
106
+        }
107
+        return responseBean;
108
+    }
109
+
110
+    @ApiOperation(value = "查询 楼栋/单元/楼层/户号", notes = "查询 楼栋/单元/楼层/户号")
111
+    @ApiImplicitParams({
112
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "building楼层;" +
113
+                    "unit单元;level楼层;roomNo户号")
114
+    })
115
+    @RequestMapping(value = "/building/info",method = RequestMethod.POST)
116
+    public ResponseBean buildingUnitNumber(@RequestBody String parameter){
117
+        ResponseBean responseBean = new ResponseBean();
118
+
89 119
         return responseBean;
90 120
     }
91 121
 

+ 58
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/exception/ExceptionHandleAdice.java 查看文件

@@ -0,0 +1,58 @@
1
+package com.community.huiju.exception;
2
+
3
+import com.community.commom.constant.Constant;
4
+import com.community.commom.mode.ResponseBean;
5
+import lombok.extern.slf4j.Slf4j;
6
+import org.springframework.validation.ObjectError;
7
+import org.springframework.web.bind.MethodArgumentNotValidException;
8
+import org.springframework.web.bind.annotation.ControllerAdvice;
9
+import org.springframework.web.bind.annotation.ExceptionHandler;
10
+import org.springframework.web.bind.annotation.ResponseBody;
11
+
12
+import java.util.List;
13
+
14
+/**
15
+ * 统一异常出口
16
+ * @author weiximei
17
+ */
18
+@ControllerAdvice
19
+@ResponseBody
20
+@Slf4j
21
+public class ExceptionHandleAdice {
22
+
23
+
24
+    @ExceptionHandler(Exception.class)
25
+    public ResponseBean handleException(Exception e){
26
+        log.error(e.getMessage(),e);
27
+        ResponseBean response = new ResponseBean();
28
+        response.addError(Constant.REQUEST_ERROR,"系统异常,请稍后重试!");
29
+        return response;
30
+    }
31
+
32
+
33
+    @ExceptionHandler(WisdomException.class)
34
+    public ResponseBean handleException(WisdomException e) {
35
+        log.error(e.getMessage(),e);
36
+        ResponseBean response = new ResponseBean();
37
+        response.addError(e.getMessage());
38
+        return response;
39
+    }
40
+
41
+
42
+    @ExceptionHandler(MethodArgumentNotValidException.class)
43
+    public ResponseBean handlelllewgalParamException(MethodArgumentNotValidException e){
44
+        ResponseBean response = new ResponseBean();
45
+
46
+        List<ObjectError> errors  =e.getBindingResult().getAllErrors();
47
+        String message = "参数不合法";
48
+        if (errors.size() >0) {
49
+            message = errors.get(0).getDefaultMessage();
50
+        }
51
+
52
+        response.addError(message);
53
+
54
+        return response;
55
+    }
56
+
57
+
58
+}

+ 23
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/exception/WisdomException.java 查看文件

@@ -0,0 +1,23 @@
1
+package com.community.huiju.exception;
2
+
3
+
4
+/**
5
+ * @author weiximei
6
+ */
7
+public class WisdomException extends RuntimeException {
8
+
9
+
10
+    public WisdomException(String msg, Throwable t) {
11
+        super(msg, t);
12
+    }
13
+
14
+    public WisdomException(String msg) {
15
+        super(msg);
16
+    }
17
+
18
+    public WisdomException(String msg, Object ...args) {
19
+        this(String.format(msg, args));
20
+    }
21
+
22
+
23
+}

+ 10
- 5
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IBuildingOwnerInfoService.java 查看文件

@@ -26,22 +26,27 @@ public interface IBuildingOwnerInfoService extends IService<BuildingOwnerInfo> {
26 26
     /**
27 27
      * 修改 楼栋业主信息
28 28
      * @param parameter
29
+     * @param userId
29 30
      * @return
30 31
      */
31
-    ResponseBean update(String parameter);
32
+    ResponseBean update(String parameter, Integer userId);
32 33
 
33 34
     /**
34 35
      * 添加 楼栋业主信息
35 36
      * @param parameter
37
+     * @param userId
36 38
      * @return
37 39
      */
38
-    ResponseBean add(String parameter);
40
+    ResponseBean add(String parameter, Integer userId);
39 41
 
40 42
     /**
41
-     * 根据Id 批量删除
42
-     * @param ids
43
+     * 查询 楼栋/单元/楼层/号
44
+     *
45
+     *  楼栋是根据 小区ID查询
46
+     *
47
+     * @param parameter
43 48
      * @return
44 49
      */
45
-    ResponseBean deleteByIdDatch(List<Integer> ids);
50
+    ResponseBean getBuildingOrUnitOrNumber(String parameter, Integer communityId);
46 51
 
47 52
 }

+ 70
- 18
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BuildingOwnerInfoServiceImpl.java 查看文件

@@ -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
 }

+ 31
- 0
CODE/smart-community/property-api/src/main/resources/log4j.properties 查看文件

@@ -0,0 +1,31 @@
1
+log4j.rootLogger=info,A1,R
2
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
3
+log4j.appender.A1.Target=System.out
4
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
5
+log4j.appender.A1.layout.ConversionPattern=%-5p%x [%t] %d - %c %m%n  
6
+
7
+log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
8
+log4j.appender.R.File=../logs/resold_admin_.log
9
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
10
+log4j.appender.R.Append = true
11
+log4j.appender.R.ImmediateFlush = true
12
+log4j.appender.R.DatePattern = '.' yyyy - MM - dd '.txt'
13
+log4j.appender.R.layout.ConversionPattern=%-5p%x [%t] %d -%c %m%n
14
+
15
+#log4j.logger.com.ibatis=DEBUG
16
+log4j.logger.org.springframework.transaction.support.TransactionSynchronizationManager = INFO
17
+log4j.logger.java.sql.Connection=DEBUG
18
+log4j.logger.java.sql.Statement=DEBUG
19
+log4j.logger.java.sql.PreparedStatement=DEBUG
20
+
21
+###############Log4j 4 SQL Output start################# #DEBUG
22
+log4j.logger.com.**.dao=INFO
23
+log4j.logger.com.springframework=DEBUG
24
+log4j.logger.com.ibatis=DEBUG  
25
+log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG  
26
+log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG  
27
+log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
28
+log4j.logger.java.sql.ResultSet=DEBUG
29
+log4j.logger.org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl=DEBUG
30
+log4j.logger.java.sql=DEBUG,CONSOLE 
31
+###############Log4j 4 SQL Output end###################