package com.project.zcustom.controller.backManager.officialCar;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.zcustom.domain.addional.LargeCar;
import com.project.zcustom.service.unit.ILargePublicCarService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/zcustom/public")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LargePublicCarController extends BaseController {

    private final ILargePublicCarService largePlatPublicCarService;

    @GetMapping("/list")
    public AjaxResult list(LargeCar entity) {
        return AjaxResult.success("查询成功", largePlatPublicCarService.pagingLargeCarList(entity));
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(LargeCar entity) {
        return AjaxResult.success("查询成功", largePlatPublicCarService.selectLargeCarList(entity));
    }


    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", largePlatPublicCarService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platPublicCar:add')")
    @Log(title = "公务用车", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody LargeCar entity) {
        return toAjax(largePlatPublicCarService.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platPublicCar:edit')")
    @Log(title = "公务用车", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody LargeCar entity) {
        return toAjax(largePlatPublicCarService.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:platPublicCar:remove')")
    @Log(title = "公务用车", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(largePlatPublicCarService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }

    /**
     * 上传json
     * */
    @PostMapping("/upload")
    public AjaxResult upload(@RequestBody Map<String, Object> obj) {
        return toAjax(largePlatPublicCarService.upload(obj));
    }
}
