def IdNo(self): try: date = datetime.datetime.now().strftime('%m-%d') month_day = ''.join(date.split('-')) sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_regions_code') list = MysqlHandle.select_mysql_data(sql) dict = list[0] city_code = dict['regions_code'] key = '\d{18}|\d{17}X' result = requests.get( 'http://sfz.uzuzuz.com/?region=%s&birthday=%s%s&sex=2&num=1' % (city_code, self.year, month_day)).text data = re.findall(key, result) data = ''.join(data) sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='update_regions_enabled') sql = sql.format(regions_code=city_code) MysqlHandle.delete_update_insert_mysql_data(sql) print('我被调用了') except Exception as e: self.code = 1 return '身份证id生成接口出现问题---详情请咨询小叶同学' return data
def updateMXstatus(request): ''' :param request: mobile:str 装饰器加密 ,type:list 为魔蝎字段 :return: json ''' data = request.JSON mobile = data['mobile'] types = list(data['type']) strs = '' for i in types: strs = strs + ',' + '"%s"' % i print('strs------->', strs) result = {'code': '200', 'data': '成功了'} try: sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='update_mx_grap') sql = sql.format(mobile=mobile, type=strs.lstrip(',')) sql_data = MysqlHandle.delete_update_insert_mysql_data( sql.format(mobile=mobile, type=strs.lstrip(','))) except Exception as e: result['code'] = '400' result['data'] = e return JsonResponse(result, status=400) return JsonResponse(result, status=200)
def delete_token_return_lend_request_id(request): data = request.JSON sale_no = data['sale_no'] mobile = data['mobile'] print('data======>', mobile) result = {'code': '202', 'data': '没有此手机号'} try: sql1 = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_lend_request_id') print(sql1.format(mobile=mobile)) sql_data1 = MysqlHandle.select_mysql_data(sql1.format(mobile=mobile)) sql2 = MysqlHandle.get_xml_sql(xml_path='delete_sql', xml_tag='delete', xml_id='delete_user_token') sql_data2 = MysqlHandle.delete_update_insert_mysql_data( sql2.format(sale_no=sale_no)) except Exception as e: result['code'] = '400' result['data'] = e return JsonResponse(result, status=400) if sql_data1: result['code'] = '200' result['data'] = sql_data1[0] return JsonResponse(result, status=200)
def changeIdNo(request): ''' :param request:mobile:str 装饰器加密 idNo:str 装饰器加密 ,customer_name:str 姓名 :return: ''' data = request.JSON mobile = data['mobile'] idNo = data['idNo'] customer_name = data['customer_name'] result = {'code': '200', 'data': '成功了'} try: sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='update_customer_idno') print( 'sql.format(idNo=idNo,mobile=mobile,customer_name=customer_name)---->', sql.format(idNo=idNo, mobile=mobile, customer_name=customer_name)) sql_data = MysqlHandle.delete_update_insert_mysql_data( sql.format(idNo=idNo, mobile=mobile, customer_name=customer_name)) except Exception as e: result['code'] = '400' result['data'] = e return JsonResponse(result, status=400) return JsonResponse(result, status=200)
def add_piece_api(request): gain_data = request.POST status = gain_data['status'] num = gain_data['num'] name = gain_data['name'] product_type = gain_data['product_type'] video_check = gain_data['video_check'] print('video_Check--------------->', video_check) print('gain_data---->', gain_data) mobile = gain_data['mobile'] lend_status = Func_status('lend') print('status---------------->', status) if status in lend_status and num == '0' and product_type == '': # 判断是否需要搜索进件 data = {'status': status} result = post(url='/v1/get/SearchResult', data=data) print('result------>', result) if result: return HttpResponse(result, content_type="application/json") mobile_enable = AddPiece.mobile_enable(mobile) # 判断手机号是否有人使用 if mobile_enable: return JsonResponse({'code': 202, 'message': '手机号已存在,请更换手机号'}) # 以下操作为跑流程 strs = request.strs t = MyThread(func=AddPiece.piece_to_status, args=(status, strs, product_type)) t.start() t.join() data = t.get_result() if data in (1, 2): data = {"mobile": mobile} result_post = post(url='/v1/get/IdAndStatus', data=data) dict_data = json.loads(result_post) print('dict_data--->', dict_data), print('type------>', type(dict_data)) post_data = dict_data['data'][0] print('post_data------->', post_data) print('type----------->', type(post_data)) app_request_id = post_data['app_request_id'] lend_request_id = post_data['lend_request_id'] if lend_request_id == None: lend_request_id = 'NULL' current_status = post_data['current_status'] sql = MysqlHandle.get_xml_sql(xml_path='insert_sql', xml_tag='insert', xml_id='insert_piece') MysqlHandle.delete_update_insert_mysql_data( sql.format(name=name, mobile=mobile, want_to_status=status, current_status=current_status, lend_request_id=lend_request_id, app_request_id=app_request_id)) if data == 2: return JsonResponse({'code': 202, 'message': '已推送到个贷系统,后续状态请关注列表'}) return JsonResponse({'code': 202, 'message': '造件已完成'}) elif data == 3: return JsonResponse({'code': 202, 'message': '有异常产生,请稍后重试'}) else: return JsonResponse({'code': 202, 'message': data})
def qr_ios_download(request): ids = request.GET['id'] sql_select = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_ios_qr_path') data = MysqlHandle.select_mysql_data(sql_select.format(id=ids))[0] return render(request, 'qr-ios-download.html', {'data': data})
def del_piece_list(request): piece_id = request.POST['column_id'] sql = MysqlHandle.get_xml_sql(xml_path='delete_sql', xml_tag='delete', xml_id='delete_piece_list_id') data = MysqlHandle.delete_update_insert_mysql_data(sql.format(id=piece_id)) if data: return HttpResponse('1') else: return HttpResponse('0')
def ProductIsRequired(request): data = request.JSON product_name = data['product_name'] sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='search_product_required') sql_data = MysqlHandle.select_mysql_data( sql.format(product_name=product_name)) result_data = [] for inner in sql_data: result_data.append(inner["material_type"]) result = {'code': 200, 'data': result_data} print('必填项-----》', result) return JsonResponse(result, status=200)
def update_face_id(request): try: data = request.JSON mobile = data['mobile'][0] today = date.today() sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='update_face_id') # print('sql---->',sql.format(mobile=mobile)) data = MysqlHandle.delete_update_insert_mysql_data( sql.format(mobile=mobile, date=today)) result = {'code': 200} except Exception as e: pass return JsonResponse(result, status=200)
def mobile_to_id_status(request): data = request.JSON mobile = data['mobile'] mobile_str = '' print('views 中 mobile----》', mobile) for i in mobile: mobile_str = mobile_str + '"%s"' % i + ',' sql_moblie = mobile_str.rstrip(',') print('sql_moblie----->', sql_moblie) sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_id_status_to_piece') print(sql.format(mobile=sql_moblie)) data = MysqlHandle.select_mysql_data(sql.format(mobile=sql_moblie)) result = {'code': 200, 'data': data} return JsonResponse(result, status=200)
def app_product(request): sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_product_list') data = MysqlHandle.select_mysql_data(sql) paginator = Paginator(data, 10) page = request.GET.get('page', 1) currentPage = int(page) try: print(page) result = paginator.page(page) except PageNotAnInteger: result = paginator.page(1) except EmptyPage: result = paginator.page(paginator.num_pages) return render(request, 'app-product.html', { 'data': result, 'paginator': paginator })
def add_product(request): message = '' if request.method == 'POST': product_name = request.POST['product_name'] product_enum = request.POST['product_enum'] product_type = request.POST['product_type'] sql = MysqlHandle.get_xml_sql(xml_path='insert_sql', xml_tag='insert', xml_id='insert_app_product') sql = sql.format(product_name=product_name, product_enum=product_enum, product_type=product_type) tag = MysqlHandle.delete_update_insert_mysql_data(sql) if tag == 1: message = '添加成功' else: message = '添加失败' return render(request, 'add-product.html', {'message': message})
def mobile_enable(request): data = request.JSON result = {'code': '200', 'data': '1'} mobile = data['mobile'] try: sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_mobile_enable') print('sql---->', sql.format(mobile=mobile)) mysql_data = MysqlHandle.select_mysql_data(sql.format(mobile=mobile)) dicts = mysql_data[0] tag = dicts['counts'] except Exception as e: result['code'] = '400' result['data'] = e return JsonResponse(result, status=400) if tag: return JsonResponse(result, status=200) result['data'] = '%s' % tag return JsonResponse(result, status=200)
def app_list(request): sql = request.DPOST.get('sql') + ' order by create_time desc' MysqlHandle.reConnect() data = MysqlHandle.select_mysql_data(sql) paginator = Paginator(data, 10) page = request.GET.get('page', 1) currentPage = int(page) try: print(page) result = paginator.page(page) except PageNotAnInteger: result = paginator.page(1) except EmptyPage: result = paginator.page(paginator.num_pages) return render(request, 'app-list.html', { 'applist': result, 'paginator': paginator })
def insert_statistics_amount(): # 计算昨天日期 print('开始了') today = datetime.datetime.now() offset = datetime.timedelta(days=-1) yesterday = (today + offset).strftime('%Y-%m-%d') # 查询昨日造件数量 piece_sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_chart_piece') piece_data = MysqlHandle.select_mysql_data( piece_sql.format(create_time=yesterday)) piece_number = piece_data[0].get('number') print('piece_data---->', piece_data) # 查询昨日上传包数量 app_sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_chart_app') app_data = MysqlHandle.select_mysql_data( app_sql.format(create_time=yesterday)) app_number = app_data[0].get('number') print('app_number---->', app_number) # 将数量插入到statistics_amount中 statistics_tuple = ((piece_number, 'PIECE'), (app_number, 'APP')) statistics_sql = MysqlHandle.get_xml_sql( xml_path='insert_sql', xml_tag='insert', xml_id='insert_into_statistics_data') for inner in statistics_tuple: tag = MysqlHandle.delete_update_insert_mysql_data( statistics_sql.format(date_record=yesterday, count=inner[0], category=inner[1])) print('tag----->', tag)
def del_app_list(request): column_id = request.POST['column_id'] MysqlHandle.reConnect() sql_del = MysqlHandle.get_xml_sql(xml_path='delete_sql', xml_tag='delete', xml_id='delete_app_list_id') # 删除app的sql sql_path = MysqlHandle.get_xml_sql( xml_path='select_sql', xml_tag='select', xml_id='delete_file_path') # 查找app路径的sql data = MysqlHandle.select_mysql_data(sql_path.format(id=column_id))[0] app_path = data.get('appPath') app_path = './static/' + app_path[:18] try: shutil.rmtree(app_path) except Exception as e: tag = 2 tag = MysqlHandle.delete_update_insert_mysql_data( sql_del.format(id=column_id)) if tag == 1: return HttpResponse('1') elif tag == 2: return HttpResponse('2') else: return HttpResponse('0')
def SearchResult(request): data = request.JSON status = data['status'] sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='search_result') sql_data = MysqlHandle.select_mysql_data(sql.format(status=status)) count = len(sql_data) result = {'code': 200, 'data': sql_data} if count: strs = '' for inner in sql_data: strs = strs + ',' + inner['mobile'] aus = AesUtils() mobile_list = aus.decrpyt(strs.lstrip(',')) for let in range(len(mobile_list)): sql_data[let]['mobile'] = mobile_list[let] result['data'] = sql_data return JsonResponse(result, status=200) result['code'] = 202 return JsonResponse(result, status=202)
def update_app(request): ids = request.GET['id'] sql_select = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='update_app_list') MysqlHandle.reConnect() data = MysqlHandle.select_mysql_data(sql_select.format(id=ids))[0] data['describe'] = data['describe'].replace("\r\n", "\\n") message = '' if request.method == 'POST': appType = request.POST.get('app_type') environment = request.POST.get('environment') customeroruser = request.POST.get('customeroruser') isfinal = request.POST.get('isfinal') app_version = request.POST.get('app_version') describe = request.POST.get('describe') test_or_beta = request.POST.get('test_or_beta') sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='update_app_manage') tag = MysqlHandle.delete_update_insert_mysql_data( sql.format(appType=appType, environment=environment, customerOruser=customeroruser, isFinal=isfinal, appVersion=app_version, describe=describe, test_or_beta=test_or_beta, id=ids)) if tag == 0 or tag == 1: MysqlHandle.reConnect() data = MysqlHandle.select_mysql_data(sql_select.format(id=ids))[0] message = '修改成功!' else: message = '修改失败!' return render(request, 'update_app.html', { 'data': data, 'message': message })
def welcome(request): date = [] app_count = [] piece_count = [] # 计算一周前今天的日期 today = datetime.datetime.now() offset = datetime.timedelta(days=-7) hebdomad_ago = (today + offset).strftime('%Y-%m-%d') print('一周前的今天', hebdomad_ago) sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_statistics_amount_app_data') data = MysqlHandle.select_mysql_data(sql.format(hebdomad_ago=hebdomad_ago)) for i in data: date.append(i['date']) app_count.append(i['count']) # 查询进件数 piece_sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_statistics_amount_piece_data') piece_data = MysqlHandle.select_mysql_data(piece_sql.format(hebdomad_ago=hebdomad_ago)) for i in piece_data: piece_count.append(i['count']) result = {'date': mark_safe(date), 'piece_count': piece_count, 'app_count': app_count} print('result=======>', result) return render(request, 'welcome.html', result)
def piece_list(request): print('post----------->', request.POST) sql = request.DPOST.get('sql') + ' order by create_time desc' data = MysqlHandle.select_mysql_data(sql) print('sqls------>', sql) paginator = Paginator(data, 20) page = request.GET.get('page', 1) currentPage = int(page) try: print(page) result = paginator.page(page) except PageNotAnInteger: result = paginator.page(1) except EmptyPage: result = paginator.page(paginator.num_pages) return render(request, 'piece-list.html', { 'piecelist': result, 'paginator': paginator })
def update_city_code(): print('datetime------>', datetime.datetime.now()) sql = MysqlHandle.get_xml_sql(xml_path='update_sql', xml_tag='update', xml_id='timer_regions') MysqlHandle.delete_update_insert_mysql_data(sql)
def add_piece(request): sql = MysqlHandle.get_xml_sql(xml_path='select_sql', xml_tag='select', xml_id='select_product_list') data = MysqlHandle.select_mysql_data(sql) return render(request, 'add-piece.html', {'data': data})
def add_app(request): timestrap = str(int(time.time())) sql = MysqlHandle.get_xml_sql(xml_path='insert_sql', xml_id='insert_app_path', xml_tag='insert') Rootpath = './static/appfile/{timestrap}/'.format(timestrap=timestrap) myFilemessage = '' print('request-----》', request.POST) if request.method == 'POST': myFile = request.FILES.get('myfile') customerOruser = request.POST.get('customerOruser') appType = request.POST.get('app_type') isfinal = request.POST.get('isfinal') app_version = request.POST.get('app_version') appPath = Rootpath + myFile.name os.makedirs(Rootpath) describe = request.POST.get('describe') environment = request.POST.get('environment') test_or_beta = request.POST.get('test_or_beta') #发送邮件所用标题 title = "{environment}-{appType}-{customerOruser}".format( environment=environment, appType=appType, customerOruser=customerOruser) #发送邮件所用名单 email_list = ['*****@*****.**', '*****@*****.**'] describe = describe if describe else '' customerOruser = '******' if customerOruser == '钢铁侠' else 'CUSTOMER' isfinal = 1 if isfinal == '是' else 0 if appType == "ANDROID": qr_path = appPath[9:] elif appType == "IOS": tag = createplist(appPath.lstrip('.'), timestrap) if tag == '1': qr_path = 'https://gitee.com/ituface/test/raw/master/%s.plist' % timestrap else: myFilemessage = '上传失败了' if not myFile: return render(request, 'order-add.html', {'myFilemessage': '文件有误,请重新上传'}) destination = open(os.path.join(Rootpath, myFile.name), 'wb+') # 打开特定的文件进行二进制的写操作 for chunk in myFile.chunks(): # 分块写入文件 destination.write(chunk) destination.close() try: sql = sql.format(appVersion=app_version, appType=appType, customerOruser=customerOruser, describe=describe, appPath=appPath[9:], environment=environment, isFinal=isfinal, test_or_beta=test_or_beta, qr_path=qr_path) print('sql---->', sql) MysqlHandle.reConnect() sta = MysqlHandle.delete_update_insert_mysql_data(sql) if sta != 1: myFilemessage = '上传失败了' except Exception: myFilemessage = '上传失败' sta = 2 if sta == 1: myFilemessage = '上传成功' send_email(email_list, "描述:%s" % describe, title) return render(request, 'add-app.html', {'myFilemessage': myFilemessage})