[add]处理水量功能新增

This commit is contained in:
chengjunwang 2025-05-06 12:44:08 +08:00
parent fe7bc58857
commit 3018fc4494
8 changed files with 328 additions and 0 deletions

View File

@ -0,0 +1,56 @@
package com.jdc.jdcproject.controller;
import com.jdc.jdcproject.entity.DicekePrecipitation;
import com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord;
import com.jdc.jdcproject.entity.VO.FangpaishuiWatertreatmentrecordVo;
import com.jdc.jdcproject.service.FangpaishuiWatertreatmentrecordService;
import com.jdc.jdcproject.utils.LastDayOfMonth;
import com.jdc.jdcproject.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/fangpaishuiWatertreatmentrecord")
public class FangpaishuiWatertreatmentrecordController {
@Autowired
private FangpaishuiWatertreatmentrecordService fangpaishuiWatertreatmentrecordService;
@Operation(summary = "根据月查询处理水量和拉泥车数")
@GetMapping("findWatertreatmentrecordByMonth/{dateTime}")
public Result findWatertreatmentrecordByMonth(@PathVariable String dateTime) throws ParseException {
String[] s = dateTime.split("-");
int year = Integer.parseInt(s[0]);
int month = Integer.parseInt(s[1]);
LastDayOfMonth lastDayOfMonth = new LastDayOfMonth();
String upDay = lastDayOfMonth.getLastDayOfMonth(year, month-1);
String lastDay = lastDayOfMonth.getLastDayOfMonth(year, month);
upDay = lastDayOfMonth.dateCalculations(upDay,5);
lastDay = lastDayOfMonth.dateCalculations(lastDay,6);
List<FangpaishuiWatertreatmentrecord> fangpaishuiWatertreatmentrecords =fangpaishuiWatertreatmentrecordService.findByDate(upDay,lastDay);
int waterVolume = 0;
int TruckCount = 0;
for (int i = 0; i < fangpaishuiWatertreatmentrecords.size(); i++) {
TruckCount = fangpaishuiWatertreatmentrecords.get(i).getTruckCount()+TruckCount;
waterVolume = fangpaishuiWatertreatmentrecords.get(i).getWaterVolume()+waterVolume;
}
FangpaishuiWatertreatmentrecordVo fangpaishuiWatertreatmentrecordVo = new FangpaishuiWatertreatmentrecordVo();
fangpaishuiWatertreatmentrecordVo.setWaterVolume(waterVolume);
fangpaishuiWatertreatmentrecordVo.setTruckCount(TruckCount);
fangpaishuiWatertreatmentrecordVo.setMonthRange(upDay+""+lastDay);
return Result.successResult().data("fangpaishuiWatertreatmentrecordVo",fangpaishuiWatertreatmentrecordVo);
}
}

View File

