提交 12fb98ed authored 作者: zgy's avatar zgy

订单取消接口,订单支付倒计时

上级 2de1d02b
...@@ -38,5 +38,7 @@ public class KeyConstant { ...@@ -38,5 +38,7 @@ public class KeyConstant {
public final static String SHOPIFY_TYPE = "shopify_item"; public final static String SHOPIFY_TYPE = "shopify_item";
//所有商品 //所有商品
public final static String SHOPIFY_ITEMS_ALL = "shopify_item_all"; public final static String SHOPIFY_ITEMS_ALL = "shopify_item_all";
//订单失效
public final static Integer ORDER_EXPIRE = 0;
} }
...@@ -106,4 +106,17 @@ public class TbCfOrderController { ...@@ -106,4 +106,17 @@ public class TbCfOrderController {
@ApiParam("兑换货币") @RequestParam("currency") String currency) { @ApiParam("兑换货币") @RequestParam("currency") String currency) {
return tbCfOrderService.currencyConversion(price, currency); return tbCfOrderService.currencyConversion(price, currency);
} }
/**
* 取消订单
*
* @param orderId
* @return
*/
@ApiOperation(value = "取消订单")
@GetMapping("/cancelOrder")
public Result cancelOrder(@ApiParam("订单id") @RequestParam("orderId") String orderId,
@ApiParam("原因") @RequestParam("reason") String reason) {
return tbCfOrderService.cancelOrder(orderId,reason);
}
} }
package com.diaoyun.zion.chinafrica.dao;
import com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity;
import com.diaoyun.zion.master.dao.BaseDao;
/**
* Dao
*
* @author lipengjun
* @date 2019-12-18 11:39:52
*/
public interface TbCfCancelDao extends BaseDao<TbCfCancelEntity> {
}
package com.diaoyun.zion.chinafrica.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 tb_cf_cancel
*
* @author lipengjun
* @date 2019-12-18 11:39:52
*/
public class TbCfCancelEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
private String id;
/**
* 订单ID
*/
private String orderId;
/**
* 取消订单的原因
*/
private String cancelReason;
/**
* 删除标记
*/
private Integer delFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:ID
*/
public String getId() {
return id;
}
/**
* 设置:订单ID
*/
public void setOrderId(String orderId) {
this.orderId = orderId;
}
/**
* 获取:订单ID
*/
public String getOrderId() {
return orderId;
}
/**
* 设置:取消订单的原因
*/
public void setCancelReason(String cancelReason) {
this.cancelReason = cancelReason;
}
/**
* 获取:取消订单的原因
*/
public String getCancelReason() {
return cancelReason;
}
/**
* 设置:删除标记
*/
public void setDelFlag(Integer delFlag) {
this.delFlag = delFlag;
}
/**
* 获取:删除标记
*/
public Integer getDelFlag() {
return delFlag;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
...@@ -4,6 +4,7 @@ import com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity; ...@@ -4,6 +4,7 @@ import com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity;
import com.diaoyun.zion.chinafrica.vo.TbCfOrderVo; import com.diaoyun.zion.chinafrica.vo.TbCfOrderVo;
import com.diaoyun.zion.master.base.Result; import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException; import java.io.IOException;
...@@ -90,14 +91,15 @@ public interface TbCfOrderService { ...@@ -90,14 +91,15 @@ public interface TbCfOrderService {
* @param tbCfOrderVo * @param tbCfOrderVo
* @return * @return
*/ */
Result placeOrder(TbCfOrderVo tbCfOrderVo,String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException; Result placeOrder(TbCfOrderVo tbCfOrderVo, String toitableId) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException;
/** /**
* 获取用户订单列表 * 获取用户订单列表
*
* @param orderStatus 订单状态 OrderStatusEnum * @param orderStatus 订单状态 OrderStatusEnum
* @return * @return
*/ */
Result getUserOrderList(Integer pageNum, Integer pageSize,Integer orderStatus) throws InterruptedException; Result getUserOrderList(Integer pageNum, Integer pageSize, Integer orderStatus) throws InterruptedException;
/** /**
* 取消订单 * 取消订单
...@@ -121,10 +123,11 @@ public interface TbCfOrderService { ...@@ -121,10 +123,11 @@ public interface TbCfOrderService {
* @param orderId * @param orderId
* @return * @return
*/ */
Result payForOrder(String orderId, String token) ; Result payForOrder(String orderId, String token);
/** /**
* 根据订单id,获取物流详情 * 根据订单id,获取物流详情
*
* @param orderId * @param orderId
* @return * @return
*/ */
...@@ -132,6 +135,7 @@ public interface TbCfOrderService { ...@@ -132,6 +135,7 @@ public interface TbCfOrderService {
/** /**
* 获取某段时间内的付款订单 * 获取某段时间内的付款订单
*
* @param beginTime * @param beginTime
* @param endTime * @param endTime
* @param pageNum * @param pageNum
...@@ -142,6 +146,7 @@ public interface TbCfOrderService { ...@@ -142,6 +146,7 @@ public interface TbCfOrderService {
/** /**
* 获取某段时间已发货订单数据 * 获取某段时间已发货订单数据
*
* @param beginTime * @param beginTime
* @param endTime * @param endTime
* @param pageNum * @param pageNum
...@@ -152,6 +157,7 @@ public interface TbCfOrderService { ...@@ -152,6 +157,7 @@ public interface TbCfOrderService {
/** /**
* 根据订单号获取详细订单数据 给第三方的接口 * 根据订单号获取详细订单数据 给第三方的接口
*
* @param orderId * @param orderId
* @return * @return
*/ */
...@@ -159,6 +165,7 @@ public interface TbCfOrderService { ...@@ -159,6 +165,7 @@ public interface TbCfOrderService {
/** /**
* 删除订单 伪删除 * 删除订单 伪删除
*
* @param orderId * @param orderId
* @return * @return
*/ */
...@@ -166,6 +173,7 @@ public interface TbCfOrderService { ...@@ -166,6 +173,7 @@ public interface TbCfOrderService {
/** /**
* 根据订单号获取详细订单数据 内部使用 * 根据订单号获取详细订单数据 内部使用
*
* @param orderId * @param orderId
* @return * @return
*/ */
...@@ -179,4 +187,6 @@ public interface TbCfOrderService { ...@@ -179,4 +187,6 @@ public interface TbCfOrderService {
Result currencyConversion(String price, String currency); Result currencyConversion(String price, String currency);
Result getDeliveryLists(long beginTime, long endTime, Integer pageNum, Integer pageSize); Result getDeliveryLists(long beginTime, long endTime, Integer pageNum, Integer pageSize);
Result cancelOrder(String orderId,String reason);
} }
...@@ -257,8 +257,7 @@ public class FlutterWaveServiceImpl implements FlutterWaveService { ...@@ -257,8 +257,7 @@ public class FlutterWaveServiceImpl implements FlutterWaveService {
tbCfOrder.setPayId(payId); tbCfOrder.setPayId(payId);
tbCfOrder.setOrderStatus(OrderStatusEnum.PAID.getValue()); tbCfOrder.setOrderStatus(OrderStatusEnum.PAID.getValue());
tbCfOrder.setPayStatus(OrderStatusEnum.PAID.getValue()); tbCfOrder.setPayStatus(OrderStatusEnum.PAID.getValue());
int update = tbCfOrderDao.update(tbCfOrder); tbCfOrderDao.update(tbCfOrder);
System.out.println("update......" + update);
} }
/** /**
......
...@@ -81,6 +81,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService { ...@@ -81,6 +81,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Autowired @Autowired
private JwtTokenProvider jwtTokenProvider; private JwtTokenProvider jwtTokenProvider;
@Autowired
private TbCfCancelDao tbCfCancelDao;
@Autowired @Autowired
private TbCfFeeService tbCfFeeService; private TbCfFeeService tbCfFeeService;
@Autowired @Autowired
...@@ -467,6 +469,10 @@ public class TbCfOrderServiceImpl implements TbCfOrderService { ...@@ -467,6 +469,10 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
itemDetailVoList.add(tbCfCartItemDetailVo); itemDetailVoList.add(tbCfCartItemDetailVo);
} }
tbCfOrderVo.setItemDetailList(itemDetailVoList); tbCfOrderVo.setItemDetailList(itemDetailVoList);
String expire = orderRedisCache.expire(KeyConstant.ORDER_DET + orderId);
if (!StringUtils.isBlank(expire) && "10".equals(String.valueOf(tbCfOrderVo.getOrderStatus()))) {
tbCfOrderVo.setExpire(expire);
}
result.setData(tbCfOrderVo); result.setData(tbCfOrderVo);
return result; return result;
} }
...@@ -538,6 +544,38 @@ public class TbCfOrderServiceImpl implements TbCfOrderService { ...@@ -538,6 +544,38 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
return result; return result;
} }
/**
* 取消订单
*
* @param orderId
* @return
*/
@Override
public Result cancelOrder(String orderId, String reason) {
Result result = new Result();
try {
TbCfOrderVo tbCfOrderVo = (TbCfOrderVo) orderRedisCache.get(KeyConstant.ORDER_DET + orderId);
if (!StringUtils.isBlank(orderId)) {
if (tbCfOrderVo != null) {
orderRedisCache.set(KeyConstant.ORDER_DET + orderId, KeyConstant.ORDER_EXPIRE);
}
//订单取消原因
TbCfCancelEntity cancelEntity = new TbCfCancelEntity();
cancelEntity.setId(IdUtil.createIdbyUUID());
cancelEntity.setOrderId(orderId);
cancelEntity.setCancelReason(reason);
cancelEntity.setDelFlag(1);
cancelEntity.setCreateTime(new Date());
cancelEntity.setUpdateTime(new Date());
tbCfCancelDao.save(cancelEntity);
}
result.setCode(ResultCodeEnum.SUCCESS.getCode()).setMessage(ResultCodeEnum.SUCCESS.getDesc());
} catch (Exception e) {
result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode()).setMessage(e.getMessage());
}
return result;
}
/** /**
* 记录财务流水 * 记录财务流水
......
...@@ -180,7 +180,15 @@ public class TbCfOrderVo implements Serializable { ...@@ -180,7 +180,15 @@ public class TbCfOrderVo implements Serializable {
*/ */
private Integer enableFlag; private Integer enableFlag;
private String expire;
public String getExpire() {
return expire;
}
public void setExpire(String expire) {
this.expire = expire;
}
public String getOrdersId() { public String getOrdersId() {
return ordersId; return ordersId;
...@@ -203,6 +211,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -203,6 +211,7 @@ public class TbCfOrderVo implements Serializable {
public String getOrderId() { public String getOrderId() {
return orderId; return orderId;
} }
/** /**
* 设置:订单号 * 设置:订单号
*/ */
...@@ -216,6 +225,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -216,6 +225,7 @@ public class TbCfOrderVo implements Serializable {
public Long getOrderNo() { public Long getOrderNo() {
return orderNo; return orderNo;
} }
/** /**
* 设置:订单名 * 设置:订单名
*/ */
...@@ -229,6 +239,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -229,6 +239,7 @@ public class TbCfOrderVo implements Serializable {
public String getOrderName() { public String getOrderName() {
return orderName; return orderName;
} }
/** /**
* 设置:订单创建时间 * 设置:订单创建时间
*/ */
...@@ -242,6 +253,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -242,6 +253,7 @@ public class TbCfOrderVo implements Serializable {
public Date getOrderTime() { public Date getOrderTime() {
return orderTime; return orderTime;
} }
/** /**
* 设置:更新时间 * 设置:更新时间
*/ */
...@@ -255,6 +267,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -255,6 +267,7 @@ public class TbCfOrderVo implements Serializable {
public Date getUpdateTime() { public Date getUpdateTime() {
return updateTime; return updateTime;
} }
/** /**
* 设置:成交时间 * 设置:成交时间
*/ */
...@@ -268,6 +281,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -268,6 +281,7 @@ public class TbCfOrderVo implements Serializable {
public Date getDealTime() { public Date getDealTime() {
return dealTime; return dealTime;
} }
/** /**
* 设置:交易关闭时间 * 设置:交易关闭时间
*/ */
...@@ -281,6 +295,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -281,6 +295,7 @@ public class TbCfOrderVo implements Serializable {
public Date getCloseTime() { public Date getCloseTime() {
return closeTime; return closeTime;
} }
/** /**
* 设置:订单状态(0取消,10未付款,20已付款,40已发货,50交易成功,60交易关闭) * 设置:订单状态(0取消,10未付款,20已付款,40已发货,50交易成功,60交易关闭)
*/ */
...@@ -294,6 +309,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -294,6 +309,7 @@ public class TbCfOrderVo implements Serializable {
public Integer getOrderStatus() { public Integer getOrderStatus() {
return orderStatus; return orderStatus;
} }
/** /**
* 设置:用户id * 设置:用户id
*/ */
...@@ -307,6 +323,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -307,6 +323,7 @@ public class TbCfOrderVo implements Serializable {
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
/** /**
* 设置:用户名 * 设置:用户名
*/ */
...@@ -320,6 +337,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -320,6 +337,7 @@ public class TbCfOrderVo implements Serializable {
public String getUserName() { public String getUserName() {
return userName; return userName;
} }
/** /**
* 设置:收货地址Id * 设置:收货地址Id
*/ */
...@@ -333,6 +351,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -333,6 +351,7 @@ public class TbCfOrderVo implements Serializable {
public String getDeliveryAddressId() { public String getDeliveryAddressId() {
return deliveryAddressId; return deliveryAddressId;
} }
/** /**
* 设置:收货地址 * 设置:收货地址
*/ */
...@@ -346,6 +365,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -346,6 +365,7 @@ public class TbCfOrderVo implements Serializable {
public String getDeliveryAddress() { public String getDeliveryAddress() {
return deliveryAddress; return deliveryAddress;
} }
/** /**
* 设置:收货人 * 设置:收货人
*/ */
...@@ -359,6 +379,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -359,6 +379,7 @@ public class TbCfOrderVo implements Serializable {
public String getDeliveryName() { public String getDeliveryName() {
return deliveryName; return deliveryName;
} }
/** /**
* 设置:收货人手机 * 设置:收货人手机
*/ */
...@@ -372,6 +393,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -372,6 +393,7 @@ public class TbCfOrderVo implements Serializable {
public String getDeliveryPhone() { public String getDeliveryPhone() {
return deliveryPhone; return deliveryPhone;
} }
/** /**
* 设置:商品总价 * 设置:商品总价
*/ */
...@@ -385,6 +407,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -385,6 +407,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getItemsPrice() { public BigDecimal getItemsPrice() {
return itemsPrice; return itemsPrice;
} }
/** /**
* 设置:总价 * 设置:总价
*/ */
...@@ -398,6 +421,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -398,6 +421,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getTotalPrice() { public BigDecimal getTotalPrice() {
return totalPrice; return totalPrice;
} }
/** /**
* 设置:实际付款 * 设置:实际付款
*/ */
...@@ -411,6 +435,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -411,6 +435,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getRealityPay() { public BigDecimal getRealityPay() {
return realityPay; return realityPay;
} }
/** /**
* 设置:发货标志 * 设置:发货标志
*/ */
...@@ -424,6 +449,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -424,6 +449,7 @@ public class TbCfOrderVo implements Serializable {
public Integer getDeliveryFlag() { public Integer getDeliveryFlag() {
return deliveryFlag; return deliveryFlag;
} }
/** /**
* 设置:发货时间 * 设置:发货时间
*/ */
...@@ -437,6 +463,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -437,6 +463,7 @@ public class TbCfOrderVo implements Serializable {
public Date getDeliveryTime() { public Date getDeliveryTime() {
return deliveryTime; return deliveryTime;
} }
/** /**
* 设置:快递费 * 设置:快递费
*/ */
...@@ -450,6 +477,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -450,6 +477,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getExpressCost() { public BigDecimal getExpressCost() {
return expressCost; return expressCost;
} }
/** /**
* 设置:优惠券id * 设置:优惠券id
*/ */
...@@ -463,6 +491,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -463,6 +491,7 @@ public class TbCfOrderVo implements Serializable {
public String getCouponId() { public String getCouponId() {
return couponId; return couponId;
} }
/** /**
* 设置:优惠券标题 * 设置:优惠券标题
*/ */
...@@ -476,6 +505,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -476,6 +505,7 @@ public class TbCfOrderVo implements Serializable {
public String getCouponTitle() { public String getCouponTitle() {
return couponTitle; return couponTitle;
} }
/** /**
* 设置:优惠券减免价格 * 设置:优惠券减免价格
*/ */
...@@ -489,6 +519,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -489,6 +519,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getCouponPrice() { public BigDecimal getCouponPrice() {
return couponPrice; return couponPrice;
} }
/** /**
* 设置:手续费 * 设置:手续费
*/ */
...@@ -502,6 +533,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -502,6 +533,7 @@ public class TbCfOrderVo implements Serializable {
public BigDecimal getFee() { public BigDecimal getFee() {
return fee; return fee;
} }
/** /**
* 设置:交易号 * 设置:交易号
*/ */
...@@ -515,6 +547,7 @@ public class TbCfOrderVo implements Serializable { ...@@ -515,6 +547,7 @@ public class TbCfOrderVo implements Serializable {
public String getPayId() { public String getPayId() {
return payId; return payId;
} }
/** /**
* 设置:支付状态,0未支付,1已支付 * 设置:支付状态,0未支付,1已支付
*/ */
......
...@@ -33,12 +33,10 @@ public class RedisCache<T> { ...@@ -33,12 +33,10 @@ public class RedisCache<T> {
try { try {
if (key == null) { if (key == null) {
return null; return null;
} } else {
else {
return redisTemplate.opsForValue().get(key); return redisTemplate.opsForValue().get(key);
} }
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("get key [{}] exception!", key, t); logger.error("get key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -50,8 +48,7 @@ public class RedisCache<T> { ...@@ -50,8 +48,7 @@ public class RedisCache<T> {
try { try {
redisTemplate.opsForValue().set(key, value); redisTemplate.opsForValue().set(key, value);
return value; return value;
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("set key [{}] exception!", key, t); logger.error("set key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -62,8 +59,7 @@ public class RedisCache<T> { ...@@ -62,8 +59,7 @@ public class RedisCache<T> {
try { try {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
return value; return value;
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("set key [{}] exception!", key, t); logger.error("set key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -73,8 +69,7 @@ public class RedisCache<T> { ...@@ -73,8 +69,7 @@ public class RedisCache<T> {
logger.debug("delete key [{}]", key); logger.debug("delete key [{}]", key);
try { try {
redisTemplate.delete(key); redisTemplate.delete(key);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("delete key [{}] exception!", key, t); logger.error("delete key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -89,8 +84,7 @@ public class RedisCache<T> { ...@@ -89,8 +84,7 @@ public class RedisCache<T> {
valueOps.add(key, value); valueOps.add(key, value);
if (time > 0) if (time > 0)
redisTemplate.expire(key, time, TimeUnit.SECONDS); redisTemplate.expire(key, time, TimeUnit.SECONDS);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("setSet key [{}] exception!", key, t); logger.error("setSet key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -109,8 +103,7 @@ public class RedisCache<T> { ...@@ -109,8 +103,7 @@ public class RedisCache<T> {
setOps.add(key, (T[]) v.toArray()); setOps.add(key, (T[]) v.toArray());
if (time > 0) if (time > 0)
redisTemplate.expire(key, time, TimeUnit.SECONDS); redisTemplate.expire(key, time, TimeUnit.SECONDS);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("setSet key [{}] exception!", key, t); logger.error("setSet key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -126,8 +119,7 @@ public class RedisCache<T> { ...@@ -126,8 +119,7 @@ public class RedisCache<T> {
try { try {
SetOperations<String, T> setOps = redisTemplate.opsForSet(); SetOperations<String, T> setOps = redisTemplate.opsForSet();
return setOps.members(key); return setOps.members(key);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("getSet key [{}] exception!", key, t); logger.error("getSet key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -141,8 +133,7 @@ public class RedisCache<T> { ...@@ -141,8 +133,7 @@ public class RedisCache<T> {
listOps.rightPush(key, v); listOps.rightPush(key, v);
if (time > 0) if (time > 0)
redisTemplate.expire(key, time, TimeUnit.SECONDS); redisTemplate.expire(key, time, TimeUnit.SECONDS);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("setList key [{}] exception!", key, t); logger.error("setList key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -156,8 +147,7 @@ public class RedisCache<T> { ...@@ -156,8 +147,7 @@ public class RedisCache<T> {
listOps.rightPushAll(key, v); listOps.rightPushAll(key, v);
if (time > 0) if (time > 0)
redisTemplate.expire(key, time, TimeUnit.SECONDS); redisTemplate.expire(key, time, TimeUnit.SECONDS);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("setList key [{}] exception!", key, t); logger.error("setList key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -173,8 +163,7 @@ public class RedisCache<T> { ...@@ -173,8 +163,7 @@ public class RedisCache<T> {
try { try {
ListOperations<String, T> listOps = redisTemplate.opsForList(); ListOperations<String, T> listOps = redisTemplate.opsForList();
return listOps.range(key, start, end); return listOps.range(key, start, end);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("getList key [{}] exception!", key, t); logger.error("getList key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -186,8 +175,7 @@ public class RedisCache<T> { ...@@ -186,8 +175,7 @@ public class RedisCache<T> {
try { try {
ListOperations<String, T> listOps = redisTemplate.opsForList(); ListOperations<String, T> listOps = redisTemplate.opsForList();
return listOps.size(key); return listOps.size(key);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("getListSize key [{}] exception!", key, t); logger.error("getListSize key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -198,8 +186,7 @@ public class RedisCache<T> { ...@@ -198,8 +186,7 @@ public class RedisCache<T> {
logger.debug("getListSize key [{}]", key); logger.debug("getListSize key [{}]", key);
try { try {
return listOps.size(key); return listOps.size(key);
} } catch (Throwable t) {
catch (Throwable t) {
logger.error("getListSize key [{}] exception!", key, t); logger.error("getListSize key [{}] exception!", key, t);
throw new CacheException(t); throw new CacheException(t);
} }
...@@ -228,4 +215,27 @@ public class RedisCache<T> { ...@@ -228,4 +215,27 @@ public class RedisCache<T> {
public void setRedisTemplate(RedisTemplate<String, T> redisTemplate) { public void setRedisTemplate(RedisTemplate<String, T> redisTemplate) {
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
} }
public String expire(String key) {
Long expire = redisTemplate.getExpire(key);
String hour = getHour(expire.toString());
return hour;
}
public String getHour(String date) {
Integer dt = Integer.parseInt(date);
if (dt < 0) return "0s";
if (dt < 60) return dt + "s";
if (dt < 3600) {
int min = Math.round(dt / 60);
int seconds = Math.round(dt - (min * 60));
return Math.round(dt / 60) + "min" + (seconds == 0 ? "" : seconds + "s");
}
int hour = Math.round(dt / 3600);
int minute = Math.round((dt - (hour * 3600)) / 60);
return hour + "h" + (minute == 0 ? "" : minute + "min");
}
} }
\ No newline at end of file
...@@ -6,7 +6,6 @@ import java.util.UUID; ...@@ -6,7 +6,6 @@ import java.util.UUID;
/** /**
* ID 生成工具类<br> * ID 生成工具类<br>
*
*/ */
public class IdUtil { public class IdUtil {
/** /**
...@@ -19,9 +18,10 @@ public class IdUtil { ...@@ -19,9 +18,10 @@ public class IdUtil {
// 精确到毫秒 // 精确到毫秒
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS"); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String suffix = fmt.format(new Date()); String suffix = fmt.format(new Date());
suffix = suffix+ Math.round((Math.random() * 100000)); suffix = suffix + Math.round((Math.random() * 100000));
return suffix; return suffix;
} }
/** /**
* 主要功能:生成流水号 yyyyMMddHHmmssSSS + 3位随机数 * 主要功能:生成流水号 yyyyMMddHHmmssSSS + 3位随机数
* 注意事项:不能超出long类型取值范围 9223372036854775807 * 注意事项:不能超出long类型取值范围 9223372036854775807
...@@ -32,8 +32,8 @@ public class IdUtil { ...@@ -32,8 +32,8 @@ public class IdUtil {
// 精确到毫秒 // 精确到毫秒
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS"); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String suffix = fmt.format(new Date()); String suffix = fmt.format(new Date());
String prefix=String.valueOf(Math.round(Math.random() * 100)); String prefix = String.valueOf(Math.round(Math.random() * 100));
return Long.valueOf(suffix+prefix); return Long.valueOf(suffix + prefix);
} }
/** /**
...@@ -45,4 +45,6 @@ public class IdUtil { ...@@ -45,4 +45,6 @@ public class IdUtil {
public static String createIdbyUUID() { public static String createIdbyUUID() {
return UUID.randomUUID().toString().replaceAll("-", ""); return UUID.randomUUID().toString().replaceAll("-", "");
} }
} }
...@@ -21,7 +21,7 @@ spring: ...@@ -21,7 +21,7 @@ spring:
#Redis数据库分片索引(默认为0) #Redis数据库分片索引(默认为0)
database: 0 database: 0
# host: 192.168.1.211 # host: 192.168.1.211
host: 49.235.150.107 host: 127.0.0.1
port: 6379 port: 6379
password: password:
......
<?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.diaoyun.zion.chinafrica.dao.TbCfCancelDao">
<resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity" id="tbCfCancelMap">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="cancelReason" column="cancel_reason"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity">
select
`id`,
`order_id`,
`cancel_reason`,
`del_flag`,
`create_time`,
`update_time`
from tb_cf_cancel
where id = #{id}
</select>
<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity">
select
`id`,
`order_id`,
`cancel_reason`,
`del_flag`,
`create_time`,
`update_time`
from tb_cf_cancel
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_cf_cancel
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity">
insert into tb_cf_cancel(
`id`,
`order_id`,
`cancel_reason`,
`del_flag`,
`create_time`,
`update_time`)
values(
#{id},
#{orderId},
#{cancelReason},
#{delFlag},
#{createTime},
#{updateTime})
</insert>
<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCancelEntity">
update tb_cf_cancel
<set>
<if test="orderId != null">`order_id` = #{orderId},</if>
<if test="cancelReason != null">`cancel_reason` = #{cancelReason},</if>
<if test="delFlag != null">`del_flag` = #{delFlag},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from tb_cf_cancel where id = #{value}
</delete>
<delete id="deleteBatch">
delete from tb_cf_cancel where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
...@@ -21,8 +21,8 @@ email.subject=Verification Code from Afrishop ...@@ -21,8 +21,8 @@ email.subject=Verification Code from Afrishop
################redis有效时间################### ################redis有效时间###################
#登录token second 默认30分 一个星期 604800 #登录token second 默认30分 一个星期 604800
redis.token.expiredTime=7776000000 redis.token.expiredTime=7776000000
#订单 30分 second #订单 1天 second 86400
redis.order.expiredTime=1800 redis.order.expiredTime=86400
################腾讯翻译配置################### ################腾讯翻译配置###################
tencent.translate.app_id=2120761040 tencent.translate.app_id=2120761040
//tencent.translate.app_id=2124562134 //tencent.translate.app_id=2124562134
......
...@@ -7,6 +7,8 @@ import com.diaoyun.zion.chinafrica.service.SpiderService; ...@@ -7,6 +7,8 @@ import com.diaoyun.zion.chinafrica.service.SpiderService;
import com.diaoyun.zion.chinafrica.service.TbCfCouponService; import com.diaoyun.zion.chinafrica.service.TbCfCouponService;
import com.diaoyun.zion.chinafrica.service.TbCfIssueCouponService; import com.diaoyun.zion.chinafrica.service.TbCfIssueCouponService;
import com.diaoyun.zion.chinafrica.service.TbCfUserInfoService; import com.diaoyun.zion.chinafrica.service.TbCfUserInfoService;
import com.diaoyun.zion.chinafrica.vo.TbCfOrderVo;
import com.diaoyun.zion.master.common.RedisCache;
import com.diaoyun.zion.master.thread.TaskLimitSemaphore; import com.diaoyun.zion.master.thread.TaskLimitSemaphore;
import com.diaoyun.zion.master.util.AESUtils; import com.diaoyun.zion.master.util.AESUtils;
import com.diaoyun.zion.master.util.IdUtil; import com.diaoyun.zion.master.util.IdUtil;
...@@ -23,8 +25,10 @@ import org.junit.runner.RunWith; ...@@ -23,8 +25,10 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URISyntaxException; import java.net.URISyntaxException;
...@@ -512,6 +516,7 @@ public class ZionApplicationTests { ...@@ -512,6 +516,7 @@ public class ZionApplicationTests {
System.out.println(it.next()); System.out.println(it.next());
} }
} }
/* @Test /* @Test
public void sendEmail() throws EmailException, TemplateException, IOException { public void sendEmail() throws EmailException, TemplateException, IOException {
List<String> emailList= tbCfUserInfoService.findEmails(); List<String> emailList= tbCfUserInfoService.findEmails();
...@@ -535,4 +540,48 @@ public class ZionApplicationTests { ...@@ -535,4 +540,48 @@ public class ZionApplicationTests {
"Happy Shopping!"; "Happy Shopping!";
SMSUtil.sendMessageByText(/*phone.trim()*/"+8613751400455,+8618607444177", text); SMSUtil.sendMessageByText(/*phone.trim()*/"+8613751400455,+8618607444177", text);
} }
@Resource
private RedisCache<Object> orderRedisCache;
@Test
public void testRedis() {
// String hour = orderRedisCache.expire("order_detf28b71d685a34c528180782520fef886");
String hour = getHour("3662");
System.out.println(hour);
}
public String getHour(String date) {
Integer dt = Integer.parseInt(date);
if (dt < 0) return "0s";
if (dt < 60) return dt + "s";
if (dt < 3600) {
int min = Math.round(dt / 60);
int seconds = Math.round(dt - (min * 60));
return Math.round(dt / 60) + "min" + (seconds == 0 ? "" : seconds + "s");
}
int hour = Math.round(dt / 3600);
int minute = Math.round((dt - (hour * 3600)) / 60);
return hour + "h" + (minute == 0 ? "" : minute + "min");
// //分钟
// Integer dt = Integer.parseInt(date) ;
// if (dt < 60) return dt + "分钟";
// int hour = Math.round(dt / 60);
// int minute = Math.round(dt - (hour * 60));
// return hour + "小时" + (minute == 0 ? "" : minute + "分钟");
}
@Test
public void test01() {
System.out.println(orderRedisCache.expire("order_detf28b71d685a34c528180782520fef886"));
orderRedisCache.set("order_detf28b71d685a34c528180782520fef886", 0);
System.out.println(orderRedisCache.expire("order_detf28b71d685a34c528180782520fef886"));
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论