mysteel_chemical.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/utils"
  10. "strings"
  11. "time"
  12. )
  13. // AddMysteelChemicalClassify 添加钢联化工分类
  14. func AddMysteelChemicalClassify(classifyName string, parentId, level, sysUserId int, sysUserName string) (classifyInfo *data_manage.BaseFromMysteelChemicalClassify, err error, errMsg string) {
  15. count, err := data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, parentId)
  16. if err != nil {
  17. errMsg = `判断名称是否已存在失败`
  18. return
  19. }
  20. if count > 0 {
  21. errMsg = `分类名称已存在,请重新输入`
  22. return
  23. }
  24. //获取该层级下最大的排序数
  25. maxSort, err := data_manage.GetBaseFromMysteelChemicalClassifyMaxSort(parentId)
  26. classifyInfo = &data_manage.BaseFromMysteelChemicalClassify{
  27. //BaseFromMysteelChemicalClassifyId: 0,
  28. ClassifyName: classifyName,
  29. ParentId: parentId,
  30. SysUserId: sysUserId,
  31. SysUserRealName: sysUserName,
  32. Sort: maxSort + 1,
  33. Level: level + 1,
  34. ModifyTime: time.Now(),
  35. CreateTime: time.Now(),
  36. }
  37. classifyId, err := data_manage.AddBaseFromMysteelChemicalClassify(classifyInfo)
  38. if err != nil {
  39. errMsg = "保存分类失败"
  40. }
  41. classifyInfo.BaseFromMysteelChemicalClassifyId = int(classifyId)
  42. return
  43. }
  44. // EditMysteelChemicalClassify 编辑钢联化工分类
  45. func EditMysteelChemicalClassify(classifyId int, classifyName string, sysUser *system.Admin) (err error, errMsg string) {
  46. item, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  47. if err != nil {
  48. errMsg = `保存失败`
  49. return
  50. }
  51. // 操作权限校验
  52. button := GetMysteelChemicalOpButton(sysUser, item.SysUserId)
  53. if !button.OpButton {
  54. errMsg = "无权限操作"
  55. return
  56. }
  57. // 名字相同,那么就直接返回
  58. if item.ClassifyName == classifyName {
  59. return
  60. }
  61. // 判断名称是否已存在
  62. count, err := data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, item.ParentId)
  63. if err != nil {
  64. errMsg = "判断名称是否已存在失败"
  65. return
  66. }
  67. if count > 0 {
  68. errMsg = "分类名称已存在,请重新输入"
  69. err = errors.New(errMsg)
  70. return
  71. }
  72. // 修改数据
  73. err = data_manage.EditBaseFromMysteelChemicalClassify(classifyId, classifyName)
  74. if err != nil {
  75. errMsg = "保存失败"
  76. }
  77. return
  78. }
  79. // MoveMysteelChemicalClassify 移动钢联化工分类
  80. func MoveMysteelChemicalClassify(classifyId, parentClassifyId, prevClassifyId, nextClassifyId int, sysUser *system.Admin) (err error, errMsg string) {
  81. //判断分类是否存在
  82. classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  83. if err != nil {
  84. errMsg = "移动失败"
  85. err = errors.New("获取分类信息失败,Err:" + err.Error())
  86. return
  87. }
  88. // 操作权限校验
  89. button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId)
  90. if !button.MoveButton {
  91. errMsg = "无权限操作"
  92. return
  93. }
  94. updateCol := make([]string, 0)
  95. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  96. if classifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  97. parentClassifyInfo, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(parentClassifyId)
  98. if tmpErr != nil {
  99. errMsg = "移动失败"
  100. err = errors.New("获取上级分类信息失败,Err:" + tmpErr.Error())
  101. return
  102. }
  103. classifyInfo.ParentId = parentClassifyInfo.BaseFromMysteelChemicalClassifyId
  104. classifyInfo.Level = parentClassifyInfo.Level + 1
  105. classifyInfo.ModifyTime = time.Now()
  106. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  107. }
  108. //如果有传入 上一个兄弟节点分类id
  109. if prevClassifyId > 0 {
  110. prevClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(prevClassifyId)
  111. if tmpErr != nil {
  112. errMsg = "移动失败"
  113. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  114. return
  115. }
  116. //如果是移动在两个兄弟节点之间
  117. if nextClassifyId > 0 {
  118. //下一个兄弟节点
  119. nextClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(nextClassifyId)
  120. if tmpErr != nil {
  121. errMsg = "移动失败"
  122. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  123. return
  124. }
  125. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  126. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == classifyInfo.Sort {
  127. //变更兄弟节点的排序
  128. updateSortStr := `sort + 2`
  129. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, prevClassify.BaseFromMysteelChemicalClassifyId, prevClassify.Sort, updateSortStr)
  130. } else {
  131. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  132. if nextClassify.Sort-prevClassify.Sort == 1 {
  133. //变更兄弟节点的排序
  134. updateSortStr := `sort + 1`
  135. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, 0, prevClassify.Sort, updateSortStr)
  136. }
  137. }
  138. }
  139. classifyInfo.Sort = prevClassify.Sort + 1
  140. classifyInfo.ModifyTime = time.Now()
  141. updateCol = append(updateCol, "Sort", "ModifyTime")
  142. } else {
  143. firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalClassify()
  144. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  145. errMsg = "移动失败"
  146. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  147. return
  148. }
  149. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  150. if firstClassify != nil && firstClassify.Sort == 0 {
  151. updateSortStr := ` sort + 1 `
  152. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, firstClassify.BaseFromMysteelChemicalClassifyId-1, 0, updateSortStr)
  153. }
  154. classifyInfo.Sort = 0 //那就是排在第一位
  155. classifyInfo.ModifyTime = time.Now()
  156. updateCol = append(updateCol, "Sort", "ModifyTime")
  157. }
  158. //更新
  159. if len(updateCol) > 0 {
  160. err = classifyInfo.Update(updateCol)
  161. if err != nil {
  162. errMsg = "移动失败"
  163. err = errors.New("修改失败,Err:" + err.Error())
  164. return
  165. }
  166. }
  167. return
  168. }
  169. // DelMysteelChemicalClassify 删除钢联化工分类
  170. func DelMysteelChemicalClassify(classifyId int, sysUser *system.Admin) (err error, errMsg string) {
  171. //判断分类是否存在
  172. classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  173. if err != nil {
  174. errMsg = "删除失败"
  175. err = errors.New("获取分类信息失败,Err:" + err.Error())
  176. return
  177. }
  178. // 操作权限校验
  179. button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId)
  180. if !button.DeleteButton {
  181. errMsg = "无权限操作"
  182. return
  183. }
  184. // 需要删除的分类id集合
  185. classifyIdList := make([]int, 0)
  186. classifyIdList = append(classifyIdList, classifyId)
  187. mysteelChemicalIndexIdList := make([]int, 0)
  188. indexCodeList := make([]string, 0)
  189. // 查找所有的子集id
  190. if classifyInfo.ParentId <= 0 {
  191. childrenClassifyInfoList, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(classifyId)
  192. if tmpErr != nil {
  193. errMsg = "删除失败"
  194. err = errors.New("获取分类信息失败,Err:" + tmpErr.Error())
  195. return
  196. }
  197. for _, v := range childrenClassifyInfoList {
  198. classifyIdList = append(classifyIdList, v.BaseFromMysteelChemicalClassifyId)
  199. }
  200. }
  201. // 获取分类下的所有指标
  202. baseFromMysteelChemicalIndexList, err := data_manage.GetBaseFromMysteelChemicalIndexListByClassifyIdList(classifyIdList)
  203. if err != nil {
  204. errMsg = "删除失败"
  205. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  206. return
  207. }
  208. for _, v := range baseFromMysteelChemicalIndexList {
  209. mysteelChemicalIndexIdList = append(mysteelChemicalIndexIdList, v.BaseFromMysteelChemicalIndexId)
  210. indexCodeList = append(indexCodeList, v.IndexCode)
  211. }
  212. // 获取已经加入到EDB指标库的钢联化工指标
  213. edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, indexCodeList)
  214. if err != nil {
  215. errMsg = "删除失败"
  216. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  217. return
  218. }
  219. if len(edbInfoList) > 0 {
  220. errMsg = "该分类下存在指标加入到ETA图库,无法删除"
  221. return
  222. }
  223. // 删除对应的分类和指标
  224. err = data_manage.DeleteMysteelChemicalByClassifyId(classifyIdList, mysteelChemicalIndexIdList)
  225. if err != nil {
  226. return
  227. }
  228. // 删除指标服务的excel表
  229. go func(list []*data_manage.BaseFromMysteelChemicalIndex) {
  230. for _, v := range list {
  231. CurlDelMysteelChemicalData(v.IndexCode, v.UpdateWeek)
  232. }
  233. }(baseFromMysteelChemicalIndexList)
  234. return
  235. }
  236. // AddMysteelChemicalIndex 添加钢联化工指标
  237. func AddMysteelChemicalIndex(classifyId int, indexCode, updateWeek, updateTimeStr string, sysUserId int, sysUserName string) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) {
  238. baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByCode(indexCode)
  239. if err != nil && err.Error() != utils.ErrNoRow() {
  240. errMsg = `获取数据失败`
  241. return
  242. }
  243. if baseFromMysteelChemicalIndex != nil {
  244. errMsg = `指标ID已存在,请重新输入`
  245. return
  246. }
  247. // 更新时间切割
  248. var updateTime1, updateTime2 string
  249. if updateTimeStr != `` {
  250. updateTimeList := strings.Split(updateTimeStr, ",")
  251. updateTime1 = updateTimeList[0]
  252. if len(updateTimeList) > 1 {
  253. updateTime2 = updateTimeList[1]
  254. }
  255. }
  256. baseFromMysteelChemicalIndex = &data_manage.BaseFromMysteelChemicalIndex{
  257. //BaseFromMysteelChemicalIndexId: 0,
  258. BaseFromMysteelChemicalClassifyId: classifyId,
  259. IndexCode: indexCode,
  260. IndexName: "",
  261. Unit: "",
  262. Source: "",
  263. Frequency: "",
  264. StartDate: "",
  265. EndDate: "",
  266. Describe: "",
  267. UpdateWeek: updateWeek,
  268. UpdateTime: updateTime1,
  269. UpdateTime2: updateTime2,
  270. SysUserId: sysUserId,
  271. SysUserRealName: sysUserName,
  272. ModifyTime: time.Now(),
  273. CreateTime: time.Now(),
  274. }
  275. _, err = data_manage.AddBaseFromMysteelChemicalIndex(baseFromMysteelChemicalIndex)
  276. if err != nil {
  277. errMsg = "保存分类失败"
  278. }
  279. // 调用指标服务生成excel并拉取数据
  280. go CurlAddMysteelChemicalData(indexCode, updateWeek)
  281. return
  282. }
  283. // EditMysteelChemicalIndex 编辑钢联化工指标
  284. func EditMysteelChemicalIndex(indexId, classifyId int, updateWeek, updateTimeStr string, sysUser *system.Admin) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) {
  285. baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  286. if err != nil {
  287. errMsg = `获取数据失败`
  288. if err.Error() == utils.ErrNoRow() {
  289. errMsg = `该指标未入库`
  290. err = nil
  291. }
  292. return
  293. }
  294. // 操作权限校验
  295. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  296. if !button.OpButton {
  297. errMsg = "无权限操作"
  298. return
  299. }
  300. oldUpdateWeek := baseFromMysteelChemicalIndex.UpdateWeek
  301. // 更新时间切割
  302. var updateTime1, updateTime2 string
  303. if updateTimeStr != `` {
  304. updateTimeList := strings.Split(updateTimeStr, ",")
  305. updateTime1 = updateTimeList[0]
  306. if len(updateTimeList) > 1 {
  307. updateTime2 = updateTimeList[1]
  308. }
  309. }
  310. baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId = classifyId
  311. baseFromMysteelChemicalIndex.UpdateWeek = updateWeek
  312. baseFromMysteelChemicalIndex.UpdateTime = updateTime1
  313. baseFromMysteelChemicalIndex.UpdateTime2 = updateTime2
  314. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  315. err = baseFromMysteelChemicalIndex.Update([]string{"BaseFromMysteelChemicalClassifyId", "UpdateWeek", "UpdateTime", "UpdateTime2", "ModifyTime"})
  316. if err != nil {
  317. errMsg = "保存分类失败"
  318. }
  319. go func(oldUpdateWeek string, indexInfo *data_manage.BaseFromMysteelChemicalIndex) {
  320. // 先删除excel表
  321. CurlDelMysteelChemicalData(indexInfo.IndexCode, oldUpdateWeek)
  322. // 再创建excel表
  323. CurlAddMysteelChemicalData(indexInfo.IndexCode, indexInfo.UpdateWeek)
  324. }(oldUpdateWeek, baseFromMysteelChemicalIndex)
  325. return
  326. }
  327. // DelMysteelChemical 删除钢联化工指标
  328. func DelMysteelChemical(indexId int, sysUser *system.Admin) (err error, errMsg string) {
  329. baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  330. if err != nil {
  331. errMsg = `获取数据失败`
  332. if err.Error() == utils.ErrNoRow() {
  333. errMsg = `该指标未入库`
  334. err = nil
  335. }
  336. return
  337. }
  338. // 操作权限校验
  339. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  340. if !button.DeleteButton {
  341. errMsg = "无权限操作"
  342. return
  343. }
  344. // 获取已经加入到EDB指标库的钢联化工指标
  345. edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, baseFromMysteelChemicalIndex.IndexCode)
  346. if err != nil && err.Error() != utils.ErrNoRow() {
  347. errMsg = "删除失败"
  348. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  349. return
  350. }
  351. if edbInfo != nil {
  352. errMsg = "当前指标已被引用,不可删除"
  353. err = nil
  354. return
  355. }
  356. // 删除对应的分类和指标
  357. err = data_manage.DeleteMysteelChemical(indexId)
  358. if err != nil {
  359. return
  360. }
  361. // 删除指标服务的excel表
  362. go CurlDelMysteelChemicalData(baseFromMysteelChemicalIndex.IndexCode, baseFromMysteelChemicalIndex.UpdateWeek)
  363. return
  364. }
  365. // MoveMysteelChemical 移动钢联化工指标
  366. func MoveMysteelChemical(indexId, classifyId, prevIndexId, nextIndexId int, sysUser *system.Admin) (err error, errMsg string) {
  367. //分类信息
  368. baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  369. if err != nil {
  370. errMsg = `获取数据失败`
  371. if err.Error() == utils.ErrNoRow() {
  372. errMsg = `该指标未入库`
  373. err = nil
  374. }
  375. return
  376. }
  377. // 操作权限校验
  378. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  379. if !button.MoveButton {
  380. errMsg = "无权限操作"
  381. return
  382. }
  383. //判断分类是否存在
  384. _, err = data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  385. if err != nil {
  386. errMsg = "移动失败"
  387. err = errors.New("获取分类信息失败,Err:" + err.Error())
  388. if err.Error() == utils.ErrNoRow() {
  389. errMsg = "找不到该分类"
  390. err = nil
  391. }
  392. return
  393. }
  394. //如果改变了分类,那么移动该图表数据
  395. if baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId != classifyId {
  396. tmpErr := data_manage.MoveBaseFromMysteelChemicalIndex(indexId, classifyId)
  397. if err != nil {
  398. errMsg = "移动失败"
  399. err = errors.New("移动失败,Err:" + tmpErr.Error())
  400. return
  401. }
  402. }
  403. //移动排序
  404. updateCol := make([]string, 0)
  405. //如果有传入 上一个兄弟节点分类id
  406. if prevIndexId > 0 {
  407. prevIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(prevIndexId)
  408. if err != nil {
  409. errMsg = "移动失败"
  410. err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  411. return
  412. }
  413. //如果是移动在两个兄弟节点之间
  414. if nextIndexId > 0 {
  415. //下一个兄弟节点
  416. nextIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(nextIndexId)
  417. if err != nil {
  418. errMsg = "移动失败"
  419. err = errors.New("获取下一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  420. return
  421. }
  422. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  423. if prevIndex.Sort == nextIndex.Sort || prevIndex.Sort == baseFromMysteelChemicalIndex.Sort {
  424. //变更兄弟节点的排序
  425. updateSortStr := `sort + 2`
  426. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr)
  427. } else {
  428. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  429. if nextIndex.Sort-prevIndex.Sort == 1 {
  430. //变更兄弟节点的排序
  431. updateSortStr := `sort + 1`
  432. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr)
  433. }
  434. }
  435. }
  436. baseFromMysteelChemicalIndex.Sort = prevIndex.Sort + 1
  437. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  438. updateCol = append(updateCol, "Sort", "ModifyTime")
  439. } else {
  440. firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId)
  441. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  442. errMsg = "移动失败"
  443. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  444. return
  445. }
  446. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  447. if firstClassify != nil && firstClassify.Sort == 0 {
  448. updateSortStr := ` sort + 1 `
  449. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(firstClassify.BaseFromMysteelChemicalClassifyId, 0, firstClassify.BaseFromMysteelChemicalIndexId-1, updateSortStr)
  450. }
  451. baseFromMysteelChemicalIndex.Sort = 0 //那就是排在第一位
  452. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  453. updateCol = append(updateCol, "Sort", "ModifyTime")
  454. }
  455. //更新
  456. if len(updateCol) > 0 {
  457. err = baseFromMysteelChemicalIndex.Update(updateCol)
  458. if err != nil {
  459. errMsg = "移动失败"
  460. err = errors.New("修改失败,Err:" + err.Error())
  461. return
  462. }
  463. }
  464. if err != nil {
  465. errMsg = "移动失败"
  466. err = errors.New("修改失败,Err:" + err.Error())
  467. return
  468. }
  469. return
  470. }
  471. // GetMysteelChemicalOpButton 获取钢联化工的操作权限
  472. func GetMysteelChemicalOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.BaseFromMysteelChemicalClassifyItemsButton) {
  473. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  474. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  475. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.MysteelChemicalPermission == 1 {
  476. button.AddButton = true
  477. button.OpButton = true
  478. button.DeleteButton = true
  479. button.MoveButton = true
  480. }
  481. return
  482. }
  483. // CurlAddMysteelChemicalData 请求钢联服务器添加指标
  484. func CurlAddMysteelChemicalData(indexCode, updateWeek string) {
  485. postUrl := utils.MySteelPostUrl + `/api/index/create`
  486. //type IndexAddReq struct {
  487. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  488. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  489. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  490. //}
  491. paramsMap := make(map[string]interface{})
  492. updateWeek = WeekMap[updateWeek]
  493. paramsMap["IndexCode"] = indexCode
  494. paramsMap["UpdateWeek"] = updateWeek
  495. paramsMap["RunMode"] = utils.RunMode
  496. paramJson, err := json.Marshal(paramsMap)
  497. if err != nil {
  498. fmt.Println("param json.Marshal Err:" + err.Error())
  499. err = errors.New("param json.Marshal Err:" + err.Error())
  500. return
  501. }
  502. utils.FileLog.Info(fmt.Sprintf("CurlAddMysteelChemicalData parms:%s", string(paramJson)))
  503. result, err := http.Post(postUrl, string(paramJson), "application/json")
  504. if err != nil {
  505. fmt.Println("post err:" + err.Error())
  506. err = errors.New("post Err:" + err.Error())
  507. return
  508. }
  509. utils.FileLog.Info("CurlAddMysteelChemicalData Result:%s", string(result))
  510. }
  511. // CurlDelMysteelChemicalData 请求钢联服务器删除指标
  512. func CurlDelMysteelChemicalData(indexCode, updateWeek string) {
  513. postUrl := utils.MySteelPostUrl + `/api/index/delete`
  514. //type IndexAddReq struct {
  515. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  516. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  517. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  518. //}
  519. paramsMap := make(map[string]interface{})
  520. updateWeek = WeekMap[updateWeek]
  521. paramsMap["IndexCode"] = indexCode
  522. paramsMap["UpdateWeek"] = updateWeek
  523. paramsMap["RunMode"] = utils.RunMode
  524. paramJson, err := json.Marshal(paramsMap)
  525. if err != nil {
  526. fmt.Println("param json.Marshal Err:" + err.Error())
  527. err = errors.New("param json.Marshal Err:" + err.Error())
  528. return
  529. }
  530. utils.FileLog.Info(fmt.Sprintf("CurlDelMysteelChemicalData parms:%s", string(paramJson)))
  531. result, err := http.Post(postUrl, string(paramJson), "application/json")
  532. if err != nil {
  533. fmt.Println("post err:" + err.Error())
  534. err = errors.New("post Err:" + err.Error())
  535. return
  536. }
  537. utils.FileLog.Info("CurlDelMysteelChemicalData Result:%s", string(result))
  538. }
  539. // WeekMap 中英文日期转换
  540. var WeekMap = map[string]string{
  541. "": "",
  542. "周一": "monday",
  543. "周二": "tuesday",
  544. "周三": "wednesday",
  545. "周四": "thursday",
  546. "周五": "friday",
  547. "周六": "saturday",
  548. "周日": "sunday",
  549. }
  550. // CurlAddMysteelChemicalData 请求钢联服务器添加指标
  551. func CurlRefreshMysteelChemicalData(mergeFilePath string) {
  552. postUrl := utils.MySteelPostUrl + `/api/index/refresh`
  553. //type IndexAddReq struct {
  554. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  555. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  556. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  557. //}
  558. paramsMap := make(map[string]interface{})
  559. paramsMap["MergeFilePath"] = mergeFilePath
  560. paramJson, err := json.Marshal(paramsMap)
  561. if err != nil {
  562. fmt.Println("param json.Marshal Err:" + err.Error())
  563. err = errors.New("param json.Marshal Err:" + err.Error())
  564. return
  565. }
  566. utils.FileLog.Info(fmt.Sprintf("CurlAddMysteelChemicalData parms:%s", string(paramJson)))
  567. result, err := http.Post(postUrl, string(paramJson), "application/json")
  568. if err != nil {
  569. fmt.Println("post err:" + err.Error())
  570. err = errors.New("post Err:" + err.Error())
  571. return
  572. }
  573. utils.FileLog.Info("CurlAddMysteelChemicalData Result:%s", string(result))
  574. }