ermcpCommon.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/3/30 14:51
  4. * @Modify : 2021/3/30 14:51
  5. * @Note : Ermcp定义一些公共的方法或变量
  6. */
  7. package models
  8. import (
  9. "encoding/hex"
  10. "fmt"
  11. "math"
  12. "mtp2_if/utils"
  13. )
  14. type ReportType int
  15. // IErmcp 通用接口
  16. type IErmcp interface {
  17. calc() // 相关计算和数据处理
  18. buildSql() string // 生成sql语句
  19. GetDataEx() (interface{}, error) // 获取数据接口
  20. }
  21. // PageEx 分页信息
  22. type PageEx struct {
  23. Page int `json:"-" form:"page"` // 页码
  24. PageSize int `json:"-" form:"pagesize"` // 每页大小
  25. Total int `json:"-" xorm:"'TOTAL'"` // 总条数
  26. }
  27. // DecryptField 解密字段
  28. func DecryptField(oriStr string) string {
  29. nLen := len(oriStr)
  30. if nLen < 32 || nLen%16 != 0 {
  31. // 非加密字符串
  32. return oriStr
  33. }
  34. key := "0d299ce2d4105282f7471074cb0f9f9d"
  35. key2, _ := hex.DecodeString(key)
  36. if oriStr == "" {
  37. return oriStr
  38. }
  39. d, _ := hex.DecodeString(oriStr)
  40. if dst, err := utils.AESDecrypt(d, key2); err == nil {
  41. return string(dst)
  42. }
  43. return oriStr
  44. }
  45. // DecodeStr 类似于问号表达式, true返回第1个 false返回第2个
  46. func DecodeStr(condition bool, strTrue, strFalse string) string {
  47. if condition {
  48. return strTrue
  49. }
  50. return strFalse
  51. }
  52. // InStrBuilder 构建InStr字串
  53. type InStrBuilder struct {
  54. Value []interface{}
  55. }
  56. // Add 增加元素
  57. func (r *InStrBuilder) Add(v interface{}) {
  58. r.Value = append(r.Value, v)
  59. }
  60. // InStr 返回逗号隔开的字串
  61. func (r *InStrBuilder) InStr() string {
  62. var str string
  63. for _, v := range r.Value {
  64. if len(str) > 0 {
  65. str += ","
  66. }
  67. if _, ok := v.(string); ok {
  68. str += fmt.Sprintf("'%v'", v)
  69. } else {
  70. str += fmt.Sprintf("%v", v)
  71. }
  72. }
  73. return str
  74. }
  75. // InStr
  76. func InStr(param ...interface{}) string {
  77. var str string
  78. for i := range param {
  79. if len(str) > 0 {
  80. str += ","
  81. }
  82. str += fmt.Sprintf("%v", param[i])
  83. }
  84. return str
  85. }
  86. type ZOOMFUN func(vList ...*float64)
  87. // NewZoomFun 创建缩放函数
  88. func NewZoomFun(decimalplace int) ZOOMFUN {
  89. return func(vList ...*float64) {
  90. for i := range vList {
  91. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  92. }
  93. }
  94. }
  95. // ZoomByDecimal
  96. func ZoomByDecimal(decimalplace int, vList ...*float64) {
  97. for i := range vList {
  98. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  99. }
  100. }