excel_info.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_ETA_mobile_api/utils"
  6. "time"
  7. )
  8. // ExcelInfo excel表格详情表
  9. type ExcelInfo struct {
  10. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  11. ExcelName string `description:"表格名称"`
  12. UniqueCode string `description:"表格唯一编码"`
  13. ExcelClassifyId int `description:"表格分类id"`
  14. SysUserId int `description:"操作人id"`
  15. SysUserRealName string `description:"操作人真实姓名"`
  16. Content string `description:"表格内容"`
  17. ExcelImage string `description:"表格图片"`
  18. FileUrl string `description:"表格下载地址"`
  19. Sort int `description:"排序字段,数字越小越排前面"`
  20. IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  21. ModifyTime time.Time `description:"最近修改日期"`
  22. CreateTime time.Time `description:"创建日期"`
  23. }
  24. // Update 更新 excel表格基础信息
  25. func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. _, err = o.Update(excelInfo, cols...)
  28. return
  29. }
  30. type MyExcelInfoList struct {
  31. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  32. ExcelName string `description:"表格名称"`
  33. UniqueCode string `description:"表格唯一编码"`
  34. ExcelClassifyId int `description:"表格分类id"`
  35. SysUserId int `description:"操作人id"`
  36. SysUserRealName string `description:"操作人真实姓名"`
  37. ExcelImage string `description:"表格图片"`
  38. FileUrl string `description:"表格下载地址"`
  39. Sort int `description:"排序字段,数字越小越排前面"`
  40. ModifyTime time.Time `description:"最近修改日期"`
  41. CreateTime time.Time `description:"创建日期"`
  42. }
  43. // AddExcelInfo 新增表格
  44. func AddExcelInfo(excelInfo *ExcelInfo) (err error) {
  45. o := orm.NewOrmUsingDB("data")
  46. // 表格信息入库
  47. lastId, err := o.Insert(excelInfo)
  48. if err != nil {
  49. return
  50. }
  51. excelInfo.ExcelInfoId = int(lastId)
  52. return
  53. }
  54. // EditExcelInfo 编辑表格
  55. func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string) (err error) {
  56. o := orm.NewOrmUsingDB("data")
  57. // ETA表格信息变更
  58. _, err = o.Update(excelInfo, updateExcelInfoParams...)
  59. return
  60. }
  61. // GetExcelInfoById 根据id 获取eta表格详情
  62. func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  65. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  66. return
  67. }
  68. func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  69. o := orm.NewOrmUsingDB("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).QueryRow(&count)
  75. return
  76. }
  77. func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  78. o := orm.NewOrmUsingDB("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).QueryRow(&item)
  84. return
  85. }
  86. // GetNextExcelInfoByCondition 根据条件获取下一个表格
  87. func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  88. o := orm.NewOrmUsingDB("data")
  89. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  90. if condition != "" {
  91. sql += condition
  92. }
  93. sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
  94. err = o.Raw(sql, pars).QueryRow(&item)
  95. return
  96. }
  97. // GetNextExcelInfo 根据分类id获取下一个excel表格
  98. func GetNextExcelInfo(classifyId, classifySort int) (item *ExcelInfo, err error) {
  99. o := orm.NewOrmUsingDB("data")
  100. sql := ` SELECT b.* FROM excel_classify AS a
  101. INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  102. WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
  103. ORDER BY a.sort ASC,b.sort asc,b.create_time desc
  104. LIMIT 1 `
  105. err = o.Raw(sql, classifySort, classifySort, classifyId).QueryRow(&item)
  106. return
  107. }
  108. // EditExcelInfoImage 修改excel表格的图片
  109. func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  112. _, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
  113. if err != nil {
  114. fmt.Println("EditExcelInfoImage Err:", err.Error())
  115. return err
  116. }
  117. return
  118. }
  119. // GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  120. func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
  121. o := orm.NewOrmUsingDB("data")
  122. sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  123. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  124. return
  125. }
  126. // GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  127. func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  128. o := orm.NewOrmUsingDB("data")
  129. sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id asc limit 1`
  130. err = o.Raw(sql, classifyId).QueryRow(&item)
  131. return
  132. }
  133. // UpdateExcelInfoSortByClassifyId 根据表格id更新排序
  134. func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string) (err error) {
  135. o := orm.NewOrmUsingDB("data")
  136. sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? and sort > ? AND is_delete=0 `
  137. if prevExcelInfoId > 0 {
  138. sql += ` or (excel_info_id > ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  139. }
  140. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  141. return
  142. }
  143. // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  144. func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  145. o := orm.NewOrmUsingDB("data")
  146. sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  147. err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
  148. return
  149. }
  150. // GetExcelInfoListByUniqueCodeSlice 根据表格编码获取表格列表数据
  151. func GetExcelInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ExcelInfo, err error) {
  152. num := len(uniqueCodeSlice)
  153. if num <= 0 {
  154. return
  155. }
  156. o := orm.NewOrmUsingDB("data")
  157. sql := ` SELECT * FROM excel_info WHERE unique_code in ("` + utils.GetOrmInReplace(num) + `") AND is_delete=0 `
  158. total, err = o.Raw(sql, uniqueCodeSlice).QueryRows(&items)
  159. return
  160. }
  161. // GetExcelListByCondition 获取excel表格列表数据
  162. func GetExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  163. o := orm.NewOrmUsingDB("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 sort ASC,chart_info_id DESC LIMIT ?,? "
  169. sql += " ORDER BY create_time DESC LIMIT ?,? "
  170. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  171. return
  172. }
  173. // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  174. func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  175. o := orm.NewOrmUsingDB("data")
  176. 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
  177. FROM excel_info WHERE 1=1 AND is_delete=0 `
  178. if condition != "" {
  179. sql += condition
  180. }
  181. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  182. sql += " ORDER BY create_time DESC LIMIT ?,? "
  183. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  184. return
  185. }
  186. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  187. o := orm.NewOrmUsingDB("data")
  188. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  189. if condition != "" {
  190. sql += condition
  191. }
  192. err = o.Raw(sql, pars).QueryRow(&count)
  193. return
  194. }
  195. // GetMyExcelListByAdminId 根据操作人id获取表格列表
  196. func GetMyExcelListByAdminId(adminId int) (item []*MyChartView, err error) {
  197. o := orm.NewOrmUsingDB("data")
  198. //sql := ` SELECT * FROM my_chart WHERE 1=1 AND admin_id=? `
  199. sql := ` SELECT a.*,GROUP_CONCAT(c.my_chart_classify_id SEPARATOR ',') AS my_chart_classify_id FROM my_chart AS a
  200. LEFT JOIN my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
  201. 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
  202. WHERE 1=1 AND a.admin_id=? AND a.source=2
  203. GROUP BY a.chart_info_id `
  204. _, err = o.Raw(sql, adminId).QueryRows(&item)
  205. return
  206. }
  207. // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  208. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  209. o := orm.NewOrmUsingDB("data")
  210. sql := ` SELECT * FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
  211. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  212. return
  213. }
  214. // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  215. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  216. o := orm.NewOrmUsingDB("data")
  217. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  218. err = o.Raw(sql, classifyId).QueryRow(&total)
  219. return
  220. }