|
|
package com.yoho.unions.server.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONException;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.union.bo.ShareOrderBo;
|
|
|
import com.yoho.service.model.union.bo.ShareSettlementBo;
|
|
|
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareOrderSearchBo;
|
|
|
import com.yoho.service.model.union.request.UnionOrderReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
|
|
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
|
|
|
import com.yoho.service.model.union.response.UnionShareOrderRspBO;
|
...
|
...
|
@@ -13,6 +19,7 @@ import com.yoho.unions.common.enums.ShareOrdersKeyEnum; |
|
|
import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
|
|
|
import com.yoho.unions.common.redis.RedisHashCache;
|
|
|
import com.yoho.unions.common.redis.RedisValueCache;
|
|
|
import com.yoho.unions.common.service.IBusinessExportService;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.RandomUtil;
|
|
|
import com.yoho.unions.dal.*;
|
...
|
...
|
@@ -37,8 +44,7 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
* Created by mingdan.ge on 2018/5/10.
|
|
|
*/
|
|
|
@Service
|
|
|
public class UnionShareServiceImpl implements IUnionShareService {
|
|
|
|
|
|
public class UnionShareServiceImpl implements IUnionShareService,IBusinessExportService {
|
|
|
private Logger logger = LoggerFactory.getLogger(UnionShareServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -95,35 +101,22 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
|
@Override
|
|
|
public PageUnionShareOrderRspBO queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO){
|
|
|
logger.info("queryUnionShareOrders param is {}", reqBO);
|
|
|
int beginTime = StringUtils.isBlank(reqBO.getBeginTime()) ? 0 : Integer.parseInt(reqBO.getBeginTime());
|
|
|
int endTime = StringUtils.isBlank(reqBO.getEndTime()) ? 0 : Integer.parseInt(reqBO.getEndTime());
|
|
|
long orderCode = StringUtils.isBlank(reqBO.getOrderCode()) ? 0 : Long.parseLong(reqBO.getOrderCode());
|
|
|
Long unionType = StringUtils.isBlank(reqBO.getUnionId()) ? null :Long.valueOf( reqBO.getUnionId());
|
|
|
String unionName = StringUtils.isBlank(reqBO.getUnionType()) ? null : reqBO.getUnionType();
|
|
|
String channelType=reqBO.getChannelType();
|
|
|
List<String> idList = reqBO.getIdsList();
|
|
|
List<Long> unionTypes=null;
|
|
|
if(unionType!=null || unionName!=null || channelType!=null){
|
|
|
unionTypes=mktMarketingUrlDAO.selectUnionTypes(unionType, unionName, channelType);
|
|
|
if(unionTypes.isEmpty()){
|
|
|
UnionShareOrderSearchBo bo=initUnionShareOrderSearchBo(reqBO);
|
|
|
List<Integer> uids=null;
|
|
|
if(bo.getUnionType()!=null || bo.getUnionName()!=null || bo.getChannelType()!=null){
|
|
|
uids=queryUids(bo);
|
|
|
if(null==uids){
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
List<Integer> uids=unionTypes==null?null:this.unionShareUserMapper.selectUids(unionTypes);
|
|
|
//查询总数
|
|
|
int count = unionShareOrdersMapper.selectCountByUids(beginTime, endTime, uids);
|
|
|
logger.info("userOrdersDAO.selectCount: size is {}", count);
|
|
|
int count = unionShareOrdersMapper.selectCountByUids(bo.getBeginTime(), bo.getEndTime(), uids,bo.getOrderCode());
|
|
|
logger.info("unionShareOrdersMapper.selectCountByUids: size is {}", count);
|
|
|
if (count < 1) {
|
|
|
return null;
|
|
|
}
|
|
|
Map<String,UnionShareOrders> ordersDOMap=this.unionShareOrdersMapper.selectListByUids(beginTime, endTime, uids, reqBO.getStart(), reqBO.getSize());
|
|
|
Map<Long, UserOrderDatailBO> userOrderDatailBOMap = initUserShareOrderDatails(ordersDOMap);
|
|
|
List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOMap.size());
|
|
|
for (UnionShareOrders orders : ordersDOMap.values()) {
|
|
|
UnionShareOrderRspBO bo=initShareUnionOrderRspBO(orders,userOrderDatailBOMap);
|
|
|
bo.setChannelType(Integer.valueOf(channelType));
|
|
|
unionOrderRspBOList.add(bo);
|
|
|
}
|
|
|
Map<String,UnionShareOrders> ordersDOMap=this.unionShareOrdersMapper.selectListByUids(bo.getBeginTime(), bo.getEndTime(), uids,bo.getOrderCode(), reqBO.getStart(), reqBO.getSize());
|
|
|
List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRsp(ordersDOMap);
|
|
|
PageUnionShareOrderRspBO pageUnionOrderRspBO = new PageUnionShareOrderRspBO();
|
|
|
pageUnionOrderRspBO.setList(unionOrderRspBOList);
|
|
|
pageUnionOrderRspBO.setTotal(count);
|
...
|
...
|
@@ -131,19 +124,55 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
|
pageUnionOrderRspBO.setPage(reqBO.getPage());
|
|
|
return pageUnionOrderRspBO;
|
|
|
}
|
|
|
private UnionShareOrderRspBO initShareUnionOrderRspBO(UnionShareOrders orders,Map<Long, UserOrderDatailBO> userOrderDatailBOMap){
|
|
|
|
|
|
private List<Integer> queryUids(UnionShareOrderSearchBo bo){
|
|
|
List<Integer> uids=null;
|
|
|
List<Long> unionTypes=mktMarketingUrlDAO.selectUnionTypes(bo.getUnionType(), bo.getUnionName(), bo.getChannelType());
|
|
|
if(unionTypes.isEmpty()){
|
|
|
return null;
|
|
|
}
|
|
|
uids=this.unionShareUserMapper.selectUids(unionTypes);
|
|
|
if(uids.isEmpty()){
|
|
|
return null;
|
|
|
}
|
|
|
return uids;
|
|
|
}
|
|
|
private UnionShareOrderSearchBo initUnionShareOrderSearchBo(UnionShareOrderSearchReqBO reqBO){
|
|
|
UnionShareOrderSearchBo bo=new UnionShareOrderSearchBo();
|
|
|
bo.setBeginTime(StringUtils.isBlank(reqBO.getBeginTime()) ? 0 : Integer.parseInt(reqBO.getBeginTime()));
|
|
|
bo.setEndTime(StringUtils.isBlank(reqBO.getEndTime()) ? 0 : Integer.parseInt(reqBO.getEndTime()));
|
|
|
bo.setOrderCode(StringUtils.isBlank(reqBO.getOrderCode()) ? null : reqBO.getOrderCode());
|
|
|
bo.setUnionType(StringUtils.isBlank(reqBO.getUnionId()) ? null :Long.valueOf( reqBO.getUnionId()));
|
|
|
bo.setUnionName(StringUtils.isBlank(reqBO.getUnionType()) ? null : reqBO.getUnionType());
|
|
|
bo.setChannelType(StringUtils.isBlank(reqBO.getChannelType())?null:reqBO.getChannelType());
|
|
|
bo.setIdList(reqBO.getIdsList());
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
private List<UnionShareOrderRspBO> queryUnionShareOrderRsp(Map<String,UnionShareOrders> ordersDOMap){
|
|
|
List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOMap.size());
|
|
|
Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = initUserShareOrderDatails(ordersDOMap);
|
|
|
for (UnionShareOrders orders : ordersDOMap.values()) {
|
|
|
UnionShareOrderRspBO bo=initShareUnionOrderRspBO(orders,userOrderDatailBOMap);
|
|
|
unionOrderRspBOList.add(bo);
|
|
|
}
|
|
|
return unionOrderRspBOList;
|
|
|
}
|
|
|
|
|
|
private UnionShareOrderRspBO initShareUnionOrderRspBO(UnionShareOrders orders,Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap){
|
|
|
UnionShareOrderRspBO orderRspBO=new UnionShareOrderRspBO();
|
|
|
orderRspBO.setOrderAmount(orders.getAmount());
|
|
|
orderRspBO.setOrderStatus(OrderStatusEnum.getNameByCode(orders.getStatus()));
|
|
|
Byte isNew=orders.getIsNew();
|
|
|
orderRspBO.setIsNew(isNew==null||isNew.equals(2)?"N":"Y");
|
|
|
orderRspBO.setUid(orders.getPromoteUid());
|
|
|
orderRspBO.setOrderCode(Long.parseLong(orders.getOrderCode()));
|
|
|
orderRspBO.setOrderCode(orders.getOrderCode());
|
|
|
orderRspBO.setId(orders.getId());
|
|
|
orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd HH:mm:ss"));
|
|
|
UserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getOrderCode());
|
|
|
orderRspBO.setUnionId(userOrderDatailBO.getUnionId());
|
|
|
ShareUserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getOrderCode());
|
|
|
orderRspBO.setUnionId(userOrderDatailBO.getUnionType());
|
|
|
orderRspBO.setUnionType(userOrderDatailBO.getUnionName());
|
|
|
orderRspBO.setChannelType(userOrderDatailBO.getChannelType());
|
|
|
return orderRspBO;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -154,13 +183,13 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
|
}
|
|
|
return uids;
|
|
|
}
|
|
|
private Map<Long, UserOrderDatailBO> initUserShareOrderDatails( Map<String,UnionShareOrders> ordersDOMap){
|
|
|
Map<Long, UserOrderDatailBO> userOrderDatailBOMap = new HashMap<>(ordersDOMap.size());
|
|
|
private Map<String, ShareUserOrderDatailBO> initUserShareOrderDatails( Map<String,UnionShareOrders> ordersDOMap){
|
|
|
Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = new HashMap<>(ordersDOMap.size());
|
|
|
Map<Integer,UnionShareUser> userMap=unionShareUserMapper.selectByUids(getUids(ordersDOMap));
|
|
|
for (UnionShareOrders userOrders : ordersDOMap.values()) {
|
|
|
String unionType=userMap.get(userOrders.getPromoteUid()).getUnionType();
|
|
|
UserOrderDatailBO userOrderDatailBO = new UserOrderDatailBO();
|
|
|
userOrderDatailBO.setUnionId(unionType);
|
|
|
ShareUserOrderDatailBO userOrderDatailBO = new ShareUserOrderDatailBO();
|
|
|
userOrderDatailBO.setUnionType(unionType);
|
|
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:" + unionType, MktMarketingUrl.class);
|
|
|
if (mktMarketingUrl == null) {
|
|
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(unionType));
|
...
|
...
|
@@ -168,8 +197,9 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
|
}
|
|
|
if (mktMarketingUrl != null) {
|
|
|
userOrderDatailBO.setUnionName(mktMarketingUrl.getName());
|
|
|
userOrderDatailBO.setChannelType(mktMarketingUrl.getChannelType());
|
|
|
}
|
|
|
userOrderDatailBO.setOrderCode(Long.valueOf(userOrders.getOrderCode()));
|
|
|
userOrderDatailBO.setOrderCode(userOrders.getOrderCode());
|
|
|
userOrderDatailBOMap.put(userOrderDatailBO.getOrderCode(),userOrderDatailBO);
|
|
|
}
|
|
|
return userOrderDatailBOMap;
|
...
|
...
|
@@ -517,4 +547,43 @@ public class UnionShareServiceImpl implements IUnionShareService { |
|
|
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Class getDataClass() {
|
|
|
return UnionShareOrderRspBO.class;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<? extends Object> batchExport(String confStr) {
|
|
|
try {
|
|
|
UnionShareOrderSearchReqBO request = JSONObject.parseObject(confStr, UnionShareOrderSearchReqBO.class);
|
|
|
List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRspBOForExport(request);
|
|
|
if (CollectionUtils.isEmpty(unionOrderRspBOList)) {
|
|
|
throw new ServiceException(400, "没有要导出的数据");
|
|
|
}
|
|
|
return unionOrderRspBOList;
|
|
|
} catch (JSONException e) {
|
|
|
logger.warn("parse confStr error: confStr {}, e {}", confStr, e);
|
|
|
throw new ServiceException(400, "传入数据格式错误");
|
|
|
} catch (com.yoho.error.exception.ServiceException e) {
|
|
|
logger.warn("make url error params is confStr {}, e {}", confStr, e);
|
|
|
throw new ServiceException(e.getCode(), e.getErrorMessage());
|
|
|
}
|
|
|
}
|
|
|
private List<UnionShareOrderRspBO> queryUnionShareOrderRspBOForExport(UnionShareOrderSearchReqBO reqBO){
|
|
|
UnionShareOrderSearchBo bo=initUnionShareOrderSearchBo(reqBO);
|
|
|
Map<String,UnionShareOrders> ordersDOMap=null;
|
|
|
if(bo.getIdList()!=null&&!bo.getIdList().isEmpty()){
|
|
|
ordersDOMap= this.unionShareOrdersMapper.selectListByIds(bo.getIdList());
|
|
|
}else{
|
|
|
List<Integer> uids=null;
|
|
|
if(bo.getUnionType()!=null || bo.getUnionName()!=null || bo.getChannelType()!=null){
|
|
|
uids=queryUids(bo);
|
|
|
if(null==uids){
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
ordersDOMap=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uids, bo.getOrderCode());
|
|
|
}
|
|
|
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
|
|
|
}
|
|
|
} |
...
|
...
|
|