You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.5 KiB

3 years ago
package com.cyl.h5.controller;
import com.cyl.h5.pojo.dto.OrderCreateDTO;
import com.cyl.h5.pojo.vo.OrderCalcVO;
3 years ago
import com.cyl.h5.pojo.vo.form.OrderSubmitForm;
3 years ago
import com.cyl.h5.pojo.vo.query.OrderH5Query;
import com.cyl.h5.service.H5OrderService;
import com.cyl.manager.oms.pojo.vo.OrderVO;
import com.cyl.manager.oms.service.OrderService;
import com.cyl.manager.ums.domain.Member;
2 years ago
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisService;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.ApiOperation;
2 years ago
import lombok.extern.slf4j.Slf4j;
3 years ago
import org.springframework.beans.factory.annotation.Autowired;
3 years ago
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
3 years ago
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/h5/order")
2 years ago
@Slf4j
public class H5OrderController {
2 years ago
@Autowired
private RedisService redisService;
@Autowired
private H5OrderService service;
2 years ago
@PostMapping("/add")
2 years ago
public ResponseEntity<Long> submit(@RequestBody OrderSubmitForm form) {
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
Long memberId = member.getId();
String redisKey = "h5_order_add" + memberId;
String redisValue = memberId + "_" + System.currentTimeMillis();
try{
redisService.lock(redisKey, redisValue, 60);
return ResponseEntity.ok(service.submit(form));
2 years ago
}catch (Exception e){
log.info("创建订单方法异常", e);
throw new RuntimeException("服务繁忙,稍后再试");
2 years ago
}finally {
try {
redisService.unLock(redisKey, redisValue);
} catch (Exception e) {
e.printStackTrace();
}
}
3 years ago
}
// @PostMapping("orders")
// public ResponseEntity<Page<OrderVO>> queryOrderPage(@RequestBody OrderH5Query query, Pageable pageReq) {
// return ResponseEntity.ok(service.queryOrderPage(query, pageReq));
// }
@ApiOperation("下单前校验")
@PostMapping("/addOrderCheck")
public ResponseEntity<OrderCalcVO> addOrderCheck(@RequestBody OrderCreateDTO orderCreateDTO){
return ResponseEntity.ok(service.addOrderCheck(orderCreateDTO));
}
3 years ago
}