excel_info.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package models
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "fmt"
  6. "time"
  7. )
  8. type ExcelInfo struct {
  9. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" description:"表格ID"`
  10. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  11. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  12. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  13. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  14. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  15. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  16. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  17. Content string `gorm:"column:content" description:"表格内容"`
  18. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  19. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  20. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  21. IsDelete int `gorm:"column:is_delete" description:"是否删除,0:未删除,1:已删除"`
  22. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  23. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  24. }
  25. func (e *ExcelInfo) TableName() string {
  26. return "excel_info"
  27. }
  28. func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
  29. o := global.DmSQL["data"]
  30. err = o.Model(excelInfo).Select(cols).Updates(excelInfo).Error
  31. return
  32. }
  33. type MyExcelInfoList struct {
  34. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" description:"表格ID" orm:"column(excel_info_id);pk"`
  35. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  36. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  37. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  38. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  39. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  40. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  41. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  42. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  43. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  44. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  45. }
  46. func AddExcelInfo(excelInfo *ExcelInfo) (err error) {
  47. o := global.DmSQL["data"]
  48. err = o.Create(excelInfo).Error
  49. return
  50. }
  51. func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string) (err error) {
  52. o := global.DmSQL["data"]
  53. err = o.Model(excelInfo).Select(updateExcelInfoParams).Updates(excelInfo).Error
  54. return
  55. }
  56. func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  57. o := global.DmSQL["data"]
  58. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  59. err = o.Raw(sql, excelInfoId).First(&item).Error
  60. return
  61. }
  62. func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
  63. o := global.DmSQL["data"]
  64. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  65. err = o.Raw(sql, excelInfoId).First(&item).Error
  66. return
  67. }
  68. func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  69. o := global.DmSQL["data"]
  70. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  71. if condition != "" {
  72. sql += condition
  73. }
  74. err = o.Raw(sql, pars...).Scan(&count).Error
  75. return
  76. }
  77. func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  78. o := global.DmSQL["data"]
  79. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  80. if condition != "" {
  81. sql += condition
  82. }
  83. err = o.Raw(sql, pars...).First(&item).Error
  84. return
  85. }
  86. func GetNextExcelInfo(classifyId int) (item *ExcelInfo, err error) {
  87. o := global.DmSQL["data"]
  88. sql := ` SELECT b.* FROM excel_classify AS a
  89. INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  90. WHERE a.excel_classify_id>? AND is_delete=0
  91. ORDER BY a.excel_classify_id ASC
  92. LIMIT 1 `
  93. err = o.Raw(sql, classifyId).First(&item).Error
  94. return
  95. }
  96. func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  97. o := global.DmSQL["data"]
  98. sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  99. err = o.Exec(sql, imageUrl, excelInfoId).Error
  100. if err != nil {
  101. fmt.Println("EditExcelInfoImage Err:", err.Error())
  102. return err
  103. }
  104. return
  105. }
  106. func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfoView, err error) {
  107. o := global.DmSQL["data"]
  108. sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  109. err = o.Raw(sql, uniqueCode).First(&item).Error
  110. return
  111. }
  112. func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  113. o := global.DmSQL["data"]
  114. sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id asc limit 1`
  115. err = o.Raw(sql, classifyId).First(&item).Error
  116. return
  117. }
  118. func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string) (err error) {
  119. o := global.DmSQL["data"]
  120. sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? and sort > ? AND is_delete=0 `
  121. if prevExcelInfoId > 0 {
  122. sql += ` or (excel_info_id > ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  123. }
  124. err = o.Exec(sql, classifyId, nowSort).Error
  125. return
  126. }
  127. type ExcelInfoView struct {
  128. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" description:"表格ID" orm:"column(excel_info_id);pk"`
  129. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  130. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  131. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  132. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  133. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  134. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  135. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  136. Content string `gorm:"column:content" description:"表格内容"`
  137. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  138. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  139. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  140. IsDelete int `gorm:"column:is_delete" description:"是否删除,0:未删除,1:已删除" json:"-"`
  141. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  142. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  143. SourcesFrom string `gorm:"column:sources_from" description:"图表来源"`
  144. }
  145. func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  146. o := global.DmSQL["data"]
  147. sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  148. err = o.Raw(sql, classifyId, excelName).First(&item).Error
  149. return
  150. }
  151. func GetExcelInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ExcelInfo, err error) {
  152. num := len(uniqueCodeSlice)
  153. if num <= 0 {
  154. return
  155. }
  156. o := global.DmSQL["data"]
  157. sql := ` SELECT * FROM excel_info WHERE unique_code in ("` + utils.GetGormInReplace(num) + `") AND is_delete=0 `
  158. err = o.Raw(sql, uniqueCodeSlice).Scan(&items).Error
  159. total = int64(len(items))
  160. return
  161. }
  162. func GetExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  163. o := global.DmSQL["data"]
  164. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  165. if condition != "" {
  166. sql += condition
  167. }
  168. sql += " ORDER BY create_time DESC LIMIT ?,? "
  169. pars = append(pars, startSize, pageSize)
  170. err = o.Raw(sql, pars...).Scan(&item).Error
  171. return
  172. }
  173. func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  174. o := global.DmSQL["data"]
  175. sql := ` SELECT excel_info_id,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time
  176. FROM excel_info WHERE 1=1 AND is_delete=0 `
  177. if condition != "" {
  178. sql += condition
  179. }
  180. sql += " ORDER BY create_time DESC LIMIT ?,? "
  181. pars = append(pars, startSize, pageSize)
  182. err = o.Raw(sql, pars...).Scan(&item).Error
  183. return
  184. }
  185. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  186. o := global.DmSQL["data"]
  187. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. err = o.Raw(sql, pars...).Scan(&count).Error
  192. return
  193. }
  194. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  195. o := global.DmSQL["data"]
  196. sql := ` SELECT * FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
  197. err = o.Raw(sql, excelInfoId).First(&item).Error
  198. return
  199. }
  200. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  201. o := global.DmSQL["data"]
  202. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  203. err = o.Raw(sql, classifyId).Scan(&total).Error
  204. return
  205. }
  206. func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
  207. o := global.DmSQL["data"]
  208. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  209. if condition != "" {
  210. sql += condition
  211. }
  212. sql += ` ORDER BY sort asc, excel_info_id asc`
  213. err = o.Raw(sql, pars...).Scan(&items).Error
  214. return
  215. }