package com.zcloud.controller.hiddenDangerCheckStandard;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.corp.CorpInfoService;
import com.zcloud.service.hiddenDangerCheckStandard.CommonService;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.Tools;
import com.zcloud.util.Warden;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：清单管理-隐患排查清单
 * 作者：luoxiaobao
 * 时间：2020-12-30
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/hiddenstandardCommon")
public class CommonController extends BaseController {

	@Autowired
	private CommonService commonService;
	@Autowired
	private CorpInfoService corpinfoService;

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	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());	//企业
		PageData corpinfo = corpinfoService.findById(pd);	//根据ID读取
		pd.put("CORP_TYPE", corpinfo.getString("CORP_TYPE"));
		pd.put("CORP_TYPE2", corpinfo.getString("CORP_TYPE2"));
		pd.put("CORP_TYPE3", corpinfo.getString("CORP_TYPE3"));
		pd.put("CORP_TYPE4", corpinfo.getString("CORP_TYPE4"));
		page.setPd(pd);
		List<PageData>	varList = commonService.list(page);	//列出RiskCheckItem列表
		map.put("varList", varList);
		map.put("page", page);
		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();
		Warden.updateDate(pd);
		commonService.edit(pd);
		map.put("result", errInfo);
		return map;
	}
}
