Authored by caoyan

Merge branch 'dev6.8.6.5-platform-quality4app' into test6.8.6.5

  1 +package com.yoho.ufo.util;
  2 +
  3 +import org.apache.commons.lang3.StringUtils;
  4 +
  5 +/**
  6 + * 手机号码公共处理helper类
  7 + *
  8 + * @author yoho
  9 + *
  10 + */
  11 +public class MobileHelper {
  12 +
  13 + /**
  14 + * 覆盖手机号码中4位为*
  15 + *
  16 + * @param mobile
  17 + * @return
  18 + */
  19 + public static String coverMobile(String mobile) {
  20 + if (StringUtils.isEmpty(mobile)) {
  21 + return mobile;
  22 + }
  23 + // 11位国内手机号
  24 + if (mobile.matches("\\d{11}")) {
  25 + StringBuffer sb = new StringBuffer();
  26 + sb.append(mobile.substring(0, 3)).append("****").append(mobile.substring(7));
  27 + return sb.toString();
  28 + }
  29 +
  30 + // 国际号码
  31 + int index = mobile.indexOf("-");
  32 + if (0 < index && mobile.length() > index + 3) {
  33 + StringBuffer sb = new StringBuffer();
  34 + sb.append(mobile.substring(0, index + 4)).append("****");
  35 + if (mobile.length() > index + 7) {
  36 + sb.append(mobile.substring(index + 8));
  37 + }
  38 + return sb.toString();
  39 + }
  40 + return mobile;
  41 + }
  42 +
  43 + /**
  44 + * 覆盖手机号码中6位为*
  45 + *
  46 + * @param mobile
  47 + * @return
  48 + */
  49 + public static String coverMobile2(String mobile) {
  50 + if (StringUtils.isEmpty(mobile)) {
  51 + return mobile;
  52 + }
  53 + // 11位国内手机号
  54 + if (mobile.matches("\\d{11}")) {
  55 + StringBuffer sb = new StringBuffer();
  56 + sb.append(mobile.substring(0, 3)).append("****").append(mobile.substring(7));
  57 + return sb.toString();
  58 + }
  59 +
  60 + // 国际号码--隐藏中间4位
  61 + int index = mobile.indexOf("-");
  62 + if (0 < index && mobile.length() > index + 3) {
  63 + StringBuffer sb = new StringBuffer();
  64 + sb.append(mobile.substring(0, index + 4)).append("****");
  65 + if (mobile.length() > index + 7) {
  66 + sb.append(mobile.substring(index + 8));
  67 + }
  68 + return sb.toString();
  69 + }
  70 + return mobile;
  71 + }
  72 + public static void main(String[] args) {
  73 + String a = "12345678";
  74 + System.out.println(coverMobile2(a));
  75 + }
  76 +
  77 +}
@@ -2,6 +2,8 @@ package com.yoho.order.dal; @@ -2,6 +2,8 @@ package com.yoho.order.dal;
2 2
3 import org.apache.ibatis.annotations.Param; 3 import org.apache.ibatis.annotations.Param;
4 4
  5 +import com.yoho.order.model.AppraiseAddress;
  6 +
5 /** 7 /**
6 * Created by caoyan on 2018/9/12. 8 * Created by caoyan on 2018/9/12.
7 */ 9 */
@@ -9,4 +11,6 @@ public interface AppraiseAddressMapper { @@ -9,4 +11,6 @@ public interface AppraiseAddressMapper {
9 11
10 String selectAddressByType(@Param("type") Integer type); 12 String selectAddressByType(@Param("type") Integer type);
11 13
  14 + AppraiseAddress selectByType(@Param("type") Integer type);
  15 +
12 } 16 }
@@ -98,5 +98,7 @@ public class BuyerOrderReq extends PageRequestBO{ @@ -98,5 +98,7 @@ public class BuyerOrderReq extends PageRequestBO{
98 private String checkText; 98 private String checkText;
99 99
100 private String imageUrls; 100 private String imageUrls;
  101 +
  102 + private Integer payMethod;//1:寄方付 2:收方付 3:第三方付
101 103
102 } 104 }
@@ -19,4 +19,11 @@ @@ -19,4 +19,11 @@
19 from appraise_address where type = #{type} 19 from appraise_address where type = #{type}
20 </select> 20 </select>
21 21
  22 + <select id="selectByType" resultMap = "BaseResultMap">
  23 + select <include refid="Base_Column_List"></include>
  24 + from appraise_address where type= #{type}
  25 + limit 1
  26 +
  27 + </select>
  28 +
