excel_info.go 51 KB

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