作者 tangxuhui

添加 消息设置

... ... @@ -17,7 +17,7 @@ func NewCommonService(options map[string]interface{}) *CommonService {
//GetDictionaryByCode 根据code获取字典数据
func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic()
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(0, 0, 0)
result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
DictCode: getDictionaryQuery.DictCode,
})
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//更新自定义菜单
type MenuUpdateCommand struct {
//操作人
Operator domain.Operator `json:"-"`
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//获取自定义菜单列表
type MenuListQuery struct {
//操作人
Operator domain.Operator `json:"-"`
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type NoticeSettingAddCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 消息对应的业务模块
Module string `json:"module" valid:"Required"`
// 业务环节
ModuleAction string `json:"moduleAction" valid:"Required"`
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush" valid:"Required"`
// 内容模板
Content string `json:"content" valid:"Required"`
}
func (noticeSettingUpdateQuery *NoticeSettingAddCommand) Valid(validation *validation.Validation) {
}
func (noticeSettingUpdateQuery *NoticeSettingAddCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(noticeSettingUpdateQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type NoticeSettingUpdateCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// id
NoticeSettingId string `json:"noticeSetting"`
// 消息对应的业务模块
Module string `json:"module" valid:"Required"`
// 业务环节
ModuleAction string `json:"moduleAction" valid:"Required"`
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush" valid:"Required"`
// 内容模板
Content string `json:"content" valid:"Required"`
}
func (noticeSettingUpdateQuery *NoticeSettingUpdateCommand) Valid(validation *validation.Validation) {
}
func (noticeSettingUpdateQuery *NoticeSettingUpdateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(noticeSettingUpdateQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type NoticeSettingListQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 查询偏离量
PageNumber int `json:"pageNumber" valid:"Required"`
// 查询限制
PageSize int `json:"pageSize" valid:"Required"`
}
func (noticeSettingListCommand *NoticeSettingListQuery) Valid(validation *validation.Validation) {
}
func (noticeSettingListCommand *NoticeSettingListQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(noticeSettingListCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type NoticeSettingProfileQuery struct {
//操作人
Operator domain.Operator `json:"-"`
}
func (noticeSettingProfileQuery *NoticeSettingProfileQuery) Valid(validation *validation.Validation) {
}
func (noticeSettingProfileQuery *NoticeSettingProfileQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(noticeSettingProfileQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/command"
"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"
)
// 推送消息配置
type NoticeSettingService struct {
}
//NoticeSettingList 推送消息配置列表
func (noticeSettingService *NoticeSettingService) NoticeSettingList(noticeSettingListQuery *query.NoticeSettingListQuery) (int64, interface{}, error) {
if err := noticeSettingListQuery.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
noticeSettingListQuery.Operator.CompanyId,
noticeSettingListQuery.Operator.OrgId,
noticeSettingListQuery.Operator.UserId)
result, err := creationBasicGateway.NoticeSettingSearch(allied_creation_basic.ReqNoticeSettingSearch{
PageIndex: noticeSettingListQuery.PageNumber,
PageSize: noticeSettingListQuery.PageSize,
CompanyId: noticeSettingListQuery.Operator.CompanyId,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result.Count, result.NoticeSettings, nil
}
//NoticeSettingProfile 推送消息配置需求的参数候选项
func (noticeSettingService *NoticeSettingService) NoticeSettingProfile(noticeSettingProfileQuery *query.NoticeSettingProfileQuery) (interface{}, error) {
if err := noticeSettingProfileQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
return nil, nil
}
// NoticeSettingUpdate 更新配置
func (noticeSettingService *NoticeSettingService) NoticeSettingUpdate(noticeSettingUpdateCommand *command.NoticeSettingUpdateCommand) (interface{}, error) {
if err := noticeSettingUpdateCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
noticeSettingUpdateCommand.Operator.CompanyId,
noticeSettingUpdateCommand.Operator.OrgId,
noticeSettingUpdateCommand.Operator.UserId)
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,
OrganizationID: int(noticeSettingUpdateCommand.Operator.OrgId),
})
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) {
if err := noticeSettingAddCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
noticeSettingAddCommand.Operator.CompanyId,
noticeSettingAddCommand.Operator.OrgId,
noticeSettingAddCommand.Operator.UserId)
result, err := creationBasicGateway.NoticeSettingAdd(allied_creation_basic.ReqNoticeSettingAdd{
CompanyID: int(noticeSettingAddCommand.Operator.CompanyId),
Content: noticeSettingAddCommand.Content,
IsPush: noticeSettingAddCommand.IsPush,
Module: noticeSettingAddCommand.Module,
ModuleAction: noticeSettingAddCommand.ModuleAction,
OrganizationID: int(noticeSettingAddCommand.Operator.OrgId),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
data := struct {
NoticeSettingId int `json:"noticeSettingId"`
command.NoticeSettingAddCommand
}{
NoticeSettingId: result.NoticeSettingID,
NoticeSettingAddCommand: *noticeSettingAddCommand,
}
return data, nil
}
func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
newNoticeSettingService := &NoticeSettingService{}
return newNoticeSettingService
}
... ...
... ... @@ -13,14 +13,16 @@ type HttplibAlliedCreationBasic struct {
baseUrL string
}
var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
func NewHttplibAlliedCreationBasic(companyId int64, orgId int64, userId int64) *HttplibAlliedCreationBasic {
return &HttplibAlliedCreationBasic{
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
CompanyId: companyId,
OrgId: orgId,
UserId: userId,
},
baseUrL: constant.ALLIED_CREATION_BASIC_HOST,
}
baseUrL: constant.ALLIED_CREATION_USER_HOST,
}
func NewHttplibAlliedCreationBasic() *HttplibAlliedCreationBasic {
return alliedCreationBasicClient
}
... ...
package allied_creation_basic
import (
"encoding/json"
"fmt"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
// NoticeSettingUpdate 更新消息模板
func (gateway HttplibAlliedCreationBasic) NoticeSettingUpdate(param ReqNoticeSettingUpdate) (*DataNoticeSettingUpdate, error) {
url := gateway.baseUrL + "/notice-setting"
method := "PUT"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向基础模块请求数据:更新消息模板。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求更新消息模板失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取更新消息模板失败:%w", err)
}
log.Logger.Debug("获取基础模块请求数据:更新消息模板。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析更新消息模板:%w", err)
}
var data DataNoticeSettingUpdate
err = gateway.GetResponseData(result, &data)
return &data, err
}
// NoticeSettingAdd 添加化消息模板
func (gateway HttplibAlliedCreationBasic) NoticeSettingAdd(param ReqNoticeSettingAdd) (*DataNoticeSettingAdd, error) {
url := gateway.baseUrL + "/notice-setting"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向基础模块请求数据:添加化消息模板。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求添加化消息模板失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取添加化消息模板失败:%w", err)
}
log.Logger.Debug("获取基础模块请求数据:添加化消息模板。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析添加化消息模板:%w", err)
}
var data DataNoticeSettingAdd
err = gateway.GetResponseData(result, &data)
return &data, err
}
// NoticeSettingGet 返回编排消息通知内容
func (gateway HttplibAlliedCreationBasic) NoticeSettingGet(param ReqNoticeSettingGet) (*DataNoticeSettingGet, error) {
url := gateway.baseUrL + "/notice-setting/" + strconv.Itoa(param.SettingId)
method := "GET"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向基础模块请求数据:返回编排消息通知内容。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求返回编排消息通知内容失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取返回编排消息通知内容失败:%w", err)
}
log.Logger.Debug("获取基础模块请求数据:返回编排消息通知内容。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析返回编排消息通知内容:%w", err)
}
var data DataNoticeSettingGet
err = gateway.GetResponseData(result, &data)
return &data, err
}
// NoticeSettingSearch 返回编排消息通知内容列表
func (gateway HttplibAlliedCreationBasic) NoticeSettingSearch(param ReqNoticeSettingSearch) (*DataNoticeSettingSearch, error) {
url := gateway.baseUrL + "/notice-setting/search"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向基础模块请求数据:返回编排消息通知内容列表。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求返回编排消息通知内容列表失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取返回编排消息通知内容列表失败:%w", err)
}
log.Logger.Debug("获取基础模块请求数据:返回编排消息通知内容列表。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析返回编排消息通知内容列表:%w", err)
}
var data DataNoticeSettingSearch
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_basic
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
//ReqGetDictionarysByCode 根据code获取字典数据
type ReqGetDictionaryByCode struct {
DictCode []string `json:"dictCode"`
}
//DataGetDictionarysByCode 根据code获取字典数据
type DataGetDictionaryByCode struct {
Dictionarys []domain.Dictionary `json:"dictionarys"`
}
package allied_creation_basic
//ReqGetDictionarysByCode 根据code获取字典数据
type ReqGetDictionaryByCode struct {
DictCode []string `json:"dictCode"`
}
//DataGetDictionarysByCode 根据code获取字典数据
type DataGetDictionaryByCode struct {
Dictionarys []struct {
// 字典编号 主键
DictionaryId int64 `json:"dictionaryId"`
// 字典编码
DictCode string `json:"dictCode"`
// 字典名称
DictName string `json:"dictName"`
// 备注信息
Describe string `json:"describe"`
// 字典值列表
DictItems []struct {
// 项编码
ItemCode string `json:"itemCode"`
// 项标签
ItemLabel string `json:"itemLabel"`
// 值
ItemValue string `json:"itemValue"`
// 是否可见【1:不可以】【2:可以】
IsShow int `json:"isShow"`
// 显示序号
Sort int `json:"sort"`
} `json:"dictItems"`
} `json:"dictionarys"`
}
... ...
package allied_creation_basic
//更新消息模板
type (
ReqNoticeSettingUpdate struct {
NoticeSettingID int `json:"noticeSettingId"`
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
OrganizationID int `json:"organizationId"`
}
DataNoticeSettingUpdate struct {
NoticeSettingID int `json:"noticeSettingId"`
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
OrganizationID int `json:"organizationId"`
}
)
//添加化消息模板
type (
ReqNoticeSettingAdd struct {
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
OrganizationID int `json:"organizationId"`
}
DataNoticeSettingAdd struct {
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
NoticeSettingID int `json:"noticeSettingId"`
OrganizationID int `json:"organizationId"`
}
)
//返回编排消息通知内容
type (
ReqNoticeSettingGet struct {
SettingId int `json:"settingId"`
}
DataNoticeSettingGet struct {
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
NoticeSettingID int `json:"noticeSettingId"`
OrganizationID int `json:"organizationId"`
SysCode string `json:"sysCode"`
}
)
//返回编排消息通知内容列表
type (
ReqNoticeSettingSearch struct {
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
CompanyId int64 `json:"companyId"`
}
DataNoticeSettingSearch struct {
Count int64 `json:"count"`
NoticeSettings []struct {
CompanyID int `json:"companyId"`
Content string `json:"content"`
IsPush int `json:"isPush"`
Module string `json:"module"`
ModuleAction string `json:"moduleAction"`
NoticeSettingID int `json:"noticeSettingId"`
OrganizationID int `json:"organizationId"`
SysCode string `json:"sysCode"`
} `json:"noticeSettings"`
}
)
... ...
... ... @@ -4,6 +4,7 @@ package allied_creation_user
type (
ReqFavoriteMenusUpdate struct {
UserId int64 `json:"userId"`
FavoriteMenus []string `json:"favoriteMenus"`
}
DataFavoriteMenusUpdate struct {
... ... @@ -28,5 +29,6 @@ type (
}
DataFavoriteMenusGet struct {
FavoriteMenus []string `json:"favoriteMenus"`
}
)
... ...
package web_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/noticesetting/service"
)
type NoticeSettingController struct {
baseController
}
func (controller *NoticeSettingController) NoticeSettingList() {
noticeSettingService := service.NewNoticeSettingService(nil)
noticeSettingListQuery := &query.NoticeSettingListQuery{}
controller.Unmarshal(noticeSettingListQuery)
noticeSettingListQuery.Operator = controller.GetOperator()
cnt, data, err := noticeSettingService.NoticeSettingList(noticeSettingListQuery)
controller.returnPageListData(cnt, data, err, noticeSettingListQuery.PageNumber)
}
func (controller *NoticeSettingController) NoticeSettingProfile() {
noticeSettingService := service.NewNoticeSettingService(nil)
noticeSettingProfileQuery := &query.NoticeSettingProfileQuery{}
noticeSettingProfileQuery.Operator = controller.GetOperator()
data, err := noticeSettingService.NoticeSettingProfile(noticeSettingProfileQuery)
controller.Response(data, err)
}
func (controller *NoticeSettingController) NoticeSettingUpdate() {
noticeSettingService := service.NewNoticeSettingService(nil)
noticeSettingUpdateCommand := &command.NoticeSettingUpdateCommand{}
controller.Unmarshal(noticeSettingUpdateCommand)
noticeSettingUpdateCommand.Operator = controller.GetOperator()
data, err := noticeSettingService.NoticeSettingUpdate(noticeSettingUpdateCommand)
controller.Response(data, err)
}
func (controller *NoticeSettingController) NoticeSettingAdd() {
noticeSettingService := service.NewNoticeSettingService(nil)
noticeSettingAddCommand := &command.NoticeSettingAddCommand{}
controller.Unmarshal(noticeSettingAddCommand)
noticeSettingAddCommand.Operator = controller.GetOperator()
data, err := noticeSettingService.NoticeSettingAdd(noticeSettingAddCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
func init() {
web.Router("/v1/web/notice-setting/search", &web_client.NoticeSettingController{}, "Post:NoticeSettingList")
web.Router("/v1/web/notice-setting/profile", &web_client.NoticeSettingController{}, "Get:NoticeSettingProfile")
web.Router("/v1/web/notice-setting/", &web_client.NoticeSettingController{}, "Put:NoticeSettingUpdate")
}
... ...