# click **Repository Path**: easy_code/click-in ## Basic Information - **Project Name**: click - **Description**: 日历打卡项目,go+html - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-29 - **Last Updated**: 2026-02-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 打卡系统 API 基于 Gin 框架和 MySQL 数据库的打卡系统,支持上班打卡、下班打卡以及按月份查询打卡记录的功能。 ## 功能特性 - 上班打卡 (Clock In) - 下班打卡 (Clock Out) - 按月份查询打卡记录 - 统一的错误处理和响应格式 ## 技术栈 - Go 语言 - Gin Web 框架 - MySQL 数据库 - GORM ORM 框架 ## 部署 ```bash go mod tidy && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go ``` ## 安装步骤 1. 克隆项目: ```bash git clone cd click-api ``` 2. 安装依赖: ```bash go mod tidy ``` 3. 配置数据库: - 复制 `.env.example` 文件为 `.env` 并根据实际情况修改数据库配置 ```bash cp .env.example .env ``` 4. 运行应用: ```bash go run main.go ``` ## API 接口 ### 1. 上班打卡 - **接口地址**:`POST /clock-in` - **请求参数**: - `user_id` (int, 必填) - 用户ID - **响应示例**: ```json { "code": 200, "data": { "id": 1, "user_id": 1, "date": "2023-10-10T09:00:00Z", "check_in": "2023-10-10T09:00:00Z", "check_out": "0001-01-01T00:00:00Z" }, "msg": "success" } ``` ### 2. 下班打卡 - **接口地址**:`POST /clock-out` - **请求参数**: - `user_id` (int, 必填) - 用户ID - **响应示例**: ```json { "code": 200, "data": { "id": 1, "user_id": 1, "date": "2023-10-10T18:00:00Z", "check_in": "2023-10-10T09:00:00Z", "check_out": "2023-10-10T18:00:00Z" }, "msg": "success" } ``` ### 3. 按月份查询打卡记录 - **接口地址**:`GET /attendance` - **请求参数**: - `user_id` (int, 必填) - 用户ID - `month` (string, 必填) - 月份,格式:YYYY-MM - **响应示例**: ```json { "code": 200, "data": [ { "id": 1, "user_id": 1, "date": "2023-10-10T00:00:00Z", "check_in": "2023-10-10T09:00:00Z", "check_out": "2023-10-10T18:00:00Z" } ], "msg": "success" } ``` ## 数据库表结构 ### users 表 | 字段名 | 类型 | 描述 | |--------|------|------| | id | INT | 主键,自增 | | username | VARCHAR(255) | 用户名,唯一 | | name | VARCHAR(255) | 用户姓名 | | created_at | TIMESTAMP | 创建时间 | | updated_at | TIMESTAMP | 更新时间 | | deleted_at | TIMESTAMP | 删除时间 | ### attendance 表 | 字段名 | 类型 | 描述 | |--------|------|------| | id | INT | 主键,自增 | | user_id | INT | 关联用户ID | | date | DATE | 打卡日期 | | check_in | TIMESTAMP | 上班打卡时间 | | check_out | TIMESTAMP | 下班打卡时间 | | created_at | TIMESTAMP | 创建时间 | | updated_at | TIMESTAMP | 更新时间 | ## 使用示例 ### 上班打卡 ```bash curl -X POST http://localhost:8080/clock-in \ -d "user_id=1" ``` ### 下班打卡 ```bash curl -X POST http://localhost:8080/clock-out \ -d "user_id=1" ``` ### 查询月度打卡记录 ```bash curl -X GET "http://localhost:8080/attendance?user_id=1&month=2023-10" ``` ## 项目结构 ``` click-api/ ├── main.go # 主程序入口 ├── go.mod # Go 模块管理 ├── go.sum # 依赖校验 ├── config/ # 配置文件 │ └── config.go # 配置加载 ├── models/ # 数据模型 │ └── attendance.go # 用户和打卡记录模型 ├── handlers/ # 控制器 │ └── attendance.go # 打卡相关处理函数 ├── database/ # 数据库操作 │ └── db.go # 数据库连接 ├── utils/ # 工具函数 │ └── response.go # 统一响应格式 ├── .env.example # 环境变量示例 └── test_api.go # API 测试脚本 ```