瀏覽代碼

test: 外部报告回调

hsun 5 月之前
父節點
當前提交
edada45371
共有 6 個文件被更改,包括 158 次插入6 次删除
  1. 15 1
      controllers/ppt_v2.go
  2. 1 0
      models/business_conf.go
  3. 2 0
      models/ppt_v2.go
  4. 1 1
      services/ppt_report.go
  5. 112 0
      services/report_outer.go
  6. 27 4
      services/report_v2.go

+ 15 - 1
controllers/ppt_v2.go

@@ -401,6 +401,12 @@ func (this *PptV2Controller) DeletePpt() {
 		br.ErrMsg = "删除失败,Err:" + err.Error()
 		return
 	}
+
+	// 更新报告计数
+	go func() {
+		_ = services.UpdateClassifyReportNum(pptInfo.ClassifyId)
+	}()
+
 	br.Ret = 200
 	br.Success = true
 	br.IsAddLog = true
@@ -551,6 +557,7 @@ func (this *PptV2Controller) Publish() {
 		br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)
 		return
 	}
+	stateOrigin := pptItem.State
 
 	var updateCols []string
 	updateCols = append(updateCols, "PptxUrl", "ModifyTime")
@@ -598,11 +605,18 @@ func (this *PptV2Controller) Publish() {
 		go models.AddPptV2PublishRecord(record)
 	}
 
-	// TODO:智力共享-报告回调
+	// 回调智力共享审批
 	go func() {
 		if pptItem.ReportSource != utils.ReportSourceOuter {
 			return
 		}
+		outId, _ := strconv.Atoi(pptItem.OutReportId)
+		// 若回调失败, 则恢复提交前状态(先这么处理吧,允许再次提交)
+		e = services.OuterReportCallBack(outId, pptItem.Title, req.PptxUrl, ".pptx")
+		if e != nil {
+			pptItem.State = stateOrigin
+			_ = pptItem.Update([]string{"State"})
+		}
 	}()
 
 	br.Ret = 200

+ 1 - 0
models/business_conf.go

@@ -51,6 +51,7 @@ const (
 	BusinessConfSmsJhgjVariable              = "SmsJhgjVariable"              // 聚合国际短信变量
 
 	BusinessConfEdbStopRefreshRule = "EdbStopRefreshRule" // 是否停止指标刷新规则
+	BusinessConfOuterReportApiUrl  = "OuterReportApiUrl"  // 智力共享-报告API地址
 )
 
 const (

+ 2 - 0
models/ppt_v2.go

@@ -376,6 +376,7 @@ type PptReportItem struct {
 	CreateTime       string                     `description:"创建时间"`
 	ModifyTime       string                     `description:"更新时间"`
 	FullClassify     string                     `description:"分类完整路径, /分隔"`
+	CollaborateType  int                        `description:"协作方式:1-个人;2-多人协作"`
 	CollaborateUsers []PptReportCollaborateUser `description:"协作人信息"`
 	HasAuth          bool                       `description:"是否创建人/协作人"`
 	Editor           PPTEditingCache            `description:"编辑人信息"`
@@ -410,6 +411,7 @@ func (m *PptV2) Format2ReportItem(origin *PptV2) (item *PptReportItem) {
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
 	item.AdminId = origin.AdminId
 	item.AdminRealName = origin.AdminRealName
+	item.CollaborateType = origin.CollaborateType
 	return
 }
 

+ 1 - 1
services/ppt_report.go

@@ -63,7 +63,7 @@ func UpdateClassifyReportNum(classifyId int) (err error) {
 			cond += ` AND classify_id_third = ?`
 		}
 		pars := make([]interface{}, 0)
-		pars = append(pars, classifyId, classifyId)
+		pars = append(pars, classifyId)
 		count, e := reportOb.GetCountByCondition(cond, pars)
 		if e != nil {
 			err = fmt.Errorf("获取报告计数失败, %v", e)

+ 112 - 0
services/report_outer.go

@@ -0,0 +1,112 @@
+package services
+
+import (
+	"encoding/json"
+	"eta_gn/eta_api/models"
+	"eta_gn/eta_api/utils"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"strings"
+)
+
+// OuterReportCallBackApiUrl 外部报告回调接口
+const OuterReportCallBackApiUrl = "/subject/report/writingCallback"
+
+// OuterReportCallBackRequest 外部报告回调请求
+type OuterReportCallBackRequest struct {
+	Name     string `json:"name"`
+	ReportId int    `json:"reportId"`
+	Url      string `json:"url"`
+	FileType string `json:"fileType"`
+	FileSize int    `json:"fileSize"`
+}
+
+// OuterReportCallBackResp 外部报告回调响应
+type OuterReportCallBackResp struct {
+	Code int    `json:"code"`
+	Msg  string `json:"msg"`
+	Data bool   `json:"data"`
+}
+
+// OuterReportCallBack 外部报告回调(提交审批)
+func OuterReportCallBack(outReportId int, title, fileUrl, fileType string) (err error) {
+	var params string
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("OuterReportCallBack-外部报告回调失败, Request: %s, ErrMsg: %v", params, err)
+			fmt.Println(tips)
+			utils.FileLog.Info(tips)
+		}
+	}()
+
+	// 入参
+	var req OuterReportCallBackRequest
+	req.Name = title
+	req.ReportId = outReportId
+	req.Url = fileUrl
+	req.FileType = fileType
+	b, e := json.Marshal(req)
+	if e != nil {
+		err = fmt.Errorf("请求参数JSON格式化失败, %v", e)
+		return
+	}
+	params = string(b)
+
+	// 获取地址
+	conf, e := models.GetBusinessConfByKey(models.BusinessConfOuterReportApiUrl)
+	if e != nil {
+		if utils.IsErrNoRow(e) {
+			err = fmt.Errorf("外部报告API地址未配置")
+		}
+		err = fmt.Errorf("获取外部报告API地址配置失败, %v", e)
+		return
+	}
+	if conf.ConfVal == "" {
+		err = fmt.Errorf("外部报告API地址为空")
+		return
+	}
+	requestUrl := conf.ConfVal + OuterReportCallBackApiUrl
+
+	// 请求接口
+	resByte, e := OuterReportCallBackPost(requestUrl, params, "application/json")
+	if e != nil {
+		err = fmt.Errorf("接口请求失败, %v", e)
+		return
+	}
+	var resp OuterReportCallBackResp
+	if e := json.Unmarshal(resByte, &resp); e != nil {
+		err = fmt.Errorf("响应JSON解析失败, %v", e)
+		return
+	}
+	if resp.Code != 0 {
+		err = fmt.Errorf("回调失败, Code: %d, Msg: %s", resp.Code, resp.Msg)
+		return
+	}
+	return
+}
+
+// OuterReportCallBackPost 外部报告回调POST
+func OuterReportCallBackPost(url, postData string, params ...string) ([]byte, error) {
+	body := ioutil.NopCloser(strings.NewReader(postData))
+	client := &http.Client{}
+	req, e := http.NewRequest("POST", url, body)
+	if e != nil {
+		return nil, fmt.Errorf("http request err: %v", e)
+	}
+	contentType := "application/x-www-form-urlencoded;charset=utf-8"
+	if len(params) > 0 && params[0] != "" {
+		contentType = params[0]
+	}
+	req.Header.Set("Content-Type", contentType)
+	resp, e := client.Do(req)
+	if e != nil {
+		return nil, fmt.Errorf("client do err: %v", e)
+	}
+	defer resp.Body.Close()
+	b, e := ioutil.ReadAll(resp.Body)
+	if e != nil {
+		return nil, fmt.Errorf("read body err: %v", e)
+	}
+	return b, e
+}

+ 27 - 4
services/report_v2.go

@@ -103,8 +103,12 @@ func AddReportAndChapter(reportInfo *models.Report, inheritReportId int, grantAd
 	}
 
 	// 报告权限处理
-	go handleReportPermission(reportId, minClassifyId)
+	go func() {
+		handleReportPermission(reportId, minClassifyId)
 
+		// 更新报告计数
+		_ = UpdateClassifyReportNum(minClassifyId)
+	}()
 	return
 }
 
