Authored by caoyan

订单查询

1 package com.yoho.order.dal; 1 package com.yoho.order.dal;
2 2
  3 +import java.util.List;
  4 +
3 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
4 6
5 import com.yoho.order.model.BuyerOrderMeta; 7 import com.yoho.order.model.BuyerOrderMeta;
@@ -12,4 +14,6 @@ public interface BuyerOrderMetaMapper { @@ -12,4 +14,6 @@ public interface BuyerOrderMetaMapper {
12 BuyerOrderMeta selectByOrderCodeAndKey(@Param("orderCode") String orderCode, @Param("metaKey") String metaKey); 14 BuyerOrderMeta selectByOrderCodeAndKey(@Param("orderCode") String orderCode, @Param("metaKey") String metaKey);
13 15
14 int updateMetaValue(@Param("orderCode") String orderCode, @Param("metaKey") String metaKey, @Param("metaValue") String metaValue); 16 int updateMetaValue(@Param("orderCode") String orderCode, @Param("metaKey") String metaKey, @Param("metaValue") String metaValue);
  17 +
  18 + List<BuyerOrderMeta> selectByBatchOrderCodeAndKey(@Param("list") List<String> orderCodeList, @Param("metaKey") String metaKey);
15 } 19 }
@@ -23,4 +23,12 @@ @@ -23,4 +23,12 @@
23 where order_code=#{orderCode} and meta_key=#{metaKey} 23 where order_code=#{orderCode} and meta_key=#{metaKey}
24 </update> 24 </update>
25 25
  26 + <select id="selectByBatchOrderCodeAndKey" resultMap="BaseResultMap">
  27 + select <include refid="Base_Column_List" />
  28 + from buyer_order_meta where meta_key=#{metaKey} and order_code in
  29 + <foreach collection="list" item="orderCode" open="(" separator="," close=")">
  30 + #{orderCode}
  31 + </foreach>
  32 + </select>
  33 +
26 </mapper> 34 </mapper>
@@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils; @@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.web.bind.annotation.RequestBody;
10 import org.springframework.web.bind.annotation.RequestMapping; 11 import org.springframework.web.bind.annotation.RequestMapping;
11 import org.springframework.web.bind.annotation.RestController; 12 import org.springframework.web.bind.annotation.RestController;
12 13
@@ -138,4 +139,11 @@ public class BuyerOrderController { @@ -138,4 +139,11 @@ public class BuyerOrderController {
138 List<OrderOperateRecordResp> result = buyerOrderService.queryOperateRecordList(req); 139 List<OrderOperateRecordResp> result = buyerOrderService.queryOperateRecordList(req);
139 return new ApiResponse.ApiResponseBuilder().code(200).message("获取信息成功").data(result).build(); 140 return new ApiResponse.ApiResponseBuilder().code(200).message("获取信息成功").data(result).build();
140 } 141 }
  142 +
  143 + @RequestMapping(value = "/queryByOrderCodeOrWaybillCode")
  144 + public ApiResponse queryByOrderCodeOrWaybillCode(@RequestBody String queryStr) {
  145 + LOGGER.info("queryByOrderCodeOrWaybillCode in. queryStr is {}", queryStr);
  146 + PageResponseBO<BuyerOrderResp> result = buyerOrderService.queryByOrderCodeOrWaybillCode(queryStr);
  147 + return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
  148 + }
