作者 Your Name

更新事故管理

... ... @@ -173,3 +173,11 @@ func CreateRewardRuleRepository(options map[string]interface{}) (domain.RewardRu
}
return repository.NewRewardRuleRepository(transactionContext)
}
func CreateProductTroubleRepository(options map[string]interface{}) (domain.ProductTroubleRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProductTroubleRepository(transactionContext)
}
... ...
package command
//创建事故记录
type CreatedProductTroubleCommand struct{}
type SaveProductTroubleCommand struct {
Id int `json:"id"` //id
WorkshopId int `json:"workshopId" valid:"Required"` //车间id
LineId int `json:"lineId" valid:"Required"` //生产线ID
SectionId int `json:"sectionId" valid:"Required"` //工段ID
WorkerId int `json:"workerId"` //员工id
Remark string `json:"remark"` //备注
AmountLoss float64 `json:"amountLoss"` // 损失的金额
Types int `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
RecordDate string `json:"recordDate"` // 事故发生的日期
}
... ...
package dto
type ProductTroubleInfo struct {
Id int `json:"id"` //id
WorkshopId int `json:"workshopId"` //车间id
WorkshopName string `json:"workshopName"` //
LineId int `json:"lineId"` //生产线ID
LineName string `json:"lineName"` //
SectionId int `json:"sectionId"` //工段ID
SectionName string `json:"sectionName"` //
Remark string `json:"remark"` //备注
ProductDate string `json:"productDate"` //日期
AmountLoss float64 `json:"amountLoss"` //损失的金额
Types int `json:"types"` //事故类型
}
... ...
package service
import (
"time"
"github.com/linmadan/egglib-go/core/application"
"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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
)
// 事故管理
... ... @@ -14,7 +19,7 @@ func NewProductTroubleService(options map[string]interface{}) *ProductTroubleSer
return newService
}
func (srv ProductTroubleService) SaveProductTrouble(param *command.CreatedProductTroubleCommand) (map[string]interface{}, error) {
func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateInfo, param *command.SaveProductTroubleCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -26,15 +31,76 @@ func (srv ProductTroubleService) SaveProductTrouble(param *command.CreatedProduc
transactionContext.RollbackTransaction()
}()
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
workShopRepo, _ := factory.CreateWorkshopRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取车间数据
workShopData, err := workShopRepo.FindOne(map[string]interface{}{
"workshopId": param.WorkshopId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "车间数据不能存在"+err.Error())
}
if workShopData.CompanyId != operateInfo.CompanyId {
return nil, application.ThrowError(application.ARG_ERROR, "车间数据填写错误")
}
workStation, err := workShopData.FindWorkStation(param.WorkshopId, param.LineId, param.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
var workerUser *domain.User
userService := domainService.NewUserService()
workerUser, err = userService.User(param.WorkerId)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工信息失败,"+err.Error())
}
recordDate, err := time.ParseInLocation("2006-01-02", param.RecordDate, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
}
var troubleData *domain.ProductTrouble
if param.Id > 0 {
troubleData, err = productTroubleRepo.FindOne(map[string]interface{}{
"id": param.Id,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "事故数据填写错误")
}
} else {
troubleData = &domain.ProductTrouble{
CompanyId: operateInfo.CompanyId,
OrgId: operateInfo.OrgId,
CreatedAt: time.Now(),
ApproveStatus: domain.TroubleWaitApprove,
}
}
troubleData.AmountLoss = param.AmountLoss
troubleData.ProductWorker = *workerUser
troubleData.RecordData = recordDate
troubleData.Remark = param.Remark
troubleData.UpdatedAt = time.Now()
troubleData.WorkStation = *workStation
err = troubleData.SetTypes(param.Types)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
_, err = productTroubleRepo.Save(troubleData)
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{}{
"id": 0,
"id": troubleData.Id,
}, nil
}
func (srv ProductTroubleService) GetProductTrouble(id int64) (map[string]interface{}, error) {
func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleInfo, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -46,12 +112,33 @@ func (srv ProductTroubleService) GetProductTrouble(id int64) (map[string]interfa
transactionContext.RollbackTransaction()
}()
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
"id": id,
})
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{}{
"id": 0,
}, nil
result := dto.ProductTroubleInfo{
Id: troubleData.Id,
WorkshopId: troubleData.WorkStation.WorkshopId,
WorkshopName: troubleData.WorkStation.WorkshopName,
LineId: troubleData.WorkStation.LineId,
LineName: troubleData.WorkStation.LineName,
SectionId: troubleData.WorkStation.SectionId,
SectionName: troubleData.WorkStation.SectionName,
Remark: troubleData.Remark,
ProductDate: troubleData.RecordData.Format("2006-01-02"),
AmountLoss: troubleData.AmountLoss,
Types: int(troubleData.Types),
}
return &result, nil
}
func (srv ProductTroubleService) DeleteProductTrouble(id int64) error {
... ... @@ -65,14 +152,26 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error {
defer func() {
transactionContext.RollbackTransaction()
}()
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
"id": id,
})
if err != nil {
return application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
}
_, err = productTroubleRepo.Remove(troubleData)
if err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
func (srv ProductTroubleService) ApproveProductTrouble(id int64) error {
func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -83,7 +182,31 @@ func (srv ProductTroubleService) ApproveProductTrouble(id int64) error {
defer func() {
transactionContext.RollbackTransaction()
}()
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
troubleData, err := productTroubleRepo.FindOne(map[string]interface{}{
"id": id,
})
if err != nil {
return application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
}
var approveUser *domain.User
userService := domainService.NewUserService()
approveUser, err = userService.User(operateInfo.UserId)
if err != nil {
return application.ThrowError(application.ARG_ERROR, "获取审核人信息失败,"+err.Error())
}
err = troubleData.Approve(approveUser)
if err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
troubleData.UpdatedAt = time.Now()
_, err = productTroubleRepo.Save(troubleData)
if err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -11,7 +11,7 @@ type ProductTrouble struct {
CompanyId int `json:"companyId"` //企业id
OrgId int `json:"orgId"` //组织ID
WorkStation WorkStation `json:"workStation"` // 工作位置
ProductWorker *User `json:"productWorker,omitempty"` // 生产工人
ProductWorker User `json:"productWorker,omitempty"` // 生产工人
AmountLoss float64 `json:"amountLoss"` // 损失的金额
Types TroubleType `json:"types"` // 事故类型
RecordData time.Time `json:"recordData"` // 事故发生的日期
... ... @@ -63,7 +63,7 @@ func (m *ProductTrouble) SetTypes(v int) error {
}
// 审核事故数据
func (m *ProductTrouble) Approve() error {
func (m *ProductTrouble) Approve(approveUser *User) error {
nowTime := time.Now()
switch m.ApproveStatus {
case TroubleIsApprove:
... ... @@ -71,6 +71,7 @@ func (m *ProductTrouble) Approve() error {
default:
m.ApproveAt = &nowTime
m.ApproveStatus = TroubleIsApprove
m.ApproveUser = approveUser
}
return nil
}
... ...
... ... @@ -13,7 +13,7 @@ type ProductTrouble struct {
CompanyId int //企业id
OrgId int //组织ID
WorkStation domain.WorkStation // 工作位置
ProductWorker *domain.User // 生产工人
ProductWorker domain.User // 生产工人
AmountLoss float64 // 损失的金额
Types int // 事故类型
RecordData time.Time // 事故发生的日期
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/service"
)
type ProductTroubleController struct {
beego.BaseController
}
// 创建事故记录
func (c *ProductTroubleController) CreatedProductTrouble() {
srv := service.NewProductTroubleService(nil)
createCommand := &command.SaveProductTroubleCommand{}
Must(c.Unmarshal(createCommand))
operater := ParseOperateInfo(c.BaseController)
data, err := srv.SaveProductTrouble(operater, createCommand)
c.Response(data, err)
}
// 更新事故记录
func (c *ProductTroubleController) UpdateProductTrouble() {
srv := service.NewProductTroubleService(nil)
createCommand := &command.SaveProductTroubleCommand{}
Must(c.Unmarshal(createCommand))
id, _ := c.GetInt(":id")
createCommand.Id = id
operater := ParseOperateInfo(c.BaseController)
data, err := srv.SaveProductTrouble(operater, createCommand)
c.Response(data, err)
}
// 获取事故记录
func (c *ProductTroubleController) GetProductTrouble() {
srv := service.NewProductTroubleService(nil)
id, _ := c.GetInt(":id")
data, err := srv.GetProductTrouble(id)
c.Response(data, err)
}
// 删除事故记录
func (c RewardStandardController) DeleteProductTrouble() {
srv := service.NewProductTroubleService(nil)
getQuery := &query.GetProductTroubleQuery{}
Must(c.Unmarshal(getQuery))
err := srv.DeleteProductTrouble(int64(getQuery.Id))
c.Response(nil, err)
}
... ...
... ... @@ -11,8 +11,8 @@ type RewardStandardController struct {
beego.BaseController
}
//创建奖惩标准
func (c RewardStandardController) CreatedRewardStandard() {
// 创建奖惩标准
func (c *RewardStandardController) CreatedRewardStandard() {
srv := service.NewRewardStandardService(nil)
createCommand := &command.SaveRewardStandardCommand{}
Must(c.Unmarshal(createCommand))
... ... @@ -21,8 +21,8 @@ func (c RewardStandardController) CreatedRewardStandard() {
c.Response(data, err)
}
//更新奖惩标准
func (c RewardStandardController) UpdateRewardStandard() {
// 更新奖惩标准
func (c *RewardStandardController) UpdateRewardStandard() {
srv := service.NewRewardStandardService(nil)
createCommand := &command.SaveRewardStandardCommand{}
Must(c.Unmarshal(createCommand))
... ... @@ -33,8 +33,8 @@ func (c RewardStandardController) UpdateRewardStandard() {
c.Response(data, err)
}
//获取奖惩标准
func (c RewardStandardController) GetRewardStandard() {
// 获取奖惩标准
func (c *RewardStandardController) GetRewardStandard() {
srv := service.NewRewardStandardService(nil)
id, _ := c.GetInt(":id")
getQuery := &query.GetRewardStandard{
... ... @@ -45,8 +45,8 @@ func (c RewardStandardController) GetRewardStandard() {
c.Response(data, err)
}
//删除奖惩标准
func (c RewardStandardController) DeleteRewardStandard() {
// 删除奖惩标准
func (c *RewardStandardController) DeleteRewardStandard() {
srv := service.NewRewardStandardService(nil)
getQuery := &query.GetRewardStandard{}
Must(c.Unmarshal(getQuery))
... ... @@ -55,8 +55,8 @@ func (c RewardStandardController) DeleteRewardStandard() {
c.Response(data, err)
}
//列表展示奖惩标准
func (c RewardStandardController) ListRewardStandard() {
// 列表展示奖惩标准
func (c *RewardStandardController) ListRewardStandard() {
srv := service.NewRewardStandardService(nil)
cmd := &query.ListRewardStandard{}
Must(c.Unmarshal(cmd))
... ... @@ -66,8 +66,8 @@ func (c RewardStandardController) ListRewardStandard() {
ResponseGrid(c.BaseController, total, data, err)
}
//SaveRewardRule 保存奖惩规则
func (c RewardStandardController) SaveRewardRule() {
// SaveRewardRule 保存奖惩规则
func (c *RewardStandardController) SaveRewardRule() {
srv := service.NewRewardStandardService(nil)
createCommand := &command.SaveRewardRuleCommand{}
Must(c.Unmarshal(createCommand))
... ... @@ -76,8 +76,8 @@ func (c RewardStandardController) SaveRewardRule() {
c.Response(data, err)
}
//GetRewardRule 获取奖惩规则
func (c RewardStandardController) GetRewardRule() {
// GetRewardRule 获取奖惩规则
func (c *RewardStandardController) GetRewardRule() {
srv := service.NewRewardStandardService(nil)
operater := ParseOperateInfo(c.BaseController)
data, err := srv.GetRewardRule(operater)
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
)
func init() {
web.Router("/product_trouble/", &controllers.ProductTroubleController{}, "Post:CreatedProductTrouble")
web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Put:UpdateProductTrouble")
web.Router("/product_trouble/:id", &controllers.ProductTroubleController{}, "Get:GetProductTrouble")
web.Router("/product_trouble/remove", &controllers.ProductTroubleController{}, "Post:DeleteProductTrouble")
// web.Router("/reward-standard/search", &controllers.RewardStandardController{}, "Post:ListRewardStandard")
}
... ...