|
@@ -345,6 +345,7 @@ class Vehicle extends CatchController
|
|
|
$total = 0; //总共设备数
|
|
|
$data = []; //设备数据
|
|
|
//循环读取每一张表
|
|
|
+ $conn=getOracleConnect();
|
|
|
for ($index = 0; $index < $sheetCount; $index++) {
|
|
|
//设置当前要读取的表
|
|
|
$sheet = $objPHPExcel->getSheet($index); //excel中的第一张sheet
|
|
@@ -357,13 +358,23 @@ class Vehicle extends CatchController
|
|
|
$brand_type_id = Db::table("sys_dict_type")->where('code', 'CAR_BRAND_OPTION')->value('id');
|
|
|
$car_type_id = Db::table("sys_dict_type")->where('code', 'CAR_TYPE_OPTION')->value('id');
|
|
|
|
|
|
- // return $this->where('type_id', $type_id)
|
|
|
- // ->where('code', $value)
|
|
|
- // ->cache(true, 60)
|
|
|
- // ->value('remark');
|
|
|
|
|
|
- // $r=$this->execSaveVehicle($param);
|
|
|
$total += $highestRow - 1;
|
|
|
+ // $sql='declare
|
|
|
+ // tagId number;
|
|
|
+ // begin
|
|
|
+ // INSERT INTO DSSC3.W_DW_RFID_TAGS("ID", "RFID_SN","INSTALLER","INSTA_DATE") VALUES (DSSC3.SEQ_W_DW_RFID_TAGS.nextval, \''.$arr['RFID_SN'].'\',\''.$arr['INSTALLER'].'\', TO_DATE(\''.$arr['INSTA_DATE'].'\', \'SYYYY-MM-DD HH24:MI:SS\')) returning ID into tagId;
|
|
|
+ // INSERT INTO DSSC3.W_DW_NON_MOTOR("ID", "RFID_ID","PLATE_NO","CAR_BRAND","CAR_TYPE") VALUES (DSSC3.SEQ_W_DW_RFID_TAGS.nextval, tagId,\''.$arr['PLATE_NO'].'\',\''.$arr['CAR_BRAND'].'\',\''.$arr['CAR_TYPE'].'\');
|
|
|
+ // end;';
|
|
|
+ // 预编译SQL语句
|
|
|
+ $sql='declare
|
|
|
+ tagId number;
|
|
|
+ begin
|
|
|
+ INSERT INTO DSSC3.W_DW_RFID_TAGS("ID", "RFID_SN","INSTALLER","INSTA_DATE") VALUES (DSSC3.SEQ_W_DW_RFID_TAGS.nextval, :col1,:col2, TO_DATE(:col3, \'SYYYY-MM-DD HH24:MI:SS\')) returning ID into tagId;
|
|
|
+ INSERT INTO DSSC3.W_DW_NON_MOTOR("ID", "RFID_ID","PLATE_NO","CAR_BRAND","CAR_TYPE") VALUES (DSSC3.SEQ_W_DW_RFID_TAGS.nextval, tagId,:col4,:col5,:col6);
|
|
|
+ end;';
|
|
|
+ $stmt = oci_parse($conn, $sql);
|
|
|
+ $start=2;
|
|
|
for ($j = 2; $j <= $highestRow; $j++) {
|
|
|
$arr = array(); //每条设备信息
|
|
|
$arr['PLATE_NO'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue()));
|
|
@@ -377,28 +388,40 @@ class Vehicle extends CatchController
|
|
|
$arr['RFID_SN'] = trim($sheet->getCell("D" . $j)->getFormattedValue());
|
|
|
$arr['INSTA_DATE'] = trim($sheet->getCell("E" . $j)->getFormattedValue());
|
|
|
$arr['INSTALLER'] = trim($sheet->getCell("F" . $j)->getFormattedValue());
|
|
|
- // var_dump($arr);
|
|
|
- $r=$this->execSaveVehicle($arr);
|
|
|
- if($r){
|
|
|
- $arr['DATA_TYPE']='vehicle_save';
|
|
|
- pushDataToRedisList($arr);
|
|
|
- $success++;
|
|
|
- }else{
|
|
|
- $fail++;
|
|
|
+
|
|
|
+ //变量绑定
|
|
|
+ oci_bind_by_name($stmt, ':col1', $arr['RFID_SN']);
|
|
|
+ oci_bind_by_name($stmt, ':col2', $arr['INSTALLER']);
|
|
|
+ oci_bind_by_name($stmt, ':col3', $arr['INSTA_DATE']);
|
|
|
+ oci_bind_by_name($stmt, ':col4', $arr['PLATE_NO']);
|
|
|
+ oci_bind_by_name($stmt, ':col5', $arr['CAR_BRAND']);
|
|
|
+ oci_bind_by_name($stmt, ':col6', $arr['CAR_TYPE']);
|
|
|
+
|
|
|
+ // 添加到批处理
|
|
|
+ oci_execute($stmt, OCI_DEFAULT);
|
|
|
+
|
|
|
+ $arr['DATA_TYPE']='vehicle_save';
|
|
|
+ pushDataToRedisList($arr);
|
|
|
+ if( ($j%1000 == 0) || $j==$highestRow){
|
|
|
+ // 提交事务
|
|
|
+ $res=oci_commit($conn);
|
|
|
+ if($res){
|
|
|
+ $success+=$j-$start;
|
|
|
+ }else{
|
|
|
+ $fail+=$j-$start;
|
|
|
+ }
|
|
|
+ $start=$j;
|
|
|
}
|
|
|
- // var_dump($arr);
|
|
|
- // array_push($data,$arr);
|
|
|
+
|
|
|
}
|
|
|
+ // 释放资源
|
|
|
+ oci_free_statement($stmt);
|
|
|
}
|
|
|
- // array_unique($data, SORT_REGULAR);
|
|
|
- // // var_dump($data);return CatchResponse::success();
|
|
|
- // $count = $this->deviceModel->limit(100)->insertAll($data);
|
|
|
- // if ($success = $count) {
|
|
|
-
|
|
|
- return CatchResponse::success('共' . $total . '条数据,成功' . $success . '条,失败' . $fail . '条');
|
|
|
+ //关闭连接
|
|
|
+ oci_close($conn);
|
|
|
+ return CatchResponse::success('共' . $total . '条数据,成功' . $success . '条,失败' . $fail . '条');
|
|
|
|
|
|
- // }
|
|
|
- // return CatchResponse::success(['error' => true, 'msg' => '导入失败']);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|