|
|
@@ -81,7 +81,7 @@ func (s ProductConsultRecordService) List(ctx context.Context, req *model.Produc
|
|
|
if req.PageNum != 0 {
|
|
|
dao = dao.Page(req.GetPage())
|
|
|
}
|
|
|
- orderby := "created_time desc"
|
|
|
+ orderby := "id DESC"
|
|
|
if req.OrderBy != "" {
|
|
|
orderby = req.OrderBy
|
|
|
}
|
|
|
@@ -252,3 +252,105 @@ func (s ProductConsultRecordService) Delete(ctx context.Context, id []int) error
|
|
|
_, err := s.Dao.Where("Id IN (?)", id).Delete()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+func (s ProductConsultRecordService) GetOperateEntity(ctx context.Context, req *model.GetOperateReq) (*model.GetOperateRsp, error) {
|
|
|
+ // 数据校验
|
|
|
+ if req.Id == 0 {
|
|
|
+ return nil, myerrors.TipsError("Id缺失,查询失败")
|
|
|
+ }
|
|
|
+ if req.CreatedTime == nil {
|
|
|
+ return nil, myerrors.TipsError("日期缺失,查询失败")
|
|
|
+ }
|
|
|
+ if req.OperateType != "Last" && req.OperateType != "Now" && req.OperateType != "Next" {
|
|
|
+ return nil, myerrors.TipsError("操作类型参数错误,查询失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ var rsp model.GetOperateRsp
|
|
|
+ limit := 1
|
|
|
+ where := ""
|
|
|
+ orderBy := ""
|
|
|
+ switch req.OperateType {
|
|
|
+ case "Last":
|
|
|
+ limit = 2
|
|
|
+ where = fmt.Sprintf("id>=%v AND created_time>='%v'", req.Id, req.CreatedTime)
|
|
|
+ orderBy = "id ASC"
|
|
|
+ case "Now":
|
|
|
+ // 判断是否存在上一条、下一条数据,并直接返回数据
|
|
|
+ var err error
|
|
|
+ rsp.HasLast, rsp.HasNext, err = s.getExistLastNext(req)
|
|
|
+ rsp.Id = req.Id
|
|
|
+ return &rsp, err
|
|
|
+ case "Next":
|
|
|
+ limit = 2
|
|
|
+ where = fmt.Sprintf("id<=%v AND created_time<='%v'", req.Id, req.CreatedTime)
|
|
|
+ orderBy = "id DESC"
|
|
|
+ }
|
|
|
+
|
|
|
+ consultDao := &s.Dao.ProductConsultRecordDao
|
|
|
+ // 权限限制(销售工程师看自己的)
|
|
|
+ if service.StringsContains(s.userInfo.Roles, "SalesEngineer") {
|
|
|
+ consultDao = consultDao.Where("incharge_id like ?", s.userInfo.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ var results []*model.ProductConsultRecord
|
|
|
+
|
|
|
+ err := consultDao.Where(where).Order(orderBy).Limit(limit).Structs(&results)
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 数据查询数据缺失
|
|
|
+ if len(results) == 0 {
|
|
|
+ return nil, myerrors.TipsError("无数据,查询失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ switch req.OperateType {
|
|
|
+ case "Last":
|
|
|
+ rsp.HasNext = true
|
|
|
+ if len(results) == 2 {
|
|
|
+ rsp.HasLast = true
|
|
|
+ rsp.Id = results[1].Id
|
|
|
+ }
|
|
|
+ case "Next":
|
|
|
+ if len(results) == 2 {
|
|
|
+ rsp.HasNext = true
|
|
|
+ rsp.Id = results[1].Id
|
|
|
+ }
|
|
|
+ rsp.HasLast = true
|
|
|
+ }
|
|
|
+
|
|
|
+ return &rsp, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取当前数据,是否存在上一条、下一条
|
|
|
+func (s ProductConsultRecordService) getExistLastNext(req *model.GetOperateReq) (bool, bool, error) {
|
|
|
+ where1 := fmt.Sprintf("id>=%v AND created_time>='%v'", req.Id, req.CreatedTime)
|
|
|
+ where2 := fmt.Sprintf("id<=%v AND created_time<='%v'", req.Id, req.CreatedTime)
|
|
|
+
|
|
|
+ consultDao1 := &s.Dao.ProductConsultRecordDao
|
|
|
+ consultDao2 := &s.Dao.ProductConsultRecordDao
|
|
|
+ // 权限限制(销售工程师看自己的)
|
|
|
+ if service.StringsContains(s.userInfo.Roles, "SalesEngineer") {
|
|
|
+ consultDao1 = consultDao1.Where("incharge_id like ?", s.userInfo.Id)
|
|
|
+ consultDao2 = consultDao2.Where("incharge_id like ?", s.userInfo.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ orderBy1 := "id ASC"
|
|
|
+ orderBy2 := "id DESC"
|
|
|
+ var results1 []*model.ProductConsultRecord
|
|
|
+ var results2 []*model.ProductConsultRecord
|
|
|
+
|
|
|
+ err := consultDao1.Where(where1).Order(orderBy1).Limit(2).Structs(&results1)
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ return false, false, err
|
|
|
+ }
|
|
|
+ err = consultDao2.Where(where2).Order(orderBy2).Limit(2).Structs(&results2)
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
+ return false, false, err
|
|
|
+ }
|
|
|
+ // 数据查询数据缺失
|
|
|
+ if len(results1) == 0 || len(results2) == 0 {
|
|
|
+ return false, false, myerrors.TipsError("无数据,查询失败")
|
|
|
+ }
|
|
|
+
|
|
|
+ return len(results1) == 2, len(results2) == 2, nil
|
|
|
+}
|