update
This commit is contained in:
parent
0d7e569cf8
commit
7d656a3fc4
|
@ -56,7 +56,6 @@ class FarmLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||
public function lists(): array
|
||||
{
|
||||
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'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
|
|
|
@ -131,16 +131,7 @@ class DeviceLogic extends BaseLogic
|
|||
|
||||
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 = [];
|
||||
if (!empty($params['name'])) {
|
||||
$queryWhere[] = ['d.name', 'like', '%' . $params['name'] . '%'];
|
||||
|
@ -150,7 +141,7 @@ class DeviceLogic extends BaseLogic
|
|||
$deviceIdArray= [];
|
||||
}
|
||||
$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 p','p.id = pd.product_id')
|
||||
->leftJoin('user u','u.id = p.user_id')
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -16,16 +16,14 @@ use think\facade\Log;
|
|||
class DataCollectController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['collect', 'disabled'];
|
||||
// 种植数据采集
|
||||
// 养殖数据采集
|
||||
public function collect()
|
||||
{
|
||||
try {
|
||||
|
||||
$parmas = $this->request->post();
|
||||
Log::info('采集消息发布'.json_encode($parmas));
|
||||
if(!$parmas || !isset($parmas['username']) || $parmas['username']==''){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
|
||||
$payload= json_decode($parmas['payload'], true);
|
||||
|
||||
$user = User::where('account', $parmas['username'])->find();
|
||||
|
|
|
@ -5,14 +5,10 @@ namespace app\api\controller;
|
|||
use app\adminapi\lists\fence_house\FenceHouseLists;
|
||||
use app\adminapi\logic\fence_house\FenceHouseLogic;
|
||||
use app\adminapi\validate\fence_house\FenceHouseValidate;
|
||||
use think\response\Json;
|
||||
|
||||
class FenceHouseController extends BaseApiController
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new FenceHouseLists());
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = (new FenceHouseValidate())->post()->goCheck('add');
|
||||
|
@ -46,4 +42,14 @@ class FenceHouseController extends BaseApiController
|
|||
$result = FenceHouseLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Json
|
||||
*/
|
||||
public function datas(): Json
|
||||
{
|
||||
$params = ['user_id', $this->userId];
|
||||
$datas = (new FenceHouseLogic())->datas($params);
|
||||
return $this->data($datas);
|
||||
}
|
||||
}
|
|
@ -5,9 +5,12 @@ use app\common\enum\notice\NoticeEnum;
|
|||
use app\common\model\action\Action;
|
||||
use app\common\model\device\Device;
|
||||
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\land\Land;
|
||||
use app\common\model\land\LandProduct;
|
||||
use app\common\model\land\Product;
|
||||
use app\common\model\LandCollection;
|
||||
use app\common\model\monitor\MonitorData;
|
||||
use app\common\model\plant\Plant;
|
||||
|
@ -26,68 +29,41 @@ class IndexController extends BaseApiController
|
|||
|
||||
public array $notNeedLogin = ['code','suYuan'];
|
||||
|
||||
//溯源首页
|
||||
//首页
|
||||
public function index(): Json
|
||||
{
|
||||
$params = $this->request->get(['land_id']);
|
||||
//获取土地信息
|
||||
if(isset($params['land_id']) && $params['land_id'] !=''){
|
||||
$data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray();
|
||||
$params = $this->request->get();
|
||||
//获取栏舍信息
|
||||
if(isset($params['fence_house_id']) && $params['fence_house_id'] !=''){
|
||||
$data = FenceHouse::where('user_id',$this->userId)->where('id',$params['fence_house_id'])->order('id desc')->findOrEmpty()->toArray();
|
||||
}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)){
|
||||
return $this->success('请求成功',[]);
|
||||
}
|
||||
$data['pic'] = json_decode($data['pic'],true);
|
||||
//获取绑定产品
|
||||
$landProduct = LandProduct::where('land_id',$data['id'])->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['device_id'] = $device['id'];
|
||||
// 监控视频封面
|
||||
$file = File::where('cid', $device['id'])->order('id', 'desc')->findOrEmpty();
|
||||
$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()){
|
||||
$data['monitor'] = [];
|
||||
}else{
|
||||
$data['monitor']['soil_monitor_data'] = [
|
||||
'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){
|
||||
$monitorThreshold=$monitorThreshold[0];
|
||||
}else{
|
||||
$monitorThreshold=[];
|
||||
}
|
||||
$monitorThreshold['ambient_air_pressure_max'] = 120;
|
||||
$monitorThreshold['ambient_air_pressure_min'] = 10;
|
||||
$data['monitor']['threshold'] = $monitorThreshold;
|
||||
}
|
||||
}
|
||||
$product = Product::where('fence_house_id', $data['id'])->findOrEmpty()->toArray();
|
||||
$deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id');
|
||||
$device = Device::whereIn('id', $deviceIds)->where('device_type', 3)->findOrEmpty();
|
||||
$data['video_url'] = $device['video_url'];
|
||||
$data['device_id'] = $device['id'];
|
||||
// 监控视频封面
|
||||
$file = File::where('cid', $device['id'])->order('id', 'desc')->findOrEmpty();
|
||||
$data['video_cover'] = isset($file['uri'])? env('project.project_url').'/'.$file['uri']: '';
|
||||
|
||||
//todo 请求python接口
|
||||
$data['monitor'] = [];
|
||||
|
||||
$monitorThreshold = MonitorThreshold::find();
|
||||
if($monitorThreshold->toArray()!=null){
|
||||
$monitorThreshold=$monitorThreshold[0];
|
||||
}else{
|
||||
$monitorThreshold=[];
|
||||
}
|
||||
|
||||
$data['monitor']['threshold'] = $monitorThreshold;
|
||||
|
||||
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue