Эх сурвалжийг харах

Merge branch 'pool/xy_login' into debug

# Conflicts:
#	services/user_login.go
Roc 1 жил өмнө
parent
commit
eefabbca42

+ 3 - 0
controllers/sys_role.go

@@ -705,6 +705,9 @@ func (this *SysRoleController) SystemConfig() {
 	}, system.BusinessConf{
 		ConfKey: "ChartViewUrl",
 		ConfVal: conf["ChartViewUrl"],
+	}, system.BusinessConf{
+		ConfKey: "LoginUrl",
+		ConfVal: conf["LoginUrl"],
 	})
 
 	osc := system.BusinessConf{

+ 17 - 6
controllers/sys_user.go

@@ -347,16 +347,27 @@ func (this *SysUserController) AuthCodeLogin() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	authCode := this.GetString("AuthCode", "")
-	if authCode == "" {
-		br.Msg = "参数有误"
-		br.ErrMsg = "参数缺失, AuthCode"
-		return
+	//authCode := this.GetString("AuthCode", "")
+	//if authCode == "" {
+	//	br.Msg = "参数有误"
+	//	br.ErrMsg = "参数缺失, AuthCode"
+	//	return
+	//}
+
+	req := make(map[string]interface{})
+	query := this.Ctx.Request.URL.Query()
+	for key, value := range query {
+		req[key] = value[0]
 	}
+	fmt.Println(req)
 
-	data, e := services.CodeLoginFromMiddleServer(authCode)
+	//data, e := services.CodeLoginFromMiddleServer(authCode)
+	data, e, errMsg := services.ThirdLogin(req)
 	if e != nil {
 		br.Msg = "获取失败"
+		if errMsg != `` {
+			br.Msg = errMsg
+		}
 		br.ErrMsg = "获取登录Token失败, Err: " + e.Error()
 		return
 	}

+ 3 - 2
services/crm_eta.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta/eta_api/utils"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"net/http"
 	"strings"
@@ -137,7 +138,7 @@ func CodeLoginFromMiddleServer(authCode string) (tokenResp GetCrmTokenData, err
 		return
 	}
 
-	body := ioutil.NopCloser(strings.NewReader(string(data)))
+	body := io.NopCloser(strings.NewReader(string(data)))
 	client := &http.Client{}
 	req, e := http.NewRequest("POST", url, body)
 	if e != nil {
@@ -156,7 +157,7 @@ func CodeLoginFromMiddleServer(authCode string) (tokenResp GetCrmTokenData, err
 	defer func() {
 		_ = resp.Body.Close()
 	}()
-	b, e := ioutil.ReadAll(resp.Body)
+	b, e := io.ReadAll(resp.Body)
 	if e != nil {
 		err = fmt.Errorf("resp body read err: %s", e.Error())
 		return

+ 9 - 4
services/data/excel/custom_analysis_edb.go

@@ -48,6 +48,7 @@ func GetCustomAnalysisExcelData(excelInfo *excel.ExcelInfo) (luckySheet excelSer
 			tmpSheetDataList := make([]excelServices.LuckySheetCellData, 0)
 			err = json.Unmarshal([]byte(cellData.Data), &tmpSheetDataList)
 			if err != nil {
+				err = errors.New(fmt.Sprintf("解析data的配置失败,sheetId:%d,Err:%s", cellData.ExcelDataId, err.Error()))
 				return
 			}
 			sheetCellDataMapList[cellData.ExcelSheetId] = append(sheetDataList, tmpSheetDataList...)
@@ -63,6 +64,7 @@ func GetCustomAnalysisExcelData(excelInfo *excel.ExcelInfo) (luckySheet excelSer
 		var luckySheetDataConfig excelServices.LuckySheetDataConfig
 		err = json.Unmarshal([]byte(sheet.Config), &luckySheetDataConfig)
 		if err != nil {
+			err = errors.New(fmt.Sprintf("解析sheet的配置失败,sheetId:%d,Err:%s", sheet.ExcelSheetId, err.Error()))
 			return
 		}
 		tmpLuckySheetDataInfo := excelServices.LuckySheetData{
@@ -218,6 +220,7 @@ func Refresh(excelInfo *excel.ExcelInfo) (err error, errMsg string, isSendEmail
 	list, err := excel.GetAllExcelEdbMappingItemByExcelInfoId(excelInfo.ExcelInfoId)
 	if err != nil {
 		errMsg = "获取失败"
+		err = errors.New("查找所有的mapping失败" + err.Error())
 		return
 	}
 
@@ -231,7 +234,7 @@ func Refresh(excelInfo *excel.ExcelInfo) (err error, errMsg string, isSendEmail
 		err = json.Unmarshal([]byte(v.CalculateFormula), &tmpCalculateFormula)
 		if err != nil {
 			errMsg = "获取失败"
-			err = errors.New("公式转换失败,Err:" + err.Error())
+			err = errors.New(fmt.Sprintf("指标id:%d,公式转换失败,Err:%s", v.EdbInfoId, err.Error()))
 			return
 		}
 		v.DateSequenceStr = tmpCalculateFormula.DateSequenceStr
@@ -241,12 +244,14 @@ func Refresh(excelInfo *excel.ExcelInfo) (err error, errMsg string, isSendEmail
 
 	luckySheet, err, errMsg := GetCustomAnalysisExcelData(excelInfo)
 	if err != nil {
+		err = errors.New(fmt.Sprintf("获取自定义分析Excel数据失败,Err:%s", err.Error()))
 		return
 	}
 
 	// 获取excel表格数据
 	xlsxFile, err := luckySheet.GetExcelData(false)
 	if err != nil {
+		err = errors.New(fmt.Sprintf("获取excel表格数据,Err:%s", err.Error()))
 		return
 	}
 
@@ -260,7 +265,7 @@ func Refresh(excelInfo *excel.ExcelInfo) (err error, errMsg string, isSendEmail
 		// 获取对应的日期和数据列表
 		relDateList, relDataList, tmpErr, tmpErrMsg := getDateAndDataList(v, xlsxFile)
 		if tmpErr != nil {
-			err = tmpErr
+			err = errors.New(fmt.Sprintf("获取对应的日期和数据列表,Err:%s", tmpErr.Error()))
 			errMsg = tmpErrMsg
 			return
 		}
@@ -274,12 +279,12 @@ func Refresh(excelInfo *excel.ExcelInfo) (err error, errMsg string, isSendEmail
 		// 调用指标库去更新
 		reqJson, tmpErr := json.Marshal(req2)
 		if tmpErr != nil {
-			err = tmpErr
+			err = errors.New(fmt.Sprintf("结构体转对象失败,Err:%s", tmpErr.Error()))
 			return
 		}
 		respItem, tmpErr := data.ResetCustomAnalysisData(string(reqJson))
 		if tmpErr != nil {
-			err = tmpErr
+			err = errors.New(fmt.Sprintf("调用指标库去更新,Err:%s", tmpErr.Error()))
 			return
 		}
 		if respItem.Ret != 200 {

+ 86 - 0
services/user_login.go

@@ -2,12 +2,15 @@ package services
 
 import (
 	"encoding/json"
+	"errors"
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
 	"eta/eta_api/models/system"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/go-ldap/ldap"
+	"io"
+	"net/http"
 	"strconv"
 	"strings"
 	"time"
@@ -239,3 +242,86 @@ func LdapUserCheck(userName, password string) (pass bool, err error) {
 	pass = true
 	return
 }
+
+func ThirdLogin(req map[string]interface{}) (data GetCrmTokenData, err error, errMsg string) {
+	if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
+		authCode, ok := req["code"]
+		if !ok {
+			errMsg = "参数有误"
+			err = errors.New("参数缺失, code")
+			return
+		}
+		authCodeStr := fmt.Sprint(authCode)
+		if authCodeStr == "" {
+			errMsg = "参数有误"
+			err = errors.New("参数缺失, AuthCode")
+			return
+		}
+
+		data, err = CodeLoginFromMiddleServer(authCodeStr)
+
+		return
+	}
+
+	data, err = ThirdCodeLoginFromMiddleServer(req)
+
+	// 普通的第三方
+
+	return
+}
+
+// ThirdCodeLoginFromMiddleServer 中间服务-编码登录
+func ThirdCodeLoginFromMiddleServer(param map[string]interface{}) (tokenResp GetCrmTokenData, err error) {
+	data, e := json.Marshal(param)
+	if e != nil {
+		err = fmt.Errorf("data json marshal err: %s", e.Error())
+		return
+	}
+
+	body := io.NopCloser(strings.NewReader(string(data)))
+	client := &http.Client{}
+	req, e := http.NewRequest("POST", utils.EtaBridgeLoginUrl, body)
+	if e != nil {
+		err = fmt.Errorf("http create request err: %s", e.Error())
+		return
+	}
+
+	contentType := "application/json;charset=utf-8"
+	req.Header.Set("Content-Type", contentType)
+	req.Header.Set("Authorization", utils.CrmEtaAuthorization)
+	resp, e := client.Do(req)
+	if e != nil {
+		err = fmt.Errorf("http client do err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = resp.Body.Close()
+	}()
+	b, e := io.ReadAll(resp.Body)
+	if e != nil {
+		err = fmt.Errorf("resp body read err: %s", e.Error())
+		return
+	}
+	if len(b) == 0 {
+		err = fmt.Errorf("resp body is empty")
+		return
+	}
+	// 生产环境解密, 注意有个坑前后的双引号
+	if utils.RunMode == "release" {
+		str := string(b)
+		str = strings.Trim(str, `"`)
+		b = utils.DesBase64Decrypt([]byte(str), utils.DesKey)
+	}
+
+	result := new(GetCrmTokenDataResp)
+	if e = json.Unmarshal(b, &result); e != nil {
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s", string(b))
+		return
+	}
+	tokenResp = result.Data
+	return
+}

+ 2 - 0
utils/config.go

@@ -88,6 +88,7 @@ var (
 	EtaBridgeAppNameEn string // 桥接服务英文名称-鉴权用
 	EtaBridgeMd5Key    string // 桥接服务Md5密钥-鉴权用
 	EtaBridgeDesKey    string // 桥接服务Des密钥-解密数据用
+	EtaBridgeLoginUrl  string // 第三方登录鉴权接口地址
 )
 
 // 微信配置信息
@@ -350,6 +351,7 @@ func init() {
 		EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
 		EtaBridgeMd5Key = config["eta_bridge_md5_key"]        // 桥接服务Md5密钥-鉴权用
 		EtaBridgeDesKey = config["eta_bridge_des_key"]        // 桥接服务Des密钥-解密数据用
+		EtaBridgeLoginUrl = config["eta_bridge_login_url"]    // eta桥接服务-登录接口地址
 	}
 
 	//日志配置