This commit is contained in:
chenbo 2024-01-17 11:59:25 +08:00
parent 0d7e569cf8
commit 7d656a3fc4
6 changed files with 126 additions and 76 deletions

View File

@ -56,7 +56,6 @@ class FarmLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
return Farm::where($this->searchWhere) return Farm::where($this->searchWhere)
->field(['id', 'farm_name', 'farm_type', 'breed_type', 'form_scale', 'master', 'master_contact', 'province', 'city', 'area', 'street', 'village', 'bridge', 'address', 'image'])
->with(['provinceAttr', 'cityAttr', 'areaAttr', 'streetAttr', 'villageAttr', 'bridgeAttr']) ->with(['provinceAttr', 'cityAttr', 'areaAttr', 'streetAttr', 'villageAttr', 'bridgeAttr'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])

View File

@ -131,16 +131,7 @@ class DeviceLogic extends BaseLogic
public function datas($params): array public function datas($params): array
{ {
$userWhere['d.user_id'] = -1;
if (!empty($params['user_id'])) {
$userWhere['d.user_id'] = $params['user_id'];
}
if (!request()->adminInfo['root'] && request()->adminInfo['user_id']) {
$userWhere['d.user_id'] = request()->adminInfo['user_id'];
}
if (request()->adminInfo['root']) {
unset($userWhere['d.user_id']);
}
$queryWhere = []; $queryWhere = [];
if (!empty($params['name'])) { if (!empty($params['name'])) {
$queryWhere[] = ['d.name', 'like', '%' . $params['name'] . '%']; $queryWhere[] = ['d.name', 'like', '%' . $params['name'] . '%'];
@ -150,7 +141,7 @@ class DeviceLogic extends BaseLogic
$deviceIdArray= []; $deviceIdArray= [];
} }
$lists = Db::name('device')->alias('d') $lists = Db::name('device')->alias('d')
->where($userWhere)->where($queryWhere)->whereNotIn('d.id', $deviceIdArray) ->where($queryWhere)->whereNotIn('d.id', $deviceIdArray)
->leftJoin('product_device pd','pd.device_id = d.id') ->leftJoin('product_device pd','pd.device_id = d.id')
->leftJoin('product p','p.id = pd.product_id') ->leftJoin('product p','p.id = pd.product_id')
->leftJoin('user u','u.id = p.user_id') ->leftJoin('user u','u.id = p.user_id')

View File

@ -0,0 +1,80 @@
<?php
namespace app\api\controller;
use app\common\model\dict\DictData;
use think\facade\Db;
class CommonController extends BaseApiController
{
public array $notNeedLogin = ['city', 'area', 'street','province','village','brigade','dict_data_lists','dict_data_lists_by_type_value','getMiniProgramInfo'];
//**省列表 */
public function province()
{
$data = Db::name('geo_province')->where(['switch' => 1])->select();
return $this->data($data->toArray());
} //**市列表 */
public function city($city)
{
$data = Db::name('geo_city')->where(['province_code' => $city])->select();
return $this->data($data->toArray());
}
//**区域列表 */
public function area($area)
{
$data = Db::name('geo_county')->where(['city_code' => $area])->select();
return $this->data($data->toArray());
}
//**街道列表 */
public function street($street)
{
$data = Db::name('geo_town')->where(['county_code' => $street])->select();
return $this->data($data->toArray());
}
//**村列表 */
public function village($village)
{
$data = Db::name('geo_village')->where(['street_code' => $village])->select();
return $this->data($data->toArray());
}
//**小队列表 */
public function brigade()
{
$data = Db::name('geo_brigade')->select();
return $this->data($data->toArray());
}
//**字典列表 */
public function dict_data_lists($type_id)
{
$data= DictData::where(['type_id' => $type_id])
->append(['status_desc'])
->limit(100)
->order(['sort' => 'desc', 'id' => 'desc'])
->select();
return $this->data($data->toArray());
}
public function dict_data_lists_by_type_value($type_value)
{
$data= DictData::where(['type_value' => $type_value])
->append(['status_desc'])
->limit(100)
->order(['sort' => 'desc', 'id' => 'desc'])
->select();
return $this->data($data->toArray());
}
public function getMiniProgramInfo()
{
$param = $this->request->param();
$data = Db::name('miniprogram')->where(['name' => $param['name']])->order('id', 'desc')->find();
return $this->data($data);
}
}

View File

@ -16,16 +16,14 @@ use think\facade\Log;
class DataCollectController extends BaseApiController class DataCollectController extends BaseApiController
{ {
public array $notNeedLogin = ['collect', 'disabled']; public array $notNeedLogin = ['collect', 'disabled'];
// 种植数据采集 // 养殖数据采集
public function collect() public function collect()
{ {
try { try {
$parmas = $this->request->post(); $parmas = $this->request->post();
Log::info('采集消息发布'.json_encode($parmas)); Log::info('采集消息发布'.json_encode($parmas));
if(!$parmas || !isset($parmas['username']) || $parmas['username']==''){
return $this->fail('参数错误');
}
$payload= json_decode($parmas['payload'], true); $payload= json_decode($parmas['payload'], true);
$user = User::where('account', $parmas['username'])->find(); $user = User::where('account', $parmas['username'])->find();

View File

@ -5,14 +5,10 @@ namespace app\api\controller;
use app\adminapi\lists\fence_house\FenceHouseLists; use app\adminapi\lists\fence_house\FenceHouseLists;
use app\adminapi\logic\fence_house\FenceHouseLogic; use app\adminapi\logic\fence_house\FenceHouseLogic;
use app\adminapi\validate\fence_house\FenceHouseValidate; use app\adminapi\validate\fence_house\FenceHouseValidate;
use think\response\Json;
class FenceHouseController extends BaseApiController class FenceHouseController extends BaseApiController
{ {
public function lists()
{
return $this->dataLists(new FenceHouseLists());
}
public function add() public function add()
{ {
$params = (new FenceHouseValidate())->post()->goCheck('add'); $params = (new FenceHouseValidate())->post()->goCheck('add');
@ -46,4 +42,14 @@ class FenceHouseController extends BaseApiController
$result = FenceHouseLogic::detail($params); $result = FenceHouseLogic::detail($params);
return $this->data($result); return $this->data($result);
} }
/**
* @return Json
*/
public function datas(): Json
{
$params = ['user_id', $this->userId];
$datas = (new FenceHouseLogic())->datas($params);
return $this->data($datas);
}
} }

View File

@ -5,9 +5,12 @@ use app\common\enum\notice\NoticeEnum;
use app\common\model\action\Action; use app\common\model\action\Action;
use app\common\model\device\Device; use app\common\model\device\Device;
use app\common\model\device\MonitorThreshold; use app\common\model\device\MonitorThreshold;
use app\common\model\farm\Farm;
use app\common\model\fence_house\FenceHouse;
use app\common\model\file\File; use app\common\model\file\File;
use app\common\model\land\Land; use app\common\model\land\Land;
use app\common\model\land\LandProduct; use app\common\model\land\LandProduct;
use app\common\model\land\Product;
use app\common\model\LandCollection; use app\common\model\LandCollection;
use app\common\model\monitor\MonitorData; use app\common\model\monitor\MonitorData;
use app\common\model\plant\Plant; use app\common\model\plant\Plant;
@ -26,68 +29,41 @@ class IndexController extends BaseApiController
public array $notNeedLogin = ['code','suYuan']; public array $notNeedLogin = ['code','suYuan'];
//溯源首页 //首页
public function index(): Json public function index(): Json
{ {
$params = $this->request->get(['land_id']); $params = $this->request->get();
//获取土地信息 //获取栏舍信息
if(isset($params['land_id']) && $params['land_id'] !=''){ if(isset($params['fence_house_id']) && $params['fence_house_id'] !=''){
$data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray(); $data = FenceHouse::where('user_id',$this->userId)->where('id',$params['fence_house_id'])->order('id desc')->findOrEmpty()->toArray();
}else{ }else{
$data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray(); $data = FenceHouse::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray();
} }
if(empty($data)){ if(empty($data)){
return $this->success('请求成功',[]); return $this->success('请求成功',[]);
} }
$data['pic'] = json_decode($data['pic'],true); $product = Product::where('fence_house_id', $data['id'])->findOrEmpty()->toArray();
//获取绑定产品 $deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id');
$landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty(); $device = Device::whereIn('id', $deviceIds)->where('device_type', 3)->findOrEmpty();
if($landProduct->isEmpty()){
$data['monitor'] = [];
}else{
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->findOrEmpty();
$device = Device::where('id', $productDevice['device_id'])->findOrEmpty();
$data['video_url'] = $device['video_url']; $data['video_url'] = $device['video_url'];
$data['device_id'] = $device['id']; $data['device_id'] = $device['id'];
// 监控视频封面 // 监控视频封面
$file = File::where('cid', $device['id'])->order('id', 'desc')->findOrEmpty(); $file = File::where('cid', $device['id'])->order('id', 'desc')->findOrEmpty();
$data['video_cover'] = isset($file['uri'])? env('project.project_url').'/'.$file['uri']: ''; $data['video_cover'] = isset($file['uri'])? env('project.project_url').'/'.$file['uri']: '';
$landCollection = LandCollection::where('land_id',$params['land_id'])->order('id desc')->findOrEmpty();
if($landCollection->isEmpty()){ //todo 请求python接口
$data['monitor'] = []; $data['monitor'] = [];
}else{
$data['monitor']['soil_monitor_data'] = [ $monitorThreshold = MonitorThreshold::find();
'soil_temperature'=>$landCollection['soil_temperature'],
'soil_moisture'=>$landCollection['soil_moisture'],
'conductivity'=>$landCollection['soil_conductivity'],
'ph'=>$landCollection['soil_PH'],
'n_content'=>$landCollection['soil_potassium_phosphate_nitrogen'],
'p_content'=>$landCollection['soil_potassium_phosphate_phosphorus'],
'k_content'=>$landCollection['soil_potassium_phosphate_potassium'],
'create_time' => $landCollection['create_time']
];
$data['monitor']['air_monitor_data'] = [
'wind_direction'=>$landCollection['wind_direction'],
'wind_speed'=>$landCollection['wind_speed'],
'air_temperature'=>$landCollection['ambient_temperature'],
'air_moisture'=>$landCollection['ambient_humidity'],
'co2_content'=>$landCollection['carbon_dioxide'],
'pressure'=>$landCollection['ambient_air_pressure'],
'rainfall'=>$landCollection['rainfall'],
'light_intensity'=>$landCollection['ambient_lighting'],
'create_time' => $landCollection['create_time']
];
$monitorThreshold = MonitorThreshold::select();
if($monitorThreshold->toArray()!=null){ if($monitorThreshold->toArray()!=null){
$monitorThreshold=$monitorThreshold[0]; $monitorThreshold=$monitorThreshold[0];
}else{ }else{
$monitorThreshold=[]; $monitorThreshold=[];
} }
$monitorThreshold['ambient_air_pressure_max'] = 120;
$monitorThreshold['ambient_air_pressure_min'] = 10;
$data['monitor']['threshold'] = $monitorThreshold; $data['monitor']['threshold'] = $monitorThreshold;
}
}
return $this->success('请求成功',$data); return $this->success('请求成功',$data);
} }