|
|
package com.yoho.ufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.order.dal.TradeBillsMapper;
|
|
|
import com.yoho.order.model.*;
|
|
|
import com.yoho.ufo.order.constant.TradeStatusEnum;
|
|
|
import com.yoho.ufo.order.service.ITradeBillsService;
|
|
|
import com.yoho.ufo.service.impl.UserHelper;
|
|
|
import com.yoho.ufo.service.model.PageResponseBO;
|
|
|
import com.yohobuy.ufo.model.order.resp.*;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.common.collect.Lists;
|
|
|
import org.elasticsearch.common.collect.Maps;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author craig.qin
|
|
|
*/
|
|
|
@Service
|
|
|
public class TradeBillsServiceImpl implements ITradeBillsService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TradeBillsServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
@Value("${ip.port.uic.server}")
|
|
|
private String uicServerIpAndPort;
|
|
|
|
|
|
private static final String UIC_GETPROFILE_URL = "/uic/profile/getProfile";
|
|
|
|
|
|
private static final String UIC_GETUSERPROFILE_URL = "/uic/profile/getUserProfile";
|
|
|
|
|
|
@Autowired
|
|
|
private TradeBillsMapper tradeBillsMapper;
|
|
|
|
|
|
public PageResponseBO<TradeBillsResp> queryTradeBillsList(TradeBillsReq req) {
|
|
|
if(!checkAndBuildParam(req)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if(req.getUid()==null&&StringUtils.isNotBlank(req.getMobile())){
|
|
|
Integer uid = getUidByMobile(req.getMobile());
|
|
|
if(uid!=null){
|
|
|
req.setUid(uid);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int total = tradeBillsMapper.selectCountByCondition(req);
|
|
|
if(total == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<TradeBills> tradeBillsList = tradeBillsMapper.selectByConditionWithPage(req);
|
|
|
if(CollectionUtils.isEmpty(tradeBillsList)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<TradeBillsResp> respList = convertToResp(tradeBillsList);
|
|
|
|
|
|
PageResponseBO<TradeBillsResp> result=new PageResponseBO<>();
|
|
|
result.setList(respList);
|
|
|
result.setPage(req.getPage());
|
|
|
result.setSize(req.getSize());
|
|
|
result.setTotal(total);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private boolean checkAndBuildParam(TradeBillsReq req){
|
|
|
/*if(req.getUid()==null&&req.getOrderCode()==null&&StringUtils.isBlank(req.getMobile())){
|
|
|
return false;
|
|
|
}*/
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private List<TradeBillsResp> convertToResp(List<TradeBills> tradeBillsList){
|
|
|
List<TradeBillsResp> respList = Lists.newArrayList();
|
|
|
for(TradeBills item : tradeBillsList) {
|
|
|
TradeBillsResp resp=new TradeBillsResp();
|
|
|
resp.setId(item.getId());
|
|
|
resp.setUid(item.getUid());
|
|
|
resp.setMobile(getMobileByUid(item.getUid()));
|
|
|
resp.setOrderCode(item.getOrderCode());
|
|
|
resp.setAmount(item.getAmount());
|
|
|
resp.setIncomeOutcome(item.getIncomeOutcome());
|
|
|
resp.setCreateTimeStr(null == item.getCreateTime() ? "" : DateUtil.long2DateStr(item.getCreateTime().longValue()*1000, "yyyy-MM-dd HH:mm:ss"));
|
|
|
resp.setOperatorUid(item.getDealUid());
|
|
|
resp.setOperatorName(item.getDealUid()==0?"系统":item.getDealUserName());
|
|
|
resp.setTradeStatus(item.getTradeStatus());
|
|
|
//打款失败原因
|
|
|
if(100!=item.getTradeStatus()){
|
|
|
String failReason = TradeStatusEnum.getDescByCode(item.getTradeStatus());
|
|
|
resp.setTradeStatusDesc(StringUtils.isBlank(failReason)?String.valueOf(item.getTradeStatus()):failReason);
|
|
|
}
|
|
|
|
|
|
respList.add(resp);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return respList;
|
|
|
}
|
|
|
|
|
|
private String getMobileByUid(Integer uid) {
|
|
|
LOGGER.info("TradeBillsServiceImpl call getMobileByUid uid is{}", uid);
|
|
|
Map<String,Integer> request = Collections.singletonMap("uid", uid);
|
|
|
JSONObject jsonObject = serviceCaller.get("uic.getProfileAction", "http://" + uicServerIpAndPort + UIC_GETPROFILE_URL, request, JSONObject.class, null).get(1);
|
|
|
|
|
|
if(null == jsonObject.getJSONObject("data") || null == jsonObject.getJSONObject("data").getString("mobile_phone")) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return jsonObject.getJSONObject("data").getString("mobile_phone");
|
|
|
}
|
|
|
|
|
|
private Integer getUidByMobile(String mobile) {
|
|
|
Map<String,String> request = Collections.singletonMap("account", mobile);
|
|
|
JSONObject jsonObject = serviceCaller.get("uic.getProfileAction", "http://" + uicServerIpAndPort + UIC_GETPROFILE_URL, request, JSONObject.class, null).get(1);
|
|
|
if(null == jsonObject.getJSONObject("data") || null == jsonObject.getJSONObject("data").getInteger("uid")) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return jsonObject.getJSONObject("data").getInteger("uid");
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|