diff --git a/.gitignore b/.gitignore index 977a572..81308fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea/ -logs/ \ No newline at end of file +logs/* \ No newline at end of file diff --git a/build_and_run.sh b/build_and_run.sh index 085f77c..f82185c 100644 --- a/build_and_run.sh +++ b/build_and_run.sh @@ -1,8 +1,11 @@ #!/bin/bash # 重新构建docker镜像 -sudo docker build -t staff-sync . +sudo docker build -t local-face-app . -sudo mkdir -p /home/digimeta/staff-sync +sudo mkdir -p /home/digimeta/local-face + +sudo cp -r ./config.json /home/digimeta/local-face/ # 运行生成的docker镜像 -sudo docker run --add-host='oa.dfwytech.net:10.1.31.231' -v /home/digimeta/staff-sync/logs:/app/logs -v /home/digimeta/staff-sync/config.json:/app/config.json --restart=always -p 48480:18080 --name staff-sync -d staff-sync -sudo tail -f -n 500 /home/digimeta/logs/web.log \ No newline at end of file +#sudo docker run --add-host='oa.dfwytech.net:10.1.31.231' -v /home/digimeta/local-face/logs:/app/logs -v /home/digimeta/local-face/config.json:/app/config.json --restart=always -p 48484:18080 --name local-face-app -d local-face-app +sudo docker run -v /home/digimeta/local-face/logs:/app/logs -v /home/digimeta/local-face/config.json:/app/config.json --restart=always -p 48484:18080 --name local-face-app -d local-face-app +sudo tail -f -n 500 /home/digimeta/local-face/logs/web.log \ No newline at end of file diff --git a/business/staff.go b/business/staff.go index d708e72..cc95d49 100644 --- a/business/staff.go +++ b/business/staff.go @@ -16,7 +16,6 @@ import ( "io" "mime/multipart" "net/http" - "os" "sort" "strconv" "strings" @@ -728,7 +727,7 @@ func extractFeature(data interface{}) (string, error) { } func LocalFetchStaffFaceFeature(base64 string) (string, string, error) { - url := common.ConfigData.LocalDetectUrl + url := "http://" + common.ConfigData.DevIp + common.ConfigData.LocalDetectUrl method := "POST" imgName := "static/faces/" + fmt.Sprintf("%d", time.Now().Unix()) + "test.jpg" @@ -820,67 +819,70 @@ func TimerHandle() { now := time.Now() // 将时间设置为23点59分59秒 t := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 55, 0, now.Location()) - common.Info(common.GenLogLine() + "--1,执行日志分割 START--") duration := t.Sub(now) isWithin10Seconds := duration > 0*time.Second && duration <= time.Duration(timeStep)*time.Second - fmt.Fprintln(os.Stdout, isWithin10Seconds) + common.Info(common.GenLogLine() + "--1,执行日志分割判断 是否开始切割:--" + strconv.FormatBool(isWithin10Seconds)) if isWithin10Seconds { common.Info(common.GenLogLine() + "--1.1执行RenameLogFile--") common.RenameLogFile() } - common.Info(common.GenLogLine() + "--1,执行日志分割 END--") - common.Info(common.GenLogLine() + "--2,数据同步 START--") + common.Info(common.GenLogLine() + "--1,执行日志分割判断 END--") - //获取接口数据 - staffs := Fetch() - cachedTime := common.GetCache("maxTime") + if common.ConfigData.Sync == 1 { + common.Info(common.GenLogLine() + "--2,数据同步 START--") - if len(staffs) == 0 { - common.Info(common.GenLogLine() + "数据为空") - } else { - //获取最新更新时间 - maxTime := GetNewestModified(staffs) - var t1 time.Time - var t2 time.Time - var t3 time.Time - if cachedTime == "" { - cachedTime = common.ReadFile("di.txt") - common.SetCacheWithExpire("maxTime", cachedTime, 0) - } - t1, _ = time.Parse("2006-01-02 15:04:05", cachedTime) - t2, _ = time.Parse("2006-01-02 15:04:05", maxTime) - if !t2.After(t1) { - common.Info(common.GenLogLine() + "--2.1, 数据已被同步") + //获取接口数据 + staffs := Fetch() + cachedTime := common.GetCache("maxTime") + + if len(staffs) == 0 { + common.Info(common.GenLogLine() + "数据为空") } else { - common.SetCacheWithExpire("maxTime", maxTime, 0) - - for _, staff := range staffs { - time.Sleep(1 * time.Second) // 暂停1秒 - t3, _ = time.Parse("2006-01-02 15:04:05", staff.Modified) - if t3.After(t1) { - staff.StaffBase64Img = FetchStaffImage(staff.Code) - common.Info(common.GenLogLine()+"----%v", "" == staff.StaffBase64Img) - str := HandleStaff(staff) - common.Info(common.GenLogLine()+"--2.2注册人员 姓名:%s 编号:%s 更新时间:%s--\n", staff.StaffName, staff.Code, staff.Modified) - //str := RegOnlineStaff(staff) - ss := "" - if str == nil { - ss = "保存成功" + //获取最新更新时间 + maxTime := GetNewestModified(staffs) + var t1 time.Time + var t2 time.Time + var t3 time.Time + if cachedTime == "" { + cachedTime = common.ReadFile("di.txt") + common.SetCacheWithExpire("maxTime", cachedTime, 0) + } + t1, _ = time.Parse("2006-01-02 15:04:05", cachedTime) + t2, _ = time.Parse("2006-01-02 15:04:05", maxTime) + if !t2.After(t1) { + common.Info(common.GenLogLine() + "--2.1, 数据已被同步") + } else { + common.SetCacheWithExpire("maxTime", maxTime, 0) + + for _, staff := range staffs { + time.Sleep(1 * time.Second) // 暂停1秒 + t3, _ = time.Parse("2006-01-02 15:04:05", staff.Modified) + if t3.After(t1) { + staff.StaffBase64Img = FetchStaffImage(staff.Code) + common.Info(common.GenLogLine()+"----%v", "" == staff.StaffBase64Img) + str := HandleStaff(staff) + common.Info(common.GenLogLine()+"--2.2注册人员 姓名:%s 编号:%s 更新时间:%s--\n", staff.StaffName, staff.Code, staff.Modified) + //str := RegOnlineStaff(staff) + ss := "" + if str == nil { + ss = "保存成功" + } else { + ss = str.Error() + } + fmt.Printf("注册人员:%v\n", ss) + common.Info(common.GenLogLine()+"--2.3注册人员:%v--\n", ss) } else { - ss = str.Error() + break } - fmt.Printf("注册人员:%v\n", ss) - common.Info(common.GenLogLine()+"--2.3注册人员:%v--\n", ss) - } else { - break } + common.WriteFile("di.txt", maxTime) + common.Info(common.GenLogLine()+"--2.4,数据同步,缓存数据maxID-- :%s", common.GetCache("maxTime")) } - common.WriteFile("di.txt", maxTime) - common.Info(common.GenLogLine()+"--2.4,数据同步,缓存数据maxID-- :%s", common.GetCache("maxTime")) } + common.Info(common.GenLogLine() + "--2,数据同步 END--") } - common.Info(common.GenLogLine() + "--2,数据同步 END--") + common.Info(common.GenLogLine() + "=====执行timerHandle结束=====") } } diff --git a/common/config.go b/common/config.go index f0e8baa..6e3bd0c 100644 --- a/common/config.go +++ b/common/config.go @@ -21,7 +21,9 @@ type Config struct { PushDataUrl string `json:"pushDataUrl"` LocalDetectUrl string `json:"localDetectUrl"` DevId string `json:"devId"` + DevIp string `json:"devIp"` Timer int `json:"timer"` + Sync int `json:"sync"` Mode string `json:"mode"` } @@ -54,6 +56,8 @@ func UpdateConfig(updateValues map[string]interface{}) string { config.Phone = value.(string) case "devId": config.DevId = value.(string) + case "devIp": + config.DevIp = value.(string) case "mode": config.Mode = value.(string) case "enterpriseName": @@ -82,6 +86,8 @@ func UpdateConfig(updateValues map[string]interface{}) string { config.StaffInfoUrl = value.(string) case "timer": config.Timer = int(value.(float64)) + case "sync": + config.Sync = int(value.(float64)) default: return "Unknown config key: " + key } diff --git a/config.json b/config.json index 3d46f13..9e315a6 100644 --- a/config.json +++ b/config.json @@ -1,19 +1,21 @@ { - "fetchTokenUrl": "http://127.0.0.1:8080/auth/deviceLogin", + "fetchTokenUrl": "http://172.17.0.1:8080/auth/deviceLogin", "phone": "18910801519", - "fetchDataUrl": "http://127.0.0.1:8080/system/staff/list", + "fetchDataUrl": "http://172.17.0.1:8080/system/staff/list", "fetchData2Url": "http://10.1.26.139/api/dizhiyuan/member/DZYAction", - "sendCodeUrl": "http://127.0.0.1:8080/system/sms/api/send-code", - "checkSendCodeUrl": "http://127.0.0.1:8080/system/staff/api/ableLogin", - "phoneLoginUrl": "http://127.0.0.1:8080/auth/phoneLogin", - "mgrLoginUrl": "http://127.0.0.1:8080/auth/mgr-login", - "validCodeUrl": "http://127.0.0.1:8080/system/staff/api/validCode", - "staffInfoUrl": "http://127.0.0.1:8080/system/staff/list", + "sendCodeUrl": "http://172.17.0.1:8080/system/sms/api/send-code", + "checkSendCodeUrl": "http://172.17.0.1:8080/system/staff/api/ableLogin", + "phoneLoginUrl": "http://172.17.0.1:8080/auth/phoneLogin", + "mgrLoginUrl": "http://172.17.0.1:8080/auth/mgr-login", + "validCodeUrl": "http://172.17.0.1:8080/system/staff/api/validCode", + "staffInfoUrl": "http://172.17.0.1:8080/system/staff/list", "enterpriseName": "演示机", "port": "18080", - "pushDataUrl": "http://127.0.0.1:8080/system/staff/api/new-staff", - "localDetectUrl": "http://192.168.10.32:8080/face/feature", + "pushDataUrl": "http://172.17.0.1:8080/system/staff/api/new-staff", + "localDetectUrl": "/face/feature", "devId": "442926c7610ed10b", + "devIp": "192.168.10.32", "timer": 90, + "sync": 0, "mode": "online" } \ No newline at end of file diff --git a/main.go b/main.go index e33e6ec..bf13e5b 100644 --- a/main.go +++ b/main.go @@ -73,6 +73,7 @@ func main() { router.LoadHTMLGlob("templates/*") router.GET("/", HomeHandler) router.GET("/reg", RegPageHandler) + router.GET("/config", ConfigPageHandler) router.GET("/info", InfoPageHandler) router.POST("/send_validation_code", SendCodeHandler) router.POST("/valid_code", ValidCodeHandler) @@ -83,7 +84,7 @@ func main() { router.GET("/register", RegisterPageHandler) router.POST("/register", RegisterHandler) router.POST("/pass", PassHandler) - router.POST("/update", UpdateConfigHandler) + router.POST("/updateConfig", UpdateConfigHandler) common.Info(common.GenLogLine()+"file content:%s", common.ReadFile("di.txt")) @@ -120,7 +121,7 @@ func UpdateConfigHandler(c *gin.Context) { //更新配置文件变量configData common.LoadConfig() - c.JSON(http.StatusOK, gin.H{"message": "Config updated successfully"}) + c.JSON(http.StatusOK, gin.H{"message": "配置更新成功"}) } func HomeHandler(c *gin.Context) { @@ -134,6 +135,13 @@ func RegPageHandler(c *gin.Context) { c.HTML(http.StatusOK, "reg.html", nil) } +func ConfigPageHandler(c *gin.Context) { + + c.HTML(http.StatusOK, "conf.html", gin.H{ + "config": common.ConfigData, + }) +} + func InfoPageHandler(c *gin.Context) { staffId := c.Query("staffId") res, err := business.StaffInfo(staffId) diff --git a/staffs.db b/staffs.db new file mode 100644 index 0000000..e99d6eb Binary files /dev/null and b/staffs.db differ diff --git a/templates/conf.html b/templates/conf.html new file mode 100644 index 0000000..74d5fbc --- /dev/null +++ b/templates/conf.html @@ -0,0 +1,193 @@ + + +
+ + +