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.HighworkService;
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("/highwork")
public class HighworkController extends BaseController {

    @Autowired
    private HighworkService highworkService;


    /**列表
     * @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 = highworkService.list(page);	//列出highwork列表
        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();
        pd = highworkService.findById(pd);
        List<PageData> flowList = highworkService.getFlowList(pd);
        map.put("flowList", flowList);
        map.put("flowingWork", pd);
        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 = highworkService.findById(pd);
        PageData signs = highworkService.listSignFinished(pd);
        List<PageData> finishMeasuresList = highworkService.listSignFinishMeasures(pd);
        map.put("measuresList",finishMeasuresList);
        map.put("signs",signs);
        map.put("pd",pd);
        map.put("result",errInfo);
        return map;
    }

}
