package com.zcloud.controller.dynamicAssessment;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.entity.Response;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.dynamicAssessment.ReportService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 说明：报表模板
 * 作者：luoxiaobao
 * 时间：2023-04-24
 * 官网：www.zcloudchina.com
 */
@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

    @Resource
    private ReportService reportService;

    @RequestMapping("getList")
    public Response getList(Page page) throws Exception {
        Response response = Response.getResponse();
        try {
            PageData request = this.getPageData();
            response.putAll(reportService.getList(request, page));
            return response.OK();
        } catch (Exception e) {
            e.printStackTrace();
            return response.errorMessage(e.getMessage());
        }
    }

    @RequestMapping("getForm")
    public Response getFrom() throws Exception {
        Response response = Response.getResponse();
        try {
            PageData request = this.getPageData();
            response.putAll(reportService.getForm(request));
            return response.OK();
        } catch (Exception e) {
            e.printStackTrace();
            return response.errorMessage(e.getMessage());
        }
    }

    @RequestMapping("init")
    public Response init() throws Exception {
        Response response = Response.getResponse();
        try {
            PageData request = this.getPageData();
            reportService.init(request);
            return response.OK();
        } catch (Exception e) {
            e.printStackTrace();
            return response.errorMessage(e.getMessage());
        }
    }

    /**
     * description: 重大危险源企业安全包保责任人履职模块样例 (企业级)
     */
    @RequestMapping(value = "/getBaoBaoForm")
    @LogAnno(menuType = "检测预警", menuServer = "报表", instructionsOperate = "重大危险源企业安全包保责任人履职模块", instructionsType = "详情")
    public Object edit(Page page) throws Exception {
        Map<String, Object> map;
        try {
            map = reportService.getBaoBaoReport(page, this.getPageData());
            map.put("result", "success");
        } catch (Exception e) {
            e.printStackTrace();
            map = new HashMap<>();
            map.put("code", "9999");
            map.put("errorMessage", e.getMessage());
        }
        return map;
    }
}
