package com.zcloud.controller.corp;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.PageData;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.corp.CorpInfoService;
import com.zcloud.service.corp.CorpTypeService;
import com.zcloud.service.sms.SMSManagementService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.service.system.UsersService;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：企业管理
 * 作者：luoxiaobao
 * 时间：2020-12-24
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/corpinfo")
public class AppCorpInfoController extends BaseController {

	@Autowired
	private CorpInfoService corpinfoService;
	@Autowired
    private UsersService usersService;
	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private DictionariesService dictionariesService;
	@Autowired
	private SMSManagementService smsmanagementService;
	@Autowired
	private CorpTypeService corptypeService;
	@Autowired
	private ImgFilesService imgfilesService;

//	@Value("${kfq.http}")
//	private String kfq_http;
/*初始化短信管理
	@RequestMapping(value="/goc")
	@ResponseBody
	public Object goc() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();

		List<PageData> cpd=corpinfoService.listAll(pd);


		List<Dictionaries> aDictionaries = dictionariesService.listAllDict("514042127588463bba0bec45e982d42f");
		for(PageData c:cpd) {
			for(Dictionaries d:aDictionaries) {
			PageData spd = new PageData();
			spd.put("SMSMANAGEMENT_ID", this.get32UUID());	//主键
			spd.put("SMSNAME", d.getNAME());	//操作人
			spd.put("SMSCODE", d.getBIANMA());	//操作人
			spd.put("SMSTYPE", d.getDICTIONARIES_ID());	//操作人
			spd.put("ISENABLE", "1");	//操作人
			spd.put("CORPINFO_ID", c.getString("CORPINFO_ID"));	//操作人
			spd.put("OPDATE", DateUtil.date2Str(new Date()));	//操作日期
			spd.put("OPUSER", "admin");	//操作人
			spd.put("ISDELETE", "0");	//是否删除
			spd.put("OPERATOR", "admin");	//修改人
			spd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改日期
			smsmanagementService.save(spd);
			}
		}



		map.put("result", errInfo);
		return map;
	}*/



	@RequestMapping(value="/goqyzzh")
	@ResponseBody
	@LogAnno(menuType= "手机",menuServer= "隐患治理",instructionsOperate = "隐患整改",instructionsType = "获取企业信息")
	public Object goqyzzh() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("ISMAIN", "1");
		List<PageData>	userList = usersService.listAllUser(pd);
		pd.put("PARENT_ID", "0");
		List<PageData>	depList =departmentService.listAll(pd);
		map.put("userpd", userList.get(0));
		map.put("deppd", depList.get(0));
		map.put("result", errInfo);
		return map;
	}



	/**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	@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 = corpinfoService.findById(pd);	//根据ID读取

		PageData pd2 = new PageData();
		pd2.put("FOREIGN_KEY", pd.getString("CORPINFO_ID"));
		pd2.put("TYPE",1);
		List<PageData> busImgs = imgfilesService.listAll(pd2);//营业执照图片

		pd2.put("TYPE",2);
		List<PageData> fourImgs = imgfilesService.listAll(pd2);//四色图照图片

		List<String> POSSESSIONALL = new ArrayList<String>();
		if(pd.get("PROVINCE") != null && Tools.notEmpty(pd.get("PROVINCE").toString())) {
			POSSESSIONALL.add(pd.get("PROVINCE").toString());
		}
		if(pd.get("CITY") != null && Tools.notEmpty(pd.get("CITY").toString())) {
			POSSESSIONALL.add(pd.get("CITY").toString());
		}
		if(pd.get("COUNTY") != null && Tools.notEmpty(pd.get("COUNTY").toString())) {
			POSSESSIONALL.add(pd.get("COUNTY").toString());
		}
		if(pd.get("VILLAGE") != null && Tools.notEmpty(pd.get("VILLAGE").toString())) {
			POSSESSIONALL.add(pd.get("VILLAGE").toString());
		}
		if(pd.get("STREET") != null && Tools.notEmpty(pd.get("STREET").toString())) {
			POSSESSIONALL.add(pd.get("STREET").toString());
		}

		List<String> ECO_TYPEALL = new ArrayList<String>();
		if(pd.get("ECO_TYPE") != null && Tools.notEmpty(pd.get("ECO_TYPE").toString())) {
			ECO_TYPEALL.add(pd.get("ECO_TYPE").toString());
		}
		if(pd.get("ECO_TYPE2") != null && Tools.notEmpty(pd.get("ECO_TYPE2").toString())) {
			ECO_TYPEALL.add(pd.get("ECO_TYPE2").toString());
		}
		List<String> CORP_TYPEALL = new ArrayList<String>();
		if(pd.get("CORP_TYPE") != null && Tools.notEmpty(pd.get("CORP_TYPE").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE").toString());
		}
		if(pd.get("CORP_TYPE2") != null && Tools.notEmpty(pd.get("CORP_TYPE2").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE2").toString());
		}
		if(pd.get("CORP_TYPE3") != null && Tools.notEmpty(pd.get("CORP_TYPE3").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE3").toString());
		}
		if(pd.get("CORP_TYPE4") != null && Tools.notEmpty(pd.get("CORP_TYPE4").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE4").toString());
		}
		if (Tools.notEmpty(pd.getString("CORP_OF_TYPE"))) {
			PageData corpOfType = new PageData();
			corpOfType.put("CORPTYPE_ID", pd.get("CORP_OF_TYPE"));
			corpOfType = corptypeService.findById(corpOfType);
			pd.put("CORP_OF_TYPE_NAME", corpOfType.get("NAME"));

		}
		if (Tools.notEmpty(pd.getString("CORP_OF_TYPE2"))) {
			PageData corpOfType2 = new PageData();
			corpOfType2.put("CORPTYPE_ID", pd.get("CORP_OF_TYPE2"));
			corpOfType2 = corptypeService.findById(corpOfType2);
			pd.put("CORP_OF_TYPE_NAME2", corpOfType2.get("NAME"));
		}

		pd.put("POSSESSION", POSSESSIONALL);
		pd.put("ECO_TYPEALL", ECO_TYPEALL);
		pd.put("INDUSTRYALL", CORP_TYPEALL);
		map.put("pd", pd);
		map.put("busImgs", busImgs);
		map.put("fourImgs", fourImgs);
		map.put("result", errInfo);
		return map;
	}


//	/**获取连级数据
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/getKfqDictData")
//	@ResponseBody
////	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "获取连级数据 ")
//	public Object getKfqDictData() throws Exception{
//		Map<String,Object> map = new HashMap<String,Object>();
//		String errInfo = "success";
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		Map<String,Object> resultMap = new HashMap<String,Object>();
//		resultMap = HttpClientUtil.doPost(kfq_http + "/app/corpinfo/getLevelsAndSCount",pd);
//		List<Map<Object, Object>> list = (List<Map<Object, Object>>) resultMap.get("list");
//		map.put("list", list);
//		map.put("result", errInfo);
//		return map;
//	}
}
