package com.zcloud.controller.relatedparty;

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.relatedparty.OutSourcedService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.service.system.UsersService;
import com.zcloud.service.video.AIWarningService;
import com.zcloud.service.video.VideoManagerService;
import com.zcloud.util.*;
import org.apache.commons.lang.StringUtils;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * 说明：外包工程
 * 作者：luoxiaobao
 * 时间：2022-06-14
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/outsourced")
public class OutSourcedController extends BaseController {

	@Autowired
	private OutSourcedService outsourcedService;
	@Autowired
	private Smb smb;
	@Autowired
	private AIWarningService aiWarningService;

	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private UsersService usersService;
	@Autowired
	private ImgFilesService imgfilesService;

	@Autowired
	private VideoManagerService videoManagerService;

	@RequestMapping(value = "/start")
	@ResponseBody
	public Object start() throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = outsourcedService.findById(pd);
		if (!StringUtils.isNotBlank(pd.getString("WORK_LONGITUDE"))){
			map.put("result", errInfo);
			map.put("message","工程未定位!");
			map.put("code","500");
			return map;
		}
		outsourcedService.start(pd);
		map.put("code","0");
		map.put("result", errInfo);                //返回结果
		return map;
	}


	/**
	 * 删除
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/jie")
	@ResponseBody
	public Object jie() throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		//校验当前重点工程是否存在未完成的隐患 （包含未整改，未处罚，ai报警未处置的）
		PageData pageData = outsourcedService.jieshuOutSourced(pd);
		if(!StringUtils.equals("0",pageData.getString("qr"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("qr")+"项待确认安全环保检查,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		if(!StringUtils.equals("0",pageData.getString("zg"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("zg")+"项需整改的隐患,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		if(!StringUtils.equals("0",pageData.getString("ys"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("ys")+"项待验收隐患,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		if(!StringUtils.equals("0",pageData.getString("cf"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("cf")+"项待处罚隐患,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		if(!StringUtils.equals("0",pageData.getString("fk"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("fk")+"项处罚待反馈隐患,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		if(!StringUtils.equals("0",pageData.getString("ai"))){
			map.put("result", errInfo);
			map.put("message","当前重点工程还有"+pageData.getString("ai")+"项AI报警待处置,请处理以后再结束");
			map.put("code","500");
			return map;
		}
		pd = outsourcedService.findById(pd);
		outsourcedService.jie(pd);
		//清空摄像头与重点工程的关联关系
		videoManagerService.updateAiByOUTSOURCED_ID(pd);
		map.put("code","0");
		map.put("result", errInfo);                //返回结果
		return map;
	}

	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	// @RequiresPermissions("outsourced:add")
	@ResponseBody
	@LogAnno(menuType= "综合管理",menuServer= "相关方管理",instructionsOperate = "外包工程管理",instructionsType = "新增")
	public Object add(@RequestParam(value="file",required=false) MultipartFile file,
					  @RequestParam(value="file1",required=false) MultipartFile file1,
					  @RequestParam(value="file2",required=false) MultipartFile file2,
					  @RequestParam(value="file3",required=false) MultipartFile file3,
					  @RequestParam(value="file4",required=false) MultipartFile file4,
					  @RequestParam(value="file5",required=false) MultipartFile file5,
					  @RequestParam(value="file6",required=false) MultipartFile file6,
					  @RequestParam(value="file7",required=false) MultipartFile file7,
					  @RequestParam(value="file8",required=false) MultipartFile file8) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("OUTSOURCED_ID", this.get32UUID());	//主键
		pd.put("CREATOR", Jurisdiction.getUsername());	//添加人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//添加时间
		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		pd.put("ISDELETE", "0");	//是否删除
		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
		if (null != file && !file.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("UNITS_APTITUDE", file.getOriginalFilename());
			pd.put("UNITS_APTITUDEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file1 && !file1.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file1.getOriginalFilename().substring(file1.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file1, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("MEASURES", file2.getOriginalFilename());
			pd.put("MEASURESPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file2 && !file2.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file2.getOriginalFilename().substring(file2.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file2, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("MANAGE_APTITUDE", file2.getOriginalFilename());
			pd.put("MANAGE_APTITUDEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file3 && !file3.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file3.getOriginalFilename().substring(file3.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file3, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("DESIGE", file3.getOriginalFilename());
			pd.put("DESIGEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file4 && !file4.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file4.getOriginalFilename().substring(file4.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file4, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("ATTACHMENTS", file4.getOriginalFilename());
			pd.put("ATTACHMENTSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file5 && !file5.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file5.getOriginalFilename().substring(file5.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file5, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("RECORDS", file5.getOriginalFilename());
			pd.put("RECORDSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file6 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file6.getOriginalFilename().substring(file6.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file6, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("SHEET", file6.getOriginalFilename());
			pd.put("SHEETPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file7 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file7.getOriginalFilename().substring(file7.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file7, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("EXAMINATION", file7.getOriginalFilename());
			pd.put("EXAMINATIONPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file8 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file8.getOriginalFilename().substring(file8.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file8, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("OATTACHMENTS", file8.getOriginalFilename());
			pd.put("OATTACHMENTSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		outsourcedService.save(pd);
		map.put("result", errInfo);
		return map;
	}

	/**删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	// @RequiresPermissions("outsourced: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();
		outsourcedService.delete(pd);
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	// @RequiresPermissions("outsourced:edit")
	@ResponseBody
	@LogAnno(menuType= "综合管理",menuServer= "相关方管理",instructionsOperate = "外包工程管理",instructionsType = "修改")
	public Object edit(@RequestParam(value="file",required=false) MultipartFile file,
					   @RequestParam(value="file1",required=false) MultipartFile file1,
					   @RequestParam(value="file2",required=false) MultipartFile file2,
					   @RequestParam(value="file3",required=false) MultipartFile file3,
					   @RequestParam(value="file4",required=false) MultipartFile file4,
					   @RequestParam(value="file5",required=false) MultipartFile file5,
					   @RequestParam(value="file6",required=false) MultipartFile file6,
					   @RequestParam(value="file7",required=false) MultipartFile file7,
					   @RequestParam(value="file8",required=false) MultipartFile file8,
					   @RequestParam(value= "file9", required = false) MultipartFile[] file9) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		if (null != file && !file.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("UNITS_APTITUDE", file.getOriginalFilename());
			pd.put("UNITS_APTITUDEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file1 && !file1.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file1.getOriginalFilename().substring(file1.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file1, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("MEASURES", file2.getOriginalFilename());
			pd.put("MEASURESPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file2 && !file2.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file2.getOriginalFilename().substring(file2.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file2, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("MANAGE_APTITUDE", file2.getOriginalFilename());
			pd.put("MANAGE_APTITUDEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file3 && !file3.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file3.getOriginalFilename().substring(file3.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file3, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("DESIGE", file3.getOriginalFilename());
			pd.put("DESIGEPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file4 && !file4.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file4.getOriginalFilename().substring(file4.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file4, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("ATTACHMENTS", file4.getOriginalFilename());
			pd.put("ATTACHMENTSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file5 && !file5.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file5.getOriginalFilename().substring(file5.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file5, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("RECORDS", file5.getOriginalFilename());
			pd.put("RECORDSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file6 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file6.getOriginalFilename().substring(file6.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file6, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("SHEET", file6.getOriginalFilename());
			pd.put("SHEETPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file7 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file7.getOriginalFilename().substring(file7.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file7, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("EXAMINATION", file7.getOriginalFilename());
			pd.put("EXAMINATIONPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		if (null != file8 && !file6.isEmpty()) {
			String  ffile = DateUtil.getDays();
			String fileName = this.get32UUID()+file8.getOriginalFilename().substring(file8.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file8, fileName, Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("OATTACHMENTS", file8.getOriginalFilename());
			pd.put("OATTACHMENTSPATH", Const.FILEPATHFXGFGL + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}

		if (null != file9 && file9.length > 0) {
			//校验
			for (int i = 0; i < file9.length; i++) {
				MultipartFile file9One = file9[i];
				String suffixName = file9One.getOriginalFilename().substring(file9One.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 < file9.length; i++) {
				MultipartFile file9One = file9[i];
				String ffile = DateUtil.getDays();
				String fileName = this.get32UUID() + file9One.getOriginalFilename().
						substring(file9One.getOriginalFilename().lastIndexOf("."));
				smb.sshSftp(file9One, fileName, Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
				PageData pdImg = new PageData();
				String fileUpdateName = file9One.getOriginalFilename();
				pdImg.put("IMGFILES_ID", this.get32UUID());
				pdImg.put("FILE_NAME", fileUpdateName);
				pdImg.put("FILEPATH", Const.FILEPATHYHTP + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
				pdImg.put("TYPE", "300");
				pdImg.put("FOREIGN_KEY", pd.getString("OUTSOURCED_ID"));
				imgfilesService.save(pdImg);
			}

		}

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

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	// @RequiresPermissions("outsourced: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 KEYWORDS = pd.getString("KEYWORDS");						//关键词检索条件
		if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim());
		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
		page.setPd(pd);
		List<PageData>	varList = outsourcedService.list(page);	//列出OutSourced列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	 /**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	// @RequiresPermissions("outsourced:edit")
	@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 = outsourcedService.findById(pd);	//根据ID读取
		PageData selectPageData = new PageData();
		selectPageData.put("CORPINFO_ID", pd.get("PUNISH_THE_PERSON"));
		List<PageData> deptList = departmentService.listAll(selectPageData);    //根据ID读取
		String userStr = pd.getString("PUNISH_THE_PERSON");
		if (!Tools.isEmpty(userStr)) {
			String[] split = userStr.split(",");
			selectPageData.put("ids", split);
//			List<PageData> pageData = usersService.listUserAndDept(selectPageData);
			// 监管与企业的
			List<PageData> pageData = usersService.selectUserListByUserIds(selectPageData);
			map.put("punishThePerson", pageData);
		}
		PageData pd3 = new PageData();
		pd3.put("TYPE", 300);
		pd3.put("FOREIGN_KEY", pd.getString("OUTSOURCED_ID"));
		List<PageData> file9 = imgfilesService.listAll(pd3);

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

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

	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excel")
	// @RequiresPermissions("toExcel")
	@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("企业ID");	//31
		titles.add("申请人");	//32
		titles.add("状态");	//33
		dataMap.put("titles", titles);
		List<PageData> varOList = outsourcedService.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("CONTRACT_ID"));	    //1
			vpd.put("var2", varOList.get(i).getString("CONTRACT_PIC"));	    //2
			vpd.put("var3", varOList.get(i).getString("OUTSOURCED_NAME"));	    //3
			vpd.put("var4", varOList.get(i).getString("STARTTIME"));	    //4
			vpd.put("var5", varOList.get(i).getString("ENDTIME"));	    //5
			vpd.put("var6", varOList.get(i).getString("CONTRACTTIME"));	    //6
			vpd.put("var7", varOList.get(i).getString("UNITS_NAME"));	    //7
			vpd.put("var8", varOList.get(i).getString("CONTRACT_NUM"));	    //8
			vpd.put("var9", varOList.get(i).getString("UNITS_APTITUDE"));	    //9
			vpd.put("var10", varOList.get(i).getString("UNITS_PIC"));	    //10
			vpd.put("var11", varOList.get(i).get("UNITS_PHONE").toString());	//11
			vpd.put("var12", varOList.get(i).getString("MANAGE_NAME"));	    //12
			vpd.put("var13", varOList.get(i).getString("MANAGE_APTITUDE"));	    //13
			vpd.put("var14", varOList.get(i).getString("MANAGE_PIC"));	    //14
			vpd.put("var15", varOList.get(i).get("MANAGE_PHONE").toString());	//15
			vpd.put("var16", varOList.get(i).getString("MEASURES"));	    //16
			vpd.put("var17", varOList.get(i).getString("ATTACHMENTS"));	    //17
			vpd.put("var18", varOList.get(i).getString("REMARKS"));	    //18
			vpd.put("var19", varOList.get(i).getString("TRAINING_NAME"));	    //19
			vpd.put("var20", varOList.get(i).getString("TRAINING_PIC"));	    //20
			vpd.put("var21", varOList.get(i).getString("TRAINING_TIME"));	    //21
			vpd.put("var22", varOList.get(i).getString("RECORDS"));	    //22
			vpd.put("var23", varOList.get(i).getString("SHEET"));	    //23
			vpd.put("var24", varOList.get(i).getString("EXAMINATION"));	    //24
			vpd.put("var25", varOList.get(i).getString("OATTACHMENTS"));	    //25
			vpd.put("var26", varOList.get(i).getString("CREATOR"));	    //26
			vpd.put("var27", varOList.get(i).getString("CREATTIME"));	    //27
			vpd.put("var28", varOList.get(i).getString("OPERATOR"));	    //28
			vpd.put("var29", varOList.get(i).getString("OPERATTIME"));	    //29
			vpd.put("var30", varOList.get(i).getString("ISDELETE"));	    //30
			vpd.put("var31", varOList.get(i).getString("CORPINFO_ID"));	    //31
			vpd.put("var32", varOList.get(i).getString("APPLICANT"));	    //32
			vpd.put("var33", varOList.get(i).getString("STATE"));	    //33
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}

	/**
	 * 批量删除
	 *
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateState")
	@ResponseBody
	public Object updateState() 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());
		outsourcedService.updateState(pd);
		map.put("result", errInfo);                //返回结果
		return map;
	}


}
