package com.zcloud.controller.keyProjects.app;

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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.service.keyProjects.*;
import com.zcloud.service.relatedparty.OutSourcedService;
import com.zcloud.service.specialoperation.PersonnelManagementService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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 com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import org.springframework.web.multipart.MultipartFile;

/**
 * 说明：重点工程检查
 * 作者：luoxiaobao
 * 时间：2022-09-19
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/keyprojectcheck")
public class AppKeyprojectCheckController extends BaseController {

	@Autowired
	private KeyprojectCheckService keyprojectcheckService;
	@Autowired
	private KeyprojectCheckInfoService keyprojectcheckInfoService;
	@Autowired
	private KeyprojectHiddenService keyprojectHiddenService;
	@Autowired
	private ImgFilesService imgFilesService;
	@Autowired
	private KeyprojectPunishService keyprojectPunishService;

	@Autowired
	private OutSourcedService outsourcedService;

	@Autowired
	private PersonnelManagementService personnelmanagementService;

	@Autowired
	private UsersService usersService;

	@Autowired
	private KeyprojectPunishService keyprojectpunishService;

	@Autowired Smb smb;

	@Autowired
	private SendMessageUtil sendMessageUtil;


	/**
	 * 新增
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Object add() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = this.getPageData();
		pd.put("KEYPROJECTCHECK_ID", this.get32UUID());    //主键
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //添加时间
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
		pd.put("ISDELETE", 0);    //是否删除
		pd.put("SOURCE", 1);    //企业ID
		pd.put("CORPINFO_ID", 1);    //检查人的企业id 监管端的企业id就是1
		keyprojectcheckService.save(pd);

		String currentTime = DateUtil.date2Str(new Date());
		List<PageData> SITUATIONJSONDATA = new ArrayList<>(); //发送其他项目用
		if (Tools.notEmpty(pd.getString("SITUATIONJSON"))) {
			List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.getString("SITUATIONJSON"));
			String time = currentTime;
			for (JSONObject json : list) {
				PageData situationPd = new PageData();
				situationPd.put("KEYPROJECTCHECKINFO_ID", UuidUtil.get32UUID());    //主键
				situationPd.put("KEYPROJECTCHECK_ID", pd.getString("KEYPROJECTCHECK_ID"));    //检查ID
				situationPd.put("SITUATION", json.get("SITUATION"));    //检查情况
				situationPd.put("ISDELETE", "0");    //是否删除(0:有效 1：删除)
				situationPd.put("CREATOR", pd.getString("CREATOR"));    //添加人
				situationPd.put("CREATTIME", time);    //添加时间
				situationPd.put("OPERATOR", pd.getString("OPERATOR"));    //修改人
				situationPd.put("OPERATTIME", time);    //修改时间
				keyprojectcheckInfoService.save(situationPd);
				SITUATIONJSONDATA.add(situationPd);
				time = DateUtil.calculateDateSecond(time, 1);
			}
		}
		Boolean boo = false; // 增加开关控制
		List<PageData> HIDDENJSONDATA = new ArrayList<>(); //发送其他项目用
		if (Tools.notEmpty(pd.getString("HIDDENJSON"))) {
			boo = true;
			List<PageData> hiddenList = new ArrayList<PageData>();
			List<JSONObject> list = (List<JSONObject>) JSON.parse(pd.getString("HIDDENJSON"));
			String time = currentTime;
			for (JSONObject json : list) {
				PageData hidden = new PageData();
				hidden.put("HIDDEN_ID", UuidUtil.get32UUID());    //主键
				hidden.put("FOREIGN_ID", pd.getString("KEYPROJECTCHECK_ID"));    //外键ID
				hidden.put("HIDDENDESCR", json.getString("HIDDENDESCR"));    //隐患描述
				hidden.put("HIDDENPART", json.getString("HIDDENPART"));    //隐患部位
				hidden.put("HIDDENLEVEL", json.getString("HIDDENLEVEL"));    //隐患级别
				hidden.put("HIDDENTYPE", json.getString("HIDDENTYPE"));    //隐患类型1
				hidden.put("HIDDENTYPE2", json.getString("HIDDENTYPE2"));    //隐患类型2
				hidden.put("LONGITUDE", json.getString("LONGITUDE"));    //隐患位置经度
				hidden.put("LATITUDE", json.getString("LATITUDE"));    //隐患位置纬度
				hidden.put("DISCOVERYTIME", json.getString("DISCOVERYTIME"));    //隐患发现时间
				hidden.put("HIDDENFINDDEPT", json.getString("HIDDENFINDDEPT"));    //隐患发现部门（隐患责任人部门）
				hidden.put("RECTIFICATIONTYPE", json.getString("RECTIFICATIONTYPE"));    //隐患处置
				hidden.put("RECTIFICATIONDEADLINE", json.getString("RECTIFICATIONDEADLINE"));    //整改期限
				hidden.put("RECTIFYDESCR", json.getString("RECTIFYDESCR"));    //整改描述
				hidden.put("RECTIFICATIONDEPT", json.getString("RECTIFICATIONDEPT"));    //整改部门
				hidden.put("RECTIFICATIONOR", json.getString("RECTIFICATIONOR"));    //整改人
				hidden.put("HIDDENTYPE_NAME", json.getString("HIDDENTYPE_NAME"));    //整改人
				hidden.put("CREATOR", pd.getString("CREATOR"));    //发现人（隐患责任人）
				hidden.put("SOURCE", json.getString("SOURCE"));    //隐患来源
				hidden.put("STATE", "1");    //隐患状态 100-安全环保检查暂存的隐患（流程完转0）
				hidden.put("CREATTIME", time);    //发现时间
				hidden.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));    //企业ID
				hidden.put("ISDELETE", "0");    //是否删除(0:有效 1：删除)
				hidden.put("POSITIONDESC", json.getString("POSITIONDESC"));// 隐患位置描述
				keyprojectHiddenService.save(hidden);
				hiddenList.add(hidden);
				HIDDENJSONDATA.add(hidden);
				time = DateUtil.calculateDateSecond(time, 1);
			}
			pd.put("hiddenList", hiddenList);
		}
		try {
			//这里发送短信 通知  先判断重点工程是否要求发短信, 不发直接过，发的话 找到对应人以及对应手机号  发送对应模板短信啊
			PageData outSource = new PageData();
			outSource.put("OUTSOURCED_ID", pd.getString("OUTSOURCED_ID"));
			outSource = outsourcedService.findById(outSource);
			if (StringUtils.isNotBlank(outSource.getString("IS_SMS")) && StringUtils.equals("0", outSource.getString("IS_SMS"))) {
				//发送短信 pd中 PERSONNELMANAGEMENT_ID 对应 `qa-gwj-regulatory`.`BUS_PERSONNELMANAGEMENT` 表中 PERSONNELMANAGEMENT_ID  获取到 PHONENUM 手机号字段 发送短信
				PageData person = new PageData();
				person.put("PERSONNELMANAGEMENT_ID", pd.getString("PERSONNELMANAGEMENT_ID"));
				person = personnelmanagementService.findById(person);

				PageData mes = new PageData();
				mes.put("templateCode", "SMS_215820677");// 短信模板编码
				mes.put("CORPINFO_ID", person.get("CORPINFO_ID"));
				// 参数集合
				List<PageData> paramsList = new ArrayList<PageData>();
				// 第1个参数
				PageData params1 = new PageData();
				params1.put("name", "time");// 存入短信模板中的参数名称
				params1.put("value", outSource.getString("OUTSOURCED_NAME"));// 存入上面参数名称所传递的值
				paramsList.add(params1);
				sendMessageUtil.sendMessagesKeyproject(mes,person.getString("PHONENUM"), paramsList);

				//发送罚款待处理  上文开关控制这里发送不
				if (boo) {
					List<JSONObject> jsonList = (List<JSONObject>) JSON.parse(pd.getString("HIDDENJSON"));
					String PUNISHTHEPERSON = keyprojectHiddenService.getPUNISHTHEPERSON(pd);
					if (!Tools.isEmpty(PUNISHTHEPERSON)) {
						PageData selectPageData = new PageData();
						String[] split = PUNISHTHEPERSON.split(",");
						selectPageData.put("ids", split);
						List<String> list = keyprojectHiddenService.getPhone(selectPageData);
						for (JSONObject json : jsonList) {
							for (String phone : list) {
								if (StringUtils.isNotBlank(phone)) {
									PageData mes2 = new PageData();
									mes.put("templateCode", "SMS_215820677");// 短信模板编码
									mes.put("CORPINFO_ID", person.get("CORPINFO_ID"));
									// 参数集合
									List<PageData> paramsList2 = new ArrayList<PageData>();
									// 第1个参数
									PageData params2 = new PageData();
									params1.put("name", "time");// 存入短信模板中的参数名称
									params1.put("value", json.getString("HIDDENDESCR"));// 存入上面参数名称所传递的值
									paramsList.add(params2);
									sendMessageUtil.sendMessagesKeyproject(mes2,phone, paramsList2);
								}
							}
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			//获取当前重点工程的所属企业 根据重点工程创建人获取
			PageData dataDock = new PageData();
			String corpInfoId = outsourcedService.getCorpInfoByOutsourcesCreator(pd);
			pd.put("operatingCorpId", corpInfoId);
			dataDock.putAll(pd);
			if (SITUATIONJSONDATA.size() > 0) {
				dataDock.put("SITUATIONJSONDATA", SITUATIONJSONDATA);
			}
			if (HIDDENJSONDATA.size() > 0) {
				dataDock.put("HIDDENJSONDATA", HIDDENJSONDATA);
			}
			map.put("dockData", JSON.toJSONString(dataDock));
			map.put("pd", pd);
			map.put("result", errInfo);
		}
		//map.put("pd", pd);
		//map.put("result", errInfo);
		return map;
	}

	/**
	 * 删除
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Object delete() throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		keyprojectcheckService.delete(pd);
		map.put("result", errInfo);                //返回结果
		String corpInfoId = outsourcedService.getCorpInfoByOutsourcesCreator(pd);
		pd.put("operatingCorpId", corpInfoId);
		map.put("dockData", JSON.toJSONString(pd));
		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();
		keyprojectcheckService.edit(pd);
		map.put("result", errInfo);
		String corpInfoId = outsourcedService.getCorpInfoByOutsourcesCreator(pd);
		pd.put("operatingCorpId", corpInfoId);
		map.put("dockData", JSON.toJSONString(pd));
		return map;
	}

	/**
	 * 确认
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/confirm")
	@ResponseBody
	public Object confirm(@RequestParam(value = "FFILE", required = false) MultipartFile PERSON_SIGN) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		ArrayList<String> pictureList = new ArrayList<>();
		if (PERSON_SIGN != null) {
//			MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(pd.getString("PERSON_SIGN"));
			String suffixName = PERSON_SIGN.getOriginalFilename().substring(PERSON_SIGN.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
			if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) {
				map.put("result", "fail");
				map.put("exception", "上传文件格式不正确");
				return map;
			}
			String ffile = DateUtil.getDays();
			String fileName = this.get32UUID() + PERSON_SIGN.getOriginalFilename().substring(PERSON_SIGN.getOriginalFilename().lastIndexOf("."));
			pd.put("PERSON_SIGN_IMG", Const.FILEPATHFILE + ffile + "/" + fileName);
			pd.put("PERSON_SIGN_TIME", DateUtil.date2Str(new Date()));
			smb.sshSftp(PERSON_SIGN, fileName, Const.FILEPATHFILE + ffile);
			pictureList.add(pd.getString("PERSON_SIGN_IMG") +
					"@@"
					+ fileName);
		}
		keyprojectcheckService.confirm(pd);
		try {
			//这里发送短信  判断公司是否需要发送短信 然后判断是否有隐患  有则发送  没有不发送
			List<PageData> smsList = keyprojectcheckService.getSmsList(pd);
			if (!Tools.isEmpty(smsList)) {
				for (PageData pageData : smsList) {
					PageData mes = new PageData();
					mes.put("templateCode", "SMS_215820677");// 短信模板编码
					mes.put("CORPINFO_ID", pageData.get("CORPINFO_ID"));// 企业id
					// 参数集合
					List<PageData> paramsList = new ArrayList<PageData>();
					// 第1个参数
					PageData params1 = new PageData();
					params1.put("name", "time");// 存入短信模板中的参数名称
					params1.put("value", pageData.getString("HIDDENDESCR"));// 存入上面参数名称所传递的值
					paramsList.add(params1);
					sendMessageUtil.sendMessagesKeyproject(mes,pageData.getString("PHONENUM"), paramsList);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			map.put("result", errInfo);
		}
		map.put("sendPicturesList", JSON.toJSONString(pictureList));
		PageData pageData = keyprojectcheckService.findById(pd);
		String corpInfoId = outsourcedService.getCorpInfoByOutsourcesCreator(pageData);
		pd.put("operatingCorpId", corpInfoId);
		map.put("dockData", JSON.toJSONString(pd));
		return map;
	}

	/**
	 * 列表
	 *
	 * @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());
		page.setPd(pd);
		List<PageData> varList = keyprojectcheckService.list(page);    //列出KeyprojectCheck列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 去修改页面获取数据
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/goEdit")
	@ResponseBody
	public Object goEdit() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = keyprojectcheckService.findById(pd);    //根据ID读取

		List<PageData> situationList = keyprojectcheckInfoService.listAll(pd);

		pd.put("FOREIGN_ID", pd.getString("KEYPROJECTCHECK_ID"));
		pd.put("hiddenList", keyprojectHiddenService.listAllInspection(pd));
		pd.put("situationList", situationList);
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 去隐患页面获取数据
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/listHidden")
	@ResponseBody
	public Object listHidden(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 = keyprojectHiddenService.list(page);    //列出KeyprojectCheck列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 去隐患页面获取数据
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/findHidden")
	@ResponseBody
	public Object findHidden() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = keyprojectHiddenService.findById(pd);    //根据ID读取

		PageData pd2 = new PageData();
		pd2.put("FOREIGN_KEY", pd.getString("HIDDEN_ID"));
		pd2.put("TYPE", 3);    //隐患报警图片
		pd.put("hiddenImgs", imgFilesService.listAll(pd2));
		if (imgFilesService.listAll(pd2).size() == 0) {
			pd2.put("TYPE", 114);    //AI隐患图片
			pd.put("hiddenImgs", imgFilesService.listAll(pd2));
		}
		pd2.put("TYPE", 102);    //隐患视频
		pd.put("hiddenVideos", imgFilesService.listAll(pd2));
		pd2.put("TYPE", 4);
		pd.put("zgImgs", imgFilesService.listAll(pd2));//整改图片
		pd2.put("TYPE", 5);
		pd.put("ysImgs", imgFilesService.listAll(pd2));//整改图片
		PageData findTicketData = new PageData();
		findTicketData.put("HIDDEN_ID", pd.getString("HIDDEN_ID"));
		pd.put("punishForm", keyprojectpunishService.findById(findTicketData));
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 整改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/rectify")
	@ResponseBody
	@Transactional
	public Object rectify(@RequestParam(value = "FFILE", required = false) MultipartFile[] files) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STATE", 2);
		keyprojectHiddenService.editstate(pd);

		if (files != null && files.length > 0) {
			for (int i = 0; i < files.length; i++) {
				String suffixName = files[i].getOriginalFilename().substring(files[i].getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
				if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) {
					map.put("result", "fail");
					map.put("exception", "上传文件格式不正确");
					return map;
				}
			}
			for (int i = 0; i < files.length; i++) {
				MultipartFile file = files[i];

				String ffile = DateUtil.getDays();
//        		String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//        		String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
				String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
				PageData img = new PageData();
				String id = this.get32UUID();
				img.put("IMGFILES_ID", id);
				img.put("FILEPATH", Const.FILEPATHFILE + ffile + "/" + fileName);
				img.put("TYPE", 4);
				img.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
				imgFilesService.save(img);
			}
		}
		map.put("result", errInfo);
		String corpInfoId = keyprojectHiddenService.getCorpInfoIdByHiddenId(pd);
		pd.put("operatingCorpId", corpInfoId);
		map.put("dockData", JSON.toJSONString(pd));
		return map;
	}

	/**
	 * 验收
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/check")
	@ResponseBody
	@Transactional
	public Object check() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STATE", 4);
		keyprojectHiddenService.editstate(pd);
		//根据隐患获取重点工程所属企业
		String corpInfoId = keyprojectHiddenService.getCorpInfoIdByHiddenId(pd);
		pd.put("operatingCorpId", corpInfoId);
		map.put("dockData", JSON.toJSONString(pd));
		map.put("result", errInfo);
		return map;
	}


	/**
	 * 批量删除
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/deleteAll")
	@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(",");
			keyprojectcheckService.deleteAll(ArrayDATA_IDS);
			errInfo = "success";
		} else {
			errInfo = "error";
		}
		map.put("result", errInfo);                //返回结果
		return map;
	}

	/**去隐患页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/keyProjectCount")
	@ResponseBody
	public Object keyProjectCount() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		String UserId = pd.getString("UserId");
		if(!StringUtils.equals("1",UserId)){
			String CORPINFO_ID = pd.getString("CORPINFO_ID");
			if(!StringUtils.equals(CORPINFO_ID,"1e6dbbe16004402f8d2c0e52afd9a676")&&!StringUtils.equals(CORPINFO_ID,"3a854eefa7894e06aaa1a2611bca80f6")&&
					!StringUtils.equals(CORPINFO_ID,"020578a4c1f04bc692ee25145c2efbe5")&&!StringUtils.equals(CORPINFO_ID,"90966974de3c4b83aca6f8fd6432d5c2")){
				pd.put("DeptId",outsourcedService.getDeptId(UserId));
			}
		}
		pd = keyprojectHiddenService.keyprojectcount(pd);	//根据ID读取
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 修改处罚状态
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/editHiddenIspunish")
	@ResponseBody
	@Transactional
	public Object editHiddenIspunish() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		keyprojectHiddenService.editstate(pd);
		map.put("result", errInfo);
		map.put("dockData", JSON.toJSONString(pd));
		return map;
	}


	/**
	 * 整改 只处理图片
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/rectifyOnlyFile")
	@ResponseBody
	@Transactional
	public Object rectifyOnlyFile(@RequestParam(value = "FFILE", required = false) MultipartFile[] files) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		if (files.length > 1) {
			map.put("result", "fail");
			map.put("exception", "一次性上传图片过多！");
			return map;
		}
		if (files != null) {
			MultipartFile file = files[0];
			String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
			if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) {
				map.put("result", "fail");
				map.put("exception", "上传文件格式不正确");
				return map;
			}
			String ffile = DateUtil.getDays();
//        		String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile;	//文件上传路径
//        		String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
			String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			PageData img = new PageData();
			String IMGFILES_ID = this.get32UUID();
			img.put("IMGFILES_ID", IMGFILES_ID);
			img.put("FILEPATH", Const.FILEPATHFILE + ffile + "/" + fileName);
			img.put("TYPE", 4);
			img.put("FOREIGN_KEY", pd.get("HIDDEN_ID"));
			smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile);
			imgFilesService.save(img);
		}
		map.put("result", errInfo);
		return map;
	}

	/**
	 * 整改 只处理表单
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/rectifyOnlyForm")
	@ResponseBody
	@Transactional
	public Object rectifyOnlyForm() throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STATE", 2);
		keyprojectHiddenService.editstate(pd);
		try {
			//发送 隐患待验收模板 短信
			//这里发送短信  判断公司是否需要发送短信 然后判断是否有隐患  有则发送  没有不发送
			String HIDDENDESCR = "";
			List<PageData> smsList = keyprojectHiddenService.getSmsList(pd);
			if (!Tools.isEmpty(smsList)) {
				for (PageData pageData : smsList) {
					PageData mes = new PageData();
					mes.put("templateCode", "SMS_215820677");// 短信模板编码
					mes.put("CORPINFO_ID", pageData.get("CORPINFO_ID"));// 企业id
					// 参数集合
					List<PageData> paramsList = new ArrayList<PageData>();
					// 第1个参数
					PageData params1 = new PageData();
					params1.put("name", "time");// 存入短信模板中的参数名称
					params1.put("value", pageData.getString("HIDDENDESCR"));// 存入上面参数名称所传递的值
					paramsList.add(params1);
					sendMessageUtil.sendMessagesKeyproject(mes,pageData.getString("PHONENUM"), paramsList);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			map.put("result", errInfo);
		}
		map.put("result", errInfo);
		pd.put("operatingCorpId", keyprojectHiddenService.getCorpInfoIdByHiddenId(pd));
		map.put("dockData", JSON.toJSONString(pd));
		return map;
	}

	/**重点工程处罚列表 包含 未选择处罚结果的隐患  已下发处罚但为反馈的隐患 不处罚的隐患
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/punishlist")
	@ResponseBody
	public Object punishlist(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 = keyprojectHiddenService.getpunishlist(page);	//列出KeyprojectCheck列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}
}
