2022-01-22 08:12:02 +00:00
package app
import (
. "../../../hotime"
2022-01-22 21:13:19 +00:00
. "../../common"
2022-03-02 04:14:07 +00:00
"fmt"
"github.com/xuri/excelize"
"os"
"sort"
2022-01-22 21:13:19 +00:00
"time"
2022-01-22 08:12:02 +00:00
)
var analyseCtr = Ctr {
2022-01-22 21:13:19 +00:00
2022-01-22 08:12:02 +00:00
"home_data" : func ( this * Context ) {
orgId := ObjToInt ( this . Req . FormValue ( "org_id" ) )
if orgId == 0 {
this . Display ( 3 , "参数错误" )
return
}
2022-02-19 13:38:17 +00:00
res := this . Db . Get ( "org_analyse" , "*" , Map { "org_id" : orgId } )
2022-01-22 08:12:02 +00:00
if res == nil {
this . Display ( 4 , "找不到该数据" )
return
}
res [ "home_data" ] = res . GetMap ( "home_data" )
2022-02-19 13:38:17 +00:00
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" )
2022-02-16 20:10:53 +00:00
this . Display ( 0 , res )
} ,
2022-03-02 04:14:07 +00:00
"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 )
} ,
2022-02-16 20:10:53 +00:00
"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" )
2022-01-22 08:12:02 +00:00
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 )
} ,
2022-01-26 03:45:17 +00:00
2022-01-22 08:12:02 +00:00
"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 )
} ,
2022-01-26 03:45:17 +00:00
"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 )
} ,
2022-03-02 04:14:07 +00:00
"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")
2022-01-22 08:12:02 +00:00
2022-03-02 04:14:07 +00:00
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 )
} ,
2022-01-22 08:12:02 +00:00
"map" : func ( this * Context ) {
2022-01-26 03:45:17 +00:00
orgId := ObjToInt ( this . Req . FormValue ( "org_id" ) )
industryId := ObjToInt ( this . Req . FormValue ( "industry_id" ) )
//if orgId == 0 || industryId == 0 {
// this.Display(3, "参数错误")
// return
//}
2022-01-22 08:12:02 +00:00
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 )
}
2022-01-26 03:45:17 +00:00
if orgId != 0 {
where [ "org_id" ] = orgId
}
if industryId != 0 {
where [ "industry_id" ] = industryId
}
2022-01-22 08:12:02 +00:00
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 )
2022-02-14 11:10:58 +00:00
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" ,
2022-01-22 08:12:02 +00:00
where )
2022-02-14 11:10:58 +00:00
for _ , res := range companys {
res [ "collect_data" ] = res . GetMap ( "collect_data" )
2022-02-19 13:38:17 +00:00
//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")
// }
//}
2022-02-14 11:10:58 +00:00
}
this . Display ( 0 , Map { "count" : count , "pageSize" : pageSize , "data" : companys } )
2022-01-22 08:12:02 +00:00
} ,
"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 , "更新成功" )
} ,
2022-01-26 03:45:17 +00:00
2022-01-22 08:12:02 +00:00
"companys" : func ( this * Context ) {
page := ObjToInt ( this . Req . FormValue ( "page" ) )
pageSize := ObjToInt ( this . Req . FormValue ( "pageSize" ) )
2022-02-23 22:26:36 +00:00
orgId := ObjToInt ( this . Req . FormValue ( "org_id" ) )
2022-01-22 08:12:02 +00:00
search := this . Req . FormValue ( "search" )
2022-03-02 04:14:07 +00:00
sort := this . Req . FormValue ( "sort" )
2022-02-23 22:26:36 +00:00
where := Map { "state" : 0 }
2022-01-22 08:12:02 +00:00
levelStr := this . Req . FormValue ( "level" )
if levelStr != "" {
where [ "level" ] = ObjToInt ( levelStr )
}
2022-02-14 11:10:58 +00:00
industryId := ObjToInt ( this . Req . FormValue ( "industry_id" ) )
if industryId != 0 {
where [ "industry_id" ] = industryId
}
2022-02-23 22:26:36 +00:00
if orgId != 0 {
where [ "org_id" ] = orgId
}
2022-01-22 08:12:02 +00:00
if search != "" {
where [ "name[~]" ] = search
}
if len ( where ) > 1 {
where = Map { "AND" : where }
}
2022-03-02 04:14:07 +00:00
if sort != "" {
where [ "ORDER" ] = sort
} else {
where [ "ORDER" ] = "score DESC"
}
2022-01-22 08:12:02 +00:00
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 10
}
count := this . Db . Count ( "company" , where )
2022-02-14 11:10:58 +00:00
companys := this . Db . Page ( page , pageSize ) . PageSelect ( "company" ,
"*" ,
2022-01-22 08:12:02 +00:00
where )
2022-02-14 11:10:58 +00:00
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" )
2022-03-06 15:55:14 +00:00
//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)
//}
2022-02-14 11:10:58 +00:00
}
this . Display ( 0 , Map { "count" : count , "pageSize" : pageSize , "data" : companys } )
2022-01-22 08:12:02 +00:00
} ,
2022-03-02 04:14:07 +00:00
2022-01-22 08:12:02 +00:00
"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" )
2022-02-16 20:10:53 +00:00
2022-01-22 08:12:02 +00:00
if analyse != nil {
for k , v := range analyse {
if ADataType [ k ] != nil {
analyse [ ADataType . GetString ( k ) ] = v
}
}
res [ "analyse" ] = analyse
}
2022-02-16 20:10:53 +00:00
analyse1 := res . GetMap ( "analyse1" )
if analyse1 != nil {
for k , v := range analyse1 {
if ADataType [ k ] != nil {
analyse1 [ ADataType . GetString ( k ) ] = v
}
}
res [ "analyse1" ] = analyse1
}
2022-01-22 08:12:02 +00:00
res [ "upload_data" ] = res . GetMap ( "upload_data" )
res [ "collect_data" ] = res . GetMap ( "collect_data" )
2022-01-22 21:13:19 +00:00
if res . GetMap ( "collect_data" ) == nil {
2022-03-06 15:55:14 +00:00
go func ( res Map ) {
path := "company/" + Md5 ( res . GetString ( "name" ) ) + time . Now ( ) . Format ( "/200601021504.json" )
2022-01-22 21:13:19 +00:00
2022-03-06 15:55:14 +00:00
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 )
2022-02-14 11:10:58 +00:00
2022-01-22 21:13:19 +00:00
}
2022-01-22 08:12:02 +00:00
this . Display ( 0 , res )
} ,
2022-02-16 20:10:53 +00:00
"company_upload" : func ( this * Context ) {
id := ObjToInt ( this . Req . FormValue ( "id" ) )
if id == 0 {
this . Display ( 3 , "参数错误" )
return
}
2022-02-23 22:26:36 +00:00
res := this . Db . Get ( "company" , "upload_data,org_id" , Map { "id" : id } )
2022-02-16 20:10:53 +00:00
if res == nil {
this . Display ( 4 , "找不到该数据" )
return
}
uploadData := res . GetMap ( "upload_data" )
2022-02-23 22:26:36 +00:00
tags := this . Db . Select ( "tag" , "name,sn,`unit`,description" , Map { "AND" : Map { "type" : 0 , "org_id" : res . GetCeilInt ( "org_id" ) } } )
2022-02-16 20:10:53 +00:00
for _ , v := range tags {
v [ "value" ] = uploadData [ v . GetString ( "sn" ) ]
}
this . Display ( 0 , tags )
} ,
2022-01-22 08:12:02 +00:00
}