ApiService.php 16 KB

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