123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package permission
- import (
- "encoding/json"
- logger "eta/eta_mini_ht_api/common/component/log"
- "eta/eta_mini_ht_api/common/contants"
- configService "eta/eta_mini_ht_api/domian/config"
- "eta/eta_mini_ht_api/models/eta"
- "eta/eta_mini_ht_api/task/base"
- )
- var (
- taskName base.TaskType = "ETAPermissionSyncTask"
- cron = "0/10 * * * * *"
- )
- // Execute Task ETA取研报的数据
- func (pr *PermissionTask) Execute(taskDetail *base.TaskDetail) error {
- logger.Info(contants.TaskFormat, "同步ETA品种开始")
- classifyList, err := eta.GetSyncClassifyList()
- if err != nil {
- logger.Error("获取ETA分类列表失败:%v", err)
- return err
- }
- if len(classifyList) > 0 {
- var list []byte
- list, err = json.Marshal(classifyList)
- if err == nil {
- taskDetail.Content = string(list)
- }
- var permissionClassifyMappingDTOList []configService.PermissionClassifyMappingDTO
- for _, classify := range classifyList {
- permissionClassifyMappingDTOList = append(permissionClassifyMappingDTOList, convertMapping(classify))
- }
- err = configService.SyncPermissionClassifyMapping(permissionClassifyMappingDTOList)
- if err != nil {
- logger.Error("同步ETA分类列表失败:%v", err)
- return err
- }
- }
- permissionList, err := eta.GetSyncPermissionList()
- if err != nil {
- logger.Error("获取ETA品种列表失败:%v", err)
- return err
- }
- if len(permissionList) > 0 {
- var list []byte
- list, err = json.Marshal(permissionList)
- if err == nil {
- taskDetail.Content = string(list)
- }
- var permissionDTOList []configService.PermissionDTO
- for _, permisson := range permissionList {
- permissionDTOList = append(permissionDTOList, convert(permisson))
- }
- err = configService.SyncPermission(permissionDTOList)
- if err != nil {
- logger.Error("同步ETA品种列表失败:%v", err)
- return err
- }
- }
- logger.Info(contants.TaskFormat, "同步ETA品种结束")
- return nil
- }
- type PermissionTask struct {
- }
- func convert(permission eta.ChartPermission) configService.PermissionDTO {
- return configService.PermissionDTO{
- PermissionId: permission.ChartPermissionID,
- PermissionName: permission.PermissionName,
- ParentId: permission.ParentID,
- Sort: permission.Sort,
- }
- }
- func convertMapping(permission eta.ChartPermissionSearchKeyWordMapping) configService.PermissionClassifyMappingDTO {
- return configService.PermissionClassifyMappingDTO{
- PermissionId: permission.ChartPermissionID,
- ClassifyId: permission.ClassifyID,
- }
- }
- func init() {
- permissionTask := base.NewTask(taskName, cron, new(PermissionTask), base.PROD)
- base.RegisterTask(&permissionTask)
- }
|