package com.landtool.lanbase.modules.res.service.impl; import java.io.IOException; import java.util.Calendar; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.res.dao.ZiYuanMuLuMapper; 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.UserDefined.UserDef_ZYML_ChaXunQu; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_DanWeiTongJi; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_GongXiangXieYi; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_ShiJianTongJi; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_XingZhengQuHua; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_ZYTJ_ShenHeZhuangTai; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_ZYTJ_XingZhengQuHua; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_ZYTJ_ZiYuanLeiXing; import com.landtool.lanbase.modules.res.entity.UserDefined.ZiYuanMuLu.UserDef_ZiYuanLeiXing; import com.landtool.lanbase.modules.res.service.ZiYuanMuLuService; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; /** * 资源目录 */ @Service("ZiYuanMuLuService") public class ZiYuanMuLuServiceImpl implements ZiYuanMuLuService { @Autowired private ZiYuanMuLuMapper ziYuanMuLuMapper; @Autowired private SysTemPropertyConfig sysConfig; @Autowired private SysFieldvalueService fieldUtils; /** * 获取资源目录树数据 */ @Override public String getTreeData(int id, int treeType, String XZQHID, String NF, int IsSC) { //String apiServer = sysConfig.getApiServer(); //临时 String result = ""; Map map = new HashMap<>(); map.put("parentid", id); map.put("xzqhid", XZQHID); if(NF != null && !NF.isEmpty()) { map.put("nf", NF); } map.put("shoucang", IsSC); if (treeType == 0) { //资源目录 List resCatalogList = ziYuanMuLuMapper.getTreeData(map); for (Res_Catalog resCatalog : resCatalogList) { int childCount = ziYuanMuLuMapper.getChildNodeCount(resCatalog.getCatlogid()); if (result.length() > 0) { result += ","; } //result += (result.length() > 0 ? "," : ""); result += "{ id:" + resCatalog.getCatlogid() + ", code: '" + resCatalog.getCatlogcode() + "', name:'" + resCatalog.getTitle() + "', pId:" + resCatalog.getParentid() + ", rpId:" + resCatalog.getParentid() + (childCount > 0 ? ",isParent:true" : "") + " }"; } } else if (treeType == 4) { //资源类型 // LinkedHashMap ResourceTypeList = fieldUtils.getFieldListByKey("ResourceType"); //获取资源类型列表 // List resMainInfoList = resCatalogService.getResourceClassTreeData(map); // if(resMainInfoList.size() > 0) { // String[] arr = new String[resMainInfoList.size()]; // for (int i = 0; i < resMainInfoList.size(); i++) { // arr[i] = resMainInfoList.get(i).getResourceclass(); // } // Iterator> iterator = ResourceTypeList.entrySet().iterator(); // while(iterator.hasNext()) // { // Map.Entry entry = iterator.next(); // if(Arrays.binarySearch(arr, entry.getKey()) > -1) { // result += (result.length() > 0 ? "," : "") + "{id:'" + entry.getKey() + "', code: '" + entry.getKey() + "', name:'" + entry.getValue() + "'}"; // } // } // } return ""; } return "[" + result + "]"; //return ziYuanMuLuMapper.getTreeData(map); } /** * 获取子节点数量 */ //public int getChildNodeCount(int parentId) { // return ziYuanMuLuMapper.getChildNodeCount(parentId); //} /** * 资源类型图表 */ @Override public String getZiYuanLeiXingChart() { String jsonResult = ""; LinkedHashMap resourceTypeList = fieldUtils.getFieldListByKey("ResourceType"); List list = ziYuanMuLuMapper.getZiYuanLeiXingChart(); String seriesData = ""; String legendData = ""; int recordcount = 0; //多于4个类型的话数据显示前7个资源数量最多的类型,后面的都以其它统计 if (list.size() > 4) { int counter = 0; for (int i = 4; i < list.size(); i++) { counter += list.get(i).getRecordcount(); } for (int i = 0; i < 4; i++) { UserDef_ZiYuanLeiXing item = list.get(i); String leixing = resourceTypeList.get(item.getResourceclass()); seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + leixing + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + leixing + "'"; recordcount += item.getRecordcount(); } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + counter + ", name: '" + "其它" + "'}"; legendData += (legendData == "" ? "" : ",") + " '" + "其它" + "'"; recordcount += counter; } //少于等于4个类型就全部显示 else { for (int i = 0; i < list.size(); i++) { UserDef_ZiYuanLeiXing item = list.get(i); String leixing = resourceTypeList.get(item.getResourceclass()); seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + leixing + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + leixing + "'"; recordcount += item.getRecordcount(); } } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 行政区划统计图 */ @Override public String getXingZhengQuHuaChart() { String jsonResult = ""; String apiServer = sysConfig.getApiServer(); List list = ziYuanMuLuMapper.getXingZhengQuHuaChart(); String seriesData = ""; String legendData = ""; int recordcount = 0; String jsonStr = ""; String getRegionInfourl = apiServer + "/api/org/region/queryList"; try { jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim()); } catch (IOException e) { e.printStackTrace(); } JSONArray XZQHItem = JSONObject.parseArray(jsonStr); if (list.size() > 5) { int XZcounter = 0; for (int i = 5; i < list.size(); i++) { XZcounter += list.get(i).getRecordcount(); } for (int i = 0; i < 5; i++) { UserDef_XingZhengQuHua item = list.get(i); String quhua = item.getAdministrativeid().trim(); if (quhua.length() > 0) { if (!quhua.substring(2, quhua.length()).equals("0000")) { quhua = quhua.substring(0, 2) + "0000"; //下级市区归属到省 } } else { continue; }//为空跳过 for (int j = 0; j < XZQHItem.size(); j++) { JSONObject temp = (JSONObject) XZQHItem.get(j); String regionid = temp.getString("regionid"); if (regionid.equals(quhua)) { quhua = temp.getString("regionname"); break; } } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + quhua + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + quhua + "'"; recordcount += item.getRecordcount(); } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + XZcounter + ", name: '" + "其它" + "'}"; legendData += (legendData == "" ? "" : ",") + " '" + "其它" + "'"; recordcount += XZcounter; } else { for (int i = 0; i < list.size(); i++) { UserDef_XingZhengQuHua item = list.get(i); String quhua = item.getAdministrativeid().trim(); if (quhua.length() > 0) { if (!quhua.substring(2, quhua.length()).equals("0000")) { quhua = quhua.substring(0, 2) + "0000"; //下级市区归属到省 } } else { continue; }//为空跳过 for (int j = 0; j < XZQHItem.size(); j++) { JSONObject temp = (JSONObject) XZQHItem.get(j); String regionid = temp.getString("regionid"); if (regionid.equals(quhua)) { quhua = temp.getString("regionname"); break; } } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + quhua + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + quhua + "'"; recordcount += item.getRecordcount(); } } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 资源概况 - 共享协议 */ @Override public String getGongXiangXieYiChart() { String jsonResult = ""; //LinkedHashMap GongXiangXieYiList = FieldUtils.getFieldListByKey("SharProtocol", env.getProperty("backstageWebRoot"));//获取共享协议列表 List list = ziYuanMuLuMapper.getGongXiangXieYiChart(); String seriesData = ""; String legendData = ""; int recordcount = 0; for (int i = 0; i < list.size(); i++) { UserDef_GongXiangXieYi item = list.get(i); String xieyi = item.getSharprotocol(); seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + xieyi + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + xieyi + "'"; recordcount += item.getRecordcount(); } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 资源概况 - 时间统计 */ @Override public String getShiJianTongJiChart(UserDef_ZYML_ChaXunQu userDefZymlChaXunQu) { String jsonResult = ""; String legend = ""; String xAxis = ""; LinkedHashMap resourceClass = fieldUtils.getFieldListByKey("ResourceType"); //获取所有资源类型 LinkedHashMap hasDataResourceClass = new LinkedHashMap(); //有数据的资源类型 Calendar calendar = Calendar.getInstance(); int currentYear = calendar.get(Calendar.YEAR); //本年 int currentMonth = calendar.get(Calendar.MONTH) + 1; //本月 int lastYear = currentYear - 1; //去年 String str_lastYear_Month = ""; //去年已过的月份 String str_currentYear_Month = ""; //本年已过的月份 //获取本年的月份 for (int i = currentMonth; i >= 1 ; i--) { if (!str_currentYear_Month.isEmpty()) { str_currentYear_Month += ","; } str_currentYear_Month += String.valueOf(i); } //获取去年的月份 for (int i = 12; ; i--) { if(str_currentYear_Month.split(",").length+str_lastYear_Month.split(",").length>=24||i<=0){ break; } if (!str_lastYear_Month.isEmpty()) { str_lastYear_Month += ","; } str_lastYear_Month += String.valueOf(i); } //SQL查询的条件参数 Map paramMap = new HashMap(); paramMap.put("lastYear", lastYear); paramMap.put("str_lastYear_Month", str_lastYear_Month); paramMap.put("currentYear", currentYear); paramMap.put("str_currentYear_Month", str_currentYear_Month); //mainInfo查询条件 paramMap.put("title",userDefZymlChaXunQu.getTitle()); paramMap.put("resourceclass",userDefZymlChaXunQu.getResourceclass()); paramMap.put("createuserid",userDefZymlChaXunQu.getCreateuserid()); paramMap.put("catlogcode",userDefZymlChaXunQu.getCatlogcode()); paramMap.put("datasources",userDefZymlChaXunQu.getDatasources()); paramMap.put("ExistPermission",userDefZymlChaXunQu.getExistPermission()); paramMap.put("sourcetype",userDefZymlChaXunQu.getSourcetype()); paramMap.put("filetype",userDefZymlChaXunQu.getFiletype()); paramMap.put("integratetype",userDefZymlChaXunQu.getIntegratetype()); paramMap.put("showmodel",userDefZymlChaXunQu.getShowmodel()); paramMap.put("rendermode",userDefZymlChaXunQu.getRendermode()); paramMap.put("publishsoft",userDefZymlChaXunQu.getPublishsoft()); paramMap.put("basemaptype",userDefZymlChaXunQu.getBasemaptype()); paramMap.put("imageaccuracy",userDefZymlChaXunQu.getImageaccuracy()); paramMap.put("servertype",userDefZymlChaXunQu.getServertype()); paramMap.put("type",userDefZymlChaXunQu.getType()); paramMap.put("tmpublishsoft",userDefZymlChaXunQu.getTmpublishsoft()); paramMap.put("ywpublishsoft",userDefZymlChaXunQu.getYwpublishsoft()); paramMap.put("databasealias",userDefZymlChaXunQu.getDatabasealias()); paramMap.put("espproxy",userDefZymlChaXunQu.getEspproxy()); paramMap.put("pubdateBegin",userDefZymlChaXunQu.getPubdateBegin()); paramMap.put("pubdatefinish",userDefZymlChaXunQu.getPubdatefinish()); paramMap.put("resourcestatus",userDefZymlChaXunQu.getResourcestatus()); List list = ziYuanMuLuMapper.getShiJianTongJiChart(paramMap); //构造 Legend for (int i = 0; i < list.size(); i++) { UserDef_ShiJianTongJi item = list.get(i); String resTypeKey = item.getResourceclass(); String resTypeValue = resourceClass.get(resTypeKey); if (legend.indexOf(resTypeValue) > -1) { continue; } else { if (!legend.isEmpty()) { legend += ","; } legend += "{name: '" + resTypeValue + "', key: '" + resTypeKey + "', icon: 'rect'}"; hasDataResourceClass.put(resTypeKey, resTypeValue); } } legend = "Legend: [" + legend + "]"; //构造本年和去年 xAxis String[] arr_currentYear_Month = str_currentYear_Month.split(","); for (int i = 0; i < arr_currentYear_Month.length; i++) { if (!xAxis.isEmpty()) { xAxis += ","; } xAxis += "'" + arr_currentYear_Month[i] + "月'"; } String[] arr_lastYear_Month = str_lastYear_Month.split(","); int MonthCount=arr_currentYear_Month.length; for (int i = 0; i < arr_lastYear_Month.length; i++) { if(MonthCount>=12){ break;} MonthCount++; if (!xAxis.isEmpty()) { xAxis += ","; } xAxis += "'去年" + arr_lastYear_Month[i] + "月'"; } xAxis = "xAxis: [" + xAxis + "]"; //构造 Series String series = ""; Iterator iter = hasDataResourceClass.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String resClass = entry.getKey().toString(); if (!series.isEmpty()) { series += ","; } series += "" + resClass + ": [" + getShiJianTongJiData(resClass, list, arr_currentYear_Month, arr_lastYear_Month, currentYear, lastYear) + "]"; } series = "Series: {" + series + "}"; jsonResult = "{" + legend + ", " + xAxis + ", " + series + "}"; return jsonResult; } /** * 获取数据 */ private String getShiJianTongJiData(String resourceClass, List list, String[] arr_currentYear_Month, String[] arr_lastYear_Month, int currentYear, int lastYear) { String data = ""; //本年 for (int i = 0; i < arr_currentYear_Month.length; i++) { boolean isFind = false; if (!data.isEmpty()) { data += ","; } for (int j = 0; j < list.size(); j++) { UserDef_ShiJianTongJi item = list.get(j); if (resourceClass.equals(item.getResourceclass()) && currentYear == item.getYear() && Integer.valueOf(arr_currentYear_Month[i]) == item.getMonth()) { data += String.valueOf(item.getRecordcount()); isFind = true; break; } } //没有找到就为零 if (isFind == false) { data += String.valueOf(0); } } //去年 int MonthDataCount=arr_currentYear_Month.length; for (int i = 0; i < arr_lastYear_Month.length; i++) { if(MonthDataCount>=12){break;} MonthDataCount++; boolean isFind = false; if (!data.isEmpty()) { data += ","; } for (int j = 0; j < list.size(); j++) { UserDef_ShiJianTongJi item = list.get(j); if (resourceClass.equals(item.getResourceclass()) && lastYear == item.getYear() && Integer.valueOf(arr_lastYear_Month[i]) == item.getMonth()) { data += String.valueOf(item.getRecordcount()); isFind = true; break; } } //没有找到就为零 if (isFind == false) { data += String.valueOf(0); } } return data; } /** * 资源概况 - 单位统计 */ @Override public String getDanWeiTongJiChart() { String jsonResult = ""; List pubunitidList = ziYuanMuLuMapper.getDanWeiTongJiChart(); String seriesData = ""; String legendData = ""; int recordcount = 0; String UnitStr = ""; for (int i = 0; i < pubunitidList.size(); i++) { UserDef_DanWeiTongJi item = pubunitidList.get(i); String id = item.getPubunitid(); String getUnitInfourl = sysConfig.getApiServer() + "/api/org/unit/getInfoById/" + id; try { UnitStr = HttpOperateUtils.httpGet(getUnitInfourl.trim()); } catch (IOException e) { e.printStackTrace(); } JSONObject UnitData = JSONObject.parseObject(UnitStr); String temp = UnitData.getString("unitname"); seriesData += (seriesData == "" ? "" : ",") + item.getRecordcount(); legendData += (legendData == "" ? "" : ",") + "'" + temp + "'"; } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 资源统计 - 资源类型 */ @Override public String getZYTJ_ZiYuanLeiXingChart(UserDef_ZYML_ChaXunQu userDefZymlChaXunQu) { String jsonResult = ""; LinkedHashMap resourceTypeList = fieldUtils.getFieldListByKey("ResourceType"); List list = ziYuanMuLuMapper.getZYTJ_ZiYuanLeiXingChart(userDefZymlChaXunQu); String seriesData = ""; String legendData = ""; int recordcount = 0; for (int i = 0; i < list.size(); i++) { UserDef_ZYTJ_ZiYuanLeiXing item = list.get(i); String leixing = resourceTypeList.get(item.getResourceclass()); seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + leixing + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + leixing + "'"; recordcount += item.getRecordcount(); } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 资源统计 - 行政划区 */ @Override public String getZYTJ_XingZhengQuHuaChart(UserDef_ZYML_ChaXunQu userDefZymlChaXunQu) { String jsonResult = ""; String apiServer = sysConfig.getApiServer(); List list = ziYuanMuLuMapper.getZYTJ_XingZhengQuHuaChart(userDefZymlChaXunQu); String seriesData = ""; String legendData = ""; int recordcount = 0; String jsonStr = ""; String getRegionInfourl = apiServer + "/api/org/region/queryList"; try { jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim()); } catch (IOException e) { e.printStackTrace(); } JSONArray XZQHItem = JSONObject.parseArray(jsonStr); for (int i = 0; i < list.size(); i++) { UserDef_ZYTJ_XingZhengQuHua item = list.get(i); String quhua = item.getAdministrativeid(); if (quhua == null || quhua.trim().equals("") || quhua.length() == 0) { continue; }//为空跳过 for (int j = 0; j < XZQHItem.size(); j++) { JSONObject temp = (JSONObject) XZQHItem.get(j); String regionid = temp.getString("regionid"); if (regionid.equals(quhua+"0000")) { quhua = temp.getString("regionname"); break; } } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + quhua + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + quhua + "'"; recordcount += item.getRecordcount(); } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } /** * 资源审核状态统计饼图 */ public String getZYTJ_ShenHeZhuangTai() { String jsonResult = ""; List list = ziYuanMuLuMapper.getZYTJ_ShenHeZhuangTai(); String seriesData = ""; String legendData = ""; int recordcount = 0; for (int i = 0; i < list.size(); i++) { UserDef_ZYTJ_ShenHeZhuangTai item = list.get(i); String zhuangtai = item.getAuditstatus(); if(zhuangtai.equals("0")) { zhuangtai = "未提交"; } else if(zhuangtai.equals("1")) { zhuangtai = "待审核"; } else if(zhuangtai.equals("2")) { zhuangtai = "审核已通过"; } else if(zhuangtai.equals("3")) { zhuangtai = "审核未通过"; } seriesData += (seriesData == "" ? "" : ",") + "{ value: " + item.getRecordcount() + ", name: '" + zhuangtai + "'}"; legendData += (legendData == "" ? "" : ",") + "'" + zhuangtai + "'"; recordcount += item.getRecordcount(); } jsonResult = "{ seriesData: [" + seriesData + "], legendData: [" + legendData + "], recordcount: " + recordcount + " }"; return jsonResult; } @Override public List getZiYuanLiuLangList(Map map) { return ziYuanMuLuMapper.getZiYuanLiuLangList(map); } @Override public List selectZiYuanMuLuList(UserDef_ZYML_ChaXunQu userDef_zyml_chaXunQu) { return ziYuanMuLuMapper.selectZiYuanMuLuList(userDef_zyml_chaXunQu); } }