Authored by mlge

鉴定结果查询接口

package com.yohoufo.common.utils;
import org.apache.commons.lang3.StringUtils;
/**
* 手机号码公共处理helper类
*
* @author yoho
*
*/
public class MobileHelper {
/**
* 覆盖手机号码中4位为*
*
* @param mobile
* @return
*/
public static String coverMobile(String mobile) {
if (StringUtils.isEmpty(mobile)) {
return mobile;
}
// 11位国内手机号
if (mobile.matches("\\d{11}")) {
StringBuffer sb = new StringBuffer();
sb.append(mobile.substring(0, 3)).append("****").append(mobile.substring(7));
return sb.toString();
}
// 国际号码
int index = mobile.indexOf("-");
if (0 < index && mobile.length() > index + 3) {
StringBuffer sb = new StringBuffer();
sb.append(mobile.substring(0, index + 4)).append("****");
if (mobile.length() > index + 7) {
sb.append(mobile.substring(index + 8));
}
return sb.toString();
}
return mobile;
}
public static void main(String[] args) {
String a = "012-4";
System.out.println(coverMobile(a));
}
}
... ...
... ... @@ -25,5 +25,7 @@ public interface BuyerOrderGoodsMapper {
List<BuyerOrderGoods> selectBySkups(@Param("skups") Collection<Integer> skups);
BuyerOrderGoods selectSkupByOrderCode(@Param("orderCode") long orderCode);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.Brand;
import com.yohoufo.dal.product.model.IdentifyRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IdentifyRecordsMapper {
IdentifyRecord selectByTagAndNfcId(@Param("tagId") String tagId, @Param("nfcUid") String nfcUid);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product.model;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class IdentifyRecord {
private int id;
private String tagId;
private String nfcUid;
private int owner;
private int allowTransfer;//是否允许转移,0允许,1不允许
private Long orderCode;
private int authTime;
private int authUid;
}
\ No newline at end of file
... ...
... ... @@ -138,4 +138,13 @@
goods_amount = #{goodsAmount,jdbcType=DECIMAL}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectSkupByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from buyer_order_goods
where order_code = #{orderCode,jdbcType=BIGINT}
limit 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -19,10 +19,10 @@
<result column="product_id" property="productId" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code, skup, seller_order_code, depot_no, start_time, end_time, persistId,
id, order_code, skup, seller_order_code, depot_no, start_time, end_time, persist_id,
vedio_file_url, create_time, update_time, status, storage_id, goods_id, product_id
</sql>
<select id="selectByOrderCodes" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<select id="selectByOrderCodes" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from qiniu_live_record
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.product.IdentifyRecordsMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.IdentifyRecord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="tag_id" jdbcType="VARCHAR" property="tagId" />
<result column="nfc_uid" jdbcType="VARCHAR" property="nfcUid" />
<result column="owner" jdbcType="INTEGER" property="owner" />
<result column="allow_transfer" jdbcType="INTEGER" property="allowTransfer" />
<result column="order_code" jdbcType="BIGINT" property="orderCode" />
<result column="auth_time" jdbcType="INTEGER" property="authTime" />
<result column="auth_uid" jdbcType="INTEGER" property="authUid" />
</resultMap>
<sql id="Base_Column_List">
id, tag_id, nfc_uid, owner,allow_transfer, order_code, auth_time, auth_uid
</sql>
<select id="selectByTagAndNfcId" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from identify_records
where tag_id = #{tagId,jdbcType=VARCHAR}
and nfc_uid = #{nfcUid,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.product.controller;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.GatewayError;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.docs.ApiOperation;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.product.helper.SearchHelpService;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.*;
import com.yohoufo.product.service.ProductIdentifyService;
import com.yohoufo.product.service.ProductSearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
public class ProductIdentifyController {
private static final Logger logger = LoggerFactory.getLogger(ProductIdentifyController.class);
@Autowired
private ProductIdentifyService identifyService;
@ApiOperation(name = "ufo.product.queryIdentifyInfo", desc="UFO商品鉴定信息查询接口")
@RequestMapping(params = "method=ufo.product.queryIdentifyInfo")
public ApiResponse queryIdentifyInfo(@RequestParam(value = "tagId") String tagId,
@RequestParam(value = "nfcUid") String nfcUid) throws GatewayException {
try{
ProductIdentifyResp info = identifyService.queryIdentifyInfo(tagId, nfcUid);
return new ApiResponse.ApiResponseBuilder().code(200).data(info).build();
}catch (Exception e){
logger.warn("queryIdentifyInfo error! tagId={}, nfcUid={}, ", tagId, nfcUid);
if( e instanceof GatewayException){
throw e;
}
return new ApiResponse.ApiResponseBuilder().code(402).message("查询失败,请稍后再试!").build();
}
}
@ApiOperation(name = "ufo.product.getShareIdentifyInfo", desc="UFO商品鉴定信息查询接口")
@RequestMapping(params = "method=ufo.product.getShareIdentifyInfo")
public ApiResponse getShareIdentifyInfo(
@RequestParam(value = "nfcUid") String nfcUid,
@RequestParam(value = "tagId") String tagId) {
try{
IdentifyShareInfoResp resp = identifyService.getShareIdentifyInfo( tagId, nfcUid);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).build();
}catch (Exception e){
logger.warn("queryIdentifyInfo error! uid={}, tagId={}, ", tagId);
if( e instanceof ServiceException){
throw e;
}
return new ApiResponse.ApiResponseBuilder().code(401).message("查询失败!").build();
}
}
}
\ No newline at end of file
... ...
package com.yohoufo.product.response;
import lombok.Data;
import java.util.List;
@Data
public class IdentifyShareInfoResp {
private String headIcon;
private String productImageUrl;
private Integer productId;
private String productName;
private String allowTransfer;
}
... ...
package com.yohoufo.product.response;
import lombok.Data;
@Data
public class IdentifyTrackResp {
private Integer uid;
private String headIcon;
private String content;
private String timeStr;
private Integer time;
private String mobile;
}
... ...
package com.yohoufo.product.response;
import lombok.Data;
import java.util.List;
@Data
public class ProductIdentifyResp {
private String productImageUrl;
private String vedioFileUrl;
private String nfcUid;
private Integer productId;
private String productName;
private String productSize;
private String identifyTime;
private String identifyPlat;
private List<IdentifyTrackResp> trackList;
}
... ...
package com.yohoufo.product.service;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.product.response.IdentifyShareInfoResp;
import com.yohoufo.product.response.ProductIdentifyResp;
import java.util.List;
public interface ProductIdentifyService {
ProductIdentifyResp queryIdentifyInfo(String tagId, String nfcUid) throws GatewayException;
IdentifyShareInfoResp getShareIdentifyInfo( String tagId, String nfcUid);
}
... ...
package com.yohoufo.product.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.response.ProfileInfoRsp;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.MobileHelper;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.QiniuLiveRecordMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.QiniuLiveRecord;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.product.IdentifyRecordsMapper;
import com.yohoufo.dal.product.model.IdentifyRecord;
import com.yohoufo.product.response.IdentifyShareInfoResp;
import com.yohoufo.product.response.IdentifyTrackResp;
import com.yohoufo.product.response.ProductIdentifyResp;
import com.yohoufo.product.service.ProductIdentifyService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ProductIdentifyServiceImpl implements ProductIdentifyService{
private final Logger logger = LoggerFactory.getLogger(ProductIdentifyServiceImpl.class);
public static final String LIVE_VEDIO_DOMAIN = "http://yhb-img01.qiniudn.com/";
@Autowired
private IdentifyRecordsMapper identifyRecordsMapper;
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private ServiceCaller serviceCaller;
@Autowired
private CacheClient clientCache;
@Autowired
private ConfigReader configReader;
/**
* 鉴定结果查询接口
* @param tagId
* @param nfcUid
* @return
*/
@Override
public ProductIdentifyResp queryIdentifyInfo(String tagId, String nfcUid) throws GatewayException {
logger.info("enter queryIdentifyInfo, tagId = {}, nfcUid={}", tagId, nfcUid);
//返回结果可能在缓存中
ProductIdentifyResp result = getIdentifyFromCache(tagId, nfcUid);
if(result != null ){
logger.info("queryIdentifyInfo get result from cache success! tagId = {}, nfcUid={},result={} ", tagId, nfcUid, result );
return result;
}
result = new ProductIdentifyResp();
//鉴定 记录--先从缓存去取
IdentifyRecord identifyRecord = queryIdentifyRecord(tagId, nfcUid);
if(identifyRecord == null || identifyRecord.getOrderCode() == null){
throw new GatewayException(402, "鉴定信息不存在");
}
//根据鉴定记录 获取订单号
Long orderCode = identifyRecord.getOrderCode();
//订单号 获取订单详细信息
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if(buyerOrder == null){
throw new GatewayException(403, "订单不存在");
}
Integer buyerUid = buyerOrder.getUid();//买家
Integer sellerUid = buyerOrder.getSellerUid();//卖家
Integer orderStatus = buyerOrder.getStatus();//5--订单已经完成
//订单号获取 skup
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectSkupByOrderCode(orderCode);
Integer skup = buyerOrderGoods.getSkup();
//skup获取 productInfo
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
result.setProductImageUrl(sellerOrderGoods.getImageUrl());
result.setNfcUid(identifyRecord.getNfcUid());
result.setProductId(sellerOrderGoods.getProductId());
result.setProductName(sellerOrderGoods.getProductName());
result.setProductSize(sellerOrderGoods.getSizeName());
//vedioFileUrl视频链接
QiniuLiveRecord qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCodes(orderCode);
if (qiniuLiveRecords != null && StringUtils.isNotBlank(qiniuLiveRecords.getVedioFileUrl())) {
result.setVedioFileUrl(LIVE_VEDIO_DOMAIN + qiniuLiveRecords.getVedioFileUrl());
}
//鉴定时间
int authTime = identifyRecord.getAuthTime();
String timeStr = formatDate(authTime, "yyyy.MM.dd HH:mm:ss");
result.setIdentifyTime(timeStr);
String authName = "UFO鉴定中心";
result.setIdentifyPlat(authName);
//交易轨迹---最多三条
List<IdentifyTrackResp> trackRespList = new ArrayList<>();
result.setTrackList(trackRespList);
//1)鉴定结果
IdentifyTrackResp identifyTrack = new IdentifyTrackResp();
identifyTrack.setTime(authTime);
identifyTrack.setTimeStr(timeStr);
identifyTrack.setContent( authName + "鉴定结果为\"真\"");
String auth_inco = configReader.getString("ufo.product.authIcon", "XXXXXX");
identifyTrack.setHeadIcon(auth_inco);
trackRespList.add(identifyTrack);
List<Integer> uidsList = Arrays.asList(buyerUid, sellerUid);
Map<Integer, ProfileInfoRsp> profileMap = getUserProfileInfo(uidsList);
ProfileInfoRsp buyerInfo = profileMap.get(buyerUid);
//订单轨迹
String mobile = MobileHelper.coverMobile(buyerInfo.getMobile());//隐位的手机号码
String headIcon = buyerInfo.getHead_ico();//头像
//订单更新时间
if(orderStatus != null && orderStatus.intValue() == 5){//订单已完成
IdentifyTrackResp updateOrderTrack = new IdentifyTrackResp();
timeStr = formatDate(buyerOrder.getUpdateTime(), "yyyy.MM.dd HH:mm:ss");
updateOrderTrack.setTime(buyerOrder.getUpdateTime());
updateOrderTrack.setTimeStr(timeStr);
updateOrderTrack.setContent("用户" + mobile + "成为商品新主人");
updateOrderTrack.setHeadIcon(headIcon);
updateOrderTrack.setMobile(mobile);
trackRespList.add(updateOrderTrack);
}
//创建订单的时间
IdentifyTrackResp createOrderTrack = new IdentifyTrackResp();
createOrderTrack.setUid(buyerUid);
createOrderTrack.setHeadIcon(headIcon);
createOrderTrack.setContent("用户"+ mobile + "在UFO平台下单购买");
createOrderTrack.setTime(buyerOrder.getCreateTime());
timeStr = formatDate(buyerOrder.getCreateTime(),"yyyy.MM.dd HH:mm:ss");
createOrderTrack.setTimeStr(timeStr);
createOrderTrack.setMobile(mobile);
trackRespList.add(createOrderTrack);
Collections.sort(trackRespList, new Comparator<IdentifyTrackResp>(){//时间倒序排列
@Override
public int compare(IdentifyTrackResp o1, IdentifyTrackResp o2) {
Integer time1 = o1.getTime();
Integer time2 = o2.getTime();
return time2 -time1;
}
});
//设置缓存--可能会有延时,不影响的
setIdentifyCache(tagId, nfcUid, result);
logger.info("queryIdentifyInfo success!, tagId = {}, nfcUid={}, result ={}", tagId, nfcUid, result );
return result;
}
private IdentifyRecord queryIdentifyRecord(String tagId, String nfcUid) {
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyRecord:").
appendVar(tagId).appendVar(":").appendVar(nfcUid);
IdentifyRecord result = clientCache.get(kb, IdentifyRecord.class);
if( result != null){
logger.info("queryIdentifyRecord from cache success!");
return result;
}
result = identifyRecordsMapper.selectByTagAndNfcId(tagId, nfcUid);
if(result != null){
clientCache.set(kb.getKey(), 5 * 60, result );
}
return result;
}
/**
*
* @param tagId
* @param nfcUid
* @param result
*/
private void setIdentifyCache(String tagId, String nfcUid, ProductIdentifyResp result) {
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyInfo:").
appendVar(tagId).appendVar(":").appendVar(nfcUid);
clientCache.set(kb.getKey(), 5 * 60, result );
}
private ProductIdentifyResp getIdentifyFromCache(String tagId, String nfcUid) {
RedisKeyBuilder kb = new RedisKeyBuilder().appendFixed("ufo:product:identifyInfo:").
appendVar(tagId).appendVar(":").appendVar(nfcUid);
ProductIdentifyResp identifyResp = clientCache.get(kb.getKey(), ProductIdentifyResp.class);
return identifyResp;
}
/**
* 鉴定结果分享
* @param uid
* @param tagId
* @return
*/
@Override
public IdentifyShareInfoResp getShareIdentifyInfo( String tagId, String nfcUid) {
logger.info("enter getShareIdentifyInfo , tagId={}, nfcUid={}", tagId, nfcUid);
IdentifyShareInfoResp result = new IdentifyShareInfoResp();
IdentifyRecord identifyRecord = identifyRecordsMapper.selectByTagAndNfcId(tagId, nfcUid);
if(identifyRecord == null){
throw new ServiceException(ServiceError.ORDER_NULL);
}
Long orderCode = identifyRecord.getOrderCode();//订单号
//订单号获取 skup
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectSkupByOrderCode(orderCode);
Integer skup = buyerOrderGoods.getSkup();
//skup获取 productInfo
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
result.setProductImageUrl(sellerOrderGoods.getImageUrl());
result.setProductId(sellerOrderGoods.getProductId());
result.setProductName(sellerOrderGoods.getProductName());
result.setAllowTransfer(identifyRecord.getAllowTransfer() == 0 ? "Y" : "N");
//买家的头像
Integer buyerUid = buyerOrderGoods.getUid();
List<Integer> uidsList = Arrays.asList(buyerUid);
Map<Integer, ProfileInfoRsp> profileMap = getUserProfileInfo(uidsList);
ProfileInfoRsp profile = profileMap.get(buyerUid);
result.setHeadIcon(profile.getHead_ico());
return result;
}
private Map<Integer,ProfileInfoRsp> getUserProfileInfo(List<Integer> uidsList) {
Map<Integer,ProfileInfoRsp > result = new HashMap<>();
if(uidsList == null || uidsList.size() == 0){
return result;
}
StringBuilder sb = new StringBuilder();
for(Integer uid : uidsList ){
if(uid != null && uid > 0){
sb.append(uid).append(",");
}
}
String s = sb.toString();
if(s.length() == 0){
return result;
}
String uids = s.substring(0, s.length() - 1);
List<JSONObject> rsp = serviceCaller.call("uic.getUserProfilesByUids", uids, List.class);
//必须要强转下
List<ProfileInfoRsp> resultList = rsp.stream().map(profileInfoRsp -> JSONObject.parseObject(JSONObject.toJSONString(profileInfoRsp),ProfileInfoRsp.class))
.collect(Collectors.toList());
result = resultList.stream().collect(Collectors.toMap(ProfileInfoRsp :: getUid, (ProfileInfoRsp obj) -> obj));
return result;
}
private String formatDate(Integer time, String pattern) {
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
return dateFormat.format(new Date((long) time * 1000));
}
}
... ...
... ... @@ -28,6 +28,7 @@ datasources:
- com.yohoufo.dal.product.ProductSortMapper
- com.yohoufo.dal.product.SearchWordMapper
- com.yohoufo.dal.product.SaleCategoryMapper
- com.yohoufo.dal.product.IdentifyRecordsMapper
ufo_order:
servers:
... ...
... ... @@ -28,6 +28,7 @@ datasources:
- com.yohoufo.dal.product.ProductSortMapper
- com.yohoufo.dal.product.SearchWordMapper
- com.yohoufo.dal.product.SaleCategoryMapper
- com.yohoufo.dal.product.IdentifyRecordsMapper
ufo_order:
servers:
... ...