mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
抄表记录添加归档功能
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package cn.lihongjie.coal.device.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.device.entity.DeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -14,10 +9,6 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = DeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = DeviceEntity.class)
|
||||
public class CreateDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package cn.lihongjie.coal.device.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.device.entity.DeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -14,10 +9,6 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = DeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = DeviceEntity.class)
|
||||
public class UpdateDeviceDto extends OrgCommonDto {
|
||||
@Comment("设备型号")
|
||||
private String model;
|
||||
|
||||
@@ -52,4 +52,16 @@ public class MeterLogController {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,11 @@ public class MeterLogDto extends OrgCommonDto {
|
||||
|
||||
@Comment("使用量")
|
||||
private java.lang.Double usage;
|
||||
|
||||
|
||||
@Comment("归档状态")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
|
||||
private String archiveStatusName;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@@ -22,6 +23,21 @@ public class MeterLogEntity extends OrgCommonEntity {
|
||||
@Comment("抄表值")
|
||||
private java.lang.Double value;
|
||||
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
@Formula("( lag(value, 1, (select tm.init_value from t_meter tm where tm.id = meter_id)) over (partition by meter_id order by time asc ) )")
|
||||
private java.lang.Double previousValue;
|
||||
@Formula(" ( value - ( lag(value, 1, (select tm.init_value from t_meter tm where tm.id = meter_id)) over (partition by meter_id order by time asc ) ) )")
|
||||
|
||||
@@ -3,6 +3,8 @@ package cn.lihongjie.coal.meterLog.service;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.meterDayLog.service.MeterDayLogService;
|
||||
import cn.lihongjie.coal.meterLog.dto.CreateMeterLogDto;
|
||||
import cn.lihongjie.coal.meterLog.dto.MeterLogDto;
|
||||
@@ -46,6 +48,15 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
|
||||
public MeterLogDto update(UpdateMeterLogDto request) {
|
||||
MeterLogEntity entity = this.repository.get(request.getId());
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
MeterLogEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -55,6 +66,15 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
MeterLogEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -78,6 +98,36 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
MeterLogEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
MeterLogEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Autowired MeterMonthLogService meterMonthLogService;
|
||||
|
||||
Reference in New Issue
Block a user