Merge branch 'dev-tw'

This commit is contained in:
tangwei 2026-04-20 11:44:41 +08:00
commit b5ede77a23
28 changed files with 2312 additions and 4 deletions

View File

@ -0,0 +1,59 @@
package com.yfd.platform.common;
/**
* 通用常量
*
* @author zwl
* @date 2023/07/13
*/
public interface CommonConstant {
/**
* kendo 默认分组
*/
String DEFAULT = "default";
/**
* 计算标识
*/
String CALCULATE_FLAG = "calculateFlag";
/**
* 计算成功
*/
String CALCULATE_SUCCESS = "1";
/**
*
*/
String HOUR = "HOUR";
/**
*
*/
String DAY = "DAY";
/**
*
*/
String TEN = "TEN";
/**
*
*/
String MON = "MON";
/**
*
*/
String QUA = "QUA";
/**
*
*/
String YEAR = "YEAR";
}

View File

@ -0,0 +1,110 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.yfd.platform.common;
public interface CommonConstants {
String UTF_8 = "UTF-8";
String CONTENT_TYPE_NAME = "Content-type";
String CONTENT_TYPE = "application/json;charset=utf-8";
String TENANT_ID = "_TenantId";
String SYSTEM_ID = "_SysId";
String PROJECT_GROUP_ID = "_PgId";
String BELOND_PROJECT_ID = "_ProjectId";
String OLD_BELOND_PROJECT_ID = "_LoginProjectId";
String APPLICATION_ID = "_AppId";
String PLATFORM_ID = "_PlatformId";
String ISOLATE_LEVEL_CODE = "_IsolateLevelCode";
String ISOLATE_ID = "_IsolateId";
String TEMPLATE_ID = "_TemplateId";
String VERSION = "VERSION";
String DEFAULT_TENANT_ID = "00000000-0000-0000-0000-000000000000";
String DEFAULT_BELONG_PROJECT_ID = "00000000-0000-0000-0000-000000000000";
String DEFAULT_GUID = "00000000-0000-0000-0000-000000000000";
String STATUS_DEL = "1";
String STATUS_NORMAL = "0";
String DB_NOT_DELETED = "0";
String DB_IS_DELETED = "1";
String LOG_NORMAL_TYPE = "1";
String STATUS_LOCK = "9";
String MENU = "0";
Integer MENU_TREE_ROOT_ID = -1;
String UTF8 = "UTF-8";
String FRONT_END_PROJECT = "dec-ui";
String BACK_END_PROJECT = "dec";
String DEC_PUBLIC_PARAM_KEY = "DEC_PUBLIC_PARAM_KEY";
Integer SUCCESS = 0;
Integer FAIL = 1;
Integer YES = 1;
Integer NO = 0;
String BUCKET_NAME = "dec";
String DEFAULT_CROWN_CODE = "+86";
String DEFAULT_TIME_ZONE = "GMT+8";
public interface Symbol {
String SIGH = "!";
String AT = "@";
String WELL = "#";
String DOLLAR = "$";
String RMB = "";
String SPACE = " ";
String LB = System.getProperty("line.separator");
String PERCENTAGE = "%";
String AND = "&";
String STAR = "*";
String MIDDLE_LINE = "-";
String LOWER_LINE = "_";
String EQUAL = "=";
String PLUS = "+";
String COLON = ":";
String SEMICOLON = ";";
String COMMA = ",";
String POINT = ".";
String SLASH = "/";
String VERTICAL_BAR = "|";
String DOUBLE_SLASH = "//";
String BACKSLASH = "\\";
String QUESTION = "?";
String LEFT_BIG_BRACE = "{";
String RIGHT_BIG_BRACE = "}";
String LEFT_MIDDLE_BRACE = "[";
String RIGHT_MIDDLE_BRACE = "]";
String BACKQUOTE = "`";
}
public interface Digital {
int NEGATIVE_ONE = -1;
int ZERO = 0;
int ONE = 1;
int TWO = 2;
int FOUR = 4;
int EIGHT = 8;
int SIXTEEN = 16;
}
public interface Pattern {
String DATE = "yyyy-MM-dd";
String DATETIME = "yyyy-MM-dd HH:mm:ss";
String DATETIME_MM = "yyyy-MM-dd HH:mm";
String DATETIME_SSS = "yyyy-MM-dd HH:mm:ss.SSS";
String TIME = "HH:mm";
String TIME_SS = "HH:mm:ss";
String SYS_DATE = "yyyy/MM/dd";
String SYS_DATETIME = "yyyy/MM/dd HH:mm:ss";
String SYS_DATETIME_MM = "yyyy/MM/dd HH:mm";
String SYS_DATETIME_SSS = "yyyy/MM/dd HH:mm:ss.SSS";
String NONE_DATE = "yyyyMMdd";
String NONE_DATETIME = "yyyyMMddHHmmss";
String NONE_DATETIME_MM = "yyyyMMddHHmm";
String NONE_DATETIME_SSS = "yyyyMMddHHmmssSSS";
String CST_DATETIME = "EEE MMM dd HH:mm:ss 'CST' yyyy";
String NONE_DECIMAL = "0";
String ONE_DECIMAL = "0.0";
String TWO_DECIMAL = "0.00";
String TB_NONE_DECIMAL = "#,##0";
String TB_ONE_DECIMAL = "#,##0.0";
String TB_TWO_DECIMAL = "#,##0.00";
}
}

View File

@ -0,0 +1,19 @@
package com.yfd.platform.common.entity.baseInterface;
import java.util.Date;
public interface ILogicalDeleteEntity<TKey> {
Boolean isDeleted();
Integer getIsDeleted();
void setIsDeleted(Integer isDeleted);
TKey getDeleteUser();
void setDeleteUser(TKey deleteUser);
Date getDeleteTime();
void setDeleteTime(Date deleteTime);
}

View File

@ -0,0 +1,13 @@
package com.yfd.platform.common.entity.baseInterface;
import java.util.Date;
public interface IModifyEntity<TKey> {
TKey getModifyUser();
void setModifyUser(TKey modifyUser);
Date getModifyTime();
void setModifyTime(Date modifyTime);
}

View File

@ -0,0 +1,13 @@
package com.yfd.platform.common.entity.baseInterface;
import java.util.Date;
public interface IRecordEntity<TKey> {
TKey getRecordUser();
void setRecordUser(TKey recordUser);
Date getRecordTime();
void setRecordTime(Date recordTime);
}

View File

@ -0,0 +1,73 @@
package com.yfd.platform.common.enums;
import com.yfd.platform.common.exception.IResultCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 通用结果码枚举
*/
@Getter
@AllArgsConstructor
public enum ResultCodeEnum implements IResultCode {
/**
* 成功
*/
SUCCESS(200, "success", "操作成功"),
/**
* 失败
*/
FAILED(500, "failed", "操作失败"),
/**
* 参数错误
*/
PARAM_ERROR(400, "param_error", "参数错误"),
/**
* 未授权
*/
UNAUTHORIZED(401, "unauthorized", "未授权"),
/**
* 禁止访问
*/
FORBIDDEN(403, "forbidden", "禁止访问"),
/**
* 资源不存在
*/
NOT_FOUND(404, "not_found", "资源不存在"),
/**
* 业务异常
*/
BIZ_ERROR(500, "biz_error", "业务异常"),
/**
* 系统异常
*/
SYSTEM_ERROR(500, "system_error", "系统异常"),
/**
* 服务不可用
*/
SERVICE_UNAVAILABLE(503, "service_unavailable", "服务不可用");
/**
* 错误码
*/
private final int code;
/**
* 错误key
*/
private final String errorKey;
/**
* 错误消息
*/
private final String message;
}

View File

@ -0,0 +1,55 @@
package com.yfd.platform.common.exception;
/**
* 业务异常类
*/
public class BizException extends DecException {
private static final long serialVersionUID = 1L;
private static final String DEFAULT_ERR_CODE = "biz_error";
public BizException(String message) {
super(DEFAULT_ERR_CODE, message);
}
public BizException(String message, Object... parameters) {
super(DEFAULT_ERR_CODE, message, parameters);
}
public BizException(int errorCode, Object... parameters) {
super(errorCode, DEFAULT_ERR_CODE, parameters);
}
public BizException(int errorCode, String message) {
super(errorCode, DEFAULT_ERR_CODE, message);
}
public BizException(String errorKey, String message) {
super(errorKey, message);
}
public BizException(IResultCode resultCode) {
super(resultCode);
}
public BizException(IResultCode resultCode, Throwable cause) {
super(resultCode, cause);
}
public BizException(Throwable cause) {
super(cause);
}
public BizException(String message, Throwable cause) {
super(DEFAULT_ERR_CODE, message, cause);
}
public BizException(String errorKey, String message, Throwable cause) {
super(errorKey, message, cause);
}
public BizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,109 @@
package com.yfd.platform.common.exception;
import com.yfd.platform.common.CommonConstants;
import lombok.Getter;
/**
* 基础异常类
*/
@Getter
public class DecException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 错误码
*/
private int errorCode;
/**
* 错误key
*/
private String errorKey;
/**
* 错误消息
*/
private String message;
public DecException(String errorKey, String message) {
super(message);
this.errorKey = errorKey;
this.message = message;
this.errorCode = CommonConstants.FAIL;
}
public DecException(String errorKey, String message, Object... parameters) {
super(formatMessage(message, parameters));
this.errorKey = errorKey;
this.message = formatMessage(message, parameters);
this.errorCode = CommonConstants.FAIL;
}
public DecException(int errorCode, String errorKey, Object... parameters) {
super(errorKey);
this.errorCode = errorCode;
this.errorKey = errorKey;
this.message = formatMessage(errorKey, parameters);
}
public DecException(int errorCode, String errorKey, String message) {
super(message);
this.errorCode = errorCode;
this.errorKey = errorKey;
this.message = message;
}
public DecException(IResultCode resultCode) {
super(resultCode.getMessage());
this.errorCode = resultCode.getCode();
this.errorKey = resultCode.getErrorKey();
this.message = resultCode.getMessage();
}
public DecException(IResultCode resultCode, Throwable cause) {
super(resultCode.getMessage(), cause);
this.errorCode = resultCode.getCode();
this.errorKey = resultCode.getErrorKey();
this.message = resultCode.getMessage();
}
public DecException(Throwable cause) {
super(cause);
this.errorCode = 500;
this.errorKey = "system_error";
this.message = cause.getMessage();
}
public DecException(String errorKey, String message, Throwable cause) {
super(message, cause);
this.errorKey = errorKey;
this.message = message;
this.errorCode = 500;
}
public DecException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
this.errorKey = "system_error";
this.message = message;
this.errorCode = 500;
}
/**
* 格式化消息
* @param message 消息模板
* @param parameters 参数
* @return 格式化后的消息
*/
private static String formatMessage(String message, Object... parameters) {
if (parameters == null || parameters.length == 0) {
return message;
}
String result = message;
for (Object param : parameters) {
result = result.replaceFirst("\\{\\}", String.valueOf(param != null ? param : "null"));
}
return result;
}
}

