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.EightWorkVideoManagerService;
import com.zcloud.service.video.VideoManagerService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ObjectExcelView;
import com.zcloud.util.Tools;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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.servlet.ModelAndView;

import java.util.*;

/**
 * 说明：盲板作业
 * 作者：luoxiaobao
 * 时间：2021-08-23
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/eightworkvideomanager")
public class EightWorkVideoManagerController extends BaseController {

	@Autowired
	private EightWorkVideoManagerService eightworkvideomanagerService;
	@Autowired
	private VideoManagerService videomanagerService;


	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	@ResponseBody
	public Object add() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("EIGHTWORKVIDEOMANAGER_ID", this.get32UUID());	//主键
		pd.put("CREATOR", Jurisdiction.getUsername());	//添加人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		pd.put("ISDELETE", "0");
		eightworkvideomanagerService.save(pd);
		map.put("result", errInfo);
		return map;
	}

	/**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	@ResponseBody
	public Object goEdit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = eightworkvideomanagerService.findById(pd);	//根据ID读取
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**删除
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	@ResponseBody
	public Object delete() throws Exception{
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		eightworkvideomanagerService.delete(pd);
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	@ResponseBody
	public Object edit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		eightworkvideomanagerService.edit(pd);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @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());	//企业ID
		pd.put("ISMAIN", Jurisdiction.getIS_MAIN());
		pd.put("ISSUPERVISE", Jurisdiction.getISSUPERVISE());
		pd.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
		String DEPTIDS = pd.getString("DEPTIDS");
		if(Tools.notEmpty(DEPTIDS)) {
			String DEPT_IDS[] = DEPTIDS.split(",");
			pd.put("DEPT_IDS", DEPT_IDS);
		}
		page.setPd(pd);
		List<PageData>	varList = eightworkvideomanagerService.list(page);	//列出eightworkvideomanager列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public Object deleteAll() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		String DATA_IDS = pd.getString("DATA_IDS");
		if(Tools.notEmpty(DATA_IDS)){
			String ArrayDATA_IDS[] = DATA_IDS.split(",");
			eightworkvideomanagerService.deleteAll(ArrayDATA_IDS);
			errInfo = "success";
		}else{
			errInfo = "error";
		}
		map.put("result", errInfo);				//返回结果
		return map;
	}

	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excel")
	@RequiresPermissions("toExcel")
	public ModelAndView exportExcel() throws Exception{
		ModelAndView mv = new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		Map<String,Object> dataMap = new HashMap<String,Object>();
		List<String> titles = new ArrayList<String>();
		titles.add("设备管线名");	//1
		titles.add("所属企业");	//2
		titles.add("申请部门");	//3
		titles.add("申请人");	//4
		titles.add("删除标志");	//5
		titles.add("创建时间");	//6
		titles.add("添加人");	//7
		titles.add("修改时间");	//8
		titles.add("修改人");	//9
		titles.add("编号");	//10
		titles.add("申请单位负责人签字");	//11
		titles.add("申请单位负责人签字时间");	//12
		titles.add("介质");	//13
		titles.add("温度");	//14
		titles.add("施工单位");	//15
		titles.add("施工单位人");	//16
		titles.add("施工单位签字");	//17
		titles.add("施工单位签字时间");	//18
		titles.add("生产部门");	//19
		titles.add("生产部门人");	//20
		titles.add("生产部门签字");	//21
		titles.add("生产部门签字时间");	//22
		titles.add("安全部门");	//23
		titles.add("安全部门人");	//24
		titles.add("安全部门签字");	//25
		titles.add("安全部门签字时间");	//26
		titles.add("领导人部门");	//27
		titles.add("领导人");	//28
		titles.add("领导人签字");	//29
		titles.add("领导人签字时间");	//30
		titles.add("验收部门");	//31
		titles.add("验收人");	//32
		titles.add("验收签字");	//33
		titles.add("验收签字时间");	//34
		titles.add("状态");	//35
		dataMap.put("titles", titles);
		List<PageData> varOList = eightworkvideomanagerService.listAll(pd);
		List<PageData> varList = new ArrayList<PageData>();
		for(int i=0;i<varOList.size();i++){
			PageData vpd = new PageData();
			vpd.put("var1", varOList.get(i).getString("NAME"));	    //1
			vpd.put("var2", varOList.get(i).getString("CORP_INFO"));	    //2
			vpd.put("var3", varOList.get(i).getString("APPLY_DEPARTMENT_ID"));	    //3
			vpd.put("var4", varOList.get(i).getString("APPLY_USER_ID"));	    //4
			vpd.put("var5", varOList.get(i).get("ISDELETE").toString());	//5
			vpd.put("var6", varOList.get(i).getString("CREATTIME"));	    //6
			vpd.put("var7", varOList.get(i).getString("CREATOR"));	    //7
			vpd.put("var8", varOList.get(i).getString("OPERATTIME"));	    //8
			vpd.put("var9", varOList.get(i).getString("OPERATOR"));	    //9
			vpd.put("var10", varOList.get(i).getString("CHECK_NO"));	    //10
			vpd.put("var11", varOList.get(i).getString("APPLY_USER_SIGNER_PATH"));	    //11
			vpd.put("var12", varOList.get(i).getString("APPLY_USER_SIGNER_TIME"));	    //12
			vpd.put("var13", varOList.get(i).getString("MEDIUM"));	    //13
			vpd.put("var14", varOList.get(i).getString("TEMPERATURE"));	    //14
			vpd.put("var15", varOList.get(i).getString("CONSTRUCTION_DEPARTMENT_ID"));	    //15
			vpd.put("var16", varOList.get(i).getString("CONSTRUCTION_USER_ID"));	    //16
			vpd.put("var17", varOList.get(i).getString("CONSTRUCTION_USER_SIGNER_PATH"));	    //17
			vpd.put("var18", varOList.get(i).getString("CONSTRUCTION_USER_SIGNER_TIME"));	    //18
			vpd.put("var19", varOList.get(i).getString("PRODUCTION_DEPARTMENT_ID"));	    //19
			vpd.put("var20", varOList.get(i).getString("PRODUCTION_USER_ID"));	    //20
			vpd.put("var21", varOList.get(i).getString("PRODUCTION_USER_SIGNER_PATH"));	    //21
			vpd.put("var22", varOList.get(i).getString("PRODUCTION_USER_SIGNER_TIME"));	    //22
			vpd.put("var23", varOList.get(i).getString("SAFETY_DEPARTMENT_ID"));	    //23
			vpd.put("var24", varOList.get(i).getString("SAFETY_USER_ID"));	    //24
			vpd.put("var25", varOList.get(i).getString("SAFETY_USER_SIGNER_PATH"));	    //25
			vpd.put("var26", varOList.get(i).getString("SAFETY_USER_SIGNER_TIME"));	    //26
			vpd.put("var27", varOList.get(i).getString("LEADER_DEPARTMENT_ID"));	    //27
			vpd.put("var28", varOList.get(i).getString("LEADER_USER_ID"));	    //28
			vpd.put("var29", varOList.get(i).getString("LEADER_USER_SIGNER_PATH"));	    //29
			vpd.put("var30", varOList.get(i).getString("LEADER_USER_SIGNER_TIME"));	    //30
			vpd.put("var31", varOList.get(i).getString("ACCEPT_DEPARTMENT_ID"));	    //31
			vpd.put("var32", varOList.get(i).getString("ACCEPT_USER_ID"));	    //32
			vpd.put("var33", varOList.get(i).getString("ACCEPT_USER_SIGNER_PATH"));	    //33
			vpd.put("var34", varOList.get(i).getString("ACCEPT_USER_SIGNER_TIME"));	    //34
			vpd.put("var35", varOList.get(i).getString("APPLY_STATUS"));	    //35
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}

}
