ermcpCommon.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // DecryptField 解密字段
  22. func DecryptField(oriStr string) string {
  23. nLen := len(oriStr)
  24. if nLen < 32 || nLen%16 != 0 {
  25. // 非加密字符串
  26. return oriStr
  27. }
  28. key := "0d299ce2d4105282f7471074cb0f9f9d"
  29. key2, _ := hex.DecodeString(key)
  30. if oriStr == "" {
  31. return oriStr
  32. }
  33. d, _ := hex.DecodeString(oriStr)
  34. if dst, err := utils.AESDecrypt(d, key2); err == nil {
  35. return string(dst)
  36. }
  37. return oriStr
  38. }
  39. // DecodeStr 类似于问号表达式, true返回第1个 false返回第2个
  40. func DecodeStr(condition bool, strTrue, strFalse string) string {
  41. if condition {
  42. return strTrue
  43. }
  44. return strFalse
  45. }
  46. // InStr
  47. func InStr(param ...interface{}) string {
  48. var str string
  49. for i := range param {
  50. if len(str) > 0 {
  51. str += ","
  52. }
  53. str += fmt.Sprintf("%v", param[i])
  54. }
  55. return str
  56. }
  57. type ZOOMFUN func(vList ...*float64)
  58. // NewZoomFun 创建缩放函数
  59. func NewZoomFun(decimalplace int) ZOOMFUN {
  60. return func(vList ...*float64) {
  61. for i := range vList {
  62. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  63. }
  64. }
  65. }
  66. // ZoomByDecimal
  67. func ZoomByDecimal(decimalplace int, vList ...*float64) {
  68. for i := range vList {
  69. *vList[i] = *vList[i] / math.Pow10(decimalplace)
  70. }
  71. }