excel_info.go 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  1. package excel
  2. import (
  3. "archive/zip"
  4. "encoding/json"
  5. "eta/eta_api/controllers"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. excel3 "eta/eta_api/models/data_manage/excel"
  9. "eta/eta_api/models/data_manage/excel/request"
  10. "eta/eta_api/models/data_manage/excel/response"
  11. "eta/eta_api/services"
  12. "eta/eta_api/services/data"
  13. excel2 "eta/eta_api/services/data/excel"
  14. "eta/eta_api/services/excel"
  15. "eta/eta_api/utils"
  16. "fmt"
  17. "github.com/rdlucklib/rdluck_tools/paging"
  18. "github.com/yidane/formula"
  19. "io"
  20. "os"
  21. "path/filepath"
  22. "strconv"
  23. "strings"
  24. "time"
  25. )
  26. // ExcelInfoController ETA表格管理
  27. type ExcelInfoController struct {
  28. controllers.BaseAuthController
  29. }
  30. // Add
  31. // @Title 新增表格接口
  32. // @Description 新增表格接口
  33. // @Param request body request.AddExcelInfoReq true "type json string"
  34. // @Success 200 {object} response.AddExcelInfoResp
  35. // @router /excel_info/add [post]
  36. func (c *ExcelInfoController) Add() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. c.Data["json"] = br
  40. c.ServeJSON()
  41. }()
  42. sysUser := c.SysUser
  43. if sysUser == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,SysUser Is Empty"
  46. br.Ret = 408
  47. return
  48. }
  49. deleteCache := true
  50. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  51. defer func() {
  52. if deleteCache {
  53. _ = utils.Rc.Delete(cacheKey)
  54. }
  55. }()
  56. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  57. deleteCache = false
  58. br.Msg = "系统处理中,请稍后重试!"
  59. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  60. return
  61. }
  62. var req request.AddExcelInfoReq
  63. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  64. if err != nil {
  65. br.Msg = "参数解析异常!"
  66. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  67. return
  68. }
  69. req.ExcelName = strings.Trim(req.ExcelName, " ")
  70. if req.ExcelName == "" {
  71. br.Msg = "请填写表格名称!"
  72. br.IsSendEmail = false
  73. return
  74. }
  75. if req.ExcelClassifyId <= 0 {
  76. br.Msg = "分类参数错误!"
  77. br.IsSendEmail = false
  78. return
  79. }
  80. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  81. if err != nil {
  82. if err.Error() == utils.ErrNoRow() {
  83. br.Msg = "分类不存在"
  84. br.ErrMsg = "分类不存在"
  85. br.IsSendEmail = false
  86. return
  87. }
  88. br.Msg = "获取分类信息失败"
  89. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  90. return
  91. }
  92. if excelClassify == nil {
  93. br.Msg = "分类不存在"
  94. br.ErrMsg = "分类不存在"
  95. br.IsSendEmail = false
  96. return
  97. }
  98. var condition string
  99. var pars []interface{}
  100. condition += " AND excel_classify_id=? "
  101. pars = append(pars, req.ExcelClassifyId)
  102. condition += " AND excel_name=? "
  103. pars = append(pars, req.ExcelName)
  104. // 获取分类下是否存在该表格名称
  105. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  106. if err != nil {
  107. br.Msg = "判断表格名称是否存在失败"
  108. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  109. return
  110. }
  111. if count > 0 {
  112. br.Msg = "表格名称已存在,请重新填写表格名称"
  113. br.IsSendEmail = false
  114. return
  115. }
  116. // 默认的excel类型是1
  117. if req.Source == 0 {
  118. req.Source = 1
  119. }
  120. content := req.Content
  121. // 引用的指标id
  122. edbInfoIdList := make([]int, 0)
  123. // 自定义表格
  124. if req.Source == 2 {
  125. jsonStrByte, err := json.Marshal(req.TableData)
  126. if err != nil {
  127. br.Msg = "自定义表格数据获取失败"
  128. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  129. return
  130. }
  131. var tableData request.TableDataReq
  132. err = json.Unmarshal(jsonStrByte, &tableData)
  133. if err != nil {
  134. br.Msg = "自定义表格数据获取失败"
  135. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  136. return
  137. }
  138. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  139. if err != nil {
  140. br.Msg = "自定义表格数据获取失败"
  141. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  142. return
  143. }
  144. edbInfoIdList = tableDataConfig.EdbInfoIdList
  145. contentByte, err := json.Marshal(tableDataConfig)
  146. if err != nil {
  147. br.Msg = "自定义表格数据获取失败"
  148. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  149. return
  150. }
  151. content = string(contentByte)
  152. }
  153. // 混合表格
  154. if req.Source == 3 {
  155. contentByte, err := json.Marshal(req.TableData)
  156. if err != nil {
  157. br.Msg = "自定义表格数据获取失败"
  158. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  159. return
  160. }
  161. content = string(contentByte)
  162. var result request.MixedTableReq
  163. err = json.Unmarshal(contentByte, &result)
  164. if err != nil {
  165. br.Msg = "获取失败"
  166. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  167. return
  168. }
  169. newResult, tmpErr, tmpErrMsg := excel2.GetMixedTableCellData(result.CellRelation, result.Data)
  170. if tmpErr != nil {
  171. br.Msg = "获取失败"
  172. if tmpErrMsg != `` {
  173. br.Msg = tmpErrMsg
  174. }
  175. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  176. return
  177. }
  178. edbInfoIdMap := make(map[int]int)
  179. for _, tmpV := range newResult {
  180. for _, v := range tmpV {
  181. if v.EdbInfoId > 0 {
  182. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  183. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  184. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  185. }
  186. }
  187. }
  188. }
  189. }
  190. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  191. excelInfo := &excel3.ExcelInfo{
  192. //ExcelInfoId: 0,
  193. ExcelName: req.ExcelName,
  194. Source: req.Source,
  195. ExcelType: req.ExcelType,
  196. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  197. ExcelClassifyId: req.ExcelClassifyId,
  198. SysUserId: sysUser.AdminId,
  199. SysUserRealName: sysUser.RealName,
  200. Content: content,
  201. ExcelImage: req.ExcelImage,
  202. Sort: 0,
  203. IsDelete: 0,
  204. ModifyTime: time.Now(),
  205. CreateTime: time.Now(),
  206. }
  207. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  208. if len(edbInfoIdList) > 0 {
  209. for _, edbInfoId := range edbInfoIdList {
  210. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  211. //ExcelEdbMappingId: 0,
  212. //ExcelInfoId: 0,
  213. Source: excelInfo.Source,
  214. EdbInfoId: edbInfoId,
  215. CreateTime: time.Now(),
  216. ModifyTime: time.Now(),
  217. })
  218. }
  219. }
  220. err = excel3.AddExcelInfo(excelInfo, excelEdbMappingList)
  221. if err != nil {
  222. br.Msg = "保存失败"
  223. br.ErrMsg = "保存失败,Err:" + err.Error()
  224. return
  225. }
  226. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  227. if req.Source == 1 {
  228. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  229. }
  230. _, err = services.UpdateExcelEditMark(excelInfo.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  231. if err != nil {
  232. br.Msg = "查询标记状态失败"
  233. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  234. return
  235. }
  236. resp := new(response.AddExcelInfoResp)
  237. resp.ExcelInfoId = excelInfo.ExcelInfoId
  238. resp.UniqueCode = excelInfo.UniqueCode
  239. //新增操作日志
  240. //{
  241. // excelLog := &data_manage.ExcelInfoLog{
  242. // //ExcelInfoLogId: 0,
  243. // ExcelInfoId: excelInfo.ExcelInfoId,
  244. // ExcelName: req.ExcelName,
  245. // ExcelClassifyId: req.ExcelClassifyId,
  246. // SysUserId: sysUser.AdminId,
  247. // SysUserRealName: sysUser.RealName,
  248. // UniqueCode: excelInfo.UniqueCode,
  249. // CreateTime: time.Now(),
  250. // Content: string(c.Ctx.Input.RequestBody),
  251. // Status: "新增表格",
  252. // Method: c.Ctx.Input.URI(),
  253. // }
  254. // go data_manage.AddExcelInfoLog(excelLog)
  255. //}
  256. br.Ret = 200
  257. br.Success = true
  258. br.Msg = "保存成功"
  259. br.Data = resp
  260. br.IsAddLog = true
  261. }
  262. // List
  263. // @Title ETA表格列表接口
  264. // @Description ETA表格列表接口
  265. // @Param PageSize query int true "每页数据条数"
  266. // @Param CurrentIndex query int true "当前页页码,从1开始"
  267. // @Param ExcelClassifyId query int true "分类id"
  268. // @Param Keyword query string true "搜索关键词"
  269. // @Param AdminId query int false "创建人id"
  270. // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
  271. // @Param IsShowMe query bool true "是否只看我的,true、false"
  272. // @Success 200 {object} response.ExcelListResp
  273. // @router /excel_info/list [get]
  274. func (c *ExcelInfoController) List() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. c.Data["json"] = br
  278. c.ServeJSON()
  279. }()
  280. sysUser := c.SysUser
  281. if sysUser == nil {
  282. br.Msg = "请登录"
  283. br.ErrMsg = "请登录,SysUser Is Empty"
  284. br.Ret = 408
  285. return
  286. }
  287. excelClassifyId, _ := c.GetInt("ExcelClassifyId")
  288. pageSize, _ := c.GetInt("PageSize")
  289. currentIndex, _ := c.GetInt("CurrentIndex")
  290. keyword := c.GetString("Keyword")
  291. adminId, _ := c.GetInt("AdminId")
  292. source, _ := c.GetInt("Source")
  293. var total int
  294. page := paging.GetPaging(currentIndex, pageSize, total)
  295. var startSize int
  296. if pageSize <= 0 {
  297. pageSize = utils.PageSize20
  298. }
  299. if currentIndex <= 0 {
  300. currentIndex = 1
  301. }
  302. startSize = paging.StartIndex(currentIndex, pageSize)
  303. var condition string
  304. var pars []interface{}
  305. // 如果没有传的话,那就是代表前三种表格
  306. if source <= 0 {
  307. condition += " AND source in (?,?,?) "
  308. pars = append(pars, utils.EXCEL_DEFAULT, utils.TIME_TABLE, utils.MIXED_TABLE)
  309. } else {
  310. condition += " AND source = ? "
  311. pars = append(pars, source)
  312. }
  313. // 筛选分类
  314. if excelClassifyId > 0 {
  315. _, err := excel3.GetExcelClassifyById(excelClassifyId)
  316. if err != nil && err.Error() != utils.ErrNoRow() {
  317. br.Msg = "获取表格信息失败"
  318. br.ErrMsg = "获取信息失败,GetExcelClassify,Err:" + err.Error()
  319. return
  320. }
  321. condition += " AND excel_classify_id = ? "
  322. pars = append(pars, excelClassifyId)
  323. }
  324. if keyword != "" {
  325. condition += ` AND ( excel_name LIKE ? )`
  326. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  327. }
  328. if adminId > 0 {
  329. condition += " AND sys_user_id = ? "
  330. pars = append(pars, adminId)
  331. }
  332. //只看我的
  333. isShowMe, _ := c.GetBool("IsShowMe")
  334. if isShowMe {
  335. condition += " AND sys_user_id = ? "
  336. pars = append(pars, sysUser.AdminId)
  337. }
  338. //获取表格信息
  339. list, err := excel3.GetNoContentExcelListByCondition(condition, pars, startSize, pageSize)
  340. if err != nil && err.Error() != utils.ErrNoRow() {
  341. br.Success = true
  342. br.Msg = "获取表格信息失败"
  343. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  344. return
  345. }
  346. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  347. list = make([]*excel3.MyExcelInfoList, 0)
  348. }
  349. // 总数据量
  350. dataCount, err := excel3.GetExcelListCountByCondition(condition, pars)
  351. if err != nil && err.Error() != utils.ErrNoRow() {
  352. br.Msg = "获取表格列表信息失败"
  353. br.ErrMsg = "获取表格列表数据总数失败,Err:" + err.Error()
  354. return
  355. }
  356. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  357. resp := response.ExcelListResp{
  358. Paging: page,
  359. List: list,
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // Detail
  367. // @Title 获取表格详情
  368. // @Description 获取表格详情接口
  369. // @Param ExcelInfoId query int true "表格id"
  370. // @Success 200 {object} data_manage.ExcelInfo
  371. // @router /excel_info/detail [get]
  372. func (c *ExcelInfoController) Detail() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. c.Data["json"] = br
  376. c.ServeJSON()
  377. }()
  378. sysUser := c.SysUser
  379. if sysUser == nil {
  380. br.Msg = "请登录"
  381. br.ErrMsg = "请登录,SysUser Is Empty"
  382. br.Ret = 408
  383. return
  384. }
  385. excelInfoId, _ := c.GetInt("ExcelInfoId")
  386. if excelInfoId <= 0 {
  387. br.Msg = "请选择表格"
  388. br.ErrMsg = "ExcelInfoId未传"
  389. br.IsSendEmail = false
  390. return
  391. }
  392. // 获取数据详情
  393. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId)
  394. if err != nil {
  395. br.Msg = errMsg
  396. br.ErrMsg = err.Error()
  397. return
  398. }
  399. // 编辑状态
  400. markStatus, err := services.UpdateExcelEditMark(excelInfoId, sysUser.AdminId, 2, sysUser.RealName)
  401. if err != nil {
  402. br.Msg = "查询标记状态失败"
  403. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  404. return
  405. }
  406. if markStatus.Status == 0 {
  407. excelDetail.CanEdit = true
  408. } else {
  409. excelDetail.Editor = markStatus.Editor
  410. }
  411. // excel表格按钮权限
  412. excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source)
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "获取成功"
  416. br.Data = excelDetail
  417. }
  418. // Edit
  419. // @Title 编辑表格接口
  420. // @Description 新增表格接口
  421. // @Param request body request.EditExcelInfoReq true "type json string"
  422. // @Success 200 {object} response.AddExcelInfoResp
  423. // @router /excel_info/edit [post]
  424. func (c *ExcelInfoController) Edit() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. c.Data["json"] = br
  428. c.ServeJSON()
  429. }()
  430. sysUser := c.SysUser
  431. if sysUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,SysUser Is Empty"
  434. br.Ret = 408
  435. return
  436. }
  437. deleteCache := true
  438. var req request.EditExcelInfoReq
  439. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  440. if err != nil {
  441. br.Msg = "参数解析异常!"
  442. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  443. return
  444. }
  445. if req.ExcelInfoId <= 0 {
  446. br.Msg = "请传入ETA表格标识!"
  447. return
  448. }
  449. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  450. defer func() {
  451. if deleteCache {
  452. _ = utils.Rc.Delete(cacheKey)
  453. }
  454. }()
  455. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  456. deleteCache = false
  457. br.Msg = "系统处理中,请稍后重试!"
  458. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  459. return
  460. }
  461. req.ExcelName = strings.Trim(req.ExcelName, " ")
  462. if req.ExcelName == "" {
  463. br.Msg = "请填写表格名称!"
  464. br.IsSendEmail = false
  465. return
  466. }
  467. if req.ExcelClassifyId <= 0 {
  468. br.Msg = "分类参数错误!"
  469. br.IsSendEmail = false
  470. return
  471. }
  472. // 标记编辑状态
  473. _, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  474. if err != nil {
  475. br.Msg = "查询标记状态失败"
  476. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  477. return
  478. }
  479. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  480. if err != nil {
  481. if err.Error() == utils.ErrNoRow() {
  482. br.Msg = "分类不存在"
  483. br.ErrMsg = "分类不存在"
  484. br.IsSendEmail = false
  485. return
  486. }
  487. br.Msg = "获取分类信息失败"
  488. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  489. return
  490. }
  491. if excelClassify == nil {
  492. br.Msg = "分类不存在"
  493. br.ErrMsg = "分类不存在"
  494. br.IsSendEmail = false
  495. return
  496. }
  497. //判断表格是否存在
  498. var condition string
  499. var pars []interface{}
  500. condition += " AND excel_info_id != ? "
  501. pars = append(pars, req.ExcelInfoId)
  502. condition += " AND excel_classify_id=? "
  503. pars = append(pars, req.ExcelClassifyId)
  504. condition += " AND excel_name=? "
  505. pars = append(pars, req.ExcelName)
  506. // 获取分类下是否存在该表格名称
  507. count, err := excel3.GetExcelInfoCountByCondition(condition, pars)
  508. if err != nil {
  509. br.Msg = "ETA判断表格名称是否存在失败"
  510. br.ErrMsg = "判断ETA表格名称是否存在失败,Err:" + err.Error()
  511. return
  512. }
  513. if count > 0 {
  514. br.Msg = "ETA表格名称已存在,请重新填写"
  515. br.IsSendEmail = false
  516. return
  517. }
  518. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  519. if err != nil {
  520. br.Msg = "获取ETA表格失败"
  521. br.ErrMsg = "获取ETA表格失败,Err:" + err.Error()
  522. return
  523. }
  524. // 操作权限校验
  525. {
  526. button := excel2.GetExcelInfoOpButton(sysUser, excelInfo.SysUserId, excelInfo.Source)
  527. if !button.OpButton {
  528. br.Msg = "无操作权限"
  529. br.Msg = "无操作权限"
  530. br.IsSendEmail = false
  531. return
  532. }
  533. }
  534. // 引用的指标id
  535. edbInfoIdList := make([]int, 0)
  536. content := req.Content
  537. switch excelInfo.Source {
  538. case 2: // 自定义表格
  539. jsonStrByte, err := json.Marshal(req.TableData)
  540. if err != nil {
  541. br.Msg = "自定义表格数据获取失败"
  542. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  543. return
  544. }
  545. var tableData request.TableDataReq
  546. err = json.Unmarshal(jsonStrByte, &tableData)
  547. if err != nil {
  548. br.Msg = "自定义表格数据获取失败"
  549. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  550. return
  551. }
  552. edbInfoIdList = tableData.EdbInfoIdList
  553. tableDataConfig, err := excel2.GetTableDataConfig(tableData)
  554. if err != nil {
  555. br.Msg = "自定义表格数据获取失败"
  556. br.ErrMsg = "自定义表格数据获取失败,Err:" + err.Error()
  557. return
  558. }
  559. contentByte, err := json.Marshal(tableDataConfig)
  560. if err != nil {
  561. br.Msg = "自定义表格数据获取失败"
  562. br.ErrMsg = "自定义表格数据获取后,转json失败,Err:" + err.Error()
  563. return
  564. }
  565. content = string(contentByte)
  566. case 3: // 混合表格
  567. contentByte, err := json.Marshal(req.TableData)
  568. if err != nil {
  569. br.Msg = "混合表格数据获取失败"
  570. br.ErrMsg = "混合表格数据获取后,转json失败,Err:" + err.Error()
  571. return
  572. }
  573. content = string(contentByte)
  574. var result request.MixedTableReq
  575. err = json.Unmarshal(contentByte, &result)
  576. if err != nil {
  577. br.Msg = "获取失败"
  578. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  579. return
  580. }
  581. newResult, tmpErr, tmpErrMsg := excel2.GetMixedTableCellData(result.CellRelation, result.Data)
  582. if tmpErr != nil {
  583. br.Msg = "获取失败"
  584. if tmpErrMsg != `` {
  585. br.Msg = tmpErrMsg
  586. }
  587. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  588. return
  589. }
  590. edbInfoIdMap := make(map[int]int)
  591. for _, tmpV := range newResult {
  592. for _, v := range tmpV {
  593. if v.EdbInfoId > 0 {
  594. if _, ok := edbInfoIdMap[v.EdbInfoId]; !ok {
  595. edbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  596. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  597. }
  598. }
  599. }
  600. }
  601. }
  602. excelInfo.ModifyTime = time.Now()
  603. excelInfo.ExcelName = req.ExcelName
  604. excelInfo.ExcelType = req.ExcelType
  605. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  606. excelInfo.ExcelImage = req.ExcelImage
  607. excelInfo.Content = content
  608. // 自动保存时不会传缩略图,也就不更新这个字段
  609. var updateExcelInfoParams []string
  610. if req.ExcelImage != "" {
  611. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content"}
  612. } else {
  613. updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content"}
  614. }
  615. excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
  616. if len(edbInfoIdList) > 0 {
  617. for _, edbInfoId := range edbInfoIdList {
  618. excelEdbMappingList = append(excelEdbMappingList, &excel3.ExcelEdbMapping{
  619. //ExcelEdbMappingId: 0,
  620. ExcelInfoId: excelInfo.ExcelInfoId,
  621. Source: excelInfo.Source,
  622. EdbInfoId: edbInfoId,
  623. CreateTime: time.Now(),
  624. ModifyTime: time.Now(),
  625. })
  626. }
  627. }
  628. err = excel3.EditExcelInfo(excelInfo, updateExcelInfoParams, excelEdbMappingList)
  629. if err != nil {
  630. br.Msg = "保存失败"
  631. br.ErrMsg = "保存失败,Err:" + err.Error()
  632. return
  633. }
  634. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  635. if excelInfo.Source == 1 {
  636. go excel2.UpdateExcelInfoFileUrl(excelInfo)
  637. }
  638. // 加入草稿
  639. {
  640. excelDraftInfo := &excel3.ExcelDraft{
  641. //ExcelDraftId: 0,
  642. ExcelId: req.ExcelInfoId,
  643. Name: req.ExcelName,
  644. Content: content,
  645. OpUserId: sysUser.AdminId,
  646. OpUserName: sysUser.RealName,
  647. CreateTime: time.Now(),
  648. }
  649. err = excel3.AddExcelDraft(excelDraftInfo)
  650. }
  651. resp := response.AddExcelInfoResp{
  652. ExcelInfoId: excelInfo.ExcelInfoId,
  653. UniqueCode: excelInfo.UniqueCode,
  654. }
  655. //删除公共图库那边的缓存
  656. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelInfo.UniqueCode)
  657. br.Ret = 200
  658. br.Success = true
  659. br.Msg = "修改成功"
  660. br.Data = resp
  661. br.IsAddLog = true
  662. }
  663. // Move
  664. // @Title 移动表格接口
  665. // @Description 移动表格接口
  666. // @Param request body request.MoveExcelInfoReq true "type json string"
  667. // @Success Ret=200 移动成功
  668. // @router /excel_info/move [post]
  669. func (c *ExcelInfoController) Move() {
  670. br := new(models.BaseResponse).Init()
  671. defer func() {
  672. c.Data["json"] = br
  673. c.ServeJSON()
  674. }()
  675. sysUser := c.SysUser
  676. if sysUser == nil {
  677. br.Msg = "请登录"
  678. br.ErrMsg = "请登录,SysUser Is Empty"
  679. br.Ret = 408
  680. return
  681. }
  682. var req request.MoveExcelInfoReq
  683. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  684. if err != nil {
  685. br.Msg = "参数解析异常!"
  686. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  687. return
  688. }
  689. if req.ExcelInfoId <= 0 {
  690. br.Msg = "参数错误"
  691. br.ErrMsg = "表格id小于等于0"
  692. br.IsSendEmail = false
  693. return
  694. }
  695. if req.ExcelClassifyId <= 0 {
  696. br.Msg = "请选择分类"
  697. br.IsSendEmail = false
  698. return
  699. }
  700. //判断分类是否存在
  701. _, err = excel3.GetExcelClassifyById(req.ExcelClassifyId)
  702. if err != nil {
  703. br.Msg = "移动失败"
  704. br.ErrMsg = "获取分类信息失败" + err.Error()
  705. if err.Error() == utils.ErrNoRow() {
  706. br.Msg = "分类已被删除,不可移动,请刷新页面"
  707. br.ErrMsg = "分类已被删除,不可移动,请刷新页面"
  708. br.IsSendEmail = false
  709. }
  710. return
  711. }
  712. // 获取表格信息
  713. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  714. if err != nil {
  715. br.Msg = "移动失败"
  716. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  717. return
  718. }
  719. //如果改变了分类,那么移动该表格数据
  720. if excelInfo.ExcelClassifyId != req.ExcelClassifyId {
  721. //查询需要修改的分类下是否存在同一个表格名称
  722. tmpExcelInfo, tmpErr := excel3.GetExcelInfoByClassifyIdAndName(req.ExcelClassifyId, excelInfo.ExcelName)
  723. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  724. br.Msg = "移动失败"
  725. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  726. return
  727. }
  728. if tmpExcelInfo != nil {
  729. br.Msg = "移动失败,同一个分类下表格名称不允许重复"
  730. br.ErrMsg = "移动失败,同一个分类下表格名称不允许重复"
  731. br.IsSendEmail = false
  732. return
  733. }
  734. // 变更表格的所属分类
  735. excelInfo.ExcelClassifyId = req.ExcelClassifyId
  736. err = excelInfo.Update([]string{"ExcelClassifyId"})
  737. if err != nil {
  738. br.Msg = "移动失败"
  739. br.ErrMsg = "移动失败,Err:" + err.Error()
  740. return
  741. }
  742. }
  743. //移动排序
  744. updateCol := make([]string, 0)
  745. //如果有传入 上一个兄弟节点分类id
  746. if req.PrevExcelInfoId > 0 {
  747. prevExcelInfo, err := excel3.GetExcelInfoById(req.PrevExcelInfoId)
  748. if err != nil {
  749. br.Msg = "移动失败"
  750. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  751. return
  752. }
  753. //如果是移动在两个兄弟节点之间
  754. if req.NextExcelInfoId > 0 {
  755. //下一个兄弟节点
  756. nextExcelInfo, err := excel3.GetExcelInfoById(req.NextExcelInfoId)
  757. if err != nil {
  758. br.Msg = "移动失败"
  759. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  760. return
  761. }
  762. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  763. if prevExcelInfo.Sort == nextExcelInfo.Sort || prevExcelInfo.Sort == excelInfo.Sort {
  764. //变更兄弟节点的排序
  765. updateSortStr := `sort + 2`
  766. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
  767. } else {
  768. //如果下一个兄弟的排序权重正好是上个兄弟节点下一层,那么需要再加一层了
  769. if nextExcelInfo.Sort-prevExcelInfo.Sort == 1 {
  770. //变更兄弟节点的排序
  771. updateSortStr := `sort + 1`
  772. _ = excel3.UpdateExcelInfoSortByClassifyId(prevExcelInfo.ExcelClassifyId, prevExcelInfo.Sort, prevExcelInfo.ExcelInfoId, updateSortStr)
  773. }
  774. }
  775. }
  776. // 变更表格在当前分类下的排序
  777. excelInfo.Sort = prevExcelInfo.Sort + 1
  778. excelInfo.ModifyTime = time.Now()
  779. updateCol = append(updateCol, "Sort", "ModifyTime")
  780. } else {
  781. firstClassify, err := excel3.GetFirstExcelInfoByClassifyId(req.ExcelClassifyId)
  782. if err != nil && err.Error() != utils.ErrNoRow() {
  783. br.Msg = "移动失败"
  784. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  785. return
  786. }
  787. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  788. if firstClassify != nil && firstClassify.Sort == 0 {
  789. updateSortStr := ` sort + 1 `
  790. _ = excel3.UpdateExcelInfoSortByClassifyId(firstClassify.ExcelClassifyId, 0, firstClassify.ExcelInfoId-1, updateSortStr)
  791. }
  792. // 变更表格在当前分类下的排序
  793. excelInfo.Sort = 0 //那就是排在第一位
  794. excelInfo.ModifyTime = time.Now()
  795. updateCol = append(updateCol, "Sort", "ModifyTime")
  796. }
  797. //更新
  798. if len(updateCol) > 0 {
  799. err = excelInfo.Update(updateCol)
  800. if err != nil {
  801. br.Msg = "移动失败"
  802. br.ErrMsg = "修改失败,Err:" + err.Error()
  803. return
  804. }
  805. }
  806. if err != nil {
  807. br.Msg = "移动失败"
  808. br.ErrMsg = "修改失败,Err:" + err.Error()
  809. return
  810. }
  811. //新增操作日志
  812. //{
  813. // ExcelLog := new(data_manage.ExcelInfoLog)
  814. // ExcelLog.ExcelName = ExcelInfo.ExcelName
  815. // ExcelLog.ExcelInfoId = req.ExcelInfoId
  816. // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
  817. // ExcelLog.SysUserId = sysUser.AdminId
  818. // ExcelLog.SysUserRealName = sysUser.RealName
  819. // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
  820. // ExcelLog.CreateTime = time.Now()
  821. // ExcelLog.Content = string(c.Ctx.Input.RequestBody)
  822. // ExcelLog.Status = "移动表格"
  823. // ExcelLog.Method = c.Ctx.Input.URL()
  824. // go data_manage.AddExcelInfoLog(ExcelLog)
  825. //}
  826. br.Ret = 200
  827. br.Success = true
  828. br.IsAddLog = true
  829. br.Msg = "移动成功"
  830. }
  831. // Delete
  832. // @Title 删除表格接口
  833. // @Description 删除表格接口
  834. // @Param request body request.DeleteExcelInfoReq true "type json string"
  835. // @Success Ret=200 删除成功
  836. // @router /excel_info/delete [post]
  837. func (c *ExcelInfoController) Delete() {
  838. br := new(models.BaseResponse).Init()
  839. defer func() {
  840. c.Data["json"] = br
  841. c.ServeJSON()
  842. }()
  843. resp := response.AddExcelInfoResp{}
  844. sysUser := c.SysUser
  845. if sysUser == nil {
  846. br.Msg = "请登录"
  847. br.ErrMsg = "请登录,SysUser Is Empty"
  848. br.Ret = 408
  849. return
  850. }
  851. var req request.DeleteExcelInfoReq
  852. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  853. if err != nil {
  854. br.Msg = "参数解析异常!"
  855. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  856. return
  857. }
  858. if req.ExcelInfoId <= 0 {
  859. br.Msg = "参数错误"
  860. br.ErrMsg = "表格id小于等于0"
  861. br.IsSendEmail = false
  862. return
  863. }
  864. // 获取表格信息
  865. excelInfo, err := excel3.GetExcelInfoById(req.ExcelInfoId)
  866. if err != nil {
  867. br.Msg = "删除失败"
  868. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  869. return
  870. }
  871. // 删除excel
  872. err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
  873. if err != nil {
  874. br.Msg = "删除失败"
  875. if errMsg != `` {
  876. br.Msg = errMsg
  877. }
  878. br.ErrMsg = "删除失败,Err:" + err.Error()
  879. br.IsSendEmail = isSendEmail
  880. return
  881. }
  882. // 返回下一个表格的信息
  883. {
  884. var nextItem *excel3.ExcelInfo
  885. var condition string
  886. var pars []interface{}
  887. condition += " AND excel_classify_id=? "
  888. pars = append(pars, excelInfo.ExcelClassifyId)
  889. condition += " AND sort>=? "
  890. pars = append(pars, excelInfo.Sort)
  891. nextItem, err = excel3.GetNextExcelInfoByCondition(condition, pars)
  892. if err != nil && err.Error() != utils.ErrNoRow() {
  893. br.Msg = "删除失败"
  894. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  895. return
  896. }
  897. // 如果没找到,那么查找下一个分类的第一个表格
  898. if nextItem == nil {
  899. currClassifyInfo, err := excel3.GetExcelClassifyById(excelInfo.ExcelClassifyId)
  900. if err != nil && err.Error() != utils.ErrNoRow() {
  901. br.Msg = "删除失败"
  902. br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
  903. return
  904. }
  905. //condition += " AND level=3 "
  906. //pars = append(pars, chartInfo.ExcelClassifyId)
  907. //var condition string
  908. //var pars []interface{}
  909. //condition += " AND sort>=? ORDER BY excel_classify_id ASC LIMIT 1 "
  910. //pars = append(pars, currClassifyInfo.Sort)
  911. //
  912. //classifyItem, err := data_manage.GetNextExcelClassifyByCondition(condition, pars)
  913. //if err != nil && err.Error() != utils.ErrNoRow() {
  914. // br.Msg = "删除失败"
  915. // br.ErrMsg = "获取下一级表格分类信息失败,Err:" + err.Error()
  916. // return
  917. //}
  918. //if classifyItem != nil {
  919. // nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId,)
  920. // if err != nil && err.Error() != utils.ErrNoRow() {
  921. // br.Msg = "删除失败"
  922. // br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  923. // return
  924. // }
  925. //}
  926. nextItem, err = excel3.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
  927. if err != nil && err.Error() != utils.ErrNoRow() {
  928. br.Msg = "删除失败"
  929. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  930. return
  931. }
  932. }
  933. // 如果找到下一个表格了,那么就返回
  934. if nextItem != nil {
  935. resp = response.AddExcelInfoResp{
  936. ExcelInfoId: nextItem.ExcelInfoId,
  937. UniqueCode: nextItem.UniqueCode,
  938. }
  939. }
  940. }
  941. //删除公共图库那边的缓存
  942. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL)
  943. br.Ret = 200
  944. br.Success = true
  945. br.IsAddLog = true
  946. br.Data = resp
  947. br.Msg = "删除成功"
  948. }
  949. // AddDraft
  950. // @Title 新增表格草稿接口
  951. // @Description 新增表格草稿接口
  952. // @Param request body request.AddExcelDraftReq true "type json string"
  953. // @Success Ret=200 添加成功
  954. // @router /excel_info/draft/add [post]
  955. func (c *ExcelInfoController) AddDraft() {
  956. br := new(models.BaseResponse).Init()
  957. defer func() {
  958. c.Data["json"] = br
  959. c.ServeJSON()
  960. }()
  961. sysUser := c.SysUser
  962. if sysUser == nil {
  963. br.Msg = "请登录"
  964. br.ErrMsg = "请登录,SysUser Is Empty"
  965. br.Ret = 408
  966. return
  967. }
  968. var req request.AddExcelDraftReq
  969. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  970. if err != nil {
  971. br.Msg = "参数解析异常!"
  972. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  973. return
  974. }
  975. req.ExcelName = strings.Trim(req.ExcelName, " ")
  976. if req.ExcelName == "" {
  977. br.Msg = "请填写表格名称!"
  978. br.IsSendEmail = false
  979. return
  980. }
  981. if req.ExcelClassifyId <= 0 {
  982. br.Msg = "分类参数错误!"
  983. br.IsSendEmail = false
  984. return
  985. }
  986. excelClassify, err := excel3.GetExcelClassifyById(req.ExcelClassifyId)
  987. if err != nil {
  988. if err.Error() == utils.ErrNoRow() {
  989. br.Msg = "分类不存在"
  990. br.ErrMsg = "分类不存在"
  991. br.IsSendEmail = false
  992. return
  993. }
  994. br.Msg = "获取分类信息失败"
  995. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  996. return
  997. }
  998. if excelClassify == nil {
  999. br.Msg = "分类不存在"
  1000. br.ErrMsg = "分类不存在"
  1001. br.IsSendEmail = false
  1002. return
  1003. }
  1004. var condition string
  1005. var pars []interface{}
  1006. condition += " AND excel_classify_id=? "
  1007. pars = append(pars, req.ExcelClassifyId)
  1008. condition += " AND excel_name=? "
  1009. pars = append(pars, req.ExcelName)
  1010. // 获取分类下是否存在该表格名称
  1011. _, err = excel3.GetExcelInfoById(req.ExcelInfoId)
  1012. if err != nil {
  1013. br.Msg = "判断表格名称是否存在失败"
  1014. br.ErrMsg = "判断表格名称是否存在失败,Err:" + err.Error()
  1015. return
  1016. }
  1017. excelDraftInfo := &excel3.ExcelDraft{
  1018. //ExcelDraftId: 0,
  1019. ExcelId: req.ExcelInfoId,
  1020. Name: req.ExcelName,
  1021. Content: req.Content,
  1022. OpUserId: sysUser.AdminId,
  1023. OpUserName: sysUser.RealName,
  1024. CreateTime: time.Now(),
  1025. }
  1026. err = excel3.AddExcelDraft(excelDraftInfo)
  1027. if err != nil {
  1028. br.Msg = "保存失败"
  1029. br.ErrMsg = "保存失败,Err:" + err.Error()
  1030. return
  1031. }
  1032. _, err = services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, 1, sysUser.RealName)
  1033. if err != nil {
  1034. br.Msg = "查询标记状态失败"
  1035. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  1036. return
  1037. }
  1038. br.Ret = 200
  1039. br.Success = true
  1040. br.Msg = "添加成功"
  1041. }
  1042. // GetExcelTableData
  1043. // @Title 获取excel表格的table数据
  1044. // @Description 获取excel表格的table数据接口
  1045. // @Param UniqueCode query string true "表格code"
  1046. // @Success 200 {object} response.ExcelTableDetailResp
  1047. // @router /excel_info/table_data [get]
  1048. func (c *ExcelInfoController) GetExcelTableData() {
  1049. br := new(models.BaseResponse).Init()
  1050. defer func() {
  1051. c.Data["json"] = br
  1052. c.ServeJSON()
  1053. }()
  1054. sysUser := c.SysUser
  1055. if sysUser == nil {
  1056. br.Msg = "请登录"
  1057. br.ErrMsg = "请登录,SysUser Is Empty"
  1058. br.Ret = 408
  1059. return
  1060. }
  1061. uniqueCode := c.GetString("UniqueCode")
  1062. var err error
  1063. if uniqueCode == `` {
  1064. br.Msg = "请选择表格"
  1065. br.ErrMsg = "UniqueCode未传"
  1066. br.IsSendEmail = false
  1067. return
  1068. }
  1069. //获取eta表格信息
  1070. excelInfo, err := excel3.GetExcelInfoByUniqueCode(uniqueCode)
  1071. if err != nil {
  1072. br.Msg = "获取失败"
  1073. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  1074. if err.Error() == utils.ErrNoRow() {
  1075. br.Msg = "ETA表格被删除,请刷新页面"
  1076. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  1077. br.IsSendEmail = false
  1078. }
  1079. return
  1080. }
  1081. var tableData excel.TableData
  1082. switch excelInfo.Source {
  1083. case 1:
  1084. luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1085. if err != nil {
  1086. br.Msg = "获取失败"
  1087. br.ErrMsg = "获取excel数据失败,Err:" + err.Error()
  1088. return
  1089. }
  1090. tableData, err = luckySheetData.GetTableDataByLuckySheetDataStr(true)
  1091. if err != nil {
  1092. br.Msg = "获取失败"
  1093. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. case 2:
  1097. var tableDataConfig excel2.TableDataConfig
  1098. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  1099. if err != nil {
  1100. br.Msg = "获取失败"
  1101. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1102. return
  1103. }
  1104. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  1105. if err != nil {
  1106. br.Msg = "获取失败"
  1107. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  1108. return
  1109. }
  1110. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
  1111. if err != nil {
  1112. br.Msg = "获取失败"
  1113. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1114. return
  1115. }
  1116. case 3:
  1117. var result request.MixedTableReq
  1118. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  1119. if err != nil {
  1120. br.Msg = "获取失败"
  1121. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1122. return
  1123. }
  1124. newResult, tmpErr, tmpErrMsg := excel2.GetMixedTableCellData(result.CellRelation, result.Data)
  1125. if tmpErr != nil {
  1126. br.Msg = "获取失败"
  1127. if tmpErrMsg != `` {
  1128. br.Msg = tmpErrMsg
  1129. }
  1130. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  1131. return
  1132. }
  1133. tableData, err = excel.GetTableDataByMixedTableData(newResult)
  1134. if err != nil {
  1135. br.Msg = "获取失败"
  1136. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1137. return
  1138. }
  1139. }
  1140. tableData = excel.HandleTableCell(tableData)
  1141. resp := response.ExcelTableDetailResp{
  1142. UniqueCode: excelInfo.UniqueCode,
  1143. ExcelImage: excelInfo.ExcelImage,
  1144. ExcelName: excelInfo.ExcelName,
  1145. TableInfo: tableData,
  1146. }
  1147. br.Ret = 200
  1148. br.Success = true
  1149. br.Msg = "获取成功"
  1150. br.Data = resp
  1151. }
  1152. //func init() {
  1153. //
  1154. // excelInfo, err := data_manage.GetExcelInfoById(52)
  1155. // if err != nil {
  1156. // fmt.Println("err:", err)
  1157. // return
  1158. // }
  1159. //
  1160. // luckySheetData, err := excel.GetLuckySheetData(excelInfo.Content)
  1161. // if err != nil {
  1162. // fmt.Println("err:", err)
  1163. // return
  1164. // }
  1165. // //_, err = luckySheetData.GetTableDataByLuckySheetDataStr()
  1166. // downloadFilePath, err := luckySheetData.ToExcel()
  1167. // if err != nil {
  1168. // fmt.Println("err:", err)
  1169. // return
  1170. // }
  1171. // fmt.Println(downloadFilePath)
  1172. //
  1173. // //fmt.Println(excel.GetColumnName(988, 283))
  1174. //}
  1175. // Calculate
  1176. // @Title 公式计算接口
  1177. // @Description 公式计算接口
  1178. // @Param request body request.CalculateReq true "type json string"
  1179. // @router /excel_info/table/calculate [post]
  1180. func (c *ExcelInfoController) Calculate() {
  1181. br := new(models.BaseResponse).Init()
  1182. defer func() {
  1183. c.Data["json"] = br
  1184. c.ServeJSON()
  1185. }()
  1186. sysUser := c.SysUser
  1187. if sysUser == nil {
  1188. br.Msg = "请登录"
  1189. br.ErrMsg = "请登录,SysUser Is Empty"
  1190. br.Ret = 408
  1191. return
  1192. }
  1193. var req request.CalculateReq
  1194. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1195. if err != nil {
  1196. br.Msg = "参数解析异常!"
  1197. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1198. return
  1199. }
  1200. if req.CalculateFormula == "" {
  1201. br.Msg = "请填写公式"
  1202. return
  1203. }
  1204. calculateFormula := req.CalculateFormula
  1205. calculateFormula = strings.TrimPrefix(calculateFormula, "=")
  1206. calculateFormula = strings.Replace(calculateFormula, "(", "(", -1)
  1207. calculateFormula = strings.Replace(calculateFormula, ")", ")", -1)
  1208. calculateFormula = strings.Replace(calculateFormula, ",", ",", -1)
  1209. calculateFormula = strings.Replace(calculateFormula, "。", ".", -1)
  1210. calculateFormula = strings.Replace(calculateFormula, "%", "*0.01", -1)
  1211. formulaFormStr := utils.ReplaceFormula(req.TagMap, calculateFormula)
  1212. //计算公式异常,那么就移除该指标
  1213. if formulaFormStr == `` {
  1214. //removeDateList = append(removeDateList, sk)
  1215. //fmt.Println("异常了")
  1216. br.Msg = "公式异常"
  1217. br.ErrMsg = "公式异常"
  1218. return
  1219. }
  1220. expression := formula.NewExpression(formulaFormStr)
  1221. calResult, err := expression.Evaluate()
  1222. if err != nil {
  1223. br.Msg = "计算失败"
  1224. br.ErrMsg = "计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1225. // 分母为0的报错
  1226. if strings.Contains(err.Error(), "divide by zero") {
  1227. br.Msg = "分母不能为0"
  1228. br.ErrMsg = "分母不能为空,计算公式:" + formulaFormStr
  1229. br.IsSendEmail = false
  1230. }
  1231. return
  1232. }
  1233. // 如果计算结果是NAN,那么就提示报错
  1234. if calResult.IsNan() {
  1235. br.Msg = "计算失败"
  1236. br.ErrMsg = "计算失败:计算结果是:NAN;formulaStr:" + formulaFormStr
  1237. return
  1238. }
  1239. // 计算结果格式化
  1240. calFloat, e := calResult.Float64()
  1241. if e != nil {
  1242. br.Msg = "计算失败"
  1243. br.ErrMsg = "计算失败, Err: " + e.Error()
  1244. return
  1245. }
  1246. calVal := utils.FormatTableDataShowValue(calFloat)
  1247. //calVal := calResult.String()
  1248. //if err != nil {
  1249. // br.Msg = "计算失败"
  1250. // br.ErrMsg = "计算失败,结果转 string 失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr
  1251. // return
  1252. //}
  1253. br.Ret = 200
  1254. br.Success = true
  1255. br.Msg = "计算成功"
  1256. br.Data = calVal
  1257. }
  1258. // GetFirstEdbData
  1259. // @Title 获取未来日期数据接口
  1260. // @Description 获取未来日期数据接口
  1261. // @Param EdbInfoId query int true "指标id"
  1262. // @Param Num query int true "默认期数"
  1263. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒序`,不传默认倒序"
  1264. // @router /excel_info/table/first_edb_data_list [get]
  1265. func (c *ExcelInfoController) GetFirstEdbData() {
  1266. br := new(models.BaseResponse).Init()
  1267. defer func() {
  1268. c.Data["json"] = br
  1269. c.ServeJSON()
  1270. }()
  1271. sysUser := c.SysUser
  1272. if sysUser == nil {
  1273. br.Msg = "请登录"
  1274. br.ErrMsg = "请登录,SysUser Is Empty"
  1275. br.Ret = 408
  1276. return
  1277. }
  1278. edbInfoId, _ := c.GetInt("EdbInfoId")
  1279. num, _ := c.GetInt("Num")
  1280. sortType := c.GetString("SortType")
  1281. if edbInfoId <= 0 {
  1282. br.Msg = "请选择指标"
  1283. br.IsSendEmail = false
  1284. return
  1285. }
  1286. if num <= 0 {
  1287. br.Msg = "期数必须大于0"
  1288. br.IsSendEmail = false
  1289. return
  1290. }
  1291. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1292. if err != nil {
  1293. br.Msg = "获取失败"
  1294. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1295. return
  1296. }
  1297. dataList, err := excel2.GetFirstEdbDataList(edbInfo, num, []string{})
  1298. if err != nil {
  1299. br.Msg = "获取失败"
  1300. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1301. return
  1302. }
  1303. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1304. if sortType == "asc" {
  1305. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1306. dataList[i], dataList[j] = dataList[j], dataList[i]
  1307. }
  1308. }
  1309. br.Ret = 200
  1310. br.Success = true
  1311. br.Msg = "获取成功"
  1312. br.Data = response.TableDataItem{
  1313. EdbInfoId: edbInfoId,
  1314. Data: dataList,
  1315. }
  1316. }
  1317. // GetOtherEdbData
  1318. // @Title 获取指定日期数据接口
  1319. // @Description 获取未来日期数据接口
  1320. // @Param request body request.GetOtherEdbDateDataReq true "type json string"
  1321. // @router /excel_info/table/other_edb_data_list [post]
  1322. func (c *ExcelInfoController) GetOtherEdbData() {
  1323. br := new(models.BaseResponse).Init()
  1324. defer func() {
  1325. c.Data["json"] = br
  1326. c.ServeJSON()
  1327. }()
  1328. sysUser := c.SysUser
  1329. if sysUser == nil {
  1330. br.Msg = "请登录"
  1331. br.ErrMsg = "请登录,SysUser Is Empty"
  1332. br.Ret = 408
  1333. return
  1334. }
  1335. var req request.GetOtherEdbDateDataReq
  1336. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1337. if err != nil {
  1338. br.Msg = "参数解析异常!"
  1339. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1340. return
  1341. }
  1342. if req.EdbInfoId <= 0 {
  1343. br.Msg = "请选择指标"
  1344. br.IsSendEmail = false
  1345. return
  1346. }
  1347. if len(req.DateList) <= 0 {
  1348. br.Msg = "请选择日期"
  1349. br.IsSendEmail = false
  1350. return
  1351. }
  1352. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1353. if err != nil {
  1354. br.Msg = "获取失败"
  1355. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  1356. return
  1357. }
  1358. dataList, err := excel2.GetOtherEdbDataList(edbInfo, req.DateList)
  1359. if err != nil {
  1360. br.Msg = "获取失败"
  1361. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1362. return
  1363. }
  1364. // 默认是倒序返回的数据,如果要正序的话,那么翻转下就好了
  1365. if req.SortType == "asc" {
  1366. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  1367. dataList[i], dataList[j] = dataList[j], dataList[i]
  1368. }
  1369. }
  1370. br.Ret = 200
  1371. br.Success = true
  1372. br.Msg = "获取成功"
  1373. br.Data = response.TableDataItem{
  1374. EdbInfoId: req.EdbInfoId,
  1375. Data: dataList,
  1376. }
  1377. }
  1378. // GetFutureDateData
  1379. // @Title 获取未来日期数据接口
  1380. // @Description 获取未来日期数据接口
  1381. // @Param request body request.GetFutureDateDataReq true "type json string"
  1382. // @router /excel_info/table/future_date_list [post]
  1383. func (c *ExcelInfoController) GetFutureDateData() {
  1384. br := new(models.BaseResponse).Init()
  1385. defer func() {
  1386. c.Data["json"] = br
  1387. c.ServeJSON()
  1388. }()
  1389. sysUser := c.SysUser
  1390. if sysUser == nil {
  1391. br.Msg = "请登录"
  1392. br.ErrMsg = "请登录,SysUser Is Empty"
  1393. br.Ret = 408
  1394. return
  1395. }
  1396. var req request.GetFutureDateDataReq
  1397. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1398. if err != nil {
  1399. br.Msg = "参数解析异常!"
  1400. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1401. return
  1402. }
  1403. if req.StartDate == `` {
  1404. br.Msg = "开始日期未传"
  1405. br.IsSendEmail = false
  1406. return
  1407. }
  1408. startDate, err := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
  1409. if err != nil {
  1410. br.Msg = "开始日期异常"
  1411. br.ErrMsg = fmt.Sprint("开始日期异常,startDate:", req.StartDate, ";err:", err.Error())
  1412. return
  1413. }
  1414. if len(req.EdbInfoIdList) <= 0 {
  1415. br.Msg = "请选择指标"
  1416. br.IsSendEmail = false
  1417. return
  1418. }
  1419. baseEdbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoIdList[0])
  1420. if err != nil {
  1421. br.Msg = "查找指标失败"
  1422. br.Msg = "查找指标失败,err:" + err.Error()
  1423. return
  1424. }
  1425. // 第一个指标的数据列表
  1426. var firstEdbDataList []*data_manage.EdbDataList
  1427. {
  1428. switch baseEdbInfo.EdbInfoType {
  1429. case 0:
  1430. firstEdbDataList, err = data_manage.GetEdbDataList(baseEdbInfo.Source, baseEdbInfo.EdbInfoId, req.StartDate, ``)
  1431. case 1:
  1432. _, firstEdbDataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(baseEdbInfo.EdbInfoId, req.StartDate, ``, false)
  1433. default:
  1434. br.Msg = "指标类型异常"
  1435. br.ErrMsg = fmt.Sprint("获取失败,指标类型异常", baseEdbInfo.EdbInfoType)
  1436. br.IsSendEmail = false
  1437. return
  1438. }
  1439. }
  1440. dateList := make([]time.Time, 0)
  1441. if req.DateType == 1 {
  1442. num := req.Num
  1443. i := 0 // 数据中有的日期数
  1444. for _, v := range firstEdbDataList {
  1445. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1446. if err != nil {
  1447. br.Msg = "结束日期异常"
  1448. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1449. return
  1450. }
  1451. if tmpDate.After(startDate) {
  1452. dateList = append(dateList, tmpDate)
  1453. startDate = tmpDate
  1454. i++
  1455. }
  1456. if i >= num {
  1457. break
  1458. }
  1459. }
  1460. num = num - i
  1461. if num > 0 {
  1462. tmpDateList := utils.GetPredictEdbDayListByNum(startDate, num, baseEdbInfo.Frequency)
  1463. dateList = append(dateList, tmpDateList...)
  1464. }
  1465. } else {
  1466. if req.EndDate == `` {
  1467. br.Msg = "结束日期未传"
  1468. br.IsSendEmail = false
  1469. return
  1470. }
  1471. endDate, err := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
  1472. if err != nil {
  1473. br.Msg = "结束日期异常"
  1474. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1475. return
  1476. }
  1477. for _, v := range firstEdbDataList {
  1478. tmpDate, err := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1479. if err != nil {
  1480. br.Msg = "结束日期异常"
  1481. br.ErrMsg = fmt.Sprint("结束日期异常,startDate:", req.EndDate, ";err:", err.Error())
  1482. return
  1483. }
  1484. if tmpDate.Equal(endDate) || (tmpDate.Before(endDate) && tmpDate.After(startDate)) {
  1485. dateList = append(dateList, tmpDate)
  1486. startDate = tmpDate
  1487. }
  1488. }
  1489. if startDate.Before(endDate) {
  1490. tmpDateList := utils.GetPredictEdbDayListByEndDate(startDate, endDate, baseEdbInfo.Frequency)
  1491. dateList = append(dateList, tmpDateList...)
  1492. }
  1493. }
  1494. // 获取所有的指标信息
  1495. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1496. {
  1497. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  1498. if err != nil {
  1499. br.Msg = "获取指标信息失败"
  1500. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1501. return
  1502. }
  1503. for _, v := range edbInfoList {
  1504. edbInfoMap[v.EdbInfoId] = v
  1505. }
  1506. }
  1507. result := make([]response.TableDataItem, 0)
  1508. dateStrList := make([]string, 0)
  1509. lenDate := len(dateList)
  1510. if lenDate > 0 {
  1511. for i := lenDate - 1; i >= 0; i-- {
  1512. dateStrList = append(dateStrList, dateList[i].Format(utils.FormatDate))
  1513. }
  1514. for _, v := range req.EdbInfoIdList {
  1515. tmpEdbInfo, ok := edbInfoMap[v]
  1516. if !ok {
  1517. br.Msg = "获取指标信息失败"
  1518. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1519. return
  1520. }
  1521. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
  1522. if err != nil {
  1523. br.Msg = "获取失败"
  1524. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1525. return
  1526. }
  1527. result = append(result, response.TableDataItem{
  1528. EdbInfoId: v,
  1529. Data: dataList,
  1530. })
  1531. }
  1532. }
  1533. br.Ret = 200
  1534. br.Success = true
  1535. br.Msg = "获取成功"
  1536. br.Data = result
  1537. }
  1538. // GetHistoryDateData
  1539. // @Title 获取历史日期数据接口
  1540. // @Description 获取历史日期数据接口
  1541. // @Param request body request.GetFutureDateDataReq true "type json string"
  1542. // @router /excel_info/table/history_date_list [post]
  1543. func (c *ExcelInfoController) GetHistoryDateData() {
  1544. br := new(models.BaseResponse).Init()
  1545. defer func() {
  1546. c.Data["json"] = br
  1547. c.ServeJSON()
  1548. }()
  1549. sysUser := c.SysUser
  1550. if sysUser == nil {
  1551. br.Msg = "请登录"
  1552. br.ErrMsg = "请登录,SysUser Is Empty"
  1553. br.Ret = 408
  1554. return
  1555. }
  1556. var req request.GetHistoryDateDataReq
  1557. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1558. if err != nil {
  1559. br.Msg = "参数解析异常!"
  1560. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1561. return
  1562. }
  1563. if req.EndDate == `` {
  1564. br.Msg = "结束日期未传"
  1565. br.IsSendEmail = false
  1566. return
  1567. }
  1568. if len(req.EdbInfoIdList) <= 0 {
  1569. br.Msg = "请选择指标"
  1570. br.IsSendEmail = false
  1571. return
  1572. }
  1573. // 获取所有的指标信息
  1574. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1575. {
  1576. edbInfoList, err := data_manage.GetEdbInfoByIdList(req.EdbInfoIdList)
  1577. if err != nil {
  1578. br.Msg = "获取指标信息失败"
  1579. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1580. return
  1581. }
  1582. for _, v := range edbInfoList {
  1583. edbInfoMap[v.EdbInfoId] = v
  1584. }
  1585. }
  1586. result := make([]response.TableDataItem, 0)
  1587. dateStrList := make([]string, 0)
  1588. // 获取A列指标的历史数据
  1589. {
  1590. tmpEdbInfo, ok := edbInfoMap[req.EdbInfoIdList[0]]
  1591. if !ok {
  1592. br.Msg = "获取指标信息失败"
  1593. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1594. return
  1595. }
  1596. firstDataList, err := excel2.GetFirstHistoryEdbDataList(tmpEdbInfo, req.Num, req.EndDate)
  1597. if err != nil {
  1598. br.Msg = "获取失败"
  1599. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1600. return
  1601. }
  1602. result = append(result, response.TableDataItem{
  1603. EdbInfoId: req.EdbInfoIdList[0],
  1604. Data: firstDataList,
  1605. })
  1606. for _, v := range firstDataList {
  1607. dateStrList = append(dateStrList, v.DataTime)
  1608. }
  1609. }
  1610. if len(dateStrList) > 0 {
  1611. for k, v := range req.EdbInfoIdList {
  1612. if k == 0 {
  1613. continue
  1614. }
  1615. tmpEdbInfo, ok := edbInfoMap[v]
  1616. if !ok {
  1617. br.Msg = "获取指标信息失败"
  1618. br.ErrMsg = "获取指标信息失败,err:" + err.Error()
  1619. return
  1620. }
  1621. dataList, err := excel2.GetOtherEdbDataList(tmpEdbInfo, dateStrList)
  1622. if err != nil {
  1623. br.Msg = "获取失败"
  1624. br.ErrMsg = fmt.Sprint("获取失败,Err:", err.Error())
  1625. return
  1626. }
  1627. result = append(result, response.TableDataItem{
  1628. EdbInfoId: v,
  1629. Data: dataList,
  1630. })
  1631. }
  1632. }
  1633. br.Ret = 200
  1634. br.Success = true
  1635. br.Msg = "获取成功"
  1636. br.Data = result
  1637. }
  1638. // Refresh
  1639. // @Title 刷新
  1640. // @Description 刷新接口
  1641. // @Param ExcelInfoId query int true "表格id"
  1642. // @router /excel_info/table/refresh [get]
  1643. func (c *ExcelInfoController) Refresh() {
  1644. br := new(models.BaseResponse).Init()
  1645. defer func() {
  1646. c.Data["json"] = br
  1647. c.ServeJSON()
  1648. }()
  1649. sysUser := c.SysUser
  1650. if sysUser == nil {
  1651. br.Msg = "请登录"
  1652. br.ErrMsg = "请登录,SysUser Is Empty"
  1653. br.Ret = 408
  1654. return
  1655. }
  1656. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1657. if excelInfoId <= 0 {
  1658. br.Msg = "请选择表格"
  1659. br.ErrMsg = "ExcelInfoId未传"
  1660. br.IsSendEmail = false
  1661. return
  1662. }
  1663. // 获取数据详情
  1664. excelDetail, errMsg, err := excel2.GetExcelDetailInfoByExcelInfoId(excelInfoId)
  1665. if err != nil {
  1666. br.Msg = errMsg
  1667. br.ErrMsg = err.Error()
  1668. return
  1669. }
  1670. // 操作权限校验
  1671. {
  1672. button := excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source)
  1673. if !button.RefreshButton {
  1674. br.Msg = "无操作权限"
  1675. br.Msg = "无操作权限"
  1676. br.IsSendEmail = false
  1677. return
  1678. }
  1679. }
  1680. // 数据刷新(只有自定义表格有刷新)
  1681. if excelDetail.Source == 2 {
  1682. jsonStrByte, err := json.Marshal(excelDetail.TableData)
  1683. if err != nil {
  1684. br.Msg = "自定义表格数据获取失败"
  1685. br.ErrMsg = "自定义表格数据获取失败,转json失败,Err:" + err.Error()
  1686. return
  1687. }
  1688. var tableData request.TableDataReq
  1689. err = json.Unmarshal(jsonStrByte, &tableData)
  1690. if err != nil {
  1691. br.Msg = "自定义表格数据获取失败"
  1692. br.ErrMsg = "自定义表格数据获取失败,json转结构体失败,Err:" + err.Error()
  1693. return
  1694. }
  1695. if len(tableData.EdbInfoIdList) > 0 {
  1696. err, _ = data.EdbInfoRefreshAllFromBaseV3(tableData.EdbInfoIdList, false, true)
  1697. if err != nil {
  1698. br.Msg = "刷新失败"
  1699. br.ErrMsg = "刷新失败,Err:" + err.Error()
  1700. return
  1701. }
  1702. }
  1703. }
  1704. br.Ret = 200
  1705. br.Success = true
  1706. br.Msg = "刷新成功"
  1707. }
  1708. // Download
  1709. // @Title 获取表格详情
  1710. // @Description 获取表格详情接口
  1711. // @Param UniqueCode query string true "表格code"
  1712. // @Param ExcelInfoId query int true "表格id"
  1713. // @Success 200 {object} data_manage.ExcelInfo
  1714. // @router /excel_info/table/download [get]
  1715. func (c *ExcelInfoController) Download() {
  1716. br := new(models.BaseResponse).Init()
  1717. defer func() {
  1718. c.Data["json"] = br
  1719. c.ServeJSON()
  1720. }()
  1721. sysUser := c.SysUser
  1722. if sysUser == nil {
  1723. br.Msg = "请登录"
  1724. br.ErrMsg = "请登录,SysUser Is Empty"
  1725. br.Ret = 408
  1726. return
  1727. }
  1728. excelInfoId, _ := c.GetInt("ExcelInfoId")
  1729. uniqueCode := c.GetString("UniqueCode")
  1730. if excelInfoId <= 0 && uniqueCode == `` {
  1731. br.Msg = "请选择表格"
  1732. br.ErrMsg = "ExcelInfoId和UniqueCode都未传"
  1733. br.IsSendEmail = false
  1734. return
  1735. }
  1736. var excelInfo *excel3.ExcelInfo
  1737. var err error
  1738. //获取eta表格信息
  1739. if excelInfoId > 0 {
  1740. excelInfo, err = excel3.GetExcelInfoById(excelInfoId)
  1741. } else {
  1742. excelInfo, err = excel3.GetExcelInfoByUniqueCode(uniqueCode)
  1743. }
  1744. if err != nil {
  1745. br.Msg = "获取失败"
  1746. br.ErrMsg = "获取ETA表格信息失败,Err:" + err.Error()
  1747. if err.Error() == utils.ErrNoRow() {
  1748. br.Msg = "ETA表格被删除,请刷新页面"
  1749. br.ErrMsg = "ETA表格被删除,请刷新页面,Err:" + err.Error()
  1750. br.IsSendEmail = false
  1751. }
  1752. return
  1753. }
  1754. if excelInfo.Source == 1 {
  1755. br.Msg = "不是自定义表格"
  1756. br.IsSendEmail = false
  1757. return
  1758. }
  1759. var tableData excel.TableData
  1760. switch excelInfo.Source {
  1761. case 1:
  1762. br.Msg = "表格类型异常"
  1763. case 2: // 自定义表格
  1764. var tableDataConfig excel2.TableDataConfig
  1765. err = json.Unmarshal([]byte(excelInfo.Content), &tableDataConfig)
  1766. if err != nil {
  1767. br.Msg = "获取失败"
  1768. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1769. return
  1770. }
  1771. result, err := excel2.GetDataByTableDataConfig(tableDataConfig)
  1772. if err != nil {
  1773. br.Msg = "获取失败"
  1774. br.ErrMsg = "获取最新的表格数据失败,Err:" + err.Error()
  1775. return
  1776. }
  1777. tableData, err = excel.GetTableDataByCustomData(excelInfo.ExcelType, result)
  1778. if err != nil {
  1779. br.Msg = "获取失败"
  1780. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1781. return
  1782. }
  1783. case 3: // 混合表格
  1784. var result request.MixedTableReq
  1785. err = json.Unmarshal([]byte(excelInfo.Content), &result)
  1786. if err != nil {
  1787. br.Msg = "获取失败"
  1788. br.ErrMsg = "表格json转结构体失败,Err:" + err.Error()
  1789. return
  1790. }
  1791. newResult, tmpErr, tmpErrMsg := excel2.GetMixedTableCellData(result.CellRelation, result.Data)
  1792. if tmpErr != nil {
  1793. br.Msg = "获取失败"
  1794. if tmpErrMsg != `` {
  1795. br.Msg = tmpErrMsg
  1796. }
  1797. br.ErrMsg = "获取最新的数据失败,Err:" + err.Error()
  1798. return
  1799. }
  1800. tableData, err = excel.GetTableDataByMixedTableData(newResult)
  1801. if err != nil {
  1802. br.Msg = "获取失败"
  1803. br.ErrMsg = "转换成table失败,Err:" + err.Error()
  1804. return
  1805. }
  1806. }
  1807. downloadFilePath, err := tableData.ToExcel()
  1808. if err != nil {
  1809. fmt.Println("err:", err)
  1810. return
  1811. }
  1812. defer func() {
  1813. _ = os.Remove(downloadFilePath)
  1814. }()
  1815. downloadFileName := excelInfo.ExcelName + ".xlsx"
  1816. c.Ctx.Output.Download(downloadFilePath, downloadFileName)
  1817. br.Ret = 200
  1818. br.Success = true
  1819. br.Msg = "获取成功"
  1820. br.Data = excelInfo
  1821. }
  1822. // Copy
  1823. // @Title 复制表格
  1824. // @Description 复制表格接口
  1825. // @Param request body request.EditExcelInfoReq true "type json string"
  1826. // @Success 200 {object} response.AddExcelInfoResp
  1827. // @router /excel_info/copy [post]
  1828. func (c *ExcelInfoController) Copy() {
  1829. br := new(models.BaseResponse).Init()
  1830. defer func() {
  1831. c.Data["json"] = br
  1832. c.ServeJSON()
  1833. }()
  1834. sysUser := c.SysUser
  1835. if sysUser == nil {
  1836. br.Msg = "请登录"
  1837. br.ErrMsg = "请登录,SysUser Is Empty"
  1838. br.Ret = 408
  1839. return
  1840. }
  1841. var req request.CopyExcelInfoReq
  1842. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1843. if err != nil {
  1844. br.Msg = "参数解析异常!"
  1845. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1846. return
  1847. }
  1848. if req.ExcelInfoId <= 0 {
  1849. br.Msg = "请传入ETA表格标识!"
  1850. return
  1851. }
  1852. cacheKey := "CACHE_TABLE_INFO_EDIT_" + strconv.Itoa(req.ExcelInfoId)
  1853. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1854. br.Msg = "系统处理中,请稍后重试!"
  1855. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  1856. return
  1857. }
  1858. defer func() {
  1859. _ = utils.Rc.Delete(cacheKey)
  1860. }()
  1861. req.ExcelName = strings.Trim(req.ExcelName, " ")
  1862. if req.ExcelName == "" {
  1863. br.Msg = "请填写表格名称!"
  1864. br.IsSendEmail = false
  1865. return
  1866. }
  1867. if req.ExcelClassifyId <= 0 {
  1868. br.Msg = "分类参数错误!"
  1869. br.IsSendEmail = false
  1870. return
  1871. }
  1872. excelInfo, err, errMsg, isSendEmail := excel2.Copy(req.ExcelInfoId, req.ExcelClassifyId, req.ExcelName, sysUser)
  1873. if err != nil {
  1874. br.Msg = "复制失败"
  1875. if errMsg != `` {
  1876. br.Msg = errMsg
  1877. }
  1878. br.ErrMsg = "复制失败,Err:" + err.Error()
  1879. br.IsSendEmail = isSendEmail
  1880. return
  1881. }
  1882. resp := new(response.AddExcelInfoResp)
  1883. resp.ExcelInfoId = excelInfo.ExcelInfoId
  1884. resp.UniqueCode = excelInfo.UniqueCode
  1885. br.Ret = 200
  1886. br.Success = true
  1887. br.Msg = "保存成功"
  1888. br.Data = resp
  1889. br.IsAddLog = true
  1890. }
  1891. // GetSystemDate
  1892. // @Title 获取系统日期(包含计算日期)
  1893. // @Description 获取系统日期(包含计算日期)
  1894. // @Param request body request.MixedTableCellDataReq true "type json string"
  1895. // @router /excel_info/get_system_date [post]
  1896. func (c *ExcelInfoController) GetSystemDate() {
  1897. br := new(models.BaseResponse).Init()
  1898. defer func() {
  1899. c.Data["json"] = br
  1900. c.ServeJSON()
  1901. }()
  1902. sysUser := c.SysUser
  1903. if sysUser == nil {
  1904. br.Msg = "请登录"
  1905. br.ErrMsg = "请登录,SysUser Is Empty"
  1906. br.Ret = 408
  1907. return
  1908. }
  1909. var req request.MixedTableCellDataReq
  1910. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1911. if err != nil {
  1912. br.Msg = "参数解析异常!"
  1913. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1914. return
  1915. }
  1916. date, err, errMsg := excel2.HandleDate(req.DataTimeType, req.Value)
  1917. if err != nil {
  1918. br.Msg = "获取系统日期失败"
  1919. if errMsg != `` {
  1920. br.Msg = errMsg
  1921. }
  1922. br.ErrMsg = "获取系统日期失败,Err:" + err.Error()
  1923. return
  1924. }
  1925. type resp struct {
  1926. Date string
  1927. }
  1928. br.Ret = 200
  1929. br.Success = true
  1930. br.Msg = "获取系统日期成功"
  1931. br.Data = resp{
  1932. Date: date,
  1933. }
  1934. }
  1935. //func init() {
  1936. // //list, err := data.GetFirstEdbDataList(102739, 12)
  1937. // list, err := data.GetFirstEdbDataList(101323, 12)
  1938. // if err != nil {
  1939. // fmt.Println(err)
  1940. // return
  1941. // }
  1942. //
  1943. // fmt.Println("START")
  1944. // dateList := make([]string, 0)
  1945. // for _, v := range list {
  1946. // fmt.Println(v)
  1947. // dateList = append(dateList, v.DataTime)
  1948. // }
  1949. //
  1950. // fmt.Println("End")
  1951. //
  1952. // {
  1953. // list, err := data.GetOtherEdbDataList(102227, dateList)
  1954. // if err != nil {
  1955. // fmt.Println(err)
  1956. // return
  1957. // }
  1958. //
  1959. // for _, v := range list {
  1960. // fmt.Println(v)
  1961. // }
  1962. // }
  1963. //}
  1964. //func init() {
  1965. // str := `{"EdbInfoIdList":[101323,102227],"Sort":1,"Data":[{"EdbInfoId":101323,"Tag":"A","Data":[{"DataType":4,"DataTime":"2023-06-10","DataTimeType":4,"ShowValue":"318.2726","Value":"=A2-B2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":3,"DataTime":"2023-06-09","DataTimeType":2,"ShowValue":"15","Value":"15","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-07","DataTimeType":1,"ShowValue":"16.43","Value":"16.43","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-05","DataTimeType":1,"ShowValue":"16.85","Value":"16.85","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-02","DataTimeType":1,"ShowValue":"15.88","Value":"15.88","RelationEdbInfoList":[]}]},{"EdbInfoId":102227,"Tag":"B","Data":[{"DataType":4,"DataTime":"2023-06-10","DataTimeType":1,"ShowValue":"318.2726","Value":"=A2+B2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":1,"DataTime":"2023-06-09","DataTimeType":1,"ShowValue":"318.2726","Value":"318.2726","RelationEdbInfoList":[]},{"DataType":2,"DataTime":"2023-06-07","DataTimeType":1,"ShowValue":"100.43","Value":"100.43","RelationEdbInfoList":[]},{"DataType":2,"DataTime":"2023-06-05","DataTimeType":1,"ShowValue":"102.85","Value":"102.85","RelationEdbInfoList":[]},{"DataType":1,"DataTime":"2023-06-02","DataTimeType":1,"ShowValue":"311.5201","Value":"311.5201","RelationEdbInfoList":[]}]}],"TextRowData":[[{"DataType":3,"DataTime":"","ShowValue":"总计","Value":"总计"},{"DataType":4,"DataTime":"","ShowValue":"0","Value":"=A3+B3","RelationEdbInfoList":[{"Tag":"A","Row":"3"},{"Tag":"B","Row":"3"}]},{"DataType":3,"DataTime":"","ShowValue":"","Value":"","RelationEdbInfoList":[]}],[{"DataType":3,"DataTime":"","ShowValue":"垃圾汇总","Value":"垃圾汇总"},{"DataType":4,"DataTime":"","ShowValue":"0","Value":"=A4+B4","RelationEdbInfoList":[{"Tag":"A","Row":"4"},{"Tag":"B","Row":"4"}]},{"DataType":3,"DataTime":"","ShowValue":"这里是文本文案","Value":"这里是文本文案","RelationEdbInfoList":[]}]]}`
  1966. // str = `{"EdbInfoIdList":[102942,102938,102937],"Sort":1,"Data":[],"Num":12,"RemoveDate":["2023-06-05","2023-06-08"],"ManualDate":null,"TableEdbInfoList":[{"EdbInfoId":102942,"Tag":"A","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""},{"EdbInfoId":102938,"Tag":"B","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""},{"EdbInfoId":102937,"Tag":"C","EdbName":"","EdbAliasName":"","Frequency":"","Unit":""}],"TextRowData":[[{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"dwd","Value":"dwd","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"4454","Value":"4454","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"454","Value":"454","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"51","Value":"51","RelationEdbInfoList":[]}],[{"DataType":4,"DataTime":"","DataTimeType":0,"ShowValue":"a1b1","Value":"=a1+b1","RelationEdbInfoList":[{"Tag":"A","Row":"1"},{"Tag":"B","Row":"1"}]},{"DataType":4,"DataTime":"","DataTimeType":0,"ShowValue":"2247.1444","Value":"=a2+b2","RelationEdbInfoList":[{"Tag":"A","Row":"2"},{"Tag":"B","Row":"2"}]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"","Value":"","RelationEdbInfoList":[]},{"DataType":3,"DataTime":"","DataTimeType":0,"ShowValue":"","Value":"","RelationEdbInfoList":[]}]]}`
  1967. //
  1968. // //var req request.TableDataReq
  1969. // //err := json.Unmarshal([]byte(str), &req)
  1970. // //if err != nil {
  1971. // // fmt.Println(err)
  1972. // // return
  1973. // //}
  1974. // //tableDataConfig, err := data.GetTableDataConfig(req)
  1975. // //if err != nil {
  1976. // // fmt.Println(err)
  1977. // // return
  1978. // //}
  1979. // var tableDataConfig data.TableDataConfig
  1980. // err := json.Unmarshal([]byte(str), &tableDataConfig)
  1981. // if err != nil {
  1982. // fmt.Println(err)
  1983. // return
  1984. // }
  1985. //
  1986. // fmt.Println(tableDataConfig)
  1987. //
  1988. // result, err := data.GetDataByTableDataConfig(tableDataConfig)
  1989. // if err != nil {
  1990. // fmt.Println(err)
  1991. // return
  1992. // }
  1993. // fmt.Println(result)
  1994. // //byteStr, _ := json.Marshal(result)
  1995. // //utils.FileLog.Info(string(byteStr))
  1996. //}
  1997. //func init() {
  1998. // startNow := time.Now()
  1999. // fmt.Println(startNow.Format(utils.FormatDateTime))
  2000. // startTime := startNow.Unix()
  2001. // //filePath := `static/tmpFile/test/化工23.05.24.xlsx`
  2002. // filePath := `static/tmpFile/1. TAROUND_202308010201-500.xlsx`
  2003. // //filePath := `static/tmpFile/化工23.05.24.xml`
  2004. // //filePath := `static/tmpFile/化工23.05.24/xl/workbook.xml`
  2005. // //filePath := `static/tmpFile/1. TAROUND_202308010201.xlsx`
  2006. //
  2007. // //filePath := `static/tmpFile/1. TAROUND_202308010201-2.xlsx`
  2008. //
  2009. // //filePath := `static/tmpFile/5. Outage_Values_Daily.xlsx`
  2010. // //filePath := `static/tmpFile/1. TAROUND_202308010201 - 副本.xlsx`
  2011. // excel.ConvToLuckySheet(filePath)
  2012. // cz := time.Now().Unix() - startTime
  2013. // fmt.Printf("处理完需要的时间:%d秒;约耗时:%d分%d秒", cz, cz/60, cz%60)
  2014. // fmt.Println()
  2015. //
  2016. // //sheetName := `日度`
  2017. // //sheetName := `月度`
  2018. // //fmt.Println(excel.GetDefaultSheetIndex(filePath, sheetName))
  2019. //
  2020. // //decompressZip(filePath)
  2021. //}
  2022. // src: 需要解压的zip文件
  2023. func decompressZip(src string) error {
  2024. archive, err := zip.OpenReader(src)
  2025. if err != nil {
  2026. return err
  2027. }
  2028. dir := filepath.Dir(src) + "/zip"
  2029. defer archive.Close()
  2030. for _, f := range archive.File {
  2031. filePath := filepath.Join(dir, f.Name)
  2032. if f.FileInfo().IsDir() {
  2033. os.MkdirAll(filePath, os.ModePerm)
  2034. continue
  2035. }
  2036. if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
  2037. return fmt.Errorf("failed to make directory (%v)", err)
  2038. }
  2039. dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
  2040. if err != nil {
  2041. return fmt.Errorf("failed to create file (%v)", err)
  2042. }
  2043. fileInArchive, err := f.Open()
  2044. if err != nil {
  2045. return fmt.Errorf("failed to open file in zip (%v)", err)
  2046. }
  2047. if _, err := io.Copy(dstFile, fileInArchive); err != nil {
  2048. return fmt.Errorf("failed to copy file in zip (%v)", err)
  2049. }
  2050. dstFile.Close()
  2051. fileInArchive.Close()
  2052. }
  2053. return nil
  2054. }
  2055. // MarkEditStatus
  2056. // @Title 标记沙盘编辑状态
  2057. // @Description 标记沙盘编辑状态接口
  2058. // @Param request body request.MarkEditSandbox true "type json string"
  2059. // @Success 200 标记成功 ;202 标记成功
  2060. // @router /excel_info/mark [post]
  2061. func (this *ExcelInfoController) MarkEditStatus() {
  2062. br := new(models.BaseResponse).Init()
  2063. defer func() {
  2064. this.Data["json"] = br
  2065. this.ServeJSON()
  2066. }()
  2067. sysUser := this.SysUser
  2068. if sysUser == nil {
  2069. br.Msg = "请登录"
  2070. br.ErrMsg = "请登录,SysUser Is Empty"
  2071. br.Ret = 408
  2072. return
  2073. }
  2074. var req request.MarkEditExcel
  2075. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2076. if err != nil {
  2077. br.Msg = "参数解析异常!"
  2078. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2079. return
  2080. }
  2081. if req.ExcelInfoId <= 0 {
  2082. br.Msg = "缺少表格编号"
  2083. return
  2084. }
  2085. if req.Status <= 0 {
  2086. br.Msg = "标记状态异常"
  2087. return
  2088. }
  2089. //更新标记key
  2090. data, err := services.UpdateExcelEditMark(req.ExcelInfoId, sysUser.AdminId, req.Status, sysUser.RealName)
  2091. if err != nil {
  2092. br.Msg = err.Error()
  2093. return
  2094. }
  2095. msg := "标记成功"
  2096. br.Ret = 200
  2097. br.Success = true
  2098. br.Msg = msg
  2099. br.Data = data
  2100. }