作者 Your Name

更新

package command
type CreateProductCapacitiesCmd struct {
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
//员工
WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
//产量重量
Weigh float64 `cname:"重量" json:"weigh" valid:"Required" `
//计划id
ProductPlanId int `json:"productPlanId"`
//日期
RecordDate string `json:"recordDate"`
//上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn"`
//保存并审核
SaveAndApprove bool `json:"saveAndApprove"`
}
... ...
... ... @@ -30,7 +30,7 @@ func (productRecordService *ProductRecordService) SaveProductCapacities(operateI
}()
//日期
recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
recordDate, err := time.Parse("2006-01-02", param.RecordDate)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
}
... ... @@ -156,12 +156,12 @@ func (productRecordService *ProductRecordService) ListProductCapacities(operateI
"transactionContext": transactionContext,
})
productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)
productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local)
productBeginTime, _ := time.Parse("2006-01-02", param.ProductBeginTime)
productEndTime, _ := time.Parse("2006-01-02", param.ProductEndTime)
condition := map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
"workerName": param.WorkerName,
"userName": param.WorkerName,
"workshopName": param.WorkshopName,
"lineName": param.LineName,
"sectionName": param.SectionName,
... ... @@ -540,3 +540,117 @@ func (srv *ProductRecordService) BatchAddProductCapacities(operate *domain.Opera
}
return failRows, nil
}
// 产能管理 页面上手动创建员工生产记录
func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.CreateProductCapacitiesCmd) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//日期
recordDate, err := time.Parse("2006-01-02", param.RecordDate)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
}
userService := domainService.NewUserService()
//操作人数据
var user *domain.User
user, err = userService.User(operateInfo.UserId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取操作人错误,"+err.Error())
}
//组织数据
var org *domain.Org
org, err = userService.Organization(operateInfo.OrgId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//车间数据
workshopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
workshop, err := workshopRepo.FindOne(map[string]interface{}{"workshopId": param.WorkshopId})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取车间数据失败"+err.Error())
}
workstation, err := workshop.FindWorkStation(param.WorkshopId, param.LineId, param.SectionId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
}
//获取生产记录
productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
planData, err := productPlanRepo.FindOne(map[string]interface{}{
"productPlanId": param.ProductPlanId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取计划任务数据失败"+err.Error())
}
//员工生产记录
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
nowTime := time.Now()
productRecordIds := []int{}
for _, workerId := range param.WorkerId {
//员工数据
worker, err := userService.User(workerId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
}
epRecord := &domain.ProductRecord{
UpdatedAt: nowTime,
OrgId: operateInfo.OrgId,
CompanyId: operateInfo.CompanyId,
WorkStation: workstation,
ProductWorker: worker,
CreatedAt: recordDate,
Ext: &domain.Ext{
Operator: user,
OrgName: org.OrgName,
},
ProductRecordType: domain.RecordTypeReceiveMaterial,
ProductRecordInfo: &domain.ProductRecordInfo{
WorkOn: param.WorkOn,
ProductDate: param.RecordDate,
Weigh: param.Weigh,
WeighBefore: param.Weigh,
ApproveStatus: domain.ProductRecordNotApprove,
ApproveAt: 0,
ApproveUser: nil,
ProductPlanId: planData.ProductPlanId,
PlanProductName: planData.PlanProductName,
BatchNumber: planData.BatchNumber,
},
}
if param.SaveAndApprove {
epRecord.ProductRecordInfo.ApproveAt = nowTime.Unix()
epRecord.ProductRecordInfo.ApproveStatus = domain.ProductRecordApproved
epRecord.ProductRecordInfo.ApproveUser = user
}
_, err = productRecordRepo.Save(epRecord)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
}
productRecordIds = append(productRecordIds, epRecord.ProductRecordId)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"productRecordIds": productRecordIds,
}, nil
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -121,11 +122,15 @@ func (repo *RewardSummaryRepository) Find(queryOptions map[string]interface{}) (
}
//日期开始
if v, ok := queryOptions["beginDate"]; ok {
query.Where("record_date>=?", v)
if !(v.(time.Time)).IsZero() {
query.Where("record_date>=?", v)
}
}
//日期结束
if v, ok := queryOptions["endDate"]; ok {
query.Where("record_date<=?", v)
if !(v.(time.Time)).IsZero() {
query.Where("record_date<=?", v)
}
}
//指定查询某个日期
... ...
... ... @@ -132,10 +132,10 @@ func (controller *ProductRecordController) SearchWorkshopProductRecord() {
// 产能管理 添加产能
func (controller *ProductRecordController) CreateProductCapacities() {
productRecordService := service.NewProductRecordService(nil)
saveCommand := &command.SaveProductCapacitiesCmd{}
saveCommand := &command.CreateProductCapacitiesCmd{}
controller.Unmarshal(saveCommand)
operateInfo := ParseOperateInfo(controller.BaseController)
data, err := productRecordService.SaveProductCapacities(operateInfo, saveCommand)
data, err := productRecordService.CreateProductCapacities(operateInfo, saveCommand)
controller.Response(data, err)
}
... ...