作者 Your Name

更新奖惩汇总统计

... ... @@ -159,13 +159,33 @@ func (m *RewardStandard) ShowTargeFault() string {
}
// 判定功过, 指标类别 1:产效
func (m *RewardStandard) VerdictTargetType1(val1 int, val float64) int {
return 0
// param1 产效值
// 功过结果 0 无,1 功 ,-1 过;
func (m *RewardStandard) VerdictTargetType1(param1 float64) int {
val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
result := 0
if param1 > val1 {
result = 1
} else if param1 < val2 {
result = -1
}
return result
}
// 判定功过, 指标类别 2:合格率
func (m *RewardStandard) VerdictTargetType2(val1 int, val float64) int {
return 0
// param1 合格率
// 功过结果 0 无,1 功 ,-1 过;
func (m *RewardStandard) VerdictTargetType2(param1 float64) int {
val1, _ := strconv.ParseFloat(m.TargeVal1, 64)
val2, _ := strconv.ParseFloat(m.TargeVal2, 64)
result := 0
if param1 > val1 {
result = 1
} else if param1 < val2 {
result = -1
}
return result
}
// 判定功过, 指标类别 3:安全事故;
... ...
... ... @@ -24,9 +24,8 @@ type RewardSummary struct {
AccidentAmount2 float64 `json:"accidentAmount2"` //安全事故 损失金额
AccidentResult2 int `json:"accidentResult2"` //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum3 int `json:"accidentNum3"` //异物金属事故 次数
AccidentResult3 int `json:"accidentResult3"` //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum4 int `json:"accidentNum4"` //异物非金属事故 次数
AccidentResult4 int `json:"accidentResult4"` //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentResult3 int `json:"accidentResult3"` //异物事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum4 int `json:"accidentNum4"` //异物非金属事故次数
SummaryResult float64 `json:"summaryResult"` //奖惩金额计算结果(元)
CreatedAt time.Time `json:"createdAt"` //
UpdatedAt time.Time `json:"UpdatedAt"` //
... ... @@ -72,9 +71,7 @@ func (c *RewardSummary) SummaryAccident(trouble *ProductTrouble, rewardStandard
case TroubleType4:
c.AccidentNum4 = +1
if rewardStandard == nil {
c.AccidentResult4 = 0
} else {
if rewardStandard != nil {
r := rewardStandard.VerdictTargetType5(0, c.AccidentNum4)
c.AccidentResult2 = r
}
... ... @@ -99,11 +96,6 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
} else if c.AccidentResult3 > 0 {
rewardNum = +1
}
if c.AccidentResult4 < 0 {
faultNum = +1
} else if c.AccidentResult4 > 0 {
rewardNum = +1
}
if c.YieldResult < 0 {
faultNum = +1
} else if c.YieldResult > 0 {
... ... @@ -118,3 +110,25 @@ func (c *RewardSummary) ApplySummaryResult(rule *RewardRule) {
c.SummaryResult = rule.SumRewardAmount(rewardNum, faultNum)
}
// SummaryYield 汇总产效数据
func (c *RewardSummary) SummaryYield(yield float64, rewardStandard *RewardStandard) {
c.Yield = yield
if rewardStandard == nil {
c.YieldResult = 0
} else {
r := rewardStandard.VerdictTargetType1(c.Yield)
c.YieldResult = r
}
}
// SummaryUpToStandard 汇总合格率数据
func (c *RewardSummary) SummaryUpToStandard(param float64, rewardStandard *RewardStandard) {
c.UpToStandard = param
if rewardStandard == nil {
c.UpToStandard = 0
} else {
r := rewardStandard.VerdictTargetType2(c.Yield)
c.UpToStandardResult = r
}
}
... ...
... ... @@ -53,6 +53,49 @@ func (d *RewardSumaryDao) SeachRewardSummaryDay(companyId int, orgId int, record
tx := d.transactionContext.PgTx
var result []RewardSummaryDay
_, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
for i := range result {
switch result[i].AccidentResult1 {
case "1":
result[i].AccidentResult1 = "功"
case "0":
result[i].AccidentResult1 = "不奖不惩"
case "-1":
result[i].AccidentResult1 = "过"
}
switch result[i].AccidentResult2 {
case "1":
result[i].AccidentResult2 = "功"
case "0":
result[i].AccidentResult2 = "不奖不惩"
case "-1":
result[i].AccidentResult2 = "过"
}
switch result[i].AccidentResult3 {
case "1":
result[i].AccidentResult3 = "功"
case "0":
result[i].AccidentResult3 = "不奖不惩"
case "-1":
result[i].AccidentResult3 = "过"
}
switch result[i].UpToStandardResult {
case "1":
result[i].UpToStandardResult = "功"
case "0":
result[i].UpToStandardResult = "不奖不惩"
case "-1":
result[i].UpToStandardResult = "过"
}
switch result[i].YieldResult {
case "1":
result[i].YieldResult = "功"
case "0":
result[i].YieldResult = "不奖不惩"
case "-1":
result[i].YieldResult = "过"
}
}
return result, err
}
... ... @@ -68,20 +111,61 @@ type RewardSummaryYield struct {
// 功过看板-产效
func (d *RewardSumaryDao) SeachRewardSummaryYield(companyId int, orgId int, recordDate string) ([]RewardSummaryYield, error) {
sqlStr := `SELECT
record_date_str,
work_station->>'sectionName' as section_name,
worker->>'userName' as worker_name,
yield_result,
yield,
'24' as yield_max
// sqlStr := `SELECT
// record_date_str,
// work_station->>'sectionName' as section_name,
// worker->>'userName' as worker_name,
// yield_result,
// yield,
// '24' as yield_max
// FROM manufacture."reward_summary"
// WHERE company_id=?
// and org_id=?
// and record_date_str=?`
sqlStr := `with
t1 as( SELECT
max(yield) as yield_max,
work_station->>'sectionId' AS section_id,
worker->>'userId' as worker_id
FROM manufacture."reward_summary"
WHERE company_id=?
and org_id=?
and record_date_str=?`
WHERE company_id=? and org_id=?
GROUP BY section_id,worker_id
),
t2 as (SELECT
record_date_str,
work_station->>'sectionId' AS section_id,
worker->>'userId' as worker_id,
work_station->>'sectionName' as section_name,
worker->>'userName' as worker_name,
yield_result,
yield
FROM manufacture."reward_summary"
WHERE company_id=? and org_id=?
and record_date_str=?
)
SELECT t2.record_date_str,t2.section_name,t2.worker_name,
t2.yield_result,t2.yield,t1.yield_max
FROM t2
JOIN t1 on t2.section_id=t1.section_id AND t2.worker_id=t2.worker_id`
tx := d.transactionContext.PgTx
var result []RewardSummaryYield
_, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
params := []interface{}{
companyId, orgId,
companyId, orgId, recordDate,
}
_, err := tx.Query(&result, sqlStr, params...)
for i := range result {
switch result[i].YieldResult {
case "1":
result[i].YieldResult = "功"
case "0":
result[i].YieldResult = "不奖不惩"
case "-1":
result[i].YieldResult = "过"
}
}
return result, err
}
... ... @@ -98,35 +182,77 @@ type RewardSummaryUpToStandard struct {
// 功过看板-合格率
func (d *RewardSumaryDao) SeachRewardUpToStandard(companyId int, orgId int, recordDate string) ([]RewardSummaryUpToStandard, error) {
sqlStr := `SELECT
record_date_str,
work_station->>'sectionName' as section_name,
worker->>'userName' as worker_name,
up_to_standard_result,
up_to_standard,
'90' as up_to_standard_max
// sqlStr := `SELECT
// record_date_str,
// work_station->>'sectionName' as section_name,
// worker->>'userName' as worker_name,
// up_to_standard_result,
// up_to_standard,
// '90' as up_to_standard_max
// FROM manufacture."reward_summary"
// WHERE company_id=23
// and org_id=487
// and record_date_str='2022-10-29'`
sqlStr := `with
t1 as( SELECT
max(up_to_standard) as up_to_standard_max,
work_station->>'sectionId' AS section_id,
worker->>'userId' as worker_id
FROM manufacture."reward_summary"
WHERE company_id=23
and org_id=487
and record_date_str='2022-10-29'`
WHERE company_id=? and org_id=?
GROUP BY section_id,worker_id
),
t2 as (SELECT
record_date_str,
work_station->>'sectionId' AS section_id,
worker->>'userId' as worker_id,
work_station->>'sectionName' as section_name,
worker->>'userName' as worker_name,
up_to_standard_result,
up_to_standard
FROM manufacture."reward_summary"
WHERE company_id=? and org_id=?
and record_date_str=?
)
SELECT t2.record_date_str,t2.section_name,t2.worker_name,
t2.up_to_standard_result,t2.up_to_standard,t1.up_to_standard_max
FROM t2
JOIN t1 on t2.section_id=t1.section_id AND t2.worker_id=t2.worker_id`
tx := d.transactionContext.PgTx
var result []RewardSummaryUpToStandard
_, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
params := []interface{}{
companyId, orgId,
companyId, orgId, recordDate,
}
_, err := tx.Query(&result, sqlStr, params...)
for i := range result {
switch result[i].UpToStandardResult {
case "1":
result[i].UpToStandardResult = "功"
case "0":
result[i].UpToStandardResult = "不奖不惩"
case "-1":
result[i].UpToStandardResult = "过"
}
}
return result, err
}
// 功过看板-异常
type RewardAccident struct {
Id string `json:"id"`
RecordDateStr string `json:"record_date_str"`
SectionName string `json:"sectionName"` //工段名称
WorkerName string `json:"workerName"` //员工名称
SummaryResult string `json:"summaryResult"` //奖惩结果
YieldResult string `json:"yieldResult"` //产效功过结果
UpToStandardResult string `json:"upToStandardResult"` //合格率功过结果
AccidentResult1 string `json:"accidentResult1"` //质量事故功过结果
AccidentResult2 string `json:"accidentResul2"` //安全事故功过结果
AccidentResult3 string `json:"accidentResul3"` //异物 功过结果
Id string `json:"id"`
RecordDateStr string `json:"record_date_str"`
SectionName string `json:"sectionName"` //工段名称
WorkerName string `json:"workerName"` //员工名称
AccidentAmount1 string `json:"accidentAmount1"` //质量事故损失金额
AccidentNum1 string `json:"accidentNum1"` //质量事故次数
AccidentResult1 string `json:"accidentResult1"` //质量事故功过结果
AccidentAmount2 string `json:"accidentAmount2"` //安全事故 损失金额
AccidentResult2 string `json:"accidentResul2"` //安全事故功过结果
AccidentNum2 string `json:"accidentNum2"` //安全事故 次数
AccidentNum3 string `json:"accidentNum3"` //金属异物 次数
AccidentNum4 string `json:"accidentNum4"` //非属异物事故次数
AccidentResult3 string `json:"accidentResul3"` //异物 功过结果
}
// 功过看板-异常
... ... @@ -135,9 +261,9 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa
"id",record_date_str,
work_station->>'sectionName' as section_name,
worker->>'userName' as worker_name,
up_to_standard_result,
up_to_standard,
'90' as up_to_standard_max
accident_num1,accident_amount1,accident_result1,
accident_num2,accident_amount2,accident_result2,
accident_num3,accident_num4,accident_result3
FROM manufacture."reward_summary"
WHERE company_id=?
and org_id=?
... ... @@ -145,10 +271,37 @@ func (d *RewardSumaryDao) SeachRewardAccident(companyId int, orgId int, recordDa
tx := d.transactionContext.PgTx
var result []RewardAccident
_, err := tx.Query(&result, sqlStr, companyId, orgId, recordDate)
for i := range result {
switch result[i].AccidentResult1 {
case "1":
result[i].AccidentResult1 = "功"
case "0":
result[i].AccidentResult1 = "不奖不惩"
case "-1":
result[i].AccidentResult1 = "过"
}
switch result[i].AccidentResult2 {
case "1":
result[i].AccidentResult2 = "功"
case "0":
result[i].AccidentResult2 = "不奖不惩"
case "-1":
result[i].AccidentResult2 = "过"
}
switch result[i].AccidentResult3 {
case "1":
result[i].AccidentResult3 = "功"
case "0":
result[i].AccidentResult3 = "不奖不惩"
case "-1":
result[i].AccidentResult3 = "过"
}
}
return result, err
}
// 功过看板-异常
// 功过看板-月榜
type RewardSummaryMonth struct {
SectionId string `json:"sectionId"` //工段名称
SectionName string `json:"sectionName"` //工段名称
... ... @@ -170,32 +323,35 @@ type RewardSummaryMonth struct {
// 功过看板-月榜
func (d *RewardSumaryDao) SeachRewardSummaryMonth(companyId int, orgId int, recordMonth string) ([]RewardSummaryMonth, error) {
sqlStr := `SELECT
work_station->>'sectionId' AS section_id,
work_station->>'sectionName' as section_name,
worker->>'userId' as worker_id,
worker->>'userName' as worker_name,
count(accident_num1) as accident_num1,
count(accident_num2) as accident_num2,
count(accident_num3) as accident_num3,
count(accident_num4) as accident_num4,
count(accident_amount1) as accident_amount1,
count(accident_amount2) as accident_amount2,
'12' as yield_avg,
'13' as yield_max,
'-39' as amount_fine,
'25' as amount_reward,
'-14' as amount_final,
'12' as up_to_standard,
FROM manufacture.reward_summary
WHERE company_id=?
and org_id=?
and record_month_str=?
GROUP BY
worker->>'userId' ,
worker->>'userName' ,
work_station->>'sectionId',
work_station->>'sectionName' `
sqlStr := `
SELECT
work_station->>'sectionId' AS section_id,
work_station->>'sectionName' as section_name,
worker->>'userId' as worker_id,
worker->>'userName' as worker_name,
sum(accident_num1) as accident_num1,
sum(accident_num2) as accident_num2,
sum(accident_num3) as accident_num3,
sum(accident_num4) as accident_num4,
sum(accident_amount1) as accident_amount1,
sum(accident_amount2) as accident_amount2,
CAST(sum(summary_result) as decimal(10,2)) as amount_final,
CAST(
sum(CASE WHEN summary_result<0 THEN summary_result ELSE 0 END) as decimal(10,2)
) as amount_fine,
CAST(
sum(CASE WHEN summary_result>0 THEN summary_result ELSE 0 END) as decimal(10,2)
) as amount_reward,
max(yield) as yield_max,
CAST(avg(yield) as decimal(10,2)) as yield_avg,
CAST(avg(up_to_standard) as decimal(10,2) ) as up_to_standard
FROM manufacture.reward_summary
WHERE company_id=?
and org_id=?
and record_month_str=?
GROUP BY section_id,worker_id,worker_name,section_name
;
`
tx := d.transactionContext.PgTx
var result []RewardSummaryMonth
_, err := tx.Query(&result, sqlStr, companyId, orgId, recordMonth)
... ...
... ... @@ -112,10 +112,121 @@ func (c *PGRewardSummaryStaticService) CreateRewardSummaryByProductTrouble(param
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
}
if len(rewardRuleList) == 0 {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "未设置奖惩规则")
if len(rewardRuleList) >= 0 {
summaryData.ApplySummaryResult(rewardRuleList[0])
}
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
// CreateRewardSummaryByEmployeeProductRecord 通过员工生产记录 汇总奖惩结果
func (c *PGRewardSummaryStaticService) CreateRewardSummaryByEmployeeProductRecord(param *domain.EmployeeProductRecord) 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.CreatedAt.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.CreatedAt,
RecordDateStr: param.CreatedAt.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,
}
if param.WorkStation != nil {
summaryData.WorkStation = *param.WorkStation
}
if param.ProductWorker != nil {
summaryData.Worker = *param.ProductWorker
}
}
//获取奖惩标准 按 车间 线别 工段 类型 ;合格率类型
rewardStandardRepo, _ := repository.NewRewardStandardRepository(c.transactionContext)
_, rewardStandardList, err := rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
"workshopId": param.WorkStation.WorkshopId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"targetType": domain.TargetType2,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(rewardStandardList) > 0 {
//汇总合格率
summaryData.SummaryUpToStandard(param.ProductRecordInfo.QualificationRate, rewardStandardList[0])
} else {
summaryData.SummaryUpToStandard(param.ProductRecordInfo.QualificationRate, nil)
}
//获取奖惩标准 按 车间 线别 工段 类型 ;产能类型
_, rewardStandardList, err = rewardStandardRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
"workshopId": param.WorkStation.WorkshopId,
"lineId": param.WorkStation.LineId,
"sectionId": param.WorkStation.SectionId,
"targetType": domain.TargetType1,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(rewardStandardList) > 0 {
//汇总合格率
summaryData.SummaryYield(param.ProductRecordInfo.OutputWeight, rewardStandardList[0])
} else {
summaryData.SummaryYield(param.ProductRecordInfo.OutputWeight, nil)
}
//根据规则算 奖惩金额
//获取奖惩规则
rewardRuleRepo, _ := repository.NewRewardRuleRepository(c.transactionContext)
_, rewardRuleList, err := rewardRuleRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"orgId": param.OrgId,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取奖惩规则"+err.Error())
}
if len(rewardRuleList) >= 0 {
summaryData.ApplySummaryResult(rewardRuleList[0])
}
summaryData.ApplySummaryResult(rewardRuleList[0])
summaryData.UpdatedAt = nowTime
_, err = rewardSummaryRepo.Save(summaryData)
if err != nil {
... ...
... ... @@ -17,21 +17,20 @@ type RewardSummary struct {
RecordMonthStr string //月份 :200601
WorkStation domain.WorkStation // 工作位置
Worker domain.User //员工
UpToStandard float64 //合格率
UpToStandardResult int //合格率 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
Yield float64 //产能
YieldResult int //产能 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum1 int //质量事故 次数
AccidentAmount1 float64 //质量事故 损失金额
AccidentResult1 int //质量事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum2 int //安全事故 次数
AccidentAmount2 float64 //安全事故 损失金额
AccidentResult2 int //安全事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum3 int //异物金属事故 次数
AccidentResult3 int //异物金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
AccidentNum4 int //异物非金属事故 次数
AccidentResult4 int //异物非金属事故 功过评定结果 1`功` -1 `过` 0 `不奖不惩`
SummaryResult float64 //奖惩金额计算结果(元)
UpToStandard float64 `comment:"合格率"` //合格率
UpToStandardResult int `comment:"合格率功过评定结果 1:功 -1:过 0:不奖不惩"` //合格率功过评定结果1:功 -1:过 0:不奖不惩
Yield float64 `comment:"产能"` //产能
YieldResult int `comment:"产能功过评定结果,1:功 -1:过 0:不奖不惩"` //产能功过评定结果,1:功 -1:过 0:不奖不惩
AccidentNum1 int `comment:"质量事故 次数"` //质量事故 次数
AccidentAmount1 float64 `comment:"质量事故 损失金额"` //质量事故 损失金额
AccidentResult1 int `comment:"质量事故 功过评定结果1:功 -1:过 0:不奖不惩"` //质量事故 功过评定结果1:功 -1:过 0:不奖不惩
AccidentNum2 int `comment:"安全事故 次数"` //安全事故 次数
AccidentAmount2 float64 `comment:"安全事故 损失金额"` //安全事故 损失金额
AccidentResult2 int `comment:"安全事故 功过评定结果 1:功 -1:过 0:不奖不惩"` //安全事故 功过评定结果 1:功 -1:过 0:不奖不惩
AccidentNum3 int `comment:"异物金属事故 次数"` //异物金属事故 次数
AccidentResult3 int `comment:"异物事故 功过评定结果 1:功 -1:过 0:不奖不惩"` //异物事故 功过评定结果 1:功 -1:过 0:不奖不惩
AccidentNum4 int `comment:"异物非金属事故 次数"` //异物非金属事故 次数
SummaryResult float64 `comment:"奖惩金额计算结果(元)"` //奖惩金额计算结果(元)
CreatedAt time.Time //
UpdatedAt time.Time //
... ...