|
|
|
@ -151,6 +151,10 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
@@ -151,6 +151,10 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
|
|
|
|
|
//初识化专业id |
|
|
|
|
$speciality_id = 0; |
|
|
|
|
|
|
|
|
|
if(!array_key_exists(trim($item["二级学院"]), $secondaryCollegeList)){ |
|
|
|
|
throw new \Exception("识别失败,找不到【二级学院】--".trim($item["二级学院"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//取出指定学院下面的专业 |
|
|
|
|
$specialityInfo = Speciality::query()->where([ |
|
|
|
|
"secondary_college_id" => $secondaryCollegeList[trim($item["二级学院"])]["id"], |
|
|
|
@ -163,8 +167,9 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
@@ -163,8 +167,9 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
|
|
|
|
|
|
|
|
|
|
//专业ID为空时提示 |
|
|
|
|
if(empty($speciality_id)){ |
|
|
|
|
throw new \Exception("识别失败,请检查二级学院或专业名称是否和后台录入的一致"); |
|
|
|
|
throw new \Exception("识别失败,请检查二级学院或专业名称是否和后台录入的一致,请检查第".($key+1)."行的学院及专业:".$item["二级学院"]."--".$item["专业名称"]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//专业id |
|
|
|
|
$arr["speciality_id"] = $speciality_id; |
|
|
|
|
|
|
|
|
@ -185,22 +190,39 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
@@ -185,22 +190,39 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
|
|
|
|
|
$arr["multiple_worlds"] = $multipleWorlds->id; |
|
|
|
|
|
|
|
|
|
//生活区id |
|
|
|
|
$arr["living_area"] = $livingAreaList[trim($item["生活区"])]["id"]; |
|
|
|
|
|
|
|
|
|
if(array_key_exists(trim($item["生活区"]), $livingAreaList)){ |
|
|
|
|
$arr["living_area"] = $livingAreaList[trim($item["生活区"])]["id"]; |
|
|
|
|
}else{ |
|
|
|
|
throw new \Exception("识别失败,找不到【生活区】--".trim($item["生活区"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//楼栋id |
|
|
|
|
$arr["building_id"] = $buildingList[trim($item["楼栋"])]["id"]; |
|
|
|
|
|
|
|
|
|
if(array_key_exists(trim($item["楼栋"]), $buildingList)){ |
|
|
|
|
$arr["building_id"] = $buildingList[trim($item["楼栋"])]["id"]; |
|
|
|
|
}else{ |
|
|
|
|
throw new \Exception("识别失败,找不到【楼栋】--".trim($item["楼栋"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//楼层id |
|
|
|
|
$arr["floor_id"] = $floorList[trim($item["楼层"])]["id"]; |
|
|
|
|
|
|
|
|
|
if(array_key_exists(trim($item["楼层"]), $floorList)){ |
|
|
|
|
$arr["floor_id"] = $floorList[trim($item["楼层"])]["id"]; |
|
|
|
|
}else{ |
|
|
|
|
throw new \Exception("识别失败,找不到【楼层】--".trim($item["楼层"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//宿舍号id |
|
|
|
|
$arr["dormitory_number"] = $dormitoryNumberList[trim($item["宿舍号"])]["id"]; |
|
|
|
|
if(array_key_exists(trim($item["宿舍号"]), $dormitoryNumberList)){ |
|
|
|
|
$arr["dormitory_number"] = $dormitoryNumberList[trim($item["宿舍号"])]["id"]; |
|
|
|
|
}else{ |
|
|
|
|
throw new \Exception("识别失败,找不到【宿舍号】--".trim($item["宿舍号"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//床位id |
|
|
|
|
$arr["bed_id"] = $bedList[trim($item["床位号"])]["id"]; |
|
|
|
|
if(array_key_exists(trim($item["床位号"]), $bedList)){ |
|
|
|
|
$arr["bed_id"] = $bedList[trim($item["床位号"])]["id"]; |
|
|
|
|
}else{ |
|
|
|
|
throw new \Exception("识别失败,找不到【床位号】--".trim($item["床位号"])."--第".($key+2)."行"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//走读生 |
|
|
|
|
if(trim($item["走读生"]) == "是"){ |
|
|
|
@ -223,14 +245,25 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
@@ -223,14 +245,25 @@ class BedFirstSheetImport implements ToCollection, WithBatchInserts, WithChunkRe
|
|
|
|
|
foreach ($chunk_list as $new_list) { |
|
|
|
|
$add = AllocationDormitoryBed::query()->insert($new_list); |
|
|
|
|
if($add != count($insertData)){ |
|
|
|
|
throw new \Exception("导入数据失败,请重试"); |
|
|
|
|
throw new \Exception("导入数据失败1,请重试"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
}catch (\PDOException $e){ |
|
|
|
|
DB::rollBack(); |
|
|
|
|
if ($e->getCode() === '23000') { |
|
|
|
|
// 唯一性约束错误处理逻辑 |
|
|
|
|
$errorMessage = "导入表格中存在已入库学生信息,请勿重复导入"; |
|
|
|
|
// 可以根据需要进行相关处理 |
|
|
|
|
throw new \Exception($errorMessage); |
|
|
|
|
} else { |
|
|
|
|
// 其他类型的错误处理逻辑 |
|
|
|
|
throw new \Exception("导入数据失败2,请重试"); |
|
|
|
|
} |
|
|
|
|
}catch (\Exception $e){ |
|
|
|
|
DB::rollBack(); |
|
|
|
|
throw new \Exception("导入数据失败,请重试"); |
|
|
|
|
throw new \Exception("导入数据失败3,请重试"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|