//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.luozhihui.project.controller;

import com.luozhihui.project.common.ApiResponse;
import com.luozhihui.project.entity.Order;
import com.luozhihui.project.mapper.CarRentMapper;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/api"})
@CrossOrigin
public class CarRentController {
    @Resource
    CarRentMapper carRentMapper;

    public CarRentController() {
    }

    @PostMapping({"/carRent"})
    public ApiResponse carRent(Order order) {
        try {
            this.carRentMapper.addorder(order);
            System.out.println(order.getCarId());
            this.carRentMapper.updateCarStatus(Integer.valueOf(order.getCarId()));
            return new ApiResponse((Object)null, 200, "车位租借成功");
        } catch (Exception var3) {
            Exception e = var3;
            e.printStackTrace();
            return new ApiResponse((Object)null, 500, "服务器内部错误");
        }
    }

    @PostMapping({"/returnCar"})
    public ApiResponse returnCar(Order order) {
        try {
            this.carRentMapper.carRented(order);
            this.carRentMapper.finishOrder(order.getOrderId());
            this.carRentMapper.endCarStatus(order.getCarId(), order.getParking_id());
            return new ApiResponse((Object)null, 200, "还车成功");
        } catch (Exception var3) {
            Exception e = var3;
            e.printStackTrace();
            return new ApiResponse((Object)null, 500, "服务器内部错误");
        }
    }
}
