parent
a6322dc9ea
commit
09a3c924c7
43 changed files with 2050 additions and 411 deletions
@ -0,0 +1,76 @@ |
|||||||
|
package org.springblade.desk.energy.controller; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
import jakarta.validation.Valid; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyCoreUseEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyCoreUseVO; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyCoreUseService; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyHistoryRecService; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录 控制器 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/bsEnergyCoreUse") |
||||||
|
@Tag(name = "水电能耗记录", description = "水电能耗记录接口") |
||||||
|
public class BsEnergyCoreUseController extends BladeController { |
||||||
|
|
||||||
|
private final IBsEnergyCoreUseService bsEnergyCoreUseService; |
||||||
|
|
||||||
|
private final IBsEnergyHistoryRecService bsEnergyHistoryRecService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录 自定义分页 |
||||||
|
*/ |
||||||
|
@GetMapping("/page") |
||||||
|
@Operation(summary = "分页", description = "传入bsEnergyQuota") |
||||||
|
public R<IPage<BsEnergyCoreUseVO>> page(BsEnergyCoreUseVO bsEnergyCoreUse, Query query) { |
||||||
|
IPage<BsEnergyCoreUseVO> pages = bsEnergyCoreUseService.selectBsEnergyCoreUsePage(Condition.getPage(query), bsEnergyCoreUse); |
||||||
|
return R.data(pages); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 能源定额 新增或修改 |
||||||
|
*/ |
||||||
|
@PostMapping("/updateIsJumbotron") |
||||||
|
@Operation(summary = "新增或修改", description = "传入bsEnergyQuota") |
||||||
|
public R updateIsJumbotron(@Valid @RequestBody BsEnergyCoreUseEntity bsEnergyCoreUse) { |
||||||
|
if (bsEnergyCoreUse.getId() == null || bsEnergyCoreUse.getIsJumbotron() == null) { |
||||||
|
R.fail("修改失败"); |
||||||
|
} |
||||||
|
BsEnergyCoreUseEntity upd = new BsEnergyCoreUseEntity(); |
||||||
|
upd.setId(bsEnergyCoreUse.getId()); |
||||||
|
upd.setIsJumbotron(bsEnergyCoreUse.getIsJumbotron()); |
||||||
|
return R.status(bsEnergyCoreUseService.updateById(upd)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/detail") |
||||||
|
@Operation(summary = "详情", description = "传入bsEnergyQuota") |
||||||
|
public R<List<BsEnergyHistoryRecVO>> detail(BsEnergyCoreUseEntity bsEnergyCoreUse) { |
||||||
|
BsEnergyCoreUseEntity bsEnergyCoreUseEntity = bsEnergyCoreUseService.getById(bsEnergyCoreUse.getId()); |
||||||
|
if (bsEnergyCoreUseEntity == null) { |
||||||
|
R.fail("明细查询失败"); |
||||||
|
} |
||||||
|
BsEnergyHistoryRecVO params = new BsEnergyHistoryRecVO(); |
||||||
|
params.setCreateTime(bsEnergyCoreUseEntity.getCreateTime()); |
||||||
|
List<BsEnergyHistoryRecVO> list = bsEnergyHistoryRecService.selectBsEnergyHistoryRec(params); |
||||||
|
return R.data(list); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
package org.springblade.desk.energy.excel; |
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnore; |
||||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||||
|
import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
@Data |
||||||
|
@ColumnWidth(25) |
||||||
|
@HeadRowHeight(20) |
||||||
|
@ContentRowHeight(18) |
||||||
|
public class BsEnergyQuotaElectricExcel implements Serializable { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 作业中心 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("作业中心") |
||||||
|
private String workCenterName; |
||||||
|
/** |
||||||
|
* 作业中心编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("作业中心编码") |
||||||
|
private String wcCode; |
||||||
|
/** |
||||||
|
* 设备 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("设备") |
||||||
|
private String equipmentName; |
||||||
|
/** |
||||||
|
* 设备编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("设备") |
||||||
|
private String deviceCode; |
||||||
|
/** |
||||||
|
* 日期 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("日期") |
||||||
|
private String date; |
||||||
|
/** |
||||||
|
* 用电量 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("定额单位面积用电量(kWh/dm²)") |
||||||
|
private BigDecimal electricNum; |
||||||
|
} |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
package org.springblade.desk.energy.excel; |
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnore; |
||||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||||
|
import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
@Data |
||||||
|
@ColumnWidth(25) |
||||||
|
@HeadRowHeight(20) |
||||||
|
@ContentRowHeight(18) |
||||||
|
public class BsEnergyQuotaElectricImportExcel implements Serializable { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 作业中心编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("作业中心编码") |
||||||
|
private String wcCode; |
||||||
|
/** |
||||||
|
* 设备编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("设备编码") |
||||||
|
private String deviceCode; |
||||||
|
/** |
||||||
|
* 日期 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("日期") |
||||||
|
private String date; |
||||||
|
/** |
||||||
|
* 用电量 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("定额单位面积用电量(kWh/dm²)") |
||||||
|
private BigDecimal electricNum; |
||||||
|
} |
||||||
@ -0,0 +1,92 @@ |
|||||||
|
/** |
||||||
|
* BladeX Commercial License Agreement |
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p> |
||||||
|
* Use of this software is governed by the Commercial License Agreement |
||||||
|
* obtained after purchasing a license from BladeX. |
||||||
|
* <p> |
||||||
|
* 1. This software is for development use only under a valid license |
||||||
|
* from BladeX. |
||||||
|
* <p> |
||||||
|
* 2. Redistribution of this software's source code to any third party |
||||||
|
* without a commercial license is strictly prohibited. |
||||||
|
* <p> |
||||||
|
* 3. Licensees may copyright their own code but cannot use segments |
||||||
|
* from this software for such purposes. Copyright of this software |
||||||
|
* remains with BladeX. |
||||||
|
* <p> |
||||||
|
* Using this software signifies agreement to this License, and the software |
||||||
|
* must not be used for illegal purposes. |
||||||
|
* <p> |
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is |
||||||
|
* not liable for any claims arising from secondary or illegal development. |
||||||
|
* <p> |
||||||
|
* Author: Chill Zhuang (bladejava@qq.com) |
||||||
|
*/ |
||||||
|
package org.springblade.desk.energy.excel; |
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnore; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||||
|
import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.io.Serial; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 能源定额 Excel实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-03-02 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ColumnWidth(25) |
||||||
|
@HeadRowHeight(20) |
||||||
|
@ContentRowHeight(18) |
||||||
|
public class BsEnergyQuotaWaterImportExcel implements Serializable { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 作业中心编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("作业中心编码") |
||||||
|
private String wcCode; |
||||||
|
/** |
||||||
|
* 设备编码 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("设备编码") |
||||||
|
private String deviceCode; |
||||||
|
/** |
||||||
|
* 日期 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("日期") |
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd") |
||||||
|
private String date; |
||||||
|
/** |
||||||
|
* 自来水用水量 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("自来水用水量(L/dm²)") |
||||||
|
private BigDecimal tapWaterNum; |
||||||
|
/** |
||||||
|
* 纯水用水量 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("纯水用水量(L/dm²)") |
||||||
|
private BigDecimal pureWaterNum; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,71 @@ |
|||||||
|
/** |
||||||
|
* BladeX Commercial License Agreement |
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p> |
||||||
|
* Use of this software is governed by the Commercial License Agreement |
||||||
|
* obtained after purchasing a license from BladeX. |
||||||
|
* <p> |
||||||
|
* 1. This software is for development use only under a valid license |
||||||
|
* from BladeX. |
||||||
|
* <p> |
||||||
|
* 2. Redistribution of this software's source code to any third party |
||||||
|
* without a commercial license is strictly prohibited. |
||||||
|
* <p> |
||||||
|
* 3. Licensees may copyright their own code but cannot use segments |
||||||
|
* from this software for such purposes. Copyright of this software |
||||||
|
* remains with BladeX. |
||||||
|
* <p> |
||||||
|
* Using this software signifies agreement to this License, and the software |
||||||
|
* must not be used for illegal purposes. |
||||||
|
* <p> |
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is |
||||||
|
* not liable for any claims arising from secondary or illegal development. |
||||||
|
* <p> |
||||||
|
* Author: Chill Zhuang (bladejava@qq.com) |
||||||
|
*/ |
||||||
|
package org.springblade.desk.energy.excel; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||||
|
import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.io.Serial; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 能耗目标表 Excel实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-03-02 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ColumnWidth(25) |
||||||
|
@HeadRowHeight(20) |
||||||
|
@ContentRowHeight(18) |
||||||
|
public class BsEnergyTargetWaterExcel implements Serializable { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 年份 |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("年份") |
||||||
|
private String year; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用水目标(L/d㎡) |
||||||
|
*/ |
||||||
|
@ColumnWidth(50) |
||||||
|
@ExcelProperty("用水目标(L/d㎡)") |
||||||
|
private BigDecimal target; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
package org.springblade.desk.energy.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyCoreUseEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyCoreUseVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 Mapper 接口 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-16 |
||||||
|
*/ |
||||||
|
public interface BsEnergyCoreUseMapper extends BaseMapper<BsEnergyCoreUseEntity> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page 分页参数 |
||||||
|
* @param bsEnergyCoreUse 查询参数 |
||||||
|
* @return List<BsEnergyCoreUseVO> |
||||||
|
*/ |
||||||
|
List<BsEnergyCoreUseVO> selectBsEnergyCoreUsePage(IPage<BsEnergyCoreUseVO> page, BsEnergyCoreUseVO bsEnergyCoreUse); |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
package org.springblade.desk.energy.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyHistoryRecEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* iot水电能耗历史记录表 Mapper 接口 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
public interface BsEnergyHistoryRecMapper extends BaseMapper<BsEnergyHistoryRecEntity> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page 分页参数 |
||||||
|
* @param bsEnergyHistoryRec 查询参数 |
||||||
|
* @return List<BsEnergyHistoryRecVO> |
||||||
|
*/ |
||||||
|
List<BsEnergyHistoryRecVO> selectBsEnergyHistoryRecPage(IPage<BsEnergyHistoryRecVO> page, BsEnergyHistoryRecVO bsEnergyHistoryRec); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义查询 |
||||||
|
* |
||||||
|
* @param bsEnergyHistoryRec 查询参数 |
||||||
|
* @return List<BsEnergyHistoryRecVO> |
||||||
|
*/ |
||||||
|
List<BsEnergyHistoryRecVO> selectBsEnergyHistoryRec(BsEnergyHistoryRecVO bsEnergyHistoryRec); |
||||||
|
} |
||||||
@ -0,0 +1,59 @@ |
|||||||
|
<?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="org.springblade.desk.energy.mapper.BsEnergyCoreUseMapper"> |
||||||
|
<!-- 通用查询映射结果 --> |
||||||
|
<resultMap id="bsEnergyCoreUseResultMap" type="org.springblade.desk.energy.pojo.vo.BsEnergyCoreUseVO"> |
||||||
|
<result column="ID" property="id"/> |
||||||
|
<result column="TYPE" property="type"/> |
||||||
|
<result column="WORK_CENTER_ID" property="workCenterId"/> |
||||||
|
<result column="WORK_CENTER_NAME" property="workCenterName"/> |
||||||
|
<result column="START_TIME" property="startTime"/> |
||||||
|
<result column="END_TIME" property="endTime"/> |
||||||
|
<result column="WORK_AREA" property="workArea"/> |
||||||
|
<result column="QUO_TAP_WATER_NUM" property="quoTapWaterNum"/> |
||||||
|
<result column="REAL_TAP_WATER_NUM" property="realTapWaterNum"/> |
||||||
|
<result column="TOTAL_TAP_WATER_NUM" property="totalTapWaterNum"/> |
||||||
|
<result column="QUO_PURE_WATER_NUM" property="quoPureWaterNum"/> |
||||||
|
<result column="REAL_PURE_WATER_NUM" property="realPureWaterNum"/> |
||||||
|
<result column="TOTAL_PURE_WATER_NUM" property="totalPureWaterNum"/> |
||||||
|
<result column="QUO_ELECTRIC_NUM" property="quoElectricNum"/> |
||||||
|
<result column="REAL_ELECTRIC_NUM" property="realElectricNum"/> |
||||||
|
<result column="TOTAL_ELECTRIC_NUM" property="totalElectricNum"/> |
||||||
|
<result column="IS_JUMBOTRON" property="isJumbotron"/> |
||||||
|
<result column="CREATE_USER" property="createUser"/> |
||||||
|
<result column="CREATE_DEPT" property="createDept"/> |
||||||
|
<result column="CREATE_TIME" property="createTime"/> |
||||||
|
<result column="UPDATE_USER" property="updateUser"/> |
||||||
|
<result column="UPDATE_TIME" property="updateTime"/> |
||||||
|
<result column="STATUS" property="status"/> |
||||||
|
<result column="IS_DELETED" property="isDeleted"/> |
||||||
|
<result column="DATE" property="date"/> |
||||||
|
</resultMap> |
||||||
|
|
||||||
|
<select id="selectBsEnergyCoreUsePage" resultMap="bsEnergyCoreUseResultMap"> |
||||||
|
select t.*, TO_CHAR(t.CREATE_TIME, 'yyyy-mm-dd') as "date" |
||||||
|
from BS_ENERGY_CORE_USE t |
||||||
|
<where> |
||||||
|
t.is_deleted = 0 |
||||||
|
<if test="bsEnergyCoreUse.type!=null"> |
||||||
|
and t.type = #{bsEnergyCoreUse.type} |
||||||
|
</if> |
||||||
|
<if test="bsEnergyCoreUse.startDate!=null"> |
||||||
|
and TRUNC(t.CREATE_TIME) <![CDATA[ >= ]]> TO_DATE(#{bsEnergyCoreUse.startDate},'yyyy-mm-dd') |
||||||
|
</if> |
||||||
|
<if test="bsEnergyCoreUse.endDate!=null"> |
||||||
|
and TRUNC(t.CREATE_TIME) <![CDATA[ <= ]]> TO_DATE(#{bsEnergyCoreUse.endDate},'yyyy-mm-dd') |
||||||
|
</if> |
||||||
|
<if test="bsEnergyCoreUse.workCenterId!=null"> |
||||||
|
and ( |
||||||
|
<foreach collection="bsEnergyCoreUse.workCenterId.split(',')" |
||||||
|
item="wid" |
||||||
|
separator=" or "> |
||||||
|
t.work_center_id LIKE '%' || #{wid} || '%' |
||||||
|
</foreach> |
||||||
|
) |
||||||
|
</if> |
||||||
|
</where> |
||||||
|
</select> |
||||||
|
|
||||||
|
</mapper> |
||||||
@ -0,0 +1,66 @@ |
|||||||
|
<?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="org.springblade.desk.energy.mapper.BsEnergyHistoryRecMapper"> |
||||||
|
|
||||||
|
<!-- 通用查询映射结果 --> |
||||||
|
<resultMap id="bsEnergyHistoryRecResultMap" type="org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO"> |
||||||
|
<result column="ID" property="id"/> |
||||||
|
<result column="DEVICE_ID" property="deviceId"/> |
||||||
|
<result column="DEVICE_CODE" property="deviceCode"/> |
||||||
|
<result column="READ_TAP" property="readTap"/> |
||||||
|
<result column="READ_PURE" property="readPure"/> |
||||||
|
<result column="READ_ELECTRIC" property="readElectric"/> |
||||||
|
<result column="UPLOAD_TIME" property="uploadTime"/> |
||||||
|
<result column="CREATE_USER" property="createUser"/> |
||||||
|
<result column="CREATE_DEPT" property="createDept"/> |
||||||
|
<result column="CREATE_TIME" property="createTime"/> |
||||||
|
<result column="UPDATE_USER" property="updateUser"/> |
||||||
|
<result column="UPDATE_TIME" property="updateTime"/> |
||||||
|
<result column="STATUS" property="status"/> |
||||||
|
<result column="IS_DELETED" property="isDeleted"/> |
||||||
|
<result column="DEVICE_NAME" property="deviceName"/> |
||||||
|
<result column="MAC_SPEC" property="macSpec"/> |
||||||
|
<result column="USED" property="used"/> |
||||||
|
</resultMap> |
||||||
|
|
||||||
|
<select id="selectBsEnergyHistoryRecPage" resultMap="bsEnergyHistoryRecResultMap"> |
||||||
|
select * from BS_ENERGY_HISTORY_REC |
||||||
|
<where> |
||||||
|
is_deleted = 0 |
||||||
|
<if test="bsEnergyHistoryRec.createTime!=null"> |
||||||
|
and TRUNC(CREATE_TIME) = TRUNC(#{bsEnergyHistoryRec.createTime}) |
||||||
|
</if> |
||||||
|
<if test="bsEnergyHistoryRec.deviceId!=null"> |
||||||
|
and DEVICE_ID = #{deviceId} |
||||||
|
</if> |
||||||
|
<if test="bsEnergyHistoryRec.deviceCode!=null"> |
||||||
|
and DEVICE_CODE = #{deviceCode} |
||||||
|
</if> |
||||||
|
</where> |
||||||
|
order by UPLOAD_TIME |
||||||
|
</select> |
||||||
|
|
||||||
|
<select id="selectBsEnergyHistoryRec" resultMap="bsEnergyHistoryRecResultMap"> |
||||||
|
SELECT |
||||||
|
t.*, |
||||||
|
a.DEVICE_NAME, |
||||||
|
a.MAC_SPEC, |
||||||
|
a.USED |
||||||
|
FROM BS_ENERGY_HISTORY_REC t |
||||||
|
LEFT JOIN MES_EQUIPMENT a ON t.DEVICE_ID = a.id |
||||||
|
<where> |
||||||
|
t.is_deleted = 0 |
||||||
|
<if test="createTime!=null"> |
||||||
|
and TRUNC(t.CREATE_TIME) = TRUNC(#{createTime}) |
||||||
|
</if> |
||||||
|
<if test="deviceId!=null"> |
||||||
|
and t.DEVICE_ID = #{deviceId} |
||||||
|
</if> |
||||||
|
<if test="deviceCode!=null"> |
||||||
|
and t.DEVICE_CODE = #{deviceCode} |
||||||
|
</if> |
||||||
|
</where> |
||||||
|
order by t.UPLOAD_TIME |
||||||
|
</select> |
||||||
|
|
||||||
|
</mapper> |
||||||
@ -0,0 +1,110 @@ |
|||||||
|
package org.springblade.desk.energy.pojo.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-16 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("BS_ENERGY_CORE_USE") |
||||||
|
@Schema(description = "BsEnergyCoreUse对象") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class BsEnergyCoreUseEntity extends BaseEntity { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 类型 1-用水 2-用电 |
||||||
|
*/ |
||||||
|
@Schema(description = "类型 1-用水 2-用电") |
||||||
|
private String type; |
||||||
|
/** |
||||||
|
* 作业中心ID |
||||||
|
*/ |
||||||
|
@Schema(description = "作业中心ID") |
||||||
|
private String workCenterId; |
||||||
|
/** |
||||||
|
* 作业中心名称 |
||||||
|
*/ |
||||||
|
@Schema(description = "作业中心名称") |
||||||
|
private String workCenterName; |
||||||
|
/** |
||||||
|
* 开始时间 |
||||||
|
*/ |
||||||
|
@Schema(description = "开始时间") |
||||||
|
private Date startTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 结束时间 |
||||||
|
*/ |
||||||
|
@Schema(description = "结束时间") |
||||||
|
private Date endTime; |
||||||
|
/** |
||||||
|
* 加工面积 |
||||||
|
*/ |
||||||
|
@Schema(description = "加工面积") |
||||||
|
private BigDecimal workArea; |
||||||
|
/** |
||||||
|
* 定额单位面积自来水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "定额单位面积自来水用水量") |
||||||
|
private BigDecimal quoTapWaterNum; |
||||||
|
/** |
||||||
|
* 实际单位面积自来水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际单位面积自来水用水量") |
||||||
|
private BigDecimal realTapWaterNum; |
||||||
|
/** |
||||||
|
* 实际总自来水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际总自来水用水量") |
||||||
|
private BigDecimal totalTapWaterNum; |
||||||
|
/** |
||||||
|
* 定额单位面积纯水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "定额单位面积纯水用水量") |
||||||
|
private BigDecimal quoPureWaterNum; |
||||||
|
/** |
||||||
|
* 实际单位面积纯水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际单位面积纯水用水量") |
||||||
|
private BigDecimal realPureWaterNum; |
||||||
|
/** |
||||||
|
* 实际总纯水用水量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际总纯水用水量") |
||||||
|
private BigDecimal totalPureWaterNum; |
||||||
|
/** |
||||||
|
* 定额单位面积用电量 |
||||||
|
*/ |
||||||
|
@Schema(description = "定额单位面积用电量") |
||||||
|
private BigDecimal quoElectricNum; |
||||||
|
/** |
||||||
|
* 实际单位面积用电量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际单位面积用电量") |
||||||
|
private BigDecimal realElectricNum; |
||||||
|
/** |
||||||
|
* 实际总用电量 |
||||||
|
*/ |
||||||
|
@Schema(description = "实际总用电量") |
||||||
|
private BigDecimal totalElectricNum; |
||||||
|
/** |
||||||
|
* 是否大屏展示 |
||||||
|
*/ |
||||||
|
@Schema(description = "是否大屏展示") |
||||||
|
private Integer isJumbotron; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
package org.springblade.desk.energy.pojo.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* iot水电能耗历史记录表 实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("BS_ENERGY_HISTORY_REC") |
||||||
|
@Schema(description = "BsEnergyHistoryRec对象") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class BsEnergyHistoryRecEntity extends BaseEntity { |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备ID |
||||||
|
*/ |
||||||
|
@Schema(description = "设备ID") |
||||||
|
private Long deviceId; |
||||||
|
/** |
||||||
|
* 设备编码 |
||||||
|
*/ |
||||||
|
@Schema(description = "设备编码") |
||||||
|
private String deviceCode; |
||||||
|
/** |
||||||
|
* 自来水量读取值 |
||||||
|
*/ |
||||||
|
@Schema(description = "自来水量读取值") |
||||||
|
private BigDecimal readTap; |
||||||
|
/** |
||||||
|
* 纯水量读取值 |
||||||
|
*/ |
||||||
|
@Schema(description = "纯水量读取值") |
||||||
|
private BigDecimal readPure; |
||||||
|
/** |
||||||
|
* 电量读取值 |
||||||
|
*/ |
||||||
|
@Schema(description = "电量读取值") |
||||||
|
private BigDecimal readElectric; |
||||||
|
/** |
||||||
|
* iot上传时间 |
||||||
|
*/ |
||||||
|
@Schema(description = "iot上传时间") |
||||||
|
private Date uploadTime; |
||||||
|
} |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
package org.springblade.desk.energy.pojo.vo; |
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyCoreUseEntity; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 视图实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-16 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class BsEnergyCoreUseVO extends BsEnergyCoreUseEntity { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 开始日期 |
||||||
|
*/ |
||||||
|
@Schema(description = "开始日期") |
||||||
|
private String startDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 结束日期 |
||||||
|
*/ |
||||||
|
@Schema(description = "结束日期") |
||||||
|
private String endDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 日期 |
||||||
|
*/ |
||||||
|
@Schema(description = "日期") |
||||||
|
private String date; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
package org.springblade.desk.energy.pojo.vo; |
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyHistoryRecEntity; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
|
||||||
|
/** |
||||||
|
* iot水电能耗历史记录表 视图实体类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-16 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class BsEnergyHistoryRecVO extends BsEnergyHistoryRecEntity { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备名称 |
||||||
|
*/ |
||||||
|
@Schema(description = "设备名称") |
||||||
|
private String deviceName; |
||||||
|
/** |
||||||
|
* 设备型号 |
||||||
|
*/ |
||||||
|
@Schema(description = "设备型号") |
||||||
|
private String macSpec; |
||||||
|
/** |
||||||
|
* 服役状态 |
||||||
|
*/ |
||||||
|
@Schema(description = "服役状态") |
||||||
|
private Long used; |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package org.springblade.desk.energy.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyCoreUseEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyCoreUseVO; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 服务类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
public interface IBsEnergyCoreUseService extends BaseService<BsEnergyCoreUseEntity> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* @param page 分页参数 |
||||||
|
* @param bsEnergyCoreUse 查询参数 |
||||||
|
* @return IPage<BsEnergyCoreUseVO> |
||||||
|
*/ |
||||||
|
IPage<BsEnergyCoreUseVO> selectBsEnergyCoreUsePage(IPage<BsEnergyCoreUseVO> page, BsEnergyCoreUseVO bsEnergyCoreUse); |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新用水用电记录 |
||||||
|
* @param type 类型 |
||||||
|
*/ |
||||||
|
void updateUsed(String type); |
||||||
|
|
||||||
|
/** |
||||||
|
* 保存iot用水用电历史记录 |
||||||
|
*/ |
||||||
|
void saveHistoryRec(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
package org.springblade.desk.energy.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyHistoryRecEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 服务类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
public interface IBsEnergyHistoryRecService extends BaseService<BsEnergyHistoryRecEntity> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page 分页参数 |
||||||
|
* @param bsEnergyHistoryRec 查询参数 |
||||||
|
* @return IPage<BsEnergyHistoryRecVO> |
||||||
|
*/ |
||||||
|
IPage<BsEnergyHistoryRecVO> selectBsEnergyHistoryRecPage(IPage<BsEnergyHistoryRecVO> page, BsEnergyHistoryRecVO bsEnergyHistoryRec); |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义查询 |
||||||
|
* @param bsEnergyHistoryRec 查询参数 |
||||||
|
* @return List<BsEnergyHistoryRecVO> |
||||||
|
*/ |
||||||
|
List<BsEnergyHistoryRecVO> selectBsEnergyHistoryRec(BsEnergyHistoryRecVO bsEnergyHistoryRec); |
||||||
|
} |
||||||
@ -0,0 +1,287 @@ |
|||||||
|
package org.springblade.desk.energy.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.excel.util.StringUtils; |
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import jakarta.annotation.Resource; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.desk.device.pojo.entity.EquipmentEntity; |
||||||
|
import org.springblade.desk.device.service.IEquipmentService; |
||||||
|
import org.springblade.desk.energy.mapper.BsEnergyCoreUseMapper; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyCoreUseEntity; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyHistoryRecEntity; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyQuotaEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyCoreUseVO; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyCoreUseService; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyHistoryRecService; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyQuotaService; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.http.HttpEntity; |
||||||
|
import org.springframework.http.HttpHeaders; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.util.CollectionUtils; |
||||||
|
import org.springframework.web.client.RestTemplate; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.math.RoundingMode; |
||||||
|
import java.time.LocalDate; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.time.LocalTime; |
||||||
|
import java.time.ZoneId; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 水电能耗记录表 服务实现类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class BsEnergyCoreUseServiceImpl extends BaseServiceImpl<BsEnergyCoreUseMapper, BsEnergyCoreUseEntity> implements IBsEnergyCoreUseService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private IBsEnergyQuotaService bsEnergyQuotaService; |
||||||
|
@Resource |
||||||
|
private IBsEnergyHistoryRecService bsEnergyHistoryRecService; |
||||||
|
@Resource |
||||||
|
private IEquipmentService equipmentService; |
||||||
|
@Resource |
||||||
|
private RestTemplate httpClientTemplate; |
||||||
|
|
||||||
|
private String timestamp = "timestamp", waterOne = "Water1", waterTwo = "Water2", waterThree = "Water3", waterFour = "Water4", readElectric = "ElectricPower", readElectric2 = "TotalElectricEnergyOfBX2", readElectric3 = "TotalElectricEnergyOfBX3"; |
||||||
|
|
||||||
|
@Value("${request.iotNew.url}") |
||||||
|
private String iotNewUrl; |
||||||
|
|
||||||
|
@Value("${request.iot.orgId}") |
||||||
|
private String orgId; |
||||||
|
|
||||||
|
@Value("${request.iot.systemId}") |
||||||
|
private String systemId; |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<BsEnergyCoreUseVO> selectBsEnergyCoreUsePage(IPage<BsEnergyCoreUseVO> page, BsEnergyCoreUseVO bsEnergyCoreUse) { |
||||||
|
return page.setRecords(baseMapper.selectBsEnergyCoreUsePage(page, bsEnergyCoreUse)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateUsed(String type) { |
||||||
|
List<BsEnergyQuotaEntity> bsEnergyQuotaEntitys = bsEnergyQuotaService.list(new LambdaQueryWrapper<BsEnergyQuotaEntity>() |
||||||
|
.eq(BsEnergyQuotaEntity::getType, type)); |
||||||
|
if (CollectionUtils.isEmpty(bsEnergyQuotaEntitys)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
// 时间处理
|
||||||
|
Date date = new Date(); |
||||||
|
LocalDate today = LocalDate.now(); |
||||||
|
LocalDate yesterday = today.minusDays(1); |
||||||
|
LocalDateTime minTime = LocalDateTime.of(yesterday, LocalTime.MIN); |
||||||
|
LocalDateTime maxTime = LocalDateTime.of(yesterday, LocalTime.MAX); |
||||||
|
Date startTime = Date.from(minTime.atZone(ZoneId.systemDefault()).toInstant()); |
||||||
|
Date endTime = Date.from(maxTime.atZone(ZoneId.systemDefault()).toInstant()); |
||||||
|
for (BsEnergyQuotaEntity bsEnergyQuotaEntity : bsEnergyQuotaEntitys) { |
||||||
|
Long equipmentId = bsEnergyQuotaEntity.getEquipmentId(); |
||||||
|
EquipmentEntity equipment = equipmentService.getById(equipmentId); |
||||||
|
if (equipment == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
BsEnergyHistoryRecVO params = new BsEnergyHistoryRecVO(); |
||||||
|
params.setCreateTime(startTime); |
||||||
|
params.setDeviceCode(equipment.getDeviceCode()); |
||||||
|
List<BsEnergyHistoryRecVO> hrList = bsEnergyHistoryRecService.selectBsEnergyHistoryRec(params); |
||||||
|
if (!CollectionUtils.isEmpty(hrList)) { |
||||||
|
// 每日用自来水最大最小值
|
||||||
|
BigDecimal maxTa = hrList.get(hrList.size() - 1).getReadTap(); |
||||||
|
BigDecimal minTa = hrList.get(0).getReadTap(); |
||||||
|
// 每日用纯水最大最小值
|
||||||
|
BigDecimal maxPu = hrList.get(hrList.size() - 1).getReadPure(); |
||||||
|
BigDecimal minPu = hrList.get(0).getReadPure(); |
||||||
|
// 每日用电最大最小值
|
||||||
|
BigDecimal maxEl = hrList.get(hrList.size() - 1).getReadElectric(); |
||||||
|
BigDecimal minEl = hrList.get(0).getReadElectric(); |
||||||
|
this.createWorkCenterUse(bsEnergyQuotaEntity, maxTa.subtract(minTa), maxPu.subtract(minPu), maxEl.subtract(minEl), date, startTime, endTime, type); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void saveHistoryRec() { |
||||||
|
List<EquipmentEntity> equipments = equipmentService.list(new LambdaQueryWrapper<EquipmentEntity>().eq(EquipmentEntity::getIsDeleted, 0)); |
||||||
|
LocalDateTime now = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()); |
||||||
|
LocalDateTime lastHour = now.minusHours(1); |
||||||
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||||
|
String startTime = lastHour.format(fmt); |
||||||
|
String endTime = now.format(fmt); |
||||||
|
List<String> params = Arrays.asList("Water4", "Water3", "Water2", "Water1", "ElectricPower", "TotalElectricEnergyOfBX2", "TotalElectricEnergyOfBX2"); |
||||||
|
BsEnergyHistoryRecEntity bsEnergyHistoryRec; |
||||||
|
JSONObject jsonObject; |
||||||
|
for (EquipmentEntity equipment : equipments) { |
||||||
|
List<JSONObject> eneUsed; |
||||||
|
String deviceCode = equipment.getDeviceCode(); |
||||||
|
try { |
||||||
|
eneUsed = this.getEneUsed(deviceCode, params, startTime, endTime); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("设备:" + deviceCode + "查询用水用电量接口调用失败!\n" + e.getMessage()); |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (CollectionUtils.isEmpty(eneUsed)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
jsonObject = eneUsed.get(eneUsed.size() - 1); |
||||||
|
bsEnergyHistoryRec = new BsEnergyHistoryRecEntity(); |
||||||
|
bsEnergyHistoryRec.setDeviceId(equipment.getId()); |
||||||
|
bsEnergyHistoryRec.setDeviceCode(equipment.getDeviceCode()); |
||||||
|
// 读取自来水用量(如果存在自来水2则计算累加值)
|
||||||
|
if (jsonObject.get(waterThree) != null) { |
||||||
|
bsEnergyHistoryRec.setReadTap(new BigDecimal(this.totalRead(jsonObject, waterOne, waterThree))); |
||||||
|
} else { |
||||||
|
bsEnergyHistoryRec.setReadTap(new BigDecimal(this.totalRead(jsonObject, waterOne))); |
||||||
|
} |
||||||
|
// 读取纯水用量(如果存在纯水2则计算累加值)
|
||||||
|
if (jsonObject.get(waterFour) != null) { |
||||||
|
bsEnergyHistoryRec.setReadPure(new BigDecimal(this.totalRead(jsonObject, waterTwo, waterFour))); |
||||||
|
} else { |
||||||
|
bsEnergyHistoryRec.setReadPure(new BigDecimal(this.totalRead(jsonObject, waterTwo))); |
||||||
|
} |
||||||
|
// 读取电用量
|
||||||
|
bsEnergyHistoryRec.setReadElectric(new BigDecimal(this.totalRead(jsonObject, readElectric, readElectric2, readElectric3))); |
||||||
|
// 读取上传时间
|
||||||
|
bsEnergyHistoryRec.setUploadTime(jsonObject.getDate(timestamp)); |
||||||
|
BsEnergyHistoryRecEntity last = bsEnergyHistoryRecService.getOne(new LambdaQueryWrapper<BsEnergyHistoryRecEntity>().eq(BsEnergyHistoryRecEntity::getDeviceCode, deviceCode).orderByDesc(BsEnergyHistoryRecEntity::getCreateTime).last("AND ROWNUM = 1")); |
||||||
|
if (last != null && last.getId() != null) { |
||||||
|
BigDecimal readElectric = last.getReadElectric(); // 电
|
||||||
|
BigDecimal readPure = last.getReadPure(); // 纯水
|
||||||
|
BigDecimal readTap = last.getReadTap();// 自来水
|
||||||
|
// 如果最新的自来水数据为空或者小于上一笔数据,直接改为上一笔数据
|
||||||
|
if (!(bsEnergyHistoryRec.getReadTap() != null && bsEnergyHistoryRec.getReadTap().compareTo(readTap) > 0)) { |
||||||
|
bsEnergyHistoryRec.setReadTap(readTap); |
||||||
|
} |
||||||
|
// 如果最新的纯水数据为空或者小于上一笔数据,直接改为上一笔数据
|
||||||
|
if (!(bsEnergyHistoryRec.getReadPure() != null && bsEnergyHistoryRec.getReadPure().compareTo(readPure) > 0)) { |
||||||
|
bsEnergyHistoryRec.setReadPure(readPure); |
||||||
|
} |
||||||
|
// 如果最新的电数据为空或者小于上一笔数据,直接改为上一笔数据
|
||||||
|
if (!(bsEnergyHistoryRec.getReadElectric() != null && bsEnergyHistoryRec.getReadElectric().compareTo(readElectric) > 0)) { |
||||||
|
bsEnergyHistoryRec.setReadElectric(readElectric); |
||||||
|
} |
||||||
|
} |
||||||
|
bsEnergyHistoryRecService.save(bsEnergyHistoryRec); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建作业中心用水用电记录 |
||||||
|
* |
||||||
|
* @param bsEnergyQuota |
||||||
|
* @param useTa |
||||||
|
* @param usePu |
||||||
|
* @param useEl |
||||||
|
* @param date |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
* @param type |
||||||
|
*/ |
||||||
|
private void createWorkCenterUse(BsEnergyQuotaEntity bsEnergyQuota, BigDecimal useTa, BigDecimal usePu, BigDecimal useEl, Date date, Date startTime, Date endTime, String type) { |
||||||
|
String workCenterId = bsEnergyQuota.getWorkCenterId(); |
||||||
|
if (StringUtils.isEmpty(workCenterId)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
BigDecimal wcArea = new BigDecimal("0"); |
||||||
|
// TODO 作业面积
|
||||||
|
BigDecimal quotaEl = bsEnergyQuota.getElectricNum(); // 定额单位面积用电量
|
||||||
|
BigDecimal tapWater = bsEnergyQuota.getTapWaterNum(); // 定额自来水单位用量
|
||||||
|
BigDecimal pureWater = bsEnergyQuota.getPureWaterNum(); // 定额纯水单位用量
|
||||||
|
|
||||||
|
BigDecimal realUnitTa = new BigDecimal("0"); // 实际自来水单位用量
|
||||||
|
BigDecimal realUnitPu = new BigDecimal("0"); // 实际纯水单位用量
|
||||||
|
BigDecimal realUnitEl = new BigDecimal("0"); // 实际单位面积用电量
|
||||||
|
|
||||||
|
BsEnergyCoreUseEntity bsEnergyCoreUse = new BsEnergyCoreUseEntity(); |
||||||
|
if (!(wcArea.compareTo(BigDecimal.ZERO) == 0)) { |
||||||
|
realUnitTa = useTa.divide(wcArea, 6, RoundingMode.HALF_UP); |
||||||
|
realUnitPu = usePu.divide(wcArea, 6, RoundingMode.HALF_UP); |
||||||
|
realUnitEl = useEl.divide(wcArea, 6, RoundingMode.HALF_UP); |
||||||
|
} |
||||||
|
bsEnergyCoreUse.setType(type); |
||||||
|
bsEnergyCoreUse.setWorkCenterId(bsEnergyQuota.getWorkCenterId()); |
||||||
|
bsEnergyCoreUse.setWorkCenterName(bsEnergyQuota.getWorkCenterName()); |
||||||
|
bsEnergyCoreUse.setStartTime(startTime); |
||||||
|
bsEnergyCoreUse.setEndTime(endTime); |
||||||
|
bsEnergyCoreUse.setWorkArea(wcArea); |
||||||
|
bsEnergyCoreUse.setQuoTapWaterNum(tapWater); |
||||||
|
bsEnergyCoreUse.setQuoPureWaterNum(pureWater); |
||||||
|
bsEnergyCoreUse.setQuoElectricNum(quotaEl); |
||||||
|
bsEnergyCoreUse.setRealTapWaterNum(realUnitTa); |
||||||
|
bsEnergyCoreUse.setRealPureWaterNum(realUnitPu); |
||||||
|
bsEnergyCoreUse.setRealElectricNum(realUnitEl); |
||||||
|
bsEnergyCoreUse.setTotalTapWaterNum(useTa); |
||||||
|
bsEnergyCoreUse.setTotalPureWaterNum(usePu); |
||||||
|
bsEnergyCoreUse.setTotalElectricNum(useEl); |
||||||
|
bsEnergyCoreUse.setIsJumbotron(0); |
||||||
|
this.save(bsEnergyCoreUse); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取iot用水用电记录 |
||||||
|
* |
||||||
|
* @param deviceCode |
||||||
|
* @param params |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private List<JSONObject> getEneUsed(String deviceCode, List<String> params, String startTime, String endTime) { |
||||||
|
HttpHeaders headers = new HttpHeaders(); |
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON); |
||||||
|
JSONObject object = new JSONObject(); |
||||||
|
object.put("orgId", orgId); |
||||||
|
object.put("systemId", systemId); |
||||||
|
object.put("params", params); // 设备对应的参数信息
|
||||||
|
object.put("deviceId", deviceCode); // 设备编码
|
||||||
|
object.put("startTime", startTime); // 开始时间(入炉)
|
||||||
|
object.put("endTime", endTime); // 结束时间(出炉)
|
||||||
|
HttpEntity<JSONObject> entity = new HttpEntity<>(object, headers); |
||||||
|
ResponseEntity<JSONObject> responseEntity = null; |
||||||
|
try { |
||||||
|
responseEntity = httpClientTemplate.postForEntity(iotNewUrl + "/deviceForZhgd/deviceDataHistoryByParams", entity, JSONObject.class); |
||||||
|
JSONObject result = responseEntity.getBody(); |
||||||
|
if (result != null && result.getInteger("code").equals(0)) { |
||||||
|
List<JSONObject> jsonList = JSONArray.parseArray(result.getJSONArray("result").toJSONString(), JSONObject.class); |
||||||
|
if (jsonList != null && jsonList.size() > 0) { |
||||||
|
return jsonList; |
||||||
|
} |
||||||
|
} else { |
||||||
|
log.error("获取用水用电量、烧结解绑获取数据接口调用失败!" + result.getString("message") + "设备编码" + deviceCode + "参数" + object); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("获取用水用电量、烧结解绑获取数据接口调用失败!" + e.getMessage() + "设备编码" + deviceCode + "参数" + object); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 合计读取值 |
||||||
|
* |
||||||
|
* @param jsonObject |
||||||
|
* @param args |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Double totalRead(JSONObject jsonObject, String... args) { |
||||||
|
Double total = 0d; |
||||||
|
String waStr; |
||||||
|
for (String s : args) { |
||||||
|
waStr = jsonObject.getString(s); |
||||||
|
total += org.apache.commons.lang3.StringUtils.isNotBlank(waStr) ? Double.valueOf(waStr) : 0; |
||||||
|
} |
||||||
|
return total; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
package org.springblade.desk.energy.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.desk.energy.mapper.BsEnergyHistoryRecMapper; |
||||||
|
import org.springblade.desk.energy.pojo.entity.BsEnergyHistoryRecEntity; |
||||||
|
import org.springblade.desk.energy.pojo.vo.BsEnergyHistoryRecVO; |
||||||
|
import org.springblade.desk.energy.service.IBsEnergyHistoryRecService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* iot水电能耗历史记录表 服务实现类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
* @since 2026-04-17 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class BsEnergyHistoryRecServiceImpl extends BaseServiceImpl<BsEnergyHistoryRecMapper, BsEnergyHistoryRecEntity> implements IBsEnergyHistoryRecService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<BsEnergyHistoryRecVO> selectBsEnergyHistoryRecPage(IPage<BsEnergyHistoryRecVO> page, BsEnergyHistoryRecVO bsEnergyHistoryRec) { |
||||||
|
return page.setRecords(baseMapper.selectBsEnergyHistoryRecPage(page, bsEnergyHistoryRec)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<BsEnergyHistoryRecVO> selectBsEnergyHistoryRec(BsEnergyHistoryRecVO bsEnergyHistoryRec) { |
||||||
|
return baseMapper.selectBsEnergyHistoryRec(bsEnergyHistoryRec); |
||||||
|
} |
||||||
|
} |
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue