module_system_setting.go 3.6 KB
package allied_creation_basic

import (
	"fmt"
	"github.com/linmadan/egglib-go/utils/json"

	"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-settings"
	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-settings/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-settings/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
}