View File

@ -0,0 +1,16 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.yfd.platform.common.exception;
import java.io.Serializable;
public interface IResultCode extends Serializable {
String getMessage();
int getCode();
String getErrorKey();
}

View File

@ -54,6 +54,8 @@ public class SecurityConfig {
.requestMatchers("/user/login").anonymous() .requestMatchers("/user/login").anonymous()
.requestMatchers("/user/code").permitAll() .requestMatchers("/user/code").permitAll()
.requestMatchers("/eng/**").permitAll() .requestMatchers("/eng/**").permitAll()
.requestMatchers("/env/**").permitAll()
.requestMatchers("/sw/**").permitAll()
.requestMatchers(HttpMethod.GET, "/").permitAll() .requestMatchers(HttpMethod.GET, "/").permitAll()
.requestMatchers(HttpMethod.GET, .requestMatchers(HttpMethod.GET,
"/*.html", "/*.html",

View File

@ -0,0 +1,83 @@
package com.yfd.platform.env.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.env.entity.vo.BatchDeleteAo;
import com.yfd.platform.env.entity.vo.WtrvInfo;
import com.yfd.platform.env.service.AlongDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/sw/alongDetail")
@Tag(name = "沿程水温变化二级数据接口")
@Validated
public class SdAlongDetailController {
@Resource
private AlongDetailService alongDetailService;
@PostMapping("/GetKendoListCust")
@Operation(summary = "查询沿程水温变化二级数据列表")
public ResponseResult getKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) {
DataSourceResult result = alongDetailService.processKendoList(dataSourceRequest, null, new Page<>());
return ResponseResult.successData(result);
}
@PostMapping("/updateWtrvRData")
@Operation(summary = "修改表层水温日数据")
public ResponseResult updateWtrvRData(@RequestBody Map<String, Object> updateData) {
alongDetailService.updateWtrvRData(updateData);
return ResponseResult.success();
}
@PostMapping("/day/GetKendoListCust")
@Operation(summary = "查询出库水温日数据")
public ResponseResult getKendoDayListCust(@RequestBody DataSourceRequest dataSourceRequest) {
DataSourceResult result = alongDetailService.processDayKendoList(dataSourceRequest, null, new Page<>(), null);
return ResponseResult.successData(result);
}
@PostMapping("/drtp/GetKendoListCust")
@Operation(summary = "查询出库水温周旬月季年数据")
public ResponseResult getKendoDrtpListCust(@RequestBody DataSourceRequest dataSourceRequest) {
DataSourceResult result = alongDetailService.processDrtpKendoList(dataSourceRequest, null, new Page<>(), null);
return ResponseResult.successData(result);
}
@PostMapping("/drtp/removeKendoByIds")
@Operation(summary = "删除出库水温周旬月季年数据")
public ResponseResult removeKendoByIds(@RequestBody BatchDeleteAo batchDeleteAo) {
alongDetailService.removeKendoByIds(batchDeleteAo);
return ResponseResult.success();
}
// @PostMapping("/qgc/GetKendoListCust")
// @Operation(summary = "环保部查询出入库水温、出入库流量、入库水温、天然水温、降雨、气温数据")
// public ResponseResult getQgcKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) {
// DataSourceResult result = alongDetailService.getQgcKendoListCust(dataSourceRequest);
// return ResponseResult.successData(result);
// }
@GetMapping("/qgc/stcdCheck")
@Operation(summary = "判断出库水温站、垂向水温站或者低温水减缓设施所属的电站是否有出库水温站、垂向水温站和低温水减缓设施")
public ResponseResult getQgcStcdCheck(@RequestParam String stcd) {
WtrvInfo result = alongDetailService.getWtrvInfoByStcd2(stcd);
return ResponseResult.successData(result);
}
@GetMapping("/qgc/stcdCheck2")
@Operation(summary = "判断出库水温站、垂向水温站所属的电站是否有出库水温站、垂向水温站")
public ResponseResult getQgcStcdCheck2(@RequestParam String stcd) {
WtrvInfo result = alongDetailService.getWtrvInfoByStcd3(stcd);
return ResponseResult.successData(result);
}
}

View File

@ -0,0 +1,51 @@
package com.yfd.platform.env.controller;
import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.env.service.AlongListService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 沿程水温变化一级折线图
*
* @author lyl
* @date 2023/04/18 19:22
*/
@RestController
@RequestMapping("/sw/alongList")
@Tag(name = "沿程水温变化一级折线图")
@Validated
public class SdAlongListController{
@Resource
private AlongListService alongListService;
@PostMapping({"/limit"})
@Operation(summary = "获取流域沿程水温限值")
public ResponseResult getWtLimit(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(alongListService.getWtLimit(dataSourceRequest));
}
@PostMapping({"/default/rvcd"})
@Operation(summary = "获取沿程水温变化默认有数据的河流")
public ResponseResult getDefaultStcd(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(alongListService.getDefaultRvcd(dataSourceRequest));
}
@PostMapping({"/qgc/GetKendoListCust"})
@Operation(summary = "按时间范围查询沿程水温站最新数据时间的数据")
public ResponseResult getALongKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(this.alongListService.getALongKendoListCust(dataSourceRequest));
}
}

View File

@ -0,0 +1,20 @@
package com.yfd.platform.env.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "批量删除参数")
public class BatchDeleteAo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "数据类型")
private String dataType;
@Schema(description = "删除数据列表")
private List<DataParam> dataList;
}

View File

@ -0,0 +1,20 @@
package com.yfd.platform.env.entity.vo;
import lombok.Data;
@Data
public class DataParam {
private String dt;
private String tm;
private String month;
private String year;
private String drtp;
private String id;
}

View File

@ -0,0 +1,39 @@
package com.yfd.platform.env.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Getter
@Setter
@FieldNameConstants
@Schema(description = "沿程水温变化二级数据VO")
public class SdAlongDetailVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date tm;
@Schema(description = "月份")
private Integer mon;
@Schema(description = "站码")
private String stcd;
@Schema(description = "水温")
private BigDecimal wt;
@Schema(description = "站名")
private String stnm;
@Schema(description = "基地名称")
private String baseName;
}

View File

@ -0,0 +1,54 @@
package com.yfd.platform.env.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
import java.math.BigDecimal;
@Getter
@Setter
@FieldNameConstants
@Schema(description = "沿程水温变化一级折线图VO")
public class SdAlongVO {
@Schema(description = "站码")
private String stcd;
@Schema(description = "站名")
private String stnm;
@Schema(description = "电站编码")
private String rstcd;
@Schema(description = "水温")
private BigDecimal temperature;
@Schema(description = "类型1:电站 2:测站")
private String sttp;
@Schema(description = "时间")
private String tm;
@Schema(description = "最小时间")
private String minTm;
@Schema(description = "实测值水温")
private BigDecimal actualTemp;
@Schema(description = "去年同期水温")
private BigDecimal lastTemp;
@Schema(description = "天然水温")
private BigDecimal naturalTemp;
@Schema(description = "电站水温出库站")
private String engDwtCode;
@Schema(hidden = true)
public static final String TYPE_ENG = "1";
@Schema(hidden = true)
public static final String TYPE_ENV = "2";
}

View File

@ -0,0 +1,25 @@
package com.yfd.platform.env.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "出入库水温数据")
public class WtrvDataVo extends WtrvInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date tm;
@Schema(description = "水温")
private BigDecimal wt;
}

View File

@ -0,0 +1,66 @@
package com.yfd.platform.env.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
@Schema(description = "水温站点信息")
public class WtrvInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "出入库标识1-入库水温2-出库水温3-非出入库水温")
private Integer type;
@Schema(description = "类型名称")
private String typeName;
@Schema(description = "站码")
private String stcd;
@Schema(description = "站名")
private String stnm;
@Schema(description = "站点类型编码")
private String sttpCode;
@Schema(description = "关联电站编码")
private String rstcd;
@Schema(description = "关联电站名称")
private String ennm;
@Schema(description = "垂向水温站站码")
private String vtStcd;
@Schema(description = "垂向水温站站名")
private String vtStnm;
@Schema(description = "低温水减缓设施站码")
private String dwStcd;
@Schema(description = "低温水减缓设施站名")
private String dwStnm;
public String getTypeName() {
if (type == null) {
return "未知类型";
}
switch (type) {
case 1:
return "入库水温";
case 2:
return "出库水温";
case 3:
return "河道水温";
default:
return "未知类型";
}
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}

View File

@ -0,0 +1,143 @@
package com.yfd.platform.env.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yfd.platform.env.entity.vo.SdAlongDetailVO;
import com.yfd.platform.env.entity.vo.WtrvInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 沿程水温变化二级数据接口
*
* @author
* @since 2023-04-23 09:32:10
*/
@Mapper
public interface AlongDetailMapper extends BaseMapper<SdAlongDetailVO> {
WtrvInfo getWtrvInfoByStcd(@Param("stcd") String stcd);
//电站数据
@Select("SELECT AVG(a.QI) AS qi, AVG(a.QO) AS qo, a.tm, AVG(a.RZ) AS rz, AVG(a.DZ) AS dz " +
"FROM SD_HYDROPW_R a " +
"INNER JOIN MS_STBPRP_T b ON a.STCD = b.RSTCD " +
"WHERE b.IS_DELETED = 0 AND a.IS_DELETED = 0 " +
"AND b.STCD = #{stcd} AND a.TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY a.TM")
List<Map<String, Object>> getHydropwDataList(@Param("stcd") String stcd,
@Param("startTime") Date startTime,
@Param("endTime") Date endTime);
//天然水温
@Select("<script>" +
"SELECT STCD, WTTP, MNTH, WT FROM SD_WTNP_B " +
"WHERE WTTP = 1 " +
"<if test='rstcd != null and rstcd != \"\"'>" +
"AND STCD = #{rstcd} " +
"</if>" +
"<if test='monnth != null'>" +
"AND MNTH = #{monnth} " +
"</if>" +
"</script>")
List<Map<String, Object>> getNatureTmpDataList(@Param("rstcd") String rstcd,@Param("monnth") Integer month);
//入库水温
@Select("<script>" +
"SELECT 1 AS TYPE, AVG(b.WT) AS WT, b.TM " +
"FROM MS_STBPRP_T a " +
"INNER JOIN SD_WTRV_R b ON a.STCD = b.STCD " +
"WHERE a.STTP_CODE = 'WTRV' AND a.IS_DELETED = 0 AND b.IS_DELETED = 0 " +
"<if test='stcd != null and stcd != \"\"'>" +
"AND a.ENG_IWT_CODE = (SELECT RSTCD FROM MS_STBPRP_T WHERE STCD = #{stcd}) " +
"</if>" +
"<if test='rstcd != null and rstcd != \"\"'>" +
"AND a.ENG_IWT_CODE = #{rstcd} " +
"</if>" +
"AND b.TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY b.TM" +
"</script>")
List<Map<String, Object>> getIwtrvDataList(@Param("stcd")String stcd,@Param("rstcd")String rstcd, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
//出库水温
@Select("<script>" +
"SELECT 2 AS TYPE, AVG(b.WT) AS WT, b.TM " +
"FROM MS_STBPRP_T a " +
"INNER JOIN SD_WTRV_R b ON a.STCD = b.STCD " +
"WHERE a.STTP_CODE = 'WTRV' AND a.IS_DELETED = 0 AND b.IS_DELETED = 0 " +
"<if test='stcd != null and stcd != \"\"'>" +
"AND a.ENG_DWT_CODE = (SELECT RSTCD FROM MS_STBPRP_T WHERE STCD = #{stcd}) " +
"</if>" +
"<if test='rstcd != null and rstcd != \"\"'>" +
"AND a.ENG_DWT_CODE = #{rstcd} " +
"</if>" +
"AND b.TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY b.TM" +
"</script>")
List<Map<String, Object>> getDwtrvDataList(@Param("stcd")String stcd,@Param("rstcd")String rstcd, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
//降雨量
@Select("SELECT a.TM, AVG(a.DRP) AS DRP " +
"FROM SD_PPTN_R a " +
"INNER JOIN MS_STBPRP_T b ON a.STCD = b.STCD " +
"WHERE b.STTP_CODE = 'MM' " +
"AND a.IS_DELETED = 0 AND b.IS_DELETED = 0 " +
"AND b.RSTCD = (SELECT RSTCD FROM MS_STBPRP_T WHERE STCD = #{stcd}) " +
"AND a.TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY a.TM")
List<Map<String, Object>> getPptnDataList(@Param("stcd")String stcd, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
//气象站数据
@Select("SELECT a.TM, AVG(a.AT) AS AT " +
"FROM SD_TMP_R a " +
"INNER JOIN MS_STBPRP_T b ON a.STCD = b.STCD " +
"WHERE b.STTP_CODE = 'MM' AND a.IS_DELETED = 0 AND b.IS_DELETED = 0 " +
"AND b.RSTCD = (SELECT RSTCD FROM MS_STBPRP_T WHERE STCD = #{stcd}) " +
"AND a.TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY a.TM")
List<Map<String, Object>> getTmpDataList(@Param("stcd")String stcd, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Select("SELECT * FROM (" +
"SELECT TM, WTHG, ROUND(AVG(VWT), 2) AS VWT " +
"FROM SD_WTVT_R " +
"WHERE STCD IN (" +
" SELECT STCD FROM MS_STBPRP_T " +
" WHERE RSTCD = #{rstcd} AND STTP_CODE = 'WTVT' AND IS_DELETED = 0" +
") " +
"AND TO_CHAR(TM, 'mi') = 0 AND IS_DELETED = 0 " +
"AND TM BETWEEN #{startTime} AND #{endTime} " +
"GROUP BY TM, WTHG" +
") ORDER BY TM ASC, VWT ASC")
List<Map<String, Object>> getWtvtDataList(@Param("stcd")String stcd,@Param("rstcd")String rstcd, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Select("SELECT a.STCD AS rstcd, a.STNM AS ennm, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(b.STCD), ',') WITHIN GROUP (ORDER BY b.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS stcd, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(b.STNM), ',') WITHIN GROUP (ORDER BY b.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS stnm, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(c.STCD), ',') WITHIN GROUP (ORDER BY c.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS vtStcd, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(c.STNM), ',') WITHIN GROUP (ORDER BY c.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS vtStnm, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(d.STCD), ',') WITHIN GROUP (ORDER BY d.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS dwStcd, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(d.STNM), ',') WITHIN GROUP (ORDER BY d.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS dwStnm " +
"FROM MS_STBPRP_T a " +
"LEFT JOIN MS_STBPRP_T b ON a.STCD = b.RSTCD AND b.STTP_CODE = 'WTRV' AND b.IS_DELETED = 0 AND b.MWAY = 2 AND b.DTIN_TYPE = 0 " +
"LEFT JOIN MS_STBPRP_T c ON a.STCD = c.RSTCD AND c.STTP_CODE = 'WTVT' AND c.IS_DELETED = 0 AND c.MWAY = 2 " +
"LEFT JOIN MS_STBPRP_T d ON a.STCD = d.RSTCD AND d.STTP_CODE LIKE 'DW_%' AND d.IS_DELETED = 0 " +
"WHERE a.STTP_CODE = 'ENG' AND a.IS_DELETED = 0 " +
"AND b.STCD IS NOT NULL AND c.STCD IS NOT NULL AND d.STCD IS NOT NULL AND b.ENG_DWT_CODE IS NOT NULL " +
"AND (d.STCD = #{stcd} OR b.STCD = #{stcd} OR c.STCD = #{stcd} OR a.STCD = #{stcd}) " +
"AND a.STCD = b.ENG_DWT_CODE " +
"GROUP BY a.STCD, a.STNM")
WtrvInfo getWtrvInfoByStcd2(@Param("stcd") String stcd);
@Select("SELECT a.STCD AS rstcd, a.STNM AS ennm, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(b.STCD), ',') WITHIN GROUP (ORDER BY b.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS stcd, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(b.STNM), ',') WITHIN GROUP (ORDER BY b.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS stnm, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(c.STCD), ',') WITHIN GROUP (ORDER BY c.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS vtStcd, " +
"REGEXP_REPLACE(LISTAGG(TO_CHAR(c.STNM), ',') WITHIN GROUP (ORDER BY c.STCD), '([^,]+)(,\\1)*(,|$)', '\\1\\3') AS vtStnm " +
"FROM MS_STBPRP_T a " +
"LEFT JOIN MS_STBPRP_T b ON a.STCD = b.RSTCD AND b.STTP_CODE = 'WTRV' AND b.IS_DELETED = 0 AND b.MWAY = 2 AND b.DTIN_TYPE = 0 " +
"LEFT JOIN MS_STBPRP_T c ON a.STCD = c.RSTCD AND c.STTP_CODE = 'WTVT' AND c.IS_DELETED = 0 AND c.MWAY = 2 " +
"WHERE a.STTP_CODE = 'ENG' AND a.IS_DELETED = 0 " +
"AND b.STCD IS NOT NULL AND c.STCD IS NOT NULL AND b.ENG_DWT_CODE IS NOT NULL " +
"AND (b.STCD = #{stcd} OR c.STCD = #{stcd} OR a.STCD = #{stcd}) " +
"AND a.STCD = b.ENG_DWT_CODE " +
"GROUP BY a.STCD, a.STNM")
WtrvInfo getWtrvInfoByStcd3(@Param("stcd") String stcd);
}

View File

@ -0,0 +1,105 @@
package com.yfd.platform.env.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yfd.platform.env.entity.vo.SdAlongVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
/**
* 沿程水温变化一级数据接口
*
* @author
* @since 2023-04-23 09:32:10
*/
@Mapper
public interface AlongListMapper extends BaseMapper<SdAlongVO> {
@Select("<script>" +
"select to_char(max(TM),'yyyy-MM-dd HH24:mi:ss') tm from SD_WTRV_R " +
"where STCD in " +
"(select STCD from V_MS_STBPRP_T a " +
"where STTP_CODE='WTRV' " +
"and ENG_DWT_CODE is not null " +
"and IS_DELETED=0 " +
"and RSTCDSTEPSORT is not null " +
"<if test='rvcd != null and rvcd != \"\"'>" +
"and HBRVCD=#{rvcd} " +
"</if>" +
")" +
"</script>")
String getAlongLatestTm(@Param("rvcd") String rvcd);
@Select("<script>" +
"SELECT SARC.stcd, " +
"SARC.rstcd, " +
"MAB.RVCD, " +
"MAB.ORDER_INDEX AS rvcdSort, " +
"SARC.sort, " +
"CASE WHEN SARC.STTP = 'ENG' THEN '1' WHEN SARC.STTP = 'WTRV' THEN '2' END AS sttp, " +
"SWR.WT AS temperature, " +
"SWR.TM, " +
"SWR.TM AS minTm, " +
"MST.STNM " +
"FROM MS_ALONG_B MAB " +
"INNER JOIN MS_ALONGDET_B SARC ON MAB.ID = SARC.ALONG_ID " +
"INNER JOIN MS_STBPRP_T MST ON MST.stcd = SARC.STCD " +
"LEFT JOIN (" +
"SELECT * FROM SD_WTRV_R where is_deleted=0 " +
"<if test='maxTime != null'>" +
"and TM = #{maxTime} " +
"</if>" +
"<if test='maxTime == null'>" +
"and TM is null " +
"</if>" +
") SWR ON SWR.STCD = SARC.STCD " +
"WHERE MAB.CODE = 'common' " +
"AND (SARC.STTP = 'ENG' OR SARC.STTP = 'WTRV') " +
"AND SARC.IS_DELETED = 0 " +
"AND MST.IS_DELETED = 0 " +
"AND MAB.IS_DELETED = 0 " +
"<if test='rvcd != null and rvcd != \"\"'>" +
"and MAB.rvcd=#{rvcd} " +
"</if>" +
"<if test='baseId != null and baseId != \"\"'>" +
"and MAB.RVCD in (select WBS_CODE from SD_WBS_B where WBS_TYPE='PSB_RVCD' and is_deleted=0 and OBJ_ID=#{baseId}) " +
"</if>" +
"order by MAB.order_index asc, SARC.sort asc" +
"</script>")
List<SdAlongVO> getAlongListData(@Param("rvcd") String rvcd,@Param("baseId") String baseId,@Param("maxTime") Date maxTime);
@Select("<script>" +
"select TM from (" +
"SELECT MST.STCD, SWR.TM " +
"FROM MS_ALONG_B MAB " +
"INNER JOIN MS_ALONGDET_B SARC ON MAB.ID = SARC.ALONG_ID " +
"INNER JOIN MS_STBPRP_T MST ON MST.stcd = SARC.STCD " +
"INNER JOIN (" +
"select * from SD_WTRV_R where is_deleted = 0 " +
"<if test='startTime != null and endTime != null'>" +
"and tm between #{startTime} and #{endTime} " +
"</if>" +
") SWR ON SWR.STCD = SARC.STCD " +
"WHERE MAB.CODE = 'common' " +
"and MST.IS_DELETED=0 " +
"AND SARC.STTP = 'WTRV' " +
"AND SARC.IS_DELETED = 0 " +
"AND MAB.IS_DELETED = 0 " +
"<if test='rvcd != null and rvcd != \"\"'>" +
"and MAB.rvcd=#{rvcd} " +
"</if>" +
"<if test='baseId != null and baseId != \"\"'>" +
"and MAB.RVCD in (select WBS_CODE from SD_WBS_B where WBS_TYPE='PSB_RVCD' and is_deleted=0 and OBJ_ID=#{baseId}) " +
"</if>" +
"order by MAB.order_index asc, SARC.SORT asc, SWR.TM desc" +
") where ROWNUM=1" +
"</script>")
Date getMaxTime(@Param("rvcd") String rvcd,@Param("baseId") String baseId,@Param("startTime") Date startTime,@Param("endTime") Date endTime);
// List<SdAlongVO> getAvgAlongListData(@Param("rvcd") String rvcd,@Param("baseId") String baseId,@Param("startTime") Date startTime,@Param("endTime") Date endTime);
}

View File

@ -0,0 +1,36 @@
package com.yfd.platform.env.mapper;
import com.yfd.platform.env.entity.vo.DataParam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.Map;
@Mapper
public interface SdWtrvdrtpSMapper {
void deleteWtrvMonthData(@Param("ids") List<String> ids, @Param("deleteTime") String deleteTime);
@Delete("<script>" +
"DELETE FROM SD_WTRV_R WHERE " +
"<foreach collection='dataParamList' item='item' separator=' OR '>" +
"(STCD = #{item.id} AND TM = TO_DATE(SUBSTR(#{item.dt}, 1, 19), 'yyyy-MM-dd HH24:mi:ss'))" +
"</foreach>" +
"</script>")
void deleteWtrvRData(@Param("dataParamList") List<DataParam> dataParamList, @Param("deleteTime") String deleteTime, @Param("userID") String userID);
@Update("<script>" +
"UPDATE SD_WTRV_R " +
"<set>" +
"<if test='updateData.containsKey(\"wt\")'>WT = #{updateData.wt, jdbcType=DECIMAL},</if>" +
"</set>" +
"WHERE STCD = #{updateData.stcd} " +
"AND TM = TO_DATE(#{updateData.dt}, 'yyyy-MM-dd HH24:mi:ss')" +
"</script>")
void updateWtrvRData(@Param("updateData") Map<String, Object> updateData);
// void updateWtvtRData(@Param("updateData") Map<String, Object> updateData);
}

View File

@ -0,0 +1,48 @@
package com.yfd.platform.env.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult;
import com.yfd.platform.common.GroupResult;
import com.yfd.platform.env.entity.vo.BatchDeleteAo;
import com.yfd.platform.env.entity.vo.SdAlongDetailVO;
import com.yfd.platform.env.entity.vo.WtrvInfo;
import java.util.Map;
/**
* 沿程水温变化二级数据接口服务
*
* @author
* @since 2023-04-23 09:32:10
*/
public interface AlongDetailService extends IService<SdAlongDetailVO> {
/**
* 处理kendo列表
*
* @param dataSourceRequest 数据源请求
* @param filterResult 筛选结果
* @param page 页面
* @return {@link DataSourceResult}<{@link SdMonthListVO}>
*/
DataSourceResult<SdAlongDetailVO> processKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page);
DataSourceResult processDayKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page, String groupBy);
DataSourceResult processDrtpKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page, String groupBy);
DataSourceResult processQgcKendList(DataSourceResult dataSourceResult, WtrvInfo wtrvInfo);
WtrvInfo getWtrvInfoByStcd(String stcd);
WtrvInfo getWtrvInfoByStcd2(String stcd);
WtrvInfo getWtrvInfoByStcd3(String stcd);
boolean removeKendoByIds(BatchDeleteAo batchDeleteAo);
void updateWtrvRData(Map<String, Object> updateData);
}

View File

@ -0,0 +1,21 @@
package com.yfd.platform.env.service;
import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
/**
* 沿程水温变化一级折线图服务
*
* @author
* @since 2023-04-23 09:32:10
*/
public interface AlongListService {
Map<String,Object> getWtLimit(DataSourceRequest dataSourceRequest);
DataSourceResult getDefaultRvcd(@RequestBody DataSourceRequest dataSourceRequest);
DataSourceResult getALongKendoListCust(DataSourceRequest dataSourceRequest);
}

View File

@ -0,0 +1,597 @@
package com.yfd.platform.env.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.common.*;
import com.yfd.platform.env.entity.vo.*;
import com.yfd.platform.env.mapper.AlongDetailMapper;
import com.yfd.platform.env.mapper.SdWtrvdrtpSMapper;
import com.yfd.platform.env.service.AlongDetailService;
import com.yfd.platform.utils.CollectionExtUtils;
import com.yfd.platform.utils.SecurityUtils;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 沿程水温二级数据接口服务
*
* @author
* @since 2023-04-23 09:32:10
*/
@Service
public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlongDetailVO> implements AlongDetailService {
@Resource
private DynamicSQLMapper dynamicSQLMapper;
@Resource
private AlongDetailMapper alongDetailMapper;
@Resource
private SdWtrvdrtpSMapper sdWtrvdrtpSMapper;
@Resource
private JdbcTemplate jdbcTemplate;
@Override
public DataSourceResult processKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page) {
DataSourceResult dataSourceResult = new DataSourceResult();
StringBuilder sql = new StringBuilder("SELECT t.tm,t.mon, t.stcd, t.wt, t.stnm, t.basename,t.mway,t.rstcd\n" +
"FROM (SELECT DISTINCT r.tm,to_char(r.tm,'MM') mon, r.stcd, r.WT,r.TASK_ID,r.TASK_STATUS ,t2.stnm,t2.BASE_Id AS baseId, t2.BASE_NAME baseName,t2.MWAY AS mway, t2.rstcd\n" +
" FROM SD_WTRV_R r\n" +
//" inner join MS_ALONGDET_B b on r.stcd=b.stcd and b.is_deleted=0 inner join MS_ALONG_B a on a.ID=b.ALONG_ID and a.code='common' " +
" LEFT JOIN MS_STBPRP_T t2 ON r.STCD = t2.STCD \n" +
" WHERE r.is_deleted=0 and t2.is_deleted=0 " +
" order by r.tm DESC, r.stcd) t where 1=1 ");
sql. append(" AND (TASK_ID IS NULL OR TASK_ID ='' OR TASK_STATUS ='Approved') ");
if (ObjectUtil.isNotEmpty(filterResult.get(CommonConstant.DEFAULT))) {
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getGroupSql())) {
sql.append(" and ").append(filterResult.get(CommonConstant.DEFAULT).getGroupSql());
}
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getOrderBySql())) {
sql.append(" ").append(filterResult.get(CommonConstant.DEFAULT).getOrderBySql());
}
}
Map<String, Object> map = new HashMap();
Iterator iterator = filterResult.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
map.putAll(filterResult.get(key).getParamMap());
}
List<SdAlongDetailVO> list = this.dynamicSQLMapper.pageAllListWithResultType(page, sql.toString(), map, SdAlongDetailVO.class);
dataSourceResult.setData(list);
dataSourceResult.setTotal(ObjectUtil.isNotEmpty(page) ? page.getTotal() : (long) list.size());
return dataSourceResult;
}
@Override
public DataSourceResult processDayKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page, String groupBy) {
DataSourceResult dataSourceResult = new DataSourceResult();
StringBuilder sql = new StringBuilder();
if(StrUtil.isNotBlank(filterResult.get("default").getSelectSql())){
sql.append(filterResult.get("default").getSelectSql());
sql.append(" from ");
sql.append(" SD_WTRVDAY_S a inner join MS_STBPRP_T b on a.STCD=b.STCD and b.STTP_CODE='WTRV' ");
sql.append(" where 1=1 ");
if (ObjectUtil.isNotEmpty(filterResult.get(CommonConstant.DEFAULT))) {
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getGroupSql())) {
sql.append(" and ").append(filterResult.get(CommonConstant.DEFAULT).getGroupSql());
}
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getOrderBySql())) {
sql.append(" ").append(filterResult.get(CommonConstant.DEFAULT).getOrderBySql());
}
}
}
Map<String, Object> map = new HashMap();
Iterator iterator = filterResult.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
map.putAll(filterResult.get(key).getParamMap());
}
List< Map<String, Object>> resultList = this.dynamicSQLMapper.pageAllList(page, sql.toString(), map);
dataSourceResult.setData(resultList);
dataSourceResult.setTotal(ObjectUtil.isNotEmpty(page) ? page.getTotal() : (long) resultList.size());
return dataSourceResult;
}
@Override
public DataSourceResult processDrtpKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page, String groupBy) {
DataSourceResult dataSourceResult = new DataSourceResult();
StringBuilder sql = new StringBuilder();
if(StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getSelectSql())){
sql.append(filterResult.get(CommonConstant.DEFAULT).getSelectSql());
sql.append(" from ");
sql.append(" SD_WTRVDRTP_S a inner join MS_STBPRP_T b on a.STCD=b.STCD and b.STTP_CODE='WTRV' ");
sql.append(" where 1=1 ");
if (ObjectUtil.isNotEmpty(filterResult.get(CommonConstant.DEFAULT))) {
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getGroupSql())) {
sql.append(" and ").append(filterResult.get(CommonConstant.DEFAULT).getGroupSql());
}
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getOrderBySql())) {
sql.append(" ").append(filterResult.get(CommonConstant.DEFAULT).getOrderBySql());
}
}
}
Map<String, Object> map = new HashMap();
Iterator iterator = filterResult.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
map.putAll(filterResult.get(key).getParamMap());
}
List<Map<String, Object>> resultList = this.dynamicSQLMapper.pageAllList(page, sql.toString(), map);
dataSourceResult.setData(resultList);
dataSourceResult.setTotal(ObjectUtil.isNotEmpty(page) ? page.getTotal() : (long) resultList.size());
return dataSourceResult;
}
@Override
public DataSourceResult processQgcKendList(DataSourceResult dataSourceResult, WtrvInfo wtrvInfo) {
DataSourceResult dr = new DataSourceResult();
List<Map<String, Object>> list = (List<Map<String, Object>>) dataSourceResult.getData();
if (list == null || list.isEmpty()) {
dr.setData(new ArrayList<>());
dr.setTotal(0);
return dr;
}
Date startTime = (Date) list.get(0).get("tm");
Date endTime = (Date) list.get(list.size() - 1).get("tm");
if (startTime.compareTo(endTime) > 0) {
Date tmpDate = startTime;
startTime = endTime;
endTime = tmpDate;
}
List<Map<String, Object>> iwtDataVoList = new ArrayList<>();
List<Map<String, Object>> dwtDataVoList = new ArrayList<>();
List<Map<String, Object>> wtvtDataVoList = new ArrayList<>();
List<Map<String, Object>> hydropwDataVoList = new ArrayList<>();
List<Map<String, Object>> pptnDataVoList = new ArrayList<>();
List<Map<String, Object>> tmpDataVoList = new ArrayList<>();
List<Map<String, Object>> wtnpDataVoList;
if (wtrvInfo.getType() == 1) {
dwtDataVoList.addAll(this.alongDetailMapper.getDwtrvDataList(wtrvInfo.getStcd(), null, startTime, endTime));
}
Map<Date, List<Map<String, Object>>> wtvtDataVoMap;
if (wtrvInfo.getType() == 2) {
iwtDataVoList.addAll(this.alongDetailMapper.getIwtrvDataList(wtrvInfo.getStcd(), null, startTime, endTime));
wtvtDataVoList.addAll(this.alongDetailMapper.getWtvtDataList(null, wtrvInfo.getRstcd(), startTime, endTime));
wtvtDataVoMap = wtvtDataVoList.stream()
.filter(it -> it.get("tm") != null)
.collect(Collectors.groupingBy(it -> (Date) it.get("tm")));
} else {
wtvtDataVoMap = null;
}
Map<Date, Map<String, Object>> iwtDataMap = iwtDataVoList.stream()
.collect(Collectors.toMap(it -> (Date) it.get("tm"), Function.identity()));
Map<Date, Map<String, Object>> dwtDataMap = dwtDataVoList.stream()
.collect(Collectors.toMap(it -> (Date) it.get("tm"), Function.identity()));
hydropwDataVoList.addAll(this.alongDetailMapper.getHydropwDataList(wtrvInfo.getStcd(), startTime, endTime));
Map<Date, Map<String, Object>> hydropwDataMap = hydropwDataVoList.stream()
.collect(Collectors.toMap(it -> (Date) it.get("tm"), Function.identity()));
pptnDataVoList.addAll(this.alongDetailMapper.getPptnDataList(wtrvInfo.getStcd(), startTime, endTime));
Map<Date, Map<String, Object>> pptnDataMap = pptnDataVoList.stream()
.collect(Collectors.toMap(it -> (Date) it.get("tm"), Function.identity()));
tmpDataVoList.addAll(this.alongDetailMapper.getTmpDataList(wtrvInfo.getStcd(), startTime, endTime));
Map<Date, Map<String, Object>> tmpDataMap = tmpDataVoList.stream()
.collect(Collectors.toMap(it -> (Date) it.get("tm"), Function.identity()));
Map<Integer, BigDecimal> wtnpDataMap = new HashMap<>();
if (StrUtil.isNotBlank(wtrvInfo.getRstcd())) {
wtnpDataVoList = this.alongDetailMapper.getNatureTmpDataList(wtrvInfo.getRstcd(), null);
wtnpDataMap.putAll(wtnpDataVoList.stream()
.filter(it -> it.get("mnth") != null)
.collect(Collectors.toMap(
it -> (Integer) it.get("mnth"),
it -> (BigDecimal) it.get("wt")
)));
}
List<Map<String, Object>> qgcWtrvDataVoList = new ArrayList<>();
list.forEach(it -> {
Map<String, Object> vo = new HashMap<>();
vo.put("stcd", it.get("stcd"));
vo.put("stnm", it.get("stnm"));
vo.put("wt", it.get("wt"));
vo.put("tm", it.get("tm"));
vo.put("ennm", wtrvInfo.getEnnm());
vo.put("rstcd", wtrvInfo.getRstcd());
vo.put("type", wtrvInfo.getType());
vo.put("natureTmp", wtnpDataMap.get(it.get("mon")));
vo.put("hydropwDataVo", hydropwDataMap.get(it.get("tm")));
vo.put("pptnDataVo", pptnDataMap.get(it.get("tm")));
vo.put("tmpDataVo", tmpDataMap.get(it.get("tm")));
if (wtrvInfo.getType() == 1) {
Map<String, Object> iwtVo = new HashMap<>();
iwtVo.put("tm", it.get("tm"));
iwtVo.put("wt", it.get("wt"));
vo.put("iwtDataVo", iwtVo);
vo.put("dwtDataVo", dwtDataMap.get(it.get("tm")));
}
if (wtrvInfo.getType() == 2) {
Map<String, Object> dwtVo = new HashMap<>();
dwtVo.put("tm", it.get("tm"));
dwtVo.put("wt", it.get("wt"));
vo.put("dwtDataVo", dwtVo);
vo.put("iwtDataVo", iwtDataMap.get(it.get("tm")));
if (it.get("wt") != null && wtvtDataVoMap != null) {
List<Map<String, Object>> vtList = wtvtDataVoMap.get(it.get("tm"));
if (vtList != null) {
Map<BigDecimal, List<Map<String, Object>>> vtMap = vtList.stream()
.filter(tt -> tt.get("vwt") != null)
.collect(Collectors.groupingBy(tt -> (BigDecimal) tt.get("vwt")));
if (vtMap.containsKey(it.get("wt"))) {
vo.put("wtvtDataVo", vtMap.get(it.get("wt")).get(0));
qgcWtrvDataVoList.add(vo);
return;
}
BigDecimal leftVt = null;
BigDecimal rightVt = null;
Map<String, Object> leftVo = null;
Map<String, Object> rightVo = null;
List<BigDecimal> sortVt = new ArrayList<>(vtMap.keySet()).stream()
.sorted()
.collect(Collectors.toList());
BigDecimal[] lrValue = CollectionExtUtils.findNeighbors(sortVt, (BigDecimal) it.get("wt"));
if (lrValue.length == 2) {
leftVt = lrValue[0];
rightVt = lrValue[1];
}
Map<String, Object> vo1 = new HashMap<>();
if (leftVt != null) {
leftVo = vtMap.get(leftVt).get(0);
vo1.put("leftWtvtData", leftVo);
}
if (rightVt != null) {
rightVo = vtMap.get(rightVt).get(0);
vo1.put("rightWtvtData", rightVo);
}
if (leftVt != null && rightVt != null) {
BigDecimal currentWt = (BigDecimal) it.get("wt");
BigDecimal wthg = ((rightVt.subtract(currentWt)).multiply((BigDecimal) leftVo.get("wthg"))
.add((currentWt.subtract(leftVt)).multiply((BigDecimal) rightVo.get("wthg"))))
.divide((rightVt.subtract(currentWt)).add(currentWt.subtract(leftVt)), RoundingMode.HALF_UP);
vo1.put("wthg", wthg);
vo1.put("vwt", currentWt);
}
vo.put("wtvtDataVo", vo1);
}
}
}
qgcWtrvDataVoList.add(vo);
});
dr.setData(qgcWtrvDataVoList);
dr.setTotal(dataSourceResult.getTotal());
return dr;
}
@Override
public WtrvInfo getWtrvInfoByStcd(String stcd) {
return this.alongDetailMapper.getWtrvInfoByStcd(stcd);
}
@Override
public WtrvInfo getWtrvInfoByStcd2(String stcd) {
return this.alongDetailMapper.getWtrvInfoByStcd2(stcd);
}
@Override
public WtrvInfo getWtrvInfoByStcd3(String stcd) {
return this.alongDetailMapper.getWtrvInfoByStcd3(stcd);
}
@Override
public boolean removeKendoByIds(BatchDeleteAo batchDeleteAo) {
String dataType = batchDeleteAo.getDataType();
List<DataParam> dataList = batchDeleteAo.getDataList();
if(CollUtil.isEmpty(dataList)){
return true;
}
//删除小时数据
int batchSize = 500;
for (int i = 0; i < dataList.size(); i += batchSize) {
List<DataParam> subList = dataList.subList(i, Math.min(i + batchSize, dataList.size()));
//判断数据类型
if ("MON".equals(dataType)) {
//删除月数据
}
if ("DATE".equals(dataType)) {
//删除日数据
}
if ("TIME".equals(dataType)) {
sdWtrvdrtpSMapper.deleteWtrvRData(subList, DateUtil.now(), SecurityUtils.getCurrentUsername());
// 删除小时数据后需要重新统计对应的日数据和月数据
Map<String, String[]> dateRangeMap = new HashMap<>();
Map<String, String[]> monthRangeMap = new HashMap<>();
for (DataParam param : subList) {
if (param.getId() != null && param.getDt() != null) {
String stcd = param.getId();
String tm = param.getDt();
// 提取日期部分
String dateStr = tm.substring(0, 10);
// 收集每个测站的日期范围
if (!dateRangeMap.containsKey(stcd)) {
dateRangeMap.put(stcd, new String[]{dateStr, dateStr});
} else {
String[] range = dateRangeMap.get(stcd);
if (dateStr.compareTo(range[0]) < 0) {
range[0] = dateStr;
}
if (dateStr.compareTo(range[1]) > 0) {
range[1] = dateStr;
}
}
// 收集每个测站的月份范围
String yearMonth = tm.substring(0, 7);
String[] ym = yearMonth.split("-");
if (ym.length == 2) {
Integer year = Integer.parseInt(ym[0]);
Integer month = Integer.parseInt(ym[1]);
String monthStart = year + "-" + String.format("%02d", month) + "-01";
String monthEnd = getMonthEndDate(year, month);
String monthKey = stcd + "_" + year + "_" + month;
if (!monthRangeMap.containsKey(monthKey)) {
monthRangeMap.put(monthKey, new String[]{stcd, monthStart, monthEnd});
}
}
}
}
// 统计日数据从小时数据- 按测站和日期范围批量统计
for (Map.Entry<String, String[]> entry : dateRangeMap.entrySet()) {
String stcd = entry.getKey();
String[] range = entry.getValue();
statisticsDayDataFromHour(stcd, range[0], range[1]);
}
// 统计月数据从日数据- 按测站和月份范围批量统计
Set<String> processedMonths = new HashSet<>();
for (String[] values : monthRangeMap.values()) {
String stcd = values[0];
String startDate = values[1];
String endDate = values[2];
String monthKey = stcd + "_" + startDate;
if (!processedMonths.contains(monthKey)) {
statisticsMonthDataFromDay(stcd, startDate, endDate);
processedMonths.add(monthKey);
}
}
}
}
return true;
}
/**
* 获取指定年月的最后一天
*/
private String getMonthEndDate(Integer year, Integer month) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, 1);
int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
return year + "-" + String.format("%02d", month) + "-" + String.format("%02d", lastDay);
}
/**
* 从小时水温数据统计日数据支持日期范围
* @param stcd 测站编码
* @param startDate 开始日期 yyyy-MM-dd
* @param endDate 结束日期 yyyy-MM-dd
*/
private void statisticsDayDataFromHour(String stcd, String startDate, String endDate) {
// 第一步标记没有对应小时数据的日记录为删除
String deleteSql = "DELETE FROM SD_WTRVDAY_S T " +
"WHERE T.STCD = ? " +
"AND T.DT BETWEEN TO_DATE(?, 'YYYY-MM-DD') " +
"AND TO_DATE(?, 'YYYY-MM-DD') " +
"AND NOT EXISTS ( " +
"SELECT 1 FROM SD_WTRV_R S " +
"WHERE S.STCD = T.STCD " +
"AND TRUNC(S.TM) = T.DT " +
"AND S.TM >= TO_DATE(? || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS') " +
"AND S.TM <= TO_DATE(? || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS') " +
"AND S.IS_DELETED = 0)";
// String deleteSql = "UPDATE SD_WTRVDAY_S T " +
// "SET T.IS_DELETED = 1, " +
// "T.DELETE_TIME = SYSDATE, " +
// "T.MODIFY_TIME = SYSDATE " +
// "WHERE T.STCD = ? " +
// "AND T.DT BETWEEN TO_DATE(?, 'YYYY-MM-DD') " +
// "AND TO_DATE(?, 'YYYY-MM-DD') " +
// "AND T.IS_DELETED = 0 " +
// "AND NOT EXISTS ( " +
// "SELECT 1 FROM SD_WTRV_R S " +
// "WHERE S.STCD = T.STCD " +
// "AND TRUNC(S.TM) = T.DT " +
// "AND S.TM >= TO_DATE(? || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS') " +
// "AND S.TM <= TO_DATE(? || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS') " +
// "AND S.IS_DELETED = 0)";
jdbcTemplate.update(deleteSql, stcd, startDate, endDate, startDate, endDate);
// 第二步从小时数据聚合统计日数据
String mergeSql = "MERGE INTO SD_WTRVDAY_S T " +
"USING ( " +
" SELECT " +
" STCD, " +
" TRUNC(TM) AS DT, " +
" AVG(WT) AS WT " +
" FROM SD_WTRV_R " +
" WHERE STCD = ? " +
" AND TM >= TO_DATE(? || ' 00:00:00', 'YYYY-MM-DD HH24:MI:SS') " +
" AND TM <= TO_DATE(? || ' 23:59:59', 'YYYY-MM-DD HH24:MI:SS') " +
" AND IS_DELETED = 0 " +
" GROUP BY STCD, TRUNC(TM) " +
") S " +
"ON (T.STCD = S.STCD AND T.DT = S.DT) " +
"WHEN MATCHED THEN UPDATE SET " +
" T.WT = S.WT, " +
" T.IS_DELETED = 0, " +
" T.DELETE_TIME = NULL, " +
" T.MODIFY_TIME = SYSDATE " +
"WHEN NOT MATCHED THEN INSERT ( " +
" ID, STCD, DT, WT, RECORD_TIME, IS_DELETED " +
") VALUES ( " +
" SYS_GUID(), S.STCD, S.DT, S.WT, SYSDATE, 0 " +
")";
jdbcTemplate.update(mergeSql, stcd, startDate, endDate);
}
/**
* 从日水温数据统计月数据支持日期范围
* @param stcd 测站编码
* @param startDate 开始日期 yyyy-MM-dd
* @param endDate 结束日期 yyyy-MM-dd
*/
private void statisticsMonthDataFromDay(String stcd, String startDate, String endDate) {
// 解析年月
String startYear = startDate.substring(0, 4);
String startMonth = startDate.substring(5, 7);
String endYear = endDate.substring(0, 4);
String endMonth = endDate.substring(5, 7);
Integer startYearInt = Integer.parseInt(startYear);
Integer startMonthInt = Integer.parseInt(startMonth);
Integer endMonthInt = Integer.parseInt(endMonth);
// 第一步标记没有对应日数据的月记录为删除
// String deleteSql = "UPDATE SD_WTRVDRTP_S T " +
// "SET T.IS_DELETED = 1, " +
// "T.DELETE_TIME = SYSDATE, " +
// "T.MODIFY_TIME = SYSDATE " +
// "WHERE T.DRTP = 'MON' " +
// "AND T.STCD = ? " +
// "AND T.YEAR = ? " +
// "AND T.MONTH BETWEEN ? AND ? " +
// "AND T.IS_DELETED = 0 " +
// "AND NOT EXISTS ( " +
// " SELECT 1 FROM SD_WTRVDAY_S D " +
// " WHERE D.STCD = T.STCD " +
// " AND D.IS_DELETED = 0 " +
// " AND EXTRACT(YEAR FROM D.DT) = T.YEAR " +
// " AND EXTRACT(MONTH FROM D.DT) = T.MONTH " +
// " AND D.DT >= TO_DATE(?, 'YYYY-MM-DD') " +
// " AND D.DT < TO_DATE(?, 'YYYY-MM-DD') + 1)";
String deleteSql = "DELETE FROM SD_WTRVDRTP_S T " +
"WHERE T.DRTP = 'MON' " +
"AND T.STCD = ? " +
"AND T.YEAR = ? " +
"AND T.MONTH BETWEEN ? AND ? " +
"AND NOT EXISTS ( " +
" SELECT 1 FROM SD_WTRVDAY_S D " +
" WHERE D.STCD = T.STCD " +
" AND D.IS_DELETED = 0 " +
" AND EXTRACT(YEAR FROM D.DT) = T.YEAR " +
" AND EXTRACT(MONTH FROM D.DT) = T.MONTH " +
" AND D.DT >= TO_DATE(?, 'YYYY-MM-DD') " +
" AND D.DT < TO_DATE(?, 'YYYY-MM-DD') + 1)";
jdbcTemplate.update(deleteSql, stcd, startYearInt, startMonthInt, endMonthInt, startDate, endDate);
// 第二步从日数据聚合统计月数据
String mergeSql = "MERGE INTO SD_WTRVDRTP_S T " +
"USING ( " +
" SELECT " +
" STCD, " +
" EXTRACT(YEAR FROM DT) AS YEAR, " +
" EXTRACT(MONTH FROM DT) AS MONTH, " +
" 'MON' AS DRTP, " +
" AVG(WT) AS WT " +
" FROM SD_WTRVDAY_S " +
" WHERE STCD = ? " +
" AND DT >= TO_DATE(?, 'YYYY-MM-DD') " +
" AND DT < TO_DATE(?, 'YYYY-MM-DD') + 1 " +
" AND IS_DELETED = 0 " +
" GROUP BY STCD, EXTRACT(YEAR FROM DT), EXTRACT(MONTH FROM DT) " +
") S " +
"ON (T.STCD = S.STCD AND T.DRTP = 'MON' AND T.YEAR = S.YEAR AND T.MONTH = S.MONTH) " +
"WHEN MATCHED THEN UPDATE SET " +
" T.WT = S.WT, " +
" T.IS_DELETED = 0, " +
" T.DELETE_USER = NULL, " +
" T.DELETE_TIME = NULL, " +
" T.MODIFY_USER = USER, " +
" T.MODIFY_TIME = SYSDATE, " +
" T.TM = SYSDATE " +
"WHEN NOT MATCHED THEN INSERT ( " +
" ID, STCD, WT, DRTP, YEAR, MONTH, DR, RECORD_TIME, IS_DELETED, TM " +
") VALUES ( " +
" SYS_GUID(), S.STCD, S.WT, 'MON', S.YEAR, S.MONTH, NULL, SYSDATE, 0, SYSDATE " +
")";
jdbcTemplate.update(mergeSql, stcd, startDate, endDate);
}
@Override
public void updateWtrvRData(Map<String, Object> updateData) {
sdWtrvdrtpSMapper.updateWtrvRData(updateData);
// 获取测站编码和时间
String stcd = (String) updateData.get("stcd");
String tm = (String) updateData.get("dt");
if (StrUtil.isNotBlank(stcd) && StrUtil.isNotBlank(tm)) {
// 提取日期部分yyyy-MM-dd
String dateStr = tm.substring(0, 10);
// 从小时水温数据统计日数据
statisticsDayDataFromHour(stcd, dateStr, dateStr);
// 从日水温数据统计月数据统计该日期所在月份
String yearMonth = dateStr.substring(0, 7);
String[] ym = yearMonth.split("-");
if (ym.length == 2) {
Integer year = Integer.parseInt(ym[0]);
Integer month = Integer.parseInt(ym[1]);
String startDate = year + "-" + String.format("%02d", month) + "-01";
String endDate = getMonthEndDate(year, month);
statisticsMonthDataFromDay(stcd, startDate, endDate);
}
}
}
}

View File

@ -0,0 +1,147 @@
package com.yfd.platform.env.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.common.DataSourceLoadOptionsBase;
import com.yfd.platform.common.DataSourceRequest;
import com.yfd.platform.common.DataSourceResult;
import com.yfd.platform.common.DynamicSQLMapper;
import com.yfd.platform.common.exception.BizException;
import com.yfd.platform.env.entity.vo.SdAlongVO;
import com.yfd.platform.env.mapper.AlongListMapper;
import com.yfd.platform.env.service.AlongListService;
import com.yfd.platform.utils.QgcQueryWrapperUtil;
import com.yfd.platform.utils.QueryWrapperUtil;
import com.yfd.platform.utils.SqlUtil;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 沿程水温一级数据接口服务
*
* @author
* @since 2023-04-23 09:32:10
*/
@Service
public class AlongListServiceImpl extends ServiceImpl<AlongListMapper, SdAlongVO> implements AlongListService {
@Resource
private DynamicSQLMapper dynamicSQLMapper;
@Resource
private AlongListMapper alongListMapper;
@Override
public Map<String,Object> getWtLimit(DataSourceRequest dataSourceRequest) {
String sql = "SELECT\n" +
"\tt2.MIN_VAL AS min,\n" +
"\tt2.MAX_VAL AS max\n" +
"FROM\n" +
"\tMS_WARN_RULE_B t1\n" +
"INNER JOIN MS_WARN_RULE_DETAIL_B t2 ON\n" +
"\tt1.ID = t2.RULE_ID\n" +
"WHERE\n" +
"\tt1.RULE_TYPE = 'WTMN'";
List<Map<String,Object>> resultList = dynamicSQLMapper.getAllList(sql, null);
if(!CollectionUtils.isEmpty(resultList)){
return resultList.get(0);
}
return null;
}
@Override
public DataSourceResult getDefaultRvcd(DataSourceRequest dataSourceRequest) {
DataSourceResult<Map<String, String>> dataSourceResult = new DataSourceResult<>();
String sqlTemplate ="\tSELECT RVCD FROM " +
"\t( SELECT RVCD,SORT FROM " +
"\t(select MAB.RVCD,SAB.STCD,CASE WHEN MAB.RVCD #{rvcd} THEN 0 ELSE 1 END AS SORT from MS_ALONG_B MAB inner join MS_ALONGDET_B SAB on SAB.ALONG_ID = MAB.ID WHERE SAB.IS_DELETED =0 AND MAB.IS_DELETED =0 AND SAB.STTP IN ('WTRV', 'ENG') and MAB.CODE='common') t1 " +
"\tINNER JOIN " +
"\t(SELECT WBS_CODE FROM SD_WBS_B WHERE wbs_type = 'PSB_RVCD' #{full_path} AND WBS_NAME IS NOT NULL) t2 " +
"\tON t1.RVCD = t2.WBS_CODE " +
"\tINNER JOIN " +
"\t(SELECT STCD FROM SD_WTRV_R WHERE TM >= #{tm} AND TM <= #{tm_1} AND WT IS NOT NULL ) t3 " +
"\tON t1.STCD = t3.STCD ORDER BY SORT ASC " +
"\t) WHERE ROWNUM = 1 ";
Map<String,Object> sqlWhereMap = new HashMap<>();
SqlUtil.getWhereCondition(dataSourceRequest,sqlWhereMap);
Object full_path = sqlWhereMap.get("full_path");
if(full_path !=null){
String fullPathStr = full_path.toString();
if(fullPathStr.startsWith("'") && fullPathStr.endsWith("'")){
fullPathStr = fullPathStr.substring(1,fullPathStr.length()-1);
}
sqlWhereMap.put("full_path","AND OBJ_ID = '"+fullPathStr+"'");
}else{
sqlWhereMap.put("full_path"," ");
}
Object rvcd = sqlWhereMap.get("rvcd");
if(rvcd == null || StringUtils.isBlank(rvcd.toString())){
sqlWhereMap.put("rvcd"," IS NOT NULL ");
}else{
sqlWhereMap.put("rvcd"," = "+rvcd);
}
String sql = SqlUtil.getSqlByTemplate(sqlTemplate, sqlWhereMap);
List<Map<String, String>> list = dynamicSQLMapper.pageAllList(null, sql, null);
dataSourceResult.setData(list);
dataSourceResult.setTotal(list.size());
return dataSourceResult;
}
@Override
public DataSourceResult getALongKendoListCust(DataSourceRequest dataSourceRequest) {
DataSourceResult dataSourceResult = new DataSourceResult<>();
DataSourceLoadOptionsBase loadOptionsBase = dataSourceRequest.toDevRequest();
String rvcd = QgcQueryWrapperUtil.getFilterFieldValue(loadOptionsBase, "rvcd");
String baseId = QgcQueryWrapperUtil.getFilterFieldValue(loadOptionsBase,"baseId");
String tm = QgcQueryWrapperUtil.getFilterFieldValue(loadOptionsBase,"tm");
if(StrUtil.isBlank(tm)){
throw new BizException("时间(tm)不能为空.");
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startTime = null;
Date endTime = null;
if(StrUtil.isNotBlank(tm)){
String[] ll=tm.split(",");
if(ll.length==2){
try{
Date st = sdf.parse(ll[0]);
Date et = sdf.parse(ll[1]);
if(st.after(et)){
startTime= et;
endTime=st;
}else {
startTime =st;endTime=et;
}
}catch (Exception ex){
log.error("日期格式错误! {}",ex);
}
}
}
Date maxTm = this.alongListMapper.getMaxTime(rvcd,baseId,startTime,endTime);
String maxTmStr;
if(maxTm!=null){
maxTmStr = sdf.format(maxTm);
} else {
maxTmStr = null;
}
List<SdAlongVO> alongVOList = this.alongListMapper.getAlongListData(rvcd,baseId,maxTm);
//过滤掉无水温测站关联的电站
Set<String> rstcdSet = alongVOList.stream().filter(sdAlongVO -> SdAlongVO.TYPE_ENV.equals(sdAlongVO.getSttp())).map(SdAlongVO::getRstcd).collect(Collectors.toSet());
alongVOList =alongVOList.stream().filter(sdAlongVO -> SdAlongVO.TYPE_ENV.equals(sdAlongVO.getSttp()) || rstcdSet.contains(sdAlongVO.getStcd())).collect(Collectors.toList());
alongVOList.forEach(it->{
it.setMinTm(maxTmStr);
it.setTm(maxTmStr);
});
dataSourceResult.setTotal(alongVOList.size());
dataSourceResult.setData(alongVOList);
return dataSourceResult;
}
}

View File

@ -0,0 +1,257 @@
package com.yfd.platform.utils;
import com.google.common.base.Objects;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.util.*;
/**
* description:
* <pre>
* template
* </pre>
*
* @author supeng
* @date 2018 -08-30 14:53
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class CollectionExtUtils {
/**
* 内存分页
*
* @param <E> //
* @param datas //
* @param row //
* @param page //
* @return //
*/
public static <E> List<E> getBatch(Collection<E> datas, Integer row, Integer page) {
List<Collection<E>> batchCollection = getBatch(datas, row);
if (batchCollection.isEmpty()) {
return new ArrayList<>();
}
page = (page == null || page < 1) ? 1 : page;
if (batchCollection.size() >= page) {
return (List<E>) batchCollection.get(page - 1);
} else {
return (List<E>) batchCollection.get(batchCollection.size() - 1);
}
}
/**
* 对集合数据, 进行批次
*
* @param <E> //
* @param datas //
* @param row //
* @return //
*/
public static <E> List<Collection<E>> getBatch(Collection<E> datas, Integer row) {
List<Collection<E>> result = new ArrayList<>();
if (datas == null || datas.isEmpty()) {
return result;
}
//批量每次最多条数, 默认100
row = (row == null || row < 1) ? 100 : row;
int sourListSize = datas.size();
int subCount = (sourListSize % row == 0) ? sourListSize / row : sourListSize / row + 1;
int startIndex = 0;
int stopIndex = 0;
List<E> collectionDataList = new ArrayList<>(datas);
for (int i = 0; i < subCount; i++) {
stopIndex = ((i == subCount - 1) && (sourListSize % row != 0)) ? stopIndex + sourListSize % row : stopIndex + row;
List<E> es = collectionDataList.subList(startIndex, stopIndex);
result.add(es);
startIndex = stopIndex;
}
return result;
}
/**
* List 2 iterator array iterator.
*
* @param list the list
* @return the iterator
*/
public static Iterator<Object[]> convertIteratorArray(List<?> list) {
List<Object[]> dataToBeReturned = new ArrayList<>();
for (Object item : list) {
dataToBeReturned.add(new Object[]{item});
}
return dataToBeReturned.iterator();
}
/**
* Gets map key by value.
*
* @param findValue the find value
* @param map the map
* @return the map key by value
*/
public static Object getMapKey(Object findValue, Map<Object, Object> map) {
if (!map.containsValue(findValue)) {
return null;
}
for (Map.Entry<Object, Object> entry : map.entrySet()) {
if (findValue.equals(entry.getValue())) {
return entry.getKey();
}
}
return null;
}
public static <V> V getMapKey(Object findValue, Map<Object, Object> map, Class<V> valType) {
Object mapKey = getMapKey(findValue, map);
//noinspection unchecked
return mapKey == null ? null : (V) mapKey;
}
/**
* 移除map中空key或者value空值
*
* @param map //
*/
public static void removeNullEntry(Map map) {
removeNullKey(map);
removeNullValue(map);
}
/**
* 移除map的空key
*
* @param map //
* @return //
*/
public static void removeNullKey(Map map) {
Set set = map.keySet();
for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
Object obj = (Object) iterator.next();
remove(obj, iterator);
}
}
/**
* 移除map中的value空值
*
* @param map
* @return
*/
public static void removeNullValue(Map map) {
Set set = map.keySet();
for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
Object obj = (Object) iterator.next();
Object value = (Object) map.get(obj);
remove(value, iterator);
}
}
/**
* 移除map中的空值
* <p>
* Iterator 是工作在一个独立的线程中, 并且拥有一个 mutex . Iterator
* 被创建之后会建立一个指向原来对象的单链索引表, 当原来的对象数量发生变化时, 这个索引表的内容不会同步改变,
* 所以当索引指针往后移动的时候就找不到要迭代的对象, 所以按照 fail-fast 原则 Iterator 会马上抛出
* java.util.ConcurrentModificationException 异常. 所以 Iterator
* 在工作的时候是不允许被迭代的对象被改变的. 但你可以使用 Iterator 本身的方法 remove() 来删除对象, Iterator.remove()
* 方法会在删除当前迭代对象的同时维护索引的一致性.
*
* @param obj
* @param iterator
*/
private static void remove(Object obj, Iterator iterator) {
if (obj instanceof String) {
String str = (String) obj;
if (StringUtils.isEmpty(str)) { // 过滤掉为null和""的值 主函数输出结果map{2=BB, 1=AA, 5=CC, 8= }
// if("".equals(str.trim())){ //过滤掉为null""" "的值 主函数输出结果map{2=BB, 1=AA, 5=CC}
iterator.remove();
}
} else if (obj instanceof Collection) {
Collection col = (Collection) obj;
if (col == null || col.isEmpty()) {
iterator.remove();
}
} else if (obj instanceof Map) {
Map temp = (Map) obj;
if (temp == null || temp.isEmpty()) {
iterator.remove();
}
} else if (obj instanceof Object[]) {
Object[] array = (Object[]) obj;
if (array == null || array.length <= 0) {
iterator.remove();
}
} else {
if (obj == null) {
iterator.remove();
}
}
}
/**
* 过滤未修改的数据 主键不过滤
*
* @param map
* @return
*/
public static Map<String, Object> cleanModifyMap(Map<String, Object> map) {
Map<String, Object> mapModify = Maps.newHashMap();
if (null == map || null == map.get("modifyKeys")) {
return null;
}
//只修改数据来源不提交
// if(null != map.get("modifyKeys") && (Objects.equal(map.get("modifyKeys").toString(), "[vlsr]") || Objects.equal(map.get("modifyKeys").toString(), "[valuesr]"))) {
// return null;
// }
String modifyKeys = map.get("modifyKeys").toString().replace("[", "").replace("]", "");
String[] modifyKeyStr = modifyKeys.split(",");
for (Map.Entry<String, Object> mapEntry : map.entrySet()) {
//非key的字段不过滤
if (Objects.equal(mapEntry.getKey(), "stcd") || Objects.equal(mapEntry.getKey(), "blprd") ||
Objects.equal(mapEntry.getKey(), "spcd") || Objects.equal(mapEntry.getKey(), "mchgrno") || Objects.equal(mapEntry.getKey(), "vlsr")) {
mapModify.put(mapEntry.getKey(), mapEntry.getValue());
}
for (int i = 0; i < modifyKeyStr.length; i++) {
//主键不过滤
if (Objects.equal(modifyKeyStr[i].trim(), mapEntry.getKey())) {
mapModify.put(mapEntry.getKey(), mapEntry.getValue());
}
}
}
return mapModify;
}
/**
* 根据给定值,获取其前后的数值
* @param list
* @param target
* @return
*/
public static BigDecimal[] findNeighbors(List<BigDecimal> list, BigDecimal target) {
int index = list.indexOf(target);
// 如果找到了目标数字
if (index >= 0) {
BigDecimal before = (index > 0) ? list.get(index - 1) : null; // 前一个数字
BigDecimal after = (index < list.size() - 1) ? list.get(index + 1) : null; // 后一个数字
return new BigDecimal[]{before, after};
} else {
for(int i = 0; i < list.size(); i++){
//找到比target大的位置
if(target.compareTo(list.get(i))<0){
index=i;
break;
}
}
//取前后的值
BigDecimal before = (index <= 0) ? null: list.get(index-1); // 前一个数字
BigDecimal after = (index < 0 || index == list.size()-1)?null:(list.get(index)); // 后一个数字
return new BigDecimal[]{before, after};
}
}
}

