excel_info.go 22 KB

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