2024-07-08 17:47:02 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
2024-07-25 15:04:01 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2024-07-25 15:04:01 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
2024-07-25 15:04:01 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.gunshi.project.xyt.entity.so.GateHisPageSo;
|
2024-07-25 15:04:01 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.AttResBaseVo;
|
2024-07-22 11:31:08 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.GateStautsVo;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.GateValveOplogVo;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.project.xyt.mapper.GateValveRealMapper;
|
2024-07-25 15:04:01 +08:00
|
|
|
import com.gunshi.project.xyt.mapper.StWaterRRealMapper;
|
|
|
|
|
import com.gunshi.project.xyt.mapper.TyYearRainfallMapper;
|
|
|
|
|
import com.gunshi.project.xyt.model.*;
|
|
|
|
|
import com.gunshi.project.xyt.util.DataHandleUtil;
|
2024-07-22 11:31:08 +08:00
|
|
|
import com.gunshi.project.xyt.util.DateUtil;
|
2024-07-24 14:57:10 +08:00
|
|
|
import com.gunshi.project.xyt.util.ExcelUtil;
|
2024-07-23 15:25:02 +08:00
|
|
|
import jakarta.annotation.Resource;
|
2024-07-24 14:57:10 +08:00
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
2024-07-08 17:47:02 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2024-07-22 15:44:35 +08:00
|
|
|
import java.math.BigDecimal;
|
2024-07-25 15:04:01 +08:00
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.*;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 闸阀开关表
|
|
|
|
|
* author: xusan
|
|
|
|
|
* date: 2024-07-08 17:30:37
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class GateValveRealService extends ServiceImpl<GateValveRealMapper, GateValveReal>
|
|
|
|
|
{
|
2024-07-23 15:25:02 +08:00
|
|
|
@Resource
|
2024-07-25 15:07:09 +08:00
|
|
|
private com.gunshi.project.xyt.model.GateValveKeyAutoDao gateValveKeyAutoDao;
|
2024-07-23 15:25:02 +08:00
|
|
|
|
2024-07-24 14:57:10 +08:00
|
|
|
@Resource
|
2024-07-25 15:07:09 +08:00
|
|
|
private com.gunshi.project.xyt.model.GateValveOplogAutoDao gateValveOplogAutoDao;
|
2024-07-24 14:57:10 +08:00
|
|
|
|
2024-07-23 15:25:02 +08:00
|
|
|
@Resource
|
2024-07-25 15:04:01 +08:00
|
|
|
private ReservoirWaterService reservoirWaterService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private StWaterRRealMapper stWaterRRealMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private TyYearRainfallMapper tyYearRainfallMapper;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
2024-07-22 11:31:08 +08:00
|
|
|
public List<GateStautsVo> gateStatusList() {
|
|
|
|
|
List<GateStautsVo> list = baseMapper.gateStatusList();
|
|
|
|
|
for(GateStautsVo vo : list){
|
|
|
|
|
if(vo.getTm() != null && DateUtil.hoursBetweenDate(vo.getTm(), new Date()) > 2){
|
|
|
|
|
vo.setFlag(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-07-22 15:44:35 +08:00
|
|
|
|
|
|
|
|
public BigDecimal realQ(String valveCode) {
|
|
|
|
|
return baseMapper.realQ(valveCode);
|
|
|
|
|
}
|
2024-07-23 15:25:02 +08:00
|
|
|
|
|
|
|
|
public String control(GateValveKey gateValveKey) {
|
|
|
|
|
//先判断密码是否正确
|
|
|
|
|
String valveCode = gateValveKey.getValveCode();
|
|
|
|
|
String key = gateValveKey.getKey();
|
|
|
|
|
GateValveKey valveKey = gateValveKeyAutoDao.getById(valveCode);
|
|
|
|
|
if(valveKey == null || !key.equals(valveKey.getKey())){
|
|
|
|
|
throw new IllegalArgumentException("密码不正确");
|
|
|
|
|
}
|
2024-07-24 14:57:10 +08:00
|
|
|
//生成闸阀操作日志
|
|
|
|
|
GateValveOplog oplog = new GateValveOplog();
|
|
|
|
|
oplog.setId(IdWorker.getId());
|
|
|
|
|
oplog.setStatus(gateValveKey.getStatus());
|
|
|
|
|
oplog.setOpContent("设置闸阀开度为"+gateValveKey.getStatus());
|
|
|
|
|
oplog.setValveCode(valveCode);
|
|
|
|
|
oplog.setTm(new Date());
|
|
|
|
|
oplog.setOpUserId(1L);
|
|
|
|
|
oplog.setOpUserName("胡兵");
|
|
|
|
|
|
|
|
|
|
GateValveReal valveReal = this.getOne(new QueryWrapper<GateValveReal>().eq("valve_code", valveCode));
|
|
|
|
|
oplog.setBeforeStatus(valveReal == null ? "-" : valveReal.getStatus());
|
|
|
|
|
gateValveOplogAutoDao.save(oplog);
|
2024-07-24 09:11:20 +08:00
|
|
|
//todo 给闸阀下发调节指令
|
|
|
|
|
// GateValveR gateValveR = new GateValveR();
|
|
|
|
|
// BeanUtils.copyProperties(gateValveKey,gateValveR);
|
|
|
|
|
// gateValveR.setTm(new Date());
|
|
|
|
|
// gateValveRMapper.insert(gateValveR);
|
|
|
|
|
//
|
|
|
|
|
// GateValveReal real = new GateValveReal();
|
|
|
|
|
// BeanUtils.copyProperties(gateValveKey,real);
|
|
|
|
|
// real.setTm(new Date());
|
|
|
|
|
// this.remove(new QueryWrapper<GateValveReal>().eq("valve_code",valveCode));
|
|
|
|
|
// this.save(real);
|
2024-07-24 14:57:10 +08:00
|
|
|
return "调节闸阀成功";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<GateValveOplogVo> logPage(GateHisPageSo so) {
|
|
|
|
|
return baseMapper.logPage(so.getPageSo().toPage(),so);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void logExport(GateHisPageSo so, HttpServletResponse response) {
|
|
|
|
|
List<GateValveOplogVo> logList = baseMapper.logList(so);
|
|
|
|
|
ExcelUtil.exportExcel(logList,"闸阀操作日志",GateValveOplogVo.class,response,"闸阀操作日志");
|
2024-07-23 15:25:02 +08:00
|
|
|
}
|
2024-07-25 15:04:01 +08:00
|
|
|
|
|
|
|
|
public Map<BigDecimal, String> supplyTime(Integer year, Integer month) {
|
|
|
|
|
Map<BigDecimal, String> map = new HashMap<>();
|
|
|
|
|
/**
|
|
|
|
|
* 可供水量= 实时库容 - 死库容
|
|
|
|
|
* 小时水量= (输水管流量 + 放水管流量)*3600
|
2024-07-29 13:23:23 +08:00
|
|
|
* 可供水小时数 = 可供水量 * 10000/ 小时水量
|
2024-07-25 15:04:01 +08:00
|
|
|
* 可供水天数 = 可供水小时数换算为天数
|
|
|
|
|
*/
|
|
|
|
|
List<AttResBaseVo> list = reservoirWaterService.list();
|
|
|
|
|
if(CollectionUtils.isEmpty(list)){
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
AttResBaseVo attResBaseVo = list.get(0);
|
|
|
|
|
BigDecimal nowCap = attResBaseVo.getNowCap() == null ? new BigDecimal(0) : attResBaseVo.getNowCap();
|
|
|
|
|
BigDecimal deadCap = attResBaseVo.getDeadCap();
|
|
|
|
|
|
|
|
|
|
BigDecimal supplyV = nowCap.subtract(deadCap);
|
|
|
|
|
if(year != null){
|
|
|
|
|
//计算预测来水量
|
|
|
|
|
BigDecimal predictV = calcPredictV(year,month,attResBaseVo.getWatShedArea());
|
|
|
|
|
supplyV = supplyV.add(predictV);
|
|
|
|
|
}
|
|
|
|
|
List<StWaterRReal> water = stWaterRRealMapper.listRelated();
|
|
|
|
|
//小时水量
|
|
|
|
|
BigDecimal hourQ = water.stream().map(StWaterRReal::getQ).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(3600));
|
|
|
|
|
BigDecimal day = supplyV.multiply(new BigDecimal(10000)).divide(hourQ.multiply(new BigDecimal(24)),1, RoundingMode.HALF_UP);
|
|
|
|
|
long l = DataHandleUtil.BigDecimalIntegerPart(day);
|
|
|
|
|
String date = DateUtil.getPlusDate(new Date(), l);
|
|
|
|
|
map.put(day,date);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal calcPredictV(Integer year, Integer month,BigDecimal watShedArea) {
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
Integer nowMonth = now.getMonthValue();
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<TyYearRainfall> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
queryWrapper.eq(TyYearRainfall::getYear,year)
|
|
|
|
|
.eq(TyYearRainfall::getType,2)
|
|
|
|
|
.ge(TyYearRainfall::getMonth,nowMonth)
|
|
|
|
|
.le(TyYearRainfall::getMonth,month);
|
|
|
|
|
List<TyYearRainfall> list = tyYearRainfallMapper.selectList(queryWrapper);
|
|
|
|
|
|
|
|
|
|
//和当前月份相同的降雨量
|
|
|
|
|
Optional<TyYearRainfall> first = list.stream().filter(o -> nowMonth == o.getMonth()).findFirst();
|
|
|
|
|
BigDecimal drp = first.isPresent() ? first.get().getDrp() : new BigDecimal(0);
|
|
|
|
|
int dayOfMonth = now.getDayOfMonth();
|
|
|
|
|
int total = now.lengthOfMonth();
|
|
|
|
|
BigDecimal nowMonthDrp = new BigDecimal((total - dayOfMonth + 1)).multiply(drp).divide(new BigDecimal(total), 2, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
//当前月到预测月份的降雨量
|
|
|
|
|
BigDecimal value = list.stream().filter(o -> nowMonth != o.getMonth()).map(TyYearRainfall::getDrp).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
|
|
|
//预测来水量 = 月降雨量和 * 水库坝址控制流域面积
|
|
|
|
|
BigDecimal sum = nowMonthDrp.add(value);
|
|
|
|
|
return sum.multiply(watShedArea);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|