更新后台系统

This commit is contained in:
yaooo 2023-11-28 17:18:38 +08:00
parent 482908377d
commit eed81d25e3
18 changed files with 0 additions and 1823 deletions

View File

@ -1,26 +0,0 @@
import request from '@/utils/request'
// 空气监测列表
export function apiAirMonitorLists(params: any) {
return request.get({ url: '/device.air_monitor/lists', params })
}
// 添加空气监测
export function apiAirMonitorAdd(params: any) {
return request.post({ url: '/device.air_monitor/add', params })
}
// 编辑空气监测
export function apiAirMonitorEdit(params: any) {
return request.post({ url: '/device.air_monitor/edit', params })
}
// 删除空气监测
export function apiAirMonitorDelete(params: any) {
return request.post({ url: '/device.air_monitor/delete', params })
}
// 空气监测详情
export function apiAirMonitorDetail(params: any) {
return request.get({ url: '/device.air_monitor/detail', params })
}

View File

@ -1,26 +0,0 @@
import request from '@/utils/request'
// 土壤监测列表
export function apiSoilMonitorLists(params: any) {
return request.get({ url: '/device.soil_monitor/lists', params })
}
// 添加土壤监测
export function apiSoilMonitorAdd(params: any) {
return request.post({ url: '/device.soil_monitor/add', params })
}
// 编辑土壤监测
export function apiSoilMonitorEdit(params: any) {
return request.post({ url: '/device.soil_monitor/edit', params })
}
// 删除土壤监测
export function apiSoilMonitorDelete(params: any) {
return request.post({ url: '/device.soil_monitor/delete', params })
}
// 土壤监测详情
export function apiSoilMonitorDetail(params: any) {
return request.get({ url: '/device.soil_monitor/detail', params })
}

View File

