正在显示
3 个修改的文件
包含
369 行增加
和
6 行删除
| @@ -18,7 +18,7 @@ func NewRewardStandardService(options map[string]interface{}) *RewardStandardSer | @@ -18,7 +18,7 @@ func NewRewardStandardService(options map[string]interface{}) *RewardStandardSer | ||
| 18 | return newService | 18 | return newService |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | -//SaveRewardStandard 保存奖惩标准数据 | 21 | +// SaveRewardStandard 保存奖惩标准数据 |
| 22 | func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) { | 22 | func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) { |
| 23 | if err := param.ValidateCommand(); err != nil { | 23 | if err := param.ValidateCommand(); err != nil { |
| 24 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 24 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| @@ -120,7 +120,7 @@ func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateI | @@ -120,7 +120,7 @@ func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateI | ||
| 120 | return param, nil | 120 | return param, nil |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | -//GetRewardStandard 根据id获取奖惩标准数据 | 123 | +// GetRewardStandard 根据id获取奖惩标准数据 |
| 124 | func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) { | 124 | func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) { |
| 125 | transactionContext, err := factory.CreateTransactionContext(nil) | 125 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 126 | if err != nil { | 126 | if err != nil { |
| @@ -167,7 +167,7 @@ func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateIn | @@ -167,7 +167,7 @@ func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateIn | ||
| 167 | return &result, nil | 167 | return &result, nil |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | -//DeleteRewardStandard 根据id删除奖惩标准 | 170 | +// DeleteRewardStandard 根据id删除奖惩标准 |
| 171 | func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*domain.RewardStandard, error) { | 171 | func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*domain.RewardStandard, error) { |
| 172 | transactionContext, err := factory.CreateTransactionContext(nil) | 172 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 173 | if err != nil { | 173 | if err != nil { |
| @@ -203,6 +203,7 @@ func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.Operat | @@ -203,6 +203,7 @@ func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.Operat | ||
| 203 | return rewardStandardData, nil | 203 | return rewardStandardData, nil |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | +// ListRewardStandard 奖惩标准列表 | ||
| 206 | func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStandard) (int64, []dto.RewardStandardList, error) { | 207 | func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStandard) (int64, []dto.RewardStandardList, error) { |
| 207 | transactionContext, err := factory.CreateTransactionContext(nil) | 208 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 208 | if err != nil { | 209 | if err != nil { |
| @@ -247,7 +248,7 @@ func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStand | @@ -247,7 +248,7 @@ func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStand | ||
| 247 | if err := transactionContext.CommitTransaction(); err != nil { | 248 | if err := transactionContext.CommitTransaction(); err != nil { |
| 248 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 249 | return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 249 | } | 250 | } |
| 250 | - var listResult []dto.RewardStandardList | 251 | + listResult := make([]dto.RewardStandardList, 0) |
| 251 | var temp dto.RewardStandardList | 252 | var temp dto.RewardStandardList |
| 252 | for _, v := range rewardStandardList { | 253 | for _, v := range rewardStandardList { |
| 253 | temp = dto.RewardStandardList{ | 254 | temp = dto.RewardStandardList{ |
| @@ -269,7 +270,7 @@ func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStand | @@ -269,7 +270,7 @@ func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStand | ||
| 269 | return cnt, listResult, nil | 270 | return cnt, listResult, nil |
| 270 | } | 271 | } |
| 271 | 272 | ||
| 272 | -//SaveRewardRule 保存奖惩规则 | 273 | +// SaveRewardRule 保存奖惩规则 |
| 273 | func (srv RewardStandardService) SaveRewardRule(operateInfo *domain.OperateInfo, param *command.SaveRewardRuleCommand) (*command.SaveRewardRuleCommand, error) { | 274 | func (srv RewardStandardService) SaveRewardRule(operateInfo *domain.OperateInfo, param *command.SaveRewardRuleCommand) (*command.SaveRewardRuleCommand, error) { |
| 274 | transactionContext, err := factory.CreateTransactionContext(nil) | 275 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 275 | if err != nil { | 276 | if err != nil { |
| @@ -318,7 +319,7 @@ func (srv RewardStandardService) SaveRewardRule(operateInfo *domain.OperateInfo, | @@ -318,7 +319,7 @@ func (srv RewardStandardService) SaveRewardRule(operateInfo *domain.OperateInfo, | ||
| 318 | return param, err | 319 | return param, err |
| 319 | } | 320 | } |
| 320 | 321 | ||
| 321 | -//GetRewardRule 获取奖惩规则 | 322 | +// GetRewardRule 获取奖惩规则 |
| 322 | func (srv RewardStandardService) GetRewardRule(operateInfo *domain.OperateInfo) (*dto.RewardRuleInfo, error) { | 323 | func (srv RewardStandardService) GetRewardRule(operateInfo *domain.OperateInfo) (*dto.RewardRuleInfo, error) { |
| 323 | transactionContext, err := factory.CreateTransactionContext(nil) | 324 | transactionContext, err := factory.CreateTransactionContext(nil) |
| 324 | if err != nil { | 325 | if err != nil { |
pkg/application/statistics/service/board.go
0 → 100644
| 1 | +package service |
pkg/infrastructure/dao/board_show_dao.go
0 → 100644
| 1 | +package dao | ||
| 2 | + | ||
| 3 | +import pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 4 | + | ||
| 5 | +//车间看板(生产)的展示数据 | ||
| 6 | + | ||
| 7 | +type BoardShowDao struct { | ||
| 8 | + transactionContext *pgTransaction.TransactionContext | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +type BoardWorkshopDesc struct { | ||
| 12 | + WorkshopName string `json:"workshopName"` | ||
| 13 | + Uname string `json:"uname"` | ||
| 14 | + Lines string `json:"lines"` | ||
| 15 | + Workon string `json:"workon"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +//WorkshopDesc 车间描述 | ||
| 19 | +func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*BoardWorkshopDesc, error) { | ||
| 20 | + sqlStr := `with workshop as ( | ||
| 21 | + select a.workshop_name,a.uname,a.line->>'lineName' linename from ( | ||
| 22 | + select workshop_name,principal->>'userName' uname | ||
| 23 | + , jsonb_array_elements(product_lines) line | ||
| 24 | + from manufacture.workshop where company_id = ? | ||
| 25 | + and org_id = ? | ||
| 26 | + and workshop_id=? | ||
| 27 | + ) a | ||
| 28 | + where a.line->>'removed' = '1' | ||
| 29 | + ) | ||
| 30 | + select max(workshop_name) workshop_name | ||
| 31 | + ,max(uname) uname | ||
| 32 | + ,string_agg(linename, '\') lines, | ||
| 33 | + '全天' workon | ||
| 34 | + from workshop` | ||
| 35 | + tx := d.transactionContext.PgTx | ||
| 36 | + var result BoardWorkshopDesc | ||
| 37 | + _, err := tx.QueryOne(&result, sqlStr, companyId, orgId, workshopId) | ||
| 38 | + if err != nil { | ||
| 39 | + return nil, err | ||
| 40 | + } | ||
| 41 | + return &result, nil | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +//在岗人数 | ||
| 45 | +func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (int, error) { | ||
| 46 | + sqlStr := `select count(distinct product_worker->>'userId') from manufacture.product_attendance_record | ||
| 47 | + where company_id = ? | ||
| 48 | + and org_id = ? | ||
| 49 | + and work_station->>'workshopId'='?' | ||
| 50 | + and sign_in>to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD')` | ||
| 51 | + var cnt int | ||
| 52 | + tx := d.transactionContext.PgTx | ||
| 53 | + _, err := tx.QueryOne(&cnt, sqlStr, companyId, orgId, workshopId) | ||
| 54 | + return cnt, err | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +//员工效率排名 | ||
| 58 | +type BoardEmployeeWorkpieceRatio struct { | ||
| 59 | + Uname string `json:"uname"` | ||
| 60 | + Today string `json:"today"` | ||
| 61 | + Yesterday string `json:"yesterday"` | ||
| 62 | + History string `json:"history"` | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +//员工效率排名 | ||
| 66 | +func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshopId int) ( | ||
| 67 | + []BoardEmployeeWorkpieceRatio, error) { | ||
| 68 | + sqlStr := `with employee_plan_product as( | ||
| 69 | + select product_worker->>'userName' as uname, | ||
| 70 | + (product_weigh - second_level_weigh - CAST(product_record_info->>'totalOtherSecondLevelWeigh' as decimal)) today | ||
| 71 | + ,CAST(product_record_info->>'yesterdayOutputWeight' as decimal) yesterday | ||
| 72 | + ,CAST(product_record_info->>'bestOutputWeight' as decimal) history | ||
| 73 | + from manufacture.employee_product_record | ||
| 74 | + where | ||
| 75 | + company_id = ? | ||
| 76 | + and org_id = ? | ||
| 77 | + and work_station->>'workshopId'='?' | ||
| 78 | + and work_station->>'sectionName' = '包装' | ||
| 79 | + and product_record_info->>'productDate'=to_char(now(), 'YYYY-MM-DD') | ||
| 80 | + ),group_employee_plan_product as ( | ||
| 81 | + select uname,sum(today) today,sum(yesterday) yesterday,sum(history) history from employee_plan_product | ||
| 82 | + group by uname | ||
| 83 | + ) | ||
| 84 | + select * from group_employee_plan_product | ||
| 85 | + order by today desc` | ||
| 86 | + var result []BoardEmployeeWorkpieceRatio | ||
| 87 | + tx := d.transactionContext.PgTx | ||
| 88 | + _, err := tx.Query(&result, sqlStr, companyId, orgId, workshopId) | ||
| 89 | + if err != nil { | ||
| 90 | + return nil, err | ||
| 91 | + } | ||
| 92 | + return result, nil | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +//时段产能 | ||
| 96 | +type BoardTimeSectionProductRecord struct { | ||
| 97 | + Ts string `json:"ts"` | ||
| 98 | + Total string `json:"total"` | ||
| 99 | + Line string `json:"line"` | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +//TimeSectionProductRecord 时段产能 | ||
| 103 | +func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, workshopId int, lineIdA int, lineIdB int) ( | ||
| 104 | + []BoardTimeSectionProductRecord, error, | ||
| 105 | +) { | ||
| 106 | + sqlStr := `(WITH ts_product as( | ||
| 107 | + select sum(a.weight) total,a.ts,max(line) line from ( | ||
| 108 | + select | ||
| 109 | + cast(device_running_record_info->>'count' as DECIMAL) weight, | ||
| 110 | + "replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts, | ||
| 111 | + work_station->>'lineName' line | ||
| 112 | + from manufacture.device_running_record | ||
| 113 | + where | ||
| 114 | + company_id = ? | ||
| 115 | + and org_id = ? | ||
| 116 | + and work_station->>'workshopId'='?' | ||
| 117 | + and work_station->>'lineId' = '?' | ||
| 118 | + and device_running_record_info->>'deviceType'='CCJ' | ||
| 119 | + and created_at >to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') | ||
| 120 | + ) a | ||
| 121 | + group by a.ts | ||
| 122 | + order by ts | ||
| 123 | + ) | ||
| 124 | + , ts_product_list as ( | ||
| 125 | + select d.ts,ts_product.total,line from ( | ||
| 126 | + select to_char(c.ts::timestamp,'HH24:MI') ts from ( | ||
| 127 | + select generate_series(a.end - interval '2.5 hour', | ||
| 128 | + "replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp, | ||
| 129 | + '30 minute') ts from ( | ||
| 130 | + select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end | ||
| 131 | + ) a | ||
| 132 | + ) c | ||
| 133 | + ) d left join ts_product on d.ts = ts_product.ts | ||
| 134 | + ) | ||
| 135 | + SELECT ts, coalesce(total,0) total ,'南瓜饼1线' line | ||
| 136 | + from ts_product_list | ||
| 137 | + ) | ||
| 138 | + union all | ||
| 139 | + (WITH ts_product as( | ||
| 140 | + select sum(a.weight) total,a.ts,max(line) line from ( | ||
| 141 | + select | ||
| 142 | + cast(device_running_record_info->>'count' as DECIMAL) weight, | ||
| 143 | + "replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts, | ||
| 144 | + work_station->>'lineName' line | ||
| 145 | + from manufacture.device_running_record | ||
| 146 | + where | ||
| 147 | + company_id = ? | ||
| 148 | + and org_id = ? | ||
| 149 | + and work_station->>'workshopId'='?' | ||
| 150 | + and work_station->>'lineId' = '?' | ||
| 151 | + and device_running_record_info->>'deviceType'='CCJ' | ||
| 152 | + and created_at >to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') | ||
| 153 | + ) a | ||
| 154 | + group by a.ts | ||
| 155 | + order by ts | ||
| 156 | + ) | ||
| 157 | + , ts_product_list as ( | ||
| 158 | + select d.ts,ts_product.total,line from ( | ||
| 159 | + select to_char(c.ts::timestamp,'HH24:MI') ts from ( | ||
| 160 | + select generate_series(a.end - interval '2.5 hour', | ||
| 161 | + "replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp, | ||
| 162 | + '30 minute') ts from ( | ||
| 163 | + select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end | ||
| 164 | + ) a | ||
| 165 | + ) c | ||
| 166 | + ) d left join ts_product on d.ts = ts_product.ts | ||
| 167 | + ) | ||
| 168 | + SELECT ts, coalesce(total,0) total ,'南瓜饼2线' line | ||
| 169 | + from ts_product_list | ||
| 170 | + )` | ||
| 171 | + condition := []interface{}{ | ||
| 172 | + companyId, orgId, workshopId, lineIdA, | ||
| 173 | + companyId, orgId, workshopId, lineIdB, | ||
| 174 | + } | ||
| 175 | + var result []BoardTimeSectionProductRecord | ||
| 176 | + tx := d.transactionContext.PgTx | ||
| 177 | + _, err := tx.Query(&result, sqlStr, condition...) | ||
| 178 | + return result, err | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +//今日昨日历史最佳 | ||
| 182 | +type BoardTopShow struct { | ||
| 183 | + Today string `json:"today"` | ||
| 184 | + Yesterday string `json:"yesterday"` | ||
| 185 | + History string `json:"history"` | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +//TopShop 今日昨日历史最佳 | ||
| 189 | +func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*BoardTopShow, error) { | ||
| 190 | + sqlStr := `with today_product as ( | ||
| 191 | + select | ||
| 192 | + (case when product_record_type=1 then cast(product_record_info->>'weigh' as DECIMAL) | ||
| 193 | + ELSE -(cast(product_record_info->>'weigh' as DECIMAL)) | ||
| 194 | + END) as weight, | ||
| 195 | + cast(product_record_info->>'productPlanId' as INTEGER) plan_id | ||
| 196 | + from manufacture.product_records | ||
| 197 | + where company_id = ? | ||
| 198 | + and org_id = ? | ||
| 199 | + and work_station->>'workshopId'='?' | ||
| 200 | + and product_record_type in (1,2) | ||
| 201 | + and created_at>=to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') | ||
| 202 | + ) ,tmp_today_product as( | ||
| 203 | + select | ||
| 204 | + (select COALESCE(sum(weight),0) weight from today_product) today, | ||
| 205 | + (select COALESCE(sum(real),0) from manufacture.workshop_plan_completion_record where | ||
| 206 | + company_id =? | ||
| 207 | + and org_id =? | ||
| 208 | + and created_at > CURRENT_DATE -1 | ||
| 209 | + and workshop_id = ? | ||
| 210 | + limit 1 | ||
| 211 | + ) yesterday, | ||
| 212 | + (select max(real) from manufacture.workshop_plan_completion_record where workshop_id = ?) history | ||
| 213 | + ) | ||
| 214 | + select today, | ||
| 215 | + cast(yesterday as DECIMAL) yesterday, | ||
| 216 | + (case when today > history then today else history end) history | ||
| 217 | + from tmp_today_product` | ||
| 218 | + condition := []interface{}{ | ||
| 219 | + companyId, orgId, workshopId, | ||
| 220 | + companyId, orgId, workshopId, workshopId, | ||
| 221 | + } | ||
| 222 | + var result BoardTopShow | ||
| 223 | + tx := d.transactionContext.PgTx | ||
| 224 | + _, err := tx.QueryOne(&result, sqlStr, condition...) | ||
| 225 | + return &result, err | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +//二级品占比 | ||
| 229 | +type BoardProportionOfSecondLevel struct { | ||
| 230 | + Sname string `json:"sname"` //品名 | ||
| 231 | + Rate string `json:"rate"` //占比 | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +//二级品占比 | ||
| 235 | +func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, workshopId int) ( | ||
| 236 | + []BoardProportionOfSecondLevel, error) { | ||
| 237 | + sqlStr := `with item_product as ( | ||
| 238 | + select sum(a.weight) item_total,max(sname) sname from ( | ||
| 239 | + select cast(product_record_info->>'weigh' as DECIMAL) weight | ||
| 240 | + ,work_station->>'sectionName' sname | ||
| 241 | + ,work_station->>'workStationId' workStationId | ||
| 242 | + from manufacture.product_records | ||
| 243 | + where company_id = ? | ||
| 244 | + and org_id = ? | ||
| 245 | + and work_station->>'workshopId'='?' | ||
| 246 | + and product_record_type = 8 | ||
| 247 | + and product_record_info->>'approveStatus'='2' | ||
| 248 | + and created_at >=to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') | ||
| 249 | + and work_station->>'sectionName' in ('制模','成型','穿串','包装') | ||
| 250 | + ) a | ||
| 251 | + group by a.workStationId | ||
| 252 | + ) | ||
| 253 | + ,item_product_rate as( | ||
| 254 | + select sname,round(item_total/(select sum(item_total) from item_product)*100, 0) as rate from item_product | ||
| 255 | + ) | ||
| 256 | + select b.sname, coalesce(b.rate,0) rate from item_product_rate b` | ||
| 257 | + condition := []interface{}{ | ||
| 258 | + companyId, orgId, workshopId, | ||
| 259 | + } | ||
| 260 | + var result []BoardProportionOfSecondLevel | ||
| 261 | + tx := d.transactionContext.PgTx | ||
| 262 | + _, err := tx.Query(&result, sqlStr, condition...) | ||
| 263 | + return result, err | ||
| 264 | +} | ||
| 265 | + | ||
| 266 | +//工段生产信息 | ||
| 267 | +type BoardSectionProductInfo struct { | ||
| 268 | + Sname string `json:"sname"` | ||
| 269 | + ProductWeight string `json:"productWeight"` | ||
| 270 | + SecondLevelWeight string `json:"secondLevelWeight"` | ||
| 271 | + TotalWeigh string `json:"totalWeigh"` | ||
| 272 | + Qu string `json:"qu"` | ||
| 273 | + Sort string `json:"sort"` //排名 | ||
| 274 | +} | ||
| 275 | + | ||
| 276 | +//工段生产信息 | ||
| 277 | +func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId int) ( | ||
| 278 | + []BoardSectionProductInfo, error) { | ||
| 279 | + sqlStr := `with section_product as( | ||
| 280 | + select | ||
| 281 | + work_station->>'sectionName' section, --工段 | ||
| 282 | + CAST(product_record_info->>'outputWeight' as decimal) product_weigh, --产出量 | ||
| 283 | + CAST(product_record_info->>'secondLevelWeight' as decimal) second_level_weigh, | ||
| 284 | + CAST(product_record_info->>'qualificationRate' as decimal) qu | ||
| 285 | + --二级品 | ||
| 286 | + from manufacture.workshop_product_record | ||
| 287 | + where company_id = ? | ||
| 288 | + and org_id = ? | ||
| 289 | + and work_station->>'workshopId'='?' | ||
| 290 | + and product_date =to_char(now(), 'YYYY-MM-DD') | ||
| 291 | + ), | ||
| 292 | + all_section_product as( | ||
| 293 | + select b.sname, | ||
| 294 | + COALESCE(a.product_weigh,0) product_weigh, | ||
| 295 | + COALESCE(a.second_level_weigh,0) second_level_weigh, | ||
| 296 | + COALESCE(a.qu,0) qu | ||
| 297 | + from section_product a right join ( | ||
| 298 | + select unnest(ARRAY ['制模','成型','穿串','包装']) sname | ||
| 299 | + ) b on a.section = b.sname | ||
| 300 | + ),group_section_product as( | ||
| 301 | + select | ||
| 302 | + sname, | ||
| 303 | + sum(product_weigh) product_weigh, | ||
| 304 | + sum(second_level_weigh) second_level_weigh | ||
| 305 | + ,sum(product_weigh+second_level_weigh) total_weigh | ||
| 306 | + from all_section_product | ||
| 307 | + GROUP BY sname | ||
| 308 | + ) | ||
| 309 | + select *, | ||
| 310 | + (case when product_weigh=0 or total_weigh=0 then 0 else round(product_weigh*100/total_weigh,1) end) qu, | ||
| 311 | + (case when sname = '制模' then 1 | ||
| 312 | + when sname='成型' then 2 | ||
| 313 | + when sname='穿串' then 3 else 4 end) sort | ||
| 314 | + from group_section_product | ||
| 315 | + order by sort` | ||
| 316 | + condition := []interface{}{ | ||
| 317 | + companyId, orgId, workshopId, | ||
| 318 | + } | ||
| 319 | + var result []BoardSectionProductInfo | ||
| 320 | + tx := d.transactionContext.PgTx | ||
| 321 | + _, err := tx.Query(&result, sqlStr, condition...) | ||
| 322 | + return result, err | ||
| 323 | +} | ||
| 324 | + | ||
| 325 | +//当前计划达成率 | ||
| 326 | +func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, workshopId int) (string, error) { | ||
| 327 | + sqlStr := `select rate rate from manufacture.workshop_plan_completion_record where | ||
| 328 | + company_id = ? | ||
| 329 | + and org_id = ? | ||
| 330 | + and workshop_id=? | ||
| 331 | + order by created_at desc | ||
| 332 | + limit 1` | ||
| 333 | + condition := []interface{}{ | ||
| 334 | + companyId, orgId, workshopId, | ||
| 335 | + } | ||
| 336 | + var result string | ||
| 337 | + tx := d.transactionContext.PgTx | ||
| 338 | + _, err := tx.QueryOne(&result, sqlStr, condition...) | ||
| 339 | + return result, err | ||
| 340 | +} | ||
| 341 | + | ||
| 342 | +//近5天 计划达成率 | ||
| 343 | +func (d *BoardShowDao) WorkshopPlanCompletion5Day(companyId int, orgId int, workshopId int) { | ||
| 344 | + // sqlStr := `with ts_product as ( | ||
| 345 | + // select rate, | ||
| 346 | + // to_char(created_at,'mm-dd') ts | ||
| 347 | + // from manufacture.workshop_plan_completion_record | ||
| 348 | + // where company_id = 23 | ||
| 349 | + // and org_id = 487 | ||
| 350 | + // and workshop_id= 38 | ||
| 351 | + // and created_at > (now()-interval '6d') | ||
| 352 | + // ) | ||
| 353 | + // ,ts_product_list as ( | ||
| 354 | + // select d.ts,ts_product.rate from ( | ||
| 355 | + // select to_char(c.ts::timestamp,'mm-dd') ts from ( | ||
| 356 | + // select generate_series(now() - interval '4 day',now(),'1 day') ts | ||
| 357 | + // ) c ) d left join ts_product on d.ts = ts_product.ts | ||
| 358 | + // ) | ||
| 359 | + // SELECT ts, coalesce(rate,0) total | ||
| 360 | + // from ts_product_list` | ||
| 361 | +} |
-
请 注册 或 登录 后发表评论