package com.landtool.lanbase.modules.res.controller;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
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.JSONObject;
|
import com.landtool.lanbase.common.utils.HttpOperateUtils;
|
import com.landtool.lanbase.config.SysTemPropertyConfig;
|
import com.landtool.lanbase.modules.org.entity.OrgUnit;
|
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_MainInfo;
|
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.sys.controller.AbstractController;
|
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
|
|
/**
|
* 功能描述:资源管理 - 资源注册
|
*/
|
@Controller
|
@RequestMapping("/res/ResManage/ResRegister")
|
public class ResRegisterController extends AbstractController {
|
@Autowired
|
private ResMainInfoService resMainInfoService;
|
|
@Autowired
|
private ResCatalogService resCatalogService;
|
|
@Autowired
|
private ResApplyRecommendService resApplyRecommendService;
|
|
@Autowired
|
private SysTemPropertyConfig sysConfig;
|
|
@Autowired
|
private SysFieldvalueService FieldUtils;
|
|
@Autowired
|
private OrgUnitService orgUnitService;
|
|
@Autowired
|
private OrgUserService orgUserService;
|
|
@Value("${sys.iconResourcePath}")
|
private String iconResourcePath;
|
|
/**
|
* 列表页面
|
*/
|
@RequestMapping("/List")
|
public String List(Model model) {
|
HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
|
System.out.println("测试资源类型--------------------------\n" + ResourceTypeList + "-------------------------------------------------");
|
model.addAttribute("ResourceTypeList", ResourceTypeList);
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
model.addAttribute("systemName", sysConfig.getAppFullName());
|
HashMap<String, String> SharProtocolList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
|
model.addAttribute("SharProtocolList",SharProtocolList);
|
return "ResManage/ResRegister/List";
|
}
|
|
/**
|
* 编辑页面
|
*/
|
@RequestMapping("/ResEdit")
|
public String Edit(Model model, Long resMainInfoId) {
|
if (resMainInfoId != null) {
|
Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
|
HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
|
model.addAttribute("resourceclass", ResourceTypeList.get(resMainInfo.getResourceclass()));
|
}
|
String pubzyWebRoot = sysConfig.getPubzyWebRoot();
|
model.addAttribute("resMainInfoId", resMainInfoId);
|
model.addAttribute("pubzyWebRoot", pubzyWebRoot);
|
model.addAttribute("systemName", sysConfig.getAppFullName());
|
model.addAttribute("jspwebroot", pubzyWebRoot.replace("javapubzy/", ""));// 临时处理
|
return "ResManage/ResRegister/Edit";
|
}
|
|
/**
|
* 基本信息
|
*/
|
@RequestMapping("/MainInfo")
|
public String MainInfo(HttpServletRequest request, Model model, Long resMainInfoId) throws IOException {
|
Res_MainInfo res_mainInfo = new Res_MainInfo();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Res_Catalog res_catalog = new Res_Catalog();
|
String newDate = sdf.format(new Date());
|
String Imagelujin = null;
|
int auditstatus = -1;// 审核状态
|
// 获取当前登录人id name 还有对应的单位id name
|
Long userid = getUserId();
|
|
// 修改
|
if (resMainInfoId != null) {
|
res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
|
String Pubdate = sdf.format(res_mainInfo.getPubdate());
|
if (res_mainInfo.getProductiontime() != null) {
|
String productiontimes = sdf.format(res_mainInfo.getProductiontime());
|
model.addAttribute("productiontime", productiontimes);
|
}
|
model.addAttribute("Pubdate", Pubdate);
|
if (res_mainInfo.getCatlogid() != null) {
|
res_catalog = resCatalogService.selectByPrimaryKey(res_mainInfo.getCatlogid());
|
if (res_catalog != null) {
|
model.addAttribute("catlogtitle", res_catalog.getTitle());
|
}
|
}
|
if (res_mainInfo.getImgurl() != null && res_mainInfo.getImgurl() != "") {
|
if(res_mainInfo.getImgurl().startsWith("Atkas")){//图集
|
Imagelujin = "/image/"+res_mainInfo.getImgurl();
|
}else{
|
StringBuffer url = request.getRequestURL();
|
//TODO: 这个映射路径 直接写死代码里面2018.5.20
|
String ip = "/uploadPath/";
|
Imagelujin = ip + res_mainInfo.getImgurl();
|
}
|
}
|
// modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = ' ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
|
String administrativeid = (String) res_mainInfo.getAdministrativeid();// 数据覆盖范围--行政区划Id
|
String finalValue = null;
|
if (StringUtils.isNotEmpty(administrativeid)){
|
finalValue = administrativeid.trim();
|
}
|
if (StringUtils.isNotEmpty(finalValue)) {
|
String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
|
String jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
|
if (jsonStr != null && !jsonStr.isEmpty()) {
|
JSONObject item = JSONObject.parseObject(jsonStr);
|
String regionname = item.getString("regionname");
|
model.addAttribute("administrativename", regionname);
|
}
|
}
|
// 审核状态
|
if (res_mainInfo.getAuditstatus() != null) {
|
auditstatus = res_mainInfo.getAuditstatus();
|
}
|
model.addAttribute("chinesename", orgUserService.queryObject(res_mainInfo.getCreateuserid()).getChinesename());
|
if(res_mainInfo.getPubunitid() == 0) {
|
OrgUnit orgunit = orgUserService.getDefaultUnit(res_mainInfo.getCreateuserid());
|
model.addAttribute("unitname", orgunit.getUnitname());
|
res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
|
} else {
|
OrgUnit orgunit = orgUnitService.getUnitById(res_mainInfo.getPubunitid().longValue());
|
model.addAttribute("unitname", orgunit.getUnitname());
|
}
|
} else {
|
//新增
|
OrgUnit orgunit = orgUserService.getDefaultUnit(userid);
|
String unitname = "";
|
if(orgunit.getUnitid() != null) {
|
res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
|
unitname = orgunit.getUnitname();
|
}
|
res_mainInfo.setCreateuserid(userid);
|
// modified by qufangxu
|
res_mainInfo.setInsteadaudit(0);
|
model.addAttribute("loginname", getUser().getLoginname());
|
model.addAttribute("unitname", unitname);
|
model.addAttribute("Pubdate", newDate);
|
model.addAttribute("chinesename", getUser().getChinesename());
|
}
|
HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
|
//获取数据来源列表
|
LinkedHashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();
|
String datasources = res_mainInfo.getDatasources();
|
if(StringUtils.isNotBlank(datasources)){
|
DataSourceList.put(datasources, datasources);
|
}
|
HashMap<String, String> SharProtocolList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
|
List<String> list = resMainInfoService.selectTopHotSearch();
|
String[] KeywordsList = new String[list.size()];// 获取关键字列表
|
for (int i = 0; i < list.size(); i++) {
|
KeywordsList[i] = list.get(i);
|
}
|
//换地址
|
if(res_mainInfo != null && res_mainInfo.getDesurl() != null && res_mainInfo.getDesurl().indexOf("diydes") != -1 && res_mainInfo.getDesurl().indexOf(res_mainInfo.getResourceid().toString()) != -1){
|
String url = sysConfig.getUploadRootPath()+res_mainInfo.getDesurl();
|
res_mainInfo.setDesurl(url);
|
}
|
model.addAttribute("datasourcelist", DataSourceList);
|
model.addAttribute("mainInfo", res_mainInfo);
|
// model.addAttribute("rescatalog", res_catalog);
|
model.addAttribute("resMainInfoId", resMainInfoId);
|
model.addAttribute("ResourceTypeList", ResourceTypeList);
|
model.addAttribute("Imagelujin", Imagelujin);
|
model.addAttribute("auditstatus", auditstatus);
|
model.addAttribute("SharProtocolList", SharProtocolList);
|
model.addAttribute("KeywordsList", KeywordsList);
|
|
HashMap<String, String> UpdateTimesList = FieldUtils.getFieldListByKey("UpdateTimes");// 获取更新频率列表
|
model.addAttribute("UpdateTimesList", UpdateTimesList);
|
|
if(SecurityUtils.getSubject().isPermitted("org_user_admin")) {
|
//判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
|
model.addAttribute("admin",true);
|
}
|
else {
|
model.addAttribute("admin",false);
|
}
|
return "ResManage/ResRegister/MainInfo";
|
}
|
|
/**
|
* 所属目录目录树
|
*/
|
@RequestMapping("/MuLuShu")
|
public String muLuShu(Model model) {
|
model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
return "ResManage/ResRegister/MuLuShu";
|
}
|
|
/**
|
* 行政区划目录树
|
*/
|
@RequestMapping("/AreaTree")
|
public String areaTree(Model model) {
|
model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
model.addAttribute("systemName", sysConfig.getAppFullName());
|
return "ResManage/ResRegister/AreaTree";
|
}
|
|
// 根据资源ID返回资源名称给专题地图扩展表
|
@ResponseBody
|
@RequestMapping("/dataname")
|
public String dataname(int resourceid) {
|
Res_MainInfo list = resMainInfoService.selectByPrimaryKey(resourceid);
|
String name = list.getTitle();
|
return name;
|
}
|
|
/**
|
* 资源推荐页面
|
*/
|
@RequestMapping("ZiYuanRecommend")
|
public String ziYuanRecommend(int resourceid, Model model) {
|
Long userid = getUserId();
|
model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
model.addAttribute("resourceid", resourceid);
|
model.addAttribute("userid", userid);
|
String userIds = "";
|
String unitIds = "";
|
Res_ApplyRecommend entity = new Res_ApplyRecommend();
|
entity.setResourceid(resourceid);
|
|
List<Res_ApplyRecommend> resApplyRecommendList = resApplyRecommendService.getRecommendListByResourceid(entity);
|
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();
|
}
|
}
|
|
model.addAttribute("userIds", userIds);
|
model.addAttribute("unitIds", unitIds);
|
|
return "ResManage/ResRegister/ZiYuanRecommend";
|
}
|
|
/**
|
* 图集列表
|
*/
|
@RequestMapping("/AtkasList")
|
public String AtkasList(Model model,String resourceclass) {
|
List<String > atkasList = new ArrayList<>();
|
String path = iconResourcePath;
|
TraverseFolder(path,atkasList,resourceclass);
|
model.addAttribute("atkasList",atkasList);
|
model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
model.addAttribute("systemName", sysConfig.getAppFullName());
|
return "ResManage/ResRegister/AtkasList";
|
}
|
|
public void TraverseFolder(String path,List<String> atkasList,String resourceclass) {
|
File file = new File(path);
|
if (file.exists()) {
|
File[] files = file.listFiles();
|
if (files.length != 0) {
|
for (File file2 : files) {
|
if (file2.isDirectory()) {//文件夹
|
TraverseFolder(file2.getAbsolutePath(),atkasList,resourceclass);
|
} else {//文件
|
if(resourceclass == null || resourceclass.length() == 0){
|
atkasList.add(file.getName()+"|"+file2.getName());
|
}else{
|
if(file.getName().equals(resourceclass)){
|
atkasList.add(file.getName()+"|"+file2.getName());
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|