作者 Your Name

更新

... ... @@ -9,7 +9,7 @@ import (
)
type CreateProductRecordCommand struct {
ProductRecordId int `json:"productRecordId"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
... ... @@ -17,7 +17,7 @@ type CreateProductRecordCommand struct {
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
WorkerId int `cname:"工人ID" json:"workerId" valid:"Required"`
WorkerId []int `cname:"工人ID" json:"workerId" valid:"Required"`
//生气计划id
ProductPlanId int `cname:"生气计划id" json:"productPlanId" valid:"Required"`
... ...
... ... @@ -56,7 +56,7 @@ func (productRecordService *ProductRecordService) ApproveProductRecord(cmd *comm
return struct{}{}, nil
}
// 创建生产记录服务
// 创建生产记录服务,二级品
func (productRecordService *ProductRecordService) CreateProductRecord(operateInfo *domain.OperateInfo, param *command.CreateProductRecordCommand) (interface{}, error) {
if err := param.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -117,44 +117,50 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取车间工段数据失败"+err.Error())
}
productRecordData := &domain.ProductRecord{
ProductRecordId: param.ProductRecordId,
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
ProductRecordType: domain.RecordTypeSecondLevelWeigh,
ProductWorker: user,
WorkStation: workstation,
CreatedAt: dataTime,
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
Original: param.Weigh,
Weigh: utils.Round(param.Weigh, 1),
WeighBefore: utils.Round(param.Weigh, 1),
UnitConversionId: 0,
ApproveStatus: domain.ProductRecordNotApprove,
ProductPlanId: productPlanData.ProductPlanId,
BatchNumber: productPlanData.BatchNumber,
PlanProductName: productPlanData.PlanProductName,
ProductGroupId: 0,
WorkOn: productPlanData.WorkOn,
},
Ext: domain.NewExt(org.OrgName),
}
//保存并审核
if param.SaveAndApprove {
productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
}
_, err = productRecordRepo.Save(productRecordData)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
productRecordIds := []int{}
for _, workerId := range param.WorkerId {
workerData, err := userService.User(workerId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工数据错误,"+err.Error())
}
productRecordData := &domain.ProductRecord{
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
ProductRecordType: domain.RecordTypeSecondLevelWeigh,
ProductWorker: workerData,
WorkStation: workstation,
CreatedAt: dataTime,
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: productPlanData.ProductDate.Local().Format("2006-01-02"),
Original: param.Weigh,
Weigh: utils.Round(param.Weigh, 1),
WeighBefore: utils.Round(param.Weigh, 1),
UnitConversionId: 0,
ApproveStatus: domain.ProductRecordNotApprove,
ProductPlanId: productPlanData.ProductPlanId,
BatchNumber: productPlanData.BatchNumber,
PlanProductName: productPlanData.PlanProductName,
ProductGroupId: 0,
WorkOn: productPlanData.WorkOn,
},
Ext: domain.NewExt(org.OrgName),
}
//保存并审核
if param.SaveAndApprove {
productRecordData.Approve(user, param.Weigh, time.Now(), domain.ProductRecordApproved)
}
_, err = productRecordRepo.Save(productRecordData)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "保存生产记录"+err.Error())
}
productRecordIds = append(productRecordIds, productRecordData.ProductRecordId)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"productRecordId": productRecordData.ProductRecordId,
"productRecordId": productRecordIds,
}, nil
}
... ...
... ... @@ -2,12 +2,13 @@ package repository
import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -176,7 +177,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
query.Where("created_at>=?", v.(time.Time))
}
if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("created_at<?", v.(time.Time))
query.Where("created_at<=?", v.(time.Time))
}
if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v))
... ...