forked from golang/hotime
技术性调整
This commit is contained in:
parent
f7410200e3
commit
f390617167
116
code.go
116
code.go
@ -420,6 +420,103 @@ var TptProject = Proj{
|
||||
|
||||
that.Display(0, filePath)
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
tableName := fileConfig.GetString("table")
|
||||
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(tableName, data, that.Db)
|
||||
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(tableName, str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
seStr := "id," + column.GetString("value")
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
|
||||
//权限设置
|
||||
if column["type"] == "auth" {
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
userAuth := re.GetMap("auth")
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if userAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("name")]
|
||||
}
|
||||
for k2, _ := range v1.GetSlice("menus") {
|
||||
v2 := menus.GetMap(k2)
|
||||
if userAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("name")]
|
||||
}
|
||||
}
|
||||
}
|
||||
re["auth"] = menus
|
||||
//that.Display(0,menus)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//如果有table字段则代为link
|
||||
if re["table"] != nil && re["table_id"] != nil {
|
||||
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][re.GetString("table")]
|
||||
v := re.GetCeilInt64("table_id")
|
||||
|
||||
seStr := "id," + column.GetString("value")
|
||||
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
|
||||
}
|
||||
re["table"] = fileConfig.GetString("table")
|
||||
that.Display(0, re)
|
||||
},
|
||||
"login": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@ -430,7 +527,16 @@ var TptProject = Proj{
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
|
||||
where := Map{"name": name}
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||
where["phone"] = name
|
||||
where = Map{"AND": Map{"OR": where}, "password": Md5(password)}
|
||||
} else {
|
||||
where["password"] = Md5(password)
|
||||
}
|
||||
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
||||
|
||||
if user == nil {
|
||||
that.Display(5, "登录失败")
|
||||
@ -440,8 +546,10 @@ var TptProject = Proj{
|
||||
that.Session(fileConfig.GetString("table")+"_name", name)
|
||||
delete(user, "password")
|
||||
user["table"] = fileConfig.GetString("table")
|
||||
user["token"] = that.SessionId
|
||||
that.Display(0, user)
|
||||
},
|
||||
|
||||
"logout": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@ -496,7 +604,7 @@ var TptProject = Proj{
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := menus.GetMap(k2)
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if linkAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||
}
|
||||
@ -559,9 +667,9 @@ var TptProject = Proj{
|
||||
}
|
||||
}
|
||||
|
||||
config["tables"] = newTables
|
||||
conf["tables"] = newTables
|
||||
|
||||
that.Display(0, config)
|
||||
that.Display(0, conf)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.6.253",
|
||||
"name": "gov_crawler",
|
||||
"name": "iedc_dev",
|
||||
"password": "dasda8454456",
|
||||
"port": "3306",
|
||||
"user": "root"
|
||||
|
@ -4,9 +4,29 @@ import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
"golang.org/x/net/websocket"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func convertToTitle(columnNumber int) string {
|
||||
var res []byte
|
||||
for columnNumber > 0 {
|
||||
a := columnNumber % 26
|
||||
if a == 0 {
|
||||
a = 26
|
||||
}
|
||||
res = append(res, 'A'+byte(a-1))
|
||||
columnNumber = (columnNumber - a) / 26
|
||||
}
|
||||
// 上面输出的res是反着的,前后交换
|
||||
for i, n := 0, len(res); i < n/2; i++ {
|
||||
res[i], res[n-1-i] = res[n-1-i], res[i]
|
||||
}
|
||||
return string(res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
appIns := Init("config/config.json")
|
||||
@ -22,6 +42,83 @@ func main() {
|
||||
//that.Display(0, Slice{id, ok, ps, p, row})
|
||||
that.Display(0, Slice{ps, p})
|
||||
},
|
||||
"download": func(that *Context) {
|
||||
orgId := ObjToInt(that.Req.FormValue("org_id"))
|
||||
if orgId == 0 {
|
||||
that.Display(3, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
filePath := "temp/home" + ObjToStr(orgId) + ".xlsx"
|
||||
f, e := excelize.OpenFile(that.Config.GetString("tpt") + "/" + filePath)
|
||||
// 设置单元格的值
|
||||
questions := that.Db.Query("SELECT user.name AS user_name,user.phone,company.name AS company_name,question_company.name,question_company.question_data,question_company.status,question_company.modify_time FROM question_company INNER JOIN `user` ON question_company.`user_id`=`user`.id INNER JOIN `company` ON question_company.`company_id`=`company`.id WHERE question_company.org_id=?", orgId)
|
||||
if e != nil {
|
||||
f = excelize.NewFile()
|
||||
}
|
||||
// 创建一个工作表
|
||||
f.NewSheet("企业填报")
|
||||
|
||||
f.DeleteSheet("Sheet1")
|
||||
|
||||
//cs := append(NewCompanys{}, companys...)
|
||||
f.SetCellValue("企业填报", convertToTitle(1)+"1", "调查名")
|
||||
f.SetCellValue("企业填报", convertToTitle(2)+"1", "企业名")
|
||||
f.SetCellValue("企业填报", convertToTitle(3)+"1", "姓名")
|
||||
f.SetCellValue("企业填报", convertToTitle(4)+"1", "手机号")
|
||||
f.SetCellValue("企业填报", convertToTitle(5)+"1", "状态")
|
||||
f.SetCellValue("企业填报", convertToTitle(6)+"1", "修改时间")
|
||||
for k, question := range questions {
|
||||
//企业基础信息
|
||||
f.SetCellValue("企业填报", convertToTitle(1)+ObjToStr(k+5), question.GetString("name"))
|
||||
f.SetCellValue("企业填报", convertToTitle(2)+ObjToStr(k+5), question.GetString("company_name"))
|
||||
f.SetCellValue("企业填报", convertToTitle(3)+ObjToStr(k+5), question.GetString("user_name"))
|
||||
f.SetCellValue("企业填报", convertToTitle(4)+ObjToStr(k+5), question.GetString("phone"))
|
||||
f.SetCellValue("企业填报", convertToTitle(5)+ObjToStr(k+5), question.GetString("status"))
|
||||
f.SetCellValue("企业填报", convertToTitle(6)+ObjToStr(k+5), time.Unix(question.GetCeilInt64("modify_time"), 0).Format("2006-01-02 15:04"))
|
||||
//企业问题信息基础信息
|
||||
questionData := question.GetSlice("question_data")
|
||||
for k1, _ := range questionData {
|
||||
v1 := questionData.GetMap(k1)
|
||||
if k == 0 {
|
||||
f.SetCellValue("企业填报", convertToTitle(k1+7)+"1", v1.GetString("label"))
|
||||
f.SetCellValue("企业填报", convertToTitle(k1+7)+"2", v1.GetString("unit"))
|
||||
f.SetCellValue("企业填报", convertToTitle(k1+7)+"3", v1.GetString("remarks"))
|
||||
f.SetCellValue("企业填报", convertToTitle(k1+7)+"4", v1.GetString("type"))
|
||||
}
|
||||
value := v1.GetString("value")
|
||||
extend := v1.GetSlice("extend")
|
||||
if extend != nil && len(extend) > 0 {
|
||||
for k2, _ := range extend {
|
||||
v2 := extend.GetMap(k2)
|
||||
value = value + ";" + v2.GetString("value")
|
||||
}
|
||||
}
|
||||
|
||||
f.SetCellValue("企业填报", convertToTitle(k1+7)+ObjToStr(k+5), value)
|
||||
|
||||
}
|
||||
|
||||
//break
|
||||
|
||||
}
|
||||
|
||||
os.MkdirAll(that.Config.GetString("tpt")+"/temp/", os.ModeDir)
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs(that.Config.GetString("tpt") + "/" + filePath); err != nil {
|
||||
fmt.Println(err)
|
||||
that.Display(4, "输出异常")
|
||||
return
|
||||
}
|
||||
|
||||
//}
|
||||
f.Save()
|
||||
that.Resp.Header().Set("Location", "/"+filePath)
|
||||
that.Resp.WriteHeader(307) //关键在这里!
|
||||
that.Display(0, filePath)
|
||||
|
||||
},
|
||||
|
||||
"websocket": func(that *Context) {
|
||||
hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||
for true {
|
||||
|
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module code.hoteas.com/golang/hotime
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1
|
||||
github.com/garyburd/redigo v1.6.3
|
||||
github.com/go-pay/gopay v1.5.78
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
|
5
go.sum
5
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
@ -21,6 +23,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
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/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@ -33,6 +37,7 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
@ -1,3 +1,6 @@
|
||||
# github.com/360EntSecGroup-Skylar/excelize v1.4.1
|
||||
## explicit
|
||||
github.com/360EntSecGroup-Skylar/excelize
|
||||
# github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
|
||||
github.com/bradfitz/gomemcache/memcache
|
||||
# github.com/fatih/structs v1.1.0
|
||||
@ -25,6 +28,8 @@ github.com/gomodule/redigo/redis
|
||||
# github.com/mattn/go-sqlite3 v1.14.12
|
||||
## explicit
|
||||
github.com/mattn/go-sqlite3
|
||||
# github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||
github.com/mohae/deepcopy
|
||||
# github.com/silenceper/wechat/v2 v2.1.2
|
||||
## explicit
|
||||
github.com/silenceper/wechat/v2
|
||||
|
Loading…
Reference in New Issue
Block a user