正在显示
15 个修改的文件
包含
400 行增加
和
18 行删除
| @@ -119,9 +119,9 @@ spec: | @@ -119,9 +119,9 @@ spec: | ||
| 119 | - name: MANUFACTURE_DEFAULT_ORGID | 119 | - name: MANUFACTURE_DEFAULT_ORGID |
| 120 | value: "487" | 120 | value: "487" |
| 121 | - name: MANUFACTURE_DEFAULT_WORKSHOPID | 121 | - name: MANUFACTURE_DEFAULT_WORKSHOPID |
| 122 | - value: "2" | 122 | + value: "28" |
| 123 | - name: MANUFACTURE_PRODUCT_TYPE | 123 | - name: MANUFACTURE_PRODUCT_TYPE |
| 124 | - value: "0502010004ST,0502010004ST" | 124 | + value: "SG,SG" |
| 125 | - name: MQTT_HOST | 125 | - name: MQTT_HOST |
| 126 | value: "47.97.5.102" | 126 | value: "47.97.5.102" |
| 127 | - name: MQTT_PORT | 127 | - name: MQTT_PORT |
| @@ -37,7 +37,7 @@ func AutoWorkshopPlanCompletionRecord(ctx context.Context) error { | @@ -37,7 +37,7 @@ func AutoWorkshopPlanCompletionRecord(ctx context.Context) error { | ||
| 37 | begin := utils.GetZeroTime(end.Add(-time.Second)) | 37 | begin := utils.GetZeroTime(end.Add(-time.Second)) |
| 38 | approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext)) | 38 | approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext)) |
| 39 | 39 | ||
| 40 | - if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end); err != nil { | 40 | + if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "yesterday"); err != nil { |
| 41 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新车间计划完成纪录"}) | 41 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新车间计划完成纪录"}) |
| 42 | return err | 42 | return err |
| 43 | } | 43 | } |
| @@ -74,7 +74,7 @@ func AutoTodayWorkshopPlanCompletionRecord(ctx context.Context) error { | @@ -74,7 +74,7 @@ func AutoTodayWorkshopPlanCompletionRecord(ctx context.Context) error { | ||
| 74 | end := time.Now() | 74 | end := time.Now() |
| 75 | approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext)) | 75 | approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext)) |
| 76 | 76 | ||
| 77 | - if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end); err != nil { | 77 | + if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "today"); err != nil { |
| 78 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新当天车间计划完成纪录"}) | 78 | log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新当天车间计划完成纪录"}) |
| 79 | return err | 79 | return err |
| 80 | } | 80 | } |
| @@ -13,6 +13,7 @@ import ( | @@ -13,6 +13,7 @@ import ( | ||
| 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
| 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
| 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
| 16 | + "math/rand" | ||
| 16 | "strconv" | 17 | "strconv" |
| 17 | "sync" | 18 | "sync" |
| 18 | "time" | 19 | "time" |
| @@ -143,9 +144,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -143,9 +144,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
| 143 | } | 144 | } |
| 144 | } | 145 | } |
| 145 | // TODO:测试假数据,后期注释掉 | 146 | // TODO:测试假数据,后期注释掉 |
| 146 | - //if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
| 147 | - // newDeviceCollection.Values["Count"] = rand.Intn(300) | ||
| 148 | - //} | 147 | + if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { |
| 148 | + newDeviceCollection.Values["Count"] = rand.Intn(300) | ||
| 149 | + } | ||
| 149 | deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection) | 150 | deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection) |
| 150 | if err != nil { | 151 | if err != nil { |
| 151 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 152 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -22,6 +22,8 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio | @@ -22,6 +22,8 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio | ||
| 22 | //天联共创业务模块 | 22 | //天联共创业务模块 |
| 23 | var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" | 23 | var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" |
| 24 | 24 | ||
| 25 | +var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" | ||
| 26 | + | ||
| 25 | var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | 27 | var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} |
| 26 | 28 | ||
| 27 | const CUSTOMER_ACCOUNT_DELIMITER = "," | 29 | const CUSTOMER_ACCOUNT_DELIMITER = "," |
| @@ -64,7 +66,9 @@ func init() { | @@ -64,7 +66,9 @@ func init() { | ||
| 64 | //if os.Getenv("SMS_SERVE_HOST") != "" { | 66 | //if os.Getenv("SMS_SERVE_HOST") != "" { |
| 65 | // SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST") | 67 | // SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST") |
| 66 | //} | 68 | //} |
| 67 | - | 69 | + if os.Getenv("MMM_BYTE_BANK_HOST") != "" { |
| 70 | + MMM_BYTE_BANK_HOST = os.Getenv("MMM_BYTE_BANK_HOST") | ||
| 71 | + } | ||
| 68 | if os.Getenv("SERVICE_ENV") != "" { | 72 | if os.Getenv("SERVICE_ENV") != "" { |
| 69 | SERVICE_ENV = os.Getenv("SERVICE_ENV") | 73 | SERVICE_ENV = os.Getenv("SERVICE_ENV") |
| 70 | } | 74 | } |
| @@ -137,8 +137,8 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device | @@ -137,8 +137,8 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device | ||
| 137 | d.Temp2 = data.Temp2 | 137 | d.Temp2 = data.Temp2 |
| 138 | d.AddTimeLineDeviceStatus(t, data) | 138 | d.AddTimeLineDeviceStatus(t, data) |
| 139 | 139 | ||
| 140 | - //d.OEE | ||
| 141 | - d.TimeUtilization = utils.Round(d.UpTime*100/(time.Now().Sub(utils.GetZeroTime(time.Now())).Minutes()), 2) | 140 | + //d.OEE (time.Now().Sub(utils.GetZeroTime(time.Now())).Minutes()) |
| 141 | + d.TimeUtilization = utils.Round((d.UpTime*100)/(24*60), 2) | ||
| 142 | //d.PerformanceUtilization | 142 | //d.PerformanceUtilization |
| 143 | //d.QualificationUtilization | 143 | //d.QualificationUtilization |
| 144 | } | 144 | } |
| @@ -175,7 +175,7 @@ func (d *DeviceRunningRecordInfo) ResetUpTime() float64 { | @@ -175,7 +175,7 @@ func (d *DeviceRunningRecordInfo) ResetUpTime() float64 { | ||
| 175 | func (d *DeviceRunningRecordInfo) ResetOEE(pu, qu float64) float64 { | 175 | func (d *DeviceRunningRecordInfo) ResetOEE(pu, qu float64) float64 { |
| 176 | d.PerformanceUtilization = pu | 176 | d.PerformanceUtilization = pu |
| 177 | d.QualificationUtilization = qu | 177 | d.QualificationUtilization = qu |
| 178 | - d.OEE = utils.Round((d.TimeUtilization+d.PerformanceUtilization+d.QualificationUtilization)/3, 1) | 178 | + d.OEE = utils.Round((d.TimeUtilization*d.PerformanceUtilization*d.QualificationUtilization)/10000, 1) |
| 179 | return d.OEE | 179 | return d.OEE |
| 180 | } | 180 | } |
| 181 | 181 |
| 1 | +package byte_bank | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 6 | + gatewayLib "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway" | ||
| 7 | + translator2 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank/translator" | ||
| 8 | + "strconv" | ||
| 9 | + "strings" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type HttpLibByteBankServiceGateway struct { | ||
| 14 | + gatewayLib.BaseServiceGateway | ||
| 15 | + baseURL string | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +// ListFormulas 列出所有公式 | ||
| 19 | +func (serviceGateway *HttpLibByteBankServiceGateway) ListFormulas(pageSize int64, pageNumber int64) (*translator2.Formula, error) { | ||
| 20 | + url := strings.Join([]string{serviceGateway.baseURL, "formulas"}, "/") | ||
| 21 | + request := serviceGateway.CreateRequest(url, "get") | ||
| 22 | + request.Param("pageSize", strconv.FormatInt(pageSize, 10)) | ||
| 23 | + request.Param("pageNumber", strconv.FormatInt(pageNumber, 10)) | ||
| 24 | + byteResult, err := request.Bytes() | ||
| 25 | + if err != nil { | ||
| 26 | + return nil, fmt.Errorf("获取列表列表失败:%w", err) | ||
| 27 | + } | ||
| 28 | + var result gatewayLib.Response | ||
| 29 | + err = json.Unmarshal(byteResult, &result) | ||
| 30 | + if err != nil { | ||
| 31 | + return nil, fmt.Errorf("解析公式列表失败:%w", err) | ||
| 32 | + } | ||
| 33 | + var data translator2.Formula | ||
| 34 | + err = serviceGateway.GetResponseData(result, &data) | ||
| 35 | + return &data, err | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +func (serviceGateway *HttpLibByteBankServiceGateway) GetFormula(formulaId string) (*translator2.FormulaDetail, error) { | ||
| 39 | + url := strings.Join([]string{serviceGateway.baseURL, "/formulas/" + formulaId}, "/") | ||
| 40 | + request := serviceGateway.CreateRequest(url, "get") | ||
| 41 | + byteResult, err := request.Bytes() | ||
| 42 | + if err != nil { | ||
| 43 | + return nil, fmt.Errorf("获取列表列表失败:%w", err) | ||
| 44 | + } | ||
| 45 | + var result gatewayLib.Response | ||
| 46 | + err = json.Unmarshal(byteResult, &result) | ||
| 47 | + if err != nil { | ||
| 48 | + return nil, fmt.Errorf("解析公式列表失败:%w", err) | ||
| 49 | + } | ||
| 50 | + var data translator2.FormulaDetail | ||
| 51 | + err = serviceGateway.GetResponseData(result, &data) | ||
| 52 | + return &data, err | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +// AnalysisFormula 方案解析 | ||
| 56 | +func (serviceGateway *HttpLibByteBankServiceGateway) AnalysisFormula(formulaId int64) (*translator2.AnalysisFormulaDetail, error) { | ||
| 57 | + url := strings.Join([]string{serviceGateway.baseURL, "sql/ad-hoc/for-formula"}, "/") | ||
| 58 | + request := serviceGateway.CreateRequest(url, "post") | ||
| 59 | + options := make(map[string]interface{}) | ||
| 60 | + options["formulaId"] = strconv.FormatInt(formulaId, 10) | ||
| 61 | + _, err := request.JSONBody(options) | ||
| 62 | + if err != nil { | ||
| 63 | + return nil, err | ||
| 64 | + } | ||
| 65 | + byteResult, err := request.Bytes() | ||
| 66 | + if err != nil { | ||
| 67 | + return nil, fmt.Errorf("方案解析失败失败:%w", err) | ||
| 68 | + } | ||
| 69 | + var result gatewayLib.Response | ||
| 70 | + err = json.Unmarshal(byteResult, &result) | ||
| 71 | + if err != nil { | ||
| 72 | + return nil, fmt.Errorf("解析方案解析结果失败:%w", err) | ||
| 73 | + } | ||
| 74 | + var data translator2.AnalysisFormulaDetail | ||
| 75 | + err = serviceGateway.GetResponseData(result, &data) | ||
| 76 | + return &data, err | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +// AnalysisFormula 方案解析 | ||
| 80 | +func (serviceGateway *HttpLibByteBankServiceGateway) AnalysisFormulaByte(formulaId string) ([]byte, error) { | ||
| 81 | + url := strings.Join([]string{serviceGateway.baseURL, "sql/ad-hoc/for-formula"}, "/") | ||
| 82 | + request := serviceGateway.CreateRequest(url, "post") | ||
| 83 | + options := make(map[string]interface{}) | ||
| 84 | + options["formulaId"] = formulaId | ||
| 85 | + _, err := request.JSONBody(options) | ||
| 86 | + if err != nil { | ||
| 87 | + return nil, err | ||
| 88 | + } | ||
| 89 | + byteResult, err := request.Bytes() | ||
| 90 | + if err != nil { | ||
| 91 | + return byteResult, fmt.Errorf("方案解析失败失败:%w", err) | ||
| 92 | + } | ||
| 93 | + return byteResult, err | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +// ListDataApplications 列出所有数据应用 | ||
| 97 | +func (serviceGateway *HttpLibByteBankServiceGateway) ListDataApplications(pageSize int64, pageNumber int64) (*translator2.DataApplication, error) { | ||
| 98 | + url := strings.Join([]string{serviceGateway.baseURL, "data-applications"}, "/") | ||
| 99 | + request := serviceGateway.CreateRequest(url, "get") | ||
| 100 | + request.Param("pageSize", strconv.FormatInt(pageSize, 10)) | ||
| 101 | + request.Param("pageNumber", strconv.FormatInt(pageNumber, 10)) | ||
| 102 | + byteResult, err := request.Bytes() | ||
| 103 | + if err != nil { | ||
| 104 | + return nil, fmt.Errorf("获取应用列表失败:%w", err) | ||
| 105 | + } | ||
| 106 | + var result gatewayLib.Response | ||
| 107 | + err = json.Unmarshal(byteResult, &result) | ||
| 108 | + if err != nil { | ||
| 109 | + return nil, fmt.Errorf("解析应用列表失败:%w", err) | ||
| 110 | + } | ||
| 111 | + var data translator2.DataApplication | ||
| 112 | + err = serviceGateway.GetResponseData(result, &data) | ||
| 113 | + return &data, err | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +// StartDataApplication 启动数据应用 | ||
| 117 | +func (serviceGateway *HttpLibByteBankServiceGateway) StartDataApplication(dataApplicationId int64) (map[string]interface{}, error) { | ||
| 118 | + dataApplicationIdString := strconv.FormatInt(dataApplicationId, 10) | ||
| 119 | + url := strings.Join([]string{serviceGateway.baseURL, "data-applications/" + dataApplicationIdString + "/data-job/launch"}, "/") | ||
| 120 | + request := serviceGateway.CreateRequest(url, "post") | ||
| 121 | + response := make(map[string]interface{}) | ||
| 122 | + err := request.ToJSON(&response) | ||
| 123 | + if err != nil { | ||
| 124 | + //log.Logger.Error("Service Gateway Fail") | ||
| 125 | + return nil, err | ||
| 126 | + } | ||
| 127 | + data, err := serviceGateway.responseHandle(response) | ||
| 128 | + return data, err | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +func (serviceGateway *HttpLibByteBankServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) { | ||
| 132 | + data := make(map[string]interface{}) | ||
| 133 | + var err error | ||
| 134 | + if code, ok := response["code"]; ok { | ||
| 135 | + code := code.(float64) | ||
| 136 | + if code == 0 { | ||
| 137 | + data = response["data"].(map[string]interface{}) | ||
| 138 | + } else { | ||
| 139 | + msg := response["msg"].(string) | ||
| 140 | + err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " ")) | ||
| 141 | + } | ||
| 142 | + } else { | ||
| 143 | + jsonBytes, marshalErr := json.Marshal(response) | ||
| 144 | + if marshalErr != nil { | ||
| 145 | + err = marshalErr | ||
| 146 | + } | ||
| 147 | + err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes)) | ||
| 148 | + } | ||
| 149 | + return data, err | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +func NewHttpLibByteBankServiceGateway(host string) *HttpLibByteBankServiceGateway { | ||
| 153 | + gt := gatewayLib.NewBaseServiceGateway(host) | ||
| 154 | + gt.ConnectTimeout = 10 * time.Second | ||
| 155 | + gt.ReadWriteTimeout = 10 * time.Second | ||
| 156 | + return &HttpLibByteBankServiceGateway{ | ||
| 157 | + BaseServiceGateway: gt, | ||
| 158 | + } | ||
| 159 | +} |
pkg/infrastructure/allied-lib/gateway/byte_bank/translator/analysis_formula_translator.go
0 → 100644
| 1 | +package translator | ||
| 2 | + | ||
| 3 | +type AnalysisFormulaTranslator struct { | ||
| 4 | +} | ||
| 5 | + | ||
| 6 | +type QueryResult struct { | ||
| 7 | + Date string `json:"date"` | ||
| 8 | + Uid string `json:"uid"` | ||
| 9 | + Value string `json:"value"` | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +type AnalysisFormulaDetail struct { | ||
| 13 | + QueryColumnMap struct { | ||
| 14 | + Date struct { | ||
| 15 | + Description string `json:"description"` | ||
| 16 | + Sort int `json:"sort"` | ||
| 17 | + } `json:"date"` | ||
| 18 | + Uid struct { | ||
| 19 | + Description string `json:"description"` | ||
| 20 | + Sort int `json:"sort"` | ||
| 21 | + } `json:"uid"` | ||
| 22 | + Value struct { | ||
| 23 | + Description string `json:"description"` | ||
| 24 | + Sort int `json:"sort"` | ||
| 25 | + } `json:"value"` | ||
| 26 | + } `json:"queryColumnMap"` | ||
| 27 | + QueryResult []*QueryResult `json:"queryResult"` | ||
| 28 | + SqlExpressionError string `json:"sqlExpressionError"` | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func NewAnalysisFormulaTranslator() (*AnalysisFormulaTranslator, error) { | ||
| 32 | + return &AnalysisFormulaTranslator{}, nil | ||
| 33 | +} |
pkg/infrastructure/allied-lib/gateway/byte_bank/translator/data_application_translator.go
0 → 100644
| 1 | +package translator | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type DataApplicationTranslator struct { | ||
| 6 | +} | ||
| 7 | + | ||
| 8 | +type DataApplicationDetail struct { | ||
| 9 | + DataApplicationId string `json:"dataApplicationId"` | ||
| 10 | + DataApplicationMark string `json:"dataApplicationMark"` | ||
| 11 | + DataApplicationTitle string `json:"dataApplicationTitle"` | ||
| 12 | + DataApplicationLaunchType int32 `json:"dataApplicationLaunchType"` | ||
| 13 | + DataApplicationTags []interface{} `json:"dataApplicationTags"` | ||
| 14 | + Description string `json:"description"` | ||
| 15 | + CreateTime time.Time `json:"createTime"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +type DataApplication struct { | ||
| 19 | + Count int64 `json:"count"` | ||
| 20 | + DataApplications []*DataApplicationDetail `json:"dataApplications"` | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func NewDataApplicationTranslator() (*DataApplicationTranslator, error) { | ||
| 24 | + return &DataApplicationTranslator{}, nil | ||
| 25 | +} |
| 1 | +package translator | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type FormulaTranslator struct { | ||
| 6 | +} | ||
| 7 | + | ||
| 8 | +type Formula struct { | ||
| 9 | + Count int64 `json:"count"` | ||
| 10 | + Formulas []FormulaDetail `json:"formulas"` | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +type FormulaDetail struct { | ||
| 14 | + CreateTime time.Time `json:"createTime"` | ||
| 15 | + DataApplicationMark string `json:"dataApplicationMark"` | ||
| 16 | + FormulaCalculateType int `json:"formulaCalculateType"` | ||
| 17 | + FormulaConditions []struct { | ||
| 18 | + FormulaCondition struct { | ||
| 19 | + FormulaConditionExpression string `json:"formulaConditionExpression"` | ||
| 20 | + FormulaConditionLeftField struct { | ||
| 21 | + FormulaFieldDescription string `json:"formulaFieldDescription"` | ||
| 22 | + FormulaFieldName string `json:"formulaFieldName"` | ||
| 23 | + FormulaFieldType string `json:"formulaFieldType"` | ||
| 24 | + FromDataBaseName string `json:"fromDataBaseName"` | ||
| 25 | + FromDataSetName string `json:"fromDataSetName"` | ||
| 26 | + } `json:"formulaConditionLeftField"` | ||
| 27 | + FormulaConditionOperator string `json:"formulaConditionOperator"` | ||
| 28 | + FormulaConditionRightField struct { | ||
| 29 | + FormulaFieldDescription string `json:"formulaFieldDescription"` | ||
| 30 | + FormulaFieldName string `json:"formulaFieldName"` | ||
| 31 | + FormulaFieldType string `json:"formulaFieldType"` | ||
| 32 | + FromDataBaseName string `json:"fromDataBaseName"` | ||
| 33 | + FromDataSetName string `json:"fromDataSetName"` | ||
| 34 | + } `json:"formulaConditionRightField"` | ||
| 35 | + FormulaConditionRightValue string `json:"formulaConditionRightValue"` | ||
| 36 | + FormulaConditionType int `json:"formulaConditionType"` | ||
| 37 | + } `json:"formulaCondition"` | ||
| 38 | + OrConditions []interface{} `json:"orConditions"` | ||
| 39 | + } `json:"formulaConditions"` | ||
| 40 | + FormulaDescription string `json:"formulaDescription"` | ||
| 41 | + FormulaGenSqlExpression string `json:"formulaGenSqlExpression"` | ||
| 42 | + FormulaGroup struct { | ||
| 43 | + CreateTime time.Time `json:"createTime"` | ||
| 44 | + FormulaGroupId string `json:"formulaGroupId"` | ||
| 45 | + FormulaGroupName string `json:"formulaGroupName"` | ||
| 46 | + FormulaGroupParentId string `json:"formulaGroupParentId"` | ||
| 47 | + SortNumber int `json:"sortNumber"` | ||
| 48 | + } `json:"formulaGroup"` | ||
| 49 | + FormulaId string `json:"formulaId"` | ||
| 50 | + FormulaName string `json:"formulaName"` | ||
| 51 | + FormulaSelectFields []struct { | ||
| 52 | + FormulaField struct { | ||
| 53 | + FormulaFieldDescription string `json:"formulaFieldDescription"` | ||
| 54 | + FormulaFieldName string `json:"formulaFieldName"` | ||
| 55 | + FormulaFieldType string `json:"formulaFieldType"` | ||
| 56 | + FromDataBaseName string `json:"fromDataBaseName"` | ||
| 57 | + FromDataSetName string `json:"fromDataSetName"` | ||
| 58 | + } `json:"formulaField"` | ||
| 59 | + FormulaSelectFieldExpression string `json:"formulaSelectFieldExpression"` | ||
| 60 | + FormulaSelectFieldIsGroup bool `json:"formulaSelectFieldIsGroup"` | ||
| 61 | + FormulaSelectFieldType int `json:"formulaSelectFieldType"` | ||
| 62 | + SortNumber int `json:"sortNumber"` | ||
| 63 | + } `json:"formulaSelectFields"` | ||
| 64 | + FormulaSqlExpression string `json:"formulaSqlExpression"` | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +func NewFormulaTranslator() (*FormulaTranslator, error) { | ||
| 68 | + return &FormulaTranslator{}, nil | ||
| 69 | +} |
| @@ -26,7 +26,8 @@ from manufacture.product_records | @@ -26,7 +26,8 @@ from manufacture.product_records | ||
| 26 | where company_id = ? | 26 | where company_id = ? |
| 27 | and org_id =? | 27 | and org_id =? |
| 28 | and work_station->>'workshopId'='?' | 28 | and work_station->>'workshopId'='?' |
| 29 | -and product_record_type in (1,2) | 29 | +and work_station->>'sectionName'='包装' |
| 30 | +and product_record_type in (1,2,8) | ||
| 30 | and created_at>=? | 31 | and created_at>=? |
| 31 | and created_at<? | 32 | and created_at<? |
| 32 | ), product_record_sum as( | 33 | ), product_record_sum as( |
| @@ -37,13 +38,14 @@ select | @@ -37,13 +38,14 @@ select | ||
| 37 | plan_devoted->>'weight' plan_weight -- 计划重量 | 38 | plan_devoted->>'weight' plan_weight -- 计划重量 |
| 38 | , coalesce(b.weight,0) real_weight --批次实际产能 | 39 | , coalesce(b.weight,0) real_weight --批次实际产能 |
| 39 | ,a.product_plan_id | 40 | ,a.product_plan_id |
| 41 | +,a.product_date | ||
| 40 | from manufacture.product_plan a left join product_record_sum b on a.product_plan_id = b.plan_id | 42 | from manufacture.product_plan a left join product_record_sum b on a.product_plan_id = b.plan_id |
| 41 | where company_id = ? | 43 | where company_id = ? |
| 42 | and org_id =? | 44 | and org_id =? |
| 43 | and workshop->>'workshopId'='?' | 45 | and workshop->>'workshopId'='?' |
| 44 | -and created_at >=? | ||
| 45 | -and created_at<? | ||
| 46 | -order by created_at desc`) | 46 | +and product_date >=? |
| 47 | +--and created_at<? | ||
| 48 | +--order by created_at desc`) | ||
| 47 | if _, err := tx.Query(records, sql, | 49 | if _, err := tx.Query(records, sql, |
| 48 | companyId, orgId, workshopId, begin, end, | 50 | companyId, orgId, workshopId, begin, end, |
| 49 | companyId, orgId, workshopId, begin, end); err != nil { | 51 | companyId, orgId, workshopId, begin, end); err != nil { |
| 1 | +package domainService | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "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/infrastructure/allied-lib/gateway/byte_bank" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type ByteBankService struct { | ||
| 11 | + internalService *byte_bank.HttpLibByteBankServiceGateway | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func NewByteBankService() *ByteBankService { | ||
| 15 | + return &ByteBankService{ | ||
| 16 | + internalService: byte_bank.NewHttpLibByteBankServiceGateway(constant.MMM_BYTE_BANK_HOST), | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +//GetFormulasId 获取公式id | ||
| 21 | +func (svr *ByteBankService) GetFormulasId(formulaName string) string { | ||
| 22 | + //获取公式id | ||
| 23 | + formulaId := "" | ||
| 24 | +listLoop: | ||
| 25 | + for i := 0; ; i++ { | ||
| 26 | + data, err := svr.internalService.ListFormulas(1000, int64(i)) | ||
| 27 | + if err != nil { | ||
| 28 | + return "" | ||
| 29 | + } | ||
| 30 | + if len(data.Formulas) == 0 { | ||
| 31 | + break listLoop | ||
| 32 | + } | ||
| 33 | + for _, item := range data.Formulas { | ||
| 34 | + | ||
| 35 | + if item.FormulaDescription == formulaName { | ||
| 36 | + formulaId = item.FormulaId | ||
| 37 | + break listLoop | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + return formulaId | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// SectionProductive 时段产能 | ||
| 45 | +func (svr *ByteBankService) SectionProductive() (interface{}, error) { | ||
| 46 | + //获取公式id时段产能 | ||
| 47 | + formulaId := svr.GetFormulasId("type_salesman_id") | ||
| 48 | + //获取解析数据 | ||
| 49 | + byteResult, err := svr.internalService.AnalysisFormulaByte(formulaId) | ||
| 50 | + if err != nil { | ||
| 51 | + return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 52 | + } | ||
| 53 | + code := gjson.GetBytes(byteResult, "code").String() | ||
| 54 | + if code != "0" { | ||
| 55 | + msg := gjson.GetBytes(byteResult, "msg").String() | ||
| 56 | + return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, msg) | ||
| 57 | + } | ||
| 58 | + //待解析的 | ||
| 59 | + queryResult := gjson.GetBytes(byteResult, "data.queryResult").Array() | ||
| 60 | + for _, item := range queryResult { | ||
| 61 | + if item.Get("type_salesman_id").String() != "" { | ||
| 62 | + continue | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + return nil, nil | ||
| 66 | +} |
| @@ -289,7 +289,6 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | @@ -289,7 +289,6 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s | ||
| 289 | if err != nil { | 289 | if err != nil { |
| 290 | return nil, err | 290 | return nil, err |
| 291 | } | 291 | } |
| 292 | - | ||
| 293 | var response = make([]interface{}, 0) | 292 | var response = make([]interface{}, 0) |
| 294 | _, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": t}) | 293 | _, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": t}) |
| 295 | for i := 0; i < len(devices); i++ { | 294 | for i := 0; i < len(devices); i++ { |
| @@ -28,11 +28,12 @@ func NewPGWorkshopPlanCompletionRecordService(transactionContext *pgTransaction. | @@ -28,11 +28,12 @@ func NewPGWorkshopPlanCompletionRecordService(transactionContext *pgTransaction. | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | // 车间完成统计 | 30 | // 车间完成统计 |
| 31 | -func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin time.Time, end time.Time) error { | 31 | +func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin time.Time, end time.Time, planIn string) error { |
| 32 | type record struct { | 32 | type record struct { |
| 33 | PlanWeight float64 `json:"plan_weight"` | 33 | PlanWeight float64 `json:"plan_weight"` |
| 34 | RealWeight float64 `json:"real_weight"` | 34 | RealWeight float64 `json:"real_weight"` |
| 35 | ProductPlanId float64 `json:"product_plan_id"` | 35 | ProductPlanId float64 `json:"product_plan_id"` |
| 36 | + ProductDate time.Time `json:"product_date"` | ||
| 36 | } | 37 | } |
| 37 | cid := constant.MANUFACTURE_DEFAULT_COMPANYID | 38 | cid := constant.MANUFACTURE_DEFAULT_COMPANYID |
| 38 | oid := constant.MANUFACTURE_DEFAULT_ORGID | 39 | oid := constant.MANUFACTURE_DEFAULT_ORGID |
| @@ -54,6 +55,11 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | @@ -54,6 +55,11 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | ||
| 54 | var totalPlan float64 = 0 | 55 | var totalPlan float64 = 0 |
| 55 | var totalReal float64 = 0 | 56 | var totalReal float64 = 0 |
| 56 | for _, v := range result { | 57 | for _, v := range result { |
| 58 | + if planIn == "yesterday" { | ||
| 59 | + if !(utils.TimeBeforeEqual(begin, v.ProductDate) && utils.TimeAfterEqual(end, v.ProductDate)) { | ||
| 60 | + continue | ||
| 61 | + } | ||
| 62 | + } | ||
| 57 | totalPlan += v.PlanWeight | 63 | totalPlan += v.PlanWeight |
| 58 | totalReal += v.RealWeight | 64 | totalReal += v.RealWeight |
| 59 | } | 65 | } |
| @@ -68,7 +74,7 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | @@ -68,7 +74,7 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | ||
| 68 | } else { | 74 | } else { |
| 69 | completionRate = 0 | 75 | completionRate = 0 |
| 70 | } | 76 | } |
| 71 | - | 77 | + totalReal = utils.Round(totalReal, 1) |
| 72 | var record *models.WorkshopPlanCompletionRecord | 78 | var record *models.WorkshopPlanCompletionRecord |
| 73 | if record, err = workshopProductRecordDao.FindOne(cid, oid, workshops[i].WorkshopId, begin); err == domain.ErrorNotFound && record == nil { | 79 | if record, err = workshopProductRecordDao.FindOne(cid, oid, workshops[i].WorkshopId, begin); err == domain.ErrorNotFound && record == nil { |
| 74 | record = &models.WorkshopPlanCompletionRecord{ | 80 | record = &models.WorkshopPlanCompletionRecord{ |
| @@ -6,6 +6,8 @@ import ( | @@ -6,6 +6,8 @@ import ( | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" |
| 8 | "net/http" | 8 | "net/http" |
| 9 | + "strconv" | ||
| 10 | + "strings" | ||
| 9 | ) | 11 | ) |
| 10 | 12 | ||
| 11 | func init() { | 13 | func init() { |
| @@ -30,4 +32,12 @@ func init() { | @@ -30,4 +32,12 @@ func init() { | ||
| 30 | ctx.Output.Body([]byte(value)) | 32 | ctx.Output.Body([]byte(value)) |
| 31 | } | 33 | } |
| 32 | }) | 34 | }) |
| 35 | + web.Get("/test/cache/d/:key", func(ctx *context.Context) { | ||
| 36 | + key := ctx.Input.Query(":key") | ||
| 37 | + if len(key) != 0 && !strings.Contains(key, "*") { | ||
| 38 | + value, _ := redis.GetRedis().Del(key).Result() | ||
| 39 | + ctx.Output.SetStatus(http.StatusOK) | ||
| 40 | + ctx.Output.Body([]byte(strconv.Itoa(int(value)))) | ||
| 41 | + } | ||
| 42 | + }) | ||
| 33 | } | 43 | } |
-
请 注册 或 登录 后发表评论