@ -1,181 +0,0 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
:title="popupTitle"
:async="true"
width="550px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
<el-form-item label="设备ID" prop="device_id">
<el-input v-model="formData.device_id" disabled clearable placeholder="请输入设备ID" />
</el-form-item>
<el-form-item label="风向" prop="wind_direction">
<el-input v-model="formData.wind_direction" disabled clearable placeholder="请输入风向" />
</el-form-item>
<el-form-item label="风速" prop="wind_speed">
<el-input v-model="formData.wind_speed" disabled clearable placeholder="请输入风速" />
</el-form-item>
<el-form-item label="空气温度" prop="temperature">
<el-input v-model="formData.temperature" disabled clearable placeholder="请输入空气温度" />
</el-form-item>
<el-form-item label="空气湿度" prop="moisture">
<el-input v-model="formData.moisture" disabled clearable placeholder="请输入空气湿度" />
</el-form-item>
<el-form-item label="二氧化碳含量" prop="co2_content">
<el-input v-model="formData.co2_content" disabled clearable placeholder="请输入二氧化碳含量" />
</el-form-item>
<el-form-item label="大气压强" prop="pressure">
<el-input v-model="formData.pressure" disabled clearable placeholder="请输入大气压强" />
</el-form-item>
<el-form-item label="降雨量" prop="rainfall">
<el-input v-model="formData.rainfall" disabled clearable placeholder="请输入降雨量" />
</el-form-item>
<el-form-item label="光照强度" prop="light_intensity">
<el-input v-model="formData.light_intensity" disabled clearable placeholder="请输入光照强度" />
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="airMonitorEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiAirMonitorAdd, apiAirMonitorEdit, apiAirMonitorDetail } from '@/api/air_monitor'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '空气监测数据' : '新增空气监测'
})
//
const formData = reactive({
id: '',
device_id: '',
wind_direction: '',
wind_speed: '',
temperature: '',
moisture: '',
co2_content: '',
pressure: '',
rainfall: '',
light_intensity: '',
})
//
const formRules = reactive<any>({
device_id: [{
required: true,
message: '请输入设备ID',
trigger: ['blur']
}],
wind_direction: [{
required: true,
message: '请输入风向',
trigger: ['blur']
}],
wind_speed: [{
required: true,
message: '请输入风速',
trigger: ['blur']
}],
temperature: [{
required: true,
message: '请输入空气温度',
trigger: ['blur']
}],
moisture: [{
required: true,
message: '请输入空气湿度',
trigger: ['blur']
}],
co2_content: [{
required: true,
message: '请输入二氧化碳含量',
trigger: ['blur']
}],
pressure: [{
required: true,
message: '请输入大气压强',
trigger: ['blur']
}],
rainfall: [{
required: true,
message: '请输入降雨量',
trigger: ['blur']
}],
light_intensity: [{
required: true,
message: '请输入光照强度',
trigger: ['blur']
}],
})
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
}
const getDetail = async (row: Record<string, any>) => {
const data = await apiAirMonitorDetail({
id: row.id
})
setFormData(data)
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiAirMonitorEdit(data)
: await apiAirMonitorAdd(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -1,189 +0,0 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="设备ID" prop="device_id">
<el-input class="w-[280px]" v-model="queryParams.device_id" clearable placeholder="请输入设备ID" />
</el-form-item>
<el-form-item label="监测时间" prop="create_time">
<daterange-picker
v-model:startTime="queryParams.start_time"
v-model:endTime="queryParams.end_time"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<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="id" show-overflow-tooltip />
<el-table-column label="设备ID" prop="device_id" show-overflow-tooltip />
<el-table-column label="设备名称" prop="device.name" show-overflow-tooltip />
<el-table-column label="风向" prop="wind_direction" show-overflow-tooltip />
<el-table-column label="风速" prop="wind_speed" show-overflow-tooltip />
<el-table-column label="空气温度" prop="temperature" show-overflow-tooltip />
<el-table-column label="空气湿度" prop="moisture" show-overflow-tooltip />
<el-table-column label="二氧化碳含量" prop="co2_content" show-overflow-tooltip />
<el-table-column label="大气压强" prop="pressure" show-overflow-tooltip />
<el-table-column label="降雨量" prop="rainfall" show-overflow-tooltip />
<el-table-column label="光照强度" prop="light_intensity" show-overflow-tooltip />
<el-table-column label="监测时间" width="160" prop="create_time" show-overflow-tooltip />
<el-table-column label="操作" width="140" align="center" fixed="right">
<template #default="{ row }">
<el-button text @click="handleDetail(row)"
>
详情
</el-button>
<el-button
v-perms="['device.air_monitor/delete']"
type="danger"
link
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
</div>
<el-dialog v-model="dialogTableVisible" title="空气监测数据">
<el-table :data="detailData.gridData">
<el-table-column property="item" label="监测项" width="150" />
<el-table-column property="value" label="监测数据" />
</el-table>
</el-dialog>
</template>
<script lang="ts" setup name="airMonitorLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiAirMonitorLists, apiAirMonitorDelete } from '@/api/air_monitor'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const { query } = useRoute()
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
var device_id = query.device_id
if (typeof device_id == 'undefined') {
device_id = ''
}
//
const queryParams = reactive({
device_id: device_id,
start_time: '',
end_time: ''
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiAirMonitorLists,
params: queryParams
})
const dialogTableVisible = ref(false)
const detailData = reactive({
gridData : [{}]
})
//
const handleDetail = (data: any) => {
detailData.gridData = [{}]
detailData.gridData.unshift({
item: '光照强度',
value: data.light_intensity
})
detailData.gridData.unshift({
item: '降雨量',
value: data.rainfall
})
detailData.gridData.unshift({
item: '大气压强',
value: data.pressure
})
detailData.gridData.unshift({
item: '二氧化碳含量',
value: data.co2_content
})
detailData.gridData.unshift({
item: '空气湿度',
value: data.moisture
})
detailData.gridData.unshift({
item: '空气温度',
value: data.temperature
})
detailData.gridData.unshift({
item: '风速',
value: data.wind_speed
})
detailData.gridData.unshift({
item: '风向',
value: data.wind_direction
})
detailData.gridData.unshift({
item: '设备名称',
value: data.device.name
})
detailData.gridData.unshift({
item: '设备ID',
value: data.device_id
})
dialogTableVisible.value = true
}
//
const handleAdd = async () => {
showEdit.value = true
await nextTick()
editRef.value?.open('add')
}
//
const handleEdit = async (data: any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
await apiAirMonitorDelete({ id })
getLists()
}
getLists()
</script>

View File

@ -1,173 +0,0 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
:title="popupTitle"
:async="true"
width="550px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
<el-form-item label="设备ID" prop="device_id">
<el-input v-model="formData.device_id" disabled clearable placeholder="请输入设备ID" />
</el-form-item>
<el-form-item label="土壤温度" prop="temperature">
<el-input v-model="formData.temperature" disabled clearable placeholder="请输入土壤温度" />
</el-form-item>
<el-form-item label="土壤湿度" prop="moisture">
<el-input v-model="formData.moisture" disabled clearable placeholder="请输入土壤湿度" />
</el-form-item>
<el-form-item label="电导率" prop="conductivity">
<el-input v-model="formData.conductivity" disabled clearable placeholder="请输入电导率" />
</el-form-item>
<el-form-item label="土壤酸碱度" prop="ph">
<el-input v-model="formData.ph" disabled clearable placeholder="请输入土壤酸碱度" />
</el-form-item>
<el-form-item label="氮含量" prop="n_content">
<el-input v-model="formData.n_content" disabled clearable placeholder="请输入氮含量" />
</el-form-item>
<el-form-item label="磷含量" prop="p_content">
<el-input v-model="formData.p_content" disabled clearable placeholder="请输入磷含量" />
</el-form-item>
<el-form-item label="钾含量" prop="k_content">
<el-input v-model="formData.k_content" disabled clearable placeholder="请输入钾含量" />
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="soilMonitorEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiSoilMonitorAdd, apiSoilMonitorEdit, apiSoilMonitorDetail } from '@/api/soil_monitor'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '土壤监测数据' : '新增土壤监测'
})
//
const formData = reactive({
id: '',
device_id: '',
temperature: '',
moisture: '',
conductivity: '',
ph: '',
n_content: '',
p_content: '',
k_content: '',
})
//
const formRules = reactive<any>({
device_id: [{
required: true,
message: '请输入设备ID',
trigger: ['blur']
}],
temperature: [{
required: true,
message: '请输入土壤温度',
trigger: ['blur']
}],
moisture: [{
required: true,
message: '请输入土壤湿度',
trigger: ['blur']
}],
conductivity: [{
required: true,
message: '请输入电导率',
trigger: ['blur']
}],
ph: [{
required: true,
message: '请输入土壤酸碱度',
trigger: ['blur']
}],
n_content: [{
required: true,
message: '请输入氮含量',
trigger: ['blur']
}],
p_content: [{
required: true,
message: '请输入磷含量',
trigger: ['blur']
}],
k_content: [{
required: true,
message: '请输入钾含量',
trigger: ['blur']
}],
})
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
//@ts-ignore
formData.create_time = timeFormat(formData.create_time,'yyyy-mm-dd hh:MM:ss')
}
const getDetail = async (row: Record<string, any>) => {
const data = await apiSoilMonitorDetail({
id: row.id
})
setFormData(data)
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiSoilMonitorEdit(data)
: await apiSoilMonitorAdd(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -1,191 +0,0 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="设备ID" prop="device_id">
<el-input class="w-[280px]" v-model="queryParams.device_id" clearable placeholder="请输入设备ID" />
</el-form-item>
<el-form-item label="监测时间" prop="create_time">
<daterange-picker
v-model:startTime="queryParams.start_time"
v-model:endTime="queryParams.end_time"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<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="id" show-overflow-tooltip />
<el-table-column label="设备ID" prop="device_id" show-overflow-tooltip />
<el-table-column label="设备名称" prop="device.name" show-overflow-tooltip />
<el-table-column label="土壤温度" prop="temperature" show-overflow-tooltip />
<el-table-column label="土壤湿度" prop="moisture" show-overflow-tooltip />
<el-table-column label="电导率" prop="conductivity" show-overflow-tooltip />
<el-table-column label="土壤酸碱度" prop="ph" show-overflow-tooltip />
<el-table-column label="氮含量" prop="n_content" show-overflow-tooltip />
<el-table-column label="磷含量" prop="p_content" show-overflow-tooltip />
<el-table-column label="钾含量" prop="k_content" show-overflow-tooltip />
<el-table-column label="监测时间" width="160" prop="create_time">
<template #default="{ row }">
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="140" align="center" fixed="right">
<template #default="{ row }">
<el-button text @click="handleDetail(row)"
>
详情
</el-button>
<el-button
v-perms="['device.soil_monitor/delete']"
type="danger"
link
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
</div>
<el-dialog v-model="dialogTableVisible" title="土壤监测数据">
<el-table :data="detailData.gridData">
<el-table-column property="item" label="监测项" width="150" />
<el-table-column property="value" label="监测数据" />
</el-table>
</el-dialog>
</template>
<script lang="ts" setup name="soilMonitorLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiSoilMonitorLists, apiSoilMonitorDelete } from '@/api/soil_monitor'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import type EditPopup from './edit.vue'
const { query } = useRoute()
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
let device_id = query.device_id
if (typeof device_id == 'undefined') {
device_id = ''
}
//
const queryParams = reactive({
device_id: device_id,
start_time: '',
end_time: ''
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiSoilMonitorLists,
params: queryParams
})
const dialogTableVisible = ref(false)
const detailData = reactive({
gridData : [{}]
})
//
const handleDetail = (data: any) => {
detailData.gridData = [{}]
detailData.gridData.unshift({
item: '钾含量',
value: data.k_content
})
detailData.gridData.unshift({
item: '磷含量',
value: data.p_content
})
detailData.gridData.unshift({
item: '氮含量',
value: data.n_content
})
detailData.gridData.unshift({
item: '土壤酸碱度',
value: data.ph
})
detailData.gridData.unshift({
item: '电导率',
value: data.conductivity
})
detailData.gridData.unshift({
item: '土壤湿度',
value: data.moisture
})
detailData.gridData.unshift({
item: '土壤温度',
value: data.temperature
})
detailData.gridData.unshift({
item: '设备名称',
value: data.device.name
})
detailData.gridData.unshift({
item: '设备ID',
value: data.device_id
})
dialogTableVisible.value = true
}
//
const handleAdd = async () => {
showEdit.value = true
await nextTick()
editRef.value?.open('add')
}
//
const handleEdit = async (data: any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
await apiSoilMonitorDelete({ id })
getLists()
}
getLists()
</script>

View File

@ -1,108 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\device;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\device\AirMonitorLists;
use app\adminapi\logic\device\AirMonitorLogic;
use app\adminapi\validate\device\AirMonitorValidate;
/**
* AirMonitor控制器
* Class AirMonitorController
* @package app\adminapi\controller\device
*/
class AirMonitorController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function lists()
{
return $this->dataLists(new AirMonitorLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function add()
{
$params = (new AirMonitorValidate())->post()->goCheck('add');
$result = AirMonitorLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(AirMonitorLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function edit()
{
$params = (new AirMonitorValidate())->post()->goCheck('edit');
$result = AirMonitorLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(AirMonitorLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function delete()
{
$params = (new AirMonitorValidate())->post()->goCheck('delete');
AirMonitorLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function detail()
{
$params = (new AirMonitorValidate())->goCheck('detail');
$result = AirMonitorLogic::detail($params);
return $this->data($result);
}
}

View File

@ -1,108 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\device;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\device\SoilMonitorLists;
use app\adminapi\logic\device\SoilMonitorLogic;
use app\adminapi\validate\device\SoilMonitorValidate;
/**
* SoilMonitor控制器
* Class SoilMonitorController
* @package app\adminapi\controller\device
*/
class SoilMonitorController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function lists()
{
return $this->dataLists(new SoilMonitorLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function add()
{
$params = (new SoilMonitorValidate())->post()->goCheck('add');
$result = SoilMonitorLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(SoilMonitorLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function edit()
{
$params = (new SoilMonitorValidate())->post()->goCheck('edit');
$result = SoilMonitorLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(SoilMonitorLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function delete()
{
$params = (new SoilMonitorValidate())->post()->goCheck('delete');
SoilMonitorLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function detail()
{
$params = (new SoilMonitorValidate())->goCheck('detail');
$result = SoilMonitorLogic::detail($params);
return $this->data($result);
}
}

View File

@ -1,92 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\device;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\device\AirMonitor;
use app\common\lists\ListsSearchInterface;
/**
* AirMonitor列表
* Class AirMonitorLists
* @package app\adminapi\listsdevice
*/
class AirMonitorLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function setSearch(): array
{
$allowSearch = ['start_time', 'end_time'];
if (!empty($this->params['device_id'])) {
$allowSearch[] = 'device_id';
}
return array_intersect(array_keys($this->params), $allowSearch);
}
public function userSearch(): array
{
$userWhere['user_id'] = 0;
// 超级管理员数据
if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) {
unset($userWhere['user_id']);
}
// 普通用户数据
if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) {
$userWhere['user_id'] = $this->adminInfo['user_id'];
}
return $userWhere;
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function lists(): array
{
return AirMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->with('device')
->field(['id', 'device_id', 'wind_direction', 'wind_speed', 'temperature', 'moisture', 'co2_content', 'pressure', 'rainfall', 'light_intensity', 'create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function count(): int
{
return AirMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count();
}
}

View File

@ -1,92 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\device;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\device\SoilMonitor;
use app\common\lists\ListsSearchInterface;
/**
* SoilMonitor列表
* Class SoilMonitorLists
* @package app\adminapi\listsdevice
*/
class SoilMonitorLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function setSearch(): array
{
$allowSearch = ['start_time', 'end_time'];
if (!empty($this->params['device_id'])) {
$allowSearch[] = 'device_id';
}
return array_intersect(array_keys($this->params), $allowSearch);
}
public function userSearch(): array
{
$userWhere['user_id'] = 0;
// 超级管理员数据
if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) {
unset($userWhere['user_id']);
}
// 普通用户数据
if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) {
$userWhere['user_id'] = $this->adminInfo['user_id'];
}
return $userWhere;
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function lists(): array
{
return SoilMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->with('device')
->field(['id', 'device_id', 'temperature', 'moisture', 'conductivity', 'ph', 'n_content', 'p_content', 'k_content', 'create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function count(): int
{
return SoilMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count();
}
}

View File

@ -1,122 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\device;
use app\common\model\device\AirMonitor;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* AirMonitor逻辑
* Class AirMonitorLogic
* @package app\adminapi\logic\device
*/
class AirMonitorLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:49
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
AirMonitor::create([
'device_id' => $params['device_id'],
'wind_direction' => $params['wind_direction'],
'wind_speed' => $params['wind_speed'],
'temperature' => $params['temperature'],
'moisture' => $params['moisture'],
'co2_content' => $params['co2_content'],
'pressure' => $params['pressure'],
'rainfall' => $params['rainfall'],
'light_intensity' => $params['light_intensity'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:49
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
AirMonitor::where('id', $params['id'])->update([
'device_id' => $params['device_id'],
'wind_direction' => $params['wind_direction'],
'wind_speed' => $params['wind_speed'],
'temperature' => $params['temperature'],
'moisture' => $params['moisture'],
'co2_content' => $params['co2_content'],
'pressure' => $params['pressure'],
'rainfall' => $params['rainfall'],
'light_intensity' => $params['light_intensity'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:49
*/
public static function delete(array $params): bool
{
return AirMonitor::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/24 16:49
*/
public static function detail($params): array
{
return AirMonitor::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -1,120 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\device;
use app\common\model\device\SoilMonitor;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* SoilMonitor逻辑
* Class SoilMonitorLogic
* @package app\adminapi\logic\device
*/
class SoilMonitorLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 17:02
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
SoilMonitor::create([
'device_id' => $params['device_id'],
'temperature' => $params['temperature'],
'moisture' => $params['moisture'],
'conductivity' => $params['conductivity'],
'ph' => $params['ph'],
'n_content' => $params['n_content'],
'p_content' => $params['p_content'],
'k_content' => $params['k_content'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 17:02
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SoilMonitor::where('id', $params['id'])->update([
'device_id' => $params['device_id'],
'temperature' => $params['temperature'],
'moisture' => $params['moisture'],
'conductivity' => $params['conductivity'],
'ph' => $params['ph'],
'n_content' => $params['n_content'],
'p_content' => $params['p_content'],
'k_content' => $params['k_content'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 17:02
*/
public static function delete(array $params): bool
{
return SoilMonitor::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/24 17:02
*/
public static function detail($params): array
{
return SoilMonitor::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -1,112 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\device;
use app\common\validate\BaseValidate;
/**
* AirMonitor验证器
* Class AirMonitorValidate
* @package app\adminapi\validate\device
*/
class AirMonitorValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'device_id' => 'require',
'wind_direction' => 'require',
'wind_speed' => 'require',
'temperature' => 'require',
'moisture' => 'require',
'co2_content' => 'require',
'pressure' => 'require',
'rainfall' => 'require',
'light_intensity' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'device_id' => '设备ID',
'wind_direction' => '风向',
'wind_speed' => '风速',
'temperature' => '空气温度',
'moisture' => '空气湿度',
'co2_content' => '二氧化碳含量',
'pressure' => '大气压强',
'rainfall' => '降雨量',
'light_intensity' => '光照强度',
];
/**
* @notes 添加场景
* @return AirMonitorValidate
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function sceneAdd()
{
return $this->only(['device_id','wind_direction','wind_speed','temperature','moisture','co2_content','pressure','rainfall','light_intensity']);
}
/**
* @notes 编辑场景
* @return AirMonitorValidate
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function sceneEdit()
{
return $this->only(['id','device_id','wind_direction','wind_speed','temperature','moisture','co2_content','pressure','rainfall','light_intensity']);
}
/**
* @notes 删除场景
* @return AirMonitorValidate
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return AirMonitorValidate
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,110 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\device;
use app\common\validate\BaseValidate;
/**
* SoilMonitor验证器
* Class SoilMonitorValidate
* @package app\adminapi\validate\device
*/
class SoilMonitorValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'device_id' => 'require',
'temperature' => 'require',
'moisture' => 'require',
'conductivity' => 'require',
'ph' => 'require',
'n_content' => 'require',
'p_content' => 'require',
'k_content' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'device_id' => '设备ID',
'temperature' => '土壤温度',
'moisture' => '土壤湿度',
'conductivity' => '电导率',
'ph' => '土壤酸碱度',
'n_content' => '氮含量',
'p_content' => '磷含量',
'k_content' => '钾含量',
];
/**
* @notes 添加场景
* @return SoilMonitorValidate
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function sceneAdd()
{
return $this->only(['device_id','temperature','moisture','conductivity','ph','n_content','p_content','k_content']);
}
/**
* @notes 编辑场景
* @return SoilMonitorValidate
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function sceneEdit()
{
return $this->only(['id','device_id','temperature','moisture','conductivity','ph','n_content','p_content','k_content']);
}
/**
* @notes 删除场景
* @return SoilMonitorValidate
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SoilMonitorValidate
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,77 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\device;
use app\common\model\BaseModel;
/**
* AirMonitor模型
* Class AirMonitor
* @package app\common\model\device
*/
class AirMonitor extends BaseModel
{
protected $name = 'air_monitor';
/**
* @notes 关联device
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/11/24 16:49
*/
public function device()
{
return $this->hasOne(\app\common\model\device\Device::class, 'id', 'device_id');
}
/**
* @notes 搜索器-注册时间
* @param $query
* @param $value
* @param $data
* @author 段誉
* @date 2022/9/22 16:13
*/
public function searchStartTimeAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '>=', strtotime($value));
}
}
/**
* @notes 搜索器-注册时间
* @param $query
* @param $value
* @param $data
* @author 段誉
* @date 2022/9/22 16:13
*/
public function searchEndTimeAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '<=', strtotime($value));
}
}
}

View File

@ -1,76 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\device;
use app\common\model\BaseModel;
/**
* SoilMonitor模型
* Class SoilMonitor
* @package app\common\model\device
*/
class SoilMonitor extends BaseModel
{
protected $name = 'soil_monitor';
/**
* @notes 关联device
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/11/24 17:02
*/
public function device()
{
return $this->hasOne(\app\common\model\device\Device::class, 'id', 'device_id');
}
/**
* @notes 搜索器-注册时间
* @param $query
* @param $value
* @param $data
* @author 段誉
* @date 2022/9/22 16:13
*/
public function searchStartTimeAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '>=', strtotime($value));
}
}
/**
* @notes 搜索器-注册时间
* @param $query
* @param $value
* @param $data
* @author 段誉
* @date 2022/9/22 16:13
*/
public function searchEndTimeAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '<=', strtotime($value));
}
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace app\common\model\monitor;
use app\common\model\BaseModel;
class AirMonitor extends BaseModel
{
protected $name = 'air_monitor';
}

View File

@ -1,10 +0,0 @@
<?php
namespace app\common\model\monitor;
use app\common\model\BaseModel;
class SoilMonitor extends BaseModel
{
protected $name = 'soil_monitor';
}