| 149 | } |
| 150 | |
| 151 | func (i *imlImportConfigController) importServices(ctx context.Context) error { |
| 152 | data, err := unmarshal[service_dto.ExportService]("service") |
| 153 | if err != nil { |
| 154 | return err |
| 155 | } |
| 156 | for _, d := range data { |
| 157 | // 判断是否存在,如果存在,则更新 |
| 158 | _, err = i.serviceModule.Get(ctx, d.Id) |
| 159 | if err != nil { |
| 160 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 161 | return err |
| 162 | } |
| 163 | _, err = i.serviceModule.Create(ctx, d.Team, &service_dto.CreateService{ |
| 164 | Id: d.Id, |
| 165 | Name: d.Name, |
| 166 | Prefix: d.Prefix, |
| 167 | Description: d.Description, |
| 168 | ServiceType: d.ServiceType, |
| 169 | Logo: d.Logo, |
| 170 | Tags: d.Tags, |
| 171 | Catalogue: d.Catalogue, |
| 172 | }) |
| 173 | if err != nil { |
| 174 | return fmt.Errorf("create service(%s) error: %v", d.Id, err) |
| 175 | } |
| 176 | } else { |
| 177 | _, err = i.serviceModule.Edit(ctx, d.Id, &service_dto.EditService{ |
| 178 | Name: &d.Name, |
| 179 | Description: &d.Description, |
| 180 | ServiceType: &d.ServiceType, |
| 181 | Catalogue: &d.Catalogue, |
| 182 | Logo: &d.Logo, |
| 183 | Tags: &d.Tags, |
| 184 | }) |
| 185 | if err != nil { |
| 186 | return fmt.Errorf("update service(%s) error: %v", d.Id, err) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | //err = i.serviceModule.SaveServiceDoc(ctx, d.Id, &service_dto.SaveServiceDoc{Doc: d.Doc}) |
| 191 | //if err != nil { |
| 192 | // return fmt.Errorf("save service(%s) doc error: %v", d.Id, err) |
| 193 | //} |
| 194 | } |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | func (i *imlImportConfigController) importApplications(ctx context.Context) error { |
| 199 | data, err := unmarshal[service_dto.ExportApp]("app") |