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.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.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;

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;

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @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));
    }

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

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

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