package com.pine.admin.modules.business.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pine.common.dto.Page;
import com.pine.admin.modules.base.binder.BaseController;
import com.pine.common.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;
import com.pine.admin.modules.business.entity.CarBackOrder;
import com.pine.admin.modules.business.service.CarBackOrderService;


/**
 * 选配车退单表
 *
 * @author Pine
 * @email 771190883@qq.com
 * @date 2019-07-22 21:11:50
 */
@Api(value = "选配车退单表接口", tags = {"选配车退单表接口" })
@RestController
@RequestMapping("business/CarBackOrder")
public class CarBackOrderController extends BaseController {

    @Autowired
    private CarBackOrderService carBackOrderService;


    /**
     * <p>获取全部记录。</p>
     */
    @ApiOperation(value = "获取所有选配车退单表数据", notes = "可以根据条件获取")
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Result all(CarBackOrder record) {

        List<CarBackOrder> pp = carBackOrderService.getAllList(record);
        return Result.success(true, pp);
    }


    /**
     * <p>根据Id。</p>
     */
    @ApiOperation(value = "获取选配车退单表数据", notes = "根据id来获取选配车退单表详细信息")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result getCarBackOrder(@PathVariable("id") String id) {

            CarBackOrder data = carBackOrderService.getById(id);
        return Result.success(true, data);
    }

    /**
     * <p>根据条件获取。</p>
     */
    @ApiOperation(value = "获取选配车退单表数据", notes = "根据条件获取")
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    public Result getOne(CarBackOrder record) {

            CarBackOrder data = carBackOrderService.getOne(record);
        return Result.success(true, data);
    }

    /**
     * <p>分页查询。</p>
     */
    @ApiOperation(value = "分页获取选配车退单表数据", notes = "根据条件获取")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Page page, CarBackOrder record) {

        Map<String, Object> result = new HashMap<>();

        List<CarBackOrder> pp = carBackOrderService.getByPage(page, record);

        result.put("page", page);
        result.put("pp", pp);
        return Result.success(true, result);
    }

    /**
     * <p>保存。</p>
     */
    @ApiOperation(value = "新增一条选配车退单表数据", notes = "新增一条选配车退单表数据")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(CarBackOrder record) {

        boolean num = carBackOrderService.create(record);
        if (num) {
            return Result.success(true, record.getId());
        }
        return Result.error("保存异常");
    }

    /**
     * <p>更新信息。</p>
     */
    @ApiOperation(value = "更新一条选配车退单表数据", notes = "更新一条选配车退单表数据")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Result updateCarBackOrder(CarBackOrder record) {

        boolean num = carBackOrderService.update(record);
        if (num) {
            return Result.success(true, "保存成功");
        }
        return Result.error("保存异常");
    }

    /**
     * <p>删除。</p>
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除一条选配车退单表数据", notes = "根据Id一条选配车退单表数据")
    public Result deleteCarBackOrder(@PathVariable("id") String id) {

        boolean num = carBackOrderService.delete(id);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

    /**
     * <p>批量删除。</p>
     */
    @RequestMapping(value = "/deltetByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除多条选配车退单表数据", notes = "删除id的集合多个用英文逗号分隔")
    public Result delCarBackOrderAll(@RequestParam(required = true, value = "ids") String ids) {

        boolean num = carBackOrderService.deltetByIds(ids);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

}
