ermcpCommon.go 1.2 KB

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