22 </mapper> 29 </mapper>
@@ -411,5 +411,15 @@ public class BuyerOrderController { @@ -411,5 +411,15 @@ public class BuyerOrderController {
411 QcOrderDetailResp result = buyerOrderService.getQcOrderDetail(req.getOrderCode()); 411 QcOrderDetailResp result = buyerOrderService.getQcOrderDetail(req.getOrderCode());
412 return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build(); 412 return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
413 } 413 }
  414 +
  415 + @RequestMapping(value = "/getSfWaybillCode")
  416 + public ApiResponse getSfWaybillCode(BuyerOrderReq req) {
  417 + LOGGER.info("getSfWaybillCode in. param is {}", req);
  418 + if(StringUtils.isEmpty(req.getOrderCode()) || null == req.getPayMethod()) {
  419 + return new ApiResponse.ApiResponseBuilder().code(400).message("订单号或付款方式不能为空").build();
  420 + }
  421 + JSONObject result = buyerOrderService.getSfWaybillCode(req);
  422 + return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
  423 + }
414 424
415 } 425 }
@@ -94,4 +94,6 @@ public interface IBuyerOrderService { @@ -94,4 +94,6 @@ public interface IBuyerOrderService {
94 PageResponseBO<BuyerOrderResp> queryOrderListByStatusForQc(BuyerOrderReq req); 94 PageResponseBO<BuyerOrderResp> queryOrderListByStatusForQc(BuyerOrderReq req);
95 95
96 QcOrderDetailResp getQcOrderDetail(String orderCode); 96 QcOrderDetailResp getQcOrderDetail(String orderCode);
  97 +
  98 + JSONObject getSfWaybillCode(BuyerOrderReq req);
97 } 99 }
@@ -14,7 +14,6 @@ import java.util.stream.Collectors; @@ -14,7 +14,6 @@ import java.util.stream.Collectors;
14 14
15 import javax.annotation.Resource; 15 import javax.annotation.Resource;
16 16
17 -import com.yoho.ufo.order.request.SaveQualityCheckInfoRequest;  
18 import org.apache.commons.collections.CollectionUtils; 17 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang3.StringUtils; 18 import org.apache.commons.lang3.StringUtils;
20 import org.elasticsearch.common.collect.Lists; 19 import org.elasticsearch.common.collect.Lists;
@@ -51,6 +50,7 @@ import com.yoho.order.dal.QualityCheckMapper; @@ -51,6 +50,7 @@ import com.yoho.order.dal.QualityCheckMapper;
51 import com.yoho.order.dal.SellerOrderGoodsMapper; 50 import com.yoho.order.dal.SellerOrderGoodsMapper;
52 import com.yoho.order.dal.SellerOrderMapper; 51 import com.yoho.order.dal.SellerOrderMapper;
53 import com.yoho.order.dal.SellerOrderMetaMapper; 52 import com.yoho.order.dal.SellerOrderMetaMapper;
  53 +import com.yoho.order.model.AppraiseAddress;