@ -0,0 +1,88 @@
package com.jdc.jdcproject.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDate;
import lombok.Data;
/**
* 处理水量记录表;
* @TableName fangpaishui_watertreatmentrecord
*/
@TableName(value ="fangpaishui_watertreatmentrecord")
@Data
public class FangpaishuiWatertreatmentrecord implements Serializable {
/**
* 主键唯一标识记录
*/
@TableId(value = "TreatmentID", type = IdType.AUTO)
private Integer treatmentID;
/**
* 处理水量单位立方米
*/
@TableField(value = "WaterVolume")
private Integer waterVolume;
/**
* 拉泥车数单位
*/
@TableField(value = "TruckCount")
private Integer truckCount;
/**
* 月份格式YYYY-MM
*/
@TableField(value = "MonthValue")
private LocalDate monthValue;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
FangpaishuiWatertreatmentrecord other = (FangpaishuiWatertreatmentrecord) that;
return (this.getTreatmentID() == null ? other.getTreatmentID() == null : this.getTreatmentID().equals(other.getTreatmentID()))
&& (this.getWaterVolume() == null ? other.getWaterVolume() == null : this.getWaterVolume().equals(other.getWaterVolume()))
&& (this.getTruckCount() == null ? other.getTruckCount() == null : this.getTruckCount().equals(other.getTruckCount()))
&& (this.getMonthValue() == null ? other.getMonthValue() == null : this.getMonthValue().equals(other.getMonthValue()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getTreatmentID() == null) ? 0 : getTreatmentID().hashCode());
result = prime * result + ((getWaterVolume() == null) ? 0 : getWaterVolume().hashCode());
result = prime * result + ((getTruckCount() == null) ? 0 : getTruckCount().hashCode());
result = prime * result + ((getMonthValue() == null) ? 0 : getMonthValue().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", treatmentID=").append(treatmentID);
sb.append(", waterVolume=").append(waterVolume);
sb.append(", truckCount=").append(truckCount);
sb.append(", monthValue=").append(monthValue);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@ -0,0 +1,54 @@
package com.jdc.jdcproject.entity.VO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDate;
/**
* 处理水量记录表;
* @TableName fangpaishui_watertreatmentrecord
*/
@TableName(value ="fangpaishui_watertreatmentrecord")
@Data
public class FangpaishuiWatertreatmentrecordVo implements Serializable {
/**
* 主键唯一标识记录
*/
@Schema(description = "主键")
@TableId("treatmentID")
private Integer treatmentID;
/**
* 处理水量单位立方米
*/
@Schema(description = "处理水量")
private Integer waterVolume;
/**
* 拉泥车数单位
*/
@Schema(description = "拉泥车数")
private Integer truckCount;
/**
* 月份格式YYYY-MM
*/
@Schema(description = "月份")
private LocalDate monthValue;
/**
* 月份范围
*/
@Schema(description = "月份范围")
private String monthRange;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,24 @@
package com.jdc.jdcproject.mapper;
import com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author 95262
* @description 针对表fangpaishui_watertreatmentrecord(处理水量记录表;)的数据库操作Mapper
* @createDate 2025-05-05 00:18:35
* @Entity com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord
*/
@Mapper
public interface FangpaishuiWatertreatmentrecordMapper extends BaseMapper<FangpaishuiWatertreatmentrecord> {
List<FangpaishuiWatertreatmentrecord> findByDate(@Param("upDate") String upDate,@Param("lastDate")String lastDate);
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jdc.jdcproject.mapper.FangpaishuiWatertreatmentrecordMapper">
<select id="findByDate" resultType="com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord">
SELECT
* FROM fangpaishui_watertreatmentrecord
WHERE
MonthValue BETWEEN '${upDate}' AND '${lastDate}'
</select>
</mapper>

View File

@ -0,0 +1,16 @@
package com.jdc.jdcproject.service;
import com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jdc.jdcproject.entity.VO.DicekeMininglossVo;
import java.util.List;
/**
* @author 95262
* @description 针对表fangpaishui_watertreatmentrecord(处理水量记录表;)的数据库操作Service
* @createDate 2025-05-05 00:18:35
*/
public interface FangpaishuiWatertreatmentrecordService extends IService<FangpaishuiWatertreatmentrecord> {
List<FangpaishuiWatertreatmentrecord> findByDate(String upDate,String lastDate);
}

View File

@ -0,0 +1,28 @@
package com.jdc.jdcproject.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdc.jdcproject.entity.FangpaishuiWatertreatmentrecord;
import com.jdc.jdcproject.service.FangpaishuiWatertreatmentrecordService;
import com.jdc.jdcproject.mapper.FangpaishuiWatertreatmentrecordMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author 95262
* @description 针对表fangpaishui_watertreatmentrecord(处理水量记录表;)的数据库操作Service实现
* @createDate 2025-05-05 00:18:35
*/
@Service
public class FangpaishuiWatertreatmentrecordServiceImpl extends ServiceImpl<FangpaishuiWatertreatmentrecordMapper, FangpaishuiWatertreatmentrecord>
implements FangpaishuiWatertreatmentrecordService{
@Override
public List<FangpaishuiWatertreatmentrecord> findByDate(String upDate,String lastDate) {
return baseMapper.findByDate(upDate,lastDate);
}
}

View File

@ -0,0 +1,48 @@
package com.jdc.jdcproject.utils;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class LastDayOfMonth
{
/**
* 获取某月的最后一天
*
*/
public final String getLastDayOfMonth(int year,int month)
{
Calendar cal = Calendar.getInstance();
//设置年份
cal.set(Calendar.YEAR,year);
//设置月份
cal.set(Calendar.MONTH, month);
//获取当月最小值
int lastDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
//设置日历中的月份当月+1月-1天=当月最后一天
cal.set(Calendar.DAY_OF_MONTH, lastDay-1);
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String lastDayOfMonth = sdf.format(cal.getTime());
return lastDayOfMonth;
}
//截取最后一个-后的值并计算后拼接
public final String dateCalculations(String date,int index) {
String n1 = StringUtils.substringAfterLast(date, "-");//截取最后-后面的数字
int i = n1.length();
if ("".equals(n1)) {
n1 = "0";
}
//截取后的值-index
int nums = Integer.parseInt(n1)-index ;
//转字符串
String newNum = String.valueOf(nums);
i = Math.min(i, newNum.length());
return date.subSequence(0, date.length() - i) + newNum;
}
}