mysteel_chemical.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "hongze/hz_crm_api/models/data_manage"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/utils"
  10. "strings"
  11. "time"
  12. )
  13. const (
  14. mysteelPostUrl = `http://mysteelhz.hzinsights.com:8040`
  15. )
  16. // AddMysteelChemicalClassify 添加钢联化工分类
  17. func AddMysteelChemicalClassify(classifyName string, parentId, level, sysUserId int, sysUserName string) (classifyInfo *data_manage.BaseFromMysteelChemicalClassify, err error, errMsg string) {
  18. count, err := data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, parentId)
  19. if err != nil {
  20. errMsg = `判断名称是否已存在失败`
  21. return
  22. }
  23. if count > 0 {
  24. errMsg = `分类名称已存在,请重新输入`
  25. return
  26. }
  27. //获取该层级下最大的排序数
  28. maxSort, err := data_manage.GetBaseFromMysteelChemicalClassifyMaxSort(parentId)
  29. classifyInfo = &data_manage.BaseFromMysteelChemicalClassify{
  30. //BaseFromMysteelChemicalClassifyId: 0,
  31. ClassifyName: classifyName,
  32. ParentId: parentId,
  33. SysUserId: sysUserId,
  34. SysUserRealName: sysUserName,
  35. Sort: maxSort + 1,
  36. Level: level + 1,
  37. ModifyTime: time.Now(),
  38. CreateTime: time.Now(),
  39. }
  40. classifyId, err := data_manage.AddBaseFromMysteelChemicalClassify(classifyInfo)
  41. if err != nil {
  42. errMsg = "保存分类失败"
  43. }
  44. classifyInfo.BaseFromMysteelChemicalClassifyId = int(classifyId)
  45. return
  46. }
  47. // EditMysteelChemicalClassify 编辑钢联化工分类
  48. func EditMysteelChemicalClassify(classifyId int, classifyName string, sysUser *system.Admin) (err error, errMsg string) {
  49. item, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  50. if err != nil {
  51. errMsg = `保存失败`
  52. return
  53. }
  54. // 操作权限校验
  55. button := GetMysteelChemicalOpButton(sysUser, item.SysUserId)
  56. if !button.OpButton {
  57. errMsg = "无权限操作"
  58. return
  59. }
  60. // 名字相同,那么就直接返回
  61. if item.ClassifyName == classifyName {
  62. return
  63. }
  64. // 判断名称是否已存在
  65. count, err := data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, item.ParentId)
  66. if err != nil {
  67. errMsg = "判断名称是否已存在失败"
  68. return
  69. }
  70. if count > 0 {
  71. errMsg = "分类名称已存在,请重新输入"
  72. err = errors.New(errMsg)
  73. return
  74. }
  75. // 修改数据
  76. err = data_manage.EditBaseFromMysteelChemicalClassify(classifyId, classifyName)
  77. if err != nil {
  78. errMsg = "保存失败"
  79. }
  80. return
  81. }
  82. // MoveMysteelChemicalClassify 移动钢联化工分类
  83. func MoveMysteelChemicalClassify(classifyId, parentClassifyId, prevClassifyId, nextClassifyId int, sysUser *system.Admin) (err error, errMsg string) {
  84. //判断分类是否存在
  85. classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  86. if err != nil {
  87. errMsg = "移动失败"
  88. err = errors.New("获取分类信息失败,Err:" + err.Error())
  89. return
  90. }
  91. // 操作权限校验
  92. button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId)
  93. if !button.MoveButton {
  94. errMsg = "无权限操作"
  95. return
  96. }
  97. updateCol := make([]string, 0)
  98. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  99. if classifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
  100. parentClassifyInfo, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(parentClassifyId)
  101. if tmpErr != nil {
  102. errMsg = "移动失败"
  103. err = errors.New("获取上级分类信息失败,Err:" + tmpErr.Error())
  104. return
  105. }
  106. classifyInfo.ParentId = parentClassifyInfo.BaseFromMysteelChemicalClassifyId
  107. classifyInfo.Level = parentClassifyInfo.Level + 1
  108. classifyInfo.ModifyTime = time.Now()
  109. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  110. }
  111. //如果有传入 上一个兄弟节点分类id
  112. if prevClassifyId > 0 {
  113. prevClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(prevClassifyId)
  114. if tmpErr != nil {
  115. errMsg = "移动失败"
  116. err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  117. return
  118. }
  119. //如果是移动在两个兄弟节点之间
  120. if nextClassifyId > 0 {
  121. //下一个兄弟节点
  122. nextClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(nextClassifyId)
  123. if tmpErr != nil {
  124. errMsg = "移动失败"
  125. err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + tmpErr.Error())
  126. return
  127. }
  128. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  129. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == classifyInfo.Sort {
  130. //变更兄弟节点的排序
  131. updateSortStr := `sort + 2`
  132. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, prevClassify.BaseFromMysteelChemicalClassifyId, prevClassify.Sort, updateSortStr)
  133. } else {
  134. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  135. if nextClassify.Sort-prevClassify.Sort == 1 {
  136. //变更兄弟节点的排序
  137. updateSortStr := `sort + 1`
  138. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, 0, prevClassify.Sort, updateSortStr)
  139. }
  140. }
  141. }
  142. classifyInfo.Sort = prevClassify.Sort + 1
  143. classifyInfo.ModifyTime = time.Now()
  144. updateCol = append(updateCol, "Sort", "ModifyTime")
  145. } else {
  146. firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalClassify()
  147. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  148. errMsg = "移动失败"
  149. err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
  150. return
  151. }
  152. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  153. if firstClassify != nil && firstClassify.Sort == 0 {
  154. updateSortStr := ` sort + 1 `
  155. _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, firstClassify.BaseFromMysteelChemicalClassifyId-1, 0, updateSortStr)
  156. }
  157. classifyInfo.Sort = 0 //那就是排在第一位
  158. classifyInfo.ModifyTime = time.Now()
  159. updateCol = append(updateCol, "Sort", "ModifyTime")
  160. }
  161. //更新
  162. if len(updateCol) > 0 {
  163. err = classifyInfo.Update(updateCol)
  164. if err != nil {
  165. errMsg = "移动失败"
  166. err = errors.New("修改失败,Err:" + err.Error())
  167. return
  168. }
  169. }
  170. return
  171. }
  172. // DelMysteelChemicalClassify 删除钢联化工分类
  173. func DelMysteelChemicalClassify(classifyId int, sysUser *system.Admin) (err error, errMsg string) {
  174. //判断分类是否存在
  175. classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId)
  176. if err != nil {
  177. errMsg = "删除失败"
  178. err = errors.New("获取分类信息失败,Err:" + err.Error())
  179. return
  180. }
  181. // 操作权限校验
  182. button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId)
  183. if !button.DeleteButton {
  184. errMsg = "无权限操作"
  185. return
  186. }
  187. // 需要删除的分类id集合
  188. classifyIdList := make([]int, 0)
  189. classifyIdList = append(classifyIdList, classifyId)
  190. mysteelChemicalIndexIdList := make([]int, 0)
  191. indexCodeList := make([]string, 0)
  192. // 查找所有的子集id
  193. if classifyInfo.ParentId <= 0 {
  194. childrenClassifyInfoList, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(classifyId)
  195. if tmpErr != nil {
  196. errMsg = "删除失败"
  197. err = errors.New("获取分类信息失败,Err:" + tmpErr.Error())
  198. return
  199. }
  200. for _, v := range childrenClassifyInfoList {
  201. classifyIdList = append(classifyIdList, v.BaseFromMysteelChemicalClassifyId)
  202. }
  203. }
  204. // 获取分类下的所有指标
  205. baseFromMysteelChemicalIndexList, err := data_manage.GetBaseFromMysteelChemicalIndexListByClassifyIdList(classifyIdList)
  206. if err != nil {
  207. errMsg = "删除失败"
  208. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  209. return
  210. }
  211. for _, v := range baseFromMysteelChemicalIndexList {
  212. mysteelChemicalIndexIdList = append(mysteelChemicalIndexIdList, v.BaseFromMysteelChemicalIndexId)
  213. indexCodeList = append(indexCodeList, v.IndexCode)
  214. }
  215. // 获取已经加入到EDB指标库的钢联化工指标
  216. edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, indexCodeList)
  217. if err != nil {
  218. errMsg = "删除失败"
  219. err = errors.New("获取分类下的指标信息失败,Err:" + err.Error())
  220. return
  221. }
  222. if len(edbInfoList) > 0 {
  223. errMsg = "该分类下存在指标加入到ETA图库,无法删除"
  224. return
  225. }
  226. // 删除对应的分类和指标
  227. err = data_manage.DeleteMysteelChemicalByClassifyId(classifyIdList, mysteelChemicalIndexIdList)
  228. if err != nil {
  229. return
  230. }
  231. // 删除指标服务的excel表
  232. go func(list []*data_manage.BaseFromMysteelChemicalIndex) {
  233. for _, v := range list {
  234. CurlDelMysteelChemicalData(v.IndexCode, v.UpdateWeek)
  235. }
  236. }(baseFromMysteelChemicalIndexList)
  237. return
  238. }
  239. // AddMysteelChemicalIndex 添加钢联化工指标
  240. func AddMysteelChemicalIndex(classifyId int, indexCode, updateWeek, updateTimeStr string, sysUserId int, sysUserName string) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) {
  241. baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByCode(indexCode)
  242. if err != nil && err.Error() != utils.ErrNoRow() {
  243. errMsg = `获取数据失败`
  244. return
  245. }
  246. if baseFromMysteelChemicalIndex != nil {
  247. errMsg = `指标ID已存在,请重新输入`
  248. return
  249. }
  250. // 更新时间切割
  251. var updateTime1, updateTime2 string
  252. if updateTimeStr != `` {
  253. updateTimeList := strings.Split(updateTimeStr, ",")
  254. updateTime1 = updateTimeList[0]
  255. if len(updateTimeList) > 1 {
  256. updateTime2 = updateTimeList[1]
  257. }
  258. }
  259. baseFromMysteelChemicalIndex = &data_manage.BaseFromMysteelChemicalIndex{
  260. //BaseFromMysteelChemicalIndexId: 0,
  261. BaseFromMysteelChemicalClassifyId: classifyId,
  262. IndexCode: indexCode,
  263. IndexName: "",
  264. Unit: "",
  265. Source: "",
  266. Frequency: "",
  267. StartDate: "",
  268. EndDate: "",
  269. Describe: "",
  270. UpdateWeek: updateWeek,
  271. UpdateTime: updateTime1,
  272. UpdateTime2: updateTime2,
  273. SysUserId: sysUserId,
  274. SysUserRealName: sysUserName,
  275. ModifyTime: time.Now(),
  276. CreateTime: time.Now(),
  277. }
  278. _, err = data_manage.AddBaseFromMysteelChemicalIndex(baseFromMysteelChemicalIndex)
  279. if err != nil {
  280. errMsg = "保存分类失败"
  281. }
  282. // 调用指标服务生成excel并拉取数据
  283. go CurlAddMysteelChemicalData(indexCode, updateWeek)
  284. return
  285. }
  286. // EditMysteelChemicalIndex 编辑钢联化工指标
  287. func EditMysteelChemicalIndex(indexId, classifyId int, updateWeek, updateTimeStr string, sysUser *system.Admin) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) {
  288. baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  289. if err != nil {
  290. errMsg = `获取数据失败`
  291. if err.Error() == utils.ErrNoRow() {
  292. errMsg = `该指标未入库`
  293. err = nil
  294. }
  295. return
  296. }
  297. // 操作权限校验
  298. button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId)
  299. if !button.OpButton {
  300. errMsg = "无权限操作"
  301. return
  302. }
  303. oldUpdateWeek := baseFromMysteelChemicalIndex.UpdateWeek
  304. // 更新时间切割
  305. var updateTime1, updateTime2 string
  306. if updateTimeStr != `` {
  307. updateTimeList := strings.Split(updateTimeStr, ",")
  308. updateTime1 = updateTimeList[0]
  309. if len(updateTimeList) > 1 {
  310. updateTime2 = updateTimeList[1]
  311. }
  312. }
  313. baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId = classifyId
  314. baseFromMysteelChemicalIndex.UpdateWeek = updateWeek
  315. baseFromMysteelChemicalIndex.UpdateTime = updateTime1
  316. baseFromMysteelChemicalIndex.UpdateTime2 = updateTime2
  317. baseFromMysteelChemicalIndex.ModifyTime = time.Now()
  318. err = baseFromMysteelChemicalIndex.Update([]string{"BaseFromMysteelChemicalClassifyId", "UpdateWeek", "UpdateTime", "UpdateTime2", "ModifyTime"})
  319. if err != nil {
  320. errMsg = "保存分类失败"
  321. }
  322. go func(oldUpdateWeek string, indexInfo *data_manage.BaseFromMysteelChemicalIndex) {
  323. // 先删除excel表
  324. CurlDelMysteelChemicalData(indexInfo.IndexCode, oldUpdateWeek)
  325. // 再创建excel表
  326. CurlAddMysteelChemicalData(indexInfo.IndexCode, indexInfo.UpdateWeek)
  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. // CurlAddMysteelChemicalData 请求钢联服务器添加指标
  487. func CurlAddMysteelChemicalData(indexCode, updateWeek string) {
  488. //postUrl := `http://datamysteel.hzinsights.com:8040/api/index/create`
  489. postUrl := mysteelPostUrl + `/api/index/create`
  490. //type IndexAddReq struct {
  491. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  492. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  493. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  494. //}
  495. paramsMap := make(map[string]interface{})
  496. updateWeek = WeekMap[updateWeek]
  497. paramsMap["IndexCode"] = indexCode
  498. paramsMap["UpdateWeek"] = updateWeek
  499. paramsMap["RunMode"] = utils.RunMode
  500. paramJson, err := json.Marshal(paramsMap)
  501. if err != nil {
  502. fmt.Println("param json.Marshal Err:" + err.Error())
  503. err = errors.New("param json.Marshal Err:" + err.Error())
  504. return
  505. }
  506. utils.FileLog.Info(fmt.Sprintf("CurlAddMysteelChemicalData parms:%s", string(paramJson)))
  507. result, err := http.Post(postUrl, string(paramJson), "application/json")
  508. if err != nil {
  509. fmt.Println("post err:" + err.Error())
  510. err = errors.New("post Err:" + err.Error())
  511. return
  512. }
  513. utils.FileLog.Info("CurlAddMysteelChemicalData Result:%s", string(result))
  514. }
  515. // CurlDelMysteelChemicalData 请求钢联服务器删除指标
  516. func CurlDelMysteelChemicalData(indexCode, updateWeek string) {
  517. //postUrl := `http://datamysteel.hzinsights.com:8040/api/index/delete`
  518. postUrl := mysteelPostUrl + `/api/index/delete`
  519. //type IndexAddReq struct {
  520. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  521. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  522. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  523. //}
  524. paramsMap := make(map[string]interface{})
  525. updateWeek = WeekMap[updateWeek]
  526. paramsMap["IndexCode"] = indexCode
  527. paramsMap["UpdateWeek"] = updateWeek
  528. paramsMap["RunMode"] = utils.RunMode
  529. paramJson, err := json.Marshal(paramsMap)
  530. if err != nil {
  531. fmt.Println("param json.Marshal Err:" + err.Error())
  532. err = errors.New("param json.Marshal Err:" + err.Error())
  533. return
  534. }
  535. utils.FileLog.Info(fmt.Sprintf("CurlDelMysteelChemicalData parms:%s", string(paramJson)))
  536. result, err := http.Post(postUrl, string(paramJson), "application/json")
  537. if err != nil {
  538. fmt.Println("post err:" + err.Error())
  539. err = errors.New("post Err:" + err.Error())
  540. return
  541. }
  542. utils.FileLog.Info("CurlDelMysteelChemicalData Result:%s", string(result))
  543. }
  544. // WeekMap 中英文日期转换
  545. var WeekMap = map[string]string{
  546. "": "",
  547. "周一": "monday",
  548. "周二": "tuesday",
  549. "周三": "wednesday",
  550. "周四": "thursday",
  551. "周五": "friday",
  552. "周六": "saturday",
  553. "周日": "sunday",
  554. }
  555. // CurlAddMysteelChemicalData 请求钢联服务器添加指标
  556. func CurlRefreshMysteelChemicalData(mergeFilePath string) {
  557. //postUrl := `http://datamysteel.hzinsights.com:8040/api/index/refresh`
  558. postUrl := mysteelPostUrl + `/api/index/refresh`
  559. //type IndexAddReq struct {
  560. // IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  561. // UpdateWeek string `json:"UpdateWeek"` //更新周期
  562. // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  563. //}
  564. paramsMap := make(map[string]interface{})
  565. paramsMap["MergeFilePath"] = mergeFilePath
  566. paramJson, err := json.Marshal(paramsMap)
  567. if err != nil {
  568. fmt.Println("param json.Marshal Err:" + err.Error())
  569. err = errors.New("param json.Marshal Err:" + err.Error())
  570. return
  571. }
  572. utils.FileLog.Info(fmt.Sprintf("CurlAddMysteelChemicalData parms:%s", string(paramJson)))
  573. result, err := http.Post(postUrl, string(paramJson), "application/json")
  574. if err != nil {
  575. fmt.Println("post err:" + err.Error())
  576. err = errors.New("post Err:" + err.Error())
  577. return
  578. }
  579. utils.FileLog.Info("CurlAddMysteelChemicalData Result:%s", string(result))
  580. }