1、controller
geoserver.jar
package com.jeeplus.common.utils;
import java.io.File;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jeeplus.common.config.Global;
import ev.springboot.gsserver.RasterPublish;
/**
-
@author zb
-
圖層發佈
*/
public class RasterPublishUtils {private static Logger log = LoggerFactory.getLogger(RasterPublishUtils.class);
/**
- 獲取geoserver連接
- @return
*/
public static RasterPublish createGeoserverConnect(){
log.info(“獲取geoserver連接開始!”);
RasterPublish rasterPublish = null;
try {
String url = Global.getConfig(“geoserver.url”);
String username = Global.getConfig(“geoserver.username”);
String password = Global.getConfig(“geoserver.password”);
String ws = Global.getConfig(“geoserver.ws”);
rasterPublish = new RasterPublish(url,username,password,ws);
rasterPublish.GeneralWorkspace();
} catch (Exception e) {
rasterPublish = null;
log.error(“獲取geoserver連接失敗!errorMsg:” + e.getMessage());
}
log.info(“獲取geoserver連接結束”);
return rasterPublish;
}
/**
- 發佈tif 圖層
- @param filePath
- @param storeName
- @param styleName
- @return
*/
public static boolean rasterPublish(RasterPublish rasterPublish,String filePath,String storeName,String styleName){
log.info(“發佈圖層開始”);
boolean bl = true;
try {
//rasterPublish.GeneralRestStyles(styleName, asld);
//String filePath=“C:\Users\Admin\Desktop\水保監測\yingshan_taohe2015_erosion073077_xz1.tif”;
//String filePath=“C:\Users\Admin\Desktop\水保監測\yingshan_taohe2015_erosion073077_xz2new.tif”;
//String styleName = “aFactorStyle”;//raster aFactorStyle
String path = Global.getConfig(“afator.tif.rootpath”) + filePath;
log.info(“path:”+path);
File file = new File(path);
if(file.exists()) {
rasterPublish.Publish(path, storeName, storeName, styleName);
}
else {
log.info(“path:” + path + “文件不存在!”);
bl = false;
}
/rasterPublish.DeleteCoverage(storeName);/
} catch (Exception e) {
bl = false;
log.error(“發佈tif圖層失敗!errorMsg:” + e.getMessage());
}
log.info(“發佈tif圖層結束”);
return bl;
}
}
/**
*
*/
package com.jeeplus.common.utils;
/**
-
@Description
-
A因子計算因子類型常量
*/
public enum AFactorTypeEnum{水土流失模數(“土壤侵蝕模數”,1,“a.tif”,“aFactorStyle”), //土壤侵蝕模數
降雨侵蝕因子(“降雨侵蝕因子”,2,“r.tif”,“rFactorStyle”),
植被覆蓋與生物措施因子(“植被覆蓋與生物措施因子”,3,“b.tif”,“bFactorStyle”),
工程措施因子(“工程措施因子”,4,“e.tif”,“eFactorStyle”),
土壤可蝕性因子(“土壤可蝕性因子”,5,“k.tif”,“kFactorStyle”),
坡長因子(“坡長因子”,6,“l.tif”,“lFactorStyle”),
坡度因子(“坡度因子”,7,“s.tif”,“sFactorStyle”),
耕作措施因子(“耕作措施因子”,8,“t.tif”,“tFactorStyle”);/**
- 根據 因子類型獲取因子
- @param factorType
- @return
/
public static String getTifNameByType(Integer factorType){
String tifName = null;
for(AFactorTypeEnum platformFree:AFactorTypeEnum.values()){
if(factorType.equals(platformFree.getFactorType())){
tifName = platformFree.getTifName();
break;
}
}
return tifName;
}
/* - 根據 因子類型獲取因子樣式名
- @param factorType
- @return
*/
public static String getStyleNameByType(Integer factorType){
String styleName = null;
for(AFactorTypeEnum platformFree:AFactorTypeEnum.values()){
if(factorType.equals(platformFree.getFactorType())){
styleName = platformFree.getStyleName();
break;
}
}
return styleName;
}
/**
- 因子描述
/
private String factorDescribe;
/* - 類型值
*/
private Integer factorType;
/**
- tiff文件名
/
private String tifName;
/* - 樣式名
*/
private String styleName;
AFactorTypeEnum(String factorDescribe, Integer factorType, String tifName, String styleName) {
this.factorDescribe = factorDescribe;
this.factorType = factorType;
this.tifName = tifName;
this.setStyleName(styleName);
}public String getFactorDescribe() {
return factorDescribe;
}public void setFactorDescribe(String factorDescribe) {
this.factorDescribe = factorDescribe;
}public Integer getFactorType() {
return factorType;
}public void setFactorType(Integer factorType) {
this.factorType = factorType;
}public String getTifName() {
return tifName;
}public void setTifName(String tifName) {
this.tifName = tifName;
}
public String getStyleName() {
return styleName;
}
public void setStyleName(String styleName) {
this.styleName = styleName;
}
}
package com.jeeplus.modules.analysis.web;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.AfactorPlanTypeEnum;
import com.jeeplus.common.utils.CommonContants;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.analysis.dto.GeoPublishEntity;
import com.jeeplus.modules.analysis.entity.AFactorPlan;
import com.jeeplus.modules.analysis.entity.AFactorPlanGeo;
import com.jeeplus.modules.analysis.entity.Basininfo;
import com.jeeplus.modules.analysis.service.AFactorPlanGeoService;
import com.jeeplus.modules.analysis.service.AFactorPlanService;
import com.jeeplus.modules.analysis.service.BasininfoService;
import com.jeeplus.modules.sys.entity.Area;
import com.jeeplus.modules.sys.service.AreaService;
import com.jeeplus.modules.sys.utils.UserUtils;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
/**
-
A因子計算 侵蝕模數
-
@author zb
-
@date 創建時間:2019年10月14日 下午3:06:26
*/
@Controller
@RequestMapping(value = “${adminPath}/analysis/aFactorMap”)
public class AFactorMapController extends BaseController {@Autowired
private AreaService areaService;
@Autowired
private AFactorPlanService aFactorPlanService;
@Autowired
private AFactorPlanGeoService aFactorPlanGeoService;
@Autowired
private BasininfoService basininfoService;@RequestMapping(value = { “index”, “” })
public String index(HttpServletRequest request) {
request.setAttribute(“userLevel”, UserUtils.getUserLevel());
request.setAttribute(“userAreaCode”, UserUtils.getUserAreaCode());
request.setAttribute(“userAreaName”, UserUtils.getUserAreaName());
return “modules/analysis/aFactorMap”;
}@ResponseBody
@RequestMapping(“getData”)
public Map<String, Object> getData(AFactorPlan aFactorPlan, HttpServletRequest request, HttpServletResponse response, Model model) {
Integer userLevel = UserUtils.getUserLevel();
String userAreaCode = UserUtils.getUserAreaCode();
aFactorPlan.setUserLevel(userLevel);
aFactorPlan.setUserAreaCode(userAreaCode);
//省級不做過濾
// if(!userLevel.equals(1)) {
// List areaCodes = areaService.getChildAndCodesByCode(userAreaCode);
// List basincodes = basininfoService.getBasincodesByAreaCode(areaCodes);
// if(areaCodes != null && areaCodes.size()>0) {
// aFactorPlan.setSearchAreaCodes(String.join(",",areaCodes));
// }
// if(basincodes != null && basincodes.size()>0) {
// aFactorPlan.setSearchBasincodes(String.join(",",basincodes));
// }
// }
Page page = aFactorPlanService.findPage(new Page(request, response), aFactorPlan);
List list = page.getList();
this.setZonalName(list);
return getBootstrapData(page);
}/**
- 設置區域名稱
- @param list
*/
public void setZonalName(List list){
for (AFactorPlan aFactorPlan2 : list) {
String scope = aFactorPlan2.getScope();
//取小流域名稱
if(CommonContants.SCOPE_XIAOLIUYU.equals(scope)) {
Basininfo basininfo = new Basininfo();
basininfo.setBasincodes(aFactorPlan2.getZonalCode().split(","));
List basininfoList = basininfoService.findList(basininfo);
aFactorPlan2.setBasincode(aFactorPlan2.getZonalCode());
if(basininfoList != null && basininfoList.size()>0) {
String basinname = “”;
String zonalName = “”;
for (Basininfo basininfo2 : basininfoList) {
basinname +=("".equals(basinname)?basininfo2.getBasinname():","+basininfo2.getBasinname());
zonalName +=("".equals(zonalName)?basininfo2.getCounty()+ “/” +basininfo2.getBasinname():","+basininfo2.getCounty()+ “/” +basininfo2.getBasinname());
}
aFactorPlan2.setBasinname(basinname);
aFactorPlan2.setZonalName(zonalName);
}
else {
aFactorPlan2.setBasincode(aFactorPlan2.getZonalCode());
aFactorPlan2.setZonalName(aFactorPlan2.getZonalCode());
}
}
//取區域名稱
else {
if(aFactorPlan2.getZonalCode() != null && “42”.equals(aFactorPlan2.getZonalCode())) {
aFactorPlan2.setZonalName(“湖北省”);
}
else {
List areas = areaService.getAreaByCodes(aFactorPlan2.getZonalCode().split(","));
String zonalName = “”;
if(areas != null && areas.size()>0) {
for (Area area:areas) {
zonalName +=("".equals(zonalName)?area.getName():","+area.getName());
}
}
aFactorPlan2.setZonalName("".equals(zonalName)?aFactorPlan2.getZonalCode():zonalName);
}
}
}
}
@ResponseBody
@RequestMapping(value = “save”)
public AjaxJson save(AFactorPlan aFactorPlan, HttpServletRequest request) throws Exception {
AjaxJson j = new AjaxJson();
String errMsg = beanValidator(aFactorPlan);
if (StringUtils.isNotBlank(errMsg)) {
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
if(AfactorPlanTypeEnum.A實時.getAFactorPlanType().equals(aFactorPlan.getPlanType())) {
// 設置 A計算 區域編碼 zonalCode
aFactorPlanService.setAFactorZonalCode(aFactorPlan);
// 驗證數據的重複性
List aFactorPlanList = aFactorPlanService.getAFactorByTimeAndPlanType(aFactorPlan);
if(aFactorPlanList != null && aFactorPlanList.size()>0) {
j.setSuccess(false);
this.setZonalName(aFactorPlanList);
j.put(“aFactorPlanList”,aFactorPlanList);
j.setMsg(“保存計算任務失敗!已經存在相同的計算任務”+aFactorPlanList.size()+“條!”);
return j;
}
aFactorPlanService.saveAfactor(aFactorPlan);// 保存 A 計算
}
else {
// 設置 R計算 區域編碼 zonalCode
aFactorPlanService.setRFactorZonalCode(aFactorPlan);
// 驗證數據的重複性
List aFactorPlanList = aFactorPlanService.getAFactorByTimeAndPlanType(aFactorPlan);
if(aFactorPlanList != null && aFactorPlanList.size()>0) {
j.setSuccess(false);
this.setZonalName(aFactorPlanList);
j.put(“aFactorPlanList”,aFactorPlanList);
j.setMsg(“保存計算任務失敗!已經存在相同的計算任務”+aFactorPlanList.size()+“條!”);
return j;
}
aFactorPlanService.saveRfactor(aFactorPlan);// 保存 R 計算
}
j.setSuccess(true);
j.setMsg(“保存計算任務成功”);
return j;
}/**
- 查看a因子計算相關信息
- 發佈因子相關的tif文件到geoserver
- @param aFactorPlan
- @param request
- @return
- @throws Exception
*/
@ResponseBody
@RequestMapping(value = “rePublish”)
public AjaxJson rePublish(AFactorPlan aFactorPlan, HttpServletRequest request) throws Exception {
AjaxJson j = new AjaxJson();
// 因子類型
Integer factorType = aFactorPlan.getFactorType();
// 任務類型
String planType = aFactorPlan.getPlanType();
if(factorType == null) {
j.setSuccess(false);
j.setMsg(“查看因子類型不能爲空!”);
return j;
}
if(planType == null || “”.equals(planType)) {
j.setSuccess(false);
j.setMsg(“任務類型不能爲空!”);
return j;
}
//用戶級別
Integer userLevel = UserUtils.getUserLevel();
//獲取任務ID
String aFactorPlanId = aFactorPlan.getId();
// A計算任務ID爲空取定時任務產生的tif圖層
if(aFactorPlanId == null || “”.equals(aFactorPlanId)) {
AFactorPlan aFactorPlanParam = new AFactorPlan();
//定時計算 由開始時間和任務類型就可以確定一個任務,先查詢任務,根據任務查詢或者發佈tif圖層進行展示
aFactorPlanParam.setStartTime(getStartTimeByPlanType(planType));
//aFactorPlanParam.setEndTime(getEndTime());
aFactorPlanParam.setPlanType(planType);
aFactorPlanParam.setScope(CommonContants.SCOPE_SHENG);
List aFactorPlanList = aFactorPlanService.getAFactorByTimeAndPlanType(aFactorPlanParam);
if(aFactorPlanList != null && aFactorPlanList.size()>0) {
boolean haveSuccess = false;
String errorMessage = “定時計算失敗!”;
for (AFactorPlan aFactorPlanRes:aFactorPlanList) {
if(CommonContants.AFACTOR_PLAN_STATE_SUCCESS.equals(aFactorPlanRes.getState())) {
haveSuccess = true;
aFactorPlanId = aFactorPlanRes.getId();
break;
}
else if(CommonContants.AFACTOR_PLAN_STATE_ERROR.equals(aFactorPlanRes.getState())) {
errorMessage = aFactorPlanRes.getErrorMessage();
}
}
if(!haveSuccess) {
j.setSuccess(false);
j.setMsg(errorMessage);
return j;
}
}
else {
j.setSuccess(false);
j.setMsg(“沒有查詢到該因子圖層!”);
return j;
}
}
// 查詢圖層是否存在
AFactorPlanGeo aFactorPlanGeoParam = new AFactorPlanGeo();
aFactorPlanGeoParam.setAFactorPlanId(aFactorPlanId);
aFactorPlanGeoParam.setFactorType(factorType);
//不是省級用戶,取省級任務下的定時任務生成的tif圖層
List areaCodes = null;
if(StringUtils.isBlank(aFactorPlan.getId()) && userLevel != null && (!userLevel.equals(1))) {
areaCodes = areaService.getChildAndCodesByCode(UserUtils.getUserAreaCode());
aFactorPlanGeoParam.setAreaCodes(areaCodes);
}
//獲取任務 圖層是否存在,存在直接展示,不存在先發布圖層再展示
List aFactorPlanGeoList = aFactorPlanGeoService.getAFactorPlanGeoByFactorIdAndType(aFactorPlanGeoParam);
if(aFactorPlanGeoList != null && aFactorPlanGeoList.size()>0) {
// 定時任務爲省級,市級、縣級用戶需要過濾
if(areaCodes != null) {
j.put(“aFactorPlanGeoList”, filterAFactorPlanGeoListByAreaCodes(aFactorPlanGeoList, areaCodes));
}
else {
j.put(“aFactorPlanGeoList”, aFactorPlanGeoList);
}
j.setSuccess(true);
j.setMsg(“圖層已發佈成功,可直接展示!”);
return j;
}
//獲取要發佈的圖層
List geoPublishList = aFactorPlanService.getGeoPublishList(aFactorPlanId,factorType);
if(geoPublishList == null || geoPublishList.size() == 0) {
j.setSuccess(false);
j.setMsg(“沒有獲取到可以發佈的圖層!”);
return j;
}
//發佈圖層
aFactorPlanGeoList = aFactorPlanService.rePublicGeo(geoPublishList);
if(aFactorPlanGeoList != null && aFactorPlanGeoList.size()>0) {
// 定時任務爲省級,市級、縣級用戶需要過濾
if(areaCodes != null) {
j.put(“aFactorPlanGeoList”, filterAFactorPlanGeoListByAreaCodes(aFactorPlanGeoList, areaCodes));
}
else {
j.put(“aFactorPlanGeoList”, aFactorPlanGeoList);
}
j.setSuccess(true);
j.setMsg(“發佈圖層成功!”);
}
else {
j.setSuccess(false);
j.setMsg(“發佈圖層失敗!”);
}
return j;
}
/**
- 根據區劃集合過濾數據
- @param aFactorPlanGeoList
- @param areaCodes
- @return
*/
public List filterAFactorPlanGeoListByAreaCodes(List aFactorPlanGeoList, List areaCodes){
List aFactorPlanGeoListFilter = new ArrayList();
for (AFactorPlanGeo aFactorPlanGeo:aFactorPlanGeoList
) {
boolean bl= areaCodes.stream().anyMatch(areaCode -> Objects.equals(areaCode, aFactorPlanGeo.getZonalCode()));
if(bl) {
aFactorPlanGeoListFilter.add(aFactorPlanGeo);
}
}
return aFactorPlanGeoListFilter;
}
/**
- 獲取定時的開始時間
- @return
*/
public Date getStartTimeByPlanType(String planType){
Date result = new Date();
//當前年 月 日
Calendar currCal = Calendar.getInstance();
int currentYear = currCal.get(Calendar.YEAR);
int currentMonth = currCal.get(Calendar.MONTH) + 1;
int currentDay = currCal.get(Calendar.DAY_OF_MONTH);
Calendar cale = Calendar.getInstance();
// 註釋:cale.set(Calendar.MONTH, currentMonth - 1);代表設置月份爲本月
//1、任務類型爲A定時年、R定時年
if(AfactorPlanTypeEnum.A定時年.getAFactorPlanType().equals(planType) || AfactorPlanTypeEnum.R定時年.getAFactorPlanType().equals(planType)) {
cale.clear();
// 2019 年 查看的數據的開始時間是 2017年12月31號20點
cale.set(Calendar.YEAR,currentYear-2);
cale.roll(Calendar.DAY_OF_YEAR, -1);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
result = cale.getTime();
}
//2、任務類型爲A定時月、R定時月
else if(AfactorPlanTypeEnum.A定時月.getAFactorPlanType().equals(planType) || AfactorPlanTypeEnum.R定時月.getAFactorPlanType().equals(planType)) {
cale.clear();
//上半月,取上個月下半月的數據
if(currentMonth == 1) {
// 1 月 取上一年 11月 最後一天開始的
cale.set(Calendar.YEAR,currentYear-1);
cale.set(Calendar.MONTH,10);
// 獲取某月最大天數
int lastDay = cale.getActualMaximum(Calendar.DATE);
cale.set(Calendar.DAY_OF_MONTH, lastDay);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
else {
// 取上個月 15號20點開始的
cale.set(Calendar.YEAR,currentYear);
//設置月份爲上上個月
cale.set(Calendar.MONTH, currentMonth - 3);
// 獲取某月最大天數
int lastDay = cale.getActualMaximum(Calendar.DATE);
cale.set(Calendar.DAY_OF_MONTH, lastDay);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
result = cale.getTime();
}
//3、任務類型爲A定時半月、R定時半月
else if(AfactorPlanTypeEnum.A定時半月.getAFactorPlanType().equals(planType) || AfactorPlanTypeEnum.R定時半月.getAFactorPlanType().equals(planType)) {
cale.clear();
if(currentDay < 16) {
//上半月,取上個月下半月的數據
if(currentMonth == 1) {
// 1 月 取上一年 12月15號開始的
cale.set(Calendar.YEAR,currentYear-1);
cale.set(Calendar.MONTH,11);
cale.set(Calendar.DAY_OF_YEAR, 15);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
else {
// 取上個月 15號20點開始的
cale.set(Calendar.YEAR,currentYear);
cale.set(Calendar.MONTH, currentMonth - 2);
cale.set(Calendar.DAY_OF_MONTH, 15);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
}
else {
//下半月, 取本月上半月
if(currentMonth == 1) {
// 1 月 取上一年 12月最後一天20點開始的
cale.set(Calendar.YEAR,currentYear-1);
cale.roll(Calendar.DAY_OF_YEAR, -1);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
else {
// 取上月 最後一天 20點開始的
cale.set(Calendar.YEAR,currentYear);
cale.set(Calendar.DAY_OF_MONTH,currentMonth - 2);
// 獲取某月最大天數
int lastDay = cale.getActualMaximum(Calendar.DATE);
cale.set(Calendar.DAY_OF_MONTH, lastDay);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
}
}
result = cale.getTime();
}
//5、任務類型爲A定時日、R定時日
else if(AfactorPlanTypeEnum.A定時日.getAFactorPlanType().equals(planType) || AfactorPlanTypeEnum.R定時日.getAFactorPlanType().equals(planType)) {
cale.add(Calendar.DAY_OF_MONTH, -2);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
result = cale.getTime();
}
return result;
}
/**
- 獲取定時的結束時間
- @return
*/
public Date getEndTime(){
Calendar cale = Calendar.getInstance();
cale.add(Calendar.DAY_OF_MONTH, -1);
cale.set(Calendar.HOUR_OF_DAY, 20);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);// 毫秒
return cale.getTime();
}
}
2、service
/**
- Copyright © 2015-2020 JeePlus All rights reserved.
*/
package com.jeeplus.modules.analysis.service;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.utils.*;
import com.jeeplus.common.utils.time.DateFormatUtil;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.analysis.dto.GeoPublishEntity;
import com.jeeplus.modules.analysis.entity.AFactorPlan;
import com.jeeplus.modules.analysis.entity.AFactorPlanGeo;
import com.jeeplus.modules.analysis.mapper.AFactorPlanGeoMapper;
import com.jeeplus.modules.analysis.mapper.AFactorPlanMapper;
import com.jeeplus.modules.analysis.mapper.BasininfoMapper;
import com.jeeplus.modules.sys.entity.AddvSbSj;
import com.jeeplus.modules.sys.entity.Area;
import com.jeeplus.modules.sys.mapper.AreaMapper;
import com.jeeplus.modules.sys.mapper.SbSjMapper;
import ev.springboot.gsserver.RasterPublish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
-
A因子計算Service
-
@author zb
-
@version 2019-10-24
*/
@Service
@Transactional(readOnly = true)
public class AFactorPlanService extends CrudService<AFactorPlanMapper, AFactorPlan> {@Autowired
private AFactorPlanGeoMapper aFactorPlanGeoMapper;
@Autowired
private AreaMapper areaMapper;
@Autowired
private BasininfoMapper basininfoMapper;
@Autowired
private SbSjMapper sbSjMapper;public AFactorPlan get(String id) {
return super.get(id);
}public List findList(AFactorPlan aFactorPlan) {
return super.findList(aFactorPlan);
}
public List getAFactorByTimeAndPlanType(AFactorPlan aFactorPlan) {
return mapper.getAFactorByTimeAndPlanType(aFactorPlan);
}/**
- 發佈圖層,可發佈多個
- @param geoPublishList
- @return
*/
@Transactional(readOnly = false,rollbackFor = Exception.class)
public List rePublicGeo(List geoPublishList){
List aFactorPlanGeoList = new ArrayList();
//獲取geoserver連接
RasterPublish rasterPublish = RasterPublishUtils.createGeoserverConnect();
if(rasterPublish == null) {
return aFactorPlanGeoList;
}
for (GeoPublishEntity geoPublishEntity: geoPublishList) {
boolean bl = RasterPublishUtils.rasterPublish(rasterPublish,geoPublishEntity.getFilePath(),geoPublishEntity.getStoreName(),geoPublishEntity.getStyleName());
AFactorPlanGeo aFactorPlanGeoResp = new AFactorPlanGeo();
if(!bl) {
aFactorPlanGeoResp.setAFactorPlanId(geoPublishEntity.getaFactorPlanId());
aFactorPlanGeoResp.setFactorType(geoPublishEntity.getFactorType());
aFactorPlanGeoResp.setGeoWs(Global.getConfig(“geoserver.ws”));
aFactorPlanGeoResp.setGeoName(geoPublishEntity.getStoreName());
aFactorPlanGeoResp.setPlanName(geoPublishEntity.getaFactorPlan().getPlanName());
aFactorPlanGeoResp.setPlanType(geoPublishEntity.getaFactorPlan().getPlanType());
aFactorPlanGeoResp.setScope(geoPublishEntity.getaFactorPlan().getScope());
aFactorPlanGeoResp.setZonalCode(geoPublishEntity.getZonalCode());
aFactorPlanGeoResp.setSuccess(false);
aFactorPlanGeoResp.setMsg(“區域編碼爲:”+geoPublishEntity.getZonalCode()+“的圖層發佈失敗!”);
}
else {
//保存影像信息
aFactorPlanGeoResp = saveAfactorGeo(geoPublishEntity);
aFactorPlanGeoResp.setSuccess(true);
}
aFactorPlanGeoList.add(aFactorPlanGeoResp);
}
return aFactorPlanGeoList;
}
/**
- 獲取要發佈的圖層集合
- @param aFactorPlanId
- @param factorType
- @return
/
public List getGeoPublishList(String aFactorPlanId,Integer factorType){
List geoPublishList = new ArrayList();
AFactorPlan aFactorPlanResponse = mapper.get(aFactorPlanId);
aFactorPlanResponse.setFactorType(factorType);
// 區域編碼或小流域編碼
String zonalCode = aFactorPlanResponse.getZonalCode();
zonalCode = zonalCode.length() == 2?(zonalCode+“0000”):zonalCode;
// 計算範圍、省、市、縣、小流域
String scope = aFactorPlanResponse.getScope();
// 任務類型(“A實時”、“R實時”、“A定時”、“R定時”。。)
String planType = aFactorPlanResponse.getPlanType();
// 任務名稱
String planName = aFactorPlanResponse.getPlanName();
// 任務計算週期開始時間
//Date startTime = aFactorPlanResponse.getStartTime();
//Date endTime = aFactorPlanResponse.getEndTime();
Date date = aFactorPlanResponse.getStartTime();
Date endTime = aFactorPlanResponse.getEndTime();
// 因子圖相對路徑
String planTypePath = CommonContants.AFACTOR_REALTIME;
if(factorType>2) {
//6因子
planTypePath = CommonContants.AFACTOR_BG;
// B 因子
// 實時計算所選時間段跨半月
//B因子:42/4201/420101/RealTime/20191023110000/b.tif。
//實時計算所選時間段沒跨半月,判斷查詢時間段所屬半月號,如2019-11-01 —— 2019-11-10,則屬於21半月,其B因子在
//B因子:42/4201/420101/ bg00/slr/slr21.tif實時計算所選時間段跨半月
//B因子:42/4201/420101/RealTime/20191023110000/b.tif。
//實時計算所選時間段沒跨半月,判斷查詢時間段所屬半月號,如2019-11-01 —— 2019-11-10,則屬於21半月,其B因子在
//B因子:42/4201/420101/ bg00/slr/slr21.tif
if(AFactorTypeEnum.植被覆蓋與生物措施因子.getFactorType().equals(factorType)) {
if(AfactorPlanTypeEnum.A實時.getAFactorPlanType().equals(planType)){
//沒有跨半月, 不進行計算 直接取42/4201/420101/ bg00/slr/slr21.tif
if(isNotKuaBanYue(date,endTime)) {
planTypePath = CommonContants.AFACTOR_BG + “/slr”;
}
else {
planTypePath = CommonContants.AFACTOR_REALTIME + “/” + planName;
}
}
else {
// 定時的都是跨半月的
planTypePath = CommonContants.AFACTOR_REALTIME + “/” + planName;
}
}
}
else {
// A因子 R因子
planTypePath = this.getPlanFilePathByDateAndPlanType(date, planType, planName);
}
// tif 文件名
String fileName = AFactorTypeEnum.getTifNameByType(factorType);
/
if(AfactorPlanTypeEnum.R定時年.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時月.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時半月.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時日.getAFactorPlanType().equals(planType)
) {
fileName = CommonContants.R_RUNTIME_FILE_NAME;
}/
// A實時計算 :沒有跨半月, 不進行計算 直接取42/4201/420101/ bg00/slr/slr21.tif
if(AFactorTypeEnum.植被覆蓋與生物措施因子.getFactorType().equals(factorType)) {
if (AfactorPlanTypeEnum.A實時.getAFactorPlanType().equals(planType)) {
//沒有跨半月, 不進行計算 直接取42/4201/420101/ bg00/slr/slr21.tif
//若:實時計算所選時間段跨半月會生成b.tif,存放路徑爲:
//B因子:42/4201/420101/RealTime/20191023110000/b.tif。
//若:實時計算所選時間段沒跨半月,判斷查詢時間段所屬半月,判斷規則爲:當日<=15時,所屬半月爲 2月-1,當日>15時,所屬半月爲2月。
//如2019-11-01 —— 2019-11-10。則屬於211-1=21半月,其B因子調用對應半月slr參與計算。
//B因子:42/4201/420101/ bg00/slr/slr21.tif
if (isNotKuaBanYue(date, endTime)) {
Calendar startCalender = Calendar.getInstance();
startCalender.setTime(date);
int startMonth = startCalender.get(Calendar.MONTH) + 1;
int startDayOfMonth = startCalender.get(Calendar.DAY_OF_MONTH);
Integer byInt = (startDayOfMonth<=15?(2startMonth - 1):(2startMonth));
fileName = “slr” + (byInt<10?“0”+byInt:byInt) + “.tif”;
}
}
}
// 樣式名
String styleName = AFactorTypeEnum.getStyleNameByType(factorType);
// tif 文件路徑
String filePath = “”;
//小流域
if(CommonContants.SCOPE_XIAOLIUYU.equals(scope)){
//獲取所有小流域信息
String basincodes[] = zonalCode.split(",");
for (String basincode : basincodes) {
//小流域 D:\BJ-RUC\42\0000\420111\FA030000021420111
filePath = “0000/” + basincode.substring(basincode.length() - 6, basincode.length())
+ “/” + basincode
+ “/” + planTypePath
+ “/” + fileName;
String storeName = “sbjc_”+ UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,basincode));
}
}
//省 市
else if(CommonContants.SCOPE_SHENG.equals(scope) || CommonContants.SCOPE_SHI.equals(scope)){
if(AfactorPlanTypeEnum.R定時年.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時月.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時半月.getAFactorPlanType().equals(planType)
|| AfactorPlanTypeEnum.R定時日.getAFactorPlanType().equals(planType)
) {
// 這幾個計算的都是全省的圖 42/2019/10/23/rr.tif
// 42/2019/13/rr.tif
filePath = planTypePath
+ “/” + fileName;
String storeName = “sbjc_”+ UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,aFactorPlanResponse.getZonalCode()));
}
else if(AfactorPlanTypeEnum.R實時.getAFactorPlanType().equals(planType)){
//R實時 市級
if(CommonContants.SCOPE_SHI.equals(scope)){
String zonalCodes[] = zonalCode.split(",");
for (String cityCode : zonalCodes) {
// D:\42\4201\RealTime\20191122114921697
filePath = cityCode.substring(0,4)
+ “/” + planTypePath
+ “/” + fileName;
String storeName = “sbjc_” + UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,cityCode));
}
}
//R實時 省級
else if(CommonContants.SCOPE_SHENG.equals(scope)){
//D:\42\RealTime\20191122120823014
filePath = planTypePath
+ “/” + fileName;
String storeName = “sbjc_”+ UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,zonalCode));
}
}
else {
// A實時、 A定時年、A定時月、A定時半月、 A定時日、
//獲取所有縣信息
List areaList = areaMapper.getCountyByCodes(zonalCode.split(","));
for (Area area : areaList) {
// 縣 D:\BJ-RUC\42\4201\420103\RealTime\20191025125410034
filePath = area.getParent().getCode().substring(0, 4)
+ “/” + area.getCode()
+ “/” + planTypePath
+ “/” + fileName;
String storeName = “sbjc_”+ UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,area.getCode()));
}
}
}
//縣
else {
// 縣 D:\BJ-RUC\42\4201\420103\RealTime\20191025125410034
//獲取所有縣信息
List areaList = areaMapper.getCountyByCodes(zonalCode.split(","));
for (Area area : areaList) {
// 縣 D:\BJ-RUC\42\4201\420103\RealTime\20191025125410034
filePath = area.getParent().getCode().substring(0, 4)
+ “/” + area.getCode()
+ “/” + planTypePath
+ “/” + fileName;
String storeName = “sbjc_”+ UUID.randomUUID().toString().replace("-", “”);
geoPublishList.add(this.setGeoPublicEntity(filePath,storeName,styleName,aFactorPlanResponse,area.getCode()));
}
}
return geoPublishList;
}
/**
- 判斷 開始時間和結束時間是沒有跨半月,跨
- @param startTime
- @param endTime
- @return
*/
public boolean isNotKuaBanYue(Date startTime, Date endTime){
boolean bl = false;
// 開始時間
Calendar start = Calendar.getInstance();
start.setTime(startTime);
// 結束時間
Calendar end = Calendar.getInstance();
end.setTime(endTime);
int startMonth = start.get(Calendar.MONTH);
int startMonthOfDay = start.get(Calendar.DAY_OF_MONTH);
int endMonth = end.get(Calendar.MONTH);
int endMonthOfDay = end.get(Calendar.DAY_OF_MONTH);
if(startMonth == endMonth) {
if((startMonthOfDay<=15 && endMonthOfDay <=15)
|| (startMonthOfDay>15 && endMonthOfDay >15)) {
bl = true;
}
}
return bl;
}
/**
- 設置 圖層對象
- @param filePath
- @param storeName
- @param styleName
- @param aFactorPlan
- @param zonalCode
- @return
*/
public GeoPublishEntity setGeoPublicEntity(String filePath, String storeName, String styleName,AFactorPlan aFactorPlan, String zonalCode){
GeoPublishEntity geoPublishEntity = new GeoPublishEntity();
geoPublishEntity.setFilePath(filePath);
geoPublishEntity.setStoreName(storeName);
geoPublishEntity.setStyleName(styleName);
geoPublishEntity.setaFactorPlanId(aFactorPlan.getId());
geoPublishEntity.setFactorType(aFactorPlan.getFactorType());
geoPublishEntity.setaFactorPlan(aFactorPlan);
geoPublishEntity.setZonalCode(zonalCode);
return geoPublishEntity;
}
/**
- 獲取tif文件的相對路勁
- @param date
- @param planType
- @param planName
- @return
/
public String getPlanFilePathByDateAndPlanType(Date date, String planType, String planName){
String planTypePath = “”;
SimpleDateFormat yearSdf = new SimpleDateFormat(“yyyy”);
SimpleDateFormat monthSdf = new SimpleDateFormat(“yyyy/MM”);
SimpleDateFormat daySdf = new SimpleDateFormat(“yyyy/MM/dd”);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int monthOfDay = calendar.get(Calendar.DAY_OF_MONTH);
switch (planType) {
case “A實時” :
planTypePath = CommonContants.AFACTOR_REALTIME + “/” + planName;
break;
case “R實時” :
planTypePath = CommonContants.AFACTOR_REALTIME + “/” + planName;
break;
case “A定時年” :
planTypePath = String.valueOf(year + 1);
break;
case “R定時年” :
planTypePath = String.valueOf(year + 1);
break;
case “A定時月” :
if(month == 12) {
planTypePath = String.valueOf(year + 1) +"/01";
}
else {
planTypePath = String.valueOf(year) + “/” + String.valueOf(month + 1);
}
// planTypePath = monthSdf.format(date);
break;
case “R定時月” :
if(month == 12) {
planTypePath = String.valueOf(year + 1) +"/01";
}
else {
planTypePath = String.valueOf(year) + “/” + String.valueOf(month + 1);
}
// planTypePath = monthSdf.format(date);
break;
case “A定時半月” :
//下半月
if(monthOfDay == 15) {
int byMonthA = (2month);
planTypePath = String.valueOf(year) + “/by” + (byMonthA<10?(“0”+byMonthA) : byMonthA);
}
//上半月
else {
int byMonthA = (2month - 1);
planTypePath = String.valueOf(year) + “/by” + (byMonthA<10?(“0”+byMonthA) : byMonthA);
}
//int byMonthA = (2month - 1);
//planTypePath = yearSdf.format(date) + “/by” + (byMonthA<10?(“0”+byMonthA) : byMonthA);
// if(month<16) {
// //上半月 2n - 1
// planTypePath = yearSdf.format(date) + “/by” + (2month + 11);
// }{
// //下班月 2n + 12
// planTypePath = yearSdf.format(date) + “/by” + (2month + 12);
// }
break;
case “R定時半月” :
//下半月
if(monthOfDay == 15) {
int byMonthA = (2month);
planTypePath = String.valueOf(year) + “/by” + (byMonthA<10?(“0”+byMonthA) : byMonthA);
}
//上半月
else {
int byMonthA = (2month - 1);
planTypePath = String.valueOf(year) + “/by” + (byMonthA<10?(“0”+byMonthA) : byMonthA);
}
//int byMonthR = (2month - 1);
//planTypePath = yearSdf.format(date) + “/by” + (byMonthR<10?(“0”+byMonthR) : byMonthR);
// if(month<16) {
// //上半月 2n + 11
// planTypePath = yearSdf.format(date) + “/” + (2month + 11);
// }{
// //下班月 2n + 12
// planTypePath = yearSdf.format(date) + “/” + (2*month + 12);
// }
break;
case “A定時日” :
planTypePath = daySdf.format(date);
break;
case “R定時日” :
planTypePath = daySdf.format(date);
break;
default :
break;
}
return planTypePath;
}
/**
- 保存發佈的影像信息
- @param geoPublishEntity
- @return
*/
@Transactional(readOnly = false,rollbackFor = Exception.class)
public AFactorPlanGeo saveAfactorGeo(GeoPublishEntity geoPublishEntity){
// 存放發佈的影像信息
AFactorPlanGeo aFactorPlanGeo = new AFactorPlanGeo();
aFactorPlanGeo.setAFactorPlanId(geoPublishEntity.getaFactorPlanId());
aFactorPlanGeo.setFilePath(geoPublishEntity.getFilePath());
aFactorPlanGeo.setStyleName(geoPublishEntity.getStyleName());
aFactorPlanGeo.setFactorType(geoPublishEntity.getFactorType());
aFactorPlanGeo.setGeoWs(Global.getConfig(“geoserver.ws”));
aFactorPlanGeo.setGeoName(geoPublishEntity.getStoreName());
aFactorPlanGeo.setZonalCode(geoPublishEntity.getZonalCode());
aFactorPlanGeo.setPlanName(geoPublishEntity.getaFactorPlan().getPlanName());
aFactorPlanGeo.setPlanType(geoPublishEntity.getaFactorPlan().getPlanType());
aFactorPlanGeo.setScope(geoPublishEntity.getaFactorPlan().getScope());
aFactorPlanGeo.setId(IdGen.uuid());
aFactorPlanGeo.setCreateDate(new Date());
aFactorPlanGeoMapper.insert(aFactorPlanGeo);
return aFactorPlanGeo;
}
public Page findPage(Page page, AFactorPlan aFactorPlan) {
return super.findPage(page, aFactorPlan);
}public Page findPageGroupByPlanName(Page page, AFactorPlan aFactorPlan) {
aFactorPlan.setPage(page);
page.setList(mapper.findPageGroupByPlanName(aFactorPlan));
return page;
}/**
- A 計算實時計算保存
- @param aFactorPlan
*/
@Transactional(readOnly = false)
public void saveAfactor(AFactorPlan aFactorPlan) {
aFactorPlan.setIdType(“AUTO”);
aFactorPlan.setPlanStartTime(new Date());
aFactorPlan.setState(“待處理”);
aFactorPlan.setPlanName(DateFormatUtil.formatDate(“yyyyMMddHHmmssSSS”,new Date()));
super.save(aFactorPlan);
}
/**
- R實時計算保存
- @param aFactorPlan
*/
@Transactional(readOnly = false,rollbackFor = Exception.class)
public void saveRfactor(AFactorPlan aFactorPlan) {
aFactorPlan.setIdType(“AUTO”);
aFactorPlan.setPlanStartTime(new Date());
aFactorPlan.setState(“待處理”);
aFactorPlan.setPlanName(DateFormatUtil.formatDate(“yyyyMMddHHmmssSSS”,new Date()));
super.save(aFactorPlan);
}
/**
- 設置 A 計算保存的區域編碼
- @param aFactorPlan
*/
public void setAFactorZonalCode(AFactorPlan aFactorPlan){
Integer chooseType = aFactorPlan.getChooseType();
if(chooseType != null) {
//選擇的區域
if(chooseType == 1) {
// String zonalCodesParam[] = aFactorPlan.getZonalCode().split(",");
// List areaList = areaMapper.getCountyByCodes(zonalCodesParam);
// List countyList = areaList.stream().map(Area::getCode).collect(Collectors.toList());
// String zonalCodes[] = new String[countyList.size()];
// zonalCodes = countyList.toArray(zonalCodes);
// aFactorPlan.setZonalCodes(zonalCodes);
// aFactorPlan.setZonalCode(String.join(",",zonalCodes));
String zonalCodesParam[] = aFactorPlan.getZonalCode().split(",");
boolean haveProvince = false;
boolean haveCity = false;
List cityList = new ArrayList();
for (String code:zonalCodesParam) {
if(CommonContants.DEFAULT_SHENG_CODE.equals(code)) {
haveProvince = true;
}
if(“00”.equals(code.substring(code.length()-2,code.length()))) {
haveCity = true;
cityList.add(code);
}
}
// 有省級的,直接計算省級的
if(haveProvince) {
String zonalCodes[] = new String[]{CommonContants.DEFAULT_SHENG_CODE};
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_SHENG);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
else {
if(haveCity) {
String zonalCodes[] = new String[cityList.size()];
zonalCodes = cityList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_SHI);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
else {
List areaList = areaMapper.getCountyByCodes(zonalCodesParam);
List countyList = areaList.stream().map(Area::getCode).collect(Collectors.toList());
String zonalCodes[] = new String[countyList.size()];
zonalCodes = countyList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_XIAN);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
}
}
//選擇的八大塊
else if(chooseType == 2) {
String sbsjCodes[] = aFactorPlan.getSbsjCode().split(",");
AddvSbSj addvSbSj = new AddvSbSj();
addvSbSj.setSbsjCodes(sbsjCodes);
List addvSbsjList = sbSjMapper.findAllAddvBySbSjs(addvSbSj);
List countyList = addvSbsjList.stream().map(AddvSbSj::getCountyCode).collect(Collectors.toList());
String zonalCodes[] = new String[countyList.size()];
zonalCodes = countyList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
//選擇小流域
else if(chooseType == 3) {
String zonalCodes[] = aFactorPlan.getBasincode().split(",");
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
}
else {
// 區域集合
String zonalCodes[] = aFactorPlan.getZonalCode().split(",");
aFactorPlan.setZonalCodes(zonalCodes);
}
}
/**
- 設置 R 計算保存的區域編碼
- @param aFactorPlan
*/
public void setRFactorZonalCode(AFactorPlan aFactorPlan){
Integer chooseType = aFactorPlan.getChooseType();
if(chooseType != null) {
//選擇的區域
if(chooseType == 1) {
String zonalCodesParam[] = aFactorPlan.getZonalCode().split(",");
boolean haveProvince = false;
boolean haveCity = false;
List cityList = new ArrayList();
for (String code:zonalCodesParam) {
if(CommonContants.DEFAULT_SHENG_CODE.equals(code)) {
haveProvince = true;
}
if(“00”.equals(code.substring(code.length()-2,code.length()))) {
haveCity = true;
cityList.add(code);
}
}
// 有省級的,直接計算省級的
if(haveProvince) {
String zonalCodes[] = new String[]{CommonContants.DEFAULT_SHENG_CODE};
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_SHENG);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
else {
if(haveCity) {
String zonalCodes[] = new String[cityList.size()];
zonalCodes = cityList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_SHI);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
else {
List areaList = areaMapper.getCountyByCodes(zonalCodesParam);
List countyList = areaList.stream().map(Area::getCode).collect(Collectors.toList());
String zonalCodes[] = new String[countyList.size()];
zonalCodes = countyList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setScope(CommonContants.SCOPE_XIAN);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
}
}
//選擇的八大塊
else if(chooseType == 2) {
String sbsjCodes[] = aFactorPlan.getSbsjCode().split(",");
AddvSbSj addvSbSj = new AddvSbSj();
addvSbSj.setSbsjCodes(sbsjCodes);
List addvSbsjList = sbSjMapper.findAllAddvBySbSjs(addvSbSj);
List countyList = addvSbsjList.stream().map(AddvSbSj::getCountyCode).collect(Collectors.toList());
String zonalCodes[] = new String[countyList.size()];
zonalCodes = countyList.toArray(zonalCodes);
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
//選擇小流域
else if(chooseType == 3) {
String zonalCodes[] = aFactorPlan.getBasincode().split(",");
aFactorPlan.setZonalCodes(zonalCodes);
aFactorPlan.setZonalCode(String.join(",",zonalCodes));
}
}
else {
// 區域集合
String zonalCodes[] = aFactorPlan.getZonalCode().split(",");
aFactorPlan.setZonalCodes(zonalCodes);
}
}
@Transactional(readOnly = false)
public void delete(AFactorPlan aFactorPlan) {
super.delete(aFactorPlan);
}
}
3、entity
package com.jeeplus.modules.analysis.entity;
import java.util.Date;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
/**
-
@author zb
-
A因子計算任務
*/
public class AFactorPlan extends DataEntity{/**
*/
private static final long serialVersionUID = 1L;/**
- 頁面選擇的類型 區域、八大塊、小流域
*/
private Integer chooseType;
/**
- 因子類型
*/
private Integer factorType;
/**
- 開始時間
/
private Date planStartTime;
/* - 截止時間
/
private Date planEndTime;
/* - 開始時間
/
@NotNull(message = “開始時間不能爲空”)
private Date startTime;
/*
結束時間
/
@NotNull(message = “截止時間不能爲空”)
private Date endTime;
/ - 計算級別(“省”、“市”、“縣”、“小流域”)
/
@NotBlank(message = “計算級別不能爲空”)
private String scope;
/* - 任務類型(“即時”、“週期”)
/
@NotBlank(message = “任務類型不能爲空”)
private String planType;
/* - 任務名稱(採用任務發佈時間字符串)
/
private String planName;
/* - 分辨率
/
@NotNull(message = “分辨率不能爲空”)
private Double cellSize;
/ - 區域編號
*/
@NotBlank(message = “區域編號不能爲空”)
private String zonalCode;
/**
- 區域、小流域編碼集合
/
private String zonalCodes[];
/* - 區域名稱
/
private String zonalName;
/* - 小流域編碼
/
private String basincode;
/* - 小流域名稱
/
private String basinname;
/* - 三大分區編碼
/
private String sbsjCode;
/* - 三大分區名稱
*/
private String sbsjName;
/**
- 處理狀態
*/
private String state;
/**
- 錯誤消息
*/
private String errorMessage;
/**
- 用戶區域編碼
- @return
*/
private String userAreaCode;
/**
- 用戶級別
*/
private Integer userLevel;
private String searchAreaCodes;//逗號分隔的用戶區劃下的區域編碼集合
private String searchBasincodes;//逗號分隔的用戶區劃下的小流域編碼集合public String getSearchAreaCodes() {
return searchAreaCodes;
}public void setSearchAreaCodes(String searchAreaCodes) {
this.searchAreaCodes = searchAreaCodes;
}public String getSearchBasincodes() {
return searchBasincodes;
}public void setSearchBasincodes(String searchBasincodes) {
this.searchBasincodes = searchBasincodes;
}public String getUserAreaCode() {
return userAreaCode;
}public void setUserAreaCode(String userAreaCode) {
this.userAreaCode = userAreaCode;
}public Integer getUserLevel() {
return userLevel;
}public void setUserLevel(Integer userLevel) {
this.userLevel = userLevel;
}public String[] getZonalCodes() {
return zonalCodes;
}public void setZonalCodes(String[] zonalCodes) {
this.zonalCodes = zonalCodes;
}public String getSbsjCode() {
return sbsjCode;
}public void setSbsjCode(String sbsjCode) {
this.sbsjCode = sbsjCode;
}public String getSbsjName() {
return sbsjName;
}public void setSbsjName(String sbsjName) {
this.sbsjName = sbsjName;
}public Integer getChooseType() {
return chooseType;
}public void setChooseType(Integer chooseType) {
this.chooseType = chooseType;
}@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”)
public Date getPlanStartTime() {
return planStartTime;
}public void setPlanStartTime(Date planStartTime) {
this.planStartTime = planStartTime;
}@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”)
public Date getPlanEndTime() {
return planEndTime;
}public void setPlanEndTime(Date planEndTime) {
this.planEndTime = planEndTime;
}public String getScope() {
return scope;
}public void setScope(String scope) {
this.scope = scope;
}public String getPlanType() {
return planType;
}public void setPlanType(String planType) {
this.planType = planType;
}public String getPlanName() {
return planName;
}public void setPlanName(String planName) {
this.planName = planName;
}public Double getCellSize() {
return cellSize;
}public void setCellSize(Double cellSize) {
this.cellSize = cellSize;
}public String getZonalCode() {
return zonalCode;
}public void setZonalCode(String zonalCode) {
this.zonalCode = zonalCode;
}public String getState() {
return state;
}public void setState(String state) {
this.state = state;
}public String getErrorMessage() {
return errorMessage;
}public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”)
public Date getStartTime() {
return startTime;
}public void setStartTime(Date startTime) {
this.startTime = startTime;
}@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”)
public Date getEndTime() {
return endTime;
}public void setEndTime(Date endTime) {
this.endTime = endTime;
}public Integer getFactorType() {
return factorType;
}public void setFactorType(Integer factorType) {
this.factorType = factorType;
}public String getZonalName() {
return zonalName;
}public void setZonalName(String zonalName) {
this.zonalName = zonalName;
}public String getBasincode() {
return basincode;
}public void setBasincode(String basincode) {
this.basincode = basincode;
}public String getBasinname() {
return basinname;
}public void setBasinname(String basinname) {
this.basinname = basinname;
}
}
package com.jeeplus.modules.analysis.entity;
import com.jeeplus.core.persistence.DataEntity;
import java.util.List;
/**
-
@author zb
-
A因子計算任務發佈的影像表
*/
public class AFactorPlanGeo extends DataEntity{/**
*/
private static final long serialVersionUID = 1L;/**
- A因子任務表
/
private String aFactorPlanId;
/* - 範圍
/
private String scope;
/* - 編碼
/
private String zonalCode;
/* - 任務類型(“即時”、“週期”)
/
private String planType;
/* - 任務名稱(採用任務發佈時間字符串)
*/
private String planName;
/**
- 因子類型
/
private Integer factorType;
/* - geoserver 工作區
*/
private String geoWs;
/**
- geoserver 圖層名
*/
private String geoName;
/**
- tif文件路徑
*/
private String filePath;
/**
- tif圖層樣式文件名
*/
private String styleName;
/**
- 用戶包含的區域集合
*/
private List areaCodes;
private boolean success = true;// 是否成功
private String msg = “操作成功”;// 提示信息public boolean isSuccess() {
return success;
}public void setSuccess(boolean success) {
this.success = success;
}public String getMsg() {
return msg;
}public void setMsg(String msg) {
this.msg = msg;
}public List getAreaCodes() {
return areaCodes;
}public void setAreaCodes(List areaCodes) {
this.areaCodes = areaCodes;
}public String getFilePath() {
return filePath;
}public void setFilePath(String filePath) {
this.filePath = filePath;
}public String getStyleName() {
return styleName;
}public void setStyleName(String styleName) {
this.styleName = styleName;
}public String getAFactorPlanId() {
return aFactorPlanId;
}public void setAFactorPlanId(String aFactorPlanId) {
this.aFactorPlanId = aFactorPlanId;
}public Integer getFactorType() {
return factorType;
}public void setFactorType(Integer factorType) {
this.factorType = factorType;
}public String getGeoWs() {
return geoWs;
}public void setGeoWs(String geoWs) {
this.geoWs = geoWs;
}public String getGeoName() {
return geoName;
}public void setGeoName(String geoName) {
this.geoName = geoName;
}public String getPlanType() {
return planType;
}public void setPlanType(String planType) {
this.planType = planType;
}public String getPlanName() {
return planName;
}public void setPlanName(String planName) {
this.planName = planName;
}public String getScope() {
return scope;
}public void setScope(String scope) {
this.scope = scope;
}public String getZonalCode() {
return zonalCode;
}public void setZonalCode(String zonalCode) {
this.zonalCode = zonalCode;
}
}
package com.jeeplus.modules.analysis.dto;
import com.jeeplus.modules.analysis.entity.AFactorPlan;
import java.io.Serializable;
public class GeoPublishEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 任務ID
*/
private String aFactorPlanId;
/**
* 因子類型
*/
private Integer factorType;
/**
* 文件路徑
*/
private String filePath;
/**
* 圖層名稱
*/
private String storeName;
/**
* 樣式名稱
*/
private String styleName;
/**
* A計算任務
*/
private AFactorPlan aFactorPlan;
/**
* 區域編碼
*/
private String zonalCode;
private String zonalName;
public String getZonalName() {
return zonalName;
}
public void setZonalName(String zonalName) {
this.zonalName = zonalName;
}
public String getZonalCode() {
return zonalCode;
}
public void setZonalCode(String zonalCode) {
this.zonalCode = zonalCode;
}
public AFactorPlan getaFactorPlan() {
return aFactorPlan;
}
public void setaFactorPlan(AFactorPlan aFactorPlan) {
this.aFactorPlan = aFactorPlan;
}
public String getaFactorPlanId() {
return aFactorPlanId;
}
public void setaFactorPlanId(String aFactorPlanId) {
this.aFactorPlanId = aFactorPlanId;
}
public Integer getFactorType() {
return factorType;
}
public void setFactorType(Integer factorType) {
this.factorType = factorType;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getStoreName() {
return storeName;
}
public void setStoreName(String storeName) {
this.storeName = storeName;
}
public String getStyleName() {
return styleName;
}
public void setStyleName(String styleName) {
this.styleName = styleName;
}
}
4、js代碼
<%@ page contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8” %>
<%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
<%@ include file="/webpage/include/taglib.jsp"%>
日 半月 月 年 | 計算級別: | 縣 小流域 | 起止時間: | 區域 八大塊 小流域 |
×
|
×
|
開始計算 |
@charset “UTF-8”;
#map {
height: 100%;
width: 100%;
}
#position{
float: right;
position: absolute;
bottom: 70px;
height: 20px;
z-index: 2000;
color: #fff;
right: 80px;
display: block;
}
#scaleLine{
float: left;
position: absolute;
bottom: 40px;
height: 20px;
z-index: 2000;
color: #fff;
right: 200px;
display: block;
}
.navigate-container{
position:fixed;
z-index: 99;
margin-left: 50px;
margin-top: 20px;
}
#right_contont{
width: 340px;
height: auto;
max-height: 100%;
position: fixed;
z-index: 999;
/* background: #fff; */
right: 0;
}
.map-top{
position: absolute;
top: 0;
width: 100%;
left: 0;
text-align: center;
margin: 0;
background: #fff;
z-index: 3000;
}
#bottom_content{
width: 100%;
height: 310px;
position: fixed;
z-index: 2001;
bottom: -285px;
background: #fff;
padding: 0px 3px 3px 3px;
/* overflow-y: scroll; */
}
.bottom_title {
position: relative;
margin: 0 auto;
display: block;
height: 30px;
width: 100%;
}
#bottomBotton{
width: 150px;
display: block;
margin: 0 auto;
}
.bottom_table {
height: 280px;
overflow-y: scroll;
position:relative;
}
.bottom_table_refresh{
position:absolute;
z-index: 2;
top: 1px;
right: 5px;
}
#aFactorTaskTable .dropdown-menu {
position:relative;
}
#aFactorTaskTable .dropdown-menu > li {
list-style: none;
position: absolute;
top: -34px;
left: -78px;
background: #fff;
width: 150px;
text-align: left;
padding: 2px;
border: #d6d6d6 1px solid;
height: 32px;
line-height: 32px;
}
.fixed-table-body {
overflow: visible;
}
#aFactorTaskTable .dropdown-menu > li > a {
padding: 3px 5px;
}
html {
font-size:14px;
}
#body-container {
margin-left: 0px !important;
margin-top: 0px !important;
padding: 0px;
overflow-x: hidden !important;
transition: all 0.2s ease-in-out !important;
height: 100% !important;
}
.map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.layui-layer {
right:5px;
left: initial;
}
.layui-layim-close .layui-layer-content span {
width: auto;
max-width: 120px;
}
.layim-chat-list li span, .layui-layim-min .layui-layer-content span {
width: 100px;
padding-left: 10px;
font-size: 16px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
body .layui-layim-min {
border: 1px solid #D9D9D9;
}
.layui-layim-min .layui-layer-content {
margin: 0 5px;
padding: 5px 10px;
white-space: nowrap;
}
.layim-chat-list li, .layui-layim-min .layui-layer-content {
position: relative;
margin: 5px;
padding: 5px 30px 5px 5px;
line-height: 40px;
cursor: pointer;
border-radius: 3px;
}
.layui-nav-child {
top: auto;
bottom: 40px;
}
.layui-bg-tl {
background: #F5F5F5 !important;
}
.layui-nav .layui-nav-item a {
color: #000;
}
.layui-nav .layui-nav-item a:hover {
color: #000;
}
.layui-nav-child dd {
line-height: 36px;
}
.layui-nav .layui-nav-item {
line-height: 45px;
}
.layui-input-inline {
height: 38px;
}
.layui-form-item .layui-input-inline {
width: 100%;
}
.well {
padding: 5px;
}
.form-horizontal {
margin: 0;
}
.ol-popup {
position: absolute;
background-color: white;
-webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
padding: 5px;
border-radius: 10px;
border: 1px solid #cccccc;
bottom: 12px;
left: -50px;
width: auto;
min-width: 500px;
}
.ol-popup:after, .ol-popup:before {
top: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.ol-popup:after {
border-top-color: white;
border-width: 10px;
left: 48px;
margin-left: -10px;
}
.ol-popup:before {
border-top-color: #cccccc;
border-width: 11px;
left: 48px;
margin-left: -11px;
}
.ol-popup-closer {
text-decoration: none;
position: absolute;
top: 2px;
right: 8px;
}
.ol-popup-closer:after {
content: "✖";
}
.popup-content > div{
/* border: 1px solid #d6d6d6; */
}
.popup-content > div > div{
border-bottom : 1px solid #d6d6d6;
line-height: 1.5rem;
}
.popup-content > div > div:last-child{
border-bottom : none;
}
.popup-content > fieldset{
border: 1px solid #d6d6d6;
padding: .25em;
margin: .25rem;
border: 1px solid silver;
}
legend {
display: block;
width: 100%;
padding: 0;
margin-bottom: 0;
line-height: inherit;
padding: .5em;
padding-bottom: 0;
border: 0;
width: auto;
font-size: 16px;
webkit-box-sizing: border-box;
box-sizing: border-box;
color: inherit;
display: table;
max-width: 100%;
white-space: normal;
}
.popup-content > fieldset > div{
border-bottom : 1px solid #d6d6d6;
line-height: 1.5rem;
width: 250px;
max-height: 125px;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 5;
overflow: hidden;
}
.popup-content > fieldset > div:last-child{
border-bottom : none;
}
.layui-colla-content {
padding: 0;
}
.spc{width: 100%;background-color: red;}
.sp{
display: inline-block;
}
.main-container {
height: 100% !important;
overflow-y: scroll;
}
.page-content form table tr td > a.btn {
padding:0 .25rem;
}
.table > thead > tr {
background: #e3f2ff !important;
}
.animation {
position: absolute;
top: 0;
right: 0;
width: 20rem;
background: #fff;
}
.animation .container{
display: flex;width:100%;
}
.animation .container > label{
display: inline-block;
margin: 0;
width: 5rem;
padding-top: .25rem;
}
.animation .container > button{
background: #69aab8;
border: 1px #fff solid;
border-radius: .3rem;
height: 30px;
width: 13rem;
}
.layui-table td, .layui-table th {
position: relative;
/* padding: 2px !important;*/
min-height: 20px;
line-height: 20px;
font-size: 14px;
/* border:unset;*/
}
.layui-table-search td, .layui-table-search th{
padding: 2px !important;
border:unset;
}
.input-group .input-group-btn .btn {
width: 35px;
height: 32px;
}
.layui-tab-content{
padding: 5px 5px !important;
background-color: #ffffff;
}
.layui-tab-title .layui-this{
color:#1890ff !important;
}
.search-botton{
position: absolute;
top: 1px;
right: 5px;
}
.shenSuo-botton{
position: absolute;
left: 0;
top: 0;
color: #666666;
}
.shenSuo-botton:hover {
color: #1890ff;
}
.container{
position:relative;
display:block;
height:100%;
width:100%;
}
.ant-layout-footer, .ant-layout-header {
flex: 0 0 auto;
}
.ant-layout-header {
height: 64px;
padding: 0 50px;
line-height: 64px;
background: #001529;
}
.header___1fxJP {
height: 24px;
line-height: 24px;
font-size: 18px;
margin: 10px 20px 0 10px;
background-color: transparent;
padding: 0;
}
.tl-container{
z-index: 5;
position: absolute;
bottom: 20px;
left: 0;
width: 400px;
height: 250px;
color: #fff;
background-color: rgba(0,0,0,.55);
overflow: hidden;
}
.row___2TQGG {
line-height: 28px;
margin: 0 20px;
}
.ant-row {
position: relative;
height: auto;
zoom: 1;
display: block;
box-sizing: border-box;
}
.ant-col-12{
display:block;
width:50%;
box-sizing: border-box;
flex: 0 0 auto;
float: left;
margin: 0;
color: #fff;
font-size: 14px;
}
.anticon[tabindex] {
cursor: pointer;
}
.container___2rQsv {
z-index: 5;
position: absolute;
bottom: 40px;
left: 20px;
display: none;
}
.ant-btn {
line-height: 1.499;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
box-shadow: 0 2px 0 rgba(0,0,0,.015);
cursor: pointer;
transition: all .3s cubic-bezier(.645,.045,.355,1);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
touch-action: manipulation;
height: 32px;
padding: 0 15px;
font-size: 14px;
border-radius: 4px;
color: rgba(0,0,0,.65);
background-color: #fff;
border: 1px solid #d9d9d9;
}
.anticon {
display: inline-block;
color: inherit;
font-style: normal;
line-height: 0;
text-align: center;
text-transform: none;
vertical-align: -.125em;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.ant-btn-primary {
color: #fff;
background-color: #1890ff;
border-color: #1890ff;
text-shadow: 0 -1px 0 rgba(0,0,0,.12);
box-shadow: 0 2px 0 rgba(0,0,0,.045);
}
.ant-btn, .ant-btn:active, .ant-btn:focus {
outline: 0;
}
.ant-btn-circle, .ant-btn-circle-outline {
width: 32px;
height: 32px;
padding: 0;
font-size: 16px;
border-radius: 50%;
}