88e030b7
王彪总
init project
|
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
|
package com.java110.job.adapt.hcIot;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.community.CommunityDto;
import com.java110.dto.community.CommunityMemberDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.store.StoreDto;
import com.java110.dto.store.StoreUserDto;
import com.java110.dto.system.Business;
import com.java110.intf.common.IFileInnerServiceSMO;
import com.java110.intf.common.IFileRelInnerServiceSMO;
import com.java110.intf.community.ICommunityMemberV1InnerServiceSMO;
import com.java110.intf.community.ICommunityV1InnerServiceSMO;
import com.java110.intf.community.IRoomV1InnerServiceSMO;
import com.java110.intf.store.IStoreUserV1InnerServiceSMO;
import com.java110.intf.store.IStoreV1InnerServiceSMO;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.intf.user.IOwnerRoomRelV1InnerServiceSMO;
import com.java110.intf.user.IOwnerV1InnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.hcIot.http.ISendIot;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.util.Assert;
import com.java110.utils.util.ListUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 发送全量数据到 物联网
*/
@Component(value = "sendCommunityDataToIotAdapt")
public class SendCommunityDataToIotAdapt extends DatabusAdaptImpl {
@Autowired
private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
@Autowired
private ICommunityMemberV1InnerServiceSMO communityMemberV1InnerServiceSMOImpl;
@Autowired
private IStoreV1InnerServiceSMO storeV1InnerServiceSMOImpl;
@Autowired
private ISendIot sendIotImpl;
@Autowired
private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
@Autowired
private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
@Autowired
private IFileInnerServiceSMO fileInnerServiceSMOImpl;
@Autowired
private IOwnerRoomRelV1InnerServiceSMO ownerRoomRelV1InnerServiceSMOImpl;
@Autowired
private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
@Autowired
private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
@Autowired
private IOwnerDataToIot ownerDataToIotImpl;
@Autowired
private IStoreUserV1InnerServiceSMO storeUserV1InnerServiceSMOImpl;
public static final int DEFAULT_DEAL_COUNT = 200;
/**
* accessToken={access_token}
* &extCommunityUuid=01000
* &extCommunityId=1
* &devSn=111111111
* &name=设备名称
* &positionType=0
* &positionUuid=1
*
* @param business 当前处理业务
* @param businesses 所有业务信息
*/
@Override
public void execute(Business business, List<Business> businesses) {
String iotSwitch = MappingCache.getValue("IOT", "IOT_SWITCH");
if (!"ON".equals(iotSwitch)) {
return;
}
JSONObject data = business.getData();
String communityId = data.getString("communityId");
|
9750b443
王彪总
fix(config): 更新配置...
|
98
|
//todo 同步项目
|
88e030b7
王彪总
init project
|
99
100
101
102
103
104
105
106
107
|
sendCommunityAndProperty(communityId);
//todo 同步业主
sendOwner(communityId);
}
/**
|
9750b443
王彪总
fix(config): 更新配置...
|
108
|
* 同步项目和物业公司
|
88e030b7
王彪总
init project
|
109
|
*
|
9750b443
王彪总
fix(config): 更新配置...
|
110
|
* @param communityId 项目id
|
88e030b7
王彪总
init project
|
111
112
113
114
115
116
117
|
*/
private void sendCommunityAndProperty(String communityId) {
CommunityDto communityDto = new CommunityDto();
communityDto.setCommunityId(communityId);
List<CommunityDto> communityDtos = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto);
|
9750b443
王彪总
fix(config): 更新配置...
|
118
|
Assert.listOnlyOne(communityDtos, "项目不存在");
|
88e030b7
王彪总
init project
|
119
120
121
122
123
|
CommunityMemberDto communityMemberDto = new CommunityMemberDto();
communityMemberDto.setCommunityId(communityId);
communityMemberDto.setMemberTypeCd(CommunityMemberDto.MEMBER_TYPE_PROPERTY);
List<CommunityMemberDto> communityMemberDtos = communityMemberV1InnerServiceSMOImpl.queryCommunityMembers(communityMemberDto);
|
9750b443
王彪总
fix(config): 更新配置...
|
124
|
Assert.listOnlyOne(communityMemberDtos, "项目成员不存在");
|
88e030b7
王彪总
init project
|
125
126
127
128
|
/**
* {
* “communityId”:”12313”,
|
9750b443
王彪总
fix(config): 更新配置...
|
129
|
* “name”:”演示项目”,
|
88e030b7
王彪总
init project
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
* “address”:”地址”,
* “cityCode”:”110101”,
* “tel”:”18909711445”,
* “storeId”:”11111”,
* “storeName”:”演示物业”,
* }
*/
StoreDto storeDto = new StoreDto();
storeDto.setStoreId(communityMemberDtos.get(0).getMemberId());
List<StoreDto> storeDtos = storeV1InnerServiceSMOImpl.queryStores(storeDto);
Assert.listOnlyOne(storeDtos, "物业不存在");
JSONObject paramIn = new JSONObject();
paramIn.put("communityId", communityDtos.get(0).getCommunityId());
paramIn.put("name", communityDtos.get(0).getName());
paramIn.put("address", communityDtos.get(0).getAddress());
paramIn.put("cityCode", communityDtos.get(0).getCityCode());
paramIn.put("tel", storeDtos.get(0).getTel()); //todo 这里取 物业的
paramIn.put("storeId", storeDtos.get(0).getStoreId());
paramIn.put("storeName", storeDtos.get(0).getName());
ResultVo resultVo = sendIotImpl.post("/iot/api/community.addCommunityApi", paramIn);
if (resultVo.getCode() != ResultVo.CODE_OK) {
|
9750b443
王彪总
fix(config): 更新配置...
|
154
|
throw new IllegalArgumentException("同步项目物业失败:" + resultVo.getMsg());
|
88e030b7
王彪总
init project
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
}
//todo 同步员工
sendStaff(storeDtos.get(0));
}
private void sendStaff(StoreDto storeDto) {
StoreUserDto storeUserDto = new StoreUserDto();
storeUserDto.setStoreId(storeDto.getStoreId());
List<StoreUserDto> storeUserDtos = storeUserV1InnerServiceSMOImpl.queryStoreUsers(storeUserDto);
if (ListUtil.isNull(storeUserDtos)) {
return;
}
JSONObject staff = null;
for (StoreUserDto tmpStoreUserDto : storeUserDtos) {
if(StoreUserDto.REL_CD_MANAGER.equals(tmpStoreUserDto.getRelCd())){
continue;
}
try {
staff = new JSONObject();
staff.put("propertyId", storeDto.getStoreId());
staff.put("staffId", tmpStoreUserDto.getUserId());
staff.put("name", tmpStoreUserDto.getName());
staff.put("tel", tmpStoreUserDto.getTel());
staff.put("relCd", tmpStoreUserDto.getRelCd());
sendIotImpl.post("/iot/api/staff.addStaffApi", staff);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void sendOwner(String communityId) {
OwnerDto ownerDto = new OwnerDto();
ownerDto.setCommunityId(communityId);
int count = ownerV1InnerServiceSMOImpl.queryOwnersCount(ownerDto);
int page = 1;
int max = 15;
if (count < DEFAULT_DEAL_COUNT) {
page = 1;
max = count;
} else {
page = (int) Math.ceil((double) count / (double) DEFAULT_DEAL_COUNT);
max = DEFAULT_DEAL_COUNT;
}
ownerDto = new OwnerDto();
ownerDto.setCommunityId(communityId);
//todo 每次按200条处理
List<OwnerDto> ownerDtos = null;
for (int pageIndex = 0; pageIndex < page; pageIndex++) {
ownerDto.setPage(pageIndex + 1);
ownerDto.setRow(max);
ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
// 离散费用
doSendOwners(communityId, ownerDtos);
}
}
/**
* 推送业主
*
* @param communityId
* @param ownerDtos
*/
private void doSendOwners(String communityId, List<OwnerDto> ownerDtos) {
for (OwnerDto ownerDto : ownerDtos) {
try {
ownerDataToIotImpl.sendOwnerData(ownerDto);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|