update 企业数据相关接口

This commit is contained in:
P3ngSaM 2022-08-31 14:58:06 +08:00
parent 3a5d210827
commit 4159813baf
12 changed files with 568 additions and 3 deletions

View File

@ -0,0 +1,196 @@
from Company.Basic.Branch.BranchObj import BranchList
from Company.Basic.Business.BusinessImpl import BusinessImpl
from Company.Basic.Shareholder.ShareholderObj import ShareholderList
from DBHelper.MongoHelperInstance import DB_TYC, DB_TEST
from Utils.CommonUtil import CommonUtils
class BranchImpl(object):
"""分支机构"""
@staticmethod
def auto_update(**kwargs):
"""新增/更新(自动)"""
condition = kwargs['condition']
def save_data(**args):
"""查询保存数据"""
def search_cid(name):
"""根据股东名称查询cid"""
cid_record = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业名称': name},
'企业名称'
)
if cid_record:
return cid_record
else:
return None
company_name = args['cname']
company_id = args['cid']
records = DB_TYC.find_single_column(
'公司背景',
'分支机构',
{'企业名称': company_name},
'分支机构'
)
if records:
records = records['result']
data = dict()
list_data = list()
for record in records:
dict_data = dict()
dict_data['企业ID'] = search_cid(record['name'])
dict_data['企业名称'] = record['name']
dict_data['负责人'] = record['legalPersonName']
dict_data['成立日期'] = CommonUtils.time_stamp(record['estiblishTime'])
dict_data['企业状态'] = record['regStatus']
dict_data['所属省份'] = CommonUtils.province_conversion(record['base'])
dict_data['所属地市'] = None
list_data.append(dict_data)
data['企业ID'] = company_id
data['分支列表'] = list_data
data['更新时间'] = CommonUtils.get_current_time()
return data
else:
return False
if len(condition['cid']):
cid = condition['cid']
cname = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业ID': cid},
'企业名称'
)
update = save_data(cname=cname, cid=cid)
if update:
DB_TEST.update_single_data(
"WR_DataBase_v2_test",
"C3.5_分支机构",
{"企业ID": cid},
update
)
return 'success'
else:
return 'update failed'
elif len(condition['cname']):
cname = condition['cname']
cid = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业名称': cname},
'企业ID'
)
if not cid:
cid = BusinessImpl.auto_update(condition={"cname": cname, "cid": ""})
insert = save_data(cname=cname, cid=cid)
if insert:
DB_TEST.upsert_single_data(
"WR_DataBase_v2_test",
"C3.5_分支机构",
{"企业名称": cname},
insert
)
return 'success'
else:
return 'new failed'
else:
return 'parameter exception'
@staticmethod
def delete(**kwargs):
"""删除"""
param = kwargs['param']
cid = param['cid']
cname = param['company']
res = DB_TEST.delete_single_data_in_array(
"WR_DataBase_v2_test",
"C3.5_分支机构",
{"企业ID": cid},
{"分支列表": {"企业名称": cname}}
)
if res:
result = {
"info": "success",
}
else:
result = {
"info": "no result"
}
return result
@staticmethod
def edit(**kwargs):
"""编辑"""
param = kwargs['param']
cid = param['cid']
body = param['body']
name = param['cname']
try:
branch = BranchList()
branch.cname = body['企业名称']
branch.leader = body['负责人']
branch.establishment_date = body['成立日期']
branch.status = body['企业状态']
branch.province = body['所属省份']
branch.city = body['所属地市']
update_data = branch.fields_toggle()
DB_TEST.update_single_data_in_array(
"WR_DataBase_v2_test",
"C3.5_分支机构",
{"企业ID": cid},
{"分支列表": {"企业名称": name}},
update_data
)
time_update = {"更新时间": CommonUtils.get_current_time()}
DB_TEST.update_single_data(
"WR_DataBase_v2_test",
"C3.5_分支机构",
{"企业ID": cid},
time_update
)
return 'success'
except Exception:
return 'edit failed'
@staticmethod
def view(**kwargs):
"""查看"""
query = kwargs['query']
cid = query['cid']
page_size = int(query['page_size'])
page_num = page_size * (int(query['page_num']) - 1)
total = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.5_分支机构',
{"企业ID": cid},
'分支列表'
)
record = DB_TEST.find_data_with_aggregate(
"WR_DataBase_v2_test",
"C3.5_分支机构",
[
{"$match": {"企业ID": cid}},
{"$project": {'_id': 0, '分支列表': {"$slice": ["${}".format('分支列表'), page_num, page_size]}}}
]
)
if record:
result = {
"info": "success",
"total": len(total),
"result": record[0]['分支列表']
}
else:
result = {
"info": "no result"
}
return result

