ermcpCommon.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // InStr
  53. func InStr(param ...interface{}) string {
  54. var str string
  55. for i := range param {
  56. if len(str) > 0 {
  57. str += ","
  58. }
  59. str += fmt.Sprintf("%v", param[i])
  60. }
  61. return str
  62. }
  63. type ZOOMFUN func(vList ...*float64)
  64. // NewZoomFun 创建缩放函数
  65. func NewZoomFun(decimalplace int) ZOOMFUN {
  66. return func(vList ...*float64) {
  67. for i := range vList {
  68. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  69. }
  70. }
  71. }
  72. // ZoomByDecimal
  73. func ZoomByDecimal(decimalplace int, vList ...*float64) {
  74. for i := range vList {
  75. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  76. }
  77. }