|
|
package com.yoho.ufo.service.impl;
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
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.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.order.dal.SellerOrderGoodsMapper;
|
|
|
import com.yoho.order.model.SellerOrderGoods;
|
|
|
import com.yoho.product.dal.SecondhandFlawMapper;
|
|
|
import com.yoho.product.dal.SecondhandImagesMapper;
|
|
|
import com.yoho.product.dal.SecondhandInfoMapper;
|
|
|
import com.yoho.product.model.SecondhandFlaw;
|
|
|
import com.yoho.product.model.SecondhandImages;
|
|
|
import com.yoho.product.model.SecondhandInfo;
|
|
|
import com.yoho.product.model.SecondhandReq;
|
...
|
...
|
@@ -27,10 +35,13 @@ import com.yoho.ufo.service.model.PageResponseBO; |
|
|
import com.yoho.ufo.util.DateUtil;
|
|
|
import com.yohobuy.ufo.model.enums.ProductSkupStatusEnum;
|
|
|
import com.yohobuy.ufo.model.enums.StorageTypeEnum;
|
|
|
import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
|
|
|
|
|
|
@Service
|
|
|
public class SecondhandProductService implements ISecondhandProductService{
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(SecondhandProductService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SecondhandInfoMapper secondhandInfoMapper;
|
|
|
|
...
|
...
|
@@ -46,6 +57,12 @@ public class SecondhandProductService implements ISecondhandProductService{ |
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SecondhandFlawMapper secondhandFlawMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ServiceCaller serviceCaller;
|
|
|
|
|
|
private static final Integer STATUS_NEW = 0;
|
|
|
|
|
|
private static final Integer STATUS_WAIT_TO_BE_AUDITED = 10;
|
...
|
...
|
@@ -102,8 +119,13 @@ public class SecondhandProductService implements ISecondhandProductService{ |
|
|
List<Product> productList = productMapper.selectProductListByIds(productIdList);
|
|
|
Map<Integer, String> productIdNameMap = productList.stream().collect(Collectors.toMap(Product::getId, Product::getProductName));
|
|
|
|
|
|
//查询secondhand_flaw
|
|
|
List<String> flawIdStrList = infoList.stream().map(SecondhandInfo::getFlawId).collect(Collectors.toList());
|
|
|
List<SecondhandFlaw> flawList = secondhandFlawMapper.selectBatchByIds(getFlawIdList(flawIdStrList));
|
|
|
Map<Integer, String> flawMap = flawList.stream().collect(Collectors.toMap(SecondhandFlaw::getId, SecondhandFlaw::getName));
|
|
|
|
|
|
//组装
|
|
|
List<SecondhandRsp> respList = convertToResp(infoList, skupImageMap, storagePriceMap, sellerGoodsMap, productIdNameMap);
|
|
|
List<SecondhandRsp> respList = convertToResp(infoList, skupImageMap, storagePriceMap, sellerGoodsMap, productIdNameMap, flawMap);
|
|
|
|
|
|
PageResponseBO<SecondhandRsp> result=new PageResponseBO<>();
|
|
|
result.setList(respList);
|
...
|
...
|
@@ -124,26 +146,85 @@ public class SecondhandProductService implements ISecondhandProductService{ |
|
|
auditInfo.setAuditName(userInfo.getUserName());
|
|
|
auditInfo.setAuditUid(userInfo.getUserId());
|
|
|
auditInfo.setAuditTime(DateUtil.getCurrentTimeSeconds());
|
|
|
return secondhandInfoMapper.updateAuditInfoBySkup(auditInfo);
|
|
|
int num = secondhandInfoMapper.updateAuditInfoBySkup(auditInfo);
|
|
|
if(num ==0) {
|
|
|
return num;
|
|
|
}
|
|
|
//更新storage_price
|
|
|
num = storagePriceMapper.updateStatusBySkup(req.getStatus(), req.getSkup());
|
|
|
if(num == 0) {
|
|
|
return num;
|
|
|
}
|
|
|
//审核不通过,调用前台接口/erp/auditFailed
|
|
|
if(req.getStatus().equals(ProductSkupStatusEnum.CHECK_REJEST.getStatus())) {
|
|
|
asyncCallAuditFail("ufo-gateway.auditFailed", req.getSkup(), req.getRejectReason());
|
|
|
}
|
|
|
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
public List<SecondhandImages> queryImageList(Integer skup){
|
|
|
List<SecondhandImages> list = secondhandImagesMapper.selectBySkups(Lists.newArrayList(skup));
|
|
|
List<Integer> codeList = list.stream().map(SecondhandImages::getCode).collect(Collectors.toList());
|
|
|
List<SecondhandFlaw> flawList = secondhandFlawMapper.selectBatchByIds(codeList);
|
|
|
Map<Integer, String> flawIdNameMap = flawList.stream().collect(Collectors.toMap(SecondhandFlaw::getId, SecondhandFlaw::getName));
|
|
|
rebuiltImageList(list, flawIdNameMap);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private JSONObject asyncCallAuditFail(String args, Integer skup, String rejectReason) {
|
|
|
LOGGER.info("asyncCallAuditFail call ufo-gateway enter skup is {}, interface is {}", skup, args);
|
|
|
SellerOrderCancelReq request = new SellerOrderCancelReq();
|
|
|
request.setSkup(skup);
|
|
|
request.setRejectReason(rejectReason);
|
|
|
JSONObject jsonObject = serviceCaller.asyncCall(args, request, JSONObject.class).get(5, TimeUnit.SECONDS);
|
|
|
LOGGER.info("asyncCallAuditFail call ufo-gateway skup is {}, interface is {},result is {}", skup, args, jsonObject);
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
private List<Integer> getFlawIdList(List<String> flawIdStrList){
|
|
|
List<Integer> flawIdList = Lists.newArrayList();
|
|
|
for(String item : flawIdStrList) {
|
|
|
String[] idStrArr = item.split(",");
|
|
|
for(int i=0; i<idStrArr.length; i++) {
|
|
|
flawIdList.add(Integer.parseInt(idStrArr[i]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return removeDuplicate(flawIdList);
|
|
|
}
|
|
|
|
|
|
public static List removeDuplicate(List list) {
|
|
|
HashSet h = new HashSet(list);
|
|
|
list.clear();
|
|
|
list.addAll(h);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private List<SecondhandRsp> convertToResp(List<SecondhandInfo> infoList, Map<Integer, List<SecondhandImages>> skupImageMap,
|
|
|
Map<Integer, StoragePrice> storagePriceMap, Map<Integer, SellerOrderGoods> sellerGoodsMap,
|
|
|
Map<Integer, String> productIdNameMap){
|
|
|
Map<Integer, String> productIdNameMap, Map<Integer, String> flawMap){
|
|
|
List<SecondhandRsp> respList = Lists.newArrayList();
|
|
|
for(SecondhandInfo item : infoList) {
|
|
|
SecondhandRsp rsp = new SecondhandRsp();
|
|
|
Integer skup = item.getSkup();
|
|
|
rsp.setSkup(skup);
|
|
|
StoragePrice storagePrice = storagePriceMap.get(skup);
|
|
|
if(null == storagePrice) {
|
|
|
continue;
|
|
|
}
|
|
|
rsp.setSkupType(storagePrice.getPreSaleFlag());
|
|
|
rsp.setSkupTypeStr(StorageTypeEnum.getTypeName(storagePrice.getPreSaleFlag()));
|
|
|
List<SecondhandImages> secondhandImagesList = skupImageMap.get(skup);
|
|
|
rebuiltImageList(secondhandImagesList, flawMap);
|
|
|
rsp.setImageList(secondhandImagesList);
|
|
|
rsp.setProductImage(getProductImage(secondhandImagesList));
|
|
|
rsp.setDescribeInfo(item.getDescribeInfo());
|
|
|
rsp.setSku(storagePrice.getStorageId());
|
|
|
SellerOrderGoods sellerGoods = sellerGoodsMap.get(skup);
|
|
|
if(null == sellerGoods) {
|
|
|
continue;
|
|
|
}
|
|
|
rsp.setColorName(sellerGoods.getColorName());
|
|
|
rsp.setSizeName(sellerGoods.getSizeName());
|
|
|
rsp.setSellerUid(storagePrice.getSellerUid());
|
...
|
...
|
@@ -162,6 +243,12 @@ public class SecondhandProductService implements ISecondhandProductService{ |
|
|
return respList;
|
|
|
}
|
|
|
|
|
|
private void rebuiltImageList(List<SecondhandImages> imageList, Map<Integer, String> flawIdNameMap) {
|
|
|
for(SecondhandImages image : imageList) {
|
|
|
image.setImageDesc(flawIdNameMap.get(image.getCode()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String getProductImage(List<SecondhandImages> imageList) {
|
|
|
String imageUrl = "";
|
|
|
if(CollectionUtils.isNotEmpty(imageList)) {
|
...
|
...
|
|