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: res = BusinessImpl.auto_update(condition={"cname": cname, "cid": ""}) if res == 'success': cid = DB_TEST.find_single_column( 'WR_DataBase_v2_test', 'C3.1_工商信息', {'企业名称': cname}, '企业ID' ) else: return 'new failed' 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 manu_update(**kwargs): """新增/更新(手动)""" cid = kwargs['cid'] cname = kwargs['cname'] template = kwargs['template'] data = CompanyUtils.excel_sheet_parser(file=template) if len(cid): if data: for item in data: change_id = CompanyUtils.make_new_change_id() change = BusinessChangeObj() change.cid = cid change.change_id = change_id change.change_time = item['变更时间'] change.change_project = item['变更项目'] change.before = item['变更前'] change.after = item['变更后'] change.update_time = CommonUtils.get_current_time() update_data = change.fields_toggle() DB_TEST.upsert_single_data( "WR_DataBase_v2_test", "C3.6_工商变更", {"变更ID": change_id}, update_data ) return 'success' else: return 'update failed' elif len(cname): cid = DB_TEST.find_single_column( 'WR_DataBase_v2_test', 'C3.1_工商信息', {'企业名称': cname}, '企业ID' ) if not cid: res = BusinessImpl.auto_update(condition={"cname": cname, "cid": ""}) if res == 'success': cid = DB_TEST.find_single_column( 'WR_DataBase_v2_test', 'C3.1_工商信息', {'企业名称': cname}, '企业ID' ) else: return 'new failed' if data: for item in data: change_id = CompanyUtils.make_new_change_id() change = BusinessChangeObj() change.cid = cid change.change_id = change_id change.change_time = CommonUtils.excel_time_stamp(item['变更时间']) change.change_project = item['变更项目'] change.before = item['变更前'] change.after = item['变更后'] change.update_time = CommonUtils.get_current_time() update_data = change.fields_toggle() DB_TEST.upsert_single_data( "WR_DataBase_v2_test", "C3.6_工商变更", {"变更ID": change_id}, update_data ) return 'success' 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: update_time = record[-1]['更新时间'] result = { "info": "success", "result": { "total": total, "update_time": update_time, "records": record } } else: result = { "info": "no result" } return result