package com.palmnest.webapp.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.palmnest.application.AppConstants;
import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.bean.Page;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.application.core.util.DateUtils;
import com.palmnest.application.core.util.FileUploadUtils;
import com.palmnest.application.core.util.StringUtil;
import com.palmnest.application.dto.OrgDto;
import com.palmnest.application.dto.WebPageResultDto;
import com.palmnest.model.FloorInfo;
import com.palmnest.model.RoomInfo;
import com.palmnest.model.User;
import com.palmnest.model.VirtUserInfo;
import com.palmnest.model.estateserve.AppUser;
import com.palmnest.model.estateserve.VirUser;
import com.palmnest.model.property.TbOrganization;
import com.palmnest.model.property.VirtualArchitecture;
import com.palmnest.service.AppUserService;
import com.palmnest.service.OrganizationManager;
import com.palmnest.service.estateserve.*;
import com.palmnest.webapp.controller.BaseFormController;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;


@Slf4j
@Controller
@RequestMapping("/admin/virtual/*")
public class VirtualArchController extends BaseFormController {


	@Autowired
	private AppUserManager   appUserManager;
	@Autowired
	private FloorInfoManager floorInfoManager;
	@Autowired
	private RoomInfoManager  roomInfoManager;
	@Autowired
	private VirtUserManager  virtUserManager;
	@Autowired
	private AppUserService   appUserService;


	private VirtualArchManager virtualArchManager;

	@Autowired
	public void setVirtualArchManager(VirtualArchManager virtualArchManager) {
		this.virtualArchManager = virtualArchManager;
	}

	private OrganizationManager organizationManager;

	@Autowired
	public void setOrganizationManager(OrganizationManager organizationManager) {
		this.organizationManager = organizationManager;
	}

