custom_analysis.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package excel
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/excel"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/utils"
  9. "strconv"
  10. "time"
  11. )
  12. // AddCustomAnalysisTable 添加自定义分析表格
  13. func AddCustomAnalysisTable(excelName, content, excelImage string, excelClassifyId int, sysUser *system.Admin) (excelInfo *data_manage.ExcelInfo, err error, errMsg string, isSendEmail bool) {
  14. isSendEmail = true
  15. contentByte := []byte(content)
  16. var luckySheet LuckySheet
  17. err = json.Unmarshal(contentByte, &luckySheet)
  18. if err != nil {
  19. return
  20. }
  21. return
  22. excelClassify, err := data_manage.GetExcelClassifyById(excelClassifyId)
  23. if err != nil {
  24. if err.Error() == utils.ErrNoRow() {
  25. errMsg = "分类不存在"
  26. err = errors.New(errMsg)
  27. isSendEmail = false
  28. return
  29. }
  30. errMsg = "获取分类信息失败"
  31. err = errors.New("获取分类信息失败,Err:" + err.Error())
  32. return
  33. }
  34. if excelClassify == nil {
  35. errMsg = "分类不存在"
  36. err = errors.New(errMsg)
  37. isSendEmail = false
  38. return
  39. }
  40. if excelClassify.Source != utils.CUSTOM_ANALYSIS_TABLE {
  41. errMsg = "当前分类不是自定义分析分类"
  42. err = errors.New("当前分类不是自定义分析分类")
  43. isSendEmail = false
  44. return
  45. }
  46. // 校验是否同名文件
  47. {
  48. var condition string
  49. var pars []interface{}
  50. condition += " AND excel_classify_id=? "
  51. pars = append(pars, excelClassifyId)
  52. condition += " AND excel_name=? "
  53. pars = append(pars, excelName)
  54. // 获取分类下是否存在该表格名称
  55. count, tmpErr := data_manage.GetExcelInfoCountByCondition(condition, pars)
  56. if tmpErr != nil {
  57. errMsg = "判断表格名称是否存在失败"
  58. err = errors.New("判断表格名称是否存在失败,Err:" + tmpErr.Error())
  59. return
  60. }
  61. if count > 0 {
  62. errMsg = "表格名称已存在,请重新填写表格名称"
  63. err = errors.New(errMsg)
  64. isSendEmail = false
  65. return
  66. }
  67. }
  68. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  69. // 表格
  70. excelInfo = &data_manage.ExcelInfo{
  71. //ExcelInfoId: 0,
  72. ExcelName: excelName,
  73. Source: utils.CUSTOM_ANALYSIS_TABLE,
  74. //ExcelType: req.ExcelType,
  75. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  76. ExcelClassifyId: excelClassifyId,
  77. SysUserId: sysUser.AdminId,
  78. SysUserRealName: sysUser.RealName,
  79. Content: ``,
  80. ExcelImage: excelImage,
  81. Sort: 0,
  82. IsDelete: 0,
  83. ModifyTime: time.Now(),
  84. CreateTime: time.Now(),
  85. }
  86. sheetsList := make([]*excel.ExcelSheet, 0)
  87. // sheet处理
  88. for k, sheetInfo := range luckySheet.Sheets {
  89. sheetsList = append(sheetsList, &excel.ExcelSheet{
  90. ExcelSheetId: 0,
  91. ExcelInfoId: 0,
  92. SheetName: sheetInfo.Name,
  93. Sort: k,
  94. ModifyTime: time.Now(),
  95. CreateTime: time.Now(),
  96. })
  97. //sheetData := make([]*excel.ExcelSheetData, 0)
  98. }
  99. //err = data_manage.AddExcelInfo(excelInfo)
  100. return
  101. }
  102. type LuckySheet struct {
  103. Info struct {
  104. Name string `json:"name"`
  105. Creator string `json:"creator"`
  106. Lastmodifiedby string `json:"lastmodifiedby"`
  107. CreatedTime time.Time `json:"createdTime"`
  108. ModifiedTime time.Time `json:"modifiedTime"`
  109. Company string `json:"company"`
  110. Appversion string `json:"appversion"`
  111. } `json:"info"`
  112. Sheets []struct {
  113. Name string `json:"name"`
  114. //Config struct {
  115. // Columnlen struct {
  116. // Num15 int `json:"15"`
  117. // Num16 int `json:"16"`
  118. // Num20 int `json:"20"`
  119. // Num34 int `json:"34"`
  120. // Num35 int `json:"35"`
  121. // } `json:"columnlen"`
  122. //} `json:"config"`
  123. Index string `json:"index"`
  124. Order string `json:"order"`
  125. ZoomRatio int `json:"zoomRatio"`
  126. ShowGridLines string `json:"showGridLines"`
  127. DefaultColWidth int `json:"defaultColWidth"`
  128. DefaultRowHeight int `json:"defaultRowHeight"`
  129. Celldata []struct {
  130. R int `json:"r"`
  131. C int `json:"c"`
  132. V interface{} `json:"v,omitempty"`
  133. } `json:"celldata"`
  134. CalcChain []interface{} `json:"calcChain"`
  135. //DataVerification struct {
  136. //} `json:"dataVerification"`
  137. //Hyperlink struct {
  138. //} `json:"hyperlink"`
  139. //Hide int `json:"hide"`
  140. } `json:"sheets"`
  141. }