作者 yangfu

feat:

1.每日设备数据定时落库
2.时段产能
... ... @@ -21,6 +21,7 @@ require (
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.13.0
... ... @@ -30,7 +31,6 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
golang.org/x/text v0.3.6
)
... ...
... ... @@ -337,6 +337,8 @@ github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
... ...
... ... @@ -42,6 +42,9 @@ func (crontabService *CrontabService) initTask() {
autoApproveRecord := task.NewTask("autoApproveRecord", "0 */2 * * * *", AutoApproveProductRecord)
task.AddTask("autoApproveRecord", autoApproveRecord)
autoFlushDeviceDailyRunningRecord := task.NewTask("autoFlushDeviceDailyRunningRecord", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)
}
func (crontabService *CrontabService) StartCrontabTask() {
... ...
... ... @@ -4,11 +4,13 @@ import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 定时刷新设备每日运行记录
func AutoFreshDeviceDailyRunningRecord(ctx context.Context) error {
func AutoFlushDeviceDailyRunningRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
... ... @@ -28,10 +30,32 @@ func AutoFreshDeviceDailyRunningRecord(ctx context.Context) error {
transactionContext.RollbackTransaction()
}()
//deviceDailyRunningRecordRepository,_,_:= factory.FastPgDeviceDailyRunningRecord(transactionContext,0)
//
//// 获取redis里当天的记录
//t :=time.Now().Add(-time.Minute*20)
log.Logger.Info("【定时刷新设备每日运行记录】 启动")
deviceDailyRunningRecordRepository, _, _ := factory.FastPgDeviceDailyRunningRecord(transactionContext, 0)
// 获取redis里当天的记录
span := time.Duration(20)
t := time.Now().Add(-time.Minute * span)
records, err := redis.GetDeviceDailyAllRecord(t)
if err != nil {
log.Logger.Error(err.Error())
return err
}
for _, v := range records {
if v.UpdatedAt.Add(time.Minute * 5).Before(time.Now()) {
log.Logger.Info(fmt.Sprintf("【定时刷新设备每日运行记录】 跳过记录 %v 最后更新时间:%v", v, v.UpdatedAt))
continue
}
// 更新设备效率 OEE = tu * pu * qu
if _, err := deviceDailyRunningRecordRepository.Save(v); err != nil {
log.Logger.Error(err.Error())
continue
} else {
log.Logger.Info(fmt.Sprintf("【定时刷新设备每日运行记录】 刷新记录 %v", v))
}
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
... ...
... ... @@ -2,8 +2,10 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
)
// CommonStatisticsService 通用的统计服务
... ... @@ -11,8 +13,8 @@ type CommonStatisticsService struct {
}
// CommonStatisticsService 通用的统计服务
func (svr *CommonStatisticsService) CommonStatisticsService(contractStatisticsQuery *query.CommonStatisticsQuery) (interface{}, error) {
if err := contractStatisticsQuery.ValidateQuery(); err != nil {
func (svr *CommonStatisticsService) CommonStatisticsService(cmd *query.CommonStatisticsQuery) (interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
var err error
... ... @@ -27,58 +29,18 @@ func (svr *CommonStatisticsService) CommonStatisticsService(contractStatisticsQu
_ = transactionContext.RollbackTransaction()
}()
//statisticsService, err := factory.CreateCooperationStatisticsService(map[string]interface{}{
// "transactionContext": transactionContext,
//})
//var res interface{}
//switch contractStatisticsQuery.Action {
//case domain_service.SearchContractDividends:
// res, err = statisticsService.SearchContractDividends(contractStatisticsQuery.QueryOptions)
//case domain_service.GetContractDividends:
// res, err = statisticsService.GetContractDividends(contractStatisticsQuery.QueryOptions)
//case domain_service.CooperationGoodsStatistics:
// res, err = statisticsService.CooperationGoodsStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CooperationModeStatistics:
// res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CompanyDividendsStatistics:
// res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CompanyCooperationUsersStatistics:
// res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CompanyPaymentHistoryStatistics:
// res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CompanyCooperationProjectContracts:
// res, err = statisticsService.CompanyCooperationProjectContracts(contractStatisticsQuery.QueryOptions)
//case domain_service.PaymentHistoryHistogramStatistics:
// res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.CooperationUserModeStatistics:
// res, err = statisticsService.CooperationUserModeStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.DividendsStatistics:
// res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.SearchDividendsEstimates:
// res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions)
//case domain_service.CooperationCompanyStatistics:
// res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.PersonCooperationContractStatistics:
// res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.PersonCompanyPaymentHistoryStatistics:
// res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.PersonCooperationProjectSharedInfo:
// res, err = statisticsService.PersonCooperationProjectSharedInfo(contractStatisticsQuery.QueryOptions)
//case domain_service.PersonCooperationProjectSharedInfoAttachment:
// res, err = statisticsService.PersonCooperationProjectSharedInfoAttachment(contractStatisticsQuery.QueryOptions)
//case domain_service.PersonCooperationCompany:
// res, err = statisticsService.PersonCooperationCompany(contractStatisticsQuery.QueryOptions)
//case domain_service.CreditAccountStatistics:
// res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
//case domain_service.RelevantCooperationContractNumbers:
// res, err = statisticsService.RelevantCooperationContractNumbers(contractStatisticsQuery.QueryOptions)
//}
statisticsService, _ := domainService.NewPGCommonStatisticsService(transactionContext.(*pg.TransactionContext))
response, err := statisticsService.CommonStatistics(cmd.Action, cmd.QueryOptions)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct {
}{}, nil
return response, nil
}
func NewCommonStatisticsService(options map[string]interface{}) *CommonStatisticsService {
newProductSectionService := &CommonStatisticsService{}
return newProductSectionService
}
... ...
... ... @@ -52,6 +52,19 @@ func (deviceDailyRunningRecord *DeviceDailyRunningRecord) Update(data map[string
return nil
}
func (deviceDailyRunningRecord *DeviceDailyRunningRecord) AddDeviceRunningData(t time.Time, data *DeviceRunningData) {
deviceDailyRunningRecord.DeviceRunningRecordInfo.AddDeviceRunningData(t, data)
deviceDailyRunningRecord.UpdatedAt = time.Now()
}
func (deviceDailyRunningRecord *DeviceDailyRunningRecord) String() string {
return fmt.Sprintf("记录ID:%v 工段:%v 设备:%v",
deviceDailyRunningRecord.DeviceDailyRunningRecordId,
deviceDailyRunningRecord.WorkStation.SectionName,
deviceDailyRunningRecord.DeviceCode,
)
}
// 设备运行记录信息
type DeviceRunningRecordInfo struct {
// 当前状态
... ... @@ -66,11 +79,11 @@ type DeviceRunningRecordInfo struct {
// 1. 当前设备实际产出数量/理论数量(理论数量=60*60*12/标准工时)
// 2. 没有数量100%
PerformanceUtilization float64 `json:"pu"`
// 合格率 QualificationUtilization
// 合格率 QualificationUtilization ?设备提交的二级品事串 、 机器上报的是kg
// 1.按工段的合格率
// 2.默认100%
QualificationUtilization float64 `json:"qu"`
// 运行时长 单位:h
// 运行时长 单位:分钟
UpTime float64 `json:"upTime"`
// 生成数量
Count int `json:"count"`
... ... @@ -102,7 +115,7 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device
d.AddTimeLineDeviceStatus(t, data)
//d.OEE
d.TimeUtilization = d.UpTime * 100 / (time.Now().Sub(utils.GetZeroTime(time.Now())).Hours())
d.TimeUtilization = utils.Round(d.UpTime*100/(time.Now().Sub(utils.GetZeroTime(time.Now())).Minutes()), 2)
//d.PerformanceUtilization
//d.QualificationUtilization
}
... ... @@ -128,7 +141,7 @@ func (d *DeviceRunningRecordInfo) ResetUpTime() float64 {
var upTime float64
for _, v := range d.TimeLineDeviceStatus {
t := v.CountTime(v.Up)
upTime += t.Hours()
upTime += t.Minutes()
}
d.UpTime = upTime
return upTime
... ... @@ -191,12 +204,15 @@ func (d *HourDeviceStatus) CountTime(v int) time.Duration {
count := 0
index := 1
for i := 0; i < l; i++ {
if index > v {
break
}
if index&v > 0 {
count++
}
index <<= 1
}
return time.Duration(d.Window*count) * time.Minute / time.Hour
return time.Duration(d.Window*count) * time.Minute
}
func NewHourDeviceStatus() *HourDeviceStatus {
... ...
... ... @@ -54,3 +54,46 @@ func (dao *ProductRecordDao) RecentUnApprovedProductRecord(fromLastHour int, rec
return int64(count), productAttendanceRecords, nil
}
}
// 时段产能
func (dao *ProductRecordDao) TimeSectionProductRecord(companyId, orgId, workshopId int, lineId int, beginTime time.Time, result interface{}) error {
tx := dao.transactionContext.PgTx
sql := fmt.Sprintf(`
WITH ts_product as(
select sum(a.weight) total,a.ts from (
select
cast(product_record_info->>'weigh' as DECIMAL) weight,
"replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts
from manufacture.product_records
where
company_id = ?
and org_id = ?
and work_station->>'workshopId'='?'
and work_station->>'lineId'='?'
and product_record_type = 8
and created_at >?
) a
group by a.ts
order by ts
)
-- select * from ts_product
, ts_product_list as (
select d.ts,ts_product.total from (
select to_char(c.ts::timestamp,'HH24:MI') ts from (
select generate_series(a.end - interval '5 hour',
"replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp,
'30 minute') ts from (
select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end
) a
) c
) d left join ts_product on d.ts = ts_product.ts
)
SELECT ts, coalesce(total,0) total
from ts_product_list
`)
if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, beginTime); err != nil {
return err
}
return nil
}
... ...
... ... @@ -3,7 +3,12 @@ package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
const (
... ... @@ -15,20 +20,55 @@ type PGCommonStatisticsService struct {
transactionContext *pgTransaction.TransactionContext
}
func (ptr *PGCommonStatisticsService) CommonStatistics(actionType, queryOptions map[string]interface{}) (interface{}, error) {
func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryOptions map[string]interface{}) (interface{}, error) {
var result interface{}
var err error
switch actionType {
case HourProductiveStatistics:
result, err = ptr.HourProductiveStatistics(queryOptions)
break
}
return nil, nil
return result, err
}
// 时段产能-统计 (传串设备)
func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[string]interface{}) (interface{}, error) {
var request = &HourProductiveStatisticsRequest{}
if err := utils.LoadQueryObject(queryOptions, &request); err != nil {
if err := utils.LoadQueryObject(queryOptions, request); err != nil {
return nil, err
}
return nil, nil
workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext)
type record struct {
Ts string `json:"ts"`
Total float64 `json:"total"`
}
workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId})
if err != nil || workshop == nil {
return nil, nil
}
productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext)
var response = make([]interface{}, 0)
for _, v := range workshop.GetProductLines(domain.NotDeleted) {
var result = make([]*record, 0)
if err := productRecordDao.TimeSectionProductRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, time.Now().Add(-time.Hour*5), &result); err != nil {
log.Logger.Error(err.Error())
continue
}
var xData []string = make([]string, 0)
var values []interface{} = make([]interface{}, 0)
for _, r := range result {
xData = append(xData, r.Ts)
values = append(values, r.Total)
}
response = append(response, map[string]interface{}{
"lineName": v.LineName,
"data": NewXYData(xData, values),
})
}
return response, nil
}
type HourProductiveStatisticsRequest struct {
... ... @@ -37,6 +77,17 @@ type HourProductiveStatisticsRequest struct {
WorkshopId int `json:"workshopId" valid:"Required"`
}
func NewXYData(xData []string, values interface{}) interface{} {
return map[string]interface{}{
"xAxis": map[string]interface{}{
"data": xData,
},
"source": map[string]interface{}{
"value": values,
},
}
}
func NewPGCommonStatisticsService(transactionContext *pgTransaction.TransactionContext) (*PGCommonStatisticsService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -92,7 +92,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
// 2.保存设备生产记录
// 3.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库
deviceDailyRecord.DeviceRunningRecordInfo.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData)
deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData)
if err = redis.SaveDeviceDailyRunningRecord(deviceDailyRecord); err != nil {
return nil, err
}
... ...
... ... @@ -13,6 +13,10 @@ import (
func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) {
client := GetRedis()
key := DeviceDailyRunningRecordKey(t, deviceCode)
return getDeviceDailyRunningRecord(client, key)
}
func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.DeviceDailyRunningRecord, error) {
result := client.Get(key)
data, err := result.Bytes()
if err == redis.Nil {
... ... @@ -48,3 +52,27 @@ func DeviceDailyRunningRecordKey(t time.Time, deviceCode string) string {
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Format("2006-01-02"), deviceCode)
return str
}
// 获取设备每日所有数据记录
func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, error) {
client := GetRedis()
sliceResult := client.Keys(DeviceDailyAllRecordKey(t))
keys, err := sliceResult.Result()
var records = make([]*domain.DeviceDailyRunningRecord, 0)
if err != nil {
return nil, err
}
for _, v := range keys {
record, err := getDeviceDailyRunningRecord(client, v)
if err != nil {
return nil, err
}
records = append(records, record)
}
return records, nil
}
func DeviceDailyAllRecordKey(t time.Time) string {
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:*", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Format("2006-01-02"))
return str
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
jsonlib "github.com/linmadan/egglib-go/utils/json"
"github.com/shopspring/decimal"
"io"
"reflect"
"strconv"
... ... @@ -379,3 +380,10 @@ func SubStr(str string, start, length int) string {
}
return string(rs[start:end])
}
func Round(value float64, places int32) float64 {
quantity := decimal.NewFromFloat(value)
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/utils/json"
"github.com/linmadan/egglib-go/web/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"net/http"
"strconv"
"strings"
)
type StatisticsController struct {
beego.BaseController
}
func (controller *StatisticsController) CommonStatisticsService() {
attendanceService := service.NewCommonStatisticsService(nil)
cmd := &query.CommonStatisticsQuery{}
controller.Unmarshal(cmd)
operateInfo := ParseOperateInfo(controller.BaseController)
cmd.QueryOptions["companyId"] = operateInfo.CompanyId
cmd.QueryOptions["orgId"] = operateInfo.OrgId
data, err := attendanceService.CommonStatisticsService(cmd)
controller.Response(data, err)
}
func (controller *StatisticsController) CommonStatisticsHandler(actionType string) func(ctx *context.Context) {
return func(ctx *context.Context) {
attendanceService := service.NewCommonStatisticsService(nil)
cmd := &query.CommonStatisticsQuery{}
options := make(map[string]interface{})
Unmarshal(ctx, &options)
operateInfo := ContextParseOperateInfo(ctx)
options["companyId"] = operateInfo.CompanyId
options["orgId"] = operateInfo.OrgId
cmd.Action = actionType
cmd.QueryOptions = options
data, err := attendanceService.CommonStatisticsService(cmd)
Response(ctx, data, err)
}
}
func Response(ctx *context.Context, data interface{}, err error) {
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(ctx, err)
} else {
response = utils.ResponseData(ctx, data)
}
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.JSON(response, false, false)
}
func Unmarshal(ctx *context.Context, v interface{}) error {
body := ctx.Input.RequestBody
if len(body) == 0 {
body = []byte("{}")
}
return json.Unmarshal(body, v)
}
// ParseOperateInfo 从头部解析操作对象信息
func ContextParseOperateInfo(c *context.Context) *domain.OperateInfo {
opt := &domain.OperateInfo{}
opt.UserId = ContextHeader(c, constant.HeaderUserId)
opt.CompanyId = ContextHeader(c, constant.HeaderCompanyId)
opt.OrgId = ContextHeader(c, constant.HeaderOrgId)
orgIdList := c.Input.Header(constant.HeaderOrgIds)
splitOrgIdList := strings.Split(orgIdList, constant.CUSTOMER_ACCOUNT_DELIMITER)
for i := range splitOrgIdList {
orgId, _ := strconv.Atoi(splitOrgIdList[i])
if orgId == 0 {
continue
}
opt.OrgIds = append(opt.OrgIds, orgId)
}
return opt
}
func ContextHeader(c *context.Context, key string) int {
if len(c.Input.Header(key)) == 0 {
return 0
}
res, err := strconv.Atoi(c.Input.Header(key))
if err != nil {
log.Logger.Error(err.Error())
return 0
}
return res
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
)
func init() {
web.Router("/statistics", &controllers.StatisticsController{}, "Post:CommonStatisticsService")
c := &controllers.StatisticsController{}
web.Post("/statistics/hour-productive", c.CommonStatisticsHandler("HourProductiveStatistics"))
}
... ...