调优
This commit is contained in:
+76
-19
@@ -4,6 +4,7 @@ import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paixuArr []Map
|
||||
@@ -12,7 +13,8 @@ func (x paixuArr) Len() int {
|
||||
return len(x)
|
||||
}
|
||||
func (x paixuArr) Less(i, j int) bool {
|
||||
return x[i].GetCeilInt64("count") < x[j].GetCeilInt64("count")
|
||||
|
||||
return x[i].GetCeilInt64("count") > x[j].GetCeilInt64("count")
|
||||
}
|
||||
func (x paixuArr) Swap(i, j int) {
|
||||
x[i], x[j] = x[j], x[i]
|
||||
@@ -67,7 +69,7 @@ var DeclareCtr = Ctr{
|
||||
//政策匹配
|
||||
"match": func(that *Context) {
|
||||
|
||||
if that.Session("user_id").Data != nil {
|
||||
if that.Session("user_id").Data == nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
@@ -83,6 +85,18 @@ var DeclareCtr = Ctr{
|
||||
that.Display(3, "参数错误")
|
||||
return
|
||||
}
|
||||
qu := that.Req.FormValue("register_address")
|
||||
qus := strings.Split(qu, "/")
|
||||
|
||||
for _, v := range qus {
|
||||
if v != "" {
|
||||
qu = v
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.Contains(qu, "区") && !strings.Contains(qu, "县") {
|
||||
qu = "没有此项数据随意填充的"
|
||||
}
|
||||
|
||||
company := that.Db.Get("company", "*", Map{"user_id": that.Session("user_id").Data})
|
||||
delete(company, "id")
|
||||
@@ -125,7 +139,7 @@ var DeclareCtr = Ctr{
|
||||
//标签分析
|
||||
if tags != nil {
|
||||
for _, v := range tags {
|
||||
dtag := that.Db.Select("declare_tag", "id,declare_id", Map{"tag_id": v})
|
||||
dtag := that.Db.Select("declare_tag", Map{"[><]`declare`": "declare_tag.declare_id=declare.id"}, "declare_tag.declare_id", Map{"AND": Map{"OR": Map{"declare.policy_level": Slice{"省", "市"}, "declare.dispatch_department[~]": qu}, "declare_tag.tag_id": v}})
|
||||
for _, v1 := range dtag {
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
declares[v1.GetCeilInt64("declare_id")] = v1
|
||||
@@ -137,7 +151,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
|
||||
//企业规模分析
|
||||
dtag := that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "company_scale[<=]": ObjToInt(that.Req.FormValue("company_scale"))}})
|
||||
dtag := that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "company_scale[<=]": ObjToInt(that.Req.FormValue("company_scale"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -150,7 +164,7 @@ var DeclareCtr = Ctr{
|
||||
//是否是有效期内的科技型中小企业称号:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("smes_flag")) > 0 {
|
||||
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "smes_flag": ObjToInt(that.Req.FormValue("smes_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "smes_flag": ObjToInt(that.Req.FormValue("smes_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -164,7 +178,7 @@ var DeclareCtr = Ctr{
|
||||
//是否是有效期内的高新区技术企业称号:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("htzte_flag")) > 0 {
|
||||
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "htzte_flag": ObjToInt(that.Req.FormValue("htzte_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "htzte_flag": ObjToInt(that.Req.FormValue("htzte_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -179,11 +193,14 @@ var DeclareCtr = Ctr{
|
||||
flagslice := Slice{}
|
||||
if flags != nil {
|
||||
for _, v := range flags {
|
||||
if v == "0" {
|
||||
continue
|
||||
}
|
||||
flagslice = append(flagslice, v)
|
||||
}
|
||||
|
||||
}
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "engineering_center_flag": flagslice}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_center_flag": flagslice}})
|
||||
|
||||
for _, v1 := range dtag {
|
||||
|
||||
@@ -199,11 +216,14 @@ var DeclareCtr = Ctr{
|
||||
flagslice = Slice{}
|
||||
if flags != nil {
|
||||
for _, v := range flags {
|
||||
if v == "0" {
|
||||
continue
|
||||
}
|
||||
flagslice = append(flagslice, v)
|
||||
}
|
||||
|
||||
}
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "engineering_laboratory_flag": flagslice}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_laboratory_flag": flagslice}})
|
||||
|
||||
for _, v1 := range dtag {
|
||||
|
||||
@@ -219,11 +239,14 @@ var DeclareCtr = Ctr{
|
||||
flagslice = Slice{}
|
||||
if flags != nil {
|
||||
for _, v := range flags {
|
||||
if v == "0" {
|
||||
continue
|
||||
}
|
||||
flagslice = append(flagslice, v)
|
||||
}
|
||||
|
||||
}
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "key_laboratory_flag": flagslice}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "key_laboratory_flag": flagslice}})
|
||||
for _, v1 := range dtag {
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
declares[v1.GetCeilInt64("declare_id")] = v1
|
||||
@@ -237,11 +260,14 @@ var DeclareCtr = Ctr{
|
||||
flagslice = Slice{}
|
||||
if flags != nil {
|
||||
for _, v := range flags {
|
||||
if v == "0" {
|
||||
continue
|
||||
}
|
||||
flagslice = append(flagslice, v)
|
||||
}
|
||||
|
||||
}
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "industrial_design_center_flag": flagslice}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "industrial_design_center_flag": flagslice}})
|
||||
for _, v1 := range dtag {
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
declares[v1.GetCeilInt64("declare_id")] = v1
|
||||
@@ -265,7 +291,7 @@ var DeclareCtr = Ctr{
|
||||
|
||||
//有无授权发明专利:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("invention_patent_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "invention_patent_flag": ObjToInt(that.Req.FormValue("invention_patent_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "invention_patent_flag": ObjToInt(that.Req.FormValue("invention_patent_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -278,7 +304,7 @@ var DeclareCtr = Ctr{
|
||||
|
||||
//有无国际科技合作:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("international_cooperation_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "international_cooperation_flag": ObjToInt(that.Req.FormValue("international_cooperation_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "international_cooperation_flag": ObjToInt(that.Req.FormValue("international_cooperation_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -290,7 +316,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
//上年度有无固定资产投入:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("investment_fixed_assets_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "investment_fixed_assets_flag": ObjToInt(that.Req.FormValue("investment_fixed_assets_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "investment_fixed_assets_flag": ObjToInt(that.Req.FormValue("investment_fixed_assets_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -301,7 +327,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
}
|
||||
//高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "high_level_talents_flag": ObjToInt(that.Req.FormValue("high_level_talents_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag": ObjToInt(that.Req.FormValue("high_level_talents_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -312,7 +338,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
//企业股东或成员是否有国内外高校或科研院在编、全职人员:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("shareholders_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "shareholders_flag": ObjToInt(that.Req.FormValue("shareholders_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "shareholders_flag": ObjToInt(that.Req.FormValue("shareholders_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -324,7 +350,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
//企业有无从外地引进博士学历人才:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("nonlocal_dr_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "nonlocal_dr_flag": ObjToInt(that.Req.FormValue("nonlocal_dr_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "nonlocal_dr_flag": ObjToInt(that.Req.FormValue("nonlocal_dr_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -336,7 +362,7 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
//上年度是否有贷款/融资或未来有贷款/融资计划:0-否,1-是
|
||||
if ObjToInt(that.Req.FormValue("loan_flag")) > 0 {
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "loan_flag": ObjToInt(that.Req.FormValue("loan_flag"))}})
|
||||
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "loan_flag": ObjToInt(that.Req.FormValue("loan_flag"))}})
|
||||
for _, v1 := range dtag {
|
||||
|
||||
if declares[v1.GetCeilInt64("declare_id")] == nil {
|
||||
@@ -353,15 +379,46 @@ var DeclareCtr = Ctr{
|
||||
}
|
||||
//获取到排序后的数据
|
||||
sort.Sort(px)
|
||||
res := Slice{}
|
||||
var res []Map
|
||||
for _, v := range px {
|
||||
id := v.GetCeilInt("declare_id")
|
||||
article := that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
|
||||
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id", Map{"declare_id": id})
|
||||
article["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,tag,status", Map{"id": id})
|
||||
article["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": id})
|
||||
|
||||
res = append(res, article)
|
||||
}
|
||||
minMoney := float64(0)
|
||||
maxMoney := float64(0)
|
||||
for _, v := range res {
|
||||
if v.GetMap("declare") != nil {
|
||||
if v.GetMap("declare").GetFloat64("money_scope_min") < minMoney {
|
||||
minMoney = v.GetMap("declare").GetFloat64("money_scope_min")
|
||||
}
|
||||
if v.GetMap("declare").GetFloat64("money_scope_max") > maxMoney {
|
||||
maxMoney = v.GetMap("declare").GetFloat64("money_scope_max")
|
||||
}
|
||||
}
|
||||
}
|
||||
seData := Map{
|
||||
"user_id": that.Session("user_id").Data,
|
||||
"search_company_name": companyName,
|
||||
"policy_match_count": len(res),
|
||||
"json_data": ObjToStr(company),
|
||||
"create_time[#]": "now()",
|
||||
"modify_time[#]": "now()",
|
||||
"del_flag": 0,
|
||||
}
|
||||
if maxMoney != minMoney {
|
||||
seData["money_scope"] = ObjToStr(minMoney) + "-" + ObjToStr(maxMoney) + "万元"
|
||||
} else if maxMoney == 0 {
|
||||
seData["money_scope"] = ""
|
||||
} else {
|
||||
seData["money_scope"] = ObjToStr(maxMoney) + "万元"
|
||||
}
|
||||
|
||||
//匹配记录存储
|
||||
that.Db.Insert("search_record", seData)
|
||||
|
||||
that.Display(0, res)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user