ermcpCommon.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "mtp2_if/utils"
  11. )
  12. type ReportType int
  13. // IErmcp 通用接口
  14. type IErmcp interface {
  15. calc() // 相关计算和数据处理
  16. buildSql() string // 生成sql语句
  17. GetDataEx() (interface{}, error) // 获取数据接口
  18. }
  19. // DecryptField 解密字段
  20. func DecryptField(oriStr string) string {
  21. nLen := len(oriStr)
  22. if nLen < 32 && nLen%2 != 0 {
  23. // 非加密字符串
  24. return oriStr
  25. }
  26. key := "0d299ce2d4105282f7471074cb0f9f9d"
  27. key2, _ := hex.DecodeString(key)
  28. if oriStr == "" {
  29. return oriStr
  30. }
  31. d, _ := hex.DecodeString(oriStr)
  32. if dst, err := utils.AESDecrypt(d, key2); err == nil {
  33. return string(dst)
  34. }
  35. return oriStr
  36. }
  37. // DecodeStr 类似于问号表达式, true返回第1个 false返回第2个
  38. func DecodeStr(condition bool, strTrue, strFalse string) string {
  39. if condition {
  40. return strTrue
  41. }
  42. return strFalse
  43. }