提交 e60c245d authored 作者: zgy's avatar zgy

修改bug

上级 2318bb9c
......@@ -36,4 +36,6 @@ public class KeyConstant {
public final static String SHOPIFY_ITEM = "shopify_item";
//商品类型
public final static String SHOPIFY_TYPE = "shopify_item";
//所有商品
public final static String SHOPIFY_ITEMS_ALL = "shopify_item_all";
}
......@@ -45,15 +45,15 @@ public class LoginController extends BaseController {
@ApiOperation(value = "注册并登录")
@PostMapping(value = "/registerByPhone")
public Result<TbCfUserInfoVo> registerByPhone(@ApiParam("用户信息") @RequestBody TbCfUserInfoVo tbCfUserInfoVo,@ApiParam(value = "验证码") @RequestParam("code") String code) throws ParseException{
return tbCfUserInfoService.registerByPhone(tbCfUserInfoVo,code);
public Result<TbCfUserInfoVo> registerByPhone(@ApiParam("用户信息") @RequestBody TbCfUserInfoVo tbCfUserInfoVo, @ApiParam(value = "验证码") @RequestParam("code") String code) throws ParseException {
return tbCfUserInfoService.registerByPhone(tbCfUserInfoVo, code);
}
@ApiOperation("登录")
@PostMapping
public Result<TbCfUserInfoVo> login(@ApiParam(value = "登录名")String account,
@ApiParam(value = "密码") String password) {
return tbCfUserInfoService.login(getIpAddr(request), account,password);
public Result<TbCfUserInfoVo> login(@ApiParam(value = "登录名") @ValidateParam({Validator.NOT_BLANK}) String account,
@ApiParam(value = "密码") @ValidateParam({Validator.NOT_BLANK}) String password) {
return tbCfUserInfoService.login(getIpAddr(request), account, password);
}
@ApiOperation("使用token登录")
......@@ -65,12 +65,12 @@ public class LoginController extends BaseController {
@ApiOperation("使用手机号登录")
@GetMapping("/phone")
public Result<TbCfUserInfoVo> loginByPhone(@ApiParam(value = "手机号") @RequestParam("phone") String phone,
@ApiParam(value = "验证码") @RequestParam("code") String code){
return tbCfUserInfoService.loginByPhone(getIpAddr(request),phone,code);
@ApiParam(value = "验证码") @RequestParam("code") String code) {
return tbCfUserInfoService.loginByPhone(getIpAddr(request), phone, code);
}
/**
* 获取短信验证码
*
*/
@ApiOperation(value = "获取短信验证码")
@GetMapping(value = "/register/identifyCode/{phone}")
......@@ -83,9 +83,9 @@ public class LoginController extends BaseController {
@PostMapping("/thirdParty")
// TODO
@Deprecated
public Result<TbCfUserInfoVo> loginByThirdParty(@ApiParam("第三方账号") @RequestParam(required = false) String amount,
@ApiParam("用户昵称 url编码") @RequestParam(required = false) String nick,
@ApiParam("账号类型") @RequestParam(required = false) String userType) throws UnsupportedEncodingException {
return tbCfUserInfoService.loginByThirdParty(getIpAddr(request),amount,nick,userType);
public Result<TbCfUserInfoVo> loginByThirdParty(@ApiParam("第三方账号") @RequestParam(required = false) String amount,
@ApiParam("用户昵称 url编码") @RequestParam(required = false) String nick,
@ApiParam("账号类型") @RequestParam(required = false) String userType) throws UnsupportedEncodingException {
return tbCfUserInfoService.loginByThirdParty(getIpAddr(request), amount, nick, userType);
}
}
......@@ -69,6 +69,19 @@ public class ShopifyController {
return shopifyService.queryProductsDetails(product_id);
}
/**
* 查询所有商品
*
* @param product_id 商品ID
* @return
*/
@ApiOperation(value = "查询所有商品")
@GetMapping("/queryallproducts")
public Result queryAllProducts(@ApiParam("商品ID") @RequestParam(value = "product_id", required = false) String product_id) {
return shopifyService.queryAllProducts(product_id);
}
/**
* 查询商品最新一条评论
*
......
......@@ -31,15 +31,15 @@ public class TbCfOrderController {
@ApiOperation("用户结算,返回订单")
@GetMapping("/settle")
public Result<TbCfOrderVo> settleAccount(@ApiParam("发放ID") @RequestParam(value = "iss_coupon_id",required = false) String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
public Result<TbCfOrderVo> settleAccount(@ApiParam("发放ID") @RequestParam(value = "iss_coupon_id", required = false) String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
return tbCfOrderService.settleAccount(iss_coupon_id);
}
@ApiOperation("用户确定下单")
@PostMapping("/place")
public Result placeOrder(@ApiParam("订单详情") @RequestBody TbCfOrderVo tbCfOrderVo,@ApiParam("发放ID") @RequestParam(value = "iss_coupon_id",required = false) String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
System.out.println("发放Id"+iss_coupon_id);
return tbCfOrderService.placeOrder(tbCfOrderVo,iss_coupon_id);
public Result placeOrder(@ApiParam("订单详情") @RequestBody TbCfOrderVo tbCfOrderVo, @ApiParam("发放ID") @RequestParam(value = "iss_coupon_id", required = false) String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
System.out.println("发放Id" + iss_coupon_id);
return tbCfOrderService.placeOrder(tbCfOrderVo, iss_coupon_id);
}
/**
......@@ -48,16 +48,17 @@ public class TbCfOrderController {
*/
@ApiOperation("获取用户订单 默认10条")
@GetMapping
public Result<PageInfo> getUserOrderList(@ApiParam(value = "页数") @RequestParam(required = false) Integer pageNum,
@ApiParam(value ="每页大小") @RequestParam(required = false) Integer pageSize,
@ApiParam(value = "订单状态") @RequestParam(required = false)Integer orderStatus) {
public Result<PageInfo> getUserOrderList(@ApiParam(value = "页数") @RequestParam(value = "pageNum", required = false) Integer pageNum,
@ApiParam(value = "每页大小") @RequestParam(value = "pageSize", required = false) Integer pageSize,
@ApiParam(value = "订单状态") @RequestParam(value = "orderStatus", required = false) Integer orderStatus,
@ApiParam(value = "订单状态") @RequestParam(value = "userId") String userId) {
if (pageNum == null) {
pageNum = 1;
}
if (pageSize == null) {
pageSize = 10;
}
return tbCfOrderService.getUserOrderList(pageNum, pageSize,orderStatus);
return tbCfOrderService.getUserOrderList(pageNum, pageSize, orderStatus, userId);
}
@ApiOperation("获取stripe公钥")
......@@ -68,28 +69,28 @@ public class TbCfOrderController {
@ApiOperation("发起订单支付")
@PostMapping("/pay/{orderId}/{token}")
public Result payForOrder(@ApiParam("订单id")@PathVariable("orderId")String orderId,@ApiParam("支付token")@PathVariable("token")String token) {
return tbCfOrderService.payForOrder(orderId,token);
public Result payForOrder(@ApiParam("订单id") @PathVariable("orderId") String orderId, @ApiParam("支付token") @PathVariable("token") String token) {
return tbCfOrderService.payForOrder(orderId, token);
}
@ApiOperation("根据订单id,查询物流详情")
@GetMapping("/express/{orderId}")
public Result queryOrderExpressInfo(@ApiParam("订单id")@PathVariable String orderId) throws IOException {
return tbCfOrderService.queryOrderExpressInfo(orderId);
public Result queryOrderExpressInfo(@ApiParam("订单id") @PathVariable String orderId) throws IOException {
return tbCfOrderService.queryOrderExpressInfo(orderId);
}
@ApiOperation("删除订单")
@DeleteMapping("/{orderId}")
public Result deleteOrder(@ApiParam("订单id") @PathVariable String orderId) {
return tbCfOrderService.deleteOrder(orderId);
return tbCfOrderService.deleteOrder(orderId);
}
/**
* 根据订单号获取详细订单数据
*/
@ApiOperation(value = "根据订单号获取详细订单数据")
@GetMapping(value ="/detail/{orderId}")
public Result getOrderDetail(@PathVariable("orderId")String orderId) {
@GetMapping(value = "/detail/{orderId}")
public Result getOrderDetail(@PathVariable("orderId") String orderId) {
return tbCfOrderService.getOrderDetail(orderId);
}
}
......@@ -14,4 +14,5 @@ public interface ShopifyService {
public Result queryShopifyProducts();
public Result queryProductsByType(String product_type,String product_id);
public Result queryProductsDetails(String product_id);
public Result queryAllProducts(String product_id);
}
......@@ -95,7 +95,7 @@ public interface TbCfOrderService {
* @param orderStatus 订单状态 OrderStatusEnum
* @return
*/
Result getUserOrderList(Integer pageNum, Integer pageSize,Integer orderStatus);
Result getUserOrderList(Integer pageNum, Integer pageSize,Integer orderStatus,String userId);
/**
* 取消订单
......
......@@ -15,10 +15,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
......@@ -29,6 +26,7 @@ import java.util.Map;
@Service("shopifyService")
public class ShopifyServiceImpl implements ShopifyService {
private static Logger logger = LoggerFactory.getLogger(ShopifyServiceImpl.class);
@Resource
private RedisCache<Object> redisCache;
......@@ -39,26 +37,28 @@ public class ShopifyServiceImpl implements ShopifyService {
*/
@Override
public Result queryShopifyProducts() {
List type = Arrays.asList("Christmas", "Men", "Women", "Face", "virgin hair", "Afri Home", "Children");
Result result = new Result();
Map<String, Object> params = new HashMap<>();
List<String> list = new ArrayList();
try {
List products = (List) redisCache.get(KeyConstant.SHOPIFY_ITEMS);
if (products != null) {
if (products != null && products.size() == type.size()) {
JSONArray jsonArray = JSONArray.fromObject(products);
result.setData(jsonArray);
return result;
}
List type = (List) redisCache.get(KeyConstant.SHOPIFY_TYPE);
if (type == null) {
type = getProductType();
}
// List type = (List) redisCache.get(KeyConstant.SHOPIFY_TYPE);
// if (type == null) {
// type = getProductType();
// }
for (int i = 0; i < type.size(); i++) {
params.put("product_type", type.get(i));
params.put("limit", ShopifyConstant.SHOPIFY_LIMIT);
String data = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
list.add(data);
redisCache.set(KeyConstant.SHOPIFY_ITEMS, list);
redisCache.set(KeyConstant.SHOPIFY_ITEMS, list, 86400);
}
System.out.println(list);
JSONArray jsonArr = JSONArray.fromObject(list);
......@@ -80,7 +80,7 @@ public class ShopifyServiceImpl implements ShopifyService {
@Override
public Result queryProductsByType(String product_type, String product_id) {
Result result = new Result();
String typeProducts = (String) redisCache.get(KeyConstant.SHOPIFY_TYPE_ITEMS + product_id);
String typeProducts = (String) redisCache.get(KeyConstant.SHOPIFY_TYPE_ITEMS + product_type + product_id);
if (typeProducts != null) {
JSONObject object = JSONObject.fromObject(typeProducts);
result.setData(object);
......@@ -88,13 +88,13 @@ public class ShopifyServiceImpl implements ShopifyService {
}
Map<String, Object> params = new HashMap<>();
params.put("product_type", product_type);
params.put("limit", ShopifyConstant.SHOPIFY_PAGE_SIZE);
params.put("limit", /*ShopifyConstant.SHOPIFY_PAGE_SIZE*/ "250");
params.put("since_id", product_id);
try {
String data = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
JSONObject jsonObject = JSONObject.fromObject(data);
result.setData(jsonObject);
redisCache.set(KeyConstant.SHOPIFY_TYPE_ITEMS + product_id, data);
//redisCache.set(KeyConstant.SHOPIFY_TYPE_ITEMS + product_type + product_id, data, 86400);
} catch (IOException e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage(), e);
......@@ -122,7 +122,7 @@ public class ShopifyServiceImpl implements ShopifyService {
params.put("ids", product_id);
String data = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
jsonProduct = JSONObject.fromObject(data);
redisCache.set(KeyConstant.SHOPIFY_ITEM + product_id, data);
redisCache.set(KeyConstant.SHOPIFY_ITEM + product_id, data, 86400);
}
result.setData(jsonProduct);
} catch (IOException e) {
......@@ -133,6 +133,38 @@ public class ShopifyServiceImpl implements ShopifyService {
return result;
}
/**
* 查询所有商品
*
* @param product_id
* @return
*/
public Result queryAllProducts(String product_id) {
Result result = new Result();
try {
JSONObject jsonObject = null;
String allProducts = (String) redisCache.get(KeyConstant.SHOPIFY_ITEMS_ALL + product_id);
if (allProducts != null) {
jsonObject = JSONObject.fromObject(allProducts);
result.setData(jsonObject);
return result;
}
Map<String, Object> params = new HashMap<>();
params.put("limit", ShopifyConstant.SHOPIFY_PAGE_SIZE);
params.put("since_id", product_id);
String data = HttpClientUtil.createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
redisCache.set(KeyConstant.SHOPIFY_ITEMS_ALL + product_id, data);
jsonObject = JSONObject.fromObject(data);
result.setData(jsonObject);
} catch (Exception e) {
result.setCode(ResultCodeEnum.QUERY_ERROR.getCode()).setMessage(e.getMessage());
logger.error(e.getMessage(), e);
return result;
}
return result;
}
/**
* 查询所有商品分类
*
......@@ -155,4 +187,6 @@ public class ShopifyServiceImpl implements ShopifyService {
redisCache.set(KeyConstant.SHOPIFY_TYPE, list);
return list;
}
}
......@@ -91,7 +91,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Autowired
private SpiderService spiderService;
@Autowired
private TbCfUserInfoDao tbCfUserInfoDao;
@Resource
private RedisCache<Object> orderRedisCache;
......@@ -147,6 +148,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
/**
* 用户计算1
*
* @param iss_coupon_id
* @return
* @throws IOException
......@@ -155,7 +157,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
* @throws InterruptedException
* @throws TimeoutException
*/
@Override
@Override
public Result settleAccount(String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
Result<TbCfOrderVo> result = new Result<>();
//获取用户
......@@ -167,16 +169,16 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode()).setMessage("There are no items in the shopping cart");
} else {
//获取订单数据
TbCfOrderVo tbCfOrder = getOrderData(tbCfUserInfoVo, tbCfCartItemDetailList,iss_coupon_id);
TbCfOrderVo tbCfOrder = getOrderData(tbCfUserInfoVo, tbCfCartItemDetailList, iss_coupon_id);
result.setData(tbCfOrder).setMessage("Order pending settlement");
}
return result;
}
@Override
public Result placeOrder(TbCfOrderVo pageOrder,String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
System.out.println(iss_coupon_id+"发放ID");
Result<TbCfOrderVo> result = new Result<>();
public Result placeOrder(TbCfOrderVo pageOrder, String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
System.out.println(iss_coupon_id + "发放ID");
Result<TbCfOrderVo> result = new Result<>();
//获取用户
String token = jwtTokenProvider.resolveToken(request);
TbCfUserInfoVo tbCfUserInfoVo = tokenManager.validate(token);
......@@ -187,7 +189,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode()).setMessage("There are no items in the shopping cart");
} else {
//获取下单的订单数据
TbCfOrderVo definiteOrder = ensureOrder(tbCfUserInfoVo, pageOrder, tbCfCartItemDetailList,iss_coupon_id);
TbCfOrderVo definiteOrder = ensureOrder(tbCfUserInfoVo, pageOrder, tbCfCartItemDetailList, iss_coupon_id);
//持久化订单数据
TbCfOrderEntity tbCfOrderEntity = new TbCfOrderEntity();
BeanUtils.copyProperties(definiteOrder, tbCfOrderEntity);
......@@ -202,11 +204,12 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}
@Override
public Result getUserOrderList(Integer pageNum, Integer pageSize, Integer orderStatus) {
public synchronized Result getUserOrderList(Integer pageNum, Integer pageSize, Integer orderStatus, String userId) {
Result<PageInfo<TbCfOrderVo>> result = new Result<>();
//获取用户
String token = jwtTokenProvider.resolveToken(request);
TbCfUserInfoVo tbCfUserInfoVo = tokenManager.validate(token);
// String token = jwtTokenProvider.resolveToken(request);
// TbCfUserInfoVo tbCfUserInfoVo = tokenManager.validate(token);
TbCfUserInfoEntity tbCfUserInfoVo = tbCfUserInfoDao.queryObject(userId);
//订单数据
List<TbCfOrderEntity> orderList = tbCfOrderDao.getUserOrderList(tbCfUserInfoVo.getUserId(), orderStatus);
startPage(pageNum, pageSize);
......@@ -279,8 +282,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
//更改订单状态
changeOrderState(charge.getId(), tbCfOrderVo);
//修改使用的优惠券的状态
if(tbCfOrderVo.getOrderStatus()==20){
tbCfToiCouponDao.changeCoupnStatus(tbCfOrderVo.getUserId(),tbCfOrderVo.getCouponId());
if (tbCfOrderVo.getOrderStatus() == 20) {
tbCfToiCouponDao.changeCoupnStatus(tbCfOrderVo.getUserId(), tbCfOrderVo.getCouponId());
}
//生成流水记录
TbCfFinanceEntity tbCfFinance = createFinance(charge, tbCfOrderVo);
......@@ -314,6 +317,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
/**
* 查询物流信息
*
* @param orderId
* @return
* @throws IOException
......@@ -372,7 +376,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
public Result getOrderDetailThird(String orderId) {
Result<OrderEntity> result = new Result<>();
OrderEntity order = tbCfOrderDao.getOrder(orderId);
OrderEntity orderEntity=new OrderEntity();
OrderEntity orderEntity = new OrderEntity();
orderEntity.setOrderId(order.getOrderId());
orderEntity.setDeliveryPhone(order.getDeliveryPhone());
orderEntity.setDeliveryName(order.getDeliveryName());
......@@ -384,7 +388,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
//返回的订单商品详情
List<ItemEntity> itemList = new ArrayList<>();
for (ItemEntity item : items) {
ItemEntity entity=new ItemEntity();
ItemEntity entity = new ItemEntity();
entity.setItemNum(item.getItemNum());
entity.setItemCategory(item.getItemCategory());
entity.setItemPrice(item.getItemPrice());
......@@ -419,14 +423,14 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
Result<TbCfOrderVo> result = new Result<>();
TbCfOrderEntity tbCfOrderEntity = tbCfOrderDao.queryObject(orderId);
TbCfOrderVo tbCfOrderVo = new TbCfOrderVo();
BeanUtils.copyProperties(tbCfOrderEntity,tbCfOrderVo);
BeanUtils.copyProperties(tbCfOrderEntity, tbCfOrderVo);
//获取订单内商品
List<TbCfItemDetailEntity> tbCfItemDetailList = tbCfOrderDao.getOrderItemList(orderId);
//返回的订单商品详情
List<TbCfCartItemDetailVo> itemDetailVoList = new ArrayList<>();
for (TbCfItemDetailEntity tbCfItemDetail : tbCfItemDetailList) {
TbCfCartItemDetailVo tbCfCartItemDetailVo = new TbCfCartItemDetailVo();
BeanUtils.copyProperties(tbCfItemDetail,tbCfCartItemDetailVo);
BeanUtils.copyProperties(tbCfItemDetail, tbCfCartItemDetailVo);
itemDetailVoList.add(tbCfCartItemDetailVo);
}
tbCfOrderVo.setItemDetailList(itemDetailVoList);
......@@ -536,14 +540,14 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
* @param couponId
*/
private void couponUse(String userId, String couponId) {
// 更新领取记录已领取
// 更新领取记录已领取
int res = tbCfTakeCouponDao.updateEnableFlag(userId, couponId, StateConstant.INVALID);
if (res < 1) {
logger.error("消费了优惠券,但是在数据表里没有记录!userId:" + userId + ";couponId:" + couponId);
}
/**
* 增加已使用记录
// */
// */
// TbCfCouponUseEntity tbCfCouponUse = new TbCfCouponUseEntity();
// tbCfCouponUse.setUseId(IdUtil.createIdbyUUID());
// tbCfCouponUse.setCouponId(couponId);
......@@ -597,7 +601,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
* @throws IOException
* @throws URISyntaxException
*/
private TbCfOrderVo ensureOrder(TbCfUserInfoVo tbCfUserInfoVo, TbCfOrderVo pageOrder, List<TbCfCartItemDetailVo> tbCfCartItemDetailList,String iss_coupon_id) {
private TbCfOrderVo ensureOrder(TbCfUserInfoVo tbCfUserInfoVo, TbCfOrderVo pageOrder, List<TbCfCartItemDetailVo> tbCfCartItemDetailList, String iss_coupon_id) {
TbCfOrderVo definiteOrder = getGenericOrder(tbCfCartItemDetailList);
/*//获取可以使用的优惠券,后续还有判断此订单是否可以使用
......@@ -619,7 +623,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}*/
//计算实际需要付款
countRealityPay(definiteOrder,iss_coupon_id);
countRealityPay(definiteOrder, iss_coupon_id);
//获取订单地址
String deliveryAddressId = pageOrder.getDeliveryAddressId();
Validator.NOT_BLANK.validate("address", deliveryAddressId);
......@@ -651,7 +655,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
*
* @return
*/
private TbCfOrderVo getGenericOrder(List<TbCfCartItemDetailVo> tbCfCartItemDetailList) {
private TbCfOrderVo getGenericOrder(List<TbCfCartItemDetailVo> tbCfCartItemDetailList) {
TbCfOrderVo genericOrder = new TbCfOrderVo();
genericOrder.setItemDetailList(tbCfCartItemDetailList);
......@@ -660,7 +664,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
BigDecimal totalExpressCost = BigDecimal.ZERO;
for (TbCfCartItemDetailVo tbCfCartItemDetailVo : tbCfCartItemDetailList) {
BigDecimal itemNum = BigDecimal.valueOf(tbCfCartItemDetailVo.getItemNum());
BigDecimal itemSourcePrice=tbCfCartItemDetailVo.getItemPrice();
BigDecimal itemSourcePrice = tbCfCartItemDetailVo.getItemPrice();
itemsPrice = itemsPrice.add(itemSourcePrice.multiply(itemNum));
//计算运费
BigDecimal expressCost = getExpressTemplate(tbCfCartItemDetailVo.getItemCategory());
......@@ -715,6 +719,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
/**
* 用户计算价格2
*
* @param tbCfUserInfoVo
* @param tbCfCartItemDetailList
* @param iss_coupon_id
......@@ -725,7 +730,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
* @throws InterruptedException
* @throws TimeoutException
*/
private TbCfOrderVo getOrderData(TbCfUserInfoVo tbCfUserInfoVo, List<TbCfCartItemDetailVo> tbCfCartItemDetailList,String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
private TbCfOrderVo getOrderData(TbCfUserInfoVo tbCfUserInfoVo, List<TbCfCartItemDetailVo> tbCfCartItemDetailList, String iss_coupon_id) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
TbCfOrderVo tbCfOrder = getGenericOrder(tbCfCartItemDetailList);
/* //获取可以使用的优惠券,后续还有判断此订单是否可以使用
List<TbCfCouponEntity> tbCfCouponList = tbCfCouponDao.queryUserAvailableCoupon(tbCfUserInfoVo.getUserId(), new Date());
......@@ -740,7 +745,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}*/
//计算实际需要付款
countRealityPay(tbCfOrder,iss_coupon_id);
countRealityPay(tbCfOrder, iss_coupon_id);
tbCfOrder.setUserId(tbCfUserInfoVo.getUserId());
tbCfOrder.setUserName(tbCfUserInfoVo.getNick());
......@@ -753,10 +758,10 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
*
* @param tbCfOrder
*/
private void countRealityPay(TbCfOrderVo tbCfOrder,String iss_coupon_id) {
if(iss_coupon_id!=null){
private void countRealityPay(TbCfOrderVo tbCfOrder, String iss_coupon_id) {
if (iss_coupon_id != null) {
TbCfCouponEntity couponEntity = tbCfOrderDao.queryCouponPrice(iss_coupon_id);
if(couponEntity!=null){
if (couponEntity != null) {
tbCfOrder.setCouponPrice(couponEntity.getDeductAmount());
tbCfOrder.setCouponId(couponEntity.getCouponId());
}
......@@ -774,7 +779,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
tbCfOrder.setRealityPay(tbCfOrder.getTotalPrice());
}
removeRedisCache(tbCfOrder);
orderRedisCache.set(KeyConstant.ORDER_DET + tbCfOrder.getOrderId(),tbCfOrder);
orderRedisCache.set(KeyConstant.ORDER_DET + tbCfOrder.getOrderId(), tbCfOrder);
}
/**
......
......@@ -24,71 +24,71 @@ import java.util.Date;
@Component
public class JwtTokenProvider {
/**
* THIS IS NOT A SECURE PRACTICE! For simplicity, we are storing a static key here. Ideally, in a
* microservices environment, this key would be kept on a config-server.
*/
@Value("${security.jwt.token.secret-key}")
private String secretKey;
@Value("${security.jwt.token.expire-length}")
private long validityInMilliseconds; // 1h
@Autowired
private MyUserDetails myUserDetails;
@Resource(name = "redisTokenManager")
private TokenManager tokenManager;
@PostConstruct
protected void init() {
secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
}
public String createToken(String username) {
Claims claims = Jwts.claims().setSubject(username);
//claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
Date now = new Date();
Date validity = new Date(now.getTime() + validityInMilliseconds);
return Jwts.builder()//
.setClaims(claims)//
.setIssuedAt(now)//
.setExpiration(validity)//
.signWith(SignatureAlgorithm.HS256, secretKey)//
.compact();
}
public Authentication getAuthentication(String token) {
UserDetails userDetails = myUserDetails.loadUserByUsername(getUsername(token));
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities());
}
public String getUsername(String token) {
return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject();
}
public String resolveToken(HttpServletRequest req) {
String bearerToken = req.getHeader("Authorization");
if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
/**
* THIS IS NOT A SECURE PRACTICE! For simplicity, we are storing a static key here. Ideally, in a
* microservices environment, this key would be kept on a config-server.
*/
@Value("${security.jwt.token.secret-key}")
private String secretKey;
@Value("${security.jwt.token.expire-length}")
private long validityInMilliseconds; // 1h
@Autowired
private MyUserDetails myUserDetails;
@Resource(name = "redisTokenManager")
private TokenManager tokenManager;
@PostConstruct
protected void init() {
secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
}
public String createToken(String username) {
Claims claims = Jwts.claims().setSubject(username);
//claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
Date now = new Date();
Date validity = new Date(now.getTime() + validityInMilliseconds);
return Jwts.builder()//
.setClaims(claims)//
.setIssuedAt(now)//
.setExpiration(validity)//
.signWith(SignatureAlgorithm.HS256, secretKey)//
.compact();
}
public Authentication getAuthentication(String token) {
UserDetails userDetails = myUserDetails.loadUserByUsername(getUsername(token));
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities());
}
public String getUsername(String token) {
return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject();
}
public String resolveToken(HttpServletRequest req) {
String bearerToken = req.getHeader("Authorization");
if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
return null;
}
return null;
}
public boolean validateToken(String token) {
try {
Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token);
TbCfUserInfoVo loginUser=tokenManager.validate(token);
if(loginUser==null) {
throw new ApplicationException(ResultCodeEnum.NEED_LOGIN.getCode(),"Expired or invalid JWT token");
}
return true;
} catch (JwtException | IllegalArgumentException e) {
throw new ApplicationException(ResultCodeEnum.NEED_LOGIN.getCode(),"Expired or invalid JWT token");
public boolean validateToken(String token) {
try {
Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token);
TbCfUserInfoVo loginUser = tokenManager.validate(token);
if (loginUser == null) {
throw new ApplicationException(ResultCodeEnum.NEED_LOGIN.getCode(), "Expired or invalid JWT token");
}
return true;
} catch (JwtException | IllegalArgumentException e) {
throw new ApplicationException(ResultCodeEnum.NEED_LOGIN.getCode(), "Expired or invalid JWT token");
}
}
}
}
......@@ -42,6 +42,7 @@ public class PayTest {
}
}
System.out.println(list);
}
@Test
......@@ -84,9 +85,9 @@ public class PayTest {
}
@Test
public void test3(){
Integer count=0;
while (count<4){
public void test3() {
Integer count = 0;
while (count < 4) {
System.out.println("helloworld!");
count++;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论