11 changed files with 374 additions and 131 deletions
@ -0,0 +1,35 @@ |
|||
package com.kms.yg.cz.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.kms.yg.cz.dto.MonitorQueDto; |
|||
import com.kms.yg.cz.service.MonitorService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.AllArgsConstructor; |
|||
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; |
|||
|
|||
|
|||
/** |
|||
* 监测信息Controller |
|||
* |
|||
* @author kms |
|||
* @date 2024-04-24 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/cz/monitor") |
|||
@AllArgsConstructor |
|||
@Api(tags = "监测信息") |
|||
public class MonitorController { |
|||
|
|||
private final MonitorService monitorService; |
|||
|
|||
|
|||
@PostMapping("/page") |
|||
@ApiOperation("分页查询监测信息") |
|||
public <T> IPage<T> page(@RequestBody MonitorQueDto sp) { |
|||
return monitorService.pageQuery(sp); |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.kms.yg.cz.dto; |
|||
|
|||
import com.alibaba.fastjson.annotation.JSONField; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.kms.yg.cz.enmu.MonitorEnum; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@ApiModel("监测信息请求参数") |
|||
public class MonitorQueDto { |
|||
|
|||
@NotNull(message = "监测类型不能为空") |
|||
@ApiModelProperty(value = "监测类型", required = true, allowableValues = "MS_HDM_RSVR,MS_HDM_OBP,MS_HDM_RIVER,MS_DSM_SRVRDS,MS_DSM_SRHRDS") |
|||
private MonitorEnum monitorType; |
|||
|
|||
@JSONField(name = "STCD") |
|||
@ApiModelProperty(value = "测站编码") |
|||
private String stcd; |
|||
@ApiModelProperty(value = "测站名称") |
|||
@JSONField(name = "MPCD") |
|||
private String mpcd; |
|||
|
|||
@JSONField(name = "START_TIME", format = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|||
@NotNull(message = "开始时间不能为空") |
|||
@ApiModelProperty(value = "开始时间", required = true) |
|||
private Date startTime; |
|||
|
|||
@JSONField(name = "END_TIME", format = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|||
@NotNull(message = "结束时间不能为空") |
|||
@ApiModelProperty(value = "结束时间", required = true) |
|||
private Date endTime; |
|||
|
|||
@ApiModelProperty(value = "页码") |
|||
private Integer pageSize = 10; |
|||
@ApiModelProperty(value = "每页条数") |
|||
private Integer pageNum = 1; |
|||
} |
@ -0,0 +1,110 @@ |
|||
package com.kms.yg.cz.enmu; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.TypeReference; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.google.common.base.Strings; |
|||
import com.kms.yg.cz.dto.MonitorQueDto; |
|||
import lombok.Data; |
|||
import lombok.Getter; |
|||
|
|||
import java.util.List; |
|||
import java.util.function.Function; |
|||
|
|||
/** |
|||
* 基础数据同步服务枚举 |
|||
* |
|||
* @author hry |
|||
* @date 2024/3/4 18:57 |
|||
*/ |
|||
@Getter |
|||
public enum MonitorEnum { |
|||
|
|||
MS_HDM_RSVR("水库水情监测表"), |
|||
MS_HDM_OBP("降水量监测表"), |
|||
MS_HDM_RIVER("河道水情监测表"), |
|||
MS_DSM_SRVRDS("表面垂直位移监测表"), |
|||
MS_DSM_SRHRDS("表面水平位移监测表"), |
|||
; |
|||
|
|||
private final String name; |
|||
private final MonitorTypeEnum type; |
|||
|
|||
|
|||
MonitorEnum(String name) { |
|||
this(name, MonitorTypeEnum.MONITOR); |
|||
} |
|||
|
|||
MonitorEnum(String name, MonitorTypeEnum type) { |
|||
this.name = name; |
|||
this.type = type; |
|||
} |
|||
|
|||
|
|||
public String getTableName() { |
|||
return this.name().toLowerCase(); |
|||
} |
|||
|
|||
public <T> Function<ResultWrapper, IPage<T>> getRecords() { |
|||
return resultWrapper -> { |
|||
String json = resultWrapper.getResultJson(); |
|||
if (this.type == null || Strings.isNullOrEmpty(json)) { |
|||
return new Page<>(); |
|||
} |
|||
if (this.type == MonitorTypeEnum.MONITOR) { |
|||
MonitorResponse<List<T>> response = JSON.parseObject(json, new TypeReference<MonitorResponse<List<T>>>() { |
|||
}); |
|||
DataInfo dataInfo = response.getData(); |
|||
Page<T> page = new Page<>(dataInfo.getCurrent(), dataInfo.getSize(), dataInfo.getTotal()); |
|||
page.setRecords(response.getRecords()); |
|||
return page; |
|||
} else { |
|||
DataResponse<List<T>> response = JSON.parseObject(json, new TypeReference<DataResponse<List<T>>>() { |
|||
}); |
|||
MonitorQueDto queDto = resultWrapper.getQueDto(); |
|||
Page<T> page = new Page<>(queDto.getPageNum(), queDto.getPageSize()); |
|||
page.setRecords(response.getData()); |
|||
return page; |
|||
} |
|||
}; |
|||
} |
|||
|
|||
@Data |
|||
public static class ResultWrapper { |
|||
private String resultJson; |
|||
private MonitorQueDto queDto; |
|||
} |
|||
|
|||
@Data |
|||
public static class MonitorResponse<R> extends DataResponse<DataInfo> { |
|||
private R records; |
|||
} |
|||
|
|||
@Data |
|||
public static class DataResponse<T> { |
|||
private String msg; |
|||
private String code; |
|||
private T data; |
|||
} |
|||
|
|||
@Data |
|||
public static class DataInfo { |
|||
private Integer current; |
|||
private Integer size; |
|||
private Integer total; |
|||
private Integer pages; |
|||
} |
|||
|
|||
@Getter |
|||
public enum MonitorTypeEnum { |
|||
MONITOR, |
|||
DATA |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "表[" + this.getName() + "](" + this.name + ")"; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.kms.yg.cz.service; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.kms.yg.cz.dto.MonitorQueDto; |
|||
import com.kms.yg.cz.enmu.MonitorEnum; |
|||
import com.kms.yxgh.util.DataCenterRestTemplateUtils; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.function.Function; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class MonitorService { |
|||
|
|||
@Autowired |
|||
private DataCenterRestTemplateUtils dataCenterRestTemplateUtils; |
|||
|
|||
@Value("${dataSync.url:}") |
|||
private String dataSyncUrl; |
|||
@Value("#{${dataSync.paths:{}}}") |
|||
private Map<String, String> paths = new HashMap<>(); |
|||
|
|||
|
|||
public <T> IPage<T> pageQuery(MonitorQueDto queDto) { |
|||
MonitorEnum table = queDto.getMonitorType(); |
|||
String path = paths.get(table.getTableName()); |
|||
if (path == null) { |
|||
log.error("未找到对应的路径配置, table:{}", table); |
|||
return new Page<>(); |
|||
} |
|||
String json = dataCenterRestTemplateUtils.doPostRequest(dataSyncUrl + path, queDto); |
|||
MonitorEnum.ResultWrapper resultWrapper = new MonitorEnum.ResultWrapper(); |
|||
resultWrapper.setResultJson(json); |
|||
resultWrapper.setQueDto(queDto); |
|||
Function<MonitorEnum.ResultWrapper, IPage<T>> function = table.getRecords(); |
|||
return function.apply(resultWrapper); |
|||
} |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue