|
@@ -17,6 +17,10 @@ type UserController struct {
|
|
|
BaseCommonController
|
|
|
}
|
|
|
|
|
|
+type UserAuthController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
// @Title 用户登录接口
|
|
|
// @Description 用户登录
|
|
|
// @Param request body models.LoginReq true "type json string"
|
|
@@ -264,3 +268,110 @@ func (this *UserController) GetVerifyCode() {
|
|
|
br.Success = true
|
|
|
br.Msg = "发送成功"
|
|
|
}
|
|
|
+
|
|
|
+// @Title 新增报告浏览记录
|
|
|
+// @Description 新增报告浏览记录接口
|
|
|
+// @Param request body models.ReportRecordReq true "type json string"
|
|
|
+// @Success 200 新增成功
|
|
|
+// @router /addReportRecord [post]
|
|
|
+func (this *UserAuthController) AddReportRecord() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req request.ReportRecordReq
|
|
|
+ if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ items, err := models.GetChartPermissionChapterMappingByReportId(req.ReportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "添加阅读记录失败"
|
|
|
+ br.ErrMsg = "获取研报品种错误,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartPermissionList, err := services.GetChartPermissionAllList()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "添加阅读记录失败"
|
|
|
+ br.ErrMsg = "获取研报品种列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartMap := make(map[int]*services.ChartPermission)
|
|
|
+ for _, permission := range chartPermissionList.Data {
|
|
|
+ chartMap[permission.ChartPermissionId] = permission
|
|
|
+ }
|
|
|
+ curTime := time.Now()
|
|
|
+ insertIds := make([]int64, 0)
|
|
|
+ if len(req.RecordId) <= 0 {
|
|
|
+ // 如果不存在就新增一条记录
|
|
|
+ for _, item := range items {
|
|
|
+ curPermission := chartMap[item.ChartPermissionId]
|
|
|
+ userReadRecord := &models.UserReadRecord{
|
|
|
+ UserId: user.UserId,
|
|
|
+ ReportId: req.ReportId,
|
|
|
+ ReportTittle: req.ReportTittle,
|
|
|
+ ChartPermissionId1: chartMap[curPermission.ParentId].ChartPermissionId,
|
|
|
+ ChartPermissionId2: curPermission.ChartPermissionId,
|
|
|
+ ChartPermissionName: curPermission.PermissionName,
|
|
|
+ ClassifyId1: req.ClassifyIdFirst,
|
|
|
+ ClassifyName1: req.ClassifyNameFirst,
|
|
|
+ ClassifyId2: req.ClassifyIdSecond,
|
|
|
+ ClassifyName2: req.ClassifyNameSecond,
|
|
|
+ AreaCode: user.AreaCode,
|
|
|
+ Phone: user.Phone,
|
|
|
+ Email: user.Email,
|
|
|
+ RealName: user.RealName,
|
|
|
+ CompanyName: user.Company,
|
|
|
+ Timestamp: int(curTime.Unix()),
|
|
|
+ CreateTime: curTime,
|
|
|
+ }
|
|
|
+ insertId, _ := userReadRecord.Insert()
|
|
|
+ insertIds = append(insertIds, insertId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果存在就计算停留时间
|
|
|
+ recordIds := make([]string, 0)
|
|
|
+ for _, v := range req.RecordId {
|
|
|
+ recordIds = append(recordIds, strconv.Itoa(v))
|
|
|
+ }
|
|
|
+ userRecordList, err := models.GetUserReadRecordListByRcordIds(recordIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "更新阅读记录失败"
|
|
|
+ br.ErrMsg = "更新阅读记录失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(userRecordList) == 0 {
|
|
|
+ br.Msg = "更新阅读记录不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ stayTime := curTime.Unix() - int64(userRecordList[0].Timestamp)
|
|
|
+ stayTimeStr := utils.SecondsToHMS(stayTime)
|
|
|
+ err = models.UpdateUserReadRecordByRecordIds(recordIds, int(curTime.Unix()), int(stayTime), stayTimeStr)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "更新阅读记录失败"
|
|
|
+ br.ErrMsg = "更新阅读记录失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resp := new(response.UserReadRecordResp)
|
|
|
+ resp.RecordIds = insertIds
|
|
|
+
|
|
|
+ br.Msg = "添加阅读记录成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+}
|