原始rfid导入

This commit is contained in:
chenbo 2024-01-29 14:03:07 +08:00
parent fbababf4dc
commit 184aa00784
6 changed files with 165 additions and 80 deletions

View File

@ -14,6 +14,7 @@
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
<el-button type="primary" @click="handleImport">导入</el-button>
</el-form-item>
</el-form>
</el-card>
@ -35,7 +36,17 @@
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="RFID" prop="rfid" show-overflow-tooltip />
<el-table-column label="所属栏舍" prop="fence_house_id" show-overflow-tooltip />
<el-table-column label="原始RFID" prop="origin_rfid" />
<el-table-column label="所属栏舍" prop="fence_house_id" show-overflow-tooltip>
<template #default="{ row }">
<el-tag class="mr-2" v-if="row.fence_house_id != null" type="info"
>ID: {{ row.fence_house_id }}</el-tag
>
<el-tag class="mr-2" v-if="row.fenceHouse != null" type="info"
>名称: {{ row.fenceHouse.fence_house_name }}</el-tag
>
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
@ -70,6 +81,29 @@
@success="getLists"
@close="showEdit = false"
/>
<div>
<el-dialog v-model="showImport" @close="showImport = false" width="30%">
<el-upload
style="margin-left: 12px;"
ref="uploadImportRef"
class="upload-demo"
:action="uploadAction"
:headers="{ Token: userStore.token }"
:limit="1"
:on-exceed="handleExceed"
:auto-upload="false"
>
<template #trigger>
<el-button type="primary">选择文件</el-button>
</template>
<el-button class="ml-3" type="success" @click="submitUpload">
提交
</el-button>
</el-upload>
</el-dialog>
</div>
</div>
</template>
@ -80,11 +114,19 @@ import { apiAnimalRfidLists, apiAnimalRfidDelete } from '@/api/animal_rfid'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import { genFileId, ElMessage } from 'element-plus'
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus'
import {ref} from "vue";
import config from "@/config";
import useUserStore from "@/stores/modules/user";
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const uploadImportRef = ref<UploadInstance>()
//
const showEdit = ref(false)
const showImport = ref(false)
const uploadAction = ref(`${config.baseUrl}${config.urlPrefix}/device.device/importRfid`)
const userStore = useUserStore()
//
const queryParams = reactive({
rfid: ''
@ -128,6 +170,22 @@ const handleDelete = async (id: number | any[]) => {
await apiAnimalRfidDelete({ id })
getLists()
}
const handleImport = async () => {
showImport.value = true
await nextTick()
}
const handleExceed: UploadProps['onExceed'] = (files) => {
uploadImportRef.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadImportRef.value!.handleStart(file)
}
const submitUpload = () => {
uploadImportRef.value!.submit()
showImport.value=false
ElMessage.success('导入成功')
getLists()
}
getLists()
</script>

View File

@ -20,7 +20,11 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\device\DeviceLists;
use app\adminapi\logic\device\DeviceLogic;
use app\adminapi\validate\device\DeviceValidate;
use app\common\service\ConfigService;
use app\common\service\storage\Driver as StorageDriver;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Symfony\Component\HttpClient\HttpClient;
use think\facade\Db;
/**
@ -148,4 +152,22 @@ class DeviceController extends BaseAdminController
return $this->data($datas);
}
public function importRfid()
{
$reader = IOFactory::createReader('Xls');
// 打开文件 载入excel表格
$spreadsheet = $reader->load($_FILES['file']['tmp_name']);
$excelData = $spreadsheet->getActiveSheet()->toArray();
array_shift($excelData); // 去除表头
$insertData = [];
foreach ($excelData as $key =>$row) {
$insertData[$key]['origin_rfid'] = $row[0];
$insertData[$key]['rfid'] = $row[1];
}
Db::name('animal_rfid')->insertAll($insertData);
return $this->success('导入成功');
}
}

View File

@ -1,77 +1,78 @@
<?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\rfid;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\rfid\AnimalRfid;
use app\common\lists\ListsSearchInterface;
/**
* AnimalRfid列表
* Class AnimalRfidLists
* @package app\adminapi\listsrfid
*/
class AnimalRfidLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function setSearch(): array
{
return [
'=' => ['rfid'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function lists(): array
{
return AnimalRfid::where($this->searchWhere)
->field(['id', 'rfid', 'fence_house_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function count(): int
{
return AnimalRfid::where($this->searchWhere)->count();
}
<?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\rfid;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\rfid\AnimalRfid;
use app\common\lists\ListsSearchInterface;
/**
* AnimalRfid列表
* Class AnimalRfidLists
* @package app\adminapi\listsrfid
*/
class AnimalRfidLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function setSearch(): array
{
return [
'=' => ['rfid'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function lists(): array
{
return AnimalRfid::where($this->searchWhere)
->with(['fenceHouse'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function count(): int
{
return AnimalRfid::where($this->searchWhere)->count();
}
}

View File

@ -37,7 +37,7 @@ class AnimalRfid extends BaseModel
* @author likeadmin
* @date 2024/01/13 16:21
*/
public function fenceHouseAttr()
public function fenceHouse()
{
return $this->hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id');
}

View File

@ -42,7 +42,7 @@ abstract class Server
}
// 校验上传文件后缀
$limit = array_merge(config('project.file_image'), config('project.file_video'));
$limit = array_merge(config('project.file_image'), config('project.file_video'), config('project.file_file'));
if (!in_array(strtolower($this->file->extension()), $limit)) {
throw new Exception('不允许上传' . $this->file->extension() . '后缀文件');
}

View File

@ -74,6 +74,10 @@ return [
'wmv', 'avi', 'mpg', 'mpeg', '3gp', 'mov', 'mp4', 'flv', 'f4v', 'rmvb', 'mkv'
],
// 文件上传限制 (文件)
'file_file' => [
'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt','apk','ipa','wgt'
],
// 登录设置
'login' => [
// 登录方式1-账号密码登录2-手机短信验证码登录