@@ -102,7 +102,7 @@ type CreateOrderService struct {
102102 Audit * parser.TiStmt
103103}
104104
105- func (s * CreateOrderService ) generateApprovalRecords (tx * gorm.DB , orderID uuid.UUID ) error {
105+ func (s * CreateOrderService ) generateApprovalRecords (tx * gorm.DB , orderID uuid.UUID ) (datatypes. JSON , error ) {
106106 type FlowStage struct {
107107 Type string `json:"type"`
108108 Stage int `json:"stage"`
@@ -111,16 +111,25 @@ func (s *CreateOrderService) generateApprovalRecords(tx *gorm.DB, orderID uuid.U
111111 }
112112
113113 var record models.InsightApprovalFlows
114- flow := tx .Table ("insight_approval_flow_users a" ).Select (`b.definition` ).
114+ flow := tx .Table ("insight_approval_flow_users a" ).Select (`b.definition, b.claim_users ` ).
115115 Joins ("inner join insight_approval_flow b on a.approval_id = b.approval_id" ).
116116 Where ("a.username = ?" , s .Username ).Take (& record )
117117 if flow .Error != nil || flow .RowsAffected == 0 {
118- return fmt .Errorf ("未找到您的审批流配置,请联系管理员设置" )
118+ return nil , fmt .Errorf ("未找到您的审批流配置,请联系管理员设置" )
119+ }
120+
121+ claimUsers , err := parseClaimUsers (record .ClaimUsers )
122+ if err != nil {
123+ return nil , err
124+ }
125+ claimUsersJSON , err := marshalClaimUsers (claimUsers )
126+ if err != nil {
127+ return nil , err
119128 }
120129 // [{"type": "OR", "stage": 1, "approvers": ["zhangsan", "lisi"], "stage_name": "安全组审批"}, {"type": "AND", "stage": 1, "approvers": ["admin"], "stage_name": "部门负责人审批"}]
121130 var stages []FlowStage
122- if err : = json .Unmarshal (record .Definition , & stages ); err != nil {
123- return fmt .Errorf ("解析审批流JSON失败: %w" , err )
131+ if err = json .Unmarshal (record .Definition , & stages ); err != nil {
132+ return nil , fmt .Errorf ("解析审批流JSON失败: %w" , err )
124133 }
125134
126135 for _ , s := range stages {
@@ -134,11 +143,11 @@ func (s *CreateOrderService) generateApprovalRecords(tx *gorm.DB, orderID uuid.U
134143 ApprovalType : commonModels .EnumType (s .Type ),
135144 }
136145 if err := tx .Create (& audit ).Error ; err != nil {
137- return fmt .Errorf ("创建审批记录失败: %w" , err )
146+ return nil , fmt .Errorf ("创建审批记录失败: %w" , err )
138147 }
139148 }
140149 }
141- return nil
150+ return claimUsersJSON , nil
142151}
143152
144153// 审核SQL
@@ -299,10 +308,15 @@ func (s *CreateOrderService) Run() error {
299308 return err
300309 }
301310 // 生成审批流
302- err = s .generateApprovalRecords (tx , orderID )
311+ claimUsers , err : = s .generateApprovalRecords (tx , orderID )
303312 if err != nil {
304313 return err
305314 }
315+ if err := tx .Model (& models.InsightOrderRecords {}).
316+ Where ("order_id=?" , orderID ).
317+ Update ("claim_users" , claimUsers ).Error ; err != nil {
318+ return err
319+ }
306320 // 记录操作日志
307321 if err := WriteOrderLog (tx , orderID .String (), s .Username , fmt .Sprintf ("用户%s提交了工单" , s .Username )); err != nil {
308322 global .App .Log .Error ("CreateOrderService.Run error:" , err .Error ())
0 commit comments