Browse Source

fix:邮箱分发bug以及添加分发检查元数据与oa一致性

GTong 7 months ago
parent
commit
4aa60fc461

+ 53 - 0
CRLF_lic_op_20241015113005_企业版(双机).cfg

@@ -0,0 +1,53 @@
+
+#用户项目信息
+	project_name    = 
+	user_name       = 企业版(双机)
+	user_addr       = 未填写
+	serial_number   = 未填写
+#环境信息
+	cpu_sn          = 未填写
+	baseboard_sn    = 未填写
+	mac_addr        = fa:2a:16:56:5d:00
+	disk_id         = 未填写
+	ip_addr         = 未填写
+#License信息
+	gen_date        = 2024-07-15
+	expire_date     = 9999-12-31
+	license_type    = 3
+	license_version = 1
+	hard_type       = 3
+#企业版                                   
+    ha              = true
+    hint            = true
+    full_text_index = true
+    function_index  = true
+    batch_mode      = true
+    pl_sql          = true
+#分布式版
+    add_node            = false
+    auto_partition      = true
+    resource_quota      = true
+    net_channel         = 0
+    data_auto_rebalance = true
+#其他组件
+    black_white_list   = true
+    mac                = true
+    col_privilege      = true
+    transmit_encrypt   = true
+    store_encrypt      = true
+    backup_encrypt     = true
+    audit_mode         = 0
+    global_binlog_node = 0
+    dblink             = true
+    json               = true
+    spatial            = true
+    max_parallel       = 0
+    stream_load        = true
+#服务能力
+    instance_num   = 0
+    table_rows     = 0
+    connect_num    = 0
+    store_capacity = 0
+    max_node_num   = 0
+    listen_channel = 0
+	

+ 2 - 1
config.toml

@@ -1,6 +1,7 @@
 [config]
-ip = "127.0.0.1"
+ip = "10.28.20.150"
 port = "8080"
+is_generate = false
 
 [database]
 oadb_ip = "192.168.2.212"

+ 3 - 2
internal/global/config.go

