\ 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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', 'lrr', 'dwmc')
  151. ->select(
  152. [
  153. DB::raw('DATE(lrsj) as lrdate'),
  154. 'lrr',
  155. 'dwmc'
  156. ]
  157. )
  158. ->get();
  159. dd($query);
  160. $data = [];
  161. foreach ($query as $key => $val) {
  162. if ($depart == 'all') {
  163. $wghgl = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  164. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  165. ->where('lrr', $val->lrr)
  166. ->groupBy('xjdw')
  167. ->select('xjdw')
  168. ->get();
  169. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  170. ->where('id', $val->lrr)->value('lastname');
  171. foreach ($wghgl as $k => $v) {
  172. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  173. ->where('szxmc', $v->xjdw)->count();
  174. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  175. ->where('xjdw', $v->xjdw)
  176. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  177. ->where('lrr', $val->lrr)->count();
  178. if ($detail >= $allcount) {
  179. $data[$val->lrr] = [
  180. 'department' => $val->dwmc,
  181. 'lastname' => $lastname,
  182. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 0,
  183. ];
  184. } else {
  185. continue;
  186. }
  187. }
  188. } else {
  189. $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
  190. ->where('szxmc', $depart)->count();
  191. $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
  192. ->where('xjdw', $depart)
  193. ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
  194. ->where('lrr', $val->lrr)->count();
  195. if ($detail >= $allcount) {
  196. $lastname = DB::connection('mysql_fwview')->table('hrmresource')
  197. ->where('id', $val->lrr)->value('lastname');
  198. $data[$val->lrr] = [
  199. 'department' => $val->dwmc,
  200. 'lastname' => $lastname,
  201. 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 0,
  202. ];
  203. } else {
  204. continue;
  205. }
  206. }
  207. }
  208. $cmf_arr = array_column($data, 'count');
  209. array_multisort($cmf_arr, SORT_DESC, $data);
  210. $result['data'] = $data;
  211. return $result;
  212. }
  213. }