package com.mosty.yjzl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.yjzl.TbFzycDto;
import com.mosty.base.model.entity.jcgl.TbJcglXfll;
import com.mosty.base.model.entity.yjzl.TbFzyc;
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.mosty.yjzl.service.TbFzycService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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


@Api(tags = "犯罪预测接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbFzyc")
public class TbFzycController {

    private TbFzycService tbFzycService;

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "犯罪预测新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbFzyc vo) {
        return ResponseResult.success(tbFzycService.insert(vo));
    }

    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "犯罪预测更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbFzyc vo) {
        return ResponseResult.success(tbFzycService.fzUpdateById(vo));
    }

    @ApiOperation("删除数据")
    @JwtSysUser
    @DeleteMapping("/{id}")
    @Log(title = "犯罪预测删除", businessType = BusinessType.DELETE)
    public ResponseResult<Integer> update(@PathVariable("id") String id) {
        return ResponseResult.success(tbFzycService.deleteById(id));
    }

    @ApiOperation("App查询犯罪预测列表")
    @JwtSysUser
    @PostMapping("/queryListApp")
    @Log(title = "查询犯罪预测列表", businessType = BusinessType.OTHER)
    public ResponseResult<List<TbFzyc>> queryListApp(@RequestBody TbFzycDto tbFzycDto) {
        return ResponseResult.success(tbFzycService.queryListApp(tbFzycDto));
    }


    @ApiOperation("查询犯罪预测列表")
    @JwtSysUser
    @PostMapping("/queryList")
    @Log(title = "查询犯罪预测列表", businessType = BusinessType.OTHER)
    public ResponseResult<List<TbFzyc>> queryList(@RequestBody TbFzycDto tbFzycDto) {
        return ResponseResult.success(tbFzycService.queryList(tbFzycDto));
    }

    @ApiOperation("分页查询犯罪预测列表")
    @JwtSysUser
    @PostMapping("/queryListPage")
    @Log(title = "分页查询犯罪预测列表", businessType = BusinessType.OTHER)
    public ResponseResult<IPage<TbFzyc>> queryListPage(@RequestBody TbFzycDto tbFzycDto) {
        return ResponseResult.success(tbFzycService.queryListPage(tbFzycDto));
    }

    @GetMapping("/getFzyjCount")
    @ApiOperation("查询犯罪预测数量")
    public ResponseResult<Integer> getFzyjCount(String ssbmdm, String time, String sfxl) {
        return ResponseResult.success(tbFzycService.getFzyjCount(ssbmdm, time, sfxl));
    }

    @Log(title = "导入犯罪预测", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @JwtSysUser
    @ApiOperation(value = "导入犯罪预测")
    public ResponseResult<String> importData(MultipartFile file) throws Exception {
        ExcelUtil<TbFzyc> util = new ExcelUtil<>(TbFzyc.class);
        List<TbFzyc> fzycList = util.importExcel(file.getInputStream(), 1);
        String s = this.tbFzycService.importData(fzycList);
        return ResponseResult.success(s);
    }

    @PostMapping("/exportData")
    @ApiOperation(value = "导出犯罪预测")
    public void getStatistics(HttpServletResponse response, TbFzycDto tbFzycDto) throws Exception {
//        List<TbFzyc> list = tbFzycService.queryList(tbFzycDto);
        List<TbFzyc> list = new ArrayList<>();
        ExcelUtil<TbFzyc> util = new ExcelUtil<>(TbFzyc.class);
        util.exportExcel(response, list, "犯罪预测网格导出", "犯罪预测网格导出");
    }

}
