index.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package index
  2. import (
  3. "context"
  4. "hongze/mysteel_watch/global"
  5. "hongze/mysteel_watch/models/base"
  6. )
  7. // 钢联化工指标数据
  8. type BaseFromMysteelChemicalIndex struct {
  9. BaseFromMysteelChemicalIndexId int64 `gorm:"primaryKey;column:base_from_mysteel_chemical_index_id" json:"base_from_mysteel_chemical_index_id"` //序号
  10. IndexCode string `gorm:"column:index_code" json:"index_code"`
  11. IndexName string `gorm:"column:index_name" json:"index_name"`
  12. Unit string `gorm:"column:unit" json:"unit"`
  13. Source string `gorm:"column:source" json:"source"`
  14. Frequency string `gorm:"column:frequency" json:"frequency"`
  15. StartDate string `gorm:"column:start_date" json:"start_date"`
  16. EndDate string `gorm:"column:end_date" json:"end_date"`
  17. Describe string `gorm:"column:describe" json:"describe"`
  18. UpdateWeek string `gorm:"column:update_week" json:"update_week"`
  19. SysUserId int `gorm:"column:sys_user_id" json:"sys_user_id"`
  20. SysUserRealName string `gorm:"column:sys_user_real_name" json:"sys_user_real_name"`
  21. base.TimeBase
  22. }
  23. // TableName get sql table name.获取数据库表名
  24. func (r *BaseFromMysteelChemicalIndex) TableName() string {
  25. return "base_from_mysteel_chemical_index"
  26. }
  27. // 新增
  28. func (r *BaseFromMysteelChemicalIndex) Add(runMod string) (err error) {
  29. if runMod == "release" {
  30. err = global.MYSQL["hzdata"].Create(r).Error
  31. return
  32. } else {
  33. err = global.DEFAULT_MYSQL.Create(r).Error
  34. return
  35. }
  36. }
  37. // 修改
  38. func (r *BaseFromMysteelChemicalIndex) Update(runMod string, updateCols []string) (err error) {
  39. if runMod == "release" {
  40. err = global.MYSQL["hzdata"].Model(r).Select(updateCols).Updates(r).Error
  41. return
  42. } else {
  43. err = global.DEFAULT_MYSQL.Model(r).Select(updateCols).Updates(r).Error
  44. return
  45. }
  46. }
  47. type IndexAddReq struct {
  48. IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  49. UpdateWeek string `json:"UpdateWeek"` //更新周期
  50. RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期
  51. }
  52. func (d *BaseFromMysteelChemicalIndex) GetIndexItem(runMod, indexCode string) (item *BaseFromMysteelChemicalIndex, err error) {
  53. if runMod == "release" {
  54. err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).
  55. Where("index_code = ?", indexCode).First(&item).Error
  56. return
  57. } else {
  58. err = global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(d).
  59. Where("index_code = ?", indexCode).First(&item).Error
  60. return
  61. }
  62. }
  63. type IndexDeleteReq struct {
  64. IndexCode string `json:"IndexCode" binding:"required"` //指标编码
  65. }