|
@@ -8,8 +8,6 @@ import (
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
// 统计报表 按时间范围,供应商 包装-计划(多选) 维度进行过滤,形成报表。可以下载
|
|
@@ -26,43 +24,10 @@ func Report(r *GinRouter) {
|
|
|
func ReportProduceList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
page, size, query := UtilQueryPageSize(c)
|
|
|
// 条件处理
|
|
|
- query["status"] = "complete"
|
|
|
- if _supplierId, ok := query["supplierId"]; ok {
|
|
|
- delete(query, "supplierId")
|
|
|
- supplierId, _ := primitive.ObjectIDFromHex(_supplierId.(string))
|
|
|
- if !supplierId.IsZero() {
|
|
|
- query["supplierId"] = supplierId
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if _timeRange, ok := query["timeRange"]; ok {
|
|
|
- timeRange, _ := _timeRange.([]interface{})
|
|
|
-
|
|
|
- if len(timeRange) == 2 {
|
|
|
- start, end := getTimeRange(timeRange[0].(string), timeRange[1].(string))
|
|
|
- query["completeTime"] = bson.M{"$gte": start, "$lte": end}
|
|
|
- }
|
|
|
- delete(query, "timeRange")
|
|
|
- }
|
|
|
-
|
|
|
- if _planIds, ok := query["planIds"]; ok {
|
|
|
- if len(_planIds.([]interface{})) > 0 {
|
|
|
- planQuery := bson.A{}
|
|
|
- for _, _planId := range _planIds.([]interface{}) {
|
|
|
- planId, _ := primitive.ObjectIDFromHex(_planId.(string))
|
|
|
- planQuery = append(planQuery, bson.M{"planId": planId})
|
|
|
- }
|
|
|
- query["$or"] = planQuery
|
|
|
- }
|
|
|
- delete(query, "planIds")
|
|
|
- }
|
|
|
- fmt.Println(query)
|
|
|
-
|
|
|
// 获取采购单符合条件的信息
|
|
|
return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: repo.CollectionBillProduce,
|
|
|
- Query: query,
|
|
|
+ Query: handleReportQuery(query),
|
|
|
Page: page,
|
|
|
Size: size,
|
|
|
})
|
|
@@ -72,43 +37,9 @@ func ReportProduceList(c *gin.Context, apictx *ApiSession) (interface{}, error)
|
|
|
// 采购单
|
|
|
func ReportPurchaseList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
page, size, query := UtilQueryPageSize(c)
|
|
|
- // 条件处理
|
|
|
- query["status"] = "complete"
|
|
|
-
|
|
|
- if _supplierId, ok := query["supplierId"]; ok {
|
|
|
- delete(query, "supplierId")
|
|
|
- supplierId, _ := primitive.ObjectIDFromHex(_supplierId.(string))
|
|
|
- if !supplierId.IsZero() {
|
|
|
- query["supplierId"] = supplierId
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if _timeRange, ok := query["timeRange"]; ok {
|
|
|
- timeRange, _ := _timeRange.([]interface{})
|
|
|
-
|
|
|
- if len(timeRange) == 2 {
|
|
|
- start, end := getTimeRange(timeRange[0].(string), timeRange[1].(string))
|
|
|
- query["completeTime"] = bson.M{"$gte": start, "$lte": end}
|
|
|
- }
|
|
|
- delete(query, "timeRange")
|
|
|
- }
|
|
|
-
|
|
|
- if _planIds, ok := query["planIds"]; ok {
|
|
|
- if len(_planIds.([]interface{})) > 0 {
|
|
|
- planQuery := bson.A{}
|
|
|
- for _, _planId := range _planIds.([]interface{}) {
|
|
|
- planId, _ := primitive.ObjectIDFromHex(_planId.(string))
|
|
|
- planQuery = append(planQuery, bson.M{"planId": planId})
|
|
|
- }
|
|
|
- query["$or"] = planQuery
|
|
|
- }
|
|
|
- delete(query, "planIds")
|
|
|
- }
|
|
|
- // 获取采购单符合条件的信息
|
|
|
return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: repo.CollectionBillPurchase,
|
|
|
- Query: query,
|
|
|
+ Query: handleReportQuery(query),
|
|
|
Page: page,
|
|
|
Size: size,
|
|
|
})
|
|
@@ -117,45 +48,11 @@ func ReportPurchaseList(c *gin.Context, apictx *ApiSession) (interface{}, error)
|
|
|
|
|
|
func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
_, _, query := UtilQueryPageSize(c)
|
|
|
- // 条件处理
|
|
|
- query["status"] = "complete"
|
|
|
-
|
|
|
- if _supplierId, ok := query["supplierId"]; ok {
|
|
|
- delete(query, "supplierId")
|
|
|
- supplierId, _ := primitive.ObjectIDFromHex(_supplierId.(string))
|
|
|
- if !supplierId.IsZero() {
|
|
|
- query["supplierId"] = supplierId
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if _timeRange, ok := query["timeRange"]; ok {
|
|
|
- timeRange, _ := _timeRange.([]interface{})
|
|
|
-
|
|
|
- if len(timeRange) == 2 {
|
|
|
- start, end := getTimeRange(timeRange[0].(string), timeRange[1].(string))
|
|
|
- query["completeTime"] = bson.M{"$gte": start, "$lte": end}
|
|
|
- }
|
|
|
- delete(query, "timeRange")
|
|
|
- }
|
|
|
-
|
|
|
- if _planIds, ok := query["planIds"]; ok {
|
|
|
- if len(_planIds.([]interface{})) > 0 {
|
|
|
- planQuery := bson.A{}
|
|
|
- for _, _planId := range _planIds.([]interface{}) {
|
|
|
- planId, _ := primitive.ObjectIDFromHex(_planId.(string))
|
|
|
- planQuery = append(planQuery, bson.M{"planId": planId})
|
|
|
- }
|
|
|
- query["$or"] = planQuery
|
|
|
- }
|
|
|
- delete(query, "planIds")
|
|
|
- }
|
|
|
-
|
|
|
// 获取采符合条件的信息
|
|
|
produces := []model.ProduceBill{}
|
|
|
err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: repo.CollectionBillProduce,
|
|
|
- Query: query,
|
|
|
+ Query: handleReportQuery(query),
|
|
|
}, &produces)
|
|
|
if err != nil || len(produces) < 1 {
|
|
|
return nil, errors.New("数据不存在")
|
|
@@ -240,43 +137,11 @@ func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
|
|
|
|
|
|
func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
_, _, query := UtilQueryPageSize(c)
|
|
|
- // 条件处理
|
|
|
- query["status"] = "complete"
|
|
|
-
|
|
|
- if _supplierId, ok := query["supplierId"]; ok {
|
|
|
- delete(query, "supplierId")
|
|
|
- supplierId, _ := primitive.ObjectIDFromHex(_supplierId.(string))
|
|
|
- if !supplierId.IsZero() {
|
|
|
- query["supplierId"] = supplierId
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if _timeRange, ok := query["timeRange"]; ok {
|
|
|
- timeRange, _ := _timeRange.([]interface{})
|
|
|
-
|
|
|
- if len(timeRange) == 2 {
|
|
|
- start, end := getTimeRange(timeRange[0].(string), timeRange[1].(string))
|
|
|
- query["completeTime"] = bson.M{"$gte": start, "$lte": end}
|
|
|
- }
|
|
|
- delete(query, "timeRange")
|
|
|
- }
|
|
|
-
|
|
|
- if _planIds, ok := query["planIds"]; ok {
|
|
|
- if len(_planIds.([]interface{})) > 0 {
|
|
|
- planQuery := bson.A{}
|
|
|
- for _, _planId := range _planIds.([]interface{}) {
|
|
|
- planId, _ := primitive.ObjectIDFromHex(_planId.(string))
|
|
|
- planQuery = append(planQuery, bson.M{"planId": planId})
|
|
|
- }
|
|
|
- query["$or"] = planQuery
|
|
|
- }
|
|
|
- delete(query, "planIds")
|
|
|
- }
|
|
|
- // 获取符合条件的信息
|
|
|
purchases := []model.PurchaseBill{}
|
|
|
err := repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: repo.CollectionBillPurchase,
|
|
|
- Query: query,
|
|
|
+ Query: handleReportQuery(query),
|
|
|
}, &purchases)
|
|
|
if err != nil || len(purchases) < 1 {
|
|
|
return nil, errors.New("数据不存在")
|