Authored by sailing-PC\sailing

add cache

fix bug
... ... @@ -145,7 +145,13 @@ public class RedisGwCacheClient implements CacheClient {
}
RedisKeyBuilder keyBuilder = RedisKeyBuilder.newInstance().appendFixed(key);
try{
hashOperations.put(keyBuilder, field, JSON.toJSONString(value));
String hashValue;
if (value instanceof String){
hashValue = (String)value;
}else{
hashValue = JSON.toJSONString(value);
}
hashOperations.put(keyBuilder, field, hashValue);
redis.longExpire(keyBuilder, timeout, TimeUnit.SECONDS);
}catch (Exception e){
LOGGER.warn("hashPut redis value operation failed. e is: {}", e);
... ...
... ... @@ -52,5 +52,5 @@ public interface BuyerOrderMapper {
int selectDelCntBySellerUid(int sellerUid);
int selectCntBySellerUid(int sellerUid);
}
\ No newline at end of file
... ...
... ... @@ -345,9 +345,9 @@
</select>
<select id="selectDelCntBySellerUid" parameterType="java.lang.Integer" resultType="java.lang.Integer">
<select id="selectCntBySellerUid" parameterType="java.lang.Integer" resultType="java.lang.Integer">
select count(*) from buyer_order where seller_uid = #{sellerUid,jdbcType=INTEGER}
and seller_order_status = 0
and seller_order_status = 1
</select>
<select id="selectAllByOrderCode" resultMap="BaseResultMap">
... ...
... ... @@ -74,4 +74,12 @@ public class ActionStatusHold {
public static List<Integer> getSellerCanDelStatusList(){
return sellerCanDelStatusList;
}
private final static List<Integer> sellerOrderIsPaidStatusList = Arrays.asList(SkupStatus.CAN_SELL.getCode(),
SkupStatus.YOHO_CANCEL_SELL.getCode(), SkupStatus.SELL_OUT.getCode()
);
public static List<Integer> getSellerOrderIsPaidStatusList(){
return sellerOrderIsPaidStatusList;
}
}
... ...
... ... @@ -14,10 +14,7 @@ import com.yohoufo.order.service.impl.SellerOrderService;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
... ... @@ -177,10 +174,10 @@ public class BuyerOrderController {
@RequestMapping(value = "/confirmReceive")
@ResponseBody
public ApiResponse confirmReceive(@RequestParam("orderCode") long orderCode) {
LOG.info("method ufo.depot.confirmReceive in, orderCode is {}", orderCode);
buyerOrderService.confirmReceive(orderCode);
LOG.info("method ufo.depot.confirmReceive out, orderCode is {}", orderCode);
public ApiResponse confirmReceive(@RequestBody OrderRequest request) {
LOG.info("method ufo.depot.confirmReceive in, req is {}", request);
buyerOrderService.confirmReceive(request.getOrderCode());
LOG.info("method ufo.depot.confirmReceive out, req is {}", request);
return new ApiResponse.ApiResponseBuilder().code(200).message("鉴定中心确认收货成功").build();
}
}
... ...
... ... @@ -74,6 +74,12 @@ public class OrderDetailInfo {
*/
private ExpressInfoDetail lastExpressInfo;
/**
* 是否支付
* 1:已支付,0:未支付
*/
private Integer isPaid;
@Builder
@Data
public static class StatusDetail{
... ...
package com.yohoufo.order.service.cache;
import com.google.common.collect.Lists;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by chenchao on 2018/10/16.
*/
@Component
public class CacheCleaner {
final Logger logger = LoggerFactory.getLogger(getClass());
@Redis("gwNoSyncRedis")
private YHRedisTemplate redis;
//批量删除key
public void delete(List<RedisKeyBuilder> keyBuilders) {
try {
redis.delete(keyBuilders);
} catch (Exception ex) {
logger.warn("call redis delete error,key is {}", keyBuilders, ex);
}
}
public RedisKeyBuilder buildOrderList(int uid){
return CacheKeyBuilder.orderListKey(uid);
}
}
... ...
package com.yohoufo.order.service.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohoufo.order.model.request.OrderListRequest;
/**
* Created by chenchao on 2018/10/16.
*/
public class CacheKeyBuilder {
private static String SEPARATOR = ":";
public enum KeyTemp{
ORDER_LIST("order:orderList:");
private String fix;
KeyTemp(String fix) {
this.fix = fix;
}
}
public static void main(String[] args) {
RedisKeyBuilder kb = orderListKey(1);
System.out.println(kb.getKey() + "\n" + kb.getKeyTemplate());
}
public static RedisKeyBuilder orderListKey(int uid){
return new RedisKeyBuilder().appendFixed(KeyTemp.ORDER_LIST.fix).appendVar(uid);
}
public static String orderListHashKey(OrderListRequest req){
return new StringBuilder(req.getTabType())
.append(req.getType())
.append(req.getPage())
.append(req.getLimit())
.toString();
}
}
... ...
package com.yohoufo.order.service.cache;
import com.alibaba.fastjson.JSON;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.cache.SnappyZipUtils;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.response.OrderListInfo;
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.util.List;
/**
* Created by chenchao on 2018/10/16.
*/
@Service
public class OrderCacheService {
final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CacheClient cacheClient;
public void cacheOrderList(OrderListRequest req, List<OrderListInfo> orderListInfos){
String hashKey = CacheKeyBuilder.orderListHashKey(req);
String key = CacheKeyBuilder.orderListKey(req.getUid()).getKey();
try{
String hashValue = JSON.toJSONString(orderListInfos);
String compressHashValue = SnappyZipUtils.compress(hashValue);
cacheClient.hashPut(key, hashKey, compressHashValue, 300);
}catch (Exception ex){
logger.warn("in cacheOrderList fail ,req {}", req);
}
}
public List<OrderListInfo> getOrderListInfos(OrderListRequest req){
String hashKey = CacheKeyBuilder.orderListHashKey(req);
try{
String key = CacheKeyBuilder.orderListKey(req.getUid()).getKey();
String hashVal = cacheClient.hashGet(key, hashKey, String.class);
String uncompressHashValue = SnappyZipUtils.uncompress(hashVal);
if (StringUtils.isNotEmpty(uncompressHashValue)) {
return JSON.parseArray(uncompressHashValue, OrderListInfo.class);
} else {
return null;
}
}catch (Exception ex){
logger.warn("in cacheOrderList fail ,req {}", req);
return null;
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.common.SkupStatus;
... ... @@ -245,8 +246,17 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
orderDetailInfo.setPayment(order.getPayment());
}
}
//
orderDetailInfo.setIsPaid(getIsPaid(skupStatus));
orderDetailInfo.setCreateTime(DateUtil.formatDate(order.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
return orderDetailInfo;
}
private Integer getIsPaid(SkupStatus skupStatus){
if (skupStatus == null){
return 0;
}
return ActionStatusHold.getSellerOrderIsPaidStatusList().contains(skupStatus.getCode()) ? 1 : 0;
}
}
... ...
... ... @@ -473,14 +473,14 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
public OrderSummaryResp selectOrderNumByUid(int uid) {
//todo add cache
Integer num = sellerOrderMapper.selectOrderNumByUid(uid);
Integer delNum = buyerOrderMapper.selectDelCntBySellerUid(uid);
log.info("in seller order count uid {}, num {}, delNum {}", uid, num, delNum);
Integer buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid);
log.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
int cnt;
if (num == null){
cnt = 0;
}else{
if (delNum != null){
cnt = num - delNum;
if (buyerOrderNum != null){
cnt = num + buyerOrderNum;
}else{
cnt = num;
}
... ...