View File

@ -0,0 +1,36 @@
from Utils.ObjUtil import SpecObject
from Utils.ValidateUtil import ValidateAttr, Validate
class BranchList(SpecObject):
"""分支列表"""
cid = ValidateAttr(field='cid', type=str, default=None)
cname = ValidateAttr(field='cname', type=str)
leader = ValidateAttr(field='leader', type=str)
establishment_date = ValidateAttr(field='establishment_date', fun=Validate.date_format)
status = ValidateAttr(field='status', type=str)
province = ValidateAttr(field='province', type=str)
city = ValidateAttr(field='city', type=str, default=None)
fields_map = {
"cid": "企业ID",
"cname": "企业名称",
"leader": "负责人",
"establishment_date": "成立日期",
"status": "企业状态",
"province": "所属省份",
"city": "所属地市"
}
class ShareholderObj(SpecObject):
"""股东信息"""
cid = ValidateAttr(field='cid', type=str, length=8)
branch_list = ValidateAttr(field='branch_list', instance_list=BranchList)
update_time = ValidateAttr(field='update_time', func=Validate.time_format)
fields_map = {
"cid": "企业ID",
"branch_list": "分支列表",
"update_time": "更新时间"
}

View File

@ -0,0 +1,55 @@
from flask import Blueprint, request
from Company.Basic.Branch.BranchImpl import BranchImpl
from Utils.ErrorUtil import APIReturnError
from Utils.RouteUtil import RouteParamsCheck
branch_route = Blueprint('branch', __name__)
@branch_route.route('/auto_update', methods=['GET'])
def auto_update_route():
"""新增/更新(自动)"""
try:
RouteParamsCheck(req=request.args, params=["cname", "cid"]).required()
impl = BranchImpl()
result = impl.auto_update(condition=request.args)
return {"info": result}
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@branch_route.route('/delete', methods=['GET'])
def delete_route():
"""删除"""
try:
RouteParamsCheck(req=request.args, params=["cid", "company"]).required()
impl = BranchImpl()
result = impl.delete(param=request.args)
return result
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@branch_route.route('/edit', methods=['POST'])
def edit_route():
"""编辑"""
try:
RouteParamsCheck(req=request.json, params=["cid", "cname", "body"]).required()
impl = BranchImpl()
result = impl.edit(param=request.json)
return {"info": result}
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@branch_route.route('/view', methods=['GET'])
def view_route():
"""查看"""
try:
RouteParamsCheck(req=request.args, params=["cid", "page_num", "page_size"]).required()
impl = BranchImpl()
result = impl.view(query=request.args)
return result
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code

View File

View File

