feat: add article and production modules
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\ExceptionRecord;
|
||||
|
||||
class ExceptionRecordDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ExceptionRecord::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['order_no', 'user_code', 'reporter', 'type_name', 'reason_name', 'issue_name', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['createds']));
|
||||
$order = $order ?: 'reported_at desc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$query->where(function (Builder $builder) use ($keyword) {
|
||||
$builder->where('order_no', 'like', $keyword)
|
||||
->orWhere('user_code', 'like', $keyword)
|
||||
->orWhere('reporter', 'like', $keyword)
|
||||
->orWhere('type_name', 'like', $keyword)
|
||||
->orWhere('reason_name', 'like', $keyword)
|
||||
->orWhere('issue_name', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
foreach (['type_code', 'reason_code', 'issue_code', 'status'] as $field) {
|
||||
if (($where[$field] ?? '') !== '') {
|
||||
$query->where($field, $where[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($where['reported_at_range']) && is_array($where['reported_at_range']) && count($where['reported_at_range']) === 2) {
|
||||
$query->whereBetween('reported_at', [
|
||||
strtotime((string) $where['reported_at_range'][0] . ' 00:00:00'),
|
||||
strtotime((string) $where['reported_at_range'][1] . ' 23:59:59'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use plugin\produce\app\model\ExceptionSetting;
|
||||
|
||||
class ExceptionSettingDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ExceptionSetting::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['code', 'name', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['parent', 'createds']));
|
||||
$order = $order ?: 'setting_type asc, parent_id asc, sort asc, id asc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
|
||||
{
|
||||
$with = array_unique(array_merge($with ?? [], ['parent', 'createds']));
|
||||
return parent::get($id, $field, $with, $order, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$query->where(function (Builder $builder) use ($keyword) {
|
||||
$builder->where('code', 'like', $keyword)
|
||||
->orWhere('name', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
foreach (['setting_type', 'parent_id', 'is_enabled'] as $field) {
|
||||
if (($where[$field] ?? '') !== '') {
|
||||
$query->where($field, $where[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\produce\app\model\HardwareFaultDescription;
|
||||
|
||||
class HardwareFaultDescriptionDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return HardwareFaultDescription::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['description', 'remark'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\produce\app\model\MaterialCategory;
|
||||
|
||||
class MaterialCategoryDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return MaterialCategory::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['category_name'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\Material;
|
||||
|
||||
class MaterialDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return Material::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['product_code', 'product_name'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
return parent::selectList($where, $field, $page, $limit, $order ?: 'id desc', array_unique(array_merge($with, ['category'])), $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$query->where(function (Builder $builder) use ($keyword) {
|
||||
$builder->where('product_code', 'like', $keyword)
|
||||
->orWhere('product_name', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
if (($where['category_id'] ?? '') !== '') {
|
||||
$query->where('category_id', $where['category_id']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\Process;
|
||||
|
||||
class ProcessDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return Process::class;
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$query = $this->selectModel($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
$query->withCount(['steps as step_count']);
|
||||
|
||||
if ($page > 0 && $limit > 0) {
|
||||
return $query->paginate($limit, ['*'], 'page', $page)->getCollection();
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['process_code', 'process_name', 'description'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\ProcessStep;
|
||||
|
||||
class ProcessStepDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ProcessStep::class;
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
return parent::selectList($where, $field, $page, $limit, $order, ['process'], $search, $withoutScopes);
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['step_code', 'step_name', 'description'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\produce\app\model\ProduceConfig;
|
||||
|
||||
class ProduceConfigDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ProduceConfig::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['group_code', 'code', 'name', 'remark'];
|
||||
}
|
||||
|
||||
public function getByGroupCode(string $groupCode): array
|
||||
{
|
||||
$items = $this->getModel()::query()
|
||||
->where('group_code', $groupCode)
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
$result = [];
|
||||
foreach ($items as $item) {
|
||||
$result[$item->code] = $item->content;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function batchSave(string $groupCode, array $configs): bool
|
||||
{
|
||||
$timestamp = time();
|
||||
|
||||
foreach ($configs as $config) {
|
||||
$this->getModel()::query()->updateOrCreate(
|
||||
[
|
||||
'group_code' => $groupCode,
|
||||
'code' => (string) ($config['code'] ?? ''),
|
||||
],
|
||||
[
|
||||
'name' => (string) ($config['name'] ?? ''),
|
||||
'content' => is_scalar($config['content'] ?? null) || $config['content'] === null
|
||||
? ($config['content'] ?? null)
|
||||
: json_encode($config['content'], JSON_UNESCAPED_UNICODE),
|
||||
'sort' => (int) ($config['sort'] ?? 0),
|
||||
'remark' => (string) ($config['remark'] ?? ''),
|
||||
'updated_at' => $timestamp,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\ProductRecord;
|
||||
|
||||
class ProductRecordDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ProductRecord::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['process_order_no', 'product_code', 'operator', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['process', 'step', 'status']));
|
||||
$order = $order ?: 'created_at desc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$query->where(function (Builder $builder) use ($where) {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$builder->where('process_order_no', 'like', $keyword)
|
||||
->orWhere('product_code', 'like', $keyword)
|
||||
->orWhere('operator', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
if (($where['process_id'] ?? '') !== '') {
|
||||
$query->where('process_id', $where['process_id']);
|
||||
}
|
||||
|
||||
if (($where['step_id'] ?? '') !== '') {
|
||||
$query->where('step_id', $where['step_id']);
|
||||
}
|
||||
|
||||
if (($where['status_id'] ?? '') !== '') {
|
||||
$query->where('status_id', $where['status_id']);
|
||||
}
|
||||
|
||||
if (($where['scan_result'] ?? '') !== '') {
|
||||
$query->where('scan_result', $where['scan_result']);
|
||||
}
|
||||
|
||||
if (!empty($where['created_time_range']) && is_array($where['created_time_range']) && count($where['created_time_range']) === 2) {
|
||||
$query->whereBetween('created_at', [strtotime((string) $where['created_time_range'][0]), strtotime((string) $where['created_time_range'][1])]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\produce\app\model\RepairRecord;
|
||||
|
||||
class RepairRecordDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return RepairRecord::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['repair_no', 'order_no', 'product_code', 'product_name', 'fault_description', 'operator', 'remark'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use plugin\produce\app\model\RepairSetting;
|
||||
|
||||
class RepairSettingDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return RepairSetting::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['code', 'name', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['parent', 'createds']));
|
||||
$order = $order ?: 'setting_type asc, parent_id asc, sort asc, id asc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
|
||||
{
|
||||
$with = array_unique(array_merge($with ?? [], ['parent', 'createds']));
|
||||
return parent::get($id, $field, $with, $order, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$query->where(function (Builder $builder) use ($keyword) {
|
||||
$builder->where('code', 'like', $keyword)
|
||||
->orWhere('name', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
foreach (['setting_type', 'parent_id', 'is_enabled'] as $field) {
|
||||
if (($where[$field] ?? '') !== '') {
|
||||
$query->where($field, $where[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\ScanData;
|
||||
|
||||
class ScanDataDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return ScanData::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['order_no', 'user_code', 'operator', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['process', 'step', 'status']));
|
||||
$order = $order ?: 'scan_time desc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$query->where(function (Builder $builder) use ($where) {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$builder->where('order_no', 'like', $keyword)
|
||||
->orWhere('user_code', 'like', $keyword)
|
||||
->orWhere('operator', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
if (($where['process_id'] ?? '') !== '') {
|
||||
$query->where('process_id', $where['process_id']);
|
||||
}
|
||||
|
||||
if (($where['step_id'] ?? '') !== '') {
|
||||
$query->where('step_id', $where['step_id']);
|
||||
}
|
||||
|
||||
if (($where['status_id'] ?? '') !== '') {
|
||||
$query->where('status_id', $where['status_id']);
|
||||
}
|
||||
|
||||
if (($where['scan_result'] ?? '') !== '') {
|
||||
$query->where('scan_result', $where['scan_result']);
|
||||
}
|
||||
|
||||
if (!empty($where['scan_time_range']) && is_array($where['scan_time_range']) && count($where['scan_time_range']) === 2) {
|
||||
$query->whereBetween('scan_time', [strtotime((string) $where['scan_time_range'][0]), strtotime((string) $where['scan_time_range'][1])]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use plugin\produce\app\model\SpecificRule;
|
||||
|
||||
class SpecificRuleDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return SpecificRule::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['rule_name', 'rule_pattern', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['createds']));
|
||||
$order = $order ?: 'sort asc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
|
||||
{
|
||||
$with = array_unique(array_merge($with ?? [], ['createds']));
|
||||
return parent::get($id, $field, $with, $order, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = $this->query();
|
||||
|
||||
if (($where['keyword'] ?? '') !== '') {
|
||||
$query->where(function (Builder $builder) use ($where) {
|
||||
$keyword = '%' . $where['keyword'] . '%';
|
||||
$builder->where('rule_name', 'like', $keyword)
|
||||
->orWhere('rule_pattern', 'like', $keyword)
|
||||
->orWhere('remark', 'like', $keyword);
|
||||
});
|
||||
}
|
||||
|
||||
if (($where['rule_type'] ?? '') !== '') {
|
||||
$query->where('rule_type', $where['rule_type']);
|
||||
}
|
||||
|
||||
if (($where['is_enabled'] ?? '') !== '') {
|
||||
$query->where('is_enabled', $where['is_enabled']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use plugin\produce\app\model\StatusTransition;
|
||||
|
||||
class StatusTransitionDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return StatusTransition::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['trigger_event', 'description'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['step', 'fromStatus', 'toStatus']));
|
||||
$order = $order ?: 'priority desc, sort asc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = parent::handleSearch($where, $isPage);
|
||||
|
||||
if (($where['step_id'] ?? '') !== '') {
|
||||
$query->where('step_id', $where['step_id']);
|
||||
}
|
||||
|
||||
if (($where['from_status_id'] ?? '') !== '') {
|
||||
$query->where('from_status_id', $where['from_status_id']);
|
||||
}
|
||||
|
||||
if (($where['to_status_id'] ?? '') !== '') {
|
||||
$query->where('to_status_id', $where['to_status_id']);
|
||||
}
|
||||
|
||||
if (($where['trigger_event'] ?? '') !== '') {
|
||||
$query->where('trigger_event', $where['trigger_event']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getAutoTransitionsByStep(int|string $stepId, int|string $fromStatusId): array
|
||||
{
|
||||
return $this->getModel()::query()
|
||||
->where('step_id', $stepId)
|
||||
->where('from_status_id', $fromStatusId)
|
||||
->where('auto_trigger', 1)
|
||||
->where('status', 1)
|
||||
->orderBy('priority', 'desc')
|
||||
->orderBy('sort', 'asc')
|
||||
->with(['toStatus:id,status_name'])
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'step_id' => $item->step_id,
|
||||
'from_status_id' => $item->from_status_id,
|
||||
'to_status_id' => $item->to_status_id,
|
||||
'to_status_name' => $item->toStatus->status_name ?? '',
|
||||
'trigger_event' => $item->trigger_event,
|
||||
'event_config' => $item->event_config,
|
||||
'priority' => $item->priority,
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getAutoTransitions(int|string $stepId, int|string $fromStatusId, string $triggerEvent): array
|
||||
{
|
||||
return $this->getModel()::query()
|
||||
->where('step_id', $stepId)
|
||||
->where('from_status_id', $fromStatusId)
|
||||
->where('trigger_event', $triggerEvent)
|
||||
->where('auto_trigger', 1)
|
||||
->where('status', 1)
|
||||
->orderBy('priority', 'desc')
|
||||
->orderBy('sort', 'asc')
|
||||
->with(['toStatus:id,status_name'])
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'step_id' => $item->step_id,
|
||||
'from_status_id' => $item->from_status_id,
|
||||
'to_status_id' => $item->to_status_id,
|
||||
'to_status_name' => $item->toStatus->status_name ?? '',
|
||||
'trigger_event' => $item->trigger_event,
|
||||
'event_config' => $item->event_config,
|
||||
'priority' => $item->priority,
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use plugin\produce\app\model\StepRelation;
|
||||
|
||||
class StepRelationDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return StepRelation::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['relation_type', 'description'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['fromStep', 'toStep']));
|
||||
$order = $order ?: 'priority asc, sort asc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = parent::handleSearch($where, $isPage);
|
||||
|
||||
if (($where['from_step_id'] ?? '') !== '') {
|
||||
$query->where('from_step_id', $where['from_step_id']);
|
||||
}
|
||||
|
||||
if (($where['to_step_id'] ?? '') !== '') {
|
||||
$query->where('to_step_id', $where['to_step_id']);
|
||||
}
|
||||
|
||||
if (($where['relation_type'] ?? '') !== '') {
|
||||
$query->where('relation_type', $where['relation_type']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getPreviousSteps(int|string $currentStepId): array
|
||||
{
|
||||
return $this->getModel()::query()
|
||||
->where('to_step_id', $currentStepId)
|
||||
->where('status', 1)
|
||||
->orderBy('priority', 'asc')
|
||||
->orderBy('sort', 'asc')
|
||||
->get(['id', 'from_step_id', 'to_step_id', 'relation_type'])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use plugin\produce\app\model\StepStatus;
|
||||
|
||||
class StepStatusDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return StepStatus::class;
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
return parent::selectList($where, $field, $page, $limit, $order, ['step'], $search, $withoutScopes);
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['status_code', 'status_name', 'description'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use plugin\produce\app\model\TransitionLog;
|
||||
|
||||
class TransitionLogDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return TransitionLog::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['work_order_no', 'trigger_user', 'error_message', 'remark'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['step', 'transition', 'fromStatus', 'toStatus']));
|
||||
$order = $order ?: 'created_at desc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
|
||||
{
|
||||
$with = array_unique(array_merge($with ?? [], ['step', 'transition', 'fromStatus', 'toStatus']));
|
||||
return parent::get($id, $field, $with, $order, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = parent::handleSearch($where, $isPage);
|
||||
|
||||
if (($where['step_id'] ?? '') !== '') {
|
||||
$query->where('step_id', $where['step_id']);
|
||||
}
|
||||
|
||||
if (($where['trigger_event'] ?? '') !== '') {
|
||||
$query->where('trigger_event', $where['trigger_event']);
|
||||
}
|
||||
|
||||
if (($where['is_success'] ?? '') !== '') {
|
||||
$query->where('is_success', $where['is_success']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user