1
|
package com.yoho.unions.server.service.impl;
|
1
|
package com.yoho.unions.server.service.impl;
|
2
|
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson.JSONException;
|
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
import com.yoho.core.config.ConfigReader;
|
5
|
import com.yoho.core.config.ConfigReader;
|
4
|
import com.yoho.core.rabbitmq.YhProducer;
|
6
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
7
|
+import com.yoho.error.exception.ServiceException;
|
5
|
import com.yoho.service.model.union.bo.ShareOrderBo;
|
8
|
import com.yoho.service.model.union.bo.ShareOrderBo;
|
6
|
import com.yoho.service.model.union.bo.ShareSettlementBo;
|
9
|
import com.yoho.service.model.union.bo.ShareSettlementBo;
|
7
|
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
|
10
|
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
|
|
|
11
|
+import com.yoho.service.model.union.bo.UnionShareOrderSearchBo;
|
|
|
12
|
+import com.yoho.service.model.union.request.UnionOrderReqBO;
|
|
|
13
|
+import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
8
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
14
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
9
|
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
|
15
|
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
|
10
|
import com.yoho.service.model.union.response.UnionShareOrderRspBO;
|
16
|
import com.yoho.service.model.union.response.UnionShareOrderRspBO;
|
|
@@ -13,6 +19,7 @@ import com.yoho.unions.common.enums.ShareOrdersKeyEnum; |
|
@@ -13,6 +19,7 @@ import com.yoho.unions.common.enums.ShareOrdersKeyEnum; |
13
|
import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
|
19
|
import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
|
14
|
import com.yoho.unions.common.redis.RedisHashCache;
|
20
|
import com.yoho.unions.common.redis.RedisHashCache;
|
15
|
import com.yoho.unions.common.redis.RedisValueCache;
|
21
|
import com.yoho.unions.common.redis.RedisValueCache;
|
|
|
22
|
+import com.yoho.unions.common.service.IBusinessExportService;
|
16
|
import com.yoho.unions.common.utils.DateUtil;
|
23
|
import com.yoho.unions.common.utils.DateUtil;
|
17
|
import com.yoho.unions.common.utils.RandomUtil;
|
24
|
import com.yoho.unions.common.utils.RandomUtil;
|
18
|
import com.yoho.unions.dal.*;
|
25
|
import com.yoho.unions.dal.*;
|
|
@@ -37,8 +44,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
@@ -37,8 +44,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
37
|
* Created by mingdan.ge on 2018/5/10.
|
44
|
* Created by mingdan.ge on 2018/5/10.
|
38
|
*/
|
45
|
*/
|
39
|
@Service
|
46
|
@Service
|
40
|
-public class UnionShareServiceImpl implements IUnionShareService {
|
|
|
41
|
-
|
47
|
+public class UnionShareServiceImpl implements IUnionShareService,IBusinessExportService {
|
42
|
private Logger logger = LoggerFactory.getLogger(UnionShareServiceImpl.class);
|
48
|
private Logger logger = LoggerFactory.getLogger(UnionShareServiceImpl.class);
|
43
|
|
49
|
|
44
|
@Autowired
|
50
|
@Autowired
|
|
@@ -95,35 +101,22 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
@@ -95,35 +101,22 @@ public class UnionShareServiceImpl implements IUnionShareService { |
95
|
@Override
|
101
|
@Override
|
96
|
public PageUnionShareOrderRspBO queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO){
|
102
|
public PageUnionShareOrderRspBO queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO){
|
97
|
logger.info("queryUnionShareOrders param is {}", reqBO);
|
103
|
logger.info("queryUnionShareOrders param is {}", reqBO);
|
98
|
- int beginTime = StringUtils.isBlank(reqBO.getBeginTime()) ? 0 : Integer.parseInt(reqBO.getBeginTime());
|
|
|
99
|
- int endTime = StringUtils.isBlank(reqBO.getEndTime()) ? 0 : Integer.parseInt(reqBO.getEndTime());
|
|
|
100
|
- long orderCode = StringUtils.isBlank(reqBO.getOrderCode()) ? 0 : Long.parseLong(reqBO.getOrderCode());
|
|
|
101
|
- Long unionType = StringUtils.isBlank(reqBO.getUnionId()) ? null :Long.valueOf( reqBO.getUnionId());
|
|
|
102
|
- String unionName = StringUtils.isBlank(reqBO.getUnionType()) ? null : reqBO.getUnionType();
|
|
|
103
|
- String channelType=reqBO.getChannelType();
|
|
|
104
|
- List<String> idList = reqBO.getIdsList();
|
|
|
105
|
- List<Long> unionTypes=null;
|
|
|
106
|
- if(unionType!=null || unionName!=null || channelType!=null){
|
|
|
107
|
- unionTypes=mktMarketingUrlDAO.selectUnionTypes(unionType, unionName, channelType);
|
|
|
108
|
- if(unionTypes.isEmpty()){
|
104
|
+ UnionShareOrderSearchBo bo=initUnionShareOrderSearchBo(reqBO);
|
|
|
105
|
+ List<Integer> uids=null;
|
|
|
106
|
+ if(bo.getUnionType()!=null || bo.getUnionName()!=null || bo.getChannelType()!=null){
|
|
|
107
|
+ uids=queryUids(bo);
|
|
|
108
|
+ if(null==uids){
|
109
|
return null;
|
109
|
return null;
|
110
|
}
|
110
|
}
|
111
|
}
|
111
|
}
|
112
|
- List<Integer> uids=unionTypes==null?null:this.unionShareUserMapper.selectUids(unionTypes);
|
|
|
113
|
//查询总数
|
112
|
//查询总数
|
114
|
- int count = unionShareOrdersMapper.selectCountByUids(beginTime, endTime, uids);
|
|
|
115
|
- logger.info("userOrdersDAO.selectCount: size is {}", count);
|
113
|
+ int count = unionShareOrdersMapper.selectCountByUids(bo.getBeginTime(), bo.getEndTime(), uids,bo.getOrderCode());
|
|
|
114
|
+ logger.info("unionShareOrdersMapper.selectCountByUids: size is {}", count);
|
116
|
if (count < 1) {
|
115
|
if (count < 1) {
|
117
|
return null;
|
116
|
return null;
|
118
|
}
|
117
|
}
|
119
|
- Map<String,UnionShareOrders> ordersDOMap=this.unionShareOrdersMapper.selectListByUids(beginTime, endTime, uids, reqBO.getStart(), reqBO.getSize());
|
|
|
120
|
- Map<Long, UserOrderDatailBO> userOrderDatailBOMap = initUserShareOrderDatails(ordersDOMap);
|
|
|
121
|
- List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOMap.size());
|
|
|
122
|
- for (UnionShareOrders orders : ordersDOMap.values()) {
|
|
|
123
|
- UnionShareOrderRspBO bo=initShareUnionOrderRspBO(orders,userOrderDatailBOMap);
|
|
|
124
|
- bo.setChannelType(Integer.valueOf(channelType));
|
|
|
125
|
- unionOrderRspBOList.add(bo);
|
|
|
126
|
- }
|
118
|
+ Map<String,UnionShareOrders> ordersDOMap=this.unionShareOrdersMapper.selectListByUids(bo.getBeginTime(), bo.getEndTime(), uids,bo.getOrderCode(), reqBO.getStart(), reqBO.getSize());
|
|
|
119
|
+ List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRsp(ordersDOMap);
|
127
|
PageUnionShareOrderRspBO pageUnionOrderRspBO = new PageUnionShareOrderRspBO();
|
120
|
PageUnionShareOrderRspBO pageUnionOrderRspBO = new PageUnionShareOrderRspBO();
|
128
|
pageUnionOrderRspBO.setList(unionOrderRspBOList);
|
121
|
pageUnionOrderRspBO.setList(unionOrderRspBOList);
|
129
|
pageUnionOrderRspBO.setTotal(count);
|
122
|
pageUnionOrderRspBO.setTotal(count);
|
|
@@ -131,19 +124,55 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
@@ -131,19 +124,55 @@ public class UnionShareServiceImpl implements IUnionShareService { |
131
|
pageUnionOrderRspBO.setPage(reqBO.getPage());
|
124
|
pageUnionOrderRspBO.setPage(reqBO.getPage());
|
132
|
return pageUnionOrderRspBO;
|
125
|
return pageUnionOrderRspBO;
|
133
|
}
|
126
|
}
|
134
|
- private UnionShareOrderRspBO initShareUnionOrderRspBO(UnionShareOrders orders,Map<Long, UserOrderDatailBO> userOrderDatailBOMap){
|
127
|
+
|
|
|
128
|
+ private List<Integer> queryUids(UnionShareOrderSearchBo bo){
|
|
|
129
|
+ List<Integer> uids=null;
|
|
|
130
|
+ List<Long> unionTypes=mktMarketingUrlDAO.selectUnionTypes(bo.getUnionType(), bo.getUnionName(), bo.getChannelType());
|
|
|
131
|
+ if(unionTypes.isEmpty()){
|
|
|
132
|
+ return null;
|
|
|
133
|
+ }
|
|
|
134
|
+ uids=this.unionShareUserMapper.selectUids(unionTypes);
|
|
|
135
|
+ if(uids.isEmpty()){
|
|
|
136
|
+ return null;
|
|
|
137
|
+ }
|
|
|
138
|
+ return uids;
|
|
|
139
|
+ }
|
|
|
140
|
+ private UnionShareOrderSearchBo initUnionShareOrderSearchBo(UnionShareOrderSearchReqBO reqBO){
|
|
|
141
|
+ UnionShareOrderSearchBo bo=new UnionShareOrderSearchBo();
|
|
|
142
|
+ bo.setBeginTime(StringUtils.isBlank(reqBO.getBeginTime()) ? 0 : Integer.parseInt(reqBO.getBeginTime()));
|
|
|
143
|
+ bo.setEndTime(StringUtils.isBlank(reqBO.getEndTime()) ? 0 : Integer.parseInt(reqBO.getEndTime()));
|
|
|
144
|
+ bo.setOrderCode(StringUtils.isBlank(reqBO.getOrderCode()) ? null : reqBO.getOrderCode());
|
|
|
145
|
+ bo.setUnionType(StringUtils.isBlank(reqBO.getUnionId()) ? null :Long.valueOf( reqBO.getUnionId()));
|
|
|
146
|
+ bo.setUnionName(StringUtils.isBlank(reqBO.getUnionType()) ? null : reqBO.getUnionType());
|
|
|
147
|
+ bo.setChannelType(StringUtils.isBlank(reqBO.getChannelType())?null:reqBO.getChannelType());
|
|
|
148
|
+ bo.setIdList(reqBO.getIdsList());
|
|
|
149
|
+ return bo;
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
|
152
|
+ private List<UnionShareOrderRspBO> queryUnionShareOrderRsp(Map<String,UnionShareOrders> ordersDOMap){
|
|
|
153
|
+ List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOMap.size());
|
|
|
154
|
+ Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = initUserShareOrderDatails(ordersDOMap);
|
|
|
155
|
+ for (UnionShareOrders orders : ordersDOMap.values()) {
|
|
|
156
|
+ UnionShareOrderRspBO bo=initShareUnionOrderRspBO(orders,userOrderDatailBOMap);
|
|
|
157
|
+ unionOrderRspBOList.add(bo);
|
|
|
158
|
+ }
|
|
|
159
|
+ return unionOrderRspBOList;
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ private UnionShareOrderRspBO initShareUnionOrderRspBO(UnionShareOrders orders,Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap){
|
135
|
UnionShareOrderRspBO orderRspBO=new UnionShareOrderRspBO();
|
163
|
UnionShareOrderRspBO orderRspBO=new UnionShareOrderRspBO();
|
136
|
orderRspBO.setOrderAmount(orders.getAmount());
|
164
|
orderRspBO.setOrderAmount(orders.getAmount());
|
137
|
orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(orders.getStatus()));
|
165
|
orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(orders.getStatus()));
|
138
|
Byte isNew=orders.getIsNew();
|
166
|
Byte isNew=orders.getIsNew();
|
139
|
orderRspBO.setIsNew(isNew==null||isNew.equals(2)?"N":"Y");
|
167
|
orderRspBO.setIsNew(isNew==null||isNew.equals(2)?"N":"Y");
|
140
|
orderRspBO.setUid(orders.getPromoteUid());
|
168
|
orderRspBO.setUid(orders.getPromoteUid());
|
141
|
- orderRspBO.setOrderCode(Long.parseLong(orders.getOrderCode()));
|
169
|
+ orderRspBO.setOrderCode(orders.getOrderCode());
|
142
|
orderRspBO.setId(orders.getId());
|
170
|
orderRspBO.setId(orders.getId());
|
143
|
orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd HH:mm:ss"));
|
171
|
orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd HH:mm:ss"));
|
144
|
- UserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getOrderCode());
|
|
|
145
|
- orderRspBO.setUnionId(userOrderDatailBO.getUnionId());
|
172
|
+ ShareUserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getOrderCode());
|
|
|
173
|
+ orderRspBO.setUnionId(userOrderDatailBO.getUnionType());
|
146
|
orderRspBO.setUnionType(userOrderDatailBO.getUnionName());
|
174
|
orderRspBO.setUnionType(userOrderDatailBO.getUnionName());
|
|
|
175
|
+ orderRspBO.setChannelType(userOrderDatailBO.getChannelType());
|
147
|
return orderRspBO;
|
176
|
return orderRspBO;
|
148
|
}
|
177
|
}
|
149
|
|
178
|
|
|
@@ -154,13 +183,13 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
@@ -154,13 +183,13 @@ public class UnionShareServiceImpl implements IUnionShareService { |
154
|
}
|
183
|
}
|
155
|
return uids;
|
184
|
return uids;
|
156
|
}
|
185
|
}
|
157
|
- private Map<Long, UserOrderDatailBO> initUserShareOrderDatails( Map<String,UnionShareOrders> ordersDOMap){
|
|
|
158
|
- Map<Long, UserOrderDatailBO> userOrderDatailBOMap = new HashMap<>(ordersDOMap.size());
|
186
|
+ private Map<String, ShareUserOrderDatailBO> initUserShareOrderDatails( Map<String,UnionShareOrders> ordersDOMap){
|
|
|
187
|
+ Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = new HashMap<>(ordersDOMap.size());
|
159
|
Map<Integer,UnionShareUser> userMap=unionShareUserMapper.selectByUids(getUids(ordersDOMap));
|
188
|
Map<Integer,UnionShareUser> userMap=unionShareUserMapper.selectByUids(getUids(ordersDOMap));
|
160
|
for (UnionShareOrders userOrders : ordersDOMap.values()) {
|
189
|
for (UnionShareOrders userOrders : ordersDOMap.values()) {
|
161
|
String unionType=userMap.get(userOrders.getPromoteUid()).getUnionType();
|
190
|
String unionType=userMap.get(userOrders.getPromoteUid()).getUnionType();
|
162
|
- UserOrderDatailBO userOrderDatailBO = new UserOrderDatailBO();
|
|
|
163
|
- userOrderDatailBO.setUnionId(unionType);
|
191
|
+ ShareUserOrderDatailBO userOrderDatailBO = new ShareUserOrderDatailBO();
|
|
|
192
|
+ userOrderDatailBO.setUnionType(unionType);
|
164
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:" + unionType, MktMarketingUrl.class);
|
193
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:" + unionType, MktMarketingUrl.class);
|
165
|
if (mktMarketingUrl == null) {
|
194
|
if (mktMarketingUrl == null) {
|
166
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(unionType));
|
195
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(unionType));
|
|
@@ -168,8 +197,9 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
@@ -168,8 +197,9 @@ public class UnionShareServiceImpl implements IUnionShareService { |
168
|
}
|
197
|
}
|
169
|
if (mktMarketingUrl != null) {
|
198
|
if (mktMarketingUrl != null) {
|
170
|
userOrderDatailBO.setUnionName(mktMarketingUrl.getName());
|
199
|
userOrderDatailBO.setUnionName(mktMarketingUrl.getName());
|
|
|
200
|
+ userOrderDatailBO.setChannelType(mktMarketingUrl.getChannelType());
|
171
|
}
|
201
|
}
|
172
|
- userOrderDatailBO.setOrderCode(Long.valueOf(userOrders.getOrderCode()));
|
202
|
+ userOrderDatailBO.setOrderCode(userOrders.getOrderCode());
|
173
|
userOrderDatailBOMap.put(userOrderDatailBO.getOrderCode(),userOrderDatailBO);
|
203
|
userOrderDatailBOMap.put(userOrderDatailBO.getOrderCode(),userOrderDatailBO);
|
174
|
}
|
204
|
}
|
175
|
return userOrderDatailBOMap;
|
205
|
return userOrderDatailBOMap;
|
|
@@ -517,4 +547,43 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
@@ -517,4 +547,43 @@ public class UnionShareServiceImpl implements IUnionShareService { |
517
|
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
|
547
|
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
|
518
|
}
|
548
|
}
|
519
|
|
549
|
|
|
|
550
|
+ @Override
|
|
|
551
|
+ public Class getDataClass() {
|
|
|
552
|
+ return UnionShareOrderRspBO.class;
|
|
|
553
|
+ }
|
|
|
554
|
+
|
|
|
555
|
+ @Override
|
|
|
556
|
+ public List<? extends Object> batchExport(String confStr) {
|
|
|
557
|
+ try {
|
|
|
558
|
+ UnionShareOrderSearchReqBO request = JSONObject.parseObject(confStr, UnionShareOrderSearchReqBO.class);
|
|
|
559
|
+ List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRspBOForExport(request);
|
|
|
560
|
+ if (CollectionUtils.isEmpty(unionOrderRspBOList)) {
|
|
|
561
|
+ throw new ServiceException(400, "没有要导出的数据");
|
|
|
562
|
+ }
|
|
|
563
|
+ return unionOrderRspBOList;
|
|
|
564
|
+ } catch (JSONException e) {
|
|
|
565
|
+ logger.warn("parse confStr error: confStr {}, e {}", confStr, e);
|
|
|
566
|
+ throw new ServiceException(400, "传入数据格式错误");
|
|
|
567
|
+ } catch (com.yoho.error.exception.ServiceException e) {
|
|
|
568
|
+ logger.warn("make url error params is confStr {}, e {}", confStr, e);
|
|
|
569
|
+ throw new ServiceException(e.getCode(), e.getErrorMessage());
|
|
|
570
|
+ }
|
|
|
571
|
+ }
|
|
|
572
|
+ private List<UnionShareOrderRspBO> queryUnionShareOrderRspBOForExport(UnionShareOrderSearchReqBO reqBO){
|
|
|
573
|
+ UnionShareOrderSearchBo bo=initUnionShareOrderSearchBo(reqBO);
|
|
|
574
|
+ Map<String,UnionShareOrders> ordersDOMap=null;
|
|
|
575
|
+ if(bo.getIdList()!=null&&!bo.getIdList().isEmpty()){
|
|
|
576
|
+ ordersDOMap= this.unionShareOrdersMapper.selectListByIds(bo.getIdList());
|
|
|
577
|
+ }else{
|
|
|
578
|
+ List<Integer> uids=null;
|
|
|
579
|
+ if(bo.getUnionType()!=null || bo.getUnionName()!=null || bo.getChannelType()!=null){
|
|
|
580
|
+ uids=queryUids(bo);
|
|
|
581
|
+ if(null==uids){
|
|
|
582
|
+ return null;
|
|
|
583
|
+ }
|
|
|
584
|
+ }
|
|
|
585
|
+ ordersDOMap=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uids, bo.getOrderCode());
|
|
|
586
|
+ }
|
|
|
587
|
+ return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
|
|
|
588
|
+ }
|
520
|
} |
589
|
} |