|
@@ -71,6 +71,8 @@
|
|
|
aria-expanded="true">通用规则</a></li>
|
|
|
<li data-mode="guide" class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">关键词规则</a>
|
|
|
</li>
|
|
|
+ <li data-mode="guide" class="exactRuleShow" style="display: none"><a href="#tab_3" data-toggle="tab" aria-expanded="false">精准筛选规则</a>
|
|
|
+ </li>
|
|
|
<button class="btn btn-primary btn-sm" style="float: right;margin-top: 4px;margin-right: 10px"
|
|
|
onclick="saveTag()"><i class="fa fa-fw fa-file-text fa-lg"></i>保存
|
|
|
</button>
|
|
@@ -430,6 +432,7 @@
|
|
|
<i class="fa fa-bookmark"></i>
|
|
|
<h3 class="box-title">关键词规则</h3>
|
|
|
<div style="float: right">
|
|
|
+ <a class="btn btn-default btn-sm groups exactRuleShow" style="display: none" onclick="selectGroups()">分组管理</a>
|
|
|
<a class="btn btn-default btn-sm" onclick="selectKeyMatch(4)">关键词匹配方式</a>
|
|
|
<a class="btn btn-default btn-sm" onclick="selectKeyMatch(6)">附加词匹配方式</a>
|
|
|
<a class="btn btn-default btn-sm" onclick="selectKeyMatch(8)">排除词匹配方式</a>
|
|
@@ -460,6 +463,32 @@
|
|
|
</table>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div class="tab-pane" id="tab_3">
|
|
|
+ <div class="box box-primary">
|
|
|
+ <div class="box-header with-border">
|
|
|
+ <div class="col-sm-10">
|
|
|
+ <h5>说明:可根据公告匹配的“关键词分组”个数,确定是否推送该简公告;符合以下其中1条规则即推送</h5>
|
|
|
+ </div>
|
|
|
+ <div class="col-sm-2">
|
|
|
+ <button class="btn btn-twitter btn-sm" style="float: right;margin-top: 4px;margin-right: 10px"
|
|
|
+ onclick="addExactRuleShow()"><i class="fa fa-fw fa-file-text fa-lg"></i>新增
|
|
|
+ </button> </div>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <table id="exactRuleTable" class="table table-bordered">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>编号</th>
|
|
|
+ <th>关键词分组匹配条件</th>
|
|
|
+
|
|
|
+ <th>操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -498,15 +527,21 @@
|
|
|
var selectIndex = []; //选中的编号
|
|
|
var setValue = 0; // 4: 关键词匹配方式,6:附加词匹配方式,8:排除词匹配方式,9:采购单位,10:公告行业, 2:全局采购单位类型, 3:全局公告行业
|
|
|
var state = 1;
|
|
|
+ var exactRuleTableArr =[];// 临时数组 用于存放规则字符串转换后的数据
|
|
|
+ var testexactRuleTableArr =[];// 临时数组 用于存放数据验证规则字符串转换后的数据
|
|
|
var departName = GetQueryString("departName")
|
|
|
$("#departName").html(departName + "规则")
|
|
|
$('#departName').attr("href", "/client/cuser/rule/list?ids=" + ids + "&departName=" + departName)
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
+
|
|
|
var name1 = {{(session "user").name}};
|
|
|
if (name1 != dataMap.s_updateuser) {
|
|
|
showTip("上次修改人员是" + dataMap.s_updateuser, 1000)
|
|
|
}
|
|
|
+ if (dataMap.i_exact === 1) {
|
|
|
+ $(".exactRuleShow").show()
|
|
|
+ }
|
|
|
$('#extfiledselect').val(dataMap.i_extfieldstype);
|
|
|
//es
|
|
|
$('#estxt').val(dataMap.s_esquery);
|
|
@@ -868,6 +903,42 @@
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
+ exactRuleTableArr = exactRuleStrToArr( dataMap["s_exactRule"])
|
|
|
+ // 精准筛选规则表格
|
|
|
+ $('#exactRuleTable').DataTable({
|
|
|
+ "paging": false,
|
|
|
+ "lengthChange": false,
|
|
|
+ "searching": false,
|
|
|
+ "ordering": false,
|
|
|
+ "info": true,
|
|
|
+ "autoWidth": false,
|
|
|
+ "language": {
|
|
|
+ "url": "/dist/js/dataTables.chinese.lang"
|
|
|
+ },
|
|
|
+ "fnDrawCallback": function () {
|
|
|
+ this.api().column(0).nodes().each(function (cell, i) {
|
|
|
+ cell.innerHTML = i + 1;
|
|
|
+ });
|
|
|
+ this.api().column(2).nodes().each(function (cell, i) {
|
|
|
+ cell.innerHTML = '<div>' +
|
|
|
+ '<a onclick="editExacRuleClick(\'' + i + '\')" >编辑</a>  ' +
|
|
|
+ '<a onclick="delExacRuleClick(\'' + i + '\')" >删除</a>  ' +
|
|
|
+ '</div>';
|
|
|
+ });
|
|
|
+ },
|
|
|
+ "data": exactRuleTableArr,
|
|
|
+ "columns": [
|
|
|
+ {"data": null},
|
|
|
+ {
|
|
|
+ "data": function (row) {
|
|
|
+ return exactRuleDataFormat(row)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": null
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
$('#province').selectpicker({
|
|
@@ -2456,10 +2527,44 @@
|
|
|
type: "post",
|
|
|
data: {"title": title, "detail": detail},
|
|
|
success: function (r) {
|
|
|
+ debugger
|
|
|
+ if (r.exactRule != ""){
|
|
|
+ testexactRuleTableArr = exactRuleStrToArr( r.exactRule)
|
|
|
+ $('#checkExactRuleTable').DataTable({
|
|
|
+ "paging": false,
|
|
|
+ "lengthChange": false,
|
|
|
+ "searching": false,
|
|
|
+ "ordering": false,
|
|
|
+ "info": true,
|
|
|
+ "autoWidth": false,
|
|
|
+ "language": {
|
|
|
+ "url": "/dist/js/dataTables.chinese.lang"
|
|
|
+ },
|
|
|
+ "fnDrawCallback": function () {
|
|
|
+ this.api().column(0).nodes().each(function (cell, i) {
|
|
|
+ cell.innerHTML = i + 1;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ "data": testexactRuleTableArr,
|
|
|
+ "columns": [
|
|
|
+ {"data": null},
|
|
|
+ {
|
|
|
+ "data": function (row) {
|
|
|
+ return exactRuleDataFormat(row)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
|
|
|
-
|
|
|
+ }else{
|
|
|
+ $("#checkExactRule").text("规则:")
|
|
|
+ }
|
|
|
+ if (r.exactResult){
|
|
|
+ $("#checkExactResult").text("验证结果:通过")
|
|
|
+ }else{
|
|
|
+ $("#checkExactResult").text("验证结果:不通过")
|
|
|
+ }
|
|
|
if (r.status) {
|
|
|
-
|
|
|
//全局附加词未匹配成功或者 排除词排除
|
|
|
if (r.data.result === false) {
|
|
|
// $("#result_status").html("匹配失败")
|
|
@@ -2494,4 +2599,290 @@
|
|
|
|
|
|
})
|
|
|
}
|
|
|
+ //分组管理
|
|
|
+ var ruleGroupList = new Array()
|
|
|
+ // 精准筛选规则-新增按钮点击方法
|
|
|
+ function addExactRuleShow(){
|
|
|
+ // 判断是否设置关键词
|
|
|
+ if (ruleGroupList.length===0){
|
|
|
+ showGroupListData()
|
|
|
+ if (ruleGroupList.length===0){
|
|
|
+ showTip("请先设置关键词规则分组")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断是否设置关键词匹配方式
|
|
|
+ // debugger
|
|
|
+ // 判断是否设置关键词
|
|
|
+ if (o_rules.length===0) {
|
|
|
+ showTip("请先设置关键词")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 判断是否设置关键词匹配方式
|
|
|
+ if (!hasMatchWay()){
|
|
|
+ showTip("请先设置关键词匹配方式")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //初始化
|
|
|
+ $("#insertexactRule").html("");
|
|
|
+ $("#addExactRuleButton").show();
|
|
|
+ // 新增精准筛选规则弹框
|
|
|
+ // 请求分组列表接口获取数据
|
|
|
+ ruleHtmlFunc("insert-class","","#insertexactRule")
|
|
|
+ $("#modal-add-exactRule").modal("show");
|
|
|
+ }
|
|
|
+ // 精准筛选规则-新增页面 +新增按钮
|
|
|
+ function addExactRule(){
|
|
|
+ ruleHtmlFunc("insert-class","","#insertexactRule")
|
|
|
+ if ($('.exact-rule-class').length > 3){
|
|
|
+ $("#addExactRuleButton").hide()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 精准筛选规则-新增精准匹配规则保存按钮点击事件
|
|
|
+ function add_exactRule_save(){
|
|
|
+ // 获取值
|
|
|
+ let ruleArr = [];
|
|
|
+ let checkObj = {};
|
|
|
+ let formList = $("#insertexactRule .insertexactRule-form");
|
|
|
+ formList.each(function() {
|
|
|
+ var groupName = $(this).find('select[name="groupSelect"]').val();
|
|
|
+ var count = $(this).find('input[name="count"]').val();
|
|
|
+ var matchWayValue = $(this).find('select[name="matchWay"]').val();
|
|
|
+ if (groupName===""||matchWayValue.length===0||count===""){
|
|
|
+ // todo
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ for (let j = 0; j < matchWayValue.length; j++) {
|
|
|
+ let rule = {
|
|
|
+ "group":groupName,"match_way":matchWayValue[j],"count":count
|
|
|
+ }
|
|
|
+ if(checkObj[groupName+"_"+count+"_"+matchWayValue[j]]){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ checkObj[groupName+"_"+count+"_"+matchWayValue[j]] = matchWayValue[j]
|
|
|
+ ruleArr.push(rule)
|
|
|
+ }
|
|
|
+ console.log(matchWayValue);
|
|
|
+ });
|
|
|
+ if (ruleArr.length===0){
|
|
|
+ showMsg("规则已存在!")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 保存到exactRuleTableArr 临时数组
|
|
|
+ exactRuleTableArr.push(ruleArr)
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ $('#exactRuleTable').dataTable().fnAddData(exactRuleTableArr);
|
|
|
+ if (exactRuleTableArr.length == 0) {
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ }
|
|
|
+ $("#modal-add-exactRule").modal("hide");
|
|
|
+
|
|
|
+ }
|
|
|
+ // 精准筛选规则-临时数组转换成规则字符串
|
|
|
+ // [[{"group":"A","match_way":"content","count":5},{},{}],[]]
|
|
|
+ // (title_A>0 and content_B>8) or title_B>4 or (content_A>7 and content_B>1)
|
|
|
+ function exactRuleArrToStr(){
|
|
|
+ let ruleStrArr = []
|
|
|
+ for (let i = 0; i < exactRuleTableArr.length; i++) {
|
|
|
+ let rulesArr = [];
|
|
|
+ for (let j = 0; j < exactRuleTableArr[i].length; j++) {
|
|
|
+ let count =exactRuleTableArr[i][j].count-1
|
|
|
+ let group = exactRuleTableArr[i][j].group
|
|
|
+ let match_way = exactRuleTableArr[i][j].match_way
|
|
|
+ let rule = match_way+"_"+group+">"+count
|
|
|
+ rulesArr.push(rule)
|
|
|
+ }
|
|
|
+ if (rulesArr.length>1){ // 拼接小括号
|
|
|
+ ruleStrArr.push("("+rulesArr.join(" and ")+")")
|
|
|
+ }else {
|
|
|
+ if (rulesArr.length>0){
|
|
|
+ ruleStrArr.push(rulesArr[0])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ruleStrArr.join(" or ")
|
|
|
+ }
|
|
|
+ // (title_A>0 and content_B>8) or title_B>4 or (content_A>7 and content_B>1)
|
|
|
+ // 精准筛选规则-规则字符串转换成临时数组 仅支持这种格式 (title_A>0 and content_B>8) or title_B>4 or (content_A>7 and content_B>1)
|
|
|
+ // 分组名称不要包含公式中的符号 : 下划线、>、()、or、and
|
|
|
+ function exactRuleStrToArr( exactRuleStr) {
|
|
|
+ if (exactRuleStr===undefined||exactRuleStr===""){
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ let exactRuleTableArrTmp = []
|
|
|
+ // let exactRuleStr = "(title_A>0 and content_B>8) or title_B>4 or (content_A>7 and content_B>1)"
|
|
|
+ let exactRuleList = exactRuleStr.split(" or ") // 分割成单条规则
|
|
|
+ for (let i=0; i< exactRuleList.length; i++) {
|
|
|
+ let exactRuleTmp = exactRuleList[i]
|
|
|
+ let rulesArr = [];
|
|
|
+ if (exactRuleTmp.startsWith("(")) {
|
|
|
+ exactRuleTmp = exactRuleTmp.slice(1, -1) //去掉首尾的括号
|
|
|
+ }
|
|
|
+ let singleRuleArr = exactRuleTmp.split(" and ") // 分割单条规则中的数据
|
|
|
+ for (let j=0;j<singleRuleArr.length;j++) {
|
|
|
+ let singleRule =singleRuleArr[j]
|
|
|
+ // 匹配方式
|
|
|
+ let singleRuleSplit = singleRule.split("_")
|
|
|
+ if (singleRuleSplit.length<2){
|
|
|
+ console.log("singleRuleSplit 长度不够",singleRuleSplit)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let matchWay = singleRuleSplit[0] // 第一位是匹配方式
|
|
|
+ // 然后接着分割出分组名称和次数 使用 _
|
|
|
+ let singleRuleSplit2 = singleRuleSplit[1].split(">")
|
|
|
+ if (singleRuleSplit2.length<2){
|
|
|
+ console.log("singleRuleSplit2 长度不够",singleRuleSplit2)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let groupName = singleRuleSplit2[0]
|
|
|
+ let count = singleRuleSplit2[1]
|
|
|
+ // 次数 次数这里要+1 因为展示框里用的是>= 公式里面用的是>
|
|
|
+ let rule = {
|
|
|
+ "group":groupName,"match_way":matchWay,"count":parseInt(count)+1
|
|
|
+ }
|
|
|
+ rulesArr.push(rule)
|
|
|
+ }
|
|
|
+ exactRuleTableArrTmp.push(rulesArr)
|
|
|
+ }
|
|
|
+ return exactRuleTableArrTmp;
|
|
|
+ }
|
|
|
+ var editexactRuleId = 0;
|
|
|
+ const matchWayMap = {
|
|
|
+ "title":"标题匹配",
|
|
|
+ "content":"全文匹配"
|
|
|
+ }
|
|
|
+ // 规则数组转换列表字符串
|
|
|
+ function exactRuleDataFormat(contentArr ){
|
|
|
+ // keyArr 定义数组 维持最后有序
|
|
|
+ let keyArr = []
|
|
|
+ // 合并 标题正文 如果
|
|
|
+ let tmpDict = {}
|
|
|
+ for (let i = 0; i < contentArr.length; i++) {
|
|
|
+ let keyGroupCount = contentArr[i].group+"_"+ contentArr[i].count
|
|
|
+ if (tmpDict.hasOwnProperty(keyGroupCount)){
|
|
|
+ tmpDict[keyGroupCount].match_way.add(matchWayMap[contentArr[i].match_way])
|
|
|
+ }else {
|
|
|
+ let set = new Set();
|
|
|
+ tmpDict[keyGroupCount] = {
|
|
|
+ "group":contentArr[i].group,"match_way":set.add(matchWayMap[contentArr[i].match_way]),"count":contentArr[i].count
|
|
|
+ }
|
|
|
+ keyArr.push(keyGroupCount)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let str = ""
|
|
|
+ for (let tmpDictKey in keyArr) {
|
|
|
+ str += "关键词分组:"+tmpDict[keyArr[tmpDictKey]].group+",出现次数>="+tmpDict[keyArr[tmpDictKey]].count+",匹配方式:"+Array.from(tmpDict[keyArr[tmpDictKey]].match_way).join(",")+";"
|
|
|
+ }
|
|
|
+ return str
|
|
|
+ }
|
|
|
+ // 删除 点击事件
|
|
|
+ function delExacRuleClick(index) {
|
|
|
+ index = parseInt(index)
|
|
|
+ showConfirm("确定删除?", function () {
|
|
|
+ exactRuleTableArr = $.grep(exactRuleTableArr,function (n,i) {
|
|
|
+ return i!==index
|
|
|
+ })
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ $('#exactRuleTable').dataTable().fnAddData(exactRuleTableArr);
|
|
|
+ if (exactRuleTableArr.length == 0) {
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ function showGroupListData(){
|
|
|
+ $.ajax({
|
|
|
+ url: "/client/cuser/groupList",
|
|
|
+ type: "post",
|
|
|
+ data: {"id": dataMap.id},
|
|
|
+ async: false,
|
|
|
+ success: function (r) {
|
|
|
+ if (r.data) {
|
|
|
+ ruleGroupList=r.data;
|
|
|
+ }
|
|
|
+ }})
|
|
|
+ }
|
|
|
+ // 编辑点击事件
|
|
|
+ function editExacRuleClick(index){
|
|
|
+ $("#editexactRule").html("");
|
|
|
+ $("#editExactRuleButton").show();
|
|
|
+ editexactRuleId = index;
|
|
|
+ // 铺数据
|
|
|
+ let contentArr = exactRuleTableArr[index]
|
|
|
+ // keyArr 定义数组 维持最后有序
|
|
|
+ let keyArr = []
|
|
|
+ // 合并 标题正文
|
|
|
+ let tmpDict = {}
|
|
|
+ for (let i = 0; i < contentArr.length; i++) {
|
|
|
+ let keyGroupCount = contentArr[i].group+"_"+ contentArr[i].count
|
|
|
+ if (tmpDict.hasOwnProperty(keyGroupCount)){
|
|
|
+ tmpDict[keyGroupCount].match_way.add(contentArr[i].match_way)
|
|
|
+ }else {
|
|
|
+ let set = new Set();
|
|
|
+ tmpDict[keyGroupCount] = {
|
|
|
+ "group":contentArr[i].group,"match_way":set.add(contentArr[i].match_way),"count":contentArr[i].count
|
|
|
+ }
|
|
|
+ keyArr.push(keyGroupCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let i = 0; i < keyArr.length; i++) {
|
|
|
+ var keyGroup = tmpDict[keyArr[i]].group;
|
|
|
+ var count = tmpDict[keyArr[i]].count;
|
|
|
+ var matchWay = tmpDict[keyArr[i]].match_way;
|
|
|
+ ruleHtmlFunc("edit-class",keyArr[i],"#editexactRule");
|
|
|
+ $('#editexactRule .'+keyArr[i]+' select[name=groupSelect]').selectpicker('val',keyGroup);
|
|
|
+ $('#editexactRule .'+keyArr[i]+' input[name=count]').val(count);
|
|
|
+ let matchWayArr = Array.from(matchWay);
|
|
|
+ $('#editexactRule .'+keyArr[i]+' select[name=matchWay]').val("").trigger("change").selectpicker('val',matchWayArr);
|
|
|
+ }
|
|
|
+ $("#modal-edit-exactRule").modal("show");
|
|
|
+ }
|
|
|
+ // 编辑保存
|
|
|
+ function edit_exactRule_save(){
|
|
|
+ // let index = $("#editexactRuleId").text()
|
|
|
+ // 获取数
|
|
|
+ let ruleArr = []
|
|
|
+ let formList = $("#editexactRule .editexactRule-form")
|
|
|
+ formList.each(function() {
|
|
|
+ var groupName = $(this).find('select[name="groupSelect"]').val();
|
|
|
+ var count = $(this).find('input[name="count"]').val();
|
|
|
+ var matchWayValue = $(this).find('select[name="matchWay"]').val();
|
|
|
+ if (groupName===""||matchWayValue.length===0||count===""){
|
|
|
+ // todo
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ for (let j = 0; j < matchWayValue.length; j++) {
|
|
|
+ let rule = {
|
|
|
+ "group":groupName,"match_way":matchWayValue[j],"count":count
|
|
|
+ }
|
|
|
+ ruleArr.push(rule)
|
|
|
+ }
|
|
|
+ console.log(matchWayValue);
|
|
|
+ });
|
|
|
+ // 保存到exactRuleTableArr 临时数组
|
|
|
+ exactRuleTableArr[editexactRuleId] = ruleArr
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ $('#exactRuleTable').dataTable().fnAddData(exactRuleTableArr);
|
|
|
+ if (exactRuleTableArr.length === 0) {
|
|
|
+ $('#exactRuleTable').dataTable().fnClearTable();
|
|
|
+ }
|
|
|
+ $("#modal-edit-exactRule").modal("hide");
|
|
|
+ }
|
|
|
+ // 精准筛选规则-编辑页面 +新增按钮
|
|
|
+ function editExactRule(){
|
|
|
+ ruleHtmlFunc("edit-class","","#editexactRule")
|
|
|
+ if ($('.edit-class').length > 3){
|
|
|
+ $("#editExactRuleButton").hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断是否设置匹配方式
|
|
|
+ function hasMatchWay() {
|
|
|
+ for (let i = 0; i < o_rules.length; i++) {
|
|
|
+ if (o_rules[i]["s_keymatch"]!=""&&o_rules[i]["s_keymatch"]!=undefined){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
</script>
|