package com.landtool.lanbase.modules.res.controller;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.UUID;
|
|
import org.apache.commons.io.FileUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.landtool.lanbase.common.annotation.LogAction;
|
import com.landtool.lanbase.config.SysTemPropertyConfig;
|
import com.landtool.lanbase.modules.org.service.OrgUserService;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
|
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
|
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
|
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
|
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.service.SysFieldvalueService;
|
|
/**
|
* @Author: lizhao
|
* @Date: 2018-03-05 17:33
|
* @Description:7系统资源扩展(专题地图)(RES_EXTTHEMEMAP)
|
*/
|
@Controller
|
@RequestMapping("/res")
|
public class ResExtThemeMapController extends AbstractController {
|
|
@Autowired
|
private ResExtThemeMapService resExtThemeMapService;
|
|
@Autowired
|
private ResExtMapUrlService resExtMapUrlService;
|
|
@Autowired
|
private SysFieldvalueService FieldUtils;
|
|
@Autowired
|
private ResMainInfoService resMainInfoService;
|
|
@Autowired
|
public SysTemPropertyConfig sysConfig;
|
|
@Autowired
|
public OrgUserService orgUserService;
|
|
/**
|
* 访问资源专题地图图层信息页面
|
*/
|
@RequestMapping("/ResManage/ResRegister/ExtThemeMap")
|
public String ExtThemeMap(int resMainInfoId, Model model) {
|
List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resMainInfoId);
|
model.addAttribute("resExtMapUrlList", resExtMapUrlList);
|
|
LinkedHashMap<String, String> typeandurlList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地理参考模型列表
|
model.addAttribute("typeandurlList", typeandurlList);
|
String typeandurlListJson = "";
|
for (Map.Entry<String, String> entry : typeandurlList.entrySet()) {
|
if (typeandurlListJson != "") typeandurlListJson += ",";
|
typeandurlListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
|
}
|
model.addAttribute("typeandurlListJson", "[" + typeandurlListJson + "]");
|
|
Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resMainInfoId);
|
if (resExtThemeMap != null) {
|
Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
|
model.addAttribute("resMainInfo", res_mainInfo);
|
model.addAttribute("resExtThemeMap", resExtThemeMap);
|
model.addAttribute("resMainInfoId", resMainInfoId);
|
|
if (resExtThemeMap.getDefaultlayerset() != null) {
|
Res_MainInfo res_mainInfo1 = resMainInfoService.selectByPrimaryKey(resExtThemeMap.getDefaultlayerset());
|
String name = res_mainInfo1.getTitle();
|
model.addAttribute("baseMapLayerName", name);
|
}
|
|
LinkedHashMap<Integer, String> tucengList = new LinkedHashMap<Integer, String>();
|
if (resExtThemeMap.getSublayerset() != null && !resExtThemeMap.getSublayerset().isEmpty()) {
|
String[] tuceng = resExtThemeMap.getSublayerset().split(",");
|
for (int i = 0; i < tuceng.length; i++) {
|
Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(tuceng[i]));
|
if(resMainInfo != null) {
|
tucengList.put(resMainInfo.getResourceid(), resMainInfo.getTitle());
|
}
|
}
|
}
|
model.addAttribute("tucengList", tucengList);
|
} else {
|
Res_MainInfo res_mainInfo = new Res_MainInfo();
|
model.addAttribute("resMainInfo", res_mainInfo);
|
Res_ExtThemeMap resExtThemeMap1 = new Res_ExtThemeMap();
|
model.addAttribute("resExtThemeMap", resExtThemeMap1);
|
model.addAttribute("tucengList", new LinkedHashMap<Integer, String>());
|
}
|
|
LinkedHashMap<String, String> PublishSoftList = FieldUtils.getFieldListByKey("PublishSoft");//获取发布平台字典列表
|
LinkedHashMap<String, String> typeList = FieldUtils.getFieldListByKey("ThemeMapType");//获取发布平台字典列表
|
model.addAttribute("PublishSoftList", PublishSoftList);
|
model.addAttribute("typeList", typeList);
|
|
if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
|
//判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
|
model.addAttribute("admin", true);
|
} else {
|
model.addAttribute("admin", false);
|
}
|
model.addAttribute("esbHost",sysConfig.getEsbHost());
|
model.addAttribute("esbUrl",sysConfig.getEsbUrl());
|
String oldesbids = resExtThemeMap != null ? resExtMapUrlService.queryRsbidsByResourceid(resMainInfoId):"";
|
model.addAttribute("oldesbids",oldesbids);
|
model.addAttribute("ipHost",sysConfig.getIpHost());
|
model.addAttribute("gisHost",sysConfig.getGisHost());
|
return "ResManage/ResRegister/ExtThemeMap";
|
}
|
|
/**
|
* 根据id 删除专题地图列表功能
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/deleteByPrimaryKey")
|
public int deleteByPrimaryKey(int resourceid) {
|
|
return resExtThemeMapService.deleteByPrimaryKey(resourceid);
|
}
|
|
/**
|
* 插入专题地图列表功能(所有元素不能为空)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/insert")
|
public int insert(Res_ExtThemeMap record) {
|
return resExtThemeMapService.insert(record);
|
}
|
|
/**
|
* 插入专题地图列表功能(可以只填写必填字段)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/insertSelective")
|
public int insertSelective(Res_ExtThemeMap record) {
|
return resExtThemeMapService.insertSelective(record);
|
}
|
|
/**
|
* 插入专题地图列表功能(可以只填写必填字段)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/insertSelectiveAndUpdate")
|
@LogAction("资源管理,资源发布,资源修改,修改|zy")
|
public int insertSelectiveAndUpdate(Res_ExtThemeMap record, Res_MainInfo resMainInfo, String extMapUrlStr) {
|
// 插入资源支持协议与地址表
|
resExtMapUrlService.deleteAndInsertMapUrlArray(record.getResourceid(),extMapUrlStr);
|
Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(record.getResourceid());
|
|
if (resExtThemeMap == null) {
|
//添加
|
//alter: Xxx 处理资源注册向导新增时没有ESB代理
|
int mainInfoResult = 0;
|
if(resMainInfo.getEspproxy() != null) {
|
mainInfoResult = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
|
} else {
|
mainInfoResult = 1;
|
}
|
if(!record.getLegendurl().isEmpty()) {
|
TiHuanLuJin(record.getLegendurl());
|
}
|
int themeMapResult = resExtThemeMapService.insertSelective(record);
|
int result;
|
if (mainInfoResult == 1 && themeMapResult == 1) {
|
result = 1;
|
} else {
|
result = 0;
|
}
|
return result;
|
} else {
|
//更新
|
String path = sysConfig.getUploadPath() + "ResExtThemMapServer/" + resExtThemeMap.getLegendurl();
|
File file = new File(path);
|
if(file.exists()) {
|
file.delete();
|
}
|
int mainInfoResult = 0;
|
if(resMainInfo.getEspproxy() != null) {
|
mainInfoResult = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
|
} else {
|
mainInfoResult = 1;
|
}
|
if(!record.getLegendurl().isEmpty()) {
|
TiHuanLuJin(record.getLegendurl());
|
}
|
int themeMapResult = resExtThemeMapService.updateByPrimaryKeyWithBLOBs(record);
|
int result;
|
if (mainInfoResult == 1 && themeMapResult == 1) {
|
result = 1;
|
} else {
|
result = 0;
|
}
|
return result;
|
}
|
}
|
|
//替换路径
|
private void TiHuanLuJin(@RequestBody String lujin) {
|
lujin = "temp/ResExtThemMapServer/" +lujin;
|
String oldFileUrl=sysConfig.getUploadPath() + lujin.replace("/","\\");
|
File oldFile=new File(oldFileUrl);
|
String NewFileUrl=sysConfig.getUploadPath()+lujin.replace("temp/","").replace("/","\\");
|
NewFileUrl=NewFileUrl.substring(0,NewFileUrl.lastIndexOf("\\"))+"\\" ;
|
File NewFile=new File(NewFileUrl);
|
if (!NewFile.exists()) { // 当前地址不为空,判断该路径是否存在,不存在则创建新的文件夹
|
File newfilePath = new File(NewFile+"\\");
|
newfilePath.mkdirs();
|
}
|
com.landtool.lanbase.common.utils.FileUtils.moveTotherFolders(oldFileUrl,NewFileUrl);
|
if(oldFile.exists()) {
|
oldFile.delete();
|
}
|
}
|
|
/**
|
* 根据id查询专题地图列表
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/selectByPrimaryKey")
|
public Res_ExtThemeMap selectByPrimaryKey(int resourceid) {
|
return resExtThemeMapService.selectByPrimaryKey(resourceid);
|
}
|
|
/**
|
* 根据id更新专题地图列表(更新数据,数据可以为null)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/updateByPrimaryKeySelective")
|
public int updateByPrimaryKeySelective(Res_ExtThemeMap record) {
|
return resExtThemeMapService.updateByPrimaryKeySelective(record);
|
}
|
|
/**
|
* 根据id更新专题地图列表(更新所有数据)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/updateByPrimaryKeyWithBLOBs")
|
public int updateByPrimaryKeyWithBLOBs(Res_ExtThemeMap record) {
|
return resExtThemeMapService.updateByPrimaryKeyWithBLOBs(record);
|
}
|
|
/**
|
* 根据id更新专题地图列表(更新数据,但是ZITUCHENGSET 列不能更新)
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/updateByPrimaryKey")
|
public int updateByPrimaryKey(Res_ExtThemeMap record) {
|
return resExtThemeMapService.updateByPrimaryKey(record);
|
}
|
|
/**
|
* 子图层设置页面
|
*/
|
@RequestMapping("/ResExtThemeMap/ZiTuCengSheZhi")
|
public String ziTuCengSheZhi(Model model, String selectids) {
|
model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
|
model.addAttribute("systemName", sysConfig.getAppFullName());
|
//获取数据来源列表
|
LinkedHashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();
|
model.addAttribute("datasourcelist", DataSourceList);
|
model.addAttribute("selectids", selectids);
|
return "/ResManage/ResRegister/ZiTuCengSheZhi";
|
}
|
|
/**
|
* 查询专题地图模块我的制图列表(此方法放到 ZhuanTiZhiTuContonller 里,方法名:getWoDeZhiTu,如果还有其他地方调用就把注释去掉。 蔡 2018-05-21)
|
* @param request
|
* @param pageBean
|
* @return
|
*/
|
// @ResponseBody
|
// @RequestMapping(value = "/ResExtThemeMap/selectZTDTList", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
|
// public String selectZTDTList(HttpServletRequest request, PageBean pageBean) {
|
// String callbackFunName = request.getParameter("callback");
|
// if(callbackFunName == null || callbackFunName.isEmpty()){
|
// callbackFunName = "callback";
|
// }
|
// PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
|
// Long userid = getUserId();
|
// Map<String, Object> map = new HashMap<>();
|
// map.put("leixiId", "KJ_ZTDT");
|
// map.put("userid", userid);
|
// List<Res_MainInfo> res_mainInfos = resMainInfoService.selectZTDTList(map);
|
// int countNums = (int) ((Page) res_mainInfos).getTotal();
|
// PageBean<Res_MainInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
|
// pageData.setItems(res_mainInfos);
|
//
|
// StringBuilder rsb = new StringBuilder();
|
// rsb.append("[");
|
// for (int i = 0; i < res_mainInfos.size(); i++) {
|
// if(i > 0) rsb.append(",");
|
// rsb.append("{resourceId:" + res_mainInfos.get(i).getResourceid());
|
// rsb.append(", title: '" + res_mainInfos.get(i).getTitle() + "'}");
|
// }
|
// rsb.append("]");
|
//
|
// return callbackFunName + "(" + rsb.toString() + ")";
|
// }
|
|
/**
|
* 自定义图例上传
|
*/
|
@ResponseBody
|
@RequestMapping("/ResExtThemeMap/fileUploadTuLi")
|
public String fileUploadTuLi(@RequestParam("file") MultipartFile multipartFile,String legendurl) {
|
if (multipartFile.isEmpty()) {
|
return "请选择需要上传的文件!";
|
}
|
|
String[] imgTypeArr = new String[] { "jpg", "png", "gif", "bmp", "jpeg" };
|
String imgType = multipartFile.getContentType();// 获取文件格式
|
boolean IsImg = false;// 文件格式检查状态
|
// 判断上传文件格式
|
for (int i = 0; i < imgTypeArr.length; i++) {
|
if (imgType.toLowerCase().endsWith(imgTypeArr[i])) {
|
IsImg = true;
|
break;
|
}
|
}
|
|
if(IsImg) {
|
legendurl = sysConfig.getUploadPath() + "temp/ResExtThemMapServer/" + legendurl;
|
File file = new File(legendurl);
|
if(file.exists()) {
|
file.delete();
|
}
|
String name = multipartFile.getOriginalFilename();
|
|
//名称
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
String fileType = name.substring(name.lastIndexOf("."));
|
String Filename = uuid + fileType;
|
|
// String path = sysConfig.getUploadPath() + "ResExtThemMapServer\\";
|
String path = sysConfig.getUploadPath() + "temp/ResExtThemMapServer/"; // 类型为文件指向文件
|
// String path2 = "temp/ResExtThemMapServer/";
|
File desFile = new File(path + Filename);
|
String info = desFile.getAbsolutePath();
|
try {
|
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), desFile);
|
return "{'result':'1','Path':'" + Filename + "','Filename':'" + name.substring(name.lastIndexOf("\\") + 1, name.lastIndexOf(".")) + "'}";
|
} catch (IOException e) {
|
e.printStackTrace();
|
return "{'result':'0'}";
|
}
|
}
|
else {
|
return "{'result':'-1'}";
|
}
|
}
|
|
}
|