parent
3a795a41e5
commit
e55130b543
|
|
@ -1,6 +1,7 @@
|
||||||
package com.gunshi.project.ss.controller;
|
package com.gunshi.project.ss.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.gunshi.core.annotation.Get;
|
||||||
import com.gunshi.core.result.R;
|
import com.gunshi.core.result.R;
|
||||||
import com.gunshi.project.ss.entity.so.DocCenterPageSo;
|
import com.gunshi.project.ss.entity.so.DocCenterPageSo;
|
||||||
import com.gunshi.project.ss.model.DocCenter;
|
import com.gunshi.project.ss.model.DocCenter;
|
||||||
|
|
@ -29,6 +30,11 @@ public class DocCenterController extends AbstractCommonFileController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileAssociationsService fileService;
|
private FileAssociationsService fileService;
|
||||||
|
|
||||||
|
@Operation(description = "获取最新的档案")
|
||||||
|
@GetMapping("/latestDoc/{docCategoryId}")
|
||||||
|
public R<List<DocCenter>> latestDocCenter(@PathVariable("docCategoryId") Long docCategoryId) {
|
||||||
|
return R.ok(docCenterService.latestDocCenter(docCategoryId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(description = "分页查询")
|
@Operation(description = "分页查询")
|
||||||
|
|
@ -38,7 +44,7 @@ public class DocCenterController extends AbstractCommonFileController {
|
||||||
List<DocCenter> records = res.getRecords();
|
List<DocCenter> records = res.getRecords();
|
||||||
if(!records.isEmpty()){
|
if(!records.isEmpty()){
|
||||||
for (DocCenter record : records) {
|
for (DocCenter record : records) {
|
||||||
List<FileAssociations> files = fileService.getFiles(record.getBusinessName(), record.getId().toString());
|
List<FileAssociations> files = fileService.getFiles2(record.getBusinessName(), record.getId().toString());
|
||||||
record.setFiles(files);
|
record.setFiles(files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,16 +53,16 @@ public class DocCenterController extends AbstractCommonFileController {
|
||||||
|
|
||||||
@Operation(description = "新增")
|
@Operation(description = "新增")
|
||||||
@PostMapping("/insert")
|
@PostMapping("/insert")
|
||||||
public DocCenter insert(@RequestBody DocCenter docCenter){
|
public R<DocCenter> insert(@RequestBody DocCenter docCenter){
|
||||||
boolean flag = docCenterService.saveData(docCenter);
|
boolean flag = docCenterService.saveData(docCenter);
|
||||||
if(flag){
|
if(flag){
|
||||||
fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
||||||
}
|
}
|
||||||
return docCenter;
|
return R.ok(docCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(description = "删除")
|
@Operation(description = "删除")
|
||||||
@GetMapping("/delete/{id}")
|
@GetMapping("/del/{id}")
|
||||||
public R<Boolean> delete(@PathVariable("id") Integer id){
|
public R<Boolean> delete(@PathVariable("id") Integer id){
|
||||||
DocCenter center = docCenterService.deleteById(id);
|
DocCenter center = docCenterService.deleteById(id);
|
||||||
if(center != null){
|
if(center != null){
|
||||||
|
|
@ -68,12 +74,12 @@ public class DocCenterController extends AbstractCommonFileController {
|
||||||
|
|
||||||
@Operation(description = "修改")
|
@Operation(description = "修改")
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
public DocCenter edit(@RequestBody DocCenter docCenter){
|
public R<DocCenter> edit(@RequestBody DocCenter docCenter){
|
||||||
boolean flag = docCenterService.updateData(docCenter);
|
boolean flag = docCenterService.updateData(docCenter);
|
||||||
if(flag){
|
if(flag){
|
||||||
fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
||||||
}
|
}
|
||||||
return docCenter;
|
return R.ok(docCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.gunshi.project.ss.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.gunshi.core.result.R;
|
||||||
|
import com.gunshi.project.ss.model.ResPlanB;
|
||||||
|
import com.gunshi.project.ss.model.RotaB;
|
||||||
|
import com.gunshi.project.ss.service.FileAssociationsService;
|
||||||
|
import com.gunshi.project.ss.service.ResPlanBService;
|
||||||
|
import com.gunshi.project.ss.service.ScreenPlanService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Tag(name = "大屏-预案")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value="/screen/plan")
|
||||||
|
public class ScreenPlanController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScreenPlanService screenPlanService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileAssociationsService fileService;
|
||||||
|
|
||||||
|
@GetMapping("/rota")
|
||||||
|
public R<Map<String,List<RotaB>>> query() {
|
||||||
|
Map<String,List<RotaB>> res = screenPlanService.query();
|
||||||
|
return R.ok(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/doc")
|
||||||
|
public R<List<ResPlanB>> list(){
|
||||||
|
List<ResPlanB> list = screenPlanService.list();
|
||||||
|
if(!list.isEmpty()){
|
||||||
|
list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),String.valueOf( o.getId()))));
|
||||||
|
}
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId() {
|
||||||
|
return "ResPlanB";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import com.gunshi.core.result.R;
|
||||||
import com.gunshi.project.ss.common.model.StFlowR;
|
import com.gunshi.project.ss.common.model.StFlowR;
|
||||||
import com.gunshi.project.ss.entity.dto.StFlowDataCheckDto;
|
import com.gunshi.project.ss.entity.dto.StFlowDataCheckDto;
|
||||||
import com.gunshi.project.ss.entity.vo.StFlowLowerDataCheckVo;
|
import com.gunshi.project.ss.entity.vo.StFlowLowerDataCheckVo;
|
||||||
|
import com.gunshi.project.ss.entity.vo.StFlowRLatestVo;
|
||||||
import com.gunshi.project.ss.entity.vo.StFlowRListVo;
|
import com.gunshi.project.ss.entity.vo.StFlowRListVo;
|
||||||
import com.gunshi.project.ss.service.StFlowRService;
|
import com.gunshi.project.ss.service.StFlowRService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
@ -35,8 +36,8 @@ public class StFlowRController {
|
||||||
|
|
||||||
@Operation(description = "查询最新数据")
|
@Operation(description = "查询最新数据")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<List<StFlowRListVo>> list(){
|
public R<List<StFlowRLatestVo>> list(){
|
||||||
List<StFlowRListVo> res = service.listLatestData();
|
List<StFlowRLatestVo> res = service.listLatestData();
|
||||||
return R.ok(res);
|
return R.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.gunshi.project.ss.entity.vo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StFlowRLatestVo {
|
||||||
|
/**
|
||||||
|
* 近24h平均流量
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private BigDecimal avg24Q;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 近24h变幅
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private BigDecimal change24Q;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 近24小时累计水量单位万m³
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private BigDecimal total24V;
|
||||||
|
|
||||||
|
|
||||||
|
private String stnm;
|
||||||
|
|
||||||
|
private String stcd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 瞬时流量,单位m³/s
|
||||||
|
*/
|
||||||
|
private BigDecimal q;
|
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime tm;
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,28 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.gunshi.project.ss.model.DocCategory;
|
import com.gunshi.project.ss.model.DocCategory;
|
||||||
import com.gunshi.project.ss.model.DocCenter;
|
import com.gunshi.project.ss.model.DocCenter;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DocCenterMapper extends BaseMapper<DocCenter> {
|
public interface DocCenterMapper extends BaseMapper<DocCenter> {
|
||||||
|
|
||||||
|
|
||||||
|
@Select("""
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT *,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY group_id
|
||||||
|
ORDER BY doc_number DESC
|
||||||
|
) AS rn
|
||||||
|
FROM doc_center
|
||||||
|
WHERE doc_category_id = #{docCategoryId}
|
||||||
|
) AS ranked
|
||||||
|
WHERE rn = 1;
|
||||||
|
""")
|
||||||
|
List<DocCenter> latestDocCenter(@Param("docCategoryId") Long docCategoryId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
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.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
|
@ -34,4 +35,5 @@ public interface RotaBMapper extends BaseMapper<RotaB> {
|
||||||
</script>
|
</script>
|
||||||
""")
|
""")
|
||||||
Long queryUser(@Param("value") String value);
|
Long queryUser(@Param("value") String value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -29,19 +29,23 @@ public class DocCenter {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@TableField("doc_name")
|
@TableField("doc_name")
|
||||||
@NotNull(message = "档案名称不能为空", groups = {Insert.class, Update.class})
|
|
||||||
@Schema(description = "档案名称")
|
@Schema(description = "档案名称")
|
||||||
private String docName;
|
private String docName;
|
||||||
|
|
||||||
@TableField("replace_id")
|
@TableField("replace_id")
|
||||||
@NotNull(message = "替换档案id不能为空", groups = {Insert.class, Update.class})
|
|
||||||
@Schema(description = "替换档案id")
|
@Schema(description = "替换档案id")
|
||||||
private Long replaceId;
|
private Long replaceId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "替换档案名称")
|
||||||
|
private String replaceName;
|
||||||
|
|
||||||
@TableField("doc_category_id")
|
@TableField("doc_category_id")
|
||||||
@Schema(description = "资料类别id")
|
@Schema(description = "资料类别id")
|
||||||
private Long docCategoryId;
|
private Long docCategoryId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@TableField("group_id")
|
@TableField("group_id")
|
||||||
@Schema(description = "组id - 用于替换档案时")
|
@Schema(description = "组id - 用于替换档案时")
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
|
@ -89,7 +93,7 @@ public class DocCenter {
|
||||||
@TableField("make_time")
|
@TableField("make_time")
|
||||||
@Schema(description = "编制时间")
|
@Schema(description = "编制时间")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
private LocalDateTime makeTime;
|
private LocalDate makeTime;
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
@Schema(description = "归档人名称")
|
@Schema(description = "归档人名称")
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,17 @@ public class DocCenterService extends ServiceImpl<DocCenterMapper, DocCenter> {
|
||||||
}
|
}
|
||||||
categoryCodes.add(record.getDocNumber());
|
categoryCodes.add(record.getDocNumber());
|
||||||
record.setCategoryCodes(categoryCodes);
|
record.setCategoryCodes(categoryCodes);
|
||||||
|
//根据资料中心id查询数据
|
||||||
|
DocCategory docCategory = docCategoryService.getBaseMapper().selectById(record.getDocCategoryId());
|
||||||
|
if(docCategory != null){
|
||||||
|
record.setCategoryName(docCategory.getCategoryName());
|
||||||
|
}
|
||||||
|
if(record.getReplaceId() != null){
|
||||||
|
DocCenter replaceDocCenter = lambdaQuery().eq(DocCenter::getId, record.getReplaceId()).last("limit 1").one();
|
||||||
|
if(replaceDocCenter != null){
|
||||||
|
record.setReplaceName(replaceDocCenter.getDocName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return docCenterPage;
|
return docCenterPage;
|
||||||
}
|
}
|
||||||
|
|
@ -76,10 +87,18 @@ public class DocCenterService extends ServiceImpl<DocCenterMapper, DocCenter> {
|
||||||
if(StringUtils.isBlank(docCenter.getBusinessName())){
|
if(StringUtils.isBlank(docCenter.getBusinessName())){
|
||||||
throw new IllegalArgumentException("请传业务名称");
|
throw new IllegalArgumentException("请传业务名称");
|
||||||
}
|
}
|
||||||
Long count = lambdaQuery().eq(DocCenter::getDocCategoryId, docCenter.getDocCategoryId()).count();
|
Long latestDocNumberLong;
|
||||||
count++;
|
DocCenter theLastDocNumber = lambdaQuery().eq(DocCenter::getDocCategoryId, docCenter.getDocCategoryId()).orderByDesc(DocCenter::getDocNumber).last("limit 1").one();
|
||||||
|
if(theLastDocNumber != null){
|
||||||
|
String docNumber = theLastDocNumber.getDocNumber();
|
||||||
|
latestDocNumberLong = Long.valueOf(docNumber);
|
||||||
|
latestDocNumberLong++;
|
||||||
|
}else{
|
||||||
|
latestDocNumberLong = 1l;
|
||||||
|
}
|
||||||
|
|
||||||
// 将 count 转换为字符串,前面补0,保持至少4位数字
|
// 将 count 转换为字符串,前面补0,保持至少4位数字
|
||||||
String countStr = String.format("%04d", count);
|
String countStr = String.format("%04d", latestDocNumberLong);
|
||||||
docCenter.setDocNumber(countStr);
|
docCenter.setDocNumber(countStr);
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
docCenter.setCreateTime(now);
|
docCenter.setCreateTime(now);
|
||||||
|
|
@ -331,4 +350,29 @@ public class DocCenterService extends ServiceImpl<DocCenterMapper, DocCenter> {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DocCenter> latestDocCenter(Long docCategoryId) {
|
||||||
|
List<DocCenter> docCenters = this.baseMapper.latestDocCenter(docCategoryId);
|
||||||
|
for (DocCenter record : docCenters) {
|
||||||
|
if(record.getUserId() != null){
|
||||||
|
SysUser sysUser = sysUserMapper.selectUserById(record.getUserId());
|
||||||
|
if(sysUser != null){
|
||||||
|
record.setUserName(sysUser.getNickName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<DocCategory> categoryPathRecursive = docCategoryService.findCategoryPathRecursive(record.getDocCategoryId());
|
||||||
|
List<String> categoryCodes = new ArrayList<>();
|
||||||
|
for (DocCategory docCategory : categoryPathRecursive) {
|
||||||
|
categoryCodes.add(docCategory.getCategoryCode());
|
||||||
|
}
|
||||||
|
categoryCodes.add(record.getDocNumber());
|
||||||
|
record.setCategoryCodes(categoryCodes);
|
||||||
|
//根据资料中心id查询数据
|
||||||
|
DocCategory docCategory = docCategoryService.getBaseMapper().selectById(record.getDocCategoryId());
|
||||||
|
if(docCategory != null){
|
||||||
|
record.setCategoryName(docCategory.getCategoryName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return docCenters;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,8 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,4 +98,13 @@ public class RotaService extends ServiceImpl<RotaBMapper, RotaB> {
|
||||||
}
|
}
|
||||||
this.saveOrUpdateBatch(list);
|
this.saveOrUpdateBatch(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String,List<RotaB>> queryByDateRange(LocalDate now, LocalDate nextDay) {
|
||||||
|
Map<String,List<RotaB>> res = new HashMap<>();
|
||||||
|
List<RotaB> today = this.baseMapper.dateList(now.toString());
|
||||||
|
res.put("today",today);
|
||||||
|
List<RotaB> next = this.baseMapper.dateList(nextDay.toString());
|
||||||
|
res.put("nextDay",next);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.gunshi.project.ss.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.gunshi.core.result.R;
|
||||||
|
import com.gunshi.project.ss.model.ResPlanB;
|
||||||
|
import com.gunshi.project.ss.model.RotaB;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ScreenPlanService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RotaService rotaService;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ResPlanBService resPlanBService;
|
||||||
|
|
||||||
|
public Map<String,List<RotaB>> query() {
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
LocalDate nextDay = now.plusDays(1);
|
||||||
|
return rotaService.queryByDateRange(now,nextDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResPlanB> list() {
|
||||||
|
List<ResPlanB> list = resPlanBService.lambdaQuery().eq(ResPlanB::getIsAvailable, 1).list();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import com.gunshi.project.ss.common.model.StFlowR;
|
||||||
import com.gunshi.project.ss.common.model.StStbprpB;
|
import com.gunshi.project.ss.common.model.StStbprpB;
|
||||||
import com.gunshi.project.ss.entity.dto.StFlowDataCheckDto;
|
import com.gunshi.project.ss.entity.dto.StFlowDataCheckDto;
|
||||||
import com.gunshi.project.ss.entity.vo.StFlowLowerDataCheckVo;
|
import com.gunshi.project.ss.entity.vo.StFlowLowerDataCheckVo;
|
||||||
|
import com.gunshi.project.ss.entity.vo.StFlowRLatestVo;
|
||||||
import com.gunshi.project.ss.entity.vo.StFlowRListVo;
|
import com.gunshi.project.ss.entity.vo.StFlowRListVo;
|
||||||
import com.gunshi.project.ss.entity.vo.StFlowRVo;
|
import com.gunshi.project.ss.entity.vo.StFlowRVo;
|
||||||
import com.gunshi.project.ss.mapper.StFlowRVoMapper;
|
import com.gunshi.project.ss.mapper.StFlowRVoMapper;
|
||||||
|
|
@ -63,47 +64,100 @@ public class StFlowRService extends ServiceImpl<StFlowRMapper, StFlowR> {
|
||||||
return voMapper.getDataByStcdAndTm(stcd, tm);
|
return voMapper.getDataByStcdAndTm(stcd, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StFlowRListVo> listLatestData() {
|
public List<StFlowRLatestVo> listLatestData() {
|
||||||
List<StFlowRListVo> res = new ArrayList<>();
|
List<StFlowRLatestVo> res = new ArrayList<>();
|
||||||
List<StStbprpB> flowStations = stStbprpBService.getFlowStations();
|
List<StStbprpB> flowStations = stStbprpBService.getFlowStations();
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
LocalDateTime lastDay = now.minusDays(1);
|
LocalDateTime yesterday = now.minusDays(1);
|
||||||
|
|
||||||
for (StStbprpB flowStation : flowStations) {
|
for (StStbprpB flowStation : flowStations) {
|
||||||
StFlowRListVo stFlowR = new StFlowRListVo();
|
StFlowRLatestVo vo = new StFlowRLatestVo();
|
||||||
stFlowR.setStcd(flowStation.getStcd());
|
vo.setStcd(flowStation.getStcd());
|
||||||
stFlowR.setStnm(flowStation.getStnm());
|
vo.setStnm(flowStation.getStnm());
|
||||||
stFlowR.setLgtd(flowStation.getLgtd());
|
|
||||||
stFlowR.setLttd(flowStation.getLttd());
|
|
||||||
// 获取24小时内的所有流量数据
|
|
||||||
List<StFlowR> list = lambdaQuery()
|
List<StFlowR> list = lambdaQuery()
|
||||||
.eq(StFlowR::getStcd, flowStation.getStcd())
|
.eq(StFlowR::getStcd, vo.getStcd())
|
||||||
.ge(StFlowR::getTm, lastDay)
|
.ge(StFlowR::getTm, yesterday)
|
||||||
.le(StFlowR::getTm, now)
|
.le(StFlowR::getTm, now)
|
||||||
.orderByAsc(StFlowR::getTm) // 按时间升序排列,方便计算
|
.orderByAsc(StFlowR::getTm)
|
||||||
.list();
|
.list();
|
||||||
|
|
||||||
if(list.isEmpty()){
|
if (!list.isEmpty()) {
|
||||||
res.add(stFlowR);
|
// 初始化统计变量(每个站点独立)
|
||||||
continue;
|
BigDecimal total24V = BigDecimal.ZERO;
|
||||||
|
BigDecimal sum24Q = BigDecimal.ZERO;
|
||||||
|
BigDecimal min24Q = null;
|
||||||
|
BigDecimal max24Q = null;
|
||||||
|
int validCount = 0; // 有效数据点数
|
||||||
|
|
||||||
|
// 用于记录上一个有效数据点
|
||||||
|
StFlowR previousValid = null;
|
||||||
|
vo.setQ(list.getLast().getQ());
|
||||||
|
vo.setTm(list.getLast().getTm());
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
StFlowR current = list.get(i);
|
||||||
|
BigDecimal currentQ = current.getQ();
|
||||||
|
|
||||||
|
// 跳过流量为null的数据点
|
||||||
|
if (currentQ == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计有效数据
|
||||||
|
validCount++;
|
||||||
|
sum24Q = sum24Q.add(currentQ);
|
||||||
|
|
||||||
|
// 更新最小最大流量
|
||||||
|
if (min24Q == null || currentQ.compareTo(min24Q) < 0) {
|
||||||
|
min24Q = currentQ;
|
||||||
|
}
|
||||||
|
if (max24Q == null || currentQ.compareTo(max24Q) > 0) {
|
||||||
|
max24Q = currentQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算水量(需要与前一个有效数据点计算)
|
||||||
|
if (previousValid != null && previousValid.getQ() != null) {
|
||||||
|
// 计算时间间隔(秒)
|
||||||
|
long seconds = ChronoUnit.SECONDS.between(previousValid.getTm(), current.getTm());
|
||||||
|
if (seconds > 0) { // 确保时间间隔为正
|
||||||
|
// 使用前一个时间的流量计算水量
|
||||||
|
BigDecimal previousFlow = previousValid.getQ();
|
||||||
|
// 水量 = 流量 × 时间间隔(m³/s × s = m³,再除以10000转换为万m³)
|
||||||
|
BigDecimal waterVolume = previousFlow
|
||||||
|
.multiply(BigDecimal.valueOf(seconds)) // m³
|
||||||
|
.divide(BigDecimal.valueOf(10000), 10, RoundingMode.HALF_UP); // 万m³
|
||||||
|
total24V = total24V.add(waterVolume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新上一个有效数据点
|
||||||
|
previousValid = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置统计结果
|
||||||
|
vo.setTotal24V(total24V.setScale(4, RoundingMode.HALF_UP));
|
||||||
|
|
||||||
|
// 计算24h平均流量
|
||||||
|
if (validCount > 0) {
|
||||||
|
BigDecimal avg24Q = sum24Q.divide(BigDecimal.valueOf(validCount), 4, RoundingMode.HALF_UP);
|
||||||
|
vo.setAvg24Q(avg24Q);
|
||||||
|
} else {
|
||||||
|
vo.setAvg24Q(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算24h变幅流量(最大流量 - 最小流量)
|
||||||
|
if (min24Q != null && max24Q != null) {
|
||||||
|
BigDecimal change24Q = max24Q.subtract(min24Q);
|
||||||
|
vo.setChange24Q(change24Q.setScale(4, RoundingMode.HALF_UP));
|
||||||
|
} else {
|
||||||
|
vo.setChange24Q(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置最新时间点的数据
|
res.add(vo);
|
||||||
StFlowR latestData = list.get(list.size() - 1);
|
|
||||||
stFlowR.setTm(latestData.getTm());
|
|
||||||
stFlowR.setQ(latestData.getQ());
|
|
||||||
//判断状态
|
|
||||||
LocalDateTime tm = latestData.getTm();
|
|
||||||
Duration between = Duration.between(tm, now);
|
|
||||||
if(between.toHours() > 24){
|
|
||||||
stFlowR.setStatus(0);
|
|
||||||
}else{
|
|
||||||
stFlowR.setStatus(1);
|
|
||||||
}
|
|
||||||
// 计算统计值
|
|
||||||
|
|
||||||
res.add(stFlowR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue