mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
优化归档逻辑
This commit is contained in:
@@ -13,7 +13,6 @@ import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.common.TreeUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
@@ -421,13 +420,9 @@ DictTranslate.class)
|
||||
.addStatement(
|
||||
"""
|
||||
$T entity = this.repository.get(request.getId());
|
||||
$T.checkArchiveStatus(
|
||||
entity,
|
||||
$T::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new $T("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new $T("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -435,8 +430,6 @@ DictTranslate.class)
|
||||
return getById(entity.getId())
|
||||
""",
|
||||
ClassName.get(entityPackage, entity.name),
|
||||
ClassName.get(ArchiveUtils.class),
|
||||
ClassName.get(entityPackage, entity.name),
|
||||
ClassName.get(BizException.class))
|
||||
.build();
|
||||
}
|
||||
@@ -451,11 +444,11 @@ DictTranslate.class)
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
throw new $T("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds())
|
||||
""")
|
||||
""", ClassName.get(BizException.class))
|
||||
.build();
|
||||
|
||||
if (archive) {
|
||||
@@ -466,24 +459,19 @@ DictTranslate.class)
|
||||
.addParameter(ClassName.get(IdRequest.class), "request")
|
||||
.addStatement(
|
||||
"""
|
||||
$T.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
$T::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new $T("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new $T("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
throw new $T("数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds())
|
||||
""",
|
||||
ClassName.get(ArchiveUtils.class),
|
||||
ClassName.get(entityPackage, entity.name),
|
||||
ClassName.get(BizException.class))
|
||||
ClassName.get(BizException.class),
|
||||
ClassName.get(BizException.class)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -591,16 +579,8 @@ DictTranslate.class)
|
||||
.addParameter(ClassName.get(IdRequest.class), "dto")
|
||||
.addStatement(
|
||||
"""
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(x -> $T.checkArchiveStatus(x, $T::getArchiveStatus, y -> "0", (e, actual, expected) -> {
|
||||
throw new $T("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
""",
|
||||
ClassName.get(ArchiveUtils.class),
|
||||
ClassName.get(entityPackage, entity.name),
|
||||
ClassName.get(BizException.class))
|
||||
this.repository.archive(dto);
|
||||
""")
|
||||
.build())
|
||||
.addMethod(
|
||||
MethodSpec.methodBuilder("unarchive")
|
||||
@@ -609,16 +589,9 @@ DictTranslate.class)
|
||||
.addParameter(ClassName.get(IdRequest.class), "dto")
|
||||
.addStatement(
|
||||
"""
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(x->$T.checkArchiveStatus(x, $T::getArchiveStatus, y -> "1", (e, actual, expected) -> {
|
||||
throw new $T("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
""",
|
||||
ClassName.get(ArchiveUtils.class),
|
||||
ClassName.get(entityPackage, entity.name),
|
||||
ClassName.get(BizException.class))
|
||||
this.repository.unArchive(dto);
|
||||
"""
|
||||
)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import cn.lihongjie.coal.acAppointment.repository.AcAppointmentRepository;
|
||||
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.common.JpaUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
@@ -94,13 +93,9 @@ public class AcAppointmentService
|
||||
|
||||
public AcAppointmentDto update(UpdateAcAppointmentDto request) {
|
||||
AcAppointmentEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
AcAppointmentEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -111,14 +106,9 @@ public class AcAppointmentService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcAppointmentEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
List<AcAppointmentEntity> all = this.repository.findAllById(request.getIds());
|
||||
|
||||
@@ -141,14 +131,9 @@ public class AcAppointmentService
|
||||
}
|
||||
|
||||
public void cancel(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcAppointmentEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法操作");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
List<AcAppointmentEntity> all = this.repository.findAllById(request.getIds());
|
||||
|
||||
@@ -276,32 +261,10 @@ public class AcAppointmentService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcAppointmentEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcAppointmentEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import cn.lihongjie.coal.acDeviceData.service.AcDeviceDataService;
|
||||
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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.exception.DataLinkedException;
|
||||
@@ -50,13 +49,9 @@ public class AcDeviceService extends BaseService<AcDeviceEntity, AcDeviceReposit
|
||||
|
||||
public AcDeviceDto update(UpdateAcDeviceDto request) {
|
||||
AcDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -69,14 +64,9 @@ public class AcDeviceService extends BaseService<AcDeviceEntity, AcDeviceReposit
|
||||
@Autowired AcAppointmentService acAppointmentService;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
if (acDeviceDataService.count(
|
||||
(Specification<AcDeviceDataEntity>)
|
||||
@@ -121,32 +111,10 @@ public class AcDeviceService extends BaseService<AcDeviceEntity, AcDeviceReposit
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import cn.lihongjie.coal.acDeviceSupplier.repository.AcDeviceSupplierRepository;
|
||||
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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.exception.DataLinkedException;
|
||||
@@ -51,13 +50,9 @@ public class AcDeviceSupplierService
|
||||
|
||||
public AcDeviceSupplierDto update(UpdateAcDeviceSupplierDto request) {
|
||||
AcDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -66,14 +61,9 @@ public class AcDeviceSupplierService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
if (acDeviceService.count(
|
||||
(Specification<AcDeviceEntity>) (root, query, criteriaBuilder) -> criteriaBuilder.and(
|
||||
@@ -106,32 +96,10 @@ public class AcDeviceSupplierService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package cn.lihongjie.coal.base.dao;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.common.ReflectUtils;
|
||||
|
||||
import jakarta.persistence.criteria.Path;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
@@ -16,7 +20,105 @@ public interface BaseRepository<T> extends JpaRepository<T, String>, JpaSpecific
|
||||
return findById(id).orElseThrow(() -> new RuntimeException("数据不存在: " + id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
default void archive(IdRequest request){
|
||||
|
||||
if (request.getIds() == null || request.getIds().isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
List<T> list = findAllById(request.getIds());
|
||||
|
||||
for (T t : list) {
|
||||
|
||||
boolean hasField = ReflectUtils.hasField(t.getClass(), "archiveStatus");
|
||||
|
||||
if (!hasField) {
|
||||
|
||||
return;
|
||||
}
|
||||
Object archiveStatus = ReflectUtils.readField(t, "archiveStatus");
|
||||
|
||||
if (archiveStatus ==null || StringUtils.equals(archiveStatus.toString(), "0")){
|
||||
ReflectUtils.writeField(t, "archiveStatus", "1");
|
||||
}else {
|
||||
throw new RuntimeException("数据已经归档, 无法再次归档: " + ReflectUtils.readField(t, "id"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
saveAll(list);
|
||||
|
||||
}
|
||||
|
||||
default void unArchive(IdRequest request){
|
||||
|
||||
if (request.getIds() == null || request.getIds().isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
List<T> list = findAllById(request.getIds());
|
||||
|
||||
for (T t : list) {
|
||||
|
||||
boolean hasField = ReflectUtils.hasField(t.getClass(), "archiveStatus");
|
||||
|
||||
if (!hasField) {
|
||||
|
||||
return;
|
||||
}
|
||||
Object archiveStatus = ReflectUtils.readField(t, "archiveStatus");
|
||||
|
||||
if (archiveStatus !=null && StringUtils.equals(archiveStatus.toString(), "1")){
|
||||
ReflectUtils.writeField(t, "archiveStatus", "0");
|
||||
}else {
|
||||
throw new RuntimeException("数据未归档, 无法取消归档: " + ReflectUtils.readField(t, "id"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
saveAll(list);
|
||||
|
||||
}
|
||||
|
||||
default boolean containArchived(String id){
|
||||
return containArchived(new IdRequest(List.of(id)));
|
||||
}
|
||||
|
||||
default boolean containArchived(IdRequest request){
|
||||
|
||||
|
||||
if (request.getIds() == null || request.getIds().isEmpty()){
|
||||
return false;
|
||||
}
|
||||
|
||||
List<T> list = findAllById(request.getIds());
|
||||
|
||||
for (T t : list) {
|
||||
|
||||
boolean hasField = ReflectUtils.hasField(t.getClass(), "archiveStatus");
|
||||
|
||||
if (!hasField) {
|
||||
|
||||
return false;
|
||||
}
|
||||
Object archiveStatus = ReflectUtils.readField(t, "archiveStatus");
|
||||
|
||||
if (archiveStatus !=null && StringUtils.equals(archiveStatus.toString(), "1")){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
default List<T> findByOrganizationId(String organizationId) {
|
||||
return findAll(
|
||||
|
||||
@@ -12,7 +12,6 @@ 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;
|
||||
@@ -98,13 +97,9 @@ 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("化验报告 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
hisService.saveHis(entity);
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
@@ -115,14 +110,9 @@ 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("化验报告 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -146,20 +136,10 @@ class CoalAnalysisService extends BaseService<CoalAnalysisEntity, CoalAnalysisRe
|
||||
|
||||
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("化验报告 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
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("化验报告 " + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ 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;
|
||||
|
||||
@@ -64,9 +63,9 @@ public class CoalWashingDailyAnalysisService
|
||||
|
||||
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(entity, CoalWashingDailyAnalysisEntity::getArchiveStatus, x -> "0", (e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
|
||||
@@ -77,14 +76,9 @@ public class CoalWashingDailyAnalysisService
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
CoalWashingDailyAnalysisEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("生产报表 " + e.getName() + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
@@ -111,20 +105,10 @@ public class CoalWashingDailyAnalysisService
|
||||
|
||||
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);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
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);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,10 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.device.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.device.dto.CreateDeviceDto;
|
||||
import cn.lihongjie.coal.device.dto.DeviceDto;
|
||||
import cn.lihongjie.coal.device.dto.UpdateDeviceDto;
|
||||
@@ -41,13 +40,9 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
|
||||
|
||||
public DeviceDto update(UpdateDeviceDto request) {
|
||||
DeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
DeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -56,14 +51,9 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
DeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -86,32 +76,10 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.deviceSupplier.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.deviceSupplier.dto.CreateDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.deviceSupplier.dto.DeviceSupplierDto;
|
||||
import cn.lihongjie.coal.deviceSupplier.dto.UpdateDeviceSupplierDto;
|
||||
@@ -42,13 +41,9 @@ public class DeviceSupplierService
|
||||
|
||||
public DeviceSupplierDto update(UpdateDeviceSupplierDto request) {
|
||||
DeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
DeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -57,14 +52,9 @@ public class DeviceSupplierService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
DeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -87,32 +77,10 @@ public class DeviceSupplierService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.deviceWorkOrder.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.deviceWorkOrder.dto.CreateDeviceWorkOrderDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrder.dto.DeviceWorkOrderDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrder.dto.UpdateDeviceWorkOrderDto;
|
||||
@@ -48,13 +47,9 @@ public class DeviceWorkOrderService
|
||||
|
||||
public DeviceWorkOrderDto update(UpdateDeviceWorkOrderDto request) {
|
||||
DeviceWorkOrderEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
DeviceWorkOrderEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
|
||||
@@ -70,14 +65,9 @@ public class DeviceWorkOrderService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
DeviceWorkOrderEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -100,32 +90,10 @@ public class DeviceWorkOrderService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceWorkOrderEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceWorkOrderEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.deviceWorkOrderDetail.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.deviceWorkOrderDetail.dto.CreateDeviceWorkOrderDetailDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrderDetail.dto.DeviceWorkOrderDetailDto;
|
||||
import cn.lihongjie.coal.deviceWorkOrderDetail.dto.UpdateDeviceWorkOrderDetailDto;
|
||||
@@ -42,13 +41,9 @@ public class DeviceWorkOrderDetailService
|
||||
|
||||
public DeviceWorkOrderDetailDto update(UpdateDeviceWorkOrderDetailDto request) {
|
||||
DeviceWorkOrderDetailEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
DeviceWorkOrderDetailEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -57,14 +52,9 @@ public class DeviceWorkOrderDetailService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
DeviceWorkOrderDetailEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -87,32 +77,10 @@ public class DeviceWorkOrderDetailService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceWorkOrderDetailEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
DeviceWorkOrderDetailEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.entity.CommonEntity;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDevice.client.DustApi;
|
||||
import cn.lihongjie.coal.emDevice.dto.CreateEmDeviceDto;
|
||||
@@ -62,13 +61,9 @@ public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceReposit
|
||||
|
||||
public EmDeviceDto update(UpdateEmDeviceDto request) {
|
||||
EmDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -77,14 +72,9 @@ public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceReposit
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -107,33 +97,11 @@ public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceReposit
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
|
||||
@Autowired DustApi dustApi;
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.emDeviceSupplier.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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.CreateEmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
@@ -45,13 +44,9 @@ public class EmDeviceSupplierService
|
||||
|
||||
public EmDeviceSupplierDto update(UpdateEmDeviceSupplierDto request) {
|
||||
EmDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -60,14 +55,9 @@ public class EmDeviceSupplierService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -90,32 +80,10 @@ public class EmDeviceSupplierService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.empSalary.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.empSalary.dto.CreateEmpSalaryDto;
|
||||
import cn.lihongjie.coal.empSalary.dto.EmpSalaryDto;
|
||||
import cn.lihongjie.coal.empSalary.dto.UpdateEmpSalaryDto;
|
||||
@@ -41,13 +40,9 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
|
||||
public EmpSalaryDto update(UpdateEmpSalaryDto request) {
|
||||
EmpSalaryEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmpSalaryEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -56,14 +51,9 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmpSalaryEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -86,32 +76,10 @@ public class EmpSalaryService extends BaseService<EmpSalaryEntity, EmpSalaryRepo
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmpSalaryEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmpSalaryEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.empSalaryBatch.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.empSalaryBatch.dto.CreateEmpSalaryBatchDto;
|
||||
import cn.lihongjie.coal.empSalaryBatch.dto.EmpSalaryBatchDto;
|
||||
import cn.lihongjie.coal.empSalaryBatch.dto.UpdateEmpSalaryBatchDto;
|
||||
@@ -42,13 +41,9 @@ public class EmpSalaryBatchService
|
||||
|
||||
public EmpSalaryBatchDto update(UpdateEmpSalaryBatchDto request) {
|
||||
EmpSalaryBatchEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmpSalaryBatchEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -57,14 +52,9 @@ public class EmpSalaryBatchService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmpSalaryBatchEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -87,32 +77,10 @@ public class EmpSalaryBatchService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmpSalaryBatchEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmpSalaryBatchEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.employeeRecord.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.employeeRecord.dto.CreateEmployeeRecordDto;
|
||||
import cn.lihongjie.coal.employeeRecord.dto.EmployeeRecordDto;
|
||||
import cn.lihongjie.coal.employeeRecord.dto.UpdateEmployeeRecordDto;
|
||||
@@ -42,13 +41,9 @@ public class EmployeeRecordService
|
||||
|
||||
public EmployeeRecordDto update(UpdateEmployeeRecordDto request) {
|
||||
EmployeeRecordEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
EmployeeRecordEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -57,14 +52,9 @@ public class EmployeeRecordService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
EmployeeRecordEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -87,32 +77,10 @@ public class EmployeeRecordService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmployeeRecordEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
EmployeeRecordEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
@@ -49,13 +48,9 @@ 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("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
@@ -66,15 +61,9 @@ 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("数据 " + "已归档,无法删除");
|
||||
});
|
||||
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -99,33 +88,11 @@ public class MeterLogService extends BaseService<MeterLogEntity, MeterLogReposit
|
||||
}
|
||||
|
||||
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);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
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);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.pdcDevice.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.common.Ctx;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
@@ -83,13 +82,9 @@ public class PdcDeviceService extends BaseService<PdcDeviceEntity, PdcDeviceRepo
|
||||
|
||||
public PdcDeviceDto update(UpdatePdcDeviceDto request) {
|
||||
PdcDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
long count =
|
||||
this.repository.count(
|
||||
@@ -127,14 +122,10 @@ public class PdcDeviceService extends BaseService<PdcDeviceEntity, PdcDeviceRepo
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
@@ -164,33 +155,15 @@ public class PdcDeviceService extends BaseService<PdcDeviceEntity, PdcDeviceRepo
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
|
||||
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
|
||||
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
|
||||
public List<String> deviceGroups() {
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.pdcDeviceSupplier.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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.CreatePdcDeviceSupplierDto;
|
||||
@@ -45,13 +44,9 @@ public class PdcDeviceSupplierService
|
||||
|
||||
public PdcDeviceSupplierDto update(UpdatePdcDeviceSupplierDto request) {
|
||||
PdcDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -60,15 +55,9 @@ public class PdcDeviceSupplierService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
if (this.repository.isLinked(request.getIds())){
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
@@ -95,32 +84,10 @@ public class PdcDeviceSupplierService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.lihongjie.coal.weightDeviceData.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.common.JpaUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
@@ -62,13 +61,9 @@ public class WeightDeviceDataService
|
||||
|
||||
public WeightDeviceDataDto update(UpdateWeightDeviceDataDto request) {
|
||||
WeightDeviceDataEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
WeightDeviceDataEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
if (this.repository.containArchived(request.getId())){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
@@ -77,14 +72,9 @@ public class WeightDeviceDataService
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
WeightDeviceDataEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
if (this.repository.containArchived(request)){
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -107,33 +97,11 @@ public class WeightDeviceDataService
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
WeightDeviceDataEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
WeightDeviceDataEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
|
||||
public Page report(WeightDeviceDataReportRequest request) {
|
||||
|
||||
Reference in New Issue
Block a user