excel_info.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ExcelInfo excel表格详情表
  8. type ExcelInfo struct {
  9. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  10. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  11. ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  12. ExcelName string `description:"表格名称"`
  13. UniqueCode string `description:"表格唯一编码"`
  14. ExcelClassifyId int `description:"表格分类id"`
  15. SysUserId int `description:"操作人id"`
  16. SysUserRealName string `description:"操作人真实姓名"`
  17. Content string `description:"表格内容"`
  18. ExcelImage string `description:"表格图片"`
  19. FileUrl string `description:"表格下载地址"`
  20. Sort int `description:"排序字段,数字越小越排前面"`
  21. IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  22. ModifyTime time.Time `description:"最近修改日期"`
  23. CreateTime time.Time `description:"创建日期"`
  24. }
  25. // Update 更新 excel表格基础信息
  26. func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
  27. o := orm.NewOrmUsingDB("data")
  28. _, err = o.Update(excelInfo, cols...)
  29. return
  30. }
  31. type MyExcelInfoList struct {
  32. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  33. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  34. ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  35. ExcelName string `description:"表格名称"`
  36. UniqueCode string `description:"表格唯一编码"`
  37. ExcelClassifyId int `description:"表格分类id"`
  38. SysUserId int `description:"操作人id"`
  39. SysUserRealName string `description:"操作人真实姓名"`
  40. ExcelImage string `description:"表格图片"`
  41. FileUrl string `description:"表格下载地址"`
  42. Sort int `description:"排序字段,数字越小越排前面"`
  43. ModifyTime time.Time `description:"最近修改日期"`
  44. CreateTime time.Time `description:"创建日期"`
  45. }
  46. // AddExcelInfo 新增表格
  47. func AddExcelInfo(excelInfo *ExcelInfo) (err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. // 表格信息入库
  50. lastId, err := o.Insert(excelInfo)
  51. if err != nil {
  52. return
  53. }
  54. excelInfo.ExcelInfoId = int(lastId)
  55. return
  56. }
  57. // EditExcelInfo 编辑表格
  58. func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string) (err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. // ETA表格信息变更
  61. _, err = o.Update(excelInfo, updateExcelInfoParams...)
  62. return
  63. }
  64. // GetExcelInfoAll 获取所有表格列表,用于分类展示
  65. func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  68. unique_code,sys_user_id,sys_user_real_name,start_date
  69. FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
  70. _, err = o.Raw(sql).QueryRows(&items)
  71. return
  72. }
  73. // GetNoContentExcelInfoAll 获取不含content的表格列表 用于分类展示
  74. func GetNoContentExcelInfoAll() (items []*ExcelClassifyItems, err error) {
  75. o := orm.NewOrmUsingDB("data")
  76. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  77. unique_code,sys_user_id,sys_user_real_name
  78. FROM excel_info where is_delete=0 ORDER BY sort asc,create_time desc `
  79. _, err = o.Raw(sql).QueryRows(&items)
  80. return
  81. }
  82. // GetExcelInfoById 根据id 获取eta表格详情
  83. func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  86. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  87. return
  88. }
  89. func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  92. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  93. return
  94. }
  95. func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  98. if condition != "" {
  99. sql += condition
  100. }
  101. err = o.Raw(sql, pars).QueryRow(&count)
  102. return
  103. }
  104. func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  105. o := orm.NewOrmUsingDB("data")
  106. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  107. if condition != "" {
  108. sql += condition
  109. }
  110. err = o.Raw(sql, pars).QueryRow(&item)
  111. return
  112. }
  113. // GetNextExcelInfoByCondition 根据条件获取下一个表格
  114. func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  115. o := orm.NewOrmUsingDB("data")
  116. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  117. if condition != "" {
  118. sql += condition
  119. }
  120. sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
  121. err = o.Raw(sql, pars).QueryRow(&item)
  122. return
  123. }
  124. // GetNextExcelInfo 根据分类id获取下一个excel表格
  125. func GetNextExcelInfo(classifyId, classifySort int) (item *ExcelInfo, err error) {
  126. o := orm.NewOrmUsingDB("data")
  127. sql := ` SELECT b.* FROM excel_classify AS a
  128. INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  129. WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
  130. ORDER BY a.sort ASC,b.sort asc,b.create_time desc
  131. LIMIT 1 `
  132. err = o.Raw(sql, classifySort, classifySort, classifyId).QueryRow(&item)
  133. return
  134. }
  135. // EditExcelInfoImage 修改excel表格的图片
  136. func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  137. o := orm.NewOrmUsingDB("data")
  138. sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  139. _, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
  140. if err != nil {
  141. fmt.Println("EditExcelInfoImage Err:", err.Error())
  142. return err
  143. }
  144. return
  145. }
  146. // GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  147. func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
  148. o := orm.NewOrmUsingDB("data")
  149. sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  150. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  151. return
  152. }
  153. // GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  154. func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  155. o := orm.NewOrmUsingDB("data")
  156. sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id asc limit 1`
  157. err = o.Raw(sql, classifyId).QueryRow(&item)
  158. return
  159. }
  160. // UpdateExcelInfoSortByClassifyId 根据表格id更新排序
  161. func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string) (err error) {
  162. o := orm.NewOrmUsingDB("data")
  163. sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? and sort > ? AND is_delete=0 `
  164. if prevExcelInfoId > 0 {
  165. sql += ` or (excel_info_id > ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  166. }
  167. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  168. return
  169. }
  170. type ExcelInfoView struct {
  171. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  172. ExcelName string `description:"来源名称"`
  173. ExcelClassifyId int `description:"表格分类id"`
  174. ExcelClassifyName string `description:"表格名称"`
  175. SysUserId int
  176. SysUserRealName string
  177. UniqueCode string `description:"表格唯一编码"`
  178. CreateTime time.Time
  179. ModifyTime time.Time
  180. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  181. StartDate string `description:"自定义开始日期"`
  182. EndDate string `description:"自定义结束日期"`
  183. IsSetName int `description:"设置名称"`
  184. EdbInfoIds string `description:"指标id"`
  185. ExcelType int `description:"生成样式:1:曲线图,2:季节性图"`
  186. Calendar string `description:"公历/农历"`
  187. SeasonStartDate string `description:"季节性图开始日期"`
  188. SeasonEndDate string `description:"季节性图开始日期"`
  189. ExcelImage string `description:"表格图片"`
  190. Sort int `description:"排序字段,数字越小越排前面"`
  191. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  192. MyExcelId int
  193. MyExcelClassifyId string `description:"我的表格分类,多个用逗号隔开"`
  194. ExcelClassify []*ExcelClassifyView
  195. EdbEndDate string `description:"指标最新更新日期"`
  196. LeftMin string `description:"表格左侧最小值"`
  197. LeftMax string `description:"表格左侧最大值"`
  198. RightMin string `description:"表格右侧最小值"`
  199. RightMax string `description:"表格右侧最大值"`
  200. }
  201. // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  202. func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  203. o := orm.NewOrmUsingDB("data")
  204. sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  205. err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
  206. return
  207. }
  208. // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  209. func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  210. o := orm.NewOrmUsingDB("data")
  211. sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time
  212. FROM excel_info WHERE 1=1 AND is_delete=0 `
  213. if condition != "" {
  214. sql += condition
  215. }
  216. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  217. sql += " ORDER BY create_time DESC LIMIT ?,? "
  218. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  219. return
  220. }
  221. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  222. o := orm.NewOrmUsingDB("data")
  223. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  224. if condition != "" {
  225. sql += condition
  226. }
  227. err = o.Raw(sql, pars).QueryRow(&count)
  228. return
  229. }
  230. // GetMyExcelListByAdminId 根据操作人id获取表格列表
  231. func GetMyExcelListByAdminId(adminId int) (item []*MyChartView, err error) {
  232. o := orm.NewOrmUsingDB("data")
  233. //sql := ` SELECT * FROM my_chart WHERE 1=1 AND admin_id=? `
  234. sql := ` SELECT a.*,GROUP_CONCAT(c.my_chart_classify_id SEPARATOR ',') AS my_chart_classify_id FROM my_chart AS a
  235. LEFT JOIN my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
  236. LEFT JOIN my_chart_classify AS c ON b.my_chart_classify_id=c.my_chart_classify_id AND b.admin_id=c.admin_id
  237. WHERE 1=1 AND a.admin_id=? AND a.source=2
  238. GROUP BY a.chart_info_id `
  239. _, err = o.Raw(sql, adminId).QueryRows(&item)
  240. return
  241. }
  242. // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  243. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  244. o := orm.NewOrmUsingDB("data")
  245. sql := ` SELECT * FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
  246. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  247. return
  248. }
  249. // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  250. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  251. o := orm.NewOrmUsingDB("data")
  252. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  253. err = o.Raw(sql, classifyId).QueryRow(&total)
  254. return
  255. }