ApiService.php 16 KB

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