sync.go 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
package serverService

import "github.com/easysoft/zendata/src/model"

type SyncService struct {
	defService *DefService
	fieldService *FieldService
	rangesService *RangesService
	instancesService *InstancesService
	configService *ConfigService
	excelService *ExcelService
	textService *TextService
	referService *ReferService
	resService *ResService
}

func (s *SyncService) SyncData(mode string) { // TODO: overwrite or not
	files := s.resService.LoadRes("")

	fileMap := map[string][]model.ResFile{}
	for _, fi := range files {
		if fileMap[fi.ResType] == nil {
			fileMap[fi.ResType] = make([]model.ResFile, 0)
		}
		fileMap[fi.ResType] = append(fileMap[fi.ResType], fi)
	}

	defs := fileMap["yaml"]
	s.defService.Sync(defs)
}

func NewSyncService(
	defService *DefService,
	fieldService *FieldService,
	rangesService *RangesService,
	instancesService *InstancesService,
	configService *ConfigService,
	excelService *ExcelService,
	textService *TextService,
	referService *ReferService,
	resService *ResService) *SyncService {
	return &SyncService{
		defService: defService,
		fieldService: fieldService,
		rangesService: rangesService,
		instancesService: instancesService,
		configService: configService,
		excelService: excelService,
		textService: textService,
		referService: referService,
		resService: resService,
	}
}