processController.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }