renjiaojiao 4 bulan lalu
melakukan
7382287209
11 mengubah file dengan 686 tambahan dan 0 penghapusan
  1. 135 0
      admin.go
  2. TEMPAT SAMPAH
      bindresume_linux
  3. 6 0
      config.yaml
  4. 64 0
      config/db.go
  5. 119 0
      front.go
  6. 44 0
      go.mod
  7. 106 0
      go.sum
  8. 66 0
      main.go
  9. 100 0
      tpl/admin_list.html
  10. 29 0
      tpl/page1.html
  11. 17 0
      tpl/page2.html

+ 135 - 0
admin.go

@@ -0,0 +1,135 @@
+package main
+
+import (
+	"database/sql"
+	"fmt"
+
+	. "bindresume/config"
+	"net/http"
+	"strconv"
+	"strings"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	_ "github.com/go-sql-driver/mysql"
+)
+
+// 后台简历搜索页,前端页面拆分到 templates/admin_search.html
+func adminSearchPageHandler(c *gin.Context) {
+	c.HTML(http.StatusOK, "admin_search.html", nil)
+}
+
+// 后台绑定操作:为待绑定人员绑定简历
+func adminBindHandler(c *gin.Context) {
+	resumeID := strings.TrimSpace(c.PostForm("resume_id"))
+	if resumeID == "" {
+		resumeID = c.Query("resume_id")
+	}
+	if resumeID == "" {
+		c.JSON(http.StatusBadRequest, gin.H{"error": "简历ID不能为空"})
+		return
+	}
+
+	// 查找最早的一条待绑定记录
+	row := Db.QueryRow("SELECT id, uuid FROM bindings WHERE status = 0 ORDER BY created_at ASC LIMIT 1")
+	var id int
+	var waitingUUID string
+	err := row.Scan(&id, &waitingUUID)
+	if err != nil {
+		c.JSON(http.StatusOK, gin.H{"message": "没有待绑定的人员"})
+		return
+	}
+
+	now := time.Now()
+	_, err = Db.Exec("UPDATE bindings SET resume_id = ?, status = ?, bound_at = ?, operator = ? WHERE id = ?",
+		resumeID, 1, now, "admin", id)
+	if err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"error": "绑定失败"})
+		return
+	}
+	c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("成功绑定 uuid: %s 与简历ID: %s", waitingUUID, resumeID)})
+}
+
+// 后台绑定列表页:显示所有绑定记录
+// 后台绑定列表页:显示所有绑定记录(分页查询)
+func adminListHandler(c *gin.Context) {
+	// 获取页码参数
+	pageStr := c.DefaultQuery("page", "1")
+	page, err := strconv.Atoi(pageStr)
+	if err != nil || page < 1 {
+		page = 1
+	}
+	pageSize := 10
+	offset := (page - 1) * pageSize
+
+	// 查询总记录数
+	var totalCount int
+	row := Db.QueryRow("SELECT COUNT(*) FROM bindings")
+	if err := row.Scan(&totalCount); err != nil {
+		c.String(http.StatusInternalServerError, "查询记录总数失败")
+		return
+	}
+
+	// 查询当前页的记录
+	rows, err := Db.Query("SELECT id, uuid, resume_id, status, created_at, bound_at, operator FROM bindings ORDER BY id DESC LIMIT ? OFFSET ?", pageSize, offset)
+	if err != nil {
+		c.String(http.StatusInternalServerError, "查询失败")
+		return
+	}
+	defer rows.Close()
+
+	var bindings []map[string]interface{}
+	for rows.Next() {
+		var id, status int
+		var uuidVal, resumeID, operator string
+		var createdAt, boundAt sql.NullTime
+		if err := rows.Scan(&id, &uuidVal, &resumeID, &status, &createdAt, &boundAt, &operator); err != nil {
+			continue
+		}
+		b := map[string]interface{}{
+			"ID":       id,
+			"UUID":     uuidVal,
+			"ResumeID": resumeID,
+			"Status":   status,
+			"Operator": operator,
+		}
+		if createdAt.Valid {
+			b["CreatedAt"] = createdAt.Time.Format("2006-01-02 15:04:05")
+		} else {
+			b["CreatedAt"] = ""
+		}
+		if boundAt.Valid {
+			b["BoundAt"] = boundAt.Time.Format("2006-01-02 15:04:05")
+		} else {
+			b["BoundAt"] = ""
+		}
+		bindings = append(bindings, b)
+	}
+
+	// 计算总页数
+	totalPage := (totalCount + pageSize - 1) / pageSize
+
+	// 渲染模板,传递分页信息
+	c.HTML(http.StatusOK, "admin_list.html", gin.H{
+		"Bindings":  bindings,
+		"CurrPage":  page,
+		"TotalPage": totalPage,
+	})
+}
+
+// 后台解绑操作,删除绑定记录
+func adminUnbindHandler(c *gin.Context) {
+	idStr := c.PostForm("id")
+	resume_id := c.PostForm("resume_id")
+	id, err := strconv.Atoi(idStr)
+	if err != nil {
+		c.JSON(http.StatusBadRequest, gin.H{"error": "ID错误"})
+		return
+	}
+	_, err = Db.Exec("UPDATE bindings SET status = 2 WHERE id = ? and resume_id = ? ", id, resume_id)
+	if err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"error": "解绑失败"})
+		return
+	}
+	c.JSON(http.StatusOK, gin.H{"message": "解绑成功"})
+}

TEMPAT SAMPAH
bindresume_linux


+ 6 - 0
config.yaml

@@ -0,0 +1,6 @@
+port: :8381
+database:
+  host: 172.20.45.129:4000
+  user: jianyu
+  password: Topnet123
+  dbname: jy_resume

+ 64 - 0
config/db.go

@@ -0,0 +1,64 @@
+package config
+
+import (
+	"database/sql"
+	"fmt"
+	"gopkg.in/yaml.v3"
+	"io/ioutil"
+	"log"
+)
+
+var SysConfig Config
+var Db *sql.DB
+
+//var mysqlDB *mysql.Mysql
+
+type Config struct {
+	Port     string         `yaml:"port"`
+	Database DatabaseConfig `yaml:"database"`
+}
+
+type DatabaseConfig struct {
+	Host     string `yaml:"host"`
+	Port     int    `yaml:"port"`
+	User     string `yaml:"user"`
+	Password string `yaml:"password"`
+	DBName   string `yaml:"dbname"`
+}
+
+func LoadConfig() {
+	data, err := ioutil.ReadFile("./config.yaml")
+	if err != nil {
+		log.Println("read config err:", err)
+	}
+	//config := &Config{}
+	err = yaml.Unmarshal(data, &SysConfig)
+	if err != nil {
+		log.Println("read config err:", err)
+	}
+}
+
+// 初始化连接 MySQL 数据库并创建绑定表(如果不存在)
+func InitDB() {
+	dbCon := fmt.Sprintf("%s:%s@tcp(%s)/jy_resume?charset=utf8&parseTime=True&loc=Local", SysConfig.Database.User, SysConfig.Database.Password, SysConfig.Database.Host)
+	var err error
+	Db, err = sql.Open("mysql", dbCon)
+	if err != nil {
+		log.Fatal("数据库连接错误:", err)
+	}
+	// 测试数据库连接
+	if err = Db.Ping(); err != nil {
+		log.Fatal("数据库 ping 错误:", err)
+	}
+	//defer Db.Close()
+
+	/*mysqlDB = &mysql.Mysql{
+		Address:      SysConfig.Database.Host,
+		UserName:     SysConfig.Database.User,
+		PassWord:     SysConfig.Database.Password,
+		DBName:       SysConfig.Database.DBName,
+		MaxOpenConns: 5,
+		MaxIdleConns: 5,
+	}
+	mysqlDB.Init()*/
+}

+ 119 - 0
front.go

