excel_info.go 24 KB

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