54 import com.yoho.order.model.Area; 54 import com.yoho.order.model.Area;
55 import com.yoho.order.model.BuyerOrder; 55 import com.yoho.order.model.BuyerOrder;
56 import com.yoho.order.model.BuyerOrderFeedback; 56 import com.yoho.order.model.BuyerOrderFeedback;
@@ -75,11 +75,13 @@ import com.yoho.ufo.dal.ProductMapper; @@ -75,11 +75,13 @@ import com.yoho.ufo.dal.ProductMapper;
75 import com.yoho.ufo.dal.model.IdentifyRecords; 75 import com.yoho.ufo.dal.model.IdentifyRecords;
76 import com.yoho.ufo.dal.model.Product; 76 import com.yoho.ufo.dal.model.Product;
77 import com.yoho.ufo.order.constant.Constant; 77 import com.yoho.ufo.order.constant.Constant;
  78 +import com.yoho.ufo.order.request.SaveQualityCheckInfoRequest;
78 import com.yoho.ufo.order.service.IBuyerOrderService; 79 import com.yoho.ufo.order.service.IBuyerOrderService;
79 import com.yoho.ufo.service.impl.UserHelper; 80 import com.yoho.ufo.service.impl.UserHelper;
80 import com.yoho.ufo.service.model.PageResponseBO; 81 import com.yoho.ufo.service.model.PageResponseBO;
81 import com.yoho.ufo.util.ImagesConstant; 82 import com.yoho.ufo.util.ImagesConstant;
82 import com.yoho.ufo.util.ImagesHelper; 83 import com.yoho.ufo.util.ImagesHelper;
  84 +import com.yoho.ufo.util.MobileHelper;
83 import com.yohobuy.ufo.model.order.bo.AppraiseExpressInfoBo; 85 import com.yohobuy.ufo.model.order.bo.AppraiseExpressInfoBo;
84 import com.yohobuy.ufo.model.order.common.EnumExpressType; 86 import com.yohobuy.ufo.model.order.common.EnumExpressType;
85 import com.yohobuy.ufo.model.order.common.EnumQualityCheckStatus; 87 import com.yohobuy.ufo.model.order.common.EnumQualityCheckStatus;
@@ -188,6 +190,14 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -188,6 +190,14 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
188 @Resource(name="restTemplate") 190 @Resource(name="restTemplate")
189 RestTemplate restTemplate; 191 RestTemplate restTemplate;
190 192
  193 + //南京月结账号
  194 +// private static final String NANJING_CUSTID = "0255045253";
  195 + private static final String NANJING_CUSTID = "9999999999";
  196 +
  197 + //北京月结账号
  198 +// private static final String BEIJING_CUSTID = "0100026158";
  199 + private static final String BEIJING_CUSTID = "9999999999";
  200 +
