From d6cbfb53a3a16f667b5b7260f9672753cadfaeba Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 20 Dec 2023 16:23:20 +0800 Subject: [PATCH] QualityCheckNature --- .../quality/QualityCheckNatureController.php | 108 +++++++++++++++ .../lists/quality/QualityCheckNatureLists.php | 86 ++++++++++++ .../logic/quality/QualityCheckNatureLogic.php | 129 ++++++++++++++++++ .../quality/QualityCheckNatureValidate.php | 120 ++++++++++++++++ .../safety/SafetyAccidentValidate.php | 4 +- .../validate/safety/SafetyCheckValidate.php | 4 +- .../safety/SafetyEmergencyPlanValidate.php | 4 +- .../safety/SafetyEvaluateValidate.php | 4 +- .../validate/safety/SafetyEventValidate.php | 4 +- .../validate/safety/SafetyModifyValidate.php | 4 +- .../safety/SafetyRehearsalValidate.php | 4 +- .../safety/SafetySuperviseValidate.php | 4 +- .../model/quality/QualityCheckNature.php | 37 +++++ app/common/model/safety/SafetyAccident.php | 2 +- app/common/model/safety/SafetyCheck.php | 2 +- .../model/safety/SafetyEmergencyPlan.php | 2 +- app/common/model/safety/SafetyEvaluate.php | 2 +- app/common/model/safety/SafetyEvent.php | 2 +- app/common/model/safety/SafetyModify.php | 2 +- app/common/model/safety/SafetyRehearsal.php | 2 +- app/common/model/safety/SafetySupervise.php | 2 +- 21 files changed, 504 insertions(+), 24 deletions(-) create mode 100644 app/adminapi/controller/quality/QualityCheckNatureController.php create mode 100644 app/adminapi/lists/quality/QualityCheckNatureLists.php create mode 100644 app/adminapi/logic/quality/QualityCheckNatureLogic.php create mode 100644 app/adminapi/validate/quality/QualityCheckNatureValidate.php create mode 100644 app/common/model/quality/QualityCheckNature.php diff --git a/app/adminapi/controller/quality/QualityCheckNatureController.php b/app/adminapi/controller/quality/QualityCheckNatureController.php new file mode 100644 index 000000000..362438ac2 --- /dev/null +++ b/app/adminapi/controller/quality/QualityCheckNatureController.php @@ -0,0 +1,108 @@ +dataLists(new QualityCheckNatureLists()); + } + + + /** + * @notes 添加检查性质 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function add() + { + $params = (new QualityCheckNatureValidate())->post()->goCheck('add'); + $result = QualityCheckNatureLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(QualityCheckNatureLogic::getError()); + } + + + /** + * @notes 编辑检查性质 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function edit() + { + $params = (new QualityCheckNatureValidate())->post()->goCheck('edit'); + $result = QualityCheckNatureLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(QualityCheckNatureLogic::getError()); + } + + + /** + * @notes 删除检查性质 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function delete() + { + $params = (new QualityCheckNatureValidate())->post()->goCheck('delete'); + QualityCheckNatureLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取检查性质详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function detail() + { + $params = (new QualityCheckNatureValidate())->goCheck('detail'); + $result = QualityCheckNatureLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/quality/QualityCheckNatureLists.php b/app/adminapi/lists/quality/QualityCheckNatureLists.php new file mode 100644 index 000000000..d2adab76b --- /dev/null +++ b/app/adminapi/lists/quality/QualityCheckNatureLists.php @@ -0,0 +1,86 @@ + ['name', 'user'], + + ]; + } + + + /** + * @notes 获取检查性质列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function lists(): array + { + return QualityCheckNature::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'name', 'user', 'illustrate', 'date']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); + $item['org_name'] = $org['name']; + $item['dept_name'] = $dept['name']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取检查性质数量 + * @return int + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function count(): int + { + return QualityCheckNature::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/quality/QualityCheckNatureLogic.php b/app/adminapi/logic/quality/QualityCheckNatureLogic.php new file mode 100644 index 000000000..bd7d204fc --- /dev/null +++ b/app/adminapi/logic/quality/QualityCheckNatureLogic.php @@ -0,0 +1,129 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'name' => $params['name'], + 'user' => $params['user'], + 'illustrate' => $params['illustrate'], + 'date' => strtotime($params['date']), + 'add_user' => $admin_id, + 'update_user' => $admin_id, + ]); + 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/12/20 15:56 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + QualityCheckNature::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'name' => $params['name'], + 'user' => $params['user'], + 'illustrate' => $params['illustrate'], + 'date' => strtotime($params['date']), + 'update_user' => $admin_id, + 'update_time' => time(), + ]); + 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/12/20 15:56 + */ + public static function delete(array $params): bool + { + return QualityCheckNature::destroy($params['id']); + } + + + /** + * @notes 获取检查性质详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public static function detail($params): array + { + $data = QualityCheckNature::findOrEmpty($params['id'])->toArray(); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['add_user_name'] = $admin[$data['add_user']]; + $data['update_user_name'] = $admin[$data['update_user']]; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/quality/QualityCheckNatureValidate.php b/app/adminapi/validate/quality/QualityCheckNatureValidate.php new file mode 100644 index 000000000..941a81d81 --- /dev/null +++ b/app/adminapi/validate/quality/QualityCheckNatureValidate.php @@ -0,0 +1,120 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'name' => 'require', + 'user' => 'require', + 'date' => 'dateFormat:Y-m-d', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'name.require' => '请填写检查性质名称', + 'user.require' => '请填写创建人', + 'date.dateFormat' => '创建日期格式错误' + ]; + + + /** + * @notes 添加场景 + * @return QualityCheckNatureValidate + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return QualityCheckNatureValidate + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return QualityCheckNatureValidate + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return QualityCheckNatureValidate + * @author likeadmin + * @date 2023/12/20 15:56 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkOrg($value): bool|string + { + $data = Orgs::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '组织不存在'; + } + return true; + } + + public function checkDept($value,$rule,$data): bool|string + { + $dept = Dept::where('id',$value)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']){ + return '部门不属于当前选择的组织'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/adminapi/validate/safety/SafetyAccidentValidate.php b/app/adminapi/validate/safety/SafetyAccidentValidate.php index a22628223..49cf6cd8f 100644 --- a/app/adminapi/validate/safety/SafetyAccidentValidate.php +++ b/app/adminapi/validate/safety/SafetyAccidentValidate.php @@ -38,7 +38,7 @@ class SafetyAccidentValidate extends BaseValidate 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', - 'happen_time' => 'date', + 'happen_time' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -47,7 +47,7 @@ class SafetyAccidentValidate extends BaseValidate 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', - 'happen_time.date' => '发生时间格式错误', + 'happen_time.dateFormat' => '发生时间格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetyCheckValidate.php b/app/adminapi/validate/safety/SafetyCheckValidate.php index 93bc1ddbc..2756d93e9 100644 --- a/app/adminapi/validate/safety/SafetyCheckValidate.php +++ b/app/adminapi/validate/safety/SafetyCheckValidate.php @@ -38,7 +38,7 @@ class SafetyCheckValidate extends BaseValidate 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', - 'check_date' => 'date', + 'check_date' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -47,7 +47,7 @@ class SafetyCheckValidate extends BaseValidate 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', - 'check_date.date' => '检查日期格式错误', + 'check_date.dateFormat' => '检查日期格式错误', ]; /** diff --git a/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php b/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php index 48795ccfa..342949ada 100644 --- a/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php +++ b/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php @@ -39,7 +39,7 @@ class SafetyEmergencyPlanValidate extends BaseValidate 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', 'name' => 'require', - 'happen_date' => 'date', + 'happen_date' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -49,7 +49,7 @@ class SafetyEmergencyPlanValidate extends BaseValidate 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', 'name.require' => '请填写名称', - 'happen_date.date' => '发生日期格式错误', + 'happen_date.dateFormat' => '发生日期格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetyEvaluateValidate.php b/app/adminapi/validate/safety/SafetyEvaluateValidate.php index 0baab74f7..77e73df0f 100644 --- a/app/adminapi/validate/safety/SafetyEvaluateValidate.php +++ b/app/adminapi/validate/safety/SafetyEvaluateValidate.php @@ -39,7 +39,7 @@ class SafetyEvaluateValidate extends BaseValidate 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', 'name' => 'require', - 'happen_date' => 'date', + 'happen_date' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -49,7 +49,7 @@ class SafetyEvaluateValidate extends BaseValidate 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', 'name.require' => '请填写名称', - 'happen_date.date' => '发生日期格式错误', + 'happen_date.dateFormat' => '发生日期格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetyEventValidate.php b/app/adminapi/validate/safety/SafetyEventValidate.php index ee292c3ae..d851df3ab 100644 --- a/app/adminapi/validate/safety/SafetyEventValidate.php +++ b/app/adminapi/validate/safety/SafetyEventValidate.php @@ -38,7 +38,7 @@ class SafetyEventValidate extends BaseValidate 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', - 'happen_time' => 'date', + 'happen_time' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -47,7 +47,7 @@ class SafetyEventValidate extends BaseValidate 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', - 'happen_time.date' => '发生时间格式错误', + 'happen_time.dateFormat' => '发生时间格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetyModifyValidate.php b/app/adminapi/validate/safety/SafetyModifyValidate.php index b8ed28e60..7f63120ea 100644 --- a/app/adminapi/validate/safety/SafetyModifyValidate.php +++ b/app/adminapi/validate/safety/SafetyModifyValidate.php @@ -38,7 +38,7 @@ class SafetyModifyValidate extends BaseValidate 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', - 'check_date' => 'date', + 'check_date' => 'dateFormat:Y-m-d', ]; protected $message = [ @@ -46,7 +46,7 @@ class SafetyModifyValidate extends BaseValidate 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', - 'check_date.date' => '检查日期格式错误', + 'check_date.dateFormat' => '检查日期格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetyRehearsalValidate.php b/app/adminapi/validate/safety/SafetyRehearsalValidate.php index ed92a7141..860db4ec9 100644 --- a/app/adminapi/validate/safety/SafetyRehearsalValidate.php +++ b/app/adminapi/validate/safety/SafetyRehearsalValidate.php @@ -39,7 +39,7 @@ class SafetyRehearsalValidate extends BaseValidate 'dept_id' => 'require|checkDept', 'project_id' => 'require|checkProject', 'name' => 'require', - 'happen_date' => 'date', + 'happen_date' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -49,7 +49,7 @@ class SafetyRehearsalValidate extends BaseValidate 'dept_id.require' => '请选择部门', 'project_id.require' => '请选择项目', 'name.require' => '请填写名称', - 'happen_date.date' => '发生日期格式错误', + 'happen_date.dateFormat' => '发生日期格式错误', ]; diff --git a/app/adminapi/validate/safety/SafetySuperviseValidate.php b/app/adminapi/validate/safety/SafetySuperviseValidate.php index 25ba0de4f..f7fd825ff 100644 --- a/app/adminapi/validate/safety/SafetySuperviseValidate.php +++ b/app/adminapi/validate/safety/SafetySuperviseValidate.php @@ -37,7 +37,7 @@ class SafetySuperviseValidate extends BaseValidate 'id' => 'require', 'org_id' => 'require|checkOrg', 'dept_id' => 'require|checkDept', - 'happen_time' => 'date', + 'happen_time' => 'dateFormat:Y-m-d', 'file' => 'checkFile' ]; @@ -45,7 +45,7 @@ class SafetySuperviseValidate extends BaseValidate 'id.require' => '缺少必要参数', 'org_id.require' => '请选择组织', 'dept_id.require' => '请选择部门', - 'happen_time.date' => '发生时间格式错误', + 'happen_time.dateFormat' => '发生时间格式错误', ]; diff --git a/app/common/model/quality/QualityCheckNature.php b/app/common/model/quality/QualityCheckNature.php new file mode 100644 index 000000000..c00b17063 --- /dev/null +++ b/app/common/model/quality/QualityCheckNature.php @@ -0,0 +1,37 @@ +