作者 yangfu

fix:计划实际产能包含二级品

... ... @@ -119,9 +119,9 @@ spec:
- name: MANUFACTURE_DEFAULT_ORGID
value: "487"
- name: MANUFACTURE_DEFAULT_WORKSHOPID
value: "2"
value: "28"
- name: MANUFACTURE_PRODUCT_TYPE
value: "0502010004ST,0502010004ST"
value: "SG,SG"
- name: MQTT_HOST
value: "47.97.5.102"
- name: MQTT_PORT
... ...
... ... @@ -37,7 +37,7 @@ func AutoWorkshopPlanCompletionRecord(ctx context.Context) error {
begin := utils.GetZeroTime(end.Add(-time.Second))
approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext))
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end); err != nil {
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "yesterday"); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新车间计划完成纪录"})
return err
}
... ... @@ -74,7 +74,7 @@ func AutoTodayWorkshopPlanCompletionRecord(ctx context.Context) error {
end := time.Now()
approveAttendanceRecordsService, _ := domainService.NewPGWorkshopPlanCompletionRecordService(transactionContext.(*pgTransaction.TransactionContext))
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end); err != nil {
if err = approveAttendanceRecordsService.WorkshopPlanCompletion(begin, end, "today"); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时刷新当天车间计划完成纪录"})
return err
}
... ...
... ... @@ -13,6 +13,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"math/rand"
"strconv"
"sync"
"time"
... ... @@ -143,9 +144,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD
}
}
// TODO:测试假数据,后期注释掉
//if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
// newDeviceCollection.Values["Count"] = rand.Intn(300)
//}
if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi {
newDeviceCollection.Values["Count"] = rand.Intn(300)
}
deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection)
if err != nil {
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
//天联共创业务模块
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301"
var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
const CUSTOMER_ACCOUNT_DELIMITER = ","
... ... @@ -64,7 +66,9 @@ func init() {
//if os.Getenv("SMS_SERVE_HOST") != "" {
// SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST")
//}
if os.Getenv("MMM_BYTE_BANK_HOST") != "" {
MMM_BYTE_BANK_HOST = os.Getenv("MMM_BYTE_BANK_HOST")
}
if os.Getenv("SERVICE_ENV") != "" {
SERVICE_ENV = os.Getenv("SERVICE_ENV")
}
... ...
... ... @@ -137,8 +137,8 @@ func (d *DeviceRunningRecordInfo) AddDeviceRunningData(t time.Time, data *Device
d.Temp2 = data.Temp2
d.AddTimeLineDeviceStatus(t, data)
//d.OEE
d.TimeUtilization = utils.Round(d.UpTime*100/(time.Now().Sub(utils.GetZeroTime(time.Now())).Minutes()), 2)
//d.OEE (time.Now().Sub(utils.GetZeroTime(time.Now())).Minutes())
d.TimeUtilization = utils.Round((d.UpTime*100)/(24*60), 2)
//d.PerformanceUtilization
//d.QualificationUtilization
}
... ... @@ -175,7 +175,7 @@ func (d *DeviceRunningRecordInfo) ResetUpTime() float64 {
func (d *DeviceRunningRecordInfo) ResetOEE(pu, qu float64) float64 {
d.PerformanceUtilization = pu
d.QualificationUtilization = qu
d.OEE = utils.Round((d.TimeUtilization+d.PerformanceUtilization+d.QualificationUtilization)/3, 1)
d.OEE = utils.Round((d.TimeUtilization*d.PerformanceUtilization*d.QualificationUtilization)/10000, 1)
return d.OEE
}
... ...
package byte_bank
import (
"encoding/json"
"fmt"
gatewayLib "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway"
translator2 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/byte_bank/translator"
"strconv"
"strings"
"time"
)
type HttpLibByteBankServiceGateway struct {
gatewayLib.BaseServiceGateway
baseURL string
}
// ListFormulas 列出所有公式
func (serviceGateway *HttpLibByteBankServiceGateway) ListFormulas(pageSize int64, pageNumber int64) (*translator2.Formula, error) {
url := strings.Join([]string{serviceGateway.baseURL, "formulas"}, "/")
request := serviceGateway.CreateRequest(url, "get")
request.Param("pageSize", strconv.FormatInt(pageSize, 10))
request.Param("pageNumber", strconv.FormatInt(pageNumber, 10))
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取列表列表失败:%w", err)
}
var result gatewayLib.Response
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析公式列表失败:%w", err)
}
var data translator2.Formula
err = serviceGateway.GetResponseData(result, &data)
return &data, err
}
func (serviceGateway *HttpLibByteBankServiceGateway) GetFormula(formulaId string) (*translator2.FormulaDetail, error) {
url := strings.Join([]string{serviceGateway.baseURL, "/formulas/" + formulaId}, "/")
request := serviceGateway.CreateRequest(url, "get")
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取列表列表失败:%w", err)
}
var result gatewayLib.Response
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析公式列表失败:%w", err)
}
var data translator2.FormulaDetail
err = serviceGateway.GetResponseData(result, &data)
return &data, err
}
// AnalysisFormula 方案解析
func (serviceGateway *HttpLibByteBankServiceGateway) AnalysisFormula(formulaId int64) (*translator2.AnalysisFormulaDetail, error) {
url := strings.Join([]string{serviceGateway.baseURL, "sql/ad-hoc/for-formula"}, "/")
request := serviceGateway.CreateRequest(url, "post")
options := make(map[string]interface{})
options["formulaId"] = strconv.FormatInt(formulaId, 10)
_, err := request.JSONBody(options)
if err != nil {
return nil, err
}
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("方案解析失败失败:%w", err)
}
var result gatewayLib.Response
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析方案解析结果失败:%w", err)
}
var data translator2.AnalysisFormulaDetail
err = serviceGateway.GetResponseData(result, &data)
return &data, err
}
// AnalysisFormula 方案解析
func (serviceGateway *HttpLibByteBankServiceGateway) AnalysisFormulaByte(formulaId string) ([]byte, error) {
url := strings.Join([]string{serviceGateway.baseURL, "sql/ad-hoc/for-formula"}, "/")
request := serviceGateway.CreateRequest(url, "post")
options := make(map[string]interface{})
options["formulaId"] = formulaId
_, err := request.JSONBody(options)
if err != nil {
return nil, err
}
byteResult, err := request.Bytes()
if err != nil {
return byteResult, fmt.Errorf("方案解析失败失败:%w", err)
}
return byteResult, err
}
// ListDataApplications 列出所有数据应用
func (serviceGateway *HttpLibByteBankServiceGateway) ListDataApplications(pageSize int64, pageNumber int64) (*translator2.DataApplication, error) {
url := strings.Join([]string{serviceGateway.baseURL, "data-applications"}, "/")
request := serviceGateway.CreateRequest(url, "get")
request.Param("pageSize", strconv.FormatInt(pageSize, 10))
request.Param("pageNumber", strconv.FormatInt(pageNumber, 10))
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取应用列表失败:%w", err)
}
var result gatewayLib.Response
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析应用列表失败:%w", err)
}
var data translator2.DataApplication
err = serviceGateway.GetResponseData(result, &data)
return &data, err
}
// StartDataApplication 启动数据应用
func (serviceGateway *HttpLibByteBankServiceGateway) StartDataApplication(dataApplicationId int64) (map[string]interface{}, error) {
dataApplicationIdString := strconv.FormatInt(dataApplicationId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "data-applications/" + dataApplicationIdString + "/data-job/launch"}, "/")
request := serviceGateway.CreateRequest(url, "post")
response := make(map[string]interface{})
err := request.ToJSON(&response)
if err != nil {
//log.Logger.Error("Service Gateway Fail")
return nil, err
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttpLibByteBankServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) {
data := make(map[string]interface{})
var err error
if code, ok := response["code"]; ok {
code := code.(float64)
if code == 0 {
data = response["data"].(map[string]interface{})
} else {
msg := response["msg"].(string)
err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " "))
}
} else {
jsonBytes, marshalErr := json.Marshal(response)
if marshalErr != nil {
err = marshalErr
}
err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes))
}
return data, err
}
func NewHttpLibByteBankServiceGateway(host string) *HttpLibByteBankServiceGateway {
gt := gatewayLib.NewBaseServiceGateway(host)
gt.ConnectTimeout = 10 * time.Second
gt.ReadWriteTimeout = 10 * time.Second
return &HttpLibByteBankServiceGateway{
BaseServiceGateway: gt,
}
}
... ...
package translator
type AnalysisFormulaTranslator struct {
}
type QueryResult struct {
Date string `json:"date"`
Uid string `json:"uid"`
Value string `json:"value"`
}
type AnalysisFormulaDetail struct {
QueryColumnMap struct {
Date struct {
Description string `json:"description"`
Sort int `json:"sort"`
} `json:"date"`
Uid struct {
Description string `json:"description"`
Sort int `json:"sort"`
} `json:"uid"`
Value struct {
Description string `json:"description"`
Sort int `json:"sort"`
} `json:"value"`
} `json:"queryColumnMap"`
QueryResult []*QueryResult `json:"queryResult"`
SqlExpressionError string `json:"sqlExpressionError"`
}
func NewAnalysisFormulaTranslator() (*AnalysisFormulaTranslator, error) {
return &AnalysisFormulaTranslator{}, nil
}
... ...
package translator
import "time"
type DataApplicationTranslator struct {
}
type DataApplicationDetail struct {
DataApplicationId string `json:"dataApplicationId"`
DataApplicationMark string `json:"dataApplicationMark"`
DataApplicationTitle string `json:"dataApplicationTitle"`
DataApplicationLaunchType int32 `json:"dataApplicationLaunchType"`
DataApplicationTags []interface{} `json:"dataApplicationTags"`
Description string `json:"description"`
CreateTime time.Time `json:"createTime"`
}
type DataApplication struct {
Count int64 `json:"count"`
DataApplications []*DataApplicationDetail `json:"dataApplications"`
}
func NewDataApplicationTranslator() (*DataApplicationTranslator, error) {
return &DataApplicationTranslator{}, nil
}
... ...
package translator
import "time"
type FormulaTranslator struct {
}
type Formula struct {
Count int64 `json:"count"`
Formulas []FormulaDetail `json:"formulas"`
}
type FormulaDetail struct {
CreateTime time.Time `json:"createTime"`
DataApplicationMark string `json:"dataApplicationMark"`
FormulaCalculateType int `json:"formulaCalculateType"`
FormulaConditions []struct {
FormulaCondition struct {
FormulaConditionExpression string `json:"formulaConditionExpression"`
FormulaConditionLeftField struct {
FormulaFieldDescription string `json:"formulaFieldDescription"`
FormulaFieldName string `json:"formulaFieldName"`
FormulaFieldType string `json:"formulaFieldType"`
FromDataBaseName string `json:"fromDataBaseName"`
FromDataSetName string `json:"fromDataSetName"`
} `json:"formulaConditionLeftField"`
FormulaConditionOperator string `json:"formulaConditionOperator"`
FormulaConditionRightField struct {
FormulaFieldDescription string `json:"formulaFieldDescription"`
FormulaFieldName string `json:"formulaFieldName"`
FormulaFieldType string `json:"formulaFieldType"`
FromDataBaseName string `json:"fromDataBaseName"`
FromDataSetName string `json:"fromDataSetName"`
} `json:"formulaConditionRightField"`
FormulaConditionRightValue string `json:"formulaConditionRightValue"`
FormulaConditionType int `json:"formulaConditionType"`
} `json:"formulaCondition"`
OrConditions []interface{} `json:"orConditions"`
} `json:"formulaConditions"`
FormulaDescription string `json:"formulaDescription"`
FormulaGenSqlExpression string `json:"formulaGenSqlExpression"`
FormulaGroup struct {
CreateTime time.Time `json:"createTime"`
FormulaGroupId string `json:"formulaGroupId"`
FormulaGroupName string `json:"formulaGroupName"`
FormulaGroupParentId string `json:"formulaGroupParentId"`
SortNumber int `json:"sortNumber"`
} `json:"formulaGroup"`
FormulaId string `json:"formulaId"`
FormulaName string `json:"formulaName"`
FormulaSelectFields []struct {
FormulaField struct {
FormulaFieldDescription string `json:"formulaFieldDescription"`
FormulaFieldName string `json:"formulaFieldName"`
FormulaFieldType string `json:"formulaFieldType"`
FromDataBaseName string `json:"fromDataBaseName"`
FromDataSetName string `json:"fromDataSetName"`
} `json:"formulaField"`
FormulaSelectFieldExpression string `json:"formulaSelectFieldExpression"`
FormulaSelectFieldIsGroup bool `json:"formulaSelectFieldIsGroup"`
FormulaSelectFieldType int `json:"formulaSelectFieldType"`
SortNumber int `json:"sortNumber"`
} `json:"formulaSelectFields"`
FormulaSqlExpression string `json:"formulaSqlExpression"`
}
func NewFormulaTranslator() (*FormulaTranslator, error) {
return &FormulaTranslator{}, nil
}
... ...
... ... @@ -26,7 +26,8 @@ from manufacture.product_records
where company_id = ?
and org_id =?
and work_station->>'workshopId'='?'
and product_record_type in (1,2)
and work_station->>'sectionName'='包装'
and product_record_type in (1,2,8)
and created_at>=?
and created_at<?
), product_record_sum as(
... ... @@ -37,13 +38,14 @@ select
plan_devoted->>'weight' plan_weight -- 计划重量
, coalesce(b.weight,0) real_weight --批次实际产能
,a.product_plan_id
,a.product_date
from manufacture.product_plan a left join product_record_sum b on a.product_plan_id = b.plan_id
where company_id = ?
and org_id =?
and workshop->>'workshopId'='?'
and created_at >=?
and created_at<?
order by created_at desc`)
and product_date >=?
--and created_at<?
--order by created_at desc`)
if _, err := tx.Query(records, sql,
companyId, orgId, workshopId, begin, end,
companyId, orgId, workshopId, begin, end); err != nil {
... ...
package domainService
import (
"github.com/linmadan/egglib-go/core/application"
"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"
)
type ByteBankService struct {
internalService *byte_bank.HttpLibByteBankServiceGateway
}
func NewByteBankService() *ByteBankService {
return &ByteBankService{
internalService: byte_bank.NewHttpLibByteBankServiceGateway(constant.MMM_BYTE_BANK_HOST),
}
}
//GetFormulasId 获取公式id
func (svr *ByteBankService) GetFormulasId(formulaName string) string {
//获取公式id
formulaId := ""
listLoop:
for i := 0; ; i++ {
data, err := svr.internalService.ListFormulas(1000, int64(i))
if err != nil {
return ""
}
if len(data.Formulas) == 0 {
break listLoop
}
for _, item := range data.Formulas {
if item.FormulaDescription == formulaName {
formulaId = item.FormulaId
break listLoop
}
}
}
return formulaId
}
// SectionProductive 时段产能
func (svr *ByteBankService) SectionProductive() (interface{}, error) {
//获取公式id时段产能
formulaId := svr.GetFormulasId("type_salesman_id")
//获取解析数据
byteResult, err := svr.internalService.AnalysisFormulaByte(formulaId)
if err != nil {
return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
code := gjson.GetBytes(byteResult, "code").String()
if code != "0" {
msg := gjson.GetBytes(byteResult, "msg").String()
return struct{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, msg)
}
//待解析的
queryResult := gjson.GetBytes(byteResult, "data.queryResult").Array()
for _, item := range queryResult {
if item.Get("type_salesman_id").String() != "" {
continue
}
}
return nil, nil
}
... ...
package domainService
import "testing"
func TestSectionProductive(t *testing.T) {
svr := NewByteBankService()
svr.SectionProductive()
}
... ...
... ... @@ -289,7 +289,6 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
if err != nil {
return nil, err
}
var response = make([]interface{}, 0)
_, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": t})
for i := 0; i < len(devices); i++ {
... ...
... ... @@ -28,11 +28,12 @@ func NewPGWorkshopPlanCompletionRecordService(transactionContext *pgTransaction.
}
// 车间完成统计
func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin time.Time, end time.Time) error {
func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin time.Time, end time.Time, planIn string) error {
type record struct {
PlanWeight float64 `json:"plan_weight"`
RealWeight float64 `json:"real_weight"`
ProductPlanId float64 `json:"product_plan_id"`
PlanWeight float64 `json:"plan_weight"`
RealWeight float64 `json:"real_weight"`
ProductPlanId float64 `json:"product_plan_id"`
ProductDate time.Time `json:"product_date"`
}
cid := constant.MANUFACTURE_DEFAULT_COMPANYID
oid := constant.MANUFACTURE_DEFAULT_ORGID
... ... @@ -54,6 +55,11 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t
var totalPlan float64 = 0
var totalReal float64 = 0
for _, v := range result {
if planIn == "yesterday" {
if !(utils.TimeBeforeEqual(begin, v.ProductDate) && utils.TimeAfterEqual(end, v.ProductDate)) {
continue
}
}
totalPlan += v.PlanWeight
totalReal += v.RealWeight
}
... ... @@ -68,7 +74,7 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t
} else {
completionRate = 0
}
totalReal = utils.Round(totalReal, 1)
var record *models.WorkshopPlanCompletionRecord
if record, err = workshopProductRecordDao.FindOne(cid, oid, workshops[i].WorkshopId, begin); err == domain.ErrorNotFound && record == nil {
record = &models.WorkshopPlanCompletionRecord{
... ...
... ... @@ -6,6 +6,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
"net/http"
"strconv"
"strings"
)
func init() {
... ... @@ -30,4 +32,12 @@ func init() {
ctx.Output.Body([]byte(value))
}
})
web.Get("/test/cache/d/:key", func(ctx *context.Context) {
key := ctx.Input.Query(":key")
if len(key) != 0 && !strings.Contains(key, "*") {
value, _ := redis.GetRedis().Del(key).Result()
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.Body([]byte(strconv.Itoa(int(value))))
}
})
}
... ...