From 701b706f1252b29e45afe8c3dd70e40afc67cbc7 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 20 Apr 2024 14:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BD=92=E6=A1=A3=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/lihongjie/coal/Codegen.java | 61 +++------- .../service/AcAppointmentService.java | 59 ++-------- .../acDevice/service/AcDeviceService.java | 48 ++------ .../service/AcDeviceSupplierService.java | 48 ++------ .../coal/base/dao/BaseRepository.java | 104 +++++++++++++++++- .../service/CoalAnalysisService.java | 36 ++---- .../CoalWashingDailyAnalysisService.java | 32 ++---- .../lihongjie/coal/common/ArchiveUtils.java | 33 ------ .../coal/device/service/DeviceService.java | 48 ++------ .../service/DeviceSupplierService.java | 48 ++------ .../service/DeviceWorkOrderService.java | 48 ++------ .../service/DeviceWorkOrderDetailService.java | 48 ++------ .../emDevice/service/EmDeviceService.java | 48 ++------ .../service/EmDeviceSupplierService.java | 48 ++------ .../empSalary/service/EmpSalaryService.java | 48 ++------ .../service/EmpSalaryBatchService.java | 48 ++------ .../service/EmployeeRecordService.java | 48 ++------ .../meterLog/service/MeterLogService.java | 49 ++------- .../pdcDevice/service/PdcDeviceService.java | 53 +++------ .../service/PdcDeviceSupplierService.java | 49 ++------- .../service/WeightDeviceDataService.java | 48 ++------ 21 files changed, 272 insertions(+), 780 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/Codegen.java b/src/main/java/cn/lihongjie/coal/Codegen.java index 40bee7e7..9d25df13 100644 --- a/src/main/java/cn/lihongjie/coal/Codegen.java +++ b/src/main/java/cn/lihongjie/coal/Codegen.java @@ -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(); } diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java b/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java index ea772bb4..a5efc3ad 100644 --- a/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java +++ b/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java @@ -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 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 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); } } diff --git a/src/main/java/cn/lihongjie/coal/acDevice/service/AcDeviceService.java b/src/main/java/cn/lihongjie/coal/acDevice/service/AcDeviceService.java index 065977c5..dbda60f1 100644 --- a/src/main/java/cn/lihongjie/coal/acDevice/service/AcDeviceService.java +++ b/src/main/java/cn/lihongjie/coal/acDevice/service/AcDeviceService.java @@ -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 "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 "0", - (e, actual, expected) -> { - throw new BizException("数据 " + "已归档,无法删除"); - }); + if (this.repository.containArchived(request)){ + throw new BizException("部分数据已归档,无法编辑或删除"); + } if (acDeviceDataService.count( (Specification) @@ -121,32 +111,10 @@ public class AcDeviceService extends BaseService - 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); } } diff --git a/src/main/java/cn/lihongjie/coal/acDeviceSupplier/service/AcDeviceSupplierService.java b/src/main/java/cn/lihongjie/coal/acDeviceSupplier/service/AcDeviceSupplierService.java index 219fc68b..167fa864 100644 --- a/src/main/java/cn/lihongjie/coal/acDeviceSupplier/service/AcDeviceSupplierService.java +++ b/src/main/java/cn/lihongjie/coal/acDeviceSupplier/service/AcDeviceSupplierService.java @@ -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) (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); } } diff --git a/src/main/java/cn/lihongjie/coal/base/dao/BaseRepository.java b/src/main/java/cn/lihongjie/coal/base/dao/BaseRepository.java index 73c9c390..94ec7cf2 100644 --- a/src/main/java/cn/lihongjie/coal/base/dao/BaseRepository.java +++ b/src/main/java/cn/lihongjie/coal/base/dao/BaseRepository.java @@ -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 extends JpaRepository, JpaSpecific return findById(id).orElseThrow(() -> new RuntimeException("数据不存在: " + id)); } - + + default void archive(IdRequest request){ + + if (request.getIds() == null || request.getIds().isEmpty()){ + return; + } + + List 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 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 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 findByOrganizationId(String organizationId) { return findAll( diff --git a/src/main/java/cn/lihongjie/coal/coalAnalysis/service/CoalAnalysisService.java b/src/main/java/cn/lihongjie/coal/coalAnalysis/service/CoalAnalysisService.java index 0445e71d..a9e784b5 100644 --- a/src/main/java/cn/lihongjie/coal/coalAnalysis/service/CoalAnalysisService.java +++ b/src/main/java/cn/lihongjie/coal/coalAnalysis/service/CoalAnalysisService.java @@ -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 "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 "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 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); } } diff --git a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java index a6d034ff..b8cead4e 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java b/src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java index e3108368..6374541e 100644 --- a/src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java +++ b/src/main/java/cn/lihongjie/coal/common/ArchiveUtils.java @@ -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 void checkArchiveStatus(Function, Iterable> mapper, Iterable ids, Function statusGetter, Function expectedStatusGetter, Function3 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 void checkArchiveStatus(E entity, Function statusGetter, Function expectedStatusGetter, Function3 handler) { - - - checkArchiveStatus( - x -> Collections.singletonList(entity), - Collections.singletonList(entity), - statusGetter, - expectedStatusGetter, - handler); - } - - } diff --git a/src/main/java/cn/lihongjie/coal/device/service/DeviceService.java b/src/main/java/cn/lihongjie/coal/device/service/DeviceService.java index 37258dde..79b50173 100644 --- a/src/main/java/cn/lihongjie/coal/device/service/DeviceService.java +++ b/src/main/java/cn/lihongjie/coal/device/service/DeviceService.java @@ -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 { 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 { } 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 { } 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); } } diff --git a/src/main/java/cn/lihongjie/coal/deviceSupplier/service/DeviceSupplierService.java b/src/main/java/cn/lihongjie/coal/deviceSupplier/service/DeviceSupplierService.java index 0dd706ab..74b355ff 100644 --- a/src/main/java/cn/lihongjie/coal/deviceSupplier/service/DeviceSupplierService.java +++ b/src/main/java/cn/lihongjie/coal/deviceSupplier/service/DeviceSupplierService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/deviceWorkOrder/service/DeviceWorkOrderService.java b/src/main/java/cn/lihongjie/coal/deviceWorkOrder/service/DeviceWorkOrderService.java index df72c5c9..38ef4dbc 100644 --- a/src/main/java/cn/lihongjie/coal/deviceWorkOrder/service/DeviceWorkOrderService.java +++ b/src/main/java/cn/lihongjie/coal/deviceWorkOrder/service/DeviceWorkOrderService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/deviceWorkOrderDetail/service/DeviceWorkOrderDetailService.java b/src/main/java/cn/lihongjie/coal/deviceWorkOrderDetail/service/DeviceWorkOrderDetailService.java index 1919859d..bbafb820 100644 --- a/src/main/java/cn/lihongjie/coal/deviceWorkOrderDetail/service/DeviceWorkOrderDetailService.java +++ b/src/main/java/cn/lihongjie/coal/deviceWorkOrderDetail/service/DeviceWorkOrderDetailService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/emDevice/service/EmDeviceService.java b/src/main/java/cn/lihongjie/coal/emDevice/service/EmDeviceService.java index 0ee6f6f3..64d3a2c7 100644 --- a/src/main/java/cn/lihongjie/coal/emDevice/service/EmDeviceService.java +++ b/src/main/java/cn/lihongjie/coal/emDevice/service/EmDeviceService.java @@ -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 "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 "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 - 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; diff --git a/src/main/java/cn/lihongjie/coal/emDeviceSupplier/service/EmDeviceSupplierService.java b/src/main/java/cn/lihongjie/coal/emDeviceSupplier/service/EmDeviceSupplierService.java index 9d98acc5..37f08a02 100644 --- a/src/main/java/cn/lihongjie/coal/emDeviceSupplier/service/EmDeviceSupplierService.java +++ b/src/main/java/cn/lihongjie/coal/emDeviceSupplier/service/EmDeviceSupplierService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java index b4edd5cb..3ccae7cd 100644 --- a/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java +++ b/src/main/java/cn/lihongjie/coal/empSalary/service/EmpSalaryService.java @@ -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 "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 "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 - 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); } } diff --git a/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java b/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java index 0fd47dde..9c932f35 100644 --- a/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java +++ b/src/main/java/cn/lihongjie/coal/empSalaryBatch/service/EmpSalaryBatchService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/employeeRecord/service/EmployeeRecordService.java b/src/main/java/cn/lihongjie/coal/employeeRecord/service/EmployeeRecordService.java index 28f1ef22..44e8690a 100644 --- a/src/main/java/cn/lihongjie/coal/employeeRecord/service/EmployeeRecordService.java +++ b/src/main/java/cn/lihongjie/coal/employeeRecord/service/EmployeeRecordService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/meterLog/service/MeterLogService.java b/src/main/java/cn/lihongjie/coal/meterLog/service/MeterLogService.java index 8a3ece14..5c2fd605 100644 --- a/src/main/java/cn/lihongjie/coal/meterLog/service/MeterLogService.java +++ b/src/main/java/cn/lihongjie/coal/meterLog/service/MeterLogService.java @@ -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 "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 "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 - 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); } diff --git a/src/main/java/cn/lihongjie/coal/pdcDevice/service/PdcDeviceService.java b/src/main/java/cn/lihongjie/coal/pdcDevice/service/PdcDeviceService.java index bdcd7866..8c1daf63 100644 --- a/src/main/java/cn/lihongjie/coal/pdcDevice/service/PdcDeviceService.java +++ b/src/main/java/cn/lihongjie/coal/pdcDevice/service/PdcDeviceService.java @@ -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 "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 "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 - 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 deviceGroups() { diff --git a/src/main/java/cn/lihongjie/coal/pdcDeviceSupplier/service/PdcDeviceSupplierService.java b/src/main/java/cn/lihongjie/coal/pdcDeviceSupplier/service/PdcDeviceSupplierService.java index a142b0f1..d367bc69 100644 --- a/src/main/java/cn/lihongjie/coal/pdcDeviceSupplier/service/PdcDeviceSupplierService.java +++ b/src/main/java/cn/lihongjie/coal/pdcDeviceSupplier/service/PdcDeviceSupplierService.java @@ -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); } } diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java index 63baf47f..ca672b3c 100644 --- a/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java @@ -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) {