ApiService.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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_fwview')->table('hrmdepartment')
  91. ->where('subcompanyid1', 49)
  92. ->where('departmentname', 'like', '%' . '洗煤厂')
  93. ->where('id', '!=', 1602)->get();
  94. $depart_arr = [];
  95. foreach ($depart as $key => $val) {
  96. $depart_name = str_replace('洗选中心', '', $val->DEPARTMENTNAME);
  97. $depart_arr[$key] = [
  98. 'name' => $depart_name,
  99. ];
  100. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  101. ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
  102. ->where('xjdw', $depart_name)
  103. ->where('lrsj', 'like', '%' . $date . '%')
  104. ->groupBy('lrr')->select(
  105. [
  106. 'hrmresource.lastname as person_name',
  107. 'uf_wghgl_new.lrr as person_id'
  108. ]
  109. )->get();
  110. $query = json_decode($query);
  111. $depart_arr[$key]['person_list'] = $query;
  112. }
  113. $result['data'] = $depart_arr;
  114. return $result;
  115. }
  116. //网格化人员轨迹
  117. public static function getPersonTravel($person_id, $depart, $date = '')
  118. {
  119. $result['status'] = true;
  120. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  121. $result['data'] = [];
  122. if (!$date) {
  123. $date = date('Y-m-d', time());
  124. }
  125. $res = [];
  126. $area_arr = [];
  127. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  128. ->where('lrr', $person_id)
  129. ->where('lrsj', 'like', '%' . $date . '%')
  130. ->where('xjdw', $depart)
  131. ->orderBy('lrsj', 'asc')->get();
  132. $query = json_decode($query);
  133. if ($query) {
  134. foreach ($query as $key => $val) {
  135. $area_arr[] = $val->jcqy;
  136. $res[] = [
  137. 'area' => $val->jcqy,
  138. 'date' => $val->lrsj,
  139. 'data_id' => $val->id,
  140. 'url' => '/mobilemode/formbasebrowserview.jsp?billid=' . $val->id . '&modeId=580&formId=-976',
  141. ];
  142. }
  143. $area_list = DB::connection('mysql_fwview')->table('formtable_main_974')
  144. ->whereNotIn('qymc', $area_arr)
  145. ->where('szxmc', $depart)->orderBy('areaid', 'asc')->get();
  146. foreach ($area_list as $area) {
  147. $res[] = [
  148. 'area' => $area->qymc,
  149. 'date' => '',
  150. 'data_id' => '',
  151. 'url' => '',
  152. ];
  153. }
  154. $result['data'] = $res;
  155. }
  156. return $result;
  157. }
  158. //网格化巡检记录查询条件
  159. public static function getResultConition()
  160. {
  161. $result['status'] = true;
  162. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  163. $result['data'] = [];
  164. $depart = DB::connection('mysql_fwview')->table('hrmdepartment')
  165. ->where('subcompanyid1', 49)
  166. ->where('departmentname', 'like', '%' . '洗煤厂')
  167. ->where('id', '!=', 1602)->get();
  168. $depart_arr = [];
  169. foreach ($depart as $key => $val) {
  170. $depart_name = str_replace('洗选中心', '', $val->DEPARTMENTNAME);
  171. $depart_arr[$key] = $depart_name;
  172. }
  173. $result['data'] = $depart_arr;
  174. return $result;
  175. }
  176. //网格化巡检记录查询
  177. public static function getResultRecord($depart = 'all', $date_type = 'week')
  178. {
  179. $result['status'] = true;
  180. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  181. $result['data'] = [];
  182. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
  183. if ($depart != 'all') {
  184. $query = $query->where('xjdw', $depart);
  185. }
  186. if ($date_type == 'month') {
  187. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  188. } else if ($date_type == 'quarter') {
  189. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  190. } else {
  191. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  192. }
  193. $query = $query->groupBy('lrdate', 'xjdw', 'lrr', 'dwmc')
  194. ->select(
  195. [
  196. DB::raw('DATE(lrsj) as lrdate'),
  197. 'xjdw',
  198. 'lrr',
  199. 'dwmc'
  200. ]
  201. )
  202. ->get();
  203. $data = [];
  204. $pie = [];
  205. foreach ($query as $key => $val) {
  206. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  207. ->where('id', $val->lrr)->value('lastname');
  208. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  209. ->where('szxmc', $val->xjdw)->count();
  210. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  211. ->where('xjdw', $val->xjdw)
  212. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  213. ->where('lrr', $val->lrr)->count();
  214. if ($allcount <= 0) {
  215. continue;
  216. }
  217. // if ($detail >= $allcount) {
  218. $data[$val->lrr] = [
  219. 'department' => $val->dwmc,
  220. 'lastname' => $lastname,
  221. 'person_id' => $val->lrr,
  222. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  223. ];
  224. $pie[$val->lrr] = [
  225. 'name' => $lastname,
  226. 'value' => isset($data[$val->lrr]['value']) ? $data[$val->lrr]['value'] + 1 : 1,
  227. ];
  228. // } else {
  229. // continue;
  230. // }
  231. }
  232. $data_arr = array_column($data, 'count');
  233. array_multisort($data_arr, SORT_DESC, $data);
  234. $pie_arr = array_column($pie, 'value');
  235. array_multisort($pie_arr, SORT_DESC, $pie);
  236. $result['data']['list'] = $data;
  237. $result['data']['pie'] = $pie;
  238. return $result;
  239. }
  240. //网格化巡检记录列表
  241. public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
  242. {
  243. $result['status'] = true;
  244. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  245. $result['data'] = [];
  246. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')->where('lrr', $person_id);
  247. if ($depart != 'all') {
  248. $query = $query->where('xjdw', $depart);
  249. }
  250. if ($date_type == 'month') {
  251. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  252. } else if ($date_type == 'quarter') {
  253. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  254. } else {
  255. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  256. }
  257. $query = $query->groupBy('lrdate', 'xjdw')
  258. ->select(
  259. [
  260. 'xjdw',
  261. DB::raw('DATE(lrsj) as lrdate'),
  262. ]
  263. )
  264. ->get();
  265. $data = [];
  266. foreach ($query as $key => $val) {
  267. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  268. ->where('id', $person_id)->value('lastname');
  269. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  270. ->where('szxmc', $val->xjdw)->count();
  271. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  272. ->where('xjdw', $val->xjdw)
  273. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  274. ->where('lrr', $person_id)->count();
  275. if ($allcount <= 0) {
  276. continue;
  277. }
  278. if ($detail >= $allcount) {
  279. $data[] = [
  280. 'lastname' => $lastname,
  281. 'person_id' => $person_id,
  282. 'depart' => $val->xjdw,
  283. 'date' => $val->lrdate
  284. ];
  285. } else {
  286. continue;
  287. }
  288. }
  289. $data_arr = array_column($data, 'date');
  290. array_multisort($data_arr, SORT_DESC, $data);
  291. $result['data']['list'] = $data;
  292. return $result;
  293. }
  294. //网格化巡检记录列表明细
  295. public static function getResultDlist($person_id, $depart, $date)
  296. {
  297. $result['status'] = true;
  298. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  299. $result['data'] = [];
  300. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  301. ->where('lrr', $person_id)
  302. ->where('xjdw', $depart)
  303. ->where('lrsj', 'like', $date . '%')
  304. ->orderBy('lrsj', 'desc')
  305. ->select([
  306. 'ID',
  307. 'lrr',
  308. 'xjqy',
  309. 'lrsj',
  310. ])->get();
  311. if(count($query) > 0){
  312. for($i=0;$i<count($query);$i++){
  313. $lrr = explode('|',$query[$i]->lrr);
  314. $query[$i]->lrr_name = $lrr[0];
  315. }
  316. }
  317. $query = json_decode($query);
  318. $result['data'] = $query;
  319. return $result;
  320. }
  321. //网格化巡检记录明细
  322. public static function getResultDetails($id)
  323. {
  324. $result['status'] = true;
  325. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  326. $result['data'] = [];
  327. $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
  328. ->where('id', $id)
  329. ->select(
  330. [
  331. 'lrr',
  332. 'dwmc',
  333. 'xjdw',
  334. 'xjqy',
  335. 'jclx',
  336. 'lrsj',
  337. 'jcwt',
  338. 'wtms',
  339. 'dkpz',
  340. 'zgzp'
  341. ]
  342. )->get();
  343. if(count($query) > 0){
  344. for($i=0;$i<count($query);$i++){
  345. $lrr = explode('|',$query[$i]->lrr);
  346. $query[$i]->lrr_name = $lrr[0];
  347. }
  348. }
  349. $query = json_decode($query);
  350. $result['data'] = $query;
  351. return $result;
  352. }
  353. //网格化巡检记录
  354. public static function getFinalList($start_date, $end_date, $depart = '', $person = '')
  355. {
  356. $result['status'] = true;
  357. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  358. $result['data'] = [];
  359. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
  360. if ($start_date == $end_date) {
  361. $query = $query->where('lrsj', 'like', $start_date . '%');
  362. } else {
  363. $query = $query->where('lrsj', '>=', $start_date . ' 00:00:00')->where('lrsj', '<=', $end_date . ' 23:59:59');
  364. }
  365. if ($depart) {
  366. $query = $query->where('xjdw', $depart);
  367. }
  368. if ($person) {
  369. $person_id = DB::connection('mysql_fwview')->table('hrmresource')
  370. ->where('lastname', 'like', '%' . $person . '%')->pluck('id')->all();
  371. $query = $query->whereIn('lrr', $person_id);
  372. }
  373. $query = $query->orderBy('lrdate', 'desc')->groupBy('lrdate', 'xjdw', 'lrr')
  374. ->select(
  375. [
  376. DB::raw('DATE(lrsj) as lrdate'),
  377. 'xjdw',
  378. 'lrr'
  379. ]
  380. )
  381. ->get();
  382. $data = [];
  383. foreach ($query as $key => $val) {
  384. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  385. ->where('id', $val->lrr)->value('lastname');
  386. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  387. ->where('szxmc', $val->xjdw)->count();
  388. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  389. ->where('xjdw', $val->xjdw)
  390. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  391. ->where('lrr', $val->lrr)->count();
  392. if ($allcount <= 0) {
  393. continue;
  394. }
  395. if ($detail >= $allcount) {
  396. $data[] = [
  397. 'depart' => $val->xjdw,
  398. 'lastname' => $lastname,
  399. 'person_id' => $val->lrr,
  400. 'date' => $val->lrdate,
  401. 'is_complete' => 1
  402. ];
  403. } else {
  404. $data[] = [
  405. 'depart' => $val->xjdw,
  406. 'lastname' => $lastname,
  407. 'person_id' => $val->lrr,
  408. 'date' => $val->lrdate,
  409. 'is_complete' => 0
  410. ];
  411. }
  412. }
  413. $result['data'] = $data;
  414. return $result;
  415. }
  416. }