package allied_creation_cooperation 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" ) // CooperationProjectAdd 创建共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectAdd(param ReqCooperationProjectAdd) (*DataCooperationProjectAdd, error) { url := gateway.baseUrL + "/cooperation-projects" 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 DataCooperationProjectAdd err = gateway.GetResponseData(result, &data) return &data, err } // CooperationProjectList 返回共创项目列表 func (gateway HttplibAlliedCreationCooperation) CooperationProjectList(param ReqCooperationProjectList) (*DataCooperationProjectList, error) { url := gateway.baseUrL + "/cooperation-projects" 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 DataCooperationProjectList err = gateway.GetResponseData(result, &data) return &data, err } // Cooperation-projects[cooperationProjectId} 返回共创项目详情 func (gateway HttplibAlliedCreationCooperation) CooperationProjectGet(param ReqCooperationProjectGet) (*DataCooperationProjectGet, error) { url := gateway.baseUrL + "/cooperation-projects/" + strconv.Itoa(param.CooperationProjectId) method := "GET" req := gateway.CreateRequest(url, method) if len(param.CooperationProjectNumber) > 0 { req.Param("cooperationProjectNumber", param.CooperationProjectNumber) } 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 DataCooperationProjectGet err = gateway.GetResponseData(result, &data) return &data, err } // CooperationProjectUpdate 更新共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectUpdate(param ReqCooperationProjectUpdate) (*DataCooperationProjectUpdate, error) { url := gateway.baseUrL + "/cooperation-projects/" + param.CooperationProjectId 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 DataCooperationProjectUpdate err = gateway.GetResponseData(result, &data) return &data, err } //CooperationProjectRemove 移除共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectRemove(param ReqCooperationProjectRemove) (*DataCooperationProjectRemove, error) { url := gateway.baseUrL + "/cooperation-projects/" + strconv.Itoa(param.CooperationProjectID) method := "DELETE" 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 DataCooperationProjectRemove err = gateway.GetResponseData(result, &data) return &data, err } // CooperationProjectsRelease发布共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectsRelease(param ReqCooperationProjectsRelease) (*DataCooperationProjectsRelease, error) { url := gateway.baseUrL + "/cooperation-projects/release-cooperation-project" 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 DataCooperationProjectsRelease err = gateway.GetResponseData(result, &data) return &data, err } //CooperationProjectsSearch 查询共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectsSearch(param ReqCooperationProjectSearch) (*DataCooperationProjectSearch, error) { url := gateway.baseUrL + "/cooperation-projects/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 DataCooperationProjectSearch err = gateway.GetResponseData(result, &data) return &data, err } // CooperationProjectsCheck 判断当前勾选的承接对象是否存在用户 func (gateway HttplibAlliedCreationCooperation) CooperationProjectsCheck(param ReqCooperationProjectsCheck) (*DataCooperationProjectsCheck, error) { url := gateway.baseUrL + "/cooperation-projects/check" 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 DataCooperationProjectsCheck err = gateway.GetResponseData(result, &data) return &data, err } //CooperationProjectBatchEnd 批量结束共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectBatchEnd(param ReqCooperationProjectBatchEnd) (*DataCooperationProjectBatchEnd, error) { url := gateway.baseUrL + "/cooperation-projects/batch-end" 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 DataCooperationProjectBatchEnd err = gateway.GetResponseData(result, &data) return &data, err } //CooperationProjectBatchEnd 批量结束共创项目 func (gateway HttplibAlliedCreationCooperation) CooperationProjectEnd(param ReqCooperationProjectEnd) (*DataCooperationProjectEnd, error) { url := gateway.baseUrL + "/cooperation-projects/end" 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 DataCooperationProjectEnd err = gateway.GetResponseData(result, &data) return &data, err }