processController.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package controller
  2. import (
  3. "bswas/utilities"
  4. "strconv"
  5. )
  6. func ProcessFormat(data []map[string]string) ([]interface{}, [][]interface{}, map[string]string) {
  7. row := []interface{}{
  8. "任务号","货主","加工类型","预期数量","实际数量","状态","加工备注",
  9. "单价","提交日期","单据类型","单据号","商品编码","商品名称","商品条码","本次数量","结算备注",
  10. }
  11. column := map[string]int{
  12. "code" : 0,
  13. "owner_name" : 1,
  14. "process_method_name" : 2,
  15. "amount" : 3,
  16. "completed_amount" : 4,
  17. "status" : 5,
  18. "remark" : 6,
  19. "unit_price" : 7,
  20. "created_at" : 8,
  21. "content_bill_type" : 9,
  22. "content_wms_code" : 10,
  23. "commodity_sku" : 11,
  24. "commodity_name" : 12,
  25. "commodity_barcode_code" : 13,
  26. "content_amount" : 14,
  27. "process_balance_remark" : 15,
  28. }
  29. list := make([][]interface{},len(data))
  30. mergeRow := make(map[string]string)
  31. var columnName string
  32. var startIndex int
  33. rowAmount := 0
  34. for k,v := range data{
  35. if columnName == v["code"]{
  36. rowAmount++
  37. }else{
  38. if rowAmount != 0 {
  39. mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
  40. }
  41. columnName = v["code"]
  42. startIndex = k
  43. rowAmount = 0
  44. }
  45. if rowAmount != 0 {
  46. mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
  47. }
  48. line := make([]interface{},len(row))
  49. for key,value := range column {
  50. val := v[key]
  51. if key == "commodity_sku" && v["sign_commodity_sku_mark"] != "" {
  52. val = v["sign_commodity_sku_mark"]
  53. }
  54. if key == "commodity_name" && v["sign_commodity_name_mark"] != "" {
  55. val = v["sign_commodity_name_mark"]
  56. }
  57. if key == "commodity_barcode_code" && v["sign_commodity_barcode_mark"] != "" {
  58. val = v["sign_commodity_barcode_mark"]
  59. }
  60. if key == "created_at"{
  61. val = utilities.DateFormat(v[key],"2006-01-02T15:04:05Z")
  62. }
  63. line[value] = val
  64. }
  65. list[k] = line
  66. }
  67. return row,list,mergeRow
  68. }
  69. func ProcessStatisticFormat(data []map[string]string) ([]interface{}, [][]interface{}) {
  70. row := []interface{}{
  71. "任务号", "货主", "开始日期", "完成日期", "单价", "预期数量", "完成数量", "收入合计",
  72. "完成时间(天)'", "总工时", "加工类型", "最高日产能", "最低日产能", "日均产能", "合计成本", "毛利润",
  73. "毛利率", "状态","加工备注","结算备注",
  74. }
  75. column := map[string]int{
  76. "process_code" : 0,
  77. "owner_name" : 1,
  78. "started_at" : 2,
  79. "ended_at" : 3,
  80. "process_unit_price" : 4,
  81. "process_amount" : 5,
  82. "process_completed_amount" : 6,
  83. "revenue" : 7,
  84. "duration_days" : 8,
  85. "duration_man_hours" : 9,
  86. "process_method_name" : 10,
  87. "top_capacity" : 11,
  88. "bottom_capacity" : 12,
  89. "average_capacity" : 13,
  90. "total_cost" : 14,
  91. "gross_profit" : 15,
  92. "gross_profit_rate" : 16,
  93. "process_status" : 17,
  94. "process_remark" : 18,
  95. "process_balance_remark" : 19,
  96. }
  97. list := make([][]interface{},len(data))
  98. for k,v := range data{
  99. line := make([]interface{},len(row))
  100. for key,value := range column {
  101. if key == "gross_profit_rate" {
  102. rate,_ := strconv.ParseFloat(v[key],64)
  103. if rate != 0 {
  104. line[value] = strconv.FormatFloat(rate * 100, 'f', 2, 64)+"%"
  105. }
  106. continue
  107. }
  108. if key == "started_at" || key == "ended_at" {
  109. line[value] = utilities.DateFormat(v[key],"2006-01-02T15:04:05Z");
  110. continue
  111. }
  112. line[value] = v[key]
  113. }
  114. list[k] = line
  115. }
  116. return row,list
  117. }