作者 yangfu
package command
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)
type CreateDictionaryCommand struct {
//操作人
Operator domain.Operator `json:"-"`
allied_creation_basic.ReqDictionaryAdd
}
... ...
package command
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type RemoveDictionaryCommand struct {
//操作人
Operator domain.Operator `json:"-"`
DictionaryIds []string `json:"dictionaryIds"`
}
... ...
package command
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)
type UpdateDictionaryCommand struct {
//操作人
Operator domain.Operator `json:"-"`
allied_creation_basic.ReqDictionaryUpdate
}
... ...
package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type GetDictionaryQuery struct {
//操作人
Operator domain.Operator `json:"-"`
DictionaryId int `json:"dictionaryId,string"`
}
... ...
package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type ListDictionaryQuery struct {
//操作人
Operator domain.Operator `json:"-"`
Pageindex int `json:"pageIndex"` // 查询页码
PageSize int `json:"pageSize"` // 查询限制
}
... ...
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)
// 字典服务
type DictionayService struct {
}
func NewDictionayService(options map[string]interface{}) *DictionayService {
return &DictionayService{}
}
// 创建字典
func (dictionaryService *DictionayService) CreateDictionay(createCommand *command.CreateDictionaryCommand) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
createCommand.Operator)
result, err := creationBasicGateway.DictionaryAdd(allied_creation_basic.ReqDictionaryAdd{
DictCode: createCommand.DictCode,
DictName: createCommand.DictName,
Describe: createCommand.Describe,
DictItems: createCommand.DictItems,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
}
// 更新字典
func (dictionaryService *DictionayService) UpdateDictionay(updateCommand *command.UpdateDictionaryCommand) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
updateCommand.Operator)
result, err := creationBasicGateway.DictionaryUpdate(allied_creation_basic.ReqDictionaryUpdate{
DictionaryId: updateCommand.DictionaryId,
DictCode: updateCommand.DictCode,
DictName: updateCommand.DictName,
Describe: updateCommand.Describe,
DictItems: updateCommand.DictItems,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
}
//获取字典
func (dictionaryService *DictionayService) GetDictionay(getQuery *query.GetDictionaryQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
getQuery.Operator)
result, err := creationBasicGateway.DictionaryGet(allied_creation_basic.ReqDictionaryGet{
DictionaryId: getQuery.DictionaryId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
}
//获取字典
func (dictionaryService *DictionayService) RemoveDictionay(removeCommand *command.RemoveDictionaryCommand) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
removeCommand.Operator)
var dictionaryIds []int
for _, v := range removeCommand.DictionaryIds {
id, _ := strconv.Atoi(v)
dictionaryIds = append(dictionaryIds, id)
}
result, err := creationBasicGateway.DictionaryRemove(allied_creation_basic.ReqDictionaryRemove{
DictionaryIds: dictionaryIds,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
}
//获取字典
func (dictionaryService *DictionayService) ListDictionay(searchQuery *query.ListDictionaryQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
searchQuery.Operator)
result, err := creationBasicGateway.DictionarySearch(allied_creation_basic.ReqDictionarySearch{
Pageindex: searchQuery.Pageindex,
PageSize: searchQuery.PageSize,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
}
... ...
... ... @@ -3,6 +3,7 @@ package allied_creation_basic
import (
"encoding/json"
"fmt"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
... ... @@ -40,3 +41,163 @@ func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDicti
err = gateway.GetResponseData(result, &data)
return &data, err
}
//DictionaryAdd 添加字典
func (gateway HttplibAlliedCreationBasic) DictionaryAdd(param ReqDictionaryAdd) (*DataDictionaryAdd, error) {
url := gateway.baseUrL + "/dictionarys"
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataDictionaryAdd
err = gateway.GetResponseData(result, &data)
return &data, err
}
//DictionaryUpdate 更新字典
func (gateway HttplibAlliedCreationBasic) DictionaryUpdate(param ReqDictionaryUpdate) (*DataDictionaryUpdate, error) {
url := gateway.baseUrL + "/dictionarys/" + strconv.Itoa(int(param.DictionaryId))
method := "PUT"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataDictionaryUpdate
err = gateway.GetResponseData(result, &data)
return &data, err
}
//DictionaryGet 获取字典
func (gateway HttplibAlliedCreationBasic) DictionaryGet(param ReqDictionaryGet) (*DataDictionaryGet, error) {
url := gateway.baseUrL + "/dictionarys/" + strconv.Itoa(int(param.DictionaryId))
method := "GET"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataDictionaryGet
err = gateway.GetResponseData(result, &data)
return &data, err
}
//DictionaryRemove 删除字典
func (gateway HttplibAlliedCreationBasic) DictionaryRemove(param ReqDictionaryRemove) (*DataDictionaryRemove, error) {
url := gateway.baseUrL + "/dictionarys/remove"
method := "DELETE"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataDictionaryRemove
err = gateway.GetResponseData(result, &data)
return &data, err
}
//DictionarySearch 查询字典
func (gateway HttplibAlliedCreationBasic) DictionarySearch(param ReqDictionarySearch) (*DataDictionarySearch, error) {
url := gateway.baseUrL + "/dictionarys/search"
method := "POST"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataDictionarySearch
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -31,3 +31,77 @@ type DataGetDictionaryByCode struct {
} `json:"dictItems"`
} `json:"dictionarys"`
}
type Dictionary struct {
DictionaryId int64 `json:"dictionaryId,string"` // 字典编号 主键
DictCode string `json:"dictCode"` // 字典编码
DictName string `json:"dictName"` // 字典名称
Describe string `json:"describe"` // 备注信息
DictItems []DictionaryItem `json:"dictItems"` // 字典值列表
}
// 字典明细项
type DictionaryItem struct {
ItemCode string `json:"itemCode"` // 项编码
ItemLabel string `json:"itemLabel"` // 项标签
ItemValue string `json:"itemValue"` // 值
IsShow int `json:"isShow"` // 是否可见【1:不可以】【2:可以】
Sort int `json:"sort"` // 显示序号
}
type (
ReqDictionarySearch struct {
Pageindex int `json:"pageIndex"` // 查询页码
PageSize int `json:"pageSize"` // 查询限制
}
DataDictionarySearch struct {
Grid struct {
Total int `json:"total"`
PageNumber int `json:"pageNumber"`
List []Dictionary `json:"list"` // 字典值列表
} `json:"grid"`
}
)
type (
ReqDictionaryAdd struct {
DictCode string `json:"dictCode"` // 字典编码
DictName string `json:"dictName"` // 字典名称
Describe string `json:"describe"` // 备注信息
DictItems []DictionaryItem `json:"dictItems"` // 字典值列表
}
DataDictionaryAdd struct {
Dictionary
}
)
type (
ReqDictionaryUpdate struct {
DictionaryId int64 `json:"dictionaryId"` // 字典编号 主键
DictCode string `json:"dictCode"` // 字典编码
DictName string `json:"dictName"` // 字典名称
Describe string `json:"describe"` // 备注信息
DictItems []DictionaryItem `json:"dictItems"` // 字典值列表
}
DataDictionaryUpdate struct {
Dictionary
}
)
type (
ReqDictionaryGet struct {
DictionaryId int `json:"dictionaryId"`
}
DataDictionaryGet struct {
Dictionary
}
)
type (
ReqDictionaryRemove struct {
DictionaryIds []int `json:"dictionaryIds"`
}
DataDictionaryRemove struct {
}
)
... ...
... ... @@ -90,8 +90,8 @@ type (
DataNoticeSettingProfile struct {
ModuleList []struct {
ModuleCode string `json:"Code"`
Name string `json:"name"`
ModuleCode string `json:"moduleCode"`
ModuleName string `json:"moduleName"`
} `json:"moduleList"`
ModuleActionList []struct {
ModuleCode string `json:"moduleCode"`
... ...
package backgroud_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/service"
)
type DictionaryController struct {
baseController
}
func (controller *DictionaryController) CreateDictionary() {
dictionaryService := service.NewDictionayService(nil)
createCommand := &command.CreateDictionaryCommand{}
err := controller.Unmarshal(createCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
createCommand.Operator = controller.GetOperator()
data, err := dictionaryService.CreateDictionay(createCommand)
controller.Response(data, err)
}
func (controller *DictionaryController) UpdateDictionary() {
dictionaryService := service.NewDictionayService(nil)
updateCommand := &command.UpdateDictionaryCommand{}
err := controller.Unmarshal(updateCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
updateCommand.Operator = controller.GetOperator()
data, err := dictionaryService.UpdateDictionay(updateCommand)
controller.Response(data, err)
}
func (controller *DictionaryController) RemoveDictionary() {
dictionaryService := service.NewDictionayService(nil)
removeCommand := &command.RemoveDictionaryCommand{}
err := controller.Unmarshal(removeCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
removeCommand.Operator = controller.GetOperator()
data, err := dictionaryService.RemoveDictionay(removeCommand)
controller.Response(data, err)
}
func (controller *DictionaryController) GetDictionary() {
dictionaryService := service.NewDictionayService(nil)
getQuery := &query.GetDictionaryQuery{}
err := controller.Unmarshal(getQuery)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
getQuery.Operator = controller.GetOperator()
data, err := dictionaryService.GetDictionay(getQuery)
controller.Response(data, err)
}
func (controller *DictionaryController) ListDictionary() {
dictionaryService := service.NewDictionayService(nil)
listQuery := &query.ListDictionaryQuery{}
err := controller.Unmarshal(listQuery)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
listQuery.Operator = controller.GetOperator()
data, err := dictionaryService.ListDictionay(listQuery)
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/backgroud_client"
)
func init() {
web.Router("/v1/background/dictionary/", &backgroud_client.DictionaryController{}, "Post:CreateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Put:UpdateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Get:GetDictionary")
web.Router("/v1/background/dictionary/search", &backgroud_client.DictionaryController{}, "Post:ListDictionary")
web.Router("/v1/background/dictionary/remove", &backgroud_client.DictionaryController{}, "Post:RemoveDictionary")
}
... ...