@@ -13,8 +13,9 @@ type Config struct {
 }
 
 type AppConfig struct {
-	Ip   string `toml:"ip"`
-	Port string `toml:"port"`
+	Ip         string `toml:"ip"`
+	Port       string `toml:"port"`
+	IsGenerate bool   `toml:"is_generate"`
 }
 
 type DatabaseConfig struct {

+ 51 - 26
internal/services/OALicenseInfo_services.go

@@ -123,6 +123,15 @@ func DistributeOALicenseServices(OperatorUniqueID, OaRequestId string, UserUniqu
 }
 
 func DistributeLicenseToUserServices(OperatorUniqueID string, OaRequestId int64, UserUniqueIDs, UserAccounts, UserNames []string) (error, []string) {
+	//检测支撑库数据与oa是否一致
+	err, checkInfo := CheckOaLicInfoRequest(OaRequestId)
+	if err != nil {
+		return err, nil
+	}
+	if checkInfo {
+		return errors.Errorf("本地数据与oa数据不一致,请刷新页面"), nil
+	}
+
 	//检测OARequest是否以及分发过给用户
 	existUsers, err := checkDistributeToUser(OaRequestId, UserUniqueIDs, UserNames)
 	if err != nil {
@@ -167,6 +176,14 @@ func DistributeLicenseToEmailServices(OperatorUniqueID string, OaRequestId int64
 	//邮箱不空则发送
 	//将一个申请单的多个license信息用邮箱发送
 
+	//检测支撑库数据与oa是否一致
+	err, checkInfo := CheckOaLicInfoRequest(OaRequestId)
+	if err != nil {
+		return err, nil
+	}
+	if checkInfo {
+		return errors.Errorf("本地数据与oa数据不一致,请刷新页面"), nil
+	}
 	if len(EmailArray) == 0 {
 		return nil, nil
 	}
@@ -328,7 +345,7 @@ func GenerateOALicenseStrServices(request api.GenerateLicenseStrRequest) (error,
 
 		//生成license,已生成的不管
 		for _, v := range *OALics {
-			if v.GenrateInfo.LicenseFlage.String == "未生成" {
+			if v.GenrateInfo.LicenseFlage.String == "未生成" || v.GenrateInfo.LicenseFlage.String == "已失效" {
 				err := generateLicenseStrSub(utils.ToString(v.LicInfo.UniqueID))
 				if err != nil {
 					global.Logger.Errorf("请联系管理员, LicenseInfo%v生成失败:  %v\n", v.LicInfo.UniqueID, err.Error())
@@ -353,7 +370,7 @@ func generateLicenseStrSub(UniqueID string) error {
 		}
 	}
 
-	fmt.Printf("applications%#v\n", applications)
+	//fmt.Printf("applications%#v\n", applications)
 
 	//生成副主节点license
 	if applications == nil {
@@ -361,6 +378,11 @@ func generateLicenseStrSub(UniqueID string) error {
 		//c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("LicenseInfo数据生成失败 ,数据查询为空: ", err.Error())})
 		return errors.Errorf("LicenseInfo数据生成失败 ,数据查询为空 ")
 	}
+	for _, lic := range *applications {
+		if !lic.LicInfo.OAMainMAC.Valid {
+			return errors.Errorf("LicenseInfo数据生成失败 , %s 有集群 主mac地址缺失 ", lic.LicInfo.OAProductName.String)
+		}
+	}
 
 	pj := license.ProjectInfo{
 		ProjectName:  utils.ToString((*applications)[0].LicInfo.OAProductName),
@@ -385,52 +407,55 @@ func generateLicenseStrSub(UniqueID string) error {
 	}
 
 	//这里调用的是license模块中的生成license的方法
-	res := false
-	if res {
+	//res := false
+	fmt.Println("res是 : ", global.Cfg.App.IsGenerate)
+	if global.Cfg.App.IsGenerate {
+
+		licStr := license.GenerateLicense(pj, ei, lI)
+
+		//生成副主节点license
 		if (*applications)[0].LicInfo.OASecondMAC.String != "" {
-			// var licStr2 []byte
-			// ei.MacAddr = applications[0].SecondaryMasterMacAddress
-			// licStr2 = license.GenerateLicense(pj, ei, lI)
-			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"))
+			var licStr2 []byte
+			ei.MacAddr = (*applications)[0].LicInfo.OASecondMAC.String
+			licStr2 = license.GenerateLicense(pj, ei, lI)
+			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), licStr, licStr2)
 			if err != nil {
-				global.Logger.Errorln("LicenseInfo生成插入失败:  ", err.Error())
+				global.Logger.Errorln("LicenseInfo2生成插入失败:  ", err.Error())
 				//	c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("数据查询失败: ", err.Error())})
-				return errors.Errorf("LicenseInfo生成插入失败:: ", err.Error())
+				return errors.Errorf("LicenseInfo2生成插入失败:%s", err.Error())
 			}
 		} else {
-			//fmt.Println("licStr licStr2", licStr, licStr2)
 			//插入到数据库
-			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"), nil)
+			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), licStr, nil)
 			if err != nil {
-				global.Logger.Errorln("LicenseInfo2生成插入失败:  ", err.Error())
+				global.Logger.Errorln("LicenseInfo生成插入失败:  ", err.Error())
 				//	c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("数据查询失败: ", err.Error())})
-				return errors.Errorf("LicenseInfo2生成插入失败:: ", err.Error())
+				return errors.Errorf("LicenseInfo生成插入失败: %s", err.Error())
 			}
 		}
+
 	} else {
-		licStr := license.GenerateLicense(pj, ei, lI)
 
-		//生成副主节点license
 		if (*applications)[0].LicInfo.OASecondMAC.String != "" {
-			var licStr2 []byte
-			ei.MacAddr = (*applications)[0].LicInfo.OASecondMAC.String
-			licStr2 = license.GenerateLicense(pj, ei, lI)
-			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), licStr, licStr2)
+			// var licStr2 []byte
+			// ei.MacAddr = applications[0].SecondaryMasterMacAddress
+			// licStr2 = license.GenerateLicense(pj, ei, lI)
+			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"))
 			if err != nil {
-				global.Logger.Errorln("LicenseInfo2生成插入失败:  ", err.Error())
+				global.Logger.Errorln("LicenseInfo生成插入失败:  ", err.Error())
 				//	c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("数据查询失败: ", err.Error())})
-				return errors.Errorf("LicenseInfo2生成插入失败:: ", err.Error())
+				return errors.Errorf("LicenseInfo生成插入失败:: ", err.Error())
 			}
 		} else {
+			//fmt.Println("licStr licStr2", licStr, licStr2)
 			//插入到数据库
-			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), licStr, nil)
+			err = models.UpdateOALicenseStr(utils.ToString((*applications)[0].LicInfo.UniqueID), []byte("b4j6z4rE2IfG1av0wIPT7YnvyGZFHxwIBikMGjgCLQILR0xsT1NHiuzoi+Dqq+bmiNDEiuPyitDVgdvlRmYbFAk+MAAGASlPTkdMbE9"), nil)
 			if err != nil {
-				global.Logger.Errorln("LicenseInfo生成插入失败:  ", err.Error())
+				global.Logger.Errorln("LicenseInfo2生成插入失败:  ", err.Error())
 				//	c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("数据查询失败: ", err.Error())})
-				return errors.Errorf("LicenseInfo生成插入失败:: ", err.Error())
+				return errors.Errorf("LicenseInfo2生成插入失败:: ", err.Error())
 			}
 		}
-
 	}
 
 	//---------------------

+ 42 - 0
internal/services/OALicenseInfo_services_sub.go

@@ -3,6 +3,8 @@ package services
 import (
 	"xugu_license/internal/global"
 	"xugu_license/internal/models"
+
+	"github.com/pkg/errors"
 )
 
 func checkDistributeToUser(OaLicRequest int64, UserUniqueIDs []string, UserNames []string) (licToUser []string, err error) {
@@ -21,3 +23,43 @@ func checkDistributeToUser(OaLicRequest int64, UserUniqueIDs []string, UserNames
 	}
 	return licToUser, nil
 }
+
+func CheckOaLicInfoRequest(OARequestId int64) (error, bool) {
+	if OARequestId != 0 {
+		//一个OARequestId会有多条数据UniqueID
+		OALics, _, err := models.GetOALicenseInfo(0, 0, "", "", "", OARequestId)
+		if err != nil || OALics == nil {
+			global.Logger.Errorln("LicenseInfo数据查询失败:  ", err.Error())
+			return errors.Errorf("LicenseInfo数据查询失败 : %v", err.Error()), false
+		}
+
+		//校验license信息是否与oa一致
+		var isCheck bool
+		for _, license := range *OALics {
+			//检测该数据是否与oa库数据库一致 //todo
+			isCheckTmp, err := models.CheckLicenseInfoInOADB(&license.LicInfo)
+			if err != nil {
+				global.Logger.Errorln("LicenseInfo数据对比oa库 校验失败:  ", err.Error())
+				return errors.Errorf("LicenseInfo数据对比oa库 校验失败 %v", err.Error()), false
+			}
+			if isCheckTmp {
+				global.Logger.Errorf("\nLicenseInfo数据对比oa库 不一致:  %v\n", license.LicInfo.UniqueID)
+				isCheck = isCheckTmp
+				err = models.UpdatelicenseInfoRow(license)
+				if err != nil {
+					return err, false
+				}
+				err = models.UpdatelicenseGenerateInfoRow(license)
+				if err != nil {
+					return err, false
+				}
+			}
+		}
+		//不一致则返回
+		if isCheck {
+			return nil, true
+		}
+		return nil, false
+	}
+	return errors.Errorf("该申请单没有oa单号"), false
+}

+ 53 - 0
lic_op_20241015113005_企业版(双机).cfg

@@ -0,0 +1,53 @@
+
+#用户项目信息
+	project_name    = 
+	user_name       = 企业版(双机)
+	user_addr       = 未填写
+	serial_number   = 未填写
+#环境信息
+	cpu_sn          = 未填写
+	baseboard_sn    = 未填写
+	mac_addr        = fa:2a:16:56:5d:00
+	disk_id         = 未填写
+	ip_addr         = 未填写
+#License信息
+	gen_date        = 2024-07-15
+	expire_date     = 9999-12-31
+	license_type    = 3
+	license_version = 1
+	hard_type       = 3
+#企业版                                   
+    ha              = true
+    hint            = true
+    full_text_index = true
+    function_index  = true
+    batch_mode      = true
+    pl_sql          = true
+#分布式版
+    add_node            = false
+    auto_partition      = true
+    resource_quota      = true
+    net_channel         = 0
+    data_auto_rebalance = true
+#其他组件
+    black_white_list   = true
+    mac                = true
+    col_privilege      = true
+    transmit_encrypt   = true
+    store_encrypt      = true
+    backup_encrypt     = true
+    audit_mode         = 0
+    global_binlog_node = 0
+    dblink             = true
+    json               = true
+    spatial            = true
+    max_parallel       = 0
+    stream_load        = true
+#服务能力
+    instance_num   = 0
+    table_rows     = 0
+    connect_num    = 0
+    store_capacity = 0
+    max_node_num   = 0
+    listen_channel = 0
+	

+ 1 - 1
static/license_info/license_info.js

@@ -1,5 +1,5 @@
 // 全局变量定义
-const serverIP = '127.0.0.1';
+const serverIP = '10.28.20.150';
 const serverPort = '8080';
 
 let page = 21; // 初始页码为1,代表从第1条数据开始获取

+ 1 - 1
static/license_info/license_info_distribution.js

@@ -362,7 +362,7 @@ function distributeEmails(item, emails, usersInfo) {
         // 处理错误
         hideLoadingModal();
         console.error('分发邮件失败:', error);
-        alert('分发邮件失败,请稍后重试');
+        alert('分发邮件失败:', error);
     });
 }
 

+ 1 - 1
static/login/login.js

@@ -1,5 +1,5 @@
 // 全局变量定义
-const serverIP = '127.0.0.1';
+const serverIP = '10.28.20.150';
 const serverPort = '8080';
 
 document.addEventListener('DOMContentLoaded', () => {