正在显示
21 个修改的文件
包含
255 行增加
和
93 行删除
Dockerfile_TYYun
0 → 100644
1 | +FROM golang:alpine | ||
2 | +ENV APP_DIR $GOPATH/src/project-20211220 | ||
3 | +ENV POSTGRESQL_DB_NAME="" \ | ||
4 | + POSTGRESQL_USER="" \ | ||
5 | + POSTGRESQL_PASSWORD="" \ | ||
6 | + POSTGRESQL_HOST="" \ | ||
7 | + POSTGRESQL_PORT="" \ | ||
8 | + REDIS_HOST="" \ | ||
9 | + REDIS_PORT="" \ | ||
10 | + REDIS_AUTH="" \ | ||
11 | + LOG_LEVEL="debug" \ | ||
12 | + ERROR_BASE_CODE="1" \ | ||
13 | + ERROR_BASE_CODE_MULTIPLE="2000" \ | ||
14 | + ENABLE_KAFKA_LOG="false" \ | ||
15 | + HTTP_PORT="8082" \ | ||
16 | + SERVICE_ENV="prd" \ | ||
17 | + ALLIED_CREATION_USER_HOST="https://allied-creation-user-prd.fjmaimaimai.com" \ | ||
18 | + MANUFACTURE_DEFAULT_COMPANYID="1" \ | ||
19 | + MANUFACTURE_DEFAULT_ORGID="1" \ | ||
20 | + MANUFACTURE_DEFAULT_WORKSHOPID="2" \ | ||
21 | + MANUFACTURE_PRODUCT_TYPE="0502010004ST,0502010004ST" \ | ||
22 | + MQTT_HOST="47.97.5.102" \ | ||
23 | + MQTT_PORT="6000" | ||
24 | +RUN mkdir -p $APP_DIR | ||
25 | +WORKDIR $APP_DIR/ | ||
26 | +COPY ./pkg pkg | ||
27 | +COPY ./config config | ||
28 | +COPY ./go.mod go.mod | ||
29 | +COPY ./go.sum go.sum | ||
30 | +COPY ./main.go main.go | ||
31 | +RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] | ||
32 | +ENV GO111MODULE on | ||
33 | +ENV GOPROXY https://goproxy.cn | ||
34 | +RUN ["go","mod","tidy"] | ||
35 | +RUN ["go","build"] | ||
36 | +RUN ["ls"] | ||
37 | +ENTRYPOINT ["./allied-creation-manufacture"] |
@@ -118,6 +118,8 @@ spec: | @@ -118,6 +118,8 @@ spec: | ||
118 | value: "23" | 118 | value: "23" |
119 | - name: MANUFACTURE_DEFAULT_ORGID | 119 | - name: MANUFACTURE_DEFAULT_ORGID |
120 | value: "487" | 120 | value: "487" |
121 | + - name: MANUFACTURE_DEFAULT_WORKSHOPID | ||
122 | + value: "2" | ||
121 | - name: MANUFACTURE_PRODUCT_TYPE | 123 | - name: MANUFACTURE_PRODUCT_TYPE |
122 | value: "0502010004ST,0502010004ST" | 124 | value: "0502010004ST,0502010004ST" |
123 | - name: MQTT_HOST | 125 | - name: MQTT_HOST |
@@ -17,6 +17,7 @@ require ( | @@ -17,6 +17,7 @@ require ( | ||
17 | github.com/hibiken/asynq v0.21.0 | 17 | github.com/hibiken/asynq v0.21.0 |
18 | github.com/imkira/go-interpol v1.1.0 // indirect | 18 | github.com/imkira/go-interpol v1.1.0 // indirect |
19 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | 19 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 |
20 | + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 | ||
20 | github.com/moul/http2curl v1.0.0 // indirect | 21 | github.com/moul/http2curl v1.0.0 // indirect |
21 | github.com/mozillazg/go-pinyin v0.19.0 | 22 | github.com/mozillazg/go-pinyin v0.19.0 |
22 | github.com/onsi/ginkgo v1.15.2 | 23 | github.com/onsi/ginkgo v1.15.2 |
@@ -15,6 +15,8 @@ type AttendanceRecordDto struct { | @@ -15,6 +15,8 @@ type AttendanceRecordDto struct { | ||
15 | //OrgId int `json:"orgId,omitempty"` | 15 | //OrgId int `json:"orgId,omitempty"` |
16 | // 考勤类型 1.正常 2.支援 | 16 | // 考勤类型 1.正常 2.支援 |
17 | AttendanceType int `json:"attendanceType,omitempty"` | 17 | AttendanceType int `json:"attendanceType,omitempty"` |
18 | + // 班组名称 | ||
19 | + GroupName string `json:"groupName"` | ||
18 | // 生产工人 | 20 | // 生产工人 |
19 | ProductWorker *domain.User `json:"productWorker,omitempty"` | 21 | ProductWorker *domain.User `json:"productWorker,omitempty"` |
20 | // 审核人 | 22 | // 审核人 |
@@ -72,6 +74,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -72,6 +74,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
72 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) | 74 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) |
73 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") | 75 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") |
74 | } | 76 | } |
77 | + d.GroupName = m.Ext.AttendanceExt.GroupName | ||
75 | } | 78 | } |
76 | } | 79 | } |
77 | return d | 80 | return d |
@@ -12,6 +12,8 @@ type EmployeeAttendanceRecordDto struct { | @@ -12,6 +12,8 @@ type EmployeeAttendanceRecordDto struct { | ||
12 | SignDate string `json:"signDate"` | 12 | SignDate string `json:"signDate"` |
13 | // 工作位置 | 13 | // 工作位置 |
14 | *domain.WorkStation | 14 | *domain.WorkStation |
15 | + // 班组名称 | ||
16 | + GroupName string `json:"groupName"` | ||
15 | // 生产工人 | 17 | // 生产工人 |
16 | ProductWorker *domain.User `json:"productWorker,omitempty"` | 18 | ProductWorker *domain.User `json:"productWorker,omitempty"` |
17 | // 考勤类型 1.正常 2.支援 | 19 | // 考勤类型 1.正常 2.支援 |
@@ -52,6 +54,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | @@ -52,6 +54,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | ||
52 | if m.Ext != nil { | 54 | if m.Ext != nil { |
53 | d.OrgName = m.Ext.OrgName | 55 | d.OrgName = m.Ext.OrgName |
54 | //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt | 56 | //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt |
57 | + if m.Ext.AttendanceExt != nil { | ||
58 | + d.GroupName = m.Ext.AttendanceExt.GroupName | ||
59 | + } | ||
55 | } | 60 | } |
56 | return d | 61 | return d |
57 | } | 62 | } |
@@ -13,7 +13,6 @@ import ( | @@ -13,7 +13,6 @@ 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" | ||
17 | "strconv" | 16 | "strconv" |
18 | "sync" | 17 | "sync" |
19 | "time" | 18 | "time" |
@@ -140,9 +139,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | @@ -140,9 +139,9 @@ func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createD | ||
140 | } | 139 | } |
141 | } | 140 | } |
142 | // TODO:测试假数据,后期注释掉 | 141 | // TODO:测试假数据,后期注释掉 |
143 | - if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { | ||
144 | - newDeviceCollection.Values["Count"] = rand.Intn(300) | ||
145 | - } | 142 | + //if createDeviceCollectionCommand.DeviceType == domain.DeviceTypeChuanChuanJi { |
143 | + // newDeviceCollection.Values["Count"] = rand.Intn(300) | ||
144 | + //} | ||
146 | deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection) | 145 | deviceCollection, err := deviceCollectionRepository.Save(newDeviceCollection) |
147 | if err != nil { | 146 | if err != nil { |
148 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 147 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -11,6 +11,8 @@ var ( | @@ -11,6 +11,8 @@ var ( | ||
11 | MANUFACTURE_DEFAULT_COMPANYID = 1 | 11 | MANUFACTURE_DEFAULT_COMPANYID = 1 |
12 | // 生产制造 - 称重系统 - 默认组织 | 12 | // 生产制造 - 称重系统 - 默认组织 |
13 | MANUFACTURE_DEFAULT_ORGID = 1 | 13 | MANUFACTURE_DEFAULT_ORGID = 1 |
14 | + // 生产制造 - 称重系统 - 默认车间ID | ||
15 | + MANUFACTURE_DEFAULT_WORKSHOPID = 2 | ||
14 | // 产品类型列表 | 16 | // 产品类型列表 |
15 | MANUFACTURE_PRODUCT_TYPE = "0502010004ST,0504010004ST" | 17 | MANUFACTURE_PRODUCT_TYPE = "0502010004ST,0504010004ST" |
16 | 18 | ||
@@ -24,6 +26,9 @@ func init() { | @@ -24,6 +26,9 @@ func init() { | ||
24 | if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" { | 26 | if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" { |
25 | MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID")) | 27 | MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID")) |
26 | } | 28 | } |
29 | + if os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID") != "" { | ||
30 | + MANUFACTURE_DEFAULT_WORKSHOPID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID")) | ||
31 | + } | ||
27 | if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" { | 32 | if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" { |
28 | MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE") | 33 | MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE") |
29 | } | 34 | } |
@@ -43,6 +43,9 @@ type ProductRecord struct { | @@ -43,6 +43,9 @@ type ProductRecord struct { | ||
43 | ProductRecordInfo *ProductRecordInfo `json:"productRecordInfo,omitempty"` | 43 | ProductRecordInfo *ProductRecordInfo `json:"productRecordInfo,omitempty"` |
44 | // 扩展数据 | 44 | // 扩展数据 |
45 | Ext *Ext `json:"ext,omitempty"` | 45 | Ext *Ext `json:"ext,omitempty"` |
46 | + | ||
47 | + // 上一条记录 | ||
48 | + PreRecord *ProductRecord `json:"-"` | ||
46 | } | 49 | } |
47 | 50 | ||
48 | type ProductRecordRepository interface { | 51 | type ProductRecordRepository interface { |
@@ -70,17 +70,20 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter | @@ -70,17 +70,20 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter | ||
70 | } | 70 | } |
71 | 71 | ||
72 | // 更新生产量 | 72 | // 更新生产量 |
73 | -func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string, yesterdayWeight float64, bestWeight float64) { | 73 | +func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(productRecord *ProductRecord, yesterdayWeight float64, bestWeight float64) { |
74 | + var weigh float64 = productRecord.ProductRecordInfo.Weigh | ||
75 | + var productRecordType int = productRecord.ProductRecordType | ||
76 | + var sectionName string = productRecord.WorkStation.SectionName | ||
74 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { | 77 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { |
75 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) | 78 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) |
76 | } | 79 | } |
77 | if productRecordType == RecordTypeSecondLevelWeigh { | 80 | if productRecordType == RecordTypeSecondLevelWeigh { |
78 | // 当前工段 | 81 | // 当前工段 |
79 | - if employeeProductRecord.WorkStation.SectionName == sectionName { | 82 | + if employeeProductRecord.WorkStation.SectionName == sectionName && productRecord.PreRecord == nil { |
80 | employeeProductRecord.SecondLevelWeigh += weigh | 83 | employeeProductRecord.SecondLevelWeigh += weigh |
81 | - } else { | 84 | + } else if productRecord.PreRecord != nil { |
82 | // 其他工段的二级品 | 85 | // 其他工段的二级品 |
83 | - employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh) | 86 | + employeeProductRecord.ProductRecordInfo.AddSectionWeight(productRecord.PreRecord.WorkStation.SectionName, weigh) |
84 | } | 87 | } |
85 | } | 88 | } |
86 | if productRecordType == RecordTypeReceiveMaterial { | 89 | if productRecordType == RecordTypeReceiveMaterial { |
@@ -31,6 +31,8 @@ type ProductRecordStaticInfo struct { | @@ -31,6 +31,8 @@ type ProductRecordStaticInfo struct { | ||
31 | TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"` | 31 | TotalOtherSecondLevelWeigh float64 `json:"totalOtherSecondLevelWeigh"` |
32 | // 保存其他工段二级品的重量 | 32 | // 保存其他工段二级品的重量 |
33 | OtherSectionSecondLevelWeigh map[string]float64 `json:"otherSectionSecondLevelWeigh"` | 33 | OtherSectionSecondLevelWeigh map[string]float64 `json:"otherSectionSecondLevelWeigh"` |
34 | + // 生产计划列表 | ||
35 | + ProductPlans []int `json:"plans"` | ||
34 | } | 36 | } |
35 | 37 | ||
36 | func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 { | 38 | func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 { |
@@ -76,3 +78,24 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | @@ -76,3 +78,24 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | ||
76 | info.QualificationRate = utils.Round(info.OutputWeight*100.0/info.InputWeight, 0) | 78 | info.QualificationRate = utils.Round(info.OutputWeight*100.0/info.InputWeight, 0) |
77 | } | 79 | } |
78 | } | 80 | } |
81 | + | ||
82 | +func (info *ProductRecordStaticInfo) GetBestOutputWeight() float64 { | ||
83 | + return max(info.OutputWeight, max(info.YesterdayOutputWeight, info.BestOutputWeight)) | ||
84 | +} | ||
85 | + | ||
86 | +func (info *ProductRecordStaticInfo) AddProductPlan(productPlanId int) bool { | ||
87 | + for _, v := range info.ProductPlans { | ||
88 | + if v == productPlanId { | ||
89 | + return false | ||
90 | + } | ||
91 | + } | ||
92 | + info.ProductPlans = append(info.ProductPlans, productPlanId) | ||
93 | + return true | ||
94 | +} | ||
95 | + | ||
96 | +func max(a, b float64) float64 { | ||
97 | + if a > b { | ||
98 | + return a | ||
99 | + } | ||
100 | + return b | ||
101 | +} |
@@ -53,16 +53,23 @@ func (workshopProductRecord *WorkshopProductRecord) Update(data map[string]inter | @@ -53,16 +53,23 @@ func (workshopProductRecord *WorkshopProductRecord) Update(data map[string]inter | ||
53 | return nil | 53 | return nil |
54 | } | 54 | } |
55 | 55 | ||
56 | -func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) { | 56 | +func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(productRecord *ProductRecord) { |
57 | + var ( | ||
58 | + weigh float64 = productRecord.ProductRecordInfo.Weigh | ||
59 | + productRecordType int = productRecord.ProductRecordType | ||
60 | + sectionName string = productRecord.WorkStation.SectionName | ||
61 | + ) | ||
57 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { | 62 | if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil { |
58 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) | 63 | employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64) |
59 | } | 64 | } |
60 | if productRecordType == RecordTypeSecondLevelWeigh { | 65 | if productRecordType == RecordTypeSecondLevelWeigh { |
61 | - if employeeProductRecord.WorkStation.SectionName == sectionName { | 66 | + if employeeProductRecord.WorkStation.SectionName == sectionName && productRecord.PreRecord == nil { |
62 | employeeProductRecord.SecondLevelWeigh += weigh | 67 | employeeProductRecord.SecondLevelWeigh += weigh |
63 | } else { | 68 | } else { |
64 | // 其他工段的二级品 | 69 | // 其他工段的二级品 |
65 | - employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh) | 70 | + if productRecord.PreRecord != nil { |
71 | + employeeProductRecord.ProductRecordInfo.AddSectionWeight(productRecord.PreRecord.WorkStation.SectionName, weigh) | ||
72 | + } | ||
66 | } | 73 | } |
67 | } | 74 | } |
68 | if productRecordType == RecordTypeReceiveMaterial { | 75 | if productRecordType == RecordTypeReceiveMaterial { |
@@ -81,6 +88,13 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | @@ -81,6 +88,13 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo | ||
81 | } | 88 | } |
82 | 89 | ||
83 | // 产能 | 90 | // 产能 |
91 | +func (employeeProductRecord *WorkshopProductRecord) AddPlanProductWeight(weight float64, productPlanId int) { | ||
92 | + if employeeProductRecord.ProductRecordInfo.AddProductPlan(productPlanId) { | ||
93 | + employeeProductRecord.ProductWeigh += weight | ||
94 | + } | ||
95 | +} | ||
96 | + | ||
97 | +// 产能 | ||
84 | func (employeeProductRecord *WorkshopProductRecord) RealProductWeigh() float64 { | 98 | func (employeeProductRecord *WorkshopProductRecord) RealProductWeigh() float64 { |
85 | // 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量 | 99 | // 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量 |
86 | result := employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() | 100 | result := employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" |
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
11 | "time" | 12 | "time" |
12 | ) | 13 | ) |
13 | 14 | ||
@@ -34,6 +35,9 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or | @@ -34,6 +35,9 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or | ||
34 | query.Where("company_id = ?", companyId) | 35 | query.Where("company_id = ?", companyId) |
35 | query.Where("org_id = ?", orgId) | 36 | query.Where("org_id = ?", orgId) |
36 | query.Where("work_station->>'workStationId' = ?", workStationId) | 37 | query.Where("work_station->>'workStationId' = ?", workStationId) |
38 | + // 当天 | ||
39 | + query.Where("sign_in >= ?", utils.GetZeroTime(productTime)) | ||
40 | + query.Where("sign_in <?", utils.GetNextDayZeroTime(productTime)) | ||
37 | query.Where("sign_in <= ?", productTime) | 41 | query.Where("sign_in <= ?", productTime) |
38 | query.WhereGroup(func(q *orm.Query) (*orm.Query, error) { | 42 | query.WhereGroup(func(q *orm.Query) (*orm.Query, error) { |
39 | query.WhereOr("sign_out >= ?", productTime) | 43 | query.WhereOr("sign_out >= ?", productTime) |
@@ -25,6 +25,31 @@ func NewEmployeeProductRecordDao(transactionContext *pgTransaction.TransactionCo | @@ -25,6 +25,31 @@ func NewEmployeeProductRecordDao(transactionContext *pgTransaction.TransactionCo | ||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | +// 员工对应工段批次的生产记录 (生产日期) | ||
29 | +func (dao *EmployeeProductRecordDao) WorkerWorkStationProductRecord(companyId, orgId int, workStationId string, planId, workerId int, productTime time.Time) (*domain.EmployeeProductRecord, error) { | ||
30 | + tx := dao.transactionContext.PgTx | ||
31 | + employeeProductRecordModel := new(models.EmployeeProductRecord) | ||
32 | + query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) | ||
33 | + query.Where("company_id = ?", companyId) | ||
34 | + query.Where("org_id = ?", orgId) | ||
35 | + query.Where("product_worker ->>'userId' = '?'", workerId) | ||
36 | + query.Where("work_station ->>'workStationId' = ?", workStationId) | ||
37 | + query.Where("product_record_info ->>'productPlanId' = '?'", planId) | ||
38 | + query.Where("product_record_info ->>'productDate' = ?", productTime.Local().Format("2006-01-02")) | ||
39 | + if err := query.First(); err != nil { | ||
40 | + if err.Error() == "pg: no rows in result set" { | ||
41 | + return nil, domain.ErrorNotFound | ||
42 | + } else { | ||
43 | + return nil, err | ||
44 | + } | ||
45 | + } | ||
46 | + if employeeProductRecordModel.EmployeeProductRecordId == 0 { | ||
47 | + return nil, domain.ErrorNotFound | ||
48 | + } else { | ||
49 | + return transform.TransformToEmployeeProductRecordDomainModelFromPgModels(employeeProductRecordModel) | ||
50 | + } | ||
51 | +} | ||
52 | + | ||
28 | // 员工对应批次的生产记录 (生产日期) | 53 | // 员工对应批次的生产记录 (生产日期) |
29 | func (dao *EmployeeProductRecordDao) WorkerProductRecord(companyId, orgId, planId, workerId int, productTime time.Time) (*domain.EmployeeProductRecord, error) { | 54 | func (dao *EmployeeProductRecordDao) WorkerProductRecord(companyId, orgId, planId, workerId int, productTime time.Time) (*domain.EmployeeProductRecord, error) { |
30 | tx := dao.transactionContext.PgTx | 55 | tx := dao.transactionContext.PgTx |
@@ -25,15 +25,16 @@ func NewWorkshopProductRecordDao(transactionContext *pgTransaction.TransactionCo | @@ -25,15 +25,16 @@ func NewWorkshopProductRecordDao(transactionContext *pgTransaction.TransactionCo | ||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | -// 员工对应批次的生产记录 (生产日期) | ||
29 | -func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) { | 28 | +// 车间对应工段的生产记录 (生产日期) |
29 | +func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId int, workStationId string, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) { | ||
30 | tx := dao.transactionContext.PgTx | 30 | tx := dao.transactionContext.PgTx |
31 | employeeProductRecordModel := new(models.WorkshopProductRecord) | 31 | employeeProductRecordModel := new(models.WorkshopProductRecord) |
32 | query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) | 32 | query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{}) |
33 | query.Where("company_id = ?", companyId) | 33 | query.Where("company_id = ?", companyId) |
34 | query.Where("org_id = ?", orgId) | 34 | query.Where("org_id = ?", orgId) |
35 | + query.Where("work_station ->>'workStationId' = ?", workStationId) | ||
35 | query.Where("product_date = ?", productTime.Local().Format("2006-01-02")) | 36 | query.Where("product_date = ?", productTime.Local().Format("2006-01-02")) |
36 | - query.Where("product_record_info ->>'productPlanId' = '?'", planId) | 37 | + //query.Where("product_record_info ->>'productPlanId' = '?'", planId) |
37 | if err := query.First(); err != nil { | 38 | if err := query.First(); err != nil { |
38 | if err.Error() == "pg: no rows in result set" { | 39 | if err.Error() == "pg: no rows in result set" { |
39 | return nil, domain.ErrorNotFound | 40 | return nil, domain.ErrorNotFound |
@@ -3,6 +3,7 @@ package domainService | @@ -3,6 +3,7 @@ package domainService | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" |
@@ -222,7 +223,9 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | @@ -222,7 +223,9 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | ||
222 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { | 223 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { |
223 | return nil, err | 224 | return nil, err |
224 | } | 225 | } |
225 | - | 226 | + if request.WorkshopId == 0 { |
227 | + request.WorkshopId = constant.MANUFACTURE_DEFAULT_WORKSHOPID | ||
228 | + } | ||
226 | workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext) | 229 | workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext) |
227 | type record struct { | 230 | type record struct { |
228 | Oee float64 `json:"oee"` | 231 | Oee float64 `json:"oee"` |
@@ -342,9 +345,12 @@ func (ptr *PGCommonStatisticsService) DeviceRunningInfo(queryOptions map[string] | @@ -342,9 +345,12 @@ func (ptr *PGCommonStatisticsService) DeviceRunningInfo(queryOptions map[string] | ||
342 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { | 345 | if err := utils.LoadQueryObject(queryOptions, request); err != nil { |
343 | return nil, err | 346 | return nil, err |
344 | } | 347 | } |
348 | + if request.WorkshopId == 0 { | ||
349 | + request.WorkshopId = constant.MANUFACTURE_DEFAULT_WORKSHOPID | ||
350 | + } | ||
345 | deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) | 351 | deviceDailyRunningRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) |
346 | var response = make([]*DeviceInfo, 0) | 352 | var response = make([]*DeviceInfo, 0) |
347 | - deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "CCJ1", &response) | 353 | + deviceDailyRunningRecordDao.DeviceRunningInfo(request.CompanyId, request.OrgId, "", &response) |
348 | 354 | ||
349 | return map[string]interface{}{ | 355 | return map[string]interface{}{ |
350 | "devices": response, | 356 | "devices": response, |
@@ -388,7 +394,7 @@ func (ptr *PGCommonStatisticsService) DeviceSummary(deviceInfos []*DeviceInfo) i | @@ -388,7 +394,7 @@ func (ptr *PGCommonStatisticsService) DeviceSummary(deviceInfos []*DeviceInfo) i | ||
388 | "total": total, | 394 | "total": total, |
389 | "off": deviceSummary(total, deviceOff), | 395 | "off": deviceSummary(total, deviceOff), |
390 | "on": deviceSummary(total, deviceRunning), | 396 | "on": deviceSummary(total, deviceRunning), |
391 | - "err": deviceSummary(total, deviceRunning), | 397 | + "err": deviceSummary(total, deviceErr), |
392 | } | 398 | } |
393 | return result | 399 | return result |
394 | } | 400 | } |
@@ -95,7 +95,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | @@ -95,7 +95,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | ||
95 | 95 | ||
96 | // 领料、退料需要换算产能 | 96 | // 领料、退料需要换算产能 |
97 | if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { | 97 | if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { |
98 | - weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity | 98 | + weight = utils.Round((weight/uc.FromUnitQuantity.Quantity)*uc.ToUnitQuantity.Quantity, 1) |
99 | } | 99 | } |
100 | // 退料、需要判断用户是否有领过料 | 100 | // 退料、需要判断用户是否有领过料 |
101 | if productRecordType == domain.RecordTypeReturnMaterial { | 101 | if productRecordType == domain.RecordTypeReturnMaterial { |
@@ -132,7 +132,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | @@ -132,7 +132,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | ||
132 | } | 132 | } |
133 | 133 | ||
134 | // 发送Job | 134 | // 发送Job |
135 | - if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial { | 135 | + if (productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial) && workstation.SectionName == ProductSection4 { |
136 | // 发送Job | 136 | // 发送Job |
137 | if err = SendProductRecordStaticsJob(record); err != nil { | 137 | if err = SendProductRecordStaticsJob(record); err != nil { |
138 | return nil, err | 138 | return nil, err |
@@ -2,6 +2,7 @@ package domainService | @@ -2,6 +2,7 @@ package domainService | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/mohae/deepcopy" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" |
@@ -27,7 +28,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -27,7 +28,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
27 | workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext) | 28 | workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext) |
28 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) | 29 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) |
29 | productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | 30 | productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) |
30 | - employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext) | 31 | + //employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext) |
31 | ) | 32 | ) |
32 | 33 | ||
33 | var ( | 34 | var ( |
@@ -44,10 +45,13 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -44,10 +45,13 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
44 | //查询生产记录 批次、生产日期、下(成型)所有二级品 | 45 | //查询生产记录 批次、生产日期、下(成型)所有二级品 |
45 | // 更新打料的二级品需要再一次更新成型的二级品 | 46 | // 更新打料的二级品需要再一次更新成型的二级品 |
46 | if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil { | 47 | if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil { |
47 | - nextProductRecord := *productRecord | 48 | + if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok { |
48 | nextProductRecord.WorkStation.SectionName = ProductSection2 | 49 | nextProductRecord.WorkStation.SectionName = ProductSection2 |
49 | nextProductRecord.WorkStation.SectionId = section.SectionId | 50 | nextProductRecord.WorkStation.SectionId = section.SectionId |
50 | - ptr.EmployeeProductStatics(&nextProductRecord) | 51 | + nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId) |
52 | + nextProductRecord.PreRecord = productRecord | ||
53 | + ptr.EmployeeProductStatics(nextProductRecord) | ||
54 | + } | ||
51 | } | 55 | } |
52 | } | 56 | } |
53 | break | 57 | break |
@@ -56,7 +60,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -56,7 +60,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
56 | case ProductSection3: | 60 | case ProductSection3: |
57 | break | 61 | break |
58 | case ProductSection4: //个人特殊处理 | 62 | case ProductSection4: //个人特殊处理 |
59 | - return ptr.personalProductStatics(productRecord) | 63 | + return ptr.personalProductStatics(nil, nil, nil, productRecord) |
60 | default: | 64 | default: |
61 | return nil, nil //ptr.personalProductStatics(productRecord) | 65 | return nil, nil //ptr.personalProductStatics(productRecord) |
62 | } | 66 | } |
@@ -64,72 +68,34 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | @@ -64,72 +68,34 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. | ||
64 | log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId)) | 68 | log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId)) |
65 | return nil, nil | 69 | return nil, nil |
66 | } | 70 | } |
71 | + // 2.0 查找批次 | ||
67 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) | 72 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) |
68 | if err != nil { | 73 | if err != nil { |
69 | return nil, err | 74 | return nil, err |
70 | } | 75 | } |
71 | 76 | ||
77 | + // 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工 | ||
78 | + groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId) | ||
79 | + | ||
72 | // 集体 | 80 | // 集体 |
73 | // 1.查询员工 -》 员工打卡记录 工位+打卡日期 | 81 | // 1.查询员工 -》 员工打卡记录 工位+打卡日期 |
74 | // 2.打卡记录的时间区间 在生产记录上报的时间范围内 | 82 | // 2.打卡记录的时间区间 在生产记录上报的时间范围内 |
75 | attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext) | 83 | attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext) |
76 | - _, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, time.Now()) //, productRecord.CreatedAt | 84 | + _, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, productRecord.CreatedAt) //, productRecord.CreatedAt |
77 | if err != nil || len(attendanceRecords) == 0 { | 85 | if err != nil || len(attendanceRecords) == 0 { |
78 | return nil, err | 86 | return nil, err |
79 | } | 87 | } |
80 | 88 | ||
81 | - // 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工 | ||
82 | - groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId) | ||
83 | - employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext) | ||
84 | for i := 0; i < len(attendanceRecords); i++ { | 89 | for i := 0; i < len(attendanceRecords); i++ { |
85 | r := attendanceRecords[i] | 90 | r := attendanceRecords[i] |
86 | - participateType := domain.ParticipateNormal | ||
87 | - if _, ok := groupMembers[groupMembersKeyFunc(r.ProductWorker.UserId)]; !ok { | ||
88 | - participateType = domain.ParticipateSupport | ||
89 | - } | ||
90 | - | ||
91 | - var employeeProductRecord *domain.EmployeeProductRecord | ||
92 | - employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, r.ProductWorker.UserId, productRecord.CreatedAt) | ||
93 | - if err == domain.ErrorNotFound { | ||
94 | - employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, r.ProductWorker) | ||
95 | - } else { | ||
96 | - if err != nil { | ||
97 | - log.Logger.Error(err.Error()) | ||
98 | - continue | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - // 查询当前员工 昨日产能 、历史最好产能 | ||
103 | - var ( | ||
104 | - yesterdayOutputWeight float64 = 0 | ||
105 | - bestOutputWeight float64 = 0 | ||
106 | - ) | ||
107 | - if employeeProductRecord.ProductRecordInfo.BestOutputWeight > 0 { | ||
108 | - if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, r.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { | ||
109 | - yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | ||
110 | - bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | ||
111 | - | ||
112 | - } else { | ||
113 | - if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, r.ProductWorker.UserId); e == nil && record != nil { | ||
114 | - yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | ||
115 | - } | ||
116 | - } | ||
117 | - } | ||
118 | - | ||
119 | - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | ||
120 | - | ||
121 | - if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { | ||
122 | - // TODO:异常处理 | ||
123 | - log.Logger.Error(fmt.Sprintf("生产记录:[%v] 员工:[%v] 处理异常:%v", productRecord.ProductRecordId, r.ProductWorker.UserId, err.Error())) | ||
124 | - continue | ||
125 | - } | ||
126 | - } | 91 | + productRecord.ProductWorker = r.ProductWorker |
127 | // 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据) | 92 | // 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据) |
128 | - | ||
129 | // 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型) | 93 | // 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型) |
130 | - | ||
131 | // 个人 | 94 | // 个人 |
132 | - | 95 | + if _, err := ptr.personalProductStatics(productPlan, groupMembers, groupMembersKeyFunc, productRecord); err != nil { |
96 | + return nil, err | ||
97 | + } | ||
98 | + } | ||
133 | return nil, nil | 99 | return nil, nil |
134 | } | 100 | } |
135 | 101 | ||
@@ -208,7 +174,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | @@ -208,7 +174,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | ||
208 | } | 174 | } |
209 | 175 | ||
210 | // 个人生产记录统计 | 176 | // 个人生产记录统计 |
211 | -func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.ProductRecord) (interface{}, error) { | 177 | +func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.ProductPlan, groupMembers map[string]*domain.User, groupMembersKeyFunc func(int) string, productRecord *domain.ProductRecord) (interface{}, error) { |
212 | var ( | 178 | var ( |
213 | //workshopRepository,_=repository.NewWorkshopRepository(ptr.transactionContext) | 179 | //workshopRepository,_=repository.NewWorkshopRepository(ptr.transactionContext) |
214 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) | 180 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) |
@@ -219,26 +185,34 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -219,26 +185,34 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
219 | cid = productRecord.CompanyId | 185 | cid = productRecord.CompanyId |
220 | oid = productRecord.OrgId | 186 | oid = productRecord.OrgId |
221 | planId = productRecord.ProductRecordInfo.ProductPlanId | 187 | planId = productRecord.ProductRecordInfo.ProductPlanId |
222 | - productPlan *domain.ProductPlan | 188 | + //productPlan *domain.ProductPlan |
223 | err error | 189 | err error |
224 | ) | 190 | ) |
225 | // 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工 | 191 | // 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工 |
226 | - groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId) | ||
227 | - employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext) | ||
228 | - | 192 | + if groupMembers == nil { |
193 | + groupMembers, groupMembersKeyFunc = FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId) | ||
194 | + } | ||
195 | + if productPlan == nil { | ||
229 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) | 196 | productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId}) |
230 | if err != nil { | 197 | if err != nil { |
231 | return nil, err | 198 | return nil, err |
232 | } | 199 | } |
200 | + } | ||
201 | + workStationId := productRecord.WorkStation.WorkStationId | ||
202 | + | ||
203 | + employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext) | ||
233 | 204 | ||
234 | participateType := domain.ParticipateNormal | 205 | participateType := domain.ParticipateNormal |
235 | if _, ok := groupMembers[groupMembersKeyFunc(productRecord.ProductWorker.UserId)]; !ok { | 206 | if _, ok := groupMembers[groupMembersKeyFunc(productRecord.ProductWorker.UserId)]; !ok { |
236 | participateType = domain.ParticipateSupport | 207 | participateType = domain.ParticipateSupport |
237 | } | 208 | } |
238 | var employeeProductRecord *domain.EmployeeProductRecord | 209 | var employeeProductRecord *domain.EmployeeProductRecord |
239 | - employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt) | 210 | + employeeProductRecord, err = employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt) |
240 | if err == domain.ErrorNotFound { | 211 | if err == domain.ErrorNotFound { |
241 | employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker) | 212 | employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker) |
213 | + err = nil | ||
214 | + } else if err != nil { | ||
215 | + return nil, err | ||
242 | } | 216 | } |
243 | 217 | ||
244 | // 查询当前员工 昨日产能 、历史最好产能 | 218 | // 查询当前员工 昨日产能 、历史最好产能 |
@@ -247,9 +221,9 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -247,9 +221,9 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
247 | bestOutputWeight float64 = 0 | 221 | bestOutputWeight float64 = 0 |
248 | ) | 222 | ) |
249 | if employeeProductRecord.ProductRecordInfo.BestOutputWeight == 0 { | 223 | if employeeProductRecord.ProductRecordInfo.BestOutputWeight == 0 { |
250 | - if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { | 224 | + if record, e := employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil { |
251 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight | 225 | yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight |
252 | - bestOutputWeight = record.ProductRecordInfo.BestOutputWeight | 226 | + bestOutputWeight = record.ProductRecordInfo.GetBestOutputWeight() |
253 | 227 | ||
254 | } else { | 228 | } else { |
255 | if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil { | 229 | if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil { |
@@ -258,7 +232,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | @@ -258,7 +232,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. | ||
258 | } | 232 | } |
259 | } | 233 | } |
260 | 234 | ||
261 | - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight) | 235 | + employeeProductRecord.UpdateProductWeigh(productRecord, yesterdayOutputWeight, bestOutputWeight) |
262 | 236 | ||
263 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { | 237 | if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { |
264 | // TODO:异常处理 | 238 | // TODO:异常处理 |
@@ -273,7 +247,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -273,7 +247,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
273 | workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext) | 247 | workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext) |
274 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) | 248 | productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext) |
275 | //productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | 249 | //productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) |
276 | - employeeProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext) | 250 | + workshopProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext) |
277 | ) | 251 | ) |
278 | 252 | ||
279 | var ( | 253 | var ( |
@@ -298,29 +272,36 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | @@ -298,29 +272,36 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. | ||
298 | //查询生产记录 批次、生产日期、下(成型)所有二级品 | 272 | //查询生产记录 批次、生产日期、下(成型)所有二级品 |
299 | // 更新打料的二级品需要再一次更新成型的二级品 | 273 | // 更新打料的二级品需要再一次更新成型的二级品 |
300 | if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil { | 274 | if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil { |
301 | - nextProductRecord := *productRecord | 275 | + if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok { |
302 | nextProductRecord.WorkStation.SectionName = ProductSection2 | 276 | nextProductRecord.WorkStation.SectionName = ProductSection2 |
303 | nextProductRecord.WorkStation.SectionId = section.SectionId | 277 | nextProductRecord.WorkStation.SectionId = section.SectionId |
304 | - ptr.WorkshopProductStatics(&nextProductRecord) | 278 | + nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId) |
279 | + nextProductRecord.PreRecord = productRecord | ||
280 | + ptr.WorkshopProductStatics(nextProductRecord) | ||
281 | + } | ||
305 | } | 282 | } |
306 | } | 283 | } |
307 | break | 284 | break |
308 | } | 285 | } |
309 | 286 | ||
310 | - var employeeProductRecord *domain.WorkshopProductRecord | ||
311 | - employeeProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext) | ||
312 | - employeeProductRecord, err = employeeProductRecordDao.WorkshopProductRecord(cid, oid, planId, productRecord.CreatedAt) | 287 | + var workshopProductRecord *domain.WorkshopProductRecord |
288 | + workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext) | ||
289 | + workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt) | ||
313 | if err == domain.ErrorNotFound { | 290 | if err == domain.ErrorNotFound { |
314 | - employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan) | 291 | + workshopProductRecord = newWorkshopProductRecord(productRecord, productPlan) |
315 | } else { | 292 | } else { |
316 | if err != nil { | 293 | if err != nil { |
317 | log.Logger.Error(err.Error()) | 294 | log.Logger.Error(err.Error()) |
318 | return nil, nil | 295 | return nil, nil |
319 | } | 296 | } |
320 | } | 297 | } |
321 | - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName) | 298 | + workshopProductRecord.UpdateProductWeigh(productRecord) |
299 | + // 打料 跟 成型工段的初始产能是批次的产能 | ||
300 | + if productRecord.WorkStation.SectionName == ProductSection1 && productRecord.WorkStation.SectionName == ProductSection2 { | ||
301 | + workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId) | ||
302 | + } | ||
322 | 303 | ||
323 | - if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { | 304 | + if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil { |
324 | // TODO:异常处理 | 305 | // TODO:异常处理 |
325 | log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error())) | 306 | log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error())) |
326 | } | 307 | } |
@@ -58,12 +58,15 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | @@ -58,12 +58,15 @@ func (ptr *PGWorkshopPlanCompletionRecordService) WorkshopPlanCompletion(begin t | ||
58 | totalReal += v.RealWeight | 58 | totalReal += v.RealWeight |
59 | } | 59 | } |
60 | var completionRate float64 | 60 | var completionRate float64 |
61 | - if !(totalPlan == 0 || totalReal == 0) { | ||
62 | - completionRate = utils.Round(totalReal*100.0/totalPlan, 0) | ||
63 | - } | 61 | + if totalPlan > 0 && totalReal > 0 { |
64 | // 超出计划生产的,最多完成效率 100% | 62 | // 超出计划生产的,最多完成效率 100% |
65 | if totalPlan <= totalReal { | 63 | if totalPlan <= totalReal { |
66 | completionRate = 100 | 64 | completionRate = 100 |
65 | + } else { | ||
66 | + completionRate = utils.Round(totalReal*100.0/totalPlan, 0) | ||
67 | + } | ||
68 | + } else { | ||
69 | + completionRate = 0 | ||
67 | } | 70 | } |
68 | 71 | ||
69 | var record *models.WorkshopPlanCompletionRecord | 72 | var record *models.WorkshopPlanCompletionRecord |
@@ -27,8 +27,8 @@ func (repository *EmployeeProductRecordRepository) nextIdentify() (int64, error) | @@ -27,8 +27,8 @@ func (repository *EmployeeProductRecordRepository) nextIdentify() (int64, error) | ||
27 | func (repository *EmployeeProductRecordRepository) Save(employeeProductRecord *domain.EmployeeProductRecord) (*domain.EmployeeProductRecord, error) { | 27 | func (repository *EmployeeProductRecordRepository) Save(employeeProductRecord *domain.EmployeeProductRecord) (*domain.EmployeeProductRecord, error) { |
28 | sqlBuildFields := []string{ | 28 | sqlBuildFields := []string{ |
29 | "employee_product_record_id", | 29 | "employee_product_record_id", |
30 | - "org_id", | ||
31 | "company_id", | 30 | "company_id", |
31 | + "org_id", | ||
32 | "work_station", | 32 | "work_station", |
33 | "work_on", | 33 | "work_on", |
34 | "participate_type", | 34 | "participate_type", |
script/batch_sign_in.sh
0 → 100644
1 | +#! /bin/bash | ||
2 | + | ||
3 | +echo "批量打卡" | ||
4 | + | ||
5 | +# 待打卡的用户IC卡号列表 | ||
6 | +icList=("18860189991" "18860189992" "18860189993" "18860187878" "18860183016") | ||
7 | +# 设备编号 | ||
8 | +device_coe='STX-D-0001' | ||
9 | +# 测试环境服务地址 | ||
10 | +#host="http://allied-creation-manufacture-test.fjmaimaimai.com/zkteco/iclock/cdata?SN=$device_coe" | ||
11 | +# 本地环境服务地址 | ||
12 | +host="http://106.75.231.90:9999/zkteco/iclock/cdata?SN=$device_coe" | ||
13 | + | ||
14 | +sign_time=`date "+%Y-%m-%d 08:00:00"` | ||
15 | + | ||
16 | +if [ $1 = 'off' ];then | ||
17 | + sign_time=`date "+%Y-%m-%d 18:00:00"` | ||
18 | + echo "下班打卡" | ||
19 | +else | ||
20 | + echo "上班打卡" | ||
21 | +fi | ||
22 | + | ||
23 | +for str in ${icList[*]};do | ||
24 | + echo "IC: $str $sign_time \r\n" | ||
25 | + curl --location --request POST $host \ | ||
26 | + --data-raw "$str $sign_time $ YY" | ||
27 | +done |
script/sign_in.sh
0 → 100644
1 | +#! /bin/bash | ||
2 | + | ||
3 | +echo "批量打卡" | ||
4 | + | ||
5 | +# 待打卡的用户IC卡号列表 | ||
6 | +icList=("18860189991" "18860189992") | ||
7 | +# 设备编号 | ||
8 | +device_coe='STX-D-0001' | ||
9 | +# 测试环境服务地址 | ||
10 | +host="http://allied-creation-manufacture-test.fjmaimaimai.com/zkteco/iclock/cdata?SN=$device_coe" | ||
11 | +# 本地环境服务地址 | ||
12 | +#host="http://106.75.231.90:9999/zkteco/iclock/cdata?SN=$device_coe" | ||
13 | + | ||
14 | +sign_time=`date "+%Y-%m-%d %H:%M:%S"` | ||
15 | + | ||
16 | +for str in ${icList[*]};do | ||
17 | + echo "IC: $str 打卡时间: $sign_time \r\n" | ||
18 | + curl --location --request POST $host \ | ||
19 | + --data-raw "$str $sign_time $ YY" | ||
20 | +done |
-
请 注册 或 登录 后发表评论