mysteel_chemical.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/http"
  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. edbTerminal := getEdbTerminal(utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  257. if edbTerminal == nil {
  258. errMsg = `钢联终端信息未配置`
  259. err = errors.New(errMsg)
  260. return
  261. }
  262. baseFromMysteelChemicalIndex = &data_manage.BaseFromMysteelChemicalIndex{
  263. //BaseFromMysteelChemicalIndexId: 0,
  264. BaseFromMysteelChemicalClassifyId: classifyId,
  265. IndexCode: indexCode,
  266. IndexName: "",
  267. Unit: "",
  268. Source: "",
  269. Frequency: "",
  270. StartDate: "",
  271. EndDate: "",
  272. Describe: "",
  273. UpdateWeek: updateWeek,
  274. UpdateTime: updateTime1,
  275. UpdateTime2: updateTime2,
  276. SysUserId: sysUserId,
  277. SysUserRealName: sysUserName,
  278. ModifyTime: time.Now(),
  279. CreateTime: time.Now(),
  280. TerminalCode: edbTerminal.TerminalCode, // 终端编码
  281. }
  282. _, err = data_manage.AddBaseFromMysteelChemicalIndex(baseFromMysteelChemicalIndex)
  283. if err != nil {
  284. errMsg = "保存分类失败"
  285. }
  286. return
  287. }
  288. // EditMysteelChemicalIndex 编辑钢联化工指标
  289. func EditMysteelChemicalIndex(indexId, classifyId int, updateWeek, updateTimeStr string, sysUser *system.Admin) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) {
  290. baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  291. if err != nil {
  292. errMsg = `获取数据失败`
  293. if err.Error() == utils.ErrNoRow() {
  294. errMsg = `该指标未入库`
  295. err = nil
  296. }
  297. return
  298. }
  299. // 操作权限校验
  300. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  301. if !button.OpButton {
  302. errMsg = "无权限操作"
  303. return
  304. }
  305. oldUpdateWeek := baseFromMysteelChemicalIndex.UpdateWeek
  306. // 更新时间切割
  307. var updateTime1, updateTime2 string
  308. if updateTimeStr != `` {
  309. updateTimeList := strings.Split(updateTimeStr, ",")
  310. updateTime1 = updateTimeList[0]
  311. if len(updateTimeList) > 1 {
  312. updateTime2 = updateTimeList[1]
  313. }
  314. }
  315. baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId = classifyId
  316. baseFromMysteelChemicalIndex.UpdateWeek = updateWeek
  317. baseFromMysteelChemicalIndex.UpdateTime = updateTime1
  318. baseFromMysteelChemicalIndex.UpdateTime2 = updateTime2
  319. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  320. err = baseFromMysteelChemicalIndex.Update([]string{"BaseFromMysteelChemicalClassifyId", "UpdateWeek", "UpdateTime", "UpdateTime2", "ModifyTime"})
  321. if err != nil {
  322. errMsg = "保存分类失败"
  323. }
  324. go func(oldUpdateWeek string, indexInfo *data_manage.BaseFromMysteelChemicalIndex) {
  325. // 先删除excel表
  326. CurlDelMysteelChemicalData(indexInfo.IndexCode, oldUpdateWeek)
  327. }(oldUpdateWeek, baseFromMysteelChemicalIndex)
  328. return
  329. }
  330. // DelMysteelChemical 删除钢联化工指标
  331. func DelMysteelChemical(indexId int, sysUser *system.Admin) (err error, errMsg string) {
  332. baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  333. if err != nil {
  334. errMsg = `获取数据失败`
  335. if err.Error() == utils.ErrNoRow() {
  336. errMsg = `该指标未入库`
  337. err = nil
  338. }
  339. return
  340. }
  341. // 操作权限校验
  342. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  343. if !button.DeleteButton {
  344. errMsg = "无权限操作"
  345. return
  346. }
  347. // 获取已经加入到EDB指标库的钢联化工指标
  348. edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, baseFromMysteelChemicalIndex.IndexCode)
  349. if err != nil && err.Error() != utils.ErrNoRow() {
  350. errMsg = "删除失败"
  351. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  352. return
  353. }
  354. if edbInfo != nil {
  355. errMsg = "当前指标已被引用,不可删除"
  356. err = nil
  357. return
  358. }
  359. // 删除对应的分类和指标
  360. err = data_manage.DeleteMysteelChemical(indexId)
  361. if err != nil {
  362. return
  363. }
  364. // 删除指标服务的excel表
  365. go CurlDelMysteelChemicalData(baseFromMysteelChemicalIndex.IndexCode, baseFromMysteelChemicalIndex.UpdateWeek)
  366. return
  367. }
  368. // MoveMysteelChemical 移动钢联化工指标
  369. func MoveMysteelChemical(indexId, classifyId, prevIndexId, nextIndexId int, sysUser *system.Admin) (err error, errMsg string) {
  370. //分类信息
  371. baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  372. if err != nil {
  373. errMsg = `获取数据失败`
  374. if err.Error() == utils.ErrNoRow() {
  375. errMsg = `该指标未入库`
  376. err = nil
  377. }
  378. return
  379. }
  380. // 操作权限校验
  381. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  382. if !button.MoveButton {
  383. errMsg = "无权限操作"
  384. return
  385. }
  386. //判断分类是否存在
  387. _, err = data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  388. if err != nil {
  389. errMsg = "移动失败"
  390. err = errors.New("获取分类信息失败,Err:" + err.Error())
  391. if err.Error() == utils.ErrNoRow() {
  392. errMsg = "找不到该分类"
  393. err = nil
  394. }
  395. return
  396. }
  397. //如果改变了分类,那么移动该图表数据
  398. if baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId != classifyId {
  399. tmpErr := data_manage.MoveBaseFromMysteelChemicalIndex(indexId, classifyId)
  400. if err != nil {
  401. errMsg = "移动失败"
  402. err = errors.New("移动失败,Err:" + tmpErr.Error())
  403. return
  404. }
  405. }
  406. //移动排序
  407. updateCol := make([]string, 0)
  408. //如果有传入 上一个兄弟节点分类id
  409. if prevIndexId > 0 {
  410. prevIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(prevIndexId)
  411. if err != nil {
  412. errMsg = "移动失败"
  413. err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  414. return
  415. }
  416. //如果是移动在两个兄弟节点之间
  417. if nextIndexId > 0 {
  418. //下一个兄弟节点
  419. nextIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(nextIndexId)
  420. if err != nil {
  421. errMsg = "移动失败"
  422. err = errors.New("获取下一个兄弟节点指标信息失败,Err:" + tmpErr.Error())
  423. return
  424. }
  425. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  426. if prevIndex.Sort == nextIndex.Sort || prevIndex.Sort == baseFromMysteelChemicalIndex.Sort {
  427. //变更兄弟节点的排序
  428. updateSortStr := `sort + 2`
  429. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr)
  430. } else {
  431. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  432. if nextIndex.Sort-prevIndex.Sort == 1 {
  433. //变更兄弟节点的排序
  434. updateSortStr := `sort + 1`
  435. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr)
  436. }
  437. }
  438. }
  439. baseFromMysteelChemicalIndex.Sort = prevIndex.Sort + 1
  440. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  441. updateCol = append(updateCol, "Sort", "ModifyTime")
  442. } else {
  443. firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId)
  444. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  445. errMsg = "移动失败"
  446. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  447. return
  448. }
  449. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  450. if firstClassify != nil && firstClassify.Sort == 0 {
  451. updateSortStr := ` sort + 1 `
  452. _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(firstClassify.BaseFromMysteelChemicalClassifyId, 0, firstClassify.BaseFromMysteelChemicalIndexId-1, updateSortStr)
  453. }
  454. baseFromMysteelChemicalIndex.Sort = 0 //那就是排在第一位
  455. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  456. updateCol = append(updateCol, "Sort", "ModifyTime")
  457. }
  458. //更新
  459. if len(updateCol) > 0 {
  460. err = baseFromMysteelChemicalIndex.Update(updateCol)
  461. if err != nil {
  462. errMsg = "移动失败"
  463. err = errors.New("修改失败,Err:" + err.Error())
  464. return
  465. }
  466. }
  467. if err != nil {
  468. errMsg = "移动失败"
  469. err = errors.New("修改失败,Err:" + err.Error())
  470. return
  471. }
  472. return
  473. }
  474. // GetMysteelChemicalOpButton 获取钢联化工的操作权限
  475. func GetMysteelChemicalOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.BaseFromMysteelChemicalClassifyItemsButton) {
  476. //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类;
  477. //3、ficc管理员和超管对所有分类有编辑、移动和删除权限;
  478. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.MysteelChemicalPermission == 1 {
  479. button.AddButton = true
  480. button.OpButton = true
  481. button.DeleteButton = true
  482. button.MoveButton = true
  483. }
  484. return
  485. }
  486. // CurlDelMysteelChemicalData 请求钢联服务器删除指标
  487. func CurlDelMysteelChemicalData(indexCode, updateWeek string) {
  488. postUrl := utils.MySteelPostUrl + `/api/index/delete`
  489. //type IndexAddReq struct {
  490. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  491. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  492. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  493. //}
  494. paramsMap := make(map[string]interface{})
  495. updateWeek = WeekMap[updateWeek]
  496. paramsMap["IndexCode"] = indexCode
  497. paramsMap["UpdateWeek"] = updateWeek
  498. paramsMap["RunMode"] = utils.RunMode
  499. paramJson, err := json.Marshal(paramsMap)
  500. if err != nil {
  501. fmt.Println("param json.Marshal Err:" + err.Error())
  502. err = errors.New("param json.Marshal Err:" + err.Error())
  503. return
  504. }
  505. utils.FileLog.Info(fmt.Sprintf("CurlDelMysteelChemicalData parms:%s", string(paramJson)))
  506. result, err := http.Post(postUrl, string(paramJson), "application/json")
  507. if err != nil {
  508. fmt.Println("post err:" + err.Error())
  509. err = errors.New("post Err:" + err.Error())
  510. return
  511. }
  512. utils.FileLog.Info("CurlDelMysteelChemicalData Result:%s", string(result))
  513. }
  514. // WeekMap 中英文日期转换
  515. var WeekMap = map[string]string{
  516. "": "",
  517. "周一": "monday",
  518. "周二": "tuesday",
  519. "周三": "wednesday",
  520. "周四": "thursday",
  521. "周五": "friday",
  522. "周六": "saturday",
  523. "周日": "sunday",
  524. }
  525. // CurlRefreshMysteelChemicalData 请求钢联服务器添加指标
  526. func CurlRefreshMysteelChemicalData(mergeFilePath string) {
  527. postUrl := utils.MySteelPostUrl + `/api/index/refresh`
  528. //type IndexAddReq struct {
  529. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  530. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  531. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  532. //}
  533. paramsMap := make(map[string]interface{})
  534. paramsMap["MergeFilePath"] = mergeFilePath
  535. paramJson, err := json.Marshal(paramsMap)
  536. if err != nil {
  537. fmt.Println("param json.Marshal Err:" + err.Error())
  538. err = errors.New("param json.Marshal Err:" + err.Error())
  539. return
  540. }
  541. utils.FileLog.Info(fmt.Sprintf("CurlRefreshMysteelChemicalData parms:%s", string(paramJson)))
  542. result, err := http.Post(postUrl, string(paramJson), "application/json")
  543. if err != nil {
  544. fmt.Println("post err:" + err.Error())
  545. err = errors.New("post Err:" + err.Error())
  546. return
  547. }
  548. utils.FileLog.Info("CurlRefreshMysteelChemicalData Result:%s", string(result))
  549. }
  550. // getEdbTerminal 根据指标来源获取可用指标终端信息
  551. func getEdbTerminal(source int) (edbTerminal *data_manage.EdbTerminal) {
  552. terminalNumList, err := data_manage.GetMysteelChemicalGroupTerminalNum()
  553. if err != nil {
  554. return
  555. }
  556. terminalNumMap := make(map[string]int)
  557. for _, v := range terminalNumList {
  558. terminalNumMap[v.TerminalCode] = v.Num
  559. }
  560. terminalList, err := data_manage.GetEdbTerminalListBySource(source)
  561. if err != nil {
  562. return
  563. }
  564. num := 0
  565. for _, v := range terminalList {
  566. tmpNum := terminalNumMap[v.TerminalCode]
  567. if edbTerminal == nil {
  568. edbTerminal = v
  569. num = tmpNum
  570. } else if tmpNum < num {
  571. edbTerminal = v
  572. num = tmpNum
  573. }
  574. }
  575. return
  576. }