审查视图

pkg/application/web/noticesetting/service/notice_setting.go 6.5 KB
tangxuhui authored
1 2 3 4 5 6 7
package service

import (
	"strconv"

	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/command"
tangxuhui authored
8
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/dto"
tangxuhui authored
9 10
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
tangxuhui authored
11
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
tangxuhui authored
12 13 14 15 16 17 18 19
)

// 推送消息配置
type NoticeSettingService struct {
}

//NoticeSettingList 推送消息配置列表
func (noticeSettingService *NoticeSettingService) NoticeSettingList(noticeSettingListQuery *query.NoticeSettingListQuery) (int64, interface{}, error) {
tangxuhui authored
20
tangxuhui authored
21
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
tangxuhui authored
22 23
		noticeSettingListQuery.Operator,
	)
tangxuhui authored
24 25 26
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
		noticeSettingListQuery.Operator,
	)
27 28 29
	var orgIds []int
	if len(noticeSettingListQuery.OrgName) > 0 {
		orgResult, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
yangfu authored
30 31
			Offset:       0,
			Limit:        100,
yangfu authored
32
			CompanyId:    int(noticeSettingListQuery.Operator.CompanyId),
yangfu authored
33
			IsOrg:        0,
yangfu authored
34
			MatchOrgName: noticeSettingListQuery.OrgName,
35
		})
tangxuhui authored
36
		if err != nil {
37 38 39 40 41 42 43 44 45
			if err != nil {
				return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
			}
		}
		if len(orgResult.Orgs) == 0 {
			return 0, []dto.NoticeSettingItem{}, nil
		}
		for _, v := range orgResult.Orgs {
			orgIds = append(orgIds, v.OrgID)
tangxuhui authored
46 47
		}
	}
48
tangxuhui authored
49
	result, err := creationBasicGateway.NoticeSettingSearch(allied_creation_basic.ReqNoticeSettingSearch{
tangxuhui authored
50 51 52 53 54
		PageIndex:        noticeSettingListQuery.PageNumber,
		PageSize:         noticeSettingListQuery.PageSize,
		CompanyId:        noticeSettingListQuery.Operator.CompanyId,
		OrgIds:           orgIds,
		ModuleActionName: noticeSettingListQuery.ModuleAction,
tangxuhui authored
55 56 57 58
	})
	if err != nil {
		return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
tangxuhui authored
59
	dataList := []dto.NoticeSettingItem{}
tangxuhui authored
60
tangxuhui authored
61
	for _, v := range result.List {
tangxuhui authored
62
tangxuhui authored
63
		item := dto.NoticeSettingItem{
tangxuhui authored
64 65 66 67 68 69 70 71
			CompanyID:        v.CompanyID,
			Content:          v.Content,
			IsPush:           v.IsPush,
			Module:           v.Module,
			ModuleAction:     v.ModuleAction,
			NoticeSettingID:  v.NoticeSettingID,
			OrgID:            v.OrgID,
			ModuleActionName: v.ModuleActionName,
tangxuhui authored
72
			AuthFlag:         v.OrgID == int(noticeSettingListQuery.Operator.OrgId),
tangxuhui authored
73
		}
tangxuhui authored
74 75 76 77 78 79
		orgData, _ := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{
			OrgId: v.OrgID,
		})
		if orgData != nil {
			item.OrgName = orgData.OrgName
		}
tangxuhui authored
80 81
		dataList = append(dataList, item)
	}
tangxuhui authored
82
tangxuhui authored
83
	return result.Count, dataList, nil
tangxuhui authored
84 85 86 87
}

//NoticeSettingProfile 推送消息配置需求的参数候选项
func (noticeSettingService *NoticeSettingService) NoticeSettingProfile(noticeSettingProfileQuery *query.NoticeSettingProfileQuery) (interface{}, error) {
tangxuhui authored
88
tangxuhui authored
89 90 91 92 93
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		noticeSettingProfileQuery.Operator,
	)
	result, err := creationBasicGateway.NoticeSettingProfile(allied_creation_basic.ReqNoticeSettingProfile{})
	return result, err
