正在显示
5 个修改的文件
包含
105 行增加
和
6 行删除
| @@ -155,5 +155,6 @@ func NewHttpLibByteBankServiceGateway(host string) *HttpLibByteBankServiceGatewa | @@ -155,5 +155,6 @@ func NewHttpLibByteBankServiceGateway(host string) *HttpLibByteBankServiceGatewa | ||
| 155 | gt.ReadWriteTimeout = 10 * time.Second | 155 | gt.ReadWriteTimeout = 10 * time.Second |
| 156 | return &HttpLibByteBankServiceGateway{ | 156 | return &HttpLibByteBankServiceGateway{ |
| 157 | BaseServiceGateway: gt, | 157 | BaseServiceGateway: gt, |
| 158 | + baseURL: host, | ||
| 158 | } | 159 | } |
| 159 | } | 160 | } |
| @@ -2,9 +2,12 @@ package domainService | @@ -2,9 +2,12 @@ package domainService | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
| 5 | + pG "github.com/linmadan/egglib-go/transaction/pg" | ||
| 5 | "github.com/tidwall/gjson" | 6 | "github.com/tidwall/gjson" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
| 8 | ) | 11 | ) |
| 9 | 12 | ||
| 10 | type ByteBankService struct { | 13 | type ByteBankService struct { |
| @@ -41,15 +44,16 @@ listLoop: | @@ -41,15 +44,16 @@ listLoop: | ||
| 41 | return formulaId | 44 | return formulaId |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | -// SectionProductive 时段产能 | ||
| 45 | -func (svr *ByteBankService) SectionProductive() (interface{}, error) { | 47 | +// DeviceOperationEfficiency 设备运行效率 |
| 48 | +func (svr *ByteBankService) DeviceOperationEfficiency() (interface{}, error) { | ||
| 46 | //获取公式id时段产能 | 49 | //获取公式id时段产能 |
| 47 | - formulaId := svr.GetFormulasId("type_salesman_id") | 50 | + formulaId := svr.GetFormulasId("设备运行效率") |
| 48 | //获取解析数据 | 51 | //获取解析数据 |
| 49 | byteResult, err := svr.internalService.AnalysisFormulaByte(formulaId) | 52 | byteResult, err := svr.internalService.AnalysisFormulaByte(formulaId) |
| 50 | if err != nil { | 53 | if err != nil { |
| 51 | return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 54 | return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 52 | } | 55 | } |
| 56 | + log.Logger.Debug("获取设备运行效率:" + string(byteResult)) | ||
| 53 | code := gjson.GetBytes(byteResult, "code").String() | 57 | code := gjson.GetBytes(byteResult, "code").String() |
| 54 | if code != "0" { | 58 | if code != "0" { |
| 55 | msg := gjson.GetBytes(byteResult, "msg").String() | 59 | msg := gjson.GetBytes(byteResult, "msg").String() |
| @@ -57,10 +61,66 @@ func (svr *ByteBankService) SectionProductive() (interface{}, error) { | @@ -57,10 +61,66 @@ func (svr *ByteBankService) SectionProductive() (interface{}, error) { | ||
| 57 | } | 61 | } |
| 58 | //待解析的 | 62 | //待解析的 |
| 59 | queryResult := gjson.GetBytes(byteResult, "data.queryResult").Array() | 63 | queryResult := gjson.GetBytes(byteResult, "data.queryResult").Array() |
| 64 | + | ||
| 65 | + /* | ||
| 66 | + 1.生产设备 | ||
| 67 | + 2.设备本月运行数据 | ||
| 68 | + */ | ||
| 69 | + transactionContext := pG.NewPGTransactionContext(pg.DB) | ||
| 70 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 72 | + } | ||
| 73 | + defer func() { | ||
| 74 | + transactionContext.RollbackTransaction() | ||
| 75 | + }() | ||
| 76 | + //deviceRepository, _ := repository.NewDeviceRepository(transactionContext) | ||
| 77 | + //_, devices, err := deviceRepository.Find(map[string]interface{}{ | ||
| 78 | + // "companyId": constant.MANUFACTURE_DEFAULT_COMPANYID, | ||
| 79 | + // "orgId": constant.MANUFACTURE_DEFAULT_ORGID, | ||
| 80 | + // "workshopId": constant.MANUFACTURE_DEFAULT_WORKSHOPID, | ||
| 81 | + // "orderBy": "device_name asc"}) | ||
| 82 | + //if err != nil { | ||
| 83 | + // return nil, err | ||
| 84 | + //} | ||
| 85 | + //var response = make([]interface{}, 0) | ||
| 86 | + //for _, d := range devices { | ||
| 87 | + // var deviceSn string | ||
| 88 | + // var productCount, runningTime int64 | ||
| 89 | + // for _, item := range queryResult { | ||
| 90 | + // deviceSn = item.Get("device_sn").String() | ||
| 91 | + // if deviceSn == d.DeviceCode { | ||
| 92 | + // productCount = item.Get("product_count").Int() | ||
| 93 | + // runningTime = item.Get("timing").Int() | ||
| 94 | + // break | ||
| 95 | + // } | ||
| 96 | + // } | ||
| 97 | + // response = append(response, map[string]interface{}{ | ||
| 98 | + // "deviceName": d.DeviceName, | ||
| 99 | + // "deviceType": d.DeviceType, | ||
| 100 | + // "productCount": productCount, | ||
| 101 | + // "timing": runningTime, | ||
| 102 | + // }) | ||
| 103 | + //} | ||
| 104 | + | ||
| 105 | + var response = make([]interface{}, 0) | ||
| 106 | + var deviceSn string | ||
| 107 | + var productCount, runningTime int64 | ||
| 60 | for _, item := range queryResult { | 108 | for _, item := range queryResult { |
| 61 | - if item.Get("type_salesman_id").String() != "" { | ||
| 62 | - continue | 109 | + deviceSn = item.Get("device_sn").String() |
| 110 | + if deviceSn != "" { | ||
| 111 | + productCount = item.Get("product_count").Int() | ||
| 112 | + runningTime = item.Get("timing").Int() | ||
| 113 | + response = append(response, map[string]interface{}{ | ||
| 114 | + "device_sn": deviceSn, | ||
| 115 | + "device_type": item.Get("device_type").String(), | ||
| 116 | + "product_count": productCount, | ||
| 117 | + "timing": runningTime, | ||
| 118 | + }) | ||
| 63 | } | 119 | } |
| 64 | } | 120 | } |
| 65 | - return nil, nil | 121 | + |
| 122 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 123 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 124 | + } | ||
| 125 | + return map[string]interface{}{"devices": response}, nil | ||
| 66 | } | 126 | } |
| @@ -27,6 +27,9 @@ const ( | @@ -27,6 +27,9 @@ const ( | ||
| 27 | DeviceRunningStatistics = "DeviceRunningStatistics" | 27 | DeviceRunningStatistics = "DeviceRunningStatistics" |
| 28 | // 设备运行信息 | 28 | // 设备运行信息 |
| 29 | DeviceRunningInfo = "DeviceRunningInfo" | 29 | DeviceRunningInfo = "DeviceRunningInfo" |
| 30 | + | ||
| 31 | + // DeviceOperationEfficiency 字库-设备运行效率 | ||
| 32 | + DeviceOperationEfficiency = "device-operation-efficiency" | ||
| 30 | ) | 33 | ) |
| 31 | 34 | ||
| 32 | const ( | 35 | const ( |
| @@ -62,6 +65,11 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO | @@ -62,6 +65,11 @@ func (ptr *PGCommonStatisticsService) CommonStatistics(actionType string, queryO | ||
| 62 | case DeviceRunningInfo: | 65 | case DeviceRunningInfo: |
| 63 | result, err = ptr.DeviceRunningInfo(queryOptions) | 66 | result, err = ptr.DeviceRunningInfo(queryOptions) |
| 64 | break | 67 | break |
| 68 | + | ||
| 69 | + case DeviceOperationEfficiency: | ||
| 70 | + svr := NewByteBankService() | ||
| 71 | + result, err = svr.DeviceOperationEfficiency() | ||
| 72 | + break | ||
| 65 | } | 73 | } |
| 66 | return result, err | 74 | return result, err |
| 67 | } | 75 | } |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/service" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/service" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
| 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
| 14 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | ||
| 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
| 15 | "net/http" | 16 | "net/http" |
| 16 | "strconv" | 17 | "strconv" |
| @@ -49,6 +50,24 @@ func (controller *StatisticsController) CommonStatisticsHandler(actionType strin | @@ -49,6 +50,24 @@ func (controller *StatisticsController) CommonStatisticsHandler(actionType strin | ||
| 49 | } | 50 | } |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 53 | +func (controller *StatisticsController) InternalRedirectHandler() func(ctx *context.Context) { | ||
| 54 | + return func(ctx *context.Context) { | ||
| 55 | + attendanceService := service.NewCommonStatisticsService(nil) | ||
| 56 | + cmd := &query.CommonStatisticsQuery{} | ||
| 57 | + options := make(map[string]interface{}) | ||
| 58 | + Unmarshal(ctx, &options) | ||
| 59 | + | ||
| 60 | + actionType := ctx.Input.Query(":actionType") | ||
| 61 | + operateInfo := ContextParseOperateInfo(ctx) | ||
| 62 | + options["companyId"] = operateInfo.CompanyId | ||
| 63 | + options["orgId"] = operateInfo.OrgId | ||
| 64 | + cmd.Action = actionType | ||
| 65 | + cmd.QueryOptions = options | ||
| 66 | + data, err := attendanceService.CommonStatisticsService(cmd) | ||
| 67 | + Response(ctx, data, err) | ||
| 68 | + } | ||
| 69 | +} | ||
| 70 | + | ||
| 52 | func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) { | 71 | func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) { |
| 53 | return func(ctx *context.Context) { | 72 | return func(ctx *context.Context) { |
| 54 | task := ctx.Input.Query(":taskId") | 73 | task := ctx.Input.Query(":taskId") |
| @@ -91,6 +110,15 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | @@ -91,6 +110,15 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context) | ||
| 91 | } | 110 | } |
| 92 | crontab.SyncProduct(bc) | 111 | crontab.SyncProduct(bc) |
| 93 | break | 112 | break |
| 113 | + case "9": | ||
| 114 | + svr := domainService.NewByteBankService() | ||
| 115 | + response, err := svr.DeviceOperationEfficiency() | ||
| 116 | + if err != nil { | ||
| 117 | + Response(ctx, nil, err) | ||
| 118 | + return | ||
| 119 | + } | ||
| 120 | + Response(ctx, response, nil) | ||
| 121 | + break | ||
| 94 | } | 122 | } |
| 95 | Response(ctx, nil, nil) | 123 | Response(ctx, nil, nil) |
| 96 | } | 124 | } |
| @@ -15,4 +15,6 @@ func init() { | @@ -15,4 +15,6 @@ func init() { | ||
| 15 | web.Post("/statistics/device-production-efficiency-statistics", c.CommonStatisticsHandler("DeviceProductionEfficiencyStatistics")) | 15 | web.Post("/statistics/device-production-efficiency-statistics", c.CommonStatisticsHandler("DeviceProductionEfficiencyStatistics")) |
| 16 | web.Post("/statistics/device-running-statistics", c.CommonStatisticsHandler("DeviceRunningStatistics")) | 16 | web.Post("/statistics/device-running-statistics", c.CommonStatisticsHandler("DeviceRunningStatistics")) |
| 17 | web.Post("/statistics/device-running-info", c.CommonStatisticsHandler("DeviceRunningInfo")) | 17 | web.Post("/statistics/device-running-info", c.CommonStatisticsHandler("DeviceRunningInfo")) |
| 18 | + | ||
| 19 | + web.Post("/statistics/internal/:actionType", c.InternalRedirectHandler()) | ||
| 18 | } | 20 | } |
-
请 注册 或 登录 后发表评论