|
|
package com.yoho.ufo.order.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.order.dal.*;
|
|
|
import com.yoho.order.model.*;
|
|
|
import com.yoho.ufo.exception.PlatformException;
|
|
|
import com.yoho.ufo.service.model.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
|
|
|
import org.apache.commons.collections.ArrayStack;
|
|
|
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.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
...
|
...
|
@@ -55,12 +69,29 @@ public class AppraiseOrderServiceImpl implements IAppraiseOrderService{ |
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderStorageMapper appraiseOrderStorageMapper;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ExpressRecordMapper expressRecordMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private OrdersPayRefundMapper ordersPayRefundMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private StoredSellerMapper storedSellerMapper;
|
|
|
|
|
|
|
|
|
@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 ServiceCaller serviceCaller;
|
|
|
|
|
|
@Autowired
|
|
|
private StorageDepositMapper storageDepositMapper;
|
...
|
...
|
@@ -165,7 +196,188 @@ public class AppraiseOrderServiceImpl implements IAppraiseOrderService{ |
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public PageResponseBO<AppraiseOrderResp> queryOrderList(AppraiseOrderReq req) throws PlatformException {
|
|
|
Byte status = req.getStatus();
|
|
|
List<Byte> checkStatusList = Lists.newArrayList();
|
|
|
if (status != null && status >= 0) {
|
|
|
if (status == 101) {
|
|
|
checkStatusList = Arrays.asList((byte) 12, (byte) 14, (byte) 15, (byte) 23);
|
|
|
} else if (status == 102) {
|
|
|
checkStatusList = Arrays.asList((byte) 34, (byte) 13);
|
|
|
} else {
|
|
|
checkStatusList = Arrays.asList(status);
|
|
|
}
|
|
|
}
|
|
|
req.setStatusList(checkStatusList);
|
|
|
req.setBuyStartTime(parseTime(req.getBuyStartTimeStr()));
|
|
|
req.setBuyEndTime(parseTime(req.getBuyEndTimeStr()));
|
|
|
|
|
|
int count = appraiseOrderMapper.selectParentListCount(req);
|
|
|
|
|
|
PageResponseBO<AppraiseOrderResp> resp = new PageResponseBO<>();
|
|
|
resp.setTotal(count);
|
|
|
if (count == 0) {
|
|
|
resp.setList(Lists.newArrayList());
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
req.setStart((req.getPage() - 1) * req.getSize());
|
|
|
List<AppraiseOrder> orderList = appraiseOrderMapper.selectParentList(req);
|
|
|
List<AppraiseOrderResp> respList = exchangeBo(orderList);
|
|
|
|
|
|
resp.setPage(req.getPage());
|
|
|
resp.setList(respList);
|
|
|
resp.setSize(req.getSize());
|
|
|
resp.setTotal(count);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
public AppraiseOrderResp detailInfo(AppraiseOrderReq req) {
|
|
|
AppraiseOrderResp result = new AppraiseOrderResp();
|
|
|
Integer uid = req.getUid();
|
|
|
String orderCode = req.getOrderCode();
|
|
|
List<Map<String, Object>> countInfo = appraiseOrderMapper.selectCountInfo(orderCode);
|
|
|
int count = 0;
|
|
|
for (Map<String, Object> record : countInfo) {
|
|
|
int c = ((Number) record.get("num")).intValue();
|
|
|
count += c;
|
|
|
if (record.get("status").toString().equals(Integer.toString(AppraiseOrderStatus.JUDGE_PASS.getCode()))) {
|
|
|
result.setAppraiseOkCount(c);
|
|
|
}
|
|
|
if (record.get("status").toString().equals(Integer.toString(AppraiseOrderStatus.CHECKING_FAKE.getCode()))) {
|
|
|
result.setAppraiseBadCount(c);
|
|
|
}
|
|
|
if (record.get("status").toString().equals(Integer.toString(AppraiseOrderStatus.CHECKING_FAKE.getCode()))) {
|
|
|
result.setAppraiseFaultCount(c);// TODO
|
|
|
}
|
|
|
if (record.get("status").toString().equals(Integer.toString(AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()))) {
|
|
|
result.setNoAppraiseCount(c);
|
|
|
}
|
|
|
if (record.get("status").toString().equals(Integer.toString(AppraiseOrderStatus.SHAM_SEND_OUT.getCode()))) {
|
|
|
result.setUnReceiveCount(c);
|
|
|
}
|
|
|
}
|
|
|
result.setCount(count);
|
|
|
result.setReceiveCount(count - result.getUnReceiveCount());
|
|
|
|
|
|
//卖家信息
|
|
|
result.setUserName(getUserNameByUid(uid));
|
|
|
result.setMobile(getMobileByUid(uid));
|
|
|
result.setUid(uid);
|
|
|
|
|
|
AppraiseOrderMeta addressInfo = appraiseOrderMetaMapper.selectAddress(orderCode);
|
|
|
if (addressInfo != null) {
|
|
|
JSONObject jo = JSON.parseObject(addressInfo.getMetaValue());
|
|
|
result.setBackAddress(jo.getString("area"));
|
|
|
result.setBackAddressDetail(jo.getString("address"));
|
|
|
result.setBackMobile(jo.getString("mobile"));
|
|
|
}
|
|
|
StoredSeller storedSeller = storedSellerMapper.selectUid(uid);
|
|
|
if (storedSeller != null && storedSeller.getEntryType() != null) {
|
|
|
if (1 == storedSeller.getEntryType()) {
|
|
|
result.setUserDegree("入驻卖家");
|
|
|
} else if (2 == storedSeller.getEntryType()) {
|
|
|
result.setUserDegree("超级卖家");
|
|
|
}
|
|
|
} else {
|
|
|
result.setUserDegree("普通卖家");
|
|
|
}
|
|
|
List<ExpressRecord> expressRecordList = expressRecordMapper.selectByOrderCodeListAndType(Arrays.asList(orderCode), Lists.newArrayList(EnumExpressType.EXPRESS_TYPE_1.getCode()));
|
|
|
if (!expressRecordList.isEmpty()) {
|
|
|
result.setExpressNumber(expressRecordList.get(0).getWaybillCode());
|
|
|
result.setDeliverTimeStr(formatTime(expressRecordList.get(0).getCreateTime()));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponseBO<AppraiseOrderResp> queryOrderDetailList(AppraiseOrderReq req) {
|
|
|
long orderCode = Long.parseLong(req.getOrderCode());
|
|
|
|
|
|
int count = appraiseOrderMapper.selectSonListCount(req);
|
|
|
|
|
|
PageResponseBO<AppraiseOrderResp> resp = new PageResponseBO<>();
|
|
|
resp.setTotal(count);
|
|
|
if (count == 0) {
|
|
|
resp.setList(Lists.newArrayList());
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
req.setStart((req.getPage() - 1) * req.getSize());
|
|
|
List<AppraiseOrder> orderList = appraiseOrderMapper.selectSonList(req);
|
|
|
List<AppraiseOrderGoods> goodsList = appraiseOrderGoodsMapper.selectByOrderCodes(orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList()));
|
|
|
List<AppraiseOrderStorage> storageList = appraiseOrderStorageMapper.selectByOrderCodes(orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList()));
|
|
|
List<AppraiseOrderMeta> feeList = appraiseOrderMetaMapper.selectFeeByOrderCodes(orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList()));
|
|
|
List<OrdersPayRefund> refundList = ordersPayRefundMapper.selectByRefundCodes(orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList()));
|
|
|
List<AppraiseOrderResp> respList = exchangeBo(orderList, goodsList, refundList, storageList, feeList);
|
|
|
|
|
|
resp.setPage(req.getPage());
|
|
|
resp.setList(respList);
|
|
|
resp.setSize(req.getSize());
|
|
|
resp.setTotal(count);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
private List<AppraiseOrderResp> exchangeBo(List<AppraiseOrder> orderList, List<AppraiseOrderGoods> goodsList, List<OrdersPayRefund> refundList, List<AppraiseOrderStorage> storageList, List<AppraiseOrderMeta> feeList) {
|
|
|
Map<String, AppraiseOrderStorage> storageMap = storageList.stream().collect(Collectors.toMap(AppraiseOrderStorage::getOrderCode, Function.identity()));
|
|
|
Map<String, AppraiseOrderGoods> goodsMap = goodsList.stream().collect(Collectors.toMap(AppraiseOrderGoods::getOrderCode, Function.identity()));
|
|
|
Map<Long, AppraiseOrderMeta> feeMap = feeList.stream().collect(Collectors.toMap(AppraiseOrderMeta::getOrderCode, Function.identity()));
|
|
|
Map<Long, OrdersPayRefund> refundMap = refundList.stream().collect(Collectors.toMap(OrdersPayRefund::getOrderCode, Function.identity()));
|
|
|
List<AppraiseOrderResp> result = Lists.newArrayList();
|
|
|
for(AppraiseOrder order : orderList) {
|
|
|
AppraiseOrderResp r = new AppraiseOrderResp();
|
|
|
BeanUtils.copyProperties(order, r);
|
|
|
AppraiseOrderStorage s = storageMap.get(order.getOrderCode());
|
|
|
if (s != null) {
|
|
|
BeanUtils.copyProperties(s, r);
|
|
|
}
|
|
|
AppraiseOrderGoods goods = goodsMap.get(order.getOrderCode());
|
|
|
if (goods != null) {
|
|
|
BeanUtils.copyProperties(goods, r);
|
|
|
}
|
|
|
AppraiseOrderMeta fee = feeMap.get(Long.parseLong(order.getOrderCode()));
|
|
|
if (fee != null) {
|
|
|
JSONObject j = JSON.parseObject(fee.getMetaValue());
|
|
|
r.setAvgPrice7Day(j.getString("prdPrice"));
|
|
|
r.setAppraiseFee(j.getJSONObject("platformFee").getString("appraiseFee"));
|
|
|
r.setPackageFee(j.getJSONObject("platformFee").getString("packageFee"));
|
|
|
r.setStorageManagementFee(j.getJSONObject("platformFee").getString("storageManagementFee"));
|
|
|
}
|
|
|
r.setAmount(order.getAmount().toString());
|
|
|
OrdersPayRefund refund = refundMap.get(Long.parseLong(order.getOrderCode()));
|
|
|
if (refund != null) {
|
|
|
r.setBackAmount(refund.getAmount().toString());
|
|
|
r.setUsedAmount(order.getAmount().subtract(refund.getAmount()).toString());
|
|
|
} else {
|
|
|
r.setBackAmount(BigDecimal.ZERO.toString());
|
|
|
r.setUsedAmount(order.getAmount().toString());
|
|
|
}
|
|
|
r.setCreateTimeStr(formatTime(order.getCreateTime()));
|
|
|
AppraiseOrderStatus status = AppraiseOrderStatus.getByCode(order.getStatus().intValue());
|
|
|
r.setStatusStr(status == null ? "" : status.getDesc());
|
|
|
result.add(r);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
private List<AppraiseOrderResp> exchangeBo(List<AppraiseOrder> orderList) {
|
|
|
List<AppraiseOrderResp> result = Lists.newArrayList();
|
|
|
for(AppraiseOrder order : orderList) {
|
|
|
AppraiseOrderResp r = new AppraiseOrderResp();
|
|
|
BeanUtils.copyProperties(order, r);
|
|
|
r.setAmount(order.getAmount().toString());
|
|
|
r.setCreateTimeStr(formatTime(order.getCreateTime()));
|
|
|
AppraiseOrderStatus status = AppraiseOrderStatus.getByCode(order.getStatus().intValue());
|
|
|
r.setStatusStr(status == null ? "" : status.getDesc());
|
|
|
result.add(r);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public AppraiseOrderResp getOrderDetail(String orderCode) {
|
|
|
AppraiseOrder order = appraiseOrderMapper.selectByOrderCode(orderCode);
|
...
|
...
|
@@ -418,5 +630,58 @@ public class AppraiseOrderServiceImpl implements IAppraiseOrderService{ |
|
|
}
|
|
|
}
|
|
|
|
|
|
private String getUserNameByUid(Integer uid) {
|
|
|
Map<String,Integer> request = Collections.singletonMap("uid", uid);
|
|
|
String url = "http://" + uicServerIpAndPort + UIC_GETUSERPROFILE_URL;
|
|
|
JSONObject jsonObject;
|
|
|
try {
|
|
|
jsonObject = serviceCaller.post("uic.getUserProfileAction", url, request, JSONObject.class, null).get(1);
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("call"+ url + " fail!!! uid is {}", uid);
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
if(null != jsonObject) {
|
|
|
return jsonObject.getString("profile_name");
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
private String getMobileByUid(Integer uid) {
|
|
|
LOGGER.info("call getMobileByUid uid is{}", uid);
|
|
|
Map<String,Integer> request = Collections.singletonMap("uid", uid);
|
|
|
String url = "http://" + uicServerIpAndPort + UIC_GETPROFILE_URL;
|
|
|
JSONObject jsonObject;
|
|
|
try {
|
|
|
jsonObject = serviceCaller.get("uic.getProfileAction", url, request, JSONObject.class, null).get(1);
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("call"+ url + " fail!!! uid is {}", uid);
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
if(null == jsonObject.getJSONObject("data") || null == jsonObject.getJSONObject("data").getString("mobile_phone")) {
|
|
|
return "";
|
|
|
}
|
|
|
return jsonObject.getJSONObject("data").getString("mobile_phone");
|
|
|
}
|
|
|
|
|
|
private Integer parseTime(String time) throws PlatformException {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
try {
|
|
|
if (StringUtils.isNotBlank(time)) {
|
|
|
return (int) (format.parse(time).getTime() / 1000);
|
|
|
}
|
|
|
return null;
|
|
|
} catch (ParseException e) {
|
|
|
throw new PlatformException("日期解析错误!", 400);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String formatTime(Integer time) {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
if (time != null && time > 0) {
|
|
|
return format.format(new Date(time * 1000L));
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|