From 4703c27264b8c356e44be068ee51235f0b7473d6 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Thu, 18 Jul 2019 14:41:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BF=A1=E6=81=AF=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vilson <545522390@qq.com> --- application/common/Model/ProjectReport.php | 110 ++++++++++++++++++ .../vendor/workerman/workerman.log | 0 application/project/controller/Index.php | 4 - application/project/controller/Project.php | 14 +++ data/2.8.0/2.8.0-2.8.1.sql | 14 +++ extend/controller/BasicApi.php | 2 +- 6 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 application/common/Model/ProjectReport.php delete mode 100644 application/common/Plugins/GateWayWorker/vendor/workerman/workerman.log create mode 100644 data/2.8.0/2.8.0-2.8.1.sql diff --git a/application/common/Model/ProjectReport.php b/application/common/Model/ProjectReport.php new file mode 100644 index 0000000..bcbf225 --- /dev/null +++ b/application/common/Model/ProjectReport.php @@ -0,0 +1,110 @@ + 0])->select()->toArray(); + if ($taskList) { + $projectList = []; + foreach ($taskList as $task) { + $item = null; + $projectCode = $task['project_code']; + if (!isset($projectList[$projectCode])) { + $projectList[$projectCode] = []; + } + @$projectList[$projectCode]['task']++; + !$task['done'] && @$projectList[$projectCode]['task:undone']++; + } + if ($projectList) { + foreach ($projectList as $key => $project) { + self::setData($key, $day, 'content', $project, true); + } + } + } + return true; + } + + /** + * 插入统计数据 + * @param string $projectCode 项目编号 + * @param string $date 日期 [2019-07-10] + * @param string $key 键 + * @param string|array $values 值,值为null则移除该键值对 + * @param bool $isContent 是否存储多个content的键值对 + * @param bool $replace 是否覆盖content + * @return bool + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function setData($projectCode, $date, $key, $values, $isContent = false, $replace = false) + { + if (!DateService::checkDateIsValid($date, ['Y-m-d'])) { + return error(1, '日期格式不正确'); + } + $projet = Project::where(['code' => $projectCode])->field('id')->find(); + if (!$projet) { + return error(2, '项目不存在'); + } + $saveData = new \stdClass(); + $where = ['project_code' => $projectCode, 'date' => $date]; + $report = self::where($where)->find(); + if ($report) { + $saveData->content = $report->content; + } else { + $report = new self(); + $saveData->project_code = $projectCode; + $saveData->date = $date; + $saveData->create_time = nowTime(); + $saveData->content = new \stdClass(); + } + $saveData->update_time = nowTime(); + //值为null则移除该键值对 + if ($values === null) { + unset($saveData->content->$key); + return $report->save($saveData); + } + if ($isContent) { + if ($replace) { + //直接替换content + $saveData->content = $values; + } else { + //遍历键值对,赋值到conetnt + if (!is_array($values)) { + $saveData->content->$key = $values; + } else { + foreach ($values as $keyItme => $value) { + //值为null则移除该键值对 + if ($value === null) { + unset($saveData->content->$keyItme); + continue; + } + $saveData->content->$keyItme = $value; + } + } + } + } else { + //单个键值对 + $saveData->content->$key = $values; + } + return $report->save($saveData); + } +} diff --git a/application/common/Plugins/GateWayWorker/vendor/workerman/workerman.log b/application/common/Plugins/GateWayWorker/vendor/workerman/workerman.log deleted file mode 100644 index e69de29..0000000 diff --git a/application/project/controller/Index.php b/application/project/controller/Index.php index afa22a6..f18477d 100644 --- a/application/project/controller/Index.php +++ b/application/project/controller/Index.php @@ -6,20 +6,16 @@ use app\common\Model\CommonModel; use app\common\Model\Department; use app\common\Model\Member; use app\common\Model\MemberAccount; -use app\common\Model\Notify; -use app\common\Model\SourceLink; use app\common\Model\SystemConfig; use controller\BasicApi; use Exception; use OSS\Core\OssException; -use service\FileService; use service\NodeService; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; use think\Exception\DbException; use think\exception\PDOException; use think\facade\Request; -use think\File; /** * @title 项目管理 diff --git a/application/project/controller/Project.php b/application/project/controller/Project.php index 048746a..56e3d38 100644 --- a/application/project/controller/Project.php +++ b/application/project/controller/Project.php @@ -9,6 +9,7 @@ use app\common\Model\Notify; use app\common\Model\ProjectCollection; use app\common\Model\ProjectLog; use app\common\Model\ProjectMember; +use app\common\Model\ProjectReport; use app\common\Model\SystemConfig; use controller\BasicApi; use OSS\Core\OssException; @@ -287,6 +288,19 @@ class Project extends BasicApi $this->success('', $list); } + /** + * 项目情况统计 + */ + public function _setDayilyProejctReport() + { + logRecord(nowTime(), 'setDayilyProejctReportBegin'); + debug('begin'); + $result = ProjectReport::setDayilyProejctReport(); + debug('end'); + logRecord(debug('begin','end') * 1000 . 'ms', 'setDayilyProejctReportSuccess'); + echo 'success_at ' . nowTime(); + } + /** * 概览报表 * @throws DataNotFoundException diff --git a/data/2.8.0/2.8.0-2.8.1.sql b/data/2.8.0/2.8.0-2.8.1.sql new file mode 100644 index 0000000..4e1d9f8 --- /dev/null +++ b/data/2.8.0/2.8.0-2.8.1.sql @@ -0,0 +1,14 @@ +SET FOREIGN_KEY_CHECKS=0; + +CREATE TABLE `pearProject`.`pear_project_report` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `project_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '项目编号', + `date` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '日期', + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL, + `create_time` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + `update_time` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `union`(`project_code`, `date`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '项目报表统计表' ROW_FORMAT = Compact; + +SET FOREIGN_KEY_CHECKS=1; diff --git a/extend/controller/BasicApi.php b/extend/controller/BasicApi.php index 5867f11..84277c4 100644 --- a/extend/controller/BasicApi.php +++ b/extend/controller/BasicApi.php @@ -73,7 +73,7 @@ class BasicApi * 返回资源不存在 * @param integer $code 返回代码 */ - protected function notFound($code = 404) + protected function notFound($code = 4041) { ToolsService::error('', [], $code); }