作者 Your Name

更新

@@ -260,7 +260,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou @@ -260,7 +260,7 @@ func (srv ProductTroubleService) ListProductTrouble(param *query.ListProductTrou
260 offset := param.PageSize * (param.PageNumber - 1) 260 offset := param.PageSize * (param.PageNumber - 1)
261 condition := map[string]interface{}{ 261 condition := map[string]interface{}{
262 "limit": limit, 262 "limit": limit,
263 - "offsett": offset, 263 + "offset": offset,
264 "companyId": param.CompanyId, 264 "companyId": param.CompanyId,
265 "orgId": param.OrgId, 265 "orgId": param.OrgId,
266 } 266 }
1 package service 1 package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
  9 +)
  10 +
  11 +//车间看板(生产)
  12 +
  13 +// 车间描述
  14 +func (svr *CommonStatisticsService) WorkshopDesc() (interface{}, error) {
  15 + transactionContext, err := factory.CreateTransactionContext(nil)
  16 + if err != nil {
  17 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  18 + }
  19 + if err := transactionContext.StartTransaction(); err != nil {
  20 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  21 + }
  22 + defer func() {
  23 + _ = transactionContext.RollbackTransaction()
  24 + }()
  25 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  26 + workshopDesc, err := boardShowData.WorkshopDesc(
  27 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  28 + constant.MANUFACTURE_DEFAULT_ORGID,
  29 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  30 + )
  31 + if err != nil {
  32 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  33 + }
  34 + //在岗人数
  35 + onDuty, err := boardShowData.OnDutyCount(
  36 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  37 + constant.MANUFACTURE_DEFAULT_ORGID,
  38 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  39 + )
  40 + if err != nil {
  41 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  42 + }
  43 + if err := transactionContext.CommitTransaction(); err != nil {
  44 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  45 + }
  46 + result := map[string]interface{}{
  47 + "lines": workshopDesc.Lines,
  48 + "uname": workshopDesc.Uname,
  49 + "workon": workshopDesc.Workon,
  50 + "workshopName": workshopDesc.WorkshopName,
  51 + "onDuty": onDuty,
  52 + }
  53 + return result, nil
  54 +}
  55 +
  56 +// 员工效率排名
  57 +func (svr *CommonStatisticsService) EmployeeWorkpieceRatio() (interface{}, error) {
  58 + transactionContext, err := factory.CreateTransactionContext(nil)
  59 + if err != nil {
  60 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  61 + }
  62 + if err := transactionContext.StartTransaction(); err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + defer func() {
  66 + _ = transactionContext.RollbackTransaction()
  67 + }()
  68 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  69 + result, err := boardShowData.EmployeeWorkpieceRatio(
  70 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  71 + constant.MANUFACTURE_DEFAULT_ORGID,
  72 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  73 + )
  74 + if err != nil {
  75 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  76 + }
  77 + if err := transactionContext.CommitTransaction(); err != nil {
  78 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  79 + }
  80 + listData := map[string]interface{}{
  81 + "list": result,
  82 + }
  83 + return listData, nil
  84 +}
  85 +
  86 +// TimeSectionProductRecord 时段产能
  87 +func (svr *CommonStatisticsService) TimeSectionProductRecord() (interface{}, error) {
  88 + transactionContext, err := factory.CreateTransactionContext(nil)
  89 + if err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + if err := transactionContext.StartTransaction(); err != nil {
  93 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  94 + }
  95 + defer func() {
  96 + _ = transactionContext.RollbackTransaction()
  97 + }()
  98 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  99 + // todo
  100 + result, err := boardShowData.TimeSectionProductRecord(
  101 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  102 + constant.MANUFACTURE_DEFAULT_ORGID,
  103 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  104 + 0, 0,
  105 + )
  106 + if err != nil {
  107 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  108 + }
  109 + if err := transactionContext.CommitTransaction(); err != nil {
  110 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  111 + }
  112 + listData := map[string]interface{}{
  113 + "list": result,
  114 + }
  115 + return listData, nil
  116 +}
  117 +
  118 +// TopShow 今日昨日历史最佳
  119 +func (svr *CommonStatisticsService) TopShow() (interface{}, error) {
  120 + transactionContext, err := factory.CreateTransactionContext(nil)
  121 + if err != nil {
  122 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  123 + }
  124 + if err := transactionContext.StartTransaction(); err != nil {
  125 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  126 + }
  127 + defer func() {
  128 + _ = transactionContext.RollbackTransaction()
  129 + }()
  130 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  131 + result, err := boardShowData.TopShow(
  132 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  133 + constant.MANUFACTURE_DEFAULT_ORGID,
  134 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  135 + )
  136 + if err != nil {
  137 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  138 + }
  139 + if err := transactionContext.CommitTransaction(); err != nil {
  140 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  141 + }
  142 + return result, nil
  143 +}
  144 +
  145 +// ProportionOfSecondLevel 二级品占比
  146 +func (svr *CommonStatisticsService) ProportionOfSecondLevel() (interface{}, error) {
  147 + transactionContext, err := factory.CreateTransactionContext(nil)
  148 + if err != nil {
  149 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  150 + }
  151 + if err := transactionContext.StartTransaction(); err != nil {
  152 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  153 + }
  154 + defer func() {
  155 + _ = transactionContext.RollbackTransaction()
  156 + }()
  157 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  158 + result, err := boardShowData.ProportionOfSecondLevel(
  159 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  160 + constant.MANUFACTURE_DEFAULT_ORGID,
  161 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  162 + )
  163 + if err != nil {
  164 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  165 + }
  166 + if err := transactionContext.CommitTransaction(); err != nil {
  167 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  168 + }
  169 + listData := map[string]interface{}{
  170 + "list": result,
  171 + }
  172 + return listData, nil
  173 +}
  174 +
  175 +// SectionProductInfo 工段生产信息
  176 +func (svr *CommonStatisticsService) SectionProductInfo() (interface{}, error) {
  177 + transactionContext, err := factory.CreateTransactionContext(nil)
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + if err := transactionContext.StartTransaction(); err != nil {
  182 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  183 + }
  184 + defer func() {
  185 + _ = transactionContext.RollbackTransaction()
  186 + }()
  187 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  188 + result, err := boardShowData.ProportionOfSecondLevel(
  189 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  190 + constant.MANUFACTURE_DEFAULT_ORGID,
  191 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  192 + )
  193 + if err != nil {
  194 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  195 + }
  196 + if err := transactionContext.CommitTransaction(); err != nil {
  197 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  198 + }
  199 + listData := map[string]interface{}{
  200 + "list": result,
  201 + }
  202 + return listData, nil
  203 +}
  204 +
  205 +// WorkshopPlanCompletionCurrent 当前计划达成率
  206 +func (svr *CommonStatisticsService) WorkshopPlanCompletionCurrent() (interface{}, error) {
  207 + transactionContext, err := factory.CreateTransactionContext(nil)
  208 + if err != nil {
  209 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + if err := transactionContext.StartTransaction(); err != nil {
  212 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  213 + }
  214 + defer func() {
  215 + _ = transactionContext.RollbackTransaction()
  216 + }()
  217 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  218 + result, err := boardShowData.WorkshopPlanCompletionCurrent(
  219 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  220 + constant.MANUFACTURE_DEFAULT_ORGID,
  221 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  222 + )
  223 + if err != nil {
  224 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  225 + }
  226 + if err := transactionContext.CommitTransaction(); err != nil {
  227 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  228 + }
  229 + listData := map[string]interface{}{
  230 + "rate": result,
  231 + }
  232 + return listData, nil
  233 +}
  234 +
  235 +// WorkshopPlanCompletion5Day 近5天计划达成率
  236 +func (svr *CommonStatisticsService) WorkshopPlanCompletion5Day() (interface{}, error) {
  237 + transactionContext, err := factory.CreateTransactionContext(nil)
  238 + if err != nil {
  239 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  240 + }
  241 + if err := transactionContext.StartTransaction(); err != nil {
  242 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  243 + }
  244 + defer func() {
  245 + _ = transactionContext.RollbackTransaction()
  246 + }()
  247 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  248 + result, err := boardShowData.WorkshopPlanCompletion5Day(
  249 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  250 + constant.MANUFACTURE_DEFAULT_ORGID,
  251 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  252 + )
  253 + if err != nil {
  254 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  255 + }
  256 + if err := transactionContext.CommitTransaction(); err != nil {
  257 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  258 + }
  259 + listData := map[string]interface{}{
  260 + "list": result,
  261 + }
  262 + return listData, nil
  263 +}
  264 +
  265 +// 批次产能
  266 +func (svr *CommonStatisticsService) ProductPlan() (interface{}, error) {
  267 + transactionContext, err := factory.CreateTransactionContext(nil)
  268 + if err != nil {
  269 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  270 + }
  271 + if err := transactionContext.StartTransaction(); err != nil {
  272 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  273 + }
  274 + defer func() {
  275 + _ = transactionContext.RollbackTransaction()
  276 + }()
  277 + boardShowData, _ := dao.NewBoardShowDao(transactionContext.(*pgTransaction.TransactionContext))
  278 + result, err := boardShowData.ProductPlan(
  279 + constant.MANUFACTURE_DEFAULT_COMPANYID,
  280 + constant.MANUFACTURE_DEFAULT_ORGID,
  281 + constant.MANUFACTURE_DEFAULT_WORKSHOPID,
  282 + )
  283 + if err != nil {
  284 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  285 + }
  286 + if err := transactionContext.CommitTransaction(); err != nil {
  287 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  288 + }
  289 + listData := map[string]interface{}{
  290 + "list": result,
  291 + }
  292 + return listData, nil
  293 +}
1 package dao 1 package dao
2 2
3 -import pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 3 +import (
  4 + "fmt"
  5 +
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 +)
4 8
5 //车间看板(生产)的展示数据 9 //车间看板(生产)的展示数据
6 10
@@ -8,6 +12,16 @@ type BoardShowDao struct { @@ -8,6 +12,16 @@ type BoardShowDao struct {
8 transactionContext *pgTransaction.TransactionContext 12 transactionContext *pgTransaction.TransactionContext
9 } 13 }
10 14
  15 +func NewBoardShowDao(transactionContext *pgTransaction.TransactionContext) (*BoardShowDao, error) {
  16 + if transactionContext == nil {
  17 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  18 + } else {
  19 + return &BoardShowDao{
  20 + transactionContext: transactionContext,
  21 + }, nil
  22 + }
  23 +}
  24 +
11 type BoardWorkshopDesc struct { 25 type BoardWorkshopDesc struct {
12 WorkshopName string `json:"workshopName"` 26 WorkshopName string `json:"workshopName"`
13 Uname string `json:"uname"` 27 Uname string `json:"uname"`
@@ -15,7 +29,7 @@ type BoardWorkshopDesc struct { @@ -15,7 +29,7 @@ type BoardWorkshopDesc struct {
15 Workon string `json:"workon"` 29 Workon string `json:"workon"`
16 } 30 }
17 31
18 -//WorkshopDesc 车间描述 32 +// WorkshopDesc 车间描述
19 func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*BoardWorkshopDesc, error) { 33 func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*BoardWorkshopDesc, error) {
20 sqlStr := `with workshop as ( 34 sqlStr := `with workshop as (
21 select a.workshop_name,a.uname,a.line->>'lineName' linename from ( 35 select a.workshop_name,a.uname,a.line->>'lineName' linename from (
@@ -41,7 +55,7 @@ func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (* @@ -41,7 +55,7 @@ func (d *BoardShowDao) WorkshopDesc(companyId int, orgId int, workshopId int) (*
41 return &result, nil 55 return &result, nil
42 } 56 }
43 57
44 -//在岗人数 58 +// 在岗人数
45 func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (int, error) { 59 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 60 sqlStr := `select count(distinct product_worker->>'userId') from manufacture.product_attendance_record
47 where company_id = ? 61 where company_id = ?
@@ -54,7 +68,7 @@ func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (in @@ -54,7 +68,7 @@ func (d *BoardShowDao) OnDutyCount(companyId int, orgId int, workshopId int) (in
54 return cnt, err 68 return cnt, err
55 } 69 }
56 70
57 -//员工效率排名 71 +// 员工效率排名
58 type BoardEmployeeWorkpieceRatio struct { 72 type BoardEmployeeWorkpieceRatio struct {
59 Uname string `json:"uname"` 73 Uname string `json:"uname"`
60 Today string `json:"today"` 74 Today string `json:"today"`
@@ -62,7 +76,7 @@ type BoardEmployeeWorkpieceRatio struct { @@ -62,7 +76,7 @@ type BoardEmployeeWorkpieceRatio struct {
62 History string `json:"history"` 76 History string `json:"history"`
63 } 77 }
64 78
65 -//员工效率排名 79 +// 员工效率排名
66 func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshopId int) ( 80 func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshopId int) (
67 []BoardEmployeeWorkpieceRatio, error) { 81 []BoardEmployeeWorkpieceRatio, error) {
68 sqlStr := `with employee_plan_product as( 82 sqlStr := `with employee_plan_product as(
@@ -92,14 +106,14 @@ func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshop @@ -92,14 +106,14 @@ func (d *BoardShowDao) EmployeeWorkpieceRatio(companyId int, orgId int, workshop
92 return result, nil 106 return result, nil
93 } 107 }
94 108
95 -//时段产能 109 +// 时段产能
96 type BoardTimeSectionProductRecord struct { 110 type BoardTimeSectionProductRecord struct {
97 Ts string `json:"ts"` 111 Ts string `json:"ts"`
98 Total string `json:"total"` 112 Total string `json:"total"`
99 Line string `json:"line"` 113 Line string `json:"line"`
100 } 114 }
101 115
102 -//TimeSectionProductRecord 时段产能 116 +// TimeSectionProductRecord 时段产能
103 func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, workshopId int, lineIdA int, lineIdB int) ( 117 func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, workshopId int, lineIdA int, lineIdB int) (
104 []BoardTimeSectionProductRecord, error, 118 []BoardTimeSectionProductRecord, error,
105 ) { 119 ) {
@@ -178,14 +192,14 @@ func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, worksh @@ -178,14 +192,14 @@ func (d *BoardShowDao) TimeSectionProductRecord(companyId int, orgId int, worksh
178 return result, err 192 return result, err
179 } 193 }
180 194
181 -//今日昨日历史最佳 195 +// 今日昨日历史最佳
182 type BoardTopShow struct { 196 type BoardTopShow struct {
183 Today string `json:"today"` 197 Today string `json:"today"`
184 Yesterday string `json:"yesterday"` 198 Yesterday string `json:"yesterday"`
185 History string `json:"history"` 199 History string `json:"history"`
186 } 200 }
187 201
188 -//TopShop 今日昨日历史最佳 202 +// TopShop 今日昨日历史最佳
189 func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*BoardTopShow, error) { 203 func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*BoardTopShow, error) {
190 sqlStr := `with today_product as ( 204 sqlStr := `with today_product as (
191 select 205 select
@@ -225,13 +239,13 @@ func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*Board @@ -225,13 +239,13 @@ func (d *BoardShowDao) TopShow(companyId int, orgId int, workshopId int) (*Board
225 return &result, err 239 return &result, err
226 } 240 }
227 241
228 -//二级品占比 242 +// 二级品占比
229 type BoardProportionOfSecondLevel struct { 243 type BoardProportionOfSecondLevel struct {
230 Sname string `json:"sname"` //品名 244 Sname string `json:"sname"` //品名
231 Rate string `json:"rate"` //占比 245 Rate string `json:"rate"` //占比
232 } 246 }
233 247
234 -//二级品占比 248 +// 二级品占比
235 func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, workshopId int) ( 249 func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, workshopId int) (
236 []BoardProportionOfSecondLevel, error) { 250 []BoardProportionOfSecondLevel, error) {
237 sqlStr := `with item_product as ( 251 sqlStr := `with item_product as (
@@ -263,7 +277,7 @@ func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, worksho @@ -263,7 +277,7 @@ func (d *BoardShowDao) ProportionOfSecondLevel(companyId int, orgId int, worksho
263 return result, err 277 return result, err
264 } 278 }
265 279
266 -//工段生产信息 280 +// 工段生产信息
267 type BoardSectionProductInfo struct { 281 type BoardSectionProductInfo struct {
268 Sname string `json:"sname"` 282 Sname string `json:"sname"`
269 ProductWeight string `json:"productWeight"` 283 ProductWeight string `json:"productWeight"`
@@ -273,7 +287,7 @@ type BoardSectionProductInfo struct { @@ -273,7 +287,7 @@ type BoardSectionProductInfo struct {
273 Sort string `json:"sort"` //排名 287 Sort string `json:"sort"` //排名
274 } 288 }
275 289
276 -//工段生产信息 290 +// 工段生产信息
277 func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId int) ( 291 func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId int) (
278 []BoardSectionProductInfo, error) { 292 []BoardSectionProductInfo, error) {
279 sqlStr := `with section_product as( 293 sqlStr := `with section_product as(
@@ -322,7 +336,7 @@ func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId i @@ -322,7 +336,7 @@ func (d *BoardShowDao) SectionProductInfo(companyId int, orgId int, workshopId i
322 return result, err 336 return result, err
323 } 337 }
324 338
325 -//当前计划达成率 339 +// 当前计划达成率
326 func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, workshopId int) (string, error) { 340 func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, workshopId int) (string, error) {
327 sqlStr := `select rate rate from manufacture.workshop_plan_completion_record where 341 sqlStr := `select rate rate from manufacture.workshop_plan_completion_record where
328 company_id = ? 342 company_id = ?
@@ -339,23 +353,82 @@ func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, w @@ -339,23 +353,82 @@ func (d *BoardShowDao) WorkshopPlanCompletionCurrent(companyId int, orgId int, w
339 return result, err 353 return result, err
340 } 354 }
341 355
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` 356 +type PlanCompletion5Day struct {
  357 + Ts string `jsonL:"ts"`
  358 + Total string `json:"total"`
  359 +}
  360 +
  361 +// 近5天 计划达成率
  362 +func (d *BoardShowDao) WorkshopPlanCompletion5Day(companyId int, orgId int, workshopId int) ([]PlanCompletion5Day, error) {
  363 + sqlStr := `with ts_product as (
  364 + select rate,
  365 + to_char(created_at,'mm-dd') ts
  366 + from manufacture.workshop_plan_completion_record
  367 + where company_id = ?
  368 + and org_id = ?
  369 + and workshop_id= ?
  370 + and created_at > (now()-interval '6d')
  371 + )
  372 + ,ts_product_list as (
  373 + select d.ts,ts_product.rate from (
  374 + select to_char(c.ts::timestamp,'mm-dd') ts from (
  375 + select generate_series(now() - interval '4 day',now(),'1 day') ts
  376 + ) c ) d left join ts_product on d.ts = ts_product.ts
  377 + )
  378 + SELECT ts, coalesce(rate,0) total
  379 + from ts_product_list`
  380 + var result []PlanCompletion5Day
  381 + condition := []interface{}{
  382 + companyId, orgId, workshopId,
  383 + }
  384 + tx := d.transactionContext.PgTx
  385 + _, err := tx.Query(&result, sqlStr, condition...)
  386 + return result, err
  387 +
  388 +}
  389 +
  390 +// product_plan 批次产能
  391 +func (d *BoardShowDao) ProductPlan(companyId int, orgId int, workshopId int) ([]PlanCompletion5Day, error) {
  392 + sqlStr := `with product_record as (
  393 + select
  394 + (case when product_record_type=1 then cast(product_record_info->>'weigh' as DECIMAL)
  395 + ELSE -(cast(product_record_info->>'weigh' as DECIMAL))
  396 + END) as weight,
  397 + cast(product_record_info->>'productPlanId' as INTEGER) plan_id
  398 + from manufacture.product_records
  399 + where company_id =?
  400 + and org_id = ?
  401 + and work_station->>'workshopId'='?'
  402 + and work_station->>'sectionName'='包装'
  403 + and product_record_type in (1,2)
  404 + and created_at>to_date(to_char((now() -interval '3 day'), 'YYYY-MM-DD'),'YYYY-MM-DD') --'2022-01-01' --
  405 + ), product_record_sum as(
  406 + select sum(weight) weight,plan_id
  407 + from product_record
  408 + GROUP BY plan_id
  409 + )
  410 + select
  411 + a.product_plan_id
  412 + ,batch_number --批次号
  413 + ,plan_product_name --品名
  414 + ,machine --机台
  415 + ,coalesce(plan_devoted->>'unit','') unit --规格
  416 + ,cast(coalesce(plan_devoted->>'quantity','0') as DECIMAL) quantity -- 数量
  417 + ,cast(coalesce(plan_devoted->>'weight','0')as DECIMAL) plan_weight -- 计划重量
  418 + , coalesce(b.weight,0) real_weight --批次实际产能
  419 + from manufacture.product_plan a left join product_record_sum b on a.product_plan_id = b.plan_id
  420 + where company_id = ?
  421 + and org_id = ?
  422 + and workshop->>'workshopId'='?'
  423 + and product_date >to_date(to_char(now() -interval '3 day', 'YYYY-MM-DD'),'YYYY-MM-DD')
  424 + and cast(coalesce(plan_devoted->>'weight','0')as DECIMAL) >0
  425 + order by created_at desc`
  426 + var result []PlanCompletion5Day
  427 + condition := []interface{}{
  428 + companyId, orgId, workshopId,
  429 + companyId, orgId, workshopId,
  430 + }
  431 + tx := d.transactionContext.PgTx
  432 + _, err := tx.Query(&result, sqlStr, condition...)
  433 + return result, err
361 } 434 }
@@ -125,6 +125,7 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{}) @@ -125,6 +125,7 @@ func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{})
125 query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v)) 125 query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
126 } 126 }
127 127
  128 + //TODO
128 cnt, err := query.SelectAndCount() 129 cnt, err := query.SelectAndCount()
129 if err != nil { 130 if err != nil {
130 return 0, nil, err 131 return 0, nil, err
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/statistics/service"
  6 +)
  7 +
  8 +type BoardDataController struct {
  9 + beego.BaseController
  10 +}
  11 +
  12 +func (c *BoardDataController) WorkshopDesc() {
  13 + srv := service.NewCommonStatisticsService(nil)
  14 + data, err := srv.WorkshopDesc()
  15 + c.Response(data, err)
  16 +}
  17 +
  18 +func (c *BoardDataController) EmployeeWorkpieceRatio() {
  19 + srv := service.NewCommonStatisticsService(nil)
  20 + data, err := srv.EmployeeWorkpieceRatio()
  21 + c.Response(data, err)
  22 +}
  23 +
  24 +func (c *BoardDataController) TimeSectionProductRecord() {
  25 + srv := service.NewCommonStatisticsService(nil)
  26 + data, err := srv.TimeSectionProductRecord()
  27 + c.Response(data, err)
  28 +}
  29 +
  30 +func (c *BoardDataController) TopShow() {
  31 + srv := service.NewCommonStatisticsService(nil)
  32 + data, err := srv.TopShow()
  33 + c.Response(data, err)
  34 +}
  35 +
  36 +func (c *BoardDataController) ProportionOfSecondLevel() {
  37 + srv := service.NewCommonStatisticsService(nil)
  38 + data, err := srv.ProportionOfSecondLevel()
  39 + c.Response(data, err)
  40 +}
  41 +
  42 +func (c *BoardDataController) SectionProductInfo() {
  43 + srv := service.NewCommonStatisticsService(nil)
  44 + data, err := srv.SectionProductInfo()
  45 + c.Response(data, err)
  46 +}
  47 +
  48 +func (c *BoardDataController) WorkshopPlanCompletionCurrent() {
  49 + srv := service.NewCommonStatisticsService(nil)
  50 + data, err := srv.WorkshopPlanCompletionCurrent()
  51 + c.Response(data, err)
  52 +}
  53 +
  54 +func (c *BoardDataController) WorkshopPlanCompletion5Day() {
  55 + srv := service.NewCommonStatisticsService(nil)
  56 + data, err := srv.WorkshopPlanCompletion5Day()
  57 + c.Response(data, err)
  58 +}
  59 +
  60 +func (c *BoardDataController) ProductPlan() {
  61 + srv := service.NewCommonStatisticsService(nil)
  62 + data, err := srv.ProductPlan()
  63 + c.Response(data, err)
  64 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/workshop-public-notice/workshop", &controllers.BoardDataController{}, "Get:WorkshopDesc")
  10 + web.Router("/workshop-public-notice/employee/workpiece-ratio", &controllers.BoardDataController{}, "Get:EmployeeWorkpieceRatio")
  11 + web.Router("/workshop-public-notice/section-product-info", &controllers.BoardDataController{}, "Get:TimeSectionProductRecord")
  12 + web.Router("/workshop-public-notice/proportion-of-second-level", &controllers.BoardDataController{}, "Get:ProportionOfSecondLevel")
  13 + web.Router("/workshop-public-notice/top-show", &controllers.BoardDataController{}, "Get:TopShow")
  14 + web.Router("/workshop-public-notice/product_plan", &controllers.BoardDataController{}, "Get:ProductPlan")
  15 + web.Router("/workshop-public-notice/workshop-plan-completion/current", &controllers.BoardDataController{}, "Get:WorkshopPlanCompletionCurrent")
  16 + web.Router("/workshop-public-notice/workshop-plan-completion/5day", &controllers.BoardDataController{}, "Get:WorkshopPlanCompletion5Day")
  17 +}