108 lines
5.3 KiB
PHP
108 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* 基础数据迁移
|
|
*/
|
|
namespace app\migrate\controller;
|
|
|
|
use app\admin\controller\Base;
|
|
use think\Db;
|
|
|
|
class Basis extends Base
|
|
{
|
|
/* 宗地相关数据迁移--需要运行脚本 */
|
|
public function zongdiInfoScript ()
|
|
{
|
|
set_time_limit(0);
|
|
$data = Db::name('old_app_report_detail')->distinct(true)->field('parcel_number')->select();
|
|
$i = 0;
|
|
$j = 0;
|
|
Db::startTrans();
|
|
foreach ($data as $key=>$value) {
|
|
if ($value['parcel_number'] && strlen($value['parcel_number'] < 20)) {
|
|
$i++;
|
|
$res = Db::name('old_app_report_detail')
|
|
->distinct(false)
|
|
->where(['parcel_number'=>$value['parcel_number']])
|
|
->where('near_estate', 'not null')
|
|
->field([
|
|
'appreport_id', // 2017110200044
|
|
'parcel_number', // 宗地号
|
|
'parcel_area', // 宗地面积
|
|
'near_estate', // 毗邻物业
|
|
'bus_station', // 公交线路
|
|
'four_come', // 四至
|
|
'config_facilities', // 公共服务设施
|
|
'hourse_special_illustration' // 楼盘介绍
|
|
])
|
|
->order('appreport_id desc')
|
|
->find();
|
|
if ($res) {
|
|
$j++;
|
|
$ins_data = [
|
|
'parcel_no' => $res['parcel_number'],
|
|
'parcel_area' => $res['parcel_area'],
|
|
'adjacent_property' => $res['near_estate'],
|
|
'bus_lines' => $res['bus_station'],
|
|
'boundaries' => $res['four_come'],
|
|
'pub_serv' => $res['config_facilities'],
|
|
'property_intro' => $res['hourse_special_illustration'],
|
|
'addtime' => date('Y-m-d H:i:s')
|
|
];
|
|
try {
|
|
Db::name('zongdi_info')->insert($ins_data);
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
file_put_contents('migrate.log', '迁移结果:失败'.PHP_EOL.'迁移时间:'.date('Y-m-d H:i:s').PHP_EOL.'迁移内容:宗地相关信息数据迁移'.PHP_EOL.'迁移失败宗地号:'.$res['parcel_number'].PHP_EOL.'数据记录数:'.$i.PHP_EOL.'有效迁移记录数:'.$j.PHP_EOL.'错误信息:'.$e->getMessage().PHP_EOL, FILE_APPEND);
|
|
return $this->buildFailed('宗地信息迁移失败', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Db::commit();
|
|
file_put_contents('migrate.log', '迁移结果:成功'.PHP_EOL.'迁移时间:'.date('Y-m-d H:i:s').PHP_EOL.'迁移内容:宗地相关信息数据迁移'.PHP_EOL.'数据总记录数:'.$i.PHP_EOL.'有效迁移记录数:'.$j.PHP_EOL, FILE_APPEND);
|
|
return $this->buildSuccess('', '宗地信息迁移成功');
|
|
}
|
|
|
|
/* 宗地相关数据迁移--生成SQL文件 */
|
|
public function zongdiInfoSQL ()
|
|
{
|
|
set_time_limit(0);
|
|
$data = Db::name('old_app_report_detail')->distinct(true)->field('parcel_number')->select();
|
|
$i = 0;
|
|
$j = 0;
|
|
$sql = 'INSERT INTO `pg_zongdi_info` (`parcel_no`, `parcel_area`, `adjacent_property`, `bus_lines`, `boundaries`, `pub_serv`, `property_intro`, `addtime`) VALUES ';
|
|
foreach ($data as $key=>$value) {
|
|
if ($value['parcel_number'] && strlen($value['parcel_number'] < 20)) {
|
|
$i++;
|
|
$res = Db::name('old_app_report_detail')
|
|
->distinct(false)
|
|
->where(['parcel_number'=>$value['parcel_number']])
|
|
->where('near_estate', 'not null')
|
|
->field([
|
|
'appreport_id', // 2017110200044
|
|
'parcel_number', // 宗地号
|
|
'parcel_area', // 宗地面积
|
|
'near_estate', // 毗邻物业
|
|
'bus_station', // 公交线路
|
|
'four_come', // 四至
|
|
'config_facilities', // 公共服务设施
|
|
'hourse_special_illustration' // 楼盘介绍
|
|
])
|
|
->order('appreport_id desc')
|
|
->find();
|
|
if ($res) {
|
|
if ($j==0) {
|
|
$sql .= '("'.$res['parcel_number'].'", "'.$res['parcel_area'].'", "'.$res['near_estate'].'", "'.$res['bus_station'].'", "'.$res['four_come'].'", "'.$res['config_facilities'].'", "'.$res['hourse_special_illustration'].'", "'.date('Y-m-d H:i:s').'")';
|
|
} else {
|
|
$sql .= ',("'.$res['parcel_number'].'", "'.$res['parcel_area'].'", "'.$res['near_estate'].'", "'.$res['bus_station'].'", "'.$res['four_come'].'", "'.$res['config_facilities'].'", "'.$res['hourse_special_illustration'].'", "'.date('Y-m-d H:i:s').'")';
|
|
}
|
|
$j++;
|
|
}
|
|
}
|
|
}
|
|
$sql .= ';';
|
|
file_put_contents('pg_zongdi_info.sql', $sql);
|
|
return $this->buildSuccess('', '宗地信息迁移成功=='.$i.'=='.$j);
|
|
}
|
|
}
|