Переглянути джерело

feature(400资讯): 400咨询优化:点击进入详情请增加功能按钮三个,分别为上一条、下一条、返回

likai 1 рік тому
батько
коміт
3fb6634633

+ 16 - 0
opms_parent/app/handler/cust/product_consult_record.go

@@ -97,3 +97,19 @@ func (c *ProductConsultRecordHandler) Delete(ctx context.Context, req *model.Ids
 	}
 	return nil
 }
+
+// GetOperateEntity 获取操作数据
+func (c *ProductConsultRecordHandler) GetOperateEntity(ctx context.Context, req *model.GetOperateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("ProductConsultRecordHandler.GetOperateEntity request %#v ", *req)
+	s, err := service.NewProductConsultRecordService(ctx)
+	if err != nil {
+		return err
+	}
+	data, err := s.GetOperateEntity(ctx, req)
+	if err != nil {
+		return err
+	}
+
+	rsp.Data = data
+	return nil
+}

+ 22 - 10
opms_parent/app/model/cust/product_consult_record.go

@@ -23,20 +23,20 @@ type ProductConsultRecordListReq struct {
 }
 
 type ProductConsultRecordAddReq struct {
-	Code         string      `json:"code"`                                     // 序号
+	Code         string      `json:"code"`                              // 序号
 	ConsultTime  *gtime.Time `json:"consultTime"  v:"required#请输入日期时间"` // 日期时间
-	ProvinceId   int         `json:"provinceId"`                               // 所在省ID
-	Province     string      `json:"province"`                                 // 所在省
-	CityId       int         `json:"cityId"`                                   // 所在市ID
-	City         string      `json:"city"`                                     // 所在市
+	ProvinceId   int         `json:"provinceId"`                        // 所在省ID
+	Province     string      `json:"province"`                          // 所在省
+	CityId       int         `json:"cityId"`                            // 所在市ID
+	City         string      `json:"city"`                              // 所在市
 	Unit         string      `json:"unit" v:"required#请输入单位名称"`         // 单位名称
-	Name         string      `json:"name" v:"required#请输入联系人"`           // 联系人
+	Name         string      `json:"name" v:"required#请输入联系人"`          // 联系人
 	Contact      string      `json:"contact" v:"required#请输入联系方式"`      // 联系方式
 	Product      string      `json:"product" v:"required#请输入咨询产品"`      // 咨询产品
-	InchargeId   int         `json:"inchargeId" v:"required#请输入对接人"`     // 对接人ID
-	InchargeName string      `json:"inchargeName"`                             // 对接人(销售工程师)
-	Content      string      `json:"content"`                                  // 内容
-	Remark       string      `json:"remark"`                                   // 备注
+	InchargeId   int         `json:"inchargeId" v:"required#请输入对接人"`    // 对接人ID
+	InchargeName string      `json:"inchargeName"`                      // 对接人(销售工程师)
+	Content      string      `json:"content"`                           // 内容
+	Remark       string      `json:"remark"`                            // 备注
 }
 
 type ProductConsultRecordUpdateReq struct {
@@ -78,3 +78,15 @@ type FollowUpReq struct {
 	NboName               string `json:"nboName"`               // 项目名称
 	FollowCommunicateCase string `json:"followCommunicateCase"` // 10、信息有效,可继续跟进,转C类订单;20、信息有效,可转为储备用户;30、信息无效,不再跟进。
 }
+
+type GetOperateReq struct {
+	Id          int         `json:"id" v:"required#请输入Id"` // 当前Id
+	OperateType string      `json:"operateType"`           // 操作类型
+	CreatedTime *gtime.Time `json:"createdTime"`           // 创建日期
+}
+
+type GetOperateRsp struct {
+	Id      int  `json:"id"`
+	HasLast bool `json:"hasLast"`
+	HasNext bool `json:"hasNext"`
+}

+ 103 - 1
opms_parent/app/service/cust/product_consult_record.go

@@ -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
+}