Browse Source

修复 sop 阶段和节点更新 bug

boweniac 9 months ago
parent
commit
d443270697

+ 8 - 5
internal/logic/sop_node/create_sop_node_logic.go

@@ -41,11 +41,14 @@ func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.BaseM
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	actionMessage := make([]custom_types.Action, len(req.ActionMessage))
-	for i, condition := range req.ActionMessage {
-		actionMessage[i] = custom_types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []custom_types.Action
+	if len(req.ActionMessage) > 0 {
+		actionMessage = make([]custom_types.Action, len(req.ActionMessage))
+		for i, condition := range req.ActionMessage {
+			actionMessage[i] = custom_types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 

+ 8 - 5
internal/logic/sop_node/get_sop_node_by_id_logic.go

@@ -33,11 +33,14 @@ func (l *GetSopNodeByIdLogic) GetSopNodeById(req *types.IDReq) (*types.SopNodeIn
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	actionMessage := make([]types.Action, len(data.ActionMessage))
-	for i, condition := range data.ActionMessage {
-		actionMessage[i] = types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []types.Action
+	if len(data.ActionMessage) > 0 {
+		actionMessage = make([]types.Action, len(data.ActionMessage))
+		for i, condition := range data.ActionMessage {
+			actionMessage[i] = types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 

+ 8 - 5
internal/logic/sop_node/get_sop_node_list_logic.go

@@ -45,11 +45,14 @@ func (l *GetSopNodeListLogic) GetSopNodeList(req *types.SopNodeListReq) (*types.
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
-		actionMessage := make([]types.Action, len(v.ActionMessage))
-		for i, condition := range v.ActionMessage {
-			actionMessage[i] = types.Action{
-				Type:    condition.Type,
-				Content: condition.Content,
+		var actionMessage []types.Action
+		if len(v.ActionMessage) > 0 {
+			actionMessage = make([]types.Action, len(v.ActionMessage))
+			for i, condition := range v.ActionMessage {
+				actionMessage[i] = types.Action{
+					Type:    condition.Type,
+					Content: condition.Content,
+				}
 			}
 		}
 

+ 8 - 5
internal/logic/sop_node/update_sop_node_logic.go

@@ -45,11 +45,14 @@ func (l *UpdateSopNodeLogic) UpdateSopNode(req *types.SopNodeInfo) (*types.BaseM
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	actionMessage := make([]custom_types.Action, len(req.ActionMessage))
-	for i, condition := range req.ActionMessage {
-		actionMessage[i] = custom_types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []custom_types.Action
+	if len(req.ActionMessage) > 0 {
+		actionMessage = make([]custom_types.Action, len(req.ActionMessage))
+		for i, condition := range req.ActionMessage {
+			actionMessage[i] = custom_types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 

+ 16 - 10
internal/logic/sop_stage/create_sop_stage_logic.go

@@ -43,19 +43,25 @@ func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.Ba
 	count, err := l.svcCtx.DB.SopStage.Query().Where(sopstage.TaskIDEQ(*req.TaskId)).Count(l.ctx)
 	count += 1
 
-	conditionList := make([]custom_types.Condition, len(req.ConditionList))
-	for i, condition := range req.ConditionList {
-		conditionList[i] = custom_types.Condition{
-			Equal:       condition.Equal,
-			LabelIdList: condition.LabelIdList,
+	var conditionList []custom_types.Condition
+	if len(req.ConditionList) > 0 {
+		conditionList = make([]custom_types.Condition, len(req.ConditionList))
+		for i, condition := range req.ConditionList {
+			conditionList[i] = custom_types.Condition{
+				Equal:       condition.Equal,
+				LabelIdList: condition.LabelIdList,
+			}
 		}
 	}
 
-	actionMessage := make([]custom_types.Action, len(req.ActionMessage))
-	for i, condition := range req.ActionMessage {
-		actionMessage[i] = custom_types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []custom_types.Action
+	if len(req.ActionMessage) > 0 {
+		actionMessage = make([]custom_types.Action, len(req.ActionMessage))
+		for i, condition := range req.ActionMessage {
+			actionMessage[i] = custom_types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 

+ 18 - 11
internal/logic/sop_stage/get_sop_stage_by_id_logic.go

@@ -36,24 +36,31 @@ func (l *GetSopStageByIdLogic) GetSopStageById(req *types.IDReq) (*types.SopStag
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	conditionList := make([]types.Condition, len(data.ConditionList))
-	for i, condition := range data.ConditionList {
-		conditionList[i] = types.Condition{
-			Equal:       condition.Equal,
-			LabelIdList: condition.LabelIdList,
+	var conditionList []types.Condition
+	if len(data.ConditionList) > 0 {
+		conditionList = make([]types.Condition, len(data.ConditionList))
+		for i, condition := range data.ConditionList {
+			conditionList[i] = types.Condition{
+				Equal:       condition.Equal,
+				LabelIdList: condition.LabelIdList,
+			}
 		}
 	}
 
-	actionMessage := make([]types.Action, len(data.ActionMessage))
-	for i, condition := range data.ActionMessage {
-		actionMessage[i] = types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []types.Action
+	if len(data.ActionMessage) > 0 {
+		actionMessage = make([]types.Action, len(data.ActionMessage))
+		for i, condition := range data.ActionMessage {
+			actionMessage[i] = types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 
-	nodeList := make([]types.SopNodeInfo, 0)
+	var nodeList []types.SopNodeInfo
 	if data.Edges.StageNodes != nil {
+		nodeList = make([]types.SopNodeInfo, 0)
 		for _, sn := range data.Edges.StageNodes {
 			nodeList = append(nodeList, types.SopNodeInfo{
 				BaseIDInfo: types.BaseIDInfo{

+ 16 - 10
internal/logic/sop_stage/get_sop_stage_detail_logic.go

@@ -35,19 +35,25 @@ func (l *GetSopStageDetailLogic) GetSopStageDetail(req *types.IDReq) (resp *type
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	conditionList := make([]types.Condition, len(data.ConditionList))
-	for i, condition := range data.ConditionList {
-		conditionList[i] = types.Condition{
-			Equal:       condition.Equal,
-			LabelIdList: condition.LabelIdList,
+	var conditionList []types.Condition
+	if len(data.ConditionList) > 0 {
+		conditionList = make([]types.Condition, len(data.ConditionList))
+		for i, condition := range data.ConditionList {
+			conditionList[i] = types.Condition{
+				Equal:       condition.Equal,
+				LabelIdList: condition.LabelIdList,
+			}
 		}
 	}
 
-	actionMessage := make([]types.Action, len(data.ActionMessage))
-	for i, condition := range data.ActionMessage {
-		actionMessage[i] = types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []types.Action
+	if len(data.ActionMessage) > 0 {
+		actionMessage = make([]types.Action, len(data.ActionMessage))
+		for i, condition := range data.ActionMessage {
+			actionMessage[i] = types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}
 

+ 16 - 10
internal/logic/sop_stage/get_sop_stage_list_logic.go

@@ -45,19 +45,25 @@ func (l *GetSopStageListLogic) GetSopStageList(req *types.SopStageListReq) (*typ
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
-		conditionList := make([]types.Condition, len(v.ConditionList))
-		for i, condition := range v.ConditionList {
-			conditionList[i] = types.Condition{
-				Equal:       condition.Equal,
-				LabelIdList: condition.LabelIdList,
+		var conditionList []types.Condition
+		if len(v.ConditionList) > 0 {
+			conditionList = make([]types.Condition, len(v.ConditionList))
+			for i, condition := range v.ConditionList {
+				conditionList[i] = types.Condition{
+					Equal:       condition.Equal,
+					LabelIdList: condition.LabelIdList,
+				}
 			}
 		}
 
-		actionMessage := make([]types.Action, len(v.ActionMessage))
-		for i, condition := range v.ActionMessage {
-			actionMessage[i] = types.Action{
-				Type:    condition.Type,
-				Content: condition.Content,
+		var actionMessage []types.Action
+		if len(v.ActionMessage) > 0 {
+			actionMessage = make([]types.Action, len(v.ActionMessage))
+			for i, condition := range v.ActionMessage {
+				actionMessage[i] = types.Action{
+					Type:    condition.Type,
+					Content: condition.Content,
+				}
 			}
 		}
 

+ 16 - 10
internal/logic/sop_stage/update_sop_stage_logic.go

@@ -41,19 +41,25 @@ func (l *UpdateSopStageLogic) UpdateSopStage(req *types.SopStageInfo) (*types.Ba
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	conditionList := make([]custom_types.Condition, len(req.ConditionList))
-	for i, condition := range req.ConditionList {
-		conditionList[i] = custom_types.Condition{
-			Equal:       condition.Equal,
-			LabelIdList: condition.LabelIdList,
+	var conditionList []custom_types.Condition
+	if len(req.ConditionList) > 0 {
+		conditionList = make([]custom_types.Condition, len(req.ConditionList))
+		for i, condition := range req.ConditionList {
+			conditionList[i] = custom_types.Condition{
+				Equal:       condition.Equal,
+				LabelIdList: condition.LabelIdList,
+			}
 		}
 	}
 
-	actionMessage := make([]custom_types.Action, len(req.ActionMessage))
-	for i, condition := range req.ActionMessage {
-		actionMessage[i] = custom_types.Action{
-			Type:    condition.Type,
-			Content: condition.Content,
+	var actionMessage []custom_types.Action
+	if len(req.ActionMessage) > 0 {
+		actionMessage = make([]custom_types.Action, len(req.ActionMessage))
+		for i, condition := range req.ActionMessage {
+			actionMessage[i] = custom_types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
 		}
 	}