package com.zcloud.controller.eightwork;

import com.alibaba.fastjson.JSONObject;
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.*;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.PLSUtil;
import com.zcloud.util.ReturnMap;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

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

/**
 * 说明：动火作业
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/hotwork")
public class HotworkController extends BaseController {

    @Autowired
    private HotworkService hotworkService;
    @Autowired
    private HotworkGasService hotworkGasService;
    @Autowired
    private HighworkService highworkService;
    @Autowired
    private ConfinedspaceService confinedspaceService;
    @Autowired
    private HoistingService hoistingService;
    @Autowired
    private BreakGroundService breakGroundService;
    @Autowired
    private ElectricityService electricityService;
    @Autowired
    private CutRoadService cutRoadService;
    @Autowired
    private BlindBoardService blindBoardService;
    /**
     * 列表
     *
     * @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 = hotworkService.list(page);    //列出hotwork列表
        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 = hotworkService.findById(pd);
        List<PageData> flowList = hotworkService.getFlowList(pd);
        map.put("flowingWork", 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 = hotworkService.findById(pd);
        PageData signs = hotworkService.listSignFinished(pd);
        List<PageData> finishMeasuresList = hotworkService.listSignFinishMeasures(pd);
        map.put("gasList", hotworkGasService.listAll(pd));
        map.put("measuresList", finishMeasuresList);
        map.put("signs", signs);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }


    // pc 作业删除
    @RequestMapping("/removeWorkById")
    @ResponseBody
    @LogAnno(menuType = "高危作业管理", menuServer = "作业删除", instructionsOperate = "作业删除", instructionsType = "删除")
    public Object removeWorkById() throws Exception {
        PageData pageData = getPageData();
        if (pageData.getString("WORK_TYPE").equals("HOTWORK")) {
            pageData.put("HOTWORK_ID", pageData.getString("WORK_ID"));
            hotworkService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("HIGH")) {
            pageData.put("HIGHWORK_ID", pageData.getString("WORK_ID"));
            highworkService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("confined_space")) {
            pageData.put("CONFINEDSPACE_ID", pageData.getString("WORK_ID"));
            confinedspaceService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("hoisting")) {
            pageData.put("HOISTING_ID", pageData.getString("WORK_ID"));
            hoistingService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("groundbreaking")) {
            pageData.put("BREAKGROUND_ID", pageData.getString("WORK_ID"));
            breakGroundService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("electricity")) {
            pageData.put("ELECTRICITY_ID", pageData.getString("WORK_ID"));
            electricityService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("open_circuit")) {
            pageData.put("CUTROAD_ID", pageData.getString("WORK_ID"));
            cutRoadService.delete(pageData);
        }
        if (pageData.getString("WORK_TYPE").equals("blind")) {
            pageData.put("BLINDBOARD_ID", pageData.getString("WORK_ID"));
            blindBoardService.delete(pageData);
        }
        return ReturnMap.ok();
    }


}