View File

@ -0,0 +1,127 @@
package com.yfd.platform.utils;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.yfd.platform.common.DataSourceRequest;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class SqlUtil {
public static StringBuilder getWhereCondition(DataSourceRequest dataSourceRequest, Map<String, Object> sqlWhereMap) {
StringBuilder sb = new StringBuilder();
DataSourceRequest.FilterDescriptor filterDescriptor = dataSourceRequest.getFilter();
String logic = filterDescriptor.getLogic();
for (DataSourceRequest.FilterDescriptor filter : filterDescriptor.getFilters()) {
StringBuilder keyStr = new StringBuilder();
String field = filter.getField();
field = StrUtil.toUnderlineCase(field);
Object value = filter.getValue();
String operator = filter.getOperator();
String dataType = filter.getDataType();
if (StringUtils.isBlank(dataType)) {
dataType = "string";
}
//value值不为空并且operator不是isnull和isnotnull,则忽略
if ((value == null || StringUtils.isBlank(value.toString())) && !("isnull").equals(operator) && !("isnotnull").equals(operator)) {
continue;
}
keyStr.append(String.format(" %s %s", logic, field));
if ("date".equals(dataType)) {
if (String.valueOf(value).length() == 10) {
value = value + " 00:00:00";
}
value = "TO_DATE('" + value + "'," + "'YYYY-MM-DD HH24:MI:SS'" + ")";
}
if ("string".equals(dataType)) {
value = "'" + value + "'";
}
switch (filter.getOperator()) {
case "eq":
operator = "=";
break;
case "ne":
operator = "!=";
break;
case "isnull":
operator = "is null";
break;
case "isnotnull":
operator = "is not null";
break;
case "lt":
operator = "<";
break;
case "lte":
operator = "<=";
break;
case "ge":
operator = ">";
break;
case "gte":
operator = ">=";
break;
case "contains":
operator = "like";
value = "'%" + filter.getValue() + "%'";
break;
case "in":
operator = "in";
value = "(" + getInCondition(filter.getValue().toString()) + ")";
default:
}
keyStr.append(String.format(" %s ", operator));
StringBuffer sqlBuffer = new StringBuffer();
sqlBuffer.append(keyStr).append(value);
if ("or".equalsIgnoreCase(filterDescriptor.getLogic())) {
sb.append(String.format("%s%s%s", " or (", sqlBuffer, ")"));
} else {
sb.append(sqlBuffer);
if (sqlWhereMap != null) {
if (sqlWhereMap.containsKey(field)) {
field = field + "_1";
}
sqlWhereMap.put(field, value);
}
}
}
return sb;
}
private static String getInCondition(String value) {
if (value.startsWith("[") && value.endsWith("]")) {
value = value.substring(1, value.length() - 1);
}
List<String> valueList = Arrays.asList(value.split(","));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < valueList.size(); i++) {
sb.append("'").append(valueList.get(i).trim()).append("'");
if (i != valueList.size() - 1) {
sb.append(",");
}
}
return sb.toString();
}
public static String getSqlByTemplate(String sqlTemplate, Map<String, Object> paramMap) {
if (StringUtils.isBlank(sqlTemplate) || MapUtil.isEmpty(paramMap)) {
return sqlTemplate;
}
for(String key : paramMap.keySet()){
String value = paramMap.get(key).toString();
String replcaeKey = "#{"+key+"}";
sqlTemplate = sqlTemplate.replace(replcaeKey,value);
}
return sqlTemplate;
}
public static String getDateFormat(String date){
return " TO_DATE('"+date+"','YYYY-MM-DD HH24:MI:SS') ";
}
}

View File

@ -11,13 +11,13 @@ spring:
master: master:
driverClassName: oracle.jdbc.OracleDriver driverClassName: oracle.jdbc.OracleDriver
url: "${DB_MASTER_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}" url: "${DB_MASTER_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}"
username: "${DB_MASTER_USERNAME:QGC}" username: "${DB_MASTER_USERNAME:QGC_REFA}"
password: "${DB_MASTER_PASSWORD:ar6Yr7Vxo5}" password: "${DB_MASTER_PASSWORD:Y4M4K1oCkL8U}"
slave: slave:
driverClassName: oracle.jdbc.OracleDriver driverClassName: oracle.jdbc.OracleDriver
url: "${DB_SLAVE_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}" url: "${DB_SLAVE_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}"
username: "${DB_SLAVE_USERNAME:QGC}" username: "${DB_SLAVE_USERNAME:QGC_REFA}"
password: "${DB_SLAVE_PASSWORD:ar6Yr7Vxo5}" password: "${DB_SLAVE_PASSWORD:Y4M4K1oCkL8U}"
mvc: mvc:
pathmatch: pathmatch: