45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
|
package approval
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
api "github.com/fonchain_enterprise/fonchain-main/api/approval"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/api/position"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func processPositionApprovals(detail *api.CreateRequest) error {
|
||
|
type Position struct {
|
||
|
DepartmentID uint64 `json:"DepartmentID"`
|
||
|
DepartmentName string `json:"DepartmentName"`
|
||
|
PositionName string `json:"PositionName"`
|
||
|
}
|
||
|
var positionData Position
|
||
|
for _, approval := range detail.CustomizeInfo {
|
||
|
if strings.Contains(approval.ApprovalType, "position") {
|
||
|
fmt.Println("ApprovalValue:", approval.ApprovalValue)
|
||
|
err := json.Unmarshal([]byte(approval.ApprovalValue), &positionData)
|
||
|
if err != nil {
|
||
|
fmt.Println("Error decoding JSON:", err)
|
||
|
return errors.New("json转换失败")
|
||
|
}
|
||
|
fmt.Printf("Parsed data: %+v\n", positionData)
|
||
|
_, err = service.PositionProvider.Create(context.Background(), &position.CreateRequest{
|
||
|
Name: positionData.PositionName,
|
||
|
DepartmentID: positionData.DepartmentID,
|
||
|
Domain: "fontree",
|
||
|
Color: "#000",
|
||
|
})
|
||
|
if err != nil {
|
||
|
fmt.Println("Error creating position:", err)
|
||
|
return errors.New("岗位创建失败:")
|
||
|
}
|
||
|
}
|
||
|
continue
|
||
|
}
|
||
|
return nil
|
||
|
}
|