diff --git a/business/staff.go b/business/staff.go
index cc95d49..fc0cfc7 100644
--- a/business/staff.go
+++ b/business/staff.go
@@ -62,7 +62,7 @@ type Req struct {
}
func RegStaff(param Req) (*common.Response, error) {
- url := common.ConfigData.PushDataUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.PushDataUrl
common.Info(common.GenLogLine()+"reg staff url:%s\n", url)
method := "POST"
@@ -110,12 +110,15 @@ func RegStaff(param Req) (*common.Response, error) {
fmt.Println("Error:", err)
return nil, err
}
+ if response.Code != 200 || response.Code != 0 {
+ return response, errors.New(response.Msg)
+ }
common.Error(common.GenLogLine()+"reg result %s", string(body))
return response, nil
}
func RegOnlineStaff(param Req) error {
- url := common.ConfigData.PushDataUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.PushDataUrl
fmt.Printf("url:%s\n", url)
method := "POST"
@@ -154,27 +157,39 @@ func RegOnlineStaff(param Req) error {
return nil
}
-func HandleStaff(emp Req) error {
+func HandleStaff(emp Req) (*common.Response, error) {
if emp.StaffBase64Img != "" {
//feature = FetchStaffFaceFeature(emp.StaffBase64Img)
//emp.FaceFeature = LocalFetchStaffFaceFeature(emp.StaffBase64Img)
}
- var sType int
- if emp.StaffType > 70 {
- sType = 4
- } else {
- sType = 5
+
+ if common.ConfigData.Mode != "online" {
+ emp.StaffBase64Img = ""
}
- emp.StaffType = sType
- var sDels = []int{5, 6, 7, 8}
- if common.AryContainInt(sDels, emp.DelFlag) {
- emp.DelFlag = 1
- } else {
- emp.DelFlag = 0
+
+ //======东方微银逻辑======start====
+ if strings.Contains(common.ConfigData.EnterpriseName, "东方微银") {
+ var sType int
+ if emp.StaffType > 70 {
+ sType = 4
+ } else {
+ sType = 5
+ }
+ emp.StaffType = sType
+ var sDels = []int{5, 6, 7, 8}
+ if common.AryContainInt(sDels, emp.DelFlag) {
+ emp.DelFlag = 1
+ } else {
+ emp.DelFlag = 0
+ }
}
+ //======东方微银逻辑======end====
- RegStaff(emp)
- return nil
+ resp, err := RegStaff(emp)
+ if err != nil {
+ return resp, err
+ }
+ return resp, nil
}
// Fetch2 获取员工信息,模拟获取saas的人员数据
@@ -260,7 +275,7 @@ func Fetch2() []Staff {
// AbleSendCode 发送验证码
func AbleSendCode(phone string) string {
- url := common.ConfigData.CheckSendCodeUrl + "/" + phone
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.CheckSendCodeUrl + "/" + phone
method := "GET"
payload := strings.NewReader("")
@@ -297,7 +312,7 @@ func SendCode(phone string) string {
ableSend := AbleSendCode(phone)
fmt.Println("ableSend:", ableSend)
- url := common.ConfigData.SendCodeUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.SendCodeUrl
method := "POST"
payload := strings.NewReader(`{
@@ -341,7 +356,7 @@ func SendCode(phone string) string {
func ValidCode(phone string, code string) (string, error) {
ableSend := AbleSendCode(phone)
fmt.Println("ableSend:", ableSend)
- url := common.ConfigData.ValidCodeUrl + phone + "/" + code
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.ValidCodeUrl + phone + "/" + code
method := "GET"
payload := strings.NewReader(``)
@@ -371,7 +386,7 @@ func ValidCode(phone string, code string) (string, error) {
func StaffInfo(staffId string) (map[string]interface{}, error) {
fmt.Println("staffId:", staffId)
- url := common.ConfigData.StaffInfoUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.StaffInfoUrl
method := "GET"
token, err := common.GetToken()
if err != nil {
@@ -431,7 +446,7 @@ func StaffInfo(staffId string) (map[string]interface{}, error) {
}
func MgrLogin(userName string, password string) string {
- url := common.ConfigData.MgrLoginUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.MgrLoginUrl
fmt.Println("url:", url)
enterpriseName := common.ConfigData.EnterpriseName
method := "POST"
@@ -471,7 +486,7 @@ func MgrLogin(userName string, password string) string {
}
func PhoneLogin(phone string) (map[string]interface{}, error) {
- url := common.ConfigData.PhoneLoginUrl
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.PhoneLoginUrl
method := "POST"
payload := strings.NewReader(`{
@@ -632,7 +647,7 @@ func FetchStaffImage(ygbh string) string {
fmt.Println("Error:", err)
}
- var result string = ""
+ var result = ""
for _, item := range response.Data {
var s string
@@ -645,8 +660,8 @@ func FetchStaffImage(ygbh string) string {
return strings.Replace(result, "\n", "", -1)
}
-func FetchStaffFaceFeature(base64 string) string {
- url := "http://39.105.51.226:5000/cv/feature-extraction-service/1.7"
+func FetchStaffFaceFeature(base64 string) (string, error) {
+ url := "http://" + common.ConfigData.ServerIp + ":8080/" + common.ConfigData.FaceDetectUrl
method := "POST"
err := common.SaveBase64ImageToFile(base64, "images/"+fmt.Sprintf("%d", time.Now().Unix())+"test.jpg")
@@ -662,7 +677,7 @@ func FetchStaffFaceFeature(base64 string) string {
if err != nil {
fmt.Errorf(common.GenLogLine()+"%s", err)
common.Error(common.GenLogLine()+"%s", err)
- return ""
+ return "", err
}
req.Header.Add("Authorization", "Bearer ")
req.Header.Add("Content-Type", "application/json")
@@ -671,7 +686,7 @@ func FetchStaffFaceFeature(base64 string) string {
if err != nil {
fmt.Errorf(common.GenLogLine()+"%s", err)
common.Error(common.GenLogLine()+"%s", err)
- return ""
+ return "", err
}
defer res.Body.Close()
@@ -679,7 +694,7 @@ func FetchStaffFaceFeature(base64 string) string {
if err != nil {
fmt.Errorf(common.GenLogLine()+"%s", err)
common.Error(common.GenLogLine()+"%s", err)
- return ""
+ return "", err
}
fmt.Println(string(body))
@@ -687,12 +702,16 @@ func FetchStaffFaceFeature(base64 string) string {
err = json.Unmarshal([]byte(string(body)), &response)
if err != nil {
fmt.Println("Error:", err)
+ return "", err
}
var result string
result, err = extractFeature(response.Result[0])
+ if err != nil {
+ return "", err
+ }
fmt.Printf(" success data : %+v\n", result)
- return result
+ return result, nil
}
func extractFeature(data interface{}) (string, error) {
@@ -768,6 +787,7 @@ func LocalFetchStaffFaceFeature(base64 string) (string, string, error) {
faces, ok := response["data"].(map[string]interface{})
if !ok {
fmt.Errorf("No faces found")
+ return "", imgName, errors.New("No faces found")
}
feature, ok1 := faces["faceData"].(map[string]interface{})["theFeature"].([]interface{})
@@ -861,7 +881,7 @@ func TimerHandle() {
if t3.After(t1) {
staff.StaffBase64Img = FetchStaffImage(staff.Code)
common.Info(common.GenLogLine()+"----%v", "" == staff.StaffBase64Img)
- str := HandleStaff(staff)
+ _, str := HandleStaff(staff)
common.Info(common.GenLogLine()+"--2.2注册人员 姓名:%s 编号:%s 更新时间:%s--\n", staff.StaffName, staff.Code, staff.Modified)
//str := RegOnlineStaff(staff)
ss := ""
@@ -892,7 +912,8 @@ func EmpToReq(emp mydatabase.Emp) Req {
req.StaffName = emp.Name
req.StaffType = 5 //普通员工
req.Phone = emp.Phone
- req.StaffBase64Img = emp.Avatar
+ str, _ := common.FileToBase64(emp.Avatar)
+ req.StaffBase64Img = str
req.FaceFeature = emp.Features
return req
}
diff --git a/common/cache.go b/common/cache.go
index bd2c89c..905e4ce 100644
--- a/common/cache.go
+++ b/common/cache.go
@@ -123,3 +123,14 @@ func extractBase64Data(base64Image string) string {
}
return parts[1]
}
+
+func FileToBase64(filePath string) (string, error) {
+ imageBytes, err := os.ReadFile(filePath)
+ if err != nil {
+ fmt.Println("Error reading file:", err)
+ return "", err
+ }
+
+ // 将JPEG文件内容进行Base64编码
+ return base64.StdEncoding.EncodeToString(imageBytes), nil
+}
diff --git a/common/common.go b/common/common.go
index 9866dbd..9cdaca4 100644
--- a/common/common.go
+++ b/common/common.go
@@ -72,7 +72,7 @@ func TruncateLastSlash(inputString string) string {
}
func GetToken() (string, error) {
- url := ConfigData.FetchTokenUrl
+ url := "http://" + ConfigData.ServerIp + ":8080/" + ConfigData.FetchTokenUrl
method := "POST"
Info(GenLogLine() + "获取token")
token := GetCache("token")
diff --git a/common/config.go b/common/config.go
index 6e3bd0c..4985bc8 100644
--- a/common/config.go
+++ b/common/config.go
@@ -16,12 +16,14 @@ type Config struct {
MgrLoginUrl string `json:"mgrLoginUrl"`
ValidCodeUrl string `json:"validCodeUrl"`
StaffInfoUrl string `json:"staffInfoUrl"`
+ FaceDetectUrl string `json:"faceDetectUrl"`
EnterpriseName string `json:"enterpriseName"`
Port string `json:"port"`
PushDataUrl string `json:"pushDataUrl"`
LocalDetectUrl string `json:"localDetectUrl"`
DevId string `json:"devId"`
DevIp string `json:"devIp"`
+ ServerIp string `json:"serverIp"`
Timer int `json:"timer"`
Sync int `json:"sync"`
Mode string `json:"mode"`
@@ -58,6 +60,8 @@ func UpdateConfig(updateValues map[string]interface{}) string {
config.DevId = value.(string)
case "devIp":
config.DevIp = value.(string)
+ case "serverIp":
+ config.ServerIp = value.(string)
case "mode":
config.Mode = value.(string)
case "enterpriseName":
diff --git a/config.json b/config.json
index 9e315a6..f57e3c4 100644
--- a/config.json
+++ b/config.json
@@ -1,20 +1,22 @@
{
- "fetchTokenUrl": "http://172.17.0.1:8080/auth/deviceLogin",
+ "fetchTokenUrl": "/auth/deviceLogin",
"phone": "18910801519",
- "fetchDataUrl": "http://172.17.0.1:8080/system/staff/list",
+ "fetchDataUrl": "/system/staff/list",
"fetchData2Url": "http://10.1.26.139/api/dizhiyuan/member/DZYAction",
- "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",
+ "sendCodeUrl": "/system/sms/api/send-code",
+ "checkSendCodeUrl": "/system/staff/api/ableLogin",
+ "phoneLoginUrl": "/auth/phoneLogin",
+ "mgrLoginUrl": "/auth/mgr-login",
+ "validCodeUrl": "/system/staff/api/validCode",
+ "staffInfoUrl": "/system/staff/list",
+ "faceDetectUrl": "http://39.105.51.226:5000/cv/feature-extraction-service/1.7",
"enterpriseName": "演示机",
"port": "18080",
- "pushDataUrl": "http://172.17.0.1:8080/system/staff/api/new-staff",
+ "pushDataUrl": "/system/staff/api/new-staff",
"localDetectUrl": "/face/feature",
"devId": "442926c7610ed10b",
"devIp": "192.168.10.32",
+ "serverIp": "172.17.0.1",
"timer": 90,
"sync": 0,
"mode": "online"
diff --git a/main.go b/main.go
index bf13e5b..8349a9c 100644
--- a/main.go
+++ b/main.go
@@ -214,6 +214,11 @@ func MgrPageHandler(c *gin.Context) {
func TestHandler(c *gin.Context) {
fmt.Printf("timer: ====%d\n", common.ConfigData.Timer)
+ str, err := common.FileToBase64("static/faces/1710208090test.jpg")
+ if err != nil {
+ fmt.Printf("error: ====%s\n", err)
+ }
+ fmt.Printf("str: ====%s\n", str)
c.JSON(http.StatusOK, "request successfully")
}
@@ -225,7 +230,7 @@ func RegisterHandler(c *gin.Context) {
avatar := c.PostForm("avatar")
emp, _ := mydatabase.SelectOneByPhone(phone)
- fmt.Println("====phone:" + phone)
+
fmt.Println(emp)
if emp.ID > 0 {
c.JSON(http.StatusInternalServerError, map[string]interface{}{"Message": "已存在该手机号对应的员工,请查验后重试!"})
@@ -270,7 +275,7 @@ func PassHandler(c *gin.Context) {
if handleTypeInt == 1 {
emp.Avatar = strings.ReplaceAll(emp.Avatar, "data:image/jpeg;base64,", "")
//将员工信息提交到后台
- resp, err := business.RegStaff(business.EmpToReq(emp))
+ resp, err := business.HandleStaff(business.EmpToReq(emp))
if err != nil {
c.JSON(http.StatusOK, map[string]interface{}{"Message": err.Error()})
return
diff --git a/templates/conf.html b/templates/conf.html
index 74d5fbc..46d66ad 100644
--- a/templates/conf.html
+++ b/templates/conf.html
@@ -24,7 +24,7 @@
padding-top: 15vh;
}
- .enterprise-name, .devId, .devIp, .sync {
+ .enterprise-name, .devId, .devIp, .sync, .serverIp {
width: 50vw;
height: 5vh;
border-radius: 2vw;
@@ -89,7 +89,7 @@
position: relative;
padding-top: 42vh;
}
- .enterprise-name, .devId, .devIp,.sync {
+ .enterprise-name, .devId, .devIp,.sync, .serverIp {
width: 37vh;
height: 6vh;
border-radius: 2vh;
@@ -138,6 +138,7 @@
+