excel_info.go 13 KB

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