ApiService.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 6/22/24
  6. * Time: 12:34 PM
  7. */
  8. namespace Modules\Admin\Services;
  9. use App\Enum\ApiEnum;
  10. use Illuminate\Support\Facades\Cache;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Log;
  13. use Modules\Admin\Entities\Menu;
  14. class ApiService{
  15. public function __construct()
  16. {
  17. }
  18. //网格化录入
  19. public static function addConition($params)
  20. {
  21. $result['status'] = true;
  22. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  23. $result['data'] = [];
  24. //区域字典录入
  25. $area = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')->where('szxmc',$params['xjdw'])->orderBy('areaid','desc')->get();
  26. $is_insert = true;
  27. if(count($area) > 0){
  28. for($i=0;$i<count($area);$i++){
  29. if($params['jcqy'] == $area[$i]->qymc){
  30. $is_insert = false;
  31. }
  32. }
  33. }
  34. if($is_insert){
  35. $data['ID'] = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  36. $data['FORM_DATA_ID'] = $data['ID'];
  37. $data['DATA_INDEX'] = 0.0;
  38. $data['CREATE_TIME'] = date('Y-m-d H:i:s');
  39. $data['TENANT_KEY'] = 't1zz9w8165';
  40. $data['IS_DELETE'] = 0;
  41. $data['DELETE_TYPE'] = 0;
  42. $data['FT_STATUS'] = 0;
  43. if(count($area) > 0){
  44. preg_match_all('/[0-9]+/', $area[0]->areaid, $matches);
  45. $data['areaid'] = $params['xjdw'].($matches[0] + 1);
  46. }else{
  47. $data['areaid'] = $params['xjdw'].'1';
  48. }
  49. $data['qymc'] = $params['jcqy'];
  50. $data['szxmc'] = $params['xjdw'];
  51. DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')->insert($data);
  52. }
  53. //巡检记录录入
  54. $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  55. $insert = [
  56. 'ID' => $id,
  57. 'FORM_DATA_ID' => $id,
  58. 'DATA_INDEX' => 0.0,
  59. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  60. 'TENANT_KEY' => 't1zz9w8165',
  61. 'IS_DELETE' => 0,
  62. 'DELETE_TYPE' => 0,
  63. 'FT_STATUS' => 0,
  64. 'xjqy' => $params['jcqy'],
  65. 'dkpz' => $params['dkpz'],
  66. 'lrr' => $params['lrmc'].'|'.$params['lrr'],
  67. 'jclx' => $params['jclx'],
  68. 'lrsj' => $params['lrsj'],
  69. 'dwmc' => $params['dwmc'],
  70. 'jcwt' => $params['jcwt'],
  71. 'xjdw' => $params['xjdw'],
  72. 'wtms' => $params['wtms'],
  73. 'sjr' => $params['sjr']
  74. ];
  75. if($params['jcwt'] == '有'){
  76. $insert['zgr'] = $params['zgr'];
  77. }
  78. DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->insert($insert);
  79. return $result;
  80. }
  81. //网格化人员轨迹查询条件
  82. public static function getQueryConitions($date = '')
  83. {
  84. $result['status'] = true;
  85. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  86. $result['data'] = [];
  87. if (!$date) {
  88. $date = date('Y-m-d', time());
  89. }
  90. $depart = DB::connection('mysql_fwe10_eteams')->table('department')
  91. ->where('parent', '100001980000000049')
  92. ->where('name', 'like', '%' . '洗煤厂')
  93. ->where('id','!=','100001590000001602')
  94. ->get();
  95. $depart_arr = [];
  96. foreach ($depart as $key => $val) {
  97. $depart_name = str_replace('洗选中心', '', $val->fullname);
  98. $depart_arr[$key] = [
  99. 'name' => $depart_name,
  100. ];
  101. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  102. ->where('xjdw', $depart_name)
  103. ->where('lrsj', 'like', '%' . $date . '%')
  104. ->groupBy('lrr')->select(
  105. [
  106. 'lrr'
  107. ]
  108. )->get();
  109. if(count($query) > 0){
  110. for($i=0;$i<count($query);$i++){
  111. $lrr = explode('|',$query[$i]->lrr);
  112. $query[$i]->person_name = $lrr[0];
  113. $query[$i]->person_id = $lrr[1];
  114. }
  115. }
  116. $query = json_decode($query);
  117. $depart_arr[$key]['person_list'] = $query;
  118. }
  119. $result['data'] = $depart_arr;
  120. return $result;
  121. }
  122. //网格化人员轨迹
  123. public static function getPersonTravel($person_id, $depart, $date = '')
  124. {
  125. $result['status'] = true;
  126. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  127. $result['data'] = [];
  128. if (!$date) {
  129. $date = date('Y-m-d', time());
  130. }
  131. $res = [];
  132. $area_arr = [];
  133. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  134. ->where('lrr', $person_id)
  135. ->where('lrsj', 'like', '%' . $date . '%')
  136. ->where('xjdw', $depart)
  137. ->orderBy('lrsj', 'asc')->get();
  138. $query = json_decode($query);
  139. if ($query) {
  140. foreach ($query as $key => $val) {
  141. // dd($val);
  142. $area_arr[] = $val->xjqy;
  143. $res[] = [
  144. 'area' => $val->xjqy,
  145. 'date' => $val->lrsj,
  146. 'data_id' => $val->ID,
  147. 'url' => 'http://anstatic.nxmy.com:8011/assets/html/xixuan/pages/detail.html?id='.$val->ID,
  148. ];
  149. }
  150. $area_list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')
  151. ->whereNotIn('qymc', $area_arr)
  152. ->where('szxmc', $depart)->orderBy('areaid', 'asc')->get();
  153. foreach ($area_list as $area) {
  154. $res[] = [
  155. 'area' => $area->qymc,
  156. 'date' => '',
  157. 'data_id' => '',
  158. 'url' => '',
  159. ];
  160. }
  161. $result['data'] = $res;
  162. }
  163. return $result;
  164. }
  165. //网格化巡检记录查询条件
  166. public static function getResultConition()
  167. {
  168. $result['status'] = true;
  169. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  170. $result['data'] = [];
  171. $depart = DB::connection('mysql_fwview')->table('hrmdepartment')
  172. ->where('subcompanyid1', 49)
  173. ->where('departmentname', 'like', '%' . '洗煤厂')
  174. ->where('id', '!=', 1602)->get();
  175. $depart_arr = [];
  176. foreach ($depart as $key => $val) {
  177. $depart_name = str_replace('洗选中心', '', $val->DEPARTMENTNAME);
  178. $depart_arr[$key] = $depart_name;
  179. }
  180. $result['data'] = $depart_arr;
  181. return $result;
  182. }
  183. //网格化巡检记录查询
  184. public static function getResultRecord($depart = 'all', $date_type = 'week')
  185. {
  186. $result['status'] = true;
  187. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  188. $result['data'] = [];
  189. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
  190. if ($depart != 'all') {
  191. $query = $query->where('xjdw', $depart);
  192. }
  193. if ($date_type == 'month') {
  194. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  195. } else if ($date_type == 'quarter') {
  196. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  197. } else {
  198. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  199. }
  200. $query = $query->groupBy('lrdate', 'xjdw', 'lrr', 'dwmc')
  201. ->select(
  202. [
  203. DB::raw('DATE(lrsj) as lrdate'),
  204. 'xjdw',
  205. 'lrr',
  206. 'dwmc'
  207. ]
  208. )
  209. ->get();
  210. $data = [];
  211. $pie = [];
  212. foreach ($query as $key => $val) {
  213. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  214. ->where('id', $val->lrr)->value('lastname');
  215. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  216. ->where('szxmc', $val->xjdw)->count();
  217. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  218. ->where('xjdw', $val->xjdw)
  219. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  220. ->where('lrr', $val->lrr)->count();
  221. if ($allcount <= 0) {
  222. continue;
  223. }
  224. // if ($detail >= $allcount) {
  225. $data[$val->lrr] = [
  226. 'department' => $val->dwmc,
  227. 'lastname' => $lastname,
  228. 'person_id' => $val->lrr,
  229. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  230. ];
  231. $pie[$val->lrr] = [
  232. 'name' => $lastname,
  233. 'value' => isset($data[$val->lrr]['value']) ? $data[$val->lrr]['value'] + 1 : 1,
  234. ];
  235. // } else {
  236. // continue;
  237. // }
  238. }
  239. $data_arr = array_column($data, 'count');
  240. array_multisort($data_arr, SORT_DESC, $data);
  241. $pie_arr = array_column($pie, 'value');
  242. array_multisort($pie_arr, SORT_DESC, $pie);
  243. $result['data']['list'] = $data;
  244. $result['data']['pie'] = $pie;
  245. return $result;
  246. }
  247. //网格化巡检记录列表
  248. public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
  249. {
  250. $result['status'] = true;
  251. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  252. $result['data'] = [];
  253. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')->where('lrr', $person_id);
  254. if ($depart != 'all') {
  255. $query = $query->where('xjdw', $depart);
  256. }
  257. if ($date_type == 'month') {
  258. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  259. } else if ($date_type == 'quarter') {
  260. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  261. } else {
  262. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  263. }
  264. $query = $query->groupBy('lrdate', 'xjdw')
  265. ->select(
  266. [
  267. 'xjdw',
  268. DB::raw('DATE(lrsj) as lrdate'),
  269. ]
  270. )
  271. ->get();
  272. $data = [];
  273. foreach ($query as $key => $val) {
  274. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  275. ->where('id', $person_id)->value('lastname');
  276. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  277. ->where('szxmc', $val->xjdw)->count();
  278. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  279. ->where('xjdw', $val->xjdw)
  280. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  281. ->where('lrr', $person_id)->count();
  282. if ($allcount <= 0) {
  283. continue;
  284. }
  285. if ($detail >= $allcount) {
  286. $data[] = [
  287. 'lastname' => $lastname,
  288. 'person_id' => $person_id,
  289. 'depart' => $val->xjdw,
  290. 'date' => $val->lrdate
  291. ];
  292. } else {
  293. continue;
  294. }
  295. }
  296. $data_arr = array_column($data, 'date');
  297. array_multisort($data_arr, SORT_DESC, $data);
  298. $result['data']['list'] = $data;
  299. return $result;
  300. }
  301. //网格化巡检记录列表明细
  302. public static function getResultDlist($person_id, $depart, $date)
  303. {
  304. $result['status'] = true;
  305. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  306. $result['data'] = [];
  307. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  308. ->where('lrr', $person_id)
  309. ->where('xjdw', $depart)
  310. ->where('lrsj', 'like', $date . '%')
  311. ->orderBy('lrsj', 'desc')
  312. ->select([
  313. 'ID',
  314. 'lrr',
  315. 'xjqy',
  316. 'lrsj',
  317. ])->get();
  318. if(count($query) > 0){
  319. for($i=0;$i<count($query);$i++){
  320. $lrr = explode('|',$query[$i]->lrr);
  321. $query[$i]->lrr_name = $lrr[0];
  322. }
  323. }
  324. $query = json_decode($query);
  325. $result['data'] = $query;
  326. return $result;
  327. }
  328. //网格化巡检记录明细
  329. public static function getResultDetails($id)
  330. {
  331. $result['status'] = true;
  332. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  333. $result['data'] = [];
  334. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  335. ->where('id', $id)
  336. ->select(
  337. [
  338. 'lrr',
  339. 'dwmc',
  340. 'xjdw',
  341. 'xjqy',
  342. 'jclx',
  343. 'lrsj',
  344. 'jcwt',
  345. 'wtms',
  346. 'dkpz',
  347. 'zgzp'
  348. ]
  349. )->get();
  350. if(count($query) > 0){
  351. for($i=0;$i<count($query);$i++){
  352. $lrr = explode('|',$query[$i]->lrr);
  353. $query[$i]->lrr_name = $lrr[0];
  354. }
  355. }
  356. $query = json_decode($query);
  357. $result['data'] = $query;
  358. return $result;
  359. }
  360. //网格化巡检记录
  361. public static function getFinalList($start_date, $end_date, $depart = '', $person = '')
  362. {
  363. $result['status'] = true;
  364. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  365. $result['data'] = [];
  366. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
  367. if ($start_date == $end_date) {
  368. $query = $query->where('lrsj', 'like', $start_date . '%');
  369. } else {
  370. $query = $query->where('lrsj', '>=', $start_date . ' 00:00:00')->where('lrsj', '<=', $end_date . ' 23:59:59');
  371. }
  372. if ($depart) {
  373. $query = $query->where('xjdw', $depart);
  374. }
  375. if ($person) {
  376. $person_id = DB::connection('mysql_fwview')->table('hrmresource')
  377. ->where('lastname', 'like', '%' . $person . '%')->pluck('id')->all();
  378. $query = $query->whereIn('lrr', $person_id);
  379. }
  380. $query = $query->orderBy('lrdate', 'desc')->groupBy('lrdate', 'xjdw', 'lrr')
  381. ->select(
  382. [
  383. DB::raw('DATE(lrsj) as lrdate'),
  384. 'xjdw',
  385. 'lrr'
  386. ]
  387. )
  388. ->get();
  389. $data = [];
  390. foreach ($query as $key => $val) {
  391. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  392. ->where('id', $val->lrr)->value('lastname');
  393. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  394. ->where('szxmc', $val->xjdw)->count();
  395. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  396. ->where('xjdw', $val->xjdw)
  397. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  398. ->where('lrr', $val->lrr)->count();
  399. if ($allcount <= 0) {
  400. continue;
  401. }
  402. if ($detail >= $allcount) {
  403. $data[] = [
  404. 'depart' => $val->xjdw,
  405. 'lastname' => $lastname,
  406. 'person_id' => $val->lrr,
  407. 'date' => $val->lrdate,
  408. 'is_complete' => 1
  409. ];
  410. } else {
  411. $data[] = [
  412. 'depart' => $val->xjdw,
  413. 'lastname' => $lastname,
  414. 'person_id' => $val->lrr,
  415. 'date' => $val->lrdate,
  416. 'is_complete' => 0
  417. ];
  418. }
  419. }
  420. $result['data'] = $data;
  421. return $result;
  422. }
  423. }