Commit 01b1e8b7 by 黄静

hj

parent 51edf273
#-*- encoding:utf-8 -*-
#!/usr/bin/python
import pymysql
ip = "43.247.184.94"
port = 9187
# ip = "172.16.18.20"
# port = 3306
database = "ent_data"
user = "nice"
password = "Niceee@2020#@"
def Getdata(cate_name):
sql = 'select * from tj_policycycle where cate_name = "%s" order by life_cycle' % cate_name
#数据库连接
db = pymysql.Connect(ip, user, password, database, port)
cursor = db.cursor(cursor=pymysql.cursors.DictCursor)
try:
cursor.execute(sql)
re1 = cursor.fetchall()
if re1:
list = []
for ree in re1:
if ree:
policy_name = ree["policy_name"]
life_cycle = ree["life_cycle"]
dict = {}
dict[policy_name] = life_cycle
list.append(dict)
return 1,list
else:
db.close()
return 0, {}
except:
db.close()
return -1, {}
def InsertData(datainfo):
# 数据库连接
db = pymysql.Connect(ip, user, password, database, port)
cursor = db.cursor(cursor=pymysql.cursors.DictCursor)
try:
update_sql = 'update tj_policycycle set life_cycle = %s where id = %s'
insert_sql = 'INSERT INTO `ent_data`.`tj_policycycle` (`cate_name`, `policy_name`, `life_cycle`) VALUES (%s, %s, %s)'
for data in datainfo:
cate_name = data["cate_name"]
policy_name = data["policy_name"]
life_cycle = data["life_cycle"]
select_sql = 'select * from tj_policycycle where cate_name = "%s" and policy_name = "%s"' % (cate_name, policy_name)
cursor.execute(select_sql)
re1 = cursor.fetchone()
if re1:
id = re1["id"]
tub = (life_cycle, id)
cursor.execute(update_sql,tub)
else:
tub = (cate_name, policy_name, life_cycle)
cursor.execute(insert_sql, tub)
db.commit()
db.close()
return 1
except FileExistsError as e:
db.rollback()
db.close()
return 0
# 下面一句的作用1是:运行本程序文件时执行什么操作
if __name__ == "__main__":
# #插入数据库
# datainfo = [
# {"cate_name":"文化、体育和娱乐业","policy_name":"IDC许可证","life_cycle":5},
# {"cate_name": "文化、体育和娱乐业", "policy_name": "EDI许可证", "life_cycle": 3},
# {"cate_name": "信息传输、软件和信息技术服务业", "policy_name": "IDC许可证", "life_cycle": 8},
# ]
#
#
# result = InsertData(datainfo)
# print(str(result))
#查询数据
cate_name = "文化、体育和娱乐业"
re1,re2 = Getdata(cate_name)
print(str(re1))
print(str(re2))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/3/19 10:54
# @Author : fanhui
# @File : GetImageFromSql.py
# @Software: PyCharm
"""企业画像和推荐商机"""
#读取数据库,获取画像标签
import pymysql
from DBUtils.PooledDB import PooledDB
from flask import request,jsonify
# 数据库
MYSQL_HOST = '43.247.184.94' #外网地址
PORT = 9187 #外网端口
USER = 'nice'
PASSWORD = 'Niceee@2020#@'
DB = 'ent_data'
pool = PooledDB(pymysql,8, host=MYSQL_HOST, user=USER, passwd=PASSWORD, db=DB, port=PORT)
#检索企业画像信息
def GetImageFromSql(companyname):
print(companyname,"===========获取公司名称查询画像信息")
# 查询数据库
conn = pool.connection()
cursor = conn.cursor()
image_result = [] #画像列表
try:
# 执行SQL语句
cursor.execute('SELECT * from tj_lable_copy1_test_0316 where company_name=%s',companyname)
# 获取所有配置列表
Allproduct_rules = cursor.fetchall()
print(Allproduct_rules)
for row in Allproduct_rules:
# 获取所有规则
image_result=row[1]
print(image_result)
except:
return ("没有查询到该公司画像信息")
finally:
cursor.close()
conn.close()
if image_result:
image_result = image_result.replace("[","").replace("]","").replace('"',"").replace("'","").replace(",",",")
imageresult=list(image_result.split(","))
print(type(imageresult),"%%%%%%%")
else:imageresult=image_result
return imageresult
#检索产品信息
def GetProductFromSql(companyname):
print(companyname,"===========获取公司名称查询产品推荐信息")
# 查询数据库
conn = pool.connection()
cursor = conn.cursor()
product_result = [] #产品列表
try:
# 执行SQL语句
cursor.execute('SELECT * from tj_product_result_copy1_test_0317 where companyname=%s',companyname)
# 获取所有配置列表
Allproduct_rules = cursor.fetchall()
print(Allproduct_rules)
for row in Allproduct_rules:
# 获取所有规则
product_result=row[1]
# print(type(product_result),product_result)
except:
return ("没有查询到该公司产品推荐信息")
finally:
cursor.close()
conn.close()
if product_result:
product_result = product_result.replace("[","").replace("]","").replace('"',"").replace("'","").replace(",",",").replace(" ","")
print(product_result)
productresult=list(product_result.split(","))
print(type(productresult),"%%%%%%%")
else:productresult=product_result
return productresult
def strQ2B(companyname):
"""公司名称全角转半角"""
name = ""
for uchar in companyname:
inside_code=ord(uchar)
if inside_code == 12288: #全角空格直接转换
inside_code = 32
elif (inside_code >= 65281 and inside_code <= 65374): #全角字符(除空格)根据关系转化
inside_code -= 65248
name += chr(inside_code)
return name
def getImageInfo(server):
@server.route('/gsb/api/GetHtmlInfoFromSql', methods=['POST'])
def GetImageInfo():
print("接口调用--------查询画像标签和产品推荐信息")
if request.method == 'POST':
requestdata = request.json
print(requestdata)
companyname = requestdata.get('companyname')
companyname = strQ2B(companyname)
Image_result=GetImageFromSql(companyname)
product_result=GetProductFromSql(companyname)
result={"image": Image_result,
"product":product_result}
return jsonify(result)
# server.run(host='127.0.0.1', port=9001, debug=True)
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/3/27 9:10
# @Author : huangjing
# @File : Image_status.py
# @Software: PyCharm
import pymysql
from DBUtils.PooledDB import PooledDB
from flask import request,jsonify
"""任务表"""
# # 数据库规则表
MYSQL_HOST = '43.247.184.94' #外网地址
PORT = 9187 #外网端口
USER = 'nice'
PASSWORD = 'Niceee@2020#@'
DB = 'ent_data'
pool = PooledDB(pymysql,8, host=MYSQL_HOST, user=USER, passwd=PASSWORD, db=DB, port=PORT)
#根据传入公司名称获取专利报告链接及状态
def GetReportInfoFromSql(companyName):
# 检索企业画像信息
print(companyName, "===========获取公司名称查询专利信息")
# 查询数据库
conn = pool.connection()
cursor = conn.cursor()
report_dict={"report_status":"生成中","report_url":""}
try:
# 执行SQL语句
cursor.execute('SELECT * from tj_reportUrl where companyname=%s', companyName)
# 获取所有配置列表
Allreport_rules = cursor.fetchall()
for row in Allreport_rules:
# 获取所有数据
url_result = row[2]
if url_result:
report_dict["report_status"]="已生成"
report_dict["report_url"]=url_result
print(report_dict)
finally:
cursor.close()
conn.close()
return report_dict
#根据传入公司名称获取画像状态
def GetImageInfoFromSql(companyName):
# 检索企业画像信息
print(companyName, "===========获取公司名称查询画像信息")
# 查询数据库
conn = pool.connection()
cursor = conn.cursor()
status="画像生成中"
try:
# 执行SQL语句
cursor.execute('SELECT * from tj_lable_copy1_test_0316 where company_name=%s', companyName)
# 获取所有配置列表
Allproduct_rules = cursor.fetchall()
print(Allproduct_rules)
for row in Allproduct_rules:
# 获取所有数据
image_result = row[1]
if image_result:
status="已生成"
print(status)
except:
# return ("没有查询到该公司画像信息")
return status
finally:
cursor.close()
conn.close()
return status
#将获取的信息写入数据库
def WritePRtoSql(companyName, currdate,hx_status,report_dict):#把推荐结果写进数据库
print(report_dict,"将公司信息写入数据库")
report_status = report_dict["report_status"]
report_url = report_dict["report_url"]
# json写入数据库
conn = pool.connection()
cursor = conn.cursor()
sql='insert into tj_task(companyName,submit_time,image_status,report_status,report_url) values("%s","%s","%s","%s","%s")'%(companyName,currdate,hx_status,report_status,report_url)
try:
print(sql,"======sql")
cursor.execute(sql)
# 提交到数据库执行
conn.commit()
except Exception as e:
print(e)
conn.rollback()
# 关闭数据库连接
conn.close()
return "查询信息已写入数据库"
#根据传入公司名称查询画像状态表,返回任务信息
def GetImageStatusFromSql(companyName,pageSize,pageNum):
# 检索企业画像状态表
print(companyName, "===========获取公司名称查询画像状态信息")
# 查询数据库
conn = pool.connection()
cursor = conn.cursor()
search_list=[]
num_start=(pageNum-1)*pageSize
print(num_start,"================num_start")
sql='SELECT * from tj_task where companyName=\"%s\" order by submit_time DESC,id DESC limit %s,%s'%(companyName,num_start,pageSize)
try:
print("=================================")
# 执行SQL语句
cursor.execute(sql)
print(sql,"===================sql查询状态")
# 获取所有配置列表
Allsearch_result = cursor.fetchall()
print(Allsearch_result)
r=0
for row in Allsearch_result:
# 获取所有数据
image_status = row[3]
report_status = row[4]
if image_status=="已生成" and report_status =="已生成":
status="已生成"
else:
status = "生成中"
r+=1
search_dict={
"companyName":row[1],
"submit_time":row[2],
"status":status,
"patent_link":row[5]}
search_list.append(search_dict)
finally:
cursor.close()
conn.close()
return search_list
def work_total(companyName):
# 检索企业画像状态表
print(companyName, "===========获取公司名称查询总数量")
# 查询数据库
total=""
conn = pool.connection()
cursor = conn.cursor()
# 执行SQL语句
cursor.execute('SELECT COUNT(*) from tj_task WHERE companyName=%s', companyName)
# print(sql,"===================sql查询")
# 获取所有配置列表
Allsearch_result = cursor.fetchall()
for row in Allsearch_result:
total=row[0]
print(row[0],"=======")
cursor.close()
conn.close()
return total
def strQ2B(companyname):
"""公司名称全角转半角"""
name = ""
for uchar in companyname:
inside_code=ord(uchar)
if inside_code == 12288: #全角空格直接转换
inside_code = 32
elif (inside_code >= 65281 and inside_code <= 65374): #全角字符(除空格)根据关系转化
inside_code -= 65248
name += chr(inside_code)
return name
def imageInfo(server):
@server.route('/gsb/api/ImageStatusSearch', methods=['POST'])
def ImageStatusSearch():
print("接口调用--------查询画像状态")
if request.method == 'POST':
requestdata = request.json
print(requestdata)
# 当前页数
pageNum = requestdata.get('pageNum')
#是否插入表
insert_status=requestdata.get('insert_status')
print(insert_status, type(insert_status), "==========================insert")
# 每页展示的条数
pageSize = requestdata.get('pageSize')
# 公司名称
companyName = requestdata.get('companyName')
# 提交日期
currdate=requestdata.get('currdate')
#根据公司名称查询画像标签库、画像状态
hx_status = GetImageInfoFromSql(companyName)
report_dict = GetReportInfoFromSql(companyName)
result={}
if insert_status==1:
WritePRtoSql(companyName, currdate,hx_status,report_dict)
result["result_data"]=GetImageStatusFromSql(companyName,pageSize,pageNum)
result["total"]=work_total(companyName)
else:
result["result_data"] = GetImageStatusFromSql(companyName,pageSize,pageNum)
result["total"] = work_total(companyName)
return jsonify(result)
# server.run(host='127.0.0.1', port=8100, debug=True)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/3/14 16:37
# @Author : fanhui
# @File : GetLicenseDataForImage.py
# @Software: PyCharm
from elasticsearch import Elasticsearch
from flask import request,jsonify
"""证照信息"""
esip = "43.247.184.94" #外网地址
# esip1 = "172.16.18.110" #内网地址
esport = 9200
esuser = "admines"
espassword = "adminGSBes"
es = Elasticsearch([esip], http_auth=(esuser, espassword), port=esport, timeout=15000) #工商
#检索高新技术企业ES
def GetGXLicensesFromES(companyname):
print("证照es")
license_result_list=[]
licensesinfo1 = es.search(index="enterprise_chain_gxgy",
body={"query": {"bool": {"must": {"term": {"companyName.raw": companyname}}}}})
if licensesinfo1["hits"]["hits"]:
for row in licensesinfo1["hits"]["hits"]:
if row['_source']["techType"]:
license_name="高新技术企业" # 证照名称
else:
license_name = "—" # 证照名称
if row['_source']["certificateNo"]:
certificateNo=row['_source']["certificateNo"]#证照编号
else:
certificateNo = "—" #证照编号
if row['_source']["year"]:
begin_date = row['_source']["year"] # 开始时间
else:
begin_date = "—" #开始时间
license_result = {
"license_name": license_name,
"certificateNo": certificateNo,
"begin_date": begin_date,
"end_date": "—"
}
license_result_list.append(license_result)
return license_result_list
#检索游戏类证照ES
def GetgameLicensesFromES(companyname):
print("游戏类证照es")
license_result_list1=[]
licensesinfo1 = es.search(index="enterprise_chain_game",
body={"query": {"bool": {"must": {"term": {"publishing_unit.raw": companyname}}}}})
if licensesinfo1["hits"]["hits"]:
for row in licensesinfo1["hits"]["hits"]:
if row['_source']["publishing_record"]:
license_name="网络游戏运营备案" # 证照名称
else:
license_name = "—" # 证照名称
if row['_source']["symbol"]:
certificateNo=row['_source']["symbol"]#证照编号
else:
certificateNo = "—" #证照编号
if row['_source']["publish_time"]:
begin_date = row['_source']["publish_time"] # 开始时间
else:
begin_date = "—" #开始时间
license_result = {
"license_name": license_name,
"certificateNo": certificateNo,
"begin_date": begin_date,
"end_date": "—"
}
license_result_list1.append(license_result)
license_result_list2 = []
licensesinfo1 = es.search(index="enterprise_chain_game",
body={"query": {"bool": {"must": {"term": {"operation_unit.raw": companyname}}}}})
if licensesinfo1["hits"]["hits"]:
for row in licensesinfo1["hits"]["hits"]:
if row['_source']["publishing_record"]:
license_name = "网络游戏出版备案" # 证照名称
else:
license_name = "—" # 证照名称
if row['_source']["symbol"]:
certificateNo = row['_source']["symbol"] # 证照编号
else:
certificateNo = "—" # 证照编号
if row['_source']["publish_time"]:
begin_date = row['_source']["publish_time"] # 开始时间
else:
begin_date = "—" # 开始时间
license_result = {
"license_name": license_name,
"certificateNo": certificateNo,
"begin_date": begin_date,
"end_date": "—"
}
license_result_list2.append(license_result)
license_result_list=license_result_list1+license_result_list2
return license_result_list
#检索高新技术企业ES
def GetICPLicensesFromES(companyname):
print("ICP证照es")
license_result_list=[]
licensesinfo1 = es.search(index="enterprise_chain_license",
body={"query": {"bool": {"must": {"term": {"companyName.raw": companyname}}}}})
if licensesinfo1["hits"]["hits"]:
for row in licensesinfo1["hits"]["hits"]:
if row['_source']["licence"]:
license_name=row['_source']["licence"] # 证照名称
else:
license_name = "—" # 证照名称
if row['_source']["licence_no"]:
certificateNo=row['_source']["licence_no"]#证照编号
else:
certificateNo = "—" #证照编号
if row['_source']["start_date"]:
begin_date = row['_source']["start_date"] # 开始时间
else:
begin_date = "—" #开始时间
if row['_source']["end_date"]:
end_date = row['_source']["end_date"] # 截止时间
else:
end_date = "—" #截止时间
license_result = {
"license_name": license_name,
"certificateNo": certificateNo,
"begin_date": begin_date,
"end_date": end_date
}
license_result_list.append(license_result)
return license_result_list
def strQ2B(companyname):
"""公司名称全角转半角"""
name = ""
for uchar in companyname:
inside_code=ord(uchar)
if inside_code == 12288: #全角空格直接转换
inside_code = 32
elif (inside_code >= 65281 and inside_code <= 65374): #全角字符(除空格)根据关系转化
inside_code -= 65248
name += chr(inside_code)
return name
def getlicenceInfo(server):
@server.route('/gsb/api/GetLicenseFromEs', methods=['POST'])
def GetLicenseInfo():
print("接口调用--------查询企业证照信息")
if request.method == 'POST':
requestdata = request.json
print(requestdata)
companyname = requestdata.get('companyname')
companyname = strQ2B(companyname)
license_result_list=[]
if companyname == "北京格尔法网络科技有限公司":
license_result = {
"license_name": "高新技术企业",
"certificateNo": "GR201711004770",
"begin_date": "2017-12-06",
"end_date": "2020-12-06"
}
license_result_list.append(license_result)
# result = {companyname: license_result_list}
return jsonify(license_result_list)
else:
LicenseInfo1= GetGXLicensesFromES(companyname)
LicenseInfo2 = GetgameLicensesFromES(companyname)
LicenseInfo3 = GetICPLicensesFromES(companyname)
license_result=LicenseInfo1+LicenseInfo2+LicenseInfo3
# result={companyname: license_result}
return jsonify(license_result)
# server.run(host='172.21.0.2', port=9000, debug=True)
# server.run(host='127.0.0.1', port=9000, debug=True)
\ No newline at end of file
DBUtils、pymysql、elasticsearch、flask、flask_cors
DBUtils、pymysql、elasticsearch、flask、flask_cors
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import request
from elasticsearch import Elasticsearch
import json
import Dataoper
# es连接信息
esip = "43.247.184.94"
esport = 9200
# esip = "172.16.18.110"
# esport = 9203
esuser = "admines"
espassword = "adminGSBes"
es = Elasticsearch([esip], http_auth=(esuser, espassword), port=esport,timeout=1000)
def selectcyle(server):
@server.route("/api/selectcycle",methods = ['POST'])
def getCompanyTrade():
try:
companyNames=request.get_json().get("company_name")
querybody={
"query": {
"bool": {
"must": [
{
"term": {
"company_name.raw": companyNames
}
}
]
}
}
}
searched = es.search(index='bigdata_ic_gsb_company_02', doc_type='_doc', body=querybody)
if searched["hits"]["total"]:
company_cate_1 = searched["hits"]["hits"][0]['_source']["gsb_company_cate_1"] # 行业第一大类
company_cate_2 = searched["hits"]["hits"][0]['_source']["gsb_company_cate_2"] # 行业第二大类
company_cate_3 = searched["hits"]["hits"][0]['_source']["gsb_company_cate_3"] # 行业第三大类
re1,re2 = Dataoper.Getdata(company_cate_1)
if re1:
return json.dumps({"status": 0, "msg":"操作成功","data": re2}, ensure_ascii=False)
else:
return json.dumps({"status": -1, "msg":"没有对应的证照信息","data": []}, ensure_ascii=False)
else:
return json.dumps({"status": -1, "msg":"没有对应工商信息","data": []}, ensure_ascii=False)
except:
return json.dumps({"status": -1, "msg":"调用服务出错","data": []}, ensure_ascii=False)
def insertcycle(server):
@server.route("/api/insertcycle",methods = ['POST'])
def putCompanyTrade():
try:
data=request.get_json().get("data")
print(data)
re1=Dataoper.InsertData(data)
if re1 :
return json.dumps({"status": 0, "msg":"成功","data": re1}, ensure_ascii=False)
else:
return json.dumps({"status": -1, "msg":"失败","data": 0}, ensure_ascii=False)
except:
return json.dumps({"status": -1, "msg":"调用服务出错","data": {}}, ensure_ascii=False)
# if __name__ == '__main__':
# #app.run(host='127.0.0.1', port=5000, debug=True)
# CORS(app, supports_credentials=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment