...
|
...
|
@@ -6,8 +6,11 @@ import ( |
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productCalendar/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 工厂日历服务
|
...
|
...
|
@@ -15,8 +18,10 @@ type ProductCalendarService struct { |
|
|
}
|
|
|
|
|
|
// 创建工厂日历服务
|
|
|
func (productCalendarService *ProductCalendarService) CreateProductCalendar(createProductCalendarCommand *command.CreateProductCalendarCommand) (interface{}, error) {
|
|
|
if err := createProductCalendarCommand.ValidateCommand(); err != nil {
|
|
|
func (productCalendarService *ProductCalendarService) CreateProductCalendar(operateInfo *domain.OperateInfo, cmd *command.CreateProductCalendarCommand) (interface{}, error) {
|
|
|
cmd.CompanyId = operateInfo.CompanyId
|
|
|
cmd.OrgId = operateInfo.OrgId
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -29,27 +34,42 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(crea |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProductCalendar := &domain.ProductCalendar{
|
|
|
CompanyId: createProductCalendarCommand.CompanyId,
|
|
|
OrgId: createProductCalendarCommand.OrgId,
|
|
|
//WorkshopId: createProductCalendarCommand.WorkshopId,
|
|
|
//LineId: createProductCalendarCommand.LineId,
|
|
|
//SectionId: createProductCalendarCommand.SectionId,
|
|
|
//WorkOn: createProductCalendarCommand.WorkOn,
|
|
|
CalendarSelected: createProductCalendarCommand.CalendarSelected,
|
|
|
InWorkAt: createProductCalendarCommand.InWorkAt,
|
|
|
OutWorkAt: createProductCalendarCommand.OutWorkAt,
|
|
|
BreakTime: createProductCalendarCommand.BreakTime,
|
|
|
WorkTime: createProductCalendarCommand.WorkTime,
|
|
|
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var productCalendarRepository domain.ProductCalendarRepository
|
|
|
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
|
|
|
// 判断同一个工作位置班次下,是否已重复排班
|
|
|
productCalendarRepository, _, _ := factory.FastPgProductCalendar(transactionContext, 0)
|
|
|
if total, _, err := productCalendarRepository.Find(map[string]interface{}{
|
|
|
"companyId": cmd.CompanyId,
|
|
|
"orgId": cmd.OrgId,
|
|
|
"workStationId": workStation.WorkStationId,
|
|
|
"workOn": cmd.WorkOn,
|
|
|
"limit": 1,
|
|
|
}); err == nil && total > 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "工厂日历已存在")
|
|
|
}
|
|
|
|
|
|
newProductCalendar := &domain.ProductCalendar{
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
OrgId: cmd.OrgId,
|
|
|
WorkStation: workStation,
|
|
|
WorkOn: cmd.WorkOn,
|
|
|
CalendarSelected: cmd.CalendarSelected,
|
|
|
InWorkAt: cmd.InWorkAt,
|
|
|
OutWorkAt: cmd.OutWorkAt,
|
|
|
BreakTime: cmd.BreakTime,
|
|
|
//WorkTime: cmd.WorkTime,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
if err = newProductCalendar.ResetWorkTime(cmd.WorkTime); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productCalendarRepository = value
|
|
|
}
|
|
|
|
|
|
if productCalendar, err := productCalendarRepository.Save(newProductCalendar); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -93,7 +113,10 @@ func (productCalendarService *ProductCalendarService) GetProductCalendar(getProd |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productCalendar, nil
|
|
|
|
|
|
result := &dto.ProductCalendarDto{}
|
|
|
result.LoadDto(productCalendar)
|
|
|
return result, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -174,8 +197,8 @@ func (productCalendarService *ProductCalendarService) RemoveProductCalendar(remo |
|
|
}
|
|
|
|
|
|
// 更新工厂日历服务
|
|
|
func (productCalendarService *ProductCalendarService) UpdateProductCalendar(updateProductCalendarCommand *command.UpdateProductCalendarCommand) (interface{}, error) {
|
|
|
if err := updateProductCalendarCommand.ValidateCommand(); err != nil {
|
|
|
func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd *command.UpdateProductCalendarCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -189,21 +212,42 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productCalendarRepository domain.ProductCalendarRepository
|
|
|
if value, err := factory.CreateProductCalendarRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
var productCalendar *domain.ProductCalendar
|
|
|
productCalendarRepository, productCalendar, err = factory.FastPgProductCalendar(transactionContext, cmd.ProductCalendarId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productCalendarRepository = value
|
|
|
}
|
|
|
productCalendar, err := productCalendarRepository.FindOne(map[string]interface{}{"productCalendarId": updateProductCalendarCommand.ProductCalendarId})
|
|
|
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productCalendar == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductCalendarCommand.ProductCalendarId)))
|
|
|
|
|
|
// 判断同一个工作位置班次下,是否已重复排班
|
|
|
if productCalendar.WorkOn != cmd.WorkOn || productCalendar.WorkStation.WorkStationId != workStation.WorkStationId {
|
|
|
if total, _, err := productCalendarRepository.Find(map[string]interface{}{
|
|
|
"companyId": productCalendar.CompanyId,
|
|
|
"orgId": productCalendar.OrgId,
|
|
|
"workStationId": workStation.WorkStationId,
|
|
|
"workOn": cmd.WorkOn,
|
|
|
"limit": 1,
|
|
|
}); err == nil && total > 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "工厂日历已存在")
|
|
|
}
|
|
|
}
|
|
|
if err := productCalendar.Update(tool_funs.SimpleStructToMap(updateProductCalendarCommand)); err != nil {
|
|
|
|
|
|
productCalendar.WorkStation = workStation
|
|
|
productCalendar.WorkOn = cmd.WorkOn
|
|
|
productCalendar.CalendarSelected = cmd.CalendarSelected
|
|
|
productCalendar.InWorkAt = cmd.InWorkAt
|
|
|
productCalendar.OutWorkAt = cmd.OutWorkAt
|
|
|
productCalendar.BreakTime = cmd.BreakTime
|
|
|
if err = productCalendar.ResetWorkTime(cmd.WorkTime); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := productCalendar.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if productCalendar, err := productCalendarRepository.Save(productCalendar); err != nil {
|
...
|
...
|
@@ -216,6 +260,45 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(upda |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回工厂日历服务列表
|
|
|
func (productCalendarService *ProductCalendarService) SearchProductCalendar(operateInfo *domain.OperateInfo, listProductCalendarQuery *query.SearchProductCalendarQuery) (int64, interface{}, error) {
|
|
|
listProductCalendarQuery.OrgId = operateInfo.OrgId
|
|
|
listProductCalendarQuery.CompanyId = operateInfo.CompanyId
|
|
|
if err := listProductCalendarQuery.ValidateQuery(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productCalendarRepository domain.ProductCalendarRepository
|
|
|
productCalendarRepository, _, _ = factory.FastPgProductCalendar(transactionContext, 0)
|
|
|
|
|
|
count, productCalendars, err := productCalendarRepository.Find(utils.ObjectToMap(listProductCalendarQuery))
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var result = make([]*dto.ProductCalendarDto, 0)
|
|
|
for i := range productCalendars {
|
|
|
item := productCalendars[i]
|
|
|
newJobDto := &dto.ProductCalendarDto{}
|
|
|
newJobDto.LoadDto(item)
|
|
|
result = append(result, newJobDto)
|
|
|
}
|
|
|
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
func NewProductCalendarService(options map[string]interface{}) *ProductCalendarService {
|
|
|
newProductCalendarService := &ProductCalendarService{}
|
|
|
return newProductCalendarService
|
...
|
...
|
|