forked from golang/hotime
Merge remote-tracking branch 'origin/master' into rfcb
# Conflicts: # code.go
This commit is contained in:
commit
ebea14c74f
2
LICENSE
2
LICENSE
@ -142,7 +142,7 @@ any additional terms or conditions. Notwithstanding the above, nothing herein
|
|||||||
shall supersede or modify the terms of any separate license agreement you
|
shall supersede or modify the terms of any separate license agreement you
|
||||||
may have executed with Licensor regarding such Contributions.
|
may have executed with Licensor regarding such Contributions.
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names,
|
6. Trademarks. that License does not grant permission to use the trade names,
|
||||||
trademarks, service marks, or product names of the Licensor, except as required
|
trademarks, service marks, or product names of the Licensor, except as required
|
||||||
for reasonable and customary use in describing the origin of the Work and
|
for reasonable and customary use in describing the origin of the Work and
|
||||||
reproducing the content of the NOTICE file.
|
reproducing the content of the NOTICE file.
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
"./code"
|
"code.hoteas.com/golang/hotime/code"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
. "./db"
|
. "code.hoteas.com/golang/hotime/db"
|
||||||
. "./log"
|
. "code.hoteas.com/golang/hotime/log"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
@ -30,7 +30,7 @@ type Application struct {
|
|||||||
WebConnectLog *logrus.Logger
|
WebConnectLog *logrus.Logger
|
||||||
Port string //端口号
|
Port string //端口号
|
||||||
TLSPort string //ssl访问端口号
|
TLSPort string //ssl访问端口号
|
||||||
connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
connectListener []func(that *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||||
connectDbFunc func(err ...*Error) (master, slave *sql.DB)
|
connectDbFunc func(err ...*Error) (master, slave *sql.DB)
|
||||||
configPath string
|
configPath string
|
||||||
Config Map
|
Config Map
|
||||||
@ -258,12 +258,12 @@ func (that *Application) SetConfig(configPath ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输
|
// SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输
|
||||||
func (that *Application) SetConnectListener(lis func(this *Context) bool) {
|
func (that *Application) SetConnectListener(lis func(that *Context) bool) {
|
||||||
that.connectListener = append(that.connectListener, lis)
|
that.connectListener = append(that.connectListener, lis)
|
||||||
}
|
}
|
||||||
|
|
||||||
//网络错误
|
//网络错误
|
||||||
//func (this *Application) session(w http.ResponseWriter, req *http.Request) {
|
//func (that *Application) session(w http.ResponseWriter, req *http.Request) {
|
||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
2
cache/cache.go
vendored
2
cache/cache.go
vendored
@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
10
cache/cache_db.go
vendored
10
cache/cache_db.go
vendored
@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
@ -30,14 +30,14 @@ type CacheDb struct {
|
|||||||
isInit bool
|
isInit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheDb) GetError() *Error {
|
func (that *CacheDb) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheDb) SetError(err *Error) {
|
func (that *CacheDb) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *CacheDb) initDbTable() {
|
func (that *CacheDb) initDbTable() {
|
||||||
|
90
cache/cache_memory.go
vendored
90
cache/cache_memory.go
vendored
@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -17,47 +17,47 @@ type CacheMemory struct {
|
|||||||
mutex *sync.RWMutex
|
mutex *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) GetError() *Error {
|
func (that *CacheMemory) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) SetError(err *Error) {
|
func (that *CacheMemory) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Cache键只能为string类型
|
//获取Cache键只能为string类型
|
||||||
func (this *CacheMemory) get(key string) interface{} {
|
func (that *CacheMemory) get(key string) interface{} {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
if this.Map == nil {
|
if that.Map == nil {
|
||||||
this.Map = Map{}
|
that.Map = Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.Map[key] == nil {
|
if that.Map[key] == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
data := this.Map.Get(key, this.Error).(cacheData)
|
data := that.Map.Get(key, that.Error).(cacheData)
|
||||||
if this.Error.GetError() != nil {
|
if that.Error.GetError() != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.time < time.Now().Unix() {
|
if data.time < time.Now().Unix() {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) refreshMap() {
|
func (that *CacheMemory) refreshMap() {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
defer this.mutex.Unlock()
|
defer that.mutex.Unlock()
|
||||||
for key, v := range this.Map {
|
for key, v := range that.Map {
|
||||||
data := v.(cacheData)
|
data := v.(cacheData)
|
||||||
if data.time <= time.Now().Unix() {
|
if data.time <= time.Now().Unix() {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,15 +66,15 @@ func (this *CacheMemory) refreshMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//key value ,时间为时间戳
|
//key value ,时间为时间戳
|
||||||
func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
func (that *CacheMemory) set(key string, value interface{}, time int64) {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
var data cacheData
|
var data cacheData
|
||||||
|
|
||||||
if this.Map == nil {
|
if that.Map == nil {
|
||||||
this.Map = Map{}
|
that.Map = Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
dd := this.Map[key]
|
dd := that.Map[key]
|
||||||
|
|
||||||
if dd == nil {
|
if dd == nil {
|
||||||
data = cacheData{}
|
data = cacheData{}
|
||||||
@ -85,74 +85,74 @@ func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
|||||||
data.time = time
|
data.time = time
|
||||||
data.data = value
|
data.data = value
|
||||||
|
|
||||||
this.Map.Put(key, data)
|
that.Map.Put(key, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) delete(key string) {
|
func (that *CacheMemory) delete(key string) {
|
||||||
del := strings.Index(key, "*")
|
del := strings.Index(key, "*")
|
||||||
//如果通配删除
|
//如果通配删除
|
||||||
if del != -1 {
|
if del != -1 {
|
||||||
key = Substr(key, 0, del)
|
key = Substr(key, 0, del)
|
||||||
for k, _ := range this.Map {
|
for k, _ := range that.Map {
|
||||||
if strings.Index(k, key) != -1 {
|
if strings.Index(k, key) != -1 {
|
||||||
delete(this.Map, k)
|
delete(that.Map, k)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
delete(this.Map, key)
|
delete(that.Map, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
func (that *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||||
|
|
||||||
x := RandX(1, 100000)
|
x := RandX(1, 100000)
|
||||||
if x > 99950 {
|
if x > 99950 {
|
||||||
this.refreshMap()
|
that.refreshMap()
|
||||||
}
|
}
|
||||||
if this.mutex == nil {
|
if that.mutex == nil {
|
||||||
this.mutex = &sync.RWMutex{}
|
that.mutex = &sync.RWMutex{}
|
||||||
}
|
}
|
||||||
|
|
||||||
reData := &Obj{Data: nil}
|
reData := &Obj{Data: nil}
|
||||||
|
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
this.mutex.RLock()
|
that.mutex.RLock()
|
||||||
reData.Data = this.get(key)
|
reData.Data = that.get(key)
|
||||||
this.mutex.RUnlock()
|
that.mutex.RUnlock()
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
tim := time.Now().Unix()
|
tim := time.Now().Unix()
|
||||||
|
|
||||||
if len(data) == 1 && data[0] == nil {
|
if len(data) == 1 && data[0] == nil {
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
this.delete(key)
|
that.delete(key)
|
||||||
this.mutex.Unlock()
|
that.mutex.Unlock()
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) == 1 {
|
if len(data) == 1 {
|
||||||
|
|
||||||
tim = tim + this.TimeOut
|
tim = tim + that.TimeOut
|
||||||
|
|
||||||
}
|
}
|
||||||
if len(data) == 2 {
|
if len(data) == 2 {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
tempt := ObjToInt64(data[1], this.Error)
|
tempt := ObjToInt64(data[1], that.Error)
|
||||||
|
|
||||||
if tempt > tim {
|
if tempt > tim {
|
||||||
|
|
||||||
tim = tempt
|
tim = tempt
|
||||||
} else if this.Error.GetError() == nil {
|
} else if that.Error.GetError() == nil {
|
||||||
|
|
||||||
tim = tim + tempt
|
tim = tim + tempt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.mutex.Lock()
|
that.mutex.Lock()
|
||||||
this.set(key, data[0], tim)
|
that.set(key, data[0], tim)
|
||||||
this.mutex.Unlock()
|
that.mutex.Unlock()
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
}
|
}
|
||||||
|
102
cache/cache_redis.go
vendored
102
cache/cache_redis.go
vendored
@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -20,65 +20,65 @@ type CacheRedis struct {
|
|||||||
*Error
|
*Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) GetError() *Error {
|
func (that *CacheRedis) GetError() *Error {
|
||||||
|
|
||||||
return this.Error
|
return that.Error
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) SetError(err *Error) {
|
func (that *CacheRedis) SetError(err *Error) {
|
||||||
this.Error = err
|
that.Error = err
|
||||||
}
|
}
|
||||||
|
|
||||||
//唯一标志
|
//唯一标志
|
||||||
func (this *CacheRedis) GetTag() int64 {
|
func (that *CacheRedis) GetTag() int64 {
|
||||||
|
|
||||||
if this.tag == int64(0) {
|
if that.tag == int64(0) {
|
||||||
this.tag = time.Now().UnixNano()
|
that.tag = time.Now().UnixNano()
|
||||||
}
|
}
|
||||||
return this.tag
|
return that.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) reCon() bool {
|
func (that *CacheRedis) reCon() bool {
|
||||||
var err error
|
var err error
|
||||||
this.conn, err = redis.Dial("tcp", this.Host+":"+ObjToStr(this.Port))
|
that.conn, err = redis.Dial("tcp", that.Host+":"+ObjToStr(that.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.conn = nil
|
that.conn = nil
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.Pwd != "" {
|
if that.Pwd != "" {
|
||||||
_, err = this.conn.Do("AUTH", this.Pwd)
|
_, err = that.conn.Do("AUTH", that.Pwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.conn = nil
|
that.conn = nil
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (this *CacheRedis) del(key string) {
|
func (that *CacheRedis) del(key string) {
|
||||||
del := strings.Index(key, "*")
|
del := strings.Index(key, "*")
|
||||||
if del != -1 {
|
if del != -1 {
|
||||||
val, err := redis.Strings(this.conn.Do("KEYS", key))
|
val, err := redis.Strings(that.conn.Do("KEYS", key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.conn.Send("MULTI")
|
that.conn.Send("MULTI")
|
||||||
for i, _ := range val {
|
for i, _ := range val {
|
||||||
this.conn.Send("DEL", val[i])
|
that.conn.Send("DEL", val[i])
|
||||||
}
|
}
|
||||||
this.conn.Do("EXEC")
|
that.conn.Do("EXEC")
|
||||||
} else {
|
} else {
|
||||||
_, err := this.conn.Do("DEL", key)
|
_, err := that.conn.Do("DEL", key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
_, err = this.conn.Do("DEL", key)
|
_, err = that.conn.Do("DEL", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,32 +86,32 @@ func (this *CacheRedis) del(key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//key value ,时间为时间戳
|
//key value ,时间为时间戳
|
||||||
func (this *CacheRedis) set(key string, value string, time int64) {
|
func (that *CacheRedis) set(key string, value string, time int64) {
|
||||||
_, err := this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
_, err := that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
_, err = this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
_, err = that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) get(key string) *Obj {
|
func (that *CacheRedis) get(key string) *Obj {
|
||||||
reData := &Obj{}
|
reData := &Obj{}
|
||||||
var err error
|
var err error
|
||||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reData.Data = nil
|
reData.Data = nil
|
||||||
if !strings.Contains(err.Error(), "nil returned") {
|
if !strings.Contains(err.Error(), "nil returned") {
|
||||||
this.Error.SetError(err)
|
that.Error.SetError(err)
|
||||||
_, err = this.conn.Do("PING")
|
_, err = that.conn.Do("PING")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if this.reCon() {
|
if that.reCon() {
|
||||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +121,10 @@ func (this *CacheRedis) get(key string) *Obj {
|
|||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
func (that *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||||
reData := &Obj{}
|
reData := &Obj{}
|
||||||
if this.conn == nil {
|
if that.conn == nil {
|
||||||
re := this.reCon()
|
re := that.reCon()
|
||||||
if !re {
|
if !re {
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
@ -132,38 +132,38 @@ func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
|||||||
//查询缓存
|
//查询缓存
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
|
|
||||||
reData = this.get(key)
|
reData = that.get(key)
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
}
|
}
|
||||||
tim := int64(0)
|
tim := int64(0)
|
||||||
//删除缓存
|
//删除缓存
|
||||||
if len(data) == 1 && data[0] == nil {
|
if len(data) == 1 && data[0] == nil {
|
||||||
this.del(key)
|
that.del(key)
|
||||||
return reData
|
return reData
|
||||||
}
|
}
|
||||||
//添加缓存
|
//添加缓存
|
||||||
if len(data) == 1 {
|
if len(data) == 1 {
|
||||||
|
|
||||||
if this.TimeOut == 0 {
|
if that.TimeOut == 0 {
|
||||||
//this.Time = Config.GetInt64("cacheShortTime")
|
//that.Time = Config.GetInt64("cacheShortTime")
|
||||||
}
|
}
|
||||||
|
|
||||||
tim += this.TimeOut
|
tim += that.TimeOut
|
||||||
}
|
}
|
||||||
if len(data) == 2 {
|
if len(data) == 2 {
|
||||||
this.Error.SetError(nil)
|
that.Error.SetError(nil)
|
||||||
tempt := ObjToInt64(data[1], this.Error)
|
tempt := ObjToInt64(data[1], that.Error)
|
||||||
if tempt > tim {
|
if tempt > tim {
|
||||||
|
|
||||||
tim = tempt
|
tim = tempt
|
||||||
} else if this.GetError() == nil {
|
} else if that.GetError() == nil {
|
||||||
|
|
||||||
tim = tim + tempt
|
tim = tim + tempt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set(key, ObjToStr(data[0]), tim)
|
that.set(key, ObjToStr(data[0]), tim)
|
||||||
|
|
||||||
return reData
|
return reData
|
||||||
|
|
||||||
|
2
cache/type.go
vendored
2
cache/type.go
vendored
@ -1,7 +1,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CacheIns interface {
|
type CacheIns interface {
|
||||||
|
32
code.go
32
code.go
@ -1,7 +1,7 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -166,29 +166,29 @@ var TptProject = Proj{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"hotime": Ctr{
|
"hotime": Ctr{
|
||||||
"login": func(this *Context) {
|
"login": func(that *Context) {
|
||||||
hotimeName := this.RouterString[0]
|
hotimeName := that.RouterString[0]
|
||||||
name := this.Req.FormValue("name")
|
name := that.Req.FormValue("name")
|
||||||
password := this.Req.FormValue("password")
|
password := that.Req.FormValue("password")
|
||||||
if name == "" || password == "" {
|
if name == "" || password == "" {
|
||||||
this.Display(3, "参数不足")
|
that.Display(3, "参数不足")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user := this.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
user := that.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||||
if user == nil {
|
if user == nil {
|
||||||
this.Display(5, "登录失败")
|
that.Display(5, "登录失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.Session(hotimeName+"_id", user.GetCeilInt("id"))
|
that.Session(hotimeName+"_id", user.GetCeilInt("id"))
|
||||||
this.Session(hotimeName+"_name", name)
|
that.Session(hotimeName+"_name", name)
|
||||||
delete(user, "password")
|
delete(user, "password")
|
||||||
this.Display(0, user)
|
that.Display(0, user)
|
||||||
},
|
},
|
||||||
"logout": func(this *Context) {
|
"logout": func(that *Context) {
|
||||||
hotimeName := this.RouterString[0]
|
hotimeName := that.RouterString[0]
|
||||||
this.Session(hotimeName+"_id", nil)
|
that.Session(hotimeName+"_id", nil)
|
||||||
this.Session(hotimeName+"_name", nil)
|
that.Session(hotimeName+"_name", nil)
|
||||||
this.Display(0, "退出登录成功")
|
that.Display(0, "退出登录成功")
|
||||||
},
|
},
|
||||||
"info": func(that *Context) {
|
"info": func(that *Context) {
|
||||||
hotimeName := that.RouterString[0]
|
hotimeName := that.RouterString[0]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = Map{
|
var Config = Map{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"../db"
|
"code.hoteas.com/golang/hotime/db"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -3,8 +3,8 @@ package code
|
|||||||
var InitTpt = `package {{name}}
|
var InitTpt = `package {{name}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../../hotime"
|
. "code.hoteas.com/golang/hotime"
|
||||||
. "../../../hotime/common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ID = "{{id}}"
|
var ID = "{{id}}"
|
||||||
@ -14,26 +14,26 @@ var Project = Proj{
|
|||||||
//"user": UserCtr,
|
//"user": UserCtr,
|
||||||
{{tablesCtr}}
|
{{tablesCtr}}
|
||||||
"hotime":Ctr{
|
"hotime":Ctr{
|
||||||
"login": func(this *Context) {
|
"login": func(that *Context) {
|
||||||
name := this.Req.FormValue("name")
|
name := that.Req.FormValue("name")
|
||||||
password := this.Req.FormValue("password")
|
password := that.Req.FormValue("password")
|
||||||
if name == "" || password == "" {
|
if name == "" || password == "" {
|
||||||
this.Display(3, "参数不足")
|
that.Display(3, "参数不足")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user := this.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
user := that.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
||||||
if user == nil {
|
if user == nil {
|
||||||
this.Display(5, "登录失败")
|
that.Display(5, "登录失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.Session("admin_id", user.GetCeilInt("id"))
|
that.Session("admin_id", user.GetCeilInt("id"))
|
||||||
this.Session("admin_name", name)
|
that.Session("admin_name", name)
|
||||||
this.Display(0, this.SessionId)
|
that.Display(0, that.SessionId)
|
||||||
},
|
},
|
||||||
"logout": func(this *Context) {
|
"logout": func(that *Context) {
|
||||||
this.Session("admin_id", nil)
|
that.Session("admin_id", nil)
|
||||||
this.Session("admin_name", nil)
|
that.Session("admin_name", nil)
|
||||||
this.Display(0, "退出登录成功")
|
that.Display(0, "退出登录成功")
|
||||||
},
|
},
|
||||||
"info": func(that *Context) {
|
"info": func(that *Context) {
|
||||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||||
@ -69,8 +69,8 @@ var Project = Proj{
|
|||||||
var CtrTpt = `package {{name}}
|
var CtrTpt = `package {{name}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../../hotime"
|
. "code.hoteas.com/golang/hotime"
|
||||||
. "../../../hotime/common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ type ContextBase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//唯一标志
|
//唯一标志
|
||||||
func (this *ContextBase) GetTag() string {
|
func (that *ContextBase) GetTag() string {
|
||||||
|
|
||||||
if this.tag == "" {
|
if that.tag == "" {
|
||||||
this.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
that.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
||||||
}
|
}
|
||||||
return this.tag
|
return that.tag
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func StrFirstToUpper(str string) string {
|
|||||||
return strings.ToUpper(first) + other
|
return strings.ToUpper(first) + other
|
||||||
}
|
}
|
||||||
|
|
||||||
//相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||||
func StrLd(s, t string, ignoreCase bool) int {
|
func StrLd(s, t string, ignoreCase bool) int {
|
||||||
if ignoreCase {
|
if ignoreCase {
|
||||||
s = strings.ToLower(s)
|
s = strings.ToLower(s)
|
||||||
@ -142,7 +142,7 @@ func Md5(req string) string {
|
|||||||
return hex.EncodeToString(cipherStr)
|
return hex.EncodeToString(cipherStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//随机数
|
// Rand 随机数
|
||||||
func Rand(count int) int {
|
func Rand(count int) int {
|
||||||
res := Random()
|
res := Random()
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
@ -167,7 +167,7 @@ func Random() float64 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//随机数范围
|
// RandX 随机数范围
|
||||||
func RandX(small int, max int) int {
|
func RandX(small int, max int) int {
|
||||||
res := 0
|
res := 0
|
||||||
//随机对象
|
//随机对象
|
||||||
@ -219,7 +219,7 @@ func RandX(small int, max int) int {
|
|||||||
// GetDb()
|
// GetDb()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//复制返回数组
|
// DeepCopyMap 复制返回数组
|
||||||
func DeepCopyMap(value interface{}) interface{} {
|
func DeepCopyMap(value interface{}) interface{} {
|
||||||
if valueMap, ok := value.(Map); ok {
|
if valueMap, ok := value.(Map); ok {
|
||||||
newMap := make(Map)
|
newMap := make(Map)
|
||||||
@ -278,7 +278,7 @@ func DeepCopyMap(value interface{}) interface{} {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//浮点数四舍五入保留小数
|
// Round 浮点数四舍五入保留小数
|
||||||
func Round(f float64, n int) float64 {
|
func Round(f float64, n int) float64 {
|
||||||
pow10_n := math.Pow10(n)
|
pow10_n := math.Pow10(n)
|
||||||
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
|
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
|
||||||
|
@ -10,108 +10,108 @@ import (
|
|||||||
type Map map[string]interface{}
|
type Map map[string]interface{}
|
||||||
|
|
||||||
//获取string
|
//获取string
|
||||||
func (this Map) GetString(key string, err ...*Error) string {
|
func (that Map) GetString(key string, err ...*Error) string {
|
||||||
|
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
err[0].SetError(nil)
|
err[0].SetError(nil)
|
||||||
}
|
}
|
||||||
return ObjToStr((this)[key])
|
return ObjToStr((that)[key])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Map) Pointer() *Map {
|
func (that *Map) Pointer() *Map {
|
||||||
|
|
||||||
return this
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加接口
|
//增加接口
|
||||||
func (this Map) Put(key string, value interface{}) {
|
func (that Map) Put(key string, value interface{}) {
|
||||||
//if this==nil{
|
//if that==nil{
|
||||||
// this=Map{}
|
// that=Map{}
|
||||||
//}
|
//}
|
||||||
this[key] = value
|
that[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除接口
|
//删除接口
|
||||||
func (this Map) Delete(key string) {
|
func (that Map) Delete(key string) {
|
||||||
delete(this, key)
|
delete(that, key)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
//获取Int
|
||||||
func (this Map) GetInt(key string, err ...*Error) int {
|
func (that Map) GetInt(key string, err ...*Error) int {
|
||||||
v := ObjToInt((this)[key], err...)
|
v := ObjToInt((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
//获取Int
|
||||||
func (this Map) GetInt64(key string, err ...*Error) int64 {
|
func (that Map) GetInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToInt64((this)[key], err...)
|
v := ObjToInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int64
|
//获取向上取整Int64
|
||||||
func (this Map) GetCeilInt64(key string, err ...*Error) int64 {
|
func (that Map) GetCeilInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToCeilInt64((this)[key], err...)
|
v := ObjToCeilInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int
|
//获取向上取整Int
|
||||||
func (this Map) GetCeilInt(key string, err ...*Error) int {
|
func (that Map) GetCeilInt(key string, err ...*Error) int {
|
||||||
v := ObjToCeilInt((this)[key], err...)
|
v := ObjToCeilInt((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整float64
|
//获取向上取整float64
|
||||||
func (this Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
||||||
v := ObjToCeilFloat64((this)[key], err...)
|
v := ObjToCeilFloat64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Float64
|
//获取Float64
|
||||||
func (this Map) GetFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetFloat64(key string, err ...*Error) float64 {
|
||||||
|
|
||||||
v := ObjToFloat64((this)[key], err...)
|
v := ObjToFloat64((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetSlice(key string, err ...*Error) Slice {
|
func (that Map) GetSlice(key string, err ...*Error) Slice {
|
||||||
|
|
||||||
//var v Slice
|
//var v Slice
|
||||||
v := ObjToSlice((this)[key], err...)
|
v := ObjToSlice((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
func (this Map) GetBool(key string, err ...*Error) bool {
|
func (that Map) GetBool(key string, err ...*Error) bool {
|
||||||
|
|
||||||
//var v Slice
|
//var v Slice
|
||||||
v := ObjToBool((this)[key], err...)
|
v := ObjToBool((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) GetMap(key string, err ...*Error) Map {
|
func (that Map) GetMap(key string, err ...*Error) Map {
|
||||||
//var data Slice
|
//var data Slice
|
||||||
|
|
||||||
v := ObjToMap((this)[key], err...)
|
v := ObjToMap((that)[key], err...)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) Get(key string, err ...*Error) interface{} {
|
func (that Map) Get(key string, err ...*Error) interface{} {
|
||||||
|
|
||||||
if v, ok := (this)[key]; ok {
|
if v, ok := (that)[key]; ok {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
e := errors.New("没有存储key及对应的数据")
|
e := errors.New("没有存储key及对应的数据")
|
||||||
@ -124,10 +124,10 @@ func (this Map) Get(key string, err ...*Error) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//请传递指针过来
|
//请传递指针过来
|
||||||
func (this Map) ToStruct(stct interface{}) {
|
func (that Map) ToStruct(stct interface{}) {
|
||||||
|
|
||||||
data := reflect.ValueOf(stct).Elem()
|
data := reflect.ValueOf(stct).Elem()
|
||||||
for k, v := range this {
|
for k, v := range that {
|
||||||
ks := StrFirstToUpper(k)
|
ks := StrFirstToUpper(k)
|
||||||
dkey := data.FieldByName(ks)
|
dkey := data.FieldByName(ks)
|
||||||
if !dkey.IsValid() {
|
if !dkey.IsValid() {
|
||||||
@ -135,13 +135,13 @@ func (this Map) ToStruct(stct interface{}) {
|
|||||||
}
|
}
|
||||||
switch dkey.Type().String() {
|
switch dkey.Type().String() {
|
||||||
case "int":
|
case "int":
|
||||||
dkey.SetInt(this.GetInt64(k))
|
dkey.SetInt(that.GetInt64(k))
|
||||||
case "int64":
|
case "int64":
|
||||||
dkey.Set(reflect.ValueOf(this.GetInt64(k)))
|
dkey.Set(reflect.ValueOf(that.GetInt64(k)))
|
||||||
case "float64":
|
case "float64":
|
||||||
dkey.Set(reflect.ValueOf(this.GetFloat64(k)))
|
dkey.Set(reflect.ValueOf(that.GetFloat64(k)))
|
||||||
case "string":
|
case "string":
|
||||||
dkey.Set(reflect.ValueOf(this.GetString(k)))
|
dkey.Set(reflect.ValueOf(that.GetString(k)))
|
||||||
case "interface{}":
|
case "interface{}":
|
||||||
dkey.Set(reflect.ValueOf(v))
|
dkey.Set(reflect.ValueOf(v))
|
||||||
}
|
}
|
||||||
@ -149,13 +149,13 @@ func (this Map) ToStruct(stct interface{}) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) ToJsonString() string {
|
func (that Map) ToJsonString() string {
|
||||||
return ObjToStr(this)
|
return ObjToStr(that)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
|
func (that Map) JsonToMap(jsonStr string, err ...*Error) {
|
||||||
e := json.Unmarshal([]byte(jsonStr), &this)
|
e := json.Unmarshal([]byte(jsonStr), &that)
|
||||||
if e != nil && len(err) != 0 {
|
if e != nil && len(err) != 0 {
|
||||||
err[0].SetError(e)
|
err[0].SetError(e)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
. "./db"
|
. "code.hoteas.com/golang/hotime/db"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"../cache"
|
"code.hoteas.com/golang/hotime/cache"
|
||||||
. "../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -165,7 +165,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
|
|
||||||
//
|
//
|
||||||
////code=0,1,2 0 backup all,1 backup data,2 backup ddl
|
////code=0,1,2 0 backup all,1 backup data,2 backup ddl
|
||||||
//func (this *HoTimeDB) Backup(path string, code int) {
|
//func (that *HoTimeDB) Backup(path string, code int) {
|
||||||
// var cmd *exec.Cmd
|
// var cmd *exec.Cmd
|
||||||
// switch code {
|
// switch code {
|
||||||
// case 0:cmd= exec.Command("mysqldump","-h"+ObjToStr(Config["dbHost"]), "-P"+ObjToStr(Config["dbPort"]),"-u"+ObjToStr(Config["dbUser"]), "-p"+ObjToStr(Config["dbPwd"]),ObjToStr(Config["dbName"]))
|
// case 0:cmd= exec.Command("mysqldump","-h"+ObjToStr(Config["dbHost"]), "-P"+ObjToStr(Config["dbPort"]),"-u"+ObjToStr(Config["dbUser"]), "-p"+ObjToStr(Config["dbPwd"]),ObjToStr(Config["dbName"]))
|
||||||
@ -197,7 +197,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
// //db := ``
|
// //db := ``
|
||||||
// //fmt.Println(db)
|
// //fmt.Println(db)
|
||||||
// //
|
// //
|
||||||
// //tables := this.Query("show tables")
|
// //tables := that.Query("show tables")
|
||||||
// //lth := len(tables)
|
// //lth := len(tables)
|
||||||
// //if lth == 0 {
|
// //if lth == 0 {
|
||||||
// // return
|
// // return
|
||||||
@ -212,7 +212,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
|||||||
// //
|
// //
|
||||||
// //for i := 0; i < lth; i++ {
|
// //for i := 0; i < lth; i++ {
|
||||||
// // tt := tables[i]["Tables_in_"+db].(string)
|
// // tt := tables[i]["Tables_in_"+db].(string)
|
||||||
// // this.backupSave(path, tt, code)
|
// // that.backupSave(path, tt, code)
|
||||||
// // debug.FreeOSMemory()
|
// // debug.FreeOSMemory()
|
||||||
// //}
|
// //}
|
||||||
//
|
//
|
||||||
@ -383,7 +383,7 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
|||||||
return resl, that.LastErr
|
return resl, that.LastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (this *HoTimeDB)copy(data []Map)[]Map{
|
//func (that *HoTimeDB)copy(data []Map)[]Map{
|
||||||
// if data==nil{
|
// if data==nil{
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
@ -836,7 +836,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
|||||||
return where, res
|
return where, res
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.Db.Update("user",hotime.Map{"ustate":"1"},hotime.Map{"AND":hotime.Map{"OR":hotime.Map{"uid":4,"uname":"dasda"}},"ustate":1})
|
// that.Db.Update("user",hotime.Map{"ustate":"1"},hotime.Map{"AND":hotime.Map{"OR":hotime.Map{"uid":4,"uname":"dasda"}},"ustate":1})
|
||||||
func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interface{}) (string, []interface{}) {
|
func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interface{}) (string, []interface{}) {
|
||||||
//where:=""
|
//where:=""
|
||||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||||
|
@ -1,53 +1,55 @@
|
|||||||
package aliyun
|
package aliyun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
//"fmt"
|
//"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Company struct {
|
type company struct {
|
||||||
ApiCode string
|
ApiCode string
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Company) Init(apiCode string) {
|
var Company = company{}
|
||||||
|
|
||||||
|
func (that *company) Init(apiCode string) {
|
||||||
//"06c6a07e89dd45c88de040ee1489eef7"
|
//"06c6a07e89dd45c88de040ee1489eef7"
|
||||||
this.ApiCode = apiCode
|
that.ApiCode = apiCode
|
||||||
this.Url = "http://api.81api.com"
|
that.Url = "http://api.81api.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCompanyBaseInfo 获取企业基础信息
|
// GetCompanyOtherAll 获取企业基础信息
|
||||||
func (this *Company) GetCompanyOtherAll(name string) Map {
|
func (that *company) GetCompanyOtherAll(name string) Map {
|
||||||
|
|
||||||
res := Map{}
|
res := Map{}
|
||||||
data, e := this.GetCompanyPatentsInfo(name) //获取专利信息
|
data, e := that.GetCompanyPatentsInfo(name) //获取专利信息
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println(e)
|
fmt.Println(e)
|
||||||
} else {
|
} else {
|
||||||
res["PatentsInfo"] = data.GetMap("data")
|
res["PatentsInfo"] = data.GetMap("data")
|
||||||
}
|
}
|
||||||
data, e = this.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
|
data, e = that.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println(e)
|
fmt.Println(e)
|
||||||
} else {
|
} else {
|
||||||
res["OtherCopyrightsInfo"] = data.GetMap("data")
|
res["OtherCopyrightsInfo"] = data.GetMap("data")
|
||||||
}
|
}
|
||||||
data, e = this.GetCompanyTrademarksInfo(name) //获取商标
|
data, e = that.GetCompanyTrademarksInfo(name) //获取商标
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println(e)
|
fmt.Println(e)
|
||||||
} else {
|
} else {
|
||||||
res["TrademarksInfo"] = data.GetMap("data")
|
res["TrademarksInfo"] = data.GetMap("data")
|
||||||
}
|
}
|
||||||
data, e = this.GetCompanySoftwareCopyrightsInfo(name) //获取软著
|
data, e = that.GetCompanySoftwareCopyrightsInfo(name) //获取软著
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println(e)
|
fmt.Println(e)
|
||||||
} else {
|
} else {
|
||||||
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
|
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
|
||||||
}
|
}
|
||||||
data, e = this.GetCompanyProfileTags(name) //获取大数据标签
|
data, e = that.GetCompanyProfileTags(name) //获取大数据标签
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println(e)
|
fmt.Println(e)
|
||||||
} else {
|
} else {
|
||||||
@ -57,63 +59,63 @@ func (this *Company) GetCompanyOtherAll(name string) Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCompanyBaseInfo 获取企业基础信息
|
// GetCompanyBaseInfo 获取企业基础信息
|
||||||
func (this *Company) GetCompanyBaseInfo(name string) (Map, error) {
|
func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
|
||||||
url := "/getCompanyBaseInfo/"
|
url := "/getCompanyBaseInfo/"
|
||||||
|
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCompanyPatentsInfo 获取专利信息
|
// GetCompanyPatentsInfo 获取专利信息
|
||||||
func (this *Company) GetCompanyPatentsInfo(name string) (Map, error) {
|
func (that *company) GetCompanyPatentsInfo(name string) (Map, error) {
|
||||||
url := "/getCompanyPatentsInfo/"
|
url := "/getCompanyPatentsInfo/"
|
||||||
|
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取商标信息
|
// GetCompanyTrademarksInfo 获取商标信息
|
||||||
func (this *Company) GetCompanyTrademarksInfo(name string) (Map, error) {
|
func (that *company) GetCompanyTrademarksInfo(name string) (Map, error) {
|
||||||
url := "/getCompanyTrademarksInfo/"
|
url := "/getCompanyTrademarksInfo/"
|
||||||
|
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取软著信息
|
// GetCompanySoftwareCopyrightsInfo 获取软著信息
|
||||||
func (this *Company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
|
func (that *company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
|
||||||
url := "/getCompanySoftwareCopyrightsInfo/"
|
url := "/getCompanySoftwareCopyrightsInfo/"
|
||||||
|
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取其他著作信息
|
// GetCompanyOtherCopyrightsInfo 获取其他著作信息
|
||||||
func (this *Company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
|
func (that *company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
|
||||||
url := "/getCompanyOtherCopyrightsInfo/"
|
url := "/getCompanyOtherCopyrightsInfo/"
|
||||||
|
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取大数据标签
|
// GetCompanyProfileTags 获取大数据标签
|
||||||
func (this *Company) GetCompanyProfileTags(name string) (Map, error) {
|
func (that *company) GetCompanyProfileTags(name string) (Map, error) {
|
||||||
url := "/getCompanyProfileTags/"
|
url := "/getCompanyProfileTags/"
|
||||||
body, err := this.basePost(url, name)
|
body, err := that.basePost(url, name)
|
||||||
return ObjToMap(body), err
|
return ObjToMap(body), err
|
||||||
}
|
}
|
||||||
func (this *Company) basePost(url string, name string) (string, error) {
|
func (that *company) basePost(url string, name string) (string, error) {
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
reqest, err := http.NewRequest("GET", this.Url+url+name+"/?isRaiseErrorCode=1", nil)
|
reqest, err := http.NewRequest("GET", that.Url+url+name+"/?isRaiseErrorCode=1", nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Fatal error ", err.Error())
|
fmt.Println("Fatal error ", err.Error())
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
reqest.Header.Add("Authorization", "APPCODE "+this.ApiCode)
|
reqest.Header.Add("Authorization", "APPCODE "+that.ApiCode)
|
||||||
response, err := client.Do(reqest)
|
response, err := client.Do(reqest)
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
@ -130,9 +132,3 @@ func (this *Company) basePost(url string, name string) (string, error) {
|
|||||||
fmt.Println(res)
|
fmt.Println(res)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultCompany Company
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
DefaultCompany = Company{}
|
|
||||||
}
|
|
||||||
|
@ -7,26 +7,28 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaiduMap struct {
|
type baiduMap struct {
|
||||||
Ak string
|
Ak string
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BaiduMap) Init(Ak string) {
|
var BaiDuMap = baiduMap{}
|
||||||
|
|
||||||
|
func (that *baiduMap) Init(Ak string) {
|
||||||
//"ak=ZeT902EZvVgIoGVWEFK3osUm"
|
//"ak=ZeT902EZvVgIoGVWEFK3osUm"
|
||||||
this.Ak = Ak
|
that.Ak = Ak
|
||||||
this.Url = "https://api.map.baidu.com/place/v2/suggestion?output=json" + "&ak=" + Ak
|
that.Url = "https://api.map.baidu.com/place/v2/suggestion?output=json" + "&ak=" + Ak
|
||||||
//query
|
//query
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPosition 获取定位列表
|
// GetPosition 获取定位列表
|
||||||
func (this *BaiduMap) GetPosition(name string, region string) (string, error) {
|
func (that *baiduMap) GetPosition(name string, region string) (string, error) {
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
if region == "" {
|
if region == "" {
|
||||||
region = "全国"
|
region = "全国"
|
||||||
}
|
}
|
||||||
reqest, err := http.NewRequest("GET", this.Url+"&query="+url.PathEscape(name)+"®ion="+url.PathEscape(region), nil)
|
reqest, err := http.NewRequest("GET", that.Url+"&query="+url.PathEscape(name)+"®ion="+url.PathEscape(region), nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Fatal error ", err.Error())
|
fmt.Println("Fatal error ", err.Error())
|
||||||
@ -50,9 +52,3 @@ func (this *BaiduMap) GetPosition(name string, region string) (string, error) {
|
|||||||
return string(body), err
|
return string(body), err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultBaiDuMap BaiduMap
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
DefaultBaiDuMap = BaiduMap{}
|
|
||||||
}
|
|
||||||
|
@ -10,29 +10,31 @@ import (
|
|||||||
//"fmt"
|
//"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DDY struct {
|
type dingdongyun struct {
|
||||||
ApiKey string
|
ApiKey string
|
||||||
YzmUrl string
|
YzmUrl string
|
||||||
TzUrl string
|
TzUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DDY) Init(apikey string) {
|
var DDY = dingdongyun{}
|
||||||
this.ApiKey = apikey
|
|
||||||
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
func (that *dingdongyun) Init(apikey string) {
|
||||||
this.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
that.ApiKey = apikey
|
||||||
|
that.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
||||||
|
that.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
// SendYZM 发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
||||||
func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
func (that *dingdongyun) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.send(this.YzmUrl, umoblie, tpt)
|
return that.send(that.YzmUrl, umoblie, tpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送通知
|
// SendTz 发送通知
|
||||||
func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
|
func (that *dingdongyun) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||||
}
|
}
|
||||||
@ -44,14 +46,14 @@ func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (b
|
|||||||
}
|
}
|
||||||
umobleStr += "," + v
|
umobleStr += "," + v
|
||||||
}
|
}
|
||||||
return this.send(this.TzUrl, umobleStr, tpt)
|
return that.send(that.TzUrl, umobleStr, tpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送短信
|
//发送短信
|
||||||
func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error) {
|
func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool, error) {
|
||||||
|
|
||||||
data_send_sms_yzm := url.Values{"apikey": {this.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
data_send_sms_yzm := url.Values{"apikey": {that.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
||||||
res, err := this.httpsPostForm(mUrl, data_send_sms_yzm)
|
res, err := that.httpsPostForm(mUrl, data_send_sms_yzm)
|
||||||
if err != nil && res == "" {
|
if err != nil && res == "" {
|
||||||
return false, errors.New("连接错误")
|
return false, errors.New("连接错误")
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//调用url发送短信的连接
|
//调用url发送短信的连接
|
||||||
func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
|
func (that *dingdongyun) httpsPostForm(url string, data url.Values) (string, error) {
|
||||||
resp, err := http.PostForm(url, data)
|
resp, err := http.PostForm(url, data)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,9 +91,3 @@ func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
|
|||||||
return string(body), nil
|
return string(body), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultDDY DDY
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
DefaultDDY = DDY{}
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package download
|
package download
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
//下载文件
|
// Down 下载文件
|
||||||
func Down(url, path, name string, e ...*Error) bool {
|
func Down(url, path, name string, e ...*Error) bool {
|
||||||
|
|
||||||
os.MkdirAll(path, os.ModeDir)
|
os.MkdirAll(path, os.ModeDir)
|
||||||
|
@ -23,7 +23,7 @@ func FileGet(path string) []byte {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
//RSA加密
|
// RSA_Encrypt RSA加密
|
||||||
// plainText 要加密的数据
|
// plainText 要加密的数据
|
||||||
// path 公钥匙文件地址
|
// path 公钥匙文件地址
|
||||||
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
||||||
@ -46,7 +46,7 @@ func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
|||||||
return cipherText
|
return cipherText
|
||||||
}
|
}
|
||||||
|
|
||||||
//RSA解密
|
// RSA_Decrypt RSA解密
|
||||||
// cipherText 需要解密的byte数据
|
// cipherText 需要解密的byte数据
|
||||||
// path 私钥文件路径
|
// path 私钥文件路径
|
||||||
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
|
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
|
||||||
@ -97,7 +97,7 @@ func Demo() {
|
|||||||
fmt.Println(string(decrypt))
|
fmt.Println(string(decrypt))
|
||||||
}
|
}
|
||||||
|
|
||||||
//生成RSA私钥和公钥,保存到文件中
|
// GenerateRSAKey 生成RSA私钥和公钥,保存到文件中
|
||||||
// bits 证书大小
|
// bits 证书大小
|
||||||
func GenerateRSAKey(bits int, path string) {
|
func GenerateRSAKey(bits int, path string) {
|
||||||
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
|
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package tencent
|
package tencent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@ -15,24 +15,40 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func calcAuthorization(source string, secretId string, secretKey string) (auth string, datetime string, err error) {
|
type company struct {
|
||||||
|
secretId string
|
||||||
|
secretKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Company = company{}
|
||||||
|
|
||||||
|
func (that *company) Init(secretId, secretKey string) {
|
||||||
|
// 云市场分配的密钥Id
|
||||||
|
//secretId := "xxxx"
|
||||||
|
//// 云市场分配的密钥Key
|
||||||
|
//secretKey := "xxxx"
|
||||||
|
that.secretId = secretId
|
||||||
|
that.secretKey = secretKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *company) calcAuthorization(source string) (auth string, datetime string, err error) {
|
||||||
|
|
||||||
timeLocation, _ := time.LoadLocation("Etc/GMT")
|
timeLocation, _ := time.LoadLocation("Etc/GMT")
|
||||||
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
|
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
|
||||||
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
|
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
|
||||||
|
|
||||||
// hmac-sha1
|
// hmac-sha1
|
||||||
mac := hmac.New(sha1.New, []byte(secretKey))
|
mac := hmac.New(sha1.New, []byte(that.secretKey))
|
||||||
mac.Write([]byte(signStr))
|
mac.Write([]byte(signStr))
|
||||||
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
|
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
|
||||||
secretId, sign)
|
that.secretId, sign)
|
||||||
|
|
||||||
return auth, datetime, nil
|
return auth, datetime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func urlencode(params map[string]string) string {
|
func (that *company) urlencode(params map[string]string) string {
|
||||||
var p = gourl.Values{}
|
var p = gourl.Values{}
|
||||||
for k, v := range params {
|
for k, v := range params {
|
||||||
p.Add(k, v)
|
p.Add(k, v)
|
||||||
@ -40,7 +56,7 @@ func urlencode(params map[string]string) string {
|
|||||||
return p.Encode()
|
return p.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCompany(secretId, secretKey, name string) Map {
|
func (that *company) GetCompany(name string) Map {
|
||||||
// 云市场分配的密钥Id
|
// 云市场分配的密钥Id
|
||||||
//secretId := "xxxx"
|
//secretId := "xxxx"
|
||||||
//// 云市场分配的密钥Key
|
//// 云市场分配的密钥Key
|
||||||
@ -48,7 +64,7 @@ func GetCompany(secretId, secretKey, name string) Map {
|
|||||||
source := "market"
|
source := "market"
|
||||||
|
|
||||||
// 签名
|
// 签名
|
||||||
auth, datetime, _ := calcAuthorization(source, secretId, secretKey)
|
auth, datetime, _ := that.calcAuthorization(source)
|
||||||
|
|
||||||
// 请求方法
|
// 请求方法
|
||||||
method := "GET"
|
method := "GET"
|
||||||
@ -64,13 +80,13 @@ func GetCompany(secretId, secretKey, name string) Map {
|
|||||||
// url参数拼接
|
// url参数拼接
|
||||||
url := "https://service-3jnh3ku8-1256140209.gz.apigw.tencentcs.com/release/business4/geet"
|
url := "https://service-3jnh3ku8-1256140209.gz.apigw.tencentcs.com/release/business4/geet"
|
||||||
if len(queryParams) > 0 {
|
if len(queryParams) > 0 {
|
||||||
url = fmt.Sprintf("%s?%s", url, urlencode(queryParams))
|
url = fmt.Sprintf("%s?%s", url, that.urlencode(queryParams))
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
|
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
|
||||||
var body io.Reader = nil
|
var body io.Reader = nil
|
||||||
if bodyMethods[method] {
|
if bodyMethods[method] {
|
||||||
body = strings.NewReader(urlencode(bodyParams))
|
body = strings.NewReader(that.urlencode(bodyParams))
|
||||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,16 +8,32 @@ import (
|
|||||||
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
||||||
)
|
)
|
||||||
|
|
||||||
var credential = common.NewCredential(
|
type tencent struct {
|
||||||
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
|
secretId string
|
||||||
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
|
secretKey string
|
||||||
)
|
credential *common.Credential
|
||||||
|
}
|
||||||
|
|
||||||
func OCRCOMPANY(base64Str string) string {
|
var Tencent = tencent{}
|
||||||
|
|
||||||
|
func (that *tencent) Init(secretId, secretKey string) {
|
||||||
|
// 云市场分配的密钥Id
|
||||||
|
//secretId := "xxxx"
|
||||||
|
//// 云市场分配的密钥Key
|
||||||
|
//secretKey := "xxxx"
|
||||||
|
that.secretId = secretId
|
||||||
|
that.secretKey = secretKey
|
||||||
|
that.credential = common.NewCredential(
|
||||||
|
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
|
||||||
|
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *tencent) OCRCOMPANY(base64Str string) string {
|
||||||
|
|
||||||
cpf := profile.NewClientProfile()
|
cpf := profile.NewClientProfile()
|
||||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
request := ocr.NewBizLicenseOCRRequest()
|
request := ocr.NewBizLicenseOCRRequest()
|
||||||
|
|
||||||
@ -38,11 +54,11 @@ func OCRCOMPANY(base64Str string) string {
|
|||||||
return response.ToJsonString()
|
return response.ToJsonString()
|
||||||
}
|
}
|
||||||
|
|
||||||
func OCR(base64Str string) string {
|
func (that *tencent) OCR(base64Str string) string {
|
||||||
|
|
||||||
cpf := profile.NewClientProfile()
|
cpf := profile.NewClientProfile()
|
||||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
request := ocr.NewGeneralAccurateOCRRequest()
|
request := ocr.NewGeneralAccurateOCRRequest()
|
||||||
|
|
||||||
@ -63,11 +79,11 @@ func OCR(base64Str string) string {
|
|||||||
return response.ToJsonString()
|
return response.ToJsonString()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Qrcode(base64Str string) string {
|
func (that *tencent) Qrcode(base64Str string) string {
|
||||||
|
|
||||||
cpf := profile.NewClientProfile()
|
cpf := profile.NewClientProfile()
|
||||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||||
|
|
||||||
request := ocr.NewQrcodeOCRRequest()
|
request := ocr.NewQrcodeOCRRequest()
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package upload
|
package upload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "../../common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@ -15,7 +15,7 @@ type Upload struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
func (that *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
||||||
Request.ParseMultipartForm(32 << 20)
|
Request.ParseMultipartForm(32 << 20)
|
||||||
var filePath string
|
var filePath string
|
||||||
files := Request.MultipartForm.File
|
files := Request.MultipartForm.File
|
||||||
@ -36,7 +36,7 @@ func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
|||||||
data := time.Unix(int64(t), 0).Format("2006-01")
|
data := time.Unix(int64(t), 0).Format("2006-01")
|
||||||
path := ""
|
path := ""
|
||||||
if strings.EqualFold(savefilepath, "") {
|
if strings.EqualFold(savefilepath, "") {
|
||||||
path = this.Path + data
|
path = that.Path + data
|
||||||
} else {
|
} else {
|
||||||
path = savefilepath + data
|
path = savefilepath + data
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + ObjToStr(Rand(6))
|
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + ObjToStr(Rand(6))
|
||||||
filePath = path + "/" + filename + this.Path
|
filePath = path + "/" + filename + that.Path
|
||||||
} else {
|
} else {
|
||||||
filePath = savePath
|
filePath = savePath
|
||||||
}
|
}
|
||||||
|
@ -1,535 +0,0 @@
|
|||||||
package admin
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../common"
|
|
||||||
"fmt"
|
|
||||||
"github.com/chain-zhang/pinyin"
|
|
||||||
"github.com/xuri/excelize"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
var CompanyInOutCtr = Ctr{
|
|
||||||
|
|
||||||
"upload": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//orgId := 1
|
|
||||||
//读取网络文件
|
|
||||||
fi, fheader, err := this.Req.FormFile("file")
|
|
||||||
if err != nil {
|
|
||||||
this.Display(3, err)
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
filePath := this.Config.GetString("filePath")
|
|
||||||
if filePath == "" {
|
|
||||||
filePath = "excel/2006/01/02/"
|
|
||||||
}
|
|
||||||
|
|
||||||
path := time.Now().Format(filePath)
|
|
||||||
e := os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
this.Display(3, e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
|
||||||
newFile, e := os.Create(this.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
this.Display(3, e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, e = io.Copy(newFile, fi)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
this.Display(3, e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//this.Display(0, filePath)
|
|
||||||
|
|
||||||
//读取excel
|
|
||||||
//fmt.Println(Org[orgId],OrgId)
|
|
||||||
data := excel(this.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
if len(data) != 1 {
|
|
||||||
this.Display(3, "表格不标准,请重新提交")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = decodeData2Sql(data[0], this, orgId)
|
|
||||||
if err != nil {
|
|
||||||
this.Display(4, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, "上传成功")
|
|
||||||
|
|
||||||
},
|
|
||||||
"analyse": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
companys := this.Db.Select("company", "*", Map{"org_id": orgId})
|
|
||||||
|
|
||||||
for _, v := range companys {
|
|
||||||
|
|
||||||
data := Org[orgId].analyse(v.GetMap("upload_data"))
|
|
||||||
for k, _ := range data {
|
|
||||||
data[k] = data.GetFloat64(k)
|
|
||||||
}
|
|
||||||
v["analyse"] = data
|
|
||||||
}
|
|
||||||
|
|
||||||
cs := Org[orgId].analyseSort(companys)
|
|
||||||
for _, v := range cs {
|
|
||||||
as := v.GetMap("analyse")
|
|
||||||
//v["analyse"] = as.ToJsonString()
|
|
||||||
switch as.GetString("PJ") {
|
|
||||||
case "A":
|
|
||||||
v["level"] = 0
|
|
||||||
case "B":
|
|
||||||
v["level"] = 1
|
|
||||||
case "C":
|
|
||||||
v["level"] = 2
|
|
||||||
case "D":
|
|
||||||
v["level"] = 3
|
|
||||||
}
|
|
||||||
v["score"] = as.GetFloat64("ZDF")
|
|
||||||
|
|
||||||
this.Db.Update("company", Map{"analyse": as.ToJsonString(), "level": v["level"], "score": v["score"]}, Map{"id": v.GetCeilInt("id")})
|
|
||||||
this.Db.Update("company_history", Map{"analyse": as.ToJsonString(), "level": v["level"], "score": v["score"]}, Map{"id": v.GetCeilInt("company_history_id")})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, len(companys))
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
"total_analyse": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
companys := this.Db.Select("company", "*", Map{"AND": Map{"org_id": orgId}})
|
|
||||||
|
|
||||||
home_data, six_item_data, three_item_data, n_item_data := totalAnalyse(companys)
|
|
||||||
|
|
||||||
org := this.Db.Get("org", "*", Map{"id": orgId})
|
|
||||||
fmt.Println(six_item_data)
|
|
||||||
|
|
||||||
data := Map{
|
|
||||||
"name": org.GetString("name"),
|
|
||||||
"home_data": home_data.ToJsonString(),
|
|
||||||
"six_item_data": six_item_data.ToJsonString(),
|
|
||||||
"three_item_data": three_item_data.ToJsonString(),
|
|
||||||
"n_item_data": n_item_data.ToJsonString(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
}
|
|
||||||
org_analyse := this.Db.Get("org_analyse", "id", Map{"org_id": orgId})
|
|
||||||
if org_analyse == nil {
|
|
||||||
//data["name"] = time.Now().Format("2006-01-02 15:04") + "创建"
|
|
||||||
data["name"] = org.GetString("name")
|
|
||||||
data["org_id"] = orgId
|
|
||||||
data["create_time"] = time.Now().Unix()
|
|
||||||
id := this.Db.Insert("org_analyse", data)
|
|
||||||
data["id"] = id
|
|
||||||
} else {
|
|
||||||
this.Db.Update("org_analyse", data, Map{"org_id": orgId})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, data)
|
|
||||||
|
|
||||||
},
|
|
||||||
//
|
|
||||||
//"category_analyse": func(this *Context) {
|
|
||||||
//
|
|
||||||
// orgId := 1
|
|
||||||
// org := this.Db.Get("org", "*", Map{"id": orgId})
|
|
||||||
// categoryIDS := []int{
|
|
||||||
// 1369, //电子行业
|
|
||||||
// 799, //航空航天
|
|
||||||
// 481, //生物医药
|
|
||||||
// 990, //绿色能源
|
|
||||||
// 972, //机械制造
|
|
||||||
// 1021, //建材制造
|
|
||||||
// 717, //化工类
|
|
||||||
// 170, //轻工类
|
|
||||||
// 260, //纺织类
|
|
||||||
// 1088, //商贸类
|
|
||||||
// 1424, //投资管理
|
|
||||||
// 903, //配套类
|
|
||||||
// 959, //其他
|
|
||||||
// }
|
|
||||||
// totalAnalyse := this.Db.Get("org_analyse", "*", Map{"org_id": orgId})
|
|
||||||
//
|
|
||||||
// for _, id := range categoryIDS {
|
|
||||||
//
|
|
||||||
// companys := this.Db.Select("company", Map{"[><]category": "company.category_id=category.id"},
|
|
||||||
// "company.id,company.gs,company.level,company.score,company.upload_data,company.analyse,company.category_id", Map{"category.index[~]": "," + ObjToStr(id) + ","})
|
|
||||||
// ctgAn := ctgAnalyse(companys, totalAnalyse)
|
|
||||||
// data := Map{
|
|
||||||
// "name": org.GetString("name"),
|
|
||||||
// "modify_time": time.Now().Unix(),
|
|
||||||
// "data": ctgAn.ToJsonString(),
|
|
||||||
// }
|
|
||||||
// ctgAnalyse := this.Db.Get("category_analyse", "id", Map{"AND": Map{"org_id": orgId, "category_id": id}})
|
|
||||||
// if ctgAnalyse == nil {
|
|
||||||
// data["name"] = time.Now().Format("2006-01-02 15:04") + "创建"
|
|
||||||
// data["name"] = org.GetString("name")
|
|
||||||
// data["org_id"] = orgId
|
|
||||||
// data["category_id"] = id
|
|
||||||
// data["create_time"] = time.Now().Unix()
|
|
||||||
// id := this.Db.Insert("category_analyse", data)
|
|
||||||
// data["id"] = id
|
|
||||||
// } else {
|
|
||||||
// this.Db.Update("category_analyse", data, Map{"AND": Map{"org_id": orgId, "category_id": id}})
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// this.Display(0, categoryIDS)
|
|
||||||
//},
|
|
||||||
//
|
|
||||||
"industry_analyse": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
industrys := this.Db.Select("industry_analyse", "id,name,industry_id", Map{"org_id": orgId})
|
|
||||||
totalAnalyse := this.Db.Get("org_analyse", "*", Map{"org_id": orgId})
|
|
||||||
|
|
||||||
for _, industry := range industrys {
|
|
||||||
id := industry.GetCeilInt("industry_id")
|
|
||||||
companys := this.Db.Select("industry", Map{"[><]company": "company.industry_id=industry.id"},
|
|
||||||
"company.id,company.gs,company.level,company.score,company.upload_data,company.analyse,company.industry_id", Map{"AND": Map{"industry.id": id, "company.org_id": orgId}})
|
|
||||||
ctgAn := ctgAnalyse(companys, totalAnalyse)
|
|
||||||
data := Map{
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"data": ctgAn.ToJsonString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Db.Update("industry_analyse", data, Map{"AND": Map{"org_id": orgId, "industry_id": id}})
|
|
||||||
|
|
||||||
}
|
|
||||||
this.Display(0, industrys)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeData2Sql(table [][]string, this *Context, orgId int) error {
|
|
||||||
tags := []Map{} //报错所有的tag记录
|
|
||||||
tagCtgs := []Map{}
|
|
||||||
for k, v := range table {
|
|
||||||
|
|
||||||
//第一排是指标分类,去除掉第一个参数,其存在合并所以,如果是合并的则删除
|
|
||||||
if k == 0 {
|
|
||||||
|
|
||||||
for ck, cv := range v {
|
|
||||||
cv = strings.Replace(cv, " ", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r\t", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r", "", -1)
|
|
||||||
v[ck] = cv
|
|
||||||
|
|
||||||
if ck == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if cv == "" {
|
|
||||||
v[ck] = v[ck-1]
|
|
||||||
cv = v[ck]
|
|
||||||
}
|
|
||||||
|
|
||||||
tagCtg := this.Db.Get("tag_ctg", "*", Map{"AND": Map{"name": cv, "org_id": orgId}})
|
|
||||||
if tagCtg != nil {
|
|
||||||
tagCtgs = append(tagCtgs, tagCtg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tagCtg = Map{
|
|
||||||
"name": cv,
|
|
||||||
"admin_id": this.Session("admin_id").ToInt(),
|
|
||||||
"parent_id": 1, //上传分类为1
|
|
||||||
"org_id": orgId,
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
}
|
|
||||||
id := this.Db.Insert("tag_ctg", tagCtg)
|
|
||||||
|
|
||||||
if id != 0 {
|
|
||||||
tagCtg["id"] = id
|
|
||||||
this.Db.Update("tag_ctg", Map{
|
|
||||||
"index": ",1," + ObjToStr(id) + ",",
|
|
||||||
}, Map{"id": id})
|
|
||||||
|
|
||||||
tagCtgs = append(tagCtgs, tagCtg)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//第二排是指标项,去除掉第一个参数,
|
|
||||||
//最重要的是参数tag生成,通过中文转拼音获取首字母实现,遇到同名的则最后加一位数字
|
|
||||||
if k == 1 {
|
|
||||||
|
|
||||||
for ck, cv := range v {
|
|
||||||
cv = strings.Replace(cv, " ", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r\t", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r", "", -1)
|
|
||||||
v[ck] = cv
|
|
||||||
if ck == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
//补充分类
|
|
||||||
if ck >= len(table[0]) {
|
|
||||||
tagCtgs = append(tagCtgs, tagCtgs[len(tagCtgs)-1])
|
|
||||||
}
|
|
||||||
//补充说明
|
|
||||||
if ck >= len(table[3]) {
|
|
||||||
table[3] = append(table[3], table[3][len(table[3])-1])
|
|
||||||
}
|
|
||||||
//补充单位
|
|
||||||
if ck >= len(table[2]) {
|
|
||||||
table[2] = append(table[2], "")
|
|
||||||
}
|
|
||||||
|
|
||||||
tag := this.Db.Get("tag", "*", Map{"AND": Map{"name": cv, "type": "0", "org_id": orgId}})
|
|
||||||
|
|
||||||
if tag != nil {
|
|
||||||
tags = append(tags, tag)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sn, err := pinyin.New(cv).Split(" ").Mode(pinyin.InitialsInCapitals).Convert()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
sn = cv
|
|
||||||
} else {
|
|
||||||
|
|
||||||
sns := strings.Split(sn, " ")
|
|
||||||
|
|
||||||
sn = "IEDC"
|
|
||||||
for _, v1 := range sns {
|
|
||||||
|
|
||||||
if v1 != "" && !unicode.IsPunct([]rune(v1)[0]) {
|
|
||||||
sn = sn + string([]rune(v1)[:1])
|
|
||||||
fmt.Println(sn, v1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//sn=strings.Replace(sn,"\ufffd","",-1)
|
|
||||||
|
|
||||||
tagsn := this.Db.Get("tag", "id", Map{"AND": Map{"sn": sn, "type": "0", "org_id": orgId}})
|
|
||||||
if tagsn != nil {
|
|
||||||
for i := 0; i < 100; i++ {
|
|
||||||
tagsn = this.Db.Get("tag", "id", Map{"AND": Map{"sn": sn + ObjToStr(i), "type": "0", "org_id": orgId}})
|
|
||||||
if tagsn == nil {
|
|
||||||
sn = sn + ObjToStr(i)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tag = Map{
|
|
||||||
"name": cv,
|
|
||||||
"description": table[3][ck], //第三行对应位置为描述
|
|
||||||
"unit": table[2][ck],
|
|
||||||
"admin_id": this.Session("admin_id").ToInt(),
|
|
||||||
"org_id": orgId,
|
|
||||||
"type": 0,
|
|
||||||
"sn": sn,
|
|
||||||
"tag_ctg_id": tagCtgs[ck-1].GetCeilInt("id"),
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
}
|
|
||||||
id := this.Db.Insert("tag", tag)
|
|
||||||
tag["id"] = id
|
|
||||||
tags = append(tags, tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//第四排以后是数据项,去除掉第一个参数,
|
|
||||||
//根据统一社会信用代码识别是否存在,同时将校验部分数字
|
|
||||||
if k > 3 {
|
|
||||||
|
|
||||||
//整行数据
|
|
||||||
rowData := Map{}
|
|
||||||
for ck, cv := range v {
|
|
||||||
if ck == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
cv = strings.Replace(cv, " ", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r\t", "", -1)
|
|
||||||
cv = strings.Replace(cv, "\r", "", -1)
|
|
||||||
|
|
||||||
if cv == "" {
|
|
||||||
|
|
||||||
cv = "暂无"
|
|
||||||
//return errors.New("第" + ObjToStr(k+1) + "行," + ObjToStr(ck+1) + "列,数据为空请注意检查")
|
|
||||||
}
|
|
||||||
|
|
||||||
v[ck] = cv
|
|
||||||
|
|
||||||
if ck-1 >= len(tags) {
|
|
||||||
fmt.Println(cv, "表格错误")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
rowData[tags[ck-1].GetString("sn")] = cv
|
|
||||||
}
|
|
||||||
|
|
||||||
if rowData["IEDCQYMC"] == nil {
|
|
||||||
fmt.Println("数据错误")
|
|
||||||
}
|
|
||||||
|
|
||||||
companyData := Map{
|
|
||||||
"name": rowData["IEDCQYMC"],
|
|
||||||
"sn": rowData["IEDCTYSHXYDM"],
|
|
||||||
"address": rowData["IEDCQYDZ"],
|
|
||||||
"unit": rowData["IEDCSDMC"],
|
|
||||||
"zdmj": rowData["IEDCYDMJ"],
|
|
||||||
"yysr": rowData["IEDC2NYYSR"],
|
|
||||||
"lrze": rowData["IEDC2NLRZE"],
|
|
||||||
"yjsj": rowData["IEDCYNSJ"],
|
|
||||||
"yfjf": rowData["IEDCNYFFY"],
|
|
||||||
"zgrs": rowData["IEDCSBRS"],
|
|
||||||
"zywrwpfdl": rowData["IEDCZYWRWPFDL"],
|
|
||||||
"zhnh": rowData["IEDCZHNH"],
|
|
||||||
"admin_id": this.Session("admin_id").ToInt(),
|
|
||||||
"upload_data": rowData.ToJsonString(),
|
|
||||||
"org_id": orgId,
|
|
||||||
//"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
//"lat": lat,
|
|
||||||
//"lng": lng,
|
|
||||||
}
|
|
||||||
//行业ID
|
|
||||||
//org := this.Db.Get("org", "id,name", Map{"id": orgId})
|
|
||||||
//regin := "全国"
|
|
||||||
//if org != nil {
|
|
||||||
// regin = org.GetString("name")
|
|
||||||
//}
|
|
||||||
//baiduDataStr, _ := baidu.DefaultBaiDuMap.GetPosition(companyData.GetString("address"), regin)
|
|
||||||
//baiduData := ObjToMap(baiduDataStr)
|
|
||||||
|
|
||||||
//city := Map{}
|
|
||||||
//if baiduData != nil && baiduData.GetCeilInt("status") == 0 {
|
|
||||||
// address := baiduData.GetSlice("result")
|
|
||||||
// if len(address) != 0 {
|
|
||||||
// companyData["lat"] = address.GetMap(0).GetMap("location").GetFloat64("lat")
|
|
||||||
// companyData["lng"] = address.GetMap(0).GetMap("location").GetFloat64("lng")
|
|
||||||
//
|
|
||||||
// city = this.Db.Get("city", "id", Map{"name[~]": address.GetMap(0).GetString("district"), "ORDER": "`level` DESC"})
|
|
||||||
// if city == nil {
|
|
||||||
// city = this.Db.Get("city", "id", Map{"name[~]": address.GetMap(0).GetString("city"), "ORDER": "`level` DESC"})
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if city != nil {
|
|
||||||
// companyData["city_id"] = city.GetCeilInt("id")
|
|
||||||
//}
|
|
||||||
|
|
||||||
//行业ID
|
|
||||||
category := this.Db.Get("category", "id", Map{"code": rowData["IEDCSSXYXLDM"]})
|
|
||||||
if category != nil {
|
|
||||||
companyData["category_id"] = category.GetCeilInt("id")
|
|
||||||
}
|
|
||||||
|
|
||||||
////此处需要优化
|
|
||||||
//companyData["org_id"] = 3
|
|
||||||
|
|
||||||
//产业ID
|
|
||||||
industry := this.Db.Get("industry", "id", Map{"name": rowData["IEDCCYLB"]})
|
|
||||||
if industry == nil {
|
|
||||||
industry = Map{
|
|
||||||
"admin_id": this.Session("admin_id").ToInt(),
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"name": rowData["IEDCCYLB"],
|
|
||||||
}
|
|
||||||
id := this.Db.Insert("industry", industry)
|
|
||||||
industry["id"] = id
|
|
||||||
}
|
|
||||||
|
|
||||||
if industry.GetCeilInt("id") != 0 {
|
|
||||||
|
|
||||||
//产业ID
|
|
||||||
industryAnalyse := this.Db.Get("industry_analyse", "id", Map{"AND": Map{"industry_id": industry.GetCeilInt("id"), "org_id": orgId}})
|
|
||||||
if industryAnalyse == nil {
|
|
||||||
industryAnalyse = Map{
|
|
||||||
"name": rowData["IEDCCYLB"],
|
|
||||||
"create_time": time.Now().Unix(),
|
|
||||||
"modify_time": time.Now().Unix(),
|
|
||||||
"org_id": orgId,
|
|
||||||
"industry_id": industry.GetCeilInt("id"),
|
|
||||||
}
|
|
||||||
//if city != nil {
|
|
||||||
// industryAnalyse["city_id"] = city.GetCeilInt("id")
|
|
||||||
//}
|
|
||||||
this.Db.Insert("industry_analyse", industryAnalyse)
|
|
||||||
}
|
|
||||||
companyData["industry_id"] = industry.GetCeilInt("id")
|
|
||||||
}
|
|
||||||
|
|
||||||
company := this.Db.Get("company", "id", Map{"name": companyData["name"]})
|
|
||||||
//没有则创建
|
|
||||||
if company == nil && companyData.GetString("sn") != "暂无" {
|
|
||||||
company = this.Db.Get("company", "id", Map{"sn": companyData["sn"]})
|
|
||||||
}
|
|
||||||
|
|
||||||
//没有则创建
|
|
||||||
if company == nil {
|
|
||||||
//更新两张表
|
|
||||||
companyData["create_time"] = time.Now().Unix()
|
|
||||||
id := this.Db.Insert("company", companyData)
|
|
||||||
companyData["company_id"] = id
|
|
||||||
company = Map{"id": id}
|
|
||||||
} else {
|
|
||||||
//有则更新
|
|
||||||
this.Db.Update("company", companyData, Map{"id": company.GetCeilInt("id")})
|
|
||||||
companyData["company_id"] = company.GetCeilInt("id")
|
|
||||||
companyData["create_time"] = time.Now().Unix()
|
|
||||||
}
|
|
||||||
|
|
||||||
id := this.Db.Insert("company_history", companyData)
|
|
||||||
//更新最新的企业信息
|
|
||||||
this.Db.Update("company", Map{"company_history_id": id}, Map{"id": company.GetCeilInt("id")})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func excel(filePath string) [][][]string {
|
|
||||||
xlsx, err := excelize.OpenFile(filePath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
list := xlsx.GetSheetList()
|
|
||||||
var data [][][]string
|
|
||||||
for _, v := range list {
|
|
||||||
rows, e := xlsx.GetRows(v)
|
|
||||||
if e != nil {
|
|
||||||
fmt.Println(e)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data = append(data, rows)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,142 +0,0 @@
|
|||||||
package admin
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../common"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Org = map[int]OrgInterface{
|
|
||||||
3: &Org3{},
|
|
||||||
}
|
|
||||||
|
|
||||||
type OrgInterface interface {
|
|
||||||
analyse(data Map) Map
|
|
||||||
ctgAnalyse(datas []Map, totalAnalyse Map) Map
|
|
||||||
totalAnalyse(datas []Map) (Map, Map, Map, Map)
|
|
||||||
analyseSort(datas []Map) []Map
|
|
||||||
}
|
|
||||||
|
|
||||||
type Companys []Map
|
|
||||||
|
|
||||||
var analyseSortType = ""
|
|
||||||
var analyseTypeName = "analyse"
|
|
||||||
|
|
||||||
func (s Companys) Len() int {
|
|
||||||
return len(s)
|
|
||||||
}
|
|
||||||
func (s Companys) Swap(i, j int) {
|
|
||||||
s[i], s[j] = s[j], s[i]
|
|
||||||
}
|
|
||||||
func (s Companys) Less(i, j int) bool {
|
|
||||||
return s[i].GetMap(analyseTypeName).GetFloat64(analyseSortType) > s[j].GetMap(analyseTypeName).GetFloat64(analyseSortType)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ADataType = Map{
|
|
||||||
|
|
||||||
"PJ": "评级",
|
|
||||||
|
|
||||||
"ZDF": "总得分",
|
|
||||||
|
|
||||||
"NZDF": "N项总得分",
|
|
||||||
|
|
||||||
"JGTZDF": "技改投资得分",
|
|
||||||
|
|
||||||
"JGTZ": "技改投资金额",
|
|
||||||
|
|
||||||
"ZJTXQLDF": "专精特新潜力得分",
|
|
||||||
|
|
||||||
"JBZJTXQYJCYQDF": "具备专精特新企业基础要求得分",
|
|
||||||
|
|
||||||
"JBZJTXQYYQCPDF": "具备专精特新企业要求产品得分",
|
|
||||||
|
|
||||||
"JBZJTXHJJTJDF": "具备专精特新环境及条件得分",
|
|
||||||
|
|
||||||
"JBZJTXZSCQYQDF": "具备专精特新知识产权要求得分",
|
|
||||||
|
|
||||||
"YFZBDF": "2年研发占比得分",
|
|
||||||
|
|
||||||
"KYRYZBDF": "科研人员占比得分",
|
|
||||||
|
|
||||||
"ZCFZLDF": "资产负债率得分",
|
|
||||||
|
|
||||||
"CYRCDF": "产业人才得分",
|
|
||||||
|
|
||||||
"SXZBDF": "3项指标",
|
|
||||||
|
|
||||||
"XZFZZBDF": "协作发展指标得分",
|
|
||||||
|
|
||||||
"FHDQZDCYDF": "符合地区重点产业得分",
|
|
||||||
|
|
||||||
"QYZDQYDF": "区域重点企业",
|
|
||||||
|
|
||||||
"SJ100HZDQYDF": "市级100户重点企业得分",
|
|
||||||
|
|
||||||
"CYL30HDF": "产业链30户得分",
|
|
||||||
|
|
||||||
"LSAQZBDF": "绿色安全指标",
|
|
||||||
|
|
||||||
"AQSCGLDF": "安全生产管理得分",
|
|
||||||
|
|
||||||
"QYAQSCDBDF": "企业安全生产是否达标得分",
|
|
||||||
|
|
||||||
"QYFXYHSKTXJSDF": "企业风险隐患双预控体系建设得分",
|
|
||||||
|
|
||||||
"AQSGDF": "安全事故得分",
|
|
||||||
|
|
||||||
"AQJCDF": "安全检查得分",
|
|
||||||
|
|
||||||
"LSSCGYDF": "绿色生产工艺得分",
|
|
||||||
|
|
||||||
"JPJSSJDF": "减排技术升级改造得分",
|
|
||||||
|
|
||||||
"HBJCDF": "环保检查得分",
|
|
||||||
|
|
||||||
"FZZLZBZDF": "发展质量指标总分",
|
|
||||||
|
|
||||||
"QYYLNLZDF": "企业盈利能力总得分",
|
|
||||||
|
|
||||||
"KSDF": "企业连续3年亏损得分",
|
|
||||||
|
|
||||||
"QYLRL": "企业利润率",
|
|
||||||
|
|
||||||
"DNLRZEDF": "当年利润总额得分",
|
|
||||||
|
|
||||||
"LXSNYLDF": "连续3年盈利得分",
|
|
||||||
|
|
||||||
"ZSCQDF": "知识产权总得分",
|
|
||||||
|
|
||||||
"TGMLDF": "推广目录得分",
|
|
||||||
|
|
||||||
"ZLDF": "专利得分",
|
|
||||||
|
|
||||||
"STTDF": "首台(套)、首批次、首版次企业得分",
|
|
||||||
|
|
||||||
"MJSR": "亩均收入",
|
|
||||||
"MJSRDF": "亩均收入得分",
|
|
||||||
|
|
||||||
"MJSS": "亩均税收",
|
|
||||||
"MJSSDF": "亩均税收得分",
|
|
||||||
|
|
||||||
"RJSR": "人均收入",
|
|
||||||
"RJSRDF": "人均收入得分",
|
|
||||||
|
|
||||||
"YFJFTRQD": "研发经费投入强度",
|
|
||||||
"YFJFTRQDDF": "研发经费投入强度得分",
|
|
||||||
|
|
||||||
"DWNHSS": "单位能耗税收",
|
|
||||||
"DWNHSSDF": "单位能耗税收得分",
|
|
||||||
|
|
||||||
"ZYWRWSS": "主要污染物税收",
|
|
||||||
"ZYWRWSSDF": "主要污染物税收得分",
|
|
||||||
|
|
||||||
"NXZBDF": "6项指标得分",
|
|
||||||
|
|
||||||
"DJSDLQYDF": "独角兽、瞪羚企业得分",
|
|
||||||
|
|
||||||
"JSZXDF": "企业获得技术中心得分",
|
|
||||||
|
|
||||||
"YFFYDF": "研发费用得分",
|
|
||||||
|
|
||||||
"GXJSQYDF": "高新技术企业得分",
|
|
||||||
|
|
||||||
"FZQLDF": "发展潜力总分",
|
|
||||||
}
|
|
@ -1,473 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../common"
|
|
||||||
"fmt"
|
|
||||||
"github.com/xuri/excelize"
|
|
||||||
"os"
|
|
||||||
"sort"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var analyseCtr = Ctr{
|
|
||||||
|
|
||||||
"home_data": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res := this.Db.Get("org_analyse", "*", Map{"org_id": orgId})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res["home_data"] = res.GetMap("home_data")
|
|
||||||
res["six_item_data"] = res.GetMap("six_item_data")
|
|
||||||
res["three_item_data"] = res.GetMap("three_item_data")
|
|
||||||
res["n_item_data"] = res.GetMap("n_item_data")
|
|
||||||
this.Display(0, res)
|
|
||||||
},
|
|
||||||
"home_excel": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res := this.Db.Get("org_analyse", "*", Map{"org_id": orgId})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
homeData := res.GetMap("home_data")
|
|
||||||
sixItemData := res.GetMap("six_item_data")
|
|
||||||
threeItemData := res.GetMap("three_item_data")
|
|
||||||
nItemData := res.GetMap("n_item_data")
|
|
||||||
|
|
||||||
filePath := "temp/home" + ObjToStr(orgId) + ".xlsx"
|
|
||||||
f, e := excelize.OpenFile(this.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
if e != nil {
|
|
||||||
f = excelize.NewFile()
|
|
||||||
// 创建一个工作表
|
|
||||||
f.NewSheet("IEDC全局分析")
|
|
||||||
// 创建一个工作表
|
|
||||||
f.NewSheet("“6”项量化")
|
|
||||||
f.NewSheet("“3”项定性")
|
|
||||||
f.NewSheet("“N”项特色")
|
|
||||||
f.DeleteSheet("Sheet1")
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue("IEDC全局分析", "A1", "指标项")
|
|
||||||
f.SetCellValue("IEDC全局分析", "B1", "指标值")
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue("“6”项量化", "A1", "指标项")
|
|
||||||
f.SetCellValue("“6”项量化", "B1", "指标值")
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue("“3”项定性", "A1", "指标项")
|
|
||||||
f.SetCellValue("“3”项定性", "B1", "指标值")
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue("“N”项特色", "A1", "指标项")
|
|
||||||
f.SetCellValue("“N”项特色", "B1", "指标值")
|
|
||||||
|
|
||||||
os.MkdirAll(this.Config.GetString("tpt")+"/temp/", os.ModeDir)
|
|
||||||
// 根据指定路径保存文件
|
|
||||||
if err := f.SaveAs(this.Config.GetString("tpt") + "/" + filePath); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
this.Display(4, "输出异常")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
run := func(str string, data Map, f *excelize.File) {
|
|
||||||
var keys []string
|
|
||||||
for k := range data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
//按字典升序排列
|
|
||||||
sort.Strings(keys)
|
|
||||||
for k, v := range keys {
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue(str, "A"+ObjToStr(k+2), v)
|
|
||||||
f.SetCellValue(str, "B"+ObjToStr(k+2), data[v])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run("IEDC全局分析", homeData, f)
|
|
||||||
run("“6”项量化", sixItemData, f)
|
|
||||||
run("“3”项定性", threeItemData, f)
|
|
||||||
run("“N”项特色", nItemData, f)
|
|
||||||
//f.SetCellValue("Sheet1", "B2", 100)
|
|
||||||
|
|
||||||
f.Save()
|
|
||||||
this.Resp.Header().Set("Location", "/"+filePath)
|
|
||||||
this.Resp.WriteHeader(307) //关键在这里!
|
|
||||||
this.Display(0, filePath)
|
|
||||||
},
|
|
||||||
"home1_data": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res := this.Db.Get("org_analyse", "*", Map{"org_id": orgId})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res["home1_data"] = res.GetMap("home1_data")
|
|
||||||
res["six_item_data"] = res.GetMap("six_item_data")
|
|
||||||
res["three_item_data"] = res.GetMap("three_item_data")
|
|
||||||
res["n_item_data"] = res.GetMap("n_item_data")
|
|
||||||
this.Display(0, res)
|
|
||||||
},
|
|
||||||
|
|
||||||
"ctg": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
ctgID := ObjToInt(this.Req.FormValue("ctg_id"))
|
|
||||||
if orgId == 0 || ctgID == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res := this.Db.Get("category_analyse", "*", Map{"AND": Map{"org_id": orgId, "category_id": ctgID}})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res["data"] = res.GetMap("data")
|
|
||||||
res1 := this.Db.Get("org_analyse", "home_data", Map{"org_id": orgId})
|
|
||||||
res["home"] = res1.GetMap("home_data")
|
|
||||||
this.Display(0, res)
|
|
||||||
},
|
|
||||||
"industrys": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res := this.Db.Select("industry_analyse", "industry_id,name", Map{"org_id": orgId})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, res)
|
|
||||||
},
|
|
||||||
"industry": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
industryId := ObjToInt(this.Req.FormValue("industry_id"))
|
|
||||||
if orgId == 0 || industryId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res := this.Db.Get("industry_analyse", "*", Map{"AND": Map{"org_id": orgId, "industry_id": industryId}})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res["data"] = res.GetMap("data")
|
|
||||||
res1 := this.Db.Get("org_analyse", "name,home_data", Map{"org_id": orgId})
|
|
||||||
res["home"] = res1.GetMap("home_data")
|
|
||||||
res["home_name"] = res1.GetString("name")
|
|
||||||
this.Display(0, res)
|
|
||||||
},
|
|
||||||
"industry_excel": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
industryId := ObjToInt(this.Req.FormValue("industry_id"))
|
|
||||||
if orgId == 0 || industryId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res := this.Db.Get("industry_analyse", "*", Map{"AND": Map{"org_id": orgId, "industry_id": industryId}})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res["data"] = res.GetMap("data")
|
|
||||||
//res1 := this.Db.Get("org_analyse", "name,home_data", Map{"org_id": orgId})
|
|
||||||
//res["home"] = res1.GetMap("home_data")
|
|
||||||
//res["home_name"] = res1.GetString("name")
|
|
||||||
|
|
||||||
filePath := "temp/industry" + ObjToStr(industryId) + "x" + ObjToStr(orgId) + ".xlsx"
|
|
||||||
|
|
||||||
f, e := excelize.OpenFile(this.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
if e != nil {
|
|
||||||
f = excelize.NewFile()
|
|
||||||
|
|
||||||
// 创建一个工作表
|
|
||||||
f.NewSheet(res.GetString("name"))
|
|
||||||
|
|
||||||
f.DeleteSheet("Sheet1")
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue(res.GetString("name"), "A1", "指标项")
|
|
||||||
f.SetCellValue(res.GetString("name"), "B1", "指标值")
|
|
||||||
|
|
||||||
os.MkdirAll(this.Config.GetString("tpt")+"/temp/", os.ModeDir)
|
|
||||||
|
|
||||||
// 根据指定路径保存文件
|
|
||||||
if err := f.SaveAs(this.Config.GetString("tpt") + "/" + filePath); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
this.Display(4, "输出异常")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run := func(str string, data Map, f *excelize.File) {
|
|
||||||
var keys []string
|
|
||||||
for k := range data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
//按字典升序排列
|
|
||||||
sort.Strings(keys)
|
|
||||||
for k, v := range keys {
|
|
||||||
// 设置单元格的值
|
|
||||||
f.SetCellValue(str, "A"+ObjToStr(k+2), v)
|
|
||||||
f.SetCellValue(str, "B"+ObjToStr(k+2), data[v])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run(res.GetString("name"), res.GetMap("data"), f)
|
|
||||||
//f.SetCellValue("Sheet1", "B2", 100)
|
|
||||||
f.Save()
|
|
||||||
this.Resp.Header().Set("Location", "/"+filePath)
|
|
||||||
this.Resp.WriteHeader(307) //关键在这里!
|
|
||||||
this.Display(0, filePath)
|
|
||||||
},
|
|
||||||
"map": func(this *Context) {
|
|
||||||
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
industryId := ObjToInt(this.Req.FormValue("industry_id"))
|
|
||||||
//if orgId == 0 || industryId == 0 {
|
|
||||||
// this.Display(3, "参数错误")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
page := ObjToInt(this.Req.FormValue("page"))
|
|
||||||
pageSize := ObjToInt(this.Req.FormValue("pageSize"))
|
|
||||||
search := this.Req.FormValue("search")
|
|
||||||
where := Map{}
|
|
||||||
levelStr := this.Req.FormValue("level")
|
|
||||||
if levelStr != "" {
|
|
||||||
where["level"] = ObjToInt(levelStr)
|
|
||||||
}
|
|
||||||
if orgId != 0 {
|
|
||||||
where["org_id"] = orgId
|
|
||||||
}
|
|
||||||
if industryId != 0 {
|
|
||||||
where["industry_id"] = industryId
|
|
||||||
}
|
|
||||||
|
|
||||||
if search != "" {
|
|
||||||
where["name[~]"] = search
|
|
||||||
}
|
|
||||||
if len(where) > 1 {
|
|
||||||
where = Map{"AND": where}
|
|
||||||
}
|
|
||||||
|
|
||||||
if page == 0 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
if pageSize == 0 {
|
|
||||||
pageSize = 10
|
|
||||||
}
|
|
||||||
count := this.Db.Count("company", where)
|
|
||||||
|
|
||||||
companys := this.Db.Page(page, pageSize).PageSelect("company", Map{"[><]industry": "company.industry_id=industry.id"},
|
|
||||||
"company.id,company.collect_data,company.name,company.level,company.address,company.score,company.lat,company.lng,company.category_id,industry.name AS industry_name,company.industry_id",
|
|
||||||
where)
|
|
||||||
|
|
||||||
for _, res := range companys {
|
|
||||||
|
|
||||||
res["collect_data"] = res.GetMap("collect_data")
|
|
||||||
//if res.GetMap("collect_data") == nil {
|
|
||||||
// path := "company/" + Md5(res.GetString("name")) + time.Now().Format("/200601021504.json")
|
|
||||||
//
|
|
||||||
// data := getCompany(res.GetString("name"), this.Config.GetString("tpt")+"/"+path)
|
|
||||||
//
|
|
||||||
// if len(data) != 0 {
|
|
||||||
// data["path"] = path
|
|
||||||
// re := this.Db.Update("company", Map{"collect_data": data.ToJsonString(),
|
|
||||||
// "address": data.GetString("companyAddress"),
|
|
||||||
// "sn": data.GetString("creditNo"),
|
|
||||||
// "unit": data.GetString("authority"),
|
|
||||||
// }, Map{"id": res.GetCeilInt("id")})
|
|
||||||
// fmt.Println(re)
|
|
||||||
// res["collect_data"] = data
|
|
||||||
// res["address"] = data.GetString("companyAddress")
|
|
||||||
// res["sn"] = data.GetString("creditNo")
|
|
||||||
// res["unit"] = data.GetString("authority")
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, Map{"count": count, "pageSize": pageSize, "data": companys})
|
|
||||||
},
|
|
||||||
"updateCompany": func(this *Context) {
|
|
||||||
lng := ObjToFloat64(this.Req.FormValue("lng"))
|
|
||||||
lat := ObjToFloat64(this.Req.FormValue("lat"))
|
|
||||||
id := ObjToInt(this.Req.FormValue("id"))
|
|
||||||
if lng == 0 || lat == 0 || id == 0 {
|
|
||||||
this.Display(3, "请求异常")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
re := this.Db.Update("company", Map{"lng": lng, "lat": lat}, Map{"id": id})
|
|
||||||
if re == 0 {
|
|
||||||
this.Display(4, "更新失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.Display(0, "更新成功")
|
|
||||||
},
|
|
||||||
|
|
||||||
"companys": func(this *Context) {
|
|
||||||
|
|
||||||
page := ObjToInt(this.Req.FormValue("page"))
|
|
||||||
pageSize := ObjToInt(this.Req.FormValue("pageSize"))
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
search := this.Req.FormValue("search")
|
|
||||||
sort := this.Req.FormValue("sort")
|
|
||||||
where := Map{"state": 0}
|
|
||||||
levelStr := this.Req.FormValue("level")
|
|
||||||
if levelStr != "" {
|
|
||||||
where["level"] = ObjToInt(levelStr)
|
|
||||||
}
|
|
||||||
industryId := ObjToInt(this.Req.FormValue("industry_id"))
|
|
||||||
if industryId != 0 {
|
|
||||||
where["industry_id"] = industryId
|
|
||||||
}
|
|
||||||
if orgId != 0 {
|
|
||||||
where["org_id"] = orgId
|
|
||||||
}
|
|
||||||
if search != "" {
|
|
||||||
where["name[~]"] = search
|
|
||||||
}
|
|
||||||
if len(where) > 1 {
|
|
||||||
where = Map{"AND": where}
|
|
||||||
}
|
|
||||||
if sort != "" {
|
|
||||||
where["ORDER"] = sort
|
|
||||||
} else {
|
|
||||||
where["ORDER"] = "score DESC"
|
|
||||||
}
|
|
||||||
|
|
||||||
if page == 0 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
if pageSize == 0 {
|
|
||||||
pageSize = 10
|
|
||||||
}
|
|
||||||
count := this.Db.Count("company", where)
|
|
||||||
|
|
||||||
companys := this.Db.Page(page, pageSize).PageSelect("company",
|
|
||||||
"*",
|
|
||||||
where)
|
|
||||||
for _, res := range companys {
|
|
||||||
analyse := res.GetMap("analyse")
|
|
||||||
if analyse != nil {
|
|
||||||
for k, v := range analyse {
|
|
||||||
if ADataType[k] != nil {
|
|
||||||
analyse[ADataType.GetString(k)] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res["analyse"] = analyse
|
|
||||||
}
|
|
||||||
res["upload_data"] = res.GetMap("upload_data")
|
|
||||||
res["collect_data"] = res.GetMap("collect_data")
|
|
||||||
res["collect_data"] = res.GetMap("collect_data")
|
|
||||||
//if res.GetMap("collect_data") == nil && page == 1 {
|
|
||||||
// go func(res Map, this *Context) {
|
|
||||||
// path := "company/" + Md5(res.GetString("name")) + time.Now().Format("/200601021504.json")
|
|
||||||
//
|
|
||||||
// data := getCompany(res.GetString("name"), this.Config.GetString("tpt")+"/"+path)
|
|
||||||
//
|
|
||||||
// if len(data) != 0 {
|
|
||||||
// data["path"] = path
|
|
||||||
// this.Db.Update("company", Map{"collect_data": data.ToJsonString(),
|
|
||||||
// "address": data.GetString("companyAddress"),
|
|
||||||
// "sn": data.GetString("creditNo"),
|
|
||||||
// "unit": data.GetString("authority"),
|
|
||||||
// }, Map{"id": res.GetCeilInt("id")})
|
|
||||||
// res["collect_data"] = data
|
|
||||||
// }
|
|
||||||
// }(res, this)
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, Map{"count": count, "pageSize": pageSize, "data": companys})
|
|
||||||
},
|
|
||||||
|
|
||||||
"company": func(this *Context) {
|
|
||||||
id := ObjToInt(this.Req.FormValue("id"))
|
|
||||||
if id == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res := this.Db.Get("company", "*", Map{"id": id})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
analyse := res.GetMap("analyse")
|
|
||||||
|
|
||||||
if analyse != nil {
|
|
||||||
for k, v := range analyse {
|
|
||||||
if ADataType[k] != nil {
|
|
||||||
analyse[ADataType.GetString(k)] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res["analyse"] = analyse
|
|
||||||
}
|
|
||||||
analyse1 := res.GetMap("analyse1")
|
|
||||||
if analyse1 != nil {
|
|
||||||
for k, v := range analyse1 {
|
|
||||||
if ADataType[k] != nil {
|
|
||||||
analyse1[ADataType.GetString(k)] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res["analyse1"] = analyse1
|
|
||||||
}
|
|
||||||
|
|
||||||
res["upload_data"] = res.GetMap("upload_data")
|
|
||||||
res["collect_data"] = res.GetMap("collect_data")
|
|
||||||
if res.GetMap("collect_data") == nil {
|
|
||||||
go func(res Map) {
|
|
||||||
path := "company/" + Md5(res.GetString("name")) + time.Now().Format("/200601021504.json")
|
|
||||||
|
|
||||||
data := getCompany(res.GetString("name"), this.Config.GetString("tpt")+"/"+path)
|
|
||||||
|
|
||||||
if len(data) != 0 {
|
|
||||||
data["path"] = path
|
|
||||||
this.Db.Update("company", Map{"collect_data": data.ToJsonString()}, Map{"id": res.GetCeilInt("id")})
|
|
||||||
res["collect_data"] = data
|
|
||||||
}
|
|
||||||
|
|
||||||
}(res)
|
|
||||||
|
|
||||||
}
|
|
||||||
this.Display(0, res)
|
|
||||||
|
|
||||||
},
|
|
||||||
"company_upload": func(this *Context) {
|
|
||||||
id := ObjToInt(this.Req.FormValue("id"))
|
|
||||||
if id == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res := this.Db.Get("company", "upload_data,org_id", Map{"id": id})
|
|
||||||
if res == nil {
|
|
||||||
this.Display(4, "找不到该数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadData := res.GetMap("upload_data")
|
|
||||||
tags := this.Db.Select("tag", "name,sn,`unit`,description", Map{"AND": Map{"type": 0, "org_id": res.GetCeilInt("org_id")}})
|
|
||||||
for _, v := range tags {
|
|
||||||
v["value"] = uploadData[v.GetString("sn")]
|
|
||||||
}
|
|
||||||
this.Display(0, tags)
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
//"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Category = Ctr{
|
|
||||||
|
|
||||||
//获取列表
|
|
||||||
"list": func(this *Context) {
|
|
||||||
|
|
||||||
re := this.Db.Select("category", "*", Map{"parent_id": 1})
|
|
||||||
|
|
||||||
this.Display(0, re)
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,161 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"../../dri/aliyun"
|
|
||||||
"../../dri/tencent"
|
|
||||||
"fmt"
|
|
||||||
"github.com/silenceper/wechat"
|
|
||||||
"github.com/silenceper/wechat/cache"
|
|
||||||
"gopkg.in/chanxuehong/wechat.v2/mch/core"
|
|
||||||
"gopkg.in/chanxuehong/wechat.v2/mch/pay"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Project 管理端项目
|
|
||||||
var Project = Proj{
|
|
||||||
//"user": UserCtr,
|
|
||||||
"tag": tagCtr,
|
|
||||||
"analyse": analyseCtr,
|
|
||||||
"user": User,
|
|
||||||
"wechat": Wechat,
|
|
||||||
"question": Question,
|
|
||||||
"category": Category,
|
|
||||||
"sms": Sms,
|
|
||||||
}
|
|
||||||
var weixin *wechat.Wechat //微信登录实例
|
|
||||||
//var appIns = Application{}
|
|
||||||
var wxpayClient *core.Client
|
|
||||||
|
|
||||||
//生成随机码的4位随机数
|
|
||||||
func getCode() string {
|
|
||||||
//res := ""
|
|
||||||
//for i := 0; i < 4; i++ {
|
|
||||||
res := ObjToStr(RandX(1000, 9999))
|
|
||||||
//}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCompany(name, path string) Map {
|
|
||||||
os.Setenv("ZONEINFO", "config/data.zip")
|
|
||||||
res := tencent.GetCompany("AKIDklZa1qBr3B0x1G643cg8B6UO5JZm2KX8o43G", "tdda7oro526h96dvicYkep1xsWFmHkt33xvqs2K", name)
|
|
||||||
c := Map{}
|
|
||||||
base := Map{}
|
|
||||||
if res.GetInt("code") != 200 {
|
|
||||||
|
|
||||||
return base
|
|
||||||
}
|
|
||||||
if res.GetInt("code") == 200 {
|
|
||||||
c = res.GetMap("data").GetMap("data")
|
|
||||||
|
|
||||||
base = c.GetMap("base")
|
|
||||||
base["allows"] = len(c.GetSlice("allows"))
|
|
||||||
base["branches"] = len(c.GetSlice("branches"))
|
|
||||||
base["changes"] = len(c.GetSlice("changes"))
|
|
||||||
base["employees"] = len(c.GetSlice("employees"))
|
|
||||||
base["exceptions"] = len(c.GetSlice("exceptions"))
|
|
||||||
|
|
||||||
base["mPledges"] = len(c.GetSlice("mPledges"))
|
|
||||||
base["originalName"] = len(c.GetSlice("originalName"))
|
|
||||||
base["partners"] = len(c.GetSlice("partners"))
|
|
||||||
base["pledges"] = len(c.GetSlice("pledges"))
|
|
||||||
base["punishes"] = len(c.GetSlice("punishes"))
|
|
||||||
|
|
||||||
base["shiXinItems"] = len(c.GetSlice("shiXinItems"))
|
|
||||||
base["spotChecks"] = len(c.GetSlice("spotChecks"))
|
|
||||||
base["taxCreditltems"] = len(c.GetSlice("taxCreditltems"))
|
|
||||||
base["zhiXingItems"] = len(c.GetSlice("zhiXingItems"))
|
|
||||||
base["contactInfo"] = c["contactInfo"]
|
|
||||||
base["industry"] = c["industry"]
|
|
||||||
base["liquidation"] = c["liquidation"]
|
|
||||||
}
|
|
||||||
|
|
||||||
aliyun.DefaultCompany.Init("06c6a07e89dd45c88de040ee1489eef7")
|
|
||||||
data := aliyun.DefaultCompany.GetCompanyOtherAll(name)
|
|
||||||
|
|
||||||
base["OtherCopyrightsInfo"] = data.GetMap("OtherCopyrightsInfo").GetInt("total")
|
|
||||||
base["PatentsInfo"] = data.GetMap("PatentsInfo").GetInt("total")
|
|
||||||
base["ProfileTags"] = data.GetSlice("ProfileTags")
|
|
||||||
base["SoftwareCopyrightsInfo"] = data.GetMap("SoftwareCopyrightsInfo").GetInt("total")
|
|
||||||
base["TrademarksInfo"] = data.GetMap("TrademarksInfo").GetInt("total")
|
|
||||||
|
|
||||||
if res.GetInt("code") == 200 {
|
|
||||||
data["base"] = c
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = os.MkdirAll(filepath.Dir(path), os.ModeDir)
|
|
||||||
ioutil.WriteFile(path, []byte(data.ToJsonString()), os.ModePerm)
|
|
||||||
|
|
||||||
return base
|
|
||||||
}
|
|
||||||
|
|
||||||
//微信获取个人信息
|
|
||||||
func Weixin(this *Context) *wechat.Wechat {
|
|
||||||
if weixin == nil {
|
|
||||||
cache1 := cache.Cache(WechatCache{this.CacheIns})
|
|
||||||
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppID"), AppSecret: this.Config.GetString("wechatAppSecret")}
|
|
||||||
weixin = wechat.NewWechat(&config)
|
|
||||||
}
|
|
||||||
|
|
||||||
return weixin
|
|
||||||
}
|
|
||||||
|
|
||||||
//微信获取个人信息
|
|
||||||
func WxPayClient(this *Context, sn string, money int64, openid string) Map {
|
|
||||||
if wxpayClient == nil {
|
|
||||||
wxpayClient = core.NewClient(this.Config.GetString("wechatAppID"), this.Config.GetString("wechatChid"), this.Config.GetString("wechatChkey"), nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := pay.UnifiedOrder2(wxpayClient, &pay.UnifiedOrderRequest{
|
|
||||||
|
|
||||||
// 必选参数
|
|
||||||
Body: "微信充值", // 商品或支付单简要描述
|
|
||||||
OutTradeNo: sn, // 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
|
|
||||||
TotalFee: money, // ObjToInt64(umoney*100), // `xml:"total_fee"` // 订单总金额,单位为分,详见支付金额
|
|
||||||
//SpbillCreateIP string `xml:"spbill_create_ip"` // APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
|
|
||||||
NotifyURL: this.Config.GetString("wechatPayCallBack"), // string `xml:"notify_url"` // 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
|
|
||||||
TradeType: "JSAPI", // string `xml:"trade_type"` // 取值如下:JSAPI,NATIVE,APP,详细说明见参数规定
|
|
||||||
|
|
||||||
// 可选参数
|
|
||||||
DeviceInfo: "WEB", // string `xml:"device_info"` // 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB"
|
|
||||||
// NonceStr string `xml:"nonce_str"` // 随机字符串,不长于32位。NOTE: 如果为空则系统会自动生成一个随机字符串。
|
|
||||||
//SignType string `xml:"sign_type"` // 签名类型,默认为MD5,支持HMAC-SHA256和MD5。
|
|
||||||
// Detail:"充值",// string `xml:"detail"` // 商品名称明细列表
|
|
||||||
//Attach string `xml:"attach"` // 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
|
||||||
//FeeType string `xml:"fee_type"` // 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
|
|
||||||
//TimeStart time.Time `xml:"time_start"` // 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
|
|
||||||
//TimeExpire time.Time `xml:"time_expire"` // 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
|
|
||||||
//GoodsTag string `xml:"goods_tag"` // 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
|
|
||||||
// ProductId :"CHONGZHI",// string `xml:"product_id"` // trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
|
|
||||||
// LimitPay string `xml:"limit_pay"` // no_credit--指定不能使用信用卡支付
|
|
||||||
OpenId: openid, //user.GetString("wuid"), // string `xml:"openid"` // rade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。
|
|
||||||
// SubOpenId string `xml:"sub_openid"` // trade_type=JSAPI,此参数必传,用户在子商户appid下的唯一标识。openid和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid。
|
|
||||||
// SceneInfo string `xml:"scene_info"` // 该字段用于上报支付的场景信息,针对H5支付有以下三种场景,请根据对应场景上报,H5支付不建议在APP端
|
|
||||||
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
|
|
||||||
fmt.Println(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
wcpay := Map{
|
|
||||||
"appId": this.Config.Get("wechatAppID"),
|
|
||||||
"timeStamp": ObjToStr(time.Now().Unix()),
|
|
||||||
"nonceStr": getSn(),
|
|
||||||
"package": "prepay_id=" + res.PrepayId,
|
|
||||||
"signType": "MD5",
|
|
||||||
}
|
|
||||||
wcpay["paySign"] = core.JsapiSign(this.Config.GetString("wechatAppID"), wcpay.GetString("timeStamp"), wcpay.GetString("nonceStr"), wcpay.GetString("package"), "MD5", this.Config.GetString("wechatChkey"))
|
|
||||||
|
|
||||||
return wcpay
|
|
||||||
}
|
|
||||||
|
|
||||||
//生成随机码的6位md5
|
|
||||||
func getSn() string {
|
|
||||||
x := Rand(8)
|
|
||||||
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
//"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Question = Ctr{
|
|
||||||
|
|
||||||
//获取个人信息
|
|
||||||
"update": func(this *Context) {
|
|
||||||
if this.Session("user_id").Data == nil {
|
|
||||||
this.Display(2, "还没有登录")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
questionCompanyId := ObjToInt(this.Req.FormValue("id"))
|
|
||||||
if questionCompanyId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data := this.Req.FormValue("question_data")
|
|
||||||
|
|
||||||
if data == "" {
|
|
||||||
this.Display(3, "没有上传数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
status := ObjToInt(this.Req.FormValue("status"))
|
|
||||||
re := this.Db.Update("question_company", Map{"question_data": data, "status": status}, Map{"id": questionCompanyId})
|
|
||||||
if re == 0 {
|
|
||||||
//this.Display(4, "没有更新信息!")
|
|
||||||
fmt.Println(4, "没有更新信息!")
|
|
||||||
//return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, "更新成功")
|
|
||||||
|
|
||||||
},
|
|
||||||
//获取列表
|
|
||||||
"list": func(this *Context) {
|
|
||||||
if this.Session("user_id").Data == nil {
|
|
||||||
this.Display(2, "还没有登录")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
|
|
||||||
|
|
||||||
t := time.Now().Unix()
|
|
||||||
|
|
||||||
questions := this.Db.Select("question", "*", Map{"AND": Map{"org_id": user.GetCeilInt("org_id"), "start_time[>=]": t, "end_time[<=]": t, "state": 0}})
|
|
||||||
re := []Map{}
|
|
||||||
|
|
||||||
for _, v := range questions {
|
|
||||||
questionCompany := this.Db.Get("question_company", "*", Map{"AND": Map{"question_id": v.GetCeilInt("id"), "company_id": user.GetCeilInt("company_id")}})
|
|
||||||
if questionCompany == nil {
|
|
||||||
questionCompany = Map{
|
|
||||||
"name": v.GetString("name"),
|
|
||||||
"question_data": v.GetString("question_data"),
|
|
||||||
"org_id": v.GetString("org_id"),
|
|
||||||
"question_id": v.GetString("id"),
|
|
||||||
"company_id": user.GetCeilInt("company_id"),
|
|
||||||
"user_id": user.GetString("id"),
|
|
||||||
"create_time": t,
|
|
||||||
"modify_time": t,
|
|
||||||
"status": 0,
|
|
||||||
"state": 0,
|
|
||||||
}
|
|
||||||
questionCompany["id"] = this.Db.Insert("question_company", questionCompany)
|
|
||||||
if questionCompany.GetCeilInt("id") == 0 {
|
|
||||||
this.Display(4, "无法创建调查数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(v, "question")
|
|
||||||
questionCompany["question"] = v
|
|
||||||
re = append(re, questionCompany)
|
|
||||||
}
|
|
||||||
//user["questions"]=re
|
|
||||||
this.Display(0, re)
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
"../../dri/ddsms"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Sms = Ctr{
|
|
||||||
//只允许微信验证过的或者登录成功的发送短信
|
|
||||||
"send": func(this *Context) {
|
|
||||||
//if this.Session("uid").Data == nil && this.Session("wechatInfo").Data == nil {
|
|
||||||
// this.Display(2, "没有授权")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
//if len(this.Req.FormValue("token")) != 32 {
|
|
||||||
// this.Display(2, "没有授权")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
phone := this.Req.FormValue("phone")
|
|
||||||
if len(phone) < 11 {
|
|
||||||
this.Display(3, "手机号格式错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
code := getCode()
|
|
||||||
this.Session("phone", phone)
|
|
||||||
this.Session("code", code)
|
|
||||||
|
|
||||||
ddsms.DefaultDDY.SendYZM(phone, this.Config.GetString("smsLogin"), map[string]string{"code": code})
|
|
||||||
|
|
||||||
this.Display(0, "发送成功")
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../common"
|
|
||||||
)
|
|
||||||
|
|
||||||
var tagCtr = Ctr{
|
|
||||||
|
|
||||||
"ctg_tree": func(this *Context) {
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
if orgId == 0 {
|
|
||||||
this.Display(3, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data := Map{}
|
|
||||||
run := func(t int) []Map {
|
|
||||||
//upCtg:=this.Db.Select("tag_ctg","*",Map{"parent_id":id})
|
|
||||||
//for _,v:=range upCtg{
|
|
||||||
upTag := this.Db.Select("tag", "*", Map{"AND": Map{"type": t, "org_id": 2}})
|
|
||||||
upTag1 := this.Db.Select("tag", "*", Map{"AND": Map{"type": t, "org_id": orgId}})
|
|
||||||
for _, v := range upTag {
|
|
||||||
check := true
|
|
||||||
for _, v1 := range upTag1 {
|
|
||||||
if v1.GetString("sn") == v.GetString("sn") {
|
|
||||||
check = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if check {
|
|
||||||
upTag1 = append(upTag1, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return upTag1
|
|
||||||
}
|
|
||||||
|
|
||||||
data["upload"] = run(0)
|
|
||||||
data["api"] = run(1)
|
|
||||||
data["analyse"] = run(2)
|
|
||||||
|
|
||||||
this.Display(0, data)
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../common"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ADataType = Map{
|
|
||||||
|
|
||||||
"PJ": "评级",
|
|
||||||
|
|
||||||
"ZDF": "总得分",
|
|
||||||
|
|
||||||
"NZDF": "N项总得分",
|
|
||||||
|
|
||||||
"JGTZDF": "技改投资得分",
|
|
||||||
|
|
||||||
"JGTZ": "技改投资金额",
|
|
||||||
|
|
||||||
"ZJTXQLDF": "专精特新潜力得分",
|
|
||||||
|
|
||||||
"JBZJTXQYJCYQDF": "具备专精特新企业基础要求得分",
|
|
||||||
|
|
||||||
"JBZJTXQYYQCPDF": "具备专精特新企业要求产品得分",
|
|
||||||
|
|
||||||
"JBZJTXHJJTJDF": "具备专精特新环境及条件得分",
|
|
||||||
|
|
||||||
"JBZJTXZSCQYQDF": "具备专精特新知识产权要求得分",
|
|
||||||
|
|
||||||
"YFZBDF": "2年研发占比得分",
|
|
||||||
|
|
||||||
"KYRYZBDF": "科研人员占比得分",
|
|
||||||
|
|
||||||
"ZCFZLDF": "资产负债率得分",
|
|
||||||
|
|
||||||
"CYRCDF": "产业人才得分",
|
|
||||||
|
|
||||||
"SXZBDF": "3项指标",
|
|
||||||
|
|
||||||
"XZFZZBDF": "协作发展指标得分",
|
|
||||||
|
|
||||||
"FHDQZDCYDF": "符合地区重点产业得分",
|
|
||||||
|
|
||||||
"QYZDQYDF": "区域重点企业",
|
|
||||||
|
|
||||||
"SJ100HZDQYDF": "市级100户重点企业得分",
|
|
||||||
|
|
||||||
"CYL30HDF": "产业链30户得分",
|
|
||||||
|
|
||||||
"LSAQZBDF": "绿色安全指标",
|
|
||||||
|
|
||||||
"AQSCGLDF": "安全生产管理得分",
|
|
||||||
|
|
||||||
"QYAQSCDBDF": "企业安全生产是否达标得分",
|
|
||||||
|
|
||||||
"QYFXYHSKTXJSDF": "企业风险隐患双预控体系建设得分",
|
|
||||||
|
|
||||||
"AQSGDF": "安全事故得分",
|
|
||||||
|
|
||||||
"AQJCDF": "安全检查得分",
|
|
||||||
|
|
||||||
"LSSCGYDF": "绿色生产工艺得分",
|
|
||||||
|
|
||||||
"JPJSSJDF": "减排技术升级改造得分",
|
|
||||||
|
|
||||||
"HBJCDF": "环保检查得分",
|
|
||||||
|
|
||||||
"FZZLZBZDF": "发展质量指标总分",
|
|
||||||
|
|
||||||
"QYYLNLZDF": "企业盈利能力总得分",
|
|
||||||
|
|
||||||
"KSDF": "企业连续3年亏损得分",
|
|
||||||
|
|
||||||
"QYLRL": "企业利润率",
|
|
||||||
|
|
||||||
"DNLRZEDF": "当年利润总额得分",
|
|
||||||
|
|
||||||
"LXSNYLDF": "连续3年盈利得分",
|
|
||||||
|
|
||||||
"ZSCQDF": "知识产权总得分",
|
|
||||||
|
|
||||||
"TGMLDF": "推广目录得分",
|
|
||||||
|
|
||||||
"ZLDF": "专利得分",
|
|
||||||
|
|
||||||
"STTDF": "首台(套)、首批次、首版次企业得分",
|
|
||||||
|
|
||||||
"MJSR": "亩均收入",
|
|
||||||
"MJSRDF": "亩均收入得分",
|
|
||||||
|
|
||||||
"MJSS": "亩均税收",
|
|
||||||
"MJSSDF": "亩均税收得分",
|
|
||||||
|
|
||||||
"RJSR": "人均收入",
|
|
||||||
"RJSRDF": "人均收入得分",
|
|
||||||
|
|
||||||
"YFJFTRQD": "研发经费投入强度",
|
|
||||||
"YFJFTRQDDF": "研发经费投入强度得分",
|
|
||||||
|
|
||||||
"DWNHSS": "单位能耗税收",
|
|
||||||
"DWNHSSDF": "单位能耗税收得分",
|
|
||||||
|
|
||||||
"ZYWRWSS": "主要污染物税收",
|
|
||||||
"ZYWRWSSDF": "主要污染物税收得分",
|
|
||||||
|
|
||||||
"NXZBDF": "6项指标得分",
|
|
||||||
|
|
||||||
"DJSDLQYDF": "独角兽、瞪羚企业得分",
|
|
||||||
|
|
||||||
"JSZXDF": "企业获得技术中心得分",
|
|
||||||
|
|
||||||
"YFFYDF": "研发费用得分",
|
|
||||||
|
|
||||||
"GXJSQYDF": "高新技术企业得分",
|
|
||||||
|
|
||||||
"FZQLDF": "发展潜力总分",
|
|
||||||
}
|
|
@ -1,394 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"../../../hotime/dri/download"
|
|
||||||
"../../../hotime/dri/tencent"
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
//"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var User = Ctr{
|
|
||||||
"token": func(this *Context) {
|
|
||||||
this.Display(0, this.SessionId)
|
|
||||||
},
|
|
||||||
"test": func(this *Context) {
|
|
||||||
fmt.Println(this.SessionId)
|
|
||||||
this.Session("user_id", 1)
|
|
||||||
wechat := this.Db.Get("wechat", "*")
|
|
||||||
this.Session("wechatInfo", wechat)
|
|
||||||
this.Display(0, "开始测试")
|
|
||||||
},
|
|
||||||
//获取个人信息
|
|
||||||
"info": func(this *Context) {
|
|
||||||
//this.Session("user_id", 1)
|
|
||||||
//wechat:=this.Db.Get("wechat","*")
|
|
||||||
//this.Session("wechatInfo",wechat)
|
|
||||||
|
|
||||||
if this.Session("user_id").Data == nil {
|
|
||||||
if this.Session("wechatInfo").Data != nil {
|
|
||||||
|
|
||||||
wechat := this.Db.Get("wechat", "status", Map{"id": this.Session("wechatInfo").ToMap().GetCeilInt("id")})
|
|
||||||
if wechat.GetCeilInt("status") == 0 {
|
|
||||||
this.Display(6, "需要认证")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
this.Display(2, "还没有登录")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
|
|
||||||
if user == nil {
|
|
||||||
fmt.Println(this.Session("user_id").Data, ":fsdfsd")
|
|
||||||
this.Display(4, "找不到该用户")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
org := this.Db.Get("org", "contact", Map{"id": user.GetCeilInt("org_id")})
|
|
||||||
user["org"] = org
|
|
||||||
company := this.Db.Get("company", "id,name,status", Map{"id": user.GetCeilInt("company_id")})
|
|
||||||
user["company"] = company
|
|
||||||
|
|
||||||
t := time.Now().Unix()
|
|
||||||
|
|
||||||
questions := this.Db.Select("question", "*", Map{"AND": Map{"org_id": user.GetCeilInt("org_id"), "state": 0}})
|
|
||||||
re := []Map{}
|
|
||||||
|
|
||||||
for _, v := range questions {
|
|
||||||
questionCompany := this.Db.Get("question_company", "*", Map{"AND": Map{"question_id": v.GetCeilInt("id"), "company_id": user.GetCeilInt("company_id")}})
|
|
||||||
if questionCompany == nil {
|
|
||||||
questionCompany = Map{
|
|
||||||
"name": v.GetString("name"),
|
|
||||||
"question_data": v.GetString("question_data"),
|
|
||||||
"org_id": v.GetString("org_id"),
|
|
||||||
"question_id": v.GetString("id"),
|
|
||||||
"company_id": user.GetCeilInt("company_id"),
|
|
||||||
"user_id": user.GetString("id"),
|
|
||||||
"create_time": t,
|
|
||||||
"modify_time": t,
|
|
||||||
"status": 0,
|
|
||||||
"state": 0,
|
|
||||||
}
|
|
||||||
questionCompany["id"] = this.Db.Insert("question_company", questionCompany)
|
|
||||||
if questionCompany.GetCeilInt("id") == 0 {
|
|
||||||
this.Display(4, "无法创建调查数据")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(v, "question_data")
|
|
||||||
questionCompany["question"] = v
|
|
||||||
questionCompany["question_data"] = questionCompany.GetSlice("question_data")
|
|
||||||
re = append(re, questionCompany)
|
|
||||||
}
|
|
||||||
user["questions"] = re
|
|
||||||
|
|
||||||
this.Display(0, user)
|
|
||||||
|
|
||||||
},
|
|
||||||
//身份认证
|
|
||||||
"auth": func(this *Context) {
|
|
||||||
|
|
||||||
wechat := this.Session("wechatInfo").ToMap()
|
|
||||||
|
|
||||||
if wechat == nil {
|
|
||||||
if this.Session("user_id").Data == nil {
|
|
||||||
this.Display(6, "还没有登录")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wechat := this.Db.Get("wechat", "*", Map{"user_id": this.Session("user_id").ToCeilInt()})
|
|
||||||
if wechat == nil {
|
|
||||||
this.Display(6, "没有微信登录")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if this.Session("code").Data == nil {
|
|
||||||
this.Display(8, "验证码没有获取")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
////questionCompanyId:=ObjToInt(this.Req.FormValue("id"))
|
|
||||||
//if orgId == 0 {
|
|
||||||
// this.Display(3, "没有选择组织")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
name := this.Req.FormValue("name")
|
|
||||||
phone := this.Req.FormValue("phone")
|
|
||||||
code := this.Req.FormValue("code")
|
|
||||||
authImg := this.Req.FormValue("auth_img")
|
|
||||||
categoryId := ObjToInt(this.Req.FormValue("category_id"))
|
|
||||||
companyImg := this.Req.FormValue("company_img")
|
|
||||||
companyName := this.Req.FormValue("company_name")
|
|
||||||
companySn := this.Req.FormValue("company_sn")
|
|
||||||
|
|
||||||
if code != this.Session("code").ToStr() {
|
|
||||||
this.Display(8, "验证码错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if name == "" || phone == "" || authImg == "" || categoryId == 0 || companyImg == "" || companyName == "" || companySn == "" {
|
|
||||||
this.Display(3, "参数异常")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t := time.Now().Unix()
|
|
||||||
|
|
||||||
orgId := wechat.GetInt("org_id")
|
|
||||||
|
|
||||||
company := this.Db.Get("company", "id", Map{"sn": companySn})
|
|
||||||
if company == nil {
|
|
||||||
company = Map{
|
|
||||||
"name": companyName,
|
|
||||||
"sn": companySn,
|
|
||||||
"create_time": t,
|
|
||||||
"category_id": categoryId,
|
|
||||||
//"org_id": orgId,
|
|
||||||
"modify_time": t,
|
|
||||||
"status": 1,
|
|
||||||
"state": 0,
|
|
||||||
"img": companyImg,
|
|
||||||
}
|
|
||||||
if wechat.GetInt("status") == 0 && orgId != 0 {
|
|
||||||
company["org_id"] = orgId
|
|
||||||
}
|
|
||||||
|
|
||||||
company["id"] = this.Db.Insert("company", company)
|
|
||||||
|
|
||||||
if company.GetCeilInt("id") == 0 {
|
|
||||||
this.Display(4, "无法创建企业")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
company["status"] = 1
|
|
||||||
company["modify_time"] = t
|
|
||||||
company["img"] = companyImg
|
|
||||||
company["name"] = companyName
|
|
||||||
company["img"] = companyImg
|
|
||||||
if wechat.GetInt("status") == 0 && orgId != 0 {
|
|
||||||
company["org_id"] = orgId
|
|
||||||
}
|
|
||||||
re := this.Db.Update("company", company, Map{"id": company.GetCeilInt("id")})
|
|
||||||
if re == 0 {
|
|
||||||
this.Display(4, "无法更新企业")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
user := this.Db.Get("user", "*", Map{"phone": phone})
|
|
||||||
data := Map{"name": name,
|
|
||||||
"phone": phone,
|
|
||||||
//"org_id": orgId,
|
|
||||||
//"idcard": idcard,
|
|
||||||
//"idcard_front_img": idcardFrontImg,
|
|
||||||
"company_id": company.GetCeilInt("id"),
|
|
||||||
//"idcard_back_img": idcardBackImg,
|
|
||||||
"auth_img": authImg,
|
|
||||||
"modify_time": t,
|
|
||||||
"status": 1,
|
|
||||||
"company_img": companyImg}
|
|
||||||
if wechat.GetInt("status") == 0 && orgId != 0 {
|
|
||||||
data["org_id"] = orgId
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户已经注册则更新
|
|
||||||
if user != nil {
|
|
||||||
re := this.Db.Update("user", data, Map{"id": user.GetCeilInt("id")})
|
|
||||||
if re == 0 {
|
|
||||||
this.Display(4, "无法更新用户")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data["create_time"] = t
|
|
||||||
if wechat != nil {
|
|
||||||
data["nickname"] = wechat.GetString("nickname")
|
|
||||||
path := time.Now().Format(this.Config.GetString("imgPath"))
|
|
||||||
filename := Md5(ObjToStr(t)) + ".jpg"
|
|
||||||
down := download.Down(wechat.GetString("avatar"), this.Config.GetString("tpt")+"/"+path, filename)
|
|
||||||
if down {
|
|
||||||
data["avatar"] = path + filename
|
|
||||||
}
|
|
||||||
}
|
|
||||||
user = data
|
|
||||||
user["id"] = this.Db.Insert("user", data)
|
|
||||||
if user.GetCeilInt("id") == 0 {
|
|
||||||
this.Display(4, "无法创建用户")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Db.Update("wechat", Map{"status": 1, "user_id": user.GetCeilInt("id")}, Map{"id": wechat.GetInt("id")})
|
|
||||||
|
|
||||||
this.Session("user_id", user.GetCeilInt("id"))
|
|
||||||
this.Display(0, this.SessionId)
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
//修改密码g
|
|
||||||
"forget": func(this *Context) {
|
|
||||||
if this.Session("code").Data == nil {
|
|
||||||
this.Display(8, "验证码没有获取")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if this.Req.FormValue("code") == "" || this.Req.FormValue("umobile") == "" {
|
|
||||||
this.Display(3, "验证码或者手机号没有输入")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if this.Req.FormValue("umobile") != this.Session("umobile").ToStr() ||
|
|
||||||
this.Req.FormValue("code") != this.Session("code").ToStr() {
|
|
||||||
this.Display(14, "验证码验证失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(this.Req.FormValue("upwd")) < 6 {
|
|
||||||
this.Display(3, "密码没有输入")
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
res := this.Db.Update("user", Map{"upwd": Md5(this.Req.FormValue("upwd"))}, Map{"umobile": this.Req.FormValue("umobile")})
|
|
||||||
if res == 0 {
|
|
||||||
this.Display(5, "找不到该用户")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, "成功")
|
|
||||||
},
|
|
||||||
|
|
||||||
"upload": func(this *Context) {
|
|
||||||
file := this.Req.FormValue("file")
|
|
||||||
|
|
||||||
if len(file) < 100 {
|
|
||||||
this.Display(3, "图片上传错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//fmt.Println(uimg)
|
|
||||||
|
|
||||||
btes, e := base64.StdEncoding.DecodeString(file[strings.Index(file, ",")+1:]) //成图片文件并把文件写入到buffer
|
|
||||||
//btes, e := base64.StdEncoding.DecodeString(file) //成图片文件并把文件写入到buffer
|
|
||||||
if e != nil {
|
|
||||||
this.Display(3, "无法解析图片")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//uimgPath:=time.Now().Format(this.Config.GetString("uimgPath"))
|
|
||||||
path := time.Now().Format(this.Config.GetString("wxFilePath"))
|
|
||||||
os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|
||||||
filePath := path + Md5(ObjToStr(time.Now().Unix())) + ".jpg"
|
|
||||||
|
|
||||||
err2 := ioutil.WriteFile(this.Config.GetString("tpt")+"/"+filePath, btes, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件)
|
|
||||||
|
|
||||||
if err2 != nil {
|
|
||||||
this.Display(3, "图片保存失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tp := this.Req.FormValue("type")
|
|
||||||
|
|
||||||
if tp == "company" {
|
|
||||||
data := tencent.OCRCOMPANY(file)
|
|
||||||
c := ObjToMap(data)
|
|
||||||
if c != nil {
|
|
||||||
c = c.GetMap("Response")
|
|
||||||
c["url"] = filePath
|
|
||||||
|
|
||||||
} else {
|
|
||||||
c = Map{"url": filePath}
|
|
||||||
}
|
|
||||||
this.Display(0, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if tp == "common" {
|
|
||||||
data := tencent.OCR(file)
|
|
||||||
c := ObjToMap(data)
|
|
||||||
if c != nil {
|
|
||||||
c = c.GetMap("Response")
|
|
||||||
c["url"] = filePath
|
|
||||||
} else {
|
|
||||||
c = Map{"url": filePath}
|
|
||||||
}
|
|
||||||
this.Display(0, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, filePath)
|
|
||||||
},
|
|
||||||
//"upload": func(this *Context) {
|
|
||||||
//
|
|
||||||
// //读取网络文件
|
|
||||||
// fi, fheader, err := this.Req.FormFile("file")
|
|
||||||
// if err != nil {
|
|
||||||
// this.Display(3, err)
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// filePath := this.Config.GetString("wxFilePath")
|
|
||||||
// if filePath == "" {
|
|
||||||
// filePath = "file/2006/01/02/"
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// path := time.Now().Format(filePath)
|
|
||||||
// e := os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|
||||||
//
|
|
||||||
// if e != nil {
|
|
||||||
// this.Display(3, e)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
|
||||||
// newFile, e := os.Create(this.Config.GetString("tpt") + "/" + filePath)
|
|
||||||
//
|
|
||||||
// if e != nil {
|
|
||||||
// this.Display(3, e)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _, e = io.Copy(newFile, fi)
|
|
||||||
//
|
|
||||||
// if e != nil {
|
|
||||||
// this.Display(3, e)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //this.Display(0, filePath)
|
|
||||||
//
|
|
||||||
// //读取excel
|
|
||||||
// //fmt.Println(Org[orgId],OrgId)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// this.Display(0, filePath)
|
|
||||||
//
|
|
||||||
//},
|
|
||||||
//更新个人资料
|
|
||||||
"update": func(this *Context) {
|
|
||||||
if this.Req.Form["email"] == nil ||
|
|
||||||
this.Req.Form["name"] == nil ||
|
|
||||||
//this.Req.Form["phone"] == nil ||
|
|
||||||
this.Req.Form["avatar"] == nil ||
|
|
||||||
this.Req.Form["idcard"] == nil {
|
|
||||||
this.Display(3, "参数不足")
|
|
||||||
}
|
|
||||||
//更新代码
|
|
||||||
update := Map{
|
|
||||||
"email": this.Req.FormValue("email"),
|
|
||||||
"idcard": this.Req.FormValue("idcard"),
|
|
||||||
"avatar": this.Req.FormValue("avatar"),
|
|
||||||
"name": this.Req.FormValue("name"),
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Db.Update("user", update, Map{"id": this.Session("user_id").Data})
|
|
||||||
this.Display(0, "ok")
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,177 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
. "../../../hotime"
|
|
||||||
. "../../../hotime/cache"
|
|
||||||
. "../../../hotime/common"
|
|
||||||
"fmt"
|
|
||||||
"github.com/silenceper/wechat"
|
|
||||||
"github.com/silenceper/wechat/cache"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WechatCache struct {
|
|
||||||
CacheIns
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this WechatCache) Get(key string) interface{} {
|
|
||||||
return this.Cache("x" + key).Data
|
|
||||||
//return nil
|
|
||||||
}
|
|
||||||
func (this WechatCache) Set(key string, val interface{}, timeout time.Duration) error {
|
|
||||||
|
|
||||||
this.Cache("x"+key, val, ObjToInt64(timeout.Seconds()))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this WechatCache) IsExist(key string) bool {
|
|
||||||
c := this.Cache("x" + key).Data
|
|
||||||
if c != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
|
|
||||||
}
|
|
||||||
func (this WechatCache) Delete(key string) error {
|
|
||||||
this.Cache("x"+key, nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var Wechat = Ctr{
|
|
||||||
"user": func(this *Context) {
|
|
||||||
if this.Session("wechatInfo").Data == nil {
|
|
||||||
this.Display(2, "没有登录")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, this.Session("wechatInfo").ToMap())
|
|
||||||
},
|
|
||||||
//微信注册,0已经完整的注册了,1还没有注册
|
|
||||||
"codebase": func(this *Context) {
|
|
||||||
wx := Weixin(this)
|
|
||||||
auth := wx.GetOauth(this.Req, this.Resp)
|
|
||||||
resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
|
|
||||||
if err != nil {
|
|
||||||
this.Display(6, "code错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//判断用户是否已经注册
|
|
||||||
user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
|
|
||||||
if user != nil {
|
|
||||||
this.Session("user_id", user.Get("id"))
|
|
||||||
this.Display(0, 0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user_id := this.Db.Insert("user", Map{"time": time.Now().Unix(), "state": 2})
|
|
||||||
if user_id == 0 {
|
|
||||||
this.Display(4, "创建用户失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
wid := this.Db.Insert("wechat", Map{"openid": resToken.OpenID, "appid": this.Config.GetString("wechatAppID"), "state": 1, "user_id": user_id})
|
|
||||||
if wid == 0 {
|
|
||||||
this.Display(4, "关联微信失败!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Session("user_id", user.Get("id"))
|
|
||||||
|
|
||||||
this.Display(0, 1)
|
|
||||||
},
|
|
||||||
//微信注册,0已经完整的注册了,1还没有注册
|
|
||||||
"code": func(this *Context) {
|
|
||||||
|
|
||||||
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|
||||||
//if orgId==0{
|
|
||||||
// this.Display(3, "缺少组织id")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
wx := Weixin(this)
|
|
||||||
auth := wx.GetOauth(this.Req, this.Resp)
|
|
||||||
resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
|
|
||||||
if err != nil {
|
|
||||||
this.Display(5, "code错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//判断用户是否已经注册
|
|
||||||
user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
|
|
||||||
if user != nil && user.GetCeilInt("id") != 0 && user.GetCeilInt("state") == 0 {
|
|
||||||
this.Session("user_id", user.Get("id"))
|
|
||||||
this.Display(0, Map{"type": 0, "token": this.SessionId})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//getUserInfo
|
|
||||||
userInfo, err := auth.GetUserInfo(resToken.AccessToken, resToken.OpenID)
|
|
||||||
if err != nil {
|
|
||||||
this.Display(6, "微信个人信息无法获取")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//wechatInfo := ObjToMap(userInfo)
|
|
||||||
t := time.Now().Unix()
|
|
||||||
wechatInfo := Map{
|
|
||||||
"openid": userInfo.OpenID,
|
|
||||||
"acttoken": resToken.AccessToken,
|
|
||||||
"retoken": resToken.RefreshToken,
|
|
||||||
"appid": this.Config.GetString("wechatAppID"),
|
|
||||||
"unionid": userInfo.Unionid,
|
|
||||||
"nickname": userInfo.Nickname,
|
|
||||||
"avatar": userInfo.HeadImgURL,
|
|
||||||
}
|
|
||||||
if orgId != 0 {
|
|
||||||
wechatInfo["org_id"] = orgId
|
|
||||||
wechatInfo["status"] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
wechatDb := this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
|
|
||||||
|
|
||||||
if wechatDb != nil {
|
|
||||||
|
|
||||||
this.Db.Update("wechat", wechatInfo, Map{"id": wechatDb.GetCeilInt("id")})
|
|
||||||
//userInfo["wid"]=wechatDb.GetCeilInt("wid")
|
|
||||||
} else {
|
|
||||||
wechatInfo["create_time"] = t
|
|
||||||
wechatInfo["id"] = this.Db.Insert("wechat", wechatInfo)
|
|
||||||
}
|
|
||||||
wechatDb = this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
|
|
||||||
|
|
||||||
this.Session("wechatInfo", wechatDb)
|
|
||||||
fmt.Println(wechatDb)
|
|
||||||
fmt.Println(this.Session("wechatInfo"))
|
|
||||||
//this.Display(0, 1)
|
|
||||||
this.Display(0, Map{"type": 1, "token": this.SessionId})
|
|
||||||
},
|
|
||||||
//网页签名
|
|
||||||
"sign": func(this *Context) {
|
|
||||||
|
|
||||||
if this.Req.FormValue("sign_url") == "" {
|
|
||||||
this.Display(2, "参数不足")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if weixin == nil {
|
|
||||||
cache1 := cache.Cache(WechatCache{this.CacheIns})
|
|
||||||
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppID"), AppSecret: this.Config.GetString("wechatAppSecret")}
|
|
||||||
weixin = wechat.NewWechat(&config)
|
|
||||||
}
|
|
||||||
|
|
||||||
js := weixin.GetJs(this.Req, this.Resp)
|
|
||||||
cfg, e := js.GetConfig(this.Req.FormValue("sign_url"))
|
|
||||||
if e != nil {
|
|
||||||
this.Display(7, e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
sign := Map{
|
|
||||||
"appId": cfg.AppID,
|
|
||||||
"timestamp": cfg.TimeStamp,
|
|
||||||
"nonceStr": cfg.NonceStr,
|
|
||||||
"signature": cfg.Signature,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Display(0, sign)
|
|
||||||
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,14 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"../../hotime"
|
"code.hoteas.com/golang/hotime"
|
||||||
"strings"
|
|
||||||
|
|
||||||
//"../dri/aliyun"
|
|
||||||
"../dri/baidu"
|
|
||||||
"../dri/ddsms"
|
|
||||||
"./admin"
|
|
||||||
"./app"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -16,71 +9,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
||||||
fmt.Println(date, date.Unix())
|
fmt.Println(date, date.Unix())
|
||||||
|
|
||||||
baidu.DefaultBaiDuMap.Init("ZeT902EZvVgIoGVWEFK3osUm")
|
|
||||||
//fmt.Println("0123456"[1:7])
|
//fmt.Println("0123456"[1:7])
|
||||||
appIns := hotime.Init("config/config.json")
|
appIns := hotime.Init("config/config.json")
|
||||||
notNeedLogin := []string{"token", "login", "test", "auth", "upload", "info"} //不需要登录的操作
|
appIns.Run(hotime.Router{})
|
||||||
//RESTfull接口适配
|
|
||||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
|
||||||
|
|
||||||
if len(context.RouterString) > 0 && context.RouterString[0] == "admin" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//判断是否需要登录,不需要登录则直接执行mtd
|
|
||||||
if len(context.RouterString) == 3 && !strings.Contains(context.RouterString[2], ".") {
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "user" {
|
|
||||||
isNeedLogin := true
|
|
||||||
for i := 0; i < len(notNeedLogin); i++ {
|
|
||||||
if notNeedLogin[i] == context.RouterString[2] {
|
|
||||||
isNeedLogin = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isNeedLogin {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//微信操作无需登录
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "wechat" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//微信操作无需登录
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "sms" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//微信操作无需登录
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "tag" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//微信操作无需登录
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "analyse" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//微信操作无需登录
|
|
||||||
if context.RouterString[0] == "app" && context.RouterString[1] == "category" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
//没有登录
|
|
||||||
if context.Session("user_id").Data == nil {
|
|
||||||
context.Display(2, "没有登录")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//支撑权限设置
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
appIns.Router["admin"]["company_inout"] = admin.CompanyInOutCtr
|
|
||||||
appIns.Router["admin"]["test"] = admin.TestCtr
|
|
||||||
|
|
||||||
//makeCode := code.MakeCode{}
|
|
||||||
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
|
|
||||||
if ddsms.DefaultDDY.ApiKey == "" {
|
|
||||||
ddsms.DefaultDDY.Init(appIns.Config.GetString("smsKey"))
|
|
||||||
}
|
|
||||||
|
|
||||||
appIns.Run(hotime.Router{
|
|
||||||
"app": app.Project,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
13
go.mod
Normal file
13
go.mod
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module code.hoteas.com/golang/hotime
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/garyburd/redigo v1.6.3
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12
|
||||||
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
||||||
|
)
|
27
go.sum
Normal file
27
go.sum
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
|
||||||
|
github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||||
|
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 h1:X1Jws4XqrTH+p7FBQ7BpjW4qFXObKHWm0/XhW/GvqRs=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 h1:kbor60vo37v7Hu+i17gooox9Rw281fVHNna8zwtDG1w=
|
||||||
|
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364/go.mod h1:LeIUBOLhc+Y5YCEpZrULPD9lgoXXV4/EmIcoEvmHz9c=
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||||
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||||
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
@ -44,17 +44,17 @@ func Run() {
|
|||||||
appIns.Run(hotime.Router{
|
appIns.Run(hotime.Router{
|
||||||
"app": hotime.Proj{
|
"app": hotime.Proj{
|
||||||
"index": hotime.Ctr{
|
"index": hotime.Ctr{
|
||||||
"test": func(this *hotime.Context) {
|
"test": func(that *hotime.Context) {
|
||||||
fmt.Println(this.Db.GetTag())
|
fmt.Println(that.Db.GetTag())
|
||||||
//x := this.Db.Action(func(db hotime.HoTimeDB) bool {
|
//x := that.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||||
//
|
//
|
||||||
// db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
// db.Insert("user", hotime.Map{"unickname": "dasdas"})
|
||||||
//
|
//
|
||||||
// return true
|
// return true
|
||||||
//})
|
//})
|
||||||
this.Display(0, 1)
|
that.Display(0, 1)
|
||||||
},
|
},
|
||||||
"websocket": func(this *hotime.Context) {
|
"websocket": func(that *hotime.Context) {
|
||||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||||
for true {
|
for true {
|
||||||
msg := make([]byte, 5120)
|
msg := make([]byte, 5120)
|
||||||
@ -73,7 +73,7 @@ func Run() {
|
|||||||
fmt.Printf("Send: %s\n", msg[:m])
|
fmt.Printf("Send: %s\n", msg[:m])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
hdler.ServeHTTP(this.Resp, this.Req)
|
hdler.ServeHTTP(that.Resp, that.Req)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "./cache"
|
. "code.hoteas.com/golang/hotime/cache"
|
||||||
. "./common"
|
. "code.hoteas.com/golang/hotime/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//session对象
|
//session对象
|
||||||
|
2
type.go
2
type.go
@ -5,4 +5,4 @@ type Ctr map[string]Method
|
|||||||
type Proj map[string]Ctr
|
type Proj map[string]Ctr
|
||||||
type Router map[string]Proj
|
type Router map[string]Proj
|
||||||
type MethodRouter map[string]Method //直接字符串关联函数
|
type MethodRouter map[string]Method //直接字符串关联函数
|
||||||
type Method func(this *Context)
|
type Method func(that *Context)
|
||||||
|
Loading…
Reference in New Issue
Block a user