作者 yangfu

feat: 工厂日历增加休息周期详情列表

-- 表product_calendar 增加列表 break_time_periods
ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb;
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"reflect"
"strings"
... ... @@ -32,6 +33,8 @@ type CreateProductCalendarCommand struct {
BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
// 工时 (单位 h)
WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
// 休息时间周期列表
BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"`
}
func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validation *validation.Validation) {
... ... @@ -44,6 +47,16 @@ func (createProductCalendarCommand *CreateProductCalendarCommand) Valid(validati
validation.Error(err.Error())
return
}
for _, v := range createProductCalendarCommand.BreakTimePeriods {
if err := utils.ValidWorkTime(v.BeginAt); err != nil {
validation.Error(err.Error() + " " + v.BeginAt)
return
}
if err := utils.ValidWorkTime(v.EndAt); err != nil {
validation.Error(err.Error() + " " + v.EndAt)
return
}
}
}
func (createProductCalendarCommand *CreateProductCalendarCommand) ValidateCommand() error {
... ...
... ... @@ -2,6 +2,8 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"reflect"
"strings"
... ... @@ -29,10 +31,21 @@ type UpdateProductCalendarCommand struct {
BreakTime float64 `cname:"休息时间 (单位 h)" json:"breakTime" valid:"Required"`
// 工时 (单位 h)
WorkTime float64 `cname:"工时 (单位 h)" json:"workTime" valid:"Required"`
// 休息时间周期列表
BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"`
}
func (updateProductCalendarCommand *UpdateProductCalendarCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
for _, v := range updateProductCalendarCommand.BreakTimePeriods {
if err := utils.ValidWorkTime(v.BeginAt); err != nil {
validation.Error(err.Error() + " " + v.BeginAt)
return
}
if err := utils.ValidWorkTime(v.EndAt); err != nil {
validation.Error(err.Error() + " " + v.EndAt)
return
}
}
}
func (updateProductCalendarCommand *UpdateProductCalendarCommand) ValidateCommand() error {
... ...
... ... @@ -32,6 +32,10 @@ type ProductCalendarDto struct {
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
// 休息时间周期列表
BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `json:"breakTimePeriods"`
// 累计休息时间 (单位 h)
TotalBreakTime float64 `json:"totalBreakTime"`
}
func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *ProductCalendarDto {
... ... @@ -48,5 +52,9 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
d.BreakTimePeriods = m.BreakTimePeriods
for _, v := range d.BreakTimePeriods {
d.TotalBreakTime += v.BreakTime
}
return d
}
... ...
... ... @@ -71,9 +71,10 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper
OutWorkAt: cmd.OutWorkAt,
BreakTime: cmd.BreakTime,
//WorkTime: cmd.WorkTime,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
BreakTimePeriods: cmd.BreakTimePeriods,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName),
}
if err = newProductCalendar.ResetWorkTime(cmd.WorkTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -306,6 +307,7 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd
productCalendar.InWorkAt = cmd.InWorkAt
productCalendar.OutWorkAt = cmd.OutWorkAt
productCalendar.BreakTime = cmd.BreakTime
productCalendar.BreakTimePeriods = cmd.BreakTimePeriods
productCalendar.Ext = domain.NewExt(org.OrgName)
if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -37,6 +37,8 @@ type ProductCalendar struct {
DeletedAt time.Time `json:"deletedAt,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
// 休息时间周期列表
BreakTimePeriods []*ProductCalendarBreakTimePeriod `json:"breakTimePeriods"`
}
type ProductCalendarRepository interface {
... ...
package domain
type ProductCalendarBreakTimePeriod struct {
// 开始时间 eg: 11:00
BeginAt string `json:"beginAt,omitempty"`
// 结束时间 eg: 11:30
EndAt string `json:"endAt,omitempty"`
// 休息时间 (单位 h) eg:0.5
BreakTime float64 `json:"breakTime,omitempty"`
// 备注 eg:午饭
Remark string `json:"remark,omitempty"`
}
... ...
... ... @@ -35,4 +35,6 @@ type ProductCalendar struct {
DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"`
// 扩展数据
Ext *domain.Ext `comment:"扩展数据"`
// 休息时间周期列表
BreakTimePeriods []*domain.ProductCalendarBreakTimePeriod `comment:"休息时间周期列表"`
}
... ...
... ... @@ -21,5 +21,6 @@ func TransformToProductCalendarDomainModelFromPgModels(productCalendarModel *mod
UpdatedAt: productCalendarModel.UpdatedAt,
DeletedAt: productCalendarModel.DeletedAt,
Ext: productCalendarModel.Ext,
BreakTimePeriods: productCalendarModel.BreakTimePeriods,
}, nil
}
... ...
... ... @@ -41,6 +41,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
"updated_at",
"deleted_at",
"ext",
"break_time_periods",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_calendar_id", "deleted_at"))
... ... @@ -65,6 +66,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.UpdatedAt,
&productCalendar.DeletedAt,
&productCalendar.Ext,
&productCalendar.BreakTimePeriods,
),
fmt.Sprintf("INSERT INTO manufacture.product_calendar (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
productCalendar.CompanyId,
... ... @@ -79,6 +81,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
productCalendar.CreatedAt,
productCalendar.UpdatedAt,
productCalendar.Ext,
productCalendar.BreakTimePeriods,
); err != nil {
return productCalendar, err
}
... ... @@ -99,6 +102,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
&productCalendar.UpdatedAt,
&productCalendar.DeletedAt,
&productCalendar.Ext,
&productCalendar.BreakTimePeriods,
),
fmt.Sprintf("UPDATE manufacture.product_calendar SET %s WHERE product_calendar_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
productCalendar.CompanyId,
... ... @@ -113,6 +117,7 @@ func (repository *ProductCalendarRepository) Save(productCalendar *domain.Produc
productCalendar.CreatedAt,
productCalendar.UpdatedAt,
productCalendar.Ext,
productCalendar.BreakTimePeriods,
productCalendar.Identify(),
); err != nil {
return productCalendar, err
... ...