作者 Your Name

更新,添加二级品

... ... @@ -9,6 +9,7 @@ import (
)
type CreateProductRecordCommand struct {
ProductRecordId int `json:"productRecordId"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
... ...
... ... @@ -9,7 +9,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/transaction/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
... ... @@ -73,52 +72,83 @@ func (productRecordService *ProductRecordService) CreateProductRecord(operateInf
transactionContext.RollbackTransaction()
}()
//日期
dataTime, err := time.ParseInLocation("2006-01-02", param.CreatedDate, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
}
//生产记录存储
productRecordRepo, _ := factory.CreateProductRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//生产计划
productPlanRepo, _ := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, err = productPlanRepo.FindOne(map[string]interface{}{
//生产计划数据
productPlanData, err := productPlanRepo.FindOne(map[string]interface{}{
"product_plan_id": param.ProductPlanId,
"company_id": operateInfo.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "生产计划id错误,"+err.Error())
}
//用户数据
var user *domain.User
userService := domainService.NewUserService()
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())
}
productRecordDomainService, _ := domainService.NewPGProductRecordService(transactionContext.(*pg.TransactionContext))
submitProductRecordCommand := domainService.SubmitOptions{
productRecordData := &domain.ProductRecord{
ProductRecordId: param.ProductRecordId,
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
ProductPlanId: param.ProductPlanId,
WorkshopId: param.WorkshopId,
LineId: param.LineId,
SectionId: param.SectionId,
ProductGroupId: 0,
EmployeeId: param.WorkerId,
UnitConversionId: 0,
Weigh: param.Weigh,
ProductRecordType: domain.RecordTypeSecondLevelWeigh,
ProductWorker: user,
WorkStation: workstation,
CreatedAt: dataTime,
}
productRecordData, err := productRecordDomainService.SubmitProductRecord(domain.RecordTypeSecondLevelWeigh, tool_funs.SimpleStructToMap(submitProductRecordCommand))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
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 {
svr, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
_, err = svr.Approve(
productRecordData.ProductRecordId,
operateInfo.UserId,
productRecordData.ProductRecordInfo.WeighBefore,
time.Now())
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
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())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -7,6 +7,7 @@ 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/productTrouble/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/dto"
... ... @@ -226,8 +227,10 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera
if err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
//汇总奖惩明细
err = srv.CreateRewardSummaryByProductTrouble(troubleData)
summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
err = summaryServe.CreateRewardSummaryByProductTrouble(troubleData)
if err != nil {
return application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
}
... ... @@ -442,7 +445,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
summaryServe, _ := domainService.NewPGRewardSummaryStaticService(transactionContext.(*pgTransaction.TransactionContext))
for i := range troubleDataList {
//添加事故数据
_, err = productTroubleRepo.Save(troubleDataList[i])
... ... @@ -450,7 +453,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//汇总奖惩明细
err = srv.CreateRewardSummaryByProductTrouble(troubleDataList[i])
err = summaryServe.CreateRewardSummaryByProductTrouble(troubleDataList[i])
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "计算功过奖惩明细失败,"+err.Error())
}
... ... @@ -463,7 +466,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper
}
// 奖惩汇总数据列表
func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
func (srv ProductTroubleService) ListRewardSummary(param *query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -549,73 +552,73 @@ func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummary
}
// 根据事故数据创建奖惩汇总数据
func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//查询是否已经有汇总数据
condtion := map[string]interface{}{
"orgId": param.OrgId,
"companyId": param.CompanyId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"workshopId": param.WorkStation.WorkshopId,
"workerId": param.ProductWorker.UserId,
"recordDateStr": param.RecordDate.Format("200-01-02"),
}
_, summaryList, err := rewardSummaryRepo.Find(condtion)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var summaryData *domain.RewardSummary
nowTime := time.Now()
if len(summaryList) > 0 {
summaryData = summaryList[0]
} else {
summaryData = &domain.RewardSummary{
Id: 0,
CompanyId: param.CompanyId,
OrgId: param.OrgId,
WorkStation: param.WorkStation,
Worker: param.ProductWorker,
RecordDate: param.RecordDate,
RecordDateStr: param.RecordDate.Format("2006-01-02"),
UpToStandard: 0.0,
Yield: 0.0,
AccidentNum1: 0,
AccidentAmount1: 0.0,
AccidentNum2: 0,
AccidentAmount2: 0.0,
AccidentNum3: 0,
AccidentNum4: 0,
SummaryResult: 0.0,
CreatedAt: nowTime,
UpdatedAt: nowTime,
}
}
// 将审核过的事故放入汇总数据计算
summaryData.SummaryAccident(param)
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
// func (srv ProductTroubleService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// //查询是否已经有汇总数据
// condtion := map[string]interface{}{
// "orgId": param.OrgId,
// "companyId": param.CompanyId,
// "lineId": param.WorkStation.LineId,
// "sectionId": param.WorkStation.SectionId,
// "workshopId": param.WorkStation.WorkshopId,
// "workerId": param.ProductWorker.UserId,
// "recordDateStr": param.RecordDate.Format("200-01-02"),
// }
// _, summaryList, err := rewardSummaryRepo.Find(condtion)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// var summaryData *domain.RewardSummary
// nowTime := time.Now()
// if len(summaryList) > 0 {
// summaryData = summaryList[0]
// } else {
// summaryData = &domain.RewardSummary{
// Id: 0,
// CompanyId: param.CompanyId,
// OrgId: param.OrgId,
// WorkStation: param.WorkStation,
// Worker: param.ProductWorker,
// RecordDate: param.RecordDate,
// RecordDateStr: param.RecordDate.Format("2006-01-02"),
// UpToStandard: 0.0,
// Yield: 0.0,
// AccidentNum1: 0,
// AccidentAmount1: 0.0,
// AccidentNum2: 0,
// AccidentAmount2: 0.0,
// AccidentNum3: 0,
// AccidentNum4: 0,
// SummaryResult: 0.0,
// CreatedAt: nowTime,
// UpdatedAt: nowTime,
// }
// }
// // 将审核过的事故放入汇总数据计算
// summaryData.SummaryAccident(param)
// summaryData.UpdatedAt = nowTime
// _, err = rewardSummaryRepo.Save(summaryData)
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return nil
// }
... ...
... ... @@ -2,10 +2,11 @@ package constant
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
//var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf")
// var Configurator utils.Configurator = utils.NewConfig("ini","config/app_test.conf")
var Configurator utils.Configurator = utils.EnvConfigurator{}
var SERVICE_NAME = "allied-creation-manufacture"
... ... @@ -16,13 +17,14 @@ var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
var PPROF_ON = true
//天联共创基础模块
// 天联共创基础模块
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
//天联共创用户模块
var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com"
// 天联共创用户模块
// svar ALLIED_CREATION_USER_HOST = "http://localhost:8081"
var ALLIED_CREATION_USER_HOST = "http://allied-creation-user-test.fjmaimaimai.com"
//天联共创业务模块
// 天联共创业务模块
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301"
... ...
... ... @@ -3,11 +3,11 @@
package constant
var POSTGRESQL_DB_NAME = "terms"
var POSTGRESQL_DB_NAME = "allied_creation_test"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "123456"
var POSTGRESQL_HOST = "127.0.0.1"
var POSTGRESQL_PORT = "5432"
var POSTGRESQL_PASSWORD = "eagle1010"
var POSTGRESQL_HOST = "114.55.200.59"
var POSTGRESQL_PORT = "31543"
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
var DISABLE_SQL_GENERATE_COMMENT = true
... ...
... ... @@ -158,11 +158,6 @@ func (m *RewardStandard) ShowTargeFault() string {
return show
}
// 编辑 奖惩标准时 ,是否需要将旧数据做备份处理
func (m *RewardStandard) NeedMakeBackup() bool {
// 当前时间与 数据最后更新的时间 不是同一天时
// 备份数据
updateAt := m.UpdatedAt.Local().Format("2006-01-02")
nowDate := time.Now().Format("2006-01-02")
return !(updateAt == nowDate)
func (m *RewardStandard) VerdictTarget(val1 int, val float64) int {
return 0
}
... ...
... ... @@ -14,14 +14,20 @@ type RewardSummary struct {
WorkStation WorkStation `json:"workStation"` //工作位置
Worker User `json:"user"` //员工
UpToStandard float64 `json:"upToStandard"` //合格率
UpToStandardResult float64 `json:"upToStandardResult"` //合格率 功过评定结果 `功` `过` `不奖不惩`
Yield float64 `json:"yield"` //产能
YieldResult float64 `json:"yieldResult"` //产能 功过评定结果
AccidentNum1 int `json:"accidentNum1"` //质量事故 次数
AccidentAmount1 float64 `json:"accidentAmount1"` //质量事故 损失金额
AccidentResult1 string `json:"accidentResult1"` //质量事故 功过评定结果
AccidentNum2 int `json:"accidentNum2"` //安全事故 次数
AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额
AccidentResult2 string `json:"accidentResult2"` //安全事故 功过评定结果
AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数
AccidentResult3 string `json:"accidentResult3"` //异物金属事故 功过评定结果
AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数
SummaryResult float64 `json:"summaryResult"` //奖惩计算结果
AccidentResult4 string `json:"accidentResult4"` //异物非金属事故 功过评定结果
SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元)
CreatedAt time.Time `json:"createdAt"` //
UpdatedAt time.Time `json:"UpdatedAt"` //
}
... ...
... ... @@ -2,12 +2,13 @@ package domainService
import (
"fmt"
"time"
"github.com/mohae/deepcopy"
"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/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
const (
... ... @@ -21,7 +22,7 @@ const (
DefaultCCJUnitQuantity = 0.2 //kg 穿串机默认的换算数量 1串/0.1千克
)
//EmployeeProductStatics 员工产能统计
// EmployeeProductStatics 员工产能统计
func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
var (
... ... @@ -249,10 +250,11 @@ func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.Pr
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 员工:[%v] 处理异常:%v", productRecord.ProductRecordId, productRecord.ProductWorker.UserId, err.Error()))
}
//TODO 记录奖惩明细
return nil, nil
}
//WorkshopProductStatics 车间产能统计
// WorkshopProductStatics 车间产能统计
func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
var (
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
... ...
package domainService
import (
"fmt"
"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/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
)
//功过奖惩明细汇总
type PGRewardSummaryStaticService struct {
transactionContext *pgTransaction.TransactionContext
}
func NewPGRewardSummaryStaticService(transactionContext *pgTransaction.TransactionContext) (*PGRewardSummaryStaticService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PGRewardSummaryStaticService{
transactionContext: transactionContext,
}, nil
}
}
// 根据
func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param *domain.ProductTrouble) error {
rewardSummaryRepo, _ := repository.NewRewardSummaryRepository(c.transactionContext)
//查询是否已经有汇总数据
condtion := map[string]interface{}{
"orgId": param.OrgId,
"companyId": param.CompanyId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"workshopId": param.WorkStation.WorkshopId,
"workerId": param.ProductWorker.UserId,
"recordDateStr": param.RecordDate.Format("200-01-02"),
}
_, summaryList, err := rewardSummaryRepo.Find(condtion)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var summaryData *domain.RewardSummary
nowTime := time.Now()
if len(summaryList) > 0 {
summaryData = summaryList[0]
} else {
summaryData = &domain.RewardSummary{
Id: 0,
CompanyId: param.CompanyId,
OrgId: param.OrgId,
WorkStation: param.WorkStation,
Worker: param.ProductWorker,
RecordDate: param.RecordDate,
RecordDateStr: param.RecordDate.Format("2006-01-02"),
UpToStandard: 0.0,
Yield: 0.0,
AccidentNum1: 0,
AccidentAmount1: 0.0,
AccidentNum2: 0,
AccidentAmount2: 0.0,
AccidentNum3: 0,
AccidentNum4: 0,
SummaryResult: 0.0,
CreatedAt: nowTime,
UpdatedAt: nowTime,
}
}
// 将审核过的事故放入汇总数据计算
summaryData.SummaryAccident(param)
//获取奖惩标准 按
rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
})
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -72,3 +72,14 @@ func (c *ProductTroubleController) ApproveProductTrouble() {
err := srv.ApproveProductTrouble(operater, int64(getQuery.Id))
c.Response(nil, err)
}
func (c *ProductTroubleController) ListRewardSummary() {
srv := service.NewProductTroubleService(nil)
getQuery := query.ListRewardSummaryQuery{}
Must(c.Unmarshal(&getQuery))
operater := ParseOperateInfo(c.BaseController)
getQuery.CompanyId = operater.CompanyId
getQuery.OrgId = operater.OrgId
total, data, err := srv.ListRewardSummary(&getQuery)
ResponseGrid(c.BaseController, total, data, err)
}
... ...
... ... @@ -12,5 +12,5 @@ func init() {
web.Router("/product_trouble/remove", &controllers.ProductTroubleController{}, "Post:DeleteProductTrouble")
web.Router("/product_trouble/search", &controllers.ProductTroubleController{}, "Post:ListProductTrouble")
web.Router("/product_trouble/approve", &controllers.ProductTroubleController{}, "Post:ApproveProductTrouble")
web.Router("/product_trouble/reward_summary/seach", &controllers.ProductTroubleController{}, "Post:ListRewardSummary")
}
... ...