正在显示
21 个修改的文件
包含
293 行增加
和
149 行删除
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 |
@@ -18,6 +18,11 @@ import ( | @@ -18,6 +18,11 @@ import ( | ||
18 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego" | 18 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego" |
19 | ) | 19 | ) |
20 | 20 | ||
21 | +//func init(){ | ||
22 | +// constant.Configurator = utils.BeegoAppConfigurator{} | ||
23 | +// web.LoadAppConfig("ini","config/app.conf") | ||
24 | +//} | ||
25 | + | ||
21 | func main() { | 26 | func main() { |
22 | defer func() { | 27 | defer func() { |
23 | if r := recover(); r != nil { | 28 | if r := recover(); r != nil { |
@@ -2,11 +2,10 @@ package command | @@ -2,11 +2,10 @@ 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 { |
@@ -25,11 +24,11 @@ type CreateAttendanceCommand struct { | @@ -25,11 +24,11 @@ type CreateAttendanceCommand struct { | ||
25 | // 工段ID | 24 | // 工段ID |
26 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 25 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
27 | // 生产日期 | 26 | // 生产日期 |
28 | - ProductDate time.Time `cname:"生产日期" json:"productDate,omitempty" valid:"Required"` | 27 | + ProductDate string `cname:"生产日期" json:"productDate,omitempty" valid:"Required"` |
29 | // 签到 | 28 | // 签到 |
30 | - SignIn time.Time `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"` | 29 | + SignIn string `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"` |
31 | // 签退 | 30 | // 签退 |
32 | - SignOut time.Time `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"` | 31 | + SignOut string `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"` |
33 | // 考勤状态 1.未审核 2:审核 | 32 | // 考勤状态 1.未审核 2:审核 |
34 | AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"` | 33 | AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"` |
35 | // 休息时长 | 34 | // 休息时长 |
@@ -41,7 +40,14 @@ type CreateAttendanceCommand struct { | @@ -41,7 +40,14 @@ type CreateAttendanceCommand struct { | ||
41 | } | 40 | } |
42 | 41 | ||
43 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { | 42 | func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { |
44 | - //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 | + } | ||
45 | validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus") | 51 | validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus") |
46 | } | 52 | } |
47 | 53 |
@@ -109,6 +109,18 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -109,6 +109,18 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
109 | if cmd.WorkTime-cmd.BreakTime > 0 { | 109 | if cmd.WorkTime-cmd.BreakTime > 0 { |
110 | workTime = cmd.WorkTime - cmd.BreakTime | 110 | workTime = cmd.WorkTime - cmd.BreakTime |
111 | } | 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 | + } | ||
112 | newAttendance := &domain.ProductAttendanceRecord{ | 124 | newAttendance := &domain.ProductAttendanceRecord{ |
113 | //ProductAttendanceId: cmd.ProductAttendanceId, | 125 | //ProductAttendanceId: cmd.ProductAttendanceId, |
114 | CompanyId: operateInfo.CompanyId, | 126 | CompanyId: operateInfo.CompanyId, |
@@ -116,8 +128,8 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -116,8 +128,8 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
116 | AttendanceType: cmd.AttendanceType, | 128 | AttendanceType: cmd.AttendanceType, |
117 | ProductWorker: user, | 129 | ProductWorker: user, |
118 | WorkStation: workStation, | 130 | WorkStation: workStation, |
119 | - SignIn: cmd.SignIn, | ||
120 | - SignOut: cmd.SignOut, | 131 | + SignIn: signIn, |
132 | + SignOut: signOut, | ||
121 | AttendanceStatus: cmd.AttendanceStatus, | 133 | AttendanceStatus: cmd.AttendanceStatus, |
122 | WorkTimeBefore: workTime, | 134 | WorkTimeBefore: workTime, |
123 | WorkTimeAfter: 0, | 135 | WorkTimeAfter: 0, |
@@ -127,7 +139,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -127,7 +139,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
127 | GroupName: productGroup.GroupName, | 139 | GroupName: productGroup.GroupName, |
128 | ProductGroupId: productGroup.ProductGroupId, | 140 | ProductGroupId: productGroup.ProductGroupId, |
129 | }), | 141 | }), |
130 | - ProductDate: xtime.New(cmd.ProductDate).BeginningOfDay(), | 142 | + ProductDate: productDate, |
131 | } | 143 | } |
132 | 144 | ||
133 | if cmd.AttendanceStatus == domain.AttendanceApproved { | 145 | if cmd.AttendanceStatus == domain.AttendanceApproved { |
@@ -142,12 +154,12 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -142,12 +154,12 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
142 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) | 154 | attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) |
143 | if !cmd.Prepared { | 155 | if !cmd.Prepared { |
144 | // 检查时间段内是否有重复的打卡记录 | 156 | // 检查时间段内是否有重复的打卡记录 |
145 | - count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, cmd.SignIn, cmd.SignIn) | 157 | + count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, newAttendance.SignIn, newAttendance.SignIn) |
146 | if err != nil { | 158 | if err != nil { |
147 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 159 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
148 | } | 160 | } |
149 | if count > 0 { | 161 | if count > 0 { |
150 | - return nil, &application.ServiceError{Code: 10040001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)} | 162 | + return nil, &application.ServiceError{Code: 10050001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)} |
151 | } | 163 | } |
152 | } | 164 | } |
153 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { | 165 | if attendance, err := attendanceRepository.Save(newAttendance); err != nil { |
@@ -157,7 +169,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | @@ -157,7 +169,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain | ||
157 | if err := transactionContext.CommitTransaction(); err != nil { | 169 | if err := transactionContext.CommitTransaction(); err != nil { |
158 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 170 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
159 | } | 171 | } |
160 | - return attendance, nil | 172 | + return struct{}{}, nil |
161 | } | 173 | } |
162 | } | 174 | } |
163 | 175 |
@@ -24,7 +24,7 @@ type CreateProductCalendarCommand struct { | @@ -24,7 +24,7 @@ type CreateProductCalendarCommand struct { | ||
24 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 24 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
25 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 25 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
26 | // 日历选择 | 26 | // 日历选择 |
27 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 27 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` // valid:"Required" |
28 | // 上岗时间 | 28 | // 上岗时间 |
29 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 29 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
30 | // 下岗时间 | 30 | // 下岗时间 |
@@ -21,8 +21,8 @@ type UpdateProductCalendarCommand struct { | @@ -21,8 +21,8 @@ type UpdateProductCalendarCommand struct { | ||
21 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` | 21 | SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` |
22 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 | 22 | // 上班班次 1:全天 2:白班 4:中班 8:夜班 |
23 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` | 23 | WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"` |
24 | - // 日历选择 | ||
25 | - CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"` | 24 | + // 日历选择 valid:"Required" |
25 | + CalendarSelected []int `cname:"日历选择" json:"calendarSelected" ` | ||
26 | // 上岗时间 | 26 | // 上岗时间 |
27 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` | 27 | InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"` |
28 | // 下岗时间 | 28 | // 下岗时间 |
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 | +} |
@@ -372,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | @@ -372,6 +372,43 @@ func (productCalendarService *ProductCalendarService) SearchProductCalendar(oper | ||
372 | return count, result, nil | 372 | return count, result, nil |
373 | } | 373 | } |
374 | 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 | + | ||
375 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { | 412 | func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService { |
376 | newProductCalendarService := &ProductCalendarService{} | 413 | newProductCalendarService := &ProductCalendarService{} |
377 | return newProductCalendarService | 414 | return newProductCalendarService |
@@ -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) { |
@@ -578,9 +578,7 @@ func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo | @@ -578,9 +578,7 @@ func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo | ||
578 | if err := transactionContext.CommitTransaction(); err != nil { | 578 | if err := transactionContext.CommitTransaction(); err != nil { |
579 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 579 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
580 | } | 580 | } |
581 | - return map[string]interface{}{ | ||
582 | - "groups": results, | ||
583 | - }, nil | 581 | + return results, nil |
584 | } | 582 | } |
585 | 583 | ||
586 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { | 584 | func NewProductGroupService(options map[string]interface{}) *ProductGroupService { |
@@ -2,10 +2,11 @@ package constant | @@ -2,10 +2,11 @@ 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.EnvConfigurator{} | ||
9 | + | ||
9 | var SERVICE_NAME = "allied-creation-manufacture" | 10 | var SERVICE_NAME = "allied-creation-manufacture" |
10 | var SERVICE_ENV = "dev" | 11 | var SERVICE_ENV = "dev" |
11 | var HTTP_PORT int = 8081 | 12 | var HTTP_PORT int = 8081 |
@@ -35,46 +36,13 @@ const HeaderOrgId = "orgId" | @@ -35,46 +36,13 @@ const HeaderOrgId = "orgId" | ||
35 | const HeaderOrgIds = "orgIds" | 36 | const HeaderOrgIds = "orgIds" |
36 | 37 | ||
37 | func init() { | 38 | 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 | - } | 39 | + LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) |
40 | + ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) | ||
41 | + ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) | ||
42 | + ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) | ||
43 | + MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | ||
44 | + SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | ||
45 | + HTTP_PORT = Configurator.DefaultInt("HTTP_PORT", HTTP_PORT) | ||
78 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 46 | SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
79 | CACHE_PREFIX = SERVICE_NAME | 47 | CACHE_PREFIX = SERVICE_NAME |
80 | } | 48 | } |
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" | ||
7 | - REDIS_PORT = "6379" | ||
8 | - REDIS_AUTH = "" | 4 | + REDIS_HOST = "127.0.0.1" |
5 | + REDIS_PORT = "6379" | ||
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 | } |
@@ -130,6 +130,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | @@ -130,6 +130,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | ||
130 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") | 130 | query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId") |
131 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") | 131 | query.SetWhereByQueryOption("work_station->>'workshopId'='?'", "workshopId") |
132 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") | 132 | query.SetWhereByQueryOption("work_station->>'lineId'='?'", "lineId") |
133 | + query.SetWhereByQueryOption("work_station->>'sectionId'='?'", "sectionId") | ||
133 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { | 134 | if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { |
134 | query.AllWithDeleted() | 135 | query.AllWithDeleted() |
135 | } | 136 | } |
pkg/infrastructure/utils/config.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "os" | ||
6 | + "strconv" | ||
7 | +) | ||
8 | + | ||
9 | +type Configurator interface { | ||
10 | + DefaultString(key string, defaultVal string) string | ||
11 | + DefaultInt(key string, defaultVal int) int | ||
12 | + DefaultInt64(key string, defaultVal int64) int64 | ||
13 | + DefaultBool(key string, defaultVal bool) bool | ||
14 | + DefaultFloat(key string, defaultVal float64) float64 | ||
15 | +} | ||
16 | + | ||
17 | +// EnvConfigurator read config from env param with default value | ||
18 | +type EnvConfigurator struct{} | ||
19 | + | ||
20 | +func (c EnvConfigurator) DefaultString(key string, defaultVal string) string { | ||
21 | + if os.Getenv(key) != "" { | ||
22 | + return os.Getenv(key) | ||
23 | + } | ||
24 | + return defaultVal | ||
25 | +} | ||
26 | +func (c EnvConfigurator) DefaultInt(key string, defaultVal int) int { | ||
27 | + if os.Getenv(key) == "" { | ||
28 | + return defaultVal | ||
29 | + } | ||
30 | + v, err := strconv.Atoi(os.Getenv(key)) | ||
31 | + if err != nil { | ||
32 | + return defaultVal | ||
33 | + } | ||
34 | + return v | ||
35 | +} | ||
36 | +func (c EnvConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
37 | + if os.Getenv(key) == "" { | ||
38 | + return defaultVal | ||
39 | + } | ||
40 | + v, err := strconv.ParseInt(os.Getenv(key), 10, 64) | ||
41 | + if err != nil { | ||
42 | + return defaultVal | ||
43 | + } | ||
44 | + return v | ||
45 | +} | ||
46 | +func (c EnvConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
47 | + if os.Getenv(key) == "" { | ||
48 | + return defaultVal | ||
49 | + } | ||
50 | + v, err := strconv.ParseBool(os.Getenv(key)) | ||
51 | + if err != nil { | ||
52 | + return defaultVal | ||
53 | + } | ||
54 | + return v | ||
55 | +} | ||
56 | +func (c EnvConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
57 | + if os.Getenv(key) == "" { | ||
58 | + return defaultVal | ||
59 | + } | ||
60 | + v, err := strconv.ParseFloat(os.Getenv(key), 64) | ||
61 | + if err != nil { | ||
62 | + return defaultVal | ||
63 | + } | ||
64 | + return v | ||
65 | +} | ||
66 | + | ||
67 | +// BeegoAppConfigurator read config from beego config file with default value | ||
68 | +type BeegoAppConfigurator struct{} | ||
69 | + | ||
70 | +func (c BeegoAppConfigurator) DefaultString(key string, defaultVal string) string { | ||
71 | + return web.AppConfig.DefaultString(key, defaultVal) | ||
72 | +} | ||
73 | +func (c BeegoAppConfigurator) DefaultInt(key string, defaultVal int) int { | ||
74 | + return web.AppConfig.DefaultInt(key, defaultVal) | ||
75 | +} | ||
76 | +func (c BeegoAppConfigurator) DefaultInt64(key string, defaultVal int64) int64 { | ||
77 | + return web.AppConfig.DefaultInt64(key, defaultVal) | ||
78 | +} | ||
79 | +func (c BeegoAppConfigurator) DefaultBool(key string, defaultVal bool) bool { | ||
80 | + return web.AppConfig.DefaultBool(key, defaultVal) | ||
81 | +} | ||
82 | +func (c BeegoAppConfigurator) DefaultFloat(key string, defaultVal float64) float64 { | ||
83 | + return web.AppConfig.DefaultFloat(key, defaultVal) | ||
84 | +} |
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 | +} |
@@ -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 | +} |
@@ -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 | } |
-
请 注册 或 登录 后发表评论