Browse Source

添加配置页面,整理配置

main
yk 1 year ago
parent
commit
82a5aa4222
11 changed files with 309 additions and 77 deletions
  1. +1
    -1
      .gitignore
  2. +7
    -4
      build_and_run.sh
  3. +49
    -47
      business/staff.go
  4. +6
    -0
      common/config.go
  5. +12
    -10
      config.json
  6. +10
    -2
      main.go
  7. BIN
      staffs.db
  8. +193
    -0
      templates/conf.html
  9. +21
    -0
      templates/login.html
  10. +0
    -1
      templates/mgr.html
  11. +10
    -12
      templates/reg.html

+ 1
- 1
.gitignore View File

@@ -1,2 +1,2 @@
.idea/
logs/
logs/*

+ 7
- 4
build_and_run.sh View File

@@ -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
#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

+ 49
- 47
business/staff.go View File

@@ -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结束=====")
}
}


+ 6
- 0
common/config.go View File

@@ -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
}


+ 12
- 10
config.json View File

@@ -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"
}

+ 10
- 2
main.go View File

@@ -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)


BIN
staffs.db View File


+ 193
- 0
templates/conf.html View File

@@ -0,0 +1,193 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>配置页面</title>
<style>
body{
margin: 0;
}
li {
list-style-type: none;
}
@media screen and (orientation: portrait) {
.login {
width: 100vw;
height: 100vh;
background-image: url("/static/img/phoneBgc.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
}
.register {
background-image: url("/static/img/registerBgc.jpg") !important;
padding-top: 15vh;
}

.enterprise-name, .devId, .devIp, .sync {
width: 50vw;
height: 5vh;
border-radius: 2vw;
background-color: transparent;
font-size: 3vw;
padding-left: 2vw;
border: 1px solid #000;
margin-bottom: 2vh;
}

.register_inputBox {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 5vh;
position: relative;
}
.register_loginButton {
width: 40vw;
height: 5vh;
background-color: rgb(101, 161, 255);
border-radius: 10vw;
display: flex;
justify-content: center;
align-items: center;
color:#fff;
font-size: 4vw;
margin: 2vh 0 0 30vw;
}


#div-a-login{
margin-top: 3vh;
text-align: center;
}
}
@media screen and (orientation: landscape) {
input:focus {
border: 0.1vw solid #000;
outline: none; /* 可选,用于去除默认的外边框样式 */
}
.login {
width: 100vw;
height: 100vh;
background-image: url("/static/img/phoneBgc_pc.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
position: relative;
}
.register {
background-image: url("/static/img/registerBgc_pc.jpg") !important;
}


.register_inputBox {
width: 100vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
padding-top: 42vh;
}
.enterprise-name, .devId, .devIp,.sync {
width: 37vh;
height: 6vh;
border-radius: 2vh;
background-color: transparent;
font-size: 3vh;
border: 0.1vw solid #000;
padding-left: 1vw ;
margin-bottom: 2vh;
}

.register_loginButton {
width: 8vw;
height: 2vw;
background-color: rgb(101, 161, 255);
border-radius: 1vw;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-size: 3vh;
position: absolute;
left: 46vw;
top: 65vh;
}

.hand:hover{
cursor: pointer;
}


#div-a-login{
margin-top: 10vh;
text-align: center;
font-size: 3vh;
}
}


</style>
</head>
<body>
<!-- 注册页面 -->
<div class="register login">

<div class="register_inputBox">
<input class="enterprise-name" name="enterpriseName" value="{{.config.EnterpriseName}}" type="text" placeholder="租户名">
<input class="devId" name="devId" type="text" value="{{.config.DevId}}" placeholder="对应数字人设备号">
<input class="devIp" name="devIp" value="{{.config.DevIp}}" type="text" placeholder="数字人ip">
<select class="sync" name="sync" >
<option value="1" {{if eq .config.Sync 1}}selected{{end}}>同步</option>
<option value="0" {{if eq .config.Sync 0}}selected{{end}}>不同步</option>
</select>
</div>
<div class="register_loginButton hand">保存配置</div>
<div id="div-a-login"><a id="a-login" href="/">去登录</a></div>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/msg-box.js"></script>
<script>
$(function(){

$(".register_loginButton").on("click",function() {

var enterpriseName = $(".enterprise-name").val();
var devId = $(".devId").val();
var devIp = $(".devIp").val();
//ip4正则字符串
const regex = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if (devIp !== "" && !regex.test(devIp)){
$.MsgBox.Alert("提示", "ip填写错误,请检查");
return;
}

var settings = {
"url": "/updateConfig",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({
"devIp": devIp,
"devId": devId,
"enterpriseName": enterpriseName,
"sync": Number($(".sync").val())
}),
};

$.ajax(settings).done(function (response) {
$.MsgBox.AlertWithCallback( "提示",response.message, function(){
window.location.reload()
})
});

})

})

</script>
</body>
</html>

+ 21
- 0
templates/login.html View File

@@ -136,6 +136,10 @@
top: 18vw;
right: 26vw;
}
#div-a-reg{
margin-top: 3vh;
text-align: center;
}
}
@media screen and (orientation: landscape) {
input:focus {
@@ -328,6 +332,21 @@
cursor: pointer;
}

#div-a-reg{
width: 16vw;
height: 3vw;
background-color:transparent;
border-radius: 10vh;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-size: 2vh;
position: absolute;
left: 55vw;
top: 72vh;
}

}
button:disabled {
color: black !important;
@@ -361,6 +380,8 @@
</div>
</div>
<div class="login_button hand">登 录</div>

<div id="div-a-reg"><a id="a-reg" href="/reg">去注册</a></div>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/msg-box.js"></script>


+ 0
- 1
templates/mgr.html View File

@@ -289,7 +289,6 @@
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/msg-box.js"></script>
<script>
console.log("9999999");
var token= sessionStorage.getItem('token');
console.log(token)
if (!token){


+ 10
- 12
templates/reg.html View File

@@ -102,6 +102,10 @@
left: 27vw !important;
position: relative;
}
#div-a-login{
margin-top: 3vh;
text-align: center;
}
}
@media screen and (orientation: landscape) {
input:focus {
@@ -216,6 +220,11 @@
position: relative;
}

#div-a-login{
margin-top: 10vh;
text-align: center;
font-size: 3vh;
}
}


@@ -297,23 +306,12 @@
<input class="register_phoneInput" name="staffPhone" type="text" placeholder="员工手机号">
</div>
<div class="register_loginButton hand">注册人脸</div>
<div id="div-a-login"><a id="a-login" href="/">去登录</a></div>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/msg-box.js"></script>
<script>
$(function(){
$.MsgBox = {
Alert: function(title, msg) {
GenerateHtml("alert", title, msg);
btnOk(); //alert只是弹出消息,因此没必要用到回调函数callback
btnNo();
},
Confirm: function(title, msg, callback) {
GenerateHtml("confirm", title, msg);
btnOk(callback);
btnNo();
}
}

$(".register_loginButton").on("click",function() {



Loading…
Cancel
Save