module_notice.go 2.3 KB
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"
)

// NoticeSettingUpdate 获取消息列表
func (gateway HttplibAlliedCreationBasic) NoticePersonal(param ReqNoticePersonal) (*DataNoticePersonal, error) {
	url := gateway.baseUrL + "/notice-personal/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 DataNoticePersonal
	err = gateway.GetResponseData(result, &data)
	return &data, err
}

// NoticeSettingAdd 消息标记已读
func (gateway HttplibAlliedCreationBasic) ReadNotice(param ReqReadNotice) (*DataReadNotice, error) {
	url := gateway.baseUrL + "/notice-personal/read"
	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 DataReadNotice
	err = gateway.GetResponseData(result, &data)
	return &data, err
}