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.manager.service.TbJcglJyqxService;
import com.mosty.base.model.dto.qwzx.AppSearchQuery;
import com.mosty.base.model.entity.jcgl.TbJcglJyqx;
import com.mosty.base.model.query.jcgl.TbJcglJyqxQuery;
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 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({"/tpJcglJyqx"})
@Api(tags = {"警用器械"})
public class TbJcglJyqxController {

    private final TbJcglJyqxService tbJcglJyqxService;



    @PostMapping({"/xfJyqx"})
    @JwtSysUser
    @Log(title = "下发警用器械", businessType = BusinessType.INSERT)
    @ApiOperation(value = "下发警用器械")
    public ResponseResult xfZnzb(@RequestBody TbJcglJyqx zb) {
        tbJcglJyqxService.xfZnzb(zb);
        return ResponseResult.success();

    }

    @GetMapping({"/htJyqx"})
    @JwtSysUser
    @ApiOperation(value = "回退警用器械")
    public ResponseResult htZnzb(String id,long sl) {
        tbJcglJyqxService.htZnzb(id,sl);
        return ResponseResult.success();
    }

    @GetMapping({"/bsJyqx"})
    @JwtSysUser
    @ApiOperation(value = "报损警用器械")
    public ResponseResult bsZnzb(String id,long sl) {
        tbJcglJyqxService.bsZnzb(id,sl);
        return ResponseResult.success();
    }


    @PostMapping("/addJyqx")
    @JwtSysUser
    @ApiOperation(value = "新增警用器械")
    public ResponseResult<Object> addJyqx(@RequestBody TbJcglJyqx jyqx) {
        tbJcglJyqxService.addJyqx(jyqx);
        return ResponseResult.success();
    }

    @GetMapping({"/selectJyqx"})
    @JwtSysUser
    @ApiOperation(value = "查询警用装备")
    public ResponseResult<IPage<TbJcglJyqx>> selectJyqx(TbJcglJyqx jyqx) {
        IPage<TbJcglJyqx> page = new Page<>(jyqx.getPageNo(), jyqx.getPageSize());
        return ResponseResult.success(tbJcglJyqxService.selectJyqx(jyqx, page));
    }

    @PostMapping({"/updateJyqx"})
    @JwtSysUser
    @ApiOperation(value = "修改警用装备")
    public ResponseResult updateJyqx(@RequestBody TbJcglJyqx jyqx) {
        tbJcglJyqxService.updateJyqx(jyqx);
        return ResponseResult.success();
    }

    @PostMapping({"/deleteJyQxzb"})
    @JwtSysUser
    @ApiOperation(value = "删除警用装备")
    public ResponseResult deleteJyQxzb(@RequestBody List<String> id) {
        tbJcglJyqxService.deleteJyQxzb(id);
        return ResponseResult.success();
    }

    @GetMapping({"selectJyqxXq"})
    @JwtSysUser
    @ApiOperation(value = "id查询警用器械")
    public ResponseResult selectJyqxXq(String id) {
        return ResponseResult.success(tbJcglJyqxService.selectJyqxXq(id));
    }

    @ApiOperation("警用器械到期提醒")
    @JwtSysUser
    @GetMapping("/jyqxDqtx")
    public ResponseResult<IPage<TbJcglJyqx>> jyqxDqtx(TbJcglJyqxQuery jyqx) {
        IPage<TbJcglJyqx> page = new Page<>(jyqx.getPageCurrent(), jyqx.getPageSize());
        return ResponseResult.success(tbJcglJyqxService.selectDqjyqx(jyqx, page));
    }

    @ApiOperation("app查询警用器械信息")
    @JwtSysUser
    @GetMapping("/getJyqxList")
    public ResponseResult<IPage<TbJcglJyqx>> getJyqxList(AppSearchQuery dto) {
        return ResponseResult.success(tbJcglJyqxService.getJyqxList(dto));
    }

    @Log(title = "导入警用器械", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @JwtSysUser
    @Transactional
    public ResponseResult<String> importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<TbJcglJyqx> util = new ExcelUtil<TbJcglJyqx>(TbJcglJyqx.class);
        List<TbJcglJyqx> jyqxList = util.importExcel(file.getInputStream());
        String s = this.tbJcglJyqxService.importData(jyqxList, updateSupport);
        return ResponseResult.success(s);
    }


    @Log(title = "警用器械模板下载", businessType = BusinessType.IMPORT)
    @GetMapping("/importTemplate")
    @JwtSysUser
    public void importTemplate(HttpServletResponse response) throws Exception {
        ExcelUtil<TbJcglJyqx> util = new ExcelUtil<TbJcglJyqx>(TbJcglJyqx.class);
        util.importTemplateExcel(response, "警用器械");
    }
}
