首页 > 其他分享 >GO指标系统供盘询盘合并计算技巧

GO指标系统供盘询盘合并计算技巧

时间:2024-12-16 23:57:44浏览次数:5  
标签:err 供盘 bpl reportDayEs start GO line 询盘 id

func (self *ReportDaySupply) mergeList(publishedLists ...[]*esentity.ServiceReportDayEs) report_dto.MapRet { //[]*esentity.ServiceReportDayEs {

    var publishedMap = make(report_dto.MapRet)
    //聚合统计
    for _, publishedList := range publishedLists {
       for _, publishedLine := range publishedList {
          if data, ok := publishedMap[publishedLine.ShopMemberId]; ok {
             switch data.LineType {
             case Linetype_avab_line:
                data.AvabCount += publishedLine.AvabCount
             case Linetype_rfq_line:
                data.RfqCount += publishedLine.RfqCount
             case Linetype_PurchaseOrderLine:
                data.PurchaseLineCount += publishedLine.PurchaseLineCount
             case Linetype_SalesOrderLine:
                data.SaleLineCount += publishedLine.SaleLineCount
             }
          } else {
             publishedMap[publishedLine.ShopMemberId] = publishedLine
          }
       }
    }
    return publishedMap

}

指标统计结果是一张宽表

统计过程的数据合并

package report_day

import (
    "git.ichub.com/general/webcli120/goconfig/base/basedto"
    "git.ichub.com/general/webcli120/goconfig/ichublog/golog"
    "github.com/gogf/gf/v2/util/gconv"
    "github.com/micro/go-micro/v2/logger"
    "icd/general-srv/esentity"
    "icd/general-srv/handler/report_base"
    "icd/general-srv/handler/report_base/reportkey"
    "icd/general-srv/handler/report_dto"
    "icd/plugins/db"
    "time"
)

const (
    Linetype_rfq_line          = "rfq_line"            //询盘
    Linetype_avab_line         = "avab_line"           //e供
    Linetype_SalesOrderLine    = "sales_order_line"    // 买盘销售
    Linetype_PurchaseOrderLine = "purchase_order_line" // 卖盘采购
)

// 发布项之供盘
// leijianming   lei1234 -- candao
type ReportDaySupply struct {
    basedto.BaseEntitySingle
    *report_base.ReportDayBase
}

func NewServiceReportDaySupply() *ReportDaySupply {
    return &ReportDaySupply{
       ReportDayBase: report_base.FindBeanReportDayBase(),
    }
}

func (self *ReportDaySupply) BuildId(id any, end time.Time) string {
    return end.Format(time.DateOnly) + "|" + gconv.String(id) + "|0|0"

}

