作者 Your Name

Merge branch 'dev' into test

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"`
}
... ...
... ... @@ -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"`
... ...
... ... @@ -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
}
... ...
... ... @@ -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))
... ...
... ... @@ -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)
}
... ...