前端頁面使用H-ui框架 后端使用flask框架 數據庫使用mysql 連接數據庫通過pymysql實現
前端代碼如下
<html lang="en"> <head> <meta charset="utf-8"> <meta name="renderer" content="webkit|ie-comp|ie-stand"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> <meta http-equiv="Cache-Control" content="no-siteapp"/> <title>風險預警系統</title> <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui/css/H-ui.min.css"/> <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/css/H-ui.admin.css"/> <link rel="stylesheet" type="text/css" href="../static/ui/lib/Hui-iconfont/1.0.8/iconfont.css"/> <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/skin/default/skin.css" id="skin"/> <link rel="stylesheet" type="text/css" href="../static/ui/static/h-ui.admin/css/style.css"/> <link rel="stylesheet" type="text/css" href="../static/css/out.css"/> <style> .hide { display: none; } </style> <script type="text/javascript"> var region = { "反洗錢": { "": [""], "黑名單": ["", "黑名單一致性", "黑名單實時監控"], "客戶風險等級": ["", "首次評估", "定期評估", "客戶風險等級唯一性", ""], "可疑交易": ["", "可疑交易定性意見留痕", "可疑交易上報及時性"], "法人客戶": ["", "身份要素信息完整性"], "個人客戶": ["", "身份證件有效期"] }, "財務": { "": [""], "賠付差異": ["", "財務支付金額與業務金額不一致", "核賠不通過,財務表顯示已支付成功", "財務表顯示已支付,理賠端無對應數據", "理賠業務表中未包含公估費", "財務支出時間比理賠業務表時間提前", "理賠主表中的總支付金額小於理賠業務表中的總支付金額"] } } </script> </head> <body> <nav class="breadcrumb"><i id="logo"></i> <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a></nav> <div class="page-container"> <div class="text-c"> <select id="province" onchange="change(this.value);" class="select-box" style="width:200px;"> <option>請選擇一級指標</option> </select> <select id="city" onchange="countyChange(this.value);" class="select-box" style="width:200px;"> <option>請選擇二級指標</option> </select> <select id="county" class="select-box" style="width:200px;"> <option>請選擇三級指標</option> </select> <span> 查詢數據范圍</span> <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}',dateFmt:'yyyy-MM-dd',isShowToday:false,isShowClear:false })" id="datemin" class="input-text Wdate" style="width:300px;"> - <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',isShowToday:false,isShowClear:false })" id="datemax" class="input-text Wdate" style="width:300px;"> <button type="button" class="btn btn-success radius" id="tijiao" name=""><i class="Hui-iconfont"></i> 搜索 </button> </div> <div class="mt-20"> <table class="table table-border table-bordered table-hover table-bg thisTable"> <thead> <tr class="text-c"> <th>序號</th> <th>指標名稱</th> <th>指標日期</th> <th>監控狀態</th> <th>下載</th> </tr> </thead> <tbody id="tbody" class="text-c"> </tbody> </table> <div id="page1" class="r pager" style="margin-top: 10px"></div> <div style="font-size: 18px; font-family: 宋體; margin-top: 5px">監控狀態:1--預警 0--正常</div> </div> </div> <!--_footer--> <script type="text/javascript" src="../static/ui/lib/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="../static/ui/lib/layer/2.4/layer.js"></script> <script type="text/javascript" src="../static/ui/static/h-ui/js/H-ui.min.js"></script> <script type="text/javascript" src="../static/ui/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer--> <script src='../static/js/threelevellinkpage.js'></script> <!--業務代碼--> <script type="text/javascript" src="../static/ui/lib/My97DatePicker/4.8/WdatePicker.js"></script> <script type="text/javascript" src="../static/ui/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> <script type="text/javascript" src="../static/ui/lib/laypage/1.2/laypage.js"></script> <script type="text/javascript"> $(function () { $('#DataTables_Table_0_length').hide(); $('#DataTables_Table_0_filter').hide(); $('#DataTables_Table_0_previous').hide(); $('#DataTables_Table_0_next').hide(); $('#DataTables_Table_0_info').hide(); core.getUserListByPage(); $("#tijiao").click(function () { var datemin = $("#datemin").val(); var datemax = $("#datemax").val(); var province = $("#province").val(); var city = $("#city").val(); var county = $("#county").val(); core.getUserListByPage(datemin, datemax, province, city, county); }); }); var core = (function ($$) { var getRootPath = function () { var curWwwPath = window.document.location.href; var pathName = window.document.location.pathname; var pos = curWwwPath.indexOf(pathName); var localhostPath = curWwwPath.substring(0, pos); var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); return (localhostPath + projectName); }; var getPage = function (url, config, content) { $.getJSON(url, config, function (res) { $('#theme-count').html(res.totalPeo) laypage({ cont: 'page1', pages: Math.ceil(res.total / config.pageSize), curr: config.page || 1, group: 10, skip: true, jump: function (obj, first) { if (!first) { config.page = obj.curr; getPage(url, config, content) } } }); $('tbody').html(content(res, config.page)) }); }; function parseUserList(res, currPage) { var content = ""; if (res.total > 0) { var i = 1; $.each(res.rows, function (i, o) { content += "<tr class=\"text-c\">"; content += "<td width=\"10\" title='" + o.id + "'>" + o.curr_page + "</td>"; content += "<td width=\"10\" title='" + o.target + "'>" + o.target + "</td>"; content += "<td width=\"10\" title='" + o.monitor_date + "'>" + o.monitor_date + "</td>"; content += "<td width=\"10\" title='" + o.monitir_status + "'>" + o.monitir_status + "</td>"; {#content += "<td width=\"10\"" + "id='" +o.target+ o.monitor_date+ ".xls" + "'" + "title='" + o.monitor_dpwnload + "'>" + "<button type=\"button\" class=\"btn btn-secondary radius loadExcel\" id=\"loadExcel\" name=\"\" href=\"\"><i class=\"Hui-iconfont\"></i>導出EXCEL\n" + "</button>" + o.monitor_dpwnload + "</td>";#} content += "<td width=\"10\"" + "id='" + o.target + o.monitor_date + ".xls" + "'" + "title='" + o.monitor_dpwnload + "'>" + "<a href=\"http://127.0.0.1:5000/download_xls?code_n=" + o.monitor_dpwnload + "\"><button type=\"button\" class=\"btn btn-secondary radius loadExcel " + o.hide_h + "\" id=\"loadExcel\" ><i class=\"Hui-iconfont\"></i>導出EXCEL\n" + "</button></a>" + "</td>"; content += "</tr>"; }); $('.laypage_main ').show(); return content; } else { content += "<tr class='odd'>" content += "<td valign=\"top\" colspan=\"12\" class=\"dataTables_empty\">沒有數據</td>" content += "</tr>" $('.laypage_main ').hide(); return content; } } var getUserListByPage = function (datemin, datemax, province, city, county, curr) { core.getPage(core.getRootPath() + '/log_mysql_data?', { page: curr || 1, pageSize: 10, datemin: datemin, datemax: datemax, province: province, city: city, county: county, }, parseUserList); }; return { getRootPath: getRootPath, getPage: getPage, getUserListByPage: getUserListByPage } })(jQuery); </script> </body> </html>
后端代碼
# 獲取mysql存的日志信息 @BLACKLIST_blu.route('/log_mysql_data', methods=["GET"]) def Log_mysql(): # code = '1________' start_date = request.args.get("datemin", None) end_date = request.args.get("datemax", None) # 編碼 province = request.args.get("province", None) city = request.args.get("city", None) county = request.args.get("county", None) # print(county, 'county') # 編碼 code = targetcode(province, city, county) # print(code, 'code') if start_date is None: start_date = '1970-01-01' if end_date is None: end_date = '9999-12-31' if start_date is '': start_date = '1970-01-01' if end_date is '': end_date = '9999-12-31' curr = int(request.args.get("page")) pageSize = int(request.args.get("pageSize")) curr = (curr - 1) * pageSize sql = "SELECT * FROM inner_factors_summary_display where " + "'" + str( start_date) + "' <= FactorsDate and FactorsDate <= " + "'" + str( end_date) + "'" + " and ThirdFactorCode like '" + str(code) + "'" + " limit " + str( pageSize) + " offset " + str(curr) + " ;" # print(sql, 'sql') cc = bd_db.cursor() cn_list = [] # count = "select count(id) from inner_factors_summary_display" count = "SELECT count(id) FROM inner_factors_summary_display where " + "'" + str( start_date) + "' <= FactorsDate and FactorsDate <= " + "'" + str( end_date) + "'" + " and ThirdFactorCode like '" + str(code) + "'" # cc.execute(sql, {"datemin": start_date, "datemax": end_date, "pageSize": pageSize, "curr": curr}) cc.execute(sql) content = cc.fetchall() n = 0 for i in content: n += 1 # print(i,"i") if i[4] == '1': hide = '' else: hide = 'hide' curr_page = curr + n cn_list.append( {'id': i[0], 'target': i[1], 'monitor_date': i[2], 'monitir_status': i[4], 'monitor_dpwnload': i[7], 'hide_h': hide, 'curr_page': curr_page}) cc.execute(count) count1 = cc.fetchall()[0][0] data = {"rows": cn_list, "total": count1} return json.dumps(data) # 獲取前端頁面 風險預警系統 @BLACKLIST_blu.route('/earlywarningsystem', methods=["GET", "POST"]) def Narlywarningsystem(): if request.method == "GET": return render_template('translate.html')
給個編碼代碼
from inner_ctrl01.common.utils import bd_db def targetcode(province, city, county): province_code = None city_code = None county_code = None code_str = "_________" if province == '請選擇一級指標' or province == None: province_code = '___' else: if province == '': province_code = "___" if province != "" and province != None: sql = "SELECT FactorsCode FROM inner_frist_level_factors where FactorsCName = " + "'" + str(province) + "'" cc = bd_db.cursor() cc.execute(sql) content = cc.fetchall() province_code = str(content[0][0]) if city == '請選擇二級指標'or city == None: city_code = '___' else: if city == '': city_code = '___' if city != '' and city != None: sql = "SELECT FactorsCode FROM inner_second_level_factors where FactorsCName = " + "'" + str(city) + "';" cc = bd_db.cursor() cc.execute(sql) content = cc.fetchall() province_code = '' city_code = str(content[0][0]) if county == '請選擇三級指標' or county == None: county_code = '___' else: if county == '': county_code = '___' if county != "" and county != None: sql = "SELECT FactorsCode FROM inner_third_level_factors where FactorsCName = " + "'" + str(county) + "';" cc = bd_db.cursor() cc.execute(sql) content = cc.fetchall() province_code = '' city_code = '' county_code = str(content[0][0]) if province == None: province_code = "___" city_code = "___" county_code = "___" code_str = str(province_code) + str(city_code) + str(county_code) return code_str
數據庫結構
# inner_frist_level_factors id 自增 主鍵 不能為空 FactorsCname varchar FactorsCode varchar null unique
# inner_second_level_factors id 自增 主鍵 不能為空 FactorsCname varchar FactorsCode varchar null unique FatherCode varchar null
# inner_third_level_factors id 自增 主鍵 不能為空 FactorsCname varchar FactorsCode varchar null unique
FatherCode varchar null
FactorsEname varchar
# inner_factors_summary_display
FactorsCname varchar
FactorsDate varchar
FactorsStatus varchar
FactorsFlag varchar
thirdFactorsCode varchar
FactorsDownloadUrl varchar
FactorsEname varchar
以上四張表可以根據自己需求設計。我們將第四張表的數據傳到前端頁面。
其他部門在前幾篇博客里面。
本篇博客不適合新人,結束!