setPlantId($cropInfoDto->id); $dataLand->setSeedId($cropInfoDto->seedId); // 设置种植时间 if (!empty($cropInfoDto->plantTime)) { // 如果plantTime是字符串格式的日期时间,转换为时间戳 if (is_string($cropInfoDto->plantTime)) { $plantTime = strtotime($cropInfoDto->plantTime); $dataLand->setSeedPlantingTimes($plantTime); } // 如果已经是时间戳,直接使用 else if (is_numeric($cropInfoDto->plantTime)) { $dataLand->setSeedPlantingTimes($cropInfoDto->plantTime); } } // 当前阶段开始时间 if (!empty($cropInfoDto->stageStartTime)) { // 如果 stageStartTime 是字符串格式的日期时间,转换为时间戳 if (is_string($cropInfoDto->stageStartTime)) { $stageStartTime = strtotime($cropInfoDto->stageEndTime); $dataLand->setStageNextTimes($stageStartTime); } // 如果已经是时间戳,直接使用 else if (is_numeric($cropInfoDto->stageStartTime)) { $dataLand->setStageNextTimes($cropInfoDto->stageStartTime); } } // 下一个阶段的时间 if (!empty($cropInfoDto->stageEndTime)) { // 如果stageEndTime是字符串格式的日期时间,转换为时间戳 if (is_string($cropInfoDto->stageEndTime)) { $stageEndTime = strtotime($cropInfoDto->stageEndTime); $dataLand->setStageNextTimes($stageEndTime); } // 如果已经是时间戳,直接使用 else if (is_numeric($cropInfoDto->stageEndTime)) { $dataLand->setStageNextTimes($cropInfoDto->stageEndTime); } } // 设置种子状态,这里需要将Farm模块的生长阶段映射到Proto的种子状态 // 假设我们有一个映射关系,这里简单地直接使用生长阶段值 $dataLand->setSeedStatus($cropInfoDto->growthStage); // 检查是否有灾害 if (!empty($cropInfoDto->disasters)) { foreach ($cropInfoDto->disasters as $disaster) { // 根据灾害类型设置相应的标志 if (isset($disaster['type'])) { switch ($disaster['type']) { case 1: // 假设1表示杂草 $dataLand->setNeedWeed(true); break; case 2: // 假设2表示虫害 $dataLand->setNeedPestControl(true); break; case 3: // 假设3表示缺水 $dataLand->setNeedWatering(true); break; } } } } // 检查是否可以施肥 $dataLand->setCanFertilization(!$cropInfoDto->fertilized); return $dataLand; } }