package com.zcloud.controller.corp;

import com.zcloud.controller.base.BaseController;
import com.zcloud.controller.risk.dto.RiskpointLogsDto;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.check.ListManagerService;
import com.zcloud.service.corp.CorpInfoService;
import com.zcloud.service.corp.CorpTypeService;
import com.zcloud.service.corp.CorpinfoRelatedService;
import com.zcloud.service.hidden.HiddenService;
import com.zcloud.service.hiddenDangerCheckStandard.CustomService;
import com.zcloud.service.risk.RiskPointService;
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.service.task.StudyTaskService;
import com.zcloud.util.*;
import org.apache.commons.io.FileUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.util.*;

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

	@Autowired
	private CorpInfoService corpinfoService;
	@Autowired
	private ImgFilesService imgfilesService;
	@Autowired
    private UsersService usersService;
	@Autowired
	private DictionariesService dictionariesService;
	@Autowired
	private DepartmentService departmentService;
    @Autowired
    private CorpinfoRelatedService corpinfoRelatedService;
    @Autowired
    private CorpTypeService corptypeService;
	@Autowired
	private RiskPointService riskPointService;
	@Autowired
	private ListManagerService listManagerService;
	@Autowired
	private CustomService customService;
	@Autowired
	private HiddenService hiddenService;
	@Autowired
	private StudyTaskService studyTaskService;
	@Autowired
	private Smb smb;

	@RequestMapping(value = "/listAll")
	@ResponseBody
	public Object listAll() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();

		List<PageData> varList = corpinfoService.listAll(pd);    //列出CorpInfo列表
		map.put("varList", varList);
		map.put("result", errInfo);
		return map;
	}


	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	// @RequiresPermissions("corpinfo:add")
	@ResponseBody
	@Transactional
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "新增")
	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("CORPINFO_ID", this.get32UUID());	//主键
		pd.put("ISDELETE", "0");	//是否删除
		pd.put("ISRECEIVE", "0");	//是否发送短信0不发1发
		pd.put("OPERATOR", Jurisdiction.getUsername());	//操作人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
		pd.put("CREATOR", Jurisdiction.getUsername());	//创建人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
		corpinfoService.save(pd);

		PageData dept = new PageData();
		dept.put("DEPARTMENT_ID", this.get32UUID());			//ID 主键
		dept.put("NAME", pd.get("CORP_NAME"));
		dept.put("PARENT_ID", 0);
		dept.put("TEL", pd.get("LR_MOBILE"));			//用户名
		dept.put("HEADMAN", pd.get("LR_NAME"));			//用户名
		dept.put("CORPINFO_ID", pd.get("CORPINFO_ID"));			//企业ID
		departmentService.save(dept);

		PageData user = new PageData();
		user.put("USER_ID", this.get32UUID());			//ID 主键
		user.put("USERNAME", pd.get("CORP_NAME"));			//用户名
		user.put("NAME", pd.get("LR_NAME"));			//用户名
		user.put("CORPINFO_ID", pd.get("CORPINFO_ID"));			//企业ID
		user.put("ROLE_ID", "42378ccf23e646ba8906130e82017a1e");			//角色 默认管理员
		user.put("LAST_LOGIN", "");						//最后登录时间
		user.put("DEPARTMENT_ID",dept.get("DEPARTMENT_ID"));//部门
		user.put("IP", "");								//IP
		user.put("STATUS", "0");							//状态
		user.put("SKIN", "pcoded-navbar navbar-image-3,navbar pcoded-header navbar-expand-lg navbar-light header-dark,");		//用户默认皮肤
		user.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("CORP_NAME"), "666666").toString());			//密码加密
		if(null == usersService.findByUsername(user)){	//判断用户名是否存在
			usersService.saveUser(user); 					//执行保存
//			System.out.println(user.getString("PASSWORD"));
		}else{
			throw new RuntimeException("用户已被注册!");//抛出异常 方便回滚
		}

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

	/**删除
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	// @RequiresPermissions("corpinfo:del")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "删除")
	public Object delete() throws Exception{
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		corpinfoService.delete(pd);
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit", headers = "content-type=multipart/form-data")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "修改")
	public Object edit(
			@RequestParam(value="imgFiles",required=false) MultipartFile[] imgFiles,
			@RequestParam(value="fourFiles",required=false) MultipartFile[] fourFiles) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("OPERATOR", Jurisdiction.getUsername());	//操作人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
        if(!Tools.isEmpty(pd.get("CORP_OF_TYPEAll"))){
            PageData corptypePd = new PageData();
            corptypePd.put("CORPTYPE_ID",pd.get("CORP_OF_TYPEAll"));
            PageData corptype = corptypeService.findById(corptypePd);
            if(null != corptype){
                if("0".equals(corptype.get("PARENT_ID").toString())){
                    pd.put("CORP_OF_TYPE",corptype.get("CORPTYPE_ID"));
                }else{
                    pd.put("CORP_OF_TYPE",corptype.get("PARENT_ID"));
                    pd.put("CORP_OF_TYPE2",corptype.get("CORPTYPE_ID"));
                }
            }
        }
		corpinfoService.edit(pd);
		PageData img = new PageData();
		img.put("FOREIGN_KEY", pd.get("CORPINFO_ID"));
		img.put("EDITFOURTYPE", pd.get("EDITFOURTYPE"));

		if(imgFiles != null && imgFiles.length > 0 ) {
			img.put("TYPE", "1");
			editCorpImg(imgFiles,img);
		}
		if("1".equals(pd.get("FOURTYPE").toString())) {
			img.put("TYPE", "2");
			editCorpImg(fourFiles,img);
		}
        corpinfoRelatedService.edit(pd);
        SecurityUtils.getSubject().getSession().setAttribute(Const.CORP_TRAINTYPE,
				Tools.isEmpty(pd.getString("TRAINTYPE")) ? "" : pd.getString("TRAINTYPE"));
		map.put("pd",pd);
		map.put("result", errInfo);
//		PageData dept = new PageData();
//		dept.put("NAME", pd.get("CORP_NAME"));
//		dept.put("OLDNAME", pd.get("OLD_CORP_NAME"));
//		dept.put("PARENT_ID", '0');
//		dept.put("CORPINFO_ID", pd.get("CORPINFO_ID"));			//企业ID
//		departmentService.editCornDept(dept);
//		PageData user = new PageData();
//		user.put("OLDUSERNAME", pd.get("OLD_CORP_NAME"));			//用户名
//		user.put("USERNAME", pd.get("CORP_NAME"));			//用户名
//		user.put("NAME", pd.get("CORP_NAME"));			//用户名
//		user.put("CORPINFO_ID", pd.get("CORPINFO_ID"));			//企业ID
//		user.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("CORP_NAME"), "666666").toString());			//密码加密
//		usersService.updateCornUser(user);
		return map;
	}
	@RequestMapping(value="/editIsReceive")
	@ResponseBody
	public Object editIsReceive() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd=corpinfoService.findById(pd);
		if(pd.get("ISRECEIVE").toString().equals("1")) {
			pd.put("ISRECEIVE", "0");
		}else {
			pd.put("ISRECEIVE", "1");
		}
		corpinfoService.editIsReceive(pd);
		map.put("pd",pd);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	// @RequiresPermissions("corpinfo: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());
		page.setPd(pd);
		List<PageData>	varList = corpinfoService.list(page); //列出CorpInfo列表
		map.put("varList", varList);
		map.put("page", page);
		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();
		if(pd.get("CORPINFO_ID")==null || Tools.isEmpty(pd.get("CORPINFO_ID").toString())) {
			pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
		}
		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());
		}
		if(POSSESSIONALL != null && POSSESSIONALL.size() > 0) {
			pd.put("posOption", initDicTreeByNum(POSSESSIONALL.get(POSSESSIONALL.size()-1)));
		}

		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());
		}
		if(ECO_TYPEALL != null && ECO_TYPEALL.size() > 0) {
			pd.put("ecoOption", initDicTree(ECO_TYPEALL.get(ECO_TYPEALL.size()-1)));
		}
		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(CORP_TYPEALL != null && CORP_TYPEALL.size() > 0) {
			pd.put("industryOption", initDicTree(CORP_TYPEALL.get(CORP_TYPEALL.size()-1)));
		}
		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);
			if (corpOfType != null) {
				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);
			if (corpOfType2 != null) {
				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;
	}

	@RequestMapping(value="/goLogin")
	@ResponseBody
	public Object goLogin() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		if(pd.get("CORPINFO_ID")==null || Tools.isEmpty(pd.get("CORPINFO_ID").toString())) {
			pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
		}
		pd = corpinfoService.findById(pd);	//根据ID读取
		PageData users = new PageData();
		users.put("USERNAME", pd.getString("CORP_NAME"));
		 users = usersService.findByUsername(users);
		map.put("pd", pd);
		map.put("users", users);
		map.put("result", errInfo);
		return map;
	}

	/**判断企业是否存在
	 * @return
	 */
	@RequestMapping(value="/hasCorp")
	@ResponseBody
	public Object hasUser() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = corpinfoService.findByName(pd);
		if(pd != null){
			map.put("pd",pd);
			errInfo = "error";
		}
		map.put("result", errInfo);				//返回结果
		return map;
	}
	/**
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/resetPwd")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "用户管理",instructionsType = "重置密码")
	public Object resetPwd (Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData pageData = usersService.findById(pd);
		//corpInfo
		String pwd = new SimpleHash("SHA-1", pageData.getString("USERNAME"), "666666").toString();
		PageData updateUser = new PageData();
		updateUser.put("PASSWORD", pwd);
		updateUser.put("USER_ID", pageData.getString("USER_ID"));
		usersService.editPassword(updateUser);

		map.put("result", errInfo);
		return map;
	}
	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	// @RequiresPermissions("corpinfo:del")
	@ResponseBody
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "批量删除")
	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(",");
			corpinfoService.deleteAll(ArrayDATA_IDS);
			errInfo = "success";
		}else{
			errInfo = "error";
		}
		map.put("result", errInfo);				//返回结果
		return map;
	}

	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excel")
	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "企业信息",instructionsType = "导出到excel")
	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
		dataMap.put("titles", titles);
		List<PageData> varOList = corpinfoService.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("CORP_NAME"));	    //1
			vpd.put("var2", varOList.get(i).getString("CODE"));	    //2
			vpd.put("var3", varOList.get(i).getString("COMPANY_AREA"));	    //3
			vpd.put("var4", varOList.get(i).getString("ADDRESS"));	    //4
			vpd.put("var5", varOList.get(i).getString("CREATE_DATE"));	    //5
			vpd.put("var6", varOList.get(i).getString("SCALE"));	    //6
			vpd.put("var7", varOList.get(i).get("LONGITUDE").toString());	//7
			vpd.put("var8", varOList.get(i).get("LATITUDE").toString());	//8
			vpd.put("var9", varOList.get(i).getString("POSTAL_CODE"));	    //9
			vpd.put("var10", varOList.get(i).get("EMPLOYEES").toString());	//10
			vpd.put("var11", varOList.get(i).get("AREA_COVERED").toString());	//11
			vpd.put("var12", varOList.get(i).get("TOTALASSETS").toString());	//12
			vpd.put("var13", varOList.get(i).get("REGCAPITAL").toString());	//13
			vpd.put("var14", varOList.get(i).get("SALESREVENUE").toString());	//14
			vpd.put("var15", varOList.get(i).get("ANNUALPROFIT").toString());	//15
			vpd.put("var16", varOList.get(i).getString("ECO_TYPE"));	    //16
			vpd.put("var17", varOList.get(i).getString("INDUSTRY"));	    //17
			vpd.put("var18", varOList.get(i).getString("CORP_TYPE"));	    //18
			vpd.put("var19", varOList.get(i).getString("CORP_TYPE_SMALL"));	    //19
			vpd.put("var20", varOList.get(i).getString("LR_NAME"));	    //20
			vpd.put("var21", varOList.get(i).getString("LR_POSITION"));	    //21
			vpd.put("var22", varOList.get(i).getString("LR_PHONE"));	    //22
			vpd.put("var23", varOList.get(i).getString("LR_MOBILE"));	    //23
			vpd.put("var24", varOList.get(i).getString("CONTACTS"));	    //24
			vpd.put("var25", varOList.get(i).getString("CONTACTS_PHONE"));	    //25
			vpd.put("var26", varOList.get(i).getString("CHECKPERSON"));	    //26
			vpd.put("var27", varOList.get(i).getString("CHECKPERSONPHONE"));	    //27
			vpd.put("var28", varOList.get(i).get("ISDELETE").toString());	//28
			vpd.put("var29", varOList.get(i).getString("OPERATOR"));	    //29
			vpd.put("var30", varOList.get(i).getString("OPERATTIME"));	    //30
			vpd.put("var31", varOList.get(i).getString("CREATTIME"));	    //31
			vpd.put("var32", varOList.get(i).getString("CREATOR"));	    //32
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}
	/** 根据所属行业，专业，小专业列表 获取数据
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/listByCorpType")
	// @RequiresPermissions("corpinfo:list")
	@ResponseBody
	public Object listByCorpType(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());
		List<PageData>	varList = corpinfoService.listByCorpType(pd);	//列出CorpInfo列表
		map.put("varList", varList);
		map.put("result", errInfo);
		return map;
	}


	/**
	 * 初始化数据字典懒加载下拉树（根据id）
	 * @param dictionaries_id
	 * @return
	 * @throws Exception
	 */
	public List<PageData> initDicTree(String dictionaries_id) throws Exception{
		PageData dic = new PageData();
		dic.put("DICTIONARIES_ID", dictionaries_id);
		dic = dictionariesService.findById(dic);
		dic.put("value", dic.get("DICTIONARIES_ID"));
		dic.put("id", dic.get("DICTIONARIES_ID"));
		dic.put("label", dic.get("NAME"));
		List<PageData> industryOption = dictionariesService.getTreeFromBelow(new ArrayList<PageData>(),dic);
		return industryOption;
	}
	/**
	 * 初始化数据字典懒加载下拉树（根据编码）
	 * @param dictionaries_id
	 * @return
	 * @throws Exception
	 */
	public List<PageData> initDicTreeByNum(String dictionaries_bianma) throws Exception{
		PageData dic = new PageData();
		dic.put("BIANMA", dictionaries_bianma);
		dic = dictionariesService.findByBianma(dic);
		dic.put("value", dic.get("DICTIONARIES_ID"));
		dic.put("numValue", dic.get("BIANMA"));
		dic.put("id", dic.get("DICTIONARIES_ID"));
		dic.put("label", dic.get("NAME"));
		List<PageData> industryOption = dictionariesService.getTreeFromBelow(new ArrayList<PageData>(),dic);
		return industryOption;
	}

	public boolean editCorpImg(MultipartFile[] files,PageData pd) throws Exception {
		String TYPE = pd.getString("TYPE");
		String FOREIGN_KEY = pd.getString("FOREIGN_KEY");
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		if(TYPE.equals("2") && pd.get("EDITFOURTYPE") != null
				&& Tools.notEmpty(pd.get("EDITFOURTYPE").toString()) && pd.get("EDITFOURTYPE").toString().equals("false")) {//先删除原四色图(json)
		}
		if (files != null && files.length > 0) {
			for (int i = 0; i < files.length; i++) {
				MultipartFile file = files[i];
//                 保存文件
				File tempFile = new File(file.getOriginalFilename());
				FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
				if(!FileUpload.isImage(tempFile) && !TYPE.equals("2")) {//四色图改为json文件,不用判断类型
					map.put("result", "failed");
					map.put("exception", "上传图片格式不正确，请重新上传");
					return false;
				}
				tempFile.delete();

				String  ffile = DateUtil.getDays();
				String fileName = "";				//执0行上传

				if (null != file && !file.isEmpty()) {
//        			String filePath = PathUtil.getProjectpath() +"/"+ Const.FILEPATHYHTP + ffile;	//文件上传路径
					//fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
					fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
					byte[] bytes = file.getBytes();
					smb.sshSftp(file, fileName,Const.FILEPATHYHTP + ffile);
				}
				pd.put("IMGFILES_ID",  this.get32UUID());
				pd.put("FILEPATH", Const.FILEPATHYHTP + ffile+"/"+fileName);
				imgfilesService.save(pd);
			}
		}

		map.put("result", errInfo);
		return true;
	}
		/**
	 * 初始化数据字典懒加载下拉树（根据id）
	 * @param dictionaries_id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/getsesTrainType")
	@ResponseBody
	@LogAnno(menuType= "教育培训",menuServer= "教育培训",instructionsOperate = "教育培训",instructionsType = "根据id初始化数据字典懒加载下拉树")
	public Object getsesTrainType() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		map.put("TRAINTYPE", Jurisdiction.getCORPTRAINTYPE());//企业的培训行业类型
		map.put("result", errInfo);
		return map;
	}

	/**根据企业ID获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/getDiagnosis")
	@ResponseBody
	@LogAnno(menuType= "双重预控",menuServer= "持续改进",instructionsOperate = "企业报告",instructionsType = "公司详情")

	public Object getDiagnosis() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("CORPINFO_ID",Jurisdiction.getCORPINFO_ID());
		PageData cpd = corpinfoService.findById(pd);	//根据ID读取
		pd.put("CORPCREATTIME",cpd.getString("CREATTIME").substring(0,7));
		PageData riskpd = riskPointService.getDiagnosis(pd);
		List<PageData> lists = listManagerService.listAllForDiagnosis(pd);
		List<PageData> thismonth = listManagerService.thisMonthListmanager(pd);
		List<PageData> lists2 = customService.listAllForDiagnosis(pd);
		List<PageData> thismonth2 = customService.thisMonthListmanager(pd);
		List<PageData> hdlist = hiddenService.listAllForDiagnosis(pd);
		PageData studypd = studyTaskService.getDiagnosis(pd);
		List<RiskpointLogsDto> riskLog = riskPointService.getLogDiagnosis(pd);
		lists.addAll(lists2);
		thismonth.addAll(thismonth2);
		map.put("cpd", cpd);
		map.put("monthlist",thismonth);
		map.put("riskpd", riskpd);
		map.put("lists", lists);
		map.put("hdlist", hdlist);
		map.put("studypd", studypd);
		map.put("riskLog",riskLog);
		if(pd!=null) {
			errInfo = "success";
		}else {
			errInfo = "faild";
		}
		map.put("result", errInfo);
		return map;
	}
}
