package com.yeejoin.amos.fas.business.controller;

import com.yeejoin.amos.fas.business.bo.FireParamBo;
import com.yeejoin.amos.fas.business.service.intfc.FireRectificationService;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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


/**
 * 安全执行-消防整改 控制器
 *
 * @author 郑嘉伟
 */
@RestController
@RequestMapping(value = "/api/fireRectification")
@Api(tags = "消防整改")
public class FireRectificationController extends AbstractBaseController {

    @Autowired
    private  FireRectificationService fireRectificationService;

    @Permission
    @ApiOperation(httpMethod = "GET", value = "按条件查询消防整改列表信息", notes = "按条件查询消防整改列表信息")
    @GetMapping(value = "/list")
    public CommonResponse queryFireList(
            @RequestParam(value = "nameLike") String nameLike,
            @RequestParam(value = "sDate") String sDate,
            @RequestParam(value = "eDate") String eDate,
            @RequestParam(value = "states") int states,
            @RequestParam(value = "pageNum") int pageNum,
            @RequestParam(value = "pageSize") int pageSize) {
        return CommonResponseUtil.success(fireRectificationService.queryFiresAndCount(nameLike,sDate,eDate,states,pageNum,pageSize));
    }

    @Permission
    @ApiOperation(httpMethod = "GET", value = "获取单个单据详细数据", notes = "获取单个单据详细数据")
    @GetMapping(value = "/getMoreData")
    public CommonResponse seleteOne(@RequestParam(value = "billNo") String billNo){
        return CommonResponseUtil.success(fireRectificationService.selectOneById(billNo));
    }

    @Permission
    @ApiOperation(httpMethod = "POST", value = "下载附件", notes = "下载附件")
    @PostMapping(value = "/downLoad")
    public void downLoad(@RequestBody List<String> path, HttpServletResponse response){
        fireRectificationService.downLoadFilesByUrll(path.get(0),response);
    }

    @Permission
    @ApiOperation(httpMethod = "POST", value = "修改表单数据", notes = "修改表单数据")
    @PostMapping(value = "/update")
    public CommonResponse update(@RequestBody FireParamBo paramBo){
        return CommonResponseUtil.success(fireRectificationService.updateByid(paramBo));
    }
}
