Merge remote-tracking branch 'origin/test'
正在显示
63 个修改的文件
包含
1565 行增加
和
480 行删除
config/app.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_dev | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
config/app_test.conf
0 → 100644
1 | +POSTGRESQL_DB_NAME = allied_creation_test | ||
2 | +POSTGRESQL_HOST = 114.55.200.59 | ||
3 | +POSTGRESQL_PORT = 31543 | ||
4 | +POSTGRESQL_USER = postgres | ||
5 | +POSTGRESQL_PASSWORD = eagle1010 | ||
6 | +DISABLE_SQL_GENERATE_COMMENT = false | ||
7 | +SERVICE_ENV = test | ||
8 | +HTTP_PORT = 8081 | ||
9 | +ENABLE_KAFKA_LOG11 = true | ||
10 | +HTTPS_PORT = 8143 | ||
11 | +ALLIED_CREATION_USER_HOST = http://allied-creation-user-test.fjmaimaimai.com | ||
12 | +MANUFACTURE_DEFAULT_COMPANYID = 23 | ||
13 | +MANUFACTURE_DEFAULT_ORGID = 487 | ||
14 | +MANUFACTURE_DEFAULT_WORKSHOPID = 28 |
deploy/db/v1.0.1 db_script.sql
0 → 100644
1 | + | ||
2 | +-- 表product_calendar 增加字段 break_time_periods | ||
3 | +ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb; | ||
4 | + | ||
5 | +-- 表product_attendance_record 增加字段 product_date | ||
6 | +alter table manufacture.product_attendance_record add COLUMN product_date timestamptz; | ||
7 | +update manufacture.product_attendance_record set product_date = sign_in where product_date is null ; | ||
8 | + | ||
9 | + | ||
10 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (260, 174, '监控中心', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER', '', 'catalog', '', 5, '', '7', '38,174', 1, 0, NULL); | ||
11 | + | ||
12 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (261, 260, '生产设备监控', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER_DEVICE-MONITOR', '', 'menu', '', 1, '', '7', '38,174,233,244', 1, 2, NULL); | ||
13 | + | ||
14 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (262, 260, '生产管理看板', 'BUSINESS_ALLIED-MANUFACTURING_MONITORING-CENTER_PRODUCTION-MONITOR', '', 'menu', '', 2, '', '7', '38,174,260', 1, 2, NULL); | ||
15 | + | ||
16 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (263, 224, '新增工时', 'BUSINESS_ALLIED-MANUFACTURING_PRODUCTION_MAN-HOUR_ADD', '', 'button', '', 1, '', '7', '38,174,223,224', 1, 2, NULL); | ||
17 | + | ||
18 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (264, 174, '大屏看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE', '', 'catalog', '', 6, '', '7', '38,174', 1, 2, NULL); | ||
19 | + | ||
20 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (265, 264, '生产管理看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE_PRODUCTION', '', 'menu', 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220517/object/1652752760_w66QpzZTfxsmhbM5mmBrHjpytcydMNs2.png', 1, '', '7', '38,174,264', 1, 2, NULL); | ||
21 | + | ||
22 | +INSERT INTO "users"."menu"("menu_id", "parent_id", "menu_name", "code", "access_code", "menu_type", "icon", "sort", "remark", "category", "parent_path", "is_publish", "enable_status", "link") VALUES (266, 264, '设备监控看板', 'BUSINESS_ALLIED-MANUFACTURING_LARGE-SCREEN-SIGNAGE_DEVICE', '', 'menu', 'https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220517/object/1652753144_XsBEXcRxJscRHCzQmxeseTAEQXTH7A7Z.png', 2, '', '7', '38,174,264', 1, 2, NULL); |
@@ -24,7 +24,6 @@ require ( | @@ -24,7 +24,6 @@ require ( | ||
24 | github.com/onsi/gomega v1.11.0 | 24 | github.com/onsi/gomega v1.11.0 |
25 | github.com/sergi/go-diff v1.2.0 // indirect | 25 | github.com/sergi/go-diff v1.2.0 // indirect |
26 | github.com/shopspring/decimal v1.2.0 | 26 | github.com/shopspring/decimal v1.2.0 |
27 | - github.com/sirupsen/logrus v1.8.0 | ||
28 | github.com/smartystreets/goconvey v1.7.2 // indirect | 27 | github.com/smartystreets/goconvey v1.7.2 // indirect |
29 | github.com/stretchr/testify v1.7.0 | 28 | github.com/stretchr/testify v1.7.0 |
30 | github.com/tidwall/gjson v1.13.0 | 29 | github.com/tidwall/gjson v1.13.0 |
@@ -37,4 +36,4 @@ require ( | @@ -37,4 +36,4 @@ require ( | ||
37 | golang.org/x/text v0.3.6 | 36 | golang.org/x/text v0.3.6 |
38 | ) | 37 | ) |
39 | 38 | ||
40 | -replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987 | 39 | +replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 |
@@ -380,8 +380,8 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | @@ -380,8 +380,8 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | ||
380 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= | 380 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= |
381 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= | 381 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= |
382 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= | 382 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= |
383 | -github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987 h1:0e2hOSL+//5AL7e1r3xCGEugsOPsw2POAm82VZvWLe4= | ||
384 | -github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987/go.mod h1:xl9i83IKNUkwlobRF6XLKn1RRbZsT+7yhCicpTGWTKc= | 383 | +github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 h1:mUikg1B4YHx79eAqj17OoyfLvOfYCiXmhtHd6ywu6Rc= |
384 | +github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1/go.mod h1:jfeZYXCWwE7u3bUeyJlfhlzC25b9699lUMURP7pdE3I= | ||
385 | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | 385 | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= |
386 | github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | 386 | github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= |
387 | github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= | 387 | github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= |
@@ -3,7 +3,6 @@ package main | @@ -3,7 +3,6 @@ package main | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
6 | - "github.com/linmadan/egglib-go/log/logrus" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
@@ -25,16 +24,8 @@ func main() { | @@ -25,16 +24,8 @@ func main() { | ||
25 | log.Logger.Error(fmt.Sprintf("%v", r)) | 24 | log.Logger.Error(fmt.Sprintf("%v", r)) |
26 | } | 25 | } |
27 | }() | 26 | }() |
28 | - if constant.ENABLE_KAFKA_LOG { | ||
29 | - w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false) | ||
30 | - log.Logger.AddHook(w) | ||
31 | - } | ||
32 | - bw := log.NewBeegoLogWriter(log.LoggerConfig{ | ||
33 | - Filename: constant.LOG_FILE, | ||
34 | - Level: 7, | ||
35 | - MaxSize: 1024 * 1024 * 2, | ||
36 | - }) | ||
37 | - log.Logger.AddHook(bw) | 27 | + |
28 | + log.InitLogHook(constant.ENABLE_KAFKA_LOG, true) | ||
38 | redis.InitRedis() | 29 | redis.InitRedis() |
39 | log.Logger.Info("server start ....") | 30 | log.Logger.Info("server start ....") |
40 | log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG)) | 31 | log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG)) |
@@ -2,38 +2,53 @@ package command | @@ -2,38 +2,53 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | "reflect" | 7 | "reflect" |
6 | "strings" | 8 | "strings" |
7 | - "time" | ||
8 | - | ||
9 | - "github.com/beego/beego/v2/core/validation" | ||
10 | ) | 9 | ) |
11 | 10 | ||
12 | type CreateAttendanceCommand struct { | 11 | type CreateAttendanceCommand struct { |
13 | // 考勤记录ID | 12 | // 考勤记录ID |
14 | //ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"` | 13 | //ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"` |
15 | // 考勤类型 1.正常 2.支援 | 14 | // 考勤类型 1.正常 2.支援 |
16 | - AttendanceType int `json:"attendanceType,omitempty"` | 15 | + AttendanceType int `cname:"考勤类型" json:"attendanceType,omitempty"` |
17 | // 生产班组Id | 16 | // 生产班组Id |
18 | - ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"` | 17 | + ProductGroupId int `cname:"生产班组Id" json:"productGroupId,omitempty" valid:"Required"` |
19 | // 生产工人 | 18 | // 生产工人 |
20 | - ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"` | 19 | + ProductWorkerId int `cname:"生产工人" json:"productWorkerId,omitempty" valid:"Required"` |
21 | // 车间ID | 20 | // 车间ID |
22 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` | 21 | WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` |
23 | // 生产线ID | 22 | // 生产线ID |
24 | LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` | 23 | LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` |
25 | // 工段ID | 24 | // 工段ID |
26 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 25 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
26 | + // 生产日期 | ||
27 | + ProductDate string `cname:"生产日期" json:"productDate,omitempty" valid:"Required"` | ||
27 | // 签到 | 28 | // 签到 |
28 | - SignIn time.Time `json:"signIn,omitempty"` | 29 | + SignIn string `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"` |
29 | // 签退 | 30 | // 签退 |
30 | - SignOut time.Time `json:"signOut,omitempty"` | ||
31 | - // 考勤状态 1.未审核 2:已审核 3.自动审核 | ||
32 | - //AttendanceStatus int `json:"attendanceStatus,omitempty"` | 31 | + SignOut string `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"` |
32 | + // 考勤状态 1.未审核 2:审核 | ||
33 | + AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"` | ||
34 | + // 休息时长 | ||
35 | + BreakTime float64 `cname:"休息时长" json:"breakTime"` | ||
36 | + // 工时 | ||
37 | + WorkTime float64 `cname:"工时" json:"workTime"` | ||
38 | + // 准备(true:准备完毕 false:进行预查) | ||
39 | + Prepared bool `json:"prepared"` | ||
33 | } | 40 | } |
34 | 41 | ||
35 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { | 42 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { |
36 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 43 | + if err := utils.ValidWorkTime(createAttendanceCommand.SignIn); err != nil { |
44 | + validation.Error(err.Error()) | ||
45 | + return | ||
46 | + } | ||
47 | + if err := utils.ValidWorkTime(createAttendanceCommand.SignOut); err != nil { | ||
48 | + validation.Error(err.Error()) | ||
49 | + return | ||
50 | + } | ||
51 | + validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus") | ||
37 | } | 52 | } |
38 | 53 | ||
39 | func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error { | 54 | func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error { |
@@ -31,6 +31,10 @@ type AttendanceRecordDto struct { | @@ -31,6 +31,10 @@ type AttendanceRecordDto struct { | ||
31 | SignOut string `json:"signOut"` | 31 | SignOut string `json:"signOut"` |
32 | // 考勤状态 1.未审核 2:已审核 3.自动审核 | 32 | // 考勤状态 1.未审核 2:已审核 3.自动审核 |
33 | AttendanceStatus int `json:"attendanceStatus"` | 33 | AttendanceStatus int `json:"attendanceStatus"` |
34 | + // 打卡工时 | ||
35 | + WorkTime float64 `json:"workTime"` | ||
36 | + // 休息工时 | ||
37 | + BreakTime float64 `json:"breakTime"` | ||
34 | // 工时(审核前) | 38 | // 工时(审核前) |
35 | WorkTimeBefore float64 `json:"workTimeBefore"` | 39 | WorkTimeBefore float64 `json:"workTimeBefore"` |
36 | // 工时(审核后) | 40 | // 工时(审核后) |
@@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -50,7 +54,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
50 | d.WorkStation = m.WorkStation | 54 | d.WorkStation = m.WorkStation |
51 | if !m.SignIn.IsZero() { | 55 | if !m.SignIn.IsZero() { |
52 | d.SignIn = m.SignIn.Local().Format("15:04:05") | 56 | d.SignIn = m.SignIn.Local().Format("15:04:05") |
53 | - d.SignDate = m.SignIn.Local().Format("2006-01-02") | 57 | + d.SignDate = m.ProductTime().Local().Format("2006-01-02") |
54 | } | 58 | } |
55 | if !m.SignOut.IsZero() { | 59 | if !m.SignOut.IsZero() { |
56 | d.SignOut = m.SignOut.Local().Format("15:04:05") | 60 | d.SignOut = m.SignOut.Local().Format("15:04:05") |
@@ -59,23 +63,16 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | @@ -59,23 +63,16 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i | ||
59 | d.WorkTimeAfter = m.WorkTimeAfter | 63 | d.WorkTimeAfter = m.WorkTimeAfter |
60 | d.AttendanceStatus = m.AttendanceStatus | 64 | d.AttendanceStatus = m.AttendanceStatus |
61 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 65 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
62 | - if m.Ext != nil { | ||
63 | d.OrgName = m.Ext.OrgName | 66 | d.OrgName = m.Ext.OrgName |
64 | - //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt | ||
65 | - //if | ||
66 | - if m.Ext.AttendanceExt != nil { | ||
67 | - if m.Ext.AttendanceExt.ApproveUserId > 0 { | ||
68 | - d.ApproveUser = &domain.User{ | ||
69 | - UserId: m.Ext.AttendanceExt.ApproveUserId, | ||
70 | - UserName: m.Ext.AttendanceExt.ApproveUserName, | ||
71 | - } | ||
72 | - } | 67 | + d.ApproveUser = m.ApproveUser() |
68 | + d.GroupName = m.GroupName() | ||
69 | + if m.Ext != nil && m.Ext.AttendanceExt != nil { | ||
73 | if m.Ext.AttendanceExt.ApproveAt > 0 { | 70 | if m.Ext.AttendanceExt.ApproveAt > 0 { |
74 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) | 71 | t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0) |
75 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") | 72 | d.ApproveAt = t.Local().Format("2006-01-02 15:04:05") |
76 | } | 73 | } |
77 | - d.GroupName = m.Ext.AttendanceExt.GroupName | ||
78 | - } | 74 | + d.WorkTime = m.WorkTimeBefore + m.Ext.AttendanceExt.BreakTime |
75 | + d.BreakTime = m.Ext.AttendanceExt.BreakTime | ||
79 | } | 76 | } |
80 | return d | 77 | return d |
81 | } | 78 | } |
@@ -40,10 +40,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | @@ -40,10 +40,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | ||
40 | d.AttendanceType = m.AttendanceType | 40 | d.AttendanceType = m.AttendanceType |
41 | d.ProductWorker = m.ProductWorker | 41 | d.ProductWorker = m.ProductWorker |
42 | d.WorkStation = m.WorkStation | 42 | d.WorkStation = m.WorkStation |
43 | - if !m.SignIn.IsZero() { | ||
44 | - //d.SignIn = m.SignIn.Format("15:04:05") | ||
45 | - d.SignDate = m.SignIn.Local().Format("2006-01-02") | ||
46 | - } | 43 | + d.SignDate = m.ProductTime().Local().Format("2006-01-02") |
47 | d.WorkTime = utils.Round(m.WorkTimeAfter, 1) | 44 | d.WorkTime = utils.Round(m.WorkTimeAfter, 1) |
48 | //d.WorkTimeAfter = m.WorkTimeAfter | 45 | //d.WorkTimeAfter = m.WorkTimeAfter |
49 | d.AttendanceStatus = m.AttendanceStatus | 46 | d.AttendanceStatus = m.AttendanceStatus |
@@ -51,12 +48,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | @@ -51,12 +48,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, | ||
51 | d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType) | 48 | d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType) |
52 | d.AttendanceStatusDescription = domain.AttendanceStatusDescription(m.AttendanceStatus) | 49 | d.AttendanceStatusDescription = domain.AttendanceStatusDescription(m.AttendanceStatus) |
53 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 50 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
54 | - if m.Ext != nil { | ||
55 | d.OrgName = m.Ext.OrgName | 51 | d.OrgName = m.Ext.OrgName |
56 | - //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt | ||
57 | - if m.Ext.AttendanceExt != nil { | ||
58 | - d.GroupName = m.Ext.AttendanceExt.GroupName | ||
59 | - } | ||
60 | - } | 52 | + d.GroupName = m.GroupName() |
61 | return d | 53 | return d |
62 | } | 54 | } |
@@ -34,9 +34,6 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | @@ -34,9 +34,6 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or | ||
34 | d.WorkStation = m.WorkStation | 34 | d.WorkStation = m.WorkStation |
35 | d.RecordDate = m.RecordDate.Local().Format("2006-01-02") | 35 | d.RecordDate = m.RecordDate.Local().Format("2006-01-02") |
36 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) | 36 | d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) |
37 | - if m.Ext != nil { | ||
38 | d.OrgName = m.Ext.OrgName | 37 | d.OrgName = m.Ext.OrgName |
39 | - //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt | ||
40 | - } | ||
41 | return d | 38 | return d |
42 | } | 39 | } |
@@ -55,21 +55,22 @@ func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validatio | @@ -55,21 +55,22 @@ func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validatio | ||
55 | cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) | 55 | cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize) |
56 | var err error | 56 | var err error |
57 | if len(cmd.BeginTime) > 0 { | 57 | if len(cmd.BeginTime) > 0 { |
58 | - if cmd.SignBeginTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.BeginTime, time.Local); err != nil { | 58 | + if cmd.SignBeginTime, err = time.ParseInLocation("2006-01-02", cmd.BeginTime, time.Local); err != nil { |
59 | log.Logger.Error(err.Error()) | 59 | log.Logger.Error(err.Error()) |
60 | validation.Error("开始时间有误") | 60 | validation.Error("开始时间有误") |
61 | return | 61 | return |
62 | } | 62 | } |
63 | } | 63 | } |
64 | if len(cmd.EndTime) > 0 { | 64 | if len(cmd.EndTime) > 0 { |
65 | - if cmd.SignEndTime, err = time.ParseInLocation("2006-01-02 15:04:05", cmd.EndTime, time.Local); err != nil { | 65 | + if cmd.SignEndTime, err = time.ParseInLocation("2006-01-02", cmd.EndTime, time.Local); err != nil { |
66 | log.Logger.Error(err.Error()) | 66 | log.Logger.Error(err.Error()) |
67 | validation.Error("结束时间有误") | 67 | validation.Error("结束时间有误") |
68 | return | 68 | return |
69 | } | 69 | } |
70 | - if cmd.SignBeginTime.Equal(cmd.SignEndTime) { | ||
71 | - cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24) | ||
72 | - } | 70 | + cmd.SignEndTime = cmd.SignEndTime.AddDate(0, 0, 1) |
71 | + //if cmd.SignBeginTime.Equal(cmd.SignEndTime) { | ||
72 | + // cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24) | ||
73 | + //} | ||
73 | } | 74 | } |
74 | //cmd.AttendanceStatus = 6 // 审核 + 自动审核 | 75 | //cmd.AttendanceStatus = 6 // 审核 + 自动审核 |
75 | cmd.InAttendanceStatus = []int{2, 3} | 76 | cmd.InAttendanceStatus = []int{2, 3} |
1 | package service | 1 | package service |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
6 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
13 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
12 | "time" | 16 | "time" |
@@ -100,6 +104,26 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -100,6 +104,26 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
100 | if err != nil { | 104 | if err != nil { |
101 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 105 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
102 | } | 106 | } |
107 | + | ||
108 | + //var workTime float64 = 0 | ||
109 | + //if cmd.WorkTime-cmd.BreakTime > 0 { | ||
110 | + // workTime = cmd.WorkTime - cmd.BreakTime | ||
111 | + //} | ||
112 | + signIn, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignIn)) | ||
113 | + if err != nil { | ||
114 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
115 | + } | ||
116 | + signOut, err := xtime.ParseInLocation(time.Local, fmt.Sprintf("%v %v:00", cmd.ProductDate, cmd.SignOut)) | ||
117 | + if err != nil { | ||
118 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
119 | + } | ||
120 | + productDate, err := xtime.ParseInLocation(time.Local, cmd.ProductDate) | ||
121 | + if err != nil { | ||
122 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
123 | + } | ||
124 | + if !xtime.BeforeEqual(productDate, time.Now()) { | ||
125 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("日期需要小于等于%v", time.Now().Format("2006-01-02"))) | ||
126 | + } | ||
103 | newAttendance := &domain.ProductAttendanceRecord{ | 127 | newAttendance := &domain.ProductAttendanceRecord{ |
104 | //ProductAttendanceId: cmd.ProductAttendanceId, | 128 | //ProductAttendanceId: cmd.ProductAttendanceId, |
105 | CompanyId: operateInfo.CompanyId, | 129 | CompanyId: operateInfo.CompanyId, |
@@ -107,30 +131,52 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -107,30 +131,52 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
107 | AttendanceType: cmd.AttendanceType, | 131 | AttendanceType: cmd.AttendanceType, |
108 | ProductWorker: user, | 132 | ProductWorker: user, |
109 | WorkStation: workStation, | 133 | WorkStation: workStation, |
110 | - SignIn: cmd.SignIn, | ||
111 | - SignOut: cmd.SignOut, | ||
112 | - AttendanceStatus: domain.AttendanceNotApprove, | ||
113 | - WorkTimeBefore: 0, | 134 | + SignIn: signIn, |
135 | + SignOut: signOut, | ||
136 | + AttendanceStatus: cmd.AttendanceStatus, | ||
137 | + WorkTimeBefore: cmd.WorkTime, | ||
114 | WorkTimeAfter: 0, | 138 | WorkTimeAfter: 0, |
115 | CreatedAt: time.Now(), | 139 | CreatedAt: time.Now(), |
116 | UpdatedAt: time.Now(), | 140 | UpdatedAt: time.Now(), |
117 | Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ | 141 | Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{ |
118 | GroupName: productGroup.GroupName, | 142 | GroupName: productGroup.GroupName, |
119 | ProductGroupId: productGroup.ProductGroupId, | 143 | ProductGroupId: productGroup.ProductGroupId, |
144 | + BreakTime: cmd.BreakTime, | ||
120 | }), | 145 | }), |
146 | + ProductDate: productDate, | ||
121 | } | 147 | } |
122 | - newAttendance.WorkTimeBefore = newAttendance.ComputeWorkTimeBefore() | ||
123 | - var attendanceRepository domain.ProductAttendanceRecordRepository | ||
124 | 148 | ||
149 | + if cmd.AttendanceStatus == domain.AttendanceApproved { | ||
150 | + newAttendance.WorkTimeAfter = domain.AttendanceApproved | ||
151 | + newAttendance.WorkTimeAfter = cmd.WorkTime | ||
152 | + } | ||
153 | + var ( | ||
154 | + attendanceRepository domain.ProductAttendanceRecordRepository | ||
155 | + attendanceRecordDao *dao.AttendanceRecordDao | ||
156 | + ) | ||
157 | + attendanceRecordDao, _ = dao.NewAttendanceRecordDao(transactionContext.(*pg.TransactionContext)) | ||
125 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) | 158 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) |
126 | - | 159 | + if !cmd.Prepared { |
160 | + // 检查时间段内是否有重复的打卡记录 | ||
161 | + count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, newAttendance.SignIn, newAttendance.SignIn) | ||
162 | + if err != nil { | ||
163 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
164 | + } | ||
165 | + if count > 0 { | ||
166 | + return map[string]interface{}{ | ||
167 | + "message": fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName), | ||
168 | + "needConfirm": true, | ||
169 | + }, nil | ||
170 | + } | ||
171 | + } | ||
127 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { | 172 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { |
128 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 173 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
129 | } else { | 174 | } else { |
175 | + domainService.SendWorkshopWorkTimeStaticJob(attendance) | ||
130 | if err := transactionContext.CommitTransaction(); err != nil { | 176 | if err := transactionContext.CommitTransaction(); err != nil { |
131 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 177 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
132 | } | 178 | } |
133 | - return attendance, nil | 179 | + return struct{}{}, nil |
134 | } | 180 | } |
135 | } | 181 | } |
136 | 182 |
@@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
6 | "reflect" | 7 | "reflect" |
7 | "strings" | 8 | "strings" |
@@ -23,7 +24,7 @@ type CreateProductCalendarCommand struct { | @@ -23,7 +24,7 @@ type CreateProductCalendarCommand struct { | ||
23 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 24 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
24 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 25 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
25 | // 日历选择 | 26 | // 日历选择 |
26 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 27 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` // valid:"Required" |
27 | // 上岗时间 | 28 | // 上岗时间 |
28 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 29 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
29 | // 下岗时间 | 30 | // 下岗时间 |
@@ -32,6 +33,8 @@ type CreateProductCalendarCommand struct { | @@ -32,6 +33,8 @@ type CreateProductCalendarCommand struct { | ||
32 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` | 33 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` |
33 | // 工时 (单位 h) | 34 | // 工时 (单位 h) |
34 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` | 35 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` |
36 | + // 休息时间周期列表 | ||
37 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
35 | } | 38 | } |
36 | 39 | ||
37 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { | 40 | func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) { |
@@ -44,6 +47,16 @@ func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validati | @@ -44,6 +47,16 @@ func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validati | ||
44 | validation.Error(err.Error()) | 47 | validation.Error(err.Error()) |
45 | return | 48 | return |
46 | } | 49 | } |
50 | + for _, v := range createProductCalendarCommand.BreakTimePeriods { | ||
51 | + if err := utils.ValidWorkTime(v.BeginAt); err != nil { | ||
52 | + validation.Error(err.Error() + " " + v.BeginAt) | ||
53 | + return | ||
54 | + } | ||
55 | + if err := utils.ValidWorkTime(v.EndAt); err != nil { | ||
56 | + validation.Error(err.Error() + " " + v.EndAt) | ||
57 | + return | ||
58 | + } | ||
59 | + } | ||
47 | } | 60 | } |
48 | 61 | ||
49 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { | 62 | func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error { |
@@ -2,6 +2,8 @@ package command | @@ -2,6 +2,8 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | "reflect" | 7 | "reflect" |
6 | "strings" | 8 | "strings" |
7 | 9 | ||
@@ -19,8 +21,8 @@ type UpdateProductCalendarCommand struct { | @@ -19,8 +21,8 @@ type UpdateProductCalendarCommand struct { | ||
19 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 21 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
20 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 22 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
21 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 23 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
22 | - // 日历选择 | ||
23 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 24 | + // 日历选择 valid:"Required" |
25 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` | ||
24 | // 上岗时间 | 26 | // 上岗时间 |
25 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 27 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
26 | // 下岗时间 | 28 | // 下岗时间 |
@@ -29,10 +31,21 @@ type UpdateProductCalendarCommand struct { | @@ -29,10 +31,21 @@ type UpdateProductCalendarCommand struct { | ||
29 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` | 31 | BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"` |
30 | // 工时 (单位 h) | 32 | // 工时 (单位 h) |
31 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` | 33 | WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"` |
34 | + // 休息时间周期列表 | ||
35 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
32 | } | 36 | } |
33 | 37 | ||
34 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { | 38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) { |
35 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 39 | + for _, v := range updateProductCalendarCommand.BreakTimePeriods { |
40 | + if err := utils.ValidWorkTime(v.BeginAt); err != nil { | ||
41 | + validation.Error(err.Error() + " " + v.BeginAt) | ||
42 | + return | ||
43 | + } | ||
44 | + if err := utils.ValidWorkTime(v.EndAt); err != nil { | ||
45 | + validation.Error(err.Error() + " " + v.EndAt) | ||
46 | + return | ||
47 | + } | ||
48 | + } | ||
36 | } | 49 | } |
37 | 50 | ||
38 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { | 51 | func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error { |
@@ -32,6 +32,10 @@ type ProductCalendarDto struct { | @@ -32,6 +32,10 @@ type ProductCalendarDto struct { | ||
32 | OrgName string `json:"orgName"` | 32 | OrgName string `json:"orgName"` |
33 | // 权限标识 (当前登录组织匹配为true,否则false) | 33 | // 权限标识 (当前登录组织匹配为true,否则false) |
34 | AuthFlag bool `json:"authFlag"` | 34 | AuthFlag bool `json:"authFlag"` |
35 | + // 休息时间周期列表 | ||
36 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
37 | + // 累计休息时间 (单位 h) | ||
38 | + // TotalBreakTime float64 `json:"totalBreakTime"` | ||
35 | } | 39 | } |
36 | 40 | ||
37 | func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *ProductCalendarDto { | 41 | func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *ProductCalendarDto { |
@@ -48,5 +52,9 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod | @@ -48,5 +52,9 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod | ||
48 | if m.Ext != nil { | 52 | if m.Ext != nil { |
49 | d.OrgName = m.Ext.OrgName | 53 | d.OrgName = m.Ext.OrgName |
50 | } | 54 | } |
55 | + d.BreakTimePeriods = m.BreakTimePeriods | ||
56 | + //for _, v := range d.BreakTimePeriods { | ||
57 | + // d.TotalBreakTime += v.BreakTime | ||
58 | + //} | ||
51 | return d | 59 | return d |
52 | } | 60 | } |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetProductGroupCalendarQuery struct { | ||
12 | + // 生产班组ID | ||
13 | + ProductGroupId int `cname:"工厂日历ID" json:"productGroupId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getProductCalendarQuery *GetProductGroupCalendarQuery) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getProductCalendarQuery *GetProductGroupCalendarQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getProductCalendarQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getProductCalendarQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
@@ -71,6 +71,7 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper | @@ -71,6 +71,7 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper | ||
71 | OutWorkAt: cmd.OutWorkAt, | 71 | OutWorkAt: cmd.OutWorkAt, |
72 | BreakTime: cmd.BreakTime, | 72 | BreakTime: cmd.BreakTime, |
73 | //WorkTime: cmd.WorkTime, | 73 | //WorkTime: cmd.WorkTime, |
74 | + BreakTimePeriods: cmd.BreakTimePeriods, | ||
74 | CreatedAt: time.Now(), | 75 | CreatedAt: time.Now(), |
75 | UpdatedAt: time.Now(), | 76 | UpdatedAt: time.Now(), |
76 | Ext: domain.NewExt(org.OrgName), | 77 | Ext: domain.NewExt(org.OrgName), |
@@ -306,6 +307,7 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | @@ -306,6 +307,7 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd | ||
306 | productCalendar.InWorkAt = cmd.InWorkAt | 307 | productCalendar.InWorkAt = cmd.InWorkAt |
307 | productCalendar.OutWorkAt = cmd.OutWorkAt | 308 | productCalendar.OutWorkAt = cmd.OutWorkAt |
308 | productCalendar.BreakTime = cmd.BreakTime | 309 | productCalendar.BreakTime = cmd.BreakTime |
310 | + productCalendar.BreakTimePeriods = cmd.BreakTimePeriods | ||
309 | productCalendar.Ext = domain.NewExt(org.OrgName) | 311 | productCalendar.Ext = domain.NewExt(org.OrgName) |
310 | if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil { | 312 | if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil { |
311 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 313 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
@@ -370,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | @@ -370,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | ||
370 | return count, result, nil | 372 | return count, result, nil |
371 | } | 373 | } |
372 | 374 | ||
375 | +// 返回生产班组的工厂日历 | ||
376 | +func (productCalendarService *ProductCalendarService) GetProductGroupCalendar(getProductCalendarQuery *query.GetProductGroupCalendarQuery) (interface{}, error) { | ||
377 | + if err := getProductCalendarQuery.ValidateQuery(); err != nil { | ||
378 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
379 | + } | ||
380 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
381 | + if err != nil { | ||
382 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
383 | + } | ||
384 | + if err := transactionContext.StartTransaction(); err != nil { | ||
385 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
386 | + } | ||
387 | + defer func() { | ||
388 | + transactionContext.RollbackTransaction() | ||
389 | + }() | ||
390 | + productCalendarRepository, _, _ := factory.FastPgProductCalendar(transactionContext, 0) | ||
391 | + _, productGroup, err := factory.FastPgProductGroup(transactionContext, getProductCalendarQuery.ProductGroupId) | ||
392 | + if err != nil { | ||
393 | + return nil, nil | ||
394 | + } | ||
395 | + _, productCalendar, err := productCalendarRepository.Find(map[string]interface{}{"workStationId": productGroup.WorkStation.WorkStationId, "workOn": productGroup.WorkOn, "limit": 1}) | ||
396 | + if err != nil { | ||
397 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
398 | + } | ||
399 | + if len(productCalendar) == 0 { | ||
400 | + return nil, nil | ||
401 | + } | ||
402 | + | ||
403 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
404 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
405 | + } | ||
406 | + | ||
407 | + result := &dto.ProductCalendarDto{} | ||
408 | + result.LoadDto(productCalendar[0], 0) | ||
409 | + return result, nil | ||
410 | +} | ||
411 | + | ||
373 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { | 412 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { |
374 | newProductCalendarService := &ProductCalendarService{} | 413 | newProductCalendarService := &ProductCalendarService{} |
375 | return newProductCalendarService | 414 | return newProductCalendarService |
@@ -21,6 +21,8 @@ type ProductGroupEmployeesDto struct { | @@ -21,6 +21,8 @@ type ProductGroupEmployeesDto struct { | ||
21 | // 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID) | 21 | // 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID) |
22 | //WorkStationId string `json:"workStationId,omitempty"` | 22 | //WorkStationId string `json:"workStationId,omitempty"` |
23 | UserNamePinyin string `json:"pinyin"` | 23 | UserNamePinyin string `json:"pinyin"` |
24 | + // 在线的 | ||
25 | + Online bool `json:"online"` | ||
24 | } | 26 | } |
25 | 27 | ||
26 | func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto { | 28 | func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto { |
@@ -73,12 +75,14 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | @@ -73,12 +75,14 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { | ||
73 | 75 | ||
74 | func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) { | 76 | func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) { |
75 | var mapUser = make(map[int]int) | 77 | var mapUser = make(map[int]int) |
78 | + // 打卡的用户 | ||
76 | for _, v := range list { | 79 | for _, v := range list { |
77 | item := &ProductGroupEmployeesDto{} | 80 | item := &ProductGroupEmployeesDto{} |
78 | item.UserId = v.ProductWorker.UserId | 81 | item.UserId = v.ProductWorker.UserId |
79 | item.UserName = v.ProductWorker.UserName | 82 | item.UserName = v.ProductWorker.UserName |
80 | item.ProductGroupId = 0 | 83 | item.ProductGroupId = 0 |
81 | item.GroupName = "" | 84 | item.GroupName = "" |
85 | + item.Online = true | ||
82 | if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { | 86 | if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { |
83 | item.GroupName = v.GroupName | 87 | item.GroupName = v.GroupName |
84 | item.ProductGroupId = v.GroupId | 88 | item.ProductGroupId = v.GroupId |
@@ -89,9 +93,21 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe | @@ -89,9 +93,21 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe | ||
89 | } | 93 | } |
90 | if _, ok := mapUser[item.UserId]; ok { | 94 | if _, ok := mapUser[item.UserId]; ok { |
91 | continue | 95 | continue |
92 | - } else { | 96 | + } |
93 | mapUser[item.UserId] = item.UserId | 97 | mapUser[item.UserId] = item.UserId |
98 | + d.Append(item) | ||
99 | + } | ||
100 | + // 未打卡的用户 | ||
101 | + for _, v := range mapGroupUser { | ||
102 | + if _, ok := mapUser[v.UserId]; ok { | ||
103 | + continue | ||
94 | } | 104 | } |
105 | + item := &ProductGroupEmployeesDto{} | ||
106 | + item.UserId = v.UserId | ||
107 | + item.UserName = v.UserName | ||
108 | + item.ProductGroupId = v.GroupId | ||
109 | + item.GroupName = v.GroupName | ||
110 | + mapUser[item.UserId] = item.UserId | ||
95 | d.Append(item) | 111 | d.Append(item) |
96 | } | 112 | } |
97 | } | 113 | } |
1 | +package dto | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
5 | +) | ||
6 | + | ||
7 | +// 生产班组 | ||
8 | +type ProductGroupSelectorDto struct { | ||
9 | + // 生产小组ID | ||
10 | + ProductGroupId int `json:"productGroupId,omitempty"` | ||
11 | + // 班组名称 | ||
12 | + GroupName string `json:"groupName,omitempty"` | ||
13 | + // 班组长 | ||
14 | + GroupLeader *domain.User `json:"groupLeader"` | ||
15 | + // 帮组成员列表 | ||
16 | + GroupMembers []*domain.User `json:"groupMembers"` | ||
17 | +} | ||
18 | + | ||
19 | +func (d *ProductGroupSelectorDto) LoadDto(m *domain.ProductGroup, orgId int) *ProductGroupSelectorDto { | ||
20 | + d.ProductGroupId = m.ProductGroupId | ||
21 | + d.GroupName = m.GroupName | ||
22 | + d.GroupLeader = m.GroupLeader | ||
23 | + d.GroupMembers = m.GroupMembers | ||
24 | + return d | ||
25 | +} |
@@ -30,6 +30,12 @@ type SearchProductGroupQuery struct { | @@ -30,6 +30,12 @@ type SearchProductGroupQuery struct { | ||
30 | WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"` | 30 | WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"` |
31 | // 生产线名称 | 31 | // 生产线名称 |
32 | LineName string `cname:"生产线名称" json:"lineName,omitempty"` | 32 | LineName string `cname:"生产线名称" json:"lineName,omitempty"` |
33 | + // 车间ID | ||
34 | + WorkshopId int `cname:"车间ID" json: workshopId,omitempty"` | ||
35 | + // 生产线ID | ||
36 | + LineId int `cname:"生产线ID" json:"lineId,omitempty"` | ||
37 | + // 工段ID | ||
38 | + SectionId int `json:"sectionId,omitempty"` | ||
33 | } | 39 | } |
34 | 40 | ||
35 | func (cmd *SearchProductGroupQuery) Valid(validation *validation.Validation) { | 41 | func (cmd *SearchProductGroupQuery) Valid(validation *validation.Validation) { |
@@ -543,6 +543,44 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi | @@ -543,6 +543,44 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi | ||
543 | }, nil | 543 | }, nil |
544 | } | 544 | } |
545 | 545 | ||
546 | +// 返回生产班组服务列表 | ||
547 | +func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupQuery) (interface{}, error) { | ||
548 | + if err := cmd.ValidateQuery(); err != nil { | ||
549 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
550 | + } | ||
551 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
552 | + if err != nil { | ||
553 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
554 | + } | ||
555 | + if err := transactionContext.StartTransaction(); err != nil { | ||
556 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
557 | + } | ||
558 | + defer func() { | ||
559 | + transactionContext.RollbackTransaction() | ||
560 | + }() | ||
561 | + | ||
562 | + workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId) | ||
563 | + queryOptions := utils.ObjectToMap(cmd) | ||
564 | + queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "") | ||
565 | + | ||
566 | + var productGroupRepository domain.ProductGroupRepository | ||
567 | + productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0) | ||
568 | + _, productGroups, err := productGroupRepository.Find(queryOptions) | ||
569 | + if err != nil { | ||
570 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
571 | + } | ||
572 | + var results = make([]*dto.ProductGroupSelectorDto, 0) | ||
573 | + for i := range productGroups { | ||
574 | + newItem := &dto.ProductGroupSelectorDto{} | ||
575 | + newItem.LoadDto(productGroups[i], operateInfo.OrgId) | ||
576 | + results = append(results, newItem) | ||
577 | + } | ||
578 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
579 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
580 | + } | ||
581 | + return results, nil | ||
582 | +} | ||
583 | + | ||
546 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { | 584 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { |
547 | newProductGroupService := &ProductGroupService{} | 585 | newProductGroupService := &ProductGroupService{} |
548 | return newProductGroupService | 586 | return newProductGroupService |
@@ -18,6 +18,8 @@ type SearchMaterialsQuery struct { | @@ -18,6 +18,8 @@ type SearchMaterialsQuery struct { | ||
18 | LineId int `cname:"生产线ID" json:"lineId,omitempty"` | 18 | LineId int `cname:"生产线ID" json:"lineId,omitempty"` |
19 | // 工段ID | 19 | // 工段ID |
20 | SectionId int `json:"sectionId,omitempty"` | 20 | SectionId int `json:"sectionId,omitempty"` |
21 | + // 智能称重标识 0:全部 1:是 2:否 | ||
22 | + IntelligentWeighingFlag int `cname:"智能称重标识" json:"intelligentWeighingFlag"` | ||
21 | } | 23 | } |
22 | 24 | ||
23 | func (listProductGroupQuery *SearchMaterialsQuery) Valid(validation *validation.Validation) { | 25 | func (listProductGroupQuery *SearchMaterialsQuery) Valid(validation *validation.Validation) { |
@@ -2,10 +2,12 @@ package constant | @@ -2,10 +2,12 @@ package constant | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "os" | ||
6 | - "strconv" | 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
7 | ) | 6 | ) |
8 | 7 | ||
8 | +//var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf") | ||
9 | +var Configurator utils.Configurator = utils.EnvConfigurator{} | ||
10 | + | ||
9 | var SERVICE_NAME = "allied-creation-manufacture" | 11 | var SERVICE_NAME = "allied-creation-manufacture" |
10 | var SERVICE_ENV = "dev" | 12 | var SERVICE_ENV = "dev" |
11 | var HTTP_PORT int = 8081 | 13 | var HTTP_PORT int = 8081 |
@@ -35,46 +37,13 @@ const HeaderOrgId = "orgId" | @@ -35,46 +37,13 @@ const HeaderOrgId = "orgId" | ||
35 | const HeaderOrgIds = "orgIds" | 37 | const HeaderOrgIds = "orgIds" |
36 | 38 | ||
37 | func init() { | 39 | func init() { |
38 | - if os.Getenv("LOG_LEVEL") != "" { | ||
39 | - LOG_LEVEL = os.Getenv("LOG_LEVEL") | ||
40 | - } | ||
41 | - //if os.Getenv("CUSTOMER_ACCOUNT") != "" { | ||
42 | - // account := os.Getenv("CUSTOMER_ACCOUNT") | ||
43 | - // accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER) | ||
44 | - // var tmpAccounts []int64 | ||
45 | - // for i := range accounts { | ||
46 | - // v, err := strconv.ParseInt(accounts[i], 10, 64) | ||
47 | - // if err != nil { | ||
48 | - // panic(err) | ||
49 | - // } | ||
50 | - // tmpAccounts = append(tmpAccounts, v) | ||
51 | - // } | ||
52 | - // if len(tmpAccounts) > 0 { | ||
53 | - // CUSTOMER_ACCOUNT = tmpAccounts | ||
54 | - // } | ||
55 | - //} | ||
56 | - | ||
57 | - if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" { | ||
58 | - ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST") | ||
59 | - } | ||
60 | - if os.Getenv("ALLIED_CREATION_USER_HOST") != "" { | ||
61 | - ALLIED_CREATION_USER_HOST = os.Getenv("ALLIED_CREATION_USER_HOST") | ||
62 | - } | ||
63 | - if os.Getenv("ALLIED_CREATION_COOPERATION_HOST") != "" { | ||
64 | - ALLIED_CREATION_COOPERATION_HOST = os.Getenv("ALLIED_CREATION_COOPERATION_HOST") | ||
65 | - } | ||
66 | - //if os.Getenv("SMS_SERVE_HOST") != "" { | ||
67 | - // SMS_SERVE_HOST = os.Getenv("SMS_SERVE_HOST") | ||
68 | - //} | ||
69 | - if os.Getenv("MMM_BYTE_BANK_HOST") != "" { | ||
70 | - MMM_BYTE_BANK_HOST = os.Getenv("MMM_BYTE_BANK_HOST") | ||
71 | - } | ||
72 | - if os.Getenv("SERVICE_ENV") != "" { | ||
73 | - SERVICE_ENV = os.Getenv("SERVICE_ENV") | ||
74 | - } | ||
75 | - if os.Getenv("HTTP_PORT") != "" { | ||
76 | - HTTP_PORT, _ = strconv.Atoi(os.Getenv("HTTP_PORT")) | ||
77 | - } | 40 | + LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) |
41 | + ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) | ||
42 | + ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) | ||
43 | + ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) | ||
44 | + MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | ||
45 | + SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | ||
46 | + HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) | ||
78 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 47 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
79 | CACHE_PREFIX = SERVICE_NAME | 48 | CACHE_PREFIX = SERVICE_NAME |
80 | } | 49 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var ( | 3 | var ( |
6 | // kafka 地址 | 4 | // kafka 地址 |
7 | KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" //"106.75.231.90:9092" | 5 | KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" //"106.75.231.90:9092" |
@@ -14,13 +12,6 @@ var ( | @@ -14,13 +12,6 @@ var ( | ||
14 | ) | 12 | ) |
15 | 13 | ||
16 | func init() { | 14 | func init() { |
17 | - if os.Getenv("KAFKA_HOST") != "" { | ||
18 | - KAFKA_HOST = os.Getenv("KAFKA_HOST") | ||
19 | - } | ||
20 | - //if os.Getenv("TOPIC_LOG_STASH") != "" { | ||
21 | - // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH") | ||
22 | - //} | ||
23 | - if os.Getenv("ENABLE_KAFKA_LOG") != "" { | ||
24 | - ENABLE_KAFKA_LOG = true | ||
25 | - } | 15 | + KAFKA_HOST = Configurator.DefaultString("KAFKA_HOST", KAFKA_HOST) |
16 | + ENABLE_KAFKA_LOG = Configurator.DefaultBool("ENABLE_KAFKA_LOG", ENABLE_KAFKA_LOG) | ||
26 | } | 17 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "os" | ||
5 | - "strconv" | ||
6 | "strings" | 4 | "strings" |
7 | ) | 5 | ) |
8 | 6 | ||
@@ -20,18 +18,10 @@ var ( | @@ -20,18 +18,10 @@ var ( | ||
20 | ) | 18 | ) |
21 | 19 | ||
22 | func init() { | 20 | func init() { |
23 | - if os.Getenv("MANUFACTURE_DEFAULT_COMPANYID") != "" { | ||
24 | - MANUFACTURE_DEFAULT_COMPANYID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_COMPANYID")) | ||
25 | - } | ||
26 | - if os.Getenv("MANUFACTURE_DEFAULT_ORGID") != "" { | ||
27 | - MANUFACTURE_DEFAULT_ORGID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_ORGID")) | ||
28 | - } | ||
29 | - if os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID") != "" { | ||
30 | - MANUFACTURE_DEFAULT_WORKSHOPID, _ = strconv.Atoi(os.Getenv("MANUFACTURE_DEFAULT_WORKSHOPID")) | ||
31 | - } | ||
32 | - if os.Getenv("MANUFACTURE_PRODUCT_TYPE") != "" { | ||
33 | - MANUFACTURE_PRODUCT_TYPE = os.Getenv("MANUFACTURE_PRODUCT_TYPE") | ||
34 | - } | 21 | + MANUFACTURE_DEFAULT_COMPANYID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_COMPANYID", MANUFACTURE_DEFAULT_COMPANYID) |
22 | + MANUFACTURE_DEFAULT_ORGID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_ORGID", MANUFACTURE_DEFAULT_ORGID) | ||
23 | + MANUFACTURE_DEFAULT_WORKSHOPID = Configurator.DefaultInt("MANUFACTURE_DEFAULT_WORKSHOPID", MANUFACTURE_DEFAULT_WORKSHOPID) | ||
24 | + MANUFACTURE_PRODUCT_TYPE = Configurator.DefaultString("MANUFACTURE_PRODUCT_TYPE", MANUFACTURE_PRODUCT_TYPE) | ||
35 | productTypes := strings.Split(MANUFACTURE_PRODUCT_TYPE, ",") | 25 | productTypes := strings.Split(MANUFACTURE_PRODUCT_TYPE, ",") |
36 | for i, v := range productTypes { | 26 | for i, v := range productTypes { |
37 | MapProductType[i+1] = v | 27 | MapProductType[i+1] = v |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var MQTT_TOPIC = "/MQTT" | 3 | var MQTT_TOPIC = "/MQTT" |
6 | 4 | ||
7 | //设备商提供的测试地址 | 5 | //设备商提供的测试地址 |
@@ -32,16 +30,8 @@ var MQTT_USER = "admin" | @@ -32,16 +30,8 @@ var MQTT_USER = "admin" | ||
32 | var MQTT_PASSWORD = "123456" | 30 | var MQTT_PASSWORD = "123456" |
33 | 31 | ||
34 | func init() { | 32 | func init() { |
35 | - if os.Getenv("MQTT_HOST") != "" { | ||
36 | - MQTT_HOST = os.Getenv("MQTT_HOST") | ||
37 | - } | ||
38 | - if os.Getenv("MQTT_PORT") != "" { | ||
39 | - MQTT_PORT = os.Getenv("MQTT_PORT") | ||
40 | - } | ||
41 | - if os.Getenv("MQTT_USER") != "" { | ||
42 | - MQTT_USER = os.Getenv("MQTT_USER") | ||
43 | - } | ||
44 | - if os.Getenv("MQTT_PASSWORD") != "" { | ||
45 | - MQTT_PASSWORD = os.Getenv("MQTT_PASSWORD") | ||
46 | - } | 33 | + MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST) |
34 | + MQTT_PORT = Configurator.DefaultString("MQTT_PORT", MQTT_PORT) | ||
35 | + MQTT_USER = Configurator.DefaultString("MQTT_USER", MQTT_USER) | ||
36 | + MQTT_PASSWORD = Configurator.DefaultString("MQTT_PASSWORD", MQTT_PASSWORD) | ||
47 | } | 37 | } |
@@ -3,10 +3,6 @@ | @@ -3,10 +3,6 @@ | ||
3 | 3 | ||
4 | package constant | 4 | package constant |
5 | 5 | ||
6 | -import ( | ||
7 | - "os" | ||
8 | -) | ||
9 | - | ||
10 | var POSTGRESQL_DB_NAME = "terms" | 6 | var POSTGRESQL_DB_NAME = "terms" |
11 | var POSTGRESQL_USER = "postgres" | 7 | var POSTGRESQL_USER = "postgres" |
12 | var POSTGRESQL_PASSWORD = "123456" | 8 | var POSTGRESQL_PASSWORD = "123456" |
@@ -17,25 +13,12 @@ var DISABLE_SQL_GENERATE_PRINT = false | @@ -17,25 +13,12 @@ var DISABLE_SQL_GENERATE_PRINT = false | ||
17 | var DISABLE_SQL_GENERATE_COMMENT = true | 13 | var DISABLE_SQL_GENERATE_COMMENT = true |
18 | 14 | ||
19 | func init() { | 15 | func init() { |
20 | - if os.Getenv("POSTGRESQL_DB_NAME") != "" { | ||
21 | - POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME") | ||
22 | - } | ||
23 | - if os.Getenv("POSTGRESQL_USER") != "" { | ||
24 | - POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER") | ||
25 | - } | ||
26 | - if os.Getenv("POSTGRESQL_PASSWORD") != "" { | ||
27 | - POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD") | ||
28 | - } | ||
29 | - if os.Getenv("POSTGRESQL_HOST") != "" { | ||
30 | - POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST") | ||
31 | - } | ||
32 | - if os.Getenv("POSTGRESQL_PORT") != "" { | ||
33 | - POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT") | ||
34 | - } | ||
35 | - if os.Getenv("DISABLE_CREATE_TABLE") != "" { | ||
36 | - DISABLE_CREATE_TABLE = true | ||
37 | - } | ||
38 | - if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" { | ||
39 | - DISABLE_SQL_GENERATE_PRINT = true | ||
40 | - } | 16 | + POSTGRESQL_HOST = Configurator.DefaultString("POSTGRESQL_HOST", POSTGRESQL_HOST) |
17 | + POSTGRESQL_PORT = Configurator.DefaultString("POSTGRESQL_PORT", POSTGRESQL_PORT) | ||
18 | + POSTGRESQL_DB_NAME = Configurator.DefaultString("POSTGRESQL_DB_NAME", POSTGRESQL_DB_NAME) | ||
19 | + POSTGRESQL_USER = Configurator.DefaultString("POSTGRESQL_USER", POSTGRESQL_USER) | ||
20 | + POSTGRESQL_PASSWORD = Configurator.DefaultString("POSTGRESQL_PASSWORD", POSTGRESQL_PASSWORD) | ||
21 | + | ||
22 | + DISABLE_CREATE_TABLE = Configurator.DefaultBool("DISABLE_CREATE_TABLE", DISABLE_CREATE_TABLE) | ||
23 | + DISABLE_SQL_GENERATE_PRINT = Configurator.DefaultBool("DISABLE_SQL_GENERATE_PRINT", DISABLE_SQL_GENERATE_PRINT) | ||
41 | } | 24 | } |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -import "os" | ||
4 | - | ||
5 | var ( | 3 | var ( |
6 | REDIS_HOST = "127.0.0.1" | 4 | REDIS_HOST = "127.0.0.1" |
7 | REDIS_PORT = "6379" | 5 | REDIS_PORT = "6379" |
8 | REDIS_AUTH = "" | 6 | REDIS_AUTH = "" |
7 | + REDIS_ADDRESS = "" | ||
8 | + | ||
9 | // 是否关闭仓储层缓存 | 9 | // 是否关闭仓储层缓存 |
10 | - DISABLE_REPOSITORY_CACHE = false | 10 | + ENABLE_REPOSITORY_CACHE = true |
11 | // 缓存过期时间 单位秒 | 11 | // 缓存过期时间 单位秒 |
12 | REPOSITORY_CACHE_EXPIRE = 30 * 60 | 12 | REPOSITORY_CACHE_EXPIRE = 30 * 60 |
13 | - | ||
14 | - REDIS_ADDRESS = "" | ||
15 | // redis 考勤机打卡消息队列 | 13 | // redis 考勤机打卡消息队列 |
16 | REDIS_ZKTECO_KEY = "allied-creation-zkteco" | 14 | REDIS_ZKTECO_KEY = "allied-creation-zkteco" |
17 | // redis 车间数据消息队列 | 15 | // redis 车间数据消息队列 |
@@ -19,21 +17,9 @@ var ( | @@ -19,21 +17,9 @@ var ( | ||
19 | ) | 17 | ) |
20 | 18 | ||
21 | func init() { | 19 | func init() { |
22 | - if os.Getenv("REDIS_HOST") != "" { | ||
23 | - REDIS_HOST = os.Getenv("REDIS_HOST") | ||
24 | - REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
25 | - } | ||
26 | - if os.Getenv("REDIS_PORT") != "" { | ||
27 | - REDIS_PORT = os.Getenv("REDIS_PORT") | ||
28 | - } | ||
29 | - if _, ok := os.LookupEnv("REDIS_AUTH"); ok { | ||
30 | - REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
31 | - } | ||
32 | - if os.Getenv("ENABLE_REPOSITORY_CACHE") != "" { | ||
33 | - DISABLE_REPOSITORY_CACHE = false | ||
34 | - } | ||
35 | - if os.Getenv("DISABLE_REPOSITORY_CACHE") != "" { | ||
36 | - DISABLE_REPOSITORY_CACHE = true | ||
37 | - } | 20 | + REDIS_HOST = Configurator.DefaultString("REDIS_HOST", REDIS_HOST) |
21 | + REDIS_PORT = Configurator.DefaultString("REDIS_PORT", REDIS_PORT) | ||
22 | + REDIS_AUTH = Configurator.DefaultString("REDIS_AUTH", REDIS_AUTH) | ||
23 | + ENABLE_REPOSITORY_CACHE = Configurator.DefaultBool("ENABLE_REPOSITORY_CACHE", ENABLE_REPOSITORY_CACHE) | ||
38 | REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT | 24 | REDIS_ADDRESS = REDIS_HOST + ":" + REDIS_PORT |
39 | } | 25 | } |
@@ -224,6 +224,17 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | @@ -224,6 +224,17 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string | ||
224 | on = append(on, s) | 224 | on = append(on, s) |
225 | break | 225 | break |
226 | case 3: | 226 | case 3: |
227 | + if len(s) == 2 && s[1]-s[0] <= 5 { | ||
228 | + last := len(on) - 1 | ||
229 | + if last >= 0 && len(on[last]) == 2 { | ||
230 | + if on[last][1]+1 == s[0] { // [56,79] [80,80] => [56,80] | ||
231 | + on[last][1] = s[1] | ||
232 | + break | ||
233 | + } | ||
234 | + } | ||
235 | + on = append(on, s) | ||
236 | + break | ||
237 | + } | ||
227 | off = append(off, s) | 238 | off = append(off, s) |
228 | break | 239 | break |
229 | } | 240 | } |
@@ -2,7 +2,10 @@ package domain | @@ -2,7 +2,10 @@ package domain | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "errors" | 4 | "errors" |
5 | + "fmt" | ||
6 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
6 | "time" | 9 | "time" |
7 | ) | 10 | ) |
8 | 11 | ||
@@ -44,6 +47,8 @@ type ProductAttendanceRecord struct { | @@ -44,6 +47,8 @@ type ProductAttendanceRecord struct { | ||
44 | DeletedAt time.Time `json:"deletedAt,omitempty"` | 47 | DeletedAt time.Time `json:"deletedAt,omitempty"` |
45 | // 扩展数据 | 48 | // 扩展数据 |
46 | Ext *Ext `json:"ext,omitempty"` | 49 | Ext *Ext `json:"ext,omitempty"` |
50 | + // 生产日期 | ||
51 | + ProductDate time.Time `json:"productDate,omitempty"` | ||
47 | } | 52 | } |
48 | 53 | ||
49 | type ProductAttendanceRecordRepository interface { | 54 | type ProductAttendanceRecordRepository interface { |
@@ -65,7 +70,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i | @@ -65,7 +70,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i | ||
65 | } | 70 | } |
66 | 71 | ||
67 | // 计算审核前工时 | 72 | // 计算审核前工时 |
68 | -func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() float64 { | 73 | +func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(productCalendar *ProductCalendar) float64 { |
69 | if productAttendanceRecord.SignIn.IsZero() { | 74 | if productAttendanceRecord.SignIn.IsZero() { |
70 | return 0 | 75 | return 0 |
71 | } | 76 | } |
@@ -75,7 +80,32 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() | @@ -75,7 +80,32 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() | ||
75 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { | 80 | if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) { |
76 | return 0 | 81 | return 0 |
77 | } | 82 | } |
78 | - return utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 1) | 83 | + wt := utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 1) |
84 | + if productCalendar == nil { | ||
85 | + return wt | ||
86 | + } | ||
87 | + wt = wt - productAttendanceRecord.AttendanceBreakTime(productCalendar) | ||
88 | + if wt < 0 { | ||
89 | + return 0 | ||
90 | + } | ||
91 | + return wt | ||
92 | +} | ||
93 | + | ||
94 | +func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error { | ||
95 | + now := xtime.New(productAttendanceRecord.SignIn) | ||
96 | + productAttendanceRecord.ProductDate = now.BeginningOfDay() | ||
97 | + if productCalendar == nil { | ||
98 | + return nil | ||
99 | + } | ||
100 | + overDay, err := productCalendar.CheckOverDay(productAttendanceRecord.SignIn) | ||
101 | + if err != nil { | ||
102 | + return nil | ||
103 | + } | ||
104 | + newNow := now.BeginningOfDay().Add(-time.Hour * 24) | ||
105 | + if overDay { //&& productCalendar.MatchCalendarSelected(newNow) | ||
106 | + productAttendanceRecord.ProductDate = newNow | ||
107 | + } | ||
108 | + return nil | ||
79 | } | 109 | } |
80 | 110 | ||
81 | func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error { | 111 | func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error { |
@@ -94,3 +124,76 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use | @@ -94,3 +124,76 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use | ||
94 | } | 124 | } |
95 | return nil | 125 | return nil |
96 | } | 126 | } |
127 | + | ||
128 | +func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time { | ||
129 | + attendanceExt := productAttendanceRecord.Ext.AttendanceExt | ||
130 | + if attendanceExt != nil && !xtime.IsZero(productAttendanceRecord.ProductDate) { | ||
131 | + return productAttendanceRecord.ProductDate | ||
132 | + } | ||
133 | + return productAttendanceRecord.SignIn | ||
134 | +} | ||
135 | + | ||
136 | +func (productAttendanceRecord *ProductAttendanceRecord) GroupName() string { | ||
137 | + if productAttendanceRecord.Ext == nil { | ||
138 | + return "" | ||
139 | + } | ||
140 | + if productAttendanceRecord.Ext.AttendanceExt == nil { | ||
141 | + return "" | ||
142 | + } | ||
143 | + return productAttendanceRecord.Ext.AttendanceExt.GroupName | ||
144 | +} | ||
145 | + | ||
146 | +func (productAttendanceRecord *ProductAttendanceRecord) ApproveUser() *User { | ||
147 | + if productAttendanceRecord.Ext == nil { | ||
148 | + return nil | ||
149 | + } | ||
150 | + if productAttendanceRecord.Ext.AttendanceExt == nil { | ||
151 | + return nil | ||
152 | + } | ||
153 | + if productAttendanceRecord.Ext.AttendanceExt.ApproveUserId == 0 { | ||
154 | + return nil | ||
155 | + } | ||
156 | + return &User{ | ||
157 | + UserId: productAttendanceRecord.Ext.AttendanceExt.ApproveUserId, | ||
158 | + UserName: productAttendanceRecord.Ext.AttendanceExt.ApproveUserName, | ||
159 | + } | ||
160 | +} | ||
161 | + | ||
162 | +// 计算考勤休息时间 | ||
163 | +// | ||
164 | +// 考勤打卡时间内有休息时间进行累计 | ||
165 | +func (productAttendanceRecord *ProductAttendanceRecord) AttendanceBreakTime(productCalendar *ProductCalendar) float64 { | ||
166 | + var ( | ||
167 | + signIn = productAttendanceRecord.SignIn | ||
168 | + signOut = productAttendanceRecord.SignOut | ||
169 | + ) | ||
170 | + if signIn.IsZero() { | ||
171 | + return 0 | ||
172 | + } | ||
173 | + if signOut.IsZero() { | ||
174 | + return 0 | ||
175 | + } | ||
176 | + if productCalendar == nil { | ||
177 | + return 0 | ||
178 | + } | ||
179 | + var bt float64 | ||
180 | + for _, v := range productCalendar.BreakTimePeriods { | ||
181 | + var ( | ||
182 | + checkSignIn, checkSignOut time.Time | ||
183 | + ) | ||
184 | + checkSignIn = v.GetCheckBeginTime(signIn.Local()) | ||
185 | + checkSignOut = v.GetCheckEndTime(signIn.Local()) | ||
186 | + if xtime.BeforeEqual(signIn.Local(), checkSignIn) && xtime.AfterEqual(signOut.Local(), checkSignIn) { | ||
187 | + if xtime.AfterEqual(signOut.Local(), checkSignOut) { | ||
188 | + bt += v.BreakTime | ||
189 | + } else { | ||
190 | + bt += utils.Round(signOut.Local().Sub(checkSignIn).Hours(), 2) | ||
191 | + } | ||
192 | + } | ||
193 | + log.Logger.Debug(fmt.Sprintf("range(%v,%v) actual(%v,%v) break_time:%v", checkSignIn, checkSignOut, signIn.Local(), signOut.Local(), bt)) | ||
194 | + } | ||
195 | + if productAttendanceRecord.Ext != nil && productAttendanceRecord.Ext.AttendanceExt != nil { | ||
196 | + productAttendanceRecord.Ext.AttendanceExt.BreakTime = bt | ||
197 | + } | ||
198 | + return bt | ||
199 | +} |
@@ -6,10 +6,14 @@ type ProductAttendanceRecordExt struct { | @@ -6,10 +6,14 @@ type ProductAttendanceRecordExt struct { | ||
6 | ProductGroupId int `json:"productGroupId,omitempty"` | 6 | ProductGroupId int `json:"productGroupId,omitempty"` |
7 | // 班组名称 | 7 | // 班组名称 |
8 | GroupName string `json:"groupName,omitempty"` | 8 | GroupName string `json:"groupName,omitempty"` |
9 | + // 生产日期 | ||
10 | + //ProductTime int64 `json:"productTime,omitempty"` | ||
9 | // 审核人Id | 11 | // 审核人Id |
10 | ApproveUserId int `json:"approveUserId,omitempty"` | 12 | ApproveUserId int `json:"approveUserId,omitempty"` |
11 | // 审核人名称 | 13 | // 审核人名称 |
12 | ApproveUserName string `json:"approveUserName,omitempty"` | 14 | ApproveUserName string `json:"approveUserName,omitempty"` |
13 | // 审核时间 | 15 | // 审核时间 |
14 | ApproveAt int64 `json:"approveAt,omitempty"` | 16 | ApproveAt int64 `json:"approveAt,omitempty"` |
17 | + // 休息时间 | ||
18 | + BreakTime float64 `json:"breakTime"` | ||
15 | } | 19 | } |
pkg/domain/product_attendance_record_test.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
6 | + "github.com/stretchr/testify/assert" | ||
7 | + "testing" | ||
8 | +) | ||
9 | + | ||
10 | +func TestComputeWorkTimeBefore(t *testing.T) { | ||
11 | + var input = []struct { | ||
12 | + name string | ||
13 | + begin string | ||
14 | + end string | ||
15 | + overDay bool | ||
16 | + breakTime float64 | ||
17 | + records []*ProductAttendanceRecord | ||
18 | + }{ | ||
19 | + { | ||
20 | + "normal", | ||
21 | + "11:00", | ||
22 | + "12:00", | ||
23 | + false, | ||
24 | + 1, | ||
25 | + []*ProductAttendanceRecord{ | ||
26 | + { | ||
27 | + SignIn: xtime.MustParse("2022-05-05 09:00:00"), | ||
28 | + SignOut: xtime.MustParse("2022-05-05 13:00:00"), | ||
29 | + WorkTimeBefore: 3, | ||
30 | + }, | ||
31 | + { | ||
32 | + SignIn: xtime.MustParse("2022-05-05 12:00:00"), | ||
33 | + SignOut: xtime.MustParse("2022-05-05 17:00:00"), | ||
34 | + WorkTimeBefore: 5, | ||
35 | + }, | ||
36 | + { | ||
37 | + SignIn: xtime.MustParse("2022-05-05 17:00:00"), | ||
38 | + SignOut: xtime.MustParse("2022-05-06 07:00:00"), | ||
39 | + WorkTimeBefore: 14, | ||
40 | + }, | ||
41 | + }, | ||
42 | + }, | ||
43 | + { | ||
44 | + "over day", | ||
45 | + "23:45", | ||
46 | + "00:45", | ||
47 | + true, | ||
48 | + 1, | ||
49 | + []*ProductAttendanceRecord{ | ||
50 | + { | ||
51 | + SignIn: xtime.MustParse("2022-05-05 09:00:00"), | ||
52 | + SignOut: xtime.MustParse("2022-05-05 12:00:00"), | ||
53 | + WorkTimeBefore: 3, | ||
54 | + }, | ||
55 | + { | ||
56 | + SignIn: xtime.MustParse("2022-05-05 12:00:00"), | ||
57 | + SignOut: xtime.MustParse("2022-05-05 17:00:00"), | ||
58 | + WorkTimeBefore: 5, | ||
59 | + }, | ||
60 | + { | ||
61 | + SignIn: xtime.MustParse("2022-05-05 17:00:00"), | ||
62 | + SignOut: xtime.MustParse("2022-05-06 07:00:00"), | ||
63 | + WorkTimeBefore: 13, | ||
64 | + }, | ||
65 | + }, | ||
66 | + }, | ||
67 | + } | ||
68 | + for _, v := range input { | ||
69 | + p := NewProductCalendarBreakTimePeriod(v.begin, v.end, v.breakTime) | ||
70 | + for _, r := range v.records { | ||
71 | + t.Run(v.name, func(t *testing.T) { | ||
72 | + wt := r.ComputeWorkTimeBefore(&ProductCalendar{ | ||
73 | + BreakTimePeriods: []*ProductCalendarBreakTimePeriod{p}, | ||
74 | + }) | ||
75 | + assert.Equal(t, r.WorkTimeBefore, wt, fmt.Sprintf("except work time %v got :%v", r.WorkTimeBefore, wt)) | ||
76 | + }) | ||
77 | + } | ||
78 | + } | ||
79 | +} |
@@ -2,6 +2,8 @@ package domain | @@ -2,6 +2,8 @@ package domain | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" |
5 | + "strconv" | ||
6 | + "strings" | ||
5 | "time" | 7 | "time" |
6 | ) | 8 | ) |
7 | 9 | ||
@@ -35,6 +37,8 @@ type ProductCalendar struct { | @@ -35,6 +37,8 @@ type ProductCalendar struct { | ||
35 | DeletedAt time.Time `json:"deletedAt,omitempty"` | 37 | DeletedAt time.Time `json:"deletedAt,omitempty"` |
36 | // 扩展数据 | 38 | // 扩展数据 |
37 | Ext *Ext `json:"ext,omitempty"` | 39 | Ext *Ext `json:"ext,omitempty"` |
40 | + // 休息时间周期列表 | ||
41 | + BreakTimePeriods []*ProductCalendarBreakTimePeriod `json:"breakTimePeriods"` | ||
38 | } | 42 | } |
39 | 43 | ||
40 | type ProductCalendarRepository interface { | 44 | type ProductCalendarRepository interface { |
@@ -73,3 +77,66 @@ func (productCalendar *ProductCalendar) ResetWorkTime(v float64) error { | @@ -73,3 +77,66 @@ func (productCalendar *ProductCalendar) ResetWorkTime(v float64) error { | ||
73 | productCalendar.WorkTime = td.Hours() - productCalendar.BreakTime | 77 | productCalendar.WorkTime = td.Hours() - productCalendar.BreakTime |
74 | return nil | 78 | return nil |
75 | } | 79 | } |
80 | + | ||
81 | +func (productCalendar *ProductCalendar) MatchCalendarSelected(t time.Time) bool { | ||
82 | + weekdays := productCalendar.CalendarSelectedToWeekDays() | ||
83 | + for _, v := range weekdays { | ||
84 | + if v == t.Weekday() { | ||
85 | + return true | ||
86 | + } | ||
87 | + } | ||
88 | + return false | ||
89 | +} | ||
90 | + | ||
91 | +func (productCalendar *ProductCalendar) CalendarSelectedToWeekDays() []time.Weekday { | ||
92 | + weekdays := make([]time.Weekday, 0) | ||
93 | + for _, v := range productCalendar.CalendarSelected { | ||
94 | + switch v { | ||
95 | + case "7": //周日 | ||
96 | + weekdays = append(weekdays, time.Sunday) | ||
97 | + break | ||
98 | + case "1": //"周一": | ||
99 | + weekdays = append(weekdays, time.Monday) | ||
100 | + break | ||
101 | + case "2": //"周二": | ||
102 | + weekdays = append(weekdays, time.Tuesday) | ||
103 | + break | ||
104 | + case "3": //"周三": | ||
105 | + weekdays = append(weekdays, time.Wednesday) | ||
106 | + break | ||
107 | + case "4": //"周四": | ||
108 | + weekdays = append(weekdays, time.Thursday) | ||
109 | + break | ||
110 | + case "5": //"周五": | ||
111 | + weekdays = append(weekdays, time.Friday) | ||
112 | + break | ||
113 | + case "6": //"周六": | ||
114 | + weekdays = append(weekdays, time.Saturday) | ||
115 | + break | ||
116 | + } | ||
117 | + } | ||
118 | + return weekdays | ||
119 | +} | ||
120 | + | ||
121 | +// 检查时间是否跨天 | ||
122 | +func (productCalendar *ProductCalendar) CheckOverDay(t time.Time) (bool, error) { | ||
123 | + th := t.Hour() | ||
124 | + inHour, parseInHourErr := strconv.Atoi(strings.Split(productCalendar.InWorkAt, ":")[0]) | ||
125 | + if parseInHourErr != nil { | ||
126 | + return false, parseInHourErr | ||
127 | + } | ||
128 | + outHour, parseOutHourErr := strconv.Atoi(strings.Split(productCalendar.OutWorkAt, ":")[0]) | ||
129 | + if parseOutHourErr != nil { | ||
130 | + return false, parseOutHourErr | ||
131 | + } | ||
132 | + if inHour < outHour { | ||
133 | + return false, nil // eg: 7:00 17:00 t 9:00 | ||
134 | + } | ||
135 | + if th >= inHour && th < 24 { | ||
136 | + return false, nil // eg: 7:00 24:00 t 20:00 | ||
137 | + } | ||
138 | + if th >= 0 && th < outHour { | ||
139 | + return true, nil | ||
140 | + } | ||
141 | + return false, nil | ||
142 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "strconv" | ||
5 | + "strings" | ||
6 | + "time" | ||
7 | +) | ||
8 | + | ||
9 | +type ProductCalendarBreakTimePeriod struct { | ||
10 | + // 开始时间 eg: 11:00 | ||
11 | + BeginAt string `json:"beginAt,omitempty"` | ||
12 | + // 结束时间 eg: 11:30 | ||
13 | + EndAt string `json:"endAt,omitempty"` | ||
14 | + // 休息时间 (单位 h) eg:0.5 | ||
15 | + BreakTime float64 `json:"breakTime,omitempty"` | ||
16 | + // 备注 eg:午饭 | ||
17 | + Remark string `json:"remark,omitempty"` | ||
18 | +} | ||
19 | + | ||
20 | +func (period *ProductCalendarBreakTimePeriod) CheckOverDay() (bool, error) { | ||
21 | + inHour, parseInHourErr := strconv.Atoi(strings.Split(period.BeginAt, ":")[0]) | ||
22 | + if parseInHourErr != nil { | ||
23 | + return false, parseInHourErr | ||
24 | + } | ||
25 | + outHour, parseOutHourErr := strconv.Atoi(strings.Split(period.EndAt, ":")[0]) | ||
26 | + if parseOutHourErr != nil { | ||
27 | + return false, parseOutHourErr | ||
28 | + } | ||
29 | + if inHour <= outHour { | ||
30 | + return false, nil // eg: 7:00 17:00 t 9:00 | ||
31 | + } | ||
32 | + return true, nil | ||
33 | +} | ||
34 | + | ||
35 | +func (period *ProductCalendarBreakTimePeriod) GetCheckBeginTime(t time.Time) time.Time { | ||
36 | + y, m, d := t.Date() | ||
37 | + inHour, _ := strconv.ParseInt(strings.Split(period.BeginAt, ":")[0], 10, 64) | ||
38 | + inMinuter, _ := strconv.ParseInt(strings.Split(period.BeginAt, ":")[1], 10, 64) | ||
39 | + return time.Date(y, m, d, int(inHour), int(inMinuter), 0, 0, time.Local) | ||
40 | +} | ||
41 | + | ||
42 | +func (period *ProductCalendarBreakTimePeriod) GetCheckEndTime(t time.Time) time.Time { | ||
43 | + y, m, d := t.Date() | ||
44 | + inHour, _ := strconv.ParseInt(strings.Split(period.EndAt, ":")[0], 10, 64) | ||
45 | + inMinuter, _ := strconv.ParseInt(strings.Split(period.EndAt, ":")[1], 10, 64) | ||
46 | + checkTime := time.Date(y, m, d, int(inHour), int(inMinuter), 0, 0, time.Local) | ||
47 | + if overDay, err := period.CheckOverDay(); overDay && err == nil { | ||
48 | + return checkTime.AddDate(0, 0, 1) | ||
49 | + } | ||
50 | + return checkTime | ||
51 | +} | ||
52 | + | ||
53 | +func NewProductCalendarBreakTimePeriod(begin, end string, breakTime float64) *ProductCalendarBreakTimePeriod { | ||
54 | + return &ProductCalendarBreakTimePeriod{ | ||
55 | + BeginAt: begin, | ||
56 | + EndAt: end, | ||
57 | + BreakTime: breakTime, | ||
58 | + } | ||
59 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/stretchr/testify/assert" | ||
6 | + "testing" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +func TestCheckOverDay(t *testing.T) { | ||
11 | + var input = []struct { | ||
12 | + name string | ||
13 | + begin string | ||
14 | + end string | ||
15 | + overDay bool | ||
16 | + }{ | ||
17 | + { | ||
18 | + "normal", | ||
19 | + "11:00", | ||
20 | + "12:00", | ||
21 | + false, | ||
22 | + }, | ||
23 | + { | ||
24 | + "over day", | ||
25 | + "23:45", | ||
26 | + "00:45", | ||
27 | + true, | ||
28 | + }, | ||
29 | + } | ||
30 | + for _, v := range input { | ||
31 | + p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0) | ||
32 | + t.Run(v.name, func(t *testing.T) { | ||
33 | + ok, err := p.CheckOverDay() | ||
34 | + assert.Equal(t, v.overDay, ok) | ||
35 | + assert.Nil(t, err) | ||
36 | + }) | ||
37 | + } | ||
38 | +} | ||
39 | + | ||
40 | +func TestGetCheckTime(t *testing.T) { | ||
41 | + var input = []struct { | ||
42 | + name string | ||
43 | + begin string | ||
44 | + end string | ||
45 | + overDay bool | ||
46 | + in time.Time | ||
47 | + }{ | ||
48 | + { | ||
49 | + "normal", | ||
50 | + "11:00", | ||
51 | + "12:00", | ||
52 | + false, | ||
53 | + time.Date(2022, 5, 5, 9, 0, 0, 0, time.Local), | ||
54 | + }, | ||
55 | + { | ||
56 | + "over day", | ||
57 | + "23:45", | ||
58 | + "00:45", | ||
59 | + true, | ||
60 | + time.Date(2022, 5, 5, 23, 0, 0, 0, time.Local), | ||
61 | + }, | ||
62 | + } | ||
63 | + for _, v := range input { | ||
64 | + p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0) | ||
65 | + t.Run(v.name, func(t *testing.T) { | ||
66 | + begin := p.GetCheckBeginTime(time.Now()) | ||
67 | + end := p.GetCheckEndTime(time.Now()) | ||
68 | + overDay := begin.Day() != end.Day() | ||
69 | + assert.Equal(t, v.overDay, overDay, fmt.Sprintf("begin:%v end:%v", begin, end)) | ||
70 | + }) | ||
71 | + } | ||
72 | +} |
@@ -123,3 +123,35 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker | @@ -123,3 +123,35 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker | ||
123 | return int64(count), productAttendanceRecords, nil | 123 | return int64(count), productAttendanceRecords, nil |
124 | } | 124 | } |
125 | } | 125 | } |
126 | + | ||
127 | +func (dao *AttendanceRecordDao) WorkerAttendanceRecordsByProductDate(companyId, orgId, workerId int, productDate, beginTime, endTime time.Time) (int64, []*domain.ProductAttendanceRecord, error) { | ||
128 | + tx := dao.transactionContext.PgTx | ||
129 | + //endTime := time.Now() | ||
130 | + //beginTime := endTime.Add(-(time.Hour * time.Duration(recentDay*24))) | ||
131 | + var productAttendanceRecordModels []*models.ProductAttendanceRecord | ||
132 | + productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0) | ||
133 | + query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), map[string]interface{}{}) | ||
134 | + query.Where("company_id =?", companyId) | ||
135 | + query.Where("org_id =?", orgId) | ||
136 | + query.Where("product_worker ->>'userId' = '?'", workerId) | ||
137 | + query.Where("product_date = ?", productDate) | ||
138 | + query.Where("sign_in >= ?", beginTime) | ||
139 | + query.WhereGroup(func(query *orm.Query) (*orm.Query, error) { | ||
140 | + query.Where("sign_out is null") | ||
141 | + query.WhereOr("sign_out>?", endTime) | ||
142 | + return query, nil | ||
143 | + }) | ||
144 | + query.SetOrderDirect("product_attendance_id", "DESC") | ||
145 | + if count, err := query.SelectAndCount(); err != nil { | ||
146 | + return 0, productAttendanceRecords, err | ||
147 | + } else { | ||
148 | + for _, productAttendanceRecordModel := range productAttendanceRecordModels { | ||
149 | + if productAttendanceRecord, err := transform.TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendanceRecordModel); err != nil { | ||
150 | + return 0, productAttendanceRecords, err | ||
151 | + } else { | ||
152 | + productAttendanceRecords = append(productAttendanceRecords, productAttendanceRecord) | ||
153 | + } | ||
154 | + } | ||
155 | + return int64(count), productAttendanceRecords, nil | ||
156 | + } | ||
157 | +} |
@@ -21,7 +21,7 @@ func NewDeviceDailyRunningRecordDao(transactionContext *pgTransaction.Transactio | @@ -21,7 +21,7 @@ func NewDeviceDailyRunningRecordDao(transactionContext *pgTransaction.Transactio | ||
21 | } | 21 | } |
22 | 22 | ||
23 | // 时段产能 | 23 | // 时段产能 |
24 | -func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, result interface{}) error { | 24 | +func (dao *DeviceDailyRunningRecordDao) TimeSectionRunningRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, endTime time.Time, result interface{}) error { |
25 | 25 | ||
26 | tx := dao.transactionContext.PgTx | 26 | tx := dao.transactionContext.PgTx |
27 | sql := fmt.Sprintf(` | 27 | sql := fmt.Sprintf(` |
@@ -39,6 +39,7 @@ WITH ts_product as( | @@ -39,6 +39,7 @@ WITH ts_product as( | ||
39 | and work_station->>'lineId'='?' | 39 | and work_station->>'lineId'='?' |
40 | and work_station->>'sectionName'=? | 40 | and work_station->>'sectionName'=? |
41 | and created_at >? | 41 | and created_at >? |
42 | + and created_at <? | ||
42 | ) a | 43 | ) a |
43 | group by a.ts | 44 | group by a.ts |
44 | order by ts | 45 | order by ts |
@@ -47,20 +48,20 @@ WITH ts_product as( | @@ -47,20 +48,20 @@ WITH ts_product as( | ||
47 | , ts_product_list as ( | 48 | , ts_product_list as ( |
48 | select d.ts,ts_product.total from ( | 49 | select d.ts,ts_product.total from ( |
49 | select to_char(c.ts::timestamp,'mm-dd') ts from ( | 50 | select to_char(c.ts::timestamp,'mm-dd') ts from ( |
50 | - select generate_series(now() - interval '6 day',now(),'1 day') ts | 51 | + select generate_series(to_timestamp(?),to_timestamp(?),'1 day') ts |
51 | ) c ) d left join ts_product on d.ts = ts_product.ts | 52 | ) c ) d left join ts_product on d.ts = ts_product.ts |
52 | ) | 53 | ) |
53 | SELECT ts, coalesce(total,0) total | 54 | SELECT ts, coalesce(total,0) total |
54 | from ts_product_list | 55 | from ts_product_list |
55 | `) | 56 | `) |
56 | - if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime); err != nil { | 57 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime, endTime, beginTime.Unix(), endTime.Unix()); err != nil { |
57 | return err | 58 | return err |
58 | } | 59 | } |
59 | return nil | 60 | return nil |
60 | } | 61 | } |
61 | 62 | ||
62 | // 车间性能 | 63 | // 车间性能 |
63 | -func (dao *DeviceDailyRunningRecordDao) WorkshopProductionEfficiencyStatistics(companyId, orgId, workshopId int, beginTime time.Time, result interface{}) error { | 64 | +func (dao *DeviceDailyRunningRecordDao) WorkshopProductionEfficiencyStatistics(companyId, orgId, workshopId int, beginTime time.Time, endTime time.Time, result interface{}) error { |
64 | 65 | ||
65 | tx := dao.transactionContext.PgTx | 66 | tx := dao.transactionContext.PgTx |
66 | sql := fmt.Sprintf(` | 67 | sql := fmt.Sprintf(` |
@@ -76,10 +77,11 @@ company_id = ? | @@ -76,10 +77,11 @@ company_id = ? | ||
76 | and org_id = ? | 77 | and org_id = ? |
77 | and work_station->>'workshopId'='?' | 78 | and work_station->>'workshopId'='?' |
78 | and created_at>=? | 79 | and created_at>=? |
80 | +and created_at<? | ||
79 | ) | 81 | ) |
80 | select round(avg(oee),1) oee,round(avg(tu),1) tu,round(avg(pu),1)pu, round(avg(qu),1) qu from device_running | 82 | select round(avg(oee),1) oee,round(avg(tu),1) tu,round(avg(pu),1)pu, round(avg(qu),1) qu from device_running |
81 | `) | 83 | `) |
82 | - if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime); err != nil { | 84 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime, endTime); err != nil { |
83 | return err | 85 | return err |
84 | } | 86 | } |
85 | return nil | 87 | return nil |
@@ -100,7 +100,7 @@ from ts_product_list | @@ -100,7 +100,7 @@ from ts_product_list | ||
100 | } | 100 | } |
101 | 101 | ||
102 | // 二级品比重 | 102 | // 二级品比重 |
103 | -func (dao *ProductRecordDao) ProportionOfSecondLevelRecord(companyId, orgId, workshopId int, beginTime time.Time, result interface{}) error { | 103 | +func (dao *ProductRecordDao) ProportionOfSecondLevelRecord(companyId, orgId, workshopId int, beginTime time.Time, endTime time.Time, result interface{}) error { |
104 | 104 | ||
105 | tx := dao.transactionContext.PgTx | 105 | tx := dao.transactionContext.PgTx |
106 | sql := fmt.Sprintf(` | 106 | sql := fmt.Sprintf(` |
@@ -116,6 +116,7 @@ select sum(a.weight) item_total,max(sname) sname from ( | @@ -116,6 +116,7 @@ select sum(a.weight) item_total,max(sname) sname from ( | ||
116 | and product_record_type = 8 | 116 | and product_record_type = 8 |
117 | and product_record_info->>'approveStatus'='2' | 117 | and product_record_info->>'approveStatus'='2' |
118 | and created_at >=? | 118 | and created_at >=? |
119 | + and created_at <? | ||
119 | and work_station->>'sectionName' in ('打料','成型','穿串','包装') | 120 | and work_station->>'sectionName' in ('打料','成型','穿串','包装') |
120 | ) a | 121 | ) a |
121 | group by a.workStationId | 122 | group by a.workStationId |
@@ -128,7 +129,7 @@ select sname,round(item_total/(select sum(item_total) from item_product)*100, 0) | @@ -128,7 +129,7 @@ select sname,round(item_total/(select sum(item_total) from item_product)*100, 0) | ||
128 | select a.sname, coalesce(b.rate,0) rate from ( | 129 | select a.sname, coalesce(b.rate,0) rate from ( |
129 | select unnest(ARRAY ['打料','成型','穿串','包装']) sname | 130 | select unnest(ARRAY ['打料','成型','穿串','包装']) sname |
130 | ) a left join item_product_rate b on a.sname=b.sname`) | 131 | ) a left join item_product_rate b on a.sname=b.sname`) |
131 | - if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime); err != nil { | 132 | + if _, err := tx.Query(result, sql, companyId, orgId, workshopId, beginTime, endTime); err != nil { |
132 | return err | 133 | return err |
133 | } | 134 | } |
134 | return nil | 135 | return nil |
@@ -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 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao" |
@@ -125,6 +126,7 @@ type HourProductiveStatisticsRequest struct { | @@ -125,6 +126,7 @@ type HourProductiveStatisticsRequest struct { | ||
125 | CompanyId int `json:"companyId" valid:"Required"` | 126 | CompanyId int `json:"companyId" valid:"Required"` |
126 | OrgId int `json:"orgId" valid:"Required"` | 127 | OrgId int `json:"orgId" valid:"Required"` |
127 | WorkshopId int `json:"workshopId" valid:"Required"` | 128 | WorkshopId int `json:"workshopId" valid:"Required"` |
129 | + Date time.Time `json:"date"` | ||
128 | } | 130 | } |
129 | 131 | ||
130 | func NewXYData(xData []string, values interface{}) interface{} { | 132 | func NewXYData(xData []string, values interface{}) interface{} { |
@@ -151,7 +153,10 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | @@ -151,7 +153,10 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | ||
151 | Ts string `json:"ts"` | 153 | Ts string `json:"ts"` |
152 | Total float64 `json:"total"` | 154 | Total float64 `json:"total"` |
153 | } | 155 | } |
154 | - | 156 | + var date = time.Now() |
157 | + if !xtime.IsZero(request.Date) { | ||
158 | + date = request.Date | ||
159 | + } | ||
155 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) | 160 | workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId}) |
156 | if err != nil || workshop == nil { | 161 | if err != nil || workshop == nil { |
157 | return nil, nil | 162 | return nil, nil |
@@ -163,7 +168,7 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | @@ -163,7 +168,7 @@ func (ptr *PGCommonStatisticsService) DailyProductiveStatistics(queryOptions map | ||
163 | 168 | ||
164 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { | 169 | for _, v := range workshop.GetProductLines(domain.NotDeleted) { |
165 | var result = make([]*record, 0) | 170 | var result = make([]*record, 0) |
166 | - if err := productRecordDao.TimeSectionRunningRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, time.Now().Add(-time.Hour*24*7), &result); err != nil { | 171 | + if err := productRecordDao.TimeSectionRunningRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.LineId, SectionNameCCJ, date.Add(-time.Hour*24*7), date, &result); err != nil { |
167 | log.Logger.Error(err.Error()) | 172 | log.Logger.Error(err.Error()) |
168 | continue | 173 | continue |
169 | } | 174 | } |
@@ -207,20 +212,24 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt | @@ -207,20 +212,24 @@ func (ptr *PGCommonStatisticsService) ProportionOfSecondLevelStatistics(queryOpt | ||
207 | return nil, nil | 212 | return nil, nil |
208 | } | 213 | } |
209 | productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) | 214 | productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext) |
210 | - | 215 | + var date = time.Now() |
216 | + if !xtime.IsZero(request.Date) { | ||
217 | + date = request.Date | ||
218 | + } | ||
211 | var input = []struct { | 219 | var input = []struct { |
212 | name string | 220 | name string |
213 | - t time.Time | 221 | + begin time.Time |
222 | + end time.Time | ||
214 | }{ | 223 | }{ |
215 | - {"today", utils.GetZeroTime(time.Now())}, | ||
216 | - {"current_week", utils.GetCurrentWeekFirstDay(time.Now())}, | ||
217 | - {"current_month", utils.GetCurrentMonthFirstDay(time.Now())}, | 224 | + {"today", utils.GetZeroTime(date), utils.GetZeroTime(date.AddDate(0, 0, 1))}, |
225 | + {"current_week", utils.GetCurrentWeekFirstDay(date), utils.GetCurrentWeekFirstDay(date.AddDate(0, 0, 7))}, | ||
226 | + {"current_month", utils.GetCurrentMonthFirstDay(date), utils.GetCurrentMonthFirstDay(date.AddDate(0, 1, 0))}, | ||
218 | } | 227 | } |
219 | 228 | ||
220 | var response = make(map[string]interface{}) | 229 | var response = make(map[string]interface{}) |
221 | for _, v := range input { | 230 | for _, v := range input { |
222 | var result = make([]*record, 0) | 231 | var result = make([]*record, 0) |
223 | - if err := productRecordDao.ProportionOfSecondLevelRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.t, &result); err != nil { | 232 | + if err := productRecordDao.ProportionOfSecondLevelRecord(request.CompanyId, request.OrgId, request.WorkshopId, v.begin, v.end, &result); err != nil { |
224 | log.Logger.Error(err.Error()) | 233 | log.Logger.Error(err.Error()) |
225 | return nil, err | 234 | return nil, err |
226 | } | 235 | } |
@@ -252,20 +261,24 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | @@ -252,20 +261,24 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que | ||
252 | return nil, nil | 261 | return nil, nil |
253 | } | 262 | } |
254 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) | 263 | productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext) |
255 | - | 264 | + var date = time.Now() |
265 | + if !xtime.IsZero(request.Date) { | ||
266 | + date = request.Date | ||
267 | + } | ||
256 | var input = []struct { | 268 | var input = []struct { |
257 | name string | 269 | name string |
258 | - t time.Time | 270 | + begin time.Time |
271 | + end time.Time | ||
259 | }{ | 272 | }{ |
260 | - {"today", utils.GetZeroTime(time.Now())}, | ||
261 | - {"current_week", utils.GetCurrentWeekFirstDay(time.Now())}, | ||
262 | - {"current_month", utils.GetCurrentMonthFirstDay(time.Now())}, | 273 | + {"today", utils.GetZeroTime(date), utils.GetZeroTime(date.AddDate(0, 0, 1))}, |
274 | + {"current_week", utils.GetCurrentWeekFirstDay(date), utils.GetCurrentWeekFirstDay(date.AddDate(0, 0, 7))}, | ||
275 | + {"current_month", utils.GetCurrentMonthFirstDay(date), utils.GetCurrentMonthFirstDay(date.AddDate(0, 1, 0))}, | ||
263 | } | 276 | } |
264 | 277 | ||
265 | var response = make(map[string]interface{}) | 278 | var response = make(map[string]interface{}) |
266 | for _, v := range input { | 279 | for _, v := range input { |
267 | var result = record{} | 280 | var result = record{} |
268 | - if err := productRecordDao.WorkshopProductionEfficiencyStatistics(request.CompanyId, request.OrgId, request.WorkshopId, v.t, &result); err != nil { | 281 | + if err := productRecordDao.WorkshopProductionEfficiencyStatistics(request.CompanyId, request.OrgId, request.WorkshopId, v.begin, v.end, &result); err != nil { |
269 | log.Logger.Error(err.Error()) | 282 | log.Logger.Error(err.Error()) |
270 | return nil, err | 283 | return nil, err |
271 | } | 284 | } |
@@ -168,6 +168,23 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | @@ -168,6 +168,23 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp | ||
168 | return result, keyFunc | 168 | return result, keyFunc |
169 | } | 169 | } |
170 | 170 | ||
171 | +// 查询组成员属于的分组 | ||
172 | +func FindMemberBelongToProductGroup(productGroupRepository domain.ProductGroupRepository, companyId, orgId int, workStationId string, member *domain.User) (*domain.ProductGroup, error) { | ||
173 | + _, groups, err := productGroupRepository.Find(map[string]interface{}{"companyId": companyId, "orgId": orgId, "workStationId": workStationId}) | ||
174 | + if err != nil { | ||
175 | + return nil, err | ||
176 | + } | ||
177 | + for i := range groups { | ||
178 | + for j := range groups[i].GroupMembers { | ||
179 | + u := groups[i].GroupMembers[j] | ||
180 | + if u.UserId == member.UserId { | ||
181 | + return groups[i], nil | ||
182 | + } | ||
183 | + } | ||
184 | + } | ||
185 | + return nil, nil | ||
186 | +} | ||
187 | + | ||
171 | // 个人生产记录统计 | 188 | // 个人生产记录统计 |
172 | func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.ProductPlan, productRecord *domain.ProductRecord) (interface{}, error) { | 189 | func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.ProductPlan, productRecord *domain.ProductRecord) (interface{}, error) { |
173 | var ( | 190 | var ( |
@@ -21,9 +21,10 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -21,9 +21,10 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
21 | var ( | 21 | var ( |
22 | attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext) | 22 | attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext) |
23 | attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext) | 23 | attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext) |
24 | + productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | ||
25 | + productCalendarRepository, _ = repository.NewProductCalendarRepository(ptr.transactionContext) | ||
24 | isSignIn = true | 26 | isSignIn = true |
25 | record *domain.ProductAttendanceRecord | 27 | record *domain.ProductAttendanceRecord |
26 | - //workStationId string //具体工位 | ||
27 | workStation *domain.WorkStation | 28 | workStation *domain.WorkStation |
28 | attendanceType int = domain.ParticipateSupport | 29 | attendanceType int = domain.ParticipateSupport |
29 | worker *domain.User | 30 | worker *domain.User |
@@ -37,7 +38,6 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -37,7 +38,6 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
37 | var ( | 38 | var ( |
38 | device *domain.Device | 39 | device *domain.Device |
39 | err error | 40 | err error |
40 | - productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext) | ||
41 | groupId = 0 | 41 | groupId = 0 |
42 | groupName = "" | 42 | groupName = "" |
43 | ) | 43 | ) |
@@ -58,15 +58,17 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -58,15 +58,17 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
58 | return nil, err | 58 | return nil, err |
59 | } | 59 | } |
60 | 60 | ||
61 | - groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, workStation.WorkStationId) | ||
62 | - if v, ok := groupMembers[groupMembersKeyFunc(worker.UserId)]; ok { | 61 | + var productCalendar *domain.ProductCalendar |
62 | + productGroup, _ := FindMemberBelongToProductGroup(productGroupRepository, cid, oid, workStation.WorkStationId, worker) | ||
63 | + if productGroup != nil { | ||
63 | attendanceType = domain.ParticipateNormal | 64 | attendanceType = domain.ParticipateNormal |
64 | - groupId = v.GroupId | ||
65 | - groupName = v.GroupName | 65 | + groupId = productGroup.ProductGroupId |
66 | + groupName = productGroup.GroupName | ||
67 | + productCalendar, _ = productCalendarRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "workStationId": workStation.WorkStationId}) | ||
66 | } | 68 | } |
67 | 69 | ||
68 | - beginTime := utils.GetZeroTime(report.ActionTime) | ||
69 | - endTime := time.Now() | 70 | + beginTime := report.ActionTime.Add(-time.Hour * 13) |
71 | + endTime := report.ActionTime | ||
70 | _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime) | 72 | _, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime) |
71 | for i := 0; i < len(records); i++ { | 73 | for i := 0; i < len(records); i++ { |
72 | r := records[i] | 74 | r := records[i] |
@@ -76,7 +78,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -76,7 +78,7 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
76 | if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) { | 78 | if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) { |
77 | if utils.TimeAfterEqual(report.ActionTime, r.SignIn) { | 79 | if utils.TimeAfterEqual(report.ActionTime, r.SignIn) { |
78 | r.SignOut = report.ActionTime | 80 | r.SignOut = report.ActionTime |
79 | - r.WorkTimeBefore = r.ComputeWorkTimeBefore() | 81 | + r.WorkTimeBefore = r.ComputeWorkTimeBefore(productCalendar) |
80 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 在其他工段打卡 下线当前工段:%v 签退 %v", worker.UserName, worker.UserId, r.WorkStation.SectionName, report)) | 82 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 在其他工段打卡 下线当前工段:%v 签退 %v", worker.UserName, worker.UserId, r.WorkStation.SectionName, report)) |
81 | if _, err = attendanceRecordRepository.Save(r); err != nil { | 83 | if _, err = attendanceRecordRepository.Save(r); err != nil { |
82 | return nil, err | 84 | return nil, err |
@@ -148,10 +150,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | @@ -148,10 +150,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain. | ||
148 | ProductGroupId: groupId, | 150 | ProductGroupId: groupId, |
149 | }), | 151 | }), |
150 | } | 152 | } |
153 | + record.SetProductTimeByProductCalendar(productCalendar) | ||
151 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report)) | 154 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report)) |
152 | } else { | 155 | } else { |
153 | record.SignOut = report.ActionTime | 156 | record.SignOut = report.ActionTime |
154 | - record.WorkTimeBefore = record.ComputeWorkTimeBefore() | 157 | + record.WorkTimeBefore = record.ComputeWorkTimeBefore(productCalendar) |
155 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report)) | 158 | log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report)) |
156 | } | 159 | } |
157 | 160 |
@@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" |
9 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
10 | "time" | 9 | "time" |
11 | ) | 10 | ) |
12 | 11 | ||
@@ -21,7 +20,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord | @@ -21,7 +20,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord | ||
21 | "companyId": productRecord.CompanyId, | 20 | "companyId": productRecord.CompanyId, |
22 | "orgId": productRecord.OrgId, | 21 | "orgId": productRecord.OrgId, |
23 | "workStationId": productRecord.WorkStation.WorkStationId, | 22 | "workStationId": productRecord.WorkStation.WorkStationId, |
24 | - "recordDate": utils.GetZeroTime(productRecord.SignIn), | 23 | + "recordDate": productRecord.ProductDate, |
25 | }) | 24 | }) |
26 | if err != nil && errors.Is(err, domain.ErrorNotFound) { | 25 | if err != nil && errors.Is(err, domain.ErrorNotFound) { |
27 | err = nil | 26 | err = nil |
@@ -31,7 +30,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord | @@ -31,7 +30,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord | ||
31 | CompanyId: productRecord.CompanyId, | 30 | CompanyId: productRecord.CompanyId, |
32 | OrgId: productRecord.OrgId, | 31 | OrgId: productRecord.OrgId, |
33 | Ext: productRecord.Ext, | 32 | Ext: productRecord.Ext, |
34 | - RecordDate: utils.GetZeroTime(productRecord.SignIn), | 33 | + RecordDate: productRecord.ProductDate, // utils.GetZeroTime(productRecord.SignIn), |
35 | WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{}, | 34 | WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{}, |
36 | } | 35 | } |
37 | } | 36 | } |
@@ -37,4 +37,6 @@ type ProductAttendanceRecord struct { | @@ -37,4 +37,6 @@ type ProductAttendanceRecord struct { | ||
37 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | 37 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
38 | // 扩展数据 | 38 | // 扩展数据 |
39 | Ext *domain.Ext `comment:"扩展数据"` | 39 | Ext *domain.Ext `comment:"扩展数据"` |
40 | + // 生产日期 | ||
41 | + ProductDate time.Time `comment:"生产日期"` | ||
40 | } | 42 | } |
@@ -35,4 +35,6 @@ type ProductCalendar struct { | @@ -35,4 +35,6 @@ type ProductCalendar struct { | ||
35 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` | 35 | DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` |
36 | // 扩展数据 | 36 | // 扩展数据 |
37 | Ext *domain.Ext `comment:"扩展数据"` | 37 | Ext *domain.Ext `comment:"扩展数据"` |
38 | + // 休息时间周期列表 | ||
39 | + BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `comment:"休息时间周期列表"` | ||
38 | } | 40 | } |
@@ -22,5 +22,6 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance | @@ -22,5 +22,6 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance | ||
22 | UpdatedAt: productAttendanceRecordModel.UpdatedAt, | 22 | UpdatedAt: productAttendanceRecordModel.UpdatedAt, |
23 | DeletedAt: productAttendanceRecordModel.DeletedAt, | 23 | DeletedAt: productAttendanceRecordModel.DeletedAt, |
24 | Ext: productAttendanceRecordModel.Ext, | 24 | Ext: productAttendanceRecordModel.Ext, |
25 | + ProductDate: productAttendanceRecordModel.ProductDate, | ||
25 | }, nil | 26 | }, nil |
26 | } | 27 | } |
@@ -21,5 +21,6 @@ func TransformToProductCalendarDomainModelFromPgModels(productCalendarModel *mod | @@ -21,5 +21,6 @@ func TransformToProductCalendarDomainModelFromPgModels(productCalendarModel *mod | ||
21 | UpdatedAt: productCalendarModel.UpdatedAt, | 21 | UpdatedAt: productCalendarModel.UpdatedAt, |
22 | DeletedAt: productCalendarModel.DeletedAt, | 22 | DeletedAt: productCalendarModel.DeletedAt, |
23 | Ext: productCalendarModel.Ext, | 23 | Ext: productCalendarModel.Ext, |
24 | + BreakTimePeriods: productCalendarModel.BreakTimePeriods, | ||
24 | }, nil | 25 | }, nil |
25 | } | 26 | } |
@@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
6 | "github.com/go-redis/redis" | 6 | "github.com/go-redis/redis" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
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/log" | ||
10 | "time" | 9 | "time" |
11 | ) | 10 | ) |
12 | 11 | ||
@@ -15,7 +14,7 @@ func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.Device | @@ -15,7 +14,7 @@ func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.Device | ||
15 | client := GetRedis() | 14 | client := GetRedis() |
16 | key := DeviceDailyRunningRecordKey(t, deviceCode) | 15 | key := DeviceDailyRunningRecordKey(t, deviceCode) |
17 | record, err := getDeviceDailyRunningRecord(client, key) | 16 | record, err := getDeviceDailyRunningRecord(client, key) |
18 | - log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v Value:%v", deviceCode, key, record)) | 17 | + //log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v Value:%v", deviceCode, key, record)) |
19 | return record, err | 18 | return record, err |
20 | } | 19 | } |
21 | 20 | ||
@@ -50,7 +49,7 @@ func SaveDeviceDailyRunningRecordByKey(key string, record *domain.DeviceDailyRun | @@ -50,7 +49,7 @@ func SaveDeviceDailyRunningRecordByKey(key string, record *domain.DeviceDailyRun | ||
50 | if err != nil { | 49 | if err != nil { |
51 | return err | 50 | return err |
52 | } | 51 | } |
53 | - log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Value:%v", record.DeviceCode, key, record)) | 52 | + //log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Value:%v", record.DeviceCode, key, record)) |
54 | result := client.Set(key, recordData, time.Hour*24*5) | 53 | result := client.Set(key, recordData, time.Hour*24*5) |
55 | _, err = result.Result() | 54 | _, err = result.Result() |
56 | return err | 55 | return err |
@@ -42,6 +42,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | @@ -42,6 +42,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | ||
42 | "updated_at", | 42 | "updated_at", |
43 | "deleted_at", | 43 | "deleted_at", |
44 | "ext", | 44 | "ext", |
45 | + "product_date", | ||
45 | } | 46 | } |
46 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) | 47 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) |
47 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) | 48 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) |
@@ -67,6 +68,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | @@ -67,6 +68,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | ||
67 | &productAttendanceRecord.UpdatedAt, | 68 | &productAttendanceRecord.UpdatedAt, |
68 | &productAttendanceRecord.DeletedAt, | 69 | &productAttendanceRecord.DeletedAt, |
69 | &productAttendanceRecord.Ext, | 70 | &productAttendanceRecord.Ext, |
71 | + &productAttendanceRecord.ProductDate, | ||
70 | ), | 72 | ), |
71 | fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 73 | fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
72 | //productAttendanceRecord.ProductAttendanceId, | 74 | //productAttendanceRecord.ProductAttendanceId, |
@@ -84,6 +86,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | @@ -84,6 +86,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | ||
84 | productAttendanceRecord.UpdatedAt, | 86 | productAttendanceRecord.UpdatedAt, |
85 | //productAttendanceRecord.DeletedAt, | 87 | //productAttendanceRecord.DeletedAt, |
86 | productAttendanceRecord.Ext, | 88 | productAttendanceRecord.Ext, |
89 | + productAttendanceRecord.ProductDate, | ||
87 | ); err != nil { | 90 | ); err != nil { |
88 | return productAttendanceRecord, err | 91 | return productAttendanceRecord, err |
89 | } | 92 | } |
@@ -105,6 +108,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | @@ -105,6 +108,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | ||
105 | &productAttendanceRecord.UpdatedAt, | 108 | &productAttendanceRecord.UpdatedAt, |
106 | &productAttendanceRecord.DeletedAt, | 109 | &productAttendanceRecord.DeletedAt, |
107 | &productAttendanceRecord.Ext, | 110 | &productAttendanceRecord.Ext, |
111 | + &productAttendanceRecord.ProductDate, | ||
108 | ), | 112 | ), |
109 | fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 113 | fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
110 | //productAttendanceRecord.ProductAttendanceId, | 114 | //productAttendanceRecord.ProductAttendanceId, |
@@ -122,6 +126,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | @@ -122,6 +126,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor | ||
122 | productAttendanceRecord.UpdatedAt, | 126 | productAttendanceRecord.UpdatedAt, |
123 | //productAttendanceRecord.DeletedAt, | 127 | //productAttendanceRecord.DeletedAt, |
124 | productAttendanceRecord.Ext, | 128 | productAttendanceRecord.Ext, |
129 | + productAttendanceRecord.ProductDate, | ||
125 | productAttendanceRecord.Identify(), | 130 | productAttendanceRecord.Identify(), |
126 | ); err != nil { | 131 | ); err != nil { |
127 | return productAttendanceRecord, err | 132 | return productAttendanceRecord, err |
@@ -189,10 +194,10 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin | @@ -189,10 +194,10 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin | ||
189 | query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v)) | 194 | query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v)) |
190 | } | 195 | } |
191 | if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) { | 196 | if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) { |
192 | - query.Where("created_at>=?", v.(time.Time)) | 197 | + query.Where("product_date>=?", v.(time.Time)) |
193 | } | 198 | } |
194 | if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) { | 199 | if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) { |
195 | - query.Where("created_at<?", v.(time.Time)) | 200 | + query.Where("product_date<?", v.(time.Time)) |
196 | } | 201 | } |
197 | if v, ok := queryOptions["employeeType"]; ok && (v.(int)) > 0 { | 202 | if v, ok := queryOptions["employeeType"]; ok && (v.(int)) > 0 { |
198 | query.Where("product_worker->>'employeeType'='?'", v.(int)) | 203 | query.Where("product_worker->>'employeeType'='?'", v.(int)) |
@@ -41,6 +41,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -41,6 +41,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
41 | "updated_at", | 41 | "updated_at", |
42 | "deleted_at", | 42 | "deleted_at", |
43 | "ext", | 43 | "ext", |
44 | + "break_time_periods", | ||
44 | } | 45 | } |
45 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) | 46 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) |
46 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) | 47 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at")) |
@@ -65,6 +66,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -65,6 +66,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
65 | &productCalendar.UpdatedAt, | 66 | &productCalendar.UpdatedAt, |
66 | &productCalendar.DeletedAt, | 67 | &productCalendar.DeletedAt, |
67 | &productCalendar.Ext, | 68 | &productCalendar.Ext, |
69 | + &productCalendar.BreakTimePeriods, | ||
68 | ), | 70 | ), |
69 | fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 71 | fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
70 | productCalendar.CompanyId, | 72 | productCalendar.CompanyId, |
@@ -79,6 +81,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -79,6 +81,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
79 | productCalendar.CreatedAt, | 81 | productCalendar.CreatedAt, |
80 | productCalendar.UpdatedAt, | 82 | productCalendar.UpdatedAt, |
81 | productCalendar.Ext, | 83 | productCalendar.Ext, |
84 | + productCalendar.BreakTimePeriods, | ||
82 | ); err != nil { | 85 | ); err != nil { |
83 | return productCalendar, err | 86 | return productCalendar, err |
84 | } | 87 | } |
@@ -99,6 +102,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -99,6 +102,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
99 | &productCalendar.UpdatedAt, | 102 | &productCalendar.UpdatedAt, |
100 | &productCalendar.DeletedAt, | 103 | &productCalendar.DeletedAt, |
101 | &productCalendar.Ext, | 104 | &productCalendar.Ext, |
105 | + &productCalendar.BreakTimePeriods, | ||
102 | ), | 106 | ), |
103 | fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 107 | fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
104 | productCalendar.CompanyId, | 108 | productCalendar.CompanyId, |
@@ -113,6 +117,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | @@ -113,6 +117,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc | ||
113 | productCalendar.CreatedAt, | 117 | productCalendar.CreatedAt, |
114 | productCalendar.UpdatedAt, | 118 | productCalendar.UpdatedAt, |
115 | productCalendar.Ext, | 119 | productCalendar.Ext, |
120 | + productCalendar.BreakTimePeriods, | ||
116 | productCalendar.Identify(), | 121 | productCalendar.Identify(), |
117 | ); err != nil { | 122 | ); err != nil { |
118 | return productCalendar, err | 123 | return productCalendar, err |
@@ -133,6 +138,9 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int | @@ -133,6 +138,9 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int | ||
133 | tx := repository.transactionContext.PgTx | 138 | tx := repository.transactionContext.PgTx |
134 | productCalendarModel := new(models.ProductCalendar) | 139 | productCalendarModel := new(models.ProductCalendar) |
135 | query := sqlbuilder.BuildQuery(tx.Model(productCalendarModel), queryOptions) | 140 | query := sqlbuilder.BuildQuery(tx.Model(productCalendarModel), queryOptions) |
141 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
142 | + query.SetWhereByQueryOption("org_id = ?", "orgId") | ||
143 | + query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | ||
136 | query.SetWhereByQueryOption("product_calendar.product_calendar_id = ?", "productCalendarId") | 144 | query.SetWhereByQueryOption("product_calendar.product_calendar_id = ?", "productCalendarId") |
137 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { | 145 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { |
138 | query.AllWithDeleted() | 146 | query.AllWithDeleted() |
@@ -123,11 +123,14 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | @@ -123,11 +123,14 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | ||
123 | tx := repository.transactionContext.PgTx | 123 | tx := repository.transactionContext.PgTx |
124 | productGroupModel := new(models.ProductGroup) | 124 | productGroupModel := new(models.ProductGroup) |
125 | query := sqlbuilder.BuildQuery(tx.Model(productGroupModel), queryOptions) | 125 | query := sqlbuilder.BuildQuery(tx.Model(productGroupModel), queryOptions) |
126 | + query.SetWhereByQueryOption("company_id = ?", "companyId") | ||
127 | + query.SetWhereByQueryOption("org_id = ?", "orgId") | ||
126 | query.SetWhereByQueryOption("product_group.product_group_id = ?", "productGroupId") | 128 | query.SetWhereByQueryOption("product_group.product_group_id = ?", "productGroupId") |
127 | query.SetWhereByQueryOption("group_name=?", "groupName") | 129 | query.SetWhereByQueryOption("group_name=?", "groupName") |
128 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | 130 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") |
129 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") | 131 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") |
130 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") | 132 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") |
133 | + query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId") | ||
131 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { | 134 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { |
132 | query.AllWithDeleted() | 135 | query.AllWithDeleted() |
133 | } | 136 | } |
pkg/infrastructure/utils/config.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/core/config" | ||
5 | + "github.com/beego/beego/v2/server/web" | ||
6 | + "os" | ||
7 | + "strconv" | ||
8 | +) | ||
9 | + | ||
10 | +type Configurator interface { | ||
11 | + DefaultString(key string, defaultVal string) string | ||
12 | + DefaultInt(key string, defaultVal int) int | ||
13 | + DefaultInt64(key string, defaultVal int64) int64 | ||
14 | + DefaultBool(key string, defaultVal bool) bool | ||
15 | + DefaultFloat(key string, defaultVal float64) float64 | ||
16 | +} | ||
17 | + | ||
18 | +// EnvConfigurator read config from env param with default value | ||
19 | +type EnvConfigurator struct{} | ||
20 | + | ||
21 | +func (c EnvConfigurator) DefaultString(key string, defaultVal string) string { | ||
22 | + if os.Getenv(key) != "" { | ||
23 | + return os.Getenv(key) | ||
24 | + } | ||
25 | + return defaultVal | ||
26 | +} | ||
27 | +func (c EnvConfigurator) DefaultInt(key string, defaultVal int) int { | ||
28 | + if os.Getenv(key) == "" { | ||
29 | + return defaultVal | ||
30 | + } | ||
31 | + v, err := strconv.Atoi(os.Getenv(key)) | ||
32 | + if err != nil { | ||
33 | + return defaultVal | ||
34 | + } | ||
35 | + return v | ||
36 | +} | ||
37 | +func (c EnvConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
38 | + if os.Getenv(key) == "" { | ||
39 | + return defaultVal | ||
40 | + } | ||
41 | + v, err := strconv.ParseInt(os.Getenv(key), 10, 64) | ||
42 | + if err != nil { | ||
43 | + return defaultVal | ||
44 | + } | ||
45 | + return v | ||
46 | +} | ||
47 | +func (c EnvConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
48 | + if os.Getenv(key) == "" { | ||
49 | + return defaultVal | ||
50 | + } | ||
51 | + v, err := strconv.ParseBool(os.Getenv(key)) | ||
52 | + if err != nil { | ||
53 | + return defaultVal | ||
54 | + } | ||
55 | + return v | ||
56 | +} | ||
57 | +func (c EnvConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
58 | + if os.Getenv(key) == "" { | ||
59 | + return defaultVal | ||
60 | + } | ||
61 | + v, err := strconv.ParseFloat(os.Getenv(key), 64) | ||
62 | + if err != nil { | ||
63 | + return defaultVal | ||
64 | + } | ||
65 | + return v | ||
66 | +} | ||
67 | + | ||
68 | +// BeegoAppConfigurator read config from beego config file with default value | ||
69 | +type BeegoAppConfigurator struct { | ||
70 | +} | ||
71 | + | ||
72 | +func (c BeegoAppConfigurator) DefaultString(key string, defaultVal string) string { | ||
73 | + return web.AppConfig.DefaultString(key, defaultVal) | ||
74 | +} | ||
75 | +func (c BeegoAppConfigurator) DefaultInt(key string, defaultVal int) int { | ||
76 | + return web.AppConfig.DefaultInt(key, defaultVal) | ||
77 | +} | ||
78 | +func (c BeegoAppConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
79 | + return web.AppConfig.DefaultInt64(key, defaultVal) | ||
80 | +} | ||
81 | +func (c BeegoAppConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
82 | + return web.AppConfig.DefaultBool(key, defaultVal) | ||
83 | +} | ||
84 | +func (c BeegoAppConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
85 | + return web.AppConfig.DefaultFloat(key, defaultVal) | ||
86 | +} | ||
87 | + | ||
88 | +func NewConfig(adapterName, filename string) Configurator { | ||
89 | + config, err := config.NewConfig(adapterName, filename) | ||
90 | + if err != nil { | ||
91 | + panic(err) | ||
92 | + } | ||
93 | + return config | ||
94 | +} |
pkg/infrastructure/utils/config_test.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/stretchr/testify/assert" | ||
5 | + "os" | ||
6 | + "testing" | ||
7 | +) | ||
8 | + | ||
9 | +func TestEnvConfigurator(t *testing.T) { | ||
10 | + os.Setenv("bool", "true") | ||
11 | + os.Setenv("hello", "world") | ||
12 | + os.Setenv("number", "10") | ||
13 | + | ||
14 | + var config Configurator = EnvConfigurator{} | ||
15 | + assert.Equal(t, "world", config.DefaultString("hello", "w")) | ||
16 | + assert.Equal(t, "w", config.DefaultString("unknown", "w")) | ||
17 | + | ||
18 | + assert.Equal(t, true, config.DefaultBool("bool", false)) | ||
19 | + assert.Equal(t, true, config.DefaultBool("unknown", true)) | ||
20 | + | ||
21 | + assert.Equal(t, 10, config.DefaultInt("number", 5)) | ||
22 | + assert.Equal(t, 5, config.DefaultInt("unknown", 5)) | ||
23 | + | ||
24 | + assert.Equal(t, int64(10), config.DefaultInt64("number", 5)) | ||
25 | + assert.Equal(t, int64(5), config.DefaultInt64("unknown", 5)) | ||
26 | + | ||
27 | + assert.Equal(t, float64(10), config.DefaultFloat("number", 5)) | ||
28 | + assert.Equal(t, float64(5), config.DefaultFloat("unknown", 5)) | ||
29 | +} |
pkg/infrastructure/utils/tree.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +type TreeNode interface { | ||
4 | + PID() string | ||
5 | + ID() string | ||
6 | +} | ||
7 | + | ||
8 | +type Tree struct { | ||
9 | + Node TreeNode `json:"node"` | ||
10 | + Nodes []*Tree `json:"nodes"` | ||
11 | +} | ||
12 | + | ||
13 | +func NewTree(nodes []TreeNode) *Tree { | ||
14 | + var tree = &Tree{ | ||
15 | + Node: nil, | ||
16 | + Nodes: make([]*Tree, 0), | ||
17 | + } | ||
18 | + for i := range nodes { | ||
19 | + match := traverseAdd(tree, nodes[i]) | ||
20 | + if !match { | ||
21 | + tree.Nodes = append(tree.Nodes, newTree(nodes[i])) | ||
22 | + } | ||
23 | + } | ||
24 | + return tree | ||
25 | +} | ||
26 | + | ||
27 | +func newTree(node TreeNode) *Tree { | ||
28 | + return &Tree{ | ||
29 | + Node: node, | ||
30 | + Nodes: make([]*Tree, 0), | ||
31 | + } | ||
32 | +} | ||
33 | + | ||
34 | +func (tree *Tree) Root() TreeNode { | ||
35 | + if tree.Node != nil { | ||
36 | + return tree.Node | ||
37 | + } | ||
38 | + if len(tree.Nodes) > 0 { | ||
39 | + return tree.Nodes[0].Node | ||
40 | + } | ||
41 | + return nil | ||
42 | +} | ||
43 | + | ||
44 | +// TreeNodePaths returns all the parents of the current node 1->5->7 , use time n*O(n)(need performance optimization) | ||
45 | +func (tree *Tree) TreeNodePaths(node TreeNode) []TreeNode { | ||
46 | + treeNode := node | ||
47 | + result := make([]TreeNode, 0) | ||
48 | + for { | ||
49 | + if treeNode == nil { | ||
50 | + break | ||
51 | + } | ||
52 | + tmp := tree.find(treeNode, func(a, b TreeNode) bool { | ||
53 | + if a.ID() == b.PID() { | ||
54 | + return true | ||
55 | + } | ||
56 | + return false | ||
57 | + }) | ||
58 | + result = append(result, treeNode) | ||
59 | + if tmp == nil { | ||
60 | + break | ||
61 | + } | ||
62 | + treeNode = tmp.Node | ||
63 | + } | ||
64 | + reserveResult := make([]TreeNode, 0) | ||
65 | + for i := len(result) - 1; i >= 0; i-- { | ||
66 | + reserveResult = append(reserveResult, result[i]) | ||
67 | + } | ||
68 | + return reserveResult | ||
69 | +} | ||
70 | + | ||
71 | +// Add adds a node to the first matching parent tree if add success it return true | ||
72 | +func (tree *Tree) Add(node TreeNode) bool { | ||
73 | + return traverseAdd(tree, node) | ||
74 | +} | ||
75 | + | ||
76 | +// AllChildNode returns all child nodes under Node, including itself | ||
77 | +func (tree *Tree) AllChildNode(node TreeNode) []TreeNode { | ||
78 | + treeNode := tree.find(node, nil) | ||
79 | + if treeNode == nil { | ||
80 | + return []TreeNode{} | ||
81 | + } | ||
82 | + return tree.allChildNode(treeNode, nil) | ||
83 | +} | ||
84 | + | ||
85 | +//AllLeafNode returns all leaf node under Node ,if node is nil returns all leaf node under tree | ||
86 | +func (tree *Tree) AllLeafNode(node TreeNode) []TreeNode { | ||
87 | + treeNode := tree | ||
88 | + if node != nil { | ||
89 | + treeNode = tree.find(node, nil) | ||
90 | + } | ||
91 | + if treeNode == nil { | ||
92 | + return []TreeNode{} | ||
93 | + } | ||
94 | + return tree.allChildNode(treeNode, func(node *Tree) bool { | ||
95 | + if len(node.Nodes) == 0 { | ||
96 | + return true | ||
97 | + } | ||
98 | + return false | ||
99 | + }) | ||
100 | +} | ||
101 | + | ||
102 | +// find query the node in this tree | ||
103 | +func (tree *Tree) find(node TreeNode, compared func(a, b TreeNode) bool) *Tree { | ||
104 | + var stack []*Tree | ||
105 | + stack = append(stack, tree) | ||
106 | + var find *Tree | ||
107 | + for { | ||
108 | + if len(stack) == 0 { | ||
109 | + break | ||
110 | + } | ||
111 | + pop := stack[0] | ||
112 | + stack = stack[1:] | ||
113 | + stack = append(stack, pop.Nodes...) | ||
114 | + if pop == nil || pop.Node == nil { | ||
115 | + continue | ||
116 | + } | ||
117 | + if compared != nil { | ||
118 | + if compared(pop.Node, node) { | ||
119 | + find = pop | ||
120 | + break | ||
121 | + } | ||
122 | + continue | ||
123 | + } | ||
124 | + if pop.Node.ID() == node.ID() { | ||
125 | + find = pop | ||
126 | + break | ||
127 | + } | ||
128 | + } | ||
129 | + return find | ||
130 | +} | ||
131 | + | ||
132 | +// allChildNode 返回treeNode下所有子节点 | ||
133 | +func (tree *Tree) allChildNode(treeNode *Tree, filter func(node *Tree) bool) []TreeNode { | ||
134 | + var stack []*Tree | ||
135 | + stack = append(stack, treeNode) | ||
136 | + var res []TreeNode | ||
137 | + for { | ||
138 | + if len(stack) == 0 { | ||
139 | + break | ||
140 | + } | ||
141 | + pop := stack[0] | ||
142 | + stack = stack[1:] | ||
143 | + stack = append(stack, pop.Nodes...) | ||
144 | + if filter != nil && !filter(pop) { | ||
145 | + continue | ||
146 | + } | ||
147 | + res = append(res, pop.Node) | ||
148 | + } | ||
149 | + return res | ||
150 | +} | ||
151 | + | ||
152 | +// traverseAdd 递归添加 | ||
153 | +// | ||
154 | +// tree 当前树 | ||
155 | +// node 判断的节点 | ||
156 | +func traverseAdd(tree *Tree, node TreeNode) bool { | ||
157 | + list := tree.Nodes | ||
158 | + var match bool = false | ||
159 | + for i := range list { | ||
160 | + id, pid := list[i].Node.ID(), node.PID() | ||
161 | + if pid == id { | ||
162 | + list[i].Nodes = append(list[i].Nodes, newTree(node)) | ||
163 | + return true | ||
164 | + } | ||
165 | + if match || traverseAdd(list[i], node) { | ||
166 | + match = true | ||
167 | + break | ||
168 | + } | ||
169 | + } | ||
170 | + return match | ||
171 | +} |
pkg/infrastructure/utils/tree_test.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/stretchr/testify/assert" | ||
5 | + "strconv" | ||
6 | + "testing" | ||
7 | +) | ||
8 | + | ||
9 | +func Test_Tree(t *testing.T) { | ||
10 | + table := []struct { | ||
11 | + Input []TreeNode | ||
12 | + Text string | ||
13 | + Except []string | ||
14 | + Except2 []string | ||
15 | + }{ | ||
16 | + { | ||
17 | + Input: []TreeNode{ | ||
18 | + &st{Id: 1, Pid: 0}, | ||
19 | + &st{Id: 2, Pid: 1}, &st{Id: 3, Pid: 1}, &st{Id: 4, Pid: 1}, | ||
20 | + &st{Id: 5, Pid: 3}, | ||
21 | + &st{Id: 6, Pid: 5}, &st{Id: 7, Pid: 5}}, | ||
22 | + Text: ` | ||
23 | +树形结构: | ||
24 | + 1 | ||
25 | +2 3 4 | ||
26 | + 5 | ||
27 | + 6 7 | ||
28 | +`, | ||
29 | + Except: []string{"5", "6", "7"}, | ||
30 | + Except2: []string{"2", "4", "6", "7"}, | ||
31 | + }, | ||
32 | + } | ||
33 | + | ||
34 | + for i := range table { | ||
35 | + tree := NewTree(table[i].Input) | ||
36 | + out := tree.AllChildNode(&st{Id: 5, Pid: 3}) | ||
37 | + var res []string = treeNodeResults(out) | ||
38 | + assert.Equal(t, res, table[i].Except) | ||
39 | + | ||
40 | + out = tree.AllLeafNode(nil) //tree.Root() | ||
41 | + res = treeNodeResults(out) | ||
42 | + assert.Equal(t, res, table[i].Except2) | ||
43 | + | ||
44 | + root := tree.Root() | ||
45 | + assert.Equal(t, root.ID(), "1") | ||
46 | + | ||
47 | + //tree.Add(&st{Id:10,Pid: 7}) | ||
48 | + // | ||
49 | + //out = tree.AllLeafNode(tree.Root()) | ||
50 | + //res = treeNodeResults(out) | ||
51 | + //assert.Equal(t, res, []string{"2", "4", "6", "10"}) | ||
52 | + | ||
53 | + out = tree.TreeNodePaths(&st{Id: 7, Pid: 5}) | ||
54 | + res = treeNodeResults(out) | ||
55 | + assert.Equal(t, res, []string{"1", "3", "5", "7"}) | ||
56 | + } | ||
57 | +} | ||
58 | + | ||
59 | +type st struct { | ||
60 | + Id int | ||
61 | + Pid int | ||
62 | +} | ||
63 | + | ||
64 | +func (t *st) PID() string { | ||
65 | + return strconv.Itoa(t.Pid) | ||
66 | +} | ||
67 | +func (t *st) ID() string { | ||
68 | + return strconv.Itoa(t.Id) | ||
69 | +} | ||
70 | + | ||
71 | +func treeNodeResults(nodes []TreeNode) []string { | ||
72 | + var res []string | ||
73 | + for i := range nodes { | ||
74 | + res = append(res, nodes[i].ID()) | ||
75 | + } | ||
76 | + return res | ||
77 | +} |
1 | package log | 1 | package log |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "github.com/linmadan/egglib-go/log" | ||
5 | + "github.com/linmadan/egglib-go/log/logrus" | ||
4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
7 | + "io" | ||
5 | ) | 8 | ) |
6 | 9 | ||
7 | -//var Logger log.Logger | ||
8 | -// | ||
9 | -//func init() { | ||
10 | -// Logger = logrus.NewLogrusLogger() | ||
11 | -// Logger.SetServiceName(constant.SERVICE_NAME) | ||
12 | -// Logger.SetLevel(constant.LOG_LEVEL) | ||
13 | -//} | ||
14 | - | ||
15 | -var Logger *LogrusLogger | 10 | +var Logger log.Logger |
16 | 11 | ||
17 | func init() { | 12 | func init() { |
18 | - Logger = NewLogrusLogger() | 13 | + Logger = logrus.NewLogrusLogger() |
19 | Logger.SetServiceName(constant.SERVICE_NAME) | 14 | Logger.SetServiceName(constant.SERVICE_NAME) |
20 | Logger.SetLevel(constant.LOG_LEVEL) | 15 | Logger.SetLevel(constant.LOG_LEVEL) |
21 | } | 16 | } |
17 | + | ||
18 | +func InitLogHook(enableKafka bool, enableBeeLog bool) { | ||
19 | + if enableKafka { | ||
20 | + if w, err := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false); err == nil { | ||
21 | + Logger.AddHook(w) | ||
22 | + } else { | ||
23 | + Logger.Error(err.Error()) | ||
24 | + } | ||
25 | + } | ||
26 | + | ||
27 | + if enableBeeLog { | ||
28 | + if w, err := logrus.NewWrapHook(true, func() (io.Writer, error) { | ||
29 | + return logrus.NewBeegoLogWriter("", `{"filename":"app.log","maxsize":2048000}`) | ||
30 | + }); err == nil { | ||
31 | + Logger.AddHook(w) | ||
32 | + } else { | ||
33 | + Logger.Error(err.Error()) | ||
34 | + } | ||
35 | + } | ||
36 | +} | ||
37 | + | ||
38 | +//var Logger *LogrusLogger | ||
39 | +// | ||
40 | +//func init() { | ||
41 | +// Logger = NewLogrusLogger() | ||
42 | +// Logger.SetServiceName(constant.SERVICE_NAME) | ||
43 | +// Logger.SetLevel(constant.LOG_LEVEL) | ||
44 | +//} |
1 | package log | 1 | package log |
2 | 2 | ||
3 | -import ( | ||
4 | - "github.com/linmadan/egglib-go/log" | ||
5 | - "github.com/sirupsen/logrus" | ||
6 | - "github.com/sirupsen/logrus/hooks/writer" | ||
7 | - "io" | ||
8 | - "os" | ||
9 | -) | ||
10 | - | ||
11 | -func init() { | ||
12 | - logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
13 | - logrus.SetOutput(os.Stdout) | ||
14 | - logrus.SetLevel(logrus.WarnLevel) | ||
15 | -} | ||
16 | - | ||
17 | -type LogrusLogger struct { | ||
18 | - serviceName string | ||
19 | - logrus *logrus.Logger | ||
20 | -} | ||
21 | - | ||
22 | -func (logger *LogrusLogger) SetServiceName(serviceName string) { | ||
23 | - logger.serviceName = serviceName | ||
24 | -} | ||
25 | - | ||
26 | -func (logger *LogrusLogger) SetLevel(level string) { | ||
27 | - switch level { | ||
28 | - case "trace": | ||
29 | - logger.logrus.Level = logrus.TraceLevel | ||
30 | - case "debug": | ||
31 | - logger.logrus.Level = logrus.DebugLevel | ||
32 | - case "info": | ||
33 | - logger.logrus.Level = logrus.InfoLevel | ||
34 | - case "warn": | ||
35 | - logger.logrus.Level = logrus.WarnLevel | ||
36 | - case "error": | ||
37 | - logger.logrus.Level = logrus.ErrorLevel | ||
38 | - case "fatal": | ||
39 | - logger.logrus.Level = logrus.FatalLevel | ||
40 | - case "panic": | ||
41 | - logger.logrus.Level = logrus.PanicLevel | ||
42 | - default: | ||
43 | - logger.logrus.Level = logrus.DebugLevel | ||
44 | - } | ||
45 | -} | ||
46 | - | ||
47 | -func (logger *LogrusLogger) AddHook(w io.Writer) { | ||
48 | - level := logger.logrus.Level | ||
49 | - var levels []logrus.Level | ||
50 | - // 默认已经添加了一个当前log level的hook,所以此处 level+1 | ||
51 | - for i := 0; i <= (int(level)); i++ { | ||
52 | - levels = append(levels, logrus.Level(i)) | ||
53 | - } | ||
54 | - logger.logrus.AddHook(&writer.Hook{ | ||
55 | - Writer: w, | ||
56 | - LogLevels: levels, | ||
57 | - }) | ||
58 | -} | ||
59 | - | ||
60 | -func (logger *LogrusLogger) Trace(msg string, appends ...map[string]interface{}) { | ||
61 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
62 | - for _, append := range appends { | ||
63 | - contextLogger = contextLogger.WithFields(append) | ||
64 | - } | ||
65 | - contextLogger.Trace(msg) | ||
66 | -} | ||
67 | - | ||
68 | -func (logger *LogrusLogger) Debug(msg string, appends ...map[string]interface{}) { | ||
69 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
70 | - for _, append := range appends { | ||
71 | - contextLogger = contextLogger.WithFields(append) | ||
72 | - } | ||
73 | - contextLogger.Debug(msg) | ||
74 | -} | ||
75 | - | ||
76 | -func (logger *LogrusLogger) Info(msg string, appends ...map[string]interface{}) { | ||
77 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
78 | - for _, append := range appends { | ||
79 | - contextLogger = contextLogger.WithFields(append) | ||
80 | - } | ||
81 | - contextLogger.Info(msg) | ||
82 | -} | ||
83 | - | ||
84 | -func (logger *LogrusLogger) Warn(msg string, appends ...map[string]interface{}) { | ||
85 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
86 | - for _, append := range appends { | ||
87 | - contextLogger = contextLogger.WithFields(append) | ||
88 | - } | ||
89 | - contextLogger.Warn(msg) | ||
90 | -} | ||
91 | - | ||
92 | -func (logger *LogrusLogger) Error(msg string, appends ...map[string]interface{}) { | ||
93 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
94 | - for _, append := range appends { | ||
95 | - contextLogger = contextLogger.WithFields(append) | ||
96 | - } | ||
97 | - contextLogger.Error(msg) | ||
98 | -} | ||
99 | - | ||
100 | -func (logger *LogrusLogger) Fatal(msg string, appends ...map[string]interface{}) { | ||
101 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
102 | - for _, append := range appends { | ||
103 | - contextLogger = contextLogger.WithFields(append) | ||
104 | - } | ||
105 | - contextLogger.Fatal(msg) | ||
106 | -} | ||
107 | - | ||
108 | -func (logger *LogrusLogger) Panic(msg string, appends ...map[string]interface{}) { | ||
109 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
110 | - for _, append := range appends { | ||
111 | - contextLogger = contextLogger.WithFields(append) | ||
112 | - } | ||
113 | - contextLogger.Panic(msg) | ||
114 | -} | ||
115 | - | ||
116 | -func NewLogrusLogger() *LogrusLogger { | ||
117 | - logger := logrus.New() | ||
118 | - logger.Formatter = &logrus.JSONFormatter{} | ||
119 | - logger.Out = os.Stdout | ||
120 | - return &LogrusLogger{ | ||
121 | - logrus: logger, | ||
122 | - } | ||
123 | -} | ||
124 | - | ||
125 | -var _ log.Logger = (*LogrusLogger)(nil) | 3 | +//func init() { |
4 | +// logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
5 | +// logrus.SetOutput(os.Stdout) | ||
6 | +// logrus.SetLevel(logrus.WarnLevel) | ||
7 | +//} | ||
8 | +// | ||
9 | +//type LogrusLogger struct { | ||
10 | +// serviceName string | ||
11 | +// logrus *logrus.Logger | ||
12 | +//} | ||
13 | +// | ||
14 | +//func (logger *LogrusLogger) SetServiceName(serviceName string) { | ||
15 | +// logger.serviceName = serviceName | ||
16 | +//} | ||
17 | +// | ||
18 | +//func (logger *LogrusLogger) SetLevel(level string) { | ||
19 | +// switch level { | ||
20 | +// case "trace": | ||
21 | +// logger.logrus.Level = logrus.TraceLevel | ||
22 | +// case "debug": | ||
23 | +// logger.logrus.Level = logrus.DebugLevel | ||
24 | +// case "info": | ||
25 | +// logger.logrus.Level = logrus.InfoLevel | ||
26 | +// case "warn": | ||
27 | +// logger.logrus.Level = logrus.WarnLevel | ||
28 | +// case "error": | ||
29 | +// logger.logrus.Level = logrus.ErrorLevel | ||
30 | +// case "fatal": | ||
31 | +// logger.logrus.Level = logrus.FatalLevel | ||
32 | +// case "panic": | ||
33 | +// logger.logrus.Level = logrus.PanicLevel | ||
34 | +// default: | ||
35 | +// logger.logrus.Level = logrus.DebugLevel | ||
36 | +// } | ||
37 | +//} | ||
38 | +// | ||
39 | +//func (logger *LogrusLogger) AddHook(w io.Writer) { | ||
40 | +// level := logger.logrus.Level | ||
41 | +// var levels []logrus.Level | ||
42 | +// // 默认已经添加了一个当前log level的hook,所以此处 level+1 | ||
43 | +// for i := 0; i <= (int(level)); i++ { | ||
44 | +// levels = append(levels, logrus.Level(i)) | ||
45 | +// } | ||
46 | +// logger.logrus.AddHook(&writer.Hook{ | ||
47 | +// Writer: w, | ||
48 | +// LogLevels: levels, | ||
49 | +// }) | ||
50 | +//} | ||
51 | +// | ||
52 | +//func (logger *LogrusLogger) Trace(msg string, appends ...map[string]interface{}) { | ||
53 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
54 | +// for _, append := range appends { | ||
55 | +// contextLogger = contextLogger.WithFields(append) | ||
56 | +// } | ||
57 | +// contextLogger.Trace(msg) | ||
58 | +//} | ||
59 | +// | ||
60 | +//func (logger *LogrusLogger) Debug(msg string, appends ...map[string]interface{}) { | ||
61 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
62 | +// for _, append := range appends { | ||
63 | +// contextLogger = contextLogger.WithFields(append) | ||
64 | +// } | ||
65 | +// contextLogger.Debug(msg) | ||
66 | +//} | ||
67 | +// | ||
68 | +//func (logger *LogrusLogger) Info(msg string, appends ...map[string]interface{}) { | ||
69 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
70 | +// for _, append := range appends { | ||
71 | +// contextLogger = contextLogger.WithFields(append) | ||
72 | +// } | ||
73 | +// contextLogger.Info(msg) | ||
74 | +//} | ||
75 | +// | ||
76 | +//func (logger *LogrusLogger) Warn(msg string, appends ...map[string]interface{}) { | ||
77 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
78 | +// for _, append := range appends { | ||
79 | +// contextLogger = contextLogger.WithFields(append) | ||
80 | +// } | ||
81 | +// contextLogger.Warn(msg) | ||
82 | +//} | ||
83 | +// | ||
84 | +//func (logger *LogrusLogger) Error(msg string, appends ...map[string]interface{}) { | ||
85 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
86 | +// for _, append := range appends { | ||
87 | +// contextLogger = contextLogger.WithFields(append) | ||
88 | +// } | ||
89 | +// contextLogger.Error(msg) | ||
90 | +//} | ||
91 | +// | ||
92 | +//func (logger *LogrusLogger) Fatal(msg string, appends ...map[string]interface{}) { | ||
93 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
94 | +// for _, append := range appends { | ||
95 | +// contextLogger = contextLogger.WithFields(append) | ||
96 | +// } | ||
97 | +// contextLogger.Fatal(msg) | ||
98 | +//} | ||
99 | +// | ||
100 | +//func (logger *LogrusLogger) Panic(msg string, appends ...map[string]interface{}) { | ||
101 | +// contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
102 | +// for _, append := range appends { | ||
103 | +// contextLogger = contextLogger.WithFields(append) | ||
104 | +// } | ||
105 | +// contextLogger.Panic(msg) | ||
106 | +//} | ||
107 | +// | ||
108 | +//func NewLogrusLogger() *LogrusLogger { | ||
109 | +// logger := logrus.New() | ||
110 | +// logger.Formatter = &logrus.JSONFormatter{} | ||
111 | +// logger.Out = os.Stdout | ||
112 | +// return &LogrusLogger{ | ||
113 | +// logrus: logger, | ||
114 | +// } | ||
115 | +//} | ||
116 | +// | ||
117 | +//var _ log.Logger = (*LogrusLogger)(nil) |
1 | package log | 1 | package log |
2 | 2 | ||
3 | -import ( | ||
4 | - "encoding/json" | ||
5 | - "errors" | ||
6 | - "fmt" | ||
7 | - "github.com/beego/beego/v2/core/logs" | ||
8 | - "io" | ||
9 | - "sync/atomic" | ||
10 | -) | ||
11 | - | ||
12 | -var errOutOfMaxSize = errors.New("msg size is out of limit ") | ||
13 | - | ||
14 | -type BaseHook struct { | ||
15 | - syncWrite bool | ||
16 | - msgChan chan []byte | ||
17 | - maxSize int32 | ||
18 | - currentSize int32 | ||
19 | - closeChan chan struct{} | ||
20 | - w io.Writer | ||
21 | -} | ||
22 | - | ||
23 | -func (b *BaseHook) Write(p []byte) (n int, err error) { | ||
24 | - if b.syncWrite { | ||
25 | - return b.w.Write(p) | ||
26 | - } | ||
27 | - if b.currentSize >= b.maxSize { | ||
28 | - fmt.Println(errOutOfMaxSize.Error(), b.currentSize) | ||
29 | - return 0, errOutOfMaxSize | ||
30 | - } | ||
31 | - b.msgChan <- p | ||
32 | - atomic.AddInt32(&b.currentSize, 1) | ||
33 | - | ||
34 | - return len(p), nil | ||
35 | -} | ||
36 | - | ||
37 | -// NewBaseHook | ||
38 | -// syncWriteFlag 同步写标识 true:同步写 false:异步写 | ||
39 | -func NewBaseHook(syncWriteFlag bool, internalIo io.WriteCloser) (*BaseHook, error) { | ||
40 | - writer := &BaseHook{ | ||
41 | - syncWrite: syncWriteFlag, | ||
42 | - maxSize: 10000, | ||
43 | - msgChan: make(chan []byte, 10000), | ||
44 | - closeChan: make(chan struct{}), | ||
45 | - w: internalIo, | ||
46 | - } | ||
47 | - go writer.ConsumeMsg() | ||
48 | - return writer, nil | ||
49 | -} | ||
50 | - | ||
51 | -func (b *BaseHook) ConsumeMsg() { | ||
52 | - for { | ||
53 | - select { | ||
54 | - case <-b.closeChan: | ||
55 | - return | ||
56 | - case m, ok := <-b.msgChan: | ||
57 | - if ok { | ||
58 | - atomic.AddInt32(&b.currentSize, -1) | ||
59 | - if _, err := b.w.Write(m); err != nil { | ||
60 | - fmt.Println(err) | ||
61 | - } | ||
62 | - } | ||
63 | - } | ||
64 | - } | ||
65 | -} | ||
66 | - | ||
67 | -func (b *BaseHook) Close() { | ||
68 | - close(b.msgChan) | ||
69 | - b.closeChan <- struct{}{} | ||
70 | - //b.wc.Close() | ||
71 | -} | ||
72 | - | ||
73 | -type LoggerConfig struct { | ||
74 | - Level int `json:"level,omitempty"` | ||
75 | - Filename string `json:"filename,omitempty"` | ||
76 | - MaxSize int `json:"maxsize,omitempty"` | ||
77 | - //MaxBackups int `json:"max_backups,omitempty"` | ||
78 | - //MaxAge int `json:"max_age,omitempty"` | ||
79 | - //Compress bool `json:"compress,omitempty"` | ||
80 | - //文件最多保存多少天,默认保存 7 天 | ||
81 | - //MaxDays int `json:"maxdays"` | ||
82 | -} | ||
83 | - | ||
84 | -type internalLog struct { | ||
85 | - *logs.BeeLogger | ||
86 | -} | ||
87 | - | ||
88 | -func NewBeegoLogWriter(conf LoggerConfig) io.Writer { | ||
89 | - logger := logs.GetBeeLogger() | ||
90 | - logger.SetLevel(conf.Level) | ||
91 | - logger.EnableFuncCallDepth(true) | ||
92 | - logger.SetLogFuncCallDepth(2) | ||
93 | - confByte, _ := json.Marshal(conf) | ||
94 | - err := logger.SetLogger(logs.AdapterFile, string(confByte)) | ||
95 | - if err != nil { | ||
96 | - fmt.Println(err.Error()) | ||
97 | - } | ||
98 | - return &internalLog{logger} | ||
99 | -} | ||
100 | - | ||
101 | -func (l *internalLog) Write(p []byte) (n int, err error) { | ||
102 | - l.Debug(string(p)) | ||
103 | - return len(p), nil | ||
104 | -} | 3 | +//import ( |
4 | +// "encoding/json" | ||
5 | +// "errors" | ||
6 | +// "fmt" | ||
7 | +// "github.com/beego/beego/v2/core/logs" | ||
8 | +// "io" | ||
9 | +// "sync/atomic" | ||
10 | +//) | ||
11 | +// | ||
12 | +//var errOutOfMaxSize = errors.New("msg size is out of limit ") | ||
13 | +// | ||
14 | +//type BaseHook struct { | ||
15 | +// syncWrite bool | ||
16 | +// msgChan chan []byte | ||
17 | +// maxSize int32 | ||
18 | +// currentSize int32 | ||
19 | +// closeChan chan struct{} | ||
20 | +// w io.Writer | ||
21 | +//} | ||
22 | +// | ||
23 | +//func (b *BaseHook) Write(p []byte) (n int, err error) { | ||
24 | +// if b.syncWrite { | ||
25 | +// return b.w.Write(p) | ||
26 | +// } | ||
27 | +// if b.currentSize >= b.maxSize { | ||
28 | +// fmt.Println(errOutOfMaxSize.Error(), b.currentSize) | ||
29 | +// return 0, errOutOfMaxSize | ||
30 | +// } | ||
31 | +// b.msgChan <- p | ||
32 | +// atomic.AddInt32(&b.currentSize, 1) | ||
33 | +// | ||
34 | +// return len(p), nil | ||
35 | +//} | ||
36 | +// | ||
37 | +//// NewBaseHook | ||
38 | +//// syncWriteFlag 同步写标识 true:同步写 false:异步写 | ||
39 | +//func NewBaseHook(syncWriteFlag bool, internalIo io.WriteCloser) (*BaseHook, error) { | ||
40 | +// writer := &BaseHook{ | ||
41 | +// syncWrite: syncWriteFlag, | ||
42 | +// maxSize: 10000, | ||
43 | +// msgChan: make(chan []byte, 10000), | ||
44 | +// closeChan: make(chan struct{}), | ||
45 | +// w: internalIo, | ||
46 | +// } | ||
47 | +// go writer.ConsumeMsg() | ||
48 | +// return writer, nil | ||
49 | +//} | ||
50 | +// | ||
51 | +//func (b *BaseHook) ConsumeMsg() { | ||
52 | +// for { | ||
53 | +// select { | ||
54 | +// case <-b.closeChan: | ||
55 | +// return | ||
56 | +// case m, ok := <-b.msgChan: | ||
57 | +// if ok { | ||
58 | +// atomic.AddInt32(&b.currentSize, -1) | ||
59 | +// if _, err := b.w.Write(m); err != nil { | ||
60 | +// fmt.Println(err) | ||
61 | +// } | ||
62 | +// } | ||
63 | +// } | ||
64 | +// } | ||
65 | +//} | ||
66 | +// | ||
67 | +//func (b *BaseHook) Close() { | ||
68 | +// close(b.msgChan) | ||
69 | +// b.closeChan <- struct{}{} | ||
70 | +// //b.wc.Close() | ||
71 | +//} | ||
72 | +// | ||
73 | +//type LoggerConfig struct { | ||
74 | +// Level int `json:"level,omitempty"` | ||
75 | +// Filename string `json:"filename,omitempty"` | ||
76 | +// MaxSize int `json:"maxsize,omitempty"` | ||
77 | +// //MaxBackups int `json:"max_backups,omitempty"` | ||
78 | +// //MaxAge int `json:"max_age,omitempty"` | ||
79 | +// //Compress bool `json:"compress,omitempty"` | ||
80 | +// //文件最多保存多少天,默认保存 7 天 | ||
81 | +// //MaxDays int `json:"maxdays"` | ||
82 | +//} | ||
83 | +// | ||
84 | +//type internalLog struct { | ||
85 | +// *logs.BeeLogger | ||
86 | +//} | ||
87 | +// | ||
88 | +//func NewBeegoLogWriter(conf LoggerConfig) io.Writer { | ||
89 | +// logger := logs.GetBeeLogger() | ||
90 | +// logger.SetLevel(conf.Level) | ||
91 | +// logger.EnableFuncCallDepth(true) | ||
92 | +// logger.SetLogFuncCallDepth(2) | ||
93 | +// confByte, _ := json.Marshal(conf) | ||
94 | +// err := logger.SetLogger(logs.AdapterFile, string(confByte)) | ||
95 | +// if err != nil { | ||
96 | +// fmt.Println(err.Error()) | ||
97 | +// } | ||
98 | +// return &internalLog{logger} | ||
99 | +//} | ||
100 | +// | ||
101 | +//func (l *internalLog) Write(p []byte) (n int, err error) { | ||
102 | +// l.Debug(string(p)) | ||
103 | +// return len(p), nil | ||
104 | +//} |
@@ -78,3 +78,11 @@ func (controller *ProductCalendarController) SearchProductCalendar() { | @@ -78,3 +78,11 @@ func (controller *ProductCalendarController) SearchProductCalendar() { | ||
78 | total, data, err := productCalendarService.SearchProductCalendar(ParseOperateInfo(controller.BaseController), cmd) | 78 | total, data, err := productCalendarService.SearchProductCalendar(ParseOperateInfo(controller.BaseController), cmd) |
79 | ResponseGrid(controller.BaseController, total, data, err) | 79 | ResponseGrid(controller.BaseController, total, data, err) |
80 | } | 80 | } |
81 | + | ||
82 | +func (controller *ProductCalendarController) GetProductGroupCalendar() { | ||
83 | + productCalendarService := service.NewProductCalendarService(nil) | ||
84 | + cmd := &query.GetProductGroupCalendarQuery{} | ||
85 | + Must(controller.Unmarshal(cmd)) | ||
86 | + data, err := productCalendarService.GetProductGroupCalendar(cmd) | ||
87 | + controller.Response(data, err) | ||
88 | +} |
@@ -100,3 +100,15 @@ func (controller *ProductGroupController) GetSignInEmployeeQuery() { | @@ -100,3 +100,15 @@ func (controller *ProductGroupController) GetSignInEmployeeQuery() { | ||
100 | data, err := productGroupService.GetSignEmployee(cmd) | 100 | data, err := productGroupService.GetSignEmployee(cmd) |
101 | controller.Response(data, err) | 101 | controller.Response(data, err) |
102 | } | 102 | } |
103 | + | ||
104 | +func (controller *ProductGroupController) SelectorProductGroups() { | ||
105 | + productGroupService := service.NewProductGroupService(nil) | ||
106 | + cmd := &query.SearchProductGroupQuery{} | ||
107 | + Must(controller.Unmarshal(cmd)) | ||
108 | + operateInfo := ParseOperateInfo(controller.BaseController) | ||
109 | + //cmd.OrgId = operateInfo.OrgId | ||
110 | + cmd.CompanyId = operateInfo.CompanyId | ||
111 | + cmd.InOrgIds = operateInfo.OrgIds | ||
112 | + data, err := productGroupService.SelectorProductGroup(ParseOperateInfo(controller.BaseController), cmd) | ||
113 | + controller.Response(data, err) | ||
114 | +} |
@@ -86,6 +86,7 @@ func (controller *UnitConversionController) SearchMaterial() { | @@ -86,6 +86,7 @@ func (controller *UnitConversionController) SearchMaterial() { | ||
86 | operateInfo := ParseOperateInfo(controller.BaseController) | 86 | operateInfo := ParseOperateInfo(controller.BaseController) |
87 | cmd.OrgId = operateInfo.OrgId | 87 | cmd.OrgId = operateInfo.OrgId |
88 | cmd.CompanyId = operateInfo.CompanyId | 88 | cmd.CompanyId = operateInfo.CompanyId |
89 | + cmd.IntelligentWeighingFlag = 1 | ||
89 | _, data, err := unitConversionService.SearchMaterial(ParseOperateInfo(controller.BaseController), cmd) | 90 | _, data, err := unitConversionService.SearchMaterial(ParseOperateInfo(controller.BaseController), cmd) |
90 | controller.Response(data, err) | 91 | controller.Response(data, err) |
91 | } | 92 | } |
@@ -14,4 +14,5 @@ func init() { | @@ -14,4 +14,5 @@ func init() { | ||
14 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") | 14 | web.Router("/product-calendars/", &controllers.ProductCalendarController{}, "Get:ListProductCalendar") |
15 | 15 | ||
16 | web.Router("/product-calendars/search", &controllers.ProductCalendarController{}, "Post:SearchProductCalendar") | 16 | web.Router("/product-calendars/search", &controllers.ProductCalendarController{}, "Post:SearchProductCalendar") |
17 | + web.Router("/product-calendars/product-group-calendar", &controllers.ProductCalendarController{}, "Post:GetProductGroupCalendar") | ||
17 | } | 18 | } |
@@ -15,4 +15,5 @@ func init() { | @@ -15,4 +15,5 @@ func init() { | ||
15 | web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup") | 15 | web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup") |
16 | web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees") | 16 | web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees") |
17 | web.Router("/product-groups/employee-signing", &controllers.ProductGroupController{}, "Post:GetSignInEmployeeQuery") | 17 | web.Router("/product-groups/employee-signing", &controllers.ProductGroupController{}, "Post:GetSignInEmployeeQuery") |
18 | + web.Router("/product-groups/selector", &controllers.ProductGroupController{}, "Post:SelectorProductGroups") | ||
18 | } | 19 | } |
@@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | @@ -30,13 +30,14 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) { | ||
30 | } | 30 | } |
31 | if workShop, ok := payload["WorkShop"]; ok { | 31 | if workShop, ok := payload["WorkShop"]; ok { |
32 | 32 | ||
33 | - if t, ok := payload["UpTime"]; ok { | ||
34 | - collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) | ||
35 | - } | ||
36 | - if collectionTime.IsZero() { | ||
37 | - log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message}) | ||
38 | - return | ||
39 | - } | 33 | + //if t, ok := payload["UpTime"]; ok { |
34 | + // collectionTime, _ = time.ParseInLocation("2006-01-02 - 15:04:05", t.(string), time.Local) | ||
35 | + //} | ||
36 | + //if collectionTime.IsZero() { | ||
37 | + // log.Logger.Error(fmt.Sprintf("采集时间有误:%v ", collectionTime), map[string]interface{}{"data": message}) | ||
38 | + // return | ||
39 | + //} | ||
40 | + collectionTime = time.Now() | ||
40 | var mBytes []byte | 41 | var mBytes []byte |
41 | for key, item := range payload { | 42 | for key, item := range payload { |
42 | if key == "WorkShop" || key == "UpTime" { | 43 | if key == "WorkShop" || key == "UpTime" { |
-
请 注册 或 登录 后发表评论