package com.landtool.lanbase.modules.res.controller; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; 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.github.pagehelper.Page; import com.github.pagehelper.PageHelper; 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.service.OrgUnitService; import com.landtool.lanbase.modules.org.service.OrgUserService; import com.landtool.lanbase.modules.res.entity.Res_Catalog; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.entity.ZiYuanTongJi.GroupByDataSources; import com.landtool.lanbase.modules.res.entity.ZiYuanTongJi.GroupByMuLu; import com.landtool.lanbase.modules.res.entity.ZiYuanTongJi.GroupByZiYuanLeiXing; import com.landtool.lanbase.modules.res.service.ResActionRecordService; import com.landtool.lanbase.modules.res.service.ResApplyRecommendService; import com.landtool.lanbase.modules.res.service.ResCatalogService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.res.service.ZiYuanMuLuService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; /** * @author ykm * @Description: 资源中心 * @return * @date 2018/3/21 11:00 */ @Controller @RequestMapping("res/ZiYuanZhongXin") public class ZiYuanZhongXinController extends AbstractController { @Autowired private SysTemPropertyConfig sysConfig; @Autowired private ResMainInfoService resMainInfoService; @Autowired private ResCatalogService resCatalogService; @Autowired private SysFieldvalueService FieldUtils; @Autowired private OrgUnitService orgUnitService; @Autowired private OrgUserService orgUserService; @Autowired private ResApplyRecommendService resApplyRecommendService; @Autowired private ResActionRecordService resActionRecordService; @Autowired public ZiYuanMuLuService ziYuanMuLuService; public static String strMuLu = ""; /** * 资源中心 * @param model * @return */ @RequestMapping("indexbak") public String ziYuanZhongXinIndex(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());// sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName());// sysConfig.getAppFullName()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 // 资源类型饼状统计图 List resourceclassList = resMainInfoService.selectResMainInfoGroupByLeiXing(); String AllSeries = ""; // 多于4个类型的话数据显示前7个资源数量最多的类型,后面的都以其它统计 if (resourceclassList.size() > 4) { int counter = 0; for (int i = 4; i < resourceclassList.size(); i++) { counter += resourceclassList.get(i).getCount(); } for (int i = 0; i < 4; i++) { GroupByZiYuanLeiXing item = resourceclassList.get(i); String leixing = ResourceTypeList.get(item.getResourceclass()); AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}"; } AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + counter + ", name: '" + "其它" + "'}"; } // 少于等于4个类型就全部显示 else { for (int i = 0; i < resourceclassList.size(); i++) { GroupByZiYuanLeiXing item = resourceclassList.get(i); String leixing = ResourceTypeList.get(item.getResourceclass()); AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}"; } } model.addAttribute("resourceclassSeries", "[" + AllSeries + "]"); // 资源来源统计图 List dataSourcesList = resMainInfoService.selectResMainInfoGroupByDataSources(); String DataSourceLegends = ""; String DataSourceSeries = ""; int z = dataSourcesList.size(); if(dataSourcesList.size() > 5) { z = 5; } for (int i = 0; i < z; i++) { GroupByDataSources item = dataSourcesList.get(i); if (item.getDatasources() == null || item.getDatasources().equals("")) { z++; continue; } String legend = item.getDatasources(); if (item.getDatasources().length() > 6) { legend = item.getDatasources().substring(0, 6); } DataSourceLegends += (DataSourceLegends == "" ? "" : ",") + "'" + legend + "'"; DataSourceSeries += (DataSourceSeries == "" ? "" : ",") + item.getCount(); } model.addAttribute("DataSourceLegends", "[" + DataSourceLegends + "]"); model.addAttribute("DataSourceSeries", "[" + DataSourceSeries + "]"); // 资源目录统计图 List catlogidList = resMainInfoService.selectResMainInfoGroupByMuLu(); String MuLuLegends = ""; String MuLuSeries = ""; for (int i = 0; i < catlogidList.size(); i++) { GroupByMuLu item = catlogidList.get(i); // if (item.getCatlogCode().equals("0")) // continue; strMuLu = ""; // String legend = GetBianMu(item.getCatlogCode() == null ? 0 : Integer.parseInt(item.getCatlogCode())); MuLuLegends += (MuLuLegends == "" ? "" : ",") + "'" + item.getTitle() + "'"; MuLuSeries += (MuLuSeries == "" ? "" : ",") + item.getCount(); } model.addAttribute("MuLuLegends", "[" + MuLuLegends + "]"); model.addAttribute("MuLuSeries", "[" + MuLuSeries + "]"); Long userid = getUserId(); Long unitId = orgUserService.getDefaultUnit(userid).getUnitid(); Map paramMap = new HashMap(); paramMap.put("appuserid", userid); paramMap.put("appunitid", unitId); paramMap.put("isDiTuFuwu", null); List resourceList = resApplyRecommendService.getAllRecommend(paramMap); int recordCount = resourceList != null ? resourceList.size() : 0; // 记录总数 model.addAttribute("totalpNum", recordCount); model.addAttribute("totalrNum", getMainInfoRecommendCount()); model.addAttribute("gisPortal", sysConfig.getGisPortal()); return "ZiYuanZhongXin/Index"; } /** * 热门关键字搜索 * @param key */ @ResponseBody @RequestMapping("Search") public void search(String key) { if(!key.trim().equals("")) { String keyword = resMainInfoService.selectHotSearch(key); if (keyword == null) { resMainInfoService.insertHotSearch(key); } else { resMainInfoService.updateHotSearch(key); } } } /** * 查询访问排行列表功能 */ @ResponseBody @RequestMapping("selectFangWenPaiHangGD") public Result selectResMainInfojoinCatalog(Res_MainInfo resMainInfo, PageBean pageBean) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List mainInfoJoinCatalogList = resMainInfoService.selectResMainInfoFangWenPaiHang(resMainInfo); 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 = ""; // rsb.append("{'totalCount':'" + countNums); // rsb.append("','topics':["); List> maps = new LinkedList<>(); for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) { leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass()); String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid());// obj1.getString("unitname"); Map map = new HashMap<>(); map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid()); map.put("title", mainInfoJoinCatalogList.get(i).getTitle()); map.put("resourceclass", leixin); map.put("pubdate", sdf.format(mainInfoJoinCatalogList.get(i).getPubdate())); map.put("pubunitid", unitname); map.put("fangwenpaihang", mainInfoJoinCatalogList.get(i).gett()); maps.add(map); // // if (i != 0) { // rsb.append(","); // } // // rsb.append("{'resourceid':'" + mainInfoJoinCatalogList.get(i).getResourceid() + "'");// 资源id // rsb.append(",'title':'" + mainInfoJoinCatalogList.get(i).getTitle() + "'");// 资源名称 // // rsb.append(",'resourceclass':'" + leixin + "'");// 资源类型 // rsb.append(",'pubdate':'" + sdf.format(mainInfoJoinCatalogList.get(i).getPubdate()) + "'");// 发布时间 // rsb.append(",'pubunitid':'" + unitname + "'");// 发布单位id // rsb.append(",'fangwenpaihang':'" + mainInfoJoinCatalogList.get(i).gett() + "'");// 浏览次数 // rsb.append("}"); } // rsb.append("]}"); return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 访问排行更多页面 */ @RequestMapping("FangWenPaiHangGD") public String fangWenPaiHangGD(Model model) { // 获取下拉框目录 LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 model.addAttribute("ResourceTypeList", ResourceTypeList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); model.addAttribute("gisPortal", sysConfig.getGisPortal()); return "ZiYuanZhongXin/FangWenPaiHangGD"; } /** * 我的收藏更多页面 */ @RequestMapping("WoDeShouCangJiaGD") public String WoDeShouCangJiaGD(Model model) { // 获取下拉框目录 LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 model.addAttribute("ResourceTypeList", ResourceTypeList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); model.addAttribute("gisPortal", sysConfig.getGisPortal()); return "ZiYuanZhongXin/WoDeShouCangJiaGD"; } /** * 资源统计更多页面 */ @RequestMapping("ZiYuanTongJiGD") public String ZiYuanTongJiGD(Model model) { // 获取下拉框目录 LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 model.addAttribute("ResourceTypeList", ResourceTypeList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); List DATASOURCES = resMainInfoService.selectDATASOURCES(); model.addAttribute("DATASOURCESList", DATASOURCES); List MuLuList = resCatalogService.selectResCatalogToParentid(0); model.addAttribute("MuLuList", MuLuList); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); model.addAttribute("gisPortal", sysConfig.getGisPortal()); return "ZiYuanZhongXin/ZiYuanTongJiGD"; } /** * 查询访问排行列表功能 */ @ResponseBody @RequestMapping("selectZiYuanTongJiGD") public String selectZiYuanTongJiGD(Res_MainInfo resMainInfo, PageBean pageBean) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List mainInfoJoinCatalogList = resMainInfoService.selectResMainInfojoinCatalog(resMainInfo); 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 = ""; rsb.append("{'totalCount':'" + countNums); rsb.append("','topics':["); for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) { strMuLu = ""; if (i != 0) { rsb.append(","); } rsb.append("{'resourceid':'" + mainInfoJoinCatalogList.get(i).getResourceid() + "'");// 资源id rsb.append(",'title':'" + mainInfoJoinCatalogList.get(i).getTitle() + "'");// 资源名称 rsb.append(",'mulu':'" + GetBianMu(mainInfoJoinCatalogList.get(i).getCatlogid() == null ? 0 : mainInfoJoinCatalogList.get(i).getCatlogid()) + "'");// 所属目录编码 leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass()); rsb.append(",'resourceclass':'" + leixin + "'");// 资源类型 rsb.append(",'datasources':'" + mainInfoJoinCatalogList.get(i).getDatasources() + "'");// 资源类型 rsb.append(",'pubdate':'" + sdf.format(mainInfoJoinCatalogList.get(i).getPubdate()) + "'");// 发布时间 String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid()); rsb.append(",'pubunitid':'" + unitname + "'");// 发布单位id rsb.append("}"); } rsb.append("]}"); return rsb.toString(); } /** * 资源统计导出 * @param response * @param resMainInfo * @return */ @ResponseBody @RequestMapping("ZiYuanTongJiexcel") public String ZiYuanTongJiexcel(HttpServletResponse response, Res_MainInfo resMainInfo) { List mainInfoJoinCatalogList = resMainInfoService.selectResMainInfojoinCatalog(resMainInfo); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 StringBuilder rsb = new StringBuilder(); String leixin = ""; rsb.append("{'totalCount':'" + ""); rsb.append("','topics':["); for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) { if (i != 0) { rsb.append(","); } rsb.append("{'resourceid':'" + mainInfoJoinCatalogList.get(i).getResourceid() + "'");// 资源id rsb.append(",'title':'" + mainInfoJoinCatalogList.get(i).getTitle() + "'");// 资源名称 rsb.append(",'mulu':'" + GetBianMu(mainInfoJoinCatalogList.get(i).getCatlogid() == null ? 0 : mainInfoJoinCatalogList.get(i).getCatlogid()) + "'");// 所属目录编码 leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass()); rsb.append(",'resourceclass':'" + leixin + "'");// 资源类型 rsb.append(",'datasources':'" + mainInfoJoinCatalogList.get(i).getDatasources() + "'");// 资源类型 rsb.append(",'pubdate':'" + sdf.format(mainInfoJoinCatalogList.get(i).getPubdate()) + "'");// 发布时间 String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid()); rsb.append(",'pubunitid':'" + unitname + "'");// 发布单位id rsb.append("}"); } rsb.append("]}"); String a[] = {"资源id", "资源名称", "所属目录", "资源类型", "发布时间", "发布单位", "数据来源"}; try { String Filename = Excel.TJgoing(response, a, rsb.toString(), sysConfig.getUploadPath() + "excel\\"); // bug........... // String path2 = env.getProperty("webroot") + "ZiYuanIcon/"; String path2 = "/uploadPath/excel/"; String desFile = path2 + Filename; System.out.println(desFile); return desFile; } catch (IOException e) { e.printStackTrace(); return null; } } /** * 递归获取资源目录名称 * @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; } /** * 查询资源所属目录 * @param Catlogid * @return */ private String GetBianMu(int Catlogid) { String str = ""; 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; } /** * 资源推荐更多页面 */ @RequestMapping("ZiYuanTuiJianGD") public String ZiYuanTuiJianGD(Model model) { LinkedHashMap resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型 model.addAttribute("resourceTypeList", resourceTypeList); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("gisPortal", sysConfig.getGisPortal()); return "ZiYuanZhongXin/ZiYuanTuiJianGD"; } /** * 查询条件所属目录的目录树 */ @RequestMapping("MuLuShu") public String MuLuShu(Model model) { return "ResManage/ResRegister/MuLuShu"; } /** * 资源推荐 */ private int getMainInfoRecommendCount() { Long userid = getUserId(); Long unitId = orgUserService.getDefaultUnit(userid).getUnitid(); int count = 0; //获取关键字 List keyWords = resActionRecordService.selectKeyWordsByUserid(Integer.parseInt(userid.toString())); if (keyWords != null && keyWords.size() > 0) { // String keywordStrs = ""; // for (String k : keyWords) { // if (k.indexOf(",") != -1) { // String[] newks = k.split(","); // for (String newk : newks) { // if (keywordStrs.indexOf("'" + newk + "',") == -1) keywordStrs += "'" + newk + "',"; // } // } else { // if (keywordStrs.indexOf("'" + k + "',") == -1) keywordStrs += "'" + k + "',"; // } // } Map paramMap = new HashMap(); // paramMap.put("keywords", keywordStrs.substring(0, keywordStrs.length() - 1)); paramMap.put("userid", userid); paramMap.put("isDiTuFuwu", null); List resourceList = resActionRecordService.selectMainInfoRecommends(paramMap); count = resourceList != null && resourceList.size() > 0 ? count = resourceList.size() : 0; } return count; } /** * 新版资源中心 */ /** * 资源中心 * @param model * @return */ @RequestMapping("index") public String newZiYuanZhongXinIndex(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());// sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName());// sysConfig.getAppFullName()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); LinkedHashMap ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表 // 资源类型饼状统计图 List resourceclassList = resMainInfoService.selectResMainInfoGroupByLeiXing(); String AllSeries = ""; // 多于4个类型的话数据显示前7个资源数量最多的类型,后面的都以其它统计 if (resourceclassList.size() > 4) { int counter = 0; for (int i = 4; i < resourceclassList.size(); i++) { counter += resourceclassList.get(i).getCount(); } for (int i = 0; i < 4; i++) { GroupByZiYuanLeiXing item = resourceclassList.get(i); String leixing = ResourceTypeList.get(item.getResourceclass()); AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}"; } AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + counter + ", name: '" + "其它" + "'}"; } // 少于等于4个类型就全部显示 else { for (int i = 0; i < resourceclassList.size(); i++) { GroupByZiYuanLeiXing item = resourceclassList.get(i); String leixing = ResourceTypeList.get(item.getResourceclass()); AllSeries += (AllSeries == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}"; } } model.addAttribute("resourceclassSeries", "[" + AllSeries + "]"); // 资源来源统计图 List dataSourcesList = resMainInfoService.selectResMainInfoGroupByDataSources(); String DataSourceLegends = ""; String DataSourceSeries = ""; int z = dataSourcesList.size(); if(dataSourcesList.size() > 5) { z = 5; } for (int i = 0; i < z; i++) { GroupByDataSources item = dataSourcesList.get(i); if (item.getDatasources() == null || item.getDatasources().equals("")) { z++; continue; } String legend = item.getDatasources(); if (item.getDatasources().length() > 6) { legend = item.getDatasources().substring(0, 6); } DataSourceLegends = "'" + legend + "'" + (DataSourceLegends == "" ? "" : ",") + DataSourceLegends ; DataSourceSeries = item.getCount() + (DataSourceSeries == "" ? "" : ",") + DataSourceSeries; } model.addAttribute("DataSourceLegends", "[" + DataSourceLegends + "]"); model.addAttribute("DataSourceSeries", "[" + DataSourceSeries + "]"); // 资源目录统计图 List catlogidList = resMainInfoService.selectResMainInfoGroupByMuLu(); String MuLuLegends = ""; String MuLuSeries = ""; for (int i = 0; i < catlogidList.size(); i++) { GroupByMuLu item = catlogidList.get(i); // if (item.getCatlogCode().equals("0")) // continue; strMuLu = ""; // String legend = GetBianMu(item.getCatlogCode() == null ? 0 : Integer.parseInt(item.getCatlogCode())); MuLuLegends += (MuLuLegends == "" ? "" : ",") + "'" + item.getTitle() + "'"; MuLuSeries += (MuLuSeries == "" ? "" : ",") + item.getCount(); } model.addAttribute("MuLuLegends", "[" + MuLuLegends + "]"); model.addAttribute("MuLuSeries", "[" + MuLuSeries + "]"); // 资源审核状态统计图 model.addAttribute("shenhezhuangtaiSeries", "[" + ziYuanMuLuService.getZYTJ_ShenHeZhuangTai() + "]"); //共享协议统计图 model.addAttribute("sharprotocolSeries", "[" + ziYuanMuLuService.getGongXiangXieYiChart() + "]"); Long userid = getUserId(); Long unitId = orgUserService.getDefaultUnit(userid).getUnitid(); Map paramMap = new HashMap(); paramMap.put("appuserid", userid); paramMap.put("appunitid", unitId); paramMap.put("isDiTuFuwu", null); List resourceList = resApplyRecommendService.getAllRecommend(paramMap); int recordCount = resourceList != null ? resourceList.size() : 0; // 记录总数 model.addAttribute("totalpNum", recordCount); model.addAttribute("totalrNum", getMainInfoRecommendCount()); model.addAttribute("gisPortal", sysConfig.getGisPortal()); model.addAttribute("logourl","ziyuanzhongxintitle"); logger.info("返回前端页面ZiYuanZhongXin/New/Index"); return "ZiYuanZhongXin/New/Index"; } }