Browse Source

no message

zhangchuanxing 4 months ago
parent
commit
b7d41eefb7

+ 8 - 0
controllers/roadshow/calendar.go

@@ -1938,6 +1938,14 @@ func (this *CalendarController) Delete() {
 			this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
 			return
 		}
+		itemApiLog := new(roadshow.RsCalendarApiLog)
+		itemApiLog.CreateTime = time.Now()
+		itemApiLog.Remark = "小程序CRM手动删除"
+		itemApiLog.Url = sysUser.RealName
+		itemApiLog.Body = ""
+		itemApiLog.Result = ""
+		itemApiLog.RsCalendarResearcherId = req.RsCalendarResearcherId
+		go roadshow.AddRsCalendarApiLog(itemApiLog)
 	}
 	//`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
 	for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {

+ 34 - 0
models/roadshow/rs_calendar_api_log.go

@@ -0,0 +1,34 @@
+package roadshow
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type RsCalendarApiLog struct {
+	Id                     int       `orm:"column(id);pk"`
+	Url                    string    `description:"链接"`
+	Body                   string    `description:"请求参数"`
+	Result                 string    `description:"返回参数"`
+	CreateTime             time.Time `description:"创建时间"`
+	Remark                 string    `description:"备注说明"`
+	RsCalendarResearcherId int       `description:"表rs_calendar_researcher 主键ID"`
+}
+
+// 添加日志记录
+func AddRsCalendarApiLog(item *RsCalendarApiLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 批量添加
+func AddRsCalendarApiLogList(items []*RsCalendarApiLog) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(lenitems, items)
+	return
+}

+ 27 - 2
services/rs/calendar.go

@@ -276,6 +276,13 @@ func getCurl(urlStr string, params url.Values, num int) (body []byte, err error)
 		err = errors.New(response.Msg)
 		return
 	}
+	itemApiLog := new(roadshow.RsCalendarApiLog)
+	itemApiLog.CreateTime = time.Now()
+	itemApiLog.Remark = "小程序get请求上海接口"
+	itemApiLog.Url = getUrl
+	itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(params))
+	itemApiLog.Result = string(body)
+	go roadshow.AddRsCalendarApiLog(itemApiLog)
 	return
 }
 
@@ -339,6 +346,13 @@ func postCurl(urlStr string, form url.Values, num int) (body []byte, err error,
 		err = errors.New(response.Msg)
 		return
 	}
+	itemApiLog := new(roadshow.RsCalendarApiLog)
+	itemApiLog.CreateTime = time.Now()
+	itemApiLog.Remark = "post请求上海接口"
+	itemApiLog.Url = urlStr
+	itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(form))
+	itemApiLog.Result = string(body)
+	go roadshow.AddRsCalendarApiLog(itemApiLog)
 	return
 }
 
@@ -909,7 +923,7 @@ func SyncCalendarFromShanghai(userPhone, startDate, endDate string) (err error)
 
 		}
 	}
-
+	var itemsApiLog []*roadshow.RsCalendarApiLog
 	//上海那边已经删除了路演,这边也要同步删除
 	for _, deleteRsCalendarResearcherList := range deleteRsCalendarResearcherMap {
 		for _, deleteRsCalendarResearcher := range deleteRsCalendarResearcherList {
@@ -925,7 +939,14 @@ func SyncCalendarFromShanghai(userPhone, startDate, endDate string) (err error)
 				errMsg += fmt.Sprint("第三方日历ID:", deleteRsCalendarResearcher.ThirdCalendarId, "删除关联关系失败;err:"+tmpErr.Error(), ";")
 				continue
 			}
-
+			itemApiLog := new(roadshow.RsCalendarApiLog)
+			itemApiLog.CreateTime = time.Now()
+			itemApiLog.Remark = "小程序对比上海接口之后手动删除"
+			itemApiLog.Url = fmt.Sprint("userPhone", userPhone, "currDay", currDay, "endDate", endDate)
+			itemApiLog.Body = ""
+			itemApiLog.Result = ""
+			itemApiLog.RsCalendarResearcherId = deleteRsCalendarResearcher.RsCalendarResearcherId
+			itemsApiLog = append(itemsApiLog, itemApiLog)
 			// 更新路演的同步字段
 			//calWhereParams := make(map[string]interface{})
 			//calUpdateParams := make(map[string]interface{})
@@ -934,6 +955,10 @@ func SyncCalendarFromShanghai(userPhone, startDate, endDate string) (err error)
 			//err = roadshow.UpdateRsCalendar(calWhereParams, calUpdateParams)
 		}
 	}
+	if len(itemsApiLog) > 0 {
+		go roadshow.AddRsCalendarApiLogList(itemsApiLog)
+	}
+
 	return
 }
 

+ 9 - 0
utils/common.go

@@ -1011,3 +1011,12 @@ func GetLastDayOfQuarter(t time.Time) time.Time {
 	lastDay := time.Date(year, time.Month(nextQuarter), 1, 0, 0, 0, 0, time.UTC).AddDate(0, 1, 0).Add(-time.Second)
 	return lastDay
 }
+
+// ReplaceSpaceAndWrap 去除空格跟换行
+func ReplaceSpaceAndWrap(str string) string {
+	// 去除空格
+	str = strings.Replace(str, " ", "", -1)
+	// 去除换行符
+	str = strings.Replace(str, "\n", "", -1)
+	return str
+}