|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
...
|
...
|
@@ -83,7 +84,7 @@ func (srv ProductTroubleService) SaveProductTrouble(operateInfo *domain.OperateI |
|
|
|
|
|
troubleData.AmountLoss = param.AmountLoss
|
|
|
troubleData.ProductWorker = *workerUser
|
|
|
troubleData.RecordData = recordDate
|
|
|
troubleData.RecordDate = recordDate
|
|
|
troubleData.Remark = param.Remark
|
|
|
troubleData.UpdatedAt = time.Now()
|
|
|
troubleData.WorkStation = *workStation
|
...
|
...
|
@@ -149,7 +150,7 @@ func (srv ProductTroubleService) GetProductTrouble(id int) (*dto.ProductTroubleI |
|
|
SectionId: troubleData.WorkStation.SectionId,
|
|
|
SectionName: troubleData.WorkStation.SectionName,
|
|
|
Remark: troubleData.Remark,
|
|
|
ProductDate: troubleData.RecordData.Format("2006-01-02"),
|
|
|
ProductDate: troubleData.RecordDate.Format("2006-01-02"),
|
|
|
AmountLoss: troubleData.AmountLoss,
|
|
|
Types: string(troubleData.Types),
|
|
|
WorkerId: troubleData.ProductWorker.UserId,
|
...
|
...
|
@@ -188,10 +189,7 @@ func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// func (srv ProductTroubleService) approveProductTrouble(operateInfo *domain.OperateInfo, param *domain.ProductTrouble) error {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
// 审核事故
|
|
|
func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.OperateInfo, id int64) error {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
...
|
...
|
@@ -228,6 +226,11 @@ func (srv ProductTroubleService) ApproveProductTrouble(operateInfo *domain.Opera |
|
|
if err != nil {
|
|
|
return application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
//汇总奖惩明细
|
|
|
err = srv.CreateRewardSummaryByProductTrouble(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())
|
|
|
}
|
...
|
...
|
@@ -286,7 +289,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou |
|
|
SectionId: v.WorkStation.SectionId,
|
|
|
SectionName: v.WorkStation.SectionName,
|
|
|
Remark: v.Remark,
|
|
|
ProductDate: v.RecordData.Format("2006-01-02"),
|
|
|
ProductDate: v.RecordDate.Format("2006-01-02"),
|
|
|
AmountLoss: v.AmountLoss,
|
|
|
Types: v.GetTypesName(),
|
|
|
WorkerId: v.ProductWorker.UserId,
|
...
|
...
|
@@ -415,7 +418,7 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
|
ProductWorker: *worker,
|
|
|
AmountLoss: amountLoss,
|
|
|
Types: "",
|
|
|
RecordData: recordDate,
|
|
|
RecordDate: recordDate,
|
|
|
Remark: "",
|
|
|
ApproveStatus: domain.TroubleIsApprove,
|
|
|
ApproveAt: &nowTime,
|
...
|
...
|
@@ -439,15 +442,180 @@ func (srv ProductTroubleService) BatchAddProductTrouble(operateInfo *domain.Oper |
|
|
productTroubleRepo, _ := factory.CreateProductTroubleRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
//添加事故数据
|
|
|
|
|
|
for i := range troubleDataList {
|
|
|
//添加事故数据
|
|
|
_, err = productTroubleRepo.Save(troubleDataList[i])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//汇总奖惩明细
|
|
|
err = srv.CreateRewardSummaryByProductTrouble(troubleDataList[i])
|
|
|
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 nil, nil
|
|
|
}
|
|
|
|
|
|
// 奖惩汇总数据列表
|
|
|
func (srv ProductTroubleService) ListRewardSummary(param query.ListRewardSummaryQuery) (int64, []dto.RewardSummaryList, 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()
|
|
|
}()
|
|
|
|
|
|
rewardSummaryRepo, _ := factory.CreateRewardSummaryRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
limit := param.PageSize
|
|
|
offset := param.PageSize * (param.PageNumber - 1)
|
|
|
condition := map[string]interface{}{
|
|
|
"orgId": param.OrgId,
|
|
|
"companyId": param.CompanyId,
|
|
|
"offset": offset,
|
|
|
"limit": limit,
|
|
|
}
|
|
|
//搜索条件日期
|
|
|
if len(param.BeginDate) > 0 {
|
|
|
_, err = time.Parse("2006-01-02", param.BeginDate)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
}
|
|
|
condition["beginDate"] = param.BeginDate
|
|
|
}
|
|
|
//搜索条件日期
|
|
|
if len(param.EndDate) > 0 {
|
|
|
_, err = time.Parse("2006-01-02", param.EndDate)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.ARG_ERROR, "日期格式错误")
|
|
|
}
|
|
|
condition["endDate"] = param.EndDate
|
|
|
}
|
|
|
//搜索条件 车间名称
|
|
|
if len(param.WorkshopName) > 0 {
|
|
|
condition["workshopName"] = param.WorkshopName
|
|
|
}
|
|
|
//搜索条件 线别名称
|
|
|
if len(param.LineName) > 0 {
|
|
|
condition["lineName"] = param.LineName
|
|
|
}
|
|
|
|
|
|
cnt, rewardSummaryList, err := rewardSummaryRepo.Find(condition)
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
result := []dto.RewardSummaryList{}
|
|
|
for _, v := range rewardSummaryList {
|
|
|
item := dto.RewardSummaryList{
|
|
|
Id: v.Id,
|
|
|
RecordDate: v.RecordDate.Format("2006-01-02"),
|
|
|
WorkshopName: v.WorkStation.WorkshopName,
|
|
|
LineName: v.WorkStation.LineName,
|
|
|
SectionName: v.WorkStation.SectionName,
|
|
|
Yield: fmt.Sprintf("%.2f", v.Yield),
|
|
|
UpToStandard: fmt.Sprintf("%.2f%%", v.UpToStandard),
|
|
|
Accident1: fmt.Sprintf("%d次%.2f元", v.AccidentNum1, v.AccidentAmount1),
|
|
|
Accident2: fmt.Sprintf("%d次%.2f元", v.AccidentNum2, v.AccidentAmount2),
|
|
|
Accident3: fmt.Sprintf("金属%d次,非金属%d次", v.AccidentNum3, v.AccidentNum4),
|
|
|
SummaryResult: fmt.Sprintf("%v", v.SummaryResult),
|
|
|
ResultDesc: "",
|
|
|
}
|
|
|
if v.SummaryResult == 0 {
|
|
|
item.ResultDesc = "不奖不惩"
|
|
|
} else if v.SummaryResult > 0 {
|
|
|
item.ResultDesc = "奖"
|
|
|
} else {
|
|
|
item.ResultDesc = "惩"
|
|
|
}
|
|
|
result = append(result, item)
|
|
|
}
|
|
|
return cnt, result, 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
|
|
|
} |
...
|
...
|
|