From f34e88a8d24016c3d617b78eb07c4710dfcce974 Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 13 Dec 2023 17:03:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AEWBS?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectRoleSetController.php | 7 + .../project/ProjectTypeSetController.php | 7 + .../project/ProjectWbsSetController.php | 108 ++++++++++++ .../lists/project/ProjectWbsSetLists.php | 84 ++++++++++ .../logic/project/ProjectWbsSetLogic.php | 146 ++++++++++++++++ .../project/ProjectWbsSetValidate.php | 157 ++++++++++++++++++ app/common.php | 15 ++ app/common/model/project/ProjectWbsSet.php | 34 ++++ 8 files changed, 558 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectWbsSetController.php create mode 100644 app/adminapi/lists/project/ProjectWbsSetLists.php create mode 100644 app/adminapi/logic/project/ProjectWbsSetLogic.php create mode 100644 app/adminapi/validate/project/ProjectWbsSetValidate.php create mode 100644 app/common/model/project/ProjectWbsSet.php diff --git a/app/adminapi/controller/project/ProjectRoleSetController.php b/app/adminapi/controller/project/ProjectRoleSetController.php index d0ce44191..03fd4bb9e 100644 --- a/app/adminapi/controller/project/ProjectRoleSetController.php +++ b/app/adminapi/controller/project/ProjectRoleSetController.php @@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\project\ProjectRoleSetLists; use app\adminapi\logic\project\ProjectRoleSetLogic; use app\adminapi\validate\project\ProjectRoleSetValidate; +use app\common\model\project\ProjectRoleSet; /** @@ -103,6 +104,12 @@ class ProjectRoleSetController extends BaseAdminController $result = ProjectRoleSetLogic::detail($params); return $this->data($result); } + + public function getAllProjectRoles(): \think\response\Json + { + $data = ProjectRoleSet::field('id,name')->order('sort desc')->select()->toArray(); + return $this->success('请求成功',$data); + } } \ No newline at end of file diff --git a/app/adminapi/controller/project/ProjectTypeSetController.php b/app/adminapi/controller/project/ProjectTypeSetController.php index 1cc15dcf2..9dac83fd2 100644 --- a/app/adminapi/controller/project/ProjectTypeSetController.php +++ b/app/adminapi/controller/project/ProjectTypeSetController.php @@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\project\ProjectTypeSetLists; use app\adminapi\logic\project\ProjectTypeSetLogic; use app\adminapi\validate\project\ProjectTypeSetValidate; +use app\common\model\project\ProjectTypeSet; /** @@ -103,6 +104,12 @@ class ProjectTypeSetController extends BaseAdminController $result = ProjectTypeSetLogic::detail($params); return $this->data($result); } + + public function getAllProjectTypes(): \think\response\Json + { + $data = ProjectTypeSet::field('id,name')->select()->toArray(); + return $this->success('请求成功',$data); + } } \ No newline at end of file diff --git a/app/adminapi/controller/project/ProjectWbsSetController.php b/app/adminapi/controller/project/ProjectWbsSetController.php new file mode 100644 index 000000000..6449a77d4 --- /dev/null +++ b/app/adminapi/controller/project/ProjectWbsSetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectWbsSetLists()); + } + + + /** + * @notes 添加项目WBS设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function add() + { + $params = (new ProjectWbsSetValidate())->post()->goCheck('add'); + $result = ProjectWbsSetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectWbsSetLogic::getError()); + } + + + /** + * @notes 编辑项目WBS设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function edit() + { + $params = (new ProjectWbsSetValidate())->post()->goCheck('edit'); + $result = ProjectWbsSetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectWbsSetLogic::getError()); + } + + + /** + * @notes 删除项目WBS设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function delete() + { + $params = (new ProjectWbsSetValidate())->post()->goCheck('delete'); + $result = ProjectWbsSetLogic::delete($params); + return $result ? $this->success('删除成功', [], 1, 1) : $this->fail(ProjectWbsSetLogic::getError()); + } + + + /** + * @notes 获取项目WBS设置详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function detail() + { + $params = (new ProjectWbsSetValidate())->goCheck('detail'); + $result = ProjectWbsSetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectWbsSetLists.php b/app/adminapi/lists/project/ProjectWbsSetLists.php new file mode 100644 index 000000000..932e568b4 --- /dev/null +++ b/app/adminapi/lists/project/ProjectWbsSetLists.php @@ -0,0 +1,84 @@ + ['name','wbs_code'], + ]; + } + + + /** + * @notes 获取项目WBS设置列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function lists(): array + { + $data = ProjectWbsSet::where($this->searchWhere) + ->field(['id', 'pid', 'wbs_code', 'name', 'work_standards', 'project_role_id', 'output_data', 'sort', 'weight']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $projectRole = ProjectRoleSet::field('id,name')->where('id',$item['project_role_id'])->findOrEmpty(); + $item['project_role_name'] = $projectRole->isEmpty() ? '' : $projectRole->name; + return $item; + }) + ->toArray(); + $tree = buildTree($data,'pid'); + return $tree; + } + + + /** + * @notes 获取项目WBS设置数量 + * @return int + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function count(): int + { + return ProjectWbsSet::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectWbsSetLogic.php b/app/adminapi/logic/project/ProjectWbsSetLogic.php new file mode 100644 index 000000000..d7e1a6d5e --- /dev/null +++ b/app/adminapi/logic/project/ProjectWbsSetLogic.php @@ -0,0 +1,146 @@ +findOrEmpty(); + $pid = !$supData->isEmpty() ? $supData['id'] : 0; + } + ProjectWbsSet::create([ + 'project_type_id' => $params['project_type_id'], + 'pid' => $pid, + 'wbs_code' => $params['wbs_code'], + 'name' => $params['name'], + 'work_standards' => $params['work_standards'], + 'project_role_id' => $params['project_role_id'], + 'output_data' => $params['output_data'], + 'sort' => $params['sort'], + 'weight' => $params['weight'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑项目WBS设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $pid = 0; + if(isset($params['sup_wbs_code']) && $params['sup_wbs_code'] != ''){ + $supData = ProjectWbsSet::where('wbs_code',$params['sup_wbs_code'])->findOrEmpty(); + $pid = !$supData->isEmpty() ? $supData['id'] : 0; + } + ProjectWbsSet::where('id', $params['id'])->update([ + 'project_type_id' => $params['project_type_id'], + 'pid' => $pid, + 'wbs_code' => $params['wbs_code'], + 'name' => $params['name'], + 'work_standards' => $params['work_standards'], + 'project_role_id' => $params['project_role_id'], + 'output_data' => $params['output_data'], + 'sort' => $params['sort'], + 'weight' => $params['weight'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除项目WBS设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public static function delete(array $params): bool + { + $data = ProjectWbsSet::where('pid',$params['id'])->findOrEmpty(); + if(!$data->isEmpty()){ + self::setError('当前节点存在子节点,不能删除'); + return false; + } + return ProjectWbsSet::destroy($params['id']); + } + + + /** + * @notes 获取项目WBS设置详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public static function detail($params): array + { + $data = ProjectWbsSet::field('id,project_type_id,pid,wbs_code,name,work_standards,project_role_id,output_data,sort,weight')->findOrEmpty($params['id'])->toArray(); + $projectType = ProjectTypeSet::field('id,name')->where('id',$data['project_type_id'])->findOrEmpty(); + $projectRole = ProjectRoleSet::field('id,name')->where('id',$data['project_role_id'])->findOrEmpty(); + $projectWbs = ProjectWbsSet::field('wbs_code')->where('id',$data['pid'])->findOrEmpty(); + $data['project_type_name'] = $projectType->isEmpty() ? '' : $projectType->name; + $data['project_role_name'] = $projectRole->isEmpty() ? '' : $projectRole->name; + $data['sup_wbs_code']= $projectWbs->isEmpty() ? '' : $projectWbs->wbs_code; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectWbsSetValidate.php b/app/adminapi/validate/project/ProjectWbsSetValidate.php new file mode 100644 index 000000000..d48b972f6 --- /dev/null +++ b/app/adminapi/validate/project/ProjectWbsSetValidate.php @@ -0,0 +1,157 @@ + 'require|checkWbs', + 'project_type_id' => 'require|checkProjectType', + 'wbs_code' => 'require|unique:'.ProjectWbsSet::class, + 'name' => 'require|unique:'.ProjectWbsSet::class, + 'sort' => 'require|integer', + 'weight' => 'require|integer', + 'sup_wbs_code' => 'checkSupCode|different:wbs_code', + 'project_role_id' => 'integer|checkProjectRole', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'project_type_id.require' => '请选择项目类型', + 'wbs_code.require' => 'WBS编码不能为空', + 'wbs_code.unique' => 'WBS编码不能重复', + 'name.require' => '节点名称不能为空', + 'name.unique' => '节点名称不能重复', + 'sort.require' => '排序号不能为空', + 'sort.integer' => '排序号必须是整数', + 'weight.require' => '权重不能为空', + 'weight.integer' => '权重必须是整数', + 'sup_wbs_code' => '父级WBS编码不能与WBS编码相同', + 'project_role_id.integer' => '项目角色数据格式错误', + ]; + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_type_id' => '项目类型id', + 'wbs_code' => 'WBS编码', + 'name' => '节点名称', + 'sort' => '排序号', + 'weight' => '权重', + ]; + + + /** + * @notes 添加场景 + * @return ProjectWbsSetValidate + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectWbsSetValidate + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectWbsSetValidate + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectWbsSetValidate + * @author likeadmin + * @date 2023/12/13 15:09 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkProjectType($value): bool|string + { + $projectType = ProjectTypeSet::where('id',$value)->findOrEmpty(); + if($projectType->isEmpty()) { + return '项目类型不存在'; + } + return true; + } + + public function checkSupCode($value): bool|string + { + $projectWbs = ProjectWbsSet::where('wbs_code',$value)->findOrEmpty(); + if($projectWbs->isEmpty()){ + return '父级WBS编码错误'; + } + return true; + } + + public function checkProjectRole($value): bool|string + { + $projectRole = ProjectRoleSet::where('id',$value)->findOrEmpty(); + if($projectRole->isEmpty()) { + return '角色不存在'; + } + return true; + } + + public function checkWbs($value,$rule, $data): bool|string + { + $data = ProjectWbsSet::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '数据不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common.php b/app/common.php index 218c9c287..a55c959e9 100755 --- a/app/common.php +++ b/app/common.php @@ -312,3 +312,18 @@ function group_by($array, $key): array } return $result; } + +function buildTree($items, $parentField, $parentId = 0): array +{ + $tree = []; + foreach ($items as $item) { + if ($item[$parentField] == $parentId) { + $children = buildTree($items, $parentField, $item['id']); + if ($children) { + $item['children'] = $children; + } + $tree[] = $item; + } + } + return $tree; +} diff --git a/app/common/model/project/ProjectWbsSet.php b/app/common/model/project/ProjectWbsSet.php new file mode 100644 index 000000000..dd74b142e --- /dev/null +++ b/app/common/model/project/ProjectWbsSet.php @@ -0,0 +1,34 @@ +