// 从发布项统计供盘数指标 db
func (self *ReportDaySupply) MigrationAvabLineDayReport(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {
    golog.Info("ReportDayMatch [MigrationAvabLineDayReport]开始统计所有供盘数:", end)
    var startShanghai, endShanghai = self.ToShanghai(start, end)
    //yesterday
    start = startShanghai.AddDate(0, 0, -1)
    end = endShanghai.AddDate(0, 0, -1)
    golog.Info("ReportDaySupply [MigrationAvabLineDayReport] start, end  =  ", start, end)
    var statAvabLine, err = self.statAvabLine(start, end)
    if err != nil {
       golog.Error("ReportDaySupply [MigrationAvabLineDayReport] err =", err)
       return nil, err
    }
    //statRfqLine
    //var statRfqLine, err1 = self.statRfqLine(start, end)
    //if err1 != nil {
    // golog.Error(err1)
    //}
    var statPurchaseLine, err2 = self.statPurchaseLine(start, end)
    if err2 != nil {
       golog.Error(err2)
    }
    var statSaleLine, err3 = self.statSaleLine(start, end)
    if err3 != nil {
       golog.Error(err3)
    }
    //去重
    golog.Info("ReportDaySupply [MigrationAvabLineDayReport]统计所有供盘数结束:")
    var mapRet = self.mergeList(statAvabLine, statPurchaseLine, statSaleLine)
    return self.map2List(mapRet, start), nil
}
func (self *ReportDaySupply) statRfqLine(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {

    const sql = `with P as(
select  bpl.line_id , bpl.line_type from biz_published_line bpl where bpl.line_type in 'rfq_line'
and bpl.active =true  and bpl.created_at >= ? and bpl.created_at < ?) 
select bal.shop_member_id,P.line_type,count(1) as rfq_count
from P join biz_rfq_line bal on P.line_id=bal.id  
group by bal.shop_member_id,P.line_type`
    reportDayEs := make([]*esentity.ServiceReportDayEs, 0)
    if err := db.GetDB().Raw(sql, start, end).Scan(&reportDayEs).Error; err != nil {
       logger.Errorf("MigrationAvabLineDayReport 查询新增或更新的供盘数报错:", err)
       return reportDayEs, err
    }
    golog.Info("ReportDaySupply [makePublishedLine] reportDayEs count= , ", len(reportDayEs))
    return reportDayEs, nil
}
func (self *ReportDaySupply) statPurchaseLine(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {

    const sql = `with P as(
select  bpl.line_id , bpl.line_type from biz_published_line bpl where bpl.line_type in 'purchase_order_line'
and bpl.active =true  and bpl.created_at >= ? and bpl.created_at < ?) 
select bal.shop_member_id,P.line_type,count(1) as purchase_line_count
from P join biz_purchase_order_line bal on P.line_id=bal.id  
group by bal.shop_member_id,P.line_type`
    reportDayEs := make([]*esentity.ServiceReportDayEs, 0)
    if err := db.GetDB().Raw(sql, start, end).Scan(&reportDayEs).Error; err != nil {
       logger.Errorf("MigrationAvabLineDayReport 查询新增或更新的供盘数报错:", err)
       return reportDayEs, err
    }
    golog.Info("ReportDaySupply [statPurchaseLine] reportDayEs count= , ", len(reportDayEs))
    return reportDayEs, nil
}
func (self *ReportDaySupply) statSaleLine(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {

    const sql = `with P as(
select  bpl.line_id , bpl.line_type from biz_published_line bpl where bpl.line_type in 'sale_order_line'
and bpl.active =true  and bpl.created_at >= ? and bpl.created_at < ?) 
select bal.shop_member_id,,P.line_type,count(1) as sale_line_count
from P join biz_sales_order_line bal on P.line_id=bal.id  
group by bal.shop_member_id,P.line_type`
    reportDayEs := make([]*esentity.ServiceReportDayEs, 0)
    if err := db.GetDB().Raw(sql, start, end).Scan(&reportDayEs).Error; err != nil {
       logger.Errorf("MigrationAvabLineDayReport 查询新增或更新的供盘数报错:", err)
       return reportDayEs, err
    }
    golog.Info("ReportDaySupply [statSaleLine] reportDayEs count= , ", len(reportDayEs))
    return reportDayEs, nil
}

func (self *ReportDaySupply) statAvabLine(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {

    // select  bpl.line_id from biz_published_line bpl where bpl.line_type ='avab_line' and bpl.active =true
    // and bpl.updated_at >= ? and bpl.updated_at < ? union
    const srd_addsql = `with P as(
    select  bpl.line_id,bpl.line_type from biz_published_line bpl 
    where bpl.line_type ='avab_line' and bpl.active =true  
    and bpl.created_at >= ? and bpl.created_at < ?
    ) 
    select bal.shop_member_id,P.line_type,count(1) as avab_count
    from P join biz_avab_line bal on P.line_id=bal.id and bal.source_type in (0, 1, 2)
    group by bal.shop_member_id,P.line_type`
    reportDayEs := make([]*esentity.ServiceReportDayEs, 0)
    //昨天新增或者更新激活的供盘发布项 created active=true /
    if err := db.GetDB().Raw(srd_addsql, start, end).Scan(&reportDayEs).Error; err != nil {
       logger.Errorf("MigrationAvabLineDayReport 查询新增或更新的供盘数报错:", err)
       return reportDayEs, err
    }
    golog.Info("ReportDaySupply [statAvabLine] reportDayEs coun t= , ", len(reportDayEs))
    return reportDayEs, nil
}
func (self *ReportDaySupply) mergeList(publishedLists ...[]*esentity.ServiceReportDayEs) report_dto.MapRet { //[]*esentity.ServiceReportDayEs {

    var publishedMap = make(report_dto.MapRet)
    //聚合统计
    for _, publishedList := range publishedLists {
       for _, publishedLine := range publishedList {
          if data, ok := publishedMap[publishedLine.ShopMemberId]; ok {
             switch data.LineType {
             case Linetype_avab_line:
                data.AvabCount += publishedLine.AvabCount
             case Linetype_rfq_line:
                data.RfqCount += publishedLine.RfqCount
             case Linetype_PurchaseOrderLine:
                data.PurchaseLineCount += publishedLine.PurchaseLineCount
             case Linetype_SalesOrderLine:
                data.SaleLineCount += publishedLine.SaleLineCount
             }
          } else {
             publishedMap[publishedLine.ShopMemberId] = publishedLine
          }
       }
    }
    return publishedMap

}
func (self *ReportDaySupply) ToIdByMemberId(start time.Time, id int64) string {
    return start.Format(time.DateOnly) + "|" + gconv.String(id) + "|0|0"
}

func (self *ReportDaySupply) map2List(publishedMap report_dto.MapRet, start time.Time) []*esentity.ServiceReportDayEs {
    publishedList := make([]*esentity.ServiceReportDayEs, 0)

    for _, publishedLine := range publishedMap {
       publishedLine.Id = self.ToIdByMemberId(start.In(reportkey.ZoneShanghai), publishedLine.ShopMemberId)
       publishedLine.CreatedAt = start.UTC().UnixNano() / 1e6
       publishedLine.CreatedDate = start.In(reportkey.ZoneShanghai)
       publishedLine.StatAt = time.Now().In(reportkey.ZoneShanghai)
       publishedList = append(publishedList, publishedLine)
    }
    return publishedList
}

//esservice

//指标系统的测试用例 预置
//时间维度,0点前,0点后 : 供货项,。。。
//时间维度,8点前,8点后 : 供货项,。。。
//时间维度,16点前,16点后 : 供货项,。。。

//观察点:,统计总数, 时间有没有落到正确的日期

// func (self *ReportDaySupply) makeCancel(start, end time.Time) ([]*esentity.ServiceReportDayEs, error) {
//
//     const srd_deletesql = `
//     select bal.shop_member_id,count(1) as cancel_avab_count from biz_published_line bpl
//     inner join biz_avab_line bal on bpl.line_id = bal.id
//          where bpl.updated_at > ? and bpl.updated_at < ?
//            and bpl.active = false and bal.source_type in (0,1,2)
//     group by bal.shop_member_id;
//     //昨天归档的供盘发布项
//     reportDayEs := make([]*esentity.ServiceReportDayEs, 0)
//     if err := db.GetDB().Raw(srd_deletesql, start, end).Scan(&reportDayEs).Error; err != nil {
//        golog.Error("MigrationAvabLineDayReport 查询删除的供盘数报错:", err)
//        return reportDayEs, err
//     }
//     return reportDayEs, nil
//  }

标签:err,供盘,bpl,reportDayEs,start,GO,line,询盘,id
From: https://blog.csdn.net/leijmdas/article/details/144520969

相关文章

  • Django Nginx+uwsgi 安装配置
    安装基础开发包Centos下安装步骤如下:yumgroupinstall"Developmenttools"yuminstallzlib-develbzip2-develpcre-developenssl-develncurses-develsqlite-develreadline-develtk-develCentOS自带Python2.4.3,但我们可以再安装Python2.7.5:cd~wgethttp://py......
  • Django ORM - 单表实例
    创建一个项目app01(如果之前已创建过,忽略以下操作):django-admin.pystartprojectapp01接下来在settings.py中找到INSTALLED_APPS这一项,如下:INSTALLED_APPS=('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes',&#......
  • Android version has disappeared from Google Play #1700
     IfyouspeakRussian,4pdahasacustom'improvedversion'thatisprobablywhatyouneed.Ican'tlinktoithere,butsomesearchingshouldhelp.Atleastuntilitisopensourced/broughtbacktoanappstore.  Here’stheanswerI......
  • 基于django的python校园用车管理系统校车使用记录(源码+文档+运行视频+讲解视频)
     文章目录系列文章目录前言一、开发介绍二、详细视频演示三、项目部分实现截图四、系统测试五、代码参考源码获取目的摘要:基于Django的Python校园用车管理系统为学校的校车管理提供了便捷的工具。该系统借助Django框架的稳定性和Python语言的高效性,实现了校......
  • 基于django的python图书馆管理系统图书借阅归还续借逾期罚金缴纳(源码+文档+运行视频+
     文章目录系列文章目录前言一、开发介绍二、详细视频演示三、项目部分实现截图四、系统测试五、代码参考源码获取目的摘要:基于Django的Python图书馆管理系统为图书馆的管理和服务提供了全面的解决方案。该系统通过Django框架的高效性和Python语言的灵活性,实......
  • GoPro 13 & GoPro Quik 不完全踩坑指南 All In One
    GoPro13&GoProQuik不完全踩坑指南AllInOneGoPro13&GoProQuikAppbugsAllInOnebugsGoProQuik编辑大文件11GB,导出视频时候提示磁盘空间过低bugGoPro会把录制时间过长/或文件过大的视频,自动按照12GB大小分割成多段视频,导致后期编辑视频......
  • Forms表单中的full_clean方法和django中模型的save()方法之前手动调用的full_clean()方
    它们是两个独立的实现,分别存在于Django的Model和Form对象中,用于验证不同的数据类型和场景。1.两种full_clean()方法的区别1.1Model.full_clean()•定义位置:django.db.models.Model•调用时机:必须手动调用,Django默认不会在保存(save())时自动调用它。•作用:•......
  • 打造AI驱动的数据库应用:使用Google Bigtable存储和管理Langchain文档
    打造AI驱动的数据库应用:使用GoogleBigtable存储和管理Langchain文档引言GoogleBigtable是一种高性能的键值和宽列存储数据库,专为快速访问结构化、半结构化或非结构化数据而设计。随着AI技术的发展,数据库应用可以利用Bigtable的功能和Langchain集成来提供更智能的用户体......
  • 使用svg画一个百度的logo
    创建一个SVG版本的百度logo需要一些设计和SVG的基础知识。百度的logo是由一个“熊掌”图标和文字“baidu”组成的。由于SVG绘制复杂图形和文字排版可能较为复杂,这里我将提供一个简化的SVG示例,用于展示熊掌图标的基本形状。请注意,这只是一个大致的示例,并非精确的百度logo复制品。<......
  • 《Django 5 By Example》阅读笔记:p551-p560
    《Django5ByExample》学习第20天,p551-p560总结,总计10页。一、技术总结1.custommodelfield(1)示例courses/fields.pyfromdjango.core.exceptionsimportObjectDoesNotExistfromdjango.dbimportmodelsclassOrderField(models.PositiveIntegerField):d......