作者 tangxuhui

新增 系统参数设置

package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type SettingUpdateCommand struct {
//操作人
Operator domain.Operator `json:"-"`
SettingCode string `json:"settingCode" valid:"Required"`
// 设定的值
Value string `json:"value" valid:"Required"`
}
func (settingUpdate *SettingUpdateCommand) Valid(validation *validation.Validation) {
}
func (settingUpdate *SettingUpdateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(settingUpdate)
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 SettingGetQuery struct {
//操作人
Operator domain.Operator `json:"-"`
SettingCode string `json:"settingCode"`
}
func (settingGetQuery *SettingGetQuery) Valid(validation *validation.Validation) {
}
func (settingGetQuery *SettingGetQuery) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(settingGetQuery)
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 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type SettingListQuery struct {
//操作人
Operator domain.Operator `json:"-"`
}
... ...
package service
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/systemsetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/systemsetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)
// 用户信息
type SystemSettingService struct {
}
func NewSystemSettingService(options map[string]interface{}) *SystemSettingService {
newUsersService := &SystemSettingService{}
return newUsersService
}
func (srv SystemSettingService) GetSystemSettingList(systemSettingListQuery *query.SettingListQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
systemSettingListQuery.Operator,
)
result, err := creationBasicGateway.SystemSettingSearch(allied_creation_basic.ReqSystemSettingSearch{})
return result, err
}
func (srv SystemSettingService) GetSystemSetting(systemSettingGetQuery *query.SettingGetQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
systemSettingGetQuery.Operator,
)
result, err := creationBasicGateway.SystemSettingGet(allied_creation_basic.ReqSystemSettingGet{
SettingCode: systemSettingGetQuery.SettingCode,
})
return result, err
}
func (srv SystemSettingService) SystemSettingUpdate(systemSettingUpdate *command.SettingUpdateCommand) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
systemSettingUpdate.Operator,
)
result, err := creationBasicGateway.SystemSettingUpdate(allied_creation_basic.ReqSystemSettingUpdate{
SettingCode: systemSettingUpdate.SettingCode,
Value: systemSettingUpdate.Value,
CompanyId: systemSettingUpdate.Operator.CompanyId,
})
return result, err
}
... ...
package allied_creation_basic
import (
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
// SystemSetting 更新系统设置
func (gateway HttplibAlliedCreationBasic) SystemSettingUpdate(param ReqSystemSettingUpdate) (*DataSystemSettingUpdate, error) {
url := gateway.baseUrL + "/system-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 DataSystemSettingUpdate
err = gateway.GetResponseData(result, &data)
return &data, err
}
// System-settingSearch 获取企业的系统设置列表
func (gateway HttplibAlliedCreationBasic) SystemSettingSearch(param ReqSystemSettingSearch) (*DataSystemSettingSearch, error) {
url := gateway.baseUrL + "/system-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 DataSystemSettingSearch
err = gateway.GetResponseData(result, &data)
return &data, err
}
// SystemSettingGet 获取企业的系统设置项
func (gateway HttplibAlliedCreationBasic) SystemSettingGet(param ReqSystemSettingGet) (*DataSystemSettingGet, error) {
url := gateway.baseUrL + "/system-setting/get"
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 DataSystemSettingGet
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -90,15 +90,15 @@ type (
}
DataNoticeSettingProfile struct {
Module []struct {
ModuleList []struct {
ModuleCode string `json:"Code"`
Name string `json:"name"`
} `json:"module"`
ModuleAction []struct {
} `json:"moduleList"`
ModuleActionList []struct {
ModuleCode string `json:"module_code"`
ActionCode string `json:"action_Code"`
Name string `json:"name"`
} `json:"moduleAction"`
} `json:"moduleActionList"`
ParamList []struct {
// 变量的代码标识
ParamCode string `json:"paramCode"`
... ...
package allied_creation_basic
//更新系统设置
type (
ReqSystemSettingUpdate struct {
// 公司id
CompanyId int64 `json:"companyId"`
// 设定的值
Value string `json:"value"`
// 设置对应的编码
SettingCode string `json:"settingCode"`
}
DataSystemSettingUpdate struct {
}
)
//获取企业的系统设置列表
type (
ReqSystemSettingSearch struct {
}
DataSystemSettingSearch struct {
SystemSetting []struct {
// 公司id
CompanyId int64 `json:"companyId"`
// 管控层级
ControlLevel string `json:"controlLevel"`
// 描述
Description string `json:"description"`
// 设置对应的编码
SettingCode string `json:"settingCode"`
// 设置对应的名称
SettingName string `json:"settingName"`
// 数据id
SystemSettingId int64 `json:"systemSettingId"`
// 设定的值
Value string `json:"value"`
// 值类型
ValueType string `json:"valueType"`
}
}
)
//获取企业的系统设置项
type (
ReqSystemSettingGet struct {
SettingCode string `json:"settingCode"`
}
DataSystemSettingGet struct {
// 公司id
CompanyId int64 `json:"companyId"`
// 管控层级
ControlLevel string `json:"controlLevel"`
// 描述
Description string `json:"description"`
// 设置对应的编码
SettingCode string `json:"settingCode"`
// 设置对应的名称
SettingName string `json:"settingName"`
// 数据id
SystemSettingId int64 `json:"systemSettingId"`
// 设定的值
Value string `json:"value"`
// 值类型
ValueType string `json:"valueType"`
}
)
... ...
... ... @@ -48,6 +48,7 @@ func (gateway BaseServiceGateway) CreateRequest(url string, method string) *http
request.Header("companyId", strconv.FormatInt(gateway.CompanyId, 10))
request.Header("orgId", strconv.FormatInt(gateway.OrgId, 10))
request.Header("userId", strconv.FormatInt(gateway.UserId, 10))
request.Header("userBaseId", strconv.FormatInt(gateway.UserBaseId, 10))
return request.SetTimeout(gateway.ConnectTimeout, gateway.ReadWriteTimeout)
}
... ...
package web_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/systemsetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/systemsetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/systemsetting/service"
)
type SystemSettingController struct {
baseController
}
func (controller SystemSettingController) SystemSettingSearch() {
systemSettingService := service.NewSystemSettingService(nil)
q := &query.SettingListQuery{
Operator: controller.GetOperator(),
}
data, err := systemSettingService.GetSystemSettingList(q)
controller.Response(data, err)
}
func (controller SystemSettingController) SystemSettingGet() {
systemSettingService := service.NewSystemSettingService(nil)
q := &query.SettingGetQuery{}
controller.Unmarshal(q)
q.Operator = controller.GetOperator()
data, err := systemSettingService.GetSystemSetting(q)
controller.Response(data, err)
}
func (controller SystemSettingController) SystemSettingUpdate() {
systemSettingService := service.NewSystemSettingService(nil)
q := &command.SettingUpdateCommand{}
controller.Unmarshal(q)
q.Operator = controller.GetOperator()
data, err := systemSettingService.SystemSettingUpdate(q)
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/system-setting/search", &web_client.SystemSettingController{}, "Post:SystemSettingSearch")
web.Router("/v1/web/syetem-setting/:settingId", &web_client.SystemSettingController{}, "Get:SystemSettingGet")
web.Router("/v1/web/syetem-setting", &web_client.SystemSettingController{}, "Put:SystemSettingUpdate")
}
... ...