feat: 增加出入库水温数据
This commit is contained in:
parent
831a04dc40
commit
219323e0fc
@ -1,28 +1,37 @@
|
|||||||
package com.yfd.platform.common;
|
package com.yfd.platform.common;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MicroservicDynamicSQLMapper<T> {
|
public interface MicroservicDynamicSQLMapper<T> {
|
||||||
|
@Select({"<script>", "${sql}", "</script>"})
|
||||||
|
List<Map<String, Object>> pageAllList(Page<?> page, @Param("sql") String sql, @Param("map") Map<String, Object> map);
|
||||||
|
|
||||||
@Select({"${sql}"})
|
default <R> List<R> pageAllListWithResultType(Page<?> page,
|
||||||
List<Map<String, Object>> pageAllList(Page page, String sql, @Param("map") Map<String, Object> map);
|
String sql,
|
||||||
|
Map<String, Object> map,
|
||||||
|
Class<R> resultType) {
|
||||||
|
return convertList(pageAllList(page, sql, map), resultType);
|
||||||
|
}
|
||||||
|
|
||||||
@Select({"${sql}"})
|
@Select({"<script>", "${sql}", "</script>"})
|
||||||
<resultType> List<resultType> pageAllListWithResultType(Page page, @Param("sql") String sql, @Param("map") Map<String, Object> map, @Param("resultType") Class<resultType> resultType);
|
List<Map<String, Object>> getAllList(@Param("sql") String sql, @Param("map") Map<String, Object> map);
|
||||||
|
|
||||||
@Select({"${sql}"})
|
default <R> List<R> getAllListWithResultType(String sql,
|
||||||
List<Map> getAllList(String sql, @Param("map") Map<String, Object> map);
|
Map<String, Object> map,
|
||||||
|
Class<R> resultType) {
|
||||||
@Select({"${sql}"})
|
return convertList(getAllList(sql, map), resultType);
|
||||||
<resultType> List<resultType> getAllListWithResultType(@Param("sql") String sql, @Param("map") Map<String, Object> map, @Param("resultType") Class<resultType> resultType);
|
}
|
||||||
|
|
||||||
@Select({"select count(1) count from ${sql} and ${ew.sqlSegment}"})
|
@Select({"select count(1) count from ${sql} and ${ew.sqlSegment}"})
|
||||||
Integer count(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
Integer count(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
@ -31,31 +40,36 @@ public interface MicroservicDynamicSQLMapper<T> {
|
|||||||
Integer countNoWrapper(@Param("select") String select, @Param("sql") String sql);
|
Integer countNoWrapper(@Param("select") String select, @Param("sql") String sql);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
||||||
List<Map> pageList(Page page, @Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
List<Map<String, Object>> pageList(Page<?> page, @Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
default <R> List<R> pageListWithResultType(Page<?> page,
|
||||||
<resultType> List<resultType> pageListWithResultType(Page page, @Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper, @Param("resultType") Class<resultType> resultType);
|
String select,
|
||||||
|
String sql,
|
||||||
|
QueryWrapper queryWrapper,
|
||||||
|
Class<R> resultType) {
|
||||||
|
return convertList(pageList(page, select, sql, queryWrapper), resultType);
|
||||||
|
}
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} ${ew.sqlSegment}"})
|
||||||
List<Map> pageNoFilterList(Page page, @Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
List<Map<String, Object>> pageNoFilterList(Page<?> page, @Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql}"})
|
@Select({"select ${select} from ${sql}"})
|
||||||
List<Map> pageListNoWrapper(Page page, @Param("select") String select, @Param("sql") String sql);
|
List<Map<String, Object>> pageListNoWrapper(Page<?> page, @Param("select") String select, @Param("sql") String sql);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
||||||
List<Map> getList(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
List<Map<String, Object>> getList(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
||||||
List<Map> getListWithResultType(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
List<Map<String, Object>> getListWithResultType(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
|
|
||||||
@Select({"select ${select} from ${table} where ${condition}"})
|
@Select({"select ${select} from ${table} where ${condition}"})
|
||||||
List<Map> getSingleTableList(@Param("select") String select, @Param("table") String table, @Param("condition") String condition);
|
List<Map<String, Object>> getSingleTableList(@Param("select") String select, @Param("table") String table, @Param("condition") String condition);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} ${ew.sqlSegment}"})
|
||||||
List<Map> getNoFilterList(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
List<Map<String, Object>> getNoFilterList(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql}"})
|
@Select({"select ${select} from ${sql}"})
|
||||||
List<Map> getListNoWrapper(@Param("select") String select, @Param("sql") String sql);
|
List<Map<String, Object>> getListNoWrapper(@Param("select") String select, @Param("sql") String sql);
|
||||||
|
|
||||||
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
@Select({"select ${select} from ${sql} and ${ew.sqlSegment}"})
|
||||||
Map totalSummary(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
Map totalSummary(@Param("select") String select, @Param("sql") String sql, @Param("ew") QueryWrapper queryWrapper);
|
||||||
@ -77,4 +91,29 @@ public interface MicroservicDynamicSQLMapper<T> {
|
|||||||
|
|
||||||
@Select({"select ${info} from ${joinsql} group by ${info}"})
|
@Select({"select ${info} from ${joinsql} group by ${info}"})
|
||||||
List<Object> getGroup(@Param("info") String info, @Param("joinsql") String joinsql);
|
List<Object> getGroup(@Param("info") String info, @Param("joinsql") String joinsql);
|
||||||
|
|
||||||
|
static <R> List<R> convertList(List<Map<String, Object>> sourceList, Class<R> resultType) {
|
||||||
|
List<R> resultList = new ArrayList<>();
|
||||||
|
if (sourceList == null || sourceList.isEmpty()) {
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
CopyOptions copyOptions = CopyOptions.create()
|
||||||
|
.setIgnoreCase(true)
|
||||||
|
.setIgnoreError(true);
|
||||||
|
for (Map<String, Object> row : sourceList) {
|
||||||
|
R bean = BeanUtil.fillBeanWithMap(row, createTargetBean(resultType), copyOptions);
|
||||||
|
resultList.add(bean);
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
static <R> R createTargetBean(Class<R> resultType) {
|
||||||
|
try {
|
||||||
|
Constructor<R> constructor = resultType.getDeclaredConstructor();
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
return constructor.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("动态SQL结果映射失败,目标类型必须提供无参构造器: " + resultType.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
41
backend/src/main/java/com/yfd/platform/env/controller/SdRvwtSInOutOneController.java
vendored
Normal file
41
backend/src/main/java/com/yfd/platform/env/controller/SdRvwtSInOutOneController.java
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.yfd.platform.env.controller;
|
||||||
|
|
||||||
|
import com.yfd.platform.common.DataSourceRequest;
|
||||||
|
import com.yfd.platform.config.ResponseResult;
|
||||||
|
import com.yfd.platform.env.service.SdRvwtSInOutOneService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sw/inOutOne")
|
||||||
|
@Tag(name = "出入库水温一级折线图")
|
||||||
|
@Validated
|
||||||
|
public class SdRvwtSInOutOneController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SdRvwtSInOutOneService sdRvwtSInOutOneService;
|
||||||
|
|
||||||
|
@PostMapping("/GetKendoListCust")
|
||||||
|
@Operation(summary = "查询出入库水温一级列表")
|
||||||
|
public ResponseResult getKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
|
return ResponseResult.successData(sdRvwtSInOutOneService.processKendoList(dataSourceRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/details")
|
||||||
|
@Operation(summary = "一次性返回出库水温和入库水温详情")
|
||||||
|
public ResponseResult getDetails(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
|
return ResponseResult.successData(sdRvwtSInOutOneService.getDetails(dataSourceRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/default/stcd")
|
||||||
|
@Operation(summary = "获取出入库水温默认有数据的电站")
|
||||||
|
public ResponseResult getDefaultStcd(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
|
return ResponseResult.successData(sdRvwtSInOutOneService.getDefaultStcd(dataSourceRequest));
|
||||||
|
}
|
||||||
|
}
|
||||||
56
backend/src/main/java/com/yfd/platform/env/entity/vo/SdRvwtSVO.java
vendored
Normal file
56
backend/src/main/java/com/yfd/platform/env/entity/vo/SdRvwtSVO.java
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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 SdRvwtSVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final String DWTP_IWT = "IWT";
|
||||||
|
|
||||||
|
public static final String DWTP_DWT = "DWT";
|
||||||
|
|
||||||
|
@Schema(description = "站码")
|
||||||
|
private String stcd;
|
||||||
|
|
||||||
|
@Schema(description = "站名")
|
||||||
|
private String stnm;
|
||||||
|
|
||||||
|
@Schema(description = "时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date dt;
|
||||||
|
|
||||||
|
@Schema(description = "时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date tm;
|
||||||
|
|
||||||
|
@Schema(description = "水温")
|
||||||
|
private BigDecimal wt;
|
||||||
|
|
||||||
|
@Schema(description = "类型:IWT=入库,DWT=出库")
|
||||||
|
private String dwtp;
|
||||||
|
|
||||||
|
@Schema(description = "所属电站入库水温编码")
|
||||||
|
private String engIwtCode;
|
||||||
|
|
||||||
|
@Schema(description = "所属电站出库水温编码")
|
||||||
|
private String engDwtCode;
|
||||||
|
|
||||||
|
@Schema(description = "入库水温值")
|
||||||
|
private BigDecimal iwtValue;
|
||||||
|
|
||||||
|
@Schema(description = "出库水温值")
|
||||||
|
private BigDecimal dwtValue;
|
||||||
|
}
|
||||||
21
backend/src/main/java/com/yfd/platform/env/entity/vo/StcdVo.java
vendored
Normal file
21
backend/src/main/java/com/yfd/platform/env/entity/vo/StcdVo.java
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.yfd.platform.env.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "默认电站信息")
|
||||||
|
public class StcdVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "站码")
|
||||||
|
private String stcd;
|
||||||
|
|
||||||
|
@Schema(description = "站名")
|
||||||
|
private String stnm;
|
||||||
|
}
|
||||||
60
backend/src/main/java/com/yfd/platform/env/mapper/SdRvwtSInOutOneMapper.java
vendored
Normal file
60
backend/src/main/java/com/yfd/platform/env/mapper/SdRvwtSInOutOneMapper.java
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.yfd.platform.env.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yfd.platform.env.entity.vo.SdRvwtSVO;
|
||||||
|
import com.yfd.platform.env.entity.vo.StcdVo;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SdRvwtSInOutOneMapper extends BaseMapper<SdRvwtSVO> {
|
||||||
|
|
||||||
|
@Select("SELECT STCD AS stcd, ENG_IWT_CODE AS engIwtCode, ENG_DWT_CODE AS engDwtCode " +
|
||||||
|
"FROM SD_PRWTRLTN_B " +
|
||||||
|
"WHERE IS_DELETED = 0 AND STCD = #{stcd}")
|
||||||
|
SdRvwtSVO getRelationByEngStcd(@Param("stcd") String stcd);
|
||||||
|
|
||||||
|
@Select({
|
||||||
|
"<script>",
|
||||||
|
"SELECT * FROM (",
|
||||||
|
" SELECT eng.STCD AS stcd, eng.ENNM AS stnm",
|
||||||
|
" FROM SD_ENGINFO_B_H eng",
|
||||||
|
" INNER JOIN SD_PRWTRLTN_B rel ON rel.STCD = eng.STCD AND rel.IS_DELETED = 0",
|
||||||
|
" WHERE eng.USFL = 1",
|
||||||
|
" AND eng.DTIN = 1",
|
||||||
|
" AND (rel.ENG_IWT_CODE IS NOT NULL OR rel.ENG_DWT_CODE IS NOT NULL)",
|
||||||
|
" <if test='baseIdList != null and baseIdList.size() > 0'>",
|
||||||
|
" AND eng.BASE_ID IN",
|
||||||
|
" <foreach collection='baseIdList' item='baseId' open='(' separator=',' close=')'>",
|
||||||
|
" #{baseId}",
|
||||||
|
" </foreach>",
|
||||||
|
" </if>",
|
||||||
|
" <if test='rvcdList != null and rvcdList.size() > 0'>",
|
||||||
|
" AND eng.RVCD IN",
|
||||||
|
" <foreach collection='rvcdList' item='rvcd' open='(' separator=',' close=')'>",
|
||||||
|
" #{rvcd}",
|
||||||
|
" </foreach>",
|
||||||
|
" </if>",
|
||||||
|
" AND EXISTS (",
|
||||||
|
" SELECT 1",
|
||||||
|
" FROM SD_WTRVDAY_S dayData",
|
||||||
|
" WHERE dayData.IS_DELETED = 0",
|
||||||
|
" AND (dayData.STCD = rel.ENG_IWT_CODE OR dayData.STCD = rel.ENG_DWT_CODE)",
|
||||||
|
" <if test='startTime != null and endTime != null'>",
|
||||||
|
" AND dayData.DT BETWEEN #{startTime} AND #{endTime}",
|
||||||
|
" </if>",
|
||||||
|
" )",
|
||||||
|
" ORDER BY NVL(eng.ORDER_INDEX, 999999), eng.STCD",
|
||||||
|
")",
|
||||||
|
"WHERE ROWNUM = 1",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<StcdVo> getDefaultStcd(@Param("baseIdList") List<String> baseIdList,
|
||||||
|
@Param("rvcdList") List<String> rvcdList,
|
||||||
|
@Param("startTime") Date startTime,
|
||||||
|
@Param("endTime") Date endTime);
|
||||||
|
}
|
||||||
15
backend/src/main/java/com/yfd/platform/env/service/SdRvwtSInOutOneService.java
vendored
Normal file
15
backend/src/main/java/com/yfd/platform/env/service/SdRvwtSInOutOneService.java
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.yfd.platform.env.service;
|
||||||
|
|
||||||
|
import com.yfd.platform.common.DataSourceRequest;
|
||||||
|
import com.yfd.platform.common.DataSourceResult;
|
||||||
|
import com.yfd.platform.env.entity.vo.SdRvwtSVO;
|
||||||
|
import com.yfd.platform.env.entity.vo.StcdVo;
|
||||||
|
|
||||||
|
public interface SdRvwtSInOutOneService {
|
||||||
|
|
||||||
|
DataSourceResult<SdRvwtSVO> processKendoList(DataSourceRequest dataSourceRequest);
|
||||||
|
|
||||||
|
DataSourceResult<SdRvwtSVO> getDetails(DataSourceRequest dataSourceRequest);
|
||||||
|
|
||||||
|
DataSourceResult<StcdVo> getDefaultStcd(DataSourceRequest dataSourceRequest);
|
||||||
|
}
|
||||||
338
backend/src/main/java/com/yfd/platform/env/service/impl/SdRvwtSInOutOneServiceImpl.java
vendored
Normal file
338
backend/src/main/java/com/yfd/platform/env/service/impl/SdRvwtSInOutOneServiceImpl.java
vendored
Normal file
@ -0,0 +1,338 @@
|
|||||||
|
package com.yfd.platform.env.service.impl;
|
||||||
|
|
||||||
|
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.SdRvwtSVO;
|
||||||
|
import com.yfd.platform.env.entity.vo.StcdVo;
|
||||||
|
import com.yfd.platform.env.mapper.SdRvwtSInOutOneMapper;
|
||||||
|
import com.yfd.platform.env.service.SdRvwtSInOutOneService;
|
||||||
|
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SdRvwtSInOutOneServiceImpl extends ServiceImpl<SdRvwtSInOutOneMapper, SdRvwtSVO> implements SdRvwtSInOutOneService {
|
||||||
|
|
||||||
|
private static final String TYPE_IWT = "IWT";
|
||||||
|
|
||||||
|
private static final String TYPE_DWT = "DWT";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MicroservicDynamicSQLMapper microservicDynamicSQLMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SdRvwtSInOutOneMapper sdRvwtSInOutOneMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataSourceResult<SdRvwtSVO> processKendoList(DataSourceRequest dataSourceRequest) {
|
||||||
|
return doProcessKendoList(dataSourceRequest, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataSourceResult<SdRvwtSVO> getDetails(DataSourceRequest dataSourceRequest) {
|
||||||
|
DataSourceResult<SdRvwtSVO> dwtResult = doProcessKendoList(dataSourceRequest, true, TYPE_DWT);
|
||||||
|
DataSourceResult<SdRvwtSVO> iwtResult = doProcessKendoList(dataSourceRequest, true, TYPE_IWT);
|
||||||
|
|
||||||
|
List<SdRvwtSVO> dList = dwtResult.getData() == null ? new ArrayList<>() : dwtResult.getData();
|
||||||
|
List<SdRvwtSVO> iList = iwtResult.getData() == null ? new ArrayList<>() : iwtResult.getData();
|
||||||
|
|
||||||
|
LinkedHashMap<Date, SdRvwtSVO> resultMap = new LinkedHashMap<>();
|
||||||
|
String sortField = getPrimarySortField(dataSourceRequest.getSort());
|
||||||
|
if ("dwtValue".equals(sortField)) {
|
||||||
|
mergeDetailList(resultMap, dList, TYPE_DWT);
|
||||||
|
mergeDetailList(resultMap, iList, TYPE_IWT);
|
||||||
|
} else {
|
||||||
|
mergeDetailList(resultMap, iList, TYPE_IWT);
|
||||||
|
mergeDetailList(resultMap, dList, TYPE_DWT);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SdRvwtSVO> resultList = new ArrayList<>(resultMap.values());
|
||||||
|
DataSourceResult<SdRvwtSVO> result = new DataSourceResult<>();
|
||||||
|
result.setData(resultList);
|
||||||
|
long total = dwtResult.getTotal() != 0 ? dwtResult.getTotal()
|
||||||
|
: (iwtResult.getTotal() != 0 ? iwtResult.getTotal() : resultList.size());
|
||||||
|
result.setTotal(total);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataSourceResult<StcdVo> getDefaultStcd(DataSourceRequest dataSourceRequest) {
|
||||||
|
DataSourceLoadOptionsBase loadOptions = dataSourceRequest.toDevRequest();
|
||||||
|
Date[] timeRange = parseTimeRange(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "tm"));
|
||||||
|
List<String> baseIdList = splitFilterValues(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "baseId"));
|
||||||
|
List<String> rvcdList = splitFilterValues(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "rvcd"));
|
||||||
|
|
||||||
|
List<StcdVo> resultList = sdRvwtSInOutOneMapper.getDefaultStcd(
|
||||||
|
baseIdList,
|
||||||
|
rvcdList,
|
||||||
|
timeRange[0],
|
||||||
|
timeRange[1]
|
||||||
|
);
|
||||||
|
DataSourceResult<StcdVo> result = new DataSourceResult<>();
|
||||||
|
result.setData(resultList);
|
||||||
|
result.setTotal(resultList.size());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataSourceResult<SdRvwtSVO> doProcessKendoList(DataSourceRequest dataSourceRequest,
|
||||||
|
Boolean forceDetail,
|
||||||
|
String forceType) {
|
||||||
|
DataSourceLoadOptionsBase loadOptions = dataSourceRequest.toDevRequest();
|
||||||
|
String engStcd = normalizeFilterValue(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "stcd"));
|
||||||
|
String relationStcd = firstNotBlank(
|
||||||
|
engStcd,
|
||||||
|
normalizeFilterValue(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "engIwtCode")),
|
||||||
|
normalizeFilterValue(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "engDwtCode"))
|
||||||
|
);
|
||||||
|
String url = normalizeFilterValue(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "url"));
|
||||||
|
boolean isDetail = forceDetail != null ? forceDetail : "details".equals(url);
|
||||||
|
|
||||||
|
String tableName = isDetail ? "SD_WTRV_R" : "SD_WTRVDAY_S";
|
||||||
|
String timeColumn = isDetail ? "SWS.TM" : "SWS.DT";
|
||||||
|
Date[] timeRange = parseTimeRange(resolveTimeFilterValue(loadOptions));
|
||||||
|
List<String> baseIdList = splitFilterValues(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "baseId"));
|
||||||
|
List<String> rvcdList = splitFilterValues(QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "rvcd"));
|
||||||
|
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
sql.append("SELECT SWT.STCD AS stcd, ")
|
||||||
|
.append("SWT.STNM AS stnm, ")
|
||||||
|
.append(timeColumn).append(" AS tm, ")
|
||||||
|
.append(timeColumn).append(" AS dt, ")
|
||||||
|
.append("SWS.WT AS wt, ")
|
||||||
|
.append("REL.ENG_IWT_CODE AS engIwtCode, ")
|
||||||
|
.append("REL.ENG_DWT_CODE AS engDwtCode ")
|
||||||
|
.append("FROM (")
|
||||||
|
.append(" SELECT SPR.STCD, SPR.ENG_IWT_CODE, SPR.ENG_DWT_CODE ")
|
||||||
|
.append(" FROM SD_PRWTRLTN_B SPR ")
|
||||||
|
.append(" WHERE SPR.IS_DELETED = 0 ");
|
||||||
|
|
||||||
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
if (StrUtil.isNotBlank(relationStcd)) {
|
||||||
|
paramMap.put("relationStcd", relationStcd);
|
||||||
|
sql.append(" AND SPR.STCD = #{map.relationStcd} ");
|
||||||
|
}
|
||||||
|
sql.append(") REL ")
|
||||||
|
.append("INNER JOIN SD_ENGINFO_B_H SEG ON SEG.STCD = REL.STCD ")
|
||||||
|
.append("INNER JOIN ").append(tableName).append(" SWS ON SWS.STCD IN (REL.ENG_IWT_CODE, REL.ENG_DWT_CODE) ")
|
||||||
|
.append("INNER JOIN SD_WT_B_H SWT ON SWT.STCD = SWS.STCD ")
|
||||||
|
.append("WHERE SWS.IS_DELETED = 0 ")
|
||||||
|
.append("AND SWT.IS_DELETED = 0 ")
|
||||||
|
.append("AND SWT.USFL = 1 ")
|
||||||
|
.append("AND SWT.MWAY = 2 ")
|
||||||
|
.append("AND SWT.STTP = 'WTRV' ")
|
||||||
|
.append("AND SEG.USFL = 1 ");
|
||||||
|
if (timeRange[0] != null && timeRange[1] != null) {
|
||||||
|
paramMap.put("startTime", timeRange[0]);
|
||||||
|
paramMap.put("endTime", timeRange[1]);
|
||||||
|
sql.append("AND ").append(timeColumn).append(" >= #{map.startTime} ")
|
||||||
|
.append("AND ").append(timeColumn).append(" <= #{map.endTime} ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDetail) {
|
||||||
|
appendDetailCondition(sql, forceType);
|
||||||
|
} else {
|
||||||
|
appendInCondition(sql, paramMap, "SEG.BASE_ID", "baseId", baseIdList);
|
||||||
|
appendInCondition(sql, paramMap, "SEG.RVCD", "rvcd", rvcdList);
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.append(buildOrderBySql(dataSourceRequest.getSort(), timeColumn));
|
||||||
|
Page<?> page = buildPage(loadOptions);
|
||||||
|
List<SdRvwtSVO> resultList = microservicDynamicSQLMapper.pageAllListWithResultType(page, sql.toString(), paramMap, SdRvwtSVO.class);
|
||||||
|
|
||||||
|
if (!isDetail) {
|
||||||
|
fillDwtp(resultList);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSourceResult<SdRvwtSVO> result = new DataSourceResult<>();
|
||||||
|
result.setData(resultList);
|
||||||
|
result.setTotal(ObjectUtil.isNotEmpty(page) ? page.getTotal() : resultList.size());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendDetailCondition(StringBuilder sql, String forceType) {
|
||||||
|
if (TYPE_IWT.equals(forceType)) {
|
||||||
|
sql.append("AND SWT.STCD = REL.ENG_IWT_CODE ");
|
||||||
|
} else if (TYPE_DWT.equals(forceType)) {
|
||||||
|
sql.append("AND SWT.STCD = REL.ENG_DWT_CODE ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillDwtp(List<SdRvwtSVO> voList) {
|
||||||
|
for (SdRvwtSVO vo : voList) {
|
||||||
|
if (StrUtil.isNotBlank(vo.getStcd())
|
||||||
|
&& StrUtil.isNotBlank(vo.getEngIwtCode())
|
||||||
|
&& vo.getStcd().equals(vo.getEngIwtCode())) {
|
||||||
|
vo.setDwtp(SdRvwtSVO.DWTP_IWT);
|
||||||
|
} else if (StrUtil.isNotBlank(vo.getStcd())
|
||||||
|
&& StrUtil.isNotBlank(vo.getEngDwtCode())
|
||||||
|
&& vo.getStcd().equals(vo.getEngDwtCode())) {
|
||||||
|
vo.setDwtp(SdRvwtSVO.DWTP_DWT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeDetailList(LinkedHashMap<Date, SdRvwtSVO> resultMap, List<SdRvwtSVO> sourceList, String type) {
|
||||||
|
for (SdRvwtSVO source : sourceList) {
|
||||||
|
Date key = source.getTm();
|
||||||
|
SdRvwtSVO target = resultMap.computeIfAbsent(key, item -> {
|
||||||
|
SdRvwtSVO vo = new SdRvwtSVO();
|
||||||
|
vo.setDt(item);
|
||||||
|
vo.setTm(item);
|
||||||
|
return vo;
|
||||||
|
});
|
||||||
|
if (TYPE_IWT.equals(type)) {
|
||||||
|
target.setIwtValue(source.getWt());
|
||||||
|
} else if (TYPE_DWT.equals(type)) {
|
||||||
|
target.setDwtValue(source.getWt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Page<?> buildPage(DataSourceLoadOptionsBase loadOptions) {
|
||||||
|
PageInfo pageInfo = QgcQueryWrapperUtil.getPageInfo(loadOptions);
|
||||||
|
if (Boolean.TRUE.equals(pageInfo.getHasPageInfo())) {
|
||||||
|
return pageInfo.getPage();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildOrderBySql(List<DataSourceRequest.SortDescriptor> sortList, String timeColumn) {
|
||||||
|
List<String> orderColumns = new ArrayList<>();
|
||||||
|
if (sortList != null) {
|
||||||
|
for (DataSourceRequest.SortDescriptor sortDescriptor : sortList) {
|
||||||
|
String field = sortDescriptor.getField();
|
||||||
|
String dir = "desc".equalsIgnoreCase(sortDescriptor.getDir()) ? "DESC" : "ASC";
|
||||||
|
if ("tm".equals(field) || "dt".equals(field)) {
|
||||||
|
orderColumns.add(timeColumn + " " + dir);
|
||||||
|
} else if ("wt".equals(field) || "iwtValue".equals(field) || "dwtValue".equals(field)) {
|
||||||
|
orderColumns.add("SWS.WT " + dir);
|
||||||
|
} else if ("stcd".equals(field)) {
|
||||||
|
orderColumns.add("SWS.STCD " + dir);
|
||||||
|
} else if ("stnm".equals(field)) {
|
||||||
|
orderColumns.add("SWT.STNM " + dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (orderColumns.isEmpty()) {
|
||||||
|
return " ORDER BY tm ASC";
|
||||||
|
}
|
||||||
|
return " ORDER BY " + String.join(", ", orderColumns);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPrimarySortField(List<DataSourceRequest.SortDescriptor> sortList) {
|
||||||
|
if (sortList == null || sortList.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return sortList.get(0).getField();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SdRvwtSVO> pagingMemoryList(List<SdRvwtSVO> sourceList, DataSourceRequest dataSourceRequest) {
|
||||||
|
int skip = Math.max(dataSourceRequest.getSkip(), 0);
|
||||||
|
int take = dataSourceRequest.getTake();
|
||||||
|
if (take <= 0) {
|
||||||
|
return sourceList;
|
||||||
|
}
|
||||||
|
if (skip >= sourceList.size()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
int end = Math.min(skip + take, sourceList.size());
|
||||||
|
return new ArrayList<>(sourceList.subList(skip, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendInCondition(StringBuilder sql,
|
||||||
|
Map<String, Object> paramMap,
|
||||||
|
String columnName,
|
||||||
|
String keyPrefix,
|
||||||
|
List<String> valueList) {
|
||||||
|
if (valueList == null || valueList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sql.append("AND ").append(columnName).append(" IN (");
|
||||||
|
for (int i = 0; i < valueList.size(); i++) {
|
||||||
|
String key = keyPrefix + i;
|
||||||
|
paramMap.put(key, valueList.get(i));
|
||||||
|
if (i > 0) {
|
||||||
|
sql.append(", ");
|
||||||
|
}
|
||||||
|
sql.append("#{map.").append(key).append("}");
|
||||||
|
}
|
||||||
|
sql.append(") ");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> splitFilterValues(String value) {
|
||||||
|
String filterValue = normalizeFilterValue(value);
|
||||||
|
List<String> resultList = new ArrayList<>();
|
||||||
|
if (StrUtil.isBlank(filterValue)) {
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
String[] values = filterValue.split(",");
|
||||||
|
for (String item : values) {
|
||||||
|
String valueItem = item == null ? null : item.trim();
|
||||||
|
if (StrUtil.isNotBlank(valueItem) && !resultList.contains(valueItem)) {
|
||||||
|
resultList.add(valueItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeFilterValue(String value) {
|
||||||
|
if (StrUtil.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return value.replace("[", "")
|
||||||
|
.replace("]", "")
|
||||||
|
.replace("\"", "")
|
||||||
|
.replace("'", "")
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date[] parseTimeRange(String timeValue) {
|
||||||
|
String filterValue = normalizeFilterValue(timeValue);
|
||||||
|
if (StrUtil.isBlank(filterValue)) {
|
||||||
|
return new Date[]{null, null};
|
||||||
|
}
|
||||||
|
String[] values = filterValue.split(",");
|
||||||
|
if (values.length == 0) {
|
||||||
|
return new Date[]{null, null};
|
||||||
|
}
|
||||||
|
Date startTime = DateUtil.parse(values[0].trim());
|
||||||
|
Date endTime = values.length > 1 ? DateUtil.parse(values[1].trim()) : startTime;
|
||||||
|
if (startTime.after(endTime)) {
|
||||||
|
Date temp = startTime;
|
||||||
|
startTime = endTime;
|
||||||
|
endTime = temp;
|
||||||
|
}
|
||||||
|
return new Date[]{startTime, endTime};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveTimeFilterValue(DataSourceLoadOptionsBase loadOptions) {
|
||||||
|
String timeValue = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "tm");
|
||||||
|
if (StrUtil.isBlank(normalizeFilterValue(timeValue))) {
|
||||||
|
timeValue = QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "dt");
|
||||||
|
}
|
||||||
|
return timeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNotBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (StrUtil.isNotBlank(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user