vehicleModel = $vehicleModel; // } /** * 列表 * @time 2022年01月20日 10:42 * @param Request $request */ public function index(Request $request) { $param=$request->param(); //联表条件o.rfid_id = s.id and o.owner_id = r.id $cond=[ '_string'=>'o.rfid_id = s.id', ]; if($param['PLATE_NO']){ $cond['o.PLATE_NO']=['like',$param['PLATE_NO']]; } // if($param['ID_CARD_NUMBER']){ // $cond['r.ID_CARD_NUMBER']=['like',$param['ID_CARD_NUMBER']]; // } // if($param['MOBILE_NUMBER']){ // $cond['r.MOBILE_NUMBER']=['like',$param['MOBILE_NUMBER']]; // } if($param['RFID_SN']){ $cond['s.RFID_SN']=['like',$param['RFID_SN']]; } // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond); $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond); $cond['page']=isset($param['page'])?$param['page']:1; $cond['limit']=isset($param['limit'])?$param['limit']:10; // $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'); $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'); foreach($rows as &$val){ $val['CAR_BRAND_TEXT']=(new SysDictData())->getValueByCode('CAR_BRAND_OPTION',$val['CAR_BRAND']); $val['CAR_TYPE_TEXT']=(new SysDictData())->getValueByCode('CAR_TYPE_OPTION',$val['CAR_TYPE']); } $response=[ 'code'=>10000, 'message'=>'查询成功', 'count'=>$count, 'data'=>$rows, 'current'=>isset($param['page'])?(int)$param['page']:1, 'limit'=>isset($param['limit'])?(int)$param['limit']:10, ]; return $response; } // public function index(Request $request) // { // ini_set('memory_limit','3072M'); // set_time_limit(0); // $cond=[ // '_string'=>'o.rfid_id = s.id', // ]; // // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond); // $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s',$cond); // $to=ceil($count/10000); // var_dump($to); // for($i=1;$i<=$to;$i++){ // var_dump($i); // $cond['page']=$i; // $cond['limit']=10000; // // $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'); // $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'); // // var_dump(count($rows)); // $data=[]; // foreach($rows as &$val){ // $item=array( // 'license_plate'=>$val['PLATE_NO'], // 'car_type'=>$val['CAR_TYPE'], // 'brand_id'=>(int)$val['CAR_BRAND'], // 'rfid_sn'=>$val['RFID_SN'], // 'installer'=>$val['INSTALLER'], // 'license_time'=>$val['INSTA_DATE'], // ); // array_push($data,$item); // } // $success = Db::table('vehicles')->limit(1000)->insertAll($data); // var_dump($success); // } // } /** * 保存信息 * @time 2022年01月20日 10:42 * @param Request $request */ public function save(Request $request) { $installer=$request->user()->realname; $param=$request->param(); $param['RFID_SN']=strtoupper($param['RFID_SN']); $param['PLATE_NO']=strtoupper($param['PLATE_NO']); $param['INSTA_DATE']=date('Y-m-d H:i:s',time()); $param['INSTALLER']=$installer; $r=$this->execSaveVehicle($param); return CatchResponse::success($r); } private function execSaveVehicle($data){ $conn=getOracleConnect(); $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, \''.$data['RFID_SN'].'\',\''.$data['INSTALLER'].'\', TO_DATE(\''.$data['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,\''.$data['PLATE_NO'].'\',\''.$data['CAR_BRAND'].'\',\''.$data['CAR_TYPE'].'\'); end;'; $stid = oci_parse($conn, $sql); $r = oci_execute($stid); oci_free_statement($stid); return $r; } /** * 更新 * @time 2022年01月20日 10:42 * @param Request $request * @param $id */ public function update(Request $request, $id) : \think\Response { $params=$request->post(); $params['RFID_SN']=strtoupper($params['RFID_SN']); $params['PLATE_NO']=strtoupper($params['PLATE_NO']); // var_dump($params); $conn=getOracleConnect(); // //更新 $sql='UPDATE DSSC3.W_DW_RFID_TAGS SET RFID_SN = \''.$params['RFID_SN'].'\' WHERE ID = \''.$id.'\' '; $stid = oci_parse($conn, $sql); $r = oci_execute($stid); $sql='UPDATE DSSC3.W_DW_NON_MOTOR SET PLATE_NO = \''.$params['PLATE_NO'].'\',CAR_BRAND=\''.$params['CAR_BRAND'].'\',CAR_TYPE=\''.$params['CAR_TYPE'].'\' WHERE RFID_ID = \''.$id.'\' '; // var_dump($sql); $stid2 = oci_parse($conn, $sql); $r2 = oci_execute($stid2); return CatchResponse::success('修改成功'); } /** * 删除 * @time 2022年01月20日 10:42 * @param $id */ public function delete($id) : \think\Response { $conn=getOracleConnect(); $sql='DELETE FROM DSSC3.W_DW_RFID_TAGS WHERE ID in ('.$id.')'; $stid = oci_parse($conn, $sql); $r = oci_execute($stid); $sql='DELETE FROM DSSC3.W_DW_NON_MOTOR WHERE RFID_ID in ('.$id.')'; $stid = oci_parse($conn, $sql); $r = oci_execute($stid); return CatchResponse::success($r); } /** * 导出 * * @time 2022年01月22日 * @param Excel $excel * @param VehicleExport $vehicleExport * @throws \PhpOffice\PhpSpreadsheet\Exception * @return \think\response\Json */ public function export_vehicle(Excel $excel, VehiclesExport $VehicleExport) { return CatchResponse::success($excel->save($VehicleExport, Utils::publicPath('export/vehicles'), 'local', '车辆列表')); } /** * 导入车辆 * * @time 2022年02月15日 * @param Excel $excel * @param DeviceExport $deviceExport * @throws \PhpOffice\PhpSpreadsheet\Exception * @return \think\response\Json */ public function importVehicle(Request $request) { $url = $request->post('url'); if (!$url) { return CatchResponse::fail('请上传文件'); } $creator_id = $request->post('creator_id'); //解析地址 $parse_url = parse_url($url)['path']; //载入excel表格 $objPHPExcel = IOFactory::load(public_path() . $parse_url); //获取表名,一维数组,值是表名。如:array('sheet1', 'sheet2', 'sheet3') // $nameArr = $objPHPExcel->getSheetNames(); //获取表的数量 $sheetCount = $objPHPExcel->getSheetCount(); $fail = 0; //失败条数 $success = 0; //成功条数 $total = 0; //总共设备数 $data = []; //设备数据 //循环读取每一张表 for ($index = 0; $index < $sheetCount; $index++) { //设置当前要读取的表 $sheet = $objPHPExcel->getSheet($index); //excel中的第一张sheet // var_dump($sheet);exit; $highestRow = $sheet->getHighestRow(); // 取得总行数 // var_dump($highestRow); if ($highestRow <= 1) { continue; } $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; for ($j = 2; $j <= $highestRow; $j++) { $arr = array(); //每条设备信息 $arr['PLATE_NO'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue())); $brand = trim($sheet->getCell("B" . $j)->getFormattedValue()); $brand_id=Db::table("sys_dict_data")->where('type_id', $brand_type_id)->whereLike('value','%'.$brand.'%')->cache(60)->value('code'); $arr['CAR_BRAND']=$brand_id?$brand_id:'99'; $type = trim($sheet->getCell("C" . $j)->getFormattedValue()); $car_type=Db::table("sys_dict_data")->where('type_id', $car_type_id)->whereLike('value','%'.$type.'%')->cache(60)->value('code'); $arr['CAR_BRAND']=$car_type?$car_type:'4'; $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->execSaveStation($arr); if($r){ $success++; }else{ $fail++; } // var_dump($arr); // array_push($data,$arr); } } // 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 . '条'); // } // return CatchResponse::success(['error' => true, 'msg' => '导入失败']); } }