diff --git a/application.go b/application.go index 2577ae0..67bf7fd 100644 --- a/application.go +++ b/application.go @@ -420,8 +420,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { header.Set("Cache-Control", "no-cache") } - if strings.Index(path, ".m3u8") != -1 { - header.Add("Content-Type", "audio/mpegurl") + t := strings.LastIndex(path, ".") + if t != -1 { + tt := path[t:] + + if MimeMaps[tt] != "" { + + header.Add("Content-Type", MimeMaps[tt]) + } } //w.Write(data) diff --git a/example/app/analyse.go b/example/app/analyse.go index ba8e594..294d761 100644 --- a/example/app/analyse.go +++ b/example/app/analyse.go @@ -3,6 +3,10 @@ package app import ( . "../../../hotime" . "../../common" + "fmt" + "github.com/xuri/excelize" + "os" + "sort" "time" ) @@ -25,6 +29,80 @@ var analyseCtr = Ctr{ 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 { @@ -83,7 +161,6 @@ var analyseCtr = Ctr{ 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, "找不到该数据") @@ -95,7 +172,67 @@ var analyseCtr = Ctr{ 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")) @@ -188,6 +325,7 @@ var analyseCtr = Ctr{ 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 != "" { @@ -206,7 +344,12 @@ var analyseCtr = Ctr{ if len(where) > 1 { where = Map{"AND": where} } - where["ORDER"] = "score DESC" + if sort != "" { + where["ORDER"] = sort + } else { + where["ORDER"] = "score DESC" + } + if page == 0 { page = 1 } @@ -231,28 +374,29 @@ var analyseCtr = Ctr{ 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) - } + //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 { diff --git a/example/app/user.go b/example/app/user.go index 00cd758..0c20b45 100644 --- a/example/app/user.go +++ b/example/app/user.go @@ -39,7 +39,7 @@ var User = Ctr{ 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}}) + questions := this.Db.Select("question", "*", Map{"AND": Map{"org_id": user.GetCeilInt("org_id"), "state": 0}}) re := []Map{} for _, v := range questions { diff --git a/example/iedc.exe b/example/iedc.exe index b008b94..89e003b 100644 Binary files a/example/iedc.exe and b/example/iedc.exe differ diff --git a/example/tpt/index.html b/example/tpt/index.html index db92c60..2cf67f3 100644 --- a/example/tpt/index.html +++ b/example/tpt/index.html @@ -1,3 +1,3 @@
\ No newline at end of file + }
\ No newline at end of file