123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- namespace catchAdmin\yunying\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- // use catchAdmin\yunying\model\Vehicle as vehicleModel;
- use catchAdmin\yunying\excel\VehiclesExport;
- use catchAdmin\system\model\SysDictData;
- use catcher\Utils;
- use catcher\library\excel\Excel;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use think\facade\Env;
- use think\facade\Db;
- class Vehicle extends CatchController
- {
- // protected $vehicleModel;
-
- // public function __construct(VehicleModel $vehicleModel)
- // {
- // $this->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' => '导入失败']);
- }
-
- }
|