package com.landtool.lanbase.modules.res.controller; import java.io.File; import java.io.IOException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.druid.support.json.JSONUtils; import com.google.gson.JsonObject; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.serializer.SerializerFeature; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.map.EsbToken; import com.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.Excel; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.org.service.OrgUnitService; import com.landtool.lanbase.modules.org.service.OrgUserService; import com.landtool.lanbase.modules.res.entity.Res_ApplyRecommend; import com.landtool.lanbase.modules.res.entity.Res_Catalog; import com.landtool.lanbase.modules.res.entity.Res_Ext3D; import com.landtool.lanbase.modules.res.entity.Res_ExtFileSource; import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate; import com.landtool.lanbase.modules.res.entity.Res_ExtInterFaceService; import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl; import com.landtool.lanbase.modules.res.entity.Res_ExtSpaceServer; import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinApplyRecommend; import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinApplyRecommendInfo; import com.landtool.lanbase.modules.res.service.ResApplyRecommendService; import com.landtool.lanbase.modules.res.service.ResCatalogService; import com.landtool.lanbase.modules.res.service.ResExt3DService; import com.landtool.lanbase.modules.res.service.ResExtFileSourceService; import com.landtool.lanbase.modules.res.service.ResExtIntegrateService; import com.landtool.lanbase.modules.res.service.ResExtInterFaceService; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.res.service.ResExtSpaceServerService; import com.landtool.lanbase.modules.res.service.ResExtThemeMapService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.entity.SysSysteminfo; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; /** * 申请批复(推荐) */ @Controller public class ResApplyRecommendController extends AbstractController { @Autowired private ResApplyRecommendService resApplyRecommendService; @Autowired public ResMainInfoService resMainInfoService; @Autowired private SysTemPropertyConfig sysConfig; @Autowired private OrgUserService orgUserService; @Autowired private SysFieldvalueService FieldUtils; @Autowired private OrgUnitService orgUnitService; @Autowired private ResCatalogService resCatalogService; @Autowired private ResExtMapUrlService resExtMapUrlService; @Autowired private ResExtThemeMapService resExtThemeMapService; @Autowired private ResExtInterFaceService resExtInterFaceService; @Autowired private ResExtFileSourceService resExtFileSourceService; @Autowired private ResExtIntegrateService resExtIntegrateService; @Autowired private ResExtSpaceServerService resExtSpaceServerService; @Autowired private ResExt3DService resExt3DService; public static String strMuLu = ""; @ResponseBody @RequestMapping("/res/resApplyRecommend/insertSelectiveAndUpdate") public String insertSelectiveAndUpdate(Res_ApplyRecommend record, Long resourceid,Integer isSystem) { int result; Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend(); // 获取登录人姓名和登录人id和登录人部门id applyRecommend.setAppuserid(getUserId().toString()); applyRecommend.setIsrecommend(0); applyRecommend.setResourceid(Integer.parseInt(resourceid + "")); // 判断 id是否存在 存在则删除原有记录,新增记录 不存在就 添加 Integer isDelete = 0; Long timenum = new Date().getTime(); if(isSystem == null){ Res_ApplyRecommend resApplyRecommend = resApplyRecommendService.selectByResApplyRecommend(applyRecommend); if(resApplyRecommend != null && !resApplyRecommend.getAuditresult().equals(0) && //批复后、过了申请有效截止时间 (resApplyRecommend.getEffendtime() == null || resApplyRecommend.getEffendtime().getTime() < timenum)){ isDelete = 1; } if(isDelete == 1){ resApplyRecommendService.deleteByPrimaryKey(resApplyRecommend.getAppid()); record.setAppid(null); } } record.setIsrecommend(0); record.setAuditresult(0); record.setAppuserid(getUserId().toString()); record.setAppdate(new Timestamp(new Date().getTime())); //TODO 用户插入 Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid.intValue()); record.setAudituserid(Math.toIntExact(res_mainInfo.getCreateuserid())); //算时间天数 Integer effendday = record.getEffendday(); Integer apptype = null==record.getApptype()?0:record.getApptype(); if(effendday != null && effendday != 0){ long time = record.getAppdate().getTime(); long day = effendday * 24 * 60 * 60 * 1000; time += day; record.setEffendtime(new Timestamp(new Date(time).getTime())); }else { //处理申请天数默认情况 switch (apptype){ case 0: //个人申请默认30天 effendday=30; break; case 1: //单位申请默认360天 effendday=360; break; case 3: //系统申请永久 effendday=0; break; } // long time = record.getAppdate().getTime(); // long day = Long.valueOf(effendday) * 24 * 60 * 60 * 1000; // time += day; // record.setEffendtime(new Timestamp(new Date(time).getTime())); record.setEffendtime(new Timestamp(DateUtils.addDays(record.getAppdate(), effendday).getTime())); } if(apptype==3&&effendday==0){ //系统申请永久 null record.setEffendtime(null); } int applyRecommendResult = resApplyRecommendService.insertSelective(record); if (applyRecommendResult == 1) { result = 1; } else { result = 0; } return "{\"result\":\"" + result + "\"}"; } /** * 个人中心——申请资源 */ @ResponseBody @RequestMapping("/res/resApplyRecommend/shenQingZiYuan") public Result shenQingZiYuan(Res_ApplyRecommend recommend) { recommend.setAppuserid(getUserId().toString()); List list = resApplyRecommendService.shenQingZiYuan(recommend); StringBuilder str = new StringBuilder(); str.append("["); List> maps = new LinkedList<>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap<>(); map.put("appid", list.get(i).getAppid()); map.put("title", list.get(i).getTitle()); map.put("fulltitle", list.get(i).getTitle()); map.put("auditresult", list.get(i).getAuditresult()); map.put("resourceid", list.get(i).getResourceid()); maps.add(map); } return Result.ok().put("result", maps); } /** * 个人中心——我的资源(未完成) */ @ResponseBody @RequestMapping("/res/resApplyRecommend/woDeZiYuan") public String woDeZiYuan(Res_ApplyRecommend recommend) { recommend.setAppuserid(getUserId().toString()); List list = resApplyRecommendService.shenQingZiYuan(recommend); StringBuilder str = new StringBuilder(); str.append("["); for (int i = 0; i < list.size(); i++) { if (i != 0) { str.append(","); } str.append("{"); String title = list.get(i).getTitle(); if(list.get(i).getTitle().length() > 15) { title = title.substring(0,15) + "..."; } str.append("'title':'" + title + "',"); str.append("'resourceid':'" + list.get(i).getResourceid() + "',"); str.append("}"); } str.append("]"); return str.toString(); } /** * 资源申请信息填写页面 */ @RequestMapping("/res/resApplyRecommend/ziYuanShenQing") public String ziYuanShenQing(Model model, Integer resourceid) { // 获取登录人姓名和登录人id和登录人部门id OrgUser user = getUser(); String unitid = orgUserService.getDefaultUnit(user.getUserid()).getUnitid().toString();// user.getOrguserunits().get(0).getUnitid().toString(); String chinesename = user.getChinesename();// entity.getChinesename(); Long userid = user.getUserid();// entity.getUserid(); Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend(); applyRecommend.setIsrecommend(0); applyRecommend.setAppuserid(userid.toString()); applyRecommend.setResourceid(resourceid); Res_ApplyRecommend res_applyRecommend = resApplyRecommendService.selectByResApplyRecommend(applyRecommend); // 获取当前时间并转化为yyyy-MM-dd格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String newDate = sdf.format(new Date()); // 新增页面 //if (res_applyRecommend == null) { res_applyRecommend = new Res_ApplyRecommend(); res_applyRecommend.setResourceid(resourceid); res_applyRecommend.setAppuserid(userid.toString()); res_applyRecommend.setAppunitid((unitid)); model.addAttribute("Appdate", newDate); // } else { // String appdate = sdf.format(res_applyRecommend.getAppdate()); // model.addAttribute("Appdate", appdate); // if (res_applyRecommend.getEffendtime() != null) { // String effendtime = sdf.format(res_applyRecommend.getEffendtime()); // model.addAttribute("EffEndtime", effendtime); // } // } // 获取资源信息名称 Res_MainInfo record = resMainInfoService.selectByPrimaryKey(resourceid); String title = record.getTitle(); // 获取申请类型列表 LinkedHashMap AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus"); // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示 LinkedHashMap sysList = getUserManagerSystemList(userid); if(sysList.size() > 0){ AppStatusList.put("3","应用申请"); } model.addAttribute("shenqin", sysList); //有效天数 if(res_applyRecommend != null && res_applyRecommend.getEffendtime() != null && res_applyRecommend.getAppdate() != null){ int day = (int)((res_applyRecommend.getEffendtime().getTime() - res_applyRecommend.getAppdate().getTime()) /1000*3600*24); res_applyRecommend.setEffendday(day); } // 获取资源使用方式列表 LinkedHashMap ResUseTypeList = FieldUtils.getFieldListByKey("ResUseType"); model.addAttribute("resApplyRecommend", res_applyRecommend); model.addAttribute("AppStatusList", AppStatusList); model.addAttribute("ResUseTypeList", ResUseTypeList); model.addAttribute("title", title); model.addAttribute("appuser", chinesename); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "ResManage/ResApplyRecommend/ZiYuanShenQing"; } /** * 获取后台用户对负责应用系统列表 * @param userid * @return */ private LinkedHashMap getUserManagerSystemList(Long userid) { LinkedHashMap map = new LinkedHashMap(); List systemList = new ArrayList(); try { String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysListByUserId/" + userid; systemList = HttpOperateUtils.getJsonObjectArray(url, SysSysteminfo.class); if (systemList != null) { for (int i = 0; i < systemList.size(); i++) { SysSysteminfo item = systemList.get(i); map.put(item.getAppid().toString(), item.getAppfullname()); } } } catch (IOException e) { e.printStackTrace(); } return map; } /** * 查询申请资源列表功能 */ @ResponseBody @RequestMapping("/res/resApplyRecommend/selectShenQingZiYuanGD") public Result selectShenQingZiYuanGD(Res_MainInfo resMainInfo, PageBean pageBean, Integer auditresult) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); MainInfoJoinApplyRecommend record = new MainInfoJoinApplyRecommend(); record.setAppuserid(getUserId().toString()); record.setTitle(resMainInfo.getTitle()); record.setResourceclass(resMainInfo.getResourceclass()); record.setPubdateBegin(resMainInfo.getPubdateBegin()); record.setPubdatefinish(resMainInfo.getPubdatefinish()); record.setAuditresult(auditresult); List mainInfoJoinCatalogList = resApplyRecommendService.selectResMainInfoShenQingZiYuan(record); int countNums = (int) ((Page) mainInfoJoinCatalogList).getTotal(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(mainInfoJoinCatalogList); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 StringBuilder rsb = new StringBuilder(); String leixin = ""; List> maps = new LinkedList<>(); for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) { leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass()); Integer shenqingStatus = mainInfoJoinCatalogList.get(i).getAuditresult(); String shenqingStatusStr = ""; if(shenqingStatus != null) { switch (shenqingStatus) { case 0: shenqingStatusStr = "未批复"; break; case 1: shenqingStatusStr = "已通过"; break; case 2: shenqingStatusStr = "未通过"; break; } } else { shenqingStatusStr = "未批复"; } String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid()); Map map = new HashMap<>(); map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid()); map.put("appid", mainInfoJoinCatalogList.get(i).getAppid()); map.put("title", mainInfoJoinCatalogList.get(i).getTitle()); map.put("resourceclass", leixin); map.put("shenqingdate", sdf.format(mainInfoJoinCatalogList.get(i).getAppdate())); map.put("pubunitid", unitname); map.put("shenqingstatus", shenqingStatusStr); maps.add(map); } return Result.ok().put("totalCount", countNums).put("topics", maps); } // 申请资源导出 @ResponseBody @RequestMapping("/res/resApplyRecommend/ShenQingZiYuanexcel") public String ShenQingZiYuanexcel(HttpServletResponse response, MainInfoJoinApplyRecommend resMainInfo) { MainInfoJoinApplyRecommend record = new MainInfoJoinApplyRecommend(); record.setAppuserid(getUserId().toString()); record.setTitle(resMainInfo.getTitle()); record.setResourceclass(resMainInfo.getResourceclass()); record.setPubdateBegin(resMainInfo.getPubdateBegin()); record.setPubdatefinish(resMainInfo.getPubdatefinish()); record.setAuditresult(resMainInfo.getAuditresult()); List mainInfoJoinCatalogList = resApplyRecommendService .selectResMainInfoShenQingZiYuan(record); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 StringBuilder rsb = new StringBuilder(); String leixin = ""; List> maps = new LinkedList<>(); for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) { leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass()); Integer shenqingStatus = mainInfoJoinCatalogList.get(i).getAuditresult(); String shenqingStatusStr = ""; if(shenqingStatus != null) { switch (shenqingStatus) { case 0: shenqingStatusStr = "未批复"; break; case 1: shenqingStatusStr = "已通过"; break; case 2: shenqingStatusStr = "未通过"; break; } } else { shenqingStatusStr = "未批复"; } String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid()); Map map = new HashMap<>(); map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid()); map.put("appid", mainInfoJoinCatalogList.get(i).getAppid()); map.put("title", mainInfoJoinCatalogList.get(i).getTitle()); map.put("resourceclass", leixin); map.put("shenqingdate", sdf.format(mainInfoJoinCatalogList.get(i).getAppdate())); map.put("pubunitid", unitname); map.put("shenqingstatus", shenqingStatusStr); maps.add(map); } // rsb.append("]}"); String a[] = { "资源id", "资源名称", "资源类型", "发布单位", "申请时间", "批复状态" }; try { String Filename = Excel.SQgoing(response, a, JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue),sysConfig.getUploadPath()+"excel\\"); String path2 = "/uploadPath/excel/"; String desFile = path2 + Filename; System.out.println(desFile); return desFile; } catch (IOException e) { e.printStackTrace(); return null; } } /** * 资源推荐(个人、单位) * @param resourceid 资源ID * @param RecommendType 推荐方式(个人、单位) * @param idStr 推荐ID列表(个人、单位) * @return */ @ResponseBody @RequestMapping("/res/resApplyRecommend/ResourceRecommend") public String resourceRecommend(int resourceid, int RecommendType, String idStr) { try { String[] idList = idStr.split("\\|"); String[] list = new String[idList.length]; // 获取当前时间 Timestamp audittime = new Timestamp(new Date().getTime()); // 删除已有推荐 Res_ApplyRecommend entity = new Res_ApplyRecommend(); entity.setResourceid(resourceid); entity.setApptype(RecommendType); List res_applyRecommendList = resApplyRecommendService .getRecommendListByResourceid(entity); for (Res_ApplyRecommend resApplyRecommend : res_applyRecommendList) { resApplyRecommendService.deleteByPrimaryKey(resApplyRecommend.getAppid()); } // 新增现有推荐 for (int i = 0; i < idList.length; i++) { if (list.equals(idList[i])) { continue; } else { list[i] = idList[i]; Res_ApplyRecommend resApplyRecommend = new Res_ApplyRecommend(); resApplyRecommend.setResourceid(resourceid);// 资源ID if (RecommendType == 0) { resApplyRecommend.setAppuserid(idList[i]); // 用户ID resApplyRecommend.setAppunitid("-1"); // 单位ID(非空) } else if (RecommendType == 1) { resApplyRecommend.setAppuserid("-1"); // 用户ID(非空) resApplyRecommend.setAppunitid(idList[i]); // 单位ID } resApplyRecommend.setApptype(RecommendType); // 推荐方式 resApplyRecommend.setAppdate(audittime); // 推荐时间 resApplyRecommend.setIsrecommend(1); // 是否推荐 resApplyRecommendService.insertSelective(resApplyRecommend);// 插入数据库 } } // 获取推荐记录 String userIds = ""; String unitIds = ""; Res_ApplyRecommend entitys = new Res_ApplyRecommend(); entitys.setResourceid(resourceid); List resApplyRecommendList = resApplyRecommendService .getRecommendListByResourceid(entitys); for (Res_ApplyRecommend resApplyRecommend : resApplyRecommendList) { if (resApplyRecommend.getApptype() == 0) { if (!userIds.isEmpty()) userIds += ","; userIds += resApplyRecommend.getAppuserid(); } else if (resApplyRecommend.getApptype() == 1) { if (!unitIds.isEmpty()) unitIds += ","; unitIds += resApplyRecommend.getAppunitid(); } } return "{'success': true, 'msg': '', 'userIds': '" + userIds + "', 'unitIds': '" + unitIds + "'}"; } catch (Exception e) { return "{'success': false, 'msg': '" + e.getMessage() + "'}"; } } // ============================================================================ // 后台管理 // ============================================================================ /** * 后台管理 - 列表页面 */ @RequestMapping("/res/manage/applyrecommend/index") public String index(Model model) { LinkedHashMap applyStatusList = FieldUtils.getFieldListByKey("ApplyStatus");// 获取申请类型列表 model.addAttribute("applyStatusList", applyStatusList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "manage/applyrecommend/index"; } /** * 后台管理 - 获取列表 */ @ResponseBody @RequestMapping("/res/manage/applyrecommend/getlist") @LogAction("资源管理,申请批复,申请批复列表查询,查询") public Result getList(Res_ApplyRecommend resApplyRecommend, PageBean pageBean) throws IOException { PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); // 查询当前登陆用户是否是超级管理员 是:查所有 不是:查自己的 Boolean adminFlag=true; Subject subject = SecurityUtils.getSubject(); if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) { // 如果是超级管理员,不添加用户id,查询所有。如果不是 添加id 查询单个 adminFlag=false; resApplyRecommend.setExistPermission(getUserId().toString()); // resApplyRecommend.setExistPermission("4"); } resApplyRecommend.setCreateuserid(Math.toIntExact(getUserId())); resApplyRecommend.setAudituserid(Math.toIntExact(getUserId())); List list = resApplyRecommendService.selectResApplyreCommend(resApplyRecommend); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); LinkedHashMap ApplyStatusList = FieldUtils.getFieldListByKey("ApplyStatus");// 获取申请类型列表 OrgUser orgUser = getUser(); Long userid = orgUser.getUserid(); userid=null==userid?-1:userid; List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { // 查询id对应的name String appusername = ""; MainInfoJoinApplyRecommendInfo recommendInfo = list.get(i); if (recommendInfo.getAppuserid() != null) { OrgUser eobj = orgUserService.queryObject(Long.parseLong(recommendInfo.getAppuserid())); appusername = eobj != null ? (eobj.getChinesename() != null ?eobj.getChinesename():"") : ""; } // 判断当前用户 与 资源用户是否一致 如果一致那么显示 是否批复 Integer isDangQianYongHu = 0; Integer createuserid = recommendInfo.getCreateuserid(); if (null!=createuserid && userid.toString().equals(createuserid.toString())) { isDangQianYongHu = 1; } if(adminFlag&&isDangQianYongHu==0){ isDangQianYongHu=1; } Integer apptype = recommendInfo.getApptype(); String apptypename = ApplyStatusList.get(apptype.toString()); Map map = new HashMap<>(); map.put("resourceid", recommendInfo.getResourceid()); map.put("appid", recommendInfo.getAppid()); map.put("title", recommendInfo.getTitle()); map.put("appuserid", appusername); map.put("applycount", recommendInfo.getApplycount()); map.put("auditresult", recommendInfo.getAuditresult()); map.put("replycount", recommendInfo.getReplycount()); map.put("insteadaudit", recommendInfo.getInsteadaudit()); map.put("appdate", sdf.format(recommendInfo.getAppdate())); map.put("isDangQianYongHu", isDangQianYongHu); map.put("apptype", apptypename); map.put("appreason", (recommendInfo.getAppreason() != null ? recommendInfo.getAppreason() :"")); String appDays = recommendInfo.getAppDays(); if(null==appDays){ if(apptype==0){ appDays="30"; } if(apptype==1){ appDays="360"; }if(apptype==3){ appDays="永久"; } } //系统申请的特殊处理 if(apptype==3){ SysSysteminfo info=null; String sysId = recommendInfo.getSysId(); if(StringUtils.isNotEmpty(sysId)){ String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + sysId; info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class); map.put("insteadaudit",1); //委托管理员申请 map.put("isDangQianYongHu", isDangQianYongHu); if(!StringUtils.equals(info.toString(),"{}")){ map.put("appSys", info.getAppfullname()); }else { map.put("appSys",recommendInfo.getSysName()); } }else { map.put("appSys",recommendInfo.getSysName()); } } map.put("appDays",appDays); maps.add(map); } return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 后台管理 - 保存批复 */ @ResponseBody @RequestMapping("/res/manage/applyrecommend/save") @LogAction("资源管理,申请批复,申请批复信息新增,新增") public String save(Res_ApplyRecommend resApplyRecommend) { int result = 0; Timestamp audittime = new Timestamp(new Date().getTime()); resApplyRecommend.setAudittime(audittime); resApplyRecommend.setAudituserid(getUserId().intValue()); int updateresult = resApplyRecommendService.updateResApplyreCommendResult(resApplyRecommend); if (updateresult == 1) { result = 1; } return String.valueOf(result); } /** * 后台管理 - 查看申请理由 */ @RequestMapping("/res/manage/applyrecommend/content") public String content(Integer appid, Model model) { Res_ApplyRecommend applyRecommend = resApplyRecommendService.selectByPrimaryKey(appid); model.addAttribute("apply_ecommend", applyRecommend); return "manage/applyrecommend/content"; } /** * 资源中心-查看资源申请详情 */ @RequestMapping("/res/resApplyRecommend/applyRecommendInfo") public String applyRecommendInfo(Integer appid, Model model) { Res_ApplyRecommend applyRecommend = resApplyRecommendService.selectByPrimaryKey(appid); //有效天数 if(applyRecommend != null && applyRecommend.getEffendtime() != null && applyRecommend.getAppdate() != null){ int day = (int)((applyRecommend.getEffendtime().getTime() - applyRecommend.getAppdate().getTime()) /(1000*3600*24)); applyRecommend.setEffendday(day); } //申请日期 String dateStr = ""; if(applyRecommend != null && applyRecommend.getAppdate() != null){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dateStr = sdf.format(applyRecommend.getAppdate()); } model.addAttribute("dateStr",dateStr); model.addAttribute("resApplyRecommend", applyRecommend); // 获取申请类型列表 LinkedHashMap AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus"); // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示 Long userid = getUser().getUserid(); LinkedHashMap sysList = getUserManagerSystemList(userid); if(sysList.size() > 0){ AppStatusList.put("3","应用申请"); } model.addAttribute("sysList", sysList); model.addAttribute("AppStatusList", AppStatusList); model.addAttribute("appuser", getUser().getChinesename()); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "ResManage/ResApplyRecommend/ApplyRecommendInfo"; } /** * 后台管理 - 对应应用程序的资源列表页面 */ @RequestMapping("/res/manage/applyrecommend/indexbysystem") public String indexbysystem(Model model, Integer appid) { LinkedHashMap resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 model.addAttribute("resourceTypeList", resourceTypeList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); //获取应用程序系统地址 String systemUrl = ""; try { String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + appid; SysSysteminfo info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class); if (info != null) { systemUrl = info.getSysaddress(); } } catch (IOException e) { e.printStackTrace(); } model.addAttribute("systemUrl",systemUrl); return "manage/applyrecommend/indexbysystem"; } /** * 后台管理 - 获取对应应用程序的资源列表 */ @ResponseBody @RequestMapping("/res/manage/applyrecommend/getlistbysystem") public Result getlistbysystem(MainInfoJoinApplyRecommend mainInfoJoinApplyRecommend, PageBean pageBean) { PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); // 查询当前登陆用户是否是超级管理员 是:查所有 不是:查自己的 if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) { // 如果是超级管理员,不添加用户id,查询所有。如果不是 添加id 查询单个 mainInfoJoinApplyRecommend.setExistPermission( getUserId().toString()); } List list = resApplyRecommendService.selectResMainInfoBySysid(mainInfoJoinApplyRecommend); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 StringBuilder rsb = new StringBuilder(); String leixin = ""; rsb.append("{'totalCount':'" + countNums); rsb.append("','topics':["); List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { leixin = ResourceTypeList.get(list.get(i).getResourceclass()); String chinesename = orgUserService.getChinesename(list.get(i).getCreateuserid()); String unitname = orgUnitService.getUnitName((long) list.get(i).getPubunitid()); String appusername = ""; if (list.get(i).getAppuserid() != null) { OrgUser eobj = orgUserService.queryObject(Long.parseLong(list.get(i).getAppuserid())); appusername = eobj != null ? eobj.getChinesename() : ""; } String auditresult = ""; if(list.get(i).getAuditresult() != null){ if(list.get(i).getAuditresult() == 0){ auditresult = "待批复"; }else if(list.get(i).getAuditresult() == 1){ auditresult = "已通过"; }else{ auditresult = "未通过"; } } Map map = new HashMap<>(); map.put("resourceid", list.get(i).getResourceid()); map.put("title", list.get(i).getTitle()); map.put("mulu", GetBianMu(list.get(i).getCatlogid() == null ? 0 : list.get(i).getCatlogid())); map.put("resourceclass", leixin); map.put("pubdate", sdf.format(list.get(i).getPubdate())); map.put("pubunitid", unitname); map.put("createuserid", chinesename); map.put("appuserid", appusername); map.put("appdate", sdf.format(list.get(i).getAppdate())); map.put("auditresult", auditresult); map.put("audit", list.get(i).getAuditresult()); maps.add(map); } return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 查询资源所属目录 * * @param Catlogid * @return */ private String GetBianMu(int Catlogid) { String str = ""; strMuLu = ""; if (Catlogid > 0) { Res_Catalog zymlBianMu = resCatalogService.selectByPrimaryKey(Catlogid); String str2 = CheckBianMu(zymlBianMu); String[] res = str2.split(">"); for (int i = res.length - 1; i >= 0; i--) { if (i == 0) { str += res[i]; } else { str += res[i] + " > "; } } } return str; } /** * 递归获取资源目录名称 * * @param zymlBianMu * @return */ private String CheckBianMu(Res_Catalog zymlBianMu) { if (zymlBianMu != null) { strMuLu += zymlBianMu.getTitle() + ">"; if (zymlBianMu.getParentid() == 0) { return strMuLu; } else { zymlBianMu = resCatalogService.selectByPrimaryKey(zymlBianMu.getParentid()); CheckBianMu(zymlBianMu); } } return strMuLu; } //选择资源 @RequestMapping("/res/manage/applyrecommend/getSelectZiYuan") @ResponseBody public String getSelectZiYuan(String parentid, HttpServletRequest request,Integer sysid){ Map map = new HashMap<>(); List> maps = new LinkedList<>(); List> chmaps = new LinkedList<>(); if (parentid.indexOf("ZiYuan_") == -1) { map.put("parentid", Integer.valueOf(parentid)); map.put("sysid", sysid); List resCatalogList = resApplyRecommendService.selectCatalog(map);// 获取子目录列表 // 循环构造子目录节点 for (Res_Catalog resCatalog : resCatalogList) { Map catlogmap = new HashMap<>(); catlogmap.put("id", resCatalog.getCatlogid()); catlogmap.put("name", resCatalog.getTitle()); catlogmap.put("title", resCatalog.getTitle()); catlogmap.put("isParent", true); catlogmap.put("iconOpen", "/image/classicons/folderOpen.png"); catlogmap.put("iconClose", "/image/classicons/folder.png"); // 获取资源类型列表 List> maps2 = new LinkedList<>(); map.replace("parentid", resCatalog.getCatlogid()); int isparent = resApplyRecommendService.selectCatalog(map).size(); if(isparent > 0) { // getSelectZiYuan(resCatalog.getCatlogid().toString(), request, sysid); chmaps = (List) JSONArray.parseArray(getSelectZiYuan(resCatalog.getCatlogid().toString(), request, sysid)); if(chmaps.size() > 0) { maps2.addAll(chmaps); } } List resMainInfo = resApplyRecommendService.selectCatalogZiYuanList(map); // 获取目录下业务图层资源列表 // 循环构造资源节点 for (Res_MainInfo resMainInfo1 : resMainInfo) { String unitname = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid()); Map catlogmap2 = new HashMap<>(); catlogmap2.put("id", "ZiYuan_" + resMainInfo1.getResourceid()); catlogmap2.put("name", resMainInfo1.getTitle()+(unitname != null && unitname.length()>0?("("+unitname+")"):"" )); catlogmap2.put("title", resMainInfo1.getTitle()); catlogmap2.put("isParent", false); catlogmap2.put("icon", "/image/classicons/"+ resMainInfo1.getResourceclass() +".png"); maps2.add(catlogmap2); } catlogmap.put("children", maps2); maps.add(catlogmap); } } return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue); } /** * 获取选中的资源的地址 */ @RequestMapping("/res/manage/applyrecommend/getResourcesUrl") @ResponseBody public String getResourcesUrl(HttpServletResponse response, String resourceids,String sysUrl,Integer appid) { String[] ids = resourceids.split(","); StringBuilder rsb = new StringBuilder(); String leixin = ""; List> maps = new LinkedList<>(); for (Integer i = 0; i < ids.length; i++) { Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(ids[i])); //获取资源地址,多个默认取第一个 String firstMapUrl = ""; List urlList = resExtMapUrlService.selectByCondition(resMainInfo.getResourceid()); if (urlList != null && urlList.size() > 0 && urlList.get(0).getServerurl() != null) { firstMapUrl = urlList.get(0).getServerurl(); } else { if(resMainInfo.getResourceclass().equals("JKFW")) { Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfo.getResourceid()); if(res_extInterFaceService != null) { firstMapUrl = res_extInterFaceService.getServerurl() == null ? "null" : "\"" + res_extInterFaceService.getServerurl() + "\""; } } if(resMainInfo.getResourceclass().equals("SJWJ")) { Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resMainInfo.getResourceid()); if(resExtFileSource != null) { firstMapUrl = resExtFileSource.getServerurl() == null ? "null" : "\"" + resExtFileSource.getServerurl() + "\""; } } if(resMainInfo.getResourceclass().equals("YWJC")) { Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resMainInfo.getResourceid()); if(resExtIntegrate != null) { firstMapUrl = resExtIntegrate.getServerurl() == null ? "null" : "\"" + resExtIntegrate.getServerurl() + "\""; } } if(resMainInfo.getResourceclass().equals("KJ_KJFX")) { Res_ExtSpaceServer resExtSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resMainInfo.getResourceid()); if(resExtSpaceServer != null) { firstMapUrl = resExtSpaceServer.getServerurl() == null ? "null" : "\"" + resExtSpaceServer.getServerurl() + "\""; } } // 添加三维地形和三维影像 alert 2019/08/01 if(resMainInfo.getResourceclass().equals("KJ_SWMX") || resMainInfo.getResourceclass().equals("KJ_SWDX") || resMainInfo.getResourceclass().equals("KJ_SWYX")) { Res_Ext3D resExt3D = resExt3DService.selectByPrimaryKey(resMainInfo.getResourceid()); if(resExt3D != null) { firstMapUrl = resExt3D.getServerurl() == null ? "null" : "\"" + resExt3D.getServerurl() + "\""; } } } //获取Token值 String token = ""; String subzyids = ""; String serverUrl = "null"; //查询是否是专题地图,是专题地图则获取相关子图层ID if(resMainInfo.getResourceclass().equals("KJ_ZTDT")) { Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(Integer.parseInt(ids[i])); if (resExtThemeMap != null) { subzyids = resExtThemeMap.getSublayerset(); } } token = EsbToken.getAppEsbToken(getUserId().intValue(),appid,sysUrl,Integer.parseInt(ids[i]),resMainInfo.getEspproxy(),sysConfig,subzyids,resMainInfo.getToken()); Map map = new HashMap<>(); map.put("resourceid", resMainInfo.getResourceid()); map.put("title", resMainInfo.getTitle()); map.put("firstMapUrl", firstMapUrl); map.put("token", token); maps.add(map); } String a[] = {"资源id", "资源名称", "资源地址","Token"}; try { String route = sysConfig.getUploadPath()+"excel\\"; File file = new File(route); if(!file.exists()) { file.mkdirs(); } String Filename = Excel.SystemUrlgoing(response, a, JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue),route); String path2 = "/uploadPath/excel/"; String desFile = path2 + Filename; return desFile; } catch (IOException e) { e.printStackTrace(); return null; } } @RequestMapping("/res/manage/applyrecommend/ziyuanapply") public String ziyuanapply(Model model, String ids,Integer sysid) { // 获取登录人姓名和登录人id和登录人部门id OrgUser user = getUser(); String unitid = orgUserService.getDefaultUnit(user.getUserid()).getUnitid().toString();// user.getOrguserunits().get(0).getUnitid().toString(); String chinesename = user.getChinesename();// entity.getChinesename(); Long userid = user.getUserid();// entity.getUserid(); Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend(); applyRecommend.setAppuserid(getUserId().toString()); applyRecommend.setAppunitid((unitid)); // 获取当前时间并转化为yyyy-MM-dd格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String newDate = sdf.format(new Date()); model.addAttribute("Appdate", newDate); // 获取资源信息名称 String[] idList = ids.split(","); String titles = ""; if(idList!= null && idList.length >0){ for (int i = 0; i < idList.length; i++) { if (titles != "") titles += ","; Res_MainInfo record = resMainInfoService.selectByPrimaryKey(Integer.valueOf(idList[i])); if (record != null) titles += record.getTitle(); } } // 获取申请类型列表 LinkedHashMap AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus"); // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示 LinkedHashMap sysList = getUserManagerSystemList(userid); if(sysList.size() > 0){ AppStatusList.put("3","应用申请"); } model.addAttribute("shenqin", sysList); // 获取资源使用方式列表 LinkedHashMap ResUseTypeList = FieldUtils.getFieldListByKey("ResUseType"); model.addAttribute("resApplyRecommend", applyRecommend); model.addAttribute("AppStatusList", AppStatusList); model.addAttribute("titles", titles); model.addAttribute("resourceids", ids); model.addAttribute("appuser", chinesename); model.addAttribute("sysid", sysid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "manage/applyrecommend/ziyuanapply"; } @ResponseBody @RequestMapping("/res/manage/applyrecommend/saveZiYuansApply") public String saveZiYuansApply(Res_ApplyRecommend record, String resourceids) { String result = ""; String[] idList = resourceids.split(","); if(idList!= null && idList.length >0){ for (int i = 0; i < idList.length; i++) { record.setResourceid(Integer.valueOf(idList[i])); result = insertSelectiveAndUpdate(record,Long.parseLong(idList[i]),1); } } return result; } @ResponseBody @RequestMapping("/res/manage/applyrecommend/saveSysApply") public String saveSysApply(Res_ApplyRecommend record) throws IOException { record.setResourceid(0); record.setAppunitid("0"); record.setAudituserid(4); String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + record.getSysid(); SysSysteminfo info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class); if(null!=info){ record.setAudituserid(info.getMaguser()); } insertSelectiveAndUpdate(record,0L,record.getSysid()); return JSONUtils.toJSONString(Result.ok()); } public static void main(String[] args) { } }