141 } 149 }
@@ -42,4 +42,6 @@ public interface IBuyerOrderService { @@ -42,4 +42,6 @@ public interface IBuyerOrderService {
42 int updateReceiveInfo(BuyerOrderReq req); 42 int updateReceiveInfo(BuyerOrderReq req);
43 43
44 List<OrderOperateRecordResp> queryOperateRecordList(BuyerOrderReq req); 44 List<OrderOperateRecordResp> queryOperateRecordList(BuyerOrderReq req);
  45 +
  46 + PageResponseBO<BuyerOrderResp> queryByOrderCodeOrWaybillCode(String queryStr);
45 } 47 }
@@ -177,9 +177,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -177,9 +177,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
177 } 177 }
178 178
179 public PageResponseBO<BuyerOrderResp> queryOrderList(BuyerOrderReq req) { 179 public PageResponseBO<BuyerOrderResp> queryOrderList(BuyerOrderReq req) {
180 - if(!checkAndBuildParam(req)) {  
181 - return null;  
182 - } 180 + buildParam(req);
183 181
184 int total = buyerOrderMapper.selectTotalByCondition(req); 182 int total = buyerOrderMapper.selectTotalByCondition(req);
185 if(total == 0) { 183 if(total == 0) {
@@ -239,7 +237,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -239,7 +237,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
239 List<ExpressCompany> companyList = expressCompanyMapper.selectByIdList(expressCompanyIdList); 237 List<ExpressCompany> companyList = expressCompanyMapper.selectByIdList(expressCompanyIdList);
240 companyMap = companyList.stream().collect(Collectors.toMap(ExpressCompany::getId, ExpressCompany::getCompanyName)); 238 companyMap = companyList.stream().collect(Collectors.toMap(ExpressCompany::getId, ExpressCompany::getCompanyName));
241 } 239 }
242 -  
243 List<BuyerOrderResp> respList = convertToResp(orderList, buyerGoodsMap, sellerOrderMap, sellerGoodsMap,expressRecordMap, platformExpressRecordMap, companyMap,skupProductCodeMap); 240 List<BuyerOrderResp> respList = convertToResp(orderList, buyerGoodsMap, sellerOrderMap, sellerGoodsMap,expressRecordMap, platformExpressRecordMap, companyMap,skupProductCodeMap);
244 241
245 PageResponseBO<BuyerOrderResp> result=new PageResponseBO<>(); 242 PageResponseBO<BuyerOrderResp> result=new PageResponseBO<>();
@@ -251,6 +248,59 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -251,6 +248,59 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
251 return result; 248 return result;
252 } 249 }
253 250
  251 + public PageResponseBO<BuyerOrderResp> queryByOrderCodeOrWaybillCode(String queryStr) {
  252 + if(StringUtils.isEmpty(queryStr)) {
  253 + return null;
  254 + }
  255 +
  256 + List<BuyerOrder> orderList = Lists.newArrayList();
  257 + //先按订单号来查
  258 + BuyerOrder order = buyerOrderMapper.selectByOrderCode(queryStr);
  259 + if(null == order){//再按卖家运单号来查
  260 + BuyerOrderReq req = new BuyerOrderReq();
  261 + req.setSellerWaybillCode(queryStr);
  262 + List<BuyerOrder> list = buyerOrderMapper.selectByCondition(req);
  263 + if(CollectionUtils.isEmpty(list)){
  264 + return null;
  265 + }
  266 +
  267 + orderList.addAll(list);
  268 + }else{
  269 + orderList.add(order);
  270 + }
  271 +
  272 + //查询buyer_order_goods
  273 + List<String> buyerOrderCodeList = orderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
  274 + List<BuyerOrderGoods> buyerGoodsList = buyerOrderGoodsMapper.selectByOrderCode(buyerOrderCodeList);
  275 + if(CollectionUtils.isEmpty(buyerGoodsList)) {
  276 + return null;
  277 + }
  278 + Map<String, BuyerOrderGoods> buyerGoodsMap = buyerGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, b->b));
  279 +
  280 + //查询seller_order_goods
  281 + List<Integer> skupList = buyerGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
  282 + List<SellerOrderGoods> sellerGoodsList = sellerOrderGoodsMapper.selectByIds(skupList);
  283 + Map<Integer, SellerOrderGoods> sellerGoodsMap = sellerGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, s->s));
  284 +
  285 + //查询buyer_order_meta
  286 + List<BuyerOrderMeta> buyerOrderMetaList = buyerOrderMetaMapper.selectByBatchOrderCodeAndKey(buyerOrderCodeList, BUYER_ORDER_META_KEY_DELIVERY_ADDRESS);
  287 + Map<String, BuyerOrderMeta> buyerOrderMetaMap = buyerOrderMetaList.stream().collect(Collectors.toMap(BuyerOrderMeta::getOrderCode, b->b));
  288 +
  289 + //查询卖家快递单号
  290 + List<ExpressRecord> expressRecordList =expressRecordMapper.selectByOrderCodeListAndType(buyerOrderCodeList, Lists.newArrayList(EXPRESS_TYPE_SELLER_TO_JUDGE));
  291 + Map<String, ExpressRecord> expressRecordMap = expressRecordList.stream().collect(Collectors.toMap(ExpressRecord::getOrderCode, e->e));
  292 +
  293 +
  294 + List<BuyerOrderResp> respList = convertToRespForQuery(orderList, buyerGoodsMap, sellerGoodsMap,expressRecordMap, buyerOrderMetaMap);
  295 +
  296 + PageResponseBO<BuyerOrderResp> result=new PageResponseBO<>();
  297 + result.setList(respList);
  298 + result.setSize(respList.size());
  299 + result.setTotal(respList.size());
  300 +
  301 + return result;
  302 + }
  303 +
