package com.zcloud.controller.eightwork;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.eightwork.ConfinedSpaceGasService;
import com.zcloud.service.eightwork.ConfinedSpaceGasWHService;
import com.zcloud.service.eightwork.ConfinedspaceService;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：受限作业
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/confinedspace")
public class ConfinedspaceController extends BaseController {

    @Autowired
    private ConfinedspaceService confinedspaceService;
    @Autowired
    private ConfinedSpaceGasService confinedspaceGasService;

    @Autowired
    private ConfinedSpaceGasWHService confinedspacegaswhService;

    /**列表
     * @param page
     * @throws Exception
     */
    @RequestMapping(value="/list")
    @ResponseBody
	@LogAnno(menuType= "高危作业管理",menuServer= "受限作业",instructionsOperate = "受限作业",instructionsType = "列表")
    public Object list(Page page) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        String KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
        if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim());
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        page.setPd(pd);
        List<PageData>	varList = confinedspaceService.list(page);	//列出confinedspace列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);

        return map;
    }

    /**获取受限作业流程
     * @param
     * @throws Exception
     */
    @RequestMapping(value="/getFlowList")
    @ResponseBody
    @LogAnno(menuType= "高危作业管理",menuServer= "受限作业",instructionsOperate = "受限作业",instructionsType = "获取受限作业流程")
    public Object getFlowList() throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        List<PageData> flowList = confinedspaceService.getFlowList(pd);
        map.put("flowList", flowList);
        map.put("result", errInfo);				//返回结果
        return map;
    }

    @RequestMapping("/findById")
    @ResponseBody
    @LogAnno(menuType= "高危作业管理",menuServer= "受限作业",instructionsOperate = "受限作业",instructionsType = "获取详情")
    public Object findById() throws Exception {
        Map<String,Object> map = new HashMap<>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd = confinedspaceService.findById(pd);
        PageData signs = confinedspaceService.listSignFinished(pd);
        List<PageData> finishMeasuresList = confinedspaceService.listSignFinishMeasures(pd);
        PageData toxicCombustibleGas = confinedspacegaswhService.findById(pd);
        map.put("gas", toxicCombustibleGas);
        map.put("gasList", confinedspaceGasService.listAll(pd));
        map.put("measuresList",finishMeasuresList);
        map.put("signs",signs);
        map.put("pd",pd);
        map.put("result",errInfo);
        return map;
    }

}
