大理接口 社区相应功能接口 对接功能实现以及测试完善
diff --git a/src/main/java/com/supwisdom/dlpay/hk/Test/ApiServiceTest.java b/src/main/java/com/supwisdom/dlpay/hk/Test/ApiServiceTest.java
new file mode 100644
index 0000000..98ec71d
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/Test/ApiServiceTest.java
@@ -0,0 +1,129 @@
+package com.supwisdom.dlpay.hk.Test;
+
+import com.google.gson.Gson;
+import com.supwisdom.dlpay.DoorApplication;
+import com.supwisdom.dlpay.hk.bean.ApiToken;
+import com.supwisdom.dlpay.hk.bean.CommunityBean;
+import com.supwisdom.dlpay.hk.bean.CommunityIdBean;
+import com.supwisdom.dlpay.hk.common.Resp;
+import com.supwisdom.dlpay.hk.domain.TCommunity;
+import com.supwisdom.dlpay.hk.domain.THKBuilding;
+import com.supwisdom.dlpay.hk.service.ApiService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ActiveProfiles("devel-pg")
+@SpringBootTest
+public class ApiServiceTest {
+ private static String token = "";
+
+ @Autowired
+ ApiService apiService;
+
+ @Before
+ public void token(){
+ token = "9bd89e10-4c27-40aa-bb6f-89c057f6085b";
+ }
+
+ @Test
+ public void getToken(){
+
+ try {
+ ApiToken token = apiService.getToken("f2a70c45594f44e7a7468a5fcd9d5b62", "7f99dc28bcaa46aeb4596fe607ae95e1");
+ String access_token = token.getAccess_token();
+ System.out.println(access_token);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void addCommunities(){
+ TCommunity community = new TCommunity();
+ //community.setCommunityName("1230测试社区1");
+ //community.setProvinceCode("130000");
+ //community.setAddressDetail("1230测试社区街道地址1");
+ //communityId:32c23747137c4aa1965260de179e8975
+ //community.setCommunityName("1230测试社区2");
+ //community.setProvinceCode("130000");
+ //community.setAddressDetail("1230测试社区街道地址2");
+ //{"code":200,"message":"操作成功","data":{"communityId":"94279c6b4c81403ea97a17e447464b16"}}
+ community.setCommunityName("1230测试社区3");
+ community.setProvinceCode("130000");
+ community.setAddressDetail("1230测试社区街道地址3");
+ //{"code":200,"message":"操作成功","data":{"communityId":"b55e5cbdcdf8437c840afeb77fc97134"}}
+ try {
+ Resp<CommunityIdBean> resp = apiService.addCommunities("9bd89e10-4c27-40aa-bb6f-89c057f6085b", community);
+ Gson gson = new Gson();
+ String data = gson.toJson(resp.getData());
+ CommunityIdBean bean = gson.fromJson(data, CommunityIdBean.class);
+ System.out.println(bean.getCommunityId());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deleteCommunities(){
+ String communityId = "b55e5cbdcdf8437c840afeb77fc97134";
+
+ try {
+ Resp resp = apiService.deleteCommunities(token, communityId);
+ System.out.println(resp.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void updateCommunities(){
+ CommunityBean bean = new CommunityBean();
+ bean.setCommunityId("94279c6b4c81403ea97a17e447464b16");
+ bean.setCommunityName("1230测试社区2改");
+ bean.setProvinceCode("130000");
+ bean.setAddressDetail("1230测试社区街道地址2改");
+
+ try {
+ Resp resp = apiService.updateCommunities(token, bean);
+ System.out.println(resp.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void communitiesList(){
+ try {
+ Resp resp = apiService.communitiesList(token);
+ System.out.println(resp.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void addBuildings(){
+ THKBuilding building = new THKBuilding();
+ building.setCommunityId("a095174cb8974523a9d9b63e8448c151");
+ building.setBuildingName("1230测试楼栋1");
+ building.setBuildingNumber("1");
+ building.setFloorUpCount("10");
+ building.setFloorDownCount("1");
+ building.setFloorFamilyCount("5");
+ building.setBuildingUnitSize("3");
+
+ try {
+ Resp resp = apiService.addBuildings(token, building);
+ System.out.println(resp.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/bean/ApiToken.java b/src/main/java/com/supwisdom/dlpay/hk/bean/ApiToken.java
new file mode 100644
index 0000000..82d86b6
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/bean/ApiToken.java
@@ -0,0 +1,50 @@
+package com.supwisdom.dlpay.hk.bean;
+
+public class ApiToken {
+ private String access_token;
+ private String token_type;
+ private String expires_in;
+ private String scope;
+
+ public ApiToken() {
+ }
+
+ public ApiToken(String access_token, String token_type, String expires_in, String scope) {
+ this.access_token = access_token;
+ this.token_type = token_type;
+ this.expires_in = expires_in;
+ this.scope = scope;
+ }
+
+ public String getAccess_token() {
+ return access_token;
+ }
+
+ public void setAccess_token(String access_token) {
+ this.access_token = access_token;
+ }
+
+ public String getToken_type() {
+ return token_type;
+ }
+
+ public void setToken_type(String token_type) {
+ this.token_type = token_type;
+ }
+
+ public String getExpires_in() {
+ return expires_in;
+ }
+
+ public void setExpires_in(String expires_in) {
+ this.expires_in = expires_in;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public void setScope(String scope) {
+ this.scope = scope;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityBean.java b/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityBean.java
new file mode 100644
index 0000000..2f43f6f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityBean.java
@@ -0,0 +1,130 @@
+package com.supwisdom.dlpay.hk.bean;
+
+public class CommunityBean {
+ private String communityId;
+ private String communityName;
+ private String provinceCode;
+ private String cityCode;
+ private String countyCode;
+ private String addressDetail;
+ private String communitySquareMeter;
+ private String longitude;
+ private String latitude;
+ private String chargePersonId;
+ private String phoneNumber;
+ private String communityRemark;
+
+ public CommunityBean() {
+ }
+
+ public CommunityBean(String communityId, String communityName, String provinceCode, String cityCode, String countyCode, String addressDetail, String communitySquareMeter, String longitude, String latitude, String chargePersonId, String phoneNumber, String communityRemark) {
+ this.communityId = communityId;
+ this.communityName = communityName;
+ this.provinceCode = provinceCode;
+ this.cityCode = cityCode;
+ this.countyCode = countyCode;
+ this.addressDetail = addressDetail;
+ this.communitySquareMeter = communitySquareMeter;
+ this.longitude = longitude;
+ this.latitude = latitude;
+ this.chargePersonId = chargePersonId;
+ this.phoneNumber = phoneNumber;
+ this.communityRemark = communityRemark;
+ }
+
+ public String getCommunityId() {
+ return communityId;
+ }
+
+ public void setCommunityId(String communityId) {
+ this.communityId = communityId;
+ }
+
+ public String getCommunityName() {
+ return communityName;
+ }
+
+ public void setCommunityName(String communityName) {
+ this.communityName = communityName;
+ }
+
+ public String getProvinceCode() {
+ return provinceCode;
+ }
+
+ public void setProvinceCode(String provinceCode) {
+ this.provinceCode = provinceCode;
+ }
+
+ public String getCityCode() {
+ return cityCode;
+ }
+
+ public void setCityCode(String cityCode) {
+ this.cityCode = cityCode;
+ }
+
+ public String getCountyCode() {
+ return countyCode;
+ }
+
+ public void setCountyCode(String countyCode) {
+ this.countyCode = countyCode;
+ }
+
+ public String getAddressDetail() {
+ return addressDetail;
+ }
+
+ public void setAddressDetail(String addressDetail) {
+ this.addressDetail = addressDetail;
+ }
+
+ public String getCommunitySquareMeter() {
+ return communitySquareMeter;
+ }
+
+ public void setCommunitySquareMeter(String communitySquareMeter) {
+ this.communitySquareMeter = communitySquareMeter;
+ }
+
+ public String getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+
+ public String getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+
+ public String getChargePersonId() {
+ return chargePersonId;
+ }
+
+ public void setChargePersonId(String chargePersonId) {
+ this.chargePersonId = chargePersonId;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public String getCommunityRemark() {
+ return communityRemark;
+ }
+
+ public void setCommunityRemark(String communityRemark) {
+ this.communityRemark = communityRemark;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityIdBean.java b/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityIdBean.java
new file mode 100644
index 0000000..325f134
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/bean/CommunityIdBean.java
@@ -0,0 +1,22 @@
+package com.supwisdom.dlpay.hk.bean;
+
+import java.io.Serializable;
+
+public class CommunityIdBean implements Serializable {
+ private String communityId;
+
+ public CommunityIdBean() {
+ }
+
+ public CommunityIdBean(String communityId) {
+ this.communityId = communityId;
+ }
+
+ public String getCommunityId() {
+ return communityId;
+ }
+
+ public void setCommunityId(String communityId) {
+ this.communityId = communityId;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/domain/TCommunity.java b/src/main/java/com/supwisdom/dlpay/hk/domain/TCommunity.java
new file mode 100644
index 0000000..ee50074
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/domain/TCommunity.java
@@ -0,0 +1,152 @@
+package com.supwisdom.dlpay.hk.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_COMMUNITY")
+public class TCommunity {
+
+ private String unionId;
+ private String communityName;
+ private String provinceCode;
+ private String cityCode;
+ private String countyCode;
+ private String addressDetail;
+ private String communitySquareMeter;
+ private String longitude;
+ private String latitude;
+ private String chargePersonId;
+ private String phoneNumber;
+ private String communityRemark;
+
+ public TCommunity() {
+ }
+
+ public TCommunity(String unionId, String communityName, String provinceCode, String cityCode, String countyCode, String addressDetail, String communitySquareMeter, String longitude, String latitude, String chargePersonId, String phoneNumber, String communityRemark) {
+ this.unionId = unionId;
+ this.communityName = communityName;
+ this.provinceCode = provinceCode;
+ this.cityCode = cityCode;
+ this.countyCode = countyCode;
+ this.addressDetail = addressDetail;
+ this.communitySquareMeter = communitySquareMeter;
+ this.longitude = longitude;
+ this.latitude = latitude;
+ this.chargePersonId = chargePersonId;
+ this.phoneNumber = phoneNumber;
+ this.communityRemark = communityRemark;
+ }
+
+
+ @Id
+ @Column(name = "UNIONID", unique = true, nullable = false, length = 64)
+ public String getUnionId() {
+ return unionId;
+ }
+
+ public void setUnionId(String unionId) {
+ this.unionId = unionId;
+ }
+
+ @Column(name = "COMMUNITYNAME", length = 10)
+ public String getCommunityName() {
+ return communityName;
+ }
+
+ public void setCommunityName(String communityName) {
+ this.communityName = communityName;
+ }
+
+ @Column(name = "PROVINCECODE", length = 6)
+ public String getProvinceCode() {
+ return provinceCode;
+ }
+
+ public void setProvinceCode(String provinceCode) {
+ this.provinceCode = provinceCode;
+ }
+
+ @Column(name = "CITYCODE", length = 6)
+ public String getCityCode() {
+ return cityCode;
+ }
+
+ public void setCityCode(String cityCode) {
+ this.cityCode = cityCode;
+ }
+
+ @Column(name = "COUNTYCODE", length = 6)
+ public String getCountyCode() {
+ return countyCode;
+ }
+
+ public void setCountyCode(String countyCode) {
+ this.countyCode = countyCode;
+ }
+
+ @Column(name = "ADDRESSDETAIL", length = 50)
+ public String getAddressDetail() {
+ return addressDetail;
+ }
+
+ public void setAddressDetail(String addressDetail) {
+ this.addressDetail = addressDetail;
+ }
+
+ @Column(name = "COMMUNITYSQUAREMETER", length = 10)
+ public String getCommunitySquareMeter() {
+ return communitySquareMeter;
+ }
+
+ public void setCommunitySquareMeter(String communitySquareMeter) {
+ this.communitySquareMeter = communitySquareMeter;
+ }
+
+ @Column(name = "LONGITUDE", length = 16)
+ public String getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+
+ @Column(name = "LATITUDE", length = 16)
+ public String getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+
+ @Column(name = "CHARGEPERSONID", length = 32)
+ public String getChargePersonId() {
+ return chargePersonId;
+ }
+
+ public void setChargePersonId(String chargePersonId) {
+ this.chargePersonId = chargePersonId;
+ }
+
+ @Column(name = "PHONENUMBER", length = 20)
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ @Column(name = "COMMUNITYREMARK", length = 100)
+ public String getCommunityRemark() {
+ return communityRemark;
+ }
+
+ public void setCommunityRemark(String communityRemark) {
+ this.communityRemark = communityRemark;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/domain/THKBuilding.java b/src/main/java/com/supwisdom/dlpay/hk/domain/THKBuilding.java
new file mode 100644
index 0000000..6013f5f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/domain/THKBuilding.java
@@ -0,0 +1,122 @@
+package com.supwisdom.dlpay.hk.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_HK_BUILDING")
+public class THKBuilding {
+
+ private String unionId;
+ private String communityId;
+ private String buildingName;
+ private String buildingNumber;
+ private String floorUpCount;
+ private String floorDownCount;
+ private String floorFamilyCount;
+ private String buildingUnitSize;
+ private String buildingRemark;
+
+
+ public THKBuilding() {
+ }
+
+ public THKBuilding(String unionId, String communityId, String buildingName, String buildingNumber, String floorUpCount, String floorDownCount, String floorFamilyCount, String buildingUnitSize, String buildingRemark) {
+ this.unionId = unionId;
+ this.communityId = communityId;
+ this.buildingName = buildingName;
+ this.buildingNumber = buildingNumber;
+ this.floorUpCount = floorUpCount;
+ this.floorDownCount = floorDownCount;
+ this.floorFamilyCount = floorFamilyCount;
+ this.buildingUnitSize = buildingUnitSize;
+ this.buildingRemark = buildingRemark;
+ }
+
+
+ @Id
+ @Column(name = "UNIONID", unique = true, nullable = false, length = 64)
+ public String getUnionId() {
+ return unionId;
+ }
+
+ public void setUnionId(String unionId) {
+ this.unionId = unionId;
+ }
+
+ @Column(name = "COMMUNITYID", length = 32)
+ public String getCommunityId() {
+ return communityId;
+ }
+
+ public void setCommunityId(String communityId) {
+ this.communityId = communityId;
+ }
+
+ @Column(name = "BUILDINGNAME", length = 10)
+ public String getBuildingName() {
+ return buildingName;
+ }
+
+ public void setBuildingName(String buildingName) {
+ this.buildingName = buildingName;
+ }
+
+ @Column(name = "BUILDINGNUMBER", length = 4)
+ public String getBuildingNumber() {
+ return buildingNumber;
+ }
+
+ public void setBuildingNumber(String buildingNumber) {
+ this.buildingNumber = buildingNumber;
+ }
+
+ @Column(name = "FLOORUPCOUNT", length = 4)
+ public String getFloorUpCount() {
+ return floorUpCount;
+ }
+
+ public void setFloorUpCount(String floorUpCount) {
+ this.floorUpCount = floorUpCount;
+ }
+
+ @Column(name = "FLOORDOWNCOUNT", length = 4)
+ public String getFloorDownCount() {
+ return floorDownCount;
+ }
+
+ public void setFloorDownCount(String floorDownCount) {
+ this.floorDownCount = floorDownCount;
+ }
+
+ @Column(name = "FLOORFAMILYCOUNT", length = 4)
+ public String getFloorFamilyCount() {
+ return floorFamilyCount;
+ }
+
+ public void setFloorFamilyCount(String floorFamilyCount) {
+ this.floorFamilyCount = floorFamilyCount;
+ }
+
+ @Column(name = "BUILDINGUNITSIZE", length = 4)
+ public String getBuildingUnitSize() {
+ return buildingUnitSize;
+ }
+
+ public void setBuildingUnitSize(String buildingUnitSize) {
+ this.buildingUnitSize = buildingUnitSize;
+ }
+
+ @Column(name = "BUILDINGREMARK", length = 25)
+ public String getBuildingRemark() {
+ return buildingRemark;
+ }
+
+ public void setBuildingRemark(String buildingRemark) {
+ this.buildingRemark = buildingRemark;
+ }
+
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/domain/TRoom.java b/src/main/java/com/supwisdom/dlpay/hk/domain/TRoom.java
new file mode 100644
index 0000000..159552f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/domain/TRoom.java
@@ -0,0 +1,75 @@
+package com.supwisdom.dlpay.hk.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_ROOM")
+public class TRoom {
+
+ private String unionId;
+ private String unitId;
+ private String floorNumber;
+ private String roomNumber;
+ private String roomName;
+
+
+ public TRoom() {
+ }
+
+ public TRoom(String unionId, String unitId, String floorNumber, String roomNumber, String roomName) {
+ this.unionId = unionId;
+ this.unitId = unitId;
+ this.floorNumber = floorNumber;
+ this.roomNumber = roomNumber;
+ this.roomName = roomName;
+ }
+
+ @Id
+ @Column(name = "UNIONID", unique = true, nullable = false, length = 64)
+ public String getUnionId() {
+ return unionId;
+ }
+
+ public void setUnionId(String unionId) {
+ this.unionId = unionId;
+ }
+
+ @Column(name = "UNITID",length = 32)
+ public String getUnitId() {
+ return unitId;
+ }
+
+ public void setUnitId(String unitId) {
+ this.unitId = unitId;
+ }
+
+ @Column(name = "FLOORNUMBER",length = 4)
+ public String getFloorNumber() {
+ return floorNumber;
+ }
+
+ public void setFloorNumber(String floorNumber) {
+ this.floorNumber = floorNumber;
+ }
+
+ @Column(name = "ROOMNUMBER",length = 4)
+ public String getRoomNumber() {
+ return roomNumber;
+ }
+
+ public void setRoomNumber(String roomNumber) {
+ this.roomNumber = roomNumber;
+ }
+
+ @Column(name = "ROOMNAME",length = 64)
+ public String getRoomName() {
+ return roomName;
+ }
+
+ public void setRoomName(String roomName) {
+ this.roomName = roomName;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/domain/TUnit.java b/src/main/java/com/supwisdom/dlpay/hk/domain/TUnit.java
new file mode 100644
index 0000000..7faab6f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/domain/TUnit.java
@@ -0,0 +1,64 @@
+package com.supwisdom.dlpay.hk.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_UNIT")
+public class TUnit {
+
+ private String unionId;
+ private String buildingId;
+ private String unitName;
+ private String unitNumber;
+
+
+ public TUnit() {
+ }
+
+ public TUnit(String unionId, String buildingId, String unitName, String unitNumber) {
+ this.unionId = unionId;
+ this.buildingId = buildingId;
+ this.unitName = unitName;
+ this.unitNumber = unitNumber;
+ }
+
+ @Id
+ @Column(name = "UNIONID", unique = true, nullable = false, length = 64)
+ public String getUnionId() {
+ return unionId;
+ }
+
+ public void setUnionId(String unionId) {
+ this.unionId = unionId;
+ }
+
+ @Column(name = "BUILDINGID",length = 32)
+ public String getBuildingId() {
+ return buildingId;
+ }
+
+ public void setBuildingId(String buildingId) {
+ this.buildingId = buildingId;
+ }
+
+ @Column(name = "UNITNAME",length = 10)
+ public String getUnitName() {
+ return unitName;
+ }
+
+ public void setUnitName(String unitName) {
+ this.unitName = unitName;
+ }
+
+ @Column(name = "UNITNUMBER",length = 4)
+ public String getUnitNumber() {
+ return unitNumber;
+ }
+
+ public void setUnitNumber(String unitNumber) {
+ this.unitNumber = unitNumber;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/service/ApiService.java b/src/main/java/com/supwisdom/dlpay/hk/service/ApiService.java
new file mode 100644
index 0000000..1af3337
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/service/ApiService.java
@@ -0,0 +1,56 @@
+package com.supwisdom.dlpay.hk.service;
+
+import com.supwisdom.dlpay.hk.bean.ApiToken;
+import com.supwisdom.dlpay.hk.bean.CommunityBean;
+import com.supwisdom.dlpay.hk.common.Resp;
+import com.supwisdom.dlpay.hk.domain.TCommunity;
+import com.supwisdom.dlpay.hk.domain.THKBuilding;
+import com.supwisdom.dlpay.hk.domain.TRoom;
+import com.supwisdom.dlpay.hk.domain.TUnit;
+
+public interface ApiService {
+
+ public ApiToken getToken(String id, String secret) throws Exception;
+
+ /******社区******/
+
+ //新增社区
+ public Resp addCommunities(String token, TCommunity community) throws Exception;
+
+ //删除社区
+ public Resp deleteCommunities(String token,String communityId) throws Exception;
+
+ //修改社区
+ public Resp updateCommunities(String token, CommunityBean bean) throws Exception;
+
+ //查询此租户下所有社区
+ public Resp communitiesList(String token) throws Exception;
+
+
+ /******房屋******/
+
+ //新增楼栋
+ public Resp addBuildings(String token, THKBuilding building) throws Exception;
+
+ //新增单元
+ public Resp addUnits(String token, TUnit unit) throws Exception;
+
+ //新增户室
+ public Resp addRooms(String token, TRoom room) throws Exception;
+
+ //根据编号查询户室
+ public Resp findRoomsByNumber(String token,String communityId,String buildingNumber,String unitNumber,String roomNumber) throws Exception;
+
+ //根据户室ID查询户室
+ public Resp findRoomsById(String token,String roomId) throws Exception;
+
+ //删除楼栋
+ public Resp deleteBuildings(String token,String buildingId) throws Exception;
+
+ //删除单元
+ public Resp deleteUnits(String token,String unitId) throws Exception;
+
+ //删除户室
+ public Resp deleteRooms(String token,String roomId) throws Exception;
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/hk/service/impl/ApiServiceImpl.java b/src/main/java/com/supwisdom/dlpay/hk/service/impl/ApiServiceImpl.java
new file mode 100644
index 0000000..44c8471
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/hk/service/impl/ApiServiceImpl.java
@@ -0,0 +1,178 @@
+package com.supwisdom.dlpay.hk.service.impl;
+
+import com.google.gson.Gson;
+import com.supwisdom.dlpay.hk.bean.ApiToken;
+import com.supwisdom.dlpay.hk.bean.CommunityBean;
+import com.supwisdom.dlpay.hk.common.Constant;
+import com.supwisdom.dlpay.hk.common.Resp;
+import com.supwisdom.dlpay.hk.domain.TCommunity;
+import com.supwisdom.dlpay.hk.domain.THKBuilding;
+import com.supwisdom.dlpay.hk.domain.TRoom;
+import com.supwisdom.dlpay.hk.domain.TUnit;
+import com.supwisdom.dlpay.hk.service.ApiService;
+import com.supwisdom.dlpay.util.HTTPSClientUtil;
+import com.supwisdom.dlpay.util.HTTPSTrustClient;
+import org.apache.http.client.HttpClient;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class ApiServiceImpl implements ApiService {
+
+ private static HttpClient httpClient = null;
+
+ private static Map<String, String> paramHeader = new HashMap<>();
+
+ private static Map<String, String> paramBody = new HashMap<>();
+
+ private static void initHttpClient(){
+ try {
+ httpClient = new HTTPSTrustClient().init();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ static {
+ initHttpClient();
+ }
+
+ @Override
+ public ApiToken getToken(String id, String secret) throws Exception{
+ String url = Constant.TOKEN;
+ paramHeader.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
+
+ paramBody.put("client_id", id);
+ paramBody.put("client_secret", secret);
+ paramBody.put("grant_type", "client_credentials");
+ paramBody.put("scope", "app");
+
+ String result = HTTPSClientUtil.doPost(httpClient, url, paramHeader, paramBody);
+
+ Gson gson = new Gson();
+ ApiToken apiToken = gson.fromJson(result, ApiToken.class);
+ return apiToken;
+ }
+
+ @Override
+ public Resp addCommunities(String token, TCommunity community) throws Exception {
+ String url =Constant.ADD_COMMUNITIES;
+ paramHeader.put("Content-Type", "application/json;charset=UTF-8");
+ paramHeader.put("Authorization", "bearer "+token);
+
+ Gson gson = new Gson();
+ String json = gson.toJson(community);
+
+ String result = HTTPSClientUtil.doPostJson(httpClient, url, paramHeader, paramBody,json);
+
+
+ Resp resp = gson.fromJson(result, Resp.class);
+ return resp;
+ }
+
+ @Override
+ public Resp deleteCommunities(String token,String communityId) throws Exception {
+ String url = Constant.DELETE_COMMUNITIES;
+ paramHeader.put("Content-Type", "application/json;charset=UTF-8");
+ paramHeader.put("Authorization", "bearer "+token);
+
+ String urlFinal = url + communityId;
+
+ String result = HTTPSClientUtil.doDelete(httpClient, urlFinal, paramHeader, paramBody);
+
+ Gson gson = new Gson();
+ Resp resp = gson.fromJson(result, Resp.class);
+ return resp;
+ }
+
+ @Override
+ public Resp updateCommunities(String token, CommunityBean bean) throws Exception {
+ String url = Constant.UPDATE_COMMUNITIES;
+ paramHeader.put("Content-Type", "application/json;charset=UTF-8");
+ paramHeader.put("Authorization", "bearer "+token);
+
+ Gson gson = new Gson();
+ String jsonStr = gson.toJson(bean);
+
+ String result = HTTPSClientUtil.doPostJson(httpClient, url, paramHeader, paramBody,jsonStr);
+
+
+ Resp resp = gson.fromJson(result, Resp.class);
+ return resp;
+ }
+
+ @Override
+ public Resp communitiesList(String token) throws Exception {
+ String url = Constant.COMMUNITIES_LIST;
+ paramHeader.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
+ paramHeader.put("Authorization", "bearer "+token);
+
+ String result = HTTPSClientUtil.doGet(httpClient, url, paramHeader, paramBody);
+
+ Gson gson = new Gson();
+ Resp resp = gson.fromJson(result, Resp.class);
+ return resp;
+ }
+
+ @Override
+ public Resp addBuildings(String token, THKBuilding building) throws Exception{
+ String url = Constant.ADD_BUILDINGS;
+ paramHeader.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
+ paramHeader.put("Authorization", "bearer "+token);
+
+ paramBody.put("unionId", building.getUnionId());
+ paramBody.put("communityId", building.getCommunityId());
+ paramBody.put("buildingName", building.getBuildingName());
+ paramBody.put("buildingNumber", building.getBuildingNumber());
+ paramBody.put("floorUpCount",building.getFloorUpCount());
+ paramBody.put("floorDownCount", building.getFloorDownCount());
+ paramBody.put("floorFamilyCount", building.getFloorFamilyCount());
+ paramBody.put("buildingUnitSize", building.getBuildingUnitSize());
+ paramBody.put("buildingRemark", building.getBuildingRemark());
+
+ String result = HTTPSClientUtil.doPost(httpClient, url, paramHeader, paramBody);
+
+ Gson gson = new Gson();
+ Resp resp = gson.fromJson(result, Resp.class);
+ return resp;
+ }
+
+ @Override
+ public Resp addUnits(String token, TUnit unit) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp addRooms(String token, TRoom room) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp findRoomsByNumber(String token, String communityId, String buildingNumber, String unitNumber, String roomNumber) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp findRoomsById(String token, String roomId) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp deleteBuildings(String token, String buildingId) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp deleteUnits(String token, String unitId) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Resp deleteRooms(String token, String roomId) throws Exception {
+ return null;
+ }
+
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/util/HTTPSClientUtil.java b/src/main/java/com/supwisdom/dlpay/util/HTTPSClientUtil.java
index ddc4d73..034c34f 100644
--- a/src/main/java/com/supwisdom/dlpay/util/HTTPSClientUtil.java
+++ b/src/main/java/com/supwisdom/dlpay/util/HTTPSClientUtil.java
@@ -1,27 +1,85 @@
package com.supwisdom.dlpay.util;
import com.google.gson.Gson;
+import com.supwisdom.dlpay.hk.bean.CommunityIdBean;
import com.supwisdom.dlpay.hk.common.Resp;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.util.*;
public class HTTPSClientUtil {
private static final String DEFAULT_CHARSET = "UTF-8";
+
+
+ public static String doDelete(HttpClient httpClient, String url, Map<String, String> paramHeader,
+ Map<String, String> paramBody) throws Exception {
+ return doDelete(httpClient, url, paramHeader, paramBody, DEFAULT_CHARSET);
+ }
+
+ public static String doDelete(HttpClient httpClient, String url, Map<String, String> paramHeader,
+ Map<String, String> paramBody, String charset) throws Exception {
+
+ String result = null;
+ HttpDelete httpDelete = new HttpDelete(url);
+ setHeader(httpDelete, paramHeader);
+ //setBody(, , );
+ HttpResponse response = httpClient.execute(httpDelete);
+ if (response != null) {
+ HttpEntity resEntity = response.getEntity();
+ if (resEntity != null) {
+ result = EntityUtils.toString(resEntity, charset);
+ }
+ }
+
+ return result;
+ }
+
+ public static String doPostJson(HttpClient httpClient, String url, Map<String, String> paramHeader,
+ Map<String, String> paramBody,String jsonStr) throws Exception {
+ return doPostJson(httpClient, url, paramHeader, paramBody,jsonStr, DEFAULT_CHARSET);
+ }
+
+ public static String doPostJson(HttpClient httpClient, String url, Map<String, String> paramHeader,
+ Map<String, String> paramBody,String jsonStr, String charset) throws Exception {
+
+ String result = null;
+ HttpPost httpPost = new HttpPost(url);
+ setHeader(httpPost, paramHeader);
+ setBody(httpPost, paramBody, charset);
+ StringEntity s = new StringEntity(jsonStr, "utf-8");
+ s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
+ "application/json"));
+ httpPost.setEntity(s);
+ HttpResponse response = httpClient.execute(httpPost);
+ if (response != null) {
+ HttpEntity resEntity = response.getEntity();
+ if (resEntity != null) {
+ result = EntityUtils.toString(resEntity, charset);
+ }
+ }
+
+ return result;
+ }
+
public static String doPost(HttpClient httpClient, String url, Map<String, String> paramHeader,
Map<String, String> paramBody) throws Exception {
return doPost(httpClient, url, paramHeader, paramBody, DEFAULT_CHARSET);
}
+
public static String doPost(HttpClient httpClient, String url, Map<String, String> paramHeader,
Map<String, String> paramBody, String charset) throws Exception {
@@ -97,8 +155,8 @@
httpClient = new HTTPSTrustClient().init();
//httpClient = new HTTPSCertifiedClient().init();
- //String url = "https://api2.hik-cloud.com/oauth/token";
- String url = "https://api2.hik-cloud.com/api/v1/estate/system/communities/actions/list?pageNo=1&pageSize=10";
+ String url = "https://api2.hik-cloud.com/oauth/token";
+ //String url = "https://api2.hik-cloud.com/api/v1/estate/system/communities/actions/list?pageNo=1&pageSize=10";
Map<String, String> paramHeader = new HashMap<>();
paramHeader.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
@@ -111,15 +169,22 @@
//paramBody.put("scope", "app");
//String result = doPost(httpClient, url, paramHeader, paramBody);
- String result = HTTPSClientUtil.doGet(httpClient, url, paramHeader, paramBody);
+ //String result = HTTPSClientUtil.doGet(httpClient, url, paramHeader, paramBody);
- System.out.println(result);
+ String result = "{'code':200,'message':'操作成功','data':{'communityId':'94279c6b4c81403ea97a17e447464b16'}}";
+
Gson gson = new Gson();
- Resp resp = gson.fromJson(result, Resp.class);
+ Resp<CommunityIdBean> resp = gson.fromJson(result, Resp.class);
+ System.out.println(resp.getData());
+ String s = gson.toJson(resp.getData());
+ System.out.println(s);
- System.out.println(resp.getMessage());
+ CommunityIdBean bean = gson.fromJson(s, CommunityIdBean.class);
+ System.out.println(bean.getCommunityId());
+
+
}
}
\ No newline at end of file