| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /**
- * @Author: zou.yingbin
- * @Create : 2021/3/30 14:51
- * @Modify : 2021/3/30 14:51
- * @Note : Ermcp定义一些公共的方法或变量
- */
- package models
- import (
- "encoding/hex"
- "fmt"
- "math"
- "mtp2_if/utils"
- )
- type ReportType int
- // IErmcp 通用接口
- type IErmcp interface {
- calc() // 相关计算和数据处理
- buildSql() string // 生成sql语句
- GetDataEx() (interface{}, error) // 获取数据接口
- }
- // PageEx 分页信息
- type PageEx struct {
- Page int `json:"-" form:"page"` // 页码
- PageSize int `json:"-" form:"pagesize"` // 每页大小
- Total int `json:"-" xorm:"'TOTAL'"` // 总条数
- }
- // DecryptField 解密字段
- func DecryptField(oriStr string) string {
- nLen := len(oriStr)
- if nLen < 32 || nLen%16 != 0 {
- // 非加密字符串
- return oriStr
- }
- key := "0d299ce2d4105282f7471074cb0f9f9d"
- key2, _ := hex.DecodeString(key)
- if oriStr == "" {
- return oriStr
- }
- d, _ := hex.DecodeString(oriStr)
- if dst, err := utils.AESDecrypt(d, key2); err == nil {
- return string(dst)
- }
- return oriStr
- }
- // DecodeStr 类似于问号表达式, true返回第1个 false返回第2个
- func DecodeStr(condition bool, strTrue, strFalse string) string {
- if condition {
- return strTrue
- }
- return strFalse
- }
- // InStrBuilder 构建InStr字串
- type InStrBuilder struct {
- Value []interface{}
- }
- // Add 增加元素
- func (r *InStrBuilder) Add(v interface{}) {
- r.Value = append(r.Value, v)
- }
- // InStr 返回逗号隔开的字串
- func (r *InStrBuilder) InStr() string {
- var str string
- for _, v := range r.Value {
- if len(str) > 0 {
- str += ","
- }
- if _, ok := v.(string); ok {
- str += fmt.Sprintf("'%v'", v)
- } else {
- str += fmt.Sprintf("%v", v)
- }
- }
- return str
- }
- // InStr
- func InStr(param ...interface{}) string {
- var str string
- for i := range param {
- if len(str) > 0 {
- str += ","
- }
- str += fmt.Sprintf("%v", param[i])
- }
- return str
- }
- type ZOOMFUN func(vList ...*float64)
- // NewZoomFun 创建缩放函数
- func NewZoomFun(decimalplace int) ZOOMFUN {
- return func(vList ...*float64) {
- for i := range vList {
- *vList[i] = *vList[i] / math.Pow10(decimalplace)
- }
- }
- }
- // ZoomByDecimal
- func ZoomByDecimal(decimalplace int, vList ...*float64) {
- for i := range vList {
- *vList[i] = *vList[i] / math.Pow10(decimalplace)
- }
- }
|