191 //已收货 201 //已收货
192 private static final Byte QC_STATUS_RECEIVED = 0; 202 private static final Byte QC_STATUS_RECEIVED = 0;
193 203
@@ -1585,9 +1595,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -1585,9 +1595,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
1585 return resp; 1595 return resp;
1586 } 1596 }
1587 1597
1588 -// @Override  
1589 - public String getSfWaybillCode(String orderCode) {  
1590 - BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); 1598 + @Override
  1599 + public JSONObject getSfWaybillCode(BuyerOrderReq req) {
  1600 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(req.getOrderCode());
1591 if(null == buyerOrder) { 1601 if(null == buyerOrder) {
1592 return null; 1602 return null;
1593 } 1603 }
@@ -1608,25 +1618,68 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -1608,25 +1618,68 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
1608 1618
1609 SellerOrderGoods sellerGoods = sellerGoodsList.get(0); 1619 SellerOrderGoods sellerGoods = sellerGoodsList.get(0);
1610 1620
  1621 + AppraiseAddress appraiseAddress = appraiseAddressMapper.selectByType(sellerGoods.getDepotNo());
1611 1622
1612 String url = erpDomain + PlatformConstant.ERP_GET_SF_WAYBILLCODE; 1623 String url = erpDomain + PlatformConstant.ERP_GET_SF_WAYBILLCODE;
1613 - HttpHeaders headers = getHttpHeaders();  
1614 - HttpEntity<String> formEntity = getStringHttpEntity(buyerOrder, sellerGoods, headers);  
1615 -  
1616 - ResponseEntity<Object> responseResponseEntity = restTemplate.postForEntity(url, formEntity, Object.class);  
1617 - Map<String, Object> body = (Map<String, Object>) responseResponseEntity.getBody();  
1618 1624
1619 - return null; 1625 + JSONObject jsonReqObj = getStringHttpEntity(buyerOrder, sellerGoods, appraiseAddress.getAddress(), skup, req.getPayMethod());
  1626 + HttpEntity<String> formEntity = new HttpEntity<>(jsonReqObj.toString(), getHttpHeaders());
  1627 +
  1628 + ResponseEntity<JSONObject> responseResponseEntity = restTemplate.postForEntity(url, formEntity, JSONObject.class);
  1629 + JSONObject body = responseResponseEntity.getBody();
  1630 + LOGGER.info("erp result is {}", body);
  1631 + int code = body.getIntValue("code");
  1632 + if(code != 200) {
  1633 + return body;
  1634 + }
  1635 +
  1636 + Product product = productMapper.selectByPrimaryKey(sellerGoods.getProductId());
  1637 +
  1638 + JSONObject data = body.getJSONObject("data");
  1639 + data.put("createTime", DateUtil.getcurrentDateTime());
  1640 + data.put("dContact", jsonReqObj.getString("dContact"));
  1641 + data.put("dMobile", MobileHelper.coverMobile(jsonReqObj.getString("dMobile")));
  1642 + data.put("dProvince", jsonReqObj.getString("dProvince"));
  1643 + data.put("dCity", jsonReqObj.getString("dCity"));
  1644 + data.put("dDistrict", jsonReqObj.getString("dDistrict"));
  1645 + data.put("dAddress", jsonReqObj.getString("dAddress"));
  1646 + data.put("jContact", "UFO鉴定中心");
  1647 + data.put("jMobile", MobileHelper.coverMobile(appraiseAddress.getMobile()));
  1648 + data.put("jProvince", jsonReqObj.getString("jProvince"));
  1649 + data.put("jCity", jsonReqObj.getString("jCity"));
  1650 + data.put("jDistrict", jsonReqObj.getString("jDistrict"));
  1651 + data.put("jAddress", jsonReqObj.getString("jAddress"));
  1652 + data.put("orderCode", buyerOrder.getOrderCode());
  1653 + data.put("productCode", product.getProductCode());
  1654 + data.put("sizeName", sellerGoods.getSizeName());
  1655 + data.put("shipFee", "**元");
  1656 + data.put("amount", "**元");
  1657 + data.put("businessType", data.getString("proCode").equals("T6") ? "顺丰特惠" : "标准快递");
  1658 + data.put("custid", "***");
  1659 +
  1660 + //建立订单与运单号的关联
  1661 + String receiverType = jsonReqObj.getString("receiverType");
  1662 + BuyerOrderReq relationReq = new BuyerOrderReq();
  1663 + relationReq.setOrderCode(buyerOrder.getOrderCode());
  1664 + relationReq.setWaybillCode(data.getString("mailNo"));
  1665 + relationReq.setExpressCompanyId(23);//顺丰
  1666 + relationReq.setDepotNo(sellerGoods.getDepotNo());
  1667 + relationReq.setMobile(jsonReqObj.getString("dMobile"));
  1668 + if(receiverType.equals("buyer")) {
  1669 + deliveryGoodsToBuyer(relationReq);
  1670 + }else if(receiverType.equals("seller")) {
  1671 + sendBackGoodsToSeller(relationReq);
  1672 + }
  1673 +
  1674 + return data;
1620 } 1675 }
1621 1676
1622 - private HttpEntity<String> getStringHttpEntity(BuyerOrder buyerOrder, SellerOrderGoods sellerGoods, HttpHeaders headers) { 1677 + private JSONObject getStringHttpEntity(BuyerOrder buyerOrder, SellerOrderGoods sellerGoods, String appraiseAddress, Integer skup, Integer payMethod) {
1623 JSONObject jsonObj = new JSONObject(); 1678 JSONObject jsonObj = new JSONObject();
1624 jsonObj.put("orderCode", buyerOrder.getOrderCode()); 1679 jsonObj.put("orderCode", buyerOrder.getOrderCode());
1625 jsonObj.put("uid", buyerOrder.getUid()); 1680 jsonObj.put("uid", buyerOrder.getUid());
1626 1681
1627 - Integer depotNo = sellerGoods.getDepotNo();  
1628 - String platformAddress = appraiseAddressMapper.selectAddressByType(depotNo);  
1629 - Map<String, String> addressMap = subAddress(platformAddress); 1682 + Map<String, String> addressMap = subAddress(appraiseAddress);
1630 1683
1631 //寄件人信息 1684 //寄件人信息
1632 jsonObj.put("jCompany", "Yoho!Buy有货"); 1685 jsonObj.put("jCompany", "Yoho!Buy有货");
@@ -1636,23 +1689,68 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -1636,23 +1689,68 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
1636 jsonObj.put("jCountry", "中国"); 1689 jsonObj.put("jCountry", "中国");
1637 jsonObj.put("jProvince", addressMap.get("province")); 1690 jsonObj.put("jProvince", addressMap.get("province"));
1638 jsonObj.put("jCity", addressMap.get("city")); 1691 jsonObj.put("jCity", addressMap.get("city"));
  1692 + jsonObj.put("jDistrict", addressMap.get("district"));
  1693 + jsonObj.put("jAddress", addressMap.get("address"));
  1694 + jsonObj.put("expressType", 2);//快件产品类型 1:标准快递 2:顺丰特惠(便宜,全程陆运)
  1695 + jsonObj.put("payMethod", payMethod);//1:寄方付 2:收方付 3:第三方付
  1696 + jsonObj.put("businessCode", "UFO");
  1697 + jsonObj.put("custid", sellerGoods.getDepotNo().intValue() == 0 ? BEIJING_CUSTID : NANJING_CUSTID);
  1698 +
  1699 + //收件人信息
  1700 + if(buyerOrder.getStatus().equals(Constant.BUYER_ORDER_STATUS_JUDGE_PASS.getByteVal())
  1701 + || buyerOrder.getStatus().equals(Constant.BUYER_ORDER_STATUS_MINI_FAULT_ACCEPT.getByteVal())) {//收件人为买家
  1702 + BuyerOrderMeta buyerMeta = buyerOrderMetaMapper.selectByOrderCodeAndKey(buyerOrder.getOrderCode(), BUYER_ORDER_META_KEY_DELIVERY_ADDRESS);
  1703 + JSONObject metaValue = JSONObject.parseObject(buyerMeta.getMetaValue());
  1704 + buildAddressInfo(metaValue, jsonObj);
  1705 + jsonObj.put("receiverType", "buyer");
  1706 + }else if(buyerOrder.getStatus().equals(Constant.BUYER_ORDER_STATUS_JUDGE_NOT_PASS.getByteVal())
  1707 + || buyerOrder.getStatus().equals(Constant.BUYER_ORDER_STATUS_BUYER_CANCEL_AFTER_SELLER_DELIVERY.getByteVal())
  1708 + || buyerOrder.getStatus().equals(Constant.CANCEL_QUALITY_CHECK_FAKE.getByteVal())
  1709 + || buyerOrder.getStatus().equals(Constant.CANCEL_MINI_FAULT_REJECT.getByteVal())
  1710 + || buyerOrder.getStatus().equals(Constant.CANCEL_MINI_FAULT_OUT_TIME_REJECT.getByteVal())) {//收件人为卖家
  1711 + SellerOrderMeta sellerMeta = sellerOrderMetaMapper.selectBySkupAndKey(skup, SELLER_ORDER_META_KEY_BACK_DELIVERY_ADDRESS);
  1712 + JSONObject sellerMetaValue = JSONObject.parseObject(sellerMeta.getMetaValue());
  1713 + buildAddressInfo(sellerMetaValue, jsonObj);
  1714 + jsonObj.put("receiverType", "seller");
  1715 + }
1639 1716
1640 - return new HttpEntity<String>(jsonObj.toString(), headers); 1717 + return jsonObj;
  1718 + }
  1719 +
  1720 + private void buildAddressInfo(JSONObject metaValue, JSONObject jsonObj) {
  1721 +// jsonObj.put("dCompany", "");
  1722 + jsonObj.put("dContact", metaValue.getString("consignee"));
  1723 + jsonObj.put("dTel", metaValue.getString("mobile"));
  1724 + jsonObj.put("dMobile", metaValue.getString("mobile"));
  1725 + String areaCode = metaValue.getString("areaCode");
  1726 + //查询四级地址,比如id=110102001:北京市北京市西城区西长安街街道办事处,11-北京市, 1101-北京市, 110102-西城区 110102001-西长安街街道办事处
  1727 + Integer firstId = Integer.valueOf(areaCode.substring(0, 2));
  1728 + Integer secondId = Integer.valueOf(areaCode.substring(0, 4));
  1729 + Integer thirdId = Integer.valueOf(areaCode.substring(0, 6));
  1730 + Integer fourthId = Integer.valueOf(areaCode);
  1731 + List<Area> areaList = areaMapper.selectByCodeList(Lists.newArrayList(firstId, secondId, thirdId, fourthId));
  1732 + Map<Integer, String> areaMap = areaList.stream().collect(Collectors.toMap(Area::getId, Area::getCaption));
  1733 + String dProvince = areaMap.get(firstId).replace("省", "").replace("市", "");
  1734 + jsonObj.put("dProvince", dProvince);
  1735 + jsonObj.put("dCity", areaMap.get(secondId).replace("市", ""));
  1736 + jsonObj.put("dDistrict", areaMap.get(thirdId));
  1737 + jsonObj.put("dCountry", "中国");
  1738 + jsonObj.put("dAddress", areaMap.get(fourthId) + metaValue.getString("address"));
1641 } 1739 }
1642 1740
1643 private Map<String, String> subAddress(String address){ 1741 private Map<String, String> subAddress(String address){
1644 Map<String, String> map = Maps.newHashMap(); 1742 Map<String, String> map = Maps.newHashMap();
1645 String[] str1 = address.split("省"); 1743 String[] str1 = address.split("省");
1646 - if(StringUtils.isNotEmpty(str1[0])) {  
1647 - map.put("province", str1[0]);  
1648 - String[] str2 = str1[1].split("市"); 1744 + if(str1.length == 1) {
  1745 + String[] str2 = str1[0].split("市");
  1746 + map.put("province", str2[0]);
1649 map.put("city", str2[0]); 1747 map.put("city", str2[0]);
1650 String[] str3 = str2[1].split("区"); 1748 String[] str3 = str2[1].split("区");
1651 map.put("district", str3[0]); 1749 map.put("district", str3[0]);
1652 map.put("address", str3[1]); 1750 map.put("address", str3[1]);
1653 }else { 1751 }else {
  1752 + map.put("province", str1[0]);
1654 String[] str2 = str1[1].split("市"); 1753 String[] str2 = str1[1].split("市");
1655 - map.put("provice", str2[0]);  
1656 map.put("city", str2[0]); 1754 map.put("city", str2[0]);
1657 String[] str3 = str2[1].split("区"); 1755 String[] str3 = str2[1].split("区");
1658 map.put("district", str3[0]); 1756 map.put("district", str3[0]);