package com.zcloud.controller.alarm;

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.alarm.DBAlarmService;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：报警管理
 * 作者：shaojie
 * 时间：2022-05-28
 * 官网：www.qdkjchina.com
 */
@Controller
@RequestMapping("/dbalarm")
public class DBAlarmController extends BaseController {

	@Autowired
	private DBAlarmService dbalarmService;

	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	// @RequiresPermissions("dbalarm: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("DBALARM_ID", this.get32UUID());	//主键
		dbalarmService.save(pd);
		map.put("result", errInfo);
		return map;
	}

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

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	// @RequiresPermissions("dbalarm: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();
		dbalarmService.edit(pd);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	// @RequiresPermissions("dbalarm: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());
		page.setPd(pd);
		List<PageData>	varList = dbalarmService.list(page);	//列出DBAlarm列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	 /**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	// @RequiresPermissions("dbalarm:edit")
	@ResponseBody
	@LogAnno(menuType= "监测预警",menuServer= "在线监测",instructionsOperate = "智能预警",instructionsType = "去修改页面获取数据")
	public Object goEdit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = dbalarmService.findById(pd);	//根据ID读取
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	// @RequiresPermissions("dbalarm:del")
	@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(",");
			dbalarmService.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("AlarmID");	//1
		titles.add("ScannerAlarmID");	//2
		titles.add("IntellexAlarmID");	//3
		titles.add("分析设备编号");	//4
		titles.add("分析通道号");	//5
		titles.add("分析设备IP");	//6
		titles.add("VideoSourceSystemID");	//7
		titles.add("VideoSourceChannelID");	//8
		titles.add("报警类型");	//9
		titles.add("服务端收到开始报警的时间");	//10
		titles.add("服务端收到开始报警的时间");	//11
		titles.add("服务端收到结束报警的时间");	//12
		titles.add("VideoSourceAlarmStartTime");	//13
		titles.add("VideoSourceAlarmTime");	//14
		titles.add("VideoSourceAlarmEndTime");	//15
		titles.add("报警视频路径");	//16
		titles.add("Thumbnail");	//17
		titles.add("ThumbnailRows");	//18
		titles.add("ThumbnailCols");	//19
		titles.add("ThumbnailSize");	//20
		titles.add("报警图片路径");	//21
		titles.add("分析设备名称");	//22
		titles.add("spareInt1");	//23
		titles.add("spareInt2");	//24
		titles.add("状态");	//25
		titles.add("设备类型");	//26
		titles.add("spareStr32_2");	//27
		titles.add("unicode编码的摄像机名称");	//28
		titles.add("spareStr64_2");	//29
		titles.add("转码后的报警名称 ");	//30
		titles.add("AlarmLevelID");	//31
		titles.add("UserID");	//32
		titles.add("ackTime");	//33
		titles.add("报警中文名称 ，根据此字段区分告警类型");	//34
		titles.add("预置位编号");	//35
		titles.add("SpeciesID");	//36
		titles.add("DVUID");	//37
		titles.add("相机编号");	//38
		dataMap.put("titles", titles);
		List<PageData> varOList = dbalarmService.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("ALARMID"));	    //1
			vpd.put("var2", varOList.get(i).getString("SCANNERALARMID"));	    //2
			vpd.put("var3", varOList.get(i).getString("INTELLEXALARMID"));	    //3
			vpd.put("var4", varOList.get(i).getString("SCANNERCUSTOMERNUMBER"));	    //4
			vpd.put("var5", varOList.get(i).getString("SCANNERFEEDNUMBER"));	    //5
			vpd.put("var6", varOList.get(i).getString("SCANNERIP"));	    //6
			vpd.put("var7", varOList.get(i).getString("VIDEOSOURCESYSTEMID"));	    //7
			vpd.put("var8", varOList.get(i).getString("VIDEOSOURCECHANNELID"));	    //8
			vpd.put("var9", varOList.get(i).getString("ALARMTYPE"));	    //9
			vpd.put("var10", varOList.get(i).getString("MANAGERSTARTTIME"));	    //10
			vpd.put("var11", varOList.get(i).getString("MANAGERALARMTIME"));	    //11
			vpd.put("var12", varOList.get(i).getString("MANAGERENDTIME"));	    //12
			vpd.put("var13", varOList.get(i).getString("VIDEOSOURCEALARMSTARTTIME"));	    //13
			vpd.put("var14", varOList.get(i).getString("VIDEOSOURCEALARMTIME"));	    //14
			vpd.put("var15", varOList.get(i).getString("VIDEOSOURCEALARMENDTIME"));	    //15
			vpd.put("var16", varOList.get(i).getString("JPBPATH"));	    //16
			vpd.put("var17", varOList.get(i).getString("THUMBNAIL"));	    //17
			vpd.put("var18", varOList.get(i).getString("THUMBNAILROWS"));	    //18
			vpd.put("var19", varOList.get(i).getString("THUMBNAILCOLS"));	    //19
			vpd.put("var20", varOList.get(i).getString("THUMBNAILSIZE"));	    //20
			vpd.put("var21", varOList.get(i).getString("THUMBNAILPATH"));	    //21
			vpd.put("var22", varOList.get(i).getString("SCANNERNAME"));	    //22
			vpd.put("var23", varOList.get(i).getString("SPAREINT1"));	    //23
			vpd.put("var24", varOList.get(i).getString("SPAREINT2"));	    //24
			vpd.put("var25", varOList.get(i).getString("SPAREINT3"));	    //25
			vpd.put("var26", varOList.get(i).getString("SPARESTR32_1"));	    //26
			vpd.put("var27", varOList.get(i).getString("SPARESTR32_2"));	    //27
			vpd.put("var28", varOList.get(i).getString("SPARESTR64_1"));	    //28
			vpd.put("var29", varOList.get(i).getString("SPARESTR64_2"));	    //29
			vpd.put("var30", varOList.get(i).getString("RULENAME"));	    //30
			vpd.put("var31", varOList.get(i).getString("ALARMLEVELID"));	    //31
			vpd.put("var32", varOList.get(i).getString("USERID"));	    //32
			vpd.put("var33", varOList.get(i).getString("ACKTIME"));	    //33
			vpd.put("var34", varOList.get(i).getString("RULENAMESTR"));	    //34
			vpd.put("var35", varOList.get(i).getString("PTZNUMBER"));	    //35
			vpd.put("var36", varOList.get(i).getString("SPECIESID"));	    //36
			vpd.put("var37", varOList.get(i).getString("DVUID"));	    //37
			vpd.put("var38", varOList.get(i).getString("DEVICEID"));	    //38
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}

}
