report.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. package home
  2. import (
  3. "context"
  4. contDao "dashoo.cn/micro/app/dao/contract"
  5. projDao "dashoo.cn/micro/app/dao/proj"
  6. projSrv "dashoo.cn/micro/app/service/proj"
  7. "dashoo.cn/opms_libary/myerrors"
  8. "database/sql"
  9. "fmt"
  10. "dashoo.cn/micro/app/model/home"
  11. "dashoo.cn/micro/app/service"
  12. contractService "dashoo.cn/micro/app/service/contract"
  13. "dashoo.cn/opms_libary/micro_srv"
  14. "github.com/gogf/gf/database/gdb"
  15. "github.com/gogf/gf/os/gtime"
  16. "github.com/gogf/gf/util/gconv"
  17. )
  18. // getPersonalContractReportData 获取个人数据
  19. // dataType:collection为回款;其他为合同
  20. func getPersonalContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
  21. var reportData home.ReportData
  22. targetMap := make(map[int]gdb.Record, 0)
  23. realMap := make(map[int][]*gdb.Record, 0)
  24. targetField := "sales_target"
  25. realField := "contract_amount"
  26. year := gtime.Now().Format("Y")
  27. if params != nil && (*params)["year"] != nil {
  28. year = gconv.String((*params)["year"])
  29. }
  30. // 统计字段
  31. if dataType == "COLLECTION" {
  32. targetField = "collection_target"
  33. realField = "collection_amount"
  34. }
  35. srv, err := contractService.NewCtrContractService(ctx)
  36. if err != nil {
  37. return nil, err
  38. }
  39. // 获取用户信息
  40. userInfo, err := micro_srv.GetUserInfo(ctx)
  41. if err != nil {
  42. return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
  43. }
  44. targets, err := srv.Dao.DB.Model("rpt_sales_target").Where("sale_user_id", userInfo.Id).Order("monthly ASC").FindAll()
  45. if err != nil && err != sql.ErrNoRows {
  46. return nil, err
  47. }
  48. for index, target := range targets {
  49. targetMap[target["monthly"].Int()] = targets[index]
  50. }
  51. // 统计12个月份的数据
  52. // 统计目标值
  53. for index := 1; index <= 12; index++ {
  54. reportData.XData = append(reportData.XData, fmt.Sprintf("%v月", index))
  55. if target, ok := targetMap[index]; ok {
  56. reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
  57. } else {
  58. reportData.YDataTarget = append(reportData.YDataTarget, 0)
  59. }
  60. }
  61. // 统计合同值
  62. contractModel := srv.Dao.DB.Model("ctr_contract").Where("ctr_contract.incharge_id", userInfo.Id)
  63. if dataType != "COLLECTION" {
  64. contracts, err := contractModel.Where("ctr_contract.contract_start_time LIKE ?", year+"-%").Order("ctr_contract.contract_start_time ASC").FindAll()
  65. if err != nil && err != sql.ErrNoRows {
  66. return nil, err
  67. }
  68. for index, contract := range contracts {
  69. realMap[contract["contract_start_time"].GTime().Month()] = append(realMap[contract["contract_start_time"].GTime().Month()], &contracts[index])
  70. }
  71. } else {
  72. // 回款数据统计
  73. collections, err := contractModel.InnerJoin("ctr_contract_collection", "ctr_contract.id=ctr_contract_collection.contract_id").Where("ctr_contract_collection.appro_status", "20").Where("ctr_contract_collection.collection_datetime LIKE ?", year+"-%").Order("ctr_contract_collection.collection_datetime ASC").Fields("ctr_contract_collection.*").FindAll()
  74. if err != nil && err != sql.ErrNoRows {
  75. return nil, err
  76. }
  77. for index, collection := range collections {
  78. realMap[collection["collection_datetime"].GTime().Month()] = append(realMap[collection["collection_datetime"].GTime().Month()], &collections[index])
  79. }
  80. }
  81. // 统计12个月份的数据
  82. // 统计实际值
  83. for index := 1; index <= 12; index++ {
  84. if realData, ok := realMap[index]; ok {
  85. realAmount := float64(0)
  86. for _, data := range realData {
  87. realAmount += (*data)[realField].Float64()
  88. }
  89. reportData.YDataReal = append(reportData.YDataReal, realAmount)
  90. } else {
  91. reportData.YDataReal = append(reportData.YDataReal, 0)
  92. }
  93. if reportData.YDataTarget[index-1] == 0 {
  94. reportData.PercentData = append(reportData.PercentData, 0)
  95. } else {
  96. reportData.PercentData = append(reportData.PercentData, reportData.YDataReal[index-1]*100/reportData.YDataTarget[index-1])
  97. }
  98. }
  99. return &reportData, nil
  100. }
  101. // getCompanyContractReportData 获取总部数据
  102. // dataType:collection为回款;其他为合同
  103. func getCompanyContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
  104. var reportData home.ReportData
  105. realMap := make(map[int]gdb.Record, 0)
  106. targetField := "sales_target"
  107. realField := "contract_amount"
  108. dateWhere1 := "" // 查询条件
  109. dateWhere2 := "" // 查询条件
  110. dateWhere3 := ""
  111. date := gtime.Now()
  112. if params != nil && (*params)["date"] != nil {
  113. date = gconv.GTime((*params)["date"])
  114. }
  115. dateWhere1 = fmt.Sprintf("ctr_contract.contract_start_time LIKE '%v'", date.Format("Y")+"-%")
  116. dateWhere2 = fmt.Sprintf("ctr_contract_collection.collection_datetime LIKE '%v'", date.Format("Y")+"-%")
  117. if params != nil && (*params)["searchType"] != nil {
  118. searchType := gconv.String((*params)["searchType"])
  119. if searchType == "month" {
  120. dateWhere1 = fmt.Sprintf("ctr_contract.contract_start_time LIKE '%v'", date.Format("Y-m")+"-%")
  121. dateWhere2 = fmt.Sprintf("ctr_contract_collection.collection_datetime LIKE '%v'", date.Format("Y-m")+"-%")
  122. dateWhere3 = fmt.Sprintf("monthly=%v", date.Month())
  123. } else if searchType == "quarter" {
  124. dateWhere1 = getQuarterWhere(date, "ctr_contract.contract_start_time")
  125. dateWhere2 = getQuarterWhere(date, "ctr_contract_collection.collection_datetime")
  126. dateWhere3 = getQuarterMonthWhere(date, "monthly")
  127. }
  128. }
  129. // 统计字段
  130. if dataType == "COLLECTION" {
  131. targetField = "collection_target"
  132. realField = "collection_amount"
  133. }
  134. srv, err := contractService.NewCtrContractService(ctx)
  135. if err != nil {
  136. return nil, err
  137. }
  138. targets, err := srv.Dao.DB.Model("rpt_sales_target").Where(dateWhere3).Order("sale_user_id ASC").Group("sale_user_id").Fields(fmt.Sprintf("sale_user_id, sale_user_name, SUM(%v) %v", targetField, targetField)).FindAll()
  139. if err != nil && err != sql.ErrNoRows {
  140. return nil, err
  141. }
  142. // 统计合同值
  143. contractModel := srv.Dao.DB.Model("ctr_contract").Group("ctr_contract.incharge_id").Order("ctr_contract.incharge_id ASC")
  144. if dataType != "COLLECTION" {
  145. contracts, err := contractModel.Where(dateWhere1).Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract.contract_amount) contract_amount").FindAll()
  146. if err != nil && err != sql.ErrNoRows {
  147. return nil, err
  148. }
  149. for index, contract := range contracts {
  150. realMap[contract["incharge_id"].Int()] = contracts[index]
  151. }
  152. } else {
  153. // 回款数据统计
  154. collections, err := contractModel.InnerJoin("ctr_contract_collection", "ctr_contract.id=ctr_contract_collection.contract_id").Where("ctr_contract_collection.appro_status", "20").Where(dateWhere2).Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract_collection.collection_amount) collection_amount").FindAll()
  155. if err != nil && err != sql.ErrNoRows {
  156. return nil, err
  157. }
  158. for index, collection := range collections {
  159. realMap[collection["incharge_id"].Int()] = collections[index]
  160. }
  161. }
  162. // 统计目标值和实际值
  163. for index, target := range targets {
  164. reportData.XData = append(reportData.XData, target["sale_user_name"].String())
  165. reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
  166. if realData, ok := realMap[target["sale_user_id"].Int()]; ok {
  167. reportData.YDataReal = append(reportData.YDataReal, realData[realField].Float64())
  168. } else {
  169. reportData.YDataReal = append(reportData.YDataReal, 0)
  170. }
  171. if reportData.YDataTarget[index] == 0 {
  172. reportData.PercentData = append(reportData.PercentData, 0)
  173. } else {
  174. reportData.PercentData = append(reportData.PercentData, reportData.YDataReal[index]*100/reportData.YDataTarget[index])
  175. }
  176. }
  177. return &reportData, nil
  178. }
  179. func getQuarterGoalReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
  180. if params == nil {
  181. return nil, fmt.Errorf("请输入年度")
  182. }
  183. p := *params
  184. year := gconv.Int(p["year"])
  185. quarter := gconv.Int(p["quarter"])
  186. if year == 0 {
  187. return nil, fmt.Errorf("请输入年度")
  188. }
  189. srv, err := contractService.NewCtrContractService(ctx)
  190. if err != nil {
  191. return nil, err
  192. }
  193. goal := map[string]float64{}
  194. goaldao := srv.GoalDao.Where("year = ?", year).Where("goal_type = ?", dataType)
  195. if quarter != 0 {
  196. goaldao = goaldao.Where("quarter = ?", quarter)
  197. } else {
  198. goaldao = goaldao.Where("quarter = 1 || quarter = 2 || quarter = 3 || quarter = 4")
  199. }
  200. goalent, err := goaldao.All()
  201. if err != nil {
  202. return nil, err
  203. }
  204. for _, ent := range goalent {
  205. goal[ent.ProductLine] += ent.Amount
  206. }
  207. got := map[string]float64{}
  208. ctrdao := srv.Dao.Where("year(created_time) = ?", year)
  209. if quarter != 0 {
  210. if quarter == 1 {
  211. ctrdao = ctrdao.Where("month(created_time) in (1,2,3)")
  212. }
  213. if quarter == 2 {
  214. ctrdao = ctrdao.Where("month(created_time) in (4,5,6)")
  215. }
  216. if quarter == 3 {
  217. ctrdao = ctrdao.Where("month(created_time) in (7,8,9)")
  218. }
  219. if quarter == 4 {
  220. ctrdao = ctrdao.Where("month(created_time) in (10,11,12)")
  221. }
  222. }
  223. ctrent, err := ctrdao.All()
  224. if err != nil {
  225. return nil, err
  226. }
  227. for _, ent := range ctrent {
  228. if dataType == "10" {
  229. got[ent.ProductLine] += ent.ContractAmount
  230. }
  231. if dataType == "20" {
  232. got[ent.ProductLine] += ent.CollectedAmount
  233. }
  234. }
  235. productLine, err := service.GetDictDataByType(ctx, "sys_product_line")
  236. if err != nil {
  237. return nil, err
  238. }
  239. productLineCode := []string{}
  240. productLineName := []string{}
  241. for k, v := range productLine {
  242. productLineCode = append(productLineCode, k)
  243. productLineName = append(productLineName, v)
  244. }
  245. var reportData home.ReportData
  246. for _, c := range productLineCode {
  247. reportData.XData = append(reportData.XData, productLine[c])
  248. reportData.YDataTarget = append(reportData.YDataTarget, goal[c])
  249. reportData.YDataReal = append(reportData.YDataReal, got[c]/10000)
  250. }
  251. return &reportData, nil
  252. }
  253. func getQuarterWhere(date *gtime.Time, field string) string {
  254. if date.Month() >= 1 && date.Month() <= 3 {
  255. return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"01-01 00:00:00", field, date.Format("Y-")+"04-01 00:00:00")
  256. } else if date.Month() >= 4 && date.Month() <= 6 {
  257. return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"04-01 00:00:00", field, date.Format("Y-")+"07-01 00:00:00")
  258. } else if date.Month() >= 7 && date.Month() <= 9 {
  259. return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"07-01 00:00:00", field, date.Format("Y-")+"10-01 00:00:00")
  260. } else if date.Month() >= 10 && date.Month() <= 12 {
  261. return fmt.Sprintf("%v >= '%v' AND %v <= '%v'", field, date.Format("Y-")+"10-01 00:00:00", field, date.Format("Y-")+"12-31 23:59:59")
  262. }
  263. return ""
  264. }
  265. func getQuarterMonthWhere(date *gtime.Time, field string) string {
  266. if date.Month() >= 1 && date.Month() <= 3 {
  267. return fmt.Sprintf("%v >= %v AND %v < %v", field, 1, field, 4)
  268. } else if date.Month() >= 4 && date.Month() <= 6 {
  269. return fmt.Sprintf("%v >= %v AND %v < %v", field, 4, field, 7)
  270. } else if date.Month() >= 7 && date.Month() <= 9 {
  271. return fmt.Sprintf("%v >= %v AND %v < %v", field, 7, field, 10)
  272. } else if date.Month() >= 10 && date.Month() <= 12 {
  273. return fmt.Sprintf("%v >= %v AND %v <= %v", field, 10, field, 12)
  274. }
  275. return ""
  276. }
  277. type BusCount struct {
  278. NboType string `json:"nboType"`
  279. ProductLine string `json:"productLine"`
  280. Count int `json:"count"`
  281. Remark string `json:"remark"`
  282. }
  283. // 报表数据 三大产品线,新增以及转化项目(C转B、B转A、A转签约、C转A、C转签约、B转签约、储备转A/B/C/签约)数量, 按周和月
  284. // params 10:周 20:月
  285. func (s *HomeService) getNewAndConvertBusiness(productLine []string, params *map[string]interface{}) (interface{}, error) {
  286. if params == nil {
  287. return nil, myerrors.TipsError("请求参数传递不正确")
  288. }
  289. searchType, ok := (*params)["searchType"]
  290. if !ok {
  291. return nil, myerrors.TipsError("请求查询类型参数传递错误")
  292. }
  293. currentTime := gtime.Now()
  294. weekStart, weekEnd := currentTime.StartOfWeek(), currentTime.EndOfWeek()
  295. monthStart, monthEnd := currentTime.StartOfMonth(), currentTime.EndOfMonth()
  296. businessDao := projDao.NewProjBusinessDao(s.Tenant)
  297. busDynamicsDao := projDao.NewProjBusinessDynamicsDao(s.Tenant)
  298. contractDao := contDao.NewCtrContractDao(s.Tenant)
  299. // 获取三大产品线新增项目
  300. getAddBusCount := func(searchType string) (addCount []BusCount, err error) {
  301. commonDb := businessDao.DataScope(s.Ctx, "sale_id").Group(businessDao.C.ProductLine).OrderAsc(businessDao.C.ProductLine).
  302. Fields("product_line, count(id) as count")
  303. if searchType == "week" {
  304. err = commonDb.WhereGTE(businessDao.C.FilingTime, weekStart).WhereLTE(businessDao.C.FilingTime, weekEnd).Scan(&addCount)
  305. }
  306. if searchType == "month" {
  307. err = commonDb.WhereGTE(businessDao.C.FilingTime, monthStart).WhereLTE(businessDao.C.FilingTime, monthEnd).Scan(&addCount)
  308. }
  309. return addCount, err
  310. }
  311. addCount, err := getAddBusCount(searchType.(string))
  312. if err != nil {
  313. return nil, err
  314. }
  315. // 获取三大产品线签约项目
  316. getSignBusCount := func(searchType string) (signCount []BusCount, err error) {
  317. commonDb := contractDao.As("contract").DataScope(s.Ctx, "incharge_id").LeftJoin(businessDao.Table, "bus", "bus.id=contract.nbo_id").
  318. Fields("bus.product_line, bus.nbo_type, count(contract.id) as count").
  319. Group("bus.product_line, bus.nbo_type").Order("bus.product_line ASC, bus.nbo_type ASC")
  320. if searchType == "week" {
  321. err = commonDb.WhereGTE("contract."+contractDao.C.CreatedTime, weekStart).WhereLTE("contract."+contractDao.C.CreatedTime, weekEnd).Scan(&signCount)
  322. }
  323. if searchType == "month" {
  324. err = commonDb.WhereGTE("contract."+contractDao.C.CreatedTime, monthStart).WhereLTE("contract."+contractDao.C.CreatedTime, monthEnd).Scan(&signCount)
  325. }
  326. return signCount, err
  327. }
  328. signCount, err := getSignBusCount(searchType.(string))
  329. if err != nil {
  330. return nil, err
  331. }
  332. // 获取三大产品线转化项目(C转B、B转A、A转签约、C转A、C转签约、B转签约、储备转A/B/C/签约)数量
  333. getConvertBusData := func(searchType string) (convertData []BusCount, err error) {
  334. commonDb := busDynamicsDao.As("dy").LeftJoin(businessDao.Table, "bus", "bus.id=dy.bus_id").DataScope(s.Ctx, "sale_id", "bus").
  335. Where("dy."+busDynamicsDao.C.OpnType, projSrv.OpnUpgradeApproval).WhereNot("dy."+busDynamicsDao.C.Remark, "").
  336. Fields("bus.product_line, dy.remark").OrderAsc("bus.product_line")
  337. if searchType == "week" {
  338. err = commonDb.WhereGTE("dy."+busDynamicsDao.C.CreatedTime, weekStart).WhereLTE("dy."+busDynamicsDao.C.CreatedTime, weekEnd).Scan(&convertData)
  339. }
  340. if searchType == "month" {
  341. err = commonDb.WhereGTE("dy."+busDynamicsDao.C.CreatedTime, monthStart).WhereLTE("dy."+busDynamicsDao.C.CreatedTime, monthEnd).Scan(&convertData)
  342. }
  343. return convertData, err
  344. }
  345. convertBusData, err := getConvertBusData(searchType.(string))
  346. if err != nil {
  347. return nil, err
  348. }
  349. // 处理数据
  350. result := make([][]int, len(productLine))
  351. for i, pl := range productLine {
  352. result[i] = make([]int, 8)
  353. for _, item := range addCount {
  354. if item.ProductLine == pl {
  355. result[i][0] = item.Count
  356. }
  357. }
  358. for _, item := range signCount {
  359. if item.ProductLine != pl {
  360. continue
  361. }
  362. switch item.NboType {
  363. case projSrv.StatusA:
  364. result[i][3] += item.Count
  365. case projSrv.StatusB:
  366. result[i][6] += item.Count
  367. case projSrv.StatusC:
  368. result[i][5] += item.Count
  369. case projSrv.StatusReserve:
  370. result[i][7] += item.Count
  371. }
  372. }
  373. for _, item := range convertBusData {
  374. if item.ProductLine != pl {
  375. continue
  376. }
  377. info := gconv.Map(item.Remark)
  378. if info["origNboType"] == projSrv.StatusC && info["nboType"] == projSrv.StatusB {
  379. result[i][1] += 1
  380. }
  381. if info["origNboType"] == projSrv.StatusB && info["nboType"] == projSrv.StatusA {
  382. result[i][2] += 1
  383. }
  384. if info["origNboType"] == projSrv.StatusC && info["nboType"] == projSrv.StatusA {
  385. result[i][4] += 1
  386. }
  387. if info["origNboType"] == projSrv.StatusReserve {
  388. result[i][7] += 1
  389. }
  390. }
  391. }
  392. return result, nil
  393. }
  394. // 报表数据 三大产品线,AB类项目出货金额
  395. func (s *HomeService) getShipmentAmount(productLine, nboType []string) (interface{}, error) {
  396. businessDao := projDao.NewProjBusinessDao(s.Tenant)
  397. data, err := businessDao.Fields("product_line, nbo_type, SUM(est_trans_price) as est_trans_price").
  398. WhereIn("product_line", productLine).WhereIn("nbo_type", nboType).
  399. Group("product_line, nbo_type").Order("product_line ASC, nbo_type ASC").DataScope(s.Ctx, "sale_id").All()
  400. if err != nil {
  401. return nil, err
  402. }
  403. result := make([][]float64, len(productLine))
  404. for i, pl := range productLine {
  405. result[i] = make([]float64, len(nboType))
  406. for j, t := range nboType {
  407. for _, item := range data {
  408. if item.ProductLine == pl && item.NboType == t {
  409. result[i][j] = item.EstTransPrice
  410. }
  411. }
  412. }
  413. }
  414. return arrayReversal(result), nil
  415. }
  416. // 报表数据 三大产品线,当月和累计的签约、回款额
  417. func (s *HomeService) getProductLineSignedAndBackAmount(productLine []string) (interface{}, error) {
  418. currentTime := gtime.Now()
  419. monthStart := currentTime.StartOfMonth()
  420. monthEnd := currentTime.EndOfMonth()
  421. contractDao := contDao.NewCtrContractDao(s.Tenant)
  422. commonDao := contractDao.DataScope(s.Ctx, "incharge_id").WhereIn(contractDao.C.ProductLine, productLine).
  423. Group(contractDao.C.ProductLine).OrderAsc(contractDao.C.ProductLine)
  424. //累计签约合同金额 contract_amount
  425. allContractAmount, err := commonDao.Fields("product_line, SUM(contract_amount) as contract_amount").All()
  426. if err != nil {
  427. return nil, err
  428. }
  429. //累计回款金额 collected_amount
  430. allCollectedAmount, err := commonDao.Fields("product_line, SUM(collected_amount) as collected_amount").All()
  431. if err != nil {
  432. return nil, err
  433. }
  434. //当月签约合同金额(维度:月)
  435. monthContractAmount, err := commonDao.WhereGTE(contractDao.C.CreatedTime, monthStart).WhereLTE(contractDao.C.CreatedTime, monthEnd).
  436. Fields("product_line, SUM(contract_amount) as contract_amount").All()
  437. if err != nil {
  438. return nil, err
  439. }
  440. //当月回款金额(维度:月)
  441. monthCollectedAmount, err := commonDao.WhereGTE(contractDao.C.CreatedTime, monthStart).WhereLTE(contractDao.C.CreatedTime, monthEnd).
  442. Fields("product_line, SUM(collected_amount) as collected_amount").All()
  443. if err != nil {
  444. return nil, err
  445. }
  446. result := make([][]float64, len(productLine))
  447. for i, pl := range productLine {
  448. result[i] = make([]float64, 4)
  449. for _, item := range monthContractAmount {
  450. if item.ProductLine == pl {
  451. result[i][0] = item.ContractAmount
  452. }
  453. }
  454. for _, item := range allContractAmount {
  455. if item.ProductLine == pl {
  456. result[i][1] = item.ContractAmount
  457. }
  458. }
  459. for _, item := range monthCollectedAmount {
  460. if item.ProductLine == pl {
  461. result[i][2] = item.CollectedAmount
  462. }
  463. }
  464. for _, item := range allCollectedAmount {
  465. if item.ProductLine == pl {
  466. result[i][3] = item.CollectedAmount
  467. }
  468. }
  469. }
  470. return arrayReversal(result), nil
  471. }
  472. // 二维数组反转
  473. func arrayReversal(result [][]float64) [][]float64 {
  474. if len(result) == 0 {
  475. return [][]float64{}
  476. }
  477. data := make([][]float64, len(result[0]))
  478. for k, v := range result {
  479. for m, n := range v {
  480. if k == 0 {
  481. data[m] = make([]float64, len(result))
  482. }
  483. data[m][k] = n
  484. }
  485. }
  486. return data
  487. }