@@ -0,0 +1,119 @@
+package main
+
+import (
+	. "bindresume/config"
+	"fmt"
+	"github.com/google/uuid"
+	"log"
+	"net/http"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	_ "github.com/go-sql-driver/mysql"
+)
+
+// 页面1:扫码绑定页面
+func ScanCodeHandler(c *gin.Context) {
+	userUUID, err := c.Cookie("uuid")
+	if err != nil || userUUID == "" {
+		// 如果 Cookie 中没有 UUID,则生成新 uuid,过期时间 10 分钟
+		userUUID = uuid.New().String()
+		c.SetCookie("uuid", userUUID, 600, "/", "", false, true)
+		if err = InsertCookie(userUUID); err != nil {
+			log.Println("cookie写入数据库错误:", err)
+		}
+	} else {
+		var (
+			id         int
+			resumeId   int
+			bindStatus int
+		)
+		//查询简历绑定状态,如果是1 跳转至简历详情页面,2 解绑状态,删除uuid,重新生成重新绑定
+		row := Db.QueryRow("select id,resume_id,status from bindings where uuid = ? ", userUUID)
+		if err = row.Scan(id, resumeId, bindStatus); err != nil {
+			log.Println("获取数据错误:", err)
+		}
+		if bindStatus == 2 { //解绑
+			userUUID = uuid.New().String()
+			c.SetCookie("uuid", userUUID, 600, "/", "", false, true)
+			if err = InsertCookie(userUUID); err != nil {
+				log.Println("cookie写入数据库错误:", err)
+			}
+		}
+	}
+
+	// 渲染模板,模板文件位于 templates/page1.html,此处传递 UUID 参数
+	c.HTML(http.StatusOK, "page1.html", gin.H{
+		"UUID": userUUID,
+	})
+}
+
+// SSE 接口,用于推送绑定状态
+func eventsHandler(c *gin.Context) {
+	userUUID := c.Query("uuid")
+	if userUUID == "" {
+		c.String(http.StatusBadRequest, "缺少 uuid 参数")
+		return
+	}
+
+	// 设置 SSE 响应头
+	c.Writer.Header().Set("Content-Type", "text/event-stream")
+	c.Writer.Header().Set("Cache-Control", "no-cache")
+	c.Writer.Header().Set("Connection", "keep-alive")
+	c.Writer.Flush()
+
+	ticker := time.NewTicker(2 * time.Second)
+	timeout := time.After(10 * time.Minute)
+	defer ticker.Stop()
+
+	for {
+		select {
+		case <-ticker.C:
+			_, resumeID, status, err := getBindingByUUID(userUUID)
+			if err != nil {
+				continue
+			}
+			if status == 1 {
+				data := fmt.Sprintf("{\"resume_id\":\"%s\"}", resumeID)
+				fmt.Fprintf(c.Writer, "event: bind\ndata: %s\n\n", data)
+				c.Writer.Flush()
+				return
+			}
+		case <-timeout:
+			return
+		case <-c.Request.Context().Done():
+			return
+		}
+	}
+}
+
+// 页面2:简历详情页面
+func page2Handler(c *gin.Context) {
+	userUUID := c.Query("uuid")
+	resumeID := c.Query("resume_id")
+	if userUUID == "" || resumeID == "" {
+		c.String(http.StatusBadRequest, "缺少必要参数")
+		return
+	}
+
+	_, dbResumeID, status, err := getBindingByUUID(userUUID)
+	if err != nil || status != 1 || dbResumeID != resumeID {
+		c.String(http.StatusForbidden, "绑定状态不正确")
+		return
+	}
+	// 刷新 Cookie,设置有效期为 1 天
+	c.SetCookie("uuid", userUUID, 86400, "/", "", false, true)
+	c.HTML(http.StatusOK, "page2.html", gin.H{
+		"UUID":     userUUID,
+		"ResumeID": resumeID,
+	})
+}
+
+func InsertCookie(userUUID string) error {
+	// 插入待绑定记录到数据库
+	_, err := Db.Exec("INSERT INTO bindings(uuid, created_at) VALUES(?, ?)", userUUID, time.Now())
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 44 - 0
go.mod

@@ -0,0 +1,44 @@
+module bindresume
+
+go 1.22
+
+require (
+	app.yhyue.com/moapp/jybase v0.0.0-20250228070014-019656d96e4c
+	github.com/gin-gonic/gin v1.10.0
+	github.com/go-sql-driver/mysql v1.9.0
+	github.com/google/uuid v1.6.0
+)
+
+require (
+	filippo.io/edwards25519 v1.1.0 // indirect
+	github.com/bytedance/sonic v1.11.6 // indirect
+	github.com/bytedance/sonic/loader v0.1.1 // indirect
+	github.com/cloudwego/base64x v0.1.4 // indirect
+	github.com/cloudwego/iasm v0.2.0 // indirect
+	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
+	github.com/gin-contrib/sse v0.1.0 // indirect
+	github.com/go-playground/locales v0.14.1 // indirect
+	github.com/go-playground/universal-translator v0.18.1 // indirect
+	github.com/go-playground/validator/v10 v10.20.0 // indirect
+	github.com/goccy/go-json v0.10.2 // indirect
+	github.com/jinzhu/inflection v1.0.0 // indirect
+	github.com/jinzhu/now v1.1.1 // indirect
+	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
+	github.com/leodido/go-urn v1.4.0 // indirect
+	github.com/mattn/go-isatty v0.0.20 // indirect
+	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+	github.com/modern-go/reflect2 v1.0.2 // indirect
+	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
+	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
+	github.com/ugorji/go/codec v1.2.12 // indirect
+	golang.org/x/arch v0.8.0 // indirect
+	golang.org/x/crypto v0.23.0 // indirect
+	golang.org/x/net v0.25.0 // indirect
+	golang.org/x/sys v0.20.0 // indirect
+	golang.org/x/text v0.22.0 // indirect
+	google.golang.org/protobuf v1.34.1 // indirect
+	gopkg.in/yaml.v3 v3.0.1 // indirect
+	gorm.io/driver/mysql v1.0.5 // indirect
+	gorm.io/gorm v1.21.3 // indirect
+)

+ 106 - 0
go.sum

@@ -0,0 +1,106 @@
+app.yhyue.com/moapp/jybase v0.0.0-20250228070014-019656d96e4c h1:oEl/0tbFg1nR5FWATXqpw1ks49Q6FHF5W2kM/OMauvQ=
+app.yhyue.com/moapp/jybase v0.0.0-20250228070014-019656d96e4c/go.mod h1:/HT/UZ4dKuUKAQqqKrzBBfIZ4vD56DPV4u2QyfH+kbU=
+filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
+filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
+github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
+github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
+github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
+github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
+github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
+github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
+github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
+github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
+github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
+github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
+github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
+github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
+github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
+github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
+github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
+github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
+github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
+github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
+github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
+github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
+github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-sql-driver/mysql v1.9.0 h1:Y0zIbQXhQKmQgTp44Y1dp3wTXcn804QoTptLZT1vtvo=
+github.com/go-sql-driver/mysql v1.9.0/go.mod h1:pDetrLJeA3oMujJuvXc8RJoasr589B6A9fwzD3QMrqw=
+github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
+github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
+github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
+github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
+github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
+github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
+github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
+github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
+github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
+github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
+github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
+github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
+github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
+github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
+github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
+github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
+github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
+github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
+golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
+golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
+golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
+golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
+golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
+golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
+golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
+golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
+golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
+golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
+google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gorm.io/driver/mysql v1.0.5 h1:WAAmvLK2rG0tCOqrf5XcLi2QUwugd4rcVJ/W3aoon9o=
+gorm.io/driver/mysql v1.0.5/go.mod h1:N1OIhHAIhx5SunkMGqWbGFVeh4yTNWKmMo1GOAsohLI=
+gorm.io/gorm v1.21.3 h1:qDFi55ZOsjZTwk5eN+uhAmHi8GysJ/qCTichM/yO7ME=
+gorm.io/gorm v1.21.3/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
+nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
+rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

+ 66 - 0
main.go

@@ -0,0 +1,66 @@
+package main
+
+import (
+	"html/template"
+	"log"
+
+	. "bindresume/config"
+	"github.com/gin-gonic/gin"
+	_ "github.com/go-sql-driver/mysql"
+)
+
+// 根据 uuid 查询绑定记录
+func getBindingByUUID(uuidStr string) (id int, resumeID string, status int, err error) {
+	row := Db.QueryRow("SELECT id, resume_id, status FROM bindings WHERE uuid = ?", uuidStr)
+	err = row.Scan(&id, &resumeID, &status)
+	return
+}
+
+func main() {
+	LoadConfig()
+	InitDB()
+
+	router := gin.Default()
+
+	// 注册自定义模板函数
+	router.SetFuncMap(template.FuncMap{
+		"dec": dec,
+		"inc": inc,
+		"seq": seq,
+	})
+
+	// 加载模板文件(templates目录下所有模板)
+	router.LoadHTMLGlob("tpl/*")
+	// 如有需要,可提供静态文件服务,例如 JS 与 CSS 资源
+	router.Static("/static", "./static")
+
+	// 前台页面路由
+	router.GET("/resume/scanCode", ScanCodeHandler)
+	//router.GET("/resume/page2", page2Handler)
+	router.GET("/resume/events", eventsHandler)
+
+	// 后台管理页面的路由
+	//router.GET("/admin/search", adminSearchPageHandler)
+	//router.POST("/admin/bind", adminBindHandler)
+	//router.GET("/admin/list", adminListHandler)
+	//router.POST("/admin/unbind", adminUnbindHandler)
+
+	log.Println("服务器启动在11 ", SysConfig.Port)
+	router.Run(SysConfig.Port)
+}
+
+func dec(i int) int {
+	return i - 1
+}
+
+func inc(i int) int {
+	return i + 1
+}
+
+func seq(start, end int) []int {
+	s := make([]int, 0, end-start+1)
+	for i := start; i <= end; i++ {
+		s = append(s, i)
+	}
+	return s
+}

+ 100 - 0
tpl/admin_list.html

@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+  <meta charset="UTF-8">
+  <title>绑定列表</title>
+  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
+</head>
+<body class="p-3">
+  <div class="container">
+    <h1>绑定列表</h1>
+    <table class="table table-bordered">
+      <thead>
+        <tr>
+          <th>ID</th>
+          <th>UUID</th>
+          <th>简历ID</th>
+          <th>状态</th>
+          <th>创建时间</th>
+          <th>绑定时间</th>
+          <th>操作人</th>
+          <th>操作</th>
+        </tr>
+      </thead>
+      <tbody>
+        {{range .Bindings}}
+        <tr>
+          <td>{{.ID}}</td>
+          <td>{{.UUID}}</td>
+          <td>{{.ResumeID}}</td>
+          <td>{{.Status}}</td>
+          <td>{{.CreatedAt}}</td>
+          <td>{{.BoundAt}}</td>
+          <td>{{.Operator}}</td>
+          <td>
+            <form class="unbindForm" method="post" action="/admin/unbind">
+              <input type="hidden" name="id" value="{{.ID}}">
+               <input type="hidden" name="resume_id" value="{{.ResumeID}}">
+              <button type="submit" class="btn btn-danger btn-sm">解绑</button>
+            </form>
+          </td>
+        </tr>
+        {{end}}
+      </tbody>
+    </table>
+
+    <!-- 分页导航 start -->
+    <nav aria-label="Page navigation">
+      <ul class="pagination">
+        <!-- 上一页 -->
+        <li class="page-item {{if eq .CurrPage 1}}disabled{{end}}">
+          <a class="page-link" href="/admin/list?page={{dec .CurrPage}}" aria-label="Previous">
+            <span aria-hidden="true">&laquo;</span>
+          </a>
+        </li>
+        {{/* 使用自定义模板函数 dec 和 inc 来计算当前页的前后页码 */}}
+        {{range $i := seq 1 .TotalPage}}
+        <li class="page-item {{if eq $.CurrPage $i}}active{{end}}">
+          <a class="page-link" href="/admin/list?page={{$i}}">{{$i}}</a>
+        </li>
+        {{end}}
+        <!-- 下一页 -->
+        <li class="page-item {{if eq .CurrPage .TotalPage}}disabled{{end}}">
+          <a class="page-link" href="/admin/list?page={{inc .CurrPage}}" aria-label="Next">
+            <span aria-hidden="true">&raquo;</span>
+          </a>
+        </li>
+      </ul>
+    </nav>
+    <!-- 分页导航 end -->
+
+    <a href="/admin/search" class="btn btn-secondary">返回搜索页</a>
+  </div>
+  <script>
+    document.querySelectorAll('.unbindForm').forEach(form => {
+      form.addEventListener('submit', function(e) {
+        e.preventDefault();
+        if(confirm("确定解绑吗?")) {
+          var formData = new FormData(this);
+          fetch("/admin/unbind", {
+            method: "POST",
+            body: formData
+          })
+          .then(response => response.json())
+          .then(data => {
+            if(data.error) {
+              alert(data.error);
+            } else {
+              alert(data.message);
+              location.reload();
+            }
+          })
+          .catch(err => {
+            console.error(err);
+          });
+        }
+      });
+    });
+  </script>
+</body>
+</html>

+ 29 - 0
tpl/page1.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+  <meta charset="UTF-8">
+  <title>扫码绑定简历 - 页面1</title>
+  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
+</head>
+<body class="p-3">
+  <div class="container">
+    <h1>扫码绑定简历</h1>
+    <p>请使用手机扫描二维码后进行绑定,等待绑定结果……</p>
+    <!-- 显示用户的 UUID -->
+    <div class="alert alert-info">您的标识: <strong>{{.UUID}}</strong></div>
+  </div>
+  <script>
+    var uuid = "{{.UUID}}";
+    // 建立 SSE 连接,监听后端绑定事件
+    var source = new EventSource("/events?uuid=" + encodeURIComponent(uuid));
+    source.addEventListener('bind', function(e) {
+        var data = JSON.parse(e.data);
+        // 当绑定后自动跳转到页面2,将 uuid 和 resume_id 作为参数传递
+        window.location.href = "/page2?uuid=" + encodeURIComponent(uuid) + "&resume_id=" + encodeURIComponent(data.resume_id);
+    }, false);
+    source.onerror = function(e) {
+        console.error("SSE error", e);
+    };
+  </script>
+</body>
+</html>

+ 17 - 0
tpl/page2.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+  <meta charset="UTF-8">
+  <title>简历详情 - 页面2</title>
+  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
+</head>
+<body class="p-3">
+  <div class="container">
+    <h1>简历详情</h1>
+    <div class="alert alert-success">
+      <p>UUID: <strong>{{.UUID}}</strong></p>
+      <p>简历ID: <strong>{{.ResumeID}}</strong></p>
+    </div>
+  </div>
+</body>
+</html>