Vehicle.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <?php
  2. namespace catchAdmin\yunying\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. // use catchAdmin\yunying\model\Vehicle as vehicleModel;
  7. use catchAdmin\yunying\excel\VehiclesExport;
  8. use catchAdmin\system\model\SysDictData;
  9. use catcher\Utils;
  10. use catcher\library\excel\Excel;
  11. use PhpOffice\PhpSpreadsheet\IOFactory;
  12. use think\facade\Env;
  13. use think\facade\Db;
  14. class Vehicle extends CatchController
  15. {
  16. // protected $vehicleModel;
  17. // public function __construct(VehicleModel $vehicleModel)
  18. // {
  19. // $this->vehicleModel = $vehicleModel;
  20. // }
  21. /**
  22. * 列表
  23. * @time 2022年01月20日 10:42
  24. * @param Request $request
  25. */
  26. public function index(Request $request)
  27. {
  28. $param=$request->param();
  29. //联表条件o.rfid_id = s.id and o.owner_id = r.id
  30. $cond=[
  31. '_string'=>'o.rfid_id = s.id and o.owner_id = r.id',
  32. ];
  33. if($param['PLATE_NO']){
  34. $cond['o.PLATE_NO']=['like',$param['PLATE_NO']];
  35. }
  36. if($param['ID_CARD_NUMBER']){
  37. $cond['r.ID_CARD_NUMBER']=['like',$param['ID_CARD_NUMBER']];
  38. }
  39. if($param['MOBILE_NUMBER']){
  40. $cond['r.MOBILE_NUMBER']=['like',$param['MOBILE_NUMBER']];
  41. }
  42. if($param['RFID_SN']){
  43. $cond['s.RFID_SN']=['like',$param['RFID_SN']];
  44. }
  45. $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond);
  46. // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond);
  47. // $count=100000;
  48. $cond['page']=isset($param['page'])?$param['page']:1;
  49. $cond['limit']=isset($param['limit'])?$param['limit']:10;
  50. $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,o.CAR_TYPE,o.CAR_BRAND,o.CAR_VIN,s.ID,s.RFID_SN,s.INSTALLER,to_char(s.INSTA_DATE,\'yyyy-mm-dd hh24:mi:ss\') INSTA_DATE,r.NAME,r.ID_CARD_NUMBER,r.MOBILE_NUMBER,r.HOME_ADDRESS');
  51. // $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,o.CAR_TYPE,o.CAR_BRAND,s.ID,s.RFID_SN,s.INSTALLER,to_char(s.INSTA_DATE,\'yyyy-mm-dd hh24:mi:ss\') INSTA_DATE');
  52. foreach($rows as &$val){
  53. $val['CAR_BRAND_TEXT']=(new SysDictData())->getValueByCode('CAR_BRAND_OPTION',$val['CAR_BRAND']);
  54. $val['CAR_TYPE_TEXT']=(new SysDictData())->getValueByCode('CAR_TYPE_OPTION',$val['CAR_TYPE']);
  55. // $val['CARD_NUMBER_STR']=formatDataCardNumber($val['ID_CARD_NUMBER']);
  56. }
  57. $response=[
  58. 'code'=>10000,
  59. 'message'=>'查询成功',
  60. 'count'=>$count,
  61. 'data'=>$rows,
  62. 'current'=>isset($param['page'])?(int)$param['page']:1,
  63. 'limit'=>isset($param['limit'])?(int)$param['limit']:10,
  64. ];
  65. return $response;
  66. }
  67. public function getMapList(Request $request)
  68. {
  69. $param=$request->param();
  70. //联表条件o.rfid_id = s.id and o.owner_id = r.id
  71. $cond=[
  72. '_string'=>'o.rfid_id = s.id',
  73. ];
  74. $keywords=$param['keywords'];
  75. if($keywords){
  76. $cond['_string']= '(s.RFID_SN like \'%'.$keywords.'%\' OR o.PLATE_NO like \'%'.$keywords.'%\') AND o.rfid_id = s.id';
  77. }
  78. $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond);
  79. $cond['page']=isset($param['page'])?$param['page']:1;
  80. $cond['limit']=isset($param['limit'])?$param['limit']:10;
  81. $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,o.CAR_TYPE,o.CAR_BRAND,s.ID,s.RFID_SN,s.INSTALLER,to_char(s.INSTA_DATE,\'yyyy-mm-dd hh24:mi:ss\') INSTA_DATE');
  82. $conn=getOracleConnect();
  83. foreach($rows as &$val){
  84. $val['CAR_BRAND_TEXT']=(new SysDictData())->getValueByCode('CAR_BRAND_OPTION',$val['CAR_BRAND']);
  85. $val['CAR_TYPE_TEXT']=(new SysDictData())->getValueByCode('CAR_TYPE_OPTION',$val['CAR_TYPE']);
  86. $route_sql='select * from(SELECT RF_ID,to_char(RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE FROM DSSC2.W_DW_RF_RECORD WHERE RF_FLAGID =\''.$val['RFID_SN'].'\' ORDER BY RF_DATE DESC )where rownum < 2';
  87. $stid = oci_parse($conn, $route_sql);
  88. oci_define_by_name($stid, 'RF_ID', $val['mac']);
  89. oci_define_by_name($stid, 'RF_DATE', $val['online_time']);
  90. oci_execute($stid);
  91. oci_fetch($stid);
  92. oci_free_statement($stid);
  93. $staion_info =Db::table('stations')->where('mac',$val['mac'])->find();
  94. if($staion_info){
  95. $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$staion_info['latitude'],(float)$staion_info['longitude']);
  96. $val['longitude']=$wgsLoc['lng'];
  97. $val['latitude']=$wgsLoc['lat'];
  98. $val['address']=$staion_info['name'];
  99. }else{
  100. $val['longitude']='';
  101. $val['latitude']='';
  102. $val['address']='';
  103. }
  104. }
  105. $response=[
  106. 'code'=>10000,
  107. 'message'=>'查询成功',
  108. 'count'=>$count,
  109. 'data'=>$rows,
  110. 'current'=>isset($param['page'])?(int)$param['page']:1,
  111. 'limit'=>isset($param['limit'])?(int)$param['limit']:10,
  112. ];
  113. return $response;
  114. }
  115. public function getRfidTagsList(Request $request) {
  116. $param=$request->param();
  117. //联表条件o.rfid_id = s.id and o.owner_id = r.id
  118. $cond=[];
  119. if($param['RFID_SN']){
  120. $cond['s.RFID_SN']=['like',$param['RFID_SN']];
  121. }
  122. $count=queryOracleCount('DSSC3.W_DW_RFID_TAGS s',$cond);
  123. $cond['page']=isset($param['page'])?$param['page']:1;
  124. $cond['limit']=isset($param['limit'])?$param['limit']:10;
  125. // $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,s.RFID_SN,r. NAME,r.ID_CARD_NUMBER,r.MOBILE_NUMBER,r.HOME_ADDRESS');
  126. $rows=queryOracleSelect('DSSC3.W_DW_RFID_TAGS s',$cond,'s.ID,s.RFID_SN,s.RFID_TYPE');
  127. foreach($rows as &$val){
  128. // $val['CAR_BRAND_TEXT']=(new SysDictData())->getValueByCode('CAR_BRAND_OPTION',$val['CAR_BRAND']);
  129. $val['RFID_TYPE_TEXT']=(new SysDictData())->getValueByCode('RFID_TYPE_OPTION',$val['RFID_TYPE']);
  130. if( isset($param['bw_id']) && $param['bw_id'] ){
  131. $val['isAdd']=Db::table('rfid_with_bw')->where('bw_id',$param['bw_id'])->where('rfid',$val['RFID_SN'])->count();
  132. }
  133. }
  134. $response=[
  135. 'code'=>10000,
  136. 'message'=>'查询成功',
  137. 'count'=>$count,
  138. 'data'=>$rows,
  139. 'current'=>isset($param['page'])?(int)$param['page']:1,
  140. 'limit'=>isset($param['limit'])?(int)$param['limit']:10,
  141. ];
  142. return $response;
  143. }
  144. // public function indexAdd(Request $request)
  145. // {
  146. // ini_set('memory_limit','3072M');
  147. // set_time_limit(0);
  148. // $cond=[
  149. // '_string'=>'o.rfid_id = s.id',
  150. // ];
  151. // // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond);
  152. // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond);
  153. // $to=ceil($count/10000);
  154. // var_dump($to);
  155. // for($i=1;$i<=$to;$i++){
  156. // var_dump($i);
  157. // $cond['page']=$i;
  158. // $cond['limit']=10000;
  159. // // $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,s.RFID_SN,r. NAME,r.ID_CARD_NUMBER,r.MOBILE_NUMBER,r.HOME_ADDRESS');
  160. // $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,o.CAR_TYPE,o.CAR_BRAND,s.ID,s.RFID_SN,s.INSTALLER,to_char(s.INSTA_DATE,\'yyyy-mm-dd hh24:mi:ss\') INSTA_DATE');
  161. // // var_dump(count($rows));
  162. // $data=[];
  163. // foreach($rows as &$val){
  164. // $item=array(
  165. // 'license_plate'=>$val['PLATE_NO'],
  166. // 'car_type'=>$val['CAR_TYPE'],
  167. // 'brand_id'=>(int)$val['CAR_BRAND'],
  168. // 'rfid_sn'=>$val['RFID_SN'],
  169. // 'installer'=>$val['INSTALLER'],
  170. // 'license_time'=>$val['INSTA_DATE'],
  171. // );
  172. // array_push($data,$item);
  173. // }
  174. // $success = Db::table('vehicles')->limit(1000)->insertAll($data);
  175. // var_dump($success);
  176. // }
  177. // }
  178. /**
  179. * 保存信息
  180. * @time 2022年01月20日 10:42
  181. * @param Request $request
  182. */
  183. public function save(Request $request)
  184. {
  185. $installer=$request->user()->realname;
  186. $param=$request->param();
  187. $param['RFID_SN']=strtoupper($param['RFID_SN']);
  188. $param['PLATE_NO']=strtoupper($param['PLATE_NO']);
  189. $param['INSTA_DATE']=date('Y-m-d H:i:s',time());
  190. $param['INSTALLER']=$installer;
  191. $r=$this->execSaveVehicle($param);
  192. $param['DATA_TYPE']='vehicle_save';
  193. pushDataToRedisList($param);
  194. return CatchResponse::success($r);
  195. }
  196. private function execSaveVehicle($data){
  197. $conn=getOracleConnect();
  198. $sql='declare
  199. tagId number;
  200. ownId number;
  201. begin
  202. INSERT INTO DSSC3.W_DW_RFID_TAGS("ID", "RFID_SN","INSTALLER","INSTA_DATE") VALUES (DSSC3.SEQ_W_DW_RFID_TAGS.nextval, \''.$data['RFID_SN'].'\',\''.$data['INSTALLER'].'\', TO_DATE(\''.$data['INSTA_DATE'].'\', \'SYYYY-MM-DD HH24:MI:SS\')) returning ID into tagId;
  203. INSERT INTO DSSC3.W_DW_NON_MOTOR_OWNER("ID", "NAME","ID_CARD_NUMBER","MOBILE_NUMBER","HOME_ADDRESS") VALUES (DSSC3.SEQ_W_DW_NON_MOTOR_OWNER.nextval,\''.$data['NAME'].'\',\''.$data['ID_CARD_NUMBER'].'\',\''.$data['MOBILE_NUMBER'].'\',\''.$data['HOME_ADDRESS'].'\') returning ID into ownId;
  204. INSERT INTO DSSC3.W_DW_NON_MOTOR("ID", "RFID_ID","PLATE_NO","CAR_BRAND","CAR_TYPE","CAR_VIN","OWNER_ID") VALUES (DSSC3.SEQ_W_DW_NON_MOTOR.nextval, tagId,\''.$data['PLATE_NO'].'\',\''.$data['CAR_BRAND'].'\',\''.$data['CAR_TYPE'].'\',\''.$data['CAR_VIN'].'\',ownId);
  205. end;';
  206. $stid = oci_parse($conn, $sql);
  207. $r = oci_execute($stid);
  208. oci_free_statement($stid);
  209. return $r;
  210. }
  211. /**
  212. * 更新
  213. * @time 2022年01月20日 10:42
  214. * @param Request $request
  215. * @param $id
  216. */
  217. public function update(Request $request, $id) : \think\Response
  218. {
  219. $params=$request->post();
  220. $conn=getOracleConnect();
  221. //查老的车牌
  222. $vehicle_sql='SELECT o.PLATE_NO FROM DSSC3.W_DW_NON_MOTOR o WHERE o.RFID_ID =\''.$id.'\' ';
  223. $OLD_NO='';
  224. $stid = oci_parse($conn, $vehicle_sql);
  225. oci_define_by_name($stid, 'PLATE_NO', $OLD_NO);
  226. oci_execute($stid);
  227. oci_fetch($stid);
  228. $params['OLD_NO']=$OLD_NO;
  229. $params['RFID_SN']=strtoupper($params['RFID_SN']);
  230. $params['PLATE_NO']=strtoupper($params['PLATE_NO']);
  231. // var_dump($params);
  232. // //更新
  233. $sql='UPDATE DSSC3.W_DW_RFID_TAGS SET RFID_SN = \''.$params['RFID_SN'].'\' WHERE ID = \''.$id.'\' ';
  234. $stid = oci_parse($conn, $sql);
  235. $r = oci_execute($stid);
  236. if(!$r){
  237. oci_rollback($conn);
  238. return CatchResponse::fail('修改失败');
  239. }
  240. $sql='UPDATE DSSC3.W_DW_NON_MOTOR SET PLATE_NO = \''.$params['PLATE_NO'].'\',CAR_BRAND=\''.$params['CAR_BRAND'].'\',CAR_TYPE=\''.$params['CAR_TYPE'].'\',CAR_VIN=\''.$params['CAR_VIN'].'\' WHERE RFID_ID = \''.$id.'\' ';
  241. $stid2 = oci_parse($conn, $sql);
  242. $r2 = oci_execute($stid2);
  243. if(!$r2){
  244. oci_rollback($conn);
  245. return CatchResponse::fail('修改失败');
  246. }
  247. //查车主ID
  248. $vehicle_sql='SELECT o.OWNER_ID FROM DSSC3.W_DW_NON_MOTOR o WHERE o.RFID_ID =\''.$id.'\' ';
  249. $owner_id='';
  250. $stid = oci_parse($conn, $vehicle_sql);
  251. oci_define_by_name($stid, 'OWNER_ID', $owner_id);
  252. oci_execute($stid);
  253. oci_fetch($stid);
  254. $sql='UPDATE DSSC3.W_DW_NON_MOTOR_OWNER SET MOBILE_NUMBER=\''.$params['MOBILE_NUMBER'].'\',NAME=\''.$params['NAME'].'\',ID_CARD_NUMBER=\''.$params['ID_CARD_NUMBER'].'\',HOME_ADDRESS=\''.$params['HOME_ADDRESS'].'\' WHERE ID = \''.$owner_id.'\' ';
  255. $stid3 = oci_parse($conn, $sql);
  256. $r3 = oci_execute($stid3);
  257. if(!$r3){
  258. oci_rollback($conn);
  259. return CatchResponse::fail('修改失败');
  260. }
  261. oci_commit($conn);
  262. $params['DATA_TYPE']='vehicle_update';
  263. pushDataToRedisList($params);
  264. return CatchResponse::success('修改成功');
  265. }
  266. /**
  267. * 删除
  268. * @time 2022年01月20日 10:42
  269. * @param $id
  270. */
  271. public function delete($id) : \think\Response
  272. {
  273. $conn=getOracleConnect();
  274. $sql='SELECT PLATE_NO FROM DSSC3.W_DW_NON_MOTOR WHERE RFID_ID in ('.$id.')';
  275. $stid = oci_parse($conn, $sql);
  276. $r = oci_execute($stid);
  277. $rows=[];
  278. while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  279. $rows[]=$row['PLATE_NO'];
  280. }
  281. $delete_data['PLATE_NO']=$rows;
  282. $delete_data['DATA_TYPE']='vehicle_delete';
  283. //查车主ID
  284. $sql='SELECT OWNER_ID FROM DSSC3.W_DW_NON_MOTOR WHERE RFID_ID in ('.$id.')';
  285. $stid = oci_parse($conn, $sql);
  286. $r = oci_execute($stid);
  287. $rows=[];
  288. while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  289. $rows[]=$row['OWNER_ID'];
  290. }
  291. $owner_ids=implode(',',$rows);
  292. $sql='DELETE FROM DSSC3.W_DW_NON_MOTOR_OWNER WHERE ID in ('.$owner_ids.')';
  293. $stid = oci_parse($conn, $sql);
  294. $r = oci_execute($stid);
  295. if(!$r){
  296. oci_rollback($conn);
  297. return CatchResponse::fail('删除失败');
  298. }
  299. $sql='DELETE FROM DSSC3.W_DW_RFID_TAGS WHERE ID in ('.$id.')';
  300. $stid = oci_parse($conn, $sql);
  301. $r = oci_execute($stid);
  302. if(!$r){
  303. oci_rollback($conn);
  304. return CatchResponse::fail('删除失败');
  305. }
  306. $sql='DELETE FROM DSSC3.W_DW_NON_MOTOR WHERE RFID_ID in ('.$id.')';
  307. $stid = oci_parse($conn, $sql);
  308. $r = oci_execute($stid);
  309. if(!$r){
  310. oci_rollback($conn);
  311. return CatchResponse::fail('删除失败');
  312. }
  313. oci_commit($conn);
  314. pushDataToRedisList($delete_data);
  315. return CatchResponse::success(true);
  316. }
  317. /**
  318. * 导出
  319. *
  320. * @time 2022年01月22日
  321. * @param Excel $excel
  322. * @param VehicleExport $vehicleExport
  323. * @throws \PhpOffice\PhpSpreadsheet\Exception
  324. * @return \think\response\Json
  325. */
  326. public function export_vehicle(Excel $excel, VehiclesExport $VehicleExport)
  327. {
  328. return CatchResponse::success($excel->save($VehicleExport, Utils::publicPath('export/vehicles'), 'local', '车辆列表'));
  329. }
  330. /**
  331. * 导入车辆
  332. *
  333. * @time 2022年02月15日
  334. * @param Excel $excel
  335. * @param DeviceExport $deviceExport
  336. * @throws \PhpOffice\PhpSpreadsheet\Exception
  337. * @return \think\response\Json
  338. */
  339. public function importVehicle(Request $request)
  340. {
  341. $url = $request->post('url');
  342. if (!$url) {
  343. return CatchResponse::fail('请上传文件');
  344. }
  345. $creator_id = $request->post('creator_id');
  346. //解析地址
  347. $parse_url = parse_url($url)['path'];
  348. //载入excel表格
  349. $objPHPExcel = IOFactory::load(public_path() . $parse_url);
  350. //获取表名,一维数组,值是表名。如:array('sheet1', 'sheet2', 'sheet3')
  351. // $nameArr = $objPHPExcel->getSheetNames();
  352. //获取表的数量
  353. $sheetCount = $objPHPExcel->getSheetCount();
  354. $fail = 0; //失败条数
  355. $success = 0; //成功条数
  356. $total = 0; //总共设备数
  357. $data = []; //设备数据
  358. //循环读取每一张表
  359. $conn=getOracleConnect();
  360. for ($index = 0; $index < $sheetCount; $index++) {
  361. //设置当前要读取的表
  362. $sheet = $objPHPExcel->getSheet($index); //excel中的第一张sheet
  363. // var_dump($sheet);exit;
  364. $highestRow = $sheet->getHighestRow(); // 取得总行数
  365. // var_dump($highestRow);
  366. if ($highestRow <= 1) {
  367. continue;
  368. }
  369. $brand_type_id = Db::table("sys_dict_type")->where('code', 'CAR_BRAND_OPTION')->value('id');
  370. $car_type_id = Db::table("sys_dict_type")->where('code', 'CAR_TYPE_OPTION')->value('id');
  371. $total += $highestRow - 1;
  372. $sql='declare
  373. tagId number;
  374. ownId number;
  375. begin
  376. 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;
  377. INSERT INTO DSSC3.W_DW_NON_MOTOR_OWNER("ID", "NAME","ID_CARD_NUMBER","MOBILE_NUMBER",,"HOME_ADDRESS") VALUES (DSSC3.SEQ_W_DW_NON_MOTOR_OWNER.nextval,:col4,:col5,:col6,:col7) returning ID into ownId;
  378. INSERT INTO DSSC3.W_DW_NON_MOTOR("ID", "RFID_ID","PLATE_NO","CAR_BRAND","CAR_TYPE","CAR_VIN","OWNER_ID") VALUES (DSSC3.W_DW_NON_MOTOR.nextval, tagId,:col8,:col9,:col10,:col11,ownId);
  379. end;';
  380. $stmt = oci_parse($conn, $sql);
  381. for ($j = 2; $j <= $highestRow; $j++) {
  382. $arr = array(); //每条设备信息
  383. $arr['PLATE_NO'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue()));
  384. if(empty($arr['PLATE_NO']) || strlen($arr['PLATE_NO'])<10){
  385. $fail++;
  386. debug_log('importVehicleError','车牌格式不正确,车牌号为:'.$arr['PLATE_NO']);
  387. continue;
  388. }
  389. //检测车牌是否存在
  390. $vehicle_sql='SELECT o.RFID_ID FROM DSSC3.W_DW_NON_MOTOR o WHERE o.PLATE_NO =\''.$arr['PLATE_NO'].'\' ';
  391. $rfid_id='';
  392. $stid = oci_parse($conn, $vehicle_sql);
  393. oci_define_by_name($stid, 'RFID_ID', $rfid_id);
  394. oci_execute($stid);
  395. oci_fetch($stid);
  396. if($rfid_id){
  397. $fail++;
  398. debug_log('importVehicleError','车牌已存在,车牌号为:'.$arr['PLATE_NO']);
  399. continue;
  400. }
  401. $brand = trim($sheet->getCell("B" . $j)->getFormattedValue());
  402. $brand_id=Db::table("sys_dict_data")->where('type_id', $brand_type_id)->whereLike('value','%'.$brand.'%')->cache(60)->value('code');
  403. $arr['CAR_BRAND']=$brand_id?$brand_id:'99';
  404. $type = trim($sheet->getCell("C" . $j)->getFormattedValue());
  405. $car_type=Db::table("sys_dict_data")->where('type_id', $car_type_id)->whereLike('value','%'.$type.'%')->cache(60)->value('code');
  406. $arr['CAR_TYPE']=$car_type?$car_type:'4';
  407. $arr['RFID_SN'] = trim($sheet->getCell("D" . $j)->getFormattedValue());
  408. if(empty($arr['RFID_SN']) || strlen($arr['RFID_SN'])!=8){
  409. $fail++;
  410. debug_log('importVehicleError','标签格式格式不正确,标签为:'.$arr['RFID_SN']);
  411. continue;
  412. }
  413. $arr['CAR_VIN'] = trim($sheet->getCell("E" . $j)->getFormattedValue());
  414. $arr['INSTA_DATE'] = trim($sheet->getCell("F" . $j)->getFormattedValue());
  415. $arr['INSTALLER'] = trim($sheet->getCell("G" . $j)->getFormattedValue());
  416. $arr['NAME'] = trim($sheet->getCell("H" . $j)->getFormattedValue());
  417. $arr['ID_CARD_NUMBER'] = trim($sheet->getCell("I" . $j)->getFormattedValue());
  418. $arr['MOBILE_NUMBER'] = trim($sheet->getCell("J" . $j)->getFormattedValue());
  419. $arr['HOME_ADDRESS'] = trim($sheet->getCell("K" . $j)->getFormattedValue());
  420. // var_dump($arr);
  421. //变量绑定
  422. oci_bind_by_name($stmt, ':col1', $arr['RFID_SN']);
  423. oci_bind_by_name($stmt, ':col2', $arr['INSTALLER']);
  424. oci_bind_by_name($stmt, ':col3', $arr['INSTA_DATE']);
  425. oci_bind_by_name($stmt, ':col4', $arr['NAME']);
  426. oci_bind_by_name($stmt, ':col5', $arr['ID_CARD_NUMBER']);
  427. oci_bind_by_name($stmt, ':col6', $arr['MOBILE_NUMBER']);
  428. oci_bind_by_name($stmt, ':col7', $arr['HOME_ADDRESS']);
  429. oci_bind_by_name($stmt, ':col8', $arr['PLATE_NO']);
  430. oci_bind_by_name($stmt, ':col9', $arr['CAR_BRAND']);
  431. oci_bind_by_name($stmt, ':col10',$arr['CAR_TYPE']);
  432. oci_bind_by_name($stmt, ':col11',$arr['CAR_VIN']);
  433. // 添加到批处理
  434. oci_execute($stmt, OCI_DEFAULT);
  435. $arr['DATA_TYPE']='vehicle_save';
  436. pushDataToRedisList($arr);
  437. $success++;
  438. if( ($j%1000 == 0) || $j==$highestRow){
  439. // 提交事务
  440. $res=oci_commit($conn);
  441. }
  442. }
  443. oci_free_statement($stmt);
  444. }
  445. oci_close($conn);
  446. return CatchResponse::success('共' . $total . '条数据,成功' . $success . '条,失败' . $fail . '条');
  447. }
  448. }