@ -0,0 +1,185 @@
from Company.Basic.Branch.BranchObj import BranchList
from Company.Basic.Business.BusinessImpl import BusinessImpl
from Company.Basic.Change.ChangehObj import BusinessChangeObj
from Company.Basic.Shareholder.ShareholderObj import ShareholderList
from Company.CompanyUtils import CompanyUtils
from DBHelper.MongoHelperInstance import DB_TYC, DB_TEST
from Utils.CommonUtil import CommonUtils
class ChangeImpl(object):
"""工商变更"""
@staticmethod
def auto_update(**kwargs):
"""新增/更新(自动)"""
condition = kwargs['condition']
def save_data(**args):
"""查询保存数据"""
def search_cid(name):
"""根据股东名称查询cid"""
cid_record = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业名称': name},
'企业名称'
)
if cid_record:
return cid_record
else:
return None
company_name = args['cname']
company_id = args['cid']
records = DB_TYC.find_single_column(
'公司背景',
'变更记录',
{'企业名称': company_name},
'变更记录'
)
if records:
records = records['result']
list_data = list()
for record in records:
dict_data = dict()
dict_data['企业ID'] = company_id
dict_data['变更ID'] = CompanyUtils.make_new_change_id()
dict_data['变更时间'] = record['changeTime']
dict_data['变更项目'] = record['changeItem']
dict_data['变更前'] = record['contentBefore']
dict_data['变更后'] = record['contentAfter']
dict_data['更新时间'] = CommonUtils.get_current_time()
list_data.append(dict_data)
return list_data
else:
return False
if len(condition['cid']):
cid = condition['cid']
cname = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业ID': cid},
'企业名称'
)
update = save_data(cname=cname, cid=cid)
if update:
for item in update:
DB_TEST.update_single_data(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"变更ID": item['变更ID']},
item
)
return 'success'
else:
return 'update failed'
elif len(condition['cname']):
cname = condition['cname']
cid = DB_TEST.find_single_column(
'WR_DataBase_v2_test',
'C3.1_工商信息',
{'企业名称': cname},
'企业ID'
)
if not cid:
cid = BusinessImpl.auto_update(condition={"cname": cname, "cid": ""})
insert = save_data(cname=cname, cid=cid)
if insert:
for item in insert:
DB_TEST.upsert_single_data(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"变更ID": item['变更ID']},
item
)
return 'success'
else:
return 'new failed'
else:
return 'parameter exception'
@staticmethod
def delete(**kwargs):
"""删除"""
param = kwargs['param']
change_id = param['change_id']
res = DB_TEST.delete_single_data(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"变更ID": change_id}
)
if res:
result = {
"info": "success",
}
else:
result = {
"info": "no result"
}
return result
@staticmethod
def edit(**kwargs):
"""编辑"""
param = kwargs['param']
change_id = param['change_id']
body = param['body']
try:
change = BusinessChangeObj()
change.change_time = body['变更时间']
change.change_project = body['变更项目']
change.before = body['变更前']
change.after = body['变更后']
change.update_time = CommonUtils.get_current_time()
update_data = change.fields_toggle()
DB_TEST.update_single_data(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"变更ID": change_id},
update_data
)
return 'success'
except Exception:
return 'edit failed'
@staticmethod
def view(**kwargs):
"""查看"""
query = kwargs['query']
cid = query['cid']
page_num = int(query['page_num'])
page_size = int(query['page_size'])
page_size = 10 if page_size > 10 else page_size
total = DB_TEST.find_all_data_with_count(
'WR_DataBase_v2_test',
'C3.6_工商变更',
{"企业ID": cid}
)
record = DB_TEST.find_data_by_page_with_sort(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"企业ID": cid},
[],
{'_id': 1},
page_size,
page_num
)
if record:
result = {
"info": "success",
"total": total,
"result": record
}
else:
result = {
"info": "no result"
}
return result

View File

@ -0,0 +1,55 @@
from flask import Blueprint, request
from Company.Basic.Change.ChangeImpl import ChangeImpl
from Utils.ErrorUtil import APIReturnError
from Utils.RouteUtil import RouteParamsCheck
change_route = Blueprint('change', __name__)
@change_route.route('/auto_update', methods=['GET'])
def auto_update_route():
"""新增/更新(自动)"""
try:
RouteParamsCheck(req=request.args, params=["cname", "cid"]).required()
impl = ChangeImpl()
result = impl.auto_update(condition=request.args)
return {"info": result}
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@change_route.route('/delete', methods=['GET'])
def delete_route():
"""删除"""
try:
RouteParamsCheck(req=request.args, params=["change_id"]).required()
impl = ChangeImpl()
result = impl.delete(param=request.args)
return result
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@change_route.route('/edit', methods=['POST'])
def edit_route():
"""编辑"""
try:
RouteParamsCheck(req=request.json, params=["change_id", "body"]).required()
impl = ChangeImpl()
result = impl.edit(param=request.json)
return {"info": result}
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code
@change_route.route('/view', methods=['GET'])
def view_route():
"""查看"""
try:
RouteParamsCheck(req=request.args, params=["cid", "page_num", "page_size"]).required()
impl = ChangeImpl()
result = impl.view(query=request.args)
return result
except APIReturnError as e:
return {"info": e.__str__()}, e.status_code

