package com.bs.tm.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.tm.domain.TmVehicleIdenty;
import com.bs.tm.service.ITmVehicleIdentyService;
import javax.annotation.Resource;

/**
 * 车辆作业识别Controller
 *
 * @author bs
 * @date 2025-01-12
 */
@Api(tags = "车辆作业识别")
@RestController
@RequestMapping("/tm/vehicle/identy")
public class TmVehicleIdentyController extends BaseController {
    @Resource
    private ITmVehicleIdentyService tmVehicleIdentyService;

    /**
     * 分页查询车辆作业识别列表
     */
    @ApiOperation("分页查询车辆作业识别列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(TmVehicleIdenty tmVehicleIdenty) {
        startPage();
        LambdaQueryWrapper<TmVehicleIdenty> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmVehicleIdenty);
        List<TmVehicleIdenty> list = tmVehicleIdentyService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询车辆作业识别列表
     */
    @ApiOperation("查询车辆作业识别列表")
    @GetMapping("/list")
    public AjaxResult list(TmVehicleIdenty tmVehicleIdenty) {
        LambdaQueryWrapper<TmVehicleIdenty> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmVehicleIdenty);
        List<TmVehicleIdenty> list = tmVehicleIdentyService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出车辆作业识别列表
     */
    @ApiOperation("导出车辆作业识别列表")
    @Log(title = "车辆作业识别导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmVehicleIdenty tmVehicleIdenty) {
        LambdaQueryWrapper<TmVehicleIdenty> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmVehicleIdenty);
        List<TmVehicleIdenty> list = tmVehicleIdentyService.list(queryWrapper);
        ExcelUtil<TmVehicleIdenty> util = new ExcelUtil<TmVehicleIdenty>(TmVehicleIdenty. class);
        util.exportExcel(response, list, "车辆作业识别数据");
    }

    /**
     * 获取车辆作业识别详细信息
     */
    @ApiOperation("获取车辆作业识别详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tmVehicleIdentyService.getById(id));
    }

    /**
     * 新增车辆作业识别
     */
    @ApiOperation("新增车辆作业识别")
    @Log(title = "车辆作业识别新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmVehicleIdenty tmVehicleIdenty) {
        return toAjax(tmVehicleIdentyService.save(tmVehicleIdenty));
    }

    /**
     * 修改车辆作业识别
     */
    @ApiOperation("修改车辆作业识别")
    @Log(title = "车辆作业识别修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmVehicleIdenty tmVehicleIdenty) {
        return toAjax(tmVehicleIdentyService.updateById(tmVehicleIdenty));
    }

    /**
     * 删除车辆作业识别
     */
    @ApiOperation("删除车辆作业识别")
    @Log(title = "车辆作业识别删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(tmVehicleIdentyService.removeBatchByIds(ids));
    }

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


        //id
        if(Validator.isNotEmpty(tmVehicleIdenty.getId())){
            queryWrapper.eq(TmVehicleIdenty::getId,tmVehicleIdenty.getId());
        }

        //流水号
        if(Validator.isNotEmpty(tmVehicleIdenty.getSeqNo())){
            queryWrapper.eq(TmVehicleIdenty::getSeqNo,tmVehicleIdenty.getSeqNo());
        }

        //主机编号
        if(Validator.isNotEmpty(tmVehicleIdenty.getHostNo())){
            queryWrapper.eq(TmVehicleIdenty::getHostNo,tmVehicleIdenty.getHostNo());
        }

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

        //识别日期
        if(Validator.isNotEmpty(tmVehicleIdenty.getIdentyTime())){
            queryWrapper.eq(TmVehicleIdenty::getIdentyTime,tmVehicleIdenty.getIdentyTime());
        }

        //发送日期
        if(Validator.isNotEmpty(tmVehicleIdenty.getSendTime())){
            queryWrapper.eq(TmVehicleIdenty::getSendTime,tmVehicleIdenty.getSendTime());
        }

        //接收日期
        if(Validator.isNotEmpty(tmVehicleIdenty.getReceiveTime())){
            queryWrapper.eq(TmVehicleIdenty::getReceiveTime,tmVehicleIdenty.getReceiveTime());
        }

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

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

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

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

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

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

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

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

        }

}