	/**
	 * 获取所有企业信息(包含查询接口)
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/jumpVirTualArchList")
	public ModelAndView jumpVirTualArchList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("admin/manage/enterprise");
	}

	/**
	 * 获取所有企业信息(包含查询接口)
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getVirTualArchList")
	@ResponseBody
	public WebPageResultDto getVirTualArchList(HttpServletRequest request) {
		String floorId    = request.getParameter("floorId");
		String roomId     = request.getParameter("roomId");
		String isZuStatus = request.getParameter("isZuStatus");
		String virName    = request.getParameter("virName");
		String orgId      = request.getParameter("orgId");
		int    pageNo     = 1;
		if (StringUtils.isNotBlank(request.getParameter("page"))) {
			pageNo = Integer.parseInt(request.getParameter("page"));
		}
		int pageSize = 10;
		if (StringUtils.isNotBlank(request.getParameter("limit"))) {
			pageSize = Integer.parseInt(request.getParameter("limit"));
		}
		if (StringUtils.isNotEmpty(virName)) {
			virName = virName.trim();
		}
		try {
			User         user = (User) request.getSession().getAttribute("UserCache");
			List<OrgDto> dtos = appUserService.getUserOrgs(user.getId());
			if (StringUtils.isEmpty(orgId) || "0".equals(orgId)) {
				if (dtos != null && dtos.size() > 0) {
					orgId = "";
					for (int i = 0; i < dtos.size(); i++) {
						OrgDto dto = dtos.get(i);
						orgId = orgId + dto.getId() + ";";
					}
				}
			}
			Page             page = virtualArchManager.queryVirtualArchList(orgId, floorId, roomId, isZuStatus, virName, pageNo, pageSize);
			WebPageResultDto dto  = new WebPageResultDto(AppConstants.SUCCESS_CODE, "成功", page == null ? null : page.getItems());
			if (page == null) {
				dto.setCount(Long.parseLong("0"));
			} else {
				dto.setCount(page.getTotalCount());
			}
			return dto;
		} catch (Exception e) {
			log.error("获取企业管理列表界面失败(getVirTualArchList)：" + e.getMessage());
			WebPageResultDto dto = new WebPageResultDto("100", "获取企业管理列表界面(getVirTualArchList)：" + e.getMessage(), null);
			dto.setCount(Long.parseLong("0"));
			return dto;
		}
	}

	/**
	 * 获取楼栋接口
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getBuildInfo")
	public void getBuildInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject          json    = new JSONObject();
		Map<String, Object> map     = new HashMap<String, Object>();
		String              buildId = request.getParameter("buildId");
		TbOrganization      tbOrg   = new TbOrganization();
		if (StringUtils.isEmpty(buildId)) {
			tbOrg = virtualArchManager.getBuild().get(0);
		} else {
			if (organizationManager.get(Integer.parseInt(buildId)) instanceof TbOrganization) {
				tbOrg = (TbOrganization) organizationManager.get(Integer.parseInt(buildId));
			}
		}

		List<FloorInfo> floorList = floorInfoManager.getFloorInfoByBuildId(tbOrg.getId());//获取所有的楼层-----------楼栋
		map.put("tbOrg", tbOrg);
		map.put("floorList", floorList);
		json.put("data", map);
		json.put("code", "200");
		json.put("msg", "");
		StringUtil.charSet(json, request, response);
	}

	/**
	 * 获取所有楼栋接口
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getBuildList")
	public void getBuildList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<TbOrganization> orgList = virtualArchManager.getBuild();
		TbOrganization       orgInfo = new TbOrganization();
		Map<String, Object>  map     = new HashMap<String, Object>();
		if (orgList != null && orgList.size() > 0) {
			orgInfo = orgList.get(0);
			map.put("id", orgInfo.getId());
			map.put("name", orgInfo.getName());
		}
		JSONObject json = new JSONObject();
		json.put("data", map);
		json.put("code", "200");
		json.put("msg", "");
		StringUtil.charSet(json, request, response);
	}


	/**
	 * 导入模板接口
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/importVirtualArchData", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void importVirtualArchData(@RequestParam("excelFile") MultipartFile excelFile, HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject          json   = new JSONObject();
		Map<String, Object> retMap = null;
		TbOrganization      tb     = virtualArchManager.getBuild().get(0);
		User                userLi = (User) request.getSession().getAttribute("UserCache");//----------联调时需放开注释
		try {
			retMap = virtualArchManager.saveImportVirtualData(excelFile.getInputStream());
			int bugCount = Integer.parseInt(retMap.get("bugCount").toString());
			if (bugCount > 0) {
				json.put("data", retMap);
				json.put("code", "100");
				json.put("msg", retMap.get("bugStr").toString());
				StringUtil.charSet(json, request, response);
			} else {
				List<Object> list = (List<Object>) retMap.get("userList");
				try {
					virtualArchManager.saveImportVir(list, userLi, tb);//企业保存
					json.put("data", retMap);
					json.put("code", "200");
					json.put("msg", "");
					StringUtil.charSet(json, request, response);
				} catch (Exception e) {
					log.error(e.getMessage());
					json.put("data", retMap);
					json.put("code", "100");
					json.put("msg", e.getMessage());
					StringUtil.charSet(json, request, response);
				}

			}
		} catch (Exception e) {
			log.error(e.getMessage());
			json.put("data", retMap);
			json.put("code", "100");
			json.put("msg", e.getMessage());
			StringUtil.charSet(json, request, response);
			throw new Exception(e);
		}


	}

	/**
	 * 添加企业获取楼宇、楼层、房间信息
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/saveVir", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void saveVir(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject          json = new JSONObject();
		Map<String, Object> map  = new HashMap<String, Object>();
		try {
			List<TbOrganization> orgList = virtualArchManager.getBuild();
			int                  orgId   = 10;
			if (orgList != null && orgList.size() > 0) {
				orgId = orgList.get(0).getId();
			}
			List<FloorInfo> floorList = floorInfoManager.getFloorInfoByBuildId(orgId);
			map.put("orgList", orgList);
			map.put("floorList", floorList);
			json.put("data", map);
			json.put("code", "200");
			json.put("msg", "");
			StringUtil.charSet(json, request, response);
		} catch (Exception e) {
			log.error(e.getMessage());
			json.put("data", "");
			json.put("code", "100");
			json.put("msg", e.getMessage());
			StringUtil.charSet(json, request, response);
		}

	}

	/**
	 * 添加企业(保存)
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/saveVirtualArch", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	@ResponseBody
	public AppResultDto saveVirtualArch(@RequestBody VirUser virUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
		TbOrganization            tb                  = virtualArchManager.getBuild().get(0);
		User                      user                = (User) request.getSession().getAttribute("UserCache");//----------联调时需放开注释
		JSONObject                json                = new JSONObject();
		List<AppUser>             userList            = virUser.getUserList();
		List<AppUser>             list                = new ArrayList<AppUser>();
		VirtualArchitecture       virtualArchitecture = virUser.getVirtualArchitecture();
		String                    cusNumber           = virtualArchitecture.getCustomerNumber();
		List<VirtualArchitecture> virList             = virtualArchManager.getVirByCode(cusNumber);
		try {
			AppResultDto dto = virtualArchManager.saveVirUser(virUser, tb, user, userList, list, virtualArchitecture, virList);
			return dto;
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
			return AppResultUtil.createErrorDto("100", "操作失败");
		}
	}


	/**
	 * 修改企业
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateVirtualArch")
	public void updateVirtualArch(HttpServletRequest request, HttpServletResponse response, VirtualArchitecture virtualArchitecture) throws Exception {
		JSONObject          json = new JSONObject();
		VirtualArchitecture vir  = virtualArchManager.get(virtualArchitecture.getId());
		String              user = request.getParameter("userList");
		try {
			List<AppUser> userList = JSON.parseArray(user, AppUser.class);
			if (vir != null) {
				virtualArchitecture.setType("1");
				virtualArchitecture.setModifyTime(new Date());
				virtualArchitecture.setFreeLenTime(virtualArchitecture.getFreeLenTime() == null ? BigDecimal.ZERO : virtualArchitecture.getFreeLenTime());
				virtualArchitecture.setRemainderTime(virtualArchitecture.getRemainderTime() == null ? BigDecimal.ZERO : virtualArchitecture.getRemainderTime());
				virtualArchManager.updateModel(virtualArchitecture);
				for (int i = 0; i < userList.size(); i++) {
					AppUser appUser = userList.get(i);
					appUser.setModifyTime(new Date());
					appUser.setRoleType("1");
					appUserManager.updateModel(appUser);
				}
				json.put("msg", "");
				json.put("data", virtualArchitecture);
				json.put("code", "200");
				StringUtil.charSet(json, request, response);
			} else {
				json.put("msg", "获取不到企业信息");
				json.put("data", virtualArchitecture);
				json.put("code", "100");
				StringUtil.charSet(json, request, response);
			}
		} catch (Exception e) {
			json.put("msg", e.getMessage());
			json.put("data", virtualArchitecture);
			json.put("code", "100");
			StringUtil.charSet(json, request, response);
		}


	}


	/**
	 * 修改企业(入口按钮)
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getVirtualById", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void getVirtualById(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map         = new HashMap<String, Object>();
		JSONObject          json        = new JSONObject();
		String              virId       = request.getParameter("virId");
		List<AppUser>       appUserList = new ArrayList<AppUser>();
		if (StringUtils.isNotBlank(virId)) {
			VirtualArchitecture vir = virtualArchManager.get(Integer.parseInt(virId));
			map.put("virInfo", vir);
			if (null != vir.getEnterTime()) {
				map.put("virInfoEnterTime", DateUtils.getTime(vir.getEnterTime(), "yyyy-MM-dd"));
			} else {
				map.put("virInfoEnterTime", "");
			}
			if (vir != null) {
				List<VirtUserInfo> vuserList = virtUserManager.getVirtUserByVirtId(vir.getId());
				if (vuserList != null && vuserList.size() > 0) {
					for (int i = 0; i < vuserList.size(); i++) {
						VirtUserInfo vuser   = vuserList.get(i);
						AppUser      appUser = appUserManager.get(vuser.getUserId());
						appUser.setReOrder(vuser.getReorder());
						appUserList.add(appUser);
					}
				}
//				List<AppUser> appUserList=virtualArchManager.getAppUserByVirAndIsRes(Integer.parseInt(virId));
				List<TbOrganization> orgList = virtualArchManager.getBuild();
				int                  orgId   = 10;
				if (orgList != null && orgList.size() > 0) {
					orgId = orgList.get(0).getId();
				}
				List<FloorInfo> floorList = floorInfoManager.getFloorInfoByBuildId(orgId);

				List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();

				String floorIds = vir.getFloorIds();
				if (StringUtils.isNotBlank(floorIds)) {
					floorIds = floorIds.replace(";", ",");
					List<FloorInfo> flList = floorInfoManager.getFloorListByFloorIds(floorIds);
					for (int k = 0; k < flList.size(); k++) {
						FloorInfo      floor    = flList.get(k);
						String         roomIds  = vir.getRoomIds().replace(";", ",");
						List<RoomInfo> roomList = roomInfoManager.getRoomListByRoomIds(floor.getId(), roomIds);
						//循环选中的楼层
						for (int i = 0; i < roomList.size(); i++) {
							Map<String, String> strMap   = new HashMap<String, String>();
							RoomInfo            roomInfo = roomList.get(i);
							if (roomInfo != null) {
								strMap.put("floorId", floor.getId().toString());
								strMap.put("floorName", floor.getName());
								strMap.put("roomId", roomInfo.getId().toString());
								strMap.put("roomName", roomInfo.getName());
								mapList.add(strMap);
							}
						}
					}
				}
				map.put("mapList", mapList);
				map.put("orgList", orgList);
				map.put("floorList", floorList);
				map.put("appUserList", appUserList);
				FileUploadUtils fileUploadUtils = new FileUploadUtils();
				fileUploadUtils.init();
				String businesUrl = "";
				if (StringUtils.isNotEmpty(vir.getBusinessImageUrl())) {
					businesUrl = fileUploadUtils.fullVisitPath(vir.getBusinessImageUrl());
				}
				String attorneyUrl = "";
				if (StringUtils.isNotEmpty(vir.getPowerAttorneyImageUrl())) {
					attorneyUrl = fileUploadUtils.fullVisitPath(vir.getPowerAttorneyImageUrl());
				}
				String faceUrl = "";
				if (StringUtils.isNotEmpty(vir.getPowerFaceImageUrl())) {
					faceUrl = fileUploadUtils.fullVisitPath(vir.getPowerFaceImageUrl());
				}
				String nationUrl = "";
				if (StringUtils.isNotEmpty(vir.getPowerNationImageUrl())) {
					nationUrl = fileUploadUtils.fullVisitPath(vir.getPowerNationImageUrl());
				}
				map.put("businessImageUrl", businesUrl);
				map.put("attorneyImageUrl", attorneyUrl);
				map.put("faceImageUrl", faceUrl);
				map.put("nationImageUrl", nationUrl);

				json.put("code", "200");
				json.put("msg", "");
				json.put("data", map);
				StringUtil.charSet(json, request, response);
			}
		}


	}

	/**
	 * 上传图片返回图片路径
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/getAttMagePath", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void getAttMagePath(HttpServletRequest request, HttpServletResponse response) {
		String              virIcon = request.getParameter("serviceIcon");
		String              path    = FileUploadUtils.getBase64ImageUrl(virIcon);
		JSONObject          json    = new JSONObject();
		Map<String, Object> map     = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(path)) {
			FileUploadUtils fileUploadUtils = new FileUploadUtils();
			fileUploadUtils.init();
			String preview = fileUploadUtils.fullVisitPath(path);
			map.put("path", path);
			map.put("preview", preview);
			json.put("data", map);//附件存储的路径
			json.put("code", "200");
			json.put("msg", "");
			StringUtil.charSet(json, request, response);
		} else {
			json.put("data", "");//附件存储的路径
			json.put("code", "100");
			json.put("msg", "上传图片失败");
			StringUtil.charSet(json, request, response);
		}
	}


	/**
	 * 上传图片返回图片路径
	 *
	 * @param request
	 * @param response
	 */
//	@RequestMapping(value="/getImagePath", method = { RequestMethod.GET, RequestMethod.POST }, produces = "application/json;charset=utf-8")
	@RequestMapping(value = "/getImagePath")
	@ResponseBody
	public AppResultDto getImagePath(HttpServletRequest request, HttpServletResponse response) {
		String              virIcon = request.getParameter("serviceIcon");
		String              path    = FileUploadUtils.getBase64ImageUrl(virIcon);
		Map<String, Object> map     = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(path)) {
			FileUploadUtils fileUploadUtils = new FileUploadUtils();
			fileUploadUtils.init();
			String preview = fileUploadUtils.fullVisitPath(path);
			map.put("path", path);
			map.put("preview", preview);
//			json.put("data", map);//附件存储的路径
//			json.put("code", "200");
//			json.put("msg", "");
//			StringUtil.charSet(json, request, response);
			return AppResultUtil.createCommonDto("200", "成功", map);
		} else {
//			json.put("data", "");//附件存储的路径
//			json.put("code", "100");
//			json.put("msg", "上传图片失败");
//			StringUtil.charSet(json, request, response);
			return AppResultUtil.createErrorDto("500", "上传图片失败");
		}
	}

	/**
	 * 重新上传图片后确认修改
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/updateVirtualImage", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void updateVirtualImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject json          = new JSONObject();
		String     virId         = request.getParameter("virId");
		String     businessImage = request.getParameter("businessImage");
		String     attorImage    = request.getParameter("attorImage");
		String     nationImage   = request.getParameter("nationImage");
		String     faceImage     = request.getParameter("faceImage");

		if (StringUtils.isNotBlank(virId)) {
			VirtualArchitecture vir = virtualArchManager.get(Integer.parseInt(virId));
			if (vir != null) {
				vir.setBusinessImageUrl(businessImage);
				vir.setPowerAttorneyImageUrl(attorImage);
				vir.setPowerFaceImageUrl(faceImage);
				vir.setPowerNationImageUrl(nationImage);
				virtualArchManager.updateModel(vir);
				json.put("code", "200");
				json.put("msg", "");
				json.put("data", vir);
				StringUtil.charSet(json, request, response);
			}
		} else {
			json.put("code", "100");
			json.put("msg", "企业ID为空");
			json.put("data", "");
			StringUtil.charSet(json, request, response);
		}
	}

	/**
	 * 判断企业名称不能重复
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/getVirByCusNumber", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void getVirByCusNumber(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject json      = new JSONObject();
		String     cusNumber = request.getParameter("cusNumber");
		int        virId     = 0;
		if (StringUtils.isNotEmpty(request.getParameter("virId"))) {
			virId = Integer.parseInt(request.getParameter("virId"));
		}
		if (StringUtils.isNotBlank(cusNumber)) {
			List<VirtualArchitecture> list = virtualArchManager.getVirByCode(cusNumber);
			if (list != null && list.size() > 0) {
				VirtualArchitecture vir = list.get(0);
				if (vir.getId() != virId) {
					if (cusNumber.equals(vir.getCustomerNumber())) {
						json.put("code", "100");
						json.put("data", "");
						json.put("msg", "企业编码不能重复");
						StringUtil.charSet(json, request, response);
					} else {
						json.put("code", "200");
						json.put("data", "");
						json.put("mdg", "");
						StringUtil.charSet(json, request, response);
					}
				} else {
					json.put("code", "200");
					json.put("data", "");
					json.put("msg", "");
					StringUtil.charSet(json, request, response);
				}

			} else {
				json.put("code", "200");
				json.put("data", "");
				json.put("msg", "");
				StringUtil.charSet(json, request, response);
			}
		} else {
			json.put("code", "100");
			json.put("data", "");
			json.put("msg", "企业编码不允许为空");
			StringUtil.charSet(json, request, response);
		}
	}

	/**
	 * 查看证件
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/getVirImages", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void getVirImages(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject          json    = new JSONObject();
		String              virId   = request.getParameter("virId");
		VirtualArchitecture virInfo = virtualArchManager.get(Integer.parseInt(virId));
		Map<String, String> map     = new HashMap<String, String>();
		if (virInfo != null) {
			map.put("businessImage", virInfo.getBusinessImageUrl());
			map.put("attorneyImage", virInfo.getPowerAttorneyImageUrl());
			map.put("faceImage", virInfo.getPowerFaceImageUrl());
			map.put("nationImage", virInfo.getPowerNationImageUrl());
			FileUploadUtils fileUploadUtils = new FileUploadUtils();
			fileUploadUtils.init();
			String businesUrl = "";
			if (StringUtils.isNotEmpty(virInfo.getBusinessImageUrl())) {
				businesUrl = fileUploadUtils.fullVisitPath(virInfo.getBusinessImageUrl());
			}
			String attorneyUrl = "";
			if (StringUtils.isNotEmpty(virInfo.getPowerAttorneyImageUrl())) {
				attorneyUrl = fileUploadUtils.fullVisitPath(virInfo.getPowerAttorneyImageUrl());
			}
			String faceUrl = "";
			if (StringUtils.isNotEmpty(virInfo.getPowerFaceImageUrl())) {
				faceUrl = fileUploadUtils.fullVisitPath(virInfo.getPowerFaceImageUrl());
			}
			String nationUrl = "";
			if (StringUtils.isNotEmpty(virInfo.getPowerNationImageUrl())) {
				nationUrl = fileUploadUtils.fullVisitPath(virInfo.getPowerNationImageUrl());
			}


			map.put("businessImageUrl", businesUrl);
			map.put("attorneyImageUrl", attorneyUrl);
			map.put("faceImageUrl", faceUrl);
			map.put("nationImageUrl", nationUrl);
			json.put("data", map);
			json.put("code", "200");
			json.put("msg", "");
			StringUtil.charSet(json, request, response);
		} else {
			json.put("data", "");
			json.put("code", "100");
			json.put("msg", "该企业无效");
			StringUtil.charSet(json, request, response);
		}

	}

	/**
	 * 删除企业
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/removeVirInfo", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=utf-8")
	public void removeVirInfo(HttpServletRequest request, HttpServletResponse response) {
		JSONObject          json    = new JSONObject();
		String              virId   = request.getParameter("virId");
		VirtualArchitecture virInfo = virtualArchManager.get(Integer.parseInt(virId));
		if (virInfo != null) {
			try {
				virtualArchManager.remove(virInfo);
				json.put("data", "");
				json.put("code", "200");
				json.put("msg", "");
				StringUtil.charSet(json, request, response);
			} catch (Exception e) {
				json.put("data", "");
				json.put("code", "100");
				json.put("msg", e.getMessage());
				StringUtil.charSet(json, request, response);
			}

		} else {
			json.put("data", "");
			json.put("code", "100");
			json.put("msg", "该企业无效");
			StringUtil.charSet(json, request, response);
		}
	}


	/**
	 * 修改企业的时长
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/updateVirTimeInfo")
	@ResponseBody
	public AppResultDto updateVirTimeInfo(HttpServletRequest request, HttpServletResponse response) {
		String virId         = request.getParameter("virId");
		String freeLenTime   = request.getParameter("freeLenTime");
		String remainderTime = request.getParameter("remainderTime");
		String msg           = "";
		if (StringUtils.isNotEmpty(virId)) {
			try {
				msg = virtualArchManager.updateVirInfo(virId, remainderTime, freeLenTime);
				String code = "";
				if (StringUtils.isEmpty(msg)) {
					code = "200";
				} else {
					code = "100";
				}
				return AppResultUtil.createCommonDto(code, msg, null);
			} catch (Exception e) {
				e.printStackTrace();
				msg = "修改企业时长失败：" + e.getMessage();
				log.error("修改企业时长失败：" + e.getMessage());
			}
		}
		return AppResultUtil.createErrorDto("100", msg);
	}


}
