excel_info.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. package excel
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // ExcelInfo excel表格详情表
  9. type ExcelInfo struct {
  10. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  11. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  12. ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  13. ExcelName string `description:"表格名称"`
  14. UniqueCode string `description:"表格唯一编码"`
  15. ExcelClassifyId int `description:"表格分类id"`
  16. SysUserId int `description:"操作人id"`
  17. SysUserRealName string `description:"操作人真实姓名"`
  18. Content string `description:"表格内容"`
  19. ExcelImage string `description:"表格图片"`
  20. FileUrl string `description:"表格下载地址"`
  21. Sort int `description:"排序字段,数字越小越排前面"`
  22. IsDelete int `description:"是否删除,0:未删除,1:已删除"`
  23. ModifyTime time.Time `description:"最近修改日期"`
  24. CreateTime time.Time `description:"创建日期"`
  25. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  26. ParentId int `description:"表格的父级id"`
  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. SourcesFrom string `description:"图表来源"`
  33. }
  34. // Update 更新 excel表格基础信息
  35. func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. _, err = o.Update(excelInfo, cols...)
  38. return
  39. }
  40. type MyExcelInfoList struct {
  41. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  42. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
  43. ExcelType int `description:"表格类型,1:指标列,2:日期列,默认:1"`
  44. ExcelName string `description:"表格名称"`
  45. UniqueCode string `description:"表格唯一编码"`
  46. ExcelClassifyId int `description:"表格分类id"`
  47. SysUserId int `description:"操作人id"`
  48. SysUserRealName string `description:"操作人真实姓名"`
  49. ExcelImage string `description:"表格图片"`
  50. FileUrl string `description:"表格下载地址"`
  51. Sort int `description:"排序字段,数字越小越排前面"`
  52. ModifyTime time.Time `description:"最近修改日期"`
  53. CreateTime time.Time `description:"创建日期"`
  54. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  55. HaveOperaAuth bool `description:"是否有数据权限"`
  56. }
  57. // AddExcelInfo 新增表格
  58. func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  59. o, err := orm.NewOrmUsingDB("data").Begin()
  60. if err != nil {
  61. return
  62. }
  63. defer func() {
  64. if err != nil {
  65. _ = o.Rollback()
  66. } else {
  67. _ = o.Commit()
  68. }
  69. }()
  70. // 表格信息入库
  71. lastId, err := o.Insert(excelInfo)
  72. if err != nil {
  73. return
  74. }
  75. excelInfo.ExcelInfoId = int(lastId)
  76. // excel与指标的关联关系
  77. dataNum := len(excelEdbMappingList)
  78. if dataNum > 0 {
  79. for k, v := range excelEdbMappingList {
  80. v.ExcelInfoId = excelInfo.ExcelInfoId
  81. excelEdbMappingList[k] = v
  82. }
  83. _, err = o.InsertMulti(dataNum, excelEdbMappingList)
  84. }
  85. return
  86. }
  87. // EditExcelInfo 编辑表格
  88. func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEdbMappingList []*ExcelEdbMapping) (err error) {
  89. o, err := orm.NewOrmUsingDB("data").Begin()
  90. if err != nil {
  91. return
  92. }
  93. defer func() {
  94. if err != nil {
  95. _ = o.Rollback()
  96. } else {
  97. _ = o.Commit()
  98. }
  99. }()
  100. // ETA表格信息变更
  101. _, err = o.Update(excelInfo, updateExcelInfoParams...)
  102. if err != nil {
  103. return
  104. }
  105. // 删除关系表
  106. sql := `DELETE FROM excel_edb_mapping WHERE excel_info_id=? `
  107. _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  108. // excel与指标的关联关系
  109. dataNum := len(excelEdbMappingList)
  110. if dataNum > 0 {
  111. for k, v := range excelEdbMappingList {
  112. v.ExcelInfoId = excelInfo.ExcelInfoId
  113. excelEdbMappingList[k] = v
  114. }
  115. _, err = o.InsertMulti(dataNum, excelEdbMappingList)
  116. }
  117. return
  118. }
  119. // GetExcelInfoAll 获取所有表格列表,用于分类展示
  120. func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
  121. o := orm.NewOrmUsingDB("data")
  122. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  123. unique_code,sys_user_id,sys_user_real_name,is_join_permission
  124. FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
  125. _, err = o.Raw(sql).QueryRows(&items)
  126. return
  127. }
  128. // GetNoContentExcelInfoAll 获取不含content的表格列表 用于分类展示
  129. func GetNoContentExcelInfoAll(source, userId int) (items []*ExcelClassifyItems, err error) {
  130. o := orm.NewOrmUsingDB("data")
  131. sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  132. unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission
  133. FROM excel_info where is_delete=0 AND source = ? `
  134. pars := []interface{}{source}
  135. if userId > 0 {
  136. sql += ` AND sys_user_id = ? `
  137. pars = append(pars, userId)
  138. }
  139. sql += ` ORDER BY sort asc,excel_info_id desc `
  140. _, err = o.Raw(sql, pars...).QueryRows(&items)
  141. return
  142. }
  143. // GetAllExcelInfoBySource 根据来源获取包含content的表格列表
  144. func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
  145. o := orm.NewOrmUsingDB("data")
  146. sql := ` SELECT * FROM excel_info where is_delete=0 AND source = ? ORDER BY sort asc,create_time desc `
  147. _, err = o.Raw(sql, source).QueryRows(&items)
  148. return
  149. }
  150. // GetExcelInfoById 根据id 获取eta表格详情
  151. func GetExcelInfoById(excelInfoId int) (item *ExcelInfo, err error) {
  152. o := orm.NewOrmUsingDB("data")
  153. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  154. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  155. return
  156. }
  157. // GetExcelInfoByUnicode 编码获取表格
  158. func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
  159. o := orm.NewOrmUsingDB("data")
  160. sql := ` SELECT * FROM excel_info WHERE unique_code = ? AND is_delete = 0 `
  161. err = o.Raw(sql, unicode).QueryRow(&item)
  162. return
  163. }
  164. func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
  165. o := orm.NewOrmUsingDB("data")
  166. sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  167. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  168. return
  169. }
  170. func GetExcelInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  171. o := orm.NewOrmUsingDB("data")
  172. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. err = o.Raw(sql, pars).QueryRow(&count)
  177. return
  178. }
  179. func GetNoContentExcelInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ExcelClassifyItems, err error) {
  180. o := orm.NewOrmUsingDB("data")
  181. sql := `SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
  182. unique_code,sys_user_id,sys_user_real_name,sort,is_join_permission FROM excel_info WHERE 1=1 `
  183. if condition != "" {
  184. sql += condition
  185. }
  186. sql += ` AND is_delete=0 ORDER BY excel_info_id DESC LIMIT ?,? `
  187. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  188. return
  189. }
  190. func GetExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  191. o := orm.NewOrmUsingDB("data")
  192. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  193. if condition != "" {
  194. sql += condition
  195. }
  196. err = o.Raw(sql, pars).QueryRow(&item)
  197. return
  198. }
  199. // GetNextExcelInfoByCondition 根据条件获取下一个表格
  200. func GetNextExcelInfoByCondition(condition string, pars []interface{}) (item *ExcelInfo, err error) {
  201. o := orm.NewOrmUsingDB("data")
  202. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  203. if condition != "" {
  204. sql += condition
  205. }
  206. sql += " ORDER BY sort asc , create_time desc LIMIT 1 "
  207. err = o.Raw(sql, pars).QueryRow(&item)
  208. return
  209. }
  210. // GetNextExcelInfo 根据分类id获取下一个excel表格
  211. func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, err error) {
  212. o := orm.NewOrmUsingDB("data")
  213. sql := ` SELECT b.* FROM excel_classify AS a
  214. INNER JOIN excel_info AS b ON a.excel_classify_id=b.excel_classify_id
  215. WHERE (a.sort>? OR (a.sort=? and a.excel_classify_id>?) ) AND a.is_delete=0 AND b.is_delete=0
  216. AND a.source = ? AND b.source = ?
  217. ORDER BY a.sort ASC,b.sort asc,b.create_time desc
  218. LIMIT 1 `
  219. err = o.Raw(sql, classifySort, classifySort, classifyId, source, source).QueryRow(&item)
  220. return
  221. }
  222. // EditExcelInfoImage 修改excel表格的图片
  223. func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
  224. o := orm.NewOrmUsingDB("data")
  225. sql := ` UPDATE excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
  226. _, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
  227. if err != nil {
  228. fmt.Println("EditExcelInfoImage Err:", err.Error())
  229. return err
  230. }
  231. return
  232. }
  233. // GetExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  234. func GetExcelInfoByUniqueCode(uniqueCode string) (item *ExcelInfo, err error) {
  235. o := orm.NewOrmUsingDB("data")
  236. sql := ` SELECT * FROM excel_info WHERE unique_code=? AND is_delete=0 `
  237. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  238. return
  239. }
  240. func GetExcelInfoListByCondition(condition string, pars []interface{}) (items []*ExcelInfo, err error) {
  241. o := orm.NewOrmUsingDB("data")
  242. sql := ` SELECT * FROM excel_info WHERE 1=1 AND is_delete=0 `
  243. if condition != "" {
  244. sql += condition
  245. }
  246. sql += ` ORDER BY sort asc, excel_info_id asc`
  247. _, err = o.Raw(sql, pars).QueryRows(&items)
  248. return
  249. }
  250. // GetFirstExcelInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  251. func GetFirstExcelInfoByClassifyId(classifyId int) (item *ExcelInfo, err error) {
  252. o := orm.NewOrmUsingDB("data")
  253. sql := ` SELECT * FROM excel_info WHERE excel_classify_id=? AND is_delete=0 order by sort asc,excel_info_id desc limit 1`
  254. err = o.Raw(sql, classifyId).QueryRow(&item)
  255. return
  256. }
  257. // UpdateExcelInfoSortByClassifyId 根据表格id更新排序
  258. func UpdateExcelInfoSortByClassifyId(classifyId, nowSort, prevExcelInfoId int, updateSort string, source int) (err error) {
  259. o := orm.NewOrmUsingDB("data")
  260. sql := ` update excel_info set sort = ` + updateSort + ` WHERE excel_classify_id=? AND source=? AND is_delete=0 AND ( sort > ? `
  261. // todo 前一个兄弟节点后移
  262. if prevExcelInfoId > 0 {
  263. sql += ` or (excel_info_id < ` + fmt.Sprint(prevExcelInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  264. }
  265. sql += `)`
  266. _, err = o.Raw(sql, classifyId, source, nowSort).Exec()
  267. return
  268. }
  269. type ExcelInfoView struct {
  270. ExcelInfoId int `orm:"column(excel_info_id);pk"`
  271. ExcelName string `description:"来源名称"`
  272. ExcelClassifyId int `description:"表格分类id"`
  273. ExcelClassifyName string `description:"表格名称"`
  274. SysUserId int
  275. SysUserRealName string
  276. UniqueCode string `description:"表格唯一编码"`
  277. CreateTime time.Time
  278. ModifyTime time.Time
  279. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  280. StartDate string `description:"自定义开始日期"`
  281. EndDate string `description:"自定义结束日期"`
  282. IsSetName int `description:"设置名称"`
  283. EdbInfoIds string `description:"指标id"`
  284. ExcelType int `description:"生成样式:1:曲线图,2:季节性图"`
  285. Calendar string `description:"公历/农历"`
  286. SeasonStartDate string `description:"季节性图开始日期"`
  287. SeasonEndDate string `description:"季节性图开始日期"`
  288. ExcelImage string `description:"表格图片"`
  289. Sort int `description:"排序字段,数字越小越排前面"`
  290. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  291. MyExcelId int
  292. MyExcelClassifyId string `description:"我的表格分类,多个用逗号隔开"`
  293. ExcelClassify []*ExcelClassifyView
  294. EdbEndDate string `description:"指标最新更新日期"`
  295. LeftMin string `description:"表格左侧最小值"`
  296. LeftMax string `description:"表格左侧最大值"`
  297. RightMin string `description:"表格右侧最小值"`
  298. RightMax string `description:"表格右侧最大值"`
  299. }
  300. // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
  301. func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
  302. o := orm.NewOrmUsingDB("data")
  303. sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
  304. err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
  305. return
  306. }
  307. // GetNoContentExcelListByCondition 获取没有content的excel表格列表数据
  308. func GetNoContentExcelListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MyExcelInfoList, err error) {
  309. o := orm.NewOrmUsingDB("data")
  310. 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
  311. FROM excel_info WHERE 1=1 AND is_delete=0 `
  312. if condition != "" {
  313. sql += condition
  314. }
  315. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  316. sql += " ORDER BY create_time DESC LIMIT ?,? "
  317. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  318. return
  319. }
  320. func GetExcelListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  321. o := orm.NewOrmUsingDB("data")
  322. sql := ` SELECT COUNT(1) AS count FROM excel_info WHERE 1=1 AND is_delete=0 `
  323. if condition != "" {
  324. sql += condition
  325. }
  326. err = o.Raw(sql, pars).QueryRow(&count)
  327. return
  328. }
  329. // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
  330. func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
  331. o := orm.NewOrmUsingDB("data")
  332. 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 `
  333. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  334. return
  335. }
  336. // GetExcelInfoCountByClassifyId 根据分类id获取名下表格数量
  337. func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
  338. o := orm.NewOrmUsingDB("data")
  339. sql := ` SELECT count(1) total FROM excel_info WHERE excel_classify_id = ? AND is_delete=0 `
  340. err = o.Raw(sql, classifyId).QueryRow(&total)
  341. return
  342. }
  343. // UpdateExcelInfoClassifyId 更改表格分类
  344. func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
  345. o := orm.NewOrmUsingDB("data")
  346. sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
  347. _, err = o.Raw(sql, classifyId, excelInfoId).Exec()
  348. return
  349. }
  350. // GetNoContentExcelInfoByName 根据名称 获取eta表格详情
  351. func GetNoContentExcelInfoByName(excelName string, source int) (item *MyExcelInfoList, err error) {
  352. o := orm.NewOrmUsingDB("data")
  353. 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
  354. FROM excel_info WHERE excel_name = ? AND source = ? AND is_delete=0 `
  355. err = o.Raw(sql, excelName, source).QueryRow(&item)
  356. return
  357. }
  358. // GetNoContentExcelInfoByUniqueCode 根据unique_code来获取excel表格详情
  359. func GetNoContentExcelInfoByUniqueCode(uniqueCode string) (item *MyExcelInfoList, err error) {
  360. o := orm.NewOrmUsingDB("data")
  361. 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
  362. FROM excel_info WHERE unique_code=? AND is_delete=0 `
  363. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  364. return
  365. }
  366. // GetNoContentExcelInfoByExcelId 根据表格id来获取excel表格详情
  367. func GetNoContentExcelInfoByExcelId(excelInfoId int) (item *MyExcelInfoList, err error) {
  368. o := orm.NewOrmUsingDB("data")
  369. 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
  370. FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
  371. err = o.Raw(sql, excelInfoId).QueryRow(&item)
  372. return
  373. }
  374. // AddExcelInfoAndSheet 新增excel
  375. func AddExcelInfoAndSheet(excelInfo *ExcelInfo, sheetParamsList []AddExcelSheetParams) (err error) {
  376. o, err := orm.NewOrmUsingDB("data").Begin()
  377. if err != nil {
  378. return
  379. }
  380. defer func() {
  381. if err != nil {
  382. _ = o.Rollback()
  383. } else {
  384. _ = o.Commit()
  385. }
  386. }()
  387. // 表格信息入库
  388. lastId, err := o.Insert(excelInfo)
  389. if err != nil {
  390. return
  391. }
  392. excelInfo.ExcelInfoId = int(lastId)
  393. // sheet信息入库
  394. for _, sheetInfo := range sheetParamsList {
  395. dataNum := len(sheetInfo.DataList)
  396. //sheet信息入库
  397. excelSheetInfo := &ExcelSheet{
  398. ExcelSheetId: 0,
  399. ExcelInfoId: excelInfo.ExcelInfoId,
  400. SheetName: sheetInfo.SheetName,
  401. PageNum: dataNum,
  402. Index: sheetInfo.Index,
  403. Sort: sheetInfo.Sort,
  404. Config: sheetInfo.Config,
  405. CalcChain: sheetInfo.CalcChain,
  406. ModifyTime: time.Now(),
  407. CreateTime: time.Now(),
  408. }
  409. sheetId, tmpErr := o.Insert(excelSheetInfo)
  410. if tmpErr != nil {
  411. err = tmpErr
  412. return
  413. }
  414. excelSheetInfo.ExcelSheetId = int(sheetId)
  415. // data信息入库
  416. if dataNum > 0 {
  417. for k, _ := range sheetInfo.DataList {
  418. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  419. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  420. }
  421. _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  422. if tmpErr != nil {
  423. err = tmpErr
  424. return
  425. }
  426. }
  427. }
  428. return
  429. }
  430. // SaveExcelInfoAndSheet 编辑保存
  431. func SaveExcelInfoAndSheet(excelInfo *ExcelInfo, updateExcelInfoParam []string, sheetParamsList []AddExcelSheetParams) (err error) {
  432. o, err := orm.NewOrmUsingDB("data").Begin()
  433. if err != nil {
  434. return
  435. }
  436. defer func() {
  437. if err != nil {
  438. _ = o.Rollback()
  439. } else {
  440. _ = o.Commit()
  441. }
  442. }()
  443. // 表格信息入库
  444. _, err = o.Update(excelInfo, updateExcelInfoParam...)
  445. if err != nil {
  446. return
  447. }
  448. // 先删除历史的sheet信息
  449. sql := `DELETE FROM excel_sheet WHERE excel_info_id = ?`
  450. _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  451. if err != nil {
  452. return
  453. }
  454. // 再删除历史sheet中的cell data信息
  455. sql = `DELETE FROM excel_sheet_data WHERE excel_info_id = ?`
  456. _, err = o.Raw(sql, excelInfo.ExcelInfoId).Exec()
  457. if err != nil {
  458. return
  459. }
  460. // sheet信息入库
  461. for _, sheetInfo := range sheetParamsList {
  462. dataNum := len(sheetInfo.DataList)
  463. //sheet信息入库
  464. excelSheetInfo := &ExcelSheet{
  465. ExcelSheetId: 0,
  466. ExcelInfoId: excelInfo.ExcelInfoId,
  467. SheetName: sheetInfo.SheetName,
  468. PageNum: dataNum,
  469. Index: sheetInfo.Index,
  470. Sort: sheetInfo.Sort,
  471. Config: sheetInfo.Config,
  472. CalcChain: sheetInfo.CalcChain,
  473. ModifyTime: time.Now(),
  474. CreateTime: time.Now(),
  475. }
  476. sheetId, tmpErr := o.Insert(excelSheetInfo)
  477. if tmpErr != nil {
  478. err = tmpErr
  479. return
  480. }
  481. excelSheetInfo.ExcelSheetId = int(sheetId)
  482. // data信息入库
  483. if dataNum > 0 {
  484. for k, _ := range sheetInfo.DataList {
  485. sheetInfo.DataList[k].ExcelSheetId = excelSheetInfo.ExcelSheetId
  486. sheetInfo.DataList[k].ExcelInfoId = excelSheetInfo.ExcelInfoId
  487. }
  488. _, tmpErr = o.InsertMulti(dataNum, sheetInfo.DataList)
  489. if tmpErr != nil {
  490. err = tmpErr
  491. return
  492. }
  493. }
  494. }
  495. return
  496. }
  497. // BatchRefreshExcelReq 批量刷新表格请求
  498. type BatchRefreshExcelReq struct {
  499. ExcelCodes []string `description:"表格编码"`
  500. ReportId int `description:"报告ID"`
  501. ReportChapterId int `description:"报告章节ID"`
  502. Source string `description:"来源,枚举值:report、english_report、smart_report"`
  503. }
  504. // GetExcelMaxSortByClassifyId 获取当前分类下,且排序数最大的excel
  505. func GetExcelMaxSortByClassifyId(classifyId int, source int) (sort int, err error) {
  506. o := orm.NewOrmUsingDB("data")
  507. 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`
  508. err = o.Raw(sql, classifyId, source).QueryRow(&sort)
  509. return
  510. }
  511. // GetNoContentExcelListByExcelInfoIdList
  512. // @Description: 根据ETA表格ID列表获取列表信息
  513. // @param excelInfoIdList []string
  514. // @return items
  515. // @return err
  516. func GetNoContentExcelListByExcelInfoIdList(excelInfoIdList []string) (items []*MyExcelInfoList, err error) {
  517. num := len(excelInfoIdList)
  518. if num <= 0 {
  519. return
  520. }
  521. o := orm.NewOrmUsingDB("data")
  522. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  523. _, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
  524. return
  525. }
  526. // GetNoContentExcelListByUserId
  527. // @Description: 根据ETA表格ID列表获取列表信息
  528. // @param userIdList []int
  529. // @return items
  530. // @return err
  531. func GetNoContentExcelListByUserId(userIdList []int) (items []*MyExcelInfoList, err error) {
  532. num := len(userIdList)
  533. if num <= 0 {
  534. return
  535. }
  536. o := orm.NewOrmUsingDB("data")
  537. sql := ` SELECT * FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
  538. _, err = o.Raw(sql, userIdList).QueryRows(&items)
  539. return
  540. }
  541. // ModifyExcelInfoUserIdByCodeList
  542. // @Description: 根据编码列表修改表格信息
  543. // @author: Roc
  544. // @datetime 2024-03-26 14:16:30
  545. // @param excelIdList []string
  546. // @param userId int
  547. // @param userName string
  548. // @return err error
  549. func ModifyExcelInfoUserIdByCodeList(excelIdList []string, userId int, userName string) (err error) {
  550. num := len(excelIdList)
  551. if num <= 0 {
  552. return
  553. }
  554. o := orm.NewOrmUsingDB("data")
  555. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) `
  556. _, err = o.Raw(sql, userId, userName, excelIdList).Exec()
  557. return
  558. }
  559. // ModifyExcelInfoUserIdByOldUserId
  560. // @Description: 根据旧的用户id修改创建人
  561. // @author: Roc
  562. // @datetime 2024-03-25 19:14:59
  563. // @param oldUserId int
  564. // @param userId int
  565. // @param userName string
  566. // @return err error
  567. func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  568. num := len(oldUserIdList)
  569. if num <= 0 {
  570. return
  571. }
  572. o := orm.NewOrmUsingDB("data")
  573. sql := `UPDATE excel_info SET sys_user_id=?,sys_user_real_name=? WHERE is_delete=0 AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  574. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  575. return
  576. }
  577. // ExcelInfoDetailButton 操作按钮
  578. type ExcelInfoDetailButton struct {
  579. RefreshButton bool `description:"是否可刷新"`
  580. CopyButton bool `description:"是否可另存为"`
  581. DownloadButton bool `description:"是否可下载"`
  582. OpButton bool `description:"是否可编辑"`
  583. DeleteButton bool `description:"是否可删除"`
  584. OpEdbButton bool `description:"是否可生成指标"`
  585. RefreshEdbButton bool `description:"是否可刷新指标"`
  586. OpWorkerButton bool `description:"是否修改协作人"`
  587. }