mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
归档功能
This commit is contained in:
@@ -47,6 +47,19 @@ public class CoalAnalysisController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
@SysLog(action = "归档")
|
||||
public Object archive(@RequestBody IdRequest dto) {
|
||||
this.service.archive(dto);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
@SysLog(action = "取消归档")
|
||||
public Object unarchive(@RequestBody IdRequest dto) {
|
||||
this.service.unarchive(dto);
|
||||
return true;
|
||||
}
|
||||
@PostMapping("/getById")
|
||||
public CoalAnalysisDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.lihongjie.coal.coalInfo.entity.CoalInfoEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -17,6 +18,17 @@ public class CoalAnalysisDto extends OrgCommonDto {
|
||||
@Comment("关联的煤源信息")
|
||||
private CoalInfoEntity coalInfo;
|
||||
|
||||
@Comment("归档状态")
|
||||
private String archiveStatus;
|
||||
|
||||
@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;
|
||||
@Comment("参数 1 ")
|
||||
// @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
|
||||
private Double param1;
|
||||
|
||||
@@ -9,7 +9,9 @@ import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@@ -18,6 +20,19 @@ public class CoalAnalysisEntity extends OrgCommonEntity {
|
||||
@Comment("关联的煤源信息")
|
||||
private CoalInfoEntity coalInfo;
|
||||
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus;
|
||||
|
||||
@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;
|
||||
@Comment("参数 1 ")
|
||||
// @DecimalMin(value = "0.1", inclusive = true, message = "参数不能小于0.1")
|
||||
private Double param1;
|
||||
|
||||
@@ -12,6 +12,7 @@ import cn.lihongjie.coal.coalAnalysis.repository.CoalAnalysisRepository;
|
||||
import cn.lihongjie.coal.coalAnalysisHis.service.CoalAnalysisHisService;
|
||||
import cn.lihongjie.coal.coalParameterDef.entity.CoalParameterDefEntity;
|
||||
import cn.lihongjie.coal.coalParameterDef.repository.CoalParameterDefRepository;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.GroovyScriptUtils;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
@@ -97,6 +98,13 @@ class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRe
|
||||
public CoalAnalysisDto update(UpdateCoalAnalysisDto request) {
|
||||
CoalAnalysisEntity entity = this.repository.get(request.getId());
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
CoalAnalysisEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("化验报告 " + e.getName() + "已归档,无法编辑");
|
||||
});
|
||||
hisService.saveHis(entity);
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
@@ -107,6 +115,14 @@ class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRe
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
CoalAnalysisEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("化验报告 " + e.getName() + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -127,4 +143,23 @@ class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRe
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(x -> ArchiveUtils.checkArchiveStatus(x, CoalAnalysisEntity::getArchiveStatus, y -> "0", (e, actual, expected) -> {
|
||||
throw new BizException("化验报告 " + e.getName() + "已归档,无法再次归档");
|
||||
}))
|
||||
.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, CoalAnalysisEntity::getArchiveStatus, y -> "1", (e, actual, expected) -> {
|
||||
throw new BizException("化验报告 " + e.getName() + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@@ -19,6 +20,11 @@ public class CoalAnalysisHisEntity extends OrgCommonEntity {
|
||||
@Comment("关联的煤源信息")
|
||||
private CoalInfoEntity coalInfo;
|
||||
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus;
|
||||
|
||||
@ManyToOne
|
||||
@Comment("关联化验数据")
|
||||
private CoalAnalysisEntity src;
|
||||
|
||||
@@ -57,6 +57,20 @@ public class CoalWashingDailyAnalysisController extends BaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
@SysLog(action = "归档")
|
||||
public Object archive(@RequestBody IdRequest dto) {
|
||||
this.service.archive(dto);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
@SysLog(action = "取消归档")
|
||||
public Object unarchive(@RequestBody IdRequest dto) {
|
||||
this.service.unarchive(dto);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<CoalWashingDailyAnalysisDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
|
||||
@@ -13,6 +13,7 @@ import jakarta.persistence.ForeignKey;
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
@@ -25,6 +26,18 @@ public class CoalWashingDailyAnalysisDto extends OrgCommonDto {
|
||||
@Comment("日期")
|
||||
private LocalDate date;
|
||||
|
||||
@Comment("归档状态")
|
||||
private String archiveStatus;
|
||||
|
||||
@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;
|
||||
|
||||
@ElementCollection
|
||||
@Comment("用户手动录入的记录")
|
||||
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
|
||||
@@ -12,7 +12,9 @@ import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
@@ -26,6 +28,19 @@ import java.util.stream.Collectors;
|
||||
@Comment("洗煤报告表")
|
||||
public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
|
||||
@Comment("归档状态")
|
||||
private String archiveStatus;
|
||||
|
||||
@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)")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatusName;
|
||||
|
||||
@Comment("日期")
|
||||
private LocalDate date;
|
||||
|
||||
@@ -103,21 +118,19 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
inputItems.sort(
|
||||
Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN)));
|
||||
|
||||
for(int i = 1; i < inputItems.size(); i++) {
|
||||
for (int i = 1; i < inputItems.size(); i++) {
|
||||
var c = inputItems.get(i);
|
||||
var p = inputItems.get(i - 1);
|
||||
|
||||
if (c.getTime() == null || p.getTime() == null){
|
||||
if (c.getTime() == null || p.getTime() == null) {
|
||||
throw new BizException("时间不能为空");
|
||||
}
|
||||
|
||||
if (c.getTime().equals(p.getTime())){
|
||||
if (c.getTime().equals(p.getTime())) {
|
||||
throw new BizException("时间重复 " + c.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < inputItems.size(); i++) {
|
||||
CoalWashingDailyAnalysisItemVo coalWashingDailyAnalysisItemVo = inputItems.get(i);
|
||||
if (StringUtils.equals(type, "2") && i == inputItems.size() - 1) {
|
||||
@@ -162,7 +175,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setRollingAvgDdp1(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
@@ -177,7 +189,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setFddAvgP1(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
@@ -185,8 +196,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setFddAvgP2(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
@@ -194,8 +203,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setSysDdAvgP1(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
@@ -203,8 +210,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setSysDdAvgP2(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
@@ -212,18 +217,11 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity {
|
||||
getWeight,
|
||||
(x, v) -> x.setDdAvgP1(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
|
||||
cn.lihongjie.coal.common.CollectionUtils.rollingAvg(
|
||||
inputItems,
|
||||
Comparator.comparing(CoalWashingDailyAnalysisItemVo::getTime),
|
||||
CoalWashingDailyAnalysisItemVo::getDdp2,
|
||||
getWeight,
|
||||
(x, v) -> x.setDdAvgP2(v == null ? null : v.doubleValue()));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysi
|
||||
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.CoalWashingDailyAnalysisMapper;
|
||||
import cn.lihongjie.coal.coalWashingDailyAnalysis.mapper.RoundMapper;
|
||||
import cn.lihongjie.coal.coalWashingDailyAnalysis.repository.CoalWashingDailyAnalysisRepository;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@@ -27,8 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public
|
||||
class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> {
|
||||
public class CoalWashingDailyAnalysisService
|
||||
extends BaseService<CoalWashingDailyAnalysisEntity, CoalWashingDailyAnalysisRepository> {
|
||||
|
||||
@Autowired CoalWashingDailyAnalysisRepository repository;
|
||||
|
||||
@@ -58,7 +60,14 @@ class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDailyAnalys
|
||||
}
|
||||
|
||||
public CoalWashingDailyAnalysisDto update(UpdateCoalWashingDailyAnalysisDto request) {
|
||||
|
||||
|
||||
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(entity, CoalWashingDailyAnalysisEntity::getArchiveStatus, x -> "0", (e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "已归档,无法编辑");
|
||||
});
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
|
||||
this.repository.save(entity);
|
||||
@@ -68,6 +77,15 @@ class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDailyAnalys
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
CoalWashingDailyAnalysisEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "已归档,无法删除");
|
||||
});
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -91,5 +109,22 @@ class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDailyAnalys
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(x -> ArchiveUtils.checkArchiveStatus(x, CoalWashingDailyAnalysisEntity::getArchiveStatus, y -> "0", (e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "已归档,无法再次归档");
|
||||
}))
|
||||
.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, CoalWashingDailyAnalysisEntity::getArchiveStatus, y -> "1", (e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
|
||||
43
src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java
Normal file
43
src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
|
||||
import io.vavr.Function3;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class ArchiveUtils {
|
||||
public static <T, E> void checkArchiveStatus(Function<Iterable<T>, Iterable<E>> mapper, Iterable<T> ids, Function<E, String> statusGetter, Function<E, String> expectedStatusGetter, Function3<E, String, String, Void> handler) {
|
||||
|
||||
mapper.apply(ids)
|
||||
.forEach(
|
||||
e -> {
|
||||
String actual = statusGetter.apply(e);
|
||||
String expected = expectedStatusGetter.apply(e);
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
|
||||
handler.apply(e, actual, expected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T, E> void checkArchiveStatus(E entity, Function<E, String> statusGetter, Function<E, String> expectedStatusGetter, Function3<E, String, String, Void> handler) {
|
||||
|
||||
|
||||
checkArchiveStatus(
|
||||
x -> Collections.singletonList(entity),
|
||||
Collections.singletonList(entity),
|
||||
statusGetter,
|
||||
expectedStatusGetter,
|
||||
handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1930,7 +1930,21 @@
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"code": "archiveStatus",
|
||||
"name": "归档状态",
|
||||
"item": [
|
||||
{
|
||||
"code": "0",
|
||||
"name": "未归档"
|
||||
},
|
||||
{
|
||||
"code": "1",
|
||||
"name": "已归档"
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "coalBlend.coalType",
|
||||
"name": "配煤-煤类型",
|
||||
|
||||
8
src/main/resources/db/migration/V28__archiveStatus.sql
Normal file
8
src/main/resources/db/migration/V28__archiveStatus.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
update t_coal_analysis
|
||||
set archive_status = '0';
|
||||
|
||||
update t_coal_analysis_his
|
||||
set archive_status = '0';
|
||||
|
||||
|
||||
update t_coal_washing_daily_analysis set archive_status = '0';
|
||||
Reference in New Issue
Block a user