package com.zcloud.controller.speEquip;

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.check.SysDateService;
import com.zcloud.service.speEquip.SpecialEquipmentChangeService;
import com.zcloud.service.speEquip.SpecialEquipmentService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.service.system.UsersService;
import com.zcloud.util.*;
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 javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * 说明：特种设备管理
 * 作者：luoxiaobao
 * 时间：2021-06-19
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/specialequipment")
public class SpecialEquipmentController extends BaseController {

	@Autowired
	private SpecialEquipmentService specialequipmentService;
	@Autowired
	private SpecialEquipmentChangeService specialequipmentchangeService;
	@Autowired
	private DictionariesService dictionariesService;
	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private UsersService usersService;
	@Autowired
	private SysDateService sysDateService;
	@Autowired
	private Smb smb;
	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	// @RequiresPermissions("specialequipment:add")
	@ResponseBody
	@LogAnno(menuType= "综合管理",menuServer= "特种设备",instructionsOperate = "设备管理",instructionsType = "新增")
	public Object add(@RequestParam(value="file",required=false) MultipartFile file) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("SPECIALEQUIPMENT_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");	//是否删除 1-是  0-否
		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID

		PageData sysdate = new PageData();
		sysdate.put("DATE", pd.get("CREATTIME"));
		sysdate = sysDateService.findByDate(sysdate);
		String period = pd.getString("PERIOD");
		switch (period) {
			case "specialPeriod001"://每日
				pd.put("PERIOD_START_DATE",sysdate.get("DAY_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("DAY_END"));
				break;
			case "specialPeriod002"://每周
				pd.put("PERIOD_START_DATE",sysdate.get("WEEK_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("WEEK_END"));
				break;
			case "specialPeriod003"://每旬
				pd.put("PERIOD_START_DATE",sysdate.get("XUN_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("XUN_END"));
				break;
			case "specialPeriod004"://每月
				pd.put("PERIOD_START_DATE",sysdate.get("MONTH_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("MONTH_END"));
				break;
			default:
				break;
		}
		if (null != file && !file.isEmpty()) {
			String ffile = DateUtil.getDays();
			//本地
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
			//服务器
			String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file, fileName, Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("TECHNICALFILENAME", file.getOriginalFilename());
			pd.put("TECHNICALFILEPATH", Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		specialequipmentService.save(pd);
		map.put("pd", pd);

		PageData changeData = new PageData();
		changeData.put("SPECIALEQUIPMENTCHANGE_ID", this.get32UUID());	//主键
		changeData.put("SPECIALEQUIPMENT_ID", pd.getString("SPECIALEQUIPMENT_ID"));	//主键
		changeData.put("OPERATETYPE", "新增");	//操作类型
		changeData.put("CREATOR", Jurisdiction.getUsername());	//添加人
		changeData.put("CREATTIME", DateUtil.date2Str(new Date()));	//添加时间
		changeData.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		changeData.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		changeData.put("ISDELETE", "0");	//是否删除 1-是  0-否
		changeData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
//		changeData.put("EQUIPMENTNAME_BEFORE", pd.getString("EQUIPMENTNAME"));	//设备名称（前）
		changeData.put("EQUIPMENTNAME_AFTER", pd.getString("EQUIPMENTNAME"));	//设备名称（后）
//		changeData.put("EQUIPMENTMODEL_BEFORE", pd.getString("EQUIPMENTMODEL"));	//设备型号（前）
		changeData.put("EQUIPMENTMODEL_AFTER", pd.getString("EQUIPMENTMODEL"));	//设备型号（后）
//		changeData.put("EQUIPMENTCODE_BEFORE", pd.getString("EQUIPMENTCODE"));	//设备代码（前）
		changeData.put("EQUIPMENTCODE_AFTER", pd.getString("EQUIPMENTCODE"));	//设备代码（后）
//		changeData.put("FACTORYCODE_BEFORE", pd.getString("FACTORYCODE"));	//出厂编号（前）
		changeData.put("FACTORYCODE_AFTER", pd.getString("FACTORYCODE"));	//出厂编号（后）

		PageData etWhere = new PageData();
		etWhere.put("BIANMA",pd.getString("EQUIPMENTTYPE"));
		PageData equipmentType = dictionariesService.findByBianma(etWhere);
//		changeData.put("EQUIPMENTTYPE_BEFORE", equipmentType.getString("NAME"));	//设备类型（前）
		changeData.put("EQUIPMENTTYPE_AFTER", equipmentType.getString("NAME"));	//设备类型（后）

		PageData esWhere = new PageData();
		esWhere.put("BIANMA",pd.getString("EQUIPMENTSTATE"));
		PageData equipmentState = dictionariesService.findByBianma(esWhere);
//		changeData.put("EQUIPMENTSTATE_BEFORE", equipmentState.getString("NAME"));	//设备状态（前）
		changeData.put("EQUIPMENTSTATE_AFTER", equipmentState.getString("NAME"));	//设备状态（后）
//		changeData.put("EQUIPMENTUSEPLACE_BEFORE", pd.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（前）
		changeData.put("EQUIPMENTUSEPLACE_AFTER", pd.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（后）

		PageData dWhere = new PageData();
		dWhere.put("DEPARTMENT_ID",pd.getString("RESPONSIBLEUNIT"));
		PageData department = departmentService.findById(dWhere);
//		changeData.put("RESPONSIBLEUNIT_BEFORE", department.getString("NAME"));	//设备责任单位（前）
		changeData.put("RESPONSIBLEUNIT_AFTER", department.getString("NAME"));	//设备责任单位（后）

		PageData uWhere = new PageData();
		uWhere.put("USER_ID",pd.getString("PERSONCHARGE"));
		PageData user = usersService.findById(uWhere);
//		changeData.put("PERSONCHARGE_BEFORE", user.getString("NAME"));	//设备负责人（前）
		changeData.put("PERSONCHARGE_AFTER", user.getString("NAME"));	//设备负责人（后）
//		changeData.put("PERSONCHARGEPHONE_BEFORE", pd.getString("PERSONCHARGEPHONE"));	//负责人联系电话（前）
		changeData.put("PERSONCHARGEPHONE_AFTER", pd.getString("PERSONCHARGEPHONE"));	//负责人联系电话（后）
//		changeData.put("NEXTINSPECTIONDATE_BEFORE", pd.getString("NEXTINSPECTIONDATE"));	//下次检验日期（前）
		changeData.put("NEXTINSPECTIONDATE_AFTER", pd.getString("NEXTINSPECTIONDATE"));	//下次检验日期（后）
//		changeData.put("TECHNICALFILENAME_BEFORE", pd.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（前）
		changeData.put("TECHNICALFILENAME_AFTER", pd.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（后）
//		changeData.put("TECHNICALFILEPATH_BEFORE", pd.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（前）
		changeData.put("TECHNICALFILEPATH_AFTER", pd.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（后）
//		changeData.put("REMARKS_BEFORE", pd.getString("REMARKS"));	//备注（前）
		changeData.put("REMARKS_AFTER", pd.getString("REMARKS"));	//备注（后）
		specialequipmentchangeService.save(changeData);
		map.put("result", errInfo);
		return map;
	}

	/**删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	// @RequiresPermissions("specialequipment: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();
		PageData updateBefour = specialequipmentService.findById(pd);

		PageData changeData = new PageData();
		changeData.put("SPECIALEQUIPMENTCHANGE_ID", this.get32UUID());	//主键
		changeData.put("SPECIALEQUIPMENT_ID", updateBefour.getString("SPECIALEQUIPMENT_ID"));	//主键
		changeData.put("OPERATETYPE", "删除");	//操作类型
		changeData.put("CREATOR", Jurisdiction.getUsername());	//添加人
		changeData.put("CREATTIME", DateUtil.date2Str(new Date()));	//添加时间
		changeData.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		changeData.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		changeData.put("ISDELETE", "0");	//是否删除 1-是  0-否
		changeData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
		changeData.put("EQUIPMENTNAME_AFTER", updateBefour.getString("EQUIPMENTNAME"));	//设备名称（前）
		changeData.put("EQUIPMENTMODEL_AFTER", updateBefour.getString("EQUIPMENTMODEL"));	//设备型号（前）
		changeData.put("EQUIPMENTCODE_AFTER", updateBefour.getString("EQUIPMENTCODE"));	//设备代码（前）
		changeData.put("FACTORYCODE_AFTER", updateBefour.getString("FACTORYCODE"));	//出厂编号（前）
//		PageData etWhere = new PageData();
//		etWhere.put("BIANMA",updateBefour.getString("EQUIPMENTTYPE"));
//		PageData equipmentType = dictionariesService.findByBianma(etWhere);
//		changeData.put("EQUIPMENTTYPE_AFTER", equipmentType.getString("NAME"));	//设备类型（前）
		changeData.put("EQUIPMENTTYPE_AFTER", updateBefour.getString("EQUIPMENTTYPENAME"));	//设备类型（前）
//		PageData esWhere = new PageData();
//		esWhere.put("BIANMA",updateBefour.getString("EQUIPMENTSTATE"));
//		PageData equipmentState = dictionariesService.findByBianma(esWhere);
//		changeData.put("EQUIPMENTSTATE_AFTER", equipmentState.getString("NAME"));	//设备状态（前）
		changeData.put("EQUIPMENTSTATE_AFTER", updateBefour.getString("EQUIPMENTSTATENAME"));	//设备状态（前）
		changeData.put("EQUIPMENTUSEPLACE_AFTER", updateBefour.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（前）
		changeData.put("RESPONSIBLEUNIT_AFTER", updateBefour.getString("RESPONSIBLEUNITNAME"));	//设备责任单位（前）
		changeData.put("PERSONCHARGE_AFTER", updateBefour.getString("PERSONCHARGENAME"));	//设备负责人（前）
		changeData.put("PERSONCHARGEPHONE_AFTER", updateBefour.getString("PERSONCHARGEPHONE"));	//负责人联系电话（前）
		changeData.put("NEXTINSPECTIONDATE_AFTER", updateBefour.getString("NEXTINSPECTIONDATE"));	//下次检验日期（前）
		changeData.put("TECHNICALFILENAME_AFTER", updateBefour.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（前）
		changeData.put("TECHNICALFILEPATH_AFTER", updateBefour.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（前）
		changeData.put("REMARKS_AFTER", updateBefour.getString("REMARKS"));	//备注（前）
		specialequipmentchangeService.save(changeData);

		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		specialequipmentService.delete(pd);
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	// @RequiresPermissions("specialequipment:edit")
	@ResponseBody
	@LogAnno(menuType= "综合管理",menuServer= "特种设备",instructionsOperate = "设备管理",instructionsType = "修改")
	public Object edit(@RequestParam(value="file",required=false) MultipartFile file) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData updateBefour = specialequipmentService.findById(pd);

		PageData changeData = new PageData();
		changeData.put("SPECIALEQUIPMENTCHANGE_ID", this.get32UUID());	//主键
		changeData.put("SPECIALEQUIPMENT_ID", updateBefour.getString("SPECIALEQUIPMENT_ID"));	//主键
		changeData.put("OPERATETYPE", "修改");	//操作类型
		changeData.put("CREATOR", Jurisdiction.getUsername());	//添加人
		changeData.put("CREATTIME", DateUtil.date2Str(new Date()));	//添加时间
		changeData.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		changeData.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		changeData.put("ISDELETE", "0");	//是否删除 1-是  0-否
		changeData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
		changeData.put("EQUIPMENTNAME_BEFORE", updateBefour.getString("EQUIPMENTNAME"));	//设备名称（前）
		changeData.put("EQUIPMENTMODEL_BEFORE", updateBefour.getString("EQUIPMENTMODEL"));	//设备型号（前）
		changeData.put("EQUIPMENTCODE_BEFORE", updateBefour.getString("EQUIPMENTCODE"));	//设备代码（前）
		changeData.put("FACTORYCODE_BEFORE", updateBefour.getString("FACTORYCODE"));	//出厂编号（前）
//		PageData EQUIPMENTTYPE = new PageData();
//		EQUIPMENTTYPE.put("BIANMA",updateBefour.getString("EQUIPMENTTYPE"));
//		PageData EquipmentType = dictionariesService.findByBianma(EQUIPMENTTYPE);
//		changeData.put("EQUIPMENTTYPE_BEFORE", EquipmentType.getString("NAME"));	//设备类型（前）
		changeData.put("EQUIPMENTTYPE_BEFORE", updateBefour.getString("EQUIPMENTTYPENAME"));	//设备类型（前）
//		PageData EQUIPMENTSTATE = new PageData();
//		EQUIPMENTSTATE.put("BIANMA",updateBefour.getString("EQUIPMENTSTATE"));
//		PageData EquipmentState = dictionariesService.findByBianma(EQUIPMENTSTATE);
//		changeData.put("EQUIPMENTSTATE_BEFORE", EquipmentState.getString("NAME"));	//设备状态（前）
		changeData.put("EQUIPMENTSTATE_BEFORE", updateBefour.getString("EQUIPMENTSTATENAME"));	//设备状态（前）
		changeData.put("EQUIPMENTUSEPLACE_BEFORE", updateBefour.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（前）
		changeData.put("RESPONSIBLEUNIT_BEFORE", updateBefour.getString("RESPONSIBLEUNITNAME"));	//设备责任单位（前）
		changeData.put("PERSONCHARGE_BEFORE", updateBefour.getString("PERSONCHARGENAME"));	//设备负责人（前）
		changeData.put("PERSONCHARGEPHONE_BEFORE", updateBefour.getString("PERSONCHARGEPHONE"));	//负责人联系电话（前）
//		changeData.put("NEXTINSPECTIONDATE_BEFORE", updateBefour.getString("NEXTINSPECTIONDATE"));	//下次检验日期（前）
		changeData.put("PERIOD_BEFORE", updateBefour.getString("PERIOD"));	//下次检验日期（前）
		changeData.put("TECHNICALFILENAME_BEFORE", updateBefour.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（前）
		changeData.put("TECHNICALFILEPATH_BEFORE", updateBefour.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（前）
		changeData.put("REMARKS_BEFORE", updateBefour.getString("REMARKS"));	//备注（前）

		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		PageData sysdate = new PageData();
		sysdate.put("DATE", pd.get("OPERATTIME"));
		sysdate = sysDateService.findByDate(sysdate);
		String period = pd.getString("PERIOD");
		switch (period) {
			case "specialPeriod001"://每日
				pd.put("PERIOD_START_DATE",sysdate.get("DAY_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("DAY_END"));
				break;
			case "specialPeriod002"://每周
				pd.put("PERIOD_START_DATE",sysdate.get("WEEK_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("WEEK_END"));
				break;
			case "specialPeriod003"://每旬
				pd.put("PERIOD_START_DATE",sysdate.get("XUN_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("XUN_END"));
				break;
			case "specialPeriod004"://每月
				pd.put("PERIOD_START_DATE",sysdate.get("MONTH_START"));
				pd.put("PERIOD_END_DATE",sysdate.get("MONTH_END"));
				break;
			default:
				break;
		}

		if (null != file && !file.isEmpty()) {
			String ffile = DateUtil.getDays();
			//本地
//			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile;	//文件上传路径
//			String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());				//执行上传
			//服务器
			String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			smb.sshSftp(file, fileName, Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
			pd.put("TECHNICALFILENAME", file.getOriginalFilename());
			pd.put("TECHNICALFILEPATH", Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName);
		}
		specialequipmentService.edit(pd);
		changeData.put("EQUIPMENTNAME_AFTER", pd.getString("EQUIPMENTNAME"));	//设备名称（后）
		changeData.put("EQUIPMENTMODEL_AFTER", pd.getString("EQUIPMENTMODEL"));	//设备型号（后）
		changeData.put("EQUIPMENTCODE_AFTER", pd.getString("EQUIPMENTCODE"));	//设备代码（后）
		changeData.put("FACTORYCODE_AFTER", pd.getString("FACTORYCODE"));	//出厂编号（后）
		PageData etWhere = new PageData();
		etWhere.put("BIANMA",pd.getString("EQUIPMENTTYPE"));
		PageData equipmentType = dictionariesService.findByBianma(etWhere);
		changeData.put("EQUIPMENTTYPE_AFTER", equipmentType.getString("NAME"));	//设备类型（后）

		PageData esWhere = new PageData();
		esWhere.put("BIANMA",pd.getString("EQUIPMENTSTATE"));
		PageData equipmentState = dictionariesService.findByBianma(esWhere);
		changeData.put("EQUIPMENTSTATE_AFTER", equipmentState.getString("NAME"));	//设备状态（后）
		changeData.put("EQUIPMENTUSEPLACE_AFTER", pd.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（后）

		PageData dWhere = new PageData();
		dWhere.put("DEPARTMENT_ID",pd.getString("RESPONSIBLEUNIT"));
		PageData department = departmentService.findById(dWhere);
		changeData.put("RESPONSIBLEUNIT_AFTER", department.getString("NAME"));	//设备责任单位（后）

		PageData uWhere = new PageData();
		uWhere.put("USER_ID",pd.getString("PERSONCHARGE"));
		PageData user = usersService.findById(uWhere);
		changeData.put("PERSONCHARGE_AFTER", user.getString("NAME"));	//设备负责人（后）
		changeData.put("PERSONCHARGEPHONE_AFTER", pd.getString("PERSONCHARGEPHONE"));	//负责人联系电话（后）
//		changeData.put("NEXTINSPECTIONDATE_AFTER", pd.getString("NEXTINSPECTIONDATE"));	//下次检验日期（后）
		changeData.put("PERIOD_AFTER", pd.getString("PERIOD"));	//下次检验日期（后）
		changeData.put("TECHNICALFILENAME_AFTER", pd.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（后）
		changeData.put("TECHNICALFILEPATH_AFTER", pd.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（后）
		changeData.put("REMARKS_AFTER", pd.getString("REMARKS"));	//备注（后）
		specialequipmentchangeService.save(changeData);
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	// @RequiresPermissions("specialequipment: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 = specialequipmentService.list(page);	//列出SpecialEquipment列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	/**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	// @RequiresPermissions("specialequipment: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 = specialequipmentService.findById(pd);	//根据ID读取
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	// @RequiresPermissions("specialequipment: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();
		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		String DATA_IDS = pd.getString("DATA_IDS");
		if(Tools.notEmpty(DATA_IDS)){
			String ArrayDATA_IDS[] = DATA_IDS.split(",");
			pd.put("ArrayDATA_IDS", ArrayDATA_IDS);	//待删除ids

			List<PageData> pdList = specialequipmentService.listByIds(pd);
			PageData changeData;
			String userName = Jurisdiction.getUsername();
			String date = DateUtil.date2Str(new Date());
			for (PageData updateBefour : pdList) {
				changeData = new PageData();
				changeData.put("SPECIALEQUIPMENTCHANGE_ID", this.get32UUID());	//主键
				changeData.put("SPECIALEQUIPMENT_ID", updateBefour.getString("SPECIALEQUIPMENT_ID"));	//主键
				changeData.put("OPERATETYPE", "删除");	//操作类型
				changeData.put("CREATOR", userName);	//添加人
				changeData.put("CREATTIME", date);	//添加时间
				changeData.put("OPERATOR", userName);	//修改人
				changeData.put("OPERATTIME", date);	//修改时间
				changeData.put("ISDELETE", "0");	//是否删除 1-是  0-否
				changeData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
				changeData.put("EQUIPMENTNAME_AFTER", updateBefour.getString("EQUIPMENTNAME"));	//设备名称（前）
				changeData.put("EQUIPMENTMODEL_AFTER", updateBefour.getString("EQUIPMENTMODEL"));	//设备型号（前）
				changeData.put("EQUIPMENTCODE_AFTER", updateBefour.getString("EQUIPMENTCODE"));	//设备代码（前）
				changeData.put("FACTORYCODE_AFTER", updateBefour.getString("FACTORYCODE"));	//出厂编号（前）
//		PageData etWhere = new PageData();
//		etWhere.put("BIANMA",updateBefour.getString("EQUIPMENTTYPE"));
//		PageData equipmentType = dictionariesService.findByBianma(etWhere);
//		changeData.put("EQUIPMENTTYPE_AFTER", equipmentType.getString("NAME"));	//设备类型（前）
				changeData.put("EQUIPMENTTYPE_AFTER", updateBefour.getString("EQUIPMENTTYPENAME"));	//设备类型（前）
//		PageData esWhere = new PageData();
//		esWhere.put("BIANMA",updateBefour.getString("EQUIPMENTSTATE"));
//		PageData equipmentState = dictionariesService.findByBianma(esWhere);
//		changeData.put("EQUIPMENTSTATE_AFTER", equipmentState.getString("NAME"));	//设备状态（前）
				changeData.put("EQUIPMENTSTATE_AFTER", updateBefour.getString("EQUIPMENTSTATENAME"));	//设备状态（前）
				changeData.put("EQUIPMENTUSEPLACE_AFTER", updateBefour.getString("EQUIPMENTUSEPLACE"));	//设备使用地点（前）
				changeData.put("RESPONSIBLEUNIT_AFTER", updateBefour.getString("RESPONSIBLEUNITNAME"));	//设备责任单位（前）
				changeData.put("PERSONCHARGE_AFTER", updateBefour.getString("PERSONCHARGENAME"));	//设备负责人（前）
				changeData.put("PERSONCHARGEPHONE_AFTER", updateBefour.getString("PERSONCHARGEPHONE"));	//负责人联系电话（前）
				changeData.put("NEXTINSPECTIONDATE_AFTER", updateBefour.getString("NEXTINSPECTIONDATE"));	//下次检验日期（前）
				changeData.put("TECHNICALFILENAME_AFTER", updateBefour.getString("TECHNICALFILENAME"));	//设备技术档案（附件）名称（前）
				changeData.put("TECHNICALFILEPATH_AFTER", updateBefour.getString("TECHNICALFILEPATH"));	//设备技术档案（附件）路径（前）
				changeData.put("REMARKS_AFTER", updateBefour.getString("REMARKS"));	//备注（前）
				specialequipmentchangeService.save(changeData);
			}

			specialequipmentService.deleteAll(pd);
			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("是否删除(0:有效 1：删除)");	//15
//		titles.add("添加人");	//16
//		titles.add("添加时间");	//17
//		titles.add("修改人");	//18
//		titles.add("修改时间");	//19
		dataMap.put("titles", titles);
		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());	//企业ID
		List<PageData> varOList = specialequipmentService.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("EQUIPMENTNAME"));	    //1
			vpd.put("var2", varOList.get(i).getString("EQUIPMENTMODEL"));	    //2
			vpd.put("var3", varOList.get(i).getString("EQUIPMENTCODE"));	    //3
			vpd.put("var4", varOList.get(i).getString("FACTORYCODE"));	    //4
			vpd.put("var5", varOList.get(i).getString("EQUIPMENTTYPENAME"));	    //5
			vpd.put("var6", varOList.get(i).getString("EQUIPMENTSTATENAME"));	    //6
			vpd.put("var7", varOList.get(i).getString("EQUIPMENTUSEPLACE"));	    //7
			vpd.put("var8", varOList.get(i).getString("RESPONSIBLEUNITNAME"));	    //8
			vpd.put("var9", varOList.get(i).getString("PERSONCHARGENAME"));	    //9
			vpd.put("var10", varOList.get(i).getString("PERSONCHARGEPHONE"));	    //10
			vpd.put("var11", varOList.get(i).getString("NEXTINSPECTIONDATE"));	    //11
			vpd.put("var12", varOList.get(i).getString("TECHNICALFILENAME"));	    //12
			vpd.put("var13", varOList.get(i).getString("TECHNICALFILEPATH"));	    //13
			vpd.put("var14", varOList.get(i).getString("REMARKS"));	    //14
//			vpd.put("var15", varOList.get(i).get("ISDELETE").toString());	//15
//			vpd.put("var16", varOList.get(i).getString("CREATOR"));	    //16
//			vpd.put("var17", varOList.get(i).getString("CREATTIME"));	    //17
//			vpd.put("var18", varOList.get(i).getString("OPERATOR"));	    //18
//			vpd.put("var19", varOList.get(i).getString("OPERATTIME"));	    //19
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}

	/**下载
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/download")
	@LogAnno(menuType= "综合管理",menuServer= "特种设备",instructionsOperate = "设备管理",instructionsType = "下载")
	public void download(HttpServletResponse response) throws Exception {
		PageData pd = new PageData();
		pd = this.getPageData();
		try {
			pd = specialequipmentService.findById(pd);
			String FILEPATH = pd.getString("TECHNICALFILEPATH");
			String FILENAME = pd.getString("TECHNICALFILENAME");
			//本地
//			FileDownload.fileDownload(response, PathUtil.getProjectpath() + FILEPATH, FILENAME);
////			FileDownload.mfFileDownload(response, this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort() + FILEPATH, FILENAME);	//不好用
			//服务器
			FileDownload.mfFileDownload(response, Const.HTTPFILEURL + FILEPATH, FILENAME);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("=========文件下载异常：可能要下载的文件已经没有了=========");
		}
	}
}
