/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.gpsboot.controller.car;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.gpsboot.service.car.TfCarInsuranceService;
import com.tofly.pojo.car.TfCarInsurance;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 车辆车险记录表
 *
 * @author JF
 * @date Mon Nov 25 00:00:00 CST 2024
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tfcarinsurance")
@Api(tags="车辆车险记录表接口")
public class TfCarInsuranceController {

    private final TfCarInsuranceService tfCarInsuranceService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param tfCarInsurance 车辆车险记录表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getTfCarInsurancePage(Page page, @ModelAttribute TfCarInsurance tfCarInsurance) {
        List<String> auditStatusList = new ArrayList<>();
        if (StringUtils.isNotBlank(tfCarInsurance.getAuditStatusMore())) {
            auditStatusList = Arrays.asList(tfCarInsurance.getAuditStatusMore().split(","));
        }
        return ResultRespone.success(tfCarInsuranceService.page(page, Wrappers.query(tfCarInsurance).lambda()
                .in(StringUtils.isNotBlank(tfCarInsurance.getAuditStatusMore()), TfCarInsurance::getAuditStatus, auditStatusList)));
    }


    /**
     * 通过id查询车辆车险记录表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(tfCarInsuranceService.getById(id));
    }

    /**
     * 新增车辆车险记录表
     * @param fileList 文件列表
     * @param tfCarInsurance 车辆车险记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增车辆车险记录表" )
    @ApiOperation(value = "新增车辆车险记录表")
    @PostMapping
    public ResultRespone save(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, TfCarInsurance tfCarInsurance) {
      return ResultRespone.success(tfCarInsuranceService.saveCarInsurance(fileList, tfCarInsurance));
    }

    /**
     * 修改车辆车险记录表
     * @param fileList 文件列表
     * @param tfCarInsurance 车辆车险记录表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改车辆车险记录表" )
    @ApiOperation(value = "修改车辆车险记录表")
    @PutMapping
    public ResultRespone updateById(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList, TfCarInsurance tfCarInsurance) {
      return ResultRespone.success(tfCarInsuranceService.updateCarInsurance(fileList, tfCarInsurance));
    }

    /**
     * 通过id删除车辆车险记录表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除车辆车险记录表" )
    @ApiOperation(value = "通过ID删除车辆车险记录表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(tfCarInsuranceService.removeById(id));
    }

    /**
     * 通过id批量删除车辆车险记录表
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除车辆车险记录表" )
    @ApiOperation(value = "通过ID批量删除车辆车险记录表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(tfCarInsuranceService.removeCarInsuranceByIds(ids));
    }
}
