PickUpPointManagerImpl.java
9.33 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
package com.diligrp.website.manager.impl;
import com.alibaba.rocketmq.common.message.Message;
import com.diligrp.util.rocketMQUtil.DiliMQProducer;
import com.diligrp.website.dao.PickUpCityDao;
import com.diligrp.website.dao.PickUpPersonDao;
import com.diligrp.website.dao.PickUpPointDao;
import com.diligrp.website.domain.PickUpCity;
import com.diligrp.website.domain.PickUpPerson;
import com.diligrp.website.domain.PickUpPointDomain;
import com.diligrp.website.manager.PickUpPointManager;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.redis.RedisUtil;
import com.google.common.base.Objects;
import org.nutz.json.Json;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <B>Description</B> TODO <br />
* <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
* 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
* <B>Company</B> 地利集团
*
* @createTime 2014年8月13日 下午4:59:13
* @author liujie
*/
@Component
public class PickUpPointManagerImpl implements PickUpPointManager {
@Resource
private PickUpPointDao pickUpPointDao;
@Resource
private PickUpCityDao pickUpCityDao;
@Resource
private PickUpPersonDao pickUpPersonDao;
private final static String pickup_key = "dili_redis_service_";
private final static Integer cityRedisKeyTime = 86400;
@Resource(name = "redisUtils")
private RedisUtil redisUtil;
@Resource
private DiliMQProducer diliMQProducer;
@Value("${mq.manweb.pickupInfoChange.pnr.tag}")
private String PICKUP_CHANGE_TAG;
@Value("${mq.manweb.pickupInfoChange.topic}")
private String PICKUP_CHANGE_TOPIC;
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getPickInfo(com.diligrp
* .website.util.dao.BaseQuery)
*/
@Override
public List<PickUpPointDomain> getPickInfo(BaseQuery bq) throws Exception {
return pickUpPointDao.getPickInfo(bq);
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getCountPickInfo(com.diligrp
* .website.util.dao.BaseQuery)
*/
@Override
public Integer getCountPickInfo(BaseQuery bq) throws Exception {
return pickUpPointDao.getCountPickInfo(bq);
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#savePickUpInfo(com.diligrp
* .website.domain.PickUpPointDomain)
*/
@Override
@Transactional
public boolean savePickUpInfo(PickUpPointDomain pickUpPointDomain) {
try {
List<PickUpCity> pickUpCityList = pickUpPointDomain.getCityList();
List<PickUpPerson> pickUpPersonList = pickUpPointDomain.getPersonList();
Long pickId = pickUpPointDao.savePickUpInfo(pickUpPointDomain);
if (pickUpCityList != null) {
for (int i = 0; i < pickUpCityList.size(); i++) {
PickUpCity city = pickUpCityList.get(i);
city.setPickId(pickId);
pickUpCityDao.savePickUpCity(city);
}
}
for (int i = 0; i < pickUpPersonList.size(); i++) {
PickUpPerson person = pickUpPersonList.get(i);
person.setPickid(pickId);
pickUpPersonDao.savePickUpPerson(person);
}
try {
Message msg = new Message(PICKUP_CHANGE_TOPIC, PICKUP_CHANGE_TAG, Json.toJson(pickUpPointDomain).getBytes("utf-8"));
diliMQProducer.sendMsg(msg);
} catch (Exception e) {
e.printStackTrace();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#modifyPickUpInfo(com.diligrp
* .website.domain.PickUpPointDomain)
*/
@Override
@Transactional
public boolean modifyPickUpInfo(PickUpPointDomain pickUpPointDomain)
throws Exception {
List<PickUpCity> pickUpCityList = pickUpPointDomain.getCityList();
List<PickUpPerson> pickUpPersonList = pickUpPointDomain.getPersonList();
if (Objects.equal(pickUpPointDomain.getIsMarket(), 1)) {
pickUpCityDao.deletePickUpCityById(pickUpPointDomain.getId());
}
pickUpPersonDao.deletePickUpPerson(pickUpPointDomain.getId());
if (pickUpCityList != null) {
for (int i = 0; i < pickUpCityList.size(); i++) {
PickUpCity city = pickUpCityList.get(i);
city.setPickId(pickUpPointDomain.getId());
pickUpCityDao.savePickUpCity(city);
}
}
for (int i = 0; i < pickUpPersonList.size(); i++) {
PickUpPerson person = pickUpPersonList.get(i);
person.setPickid(pickUpPointDomain.getId());
pickUpPersonDao.savePickUpPerson(person);
}
boolean flag = pickUpPointDao.modifyPickUpInfo(pickUpPointDomain);
if(flag){
redisUtil.deleteByKey(pickup_key+pickUpPointDomain.getId());
redisUtil.deleteByKey(pickup_key+pickUpPointDomain.getPickCode());
}
try {
Message msg = new Message(PICKUP_CHANGE_TOPIC, PICKUP_CHANGE_TAG, Json.toJson(pickUpPointDomain).getBytes("utf-8"));
diliMQProducer.sendMsg(msg);
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#modifyPickUpInfoDeafult
* (com.diligrp.website.domain.PickUpPointDomain)
*/
@Override
@Transactional
public boolean modifyPickUpInfoDeafult(Long id) throws Exception {
pickUpPointDao.modifyPickUpInfoDeafult();
boolean flag = pickUpPointDao.modifyStateByPickUpId(id);
return flag;
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getPickUpPointDomainInfo
* (java.lang.Long)
*/
@Override
public PickUpPointDomain getPickUpPointDomainInfo(Long id) throws Exception {
// PickUpPointDomain domain = redisUtil.getObject(pickup_key+id, PickUpPointDomain.class);
// if(domain ==null){
// domain = pickUpPointDao.getPickUpPointDomainInfo(id);
// if(domain!=null){
// redisUtil.setObjectByExpire(pickup_key+id, domain, cityRedisKeyTime);
// }
// }
// return domain;
return pickUpPointDao.getPickUpPointDomainInfo(id);
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getRelationPickInfo(java
* .lang.Long)
*/
@Override
public List<PickUpPointDomain> getRelationPickInfo(Long id)
throws Exception {
return pickUpPointDao.getRelationPickInfo(id);
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getNotMarketPickInfo()
*/
@Override
public List<PickUpPointDomain> getNotMarketPickInfo() throws Exception {
return pickUpPointDao.getNotMarketPickInfo();
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#modifyRelationPoint(java
* .util.Map)
*/
@Override
@Transactional
public boolean modifyRelationPoint(List<Long> list, Long pickId) {
try {
pickUpPointDao.modifyRelationPointParent(pickId);
if (list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
Map<String, Long> map = new HashMap<String, Long>();
map.put("pickId", pickId);
map.put("id", list.get(i));
pickUpPointDao.modifyRelationPoint(map);
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getIsMarketPickUpInfo()
*/
@Override
public List<PickUpPointDomain> getIsMarketPickUpInfo() throws Exception {
return pickUpPointDao.getIsMarketPickUpInfo();
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getIsNotMarketPickUpInfo()
*/
@Override
public List<PickUpPointDomain> getIsNotMarketPickUpInfo() throws Exception {
return pickUpPointDao.getIsNotMarketPickUpInfo();
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getAllMarketPickUpInfo()
*/
@Override
public List<PickUpPointDomain> getAllMarketPickUpInfo() throws Exception {
return pickUpPointDao.getAllMarketPickUpInfo();
}
/*
* (non-Javadoc)
*
* @see
* com.diligrp.website.manager.PickUpPointManager#getCodeByPickUpInfo(java
* .lang.String)
*/
@Override
public PickUpPointDomain getCodeByPickUpInfo(String code) throws Exception {
PickUpPointDomain domain = redisUtil.getObject(pickup_key+code, PickUpPointDomain.class);
if(domain ==null){
domain = pickUpPointDao.getCodeByPickUpInfo(code);
if(domain!=null){
redisUtil.setObjectByExpire(pickup_key+code, domain, cityRedisKeyTime);
}
}
return domain;
}
@Override
public PickUpPointDomain getDefaultPickUpInfo() throws Exception {
return pickUpPointDao.getDefaultPickUpInfo();
}
@Override
public List<PickUpPointDomain> getPickUpInfoByName(String pickName) {
return pickUpPointDao.getPickUpInfoByName(pickName);
}
@Override
public List<PickUpPointDomain> getRecommendPickUp() {
return pickUpPointDao.getRecommendPickUp();
}
@Override
public List<PickUpPointDomain> getPickUpListByCityId(Long cityId) {
return pickUpPointDao.getPickUpListByCityId(cityId);
}
@Override
public boolean configRecommend(PickUpPointDomain pickUpPointDomain) throws Exception {
return pickUpPointDao.modifyPickUpInfo(pickUpPointDomain);
}
@Override
public List<PickUpPointDomain> getPickUpInfoByCityName(String cityName) {
return pickUpPointDao.getPickUpInfoByCityName(cityName);
}
@Override
public List<PickUpPointDomain> getAllPickUpListByCityId(Long cityId) {
return pickUpPointDao.getAllPickUpListByCityId(cityId);
}
}