254 public JSONObject updateOrderStatus(BuyerOrderReq req) { 304 public JSONObject updateOrderStatus(BuyerOrderReq req) {
255 if(null == req.getId() || null == req.getStatus()) { 305 if(null == req.getId() || null == req.getStatus()) {
256 return null; 306 return null;
@@ -783,6 +833,36 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -783,6 +833,36 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
783 return respList; 833 return respList;
784 } 834 }
785 835
  836 + private List<BuyerOrderResp> convertToRespForQuery(List<BuyerOrder> orderList, Map<String, BuyerOrderGoods> buyerGoodsMap,
  837 + Map<Integer, SellerOrderGoods> sellerGoodsMap, Map<String, ExpressRecord> expressInfoMap,
  838 + Map<String, BuyerOrderMeta> buyerOrderMetaMap){
  839 + List<BuyerOrderResp> respList = Lists.newArrayList();
  840 + for(BuyerOrder item : orderList) {
  841 + if(null == buyerGoodsMap.get(item.getOrderCode())) {
  842 + continue;
  843 + }
  844 + Integer skup = buyerGoodsMap.get(item.getOrderCode()).getSkup();
  845 + BuyerOrderResp resp = new BuyerOrderResp();
  846 + resp.setOrderCode(item.getOrderCode());
  847 + resp.setSellerWaybillCode(null == expressInfoMap.get(item.getOrderCode()) ? "" : expressInfoMap.get(item.getOrderCode()).getWaybillCode());
  848 + resp.setProductName(sellerGoodsMap.get(skup).getProductName());
  849 + resp.setProductImage(ImagesHelper.getImageAbsoluteUrl(sellerGoodsMap.get(skup).getImageUrl(), ImagesConstant.BUCKET_GOODS_IMG));
  850 + resp.setColorName(sellerGoodsMap.get(skup).getColorName());
  851 + resp.setSizeName(sellerGoodsMap.get(skup).getSizeName());
  852 + resp.setGoodsPrice(String.format("%.2f", buyerGoodsMap.get(item.getOrderCode()).getGoodsPrice().doubleValue()));
  853 + resp.setAmount(null == item.getAmount() ? null : String.format("%.2f", item.getAmount().doubleValue()));
  854 + JSONObject metaValue = JSONObject.parseObject(buyerOrderMetaMap.get(item.getOrderCode()).getMetaValue());
  855 + resp.setReceiveName(metaValue.getString("consignee"));
  856 + resp.setReceiveMobile(metaValue.getString("mobile"));
  857 + String receiveAddressCode = metaValue.getString("areaCode");
  858 + resp.setReceiveAddress(getAddressInfo(receiveAddressCode));
  859 +
  860 + respList.add(resp);
  861 + }
  862 +
  863 + return respList;
  864 + }
  865 +
786 private List<Byte> getStatusListByNavStatus(Integer navStatus) { 866 private List<Byte> getStatusListByNavStatus(Integer navStatus) {
787 switch(navStatus) { 867 switch(navStatus) {
788 case 1: return Lists.newArrayList(Constant.BUYER_ORDER_STATUS_BUYER_NOT_PAY.getByteVal()); 868 case 1: return Lists.newArrayList(Constant.BUYER_ORDER_STATUS_BUYER_NOT_PAY.getByteVal());
@@ -803,7 +883,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -803,7 +883,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
803 } 883 }
804 } 884 }
805 885
806 - private boolean checkAndBuildParam(BuyerOrderReq req) { 886 + private void buildParam(BuyerOrderReq req) {
807 if(StringUtils.isNotEmpty(req.getStatusStr())) { 887 if(StringUtils.isNotEmpty(req.getStatusStr())) {
808 req.setStatusList(convertStatus(req.getStatusStr())); 888 req.setStatusList(convertStatus(req.getStatusStr()));
809 } 889 }
@@ -812,18 +892,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -812,18 +892,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
812 req.setStatusList(getStatusListByNavStatus(req.getNavStatus())); 892 req.setStatusList(getStatusListByNavStatus(req.getNavStatus()));
813 } 893 }
814 894
815 -// if(StringUtils.isNotEmpty(req.getSellerWaybillCode())) {  
816 -// List<ExpressRecord> expressRecordList = expressoRecordMapper.selectByWaybillCode(req.getSellerWaybillCode());  
817 -// if(CollectionUtils.isEmpty(expressRecordList)) {  
818 -// return false;  
819 -// }else {  
820 -// List<String> buyerOrderCodeList = expressRecordList.stream().map(ExpressRecord::getOrderCode).collect(Collectors.toList());  
821 -// List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(buyerOrderCodeList);  
822 -// List<Integer> skupList = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());  
823 -// req.setSkupList(skupList);  
824 -// }  
825 -// }  
826 -  
827 if(StringUtils.isNotEmpty(req.getMobile())) { 895 if(StringUtils.isNotEmpty(req.getMobile())) {
828 Integer uid = getUidByMobile(req.getMobile()); 896 Integer uid = getUidByMobile(req.getMobile());
829 if(null != uid) { 897 if(null != uid) {
@@ -831,8 +899,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -831,8 +899,6 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
831 } 899 }
832 } 900 }
833 901
834 - return true;  
835 -  
836 } 902 }
837 903
838 private List<Byte> convertStatus(String statusStr){ 904 private List<Byte> convertStatus(String statusStr){