作者 Your Name

更新事故管理

... ... @@ -8,6 +8,8 @@ type ProductTroubleInfo struct {
LineName string `json:"lineName"` //
SectionId int `json:"sectionId"` //工段ID
SectionName string `json:"sectionName"` //
WorkerId int `json:"workerId"` //员工id
WorkerName string `json:"workerName"` //员工名称
Remark string `json:"remark"` //备注
ProductDate string `json:"productDate"` //日期
AmountLoss float64 `json:"amountLoss"` //损失的金额
... ...
package dto
type ProductTroubleList 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 string `json:"types"` //事故类型
WorkerId int `json:"workerId"` //员工
WorkerName string `json:"workerName"` //员工名称
ApproveStatus int `json:"approveStatus"` //审核状态
ApproveStatusName string `json:"approveStatusName"` //审核状态
}
... ...
package query
type ListProductTrouble struct {
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber"`
// 页数
PageSize int `cname:"页数" json:"pageSize"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName"`
//员工名称
WorkerName string `cname:"员工名称" json:"workerName"`
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"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/application/productTrouble/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
)
... ... @@ -137,6 +138,8 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI
ProductDate: troubleData.RecordData.Format("2006-01-02"),
AmountLoss: troubleData.AmountLoss,
Types: int(troubleData.Types),
WorkerId: troubleData.ProductWorker.UserId,
WorkerName: troubleData.ProductWorker.UserName,
}
return &result, nil
}
... ... @@ -212,3 +215,68 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera
}
return nil
}
// ListProductTrouble 事故管理列表
func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrouble) (int64, []dto.ProductTroubleList, 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()
}()
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := param.PageSize
offset := param.PageSize * (param.PageNumber - 1)
condition := map[string]interface{}{
"limit": limit,
"offsett": offset,
"companyId": param.CompanyId,
"orgId": param.OrgId,
}
if len(param.WorkerName) > 0 {
condition["productWorkerName"] = param.WorkerName
}
if len(param.WorkshopName) > 0 {
condition["workshopName"] = param.WorkshopName
}
cnt, troubleDataList, err := productTroubleRepo.Find(condition)
if err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, "事故数据不存在,"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := []dto.ProductTroubleList{}
var item dto.ProductTroubleList
for _, v := range troubleDataList {
item = dto.ProductTroubleList{
Id: v.Id,
WorkshopId: v.WorkStation.WorkshopId,
WorkshopName: v.WorkStation.WorkshopName,
LineId: v.WorkStation.LineId,
LineName: v.WorkStation.LineName,
SectionId: v.WorkStation.SectionId,
SectionName: v.WorkStation.SectionName,
Remark: v.Remark,
ProductDate: v.RecordData.Format("2006-01-02"),
AmountLoss: v.AmountLoss,
Types: v.GetTypesName(),
WorkerId: v.ProductWorker.UserId,
WorkerName: v.ProductWorker.UserName,
ApproveStatus: int(v.ApproveStatus),
ApproveStatusName: v.GetApproveStatusName(),
}
result = append(result, item)
}
return cnt, result, nil
}
... ...
... ... @@ -8,12 +8,12 @@ import (
// 事故管理数据结构
type ProductTrouble struct {
Id int `json:"id"` // id
CompanyId int `json:"companyId"` //企业id
OrgId int `json:"orgId"` //组织ID
CompanyId int `json:"companyId"` // 企业id
OrgId int `json:"orgId"` // 组织ID
WorkStation WorkStation `json:"workStation"` // 工作位置
ProductWorker User `json:"productWorker,omitempty"` // 生产工人
AmountLoss float64 `json:"amountLoss"` // 损失的金额
Types TroubleType `json:"types"` // 事故类型
Types TroubleType `json:"types"` // 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故
RecordData time.Time `json:"recordData"` // 事故发生的日期
Remark string `json:"remakr"` // 备注
ApproveStatus ProductTroubleApprove `json:"approveStatus"` // 审核状态 1:未审核 2:已审核 3.自动审核
... ... @@ -75,3 +75,27 @@ func (m *ProductTrouble) Approve(approveUser *User) error {
}
return nil
}
func (m *ProductTrouble) GetApproveStatusName() string {
switch m.ApproveStatus {
case TroubleWaitApprove:
return "未审核"
case TroubleIsApprove:
return "已审核"
}
return ""
}
func (m *ProductTrouble) GetTypesName() string {
switch m.Types {
case TroubleType1:
return "安全事故"
case TroubleType2:
return "质量事故"
case TroubleType3:
return "金属事故"
case TroubleType4:
return "非金属事故"
}
return ""
}
... ...
... ... @@ -53,6 +53,7 @@ func init() {
(*models.ProductMaterial)(nil),
(*models.RewardStandard)(nil),
(*models.RewardRule)(nil),
(*models.ProductTrouble)(nil),
} {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -102,14 +102,29 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{})
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
if v, ok := queryOptions["limit"].(int); ok {
if v, ok := queryOptions["limit"].(int); ok && v > 0 {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
if v, ok := queryOptions["offset"].(int); ok && v >= 0 {
query.Offset(v)
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["orgId"]; ok {
query.Where("org_id=?", v)
}
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(`Work_station->>'workshopName' like '%?%'`, v)
}
if v, ok := queryOptions["productWorkerName"]; ok {
query.Where(`product_worker->>'userName' like '%?%'`, v)
}
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -114,6 +114,12 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{})
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["orgId"]; ok {
query.Where("org_id=?", v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
... ...
... ... @@ -43,10 +43,22 @@ func (c *ProductTroubleController) GetProductTrouble() {
}
// 删除事故记录
func (c RewardStandardController) DeleteProductTrouble() {
func (c *ProductTroubleController) DeleteProductTrouble() {
srv := service.NewProductTroubleService(nil)
getQuery := &query.GetProductTroubleQuery{}
Must(c.Unmarshal(getQuery))
err := srv.DeleteProductTrouble(int64(getQuery.Id))
c.Response(nil, err)
}
// 获取事故记录列表
func (c *ProductTroubleController) ListProductTrouble() {
srv := service.NewProductTroubleService(nil)
getQuery := query.ListProductTrouble{}
Must(c.Unmarshal(&getQuery))
operater := ParseOperateInfo(c.BaseController)
getQuery.CompanyId = operater.CompanyId
getQuery.OrgId = operater.OrgId
total, data, err := srv.ListProductTrouble(&getQuery)
ResponseGrid(c.BaseController, total, data, err)
}
... ...
... ... @@ -10,5 +10,5 @@ func init() {
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")
web.Router("/product_trouble/search", &controllers.ProductTroubleController{}, "Post:ListProductTrouble")
}
... ...