意图,根据条件查询
```
type ReportOrder struct {
Id int64
UserName string `json:"user_name"`
ReportType string `json:"report_type"`
ReportAddress string `json:"report_address"`
...
WorkerId int64 `json:"worker_id"`
}
```
对应的数据,然后循环这个数据,根据WorkerId查询
```
type WorkerList struct {
Id int64
WorkerName string `json:"worker_name"`
WorkerNickName string `json:"worker_nick_name"`
...
LoginTime string `json:"login_time"`
}
```
中对应的一个数据,
然后生成这样的数据返回
```
{
"Id": 23,
"user_name": "路人甲",
"report_type": "1",
"report_address": "上海市行知路",
"report_no": "W1551279888654819700",
"report_start_time": "2019-03-07T14:11:02+08:00",
"report_modification_time": "0001-01-01T00:00:00Z",
"report_phone": "17621953630",
"report_remark": "这是故障描述",
"worker_id": 1,
"worker_list":{
"id":1,
"worker_name":"路人甲"
...
}
}
```
我的代码这样的
```
func (orderSearchData *OrderData) OrderList() (report_order []*ReportOrder, err error) {
result := make([]*ReportOrder, 0)
pageSize,_:=strconv.Atoi(orderSearchData.PageSize)
page,_:=strconv.Atoi(orderSearchData.Page)
errs:=orm.Engine.Where("report_phone > ? or report_no=?",orderSearchData.ReportPhone,orderSearchData.ReportNo).Limit(pageSize,page-1).Find(&result)
worker:= make([]models.WorkerList,0)
for _,val:=range result{
orm.Engine.Table("worker_list").Where("id=?",val.WorkerId).Find(&worker)
//orm.Engine.Where("id=?",val.WorkerId).Find(&worker)
}
fmt.Println(worker)
return result,errs
}
```
请问怎么样才能实现上面的需求?
有疑问加站长微信联系(非本文作者)