excel_info.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. package excel
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "fmt"
  6. "time"
  7. )
  8. // ExcelInfo excel表格详情表
  9. //
  10. // type ExcelInfo struct {
  11. // ExcelInfoId int `orm:"column(excel_info_id);pk"`
  12. // Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  13. // ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  14. // ExcelName string `description:"表格名称"`
  15. // UniqueCode string `description:"表格唯一编码"`
  16. // ExcelClassifyId int `description:"表格分类id"`
  17. // SysUserId int `description:"操作人id"`
  18. // SysUserRealName string `description:"操作人真实姓名"`
  19. // Content string `description:"表格内容"`
  20. // ExcelImage string `description:"表格图片"`
  21. // FileUrl string `description:"表格下载地址"`
  22. // Sort int `description:"排序字段,数字越小越排前面"`
  23. // IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  24. // ModifyTime time.Time `description:"最近修改日期"`
  25. // CreateTime time.Time `description:"创建日期"`
  26. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  27. // BalanceType int `description:"平衡表类型:0 动态表,1静态表"`
  28. // UpdateUserId int `description:"更新人id"`
  29. // UpdateUserRealName string `description:"更新人真实姓名"`
  30. // RelExcelInfoId int `description:"平衡表里静态表关联的动态表excel id"`
  31. // VersionName string `description:"静态表版本名称"`
  32. // }
  33. type ExcelInfo struct {
  34. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" orm:"column(excel_info_id);pk"`
  35. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  36. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  37. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  38. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  39. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  40. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  41. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  42. Content string `gorm:"column:content" description:"表格内容"`
  43. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  44. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  45. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  46. IsDelete int `gorm:"column:is_delete" description:"是否删除,0:未删除,1:已删除"`
  47. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  48. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  49. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  50. BalanceType int `gorm:"column:balance_type" description:"平衡表类型:0 动态表,1静态表"`
  51. UpdateUserId int `gorm:"column:update_user_id" description:"更新人id"`
  52. UpdateUserRealName string `gorm:"column:update_user_real_name" description:"更新人真实姓名"`
  53. RelExcelInfoId int `gorm:"column:rel_excel_info_id" description:"平衡表里静态表关联的动态表excel id"`
  54. VersionName string `gorm:"column:version_name" description:"静态表版本名称"`
  55. }
  56. // Update 更新 excel表格基础信息
  57. func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
  58. o := global.DmSQL["data"]
  59. err = o.Model(excelInfo).Select(cols).Updates(excelInfo).Error
  60. return
  61. }
  62. // type MyExcelInfoList struct {
  63. // ExcelInfoId int `orm:"column(excel_info_id);pk"`
  64. // Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  65. // ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  66. // ExcelName string `description:"表格名称"`
  67. // UniqueCode string `description:"表格唯一编码"`
  68. // ExcelClassifyId int `description:"表格分类id"`
  69. // SysUserId int `description:"操作人id"`
  70. // SysUserRealName string `description:"操作人真实姓名"`
  71. // ExcelImage string `description:"表格图片"`
  72. // FileUrl string `description:"表格下载地址"`
  73. // Sort int `description:"排序字段,数字越小越排前面"`
  74. // ModifyTime time.Time `description:"最近修改日期"`
  75. // CreateTime time.Time `description:"创建日期"`
  76. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  77. // HaveOperaAuth bool `description:"是否有数据权限"`
  78. // }
  79. type MyExcelInfoList struct {
  80. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" orm:"column(excel_info_id);pk"`
  81. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  82. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  83. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  84. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  85. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  86. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  87. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  88. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  89. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  90. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  91. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  92. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  93. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  94. HaveOperaAuth bool `gorm:"column:have_opera_auth" description:"是否有数据权限"`
  95. }
  96. // AddExcelInfo 新增表格
  97. func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  98. o := global.DmSQL["data"].Begin()
  99. defer func() {
  100. if err != nil {
  101. _ = o.Rollback()
  102. } else {
  103. _ = o.Commit()
  104. }
  105. }()
  106. // 表格信息入库
  107. err = o.Create(excelInfo).Error
  108. if err != nil {
  109. return
  110. }
  111. // excel与指标的关联关系
  112. dataNum := len(excelEdbMappingList)
  113. if dataNum > 0 {
  114. for k, v := range excelEdbMappingList {
  115. v.ExcelInfoId = excelInfo.ExcelInfoId
  116. excelEdbMappingList[k] = v
  117. }
  118. err = o.CreateInBatches(excelEdbMappingList, utils.MultiAddNum).Error
  119. }
  120. return
  121. }
  122. // EditExcelInfo 编辑表格
  123. func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  124. o := global.DmSQL["data"].Begin()
  125. defer func() {
  126. if err != nil {
  127. _ = o.Rollback()
  128. } else {
  129. _ = o.Commit()
  130. }
  131. }()
  132. // ETA表格信息变更
  133. err = o.Model(excelInfo).Select(updateExcelInfoParams).Updates(excelInfo).Error
  134. if err != nil {
  135. return
  136. }
  137. // 删除关系表
  138. sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
  139. err = o.Exec(sql, excelInfo.ExcelInfoId).Error
  140. if err != nil {
  141. return
  142. }
  143. // excel与指标的关联关系
  144. dataNum := len(excelEdbMappingList)
  145. if dataNum > 0 {
  146. for k, v := range excelEdbMappingList {
  147. v.ExcelInfoId = excelInfo.ExcelInfoId
  148. excelEdbMappingList[k] = v
  149. }
  150. err = o.CreateInBatches(excelEdbMappingList, utils.MultiAddNum).Error
  151. }
  152. return
  153. }
  154. // GetExcelInfoAll 获取所有表格列表,用于分类展示
  155. func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
  156. o := global.DmSQL["data"]
  157. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  158. unique_code,sys_user_id,sys_user_real_name,is_join_permission
  159. FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
  160. err = o.Raw(sql).Scan(&items).Error
  161. return
  162. }
  163. // GetNoContentExcelInfoAll 获取不含content的表格列表 用于分类展示
  164. func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems, err error) {
  165. o := global.DmSQL["data"]
  166. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  167. unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission
  168. FROM excel_info where is_delete=0 AND source = ? `
  169. pars := []interface{}{source}
  170. if userId > 0 {
  171. sql += ` AND sys_user_id = ? `
  172. pars = append(pars, userId)
  173. }
  174. sql += ` ORDER BY sort asc,excel_info_id desc `
  175. err = o.Raw(sql, pars...).Scan(&items).Error
  176. return
  177. }
  178. // GetAllExcelInfoBySource 根据来源获取包含content的表格列表
  179. func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
  180. o := global.DmSQL["data"]
  181. sql := ` SELECT * FROM excel_info where is_delete=0 AND source = ? ORDER BY sort asc,create_time desc `
  182. err = o.Raw(sql, source).Scan(&items).Error
  183. return
  184. }
  185. // GetExcelInfoById 根据id 获取eta表格详情
  186. func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  187. o := global.DmSQL["data"]
  188. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  189. err = o.Raw(sql, excelInfoId).First(&item).Error
  190. return
  191. }
  192. // GetExcelInfoByUnicode 编码获取表格
  193. func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
  194. o := global.DmSQL["data"]
  195. sql := ` SELECT * FROM excel_info WHERE unique_code = ? AND is_delete = 0 `
  196. err = o.Raw(sql, unicode).First(&item).Error
  197. return
  198. }
  199. func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
  200. o := global.DmSQL["data"]
  201. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  202. err = o.Raw(sql, excelInfoId).First(&item).Error
  203. return
  204. }
  205. func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  206. o := global.DmSQL["data"]
  207. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  208. if condition != "" {
  209. sql += condition
  210. }
  211. err = o.Raw(sql, pars).Scan(&count).Error
  212. return
  213. }
  214. func GetNoContentExcelInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ExcelClassifyItems, err error) {
  215. o := global.DmSQL["data"]
  216. sql := `SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  217. unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission FROM excel_info WHERE 1=1 `
  218. if condition != "" {
  219. sql += condition
  220. }
  221. sql += ` AND is_delete=0 ORDER BY excel_info_id DESC LIMIT ?,? `
  222. err = o.Raw(sql, pars, startSize, pageSize).Scan(&items).Error
  223. return
  224. }
  225. func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  226. o := global.DmSQL["data"]
  227. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  228. if condition != "" {
  229. sql += condition
  230. }
  231. err = o.Raw(sql, pars).First(&item).Error
  232. return
  233. }
  234. // GetNextExcelInfoByCondition 根据条件获取下一个表格
  235. func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  236. o := global.DmSQL["data"]
  237. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  238. if condition != "" {
  239. sql += condition
  240. }
  241. sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
  242. err = o.Raw(sql, pars).First(&item).Error
  243. return
  244. }
  245. // GetNextExcelInfo 根据分类id获取下一个excel表格
  246. func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, err error) {
  247. o := global.DmSQL["data"]
  248. sql := ` SELECT b.* FROM excel_classify AS a
  249. INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  250. WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
  251. AND a.source = ? AND b.source = ?
  252. ORDER BY a.sort ASC,b.sort asc,b.create_time desc
  253. LIMIT 1 `
  254. err = o.Raw(sql, classifySort, classifySort, classifyId, source, source).First(&item).Error
  255. return
  256. }
  257. // EditExcelInfoImage 修改excel表格的图片
  258. func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  259. o := global.DmSQL["data"]
  260. sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  261. err = o.Exec(sql, imageUrl, excelInfoId).Error
  262. if err != nil {
  263. fmt.Println("EditExcelInfoImage Err:", err.Error())
  264. return err
  265. }
  266. return
  267. }
  268. // GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  269. func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
  270. o := global.DmSQL["data"]
  271. sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  272. err = o.Raw(sql, uniqueCode).First(&item).Error
  273. return
  274. }
  275. // GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  276. func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  277. o := global.DmSQL["data"]
  278. sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id desc limit 1`
  279. err = o.Raw(sql, classifyId).First(&item).Error
  280. return
  281. }
  282. // UpdateExcelInfoSortByClassifyId 根据表格id更新排序
  283. func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string, source int) (err error) {
  284. o := global.DmSQL["data"]
  285. sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? AND source=? AND is_delete=0 AND ( sort > ? `
  286. // todo 前一个兄弟节点后移
  287. if prevExcelInfoId > 0 {
  288. sql += ` or (excel_info_id < ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  289. }
  290. sql += `)`
  291. err = o.Exec(sql, classifyId, source, nowSort).Error
  292. return
  293. }
  294. // AddExcelInfo 新增表格
  295. // func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  296. // o, err := orm.NewOrmUsingDB("data").Begin()
  297. // if err != nil {
  298. // return
  299. // }
  300. // defer func() {
  301. // if err != nil {
  302. // _ = o.Rollback()
  303. // } else {
  304. // _ = o.Commit()
  305. // }
  306. // }()
  307. // // 表格信息入库
  308. // lastId, err := o.Insert(excelInfo)
  309. // if err != nil {
  310. // return
  311. // }
  312. // excelInfo.ExcelInfoId = int(lastId)
  313. // // excel与指标的关联关系
  314. // dataNum := len(excelEdbMappingList)
  315. // if dataNum > 0 {
  316. // for k, v := range excelEdbMappingList {
  317. // v.ExcelInfoId = excelInfo.ExcelInfoId
  318. // excelEdbMappingList[k] = v
  319. // }
  320. // _, err = o.InsertMulti(dataNum, excelEdbMappingList)
  321. // }
  322. // return
  323. // }
  324. // // EditExcelInfo 编辑表格
  325. // func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  326. // o, err := orm.NewOrmUsingDB("data").Begin()
  327. // if err != nil {
  328. // return
  329. // }
  330. // defer func() {
  331. // if err != nil {
  332. // _ = o.Rollback()
  333. // } else {
  334. // _ = o.Commit()
  335. // }
  336. // }()
  337. // // ETA表格信息变更
  338. // _, err = o.Update(excelInfo, updateExcelInfoParams...)
  339. // if err != nil {
  340. // return
  341. // }
  342. // // 删除关系表
  343. // sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
  344. // _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  345. // // excel与指标的关联关系
  346. // dataNum := len(excelEdbMappingList)
  347. // if dataNum > 0 {
  348. // for k, v := range excelEdbMappingList {
  349. // v.ExcelInfoId = excelInfo.ExcelInfoId
  350. // excelEdbMappingList[k] = v
  351. // }
  352. // _, err = o.InsertMulti(dataNum, excelEdbMappingList)
  353. // }
  354. // return
  355. // }
  356. // GetExcelInfoAll 获取所有表格列表,用于分类展示
  357. // func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
  358. // o := orm.NewOrmUsingDB("data")
  359. // sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  360. // unique_code,sys_user_id,sys_user_real_name,is_join_permission
  361. // FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
  362. // _, err = o.Raw(sql).QueryRows(&items)
  363. // return
  364. // }
  365. // // GetNoContentExcelInfoAll 获取不含content的表格列表 用于分类展示
  366. // func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems, err error) {
  367. // o := orm.NewOrmUsingDB("data")
  368. // sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  369. // unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission
  370. // FROM excel_info where is_delete=0 AND source = ? `
  371. // pars := []interface{}{source}
  372. // if userId > 0 {
  373. // sql += ` AND sys_user_id = ? `
  374. // pars = append(pars, userId)
  375. // }
  376. // sql += ` ORDER BY sort asc,excel_info_id desc `
  377. // _, err = o.Raw(sql, pars...).QueryRows(&items)
  378. // return
  379. // }
  380. // // GetAllExcelInfoBySource 根据来源获取包含content的表格列表
  381. // func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
  382. // o := orm.NewOrmUsingDB("data")
  383. // sql := ` SELECT * FROM excel_info where is_delete=0 AND source = ? ORDER BY sort asc,create_time desc `
  384. // _, err = o.Raw(sql, source).QueryRows(&items)
  385. // return
  386. // }
  387. // // GetExcelInfoById 根据id 获取eta表格详情
  388. // func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  389. // o := orm.NewOrmUsingDB("data")
  390. // sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  391. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  392. // return
  393. // }
  394. // // GetExcelInfoByUnicode 编码获取表格
  395. // func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
  396. // o := orm.NewOrmUsingDB("data")
  397. // sql := ` SELECT * FROM excel_info WHERE unique_code = ? AND is_delete = 0 `
  398. // err = o.Raw(sql, unicode).QueryRow(&item)
  399. // return
  400. // }
  401. // func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
  402. // o := orm.NewOrmUsingDB("data")
  403. // sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  404. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  405. // return
  406. // }
  407. // func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  408. // o := orm.NewOrmUsingDB("data")
  409. // sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  410. // if condition != "" {
  411. // sql += condition
  412. // }
  413. // err = o.Raw(sql, pars).QueryRow(&count)
  414. // return
  415. // }
  416. // func GetNoContentExcelInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ExcelClassifyItems, err error) {
  417. // o := orm.NewOrmUsingDB("data")
  418. // sql := `SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  419. // unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission FROM excel_info WHERE 1=1 `
  420. // if condition != "" {
  421. // sql += condition
  422. // }
  423. // sql += ` AND is_delete=0 ORDER BY excel_info_id DESC LIMIT ?,? `
  424. // _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  425. // return
  426. // }
  427. // func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  428. // o := orm.NewOrmUsingDB("data")
  429. // sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  430. // if condition != "" {
  431. // sql += condition
  432. // }
  433. // err = o.Raw(sql, pars).QueryRow(&item)
  434. // return
  435. // }
  436. // // GetNextExcelInfoByCondition 根据条件获取下一个表格
  437. // func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  438. // o := orm.NewOrmUsingDB("data")
  439. // sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  440. // if condition != "" {
  441. // sql += condition
  442. // }
  443. // sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
  444. // err = o.Raw(sql, pars).QueryRow(&item)
  445. // return
  446. // }
  447. // // GetNextExcelInfo 根据分类id获取下一个excel表格
  448. // func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, err error) {
  449. // o := orm.NewOrmUsingDB("data")
  450. // sql := ` SELECT b.* FROM excel_classify AS a
  451. // INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  452. // WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
  453. // AND a.source = ? AND b.source = ?
  454. // ORDER BY a.sort ASC,b.sort asc,b.create_time desc
  455. // LIMIT 1 `
  456. // err = o.Raw(sql, classifySort, classifySort, classifyId, source, source).QueryRow(&item)
  457. // return
  458. // }
  459. // // EditExcelInfoImage 修改excel表格的图片
  460. // func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  461. // o := orm.NewOrmUsingDB("data")
  462. // sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  463. // _, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
  464. // if err != nil {
  465. // fmt.Println("EditExcelInfoImage Err:", err.Error())
  466. // return err
  467. // }
  468. // return
  469. // }
  470. // // GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  471. // func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
  472. // o := orm.NewOrmUsingDB("data")
  473. // sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  474. // err = o.Raw(sql, uniqueCode).QueryRow(&item)
  475. // return
  476. // }
  477. // // GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  478. // func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  479. // o := orm.NewOrmUsingDB("data")
  480. // sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id desc limit 1`
  481. // err = o.Raw(sql, classifyId).QueryRow(&item)
  482. // return
  483. // }
  484. // // UpdateExcelInfoSortByClassifyId 根据表格id更新排序
  485. // func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string, source int) (err error) {
  486. // o := orm.NewOrmUsingDB("data")
  487. // sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? AND source=? AND is_delete=0 AND ( sort > ? `
  488. // // todo 前一个兄弟节点后移
  489. // if prevExcelInfoId > 0 {
  490. // sql += ` or (excel_info_id < ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  491. // }
  492. // sql += `)`
  493. // _, err = o.Raw(sql, classifyId, source, nowSort).Exec()
  494. // return
  495. // }
  496. // type ExcelInfoView struct {
  497. // ExcelInfoId int `orm:"column(excel_info_id);pk"`
  498. // ExcelName string `description:"来源名称"`
  499. // ExcelClassifyId int `description:"表格分类id"`
  500. // ExcelClassifyName string `description:"表格名称"`
  501. // SysUserId int
  502. // SysUserRealName string
  503. // UniqueCode string `description:"表格唯一编码"`
  504. // CreateTime time.Time
  505. // ModifyTime time.Time
  506. // DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  507. // StartDate string `description:"自定义开始日期"`
  508. // EndDate string `description:"自定义结束日期"`
  509. // IsSetName int `description:"设置名称"`
  510. // EdbInfoIds string `description:"指标id"`
  511. // ExcelType int `description:"生成样式:1:曲线图,2:季节性图"`
  512. // Calendar string `description:"公历/农历"`
  513. // SeasonStartDate string `description:"季节性图开始日期"`
  514. // SeasonEndDate string `description:"季节性图开始日期"`
  515. // ExcelImage string `description:"表格图片"`
  516. // Sort int `description:"排序字段,数字越小越排前面"`
  517. // IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  518. // MyExcelId int
  519. // MyExcelClassifyId string `description:"我的表格分类,多个用逗号隔开"`
  520. // ExcelClassify []*ExcelClassifyView
  521. // EdbEndDate string `description:"指标最新更新日期"`
  522. // LeftMin string `description:"表格左侧最小值"`
  523. // LeftMax string `description:"表格左侧最大值"`
  524. // RightMin string `description:"表格右侧最小值"`
  525. // RightMax string `description:"表格右侧最大值"`
  526. // }
  527. type ExcelInfoView struct {
  528. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" orm:"column(excel_info_id);pk"`
  529. ExcelName string `gorm:"column:excel_name" description:"来源名称"`
  530. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  531. ExcelClassifyName string `gorm:"column:excel_classify_name" description:"表格名称"`
  532. SysUserId int `gorm:"column:sys_user_id"`
  533. SysUserRealName string `gorm:"column:sys_user_real_name"`
  534. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  535. CreateTime time.Time `gorm:"column:create_time"`
  536. ModifyTime time.Time `gorm:"column:modify_time"`
  537. DateType int `gorm:"column:date_type" description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  538. StartDate string `gorm:"column:start_date" description:"自定义开始日期"`
  539. EndDate string `gorm:"column:end_date" description:"自定义结束日期"`
  540. IsSetName int `gorm:"column:is_set_name" description:"设置名称"`
  541. EdbInfoIds string `gorm:"column:edb_info_ids" description:"指标id"`
  542. ExcelType int `gorm:"column:excel_type" description:"生成样式:1:曲线图,2:季节性图"`
  543. Calendar string `gorm:"column:calendar" description:"公历/农历"`
  544. SeasonStartDate string `gorm:"column:season_start_date" description:"季节性图开始日期"`
  545. SeasonEndDate string `gorm:"column:season_end_date" description:"季节性图结束日期"`
  546. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  547. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  548. IsAdd bool `gorm:"column:is_add" description:"true:已加入我的图库,false:未加入我的图库"`
  549. MyExcelId int `gorm:"column:my_excel_id"`
  550. MyExcelClassifyId string `gorm:"column:my_excel_classify_id" description:"我的表格分类,多个用逗号隔开"`
  551. ExcelClassify []*ExcelClassifyView
  552. EdbEndDate string `gorm:"column:edb_end_date" description:"指标最新更新日期"`
  553. LeftMin string `gorm:"column:left_min" description:"表格左侧最小值"`
  554. LeftMax string `gorm:"column:left_max" description:"表格左侧最大值"`
  555. RightMin string `gorm:"column:right_min" description:"表格右侧最小值"`
  556. RightMax string `gorm:"column:right_max" description:"表格右侧最大值"`
  557. }
  558. // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  559. func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  560. o := global.DmSQL["data"]
  561. sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  562. err = o.Raw(sql, classifyId, excelName).First(&item).Error
  563. return
  564. }
  565. // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  566. func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  567. o := global.DmSQL["data"]
  568. 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,is_join_permission
  569. FROM excel_info WHERE 1=1 AND is_delete=0 `
  570. if condition != "" {
  571. sql += condition
  572. }
  573. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  574. sql += " ORDER BY create_time DESC LIMIT ?,? "
  575. err = o.Raw(sql, pars, startSize, pageSize).Scan(&item).Error
  576. return
  577. }
  578. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  579. o := global.DmSQL["data"]
  580. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  581. if condition != "" {
  582. sql += condition
  583. }
  584. err = o.Raw(sql, pars).Scan(&count).Error
  585. return
  586. }
  587. // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  588. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  589. o := global.DmSQL["data"]
  590. 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,is_join_permission FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
  591. err = o.Raw(sql, excelInfoId).First(&item).Error
  592. return
  593. }
  594. // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  595. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  596. o := global.DmSQL["data"]
  597. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  598. err = o.Raw(sql, classifyId).Scan(&total).Error
  599. return
  600. }
  601. // UpdateExcelInfoClassifyId 更改表格分类
  602. func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
  603. o := global.DmSQL["data"]
  604. sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
  605. err = o.Exec(sql, classifyId, excelInfoId).Error
  606. return
  607. }
  608. // GetNoContentExcelInfoByName 根据名称 获取eta表格详情
  609. func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
  610. o := global.DmSQL["data"]
  611. 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,is_join_permission
  612. FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
  613. err = o.Raw(sql, excelName, source).First(&item).Error
  614. return
  615. }
  616. // GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  617. func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
  618. o := global.DmSQL["data"]
  619. 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,is_join_permission
  620. FROM excel_info WHERE unique_code=? AND is_delete=0 `
  621. err = o.Raw(sql, uniqueCode).First(&item).Error
  622. return
  623. }
  624. // GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
  625. func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
  626. o := global.DmSQL["data"]
  627. 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,is_join_permission
  628. FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  629. err = o.Raw(sql, excelInfoId).First(&item).Error
  630. return
  631. }
  632. // AddExcelInfoAndSheet 新增excel
  633. func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
  634. o := global.DmSQL["data"].Begin()
  635. defer func() {
  636. if err != nil {
  637. _ = o.Rollback()
  638. } else {
  639. _ = o.Commit()
  640. }
  641. }()
  642. // 表格信息入库
  643. err = o.Create(excelInfo).Error
  644. if err != nil {
  645. return
  646. }
  647. // sheet信息入库
  648. for _, sheetInfo := range sheetParamsList {
  649. dataNum := len(sheetInfo.DataList)
  650. //sheet信息入库
  651. excelSheetInfo := &ExcelSheet{
  652. ExcelSheetId: 0,
  653. ExcelInfoId: excelInfo.ExcelInfoId,
  654. SheetName: sheetInfo.SheetName,
  655. PageNum: dataNum,
  656. Index: sheetInfo.Index,
  657. Sort: sheetInfo.Sort,
  658. Config: sheetInfo.Config,
  659. CalcChain: sheetInfo.CalcChain,
  660. ModifyTime: time.Now(),
  661. CreateTime: time.Now(),
  662. }
  663. tmpErr := o.Create(excelSheetInfo).Error
  664. if tmpErr != nil {
  665. err = tmpErr
  666. return
  667. }
  668. // data信息入库
  669. if dataNum > 0 {
  670. for k, _ := range sheetInfo.DataList {
  671. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  672. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  673. }
  674. tmpErr = o.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
  675. if tmpErr != nil {
  676. err = tmpErr
  677. return
  678. }
  679. }
  680. }
  681. return
  682. }
  683. // SaveExcelInfoAndSheet 编辑保存
  684. func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
  685. o := global.DmSQL["data"].Begin()
  686. defer func() {
  687. if err != nil {
  688. _ = o.Rollback()
  689. } else {
  690. _ = o.Commit()
  691. }
  692. }()
  693. // 表格信息入库
  694. err = o.Model(excelInfo).Select(updateExcelInfoParam).Updates(excelInfo).Error
  695. if err != nil {
  696. return
  697. }
  698. // 先删除历史的sheet信息
  699. sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
  700. err = o.Exec(sql, excelInfo.ExcelInfoId).Error
  701. if err != nil {
  702. return
  703. }
  704. // 再删除历史sheet中的cell data信息
  705. sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
  706. err = o.Exec(sql, excelInfo.ExcelInfoId).Error
  707. if err != nil {
  708. return
  709. }
  710. // sheet信息入库
  711. for _, sheetInfo := range sheetParamsList {
  712. dataNum := len(sheetInfo.DataList)
  713. //sheet信息入库
  714. excelSheetInfo := &ExcelSheet{
  715. ExcelSheetId: 0,
  716. ExcelInfoId: excelInfo.ExcelInfoId,
  717. SheetName: sheetInfo.SheetName,
  718. PageNum: dataNum,
  719. Index: sheetInfo.Index,
  720. Sort: sheetInfo.Sort,
  721. Config: sheetInfo.Config,
  722. CalcChain: sheetInfo.CalcChain,
  723. ModifyTime: time.Now(),
  724. CreateTime: time.Now(),
  725. }
  726. tmpErr := o.Create(excelSheetInfo).Error
  727. if tmpErr != nil {
  728. err = tmpErr
  729. return
  730. }
  731. // data信息入库
  732. if dataNum > 0 {
  733. for k, _ := range sheetInfo.DataList {
  734. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  735. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  736. }
  737. tmpErr = o.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
  738. if tmpErr != nil {
  739. err = tmpErr
  740. return
  741. }
  742. }
  743. }
  744. return
  745. }
  746. // // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  747. // func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  748. // o := orm.NewOrmUsingDB("data")
  749. // sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  750. // err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
  751. // return
  752. // }
  753. // // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  754. // func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  755. // o := orm.NewOrmUsingDB("data")
  756. // 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,is_join_permission
  757. // FROM excel_info WHERE 1=1 AND is_delete=0 `
  758. // if condition != "" {
  759. // sql += condition
  760. // }
  761. // //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  762. // sql += " ORDER BY create_time DESC LIMIT ?,? "
  763. // _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  764. // return
  765. // }
  766. // func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  767. // o := orm.NewOrmUsingDB("data")
  768. // sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  769. // if condition != "" {
  770. // sql += condition
  771. // }
  772. // err = o.Raw(sql, pars).QueryRow(&count)
  773. // return
  774. // }
  775. // // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  776. // func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  777. // o := orm.NewOrmUsingDB("data")
  778. // 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,is_join_permission FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
  779. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  780. // return
  781. // }
  782. // // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  783. // func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  784. // o := orm.NewOrmUsingDB("data")
  785. // sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  786. // err = o.Raw(sql, classifyId).QueryRow(&total)
  787. // return
  788. // }
  789. // // UpdateExcelInfoClassifyId 更改表格分类
  790. // func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
  791. // o := orm.NewOrmUsingDB("data")
  792. // sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
  793. // _, err = o.Raw(sql, classifyId, excelInfoId).Exec()
  794. // return
  795. // }
  796. // // GetNoContentExcelInfoByName 根据名称 获取eta表格详情
  797. // func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
  798. // o := orm.NewOrmUsingDB("data")
  799. // 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,is_join_permission
  800. // FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
  801. // err = o.Raw(sql, excelName, source).QueryRow(&item)
  802. // return
  803. // }
  804. // // GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  805. // func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
  806. // o := orm.NewOrmUsingDB("data")
  807. // 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,is_join_permission
  808. // FROM excel_info WHERE unique_code=? AND is_delete=0 `
  809. // err = o.Raw(sql, uniqueCode).QueryRow(&item)
  810. // return
  811. // }
  812. // // GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
  813. // func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
  814. // o := orm.NewOrmUsingDB("data")
  815. // 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,is_join_permission
  816. // FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  817. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  818. // return
  819. // }
  820. // // AddExcelInfoAndSheet 新增excel
  821. // func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
  822. // o, err := orm.NewOrmUsingDB("data").Begin()
  823. // if err != nil {
  824. // return
  825. // }
  826. // defer func() {
  827. // if err != nil {
  828. // _ = o.Rollback()
  829. // } else {
  830. // _ = o.Commit()
  831. // }
  832. // }()
  833. // // 表格信息入库
  834. // lastId, err := o.Insert(excelInfo)
  835. // if err != nil {
  836. // return
  837. // }
  838. // excelInfo.ExcelInfoId = int(lastId)
  839. // // sheet信息入库
  840. // for _, sheetInfo := range sheetParamsList {
  841. // dataNum := len(sheetInfo.DataList)
  842. // //sheet信息入库
  843. // excelSheetInfo := &ExcelSheet{
  844. // ExcelSheetId: 0,
  845. // ExcelInfoId: excelInfo.ExcelInfoId,
  846. // SheetName: sheetInfo.SheetName,
  847. // PageNum: dataNum,
  848. // Index: sheetInfo.Index,
  849. // Sort: sheetInfo.Sort,
  850. // Config: sheetInfo.Config,
  851. // CalcChain: sheetInfo.CalcChain,
  852. // ModifyTime: time.Now(),
  853. // CreateTime: time.Now(),
  854. // }
  855. // sheetId, tmpErr := o.Insert(excelSheetInfo)
  856. // if tmpErr != nil {
  857. // err = tmpErr
  858. // return
  859. // }
  860. // excelSheetInfo.ExcelSheetId = int(sheetId)
  861. // // data信息入库
  862. // if dataNum > 0 {
  863. // for k, _ := range sheetInfo.DataList {
  864. // sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  865. // sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  866. // }
  867. // _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  868. // if tmpErr != nil {
  869. // err = tmpErr
  870. // return
  871. // }
  872. // }
  873. // }
  874. // return
  875. // }
  876. // // SaveExcelInfoAndSheet 编辑保存
  877. // func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
  878. // o, err := orm.NewOrmUsingDB("data").Begin()
  879. // if err != nil {
  880. // return
  881. // }
  882. // defer func() {
  883. // if err != nil {
  884. // _ = o.Rollback()
  885. // } else {
  886. // _ = o.Commit()
  887. // }
  888. // }()
  889. // // 表格信息入库
  890. // _, err = o.Update(excelInfo, updateExcelInfoParam...)
  891. // if err != nil {
  892. // return
  893. // }
  894. // // 先删除历史的sheet信息
  895. // sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
  896. // _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  897. // if err != nil {
  898. // return
  899. // }
  900. // // 再删除历史sheet中的cell data信息
  901. // sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
  902. // _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  903. // if err != nil {
  904. // return
  905. // }
  906. // // sheet信息入库
  907. // for _, sheetInfo := range sheetParamsList {
  908. // dataNum := len(sheetInfo.DataList)
  909. // //sheet信息入库
  910. // excelSheetInfo := &ExcelSheet{
  911. // ExcelSheetId: 0,
  912. // ExcelInfoId: excelInfo.ExcelInfoId,
  913. // SheetName: sheetInfo.SheetName,
  914. // PageNum: dataNum,
  915. // Index: sheetInfo.Index,
  916. // Sort: sheetInfo.Sort,
  917. // Config: sheetInfo.Config,
  918. // CalcChain: sheetInfo.CalcChain,
  919. // ModifyTime: time.Now(),
  920. // CreateTime: time.Now(),
  921. // }
  922. // sheetId, tmpErr := o.Insert(excelSheetInfo)
  923. // if tmpErr != nil {
  924. // err = tmpErr
  925. // return
  926. // }
  927. // excelSheetInfo.ExcelSheetId = int(sheetId)
  928. // // data信息入库
  929. // if dataNum > 0 {
  930. // for k, _ := range sheetInfo.DataList {
  931. // sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  932. // sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  933. // }
  934. // _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  935. // if tmpErr != nil {
  936. // err = tmpErr
  937. // return
  938. // }
  939. // }
  940. // }
  941. // return
  942. // }
  943. // type BatchRefreshExcelReq struct {
  944. // ExcelCodes []string `description:"表格编码"`
  945. // ReportId int `description:"报告ID"`
  946. // ReportChapterId int `description:"报告章节ID"`
  947. // Source string `description:"来源,枚举值:report、english_report、smart_report"`
  948. // }
  949. //
  950. // BatchRefreshExcelReq 批量刷新表格请求
  951. type BatchRefreshExcelReq struct {
  952. ExcelCodes []string `gorm:"column:excel_codes" description:"表格编码"`
  953. ReportId int `gorm:"column:report_id" description:"报告ID"`
  954. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节ID"`
  955. Source string `gorm:"column:source" description:"来源,枚举值:report、english_report、smart_report"`
  956. }
  957. // GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
  958. func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
  959. o := global.DmSQL["data"]
  960. sql := ` SELECT Max(sort) AS sort FROM excel_info WHERE excel_classify_id=? AND source = ? AND is_delete=0 order by sort desc,excel_info_id desc limit 1`
  961. err = o.Raw(sql, classifyId, source).Scan(&sort).Error
  962. return
  963. }
  964. // GetNoContentExcelListByExcelInfoIdList
  965. // @Description: 根据ETA表格ID列表获取列表信息
  966. // @param excelInfoIdList []string
  967. // @return items
  968. // @return err
  969. func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*MyExcelInfoList, err error) {
  970. num := len(excelInfoIdList)
  971. if num <= 0 {
  972. return
  973. }
  974. o := global.DmSQL["data"]
  975. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  976. err = o.Raw(sql, excelInfoIdList).Scan(&items).Error
  977. return
  978. }
  979. // GetNoContentExcelListByUserId
  980. // @Description: 根据ETA表格ID列表获取列表信息
  981. // @param userIdList []int
  982. // @return items
  983. // @return err
  984. func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList, err error) {
  985. num := len(userIdList)
  986. if num <= 0 {
  987. return
  988. }
  989. o := global.DmSQL["data"]
  990. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  991. err = o.Raw(sql, userIdList).Scan(&items).Error
  992. return
  993. }
  994. // // ModifyExcelInfoUserIdByCodeList
  995. // // @Description: 根据编码列表修改表格信息
  996. // // @author: Roc
  997. // // @datetime 2024-03-26 14:16:30
  998. // // @param excelIdList []string
  999. // // @param userId int
  1000. // // @param userName string
  1001. // // @return err error
  1002. func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName string) (err error) {
  1003. num := len(excelIdList)
  1004. if num <= 0 {
  1005. return
  1006. }
  1007. o := global.DmSQL["data"]
  1008. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1009. err = o.Exec(sql, userId, userName, excelIdList).Error
  1010. return
  1011. }
  1012. // // ModifyExcelInfoUserIdByOldUserId
  1013. // // @Description: 根据旧的用户id修改创建人
  1014. // // @author: Roc
  1015. // // @datetime 2024-03-25 19:14:59
  1016. // // @param oldUserId int
  1017. // // @param userId int
  1018. // // @param userName string
  1019. // // @return err error
  1020. func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1021. num := len(oldUserIdList)
  1022. if num <= 0 {
  1023. return
  1024. }
  1025. o := global.DmSQL["data"]
  1026. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1027. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  1028. return
  1029. }
  1030. // GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
  1031. // func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
  1032. // o := orm.NewOrmUsingDB("data")
  1033. // sql := ` SELECT Max(sort) AS sort FROM excel_info WHERE excel_classify_id=? AND source = ? AND is_delete=0 order by sort desc,excel_info_id desc limit 1`
  1034. // err = o.Raw(sql, classifyId, source).QueryRow(&sort)
  1035. // return
  1036. // }
  1037. // // GetNoContentExcelListByExcelInfoIdList
  1038. // // @Description: 根据ETA表格ID列表获取列表信息
  1039. // // @param excelInfoIdList []string
  1040. // // @return items
  1041. // // @return err
  1042. // func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*MyExcelInfoList, err error) {
  1043. // num := len(excelInfoIdList)
  1044. // if num <= 0 {
  1045. // return
  1046. // }
  1047. // o := orm.NewOrmUsingDB("data")
  1048. // sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  1049. // _, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
  1050. // return
  1051. // }
  1052. // // GetNoContentExcelListByUserId
  1053. // // @Description: 根据ETA表格ID列表获取列表信息
  1054. // // @param userIdList []int
  1055. // // @return items
  1056. // // @return err
  1057. // func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList, err error) {
  1058. // num := len(userIdList)
  1059. // if num <= 0 {
  1060. // return
  1061. // }
  1062. // o := orm.NewOrmUsingDB("data")
  1063. // sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  1064. // _, err = o.Raw(sql, userIdList).QueryRows(&items)
  1065. // return
  1066. // }
  1067. // // ModifyExcelInfoUserIdByCodeList
  1068. // // @Description: 根据编码列表修改表格信息
  1069. // // @author: Roc
  1070. // // @datetime 2024-03-26 14:16:30
  1071. // // @param excelIdList []string
  1072. // // @param userId int
  1073. // // @param userName string
  1074. // // @return err error
  1075. // func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName string) (err error) {
  1076. // num := len(excelIdList)
  1077. // if num <= 0 {
  1078. // return
  1079. // }
  1080. // o := orm.NewOrmUsingDB("data")
  1081. // sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1082. // _, err = o.Raw(sql, userId, userName, excelIdList).Exec()
  1083. // return
  1084. // }
  1085. // // ModifyExcelInfoUserIdByOldUserId
  1086. // // @Description: 根据旧的用户id修改创建人
  1087. // // @author: Roc
  1088. // // @datetime 2024-03-25 19:14:59
  1089. // // @param oldUserId int
  1090. // // @param userId int
  1091. // // @param userName string
  1092. // // @return err error
  1093. // func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1094. // num := len(oldUserIdList)
  1095. // if num <= 0 {
  1096. // return
  1097. // }
  1098. // o := orm.NewOrmUsingDB("data")
  1099. // sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1100. // _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  1101. // return
  1102. // }
  1103. // type ExcelInfoDetail struct {
  1104. // ExcelInfoId int `orm:"column(excel_info_id);pk"`
  1105. // Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  1106. // ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  1107. // ExcelName string `description:"表格名称"`
  1108. // UniqueCode string `description:"表格唯一编码"`
  1109. // ExcelClassifyId int `description:"表格分类id"`
  1110. // SysUserId int `description:"操作人id"`
  1111. // SysUserRealName string `description:"操作人真实姓名"`
  1112. // Content string `description:"表格内容"`
  1113. // ExcelImage string `description:"表格图片"`
  1114. // FileUrl string `description:"表格下载地址"`
  1115. // Sort int `description:"排序字段,数字越小越排前面"`
  1116. // IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  1117. // ModifyTime time.Time `description:"最近修改日期"`
  1118. // CreateTime time.Time `description:"创建日期"`
  1119. // TableData interface{} `description:"表格内容"`
  1120. // //Button ExcelInfoDetailButton `description:"操作权限"`
  1121. // CanEdit bool `description:"是否可编辑"`
  1122. // Editor string `description:"编辑人"`
  1123. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1124. // HaveOperaAuth bool `description:"是否有数据权限"`
  1125. // }
  1126. //
  1127. // ExcelInfoDetail excel表格详情(前端使用)
  1128. type ExcelInfoDetail struct {
  1129. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" orm:"column(excel_info_id);pk"`
  1130. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  1131. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  1132. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  1133. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  1134. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  1135. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  1136. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  1137. Content string `gorm:"column:content" description:"表格内容"`
  1138. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  1139. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  1140. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  1141. IsDelete int `gorm:"column:is_delete" description:"是否删除,0:未删除,1:已删除"`
  1142. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  1143. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  1144. TableData interface{} `gorm:"column:table_data" description:"表格内容"`
  1145. CanEdit bool `gorm:"column:can_edit" description:"是否可编辑"`
  1146. Editor string `gorm:"column:editor" description:"编辑人"`
  1147. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1148. HaveOperaAuth bool `gorm:"column:have_opera_auth" description:"是否有数据权限"`
  1149. }