This commit is contained in:
chenbo 2024-01-13 14:20:38 +08:00
parent 0485c5e639
commit 485197c75c
18 changed files with 336 additions and 344 deletions

View File

@ -24,3 +24,7 @@ export function apiFenceHouseDelete(params: any) {
export function apiFenceHouseDetail(params: any) {
return request.get({ url: '/fence_house.fence_house/detail', params })
}
export function apiFarmLists(params: any) {
return request.get({ url: '/farm.farm/datas', params })
}

View File

@ -24,3 +24,7 @@ export function apiMonitorThresholdDelete(params: any) {
export function apiMonitorThresholdDetail(params: any) {
return request.get({ url: '/device.monitor_threshold/detail', params })
}
export function apiFenceHouseLists(params: any) {
return request.get({ url: '/fence_house.fence_house/datas', params })
}

View File

@ -43,7 +43,7 @@
<el-form-item label="设备编码" prop="code">
<el-input v-model="formData.code" clearable placeholder="请输入设备编码" />
</el-form-item>
<el-form-item label="产品图" prop="image">
<el-form-item label="设备图" prop="image">
<el-upload
class="avatar-uploader"
:accept="acceptFileTypes"
@ -240,10 +240,17 @@ const handleSubmit = async () => {
popupRef.value?.close()
emit('success')
}
const generateUuid = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0
const v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
//
const open = (type = 'add') => {
mode.value = type
formData.code = generateUuid()
popupRef.value?.open()
}

View File

@ -9,8 +9,21 @@
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<el-form-item label="养殖基地id" prop="farm_id">
<el-input v-model="formData.farm_id" clearable placeholder="请输入养殖基地id" />
<el-form-item label="养殖基地" prop="farm_id">
<el-select
v-model="formData.farm_id"
remote
filterable
:remote-method="queryFarm"
:loading="loading"
>
<el-option
v-for="(item, index) in optionsData.farmList"
:key="index"
:label="item.farminfo"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="栏舍名称" prop="fence_house_name">
<el-input v-model="formData.fence_house_name" clearable placeholder="请输入栏舍名称" />
@ -56,9 +69,11 @@
<script lang="ts" setup name="fenceHouseEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiFenceHouseAdd, apiFenceHouseEdit, apiFenceHouseDetail } from '@/api/fence_house'
import {apiFenceHouseAdd, apiFenceHouseEdit, apiFenceHouseDetail, apiFenceHouseLists, apiFarmLists} from '@/api/fence_house'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import {useDictOptions} from "@/hooks/useDictOptions";
import {ref} from "vue";
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
@ -96,6 +111,27 @@ const formRules = reactive<any>({
})
const { optionsData } = useDictOptions<{
farmList: any[]
}>({
farmList: {
api: apiFarmLists,
}
})
const loading = ref(false)
const queryFarm= async (query: string) => {
loading.value = true
const farmList = await apiFarmLists({
farm_name: query ?? ''
})
optionsData.farmList = farmList
loading.value = false
}
console.log(optionsData)
//
const setFormData = async (data: Record<any, any>) => {

View File

@ -33,7 +33,7 @@
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="养殖基地id" prop="farm_id" show-overflow-tooltip />
<el-table-column label="养殖基地" prop="farm_id" show-overflow-tooltip />
<el-table-column label="栏舍名称" prop="fence_house_name" show-overflow-tooltip />
<el-table-column label="动物类型" prop="animal_type">
<template #default="{ row }">

View File

@ -9,66 +9,74 @@
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="170px" :rules="formRules">
<el-form-item label="土壤最高温度" prop="soil_temp_max">
<el-input v-model="formData.soil_temp_max" clearable placeholder="请输入土壤最高温度" />
<el-form-item label="所属栏舍" prop="product_id">
<el-select
v-model="formData.fence_house_id"
remote
filterable
:remote-method="queryFenceHouse"
:loading="loading"
>
<el-option
v-for="(item, index) in optionsData.fenceHouse"
:key="index"
:label="item.fencehouseinfo"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="土壤最低温度" prop="soil_temp_min">
<el-input v-model="formData.soil_temp_min" clearable placeholder="请输入土壤最低温度" />
<el-form-item label="室温(高)" prop="air_temp_max">
<el-input v-model="formData.air_temp_max" clearable />
</el-form-item>
<el-form-item label="土壤最高湿度" prop="soil_mois_max">
<el-input v-model="formData.soil_mois_max" clearable placeholder="请输入土壤最高湿度" />
<el-form-item label="室温(低)" prop="air_temp_min">
<el-input v-model="formData.air_temp_min" clearable />
</el-form-item>
<el-form-item label="土壤最低湿度" prop="soil_mois_min">
<el-input v-model="formData.soil_mois_min" clearable placeholder="请输入土壤最低湿度" />
<el-form-item label="湿度(高)" prop="air_mois_max">
<el-input v-model="formData.air_mois_max" clearable />
</el-form-item>
<el-form-item label="土壤最高PH值" prop="soil_ph_max">
<el-input v-model="formData.soil_ph_max" clearable placeholder="请输入土壤最高PH值" />
<el-form-item label="湿度(低)" prop="air_mois_min">
<el-input v-model="formData.air_mois_min" clearable />
</el-form-item>
<el-form-item label="土壤最低PH值" prop="soil_ph_min">
<el-input v-model="formData.soil_ph_min" clearable placeholder="请输入土壤最低PH值" />
<el-form-item label="氮气含量(高)" prop="nitrogen_max">
<el-input v-model="formData.nitrogen_max" clearable/>
</el-form-item>
<el-form-item label="土壤最高氮含量" prop="soil_n_content_max">
<el-input v-model="formData.soil_n_content_max" clearable placeholder="请输入土壤最高氮含量" />
<el-form-item label="氮气含量(低)" prop="nitrogen_min">
<el-input v-model="formData.nitrogen_min" clearable/>
</el-form-item>
<el-form-item label="土壤最低氮含量" prop="soil_n_content_min">
<el-input v-model="formData.soil_n_content_min" clearable placeholder="请输入土壤最低氮含量" />
<el-form-item label="防火(高)" prop="wind_speed_min">
<el-input v-model="formData.fireproof_max" clearable />
</el-form-item>
<el-form-item label="土壤最高磷含量" prop="soil_p_content_max">
<el-input v-model="formData.soil_p_content_max" clearable placeholder="请输入土壤最高磷含量" />
<el-form-item label="防火(低)" prop="wind_speed_max">
<el-input v-model="formData.fireproof_min" clearable/>
</el-form-item>
<el-form-item label="土壤最低磷含量" prop="soil_p_content_min">
<el-input v-model="formData.soil_p_content_min" clearable placeholder="请输入土壤最低磷含量" />
<el-form-item label="甲烷(高)" prop="methane_max">
<el-input v-model="formData.methane_max" clearable />
</el-form-item>
<el-form-item label="土壤最高钾含量" prop="soil_k_content_max">
<el-input v-model="formData.soil_k_content_max" clearable placeholder="请输入土壤最高钾含量" />
<el-form-item label="甲烷(低)" prop="methane_min">
<el-input v-model="formData.methane_min" clearable/>
</el-form-item>
<el-form-item label="土壤最低钾含量" prop="soil_k_content_min">
<el-input v-model="formData.soil_k_content_min" clearable placeholder="请输入土壤最低钾含量" />
<el-form-item label="噪音(高)" prop="noise_max">
<el-input v-model="formData.noise_max" clearable />
</el-form-item>
<el-form-item label="空气最高温度" prop="air_temp_max">
<el-input v-model="formData.air_temp_max" clearable placeholder="请输入空气最高温度" />
<el-form-item label="噪音(低)" prop="noise_min">
<el-input v-model="formData.noise_min" clearable/>
</el-form-item>
<el-form-item label="空气最低温度" prop="air_temp_min">
<el-input v-model="formData.air_temp_min" clearable placeholder="请输入空气最低温度" />
<el-form-item label="体温(高)" prop="temperature_max">
<el-input v-model="formData.temperature_max" clearable />
</el-form-item>
<el-form-item label="空气最高湿度" prop="air_mois_max">
<el-input v-model="formData.air_mois_max" clearable placeholder="请输入空气最高湿度" />
</el-form-item>
<el-form-item label="空气最低湿度" prop="air_mois_min">
<el-input v-model="formData.air_mois_min" clearable placeholder="请输入空气最低湿度" />
</el-form-item>
<el-form-item label="空气最大二氧化碳含量" prop="air_co2_content_max">
<el-input v-model="formData.air_co2_content_max" clearable placeholder="请输入空气最大二氧化碳含量" />
</el-form-item>
<el-form-item label="空气最小二氧化碳含量" prop="air_co2_content_min">
<el-input v-model="formData.air_co2_content_min" clearable placeholder="请输入空气最小二氧化碳含量" />
</el-form-item>
<el-form-item label="最大风速" prop="wind_speed_max">
<el-input v-model="formData.wind_speed_max" clearable placeholder="请输入最大风速" />
</el-form-item>
<el-form-item label="最小风速" prop="wind_speed_min">
<el-input v-model="formData.wind_speed_min" clearable placeholder="请输入最小风速" />
<el-form-item label="体温(低)" prop="temperature_min">
<el-input v-model="formData.temperature_min" clearable/>
</el-form-item>
</el-form>
</popup>
</div>
@ -77,9 +85,12 @@
<script lang="ts" setup name="monitorThresholdEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiMonitorThresholdAdd, apiMonitorThresholdEdit, apiMonitorThresholdDetail } from '@/api/monitor_threshold'
import { apiMonitorThresholdAdd, apiMonitorThresholdEdit, apiMonitorThresholdDetail, apiFenceHouseLists } from '@/api/monitor_threshold'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import {useDictOptions} from "@/hooks/useDictOptions";
import {apiProductLists} from "@/api/device";
import {ref} from "vue";
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
@ -100,134 +111,49 @@ const popupTitle = computed(() => {
//
const formData = reactive({
id: '',
soil_temp_max: '',
soil_temp_min: '',
soil_mois_max: '',
soil_mois_min: '',
soil_ph_max: '',
soil_ph_min: '',
soil_n_content_max: '',
soil_n_content_min: '',
soil_p_content_max: '',
soil_p_content_min: '',
soil_k_content_max: '',
soil_k_content_min: '',
fence_house_id: '',
air_temp_max: '',
air_temp_min: '',
air_mois_max: '',
air_mois_min: '',
air_co2_content_max: '',
air_co2_content_min: '',
wind_speed_max: '',
wind_speed_min: '',
nitrogen_min: '',
nitrogen_max: '',
fireproof_min: '',
fireproof_max: '',
methane_min: '',
methane_max: '',
noise_min: '',
noise_max: '',
temperature_min: '',
temperature_max: '',
})
//
const formRules = reactive<any>({
soil_temp_max: [{
required: true,
message: '请输入土壤最高温度',
trigger: ['blur']
}],
soil_temp_min: [{
required: true,
message: '请输入土壤最低温度',
trigger: ['blur']
}],
soil_mois_max: [{
required: true,
message: '请输入土壤最高湿度',
trigger: ['blur']
}],
soil_mois_min: [{
required: true,
message: '请输入土壤最低湿度',
trigger: ['blur']
}],
soil_ph_max: [{
required: true,
message: '请输入土壤最高PH值',
trigger: ['blur']
}],
soil_ph_min: [{
required: true,
message: '请输入土壤最低PH值',
trigger: ['blur']
}],
soil_n_content_max: [{
required: true,
message: '请输入土壤最高氮含量',
trigger: ['blur']
}],
soil_n_content_min: [{
required: true,
message: '请输入土壤最低氮含量',
trigger: ['blur']
}],
soil_p_content_max: [{
required: true,
message: '请输入土壤最高磷含量',
trigger: ['blur']
}],
soil_p_content_min: [{
required: true,
message: '请输入土壤最低磷含量',
trigger: ['blur']
}],
soil_k_content_max: [{
required: true,
message: '请输入土壤最高钾含量',
trigger: ['blur']
}],
soil_k_content_min: [{
required: true,
message: '请输入土壤最低钾含量',
trigger: ['blur']
}],
air_temp_max: [{
required: true,
message: '请输入空气最高温度',
trigger: ['blur']
}],
air_temp_min: [{
required: true,
message: '请输入空气最低温度',
trigger: ['blur']
}],
air_mois_max: [{
required: true,
message: '请输入空气最高湿度',
trigger: ['blur']
}],
air_mois_min: [{
required: true,
message: '请输入空气最低湿度',
trigger: ['blur']
}],
air_co2_content_max: [{
required: true,
message: '请输入空气最大二氧化碳含量',
trigger: ['blur']
}],
air_co2_content_min: [{
required: true,
message: '请输入空气最小二氧化碳含量',
trigger: ['blur']
}],
wind_speed_max: [{
required: true,
message: '请输入最大风速',
trigger: ['blur']
}],
wind_speed_min: [{
required: true,
message: '请输入最小风速',
trigger: ['blur']
}],
const formRules = reactive<any>({})
const { optionsData } = useDictOptions<{
fenceHouse: any[]
}>({
fenceHouse: {
api: apiFenceHouseLists,
params: {
all: 1
}
}
})
const loading = ref(false)
const queryFenceHouse = async (query: string) => {
loading.value = true
const fenceHouseList = await apiFenceHouseLists({
fence_house_name: query ?? ''
})
optionsData.fenceHouse = fenceHouseList
loading.value = false
}
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {

View File

@ -1,19 +1,71 @@
<template>
<div>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<el-button v-perms="['device.monitor_threshold/add']" type="primary" @click="handleAdd">
<template #icon>
<icon name="el-icon-Plus" />
</template>
新增
</el-button>
<el-button
v-perms="['device.monitor_threshold/delete']"
:disabled="!selectData.length"
@click="handleDelete(selectData)"
>
删除
</el-button>
</el-card>
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column label="栏舍" show-overflow-tooltip>
<template #default="{ row }">
{{row.fenceHousrAttr.fence_house_name}}
</template>
</el-table-column>
<el-table-column label="室温" show-overflow-tooltip>
<template #default="{ row }">
{{row.air_temp_min}} ~ {{row.air_temp_max}}
</template>
</el-table-column>
<el-table-column label="湿度" show-overflow-tooltip>
<template #default="{ row }">
{{row.air_mois_min}} ~ {{row.air_mois_max}}
</template>
</el-table-column>
<el-table-column label="氮气含量" show-overflow-tooltip>
<template #default="{ row }">
{{row.nitrogen_min}} ~ {{row.nitrogen_max}}
</template>
</el-table-column>
<el-table-column label="防火" show-overflow-tooltip>
<template #default="{ row }">
{{row.fireproof_min}} ~ {{row.fireproof_max}}
</template>
</el-table-column>
<el-table-column label="甲烷" show-overflow-tooltip>
<template #default="{ row }">
{{row.fireproof_min}} ~ {{row.fireproof_max}}
</template>
</el-table-column>
<el-table-column label="噪音" show-overflow-tooltip>
<template #default="{ row }">
{{row.noise_min}} ~ {{row.noise_max}}
</template>
</el-table-column>
<el-table-column label="体温" show-overflow-tooltip>
<template #default="{ row }">
{{row.temperature_min}} ~ {{row.temperature_max}}
</template>
</el-table-column>
<el-table-column label="土壤最高温度" prop="soil_temp_max" show-overflow-tooltip />
<el-table-column label="土壤最低温度" prop="soil_temp_min" show-overflow-tooltip />
<el-table-column label="土壤最高湿度" prop="soil_mois_max" show-overflow-tooltip />
<el-table-column label="土壤最低湿度" prop="soil_mois_min" show-overflow-tooltip />
<el-table-column label="土壤最高PH值" prop="soil_ph_max" show-overflow-tooltip />
<el-table-column label="土壤最低PH值" prop="soil_ph_min" show-overflow-tooltip />
<el-table-column label="土壤最高氮含量" prop="soil_n_content_max" show-overflow-tooltip />
<el-table-column label="土壤最低氮含量" prop="soil_n_content_min" show-overflow-tooltip />
<el-table-column label="最大风速" prop="wind_speed_max" show-overflow-tooltip />
<el-table-column label="最小风速" prop="wind_speed_min" show-overflow-tooltip />
<el-table-column label="操作" width="120" align="center" fixed="right">
<template #default="{ row }">
<el-button
@ -43,6 +95,7 @@ import { apiMonitorThresholdLists, apiMonitorThresholdDelete } from '@/api/monit
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import {getRoutePath} from "@/router";
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//

View File

@ -62,19 +62,19 @@
</el-select>
</el-form-item>
<el-form-item label="所属养殖基地" prop="farm_id">
<el-form-item label="所属栏舍" prop="fence_house_id">
<el-select
v-model="formData.farm_id"
v-model="formData.fence_house_id"
remote
filterable
placeholder="请选择"
:remote-method="queryLand"
:remote-method="queryFenceHouse"
:loading="loading"
>
<el-option
v-for="(item, index) in optionsData.land"
v-for="(item, index) in optionsData.fenceHouse"
:key="index"
:label="item.landinfo"
:label="item.fencehouseinfo"
:value="item.id"
/>
</el-select>
@ -97,6 +97,7 @@ import useUserStore from "@/stores/modules/user";
import type { PropType } from 'vue'
import {ref} from "vue";
import config from "@/config";
import {apiFenceHouseLists} from "@/api/monitor_threshold";
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
@ -131,7 +132,7 @@ const formData = reactive({
id: '',
user_id: '',
root: 0,
farm_id: '',
fence_house_id: '',
code: '',
name: '',
desc: '',
@ -176,12 +177,12 @@ const getDetail = async (row: Record<string, any>) => {
const { optionsData } = useDictOptions<{
user: any[]
land: any[]
fenceHouse: any[]
}>({
user: {
api: getUserList
},
land: {
fenceHouse: {
api: apiLandLists
}
})
@ -198,18 +199,16 @@ const queryUser = async (query: string) => {
}
const selectedUser = (value: any) => {
optionsData.land = []
formData.land_id = ''
queryLand(value)
optionsData.fenceHouse = []
formData.fence_house_id = ''
queryFenceHouse(value)
}
const queryLand = async (user_id: string) => {
const queryFenceHouse = async (user_id: string) => {
loading.value = true
const landList = await apiLandLists({
const fenceHouseList = await apiFenceHouseLists({
user_id: user_id ?? ''
})
loading.value = false
optionsData.land = landList
optionsData.fenceHouse = fenceHouseList
loading.value = false
}
@ -240,7 +239,7 @@ const open = (type = 'add') => {
const root = res.user.root ?? 0
formData.root = root
if (type == 'edit') {
queryLand(formData.user_id)
queryFenceHouse(formData.user_id)
}
})
.catch((err: any) => {

View File

@ -42,9 +42,9 @@
</el-table-column> -->
<el-table-column label="产品名称" prop="name" show-overflow-tooltip />
<el-table-column label="产品编号" prop="code" show-overflow-tooltip />
<el-table-column label="所属土地" width="200">
<el-table-column label="所属栏舍" width="200">
<template #default="{ row }">
<el-tag class="mr-2" v-if="row.land_id != null" type="info">ID: {{ row.land_id }}</el-tag>
<el-tag class="mr-2" v-if="row.fence_house_id != null" type="info">ID: {{ row.land_id }}</el-tag>
<el-tag class="mr-2" v-if="row.title != null" type="info">名称: {{ row.title }}</el-tag>
</template>
</el-table-column>

View File

@ -19,6 +19,7 @@ namespace app\adminapi\controller\farm;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\farm\FarmLists;
use app\adminapi\logic\farm\FarmLogic;
use app\adminapi\logic\user\UserLogic;
use app\adminapi\validate\farm\FarmValidate;
@ -104,5 +105,10 @@ class FarmController extends BaseAdminController
return $this->data($result);
}
public function datas()
{
$datas = (new FarmLogic())->datas(input(''));
return $this->success('', $datas);
}
}

View File

@ -18,8 +18,10 @@ namespace app\adminapi\controller\fence_house;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\fence_house\FenceHouseLists;
use app\adminapi\logic\farm\FarmLogic;
use app\adminapi\logic\fence_house\FenceHouseLogic;
use app\adminapi\validate\fence_house\FenceHouseValidate;
use app\common\model\fence_house\FenceHouse;
/**
@ -104,5 +106,10 @@ class FenceHouseController extends BaseAdminController
return $this->data($result);
}
public function datas()
{
$datas = (new FenceHouseLogic())->datas(input(''));
return $this->success('', $datas);
}
}

View File

@ -55,7 +55,7 @@ class MonitorThresholdLists extends BaseAdminDataLists implements ListsSearchInt
public function lists(): array
{
return MonitorThreshold::where($this->searchWhere)
->field(['id', 'soil_temp_max', 'soil_temp_min', 'soil_mois_max', 'soil_mois_min', 'soil_ph_max', 'soil_ph_min', 'soil_n_content_max', 'soil_n_content_min', 'soil_p_content_max', 'soil_p_content_min', 'soil_k_content_max', 'soil_k_content_min', 'air_temp_max', 'air_temp_min', 'air_mois_max', 'air_mois_min', 'air_co2_content_max', 'air_co2_content_min', 'wind_speed_max', 'wind_speed_min'])
->with(['fenceHousrAttr'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()

View File

@ -41,26 +41,21 @@ class MonitorThresholdLogic extends BaseLogic
Db::startTrans();
try {
MonitorThreshold::create([
'soil_temp_max' => $params['soil_temp_max'],
'soil_temp_min' => $params['soil_temp_min'],
'soil_mois_max' => $params['soil_mois_max'],
'soil_mois_min' => $params['soil_mois_min'],
'soil_ph_max' => $params['soil_ph_max'],
'soil_ph_min' => $params['soil_ph_min'],
'soil_n_content_max' => $params['soil_n_content_max'],
'soil_n_content_min' => $params['soil_n_content_min'],
'soil_p_content_max' => $params['soil_p_content_max'],
'soil_p_content_min' => $params['soil_p_content_min'],
'soil_k_content_max' => $params['soil_k_content_max'],
'soil_k_content_min' => $params['soil_k_content_min'],
'fence_house_id' => $params['fence_house_id'],
'air_temp_max' => $params['air_temp_max'],
'air_temp_min' => $params['air_temp_min'],
'air_mois_max' => $params['air_mois_max'],
'air_mois_min' => $params['air_mois_min'],
'air_co2_content_max' => $params['air_co2_content_max'],
'air_co2_content_min' => $params['air_co2_content_min'],
'wind_speed_max' => $params['wind_speed_max'],
'wind_speed_min' => $params['wind_speed_min'],
'nitrogen_min' => $params['nitrogen_min'],
'nitrogen_max' => $params['nitrogen_max'],
'fireproof_min' => $params['fireproof_min'],
'fireproof_max' => $params['fireproof_max'],
'methane_min' => $params['methane_min'],
'methane_max' => $params['methane_max'],
'noise_min' => $params['noise_min'],
'noise_max' => $params['noise_max'],
'temperature_min' => $params['temperature_min'],
'temperature_max' => $params['temperature_max'],
]);
Db::commit();
@ -85,26 +80,21 @@ class MonitorThresholdLogic extends BaseLogic
Db::startTrans();
try {
MonitorThreshold::where('id', $params['id'])->update([
'soil_temp_max' => $params['soil_temp_max'],
'soil_temp_min' => $params['soil_temp_min'],
'soil_mois_max' => $params['soil_mois_max'],
'soil_mois_min' => $params['soil_mois_min'],
'soil_ph_max' => $params['soil_ph_max'],
'soil_ph_min' => $params['soil_ph_min'],
'soil_n_content_max' => $params['soil_n_content_max'],
'soil_n_content_min' => $params['soil_n_content_min'],
'soil_p_content_max' => $params['soil_p_content_max'],
'soil_p_content_min' => $params['soil_p_content_min'],
'soil_k_content_max' => $params['soil_k_content_max'],
'soil_k_content_min' => $params['soil_k_content_min'],
'fence_house_id' => $params['fence_house_id'],
'air_temp_max' => $params['air_temp_max'],
'air_temp_min' => $params['air_temp_min'],
'air_mois_max' => $params['air_mois_max'],
'air_mois_min' => $params['air_mois_min'],
'air_co2_content_max' => $params['air_co2_content_max'],
'air_co2_content_min' => $params['air_co2_content_min'],
'wind_speed_max' => $params['wind_speed_max'],
'wind_speed_min' => $params['wind_speed_min'],
'nitrogen_min' => $params['nitrogen_min'],
'nitrogen_max' => $params['nitrogen_max'],
'fireproof_min' => $params['fireproof_min'],
'fireproof_max' => $params['fireproof_max'],
'methane_min' => $params['methane_min'],
'methane_max' => $params['methane_max'],
'noise_min' => $params['noise_min'],
'noise_max' => $params['noise_max'],
'temperature_min' => $params['temperature_min'],
'temperature_max' => $params['temperature_max'],
]);
Db::commit();

View File

@ -129,4 +129,17 @@ class FarmLogic extends BaseLogic
{
return Farm::findOrEmpty($params['id'])->toArray();
}
public static function datas($params)
{
$queryWhere = [];
if (!empty($params['farm_name'])) {
$queryWhere[] = ['farm_name', 'like', '%' . $params['farm_name'] . '%'];
}
$lists = Db::name('farm')->where($queryWhere)->order(['id' => 'desc'])->select()->toArray();
foreach ($lists as &$item) {
$item['farminfo'] = 'ID' . $item['id'] . ' / 名称:' . $item['farm_name'];
}
return $lists;
}
}

View File

@ -15,6 +15,7 @@
namespace app\adminapi\logic\fence_house;
use app\common\model\farm\Farm;
use app\common\model\fence_house\FenceHouse;
use app\common\logic\BaseLogic;
use think\facade\Db;
@ -117,4 +118,22 @@ class FenceHouseLogic extends BaseLogic
{
return FenceHouse::findOrEmpty($params['id'])->toArray();
}
public static function datas($params)
{
$queryWhere = [];
if (!empty($params['fence_house_name'])) {
$queryWhere[] = ['fence_house_name', 'like', '%' . $params['fence_house_name'] . '%'];
}
if (!empty($params['user_id'])) {
$farmIds = Farm::where('user_id', $params['user_id'])->column('id');
$queryWhere[] = ['farm_id', 'in', $farmIds];
}
$lists = Db::name('fence_house')->where($queryWhere)->order(['id' => 'desc'])->select()->toArray();
foreach ($lists as &$item) {
$item['fencehouseinfo'] = 'ID' . $item['id'] . ' / 名称:' . $item['fence_house_name'];
}
return $lists;
}
}

View File

@ -15,6 +15,7 @@
namespace app\adminapi\logic\land;
use app\common\model\fence_house\FenceHouse;
use app\common\model\land\Land;
use app\common\model\land\Product;
use app\common\logic\BaseLogic;
@ -41,38 +42,23 @@ class ProductLogic extends BaseLogic
{
$root = (request()->adminInfo)['root'];
$userId = (request()->adminInfo)['user_id'];
$status = 1;
if ($root && !empty($params['user_id'])) {
$userId = $params['user_id'];
}
if (!empty($params['land_id'])) {
$land = Land::findOrEmpty($params['land_id'])->toArray();
$userId = $land['user_id'] ?? 0;
$status = 2;
}
Db::startTrans();
try {
$product = Product::create([
Product::create([
'user_id' => $userId,
'fence_house_id' => $params['fence_house_id'],
'code' => $params['code'],
'name' => $params['name'],
'desc' => $params['desc'],
'image' => $params['image'],
'status' => $status,
'status' => 2,
]);
if (!empty($params['land_id'])) {
Db::name('land_product')->where('land_id', $params['land_id'])->delete();
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $product['id'],
'create_time' => time(),
'update_time' => time()
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
@ -90,41 +76,22 @@ class ProductLogic extends BaseLogic
{
$root = (request()->adminInfo)['root'];
$userId = (request()->adminInfo)['user_id'];
$status = 1;
if ($root && !empty($params['user_id'])) {
$userId = $params['user_id'];
}
if (!empty($params['land_id'])) {
$land = Land::findOrEmpty($params['land_id'])->toArray();
$userId = $land['user_id'] ?? 0;
$status = 2;
}
Db::startTrans();
try {
Product::where('id', $params['id'])->update([
'user_id' => $userId,
'fence_house_id' => $params['fence_house_id'],
'code' => $params['code'],
'name' => $params['name'],
'desc' => $params['desc'],
'image' => $params['image'],
'status' => $status,
'status' => 2,
]);
if (!empty($params['land_id'])) {
Db::name('land_product')->where('land_id', $params['land_id'])->delete();
}
Db::name('land_product')->where('product_id', $params['id'])->delete();
if (!empty($params['land_id'])) {
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $params['id'],
'create_time' => time(),
'update_time' => time()
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}

View File

@ -31,27 +31,7 @@ class MonitorThresholdValidate extends BaseValidate
* @var string[]
*/
protected $rule = [
'id' => 'require',
'soil_temp_max' => 'require',
'soil_temp_min' => 'require',
'soil_mois_max' => 'require',
'soil_mois_min' => 'require',
'soil_ph_max' => 'require',
'soil_ph_min' => 'require',
'soil_n_content_max' => 'require',
'soil_n_content_min' => 'require',
'soil_p_content_max' => 'require',
'soil_p_content_min' => 'require',
'soil_k_content_max' => 'require',
'soil_k_content_min' => 'require',
'air_temp_max' => 'require',
'air_temp_min' => 'require',
'air_mois_max' => 'require',
'air_mois_min' => 'require',
'air_co2_content_max' => 'require',
'air_co2_content_min' => 'require',
'wind_speed_max' => 'require',
'wind_speed_min' => 'require',
];
@ -59,29 +39,7 @@ class MonitorThresholdValidate extends BaseValidate
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'soil_temp_max' => '土壤最高温度',
'soil_temp_min' => '土壤最低温度',
'soil_mois_max' => '土壤最高湿度',
'soil_mois_min' => '土壤最低湿度',
'soil_ph_max' => '土壤最高PH值',
'soil_ph_min' => '土壤最低PH值',
'soil_n_content_max' => '土壤最高氮含量',
'soil_n_content_min' => '土壤最低氮含量',
'soil_p_content_max' => '土壤最高磷含量',
'soil_p_content_min' => '土壤最低磷含量',
'soil_k_content_max' => '土壤最高钾含量',
'soil_k_content_min' => '土壤最低钾含量',
'air_temp_max' => '空气最高温度',
'air_temp_min' => '空气最低温度',
'air_mois_max' => '空气最高湿度',
'air_mois_min' => '空气最低湿度',
'air_co2_content_max' => '空气最大二氧化碳含量',
'air_co2_content_min' => '空气最小二氧化碳含量',
'wind_speed_max' => '最大风速',
'wind_speed_min' => '最小风速',
];
protected $field = [];
/**

View File

@ -16,7 +16,7 @@ namespace app\common\model\device;
use app\common\model\BaseModel;
use app\common\model\fence_house\FenceHouse;
/**
@ -29,6 +29,9 @@ class MonitorThreshold extends BaseModel
protected $name = 'monitor_threshold';
public function fenceHousrAttr()
{
return $this->hasOne(FenceHouse::class, 'id', 'fence_house_id');
}
}