ApiService.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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('xjdw1', $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('xjdw1', $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. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  164. ->where('szxmc', $depart)->count();
  165. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  166. ->where('xjdw', $depart)
  167. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  168. ->where('lrr', $val->lrr)->count();
  169. if ($detail >= $allcount) {
  170. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  171. ->where('id', $val->lrr)->value('lastname');
  172. $data[$val->lrr] = [
  173. 'department' => $val->dwmc,
  174. 'lastname' => $lastname,
  175. 'person_id' => $val->lrr,
  176. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  177. ];
  178. $pie[$val->lrr] = [
  179. 'name' => $lastname,
  180. 'value' => isset($data[$val->lrr]['value']) ? $data[$val->lrr]['value'] + 1 : 1,
  181. ];
  182. } else {
  183. continue;
  184. }
  185. }
  186. $data_arr = array_column($data, 'count');
  187. array_multisort($data_arr, SORT_DESC, $data);
  188. $pie_arr = array_column($pie, 'value');
  189. array_multisort($pie_arr, SORT_DESC, $pie);
  190. $result['data']['list'] = $data;
  191. $result['data']['pie'] = $pie;
  192. return $result;
  193. }
  194. //网格化巡检记录查询
  195. public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
  196. {
  197. $result['status'] = true;
  198. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  199. $result['data'] = [];
  200. $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')->where('lrr', $person_id);
  201. if ($depart != 'all') {
  202. $query = $query->where('xjdw', $depart);
  203. }
  204. if ($date_type == 'month') {
  205. $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
  206. } else if ($date_type = 'quarter') {
  207. $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
  208. } else {
  209. $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
  210. }
  211. $query = $query->groupBy('lrdate', 'xjdw')
  212. ->select(
  213. [
  214. 'xjdw',
  215. DB::raw('DATE(lrsj) as lrdate'),
  216. ]
  217. )
  218. ->get();
  219. $data = [];
  220. foreach ($query as $key => $val) {
  221. if ($depart == 'all') {
  222. $wghgl = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  223. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  224. ->where('lrr', $person_id)
  225. ->groupBy('xjdw')
  226. ->select('xjdw')
  227. ->get();
  228. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  229. ->where('id', $person_id)->value('lastname');
  230. foreach ($wghgl as $k => $v) {
  231. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  232. ->where('szxmc', $v->xjdw)->count();
  233. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  234. ->where('xjdw', $v->xjdw)
  235. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  236. ->where('lrr', $val->lrr)->count();
  237. if ($detail >= $allcount) {
  238. $data[$val->lrr] = [
  239. 'department' => $val->dwmc,
  240. 'lastname' => $lastname,
  241. 'person_id' => $val->lrr,
  242. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  243. ];
  244. } else {
  245. continue;
  246. }
  247. }
  248. } else {
  249. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  250. ->where('szxmc', $depart)->count();
  251. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  252. ->where('xjdw', $depart)
  253. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  254. ->where('lrr', $val->lrr)->count();
  255. if ($detail >= $allcount) {
  256. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  257. ->where('id', $val->lrr)->value('lastname');
  258. $data[$val->lrr] = [
  259. 'department' => $val->dwmc,
  260. 'lastname' => $lastname,
  261. 'person_id' => $val->lrr,
  262. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
  263. ];
  264. } else {
  265. continue;
  266. }
  267. }
  268. }
  269. $data_arr = array_column($data, 'count');
  270. array_multisort($data_arr, SORT_DESC, $data);
  271. $result['data']['list'] = $data;
  272. return $result;
  273. }
  274. }