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

修改bug

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