|
|
package service
|
|
|
|
|
|
import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
)
|
|
|
|
|
|
//产能管理
|
|
|
|
|
|
// 产能管理 页面上手动创建员工生产记录
|
|
|
func (productRecordService *ProductRecordService) CreateProductCapacities(operateInfo *domain.OperateInfo, param *command.SaveEmployeeProductRecordCmd) (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.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
}
|
|
|
//员工数据
|
|
|
var worker *domain.User
|
|
|
userService := domainService.NewUserService()
|
|
|
worker, err = userService.User(param.WorkerId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取员工错误,"+err.Error())
|
|
|
}
|
|
|
//操作人数据
|
|
|
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())
|
|
|
}
|
|
|
|
|
|
//产品数据
|
|
|
productRepo, _ := factory.CreateProductRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
//获取产品
|
|
|
productData, err := productRepo.FindOne(map[string]interface{}{
|
|
|
"companyId": operateInfo.CompanyId,
|
|
|
"orgId": operateInfo.OrgId,
|
|
|
"productCode": param.ProductCode,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取产品数据失败"+err.Error())
|
|
|
}
|
|
|
nowTime := time.Now()
|
|
|
|
|
|
//员工生产记录
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
var epRecord *domain.EmployeeProductRecord
|
|
|
if param.EmployeeProductRecordId != 0 {
|
|
|
epRecord, err = eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": param.EmployeeProductRecordId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "获取员工生产记录数据失败"+err.Error())
|
|
|
}
|
|
|
} else {
|
|
|
epRecord = &domain.EmployeeProductRecord{
|
|
|
CreatedAt: nowTime,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
}
|
|
|
}
|
|
|
epRecord.UpdatedAt = time.Now()
|
|
|
epRecord.ParticipateType = param.ParticipateType //参与类型
|
|
|
epRecord.WorkStation = workstation //车间工段
|
|
|
epRecord.ProductWorker = worker //员工
|
|
|
epRecord.WorkOn = param.WorkOn //上班班次
|
|
|
epRecord.CreatedAt = recordDate //日期
|
|
|
epRecord.Ext = &domain.Ext{
|
|
|
Operator: user,
|
|
|
OrgName: org.OrgName,
|
|
|
}
|
|
|
epRecord.ProductWeigh = param.Weigh //重量
|
|
|
if epRecord.ProductRecordInfo == nil {
|
|
|
epRecord.ProductRecordInfo = &domain.ProductRecordStaticInfo{}
|
|
|
}
|
|
|
epRecord.ProductRecordInfo.OutputWeight = param.Weigh //重量
|
|
|
epRecord.ProductRecordInfo.PlanProductName = productData.ProductName //产品名称
|
|
|
epRecord.ProductRecordInfo.PlanProductCode = productData.ProductCode //产品编码
|
|
|
epRecord.ProductRecordInfo.OutputWeight = param.Weigh //重量
|
|
|
_, err = eProductRecordRepo.Save(epRecord)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存员工生产记录失败"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": epRecord.EmployeeProductRecordId,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 产能管理 列表
|
|
|
func (productRecordService *ProductRecordService) ListProductCapacities(operateInfo *domain.OperateInfo, param *query.ListProductCapacitiesQuery) (int64, []dto.ProductCapacitiesList, 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()
|
|
|
}()
|
|
|
productRecordRepository, _ := dao.NewEmployeeProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
productBeginTime, _ := time.ParseInLocation("2006-01-02", param.ProductBeginTime, time.Local)
|
|
|
productEndTime, _ := time.ParseInLocation("2006-01-02", param.ProductEndTime, time.Local)
|
|
|
condition := map[string]interface{}{
|
|
|
"companyId": param.CompanyId,
|
|
|
"orgId": param.OrgId,
|
|
|
"workerName": param.WorkerName,
|
|
|
"workshopName": param.WorkshopName,
|
|
|
"lineName": param.LineName,
|
|
|
"sectionName": param.SectionName,
|
|
|
"productBeginTime": productBeginTime,
|
|
|
"productEndTime": productEndTime,
|
|
|
}
|
|
|
|
|
|
limit := param.PageSize
|
|
|
offset := param.PageSize * (param.PageNumber - 1)
|
|
|
if limit >= 0 {
|
|
|
condition["limit"] = limit
|
|
|
}
|
|
|
if offset >= 0 {
|
|
|
condition["offset"] = limit
|
|
|
}
|
|
|
count, productRecords, err := productRecordRepository.SearchEmployeeProductRecord(condition)
|
|
|
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.ProductCapacitiesList, 0)
|
|
|
for _, v := range productRecords {
|
|
|
item := dto.ProductCapacitiesList{
|
|
|
EmployeeProductRecordId: v.EmployeeProductRecordId,
|
|
|
WorkshopName: v.WorkStation.WorkshopName,
|
|
|
LineName: v.WorkStation.LineName,
|
|
|
SectionName: v.WorkStation.SectionName,
|
|
|
WorkerName: v.ProductWorker.UserName,
|
|
|
EmployeeType: v.ProductWorker.EmployeeType,
|
|
|
ProductName: v.ProductRecordInfo.PlanProductName,
|
|
|
ParticipateType: v.ParticipateType,
|
|
|
ProductWeigh: v.ProductRecordInfo.OutputWeight,
|
|
|
CreatedAt: v.CreatedAt.Format("2006-01-02"),
|
|
|
ApproveStatus: v.ApproveStatus,
|
|
|
}
|
|
|
result = append(result, item)
|
|
|
}
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
// 产能管理 列表-详情
|
|
|
func (productRecordService *ProductRecordService) GetProductCapacities(operateInfo *domain.OperateInfo, id int) (*dto.ProductCapacitiesInfo, 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()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var result = dto.ProductCapacitiesInfo{
|
|
|
EmployeeProductRecordId: recordData.EmployeeProductRecordId,
|
|
|
WorkshopId: recordData.WorkStation.WorkshopId,
|
|
|
WorkshopName: recordData.WorkStation.WorkshopName,
|
|
|
LineId: recordData.WorkStation.LineId,
|
|
|
LineName: recordData.WorkStation.LineName,
|
|
|
SectionId: recordData.WorkStation.SectionId,
|
|
|
SectionName: recordData.WorkStation.SectionName,
|
|
|
WorkerId: recordData.ProductWorker.UserId,
|
|
|
WorkerName: recordData.ProductWorker.UserName,
|
|
|
Weigh: recordData.ProductRecordInfo.OutputWeight,
|
|
|
ProductCode: recordData.ProductRecordInfo.PlanProductCode,
|
|
|
ProductName: recordData.ProductRecordInfo.PlanProductName,
|
|
|
ParticipateType: recordData.ParticipateType,
|
|
|
RecordDate: recordData.CreatedAt.Format("2006-01-02"),
|
|
|
WorkOn: recordData.WorkOn,
|
|
|
}
|
|
|
|
|
|
return &result, nil
|
|
|
}
|
|
|
|
|
|
// 产能管理 列表-删除
|
|
|
func (productRecordService *ProductRecordService) DeleteProductCapacities(operateInfo *domain.OperateInfo, id int) (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()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
_, err = eProductRecordRepo.Remove(recordData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": recordData.EmployeeProductRecordId,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 产能管理 列表-审核
|
|
|
func (productRecordService *ProductRecordService) ApproveProductCapacities(operateInfo *domain.OperateInfo, id int) (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()
|
|
|
}()
|
|
|
|
|
|
eProductRecordRepo, _ := factory.CreateEmployeeProductRecordRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
|
|
|
recordData, err := eProductRecordRepo.FindOne(map[string]interface{}{
|
|
|
"employeeProductRecordId": id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.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())
|
|
|
}
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
recordData.ApproveAt = &nowTime
|
|
|
recordData.ApproveStatus = 1
|
|
|
recordData.ApproveUser = user
|
|
|
_, err = eProductRecordRepo.Save(recordData)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, "保存数据错误,"+err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeeProductRecordId": recordData.EmployeeProductRecordId,
|
|
|
}, nil
|
|
|
} |
...
|
...
|
|