@@ -1276,6 +1280,19 @@ func DeleteReportAndChapter(reportId int) (err error) {
 	// 重置PPT关联报告
 	go func() {
 		_ = ResetPPTReport(reportId, false)
+
+		// 更新报告计数
+		classifyId := reportInfo.ClassifyIdThird
+		if classifyId <= 0 {
+			classifyId = reportInfo.ClassifyIdSecond
+		}
+		if classifyId <= 0 {
+			classifyId = reportInfo.ClassifyIdFirst
+		}
+		if classifyId <= 0 {
+			return
+		}
+		_ = UpdateClassifyReportNum(classifyId)
 	}()
 
 	return
@@ -1495,6 +1512,7 @@ func PublishReportV2(reportId int, sysUser *system.Admin) (tips string, err erro
 		err = fmt.Errorf("外部报告状态异常, ReportId: %d, State: %d", reportId, reportInfo.State)
 		return
 	}
+	stateOrigin := reportInfo.State
 
 	// 如果有章节,那么校验章节的状态
 	chapters := make([]*models.ReportChapter, 0)
@@ -1592,13 +1610,18 @@ func PublishReportV2(reportId int, sysUser *system.Admin) (tips string, err erro
 	// 生成报告pdf和长图, 外部报告回调发起审批
 	go func() {
 		reportPdfUrl := GetGeneralPdfUrl(reportInfo.ReportCode, reportInfo.ClassifyNameFirst, reportInfo.ReportLayout)
-		_, _ = Report2pdfAndJpeg(reportPdfUrl, reportId, 1)
+		_, pdfUrl := Report2pdfAndJpeg(reportPdfUrl, reportId, 1)
 		if reportInfo.ReportSource != utils.ReportSourceOuter {
 			return
 		}
 
-		// TODO:回调智力共享
-
+		// 回调智力共享审批, 若请求失败则恢复提交前状态(先这么处理吧,允许再次提交)
+		outId, _ := strconv.Atoi(reportInfo.OutReportId)
+		e := OuterReportCallBack(outId, reportInfo.Title, pdfUrl, ".pdf")
+		if e != nil {
+			reportInfo.State = stateOrigin
+			_ = reportInfo.Update([]string{"State"})
+		}
 	}()
 	return
 }