From 1b411edf5958d283f9ab940388a9bfe3c2eec100 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 22 May 2025 18:07:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E6=B2=9F?= =?UTF-8?q?=E9=80=9A=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20CommunicationRecords=20=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E5=92=8C=20CommunicationRecordsService=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB-=20=E5=AE=9E=E7=8E=B0=E6=B2=9F=E9=80=9A=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E5=92=8C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91=20-=20=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=96=87=E4=BB=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B2=9F=E9=80=9A=E8=AE=B0=E5=BD=95=E7=9B=B8=E5=85=B3=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/CommunicationRecords.php | 49 ++++++++++ niucloud/app/api/route/route.php | 4 + .../CommunicationRecordsService.php | 89 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 niucloud/app/api/controller/apiController/CommunicationRecords.php create mode 100644 niucloud/app/service/api/apiService/CommunicationRecordsService.php diff --git a/niucloud/app/api/controller/apiController/CommunicationRecords.php b/niucloud/app/api/controller/apiController/CommunicationRecords.php new file mode 100644 index 00000000..4814a2e3 --- /dev/null +++ b/niucloud/app/api/controller/apiController/CommunicationRecords.php @@ -0,0 +1,49 @@ + $request->param('staff_id', ''),// + 'resource_id' => $request->param('resource_id', ''),// + 'resource_type' => $request->param('resource_type', ''),//资源类型(如设备、文件、系统等) + 'communication_type' => $request->param('communication_type', ''),// + 'communication_result' => $request->param('communication_result', ''),//沟通结果: success-成功, failure-失败, pending-待定 + 'communication_time' => $request->param('communication_time', $date),//沟通时间 + 'remarks' => $request->param('remarks', ''),//备注 + 'tag' => $request->param('tag', null),//标签:|默认null high-高, medium-中, low-低 + ]; + + $res = (new CommunicationRecordsService())->add($data); + if(!$res['code']){ + return fail('操作失败'); + } + return success('操作成功'); + } +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index a73e32ed..ec249eac 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -226,6 +226,10 @@ Route::group(function () { Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign'); + //沟通记录-添加 + Route::post('communicationRecords/add', 'apiController.CommunicationRecords/add'); + + diff --git a/niucloud/app/service/api/apiService/CommunicationRecordsService.php b/niucloud/app/service/api/apiService/CommunicationRecordsService.php new file mode 100644 index 00000000..a0f2986c --- /dev/null +++ b/niucloud/app/service/api/apiService/CommunicationRecordsService.php @@ -0,0 +1,89 @@ +model = (new CommunicationRecords()); + } + + //添加沟通记录 + public function add(array $data) + { + $model = $this->model; + $add = $model->create($data);//员工信息 + if ($add) { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } + return $res; + } + + /** + * 对比新旧数据改变 + * @param array $old_data 旧数据 + * @param array $new_data 新数据 + * @param array $ignoreFields 忽略验证的字段|默认[] + * @return array + */ + public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at']) + { + $changedFields = [];//改了那些字段 + $oldChanges = [];//数据修改前的样子 + $newChanges = [];//数据修改后的样子 + + foreach ($new_data as $key => $value) { + // 如果字段在忽略列表中,则跳过 + if (in_array($key, $ignoreFields)) { + continue; + } + + if (!isset($old_data[$key]) || $old_data[$key] != $value) { + $changedFields[] = $key; + $oldChanges[$key] = $old_data[$key] ?? null; + $newChanges[$key] = $value; + } + } + + return [ + 'changed_fields' => $changedFields, + 'old_values' => $oldChanges, + 'new_values' => $newChanges, + + 'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE), + 'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE), + 'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE) + ]; + } + +}