Hydraulic.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace catchAdmin\hydraulic\model;
  3. use catchAdmin\api\Listen;
  4. use catcher\base\CatchModel as Model;
  5. use \think\facade\Db;
  6. use catchAdmin\system\model\SysDictData;
  7. use catchAdmin\permissions\model\DataRangScopeTrait;
  8. class Hydraulic extends Model
  9. {
  10. use DataRangScopeTrait;
  11. // 表名
  12. public $name = 'hydraulic';
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. // 编号
  17. 'number',
  18. // 所属部门
  19. 'department_id',
  20. // 告警状态
  21. 'alarm_state',
  22. // 网络状态
  23. 'net_state',
  24. // //扭矩
  25. // 'torque',
  26. // //压力
  27. // 'stress',
  28. // //螺栓尺寸
  29. // 'bolts_size',
  30. // //螺栓数量
  31. // 'bolts_num',
  32. //备注
  33. 'remark',
  34. // 创建人ID
  35. 'creator_id',
  36. // 创建时间
  37. 'created_at',
  38. // 更新时间
  39. 'updated_at',
  40. // 软删除
  41. 'deleted_at',
  42. 'longitude',
  43. 'latitude',
  44. 'max_pressure',
  45. 'min_pressure',
  46. 'imei',
  47. 'sim_card',
  48. 'effective_time',
  49. 'effective_period',
  50. //设备的id
  51. 'eq_id'
  52. );
  53. /**
  54. * 获取列表
  55. */
  56. public function getList()
  57. {
  58. $res = $this->dataRange()
  59. ->catchSearch()
  60. ->append(['depart_name', 'alarm_state_text', 'creator_user', 'model_name'])
  61. ->order($this->aliasField('id'), 'desc')
  62. ->paginate();
  63. return $res;
  64. }
  65. /**
  66. * 获取轨迹地图列表定位不分页 只查询有定位时间的
  67. */
  68. public function queryLocationList()
  69. {
  70. $res = $this->dataRange()
  71. ->catchSearch()
  72. ->select();
  73. return $res;
  74. }
  75. /**
  76. * 获取导入用户(文本)
  77. */
  78. public function getCreatorUserAttr($value)
  79. {
  80. $uid = $this->creator_id;
  81. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  82. }
  83. /**
  84. * 使用状态
  85. */
  86. public function getIsUsedAttr($value)
  87. {
  88. if ($value != 0) {
  89. return true;
  90. } else {
  91. return false;
  92. }
  93. }
  94. /**
  95. * 获取部门名称(文本)
  96. */
  97. public function getDepartNameAttr()
  98. {
  99. $id = $this->getData('department_id');
  100. return Db::table('departments')->where('id', $id)->value('department_name');
  101. }
  102. /**
  103. * 获取类型名称
  104. */
  105. public function getModelAttr($value)
  106. {
  107. return (int)$value;
  108. }
  109. /**
  110. * 校验日期
  111. */
  112. public function getEffectiveTimeAttr($value)
  113. {
  114. if ($value) {
  115. return date('Y-m-d H:i:s', $value);
  116. } else {
  117. return '-';
  118. }
  119. }
  120. /**
  121. * 校验日期
  122. */
  123. public function getCheckTimeAttr($value)
  124. {
  125. if ($value) {
  126. return date('Y-m-d H:i:s', $value);
  127. } else {
  128. return '-';
  129. }
  130. }
  131. /**
  132. * 获取告警状态文本
  133. */
  134. public function getAlarmStateTextAttr($value)
  135. {
  136. $alarm_state = $this->getData('alarm_state');
  137. return $alarm_state ? '告警' : '正常';
  138. }
  139. /**
  140. * 根据部门搜索
  141. */
  142. public function searchDepartmentIdAttr($query, $value, $data)
  143. {
  144. if ($value) {
  145. $id = end($value);
  146. return $query->where('department_id', '=', $id);
  147. }
  148. }
  149. /**
  150. * 根据number搜索
  151. */
  152. public function searchNumberAttr($query, $value, $data)
  153. {
  154. return $query->where('number', 'like', '%' . $value . '%');
  155. }
  156. /**
  157. * 根据name搜索
  158. */
  159. public function searchNameAttr($query, $value, $data)
  160. {
  161. return $query->where('name', 'like', '%' . $value . '%');
  162. }
  163. /**
  164. * 根据model搜索
  165. */
  166. public function searchModelAttr($query, $value, $data)
  167. {
  168. return $query->where('model', 'like', '%' . $value . '%');
  169. }
  170. /**
  171. * 根据name搜索
  172. */
  173. public function searchIsUsedAttr($query, $value, $data)
  174. {
  175. return $query->where('is_used', $value);
  176. }
  177. }