package com.dcsoft.system.vehicle.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dcsoft.system.vehicle.domain.CarParkRecord;
import com.dcsoft.system.vehicle.service.ICarParkRecordService;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 车辆授权Controller
 *
 * @author dcsoft
 * @date 2023-12-29
 */
@RestController
@RequestMapping("/parkRecord")
public class CarParkRecordController extends BaseController
{
    @Autowired
    private ICarParkRecordService carParkRecordService;

    /**
     * 查询车辆授权列表
     */
    @RequiresPermissions("system:parkRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(CarParkRecord carParkRecord)
    {
        startPage();
        List<CarParkRecord> list = carParkRecordService.selectCarParkRecordList(carParkRecord);
        return getDataTable(list);
    }

    /**
     * 导出车辆授权列表
     */
    @RequiresPermissions("system:parkRecord:export")
    @Log(title = "车辆授权", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarParkRecord carParkRecord)
    {
        List<CarParkRecord> list = carParkRecordService.selectCarParkRecordList(carParkRecord);
        ExcelUtil<CarParkRecord> util = new ExcelUtil<CarParkRecord>(CarParkRecord.class);
        util.exportExcel(response, list, "车辆授权数据");
    }

    /**
     * 获取车辆授权详细信息
     */
    @RequiresPermissions("system:parkRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carParkRecordService.selectCarParkRecordById(id));
    }

    /**
     * 新增车辆授权
     */
    @RequiresPermissions("system:parkRecord:add")
    @Log(title = "车辆授权", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarParkRecord carParkRecord)
    {
        return toAjax(carParkRecordService.insertCarParkRecord(carParkRecord));
    }

    /**
     * 修改车辆授权
     */
    @RequiresPermissions("system:parkRecord:edit")
    @Log(title = "车辆授权", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarParkRecord carParkRecord)
    {
        return toAjax(carParkRecordService.updateCarParkRecord(carParkRecord));
    }

    /**
     * 删除车辆授权
     */
    @RequiresPermissions("system:parkRecord:remove")
    @Log(title = "车辆授权", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carParkRecordService.deleteCarParkRecordByIds(ids));
    }

    /**
     * 删除车辆授权
     */
    @Log(title = "车辆授权", businessType = BusinessType.UPDATE)
    @GetMapping("/down/{ids}")
    public AjaxResult down(@PathVariable Long[] ids)
    {
       int i=0;
        for(Long id:ids){
           CarParkRecord carParkRecord=carParkRecordService.selectCarParkRecordById(id);
           carParkRecord.setSync("2");
           carParkRecordService.updateCarParkRecord(carParkRecord);
           i++;
       }
        return toAjax(i);
    }

}
