excel_info.go 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. err = o.Raw(sql, pars, startSize, pageSize).Scan(&item).Error
  577. return
  578. }
  579. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  580. o := global.DmSQL["data"]
  581. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  582. if condition != "" {
  583. sql += condition
  584. }
  585. err = o.Raw(sql, pars).Scan(&count).Error
  586. return
  587. }
  588. // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  589. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  590. o := global.DmSQL["data"]
  591. 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 `
  592. err = o.Raw(sql, excelInfoId).First(&item).Error
  593. return
  594. }
  595. // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  596. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  597. o := global.DmSQL["data"]
  598. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  599. err = o.Raw(sql, classifyId).Scan(&total).Error
  600. return
  601. }
  602. // UpdateExcelInfoClassifyId 更改表格分类
  603. func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
  604. o := global.DmSQL["data"]
  605. sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
  606. err = o.Exec(sql, classifyId, excelInfoId).Error
  607. return
  608. }
  609. // GetNoContentExcelInfoByName 根据名称 获取eta表格详情
  610. func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
  611. o := global.DmSQL["data"]
  612. 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
  613. FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
  614. err = o.Raw(sql, excelName, source).First(&item).Error
  615. return
  616. }
  617. // GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  618. func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
  619. o := global.DmSQL["data"]
  620. 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
  621. FROM excel_info WHERE unique_code=? AND is_delete=0 `
  622. err = o.Raw(sql, uniqueCode).First(&item).Error
  623. return
  624. }
  625. // GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
  626. func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
  627. o := global.DmSQL["data"]
  628. 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
  629. FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  630. err = o.Raw(sql, excelInfoId).First(&item).Error
  631. return
  632. }
  633. // AddExcelInfoAndSheet 新增excel
  634. func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
  635. o := global.DmSQL["data"].Begin()
  636. defer func() {
  637. if err != nil {
  638. _ = o.Rollback()
  639. } else {
  640. _ = o.Commit()
  641. }
  642. }()
  643. // 表格信息入库
  644. err = o.Create(excelInfo).Error
  645. if err != nil {
  646. return
  647. }
  648. // sheet信息入库
  649. for _, sheetInfo := range sheetParamsList {
  650. dataNum := len(sheetInfo.DataList)
  651. //sheet信息入库
  652. excelSheetInfo := &ExcelSheet{
  653. ExcelSheetId: 0,
  654. ExcelInfoId: excelInfo.ExcelInfoId,
  655. SheetName: sheetInfo.SheetName,
  656. PageNum: dataNum,
  657. Index: sheetInfo.Index,
  658. Sort: sheetInfo.Sort,
  659. Config: sheetInfo.Config,
  660. CalcChain: sheetInfo.CalcChain,
  661. ModifyTime: time.Now(),
  662. CreateTime: time.Now(),
  663. }
  664. tmpErr := o.Create(excelSheetInfo).Error
  665. if tmpErr != nil {
  666. err = tmpErr
  667. return
  668. }
  669. // data信息入库
  670. if dataNum > 0 {
  671. for k, _ := range sheetInfo.DataList {
  672. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  673. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  674. }
  675. tmpErr = o.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
  676. if tmpErr != nil {
  677. err = tmpErr
  678. return
  679. }
  680. }
  681. }
  682. return
  683. }
  684. // SaveExcelInfoAndSheet 编辑保存
  685. func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
  686. o := global.DmSQL["data"].Begin()
  687. defer func() {
  688. if err != nil {
  689. _ = o.Rollback()
  690. } else {
  691. _ = o.Commit()
  692. }
  693. }()
  694. // 表格信息入库
  695. err = o.Model(excelInfo).Select(updateExcelInfoParam).Updates(excelInfo).Error
  696. if err != nil {
  697. return
  698. }
  699. // 先删除历史的sheet信息
  700. sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
  701. err = o.Exec(sql, excelInfo.ExcelInfoId).Error
  702. if err != nil {
  703. return
  704. }
  705. // 再删除历史sheet中的cell data信息
  706. sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
  707. err = o.Exec(sql, excelInfo.ExcelInfoId).Error
  708. if err != nil {
  709. return
  710. }
  711. // sheet信息入库
  712. for _, sheetInfo := range sheetParamsList {
  713. dataNum := len(sheetInfo.DataList)
  714. //sheet信息入库
  715. excelSheetInfo := &ExcelSheet{
  716. ExcelSheetId: 0,
  717. ExcelInfoId: excelInfo.ExcelInfoId,
  718. SheetName: sheetInfo.SheetName,
  719. PageNum: dataNum,
  720. Index: sheetInfo.Index,
  721. Sort: sheetInfo.Sort,
  722. Config: sheetInfo.Config,
  723. CalcChain: sheetInfo.CalcChain,
  724. ModifyTime: time.Now(),
  725. CreateTime: time.Now(),
  726. }
  727. tmpErr := o.Create(excelSheetInfo).Error
  728. if tmpErr != nil {
  729. err = tmpErr
  730. return
  731. }
  732. // data信息入库
  733. if dataNum > 0 {
  734. for k, _ := range sheetInfo.DataList {
  735. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  736. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  737. }
  738. tmpErr = o.CreateInBatches(sheetInfo.DataList, utils.MultiAddNum).Error
  739. if tmpErr != nil {
  740. err = tmpErr
  741. return
  742. }
  743. }
  744. }
  745. return
  746. }
  747. // // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  748. // func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  749. // o := orm.NewOrmUsingDB("data")
  750. // sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  751. // err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
  752. // return
  753. // }
  754. // // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  755. // func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  756. // o := orm.NewOrmUsingDB("data")
  757. // 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
  758. // FROM excel_info WHERE 1=1 AND is_delete=0 `
  759. // if condition != "" {
  760. // sql += condition
  761. // }
  762. // //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  763. // sql += " ORDER BY create_time DESC LIMIT ?,? "
  764. // _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  765. // return
  766. // }
  767. // func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  768. // o := orm.NewOrmUsingDB("data")
  769. // sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  770. // if condition != "" {
  771. // sql += condition
  772. // }
  773. // err = o.Raw(sql, pars).QueryRow(&count)
  774. // return
  775. // }
  776. // // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  777. // func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  778. // o := orm.NewOrmUsingDB("data")
  779. // 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 `
  780. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  781. // return
  782. // }
  783. // // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  784. // func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  785. // o := orm.NewOrmUsingDB("data")
  786. // sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  787. // err = o.Raw(sql, classifyId).QueryRow(&total)
  788. // return
  789. // }
  790. // // UpdateExcelInfoClassifyId 更改表格分类
  791. // func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
  792. // o := orm.NewOrmUsingDB("data")
  793. // sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
  794. // _, err = o.Raw(sql, classifyId, excelInfoId).Exec()
  795. // return
  796. // }
  797. // // GetNoContentExcelInfoByName 根据名称 获取eta表格详情
  798. // func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
  799. // o := orm.NewOrmUsingDB("data")
  800. // 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
  801. // FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
  802. // err = o.Raw(sql, excelName, source).QueryRow(&item)
  803. // return
  804. // }
  805. // // GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  806. // func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
  807. // o := orm.NewOrmUsingDB("data")
  808. // 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
  809. // FROM excel_info WHERE unique_code=? AND is_delete=0 `
  810. // err = o.Raw(sql, uniqueCode).QueryRow(&item)
  811. // return
  812. // }
  813. // // GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
  814. // func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
  815. // o := orm.NewOrmUsingDB("data")
  816. // 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
  817. // FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  818. // err = o.Raw(sql, excelInfoId).QueryRow(&item)
  819. // return
  820. // }
  821. // // AddExcelInfoAndSheet 新增excel
  822. // func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
  823. // o, err := orm.NewOrmUsingDB("data").Begin()
  824. // if err != nil {
  825. // return
  826. // }
  827. // defer func() {
  828. // if err != nil {
  829. // _ = o.Rollback()
  830. // } else {
  831. // _ = o.Commit()
  832. // }
  833. // }()
  834. // // 表格信息入库
  835. // lastId, err := o.Insert(excelInfo)
  836. // if err != nil {
  837. // return
  838. // }
  839. // excelInfo.ExcelInfoId = int(lastId)
  840. // // sheet信息入库
  841. // for _, sheetInfo := range sheetParamsList {
  842. // dataNum := len(sheetInfo.DataList)
  843. // //sheet信息入库
  844. // excelSheetInfo := &ExcelSheet{
  845. // ExcelSheetId: 0,
  846. // ExcelInfoId: excelInfo.ExcelInfoId,
  847. // SheetName: sheetInfo.SheetName,
  848. // PageNum: dataNum,
  849. // Index: sheetInfo.Index,
  850. // Sort: sheetInfo.Sort,
  851. // Config: sheetInfo.Config,
  852. // CalcChain: sheetInfo.CalcChain,
  853. // ModifyTime: time.Now(),
  854. // CreateTime: time.Now(),
  855. // }
  856. // sheetId, tmpErr := o.Insert(excelSheetInfo)
  857. // if tmpErr != nil {
  858. // err = tmpErr
  859. // return
  860. // }
  861. // excelSheetInfo.ExcelSheetId = int(sheetId)
  862. // // data信息入库
  863. // if dataNum > 0 {
  864. // for k, _ := range sheetInfo.DataList {
  865. // sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  866. // sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  867. // }
  868. // _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  869. // if tmpErr != nil {
  870. // err = tmpErr
  871. // return
  872. // }
  873. // }
  874. // }
  875. // return
  876. // }
  877. // // SaveExcelInfoAndSheet 编辑保存
  878. // func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
  879. // o, err := orm.NewOrmUsingDB("data").Begin()
  880. // if err != nil {
  881. // return
  882. // }
  883. // defer func() {
  884. // if err != nil {
  885. // _ = o.Rollback()
  886. // } else {
  887. // _ = o.Commit()
  888. // }
  889. // }()
  890. // // 表格信息入库
  891. // _, err = o.Update(excelInfo, updateExcelInfoParam...)
  892. // if err != nil {
  893. // return
  894. // }
  895. // // 先删除历史的sheet信息
  896. // sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
  897. // _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  898. // if err != nil {
  899. // return
  900. // }
  901. // // 再删除历史sheet中的cell data信息
  902. // sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
  903. // _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  904. // if err != nil {
  905. // return
  906. // }
  907. // // sheet信息入库
  908. // for _, sheetInfo := range sheetParamsList {
  909. // dataNum := len(sheetInfo.DataList)
  910. // //sheet信息入库
  911. // excelSheetInfo := &ExcelSheet{
  912. // ExcelSheetId: 0,
  913. // ExcelInfoId: excelInfo.ExcelInfoId,
  914. // SheetName: sheetInfo.SheetName,
  915. // PageNum: dataNum,
  916. // Index: sheetInfo.Index,
  917. // Sort: sheetInfo.Sort,
  918. // Config: sheetInfo.Config,
  919. // CalcChain: sheetInfo.CalcChain,
  920. // ModifyTime: time.Now(),
  921. // CreateTime: time.Now(),
  922. // }
  923. // sheetId, tmpErr := o.Insert(excelSheetInfo)
  924. // if tmpErr != nil {
  925. // err = tmpErr
  926. // return
  927. // }
  928. // excelSheetInfo.ExcelSheetId = int(sheetId)
  929. // // data信息入库
  930. // if dataNum > 0 {
  931. // for k, _ := range sheetInfo.DataList {
  932. // sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  933. // sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  934. // }
  935. // _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  936. // if tmpErr != nil {
  937. // err = tmpErr
  938. // return
  939. // }
  940. // }
  941. // }
  942. // return
  943. // }
  944. // type BatchRefreshExcelReq struct {
  945. // ExcelCodes []string `description:"表格编码"`
  946. // ReportId int `description:"报告ID"`
  947. // ReportChapterId int `description:"报告章节ID"`
  948. // Source string `description:"来源,枚举值:report、english_report、smart_report"`
  949. // }
  950. //
  951. // BatchRefreshExcelReq 批量刷新表格请求
  952. type BatchRefreshExcelReq struct {
  953. ExcelCodes []string `gorm:"column:excel_codes" description:"表格编码"`
  954. ReportId int `gorm:"column:report_id" description:"报告ID"`
  955. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节ID"`
  956. Source string `gorm:"column:source" description:"来源,枚举值:report、english_report、smart_report"`
  957. }
  958. // GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
  959. func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
  960. o := global.DmSQL["data"]
  961. 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`
  962. err = o.Raw(sql, classifyId, source).Scan(&sort).Error
  963. return
  964. }
  965. // GetNoContentExcelListByExcelInfoIdList
  966. // @Description: 根据ETA表格ID列表获取列表信息
  967. // @param excelInfoIdList []string
  968. // @return items
  969. // @return err
  970. func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*MyExcelInfoList, err error) {
  971. num := len(excelInfoIdList)
  972. if num <= 0 {
  973. return
  974. }
  975. o := global.DmSQL["data"]
  976. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  977. err = o.Raw(sql, excelInfoIdList).Scan(&items).Error
  978. return
  979. }
  980. // GetNoContentExcelListByUserId
  981. // @Description: 根据ETA表格ID列表获取列表信息
  982. // @param userIdList []int
  983. // @return items
  984. // @return err
  985. func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList, err error) {
  986. num := len(userIdList)
  987. if num <= 0 {
  988. return
  989. }
  990. o := global.DmSQL["data"]
  991. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  992. err = o.Raw(sql, userIdList).Scan(&items).Error
  993. return
  994. }
  995. // // ModifyExcelInfoUserIdByCodeList
  996. // // @Description: 根据编码列表修改表格信息
  997. // // @author: Roc
  998. // // @datetime 2024-03-26 14:16:30
  999. // // @param excelIdList []string
  1000. // // @param userId int
  1001. // // @param userName string
  1002. // // @return err error
  1003. func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName string) (err error) {
  1004. num := len(excelIdList)
  1005. if num <= 0 {
  1006. return
  1007. }
  1008. o := global.DmSQL["data"]
  1009. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1010. err = o.Exec(sql, userId, userName, excelIdList).Error
  1011. return
  1012. }
  1013. // // ModifyExcelInfoUserIdByOldUserId
  1014. // // @Description: 根据旧的用户id修改创建人
  1015. // // @author: Roc
  1016. // // @datetime 2024-03-25 19:14:59
  1017. // // @param oldUserId int
  1018. // // @param userId int
  1019. // // @param userName string
  1020. // // @return err error
  1021. func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1022. num := len(oldUserIdList)
  1023. if num <= 0 {
  1024. return
  1025. }
  1026. o := global.DmSQL["data"]
  1027. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1028. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  1029. return
  1030. }
  1031. // GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
  1032. // func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
  1033. // o := orm.NewOrmUsingDB("data")
  1034. // 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`
  1035. // err = o.Raw(sql, classifyId, source).QueryRow(&sort)
  1036. // return
  1037. // }
  1038. // // GetNoContentExcelListByExcelInfoIdList
  1039. // // @Description: 根据ETA表格ID列表获取列表信息
  1040. // // @param excelInfoIdList []string
  1041. // // @return items
  1042. // // @return err
  1043. // func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*MyExcelInfoList, err error) {
  1044. // num := len(excelInfoIdList)
  1045. // if num <= 0 {
  1046. // return
  1047. // }
  1048. // o := orm.NewOrmUsingDB("data")
  1049. // sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  1050. // _, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
  1051. // return
  1052. // }
  1053. // // GetNoContentExcelListByUserId
  1054. // // @Description: 根据ETA表格ID列表获取列表信息
  1055. // // @param userIdList []int
  1056. // // @return items
  1057. // // @return err
  1058. // func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList, err error) {
  1059. // num := len(userIdList)
  1060. // if num <= 0 {
  1061. // return
  1062. // }
  1063. // o := orm.NewOrmUsingDB("data")
  1064. // sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  1065. // _, err = o.Raw(sql, userIdList).QueryRows(&items)
  1066. // return
  1067. // }
  1068. // // ModifyExcelInfoUserIdByCodeList
  1069. // // @Description: 根据编码列表修改表格信息
  1070. // // @author: Roc
  1071. // // @datetime 2024-03-26 14:16:30
  1072. // // @param excelIdList []string
  1073. // // @param userId int
  1074. // // @param userName string
  1075. // // @return err error
  1076. // func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName string) (err error) {
  1077. // num := len(excelIdList)
  1078. // if num <= 0 {
  1079. // return
  1080. // }
  1081. // o := orm.NewOrmUsingDB("data")
  1082. // sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1083. // _, err = o.Raw(sql, userId, userName, excelIdList).Exec()
  1084. // return
  1085. // }
  1086. // // ModifyExcelInfoUserIdByOldUserId
  1087. // // @Description: 根据旧的用户id修改创建人
  1088. // // @author: Roc
  1089. // // @datetime 2024-03-25 19:14:59
  1090. // // @param oldUserId int
  1091. // // @param userId int
  1092. // // @param userName string
  1093. // // @return err error
  1094. // func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1095. // num := len(oldUserIdList)
  1096. // if num <= 0 {
  1097. // return
  1098. // }
  1099. // o := orm.NewOrmUsingDB("data")
  1100. // sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1101. // _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  1102. // return
  1103. // }
  1104. // type ExcelInfoDetail struct {
  1105. // ExcelInfoId int `orm:"column(excel_info_id);pk"`
  1106. // Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  1107. // ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  1108. // ExcelName string `description:"表格名称"`
  1109. // UniqueCode string `description:"表格唯一编码"`
  1110. // ExcelClassifyId int `description:"表格分类id"`
  1111. // SysUserId int `description:"操作人id"`
  1112. // SysUserRealName string `description:"操作人真实姓名"`
  1113. // Content string `description:"表格内容"`
  1114. // ExcelImage string `description:"表格图片"`
  1115. // FileUrl string `description:"表格下载地址"`
  1116. // Sort int `description:"排序字段,数字越小越排前面"`
  1117. // IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  1118. // ModifyTime time.Time `description:"最近修改日期"`
  1119. // CreateTime time.Time `description:"创建日期"`
  1120. // TableData interface{} `description:"表格内容"`
  1121. // //Button ExcelInfoDetailButton `description:"操作权限"`
  1122. // CanEdit bool `description:"是否可编辑"`
  1123. // Editor string `description:"编辑人"`
  1124. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1125. // HaveOperaAuth bool `description:"是否有数据权限"`
  1126. // }
  1127. //
  1128. // ExcelInfoDetail excel表格详情(前端使用)
  1129. type ExcelInfoDetail struct {
  1130. ExcelInfoId int `gorm:"column:excel_info_id;primaryKey" orm:"column(excel_info_id);pk"`
  1131. Source int `gorm:"column:source" description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  1132. ExcelType int `gorm:"column:excel_type" description:"表格类型,1:指标列,2:日期列,默认:1"`
  1133. ExcelName string `gorm:"column:excel_name" description:"表格名称"`
  1134. UniqueCode string `gorm:"column:unique_code" description:"表格唯一编码"`
  1135. ExcelClassifyId int `gorm:"column:excel_classify_id" description:"表格分类id"`
  1136. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  1137. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  1138. Content string `gorm:"column:content" description:"表格内容"`
  1139. ExcelImage string `gorm:"column:excel_image" description:"表格图片"`
  1140. FileUrl string `gorm:"column:file_url" description:"表格下载地址"`
  1141. Sort int `gorm:"column:sort" description:"排序字段,数字越小越排前面"`
  1142. IsDelete int `gorm:"column:is_delete" description:"是否删除,0:未删除,1:已删除"`
  1143. ModifyTime time.Time `gorm:"column:modify_time" description:"最近修改日期"`
  1144. CreateTime time.Time `gorm:"column:create_time" description:"创建日期"`
  1145. TableData interface{} `gorm:"column:table_data" description:"表格内容"`
  1146. CanEdit bool `gorm:"column:can_edit" description:"是否可编辑"`
  1147. Editor string `gorm:"column:editor" description:"编辑人"`
  1148. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1149. HaveOperaAuth bool `gorm:"column:have_opera_auth" description:"是否有数据权限"`
  1150. }