processController.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. }
  28. list := make([][]interface{},len(data))
  29. mergeRow := make(map[string]string)
  30. var columnName string
  31. var startIndex int
  32. rowAmount := 0
  33. for k,v := range data{
  34. if columnName == v["code"]{
  35. rowAmount++
  36. }else{
  37. if rowAmount != 0 {
  38. mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
  39. }
  40. columnName = v["code"]
  41. startIndex = k
  42. rowAmount = 0
  43. }
  44. if rowAmount != 0 {
  45. mergeRow[strconv.Itoa(startIndex+2)] = strconv.Itoa(startIndex+2+rowAmount)
  46. }
  47. line := make([]interface{},len(row))
  48. for key,value := range column {
  49. val := v[key]
  50. if key == "commodity_sku" && v["sign_commodity_sku_mark"] != "" {
  51. val = v["sign_commodity_sku_mark"]
  52. }
  53. if key == "commodity_name" && v["sign_commodity_name_mark"] != "" {
  54. val = v["sign_commodity_name_mark"]
  55. }
  56. if key == "commodity_barcode_code" && v["sign_commodity_barcode_mark"] != "" {
  57. val = v["sign_commodity_barcode_mark"]
  58. }
  59. if key == "created_at"{
  60. val = utilities.DateFormat(v[key])
  61. }
  62. line[value] = val
  63. }
  64. list[k] = line
  65. }
  66. return row,list,mergeRow
  67. }
  68. func ProcessStatisticFormat(data []map[string]string) ([]interface{}, [][]interface{}) {
  69. row := []interface{}{
  70. "任务号", "货主", "开始日期", "完成日期", "单价", "预期数量", "完成数量", "收入合计",
  71. "完成时间(天)'", "总工时", "加工类型", "最高日产能", "最低日产能", "日均产能", "合计成本", "毛利润",
  72. "毛利率", "状态",
  73. }
  74. column := map[string]int{
  75. "process_code" : 0,
  76. "owner_name" : 1,
  77. "started_at" : 2,
  78. "ended_at" : 3,
  79. "process_unit_price" : 4,
  80. "process_amount" : 5,
  81. "process_completed_amount" : 6,
  82. "revenue" : 7,
  83. "duration_days" : 8,
  84. "duration_man_hours" : 9,
  85. "process_method_name" : 10,
  86. "top_capacity" : 11,
  87. "bottom_capacity" : 12,
  88. "average_capacity" : 13,
  89. "total_cost" : 14,
  90. "gross_profit" : 15,
  91. "gross_profit_rate" : 16,
  92. "process_status" : 17,
  93. }
  94. list := make([][]interface{},len(data))
  95. for k,v := range data{
  96. line := make([]interface{},len(row))
  97. for key,value := range column {
  98. if key == "gross_profit_rate" {
  99. rate,_ := strconv.ParseFloat(v[key],64)
  100. if rate != 0 {
  101. line[value] = strconv.FormatFloat(rate * 100, 'f', 2, 64)+"%"
  102. }
  103. continue
  104. }
  105. line[value] = v[key]
  106. }
  107. list[k] = line
  108. }
  109. return row,list
  110. }