作者 yangfu

feat: 统计服务重定向

... ... @@ -155,5 +155,6 @@ func NewHttpLibByteBankServiceGateway(host string) *HttpLibByteBankServiceGatewa
gt.ReadWriteTimeout = 10 * time.Second
return &HttpLibByteBankServiceGateway{
BaseServiceGateway: gt,
baseURL: host,
}
}
... ...
... ... @@ -2,9 +2,12 @@ package domainService
import (
"github.com/linmadan/egglib-go/core/application"
pG "github.com/linmadan/egglib-go/transaction/pg"
"github.com/tidwall/gjson"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
type ByteBankService struct {
... ... @@ -41,15 +44,16 @@ listLoop:
return formulaId
}
// SectionProductive 时段产能
func (svr *ByteBankService) SectionProductive() (interface{}, error) {
// DeviceOperationEfficiency 设备运行效率
func (svr *ByteBankService) DeviceOperationEfficiency() (interface{}, error) {
//获取公式id时段产能
formulaId := svr.GetFormulasId("type_salesman_id")
formulaId := svr.GetFormulasId("设备运行效率")
//获取解析数据
byteResult, err := svr.internalService.AnalysisFormulaByte(formulaId)
if err != nil {
return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
log.Logger.Debug("获取设备运行效率:" + string(byteResult))
code := gjson.GetBytes(byteResult, "code").String()
if code != "0" {
msg := gjson.GetBytes(byteResult, "msg").String()
... ... @@ -57,10 +61,66 @@ func (svr *ByteBankService) SectionProductive() (interface{}, error) {
}
//待解析的
queryResult := gjson.GetBytes(byteResult, "data.queryResult").Array()
/*
1.生产设备
2.设备本月运行数据
*/
transactionContext := pG.NewPGTransactionContext(pg.DB)
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//deviceRepository, _ := repository.NewDeviceRepository(transactionContext)
//_, devices, err := deviceRepository.Find(map[string]interface{}{
// "companyId": constant.MANUFACTURE_DEFAULT_COMPANYID,
// "orgId": constant.MANUFACTURE_DEFAULT_ORGID,
// "workshopId": constant.MANUFACTURE_DEFAULT_WORKSHOPID,
// "orderBy": "device_name asc"})
//if err != nil {
// return nil, err
//}
//var response = make([]interface{}, 0)
//for _, d := range devices {
// var deviceSn string
// var productCount, runningTime int64
// for _, item := range queryResult {
// deviceSn = item.Get("device_sn").String()
// if deviceSn == d.DeviceCode {
// productCount = item.Get("product_count").Int()
// runningTime = item.Get("timing").Int()
// break
// }
// }
// response = append(response, map[string]interface{}{
// "deviceName": d.DeviceName,
// "deviceType": d.DeviceType,
// "productCount": productCount,
// "timing": runningTime,
// })
//}
var response = make([]interface{}, 0)
var deviceSn string
var productCount, runningTime int64
for _, item := range queryResult {
if item.Get("type_salesman_id").String() != "" {
continue
deviceSn = item.Get("device_sn").String()
if deviceSn != "" {
productCount = item.Get("product_count").Int()
runningTime = item.Get("timing").Int()
response = append(response, map[string]interface{}{
"device_sn": deviceSn,
"device_type": item.Get("device_type").String(),
"product_count": productCount,
"timing": runningTime,
})
}
}
return nil, nil
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"devices": response}, nil
}
... ...
... ... @@ -27,6 +27,9 @@ const (
DeviceRunningStatistics = "DeviceRunningStatistics"
// 设备运行信息
DeviceRunningInfo = "DeviceRunningInfo"
// DeviceOperationEfficiency 字库-设备运行效率
DeviceOperationEfficiency = "device-operation-efficiency"
)
const (
... ... @@ -62,6 +65,11 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO
case DeviceRunningInfo:
result, err = ptr.DeviceRunningInfo(queryOptions)
break
case DeviceOperationEfficiency:
svr := NewByteBankService()
result, err = svr.DeviceOperationEfficiency()
break
}
return result, err
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"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/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"net/http"
"strconv"
... ... @@ -49,6 +50,24 @@ func (controller *StatisticsController) CommonStatisticsHandler(actionType strin
}
}
func (controller *StatisticsController) InternalRedirectHandler() func(ctx *context.Context) {
return func(ctx *context.Context) {
attendanceService := service.NewCommonStatisticsService(nil)
cmd := &query.CommonStatisticsQuery{}
options := make(map[string]interface{})
Unmarshal(ctx, &options)
actionType := ctx.Input.Query(":actionType")
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 (controller *StatisticsController) TaskHandler() func(ctx *context.Context) {
return func(ctx *context.Context) {
task := ctx.Input.Query(":taskId")
... ... @@ -91,6 +110,15 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context)
}
crontab.SyncProduct(bc)
break
case "9":
svr := domainService.NewByteBankService()
response, err := svr.DeviceOperationEfficiency()
if err != nil {
Response(ctx, nil, err)
return
}
Response(ctx, response, nil)
break
}
Response(ctx, nil, nil)
}
... ...
... ... @@ -15,4 +15,6 @@ func init() {
web.Post("/statistics/device-production-efficiency-statistics", c.CommonStatisticsHandler("DeviceProductionEfficiencyStatistics"))
web.Post("/statistics/device-running-statistics", c.CommonStatisticsHandler("DeviceRunningStatistics"))
web.Post("/statistics/device-running-info", c.CommonStatisticsHandler("DeviceRunningInfo"))
web.Post("/statistics/internal/:actionType", c.InternalRedirectHandler())
}
... ...