120 lines
3.2 KiB
Go
120 lines
3.2 KiB
Go
package approval
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/fonchain_enterprise/fonchain-main/api/approval"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/config"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/serializer"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/es_service/approval/common"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/es_service/approval/logic"
|
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/es_service/approval/model"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
"github.com/olivere/elastic/v7"
|
|
)
|
|
|
|
func BulkApproval(c *gin.Context) {
|
|
var req approval.ListRequest
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, e.Error, err)
|
|
return
|
|
}
|
|
fmt.Println("=================================== config.ApprovalIndex ====================================")
|
|
fmt.Printf("config.ApprovalIndex is :%+v\n", config.ApprovalIndex)
|
|
fmt.Println("=================================== config.ApprovalIndex ====================================")
|
|
|
|
if req.Page == 0 {
|
|
req.Page = 1
|
|
}
|
|
|
|
if req.PageSize == 0 {
|
|
req.PageSize = 99999
|
|
}
|
|
|
|
logic.BulkIndexApprovalInfo(config.ApprovalIndex, req.Page, req.PageSize)
|
|
|
|
service.Success(c, nil)
|
|
}
|
|
|
|
func SearchApproval(c *gin.Context) {
|
|
var req model.SearchApproval
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, e.Error, err)
|
|
return
|
|
}
|
|
|
|
if req.Page == 0 {
|
|
req.Page = 1
|
|
}
|
|
|
|
if req.PageSize == 0 {
|
|
req.PageSize = 10
|
|
}
|
|
|
|
if req.UserID == 0 {
|
|
userInfo := login.GetUserInfoFromC(c)
|
|
req.UserID = userInfo.ID
|
|
}
|
|
|
|
fmt.Println("=================================== req ====================================")
|
|
fmt.Printf("req is :%+v\n", req)
|
|
fmt.Println("=================================== req ====================================")
|
|
|
|
var query = elastic.NewBoolQuery()
|
|
|
|
if req.MenuType != 0 {
|
|
query.Must(logic.MenuTypeQuery(req.MenuType))
|
|
}
|
|
|
|
switch req.QueryType {
|
|
case 1:
|
|
query.Must(
|
|
//logic.ExistNowLevelQuery(),
|
|
//logic.ExistWorkFlowsQuery(),
|
|
logic.BuildSubmitFilterQuery(req.UserID))
|
|
case 2:
|
|
query.Must(
|
|
//logic.ExistNowLevelQuery(),
|
|
//logic.ExistWorkFlowsQuery(),
|
|
logic.BuildWorkFunctionScoreQuery(req.UserID, 2))
|
|
case 3:
|
|
query.Must(
|
|
//logic.ExistNowLevelQuery(),
|
|
//logic.ExistWorkFlowsQuery(),
|
|
logic.BuildHadWorkFunctionScoreQuery(req.UserID))
|
|
case 4:
|
|
query.Must(
|
|
//logic.ExistNowLevelQuery(),
|
|
//logic.ExistWorkFlowsQuery(),
|
|
//logic.ExistCopyUserQuery(),
|
|
logic.BuildViewFunctionScoreQuery(req.UserID, 2))
|
|
case 5:
|
|
query.Must(
|
|
//logic.ExistNowLevelQuery(),
|
|
//logic.ExistWorkFlowsQuery(),
|
|
logic.BuildAllFunctionScoreQuery(req.UserID, 2))
|
|
default:
|
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|
Msg: common.MissParamQueryApproval,
|
|
Status: e.Failed,
|
|
})
|
|
return
|
|
}
|
|
|
|
total, approvals, err := logic.Search(config.ApprovalIndex, req.Value, query, req.Page, req.PageSize)
|
|
if err != nil {
|
|
service.Error(c, e.Error, err)
|
|
return
|
|
}
|
|
|
|
res := &model.SearchApprovalRes{
|
|
Count: total,
|
|
Data: approvals,
|
|
}
|
|
|
|
service.Success(c, res)
|
|
}
|