View File

@ -0,0 +1,23 @@
from Utils.ObjUtil import SpecObject
from Utils.ValidateUtil import ValidateAttr, Validate
class BusinessChangeObj(SpecObject):
"""工商变更"""
cid = ValidateAttr(field='cid', type=str, length=8)
change_id = ValidateAttr(field='change_id', type=str, length=8)
change_time = ValidateAttr(field='change_time', func=Validate.date_format)
change_project = ValidateAttr(field='change_project', type=str)
before = ValidateAttr(field='before', type=str)
after = ValidateAttr(field='after', type=str)
update_time = ValidateAttr(field='update_time', type=str)
fields_map = {
"cid": "企业ID",
"change_id": "变更ID",
"change_time": "变更时间",
"change_project": "变更项目",
"before": "变更前",
"after": "变更后",
"update_time": "更新时间"
}

View File

View File

@ -6,7 +6,7 @@ from Utils.CommonUtil import CommonUtils
class InvestmentImpl(object):
"""股东信息"""
"""对外投资"""
@staticmethod
def auto_update(**kwargs):
@ -138,7 +138,6 @@ class InvestmentImpl(object):
name = param['cname']
try:
investment = InvestmentList()
investment.cid = body['企业ID']
investment.cname = body['企业名称']
investment.representative = body['法定代表人']
investment.establishment_date = body['成立日期']

View File

@ -134,7 +134,6 @@ class ShareholderImpl(object):
name = param['shareholder']
try:
shareholder = ShareholderList()
shareholder.sid = body['股东ID']
shareholder.name = body['股东名称']
shareholder.stype = body['股东类型']
shareholder.quality = body['股东性质']

View File

@ -16,3 +16,16 @@ class CompanyUtils(object):
while case:
new_cid = CommonUtils.random_code(8)
return new_cid
@staticmethod
def make_new_change_id():
new_cid = CommonUtils.random_code(8)
case = DB_TEST.find_single_column(
"WR_DataBase_v2_test",
"C3.6_工商变更",
{"变更ID": new_cid},
"变更ID"
) is not None
while case:
new_cid = CommonUtils.random_code(8)
return new_cid

4
app.py
View File

@ -2,7 +2,9 @@ from flask import Flask
from flask_cors import *
from Company.Basic.BasicRoutes import basic_route
from Company.Basic.Branch.BranchRoute import branch_route
from Company.Basic.Business.BusinessRoute import business_route
from Company.Basic.Change.ChangeRoute import change_route
from Company.Basic.Executives.ExecutivesRoute import executives_route
from Company.Basic.Investment.InvestmentRoute import investment_route
from Company.Basic.Shareholder.ShareholderRoute import shareholder_route
@ -42,6 +44,8 @@ app.register_blueprint(business_route, url_prefix='/data/manage/company/basic/bu
app.register_blueprint(shareholder_route, url_prefix='/data/manage/company/basic/shareholder')
app.register_blueprint(executives_route, url_prefix='/data/manage/company/basic/executive')
app.register_blueprint(investment_route, url_prefix='/data/manage/company/basic/investment')
app.register_blueprint(branch_route, url_prefix='/data/manage/company/basic/branch')
app.register_blueprint(change_route, url_prefix='/data/manage/company/basic/change')
app.register_blueprint(ip_route, url_prefix='/data/manage/company/ip')
app.register_blueprint(judicial_risk_route, url_prefix='/data/manage/company/judicial_risk')
app.register_blueprint(operational_route, url_prefix='/data/manage/company/operational_risk')