package com.bs.cm.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.bs.common.annotation.Log;
import com.bs.common.core.controller.BaseController;
import com.bs.common.core.domain.AjaxResult;
import com.bs.common.core.page.TableDataInfo;
import com.bs.common.enums.BusinessType;
import com.bs.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.hutool.core.lang.Validator;
import com.bs.cm.domain.CmVehicleRfidDate;
import com.bs.cm.service.ICmVehicleRfidDateService;
import javax.annotation.Resource;

/**
 * 车辆RFID生效日期Controller
 *
 * @author bs
 * @date 2025-01-12
 */
@Api(tags = "车辆RFID生效日期")
@RestController
@RequestMapping("/cm/vehicle/rfid/date")
public class CmVehicleRfidDateController extends BaseController {
    @Resource
    private ICmVehicleRfidDateService cmVehicleRfidDateService;

    /**
     * 分页查询车辆RFID生效日期列表
     */
    @ApiOperation("分页查询车辆RFID生效日期列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(CmVehicleRfidDate cmVehicleRfidDate) {
        startPage();
        LambdaQueryWrapper<CmVehicleRfidDate> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,cmVehicleRfidDate);
        List<CmVehicleRfidDate> list = cmVehicleRfidDateService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询车辆RFID生效日期列表
     */
    @ApiOperation("查询车辆RFID生效日期列表")
    @GetMapping("/list")
    public AjaxResult list(CmVehicleRfidDate cmVehicleRfidDate) {
        LambdaQueryWrapper<CmVehicleRfidDate> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,cmVehicleRfidDate);
        List<CmVehicleRfidDate> list = cmVehicleRfidDateService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出车辆RFID生效日期列表
     */
    @ApiOperation("导出车辆RFID生效日期列表")
    @Log(title = "车辆RFID生效日期导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmVehicleRfidDate cmVehicleRfidDate) {
        LambdaQueryWrapper<CmVehicleRfidDate> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,cmVehicleRfidDate);
        List<CmVehicleRfidDate> list = cmVehicleRfidDateService.list(queryWrapper);
        ExcelUtil<CmVehicleRfidDate> util = new ExcelUtil<CmVehicleRfidDate>(CmVehicleRfidDate. class);
        util.exportExcel(response, list, "车辆RFID生效日期数据");
    }

    /**
     * 获取车辆RFID生效日期详细信息
     */
    @ApiOperation("获取车辆RFID生效日期详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cmVehicleRfidDateService.getById(id));
    }

    /**
     * 新增车辆RFID生效日期
     */
    @ApiOperation("新增车辆RFID生效日期")
    @Log(title = "车辆RFID生效日期新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmVehicleRfidDate cmVehicleRfidDate) {
        return toAjax(cmVehicleRfidDateService.save(cmVehicleRfidDate));
    }

    /**
     * 修改车辆RFID生效日期
     */
    @ApiOperation("修改车辆RFID生效日期")
    @Log(title = "车辆RFID生效日期修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmVehicleRfidDate cmVehicleRfidDate) {
        return toAjax(cmVehicleRfidDateService.updateById(cmVehicleRfidDate));
    }

    /**
     * 删除车辆RFID生效日期
     */
    @ApiOperation("删除车辆RFID生效日期")
    @Log(title = "车辆RFID生效日期删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(cmVehicleRfidDateService.removeBatchByIds(ids));
    }

    /**
      * 条件设置
      */
    private void condition (LambdaQueryWrapper<CmVehicleRfidDate> queryWrapper,CmVehicleRfidDate cmVehicleRfidDate){


        //ID
        if(Validator.isNotEmpty(cmVehicleRfidDate.getId())){
            queryWrapper.eq(CmVehicleRfidDate::getId,cmVehicleRfidDate.getId());
        }

        //RFID标签ID
        if(Validator.isNotEmpty(cmVehicleRfidDate.getRfidId())){
            queryWrapper.eq(CmVehicleRfidDate::getRfidId,cmVehicleRfidDate.getRfidId());
        }

        //车辆ID
        if(Validator.isNotEmpty(cmVehicleRfidDate.getVehicleId())){
            queryWrapper.eq(CmVehicleRfidDate::getVehicleId,cmVehicleRfidDate.getVehicleId());
        }

        //标签编号
        if(Validator.isNotEmpty(cmVehicleRfidDate.getRfidNo())){
            queryWrapper.eq(CmVehicleRfidDate::getRfidNo,cmVehicleRfidDate.getRfidNo());
        }

        //安装日期
        if(Validator.isNotEmpty(cmVehicleRfidDate.getSetupDate())){
            queryWrapper.eq(CmVehicleRfidDate::getSetupDate,cmVehicleRfidDate.getSetupDate());
        }

        //生效日期
        if(Validator.isNotEmpty(cmVehicleRfidDate.getEffectiveDate())){
            queryWrapper.eq(CmVehicleRfidDate::getEffectiveDate,cmVehicleRfidDate.getEffectiveDate());
        }

        //失效日期
        if(Validator.isNotEmpty(cmVehicleRfidDate.getExpiringDate())){
            queryWrapper.eq(CmVehicleRfidDate::getExpiringDate,cmVehicleRfidDate.getExpiringDate());
        }

        //备注
        if(Validator.isNotEmpty(cmVehicleRfidDate.getRemark())){
            queryWrapper.eq(CmVehicleRfidDate::getRemark,cmVehicleRfidDate.getRemark());
        }

        //删除标志（0代表存在 2代表删除）
        if(Validator.isNotEmpty(cmVehicleRfidDate.getDelFlag())){
            queryWrapper.eq(CmVehicleRfidDate::getDelFlag,cmVehicleRfidDate.getDelFlag());
        }

        //创建部门
        if(Validator.isNotEmpty(cmVehicleRfidDate.getCreateDept())){
            queryWrapper.eq(CmVehicleRfidDate::getCreateDept,cmVehicleRfidDate.getCreateDept());
        }

        //创建人
        if(Validator.isNotEmpty(cmVehicleRfidDate.getCreateBy())){
            queryWrapper.eq(CmVehicleRfidDate::getCreateBy,cmVehicleRfidDate.getCreateBy());
        }

        //创建时间
        if(Validator.isNotEmpty(cmVehicleRfidDate.getCreateTime())){
            queryWrapper.eq(CmVehicleRfidDate::getCreateTime,cmVehicleRfidDate.getCreateTime());
        }

        //修改人
        if(Validator.isNotEmpty(cmVehicleRfidDate.getUpdateBy())){
            queryWrapper.eq(CmVehicleRfidDate::getUpdateBy,cmVehicleRfidDate.getUpdateBy());
        }

        //修改时间
        if(Validator.isNotEmpty(cmVehicleRfidDate.getUpdateTime())){
            queryWrapper.eq(CmVehicleRfidDate::getUpdateTime,cmVehicleRfidDate.getUpdateTime());
        }

        //租户ID
        if(Validator.isNotEmpty(cmVehicleRfidDate.getTenantId())){
            queryWrapper.eq(CmVehicleRfidDate::getTenantId,cmVehicleRfidDate.getTenantId());
        }

        }

}
