package com.zcloud.controller.risk;

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.risk.IdentificationPartsService;
import com.zcloud.service.risk.RiskPointService;
import com.zcloud.service.risk.RiskUnitService;
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;

/**
 * 说明：手机端风险点台账
 * 作者：郭跃鹏
 * 时间：2021年1月8日
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/riskpoint")
public class AppRiskPointController extends BaseController {
	@Autowired
	private RiskPointService riskpointService;
	@Autowired
	private IdentificationPartsService identificationpartsService;
	@Autowired
	private RiskUnitService riskunitService;
	/**列表
	 * @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 pdNameLiskes = pd.getString("pdNameLiskes");						//关键词检索条件
		if(Tools.notEmpty(pdNameLiskes)) {
			pd.put("NameLiskes",pdNameLiskes);
		}
		pd.put("CORPINFO_ID",pd.getString("CORPINFOID"));
		page.setPd(pd);
		List<PageData>	varList = identificationpartsService.list(page);	//列出RiskPoint列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}
	 /** 详情获取数据
		 * @param
		 * @throws Exception
		 */
	@RequestMapping(value="/getPdForId")
	@ResponseBody
	@LogAnno(menuType= "手机",menuServer= "风险管控",instructionsOperate = "风险管控台账",instructionsType = "详情获取数据")
		public Object getPdForId() throws Exception{
			Map<String,Object> map = new HashMap<String,Object>();
			String errInfo = "success";
			//根基ID获取数据
			PageData pd = new PageData();
			pd = this.getPageData();
			pd = riskpointService.findById(pd);	//根据ID读取
			map.put("pd", pd);
			map.put("result", errInfo);
			return map;
		}

		/**修改
		 * @param
		 * @throws Exception
		 */
		@RequestMapping(value="/editLonAndLat")
		@ResponseBody
		@LogAnno(menuType= "手机",menuServer= "风险管控",instructionsOperate = "风险管控台账",instructionsType = "修改")
		public Object edit() throws Exception{
			Map<String,Object> map = new HashMap<String,Object>();
			String errInfo = "success";
			PageData pd = new PageData();
			pd = this.getPageData();
			PageData id = identificationpartsService.findById(pd);
			id.put("LONGITUDE", pd.get("LONGITUDE"));
			id.put("LATITUDE", pd.get("LATITUDE"));
			identificationpartsService.edit(id);
			map.put("result", errInfo);
			return map;
		}

		/**获取风险单元下拉框选项
		 * @param page
		 * @throws Exception
		 */
		@RequestMapping(value="/listUnit")
		@ResponseBody
		@LogAnno(menuType= "手机",menuServer= "风险管控",instructionsOperate = "风险管控台账",instructionsType = "获取风险单元下拉框选项")
		public Object getPointSelect() throws Exception{
			Map<String,Object> map = new HashMap<String,Object>();
			String errInfo = "success";
			PageData pd = new PageData();
			pd = this.getPageData();

			List<PageData> unitList = riskunitService.listAll(pd);
			map.put("unitList", unitList);
			map.put("result", errInfo);
			return map;
		}

		/**根据部位获取所有风险点
		 * @param page
		 * @throws Exception
		 */
		@RequestMapping(value="/getForIdentification")
		@ResponseBody
		@LogAnno(menuType= "手机",menuServer= "风险管控",instructionsOperate = "风险管控台账",instructionsType = "根据部位获取所有风险点")
		public Object getForIdentification() throws Exception{
			Map<String,Object> map = new HashMap<String,Object>();
			String errInfo = "success";
			PageData pd = new PageData();
			pd = this.getPageData();

			List<PageData> varList = riskpointService.listAll(pd);
			map.put("varList", varList);
			map.put("result", errInfo);
			return map;
		}
}
