ApiService.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  145. } else if ($date_type == 'quarter') {
  146. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  147. } else {
  148. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  149. }
  150. $query = $query->groupBy('lrdate', 'xjdw', 'lrr', 'dwmc')
  151. ->select(
  152. [
  153. DB::raw('DATE(lrsj) as lrdate'),
  154. 'xjdw',
  155. 'lrr',
  156. 'dwmc'
  157. ]
  158. )
  159. ->get();
  160. $data = [];
  161. $pie = [];
  162. foreach ($query as $key => $val) {
  163. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  164. ->where('id', $val->lrr)->value('lastname');
  165. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  166. ->where('szxmc', $val->xjdw)->count();
  167. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  168. ->where('xjdw', $val->xjdw)
  169. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  170. ->where('lrr', $val->lrr)->count();
  171. if ($allcount <= 0) {
  172. continue;
  173. }
  174. if ($detail >= $allcount) {
  175. $data[$val->lrr] = [
  176. 'department' => $val->dwmc,
  177. 'lastname' => $lastname,
  178. 'person_id' => $val->lrr,
  179. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  180. ];
  181. $pie[$val->lrr] = [
  182. 'name' => $lastname,
  183. 'value' => isset($data[$val->lrr]['value']) ? $data[$val->lrr]['value'] + 1 : 1,
  184. ];
  185. } else {
  186. continue;
  187. }
  188. }
  189. $data_arr = array_column($data, 'count');
  190. array_multisort($data_arr, SORT_DESC, $data);
  191. $pie_arr = array_column($pie, 'value');
  192. array_multisort($pie_arr, SORT_DESC, $pie);
  193. $result['data']['list'] = $data;
  194. $result['data']['pie'] = $pie;
  195. return $result;
  196. }
  197. //网格化巡检记录列表
  198. public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
  199. {
  200. $result['status'] = true;
  201. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  202. $result['data'] = [];
  203. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')->where('lrr', $person_id);
  204. if ($depart != 'all') {
  205. $query = $query->where('xjdw', $depart);
  206. }
  207. if ($date_type == 'month') {
  208. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  209. } else if ($date_type == 'quarter') {
  210. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  211. } else {
  212. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  213. }
  214. $query = $query->groupBy('lrdate', 'xjdw')
  215. ->select(
  216. [
  217. 'xjdw',
  218. DB::raw('DATE(lrsj) as lrdate'),
  219. ]
  220. )
  221. ->get();
  222. $data = [];
  223. foreach ($query as $key => $val) {
  224. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  225. ->where('id', $person_id)->value('lastname');
  226. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  227. ->where('szxmc', $val->xjdw)->count();
  228. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  229. ->where('xjdw', $val->xjdw)
  230. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  231. ->where('lrr', $person_id)->count();
  232. if ($allcount <= 0) {
  233. continue;
  234. }
  235. if ($detail >= $allcount) {
  236. $data[] = [
  237. 'lastname' => $lastname,
  238. 'person_id' => $person_id,
  239. 'depart' => $val->xjdw,
  240. 'date' => $val->lrdate
  241. ];
  242. } else {
  243. continue;
  244. }
  245. }
  246. $data_arr = array_column($data, 'date');
  247. array_multisort($data_arr, SORT_DESC, $data);
  248. $result['data']['list'] = $data;
  249. return $result;
  250. }
  251. //网格化巡检记录列表明细
  252. public static function getResultDlist($person_id, $depart, $date)
  253. {
  254. $result['status'] = true;
  255. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  256. $result['data'] = [];
  257. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  258. ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
  259. ->where('lrr', $person_id)
  260. ->where('xjdw', $depart)
  261. ->where('lrsj', 'like', $date . '%')
  262. ->orderBy('lrsj', 'desc')
  263. ->select(
  264. [
  265. 'uf_wghgl_new.id',
  266. 'lastname',
  267. 'jcqy',
  268. 'lrsj',
  269. ]
  270. )->get();
  271. $query = json_decode($query);
  272. $result['data'] = $query;
  273. return $result;
  274. }
  275. //网格化巡检记录明细
  276. public static function getResultDetails($id)
  277. {
  278. $result['status'] = true;
  279. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  280. $result['data'] = [];
  281. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  282. ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
  283. ->where('uf_wghgl_new.id', $id)
  284. ->select(
  285. [
  286. 'lastname',
  287. 'dwmc',
  288. 'xjdw',
  289. 'jcqy',
  290. 'jclx',
  291. 'lrsj',
  292. 'jcwt',
  293. 'wtms',
  294. 'dkpz'
  295. ]
  296. )->get();
  297. $query = json_decode($query);
  298. $result['data'] = $query;
  299. return $result;
  300. }
  301. //网格化巡检记录
  302. public static function getFinalList($start_date, $end_date, $depart = '', $person = '')
  303. {
  304. $result['status'] = true;
  305. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  306. $result['data'] = [];
  307. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
  308. if ($start_date == $end_date) {
  309. $query = $query->where('lrsj', 'like', $start_date . '%');
  310. } else {
  311. $query = $query->where('lrsj', '>=', $start_date . ' 00:00:00')->where('lrsj', '<=', $end_date . ' 23:59:59');
  312. }
  313. if ($depart) {
  314. $query = $query->where('xjdw', $depart);
  315. }
  316. if ($person) {
  317. $person_id = DB::connection('mysql_fwview')->table('hrmresource')
  318. ->where('lastname', 'like', '%' . $person . '%')->pluck('id')->all();
  319. $query = $query->whereIn('lrr', $person_id);
  320. }
  321. $query = $query->orderBy('lrdate', 'desc')->groupBy('lrdate', 'xjdw', 'lrr')
  322. ->select(
  323. [
  324. DB::raw('DATE(lrsj) as lrdate'),
  325. 'xjdw',
  326. 'lrr'
  327. ]
  328. )
  329. ->get();
  330. $data = [];
  331. foreach ($query as $key => $val) {
  332. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  333. ->where('id', $val->lrr)->value('lastname');
  334. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  335. ->where('szxmc', $val->xjdw)->count();
  336. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  337. ->where('xjdw', $val->xjdw)
  338. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  339. ->where('lrr', $val->lrr)->count();
  340. if ($allcount <= 0) {
  341. continue;
  342. }
  343. if ($detail >= $allcount) {
  344. $data[] = [
  345. 'depart' => $val->xjdw,
  346. 'lastname' => $lastname,
  347. 'person_id' => $val->lrr,
  348. 'date' => $val->lrdate,
  349. 'is_complete' => 1
  350. ];
  351. } else {
  352. $data[] = [
  353. 'depart' => $val->xjdw,
  354. 'lastname' => $lastname,
  355. 'person_id' => $val->lrr,
  356. 'date' => $val->lrdate,
  357. 'is_complete' => 0
  358. ];
  359. }
  360. }
  361. $result['data'] = $data;
  362. return $result;
  363. }
  364. }