dingxin 6 years ago
parent
commit
d53c455907

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/CommunityController.java View File

@@ -32,7 +32,7 @@ public class CommunityController {
32 32
 	@ApiOperation(value = "根据小区名获取小区列表", notes = "根据小区名获取小区列表")
33 33
 	@ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "String", name = "communityName", value = "小区名字") })
34 34
 	@RequestMapping(value = "/communitys",method = RequestMethod.GET)
35
-	public ResponseBean getCommunitys(@RequestParam String communityName){
35
+	public ResponseBean getCommunitys(@RequestParam(required = false) String communityName){
36 36
 		ResponseBean responseBean = new ResponseBean();
37 37
 		List<ToCommunities> communitiesList = communityService.getCommunitys(communityName);
38 38
 		responseBean.addSuccess(communitiesList);

+ 1
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/CommunityServiceI.java View File

@@ -5,6 +5,7 @@ import com.community.huiju.model.ToCommunities;
5 5
 import java.util.List;
6 6
 
7 7
 public interface CommunityServiceI {
8
+
8 9
 	List<ToCommunities> getCommunitys(String communityName);
9 10
 
10 11
 	/**

+ 26
- 3
CODE/smart-community/community-common/src/main/java/com/community/commom/utils/BeanTools.java View File

@@ -3,11 +3,14 @@ package com.community.commom.utils;
3 3
 import jodd.bean.BeanCopy;
4 4
 import jodd.typeconverter.TypeConverterManager;
5 5
 import org.apache.commons.collections.BeanMap;
6
+import org.springframework.beans.BeanUtils;
7
+import org.springframework.beans.BeanWrapper;
8
+import org.springframework.beans.BeanWrapperImpl;
9
+import org.springframework.util.Assert;
6 10
 
11
+import java.beans.PropertyDescriptor;
7 12
 import java.lang.reflect.Method;
8
-import java.util.HashMap;
9
-import java.util.Iterator;
10
-import java.util.Map;
13
+import java.util.*;
11 14
 
12 15
 @SuppressWarnings("deprecation")
13 16
 public final class BeanTools {
@@ -112,4 +115,24 @@ public final class BeanTools {
112 115
         }
113 116
         return map;
114 117
     }
118
+
119
+    public static String[] getNullPropertyNames (Object source) {
120
+        final BeanWrapper src = new BeanWrapperImpl(source);
121
+        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
122
+
123
+        Set<String> emptyNames = new HashSet<String>();
124
+        for(java.beans.PropertyDescriptor pd : pds) {
125
+            Object srcValue = src.getPropertyValue(pd.getName());
126
+            if (srcValue == null) {
127
+                emptyNames.add(pd.getName());
128
+            }
129
+        }
130
+        String[] result = new String[emptyNames.size()];
131
+        return emptyNames.toArray(result);
132
+    }
133
+
134
+    public static void copyProperties(Object src, Object target) {
135
+        BeanUtils.copyProperties(src, target, getNullPropertyNames(src));
136
+    }
137
+
115 138
 }

+ 2
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/PropertyApplication.java View File

@@ -5,10 +5,12 @@ import org.springframework.boot.SpringApplication;
5 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 7
 import org.springframework.cloud.openfeign.EnableFeignClients;
8
+import org.springframework.transaction.annotation.EnableTransactionManagement;
8 9
 
9 10
 @EnableDiscoveryClient
10 11
 @SpringBootApplication
11 12
 @EnableFeignClients
13
+@EnableTransactionManagement
12 14
 public class PropertyApplication {
13 15
 
14 16
 	public static void main(String[] args) {

+ 10
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/common/base/BaseController.java View File

@@ -1,8 +1,18 @@
1 1
 package com.community.huiju.common.base;
2 2
 
3
+import com.community.commom.constant.Constant;
4
+import com.community.commom.session.UserElement;
5
+
6
+import javax.servlet.http.HttpSession;
7
+
3 8
 /**
4 9
  * @author FXF
5 10
  * @date 2018-12-18
6 11
  */
7 12
 public class BaseController {
13
+
14
+//    protected UserElement getUserElement(HttpSession session){
15
+//        //session.getAttribute(Constant.)
16
+//    }
17
+
8 18
 }

+ 35
- 2
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java View File

@@ -3,6 +3,7 @@ package com.community.huiju.controller;
3 3
 
4 4
 import com.community.commom.mode.ResponseBean;
5 5
 import com.community.huiju.common.base.BaseController;
6
+import com.community.huiju.model.BuildingOwnerInfo;
6 7
 import com.community.huiju.service.IBuildingOwnerInfoService;
7 8
 import io.swagger.annotations.Api;
8 9
 import io.swagger.annotations.ApiImplicitParam;
@@ -14,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
14 15
 import org.springframework.web.bind.annotation.RequestMethod;
15 16
 import org.springframework.web.bind.annotation.RestController;
16 17
 
18
+import java.util.List;
19
+
17 20
 /**
18 21
  * <p>
19 22
  * 楼栋业主资料信息表 前端控制器
@@ -46,13 +49,43 @@ public class BuildingOwnerInfoController extends BaseController {
46 49
 
47 50
     @ApiOperation(value = "修改楼栋业务信息", notes = "修改楼栋业主信息")
48 51
     @ApiImplicitParams({
49
-            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter",value = "building栋;" +
52
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter",value = "id编号;building栋;" +
50 53
                     "unit单元;level楼层;roomNo户号;" +
51 54
                     "ownerName业主姓名;" +
52
-                    "ownerTel业主手机号")
55
+                    "ownerTel业主手机号"),
56
+            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
53 57
     })
58
+    @RequestMapping(value = "update", method = RequestMethod.PUT)
54 59
     public ResponseBean update(@RequestBody String parameter){
55 60
         ResponseBean responseBean = new ResponseBean();
61
+        responseBean = iBuildingOwnerInfoService.update(parameter);
62
+        return responseBean;
63
+    }
64
+
65
+    @ApiOperation(value = "添加楼栋业务信息", notes = "添加楼栋业务信息")
66
+    @ApiImplicitParams({
67
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id编号;building栋;" +
68
+                    "unit单元;level楼层;roomNo户号;" +
69
+                    "ownerName业主姓名;" +
70
+                    "ownerTel业主手机号"),
71
+            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
72
+    })
73
+    @RequestMapping(value = "add", method = RequestMethod.POST)
74
+    public ResponseBean add(String parameter){
75
+        ResponseBean responseBean = new ResponseBean();
76
+        responseBean = iBuildingOwnerInfoService.add(parameter);
77
+        return responseBean;
78
+    }
79
+
80
+    @ApiOperation(value = "批量删除楼栋业主信息", notes = "批量删除楼栋业主信息")
81
+    @ApiImplicitParams({
82
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "ids"),
83
+            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
84
+    })
85
+    @RequestMapping(value = "delete", method = RequestMethod.DELETE)
86
+    public ResponseBean delete(@RequestBody List<Integer> ids){
87
+        ResponseBean responseBean = new ResponseBean();
88
+        responseBean = iBuildingOwnerInfoService.deleteByIdDatch(ids);
56 89
         return responseBean;
57 90
     }
58 91
 

+ 14
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IBuildingOwnerInfoService.java View File

@@ -30,4 +30,18 @@ public interface IBuildingOwnerInfoService extends IService<BuildingOwnerInfo> {
30 30
      */
31 31
     ResponseBean update(String parameter);
32 32
 
33
+    /**
34
+     * 添加 楼栋业主信息
35
+     * @param parameter
36
+     * @return
37
+     */
38
+    ResponseBean add(String parameter);
39
+
40
+    /**
41
+     * 根据Id 批量删除
42
+     * @param ids
43
+     * @return
44
+     */
45
+    ResponseBean deleteByIdDatch(List<Integer> ids);
46
+
33 47
 }

+ 45
- 5
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BuildingOwnerInfoServiceImpl.java View File

@@ -8,15 +8,17 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
8 8
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
9 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10 10
 import com.community.commom.mode.ResponseBean;
11
+import com.community.commom.utils.BeanTools;
11 12
 import com.community.huiju.dao.BuildingOwnerInfoMapper;
12 13
 import com.community.huiju.model.BuildingOwnerInfo;
13 14
 import com.community.huiju.service.IBuildingOwnerInfoService;
14 15
 import com.google.common.collect.Lists;
15 16
 import com.google.common.collect.Maps;
16
-import org.springframework.beans.BeanUtils;
17 17
 import org.springframework.beans.factory.annotation.Autowired;
18 18
 import org.springframework.stereotype.Service;
19
+import org.springframework.transaction.annotation.Transactional;
19 20
 
21
+import java.time.LocalDateTime;
20 22
 import java.util.List;
21 23
 import java.util.Map;
22 24
 
@@ -80,6 +82,7 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
80 82
 
81 83
 
82 84
     @Override
85
+    @Transactional(rollbackFor = Exception.class)
83 86
     public ResponseBean update(String parameter) {
84 87
         ResponseBean responseBean = new ResponseBean();
85 88
 
@@ -90,13 +93,50 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<BuildingOwnerInfoM
90 93
             return responseBean;
91 94
         }
92 95
 
93
-        BeanUtils.copyProperties(buildingOwnerInfo, oldBuildingOwnerInfo);
94
-        int row = buildingOwnerInfoMapper.updateById(buildingOwnerInfo);
96
+        BeanTools.copyProperties(buildingOwnerInfo, oldBuildingOwnerInfo);
97
+
98
+        oldBuildingOwnerInfo.setUpdateDate(LocalDateTime.now());
99
+        // 用户
100
+        // oldBuildingOwnerInfo.setUpdateUser();
101
+
102
+        int row = buildingOwnerInfoMapper.updateById(oldBuildingOwnerInfo);
95 103
         if (row <= 0) {
96
-            responseBean.addError("更新失败!");
104
+            responseBean.addError("操作失败!");
97 105
         } else {
98
-            responseBean.addSuccess("更新成功!");
106
+            responseBean.addSuccess("操作成功!");
99 107
         }
100 108
         return responseBean;
101 109
     }
110
+
111
+    @Override
112
+    @Transactional(rollbackFor = Exception.class)
113
+    public ResponseBean add(String parameter) {
114
+        ResponseBean responseBean = new ResponseBean();
115
+
116
+        BuildingOwnerInfo buildingOwnerInfo = JSONObject.parseObject(parameter, BuildingOwnerInfo.class);
117
+        buildingOwnerInfo.setId(null);
118
+
119
+        int row = buildingOwnerInfoMapper.insert(buildingOwnerInfo);
120
+        if (row <= 0) {
121
+            responseBean.addError("操作失败!");
122
+        } else {
123
+            responseBean.addSuccess("操作成功!");
124
+        }
125
+
126
+        return responseBean;
127
+    }
128
+
129
+    @Override
130
+    @Transactional(rollbackFor = Exception.class)
131
+    public ResponseBean deleteByIdDatch(List<Integer> ids) {
132
+        
133
+        ResponseBean responseBean = new ResponseBean();
134
+        int row = buildingOwnerInfoMapper.deleteBatchIds(ids);
135
+        if (row <= 0) {
136
+            responseBean.addError("操作失败!");
137
+        } else {
138
+            responseBean.addSuccess("操作成功!");
139
+        }
140
+        return null;
141
+    }
102 142
 }