tangxuhui authored
94 95 96 97 98
}

// NoticeSettingUpdate 更新配置
func (noticeSettingService *NoticeSettingService) NoticeSettingUpdate(noticeSettingUpdateCommand *command.NoticeSettingUpdateCommand) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
tangxuhui authored
99 100
		noticeSettingUpdateCommand.Operator,
	)
tangxuhui authored
101 102 103 104 105 106 107 108 109

	noticeSettingID, _ := strconv.Atoi(noticeSettingUpdateCommand.NoticeSettingId)
	_, err := creationBasicGateway.NoticeSettingUpdate(allied_creation_basic.ReqNoticeSettingUpdate{
		NoticeSettingID: noticeSettingID,
		CompanyID:       int(noticeSettingUpdateCommand.Operator.CompanyId),
		Content:         noticeSettingUpdateCommand.Content,
		IsPush:          noticeSettingUpdateCommand.IsPush,
		Module:          noticeSettingUpdateCommand.Module,
		ModuleAction:    noticeSettingUpdateCommand.ModuleAction,
tangxuhui authored
110
		OrgId:           int(noticeSettingUpdateCommand.Operator.OrgId),
tangxuhui authored
111 112 113 114 115 116 117 118 119
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return noticeSettingUpdateCommand, nil
}

// NoticeSettingUpdate 添加配置
func (noticeSettingService *NoticeSettingService) NoticeSettingAdd(noticeSettingAddCommand *command.NoticeSettingAddCommand) (interface{}, error) {
tangxuhui authored
120
tangxuhui authored
121
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
tangxuhui authored
122 123
		noticeSettingAddCommand.Operator,
	)
tangxuhui authored
124
	result, err := creationBasicGateway.NoticeSettingAdd(allied_creation_basic.ReqNoticeSettingAdd{
tangxuhui authored
125 126 127 128 129 130
		CompanyID:    int(noticeSettingAddCommand.Operator.CompanyId),
		Content:      noticeSettingAddCommand.Content,
		IsPush:       noticeSettingAddCommand.IsPush,
		Module:       noticeSettingAddCommand.Module,
		ModuleAction: noticeSettingAddCommand.ModuleAction,
		OrgId:        int(noticeSettingAddCommand.Operator.OrgId),
tangxuhui authored
131 132 133 134 135
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	data := struct {
tangxuhui authored
136
		NoticeSettingId int `json:"noticeSettingId,string"`
tangxuhui authored
137 138 139 140 141 142 143 144
		command.NoticeSettingAddCommand
	}{
		NoticeSettingId:         result.NoticeSettingID,
		NoticeSettingAddCommand: *noticeSettingAddCommand,
	}
	return data, nil
}
tangxuhui authored
145 146
// NoticeSettingGet 获取配置
func (noticeSettingService *NoticeSettingService) NoticeSettingGet(noticeSettingGetQuery *query.NoticeSettingGetQuery) (interface{}, error) {
tangxuhui authored
147
tangxuhui authored
148 149 150 151 152 153 154 155 156 157 158
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		noticeSettingGetQuery.Operator,
	)

	noticeSettingID, _ := strconv.Atoi(noticeSettingGetQuery.NoticeSettingId)
	result, err := creationBasicGateway.NoticeSettingGet(allied_creation_basic.ReqNoticeSettingGet{
		NoticeSettingID: noticeSettingID,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
tangxuhui authored
159 160 161 162 163 164 165 166
	data := dto.NoticeSettingItem{
		CompanyID:       result.CompanyID,
		Content:         result.Content,
		IsPush:          result.IsPush,
		Module:          result.Module,
		ModuleAction:    result.ModuleAction,
		NoticeSettingID: result.NoticeSettingID,
		OrgID:           result.OrgID,
tangxuhui authored
167
		AuthFlag:        result.OrgID == int(noticeSettingGetQuery.Operator.OrgId),
tangxuhui authored
168 169
	}
	return data, nil
tangxuhui authored
170 171
}
tangxuhui authored
172 173 174 175
func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
	newNoticeSettingService := &NoticeSettingService{}
	return newNoticeSettingService
}