Fan.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-05-27 13:34:31
  7. * @LastEditors: likang
  8. * @LastEditTime: 2022-07-26 15:07:54
  9. */
  10. namespace catchAdmin\wind\model;
  11. use catchAdmin\api\Listen;
  12. use catchAdmin\hydraulic\model\DeviceMold as ModelDeviceMold;
  13. use catcher\base\CatchModel as Model;
  14. use think\facade\Db;
  15. use catchAdmin\wind\model\get\FanGet;
  16. use catchAdmin\wind\model\search\FanSearch;
  17. use catchAdmin\permissions\model\DataRangScopeTrait;
  18. use catchAdmin\system\controller\Developer;
  19. use DeviceMold;
  20. class Fan extends Model
  21. {
  22. use Listen;
  23. use DataRangScopeTrait;
  24. use FanGet;
  25. use FanSearch;
  26. // 表名
  27. public $name = 'fan';
  28. // 数据库字段映射
  29. public $field = array(
  30. 'id',
  31. // 风厂的id
  32. 'wind_id',
  33. // 编号
  34. 'number',
  35. 'fan_model',
  36. 'out_date',
  37. 'supplier',
  38. 'longitude',
  39. 'latitude',
  40. 'info',
  41. 'address',
  42. // 创建人ID
  43. 'creator_id',
  44. // 创建时间
  45. 'created_at',
  46. // 更新时间
  47. 'updated_at',
  48. // 软删除
  49. 'deleted_at',
  50. );
  51. public function getList()
  52. {
  53. return $this->dataRange()
  54. ->catchSearch()
  55. ->append(['wind_name', 'model_name'])
  56. ->field('*')
  57. ->catchOrder()
  58. ->creator()
  59. ->paginate();
  60. }
  61. public function getFanList()
  62. {
  63. return $this->dataRange()
  64. ->catchSearch()
  65. ->field('id as value,number as name')
  66. ->catchOrder()
  67. ->select();
  68. }
  69. //根据风场的id,获取风机的机位号
  70. public function getFanListByWindId($wind_id)
  71. {
  72. $data = $this->where('wind_id', $wind_id)->select();
  73. return $data;
  74. }
  75. /**
  76. * 风机下发内容
  77. */
  78. public function addContent(&$obj)
  79. {
  80. $data = null;
  81. $content = null;
  82. $wind_number = Wind::where('id', $obj->wind_id)->value('number');
  83. $model_name = ModelDeviceMold::where('device_type', 4)->where('id', $obj->fan_model)->value('name');
  84. $data = [
  85. 'id' => intval($obj->id),
  86. 'wnum' => $wind_number ? $wind_number : 0,
  87. 'number' => strval($this->number),
  88. 'model' => $model_name ? $model_name : ""
  89. ];
  90. $content['data'] = $data;
  91. $content['type'] = 'Fan';
  92. return $content;
  93. }
  94. /**
  95. * @Descripttion: 风机的id
  96. * @name: likang
  97. * @param {*} $wind_num
  98. * @return {*}
  99. */
  100. public function IssuedFanModel($wind_id)
  101. {
  102. //获取风场编号
  103. //分组查询当前风场所有的风机模型
  104. $array = [];
  105. //差集
  106. $diff_array = [];
  107. $content = [];
  108. $diff_array1 = [];
  109. $fan_model = $this->where('wind_id', $wind_id)->group('fan_model')->column('fan_model');
  110. //获取风机名称
  111. $wind_num = Wind::where('id', $wind_id)->value('number');
  112. $wheres[] = ['device_type', '=', 4];
  113. $wheres[] = ['id', 'in', $fan_model];
  114. $model_name = ModelDeviceMold::where($wheres)->column('name');
  115. $where[] = ['ContentType', '=', 'FanModel'];
  116. $where[] = ['ContentId', 'like', '%' . $wind_num . '_%'];
  117. //获取当前风场下发的风机模型
  118. $list = Db::name('publish')->where($where)->field('ContentId')->select();
  119. //截取ContentId 获取模型名称
  120. foreach ($list as $item) {
  121. $array[] = substr(strstr($item['ContentId'], '_'), 1);
  122. }
  123. $diff_array = array_diff($array, $model_name);
  124. foreach ($diff_array as $item) {
  125. Db::name('publish')->where('ContentType', 'FanModel')->where("ContentId", $wind_num . '_' . $item)->update(
  126. [
  127. "Type" => 'delete',
  128. 'Version' => msectime()
  129. ]
  130. );
  131. }
  132. $diff_array1 = array_diff($model_name, $array);
  133. foreach ($diff_array1 as $item) {
  134. $time = msectime();
  135. $json = json_encode([
  136. 'id' => $wind_num . '_' . $item,
  137. 'wnum' => strval($wind_num),
  138. 'model' => strval($item)
  139. ]);
  140. $content[] = [
  141. 'Type' => 'add',
  142. 'ContentType' => 'FanModel',
  143. 'Version' => $time,
  144. 'ContentId' => $wind_num . '_' . $item,
  145. 'Content' => $json,
  146. 'AddTime' => $time,
  147. 'Status' => 1
  148. ];
  149. }
  150. Db::name('publish')->insertAll($content);
  151. //风机 模型id
  152. }
  153. }