Skip to content

Commit

Permalink
Merge pull request #111 from mineadmin/2.0.x-dev
Browse files Browse the repository at this point in the history
fix: 修改handleSearch条件检查函数,以及适配主键支持雪花ID和UUID
  • Loading branch information
kanyxmo authored Jan 25, 2024
2 parents 316b440 + 800c06e commit afbd1d0
Show file tree
Hide file tree
Showing 35 changed files with 167 additions and 146 deletions.
2 changes: 1 addition & 1 deletion app/Setting/Mapper/SettingConfigGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function assignModel()
* 删除组和所属配置.
* @throws \Exception
*/
public function deleteGroupAndConfig(int $id): bool
public function deleteGroupAndConfig(mixed $id): bool
{
/* @var $model SettingConfigGroup */
$model = $this->read($id);
Expand Down
8 changes: 4 additions & 4 deletions app/Setting/Mapper/SettingConfigMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function updateByKey(string $key, mixed $value = null): bool
/**
* 保存配置.
*/
public function save(array $data): int
public function save(array $data): mixed
{
$this->filterExecuteAttributes($data);
$model = $this->model::create($data);
Expand All @@ -87,13 +87,13 @@ public function save(array $data): int
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['group_id'])) {
if (isset($params['group_id']) && filled($params['group_id'])) {
$query->where('group_id', $params['group_id']);
}
if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', $params['name']);
}
if (! empty($params['key'])) {
if (isset($params['key']) && filled($params['key'])) {
$query->where('key', 'like', '%' . $params['key'] . '%');
}
return $query;
Expand Down
8 changes: 4 additions & 4 deletions app/Setting/Mapper/SettingCrontabMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public function delete(array $ids): bool
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', 'like', '%' . $params['name'] . '%');
}
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', $params['status']);
}
if (! empty($params['type'])) {
if (isset($params['type']) && filled($params['type'])) {
$query->where('type', $params['type']);
}
if (! empty($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
if (isset($params['created_at']) && filled($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
$query->whereBetween(
'created_at',
[$params['created_at'][0] . ' 00:00:00', $params['created_at'][1] . ' 23:59:59']
Expand Down
2 changes: 1 addition & 1 deletion app/Setting/Mapper/SettingDatasourceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function assignModel()
public function handleSearch(Builder $query, array $params): Builder
{
// 数据源名称
if (! empty($params['source_name'])) {
if (isset($params['source_name']) && filled($params['source_name'])) {
$query->where('source_name', 'like', '%' . $params['source_name'] . '%');
}

Expand Down
4 changes: 2 additions & 2 deletions app/Setting/Mapper/SettingGenerateTablesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function delete(array $ids): bool
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['table_name'])) {
if (isset($params['table_name']) && filled($params['table_name'])) {
$query->where('table_name', 'like', '%' . $params['table_name'] . '%');
}
if (! empty($params['minDate']) && ! empty($params['maxDate'])) {
if (isset($params['minDate']) && filled($params['minDate']) && isset($params['maxDate']) && filled($params['maxDate'])) {
$query->whereBetween(
'created_at',
[$params['minDate'] . ' 00:00:00', $params['maxDate'] . ' 23:59:59']
Expand Down
2 changes: 1 addition & 1 deletion app/Setting/Service/SettingConfigGroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(SettingConfigGroupMapper $mapper)
* 删除配置组和其所属配置.
*/
#[Transaction]
public function deleteConfigGroup(int $id): bool
public function deleteConfigGroup(mixed $id): bool
{
return $this->mapper->deleteGroupAndConfig($id);
}
Expand Down
11 changes: 6 additions & 5 deletions app/Setting/Service/SettingCrontabService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
/**
* 保存.
*/
public function save(array $data): int
public function save(array $data): mixed
{
return parent::save($data);
}
Expand All @@ -52,7 +52,7 @@ public function save(array $data): int
* 更新.
*/
#[CacheEvict(prefix: 'setting:crontab:read', value: '_#{id}')]
public function update(int $id, array $data): bool
public function update(mixed $id, array $data): bool
{
return parent::update($id, $data);
}
Expand All @@ -64,18 +64,19 @@ public function delete(array $ids): bool
}

#[Cacheable(prefix: 'setting:crontab:read', value: '_#{id}', ttl: 600)]
public function read(int $id, array $column = ['*']): ?MineModel
public function read(mixed $id, array $column = ['*']): ?MineModel
{
return parent::read($id, $column);
}

/**
* 立即执行一次定时任务
* @param mixed $id
* @return bool|null
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function run($id): ?bool
public function run(mixed $id): ?bool
{
$crontab = new MineCrontab();
$model = $this->read($id);
Expand All @@ -90,7 +91,7 @@ public function run($id): ?bool
}

#[DeleteCache('crontab')]
public function changeStatus(int $id, string $value, string $filed = 'status'): bool
public function changeStatus(mixed $id, string $value, string $filed = 'status'): bool
{
return parent::changeStatus($id, $value, $filed);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Setting/Service/SettingDatasourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getDataSourceTablePageList(?array $params = [], bool $isScope =
/**
* 同步远程库表结构到本地.
*/
public function syncRemoteTableStructToLocal(int $id, array $tableInfo): bool
public function syncRemoteTableStructToLocal(mixed $id, array $tableInfo): bool
{
if (empty($id)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions app/Setting/Service/SettingGenerateColumnsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(SettingGenerateColumnsMapper $mapper)
/**
* 循环插入数据.
*/
public function save(array $data): int
public function save(array $data): mixed
{
$default_column = ['created_at', 'updated_at', 'created_by', 'updated_by', 'deleted_at', 'remark'];
// 组装数据
Expand Down Expand Up @@ -81,7 +81,7 @@ public function save(array $data): int
return 1;
}

public function update(int $id, array $data): bool
public function update(mixed $id, array $data): bool
{
$data['is_insert'] = $data['is_insert'] ? SettingGenerateColumns::YES : SettingGenerateColumns::NO;
$data['is_edit'] = $data['is_edit'] ? SettingGenerateColumns::YES : SettingGenerateColumns::NO;
Expand Down
6 changes: 3 additions & 3 deletions app/Setting/Service/SettingGenerateTablesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function loadTable(array $params): bool
* 同步数据表.
*/
#[Transaction]
public function sync(int $id): bool
public function sync(mixed $id): bool
{
$table = $this->read($id);
$columns = $this->dataMaintainService->getColumnList(
Expand Down Expand Up @@ -212,7 +212,7 @@ public function getModels(): array
* 预览代码
* @throws \Exception
*/
public function preview(int $id): array
public function preview(mixed $id): array
{
/** @var SettingGenerateTables $model */
$model = $this->read($id);
Expand Down Expand Up @@ -281,7 +281,7 @@ public function preview(int $id): array
* @throws NotFoundExceptionInterface
* @throws \Exception
*/
protected function generateCodeFile(int $id, int $adminId): SettingGenerateTables
protected function generateCodeFile(mixed $id, int $adminId): SettingGenerateTables
{
/** @var SettingGenerateTables $model */
$model = $this->read($id);
Expand Down
12 changes: 6 additions & 6 deletions app/System/Mapper/SystemApiColumnMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ public function assignModel()
public function handleSearch(Builder $query, array $params): Builder
{
// 接口ID
if (! empty($params['api_id'])) {
if (isset($params['api_id']) && filled($params['api_id'])) {
$query->where('api_id', '=', $params['api_id']);
}

// 字段类型
if (! empty($params['type'])) {
if (isset($params['type']) && filled($params['type'])) {
$query->where('type', '=', $params['type']);
}

// 字段名称
if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', '=', $params['name']);
}

// 数据类型
if (! empty($params['data_type'])) {
if (isset($params['data_type']) && filled($params['data_type'])) {
$query->where('data_type', '=', $params['data_type']);
}

// 是否必填 1 非必填 2 必填
if (! empty($params['is_required'])) {
if (isset($params['is_required']) && filled($params['is_required'])) {
$query->where('is_required', '=', $params['is_required']);
}

// 状态 (1正常 2停用)
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', '=', $params['status']);
}
return $query;
Expand Down
6 changes: 3 additions & 3 deletions app/System/Mapper/SystemApiGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public function assignModel()
public function handleSearch(Builder $query, array $params): Builder
{
// 应用组名称
if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', '=', $params['name']);
}

// 状态
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', '=', $params['status']);
}

// 关联查询api列表
if (! empty($params['getApiList']) && $params['getApiList'] == true) {
if (isset($params['getApiList']) && filled($params['getApiList']) && $params['getApiList'] == true) {
$query->with(['apis' => function ($query) {
$query->where('status', SystemApi::ENABLE)->select(['id', 'group_id', 'name', 'access_name']);
}]);
Expand Down
8 changes: 4 additions & 4 deletions app/System/Mapper/SystemApiLogMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public function assignModel()
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['api_name'])) {
if (isset($params['api_name']) && filled($params['api_name'])) {
$query->where('api_name', 'like', '%' . $params['api_name'] . '%');
}
if (! empty($params['ip'])) {
if (isset($params['ip']) && filled($params['ip'])) {
$query->where('ip', 'like', '%' . $params['ip'] . '%');
}
if (! empty($params['access_name'])) {
if (isset($params['access_name']) && filled($params['access_name'])) {
$query->where('access_name', 'like', '%' . $params['access_name'] . '%');
}
if (! empty($params['access_time']) && is_array($params['access_time']) && count($params['access_time']) == 2) {
if (isset($params['access_time']) && filled($params['access_time']) && is_array($params['access_time']) && count($params['access_time']) == 2) {
$query->whereBetween(
'access_time',
[$params['access_time'][0] . ' 00:00:00', $params['access_time'][1] . ' 23:59:59']
Expand Down
4 changes: 2 additions & 2 deletions app/System/Mapper/SystemAppGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function assignModel()
public function handleSearch(Builder $query, array $params): Builder
{
// 应用组名称
if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', '=', $params['name']);
}

// 状态
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', '=', $params['status']);
}
return $query;
Expand Down
8 changes: 4 additions & 4 deletions app/System/Mapper/SystemAppMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ public function assignModel()
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['app_name'])) {
if (isset($params['app_name']) && filled($params['app_name'])) {
$query->where('app_name', $params['app_name']);
}

if (! empty($params['app_id'])) {
if (isset($params['app_id']) && filled($params['app_id'])) {
$query->where('app_id', $params['app_id']);
}

if (! empty($params['group_id'])) {
if (isset($params['group_id']) && filled($params['group_id'])) {
$query->where('group_id', $params['group_id']);
}

if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', $params['status']);
}
return $query;
Expand Down
18 changes: 9 additions & 9 deletions app/System/Mapper/SystemDeptMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ public function getSelectTree(): array
*/
public function getLeaderList(?array $params = null): array
{
if (empty($params['dept_id'])) {
if (blank($params['dept_id'])) {
throw new MineException('缺少部门ID', 500);
}
$query = Db::table('system_user as u')
->join('system_dept_leader as dl', 'u.id', '=', 'dl.user_id')
->where('dl.dept_id', '=', $params['dept_id']);

if (! empty($params['username'])) {
if (isset($params['username']) && filled($params['username'])) {
$query->where('u.username', 'like', '%' . $params['username'] . '%');
}

if (! empty($params['nickname'])) {
if (isset($params['nickname']) && filled($params['nickname'])) {
$query->where('u.nickname', 'like', '%' . $params['nickname'] . '%');
}

if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('u.status', $params['status']);
}

Expand Down Expand Up @@ -139,23 +139,23 @@ public function checkChildrenExists(int $id): bool
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', $params['status']);
}

if (! empty($params['name'])) {
if (isset($params['name']) && filled($params['name'])) {
$query->where('name', 'like', '%' . $params['name'] . '%');
}

if (! empty($params['leader'])) {
if (isset($params['leader']) && filled($params['leader'])) {
$query->where('leader', $params['leader']);
}

if (! empty($params['phone'])) {
if (isset($params['phone']) && filled($params['phone'])) {
$query->where('phone', $params['phone']);
}

if (! empty($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
if (isset($params['created_at']) && filled($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
$query->whereBetween(
'created_at',
[$params['created_at'][0] . ' 00:00:00', $params['created_at'][1] . ' 23:59:59']
Expand Down
10 changes: 5 additions & 5 deletions app/System/Mapper/SystemDictDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public function assignModel()
*/
public function handleSearch(Builder $query, array $params): Builder
{
if (! empty($params['type_id'])) {
if (isset($params['type_id']) && filled($params['type_id'])) {
$query->where('type_id', $params['type_id']);
}
if (! empty($params['code'])) {
if (isset($params['code']) && filled($params['code'])) {
$query->where('code', $params['code']);
}
if (! empty($params['value'])) {
if (isset($params['value']) && filled($params['value'])) {
$query->where('value', 'like', '%' . $params['value'] . '%');
}
if (! empty($params['label'])) {
if (isset($params['label']) && filled($params['label'])) {
$query->where('label', 'like', '%' . $params['label'] . '%');
}
if (! empty($params['status'])) {
if (isset($params['status']) && filled($params['status'])) {
$query->where('status', $params['status']);
}

Expand Down
Loading

0 comments on commit afbd1d0

Please sign in to comment.