首页>代码>vue+maven+ssh的网上花店系统>/flowers/src/main/java/com/jack/controller/OrderController.java
package com.jack.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;





import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jack.entity.Cart;
import com.jack.entity.Order;
import com.jack.entity.Product;
import com.jack.service.OrderItemService;
import com.jack.service.OrderService;
import com.jack.service.ProductService;
import com.util.controller.BaseController;
import com.util.entity.ResponseEntity;

@RestController
@RequestMapping("order")
public class OrderController extends BaseController {

	private static final Logger LOGGER=Logger.getLogger(OrderController.class);
	
	@Autowired 
	private OrderService orderService;
	
	@Autowired
	private ProductService productService;
	
	@Autowired
	private OrderItemService orderItemService;
	
	@GetMapping
	public ResponseEntity getOrderListByUserId(Order order,HttpServletRequest request){
		String userId=(String) super.getSessionParams(request, "userId");
		ResponseEntity re=new ResponseEntity();
		try{
			order.setUserId(userId);
			List<Order> orderList=orderService.findOrders(order);
			re.setData(orderList);
			re.setStatusCode("200");
		}catch(Exception e){
			e.printStackTrace();
			String errorMsg=e.getMessage();
			re.setStatusCode("500");
			re.setErrorMsg("500");
			LOGGER.info(errorMsg);
		}
		return re;
	}
	
	//从购物车中生成订单或直接生成订单
	@PostMapping
	public ResponseEntity saveOrder(Order order,Product product,HttpServletRequest request){
		Cart cart=(Cart) super.getSessionParams(request, "cart");
		ResponseEntity re=new ResponseEntity();
		try{
		   String id=orderService.generateOrder(cart, order, product);
		   re.setData(id);
		   re.setStatusCode("200");
		}catch(Exception e){		
			e.printStackTrace();
			String errorMsg=e.getMessage();
		    re.setStatusCode("500");
			re.setErrorCode("500");
			re.setErrorMsg(errorMsg);
			LOGGER.info(errorMsg);
		}
		return re;
	}
}
最近下载更多
20041226  LV3 6月19日
543666826  LV34 2024年12月28日
wuni1105  LV2 2024年5月16日
阿九11111  LV4 2024年5月9日
微信网友_6505237310967808  LV1 2023年6月5日
hbsoft2008  LV16 2023年2月17日
张三helisi  LV4 2022年6月11日
对方说到底是  LV2 2022年5月29日
gch666  LV6 2022年5月23日
a1642865118  LV8 2022年5月22日
最近浏览更多
20041226  LV3 6月18日
jhkhk313  LV1 6月8日
周 敬博  LV2 6月6日
chunnnn 6月4日
暂无贡献等级
两杆大烟枪 5月26日
暂无贡献等级
lilimyeclipse  LV6 5月11日
徐长风  LV2 4月27日
zdh3907  LV15 4月23日
zhaoming200677  LV13 4月19日
做自己的太阳  LV11 3月22日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友