Station.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. namespace catchAdmin\device\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\device\model\Station as stationModel;
  7. use catcher\Utils;
  8. use catcher\library\excel\Excel;
  9. use PhpOffice\PhpSpreadsheet\IOFactory;
  10. use think\facade\Env;
  11. use think\facade\Db;
  12. use PDO;
  13. use think\facade\Cache;
  14. class Station extends CatchController
  15. {
  16. protected $stationModel;
  17. public function __construct(StationModel $stationModel)
  18. {
  19. $this->stationModel = $stationModel;
  20. }
  21. /**
  22. * 列表
  23. * @time 2022年10月26日 10:32
  24. * @param Request $request
  25. */
  26. public function index(Request $request) : \think\Response
  27. {
  28. return CatchResponse::paginate($this->stationModel->getList());
  29. }
  30. /**
  31. * 保存信息
  32. * @time 2022年10月26日 10:32
  33. * @param Request $request
  34. */
  35. public function save(Request $request) : \think\Response
  36. {
  37. $params=$request->post();
  38. $shortcode=$this->stationModel->order('shortcode','desc')->value('shortcode');
  39. $params['shortcode']=$shortcode+1;
  40. // $gcjLoc = \algorithm\Geometry::convertBd09ToGcj02((float)$params['latitude'],(float)$params['longitude']);
  41. $gcjLoc = \algorithm\Geometry::wgsTOgcj((float)$params['latitude'],(float)$params['longitude']);
  42. $params['longitude']=$gcjLoc['lng'];
  43. $params['latitude']=$gcjLoc['lat'];
  44. $params['DATA_TYPE']='station_save';
  45. pushDataToRedisList($params);
  46. return CatchResponse::success($this->stationModel->storeBy($params));
  47. }
  48. /**
  49. * 读取
  50. * @time 2022年10月26日 10:32
  51. * @param $id
  52. */
  53. public function read($id) : \think\Response
  54. {
  55. return CatchResponse::success($this->stationModel->findBy($id));
  56. }
  57. /**
  58. * 更新
  59. * @time 2022年10月26日 10:32
  60. * @param Request $request
  61. * @param $id
  62. */
  63. public function update(Request $request, $id) : \think\Response
  64. {
  65. $params=$request->post();
  66. // $gcjLoc = \algorithm\Geometry::convertBd09ToGcj02((float)$params['latitude'],(float)$params['longitude']);
  67. $gcjLoc = \algorithm\Geometry::wgsTOgcj((float)$params['latitude'],(float)$params['longitude']);
  68. $params['longitude']=$gcjLoc['lng'];
  69. $params['latitude']=$gcjLoc['lat'];
  70. $params['update_id']=$id;
  71. $params['DATA_TYPE']='station_update';
  72. pushDataToRedisList($params);
  73. return CatchResponse::success($this->stationModel->updateBy($id, $params));
  74. }
  75. /**
  76. * 删除
  77. * @time 2022年10月26日 10:32
  78. * @param $id
  79. */
  80. public function delete($id) : \think\Response
  81. {
  82. $ids=explode(',',$id);
  83. $shortcode=$this->stationModel->whereIn('id',$ids)->column('shortcode');
  84. $params['delete_code']=$shortcode;
  85. $params['DATA_TYPE']='station_save';
  86. pushDataToRedisList($params);
  87. return CatchResponse::success($this->stationModel->deleteBy($id,true));
  88. }
  89. public function getdeviceListByStation(Request $request){
  90. $params=$request->param();
  91. if(!$params['station_code']){
  92. return CatchResponse::success([]);
  93. }
  94. $cond=[];
  95. if($params['station_code']){
  96. $cond['RF_ID']=['=',$params['station_code']];
  97. }
  98. $start_time = date('Y-m-d 00:00:00',time());
  99. $end_time = date('Y-m-d 23:59:59',time());
  100. if(isset($params['timeRange']) && $params['timeRange'] != ''){
  101. $start_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][0]));
  102. $end_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][1]));
  103. $cond['RF_DATE']=['timeRange',$start_time,$end_time];
  104. }
  105. // $count=queryOracleCount('DSSC2.W_DW_RF_RECORD',$cond);
  106. $cond['page']=isset($params['page'])?$params['page']:1;
  107. $cond['limit']=isset($params['limit'])?$params['limit']:10;
  108. $rows=queryOracleSelect('(SELECT * FROM DSSC2.W_DW_RF_RECORD ORDER BY RF_DATE DESC) a',$cond,'a.RF_FLAGID,a.RF_STAT,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE');
  109. foreach($rows as &$val){
  110. //状态: 0- 未知,1 - 进入,2 - 离开
  111. if($val['RF_STAT']==1){
  112. $val['RF_STAT_TEXT']='进入';
  113. }elseif($val['RF_STAT']==2){
  114. $val['RF_STAT_TEXT']='离开';
  115. }else{
  116. $val['RF_STAT_TEXT']='未知';
  117. }
  118. }
  119. $response=[
  120. 'code'=>10000,
  121. 'message'=>'查询成功',
  122. // 'count'=>$count,
  123. 'data'=>$rows,
  124. 'current'=>isset($params['page'])?(int)$params['page']:1,
  125. 'limit'=>isset($params['limit'])?(int)$params['limit']:10,
  126. ];
  127. return $response;
  128. // $cond=[];
  129. // $params=$request->param();
  130. // if(!$params['station_code']){
  131. // return CatchResponse::success('');
  132. // }
  133. // if($params['station_code']){
  134. // $cond[]=['RF_ID','=',$params['station_code']];
  135. // }
  136. // $start_time = date('Y-m-d 00:00:00',time());
  137. // $end_time = date('Y-m-d 23:59:59',time());
  138. // if(isset($params['timeRange']) && $params['timeRange'] != ''){
  139. // $start_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][0]));
  140. // $end_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][1]));
  141. // $cond[]=['RF_DATE','between',[$start_time,$end_time]];
  142. // }
  143. // $list=$this->rfRecordModel->getList($cond);
  144. // return CatchResponse::paginate($list);
  145. }
  146. /**
  147. * 导入设备
  148. *
  149. * @time 2022年02月15日
  150. * @param Excel $excel
  151. * @param DeviceExport $deviceExport
  152. * @throws \PhpOffice\PhpSpreadsheet\Exception
  153. * @return \think\response\Json
  154. */
  155. public function importStation(Request $request)
  156. {
  157. $url = $request->post('url');
  158. if (!$url) {
  159. return CatchResponse::fail('请上传文件');
  160. }
  161. $creator_id = $request->post('creator_id');
  162. //解析地址
  163. $parse_url = parse_url($url)['path'];
  164. //载入excel表格
  165. $objPHPExcel = IOFactory::load(public_path() . $parse_url);
  166. //获取表名,一维数组,值是表名。如:array('sheet1', 'sheet2', 'sheet3')
  167. // $nameArr = $objPHPExcel->getSheetNames();
  168. //获取表的数量
  169. $sheetCount = $objPHPExcel->getSheetCount();
  170. $fail = 0; //失败条数
  171. $success = 0; //成功条数
  172. $total = 0; //总共设备数
  173. $data = []; //设备数据
  174. //循环读取每一张表
  175. $shortcode=$this->stationModel->order('shortcode','desc')->value('shortcode');
  176. for ($index = 0; $index < $sheetCount; $index++) {
  177. //设置当前要读取的表
  178. $sheet = $objPHPExcel->getSheet($index); //excel中的第一张sheet
  179. // var_dump($sheet);exit;
  180. $highestRow = $sheet->getHighestRow(); // 取得总行数
  181. // var_dump($highestRow);
  182. if ($highestRow <= 1) {
  183. continue;
  184. }
  185. $total += $highestRow - 1;
  186. for ($j = 2; $j <= $highestRow; $j++) {
  187. $shortcode++;
  188. $arr = array(); //每条设备信息
  189. $arr['mac'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue()));
  190. $arr['longitude'] = trim($sheet->getCell("B" . $j)->getFormattedValue());
  191. $arr['latitude'] = trim($sheet->getCell("C" . $j)->getFormattedValue());
  192. $arr['name'] = trim($sheet->getCell("D" . $j)->getFormattedValue());
  193. $arr['created_at']=time();
  194. $arr['shortcode']=$shortcode;
  195. $arr['DATA_TYPE']='station_save';
  196. pushDataToRedisList($arr);
  197. array_push($data,$arr);
  198. }
  199. }
  200. // array_unique($data, SORT_REGULAR);
  201. // // var_dump($data);return CatchResponse::success();
  202. $count = $this->stationModel->limit(100)->insertAll($data);
  203. if ($count) {
  204. return CatchResponse::success('共' . $total . '条数据,成功' . $count . '条,失败' . ($total-$count) . '条');
  205. }
  206. return CatchResponse::success(['error' => true, 'msg' => '导入失败']);
  207. }
  208. /**
  209. * 基站地图额
  210. * @time 2022年01月20日 10:09
  211. * @param Request $request
  212. */
  213. public function getMapList(Request $request)
  214. {
  215. return CatchResponse::paginate($this->stationModel->getMapList());
  216. }
  217. /**
  218. * 所有列表
  219. * @time 2022年01月20日 10:09
  220. * @param Request $request
  221. */
  222. public function getAllList(Request $request)
  223. {
  224. $params=$request->param();
  225. $start=$params['start']?$params['start']*4000:0;
  226. $limit=$params['limit']?:4000;
  227. $total=$this->stationModel->count();
  228. return CatchResponse::success(['list'=>$this->stationModel->getAllList($start,$limit),'total'=>$total]);
  229. }
  230. /**
  231. * 导出列表
  232. * @time 2022年01月20日 10:09
  233. * @param Request $request
  234. */
  235. public function getExportList(Request $request)
  236. {
  237. return CatchResponse::success($this->stationModel->getExportList());
  238. }
  239. public function getAllListForTrans(Request $request) {
  240. $start=0;
  241. $limit=40000;
  242. $list=$this->stationModel->getAllList($start,$limit);
  243. $rows=[];
  244. foreach($list as $val){
  245. $item=['key'=>$val['mac'],'label'=>$val['name'] ];
  246. $rows[]=$item;
  247. }
  248. return CatchResponse::success($rows);
  249. }
  250. }