package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mosty.base.model.dto.qwzx.AppSearchQuery;
import com.mosty.base.model.entity.jcgl.TbJcglJyqx;
import com.mosty.base.model.entity.jcgl.TbJcglXfcl;
import com.mosty.base.model.query.jcgl.TbJcglXfclQuery;
import com.mosty.base.manager.service.TbJcglXfclService;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.config.Excel.ExcelUtil;
import com.mosty.common.token.JwtSysUser;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

@RestController
@AllArgsConstructor
@RequestMapping({"/tpJcglXfcl"})
@Api(tags = {"巡防车辆"})
public class TbJcglXfclController {

    private final TbJcglXfclService tbJcglXfclService;

    @GetMapping({"/getXfclList"})
    @JwtSysUser
    @ApiOperation(value = "查询巡防车辆")
    public ResponseResult<IPage<TbJcglXfcl>> getXfclList(TbJcglXfclQuery dto) {
        return ResponseResult.success(tbJcglXfclService.getXfclList(dto));
    }

    @PostMapping({"/addXfcl"})
    @JwtSysUser
    @ApiOperation(value = "新增巡防车辆")
    public ResponseResult<Void> addXfcl(@RequestBody TbJcglXfcl cl) {
        tbJcglXfclService.addXfcl(cl);
        return ResponseResult.success();
    }

    @PostMapping({"/updateXfcl"})
    @JwtSysUser
    @ApiOperation(value = "修改巡防车辆")
    public ResponseResult<Void> updateXfcl(@RequestBody TbJcglXfcl cl) {
        tbJcglXfclService.updateXfcl(cl);
        return ResponseResult.success();
    }

    @PostMapping({"/deleteXfcl"})
    @JwtSysUser
    @ApiOperation(value = "删除巡防车辆")
    public ResponseResult<Boolean> deleteXfcl(@RequestBody List<String> id) {
        return ResponseResult.success(tbJcglXfclService.deleteXfcl(id));
    }

    @GetMapping({"/selectClxq"})
    @JwtSysUser
    @ApiOperation(value = "查询车辆详情")
    public ResponseResult<TbJcglXfcl> selectClxq(String id) {
        return ResponseResult.success(tbJcglXfclService.selectClxq(id));
    }

    @GetMapping({"/selectXfclList"})
    @JwtSysUser
    @ApiOperation(value = "app查询车辆列表")
    public ResponseResult<Page<TbJcglXfcl>> selectXfclList(AppSearchQuery dto) {
        return ResponseResult.success(tbJcglXfclService.selectXfclList(dto));
    }


    @Log(title = "导入巡防车辆", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @JwtSysUser
    @Transactional
    public ResponseResult<String> importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<TbJcglXfcl> util = new ExcelUtil<TbJcglXfcl>(TbJcglXfcl.class);
        List<TbJcglXfcl> xfclList = util.importExcel(file.getInputStream());
        String s = this.tbJcglXfclService.importData(xfclList, updateSupport);
        return ResponseResult.success(s);
    }


    @Log(title = "巡防车辆模板下载", businessType = BusinessType.IMPORT)
    @GetMapping("/importTemplate")
    @JwtSysUser
    public void importTemplate(HttpServletResponse response) throws Exception {
        ExcelUtil<TbJcglXfcl> util = new ExcelUtil<TbJcglXfcl>(TbJcglXfcl.class);
        util.importTemplateExcel(response, "巡防车辆");
    }


}
