From fed3313e287914e24a154852acf62daee02e1741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=BE=E5=90=9B=E7=A6=B9?= <2673609096@qq.com> Date: Thu, 28 Aug 2025 09:28:36 +0800 Subject: [PATCH] =?UTF-8?q?farm=E6=A8=A1=E5=9D=97-=E5=9C=B0=E5=9D=97?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CropFarmingCenterServiceImpl.java | 71 +++++++++++-------- .../service/plotinfo/PlotInfoService.java | 1 + .../service/plotinfo/PlotInfoServiceImpl.java | 30 ++++---- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/cropFarmingCenter/CropFarmingCenterServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/cropFarmingCenter/CropFarmingCenterServiceImpl.java index 9d3448b7..6de301b5 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/cropFarmingCenter/CropFarmingCenterServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/cropFarmingCenter/CropFarmingCenterServiceImpl.java @@ -8,10 +8,11 @@ import cn.iocoder.yudao.module.farm.controller.admin.cropFarmingCenter.vo.*; import cn.iocoder.yudao.module.farm.controller.admin.farmingrecord.vo.FarmingRecordSaveReqVO; import cn.iocoder.yudao.module.farm.controller.admin.farmingrecordinput.vo.FarmingRecordInputSaveReqVO; import cn.iocoder.yudao.module.farm.controller.admin.modelcycle.vo.ModelCycleRespVO; -import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.ModelManagementRespVO; import cn.iocoder.yudao.module.farm.controller.admin.modelfarmingoperation.vo.ModelFarmingOperationRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.ModelManagementRespVO; import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO; import cn.iocoder.yudao.module.farm.dal.dataobject.modelfarmingoperationinput.ModelFarmingOperationInputDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO; import cn.iocoder.yudao.module.farm.dal.dataobject.productionplan.ProductionPlanDO; import cn.iocoder.yudao.module.farm.dal.mysql.baseinfo.BaseInfoMapper; import cn.iocoder.yudao.module.farm.dal.mysql.productionplan.ProductionPlanMapper; @@ -19,8 +20,10 @@ import cn.iocoder.yudao.module.farm.enums.CommonConstants; import cn.iocoder.yudao.module.farm.service.farmingrecord.FarmingRecordService; import cn.iocoder.yudao.module.farm.service.farmingrecordinput.FarmingRecordInputService; import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementService; +import cn.iocoder.yudao.module.farm.service.plotinfo.PlotInfoService; import cn.iocoder.yudao.module.farm.utils.StrHelperUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -49,28 +52,24 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { private final ModelManagementService modelManagementService; private final FarmingRecordService farmingRecordService; private final FarmingRecordInputService farmingRecordInputService; + private final PlotInfoService plotInfoService; public CropFarmingCenterServiceImpl(BaseInfoMapper baseInfoMapper, ProductionPlanMapper productionPlanMapper, ModelManagementService modelManagementService, FarmingRecordService farmingRecordService, - FarmingRecordInputService farmingRecordInputService) { + FarmingRecordInputService farmingRecordInputService, PlotInfoService plotInfoService) { this.baseInfoMapper = baseInfoMapper; this.productionPlanMapper = productionPlanMapper; this.modelManagementService = modelManagementService; this.farmingRecordService = farmingRecordService; this.farmingRecordInputService = farmingRecordInputService; + this.plotInfoService = plotInfoService; } @Override public void createProductionPlan(ProductionPlanSaveReqVO reqVO) { - String taskId = IdUtil.fastUUID(); - String speciesModelId = reqVO.getSpeciesModelId(); - // 创建模型案例 - speciesModelId = modelManagementService.createModelManagementCase(speciesModelId, taskId); - if (speciesModelId.equals("")) { - return; - } + String speciesModelId = reqVO.getSpeciesModelId(); List cultivationAreaList = reqVO.getCultivationAreaList(); @@ -94,38 +93,48 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { obj.setRemark(e.getRemark()); obj.setBaseId(e.getBaseId()); - obj.setBaseName(e.getBaseName()); + BaseInfoDO baseInfoDO = baseInfoMapper.selectById(e.getBaseId()); + obj.setBaseName(baseInfoDO.getName()); obj.setPlotId(e.getPlotId()); - obj.setPlotName(e.getPlotName()); - obj.setTenantId(e.getTenantId()); + PlotInfoDO plotInfo = plotInfoService.getPlotInfoByPlotId(e.getPlotId()); + obj.setPlotName(plotInfo.getPlotName()); + obj.setTenantId(getLoginUser().getTenantId().toString()); + obj.setId(IdUtil.fastUUID()); // 随机字符串 + 地块名称 obj.setPlanNumber(StrHelperUtil.generate() + "-" + e.getPlotName()); + String taskId = IdUtil.fastUUID(); obj.setId(taskId); + // 创建模型案例 + speciesModelId = modelManagementService.createModelManagementCase(speciesModelId, taskId); + if (speciesModelId.equals("")) { + return; + } + list.add(obj); } productionPlanMapper.insertBatch(list); // 根据模型生成农事记录 - for (ProductionPlanSaveReqVO.CultivationArea e : cultivationAreaList) { - generateFarmingRecordsFromModel(speciesModelId, taskId, e.getPlantingDate(), e.getBaseId(), e.getBaseName(), e.getPlotId(), e.getPlotName(), e.getTenantId()); - } +// for (ProductionPlanSaveReqVO.CultivationArea e : cultivationAreaList) { +// generateFarmingRecordsFromModel(speciesModelId, taskId, e.getPlantingDate(), e.getBaseId(), e.getBaseName(), e.getPlotId(), e.getPlotName(), e.getTenantId()); +// } } /** * 根据模型生成农事记录 - * - * @param modelId 模型ID + * + * @param modelId 模型ID * @param productionPlanId 生产计划ID - * @param plantingDate 种植日期 - * @param baseId 基地ID - * @param baseName 基地名称 - * @param plotId 地块ID - * @param plotName 地块名称 - * @param tenantId 租户ID + * @param plantingDate 种植日期 + * @param baseId 基地ID + * @param baseName 基地名称 + * @param plotId 地块ID + * @param plotName 地块名称 + * @param tenantId 租户ID */ - private void generateFarmingRecordsFromModel(String modelId, String productionPlanId, LocalDate plantingDate, - String baseId, String baseName, String plotId, String plotName, String tenantId) { + private void generateFarmingRecordsFromModel(String modelId, String productionPlanId, LocalDate plantingDate, + String baseId, String baseName, String plotId, String plotName, String tenantId) { // 获取模型信息 ModelManagementRespVO model = modelManagementService.getModelManagement(modelId); if (model == null || model.getModelCycles() == null) { @@ -137,7 +146,7 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { for (ModelCycleRespVO cycle : model.getModelCycles()) { // 计算农事操作时间(基于种植日期和周期天数) LocalDate operationDate = plantingDate.plusDays(cycle.getStage()); - + // 生成农事操作记录 if (cycle.getFarmingOperationDOS() != null) { for (ModelFarmingOperationRespVO operation : cycle.getFarmingOperationDOS()) { @@ -156,9 +165,9 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { farmingRecordReq.setBaseName(baseName); farmingRecordReq.setPlotName(plotName); farmingRecordReq.setTenantId(tenantId); - + String farmingRecordId = farmingRecordService.createFarmingRecord(farmingRecordReq); - + // 生成农事操作投入品记录 if (operation.getFarmingOperationInputDOS() != null) { for (ModelFarmingOperationInputDO input : operation.getFarmingOperationInputDOS()) { @@ -174,14 +183,14 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { inputReq.setPlotId(plotId); inputReq.setPlotName(plotName); inputReq.setTenantId(tenantId); - + farmingRecordInputService.createFarmingRecordInput(inputReq); } } } } } - + log.info("成功为生产计划 {} 生成农事记录,基于模型 {}", productionPlanId, modelId); } @@ -243,7 +252,7 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService { .collect(Collectors.toList()); long size = collect.size(); - return new PageResult<>(collect,size); + return new PageResult<>(collect, size); } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java index 1beab8d0..a4602764 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java @@ -60,4 +60,5 @@ public interface PlotInfoService { */ PageResult getPlotInfoPage(PlotInfoPageReqVO pageReqVO); + PlotInfoDO getPlotInfoByPlotId(String plotId); } \ No newline at end of file diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java index 36614c70..a3f8830c 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java @@ -1,24 +1,21 @@ package cn.iocoder.yudao.module.farm.service.plotinfo; import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoPageReqVO; -import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoSaveReqVO; -import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.security.core.LoginUser; - +import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoPageReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoSaveReqVO; +import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO; import cn.iocoder.yudao.module.farm.dal.mysql.plotinfo.PlotInfoMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.PLOT_INFO_NOT_EXISTS; @@ -65,12 +62,12 @@ public class PlotInfoServiceImpl implements PlotInfoService { } @Override - public void deletePlotInfoListByIds(List ids) { + public void deletePlotInfoListByIds(List ids) { // 删除 plotInfoMapper.deleteByIds(ids); - } + } -private void validatePlotInfoExists(String id) { + private void validatePlotInfoExists(String id) { if (plotInfoMapper.selectById(id) == null) { throw exception(PLOT_INFO_NOT_EXISTS); } @@ -91,4 +88,11 @@ private void validatePlotInfoExists(String id) { return plotInfoMapper.selectPage(pageReqVO); } + @Override + public PlotInfoDO getPlotInfoByPlotId(String plotId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PlotInfoDO::getPlotId, plotId); + return plotInfoMapper.selectOne(queryWrapper); + } + } \ No newline at end of file