From 247d909cda00ac9c8f9bf32bc3893d4536f7be71 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 19 Dec 2023 16:54:01 +0800 Subject: [PATCH 1/5] SafetyModify --- .../safety/SafetyModifyController.php | 108 +++++++++++++ .../lists/safety/SafetyModifyLists.php | 91 +++++++++++ .../logic/safety/SafetyModifyLogic.php | 149 ++++++++++++++++++ .../validate/safety/SafetyModifyValidate.php | 142 +++++++++++++++++ app/common/model/safety/SafetyModify.php | 37 +++++ 5 files changed, 527 insertions(+) create mode 100644 app/adminapi/controller/safety/SafetyModifyController.php create mode 100644 app/adminapi/lists/safety/SafetyModifyLists.php create mode 100644 app/adminapi/logic/safety/SafetyModifyLogic.php create mode 100644 app/adminapi/validate/safety/SafetyModifyValidate.php create mode 100644 app/common/model/safety/SafetyModify.php diff --git a/app/adminapi/controller/safety/SafetyModifyController.php b/app/adminapi/controller/safety/SafetyModifyController.php new file mode 100644 index 000000000..297dcf782 --- /dev/null +++ b/app/adminapi/controller/safety/SafetyModifyController.php @@ -0,0 +1,108 @@ +dataLists(new SafetyModifyLists()); + } + + + /** + * @notes 添加安全整改 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function add() + { + $params = (new SafetyModifyValidate())->post()->goCheck('add'); + $result = SafetyModifyLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SafetyModifyLogic::getError()); + } + + + /** + * @notes 编辑安全整改 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function edit() + { + $params = (new SafetyModifyValidate())->post()->goCheck('edit'); + $result = SafetyModifyLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SafetyModifyLogic::getError()); + } + + + /** + * @notes 删除安全整改 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function delete() + { + $params = (new SafetyModifyValidate())->post()->goCheck('delete'); + SafetyModifyLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取安全整改详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function detail() + { + $params = (new SafetyModifyValidate())->goCheck('detail'); + $result = SafetyModifyLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/safety/SafetyModifyLists.php b/app/adminapi/lists/safety/SafetyModifyLists.php new file mode 100644 index 000000000..0d6407d13 --- /dev/null +++ b/app/adminapi/lists/safety/SafetyModifyLists.php @@ -0,0 +1,91 @@ + ['check_date', 'modify_term'], + '%like%' => ['check_nature', 'check_user', 'check_company', 'modify_company', 'modify_user', 'resp_user'], + + ]; + } + + + /** + * @notes 获取安全整改列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function lists(): array + { + return SafetyModify::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'project_id', 'check_nature', 'check_date', 'check_user', 'check_company', 'check_item', 'check_result', 'modify_term', 'modify_company', 'modify_user', 'safety_hazard', 'resp_user']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $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']; + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取安全整改数量 + * @return int + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function count(): int + { + return SafetyModify::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/safety/SafetyModifyLogic.php b/app/adminapi/logic/safety/SafetyModifyLogic.php new file mode 100644 index 000000000..b476911ad --- /dev/null +++ b/app/adminapi/logic/safety/SafetyModifyLogic.php @@ -0,0 +1,149 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'check_nature' => $params['check_nature'], + 'check_date' => strtotime($params['check_date']), + 'check_user' => $params['check_user'], + 'check_company' => $params['check_company'], + 'check_item' => $params['check_item'], + 'check_result' => $params['check_result'], + 'modify_term' => $params['modify_term'], + 'modify_company' => $params['modify_company'], + 'modify_user' => $params['modify_user'], + 'safety_hazard' => $params['safety_hazard'], + 'resp_user' => $params['resp_user'], + '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/19 16:40 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + SafetyModify::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'check_nature' => $params['check_nature'], + 'check_date' => strtotime($params['check_date']), + 'check_user' => $params['check_user'], + 'check_company' => $params['check_company'], + 'check_item' => $params['check_item'], + 'check_result' => $params['check_result'], + 'modify_term' => $params['modify_term'], + 'modify_company' => $params['modify_company'], + 'modify_user' => $params['modify_user'], + 'safety_hazard' => $params['safety_hazard'], + 'resp_user' => $params['resp_user'], + '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/19 16:40 + */ + public static function delete(array $params): bool + { + return SafetyModify::destroy($params['id']); + } + + + /** + * @notes 获取安全整改详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public static function detail($params): array + { + $data = SafetyModify::findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $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['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $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/safety/SafetyModifyValidate.php b/app/adminapi/validate/safety/SafetyModifyValidate.php new file mode 100644 index 000000000..b8ed28e60 --- /dev/null +++ b/app/adminapi/validate/safety/SafetyModifyValidate.php @@ -0,0 +1,142 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'check_date' => 'date', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'check_date.date' => '检查日期格式错误', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'org_id' => '组织id', + 'dept_id' => '部门id', + 'project_id' => '项目id', + 'add_user' => '添加人', + 'update_user' => '更新人', + ]; + + + /** + * @notes 添加场景 + * @return SafetyModifyValidate + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SafetyModifyValidate + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SafetyModifyValidate + * @author likeadmin + * @date 2023/12/19 16:40 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SafetyModifyValidate + * @author likeadmin + * @date 2023/12/19 16:40 + */ + 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; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/safety/SafetyModify.php b/app/common/model/safety/SafetyModify.php new file mode 100644 index 000000000..ad4b978fc --- /dev/null +++ b/app/common/model/safety/SafetyModify.php @@ -0,0 +1,37 @@ + Date: Tue, 19 Dec 2023 17:36:35 +0800 Subject: [PATCH 2/5] SafetyHazard --- .../safety/SafetyHazardController.php | 108 ++++++++++++ .../lists/safety/SafetyHazardLists.php | 89 ++++++++++ .../logic/safety/SafetyHazardLogic.php | 158 ++++++++++++++++++ .../validate/safety/SafetyHazardValidate.php | 138 +++++++++++++++ app/common/model/safety/SafetyHazard.php | 37 ++++ 5 files changed, 530 insertions(+) create mode 100644 app/adminapi/controller/safety/SafetyHazardController.php create mode 100644 app/adminapi/lists/safety/SafetyHazardLists.php create mode 100644 app/adminapi/logic/safety/SafetyHazardLogic.php create mode 100644 app/adminapi/validate/safety/SafetyHazardValidate.php create mode 100644 app/common/model/safety/SafetyHazard.php diff --git a/app/adminapi/controller/safety/SafetyHazardController.php b/app/adminapi/controller/safety/SafetyHazardController.php new file mode 100644 index 000000000..5b55d3bd0 --- /dev/null +++ b/app/adminapi/controller/safety/SafetyHazardController.php @@ -0,0 +1,108 @@ +dataLists(new SafetyHazardLists()); + } + + + /** + * @notes 添加危险源管理 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function add() + { + $params = (new SafetyHazardValidate())->post()->goCheck('add'); + $result = SafetyHazardLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SafetyHazardLogic::getError()); + } + + + /** + * @notes 编辑危险源管理 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function edit() + { + $params = (new SafetyHazardValidate())->post()->goCheck('edit'); + $result = SafetyHazardLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SafetyHazardLogic::getError()); + } + + + /** + * @notes 删除危险源管理 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function delete() + { + $params = (new SafetyHazardValidate())->post()->goCheck('delete'); + SafetyHazardLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取危险源管理详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function detail() + { + $params = (new SafetyHazardValidate())->goCheck('detail'); + $result = SafetyHazardLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/safety/SafetyHazardLists.php b/app/adminapi/lists/safety/SafetyHazardLists.php new file mode 100644 index 000000000..b5e977c65 --- /dev/null +++ b/app/adminapi/lists/safety/SafetyHazardLists.php @@ -0,0 +1,89 @@ + ['fill_company', 'construction_company_user', 'supervision_company_user', 'build_company_user'], + ]; + } + + + /** + * @notes 获取危险源管理列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function lists(): array + { + return SafetyHazard::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'project_id', 'fill_company', 'construction_company_user', 'supervision_company_user', 'build_company_user', 'source', 'accident', 'risk_level', 'control_level', 'department', 'users', 'technical_measure', 'manage_measure', 'emergency_measure', 'remark', 'file']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $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']; + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取危险源管理数量 + * @return int + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function count(): int + { + return SafetyHazard::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/safety/SafetyHazardLogic.php b/app/adminapi/logic/safety/SafetyHazardLogic.php new file mode 100644 index 000000000..79beb762c --- /dev/null +++ b/app/adminapi/logic/safety/SafetyHazardLogic.php @@ -0,0 +1,158 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'fill_company' => $params['fill_company'], + 'construction_company_user' => $params['construction_company_user'], + 'supervision_company_user' => $params['supervision_company_user'], + 'build_company_user' => $params['build_company_user'], + 'source' => $params['source'], + 'accident' => $params['accident'], + 'risk_level' => $params['risk_level'], + 'control_level' => $params['control_level'], + 'department' => $params['department'], + 'users' => $params['users'], + 'technical_measure' => $params['technical_measure'], + 'manage_measure' => $params['manage_measure'], + 'emergency_measure' => $params['emergency_measure'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + '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/19 17:22 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + SafetyHazard::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'fill_company' => $params['fill_company'], + 'construction_company_user' => $params['construction_company_user'], + 'supervision_company_user' => $params['supervision_company_user'], + 'build_company_user' => $params['build_company_user'], + 'source' => $params['source'], + 'accident' => $params['accident'], + 'risk_level' => $params['risk_level'], + 'control_level' => $params['control_level'], + 'department' => $params['department'], + 'users' => $params['users'], + 'technical_measure' => $params['technical_measure'], + 'manage_measure' => $params['manage_measure'], + 'emergency_measure' => $params['emergency_measure'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + '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/19 17:22 + */ + public static function delete(array $params): bool + { + return SafetyHazard::destroy($params['id']); + } + + + /** + * @notes 获取危险源管理详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public static function detail($params): array + { + $data = SafetyHazard::findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $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['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $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/safety/SafetyHazardValidate.php b/app/adminapi/validate/safety/SafetyHazardValidate.php new file mode 100644 index 000000000..4d4c86e6f --- /dev/null +++ b/app/adminapi/validate/safety/SafetyHazardValidate.php @@ -0,0 +1,138 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'file' => 'checkFile' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + ]; + + + /** + * @notes 添加场景 + * @return SafetyHazardValidate + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SafetyHazardValidate + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SafetyHazardValidate + * @author likeadmin + * @date 2023/12/19 17:22 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SafetyHazardValidate + * @author likeadmin + * @date 2023/12/19 17:22 + */ + 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; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkFile($value): bool|string + { + if($value != ''){ + $file = json_decode($value,true); + if(empty($file)){ + return '附件必须是json数组'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/safety/SafetyHazard.php b/app/common/model/safety/SafetyHazard.php new file mode 100644 index 000000000..cf9bd0673 --- /dev/null +++ b/app/common/model/safety/SafetyHazard.php @@ -0,0 +1,37 @@ + Date: Wed, 20 Dec 2023 09:54:54 +0800 Subject: [PATCH 3/5] SafetyEmergencyPlan --- .../safety/SafetyEmergencyPlanController.php | 108 +++++++++++++ .../lists/safety/SafetyEmergencyPlanLists.php | 90 +++++++++++ .../logic/safety/SafetyEmergencyPlanLogic.php | 130 +++++++++++++++ .../safety/SafetyEmergencyPlanValidate.php | 152 ++++++++++++++++++ .../model/safety/SafetyEmergencyPlan.php | 42 +++++ 5 files changed, 522 insertions(+) create mode 100644 app/adminapi/controller/safety/SafetyEmergencyPlanController.php create mode 100644 app/adminapi/lists/safety/SafetyEmergencyPlanLists.php create mode 100644 app/adminapi/logic/safety/SafetyEmergencyPlanLogic.php create mode 100644 app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php create mode 100644 app/common/model/safety/SafetyEmergencyPlan.php diff --git a/app/adminapi/controller/safety/SafetyEmergencyPlanController.php b/app/adminapi/controller/safety/SafetyEmergencyPlanController.php new file mode 100644 index 000000000..475ddcdb8 --- /dev/null +++ b/app/adminapi/controller/safety/SafetyEmergencyPlanController.php @@ -0,0 +1,108 @@ +dataLists(new SafetyEmergencyPlanLists()); + } + + + /** + * @notes 添加安全应急预案 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function add() + { + $params = (new SafetyEmergencyPlanValidate())->post()->goCheck('add'); + $result = SafetyEmergencyPlanLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SafetyEmergencyPlanLogic::getError()); + } + + + /** + * @notes 编辑安全应急预案 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function edit() + { + $params = (new SafetyEmergencyPlanValidate())->post()->goCheck('edit'); + $result = SafetyEmergencyPlanLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SafetyEmergencyPlanLogic::getError()); + } + + + /** + * @notes 删除安全应急预案 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function delete() + { + $params = (new SafetyEmergencyPlanValidate())->post()->goCheck('delete'); + SafetyEmergencyPlanLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取安全应急预案详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function detail() + { + $params = (new SafetyEmergencyPlanValidate())->goCheck('detail'); + $result = SafetyEmergencyPlanLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/safety/SafetyEmergencyPlanLists.php b/app/adminapi/lists/safety/SafetyEmergencyPlanLists.php new file mode 100644 index 000000000..ff3ddfca8 --- /dev/null +++ b/app/adminapi/lists/safety/SafetyEmergencyPlanLists.php @@ -0,0 +1,90 @@ + ['happen_date'], + '%like%' => ['name'], + ]; + } + + + /** + * @notes 获取安全应急预案列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function lists(): array + { + return SafetyEmergencyPlan::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'project_id', 'name', 'happen_date', 'content', 'remark', 'file']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $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']; + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取安全应急预案数量 + * @return int + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function count(): int + { + return SafetyEmergencyPlan::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/safety/SafetyEmergencyPlanLogic.php b/app/adminapi/logic/safety/SafetyEmergencyPlanLogic.php new file mode 100644 index 000000000..785e3292a --- /dev/null +++ b/app/adminapi/logic/safety/SafetyEmergencyPlanLogic.php @@ -0,0 +1,130 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + ]); + 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 09:27 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + SafetyEmergencyPlan::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + '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 09:27 + */ + public static function delete(array $params): bool + { + return SafetyEmergencyPlan::destroy($params['id']); + } + + + /** + * @notes 获取安全应急预案详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public static function detail($params): array + { + $data = SafetyEmergencyPlan::findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php b/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php new file mode 100644 index 000000000..48795ccfa --- /dev/null +++ b/app/adminapi/validate/safety/SafetyEmergencyPlanValidate.php @@ -0,0 +1,152 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'name' => 'require', + 'happen_date' => 'date', + 'file' => 'checkFile' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'name.require' => '请填写名称', + 'happen_date.date' => '发生日期格式错误', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_id' => '项目id', + ]; + + + /** + * @notes 添加场景 + * @return SafetyEmergencyPlanValidate + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SafetyEmergencyPlanValidate + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SafetyEmergencyPlanValidate + * @author likeadmin + * @date 2023/12/20 09:27 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SafetyEmergencyPlanValidate + * @author likeadmin + * @date 2023/12/20 09:27 + */ + 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; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkFile($value): bool|string + { + if($value != ''){ + $file = json_decode($value,true); + if(empty($file)){ + return '附件必须是json数组'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/safety/SafetyEmergencyPlan.php b/app/common/model/safety/SafetyEmergencyPlan.php new file mode 100644 index 000000000..5a07ed4c6 --- /dev/null +++ b/app/common/model/safety/SafetyEmergencyPlan.php @@ -0,0 +1,42 @@ + Date: Wed, 20 Dec 2023 10:13:25 +0800 Subject: [PATCH 4/5] SafetyRehearsal --- .../safety/SafetyRehearsalController.php | 108 ++++++++++++ .../lists/safety/SafetyRehearsalLists.php | 90 ++++++++++ .../logic/safety/SafetyRehearsalLogic.php | 129 +++++++++++++++ .../safety/SafetyRehearsalValidate.php | 155 ++++++++++++++++++ app/common/model/safety/SafetyRehearsal.php | 42 +++++ 5 files changed, 524 insertions(+) create mode 100644 app/adminapi/controller/safety/SafetyRehearsalController.php create mode 100644 app/adminapi/lists/safety/SafetyRehearsalLists.php create mode 100644 app/adminapi/logic/safety/SafetyRehearsalLogic.php create mode 100644 app/adminapi/validate/safety/SafetyRehearsalValidate.php create mode 100644 app/common/model/safety/SafetyRehearsal.php diff --git a/app/adminapi/controller/safety/SafetyRehearsalController.php b/app/adminapi/controller/safety/SafetyRehearsalController.php new file mode 100644 index 000000000..50e4f5f5a --- /dev/null +++ b/app/adminapi/controller/safety/SafetyRehearsalController.php @@ -0,0 +1,108 @@ +dataLists(new SafetyRehearsalLists()); + } + + + /** + * @notes 添加安全演练 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function add() + { + $params = (new SafetyRehearsalValidate())->post()->goCheck('add'); + $result = SafetyRehearsalLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SafetyRehearsalLogic::getError()); + } + + + /** + * @notes 编辑安全演练 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function edit() + { + $params = (new SafetyRehearsalValidate())->post()->goCheck('edit'); + $result = SafetyRehearsalLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SafetyRehearsalLogic::getError()); + } + + + /** + * @notes 删除安全演练 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function delete() + { + $params = (new SafetyRehearsalValidate())->post()->goCheck('delete'); + SafetyRehearsalLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取安全演练详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function detail() + { + $params = (new SafetyRehearsalValidate())->goCheck('detail'); + $result = SafetyRehearsalLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/safety/SafetyRehearsalLists.php b/app/adminapi/lists/safety/SafetyRehearsalLists.php new file mode 100644 index 000000000..5141d335d --- /dev/null +++ b/app/adminapi/lists/safety/SafetyRehearsalLists.php @@ -0,0 +1,90 @@ + ['happen_date'], + '%like%' => ['name'], + ]; + } + + + /** + * @notes 获取安全演练列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function lists(): array + { + return SafetyRehearsal::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'project_id', 'name', 'happen_date', 'content', 'remark', 'file']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $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']; + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取安全演练数量 + * @return int + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function count(): int + { + return SafetyRehearsal::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/safety/SafetyRehearsalLogic.php b/app/adminapi/logic/safety/SafetyRehearsalLogic.php new file mode 100644 index 000000000..e2b4d4c30 --- /dev/null +++ b/app/adminapi/logic/safety/SafetyRehearsalLogic.php @@ -0,0 +1,129 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + ]); + 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 10:05 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + SafetyRehearsal::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + ]); + 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 10:05 + */ + public static function delete(array $params): bool + { + return SafetyRehearsal::destroy($params['id']); + } + + + /** + * @notes 获取安全演练详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public static function detail($params): array + { + $data = SafetyRehearsal::findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/safety/SafetyRehearsalValidate.php b/app/adminapi/validate/safety/SafetyRehearsalValidate.php new file mode 100644 index 000000000..ed92a7141 --- /dev/null +++ b/app/adminapi/validate/safety/SafetyRehearsalValidate.php @@ -0,0 +1,155 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'name' => 'require', + 'happen_date' => 'date', + 'file' => 'checkFile' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'name.require' => '请填写名称', + 'happen_date.date' => '发生日期格式错误', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'org_id' => '组织id', + 'dept_id' => '部门id', + 'project_id' => '项目id', + 'name' => '名称', + ]; + + + /** + * @notes 添加场景 + * @return SafetyRehearsalValidate + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SafetyRehearsalValidate + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SafetyRehearsalValidate + * @author likeadmin + * @date 2023/12/20 10:05 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SafetyRehearsalValidate + * @author likeadmin + * @date 2023/12/20 10:05 + */ + 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; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkFile($value): bool|string + { + if($value != ''){ + $file = json_decode($value,true); + if(empty($file)){ + return '附件必须是json数组'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/safety/SafetyRehearsal.php b/app/common/model/safety/SafetyRehearsal.php new file mode 100644 index 000000000..43e263d85 --- /dev/null +++ b/app/common/model/safety/SafetyRehearsal.php @@ -0,0 +1,42 @@ + Date: Wed, 20 Dec 2023 10:36:53 +0800 Subject: [PATCH 5/5] SafetyEvaluate --- .../safety/SafetyEvaluateController.php | 108 ++++++++++++ .../lists/safety/SafetyEvaluateLists.php | 90 ++++++++++ .../logic/safety/SafetyEvaluateLogic.php | 128 +++++++++++++++ .../safety/SafetyEvaluateValidate.php | 155 ++++++++++++++++++ app/common/model/safety/SafetyEvaluate.php | 42 +++++ 5 files changed, 523 insertions(+) create mode 100644 app/adminapi/controller/safety/SafetyEvaluateController.php create mode 100644 app/adminapi/lists/safety/SafetyEvaluateLists.php create mode 100644 app/adminapi/logic/safety/SafetyEvaluateLogic.php create mode 100644 app/adminapi/validate/safety/SafetyEvaluateValidate.php create mode 100644 app/common/model/safety/SafetyEvaluate.php diff --git a/app/adminapi/controller/safety/SafetyEvaluateController.php b/app/adminapi/controller/safety/SafetyEvaluateController.php new file mode 100644 index 000000000..bb9f359a0 --- /dev/null +++ b/app/adminapi/controller/safety/SafetyEvaluateController.php @@ -0,0 +1,108 @@ +dataLists(new SafetyEvaluateLists()); + } + + + /** + * @notes 添加安全评估 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function add() + { + $params = (new SafetyEvaluateValidate())->post()->goCheck('add'); + $result = SafetyEvaluateLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SafetyEvaluateLogic::getError()); + } + + + /** + * @notes 编辑安全评估 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function edit() + { + $params = (new SafetyEvaluateValidate())->post()->goCheck('edit'); + $result = SafetyEvaluateLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SafetyEvaluateLogic::getError()); + } + + + /** + * @notes 删除安全评估 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function delete() + { + $params = (new SafetyEvaluateValidate())->post()->goCheck('delete'); + SafetyEvaluateLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取安全评估详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function detail() + { + $params = (new SafetyEvaluateValidate())->goCheck('detail'); + $result = SafetyEvaluateLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/safety/SafetyEvaluateLists.php b/app/adminapi/lists/safety/SafetyEvaluateLists.php new file mode 100644 index 000000000..db1888ccd --- /dev/null +++ b/app/adminapi/lists/safety/SafetyEvaluateLists.php @@ -0,0 +1,90 @@ + ['happen_date'], + '%like%' => ['name'], + + ]; + } + + + /** + * @notes 获取安全评估列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function lists(): array + { + return SafetyEvaluate::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'project_id', 'name', 'happen_date', 'content', 'remark', 'file']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $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']; + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + })->toArray(); + } + + + /** + * @notes 获取安全评估数量 + * @return int + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function count(): int + { + return SafetyEvaluate::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/safety/SafetyEvaluateLogic.php b/app/adminapi/logic/safety/SafetyEvaluateLogic.php new file mode 100644 index 000000000..b04e03645 --- /dev/null +++ b/app/adminapi/logic/safety/SafetyEvaluateLogic.php @@ -0,0 +1,128 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + ]); + 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 10:27 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + SafetyEvaluate::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'name' => $params['name'], + 'happen_date' => strtotime($params['happen_date']), + 'content' => $params['content'], + 'remark' => $params['remark'], + 'file' => !empty($params['file']) ? $params['file'] : null, + ]); + 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 10:27 + */ + public static function delete(array $params): bool + { + return SafetyEvaluate::destroy($params['id']); + } + + + /** + * @notes 获取安全评估详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public static function detail($params): array + { + $data = SafetyEvaluate::findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/safety/SafetyEvaluateValidate.php b/app/adminapi/validate/safety/SafetyEvaluateValidate.php new file mode 100644 index 000000000..0baab74f7 --- /dev/null +++ b/app/adminapi/validate/safety/SafetyEvaluateValidate.php @@ -0,0 +1,155 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'name' => 'require', + 'happen_date' => 'date', + 'file' => 'checkFile' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'name.require' => '请填写名称', + 'happen_date.date' => '发生日期格式错误', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'org_id' => '组织id', + 'dept_id' => '部门id', + 'project_id' => '项目id', + 'name' => '名称', + ]; + + + /** + * @notes 添加场景 + * @return SafetyEvaluateValidate + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SafetyEvaluateValidate + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SafetyEvaluateValidate + * @author likeadmin + * @date 2023/12/20 10:27 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SafetyEvaluateValidate + * @author likeadmin + * @date 2023/12/20 10:27 + */ + 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; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkFile($value): bool|string + { + if($value != ''){ + $file = json_decode($value,true); + if(empty($file)){ + return '附件必须是json数组'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/safety/SafetyEvaluate.php b/app/common/model/safety/SafetyEvaluate.php new file mode 100644 index 000000000..cbc64b1ea --- /dev/null +++ b/app/common/model/safety/SafetyEvaluate.php @@ -0,0 +1,42 @@ +