Browse Source

自定义查询更新参数取值;事项绑定关系逻辑更新;

xubin.jiang 11 months ago
parent
commit
a48e33d4b2
3 changed files with 89 additions and 71 deletions
  1. 84 66
      src/controller/matter_relation.js
  2. 4 4
      src/controller/search/commonQuery.js
  3. 1 1
      src/handle/repeat.js

+ 84 - 66
src/controller/matter_relation.js

@@ -17,68 +17,49 @@ module.exports = class extends Base {
     let relation = await this.model('dictionary').where({'dictID':'SGX','flag':1}).select();
     for (let ml of param.matterList){
       for (let r of relation){
-        if (ml.relationID.toString() === r.dictValue){
+        if (ml.relationID.toString() === r.dictValue && (relation.description !== "互不相关")){// 互不相关不绑定
           ml['relation'] = r.description;
           break;
         }
       }
     }
-    if (think.isEmpty(relation) || relation.description === "互不相关"){
-      return this.fail("所选事项关系不存在或事项互不相关,不需要绑定")
-    } else {
-      let relationList = await this.model('matter_relation').where({'matter_a':param.matter, 'matter_b':param.matter, _logic: 'or'}).select();
-      if (think.isEmpty(relationList)){
-        // matter_a 没有绑定关系
-        let addData = [];
-        param.matterList.forEach(function(item) {
-          addData.push({
-            'matter_a':param.matter,
-            'matter_b':item.matterID,
-            'relationID':item.relationID,
-            'relation':item.relation,
-            'createUserID':param.userId,
-            'createUserName':userInfo.name,
-            'createOrgID':userInfo.orgID,
-            'createOrgName':userInfo.orgName
-          });
-          // 更新重复访事项关系表
-          if (item.relationID === '102'){
-            repeat.upRepeat(param.matter,item.matterID);
-          }
+    let relationList = await this.model('matter_relation').where({'matter_a':param.matter, 'matter_b':param.matter, _logic: 'or'}).select();
+    if (think.isEmpty(relationList)){
+      // matter_a 没有绑定关系
+      let addData = [];
+      param.matterList.forEach(async function(item) {
+        addData.push({
+          'matter_a': param.matter,
+          'matter_b': item.matterID,
+          'relationID': item.relationID,
+          'relation': item.relation,
+          'createUserID': param.userId,
+          'createUserName': userInfo.name,
+          'createOrgID': userInfo.orgID,
+          'createOrgName': userInfo.orgName
         });
-        if (addData.length > 0 ) {
-          await this.model('matter_relation').addMany(addData);
-          return this.success()
-        }else {
-          return this.fail()
+        // 更新重复访事项关系表
+        if (item.relationID === '102') {
+          await repeat.upRepeat(param.matter, item.matterID);
         }
-      } else {
-        let upData = [];
-        let newData = [];
-        for (let mb of param.matterList){
-          let states = 0 ;
-          for (let list of relationList){
-            if (list.matter_a === mb.matterID || list.matter_b === mb.matterID) {
-              // 匹配到记录,修改关系
-              states = 1;
-              upData.push({
-                'id':list.id,
-                'matter_a':param.matter,
-                'matter_b':mb.matterID,
-                'relationID':mb.relationID,
-                'relation':mb.relation,
-                'createUserID':param.userId,
-                'createUserName':userInfo.name,
-                'createOrgID':userInfo.orgID,
-                'createOrgName':userInfo.orgName,
-                'time':moment().format("YYYY-MM-DD HH:mm:ss"),
-              });
-              break;
-            }
-          }
-          if (states === 0){
-            // 没有匹配到任何记录
-            newData.push({
+      });
+      if (addData.length > 0 ) {
+        await this.model('matter_relation').addMany(addData);
+        return this.success()
+      }else {
+        return this.fail()
+      }
+    } else {
+      let upData = [];
+      let newData = [];
+      for (let mb of param.matterList){
+        let states = 0 ;
+        for (let list of relationList){
+          if (list.matter_a === mb.matterID || list.matter_b === mb.matterID) {
+            // 匹配到记录,修改关系
+            states = 1;
+            upData.push({
+              'id':list.id,
               'matter_a':param.matter,
               'matter_b':mb.matterID,
               'relationID':mb.relationID,
@@ -86,18 +67,33 @@ module.exports = class extends Base {
               'createUserID':param.userId,
               'createUserName':userInfo.name,
               'createOrgID':userInfo.orgID,
-              'createOrgName':userInfo.orgName
-            })
+              'createOrgName':userInfo.orgName,
+              'time':moment().format("YYYY-MM-DD HH:mm:ss"),
+            });
+            break;
           }
         }
-        if (newData.length > 0 ) {
-          await this.model('matter_relation').addMany(newData);
-        }
-        if (upData.length > 0 ) {
-          await this.model('matter_relation').updateMany(upData);
+        if (states === 0){
+          // 没有匹配到任何记录
+          newData.push({
+            'matter_a':param.matter,
+            'matter_b':mb.matterID,
+            'relationID':mb.relationID,
+            'relation':mb.relation,
+            'createUserID':param.userId,
+            'createUserName':userInfo.name,
+            'createOrgID':userInfo.orgID,
+            'createOrgName':userInfo.orgName
+          })
         }
-        return this.success();
       }
+      if (newData.length > 0 ) {
+        await this.model('matter_relation').addMany(newData);
+      }
+      if (upData.length > 0 ) {
+        await this.model('matter_relation').updateMany(upData);
+      }
+      return this.success();
     }
   }
 
@@ -295,6 +291,9 @@ module.exports = class extends Base {
     let matter = await this.model('activity').alias('a').join('person_activity as pa on a.id = pa.activityID')
       .join('person as p on p.id = pa.personID').join('matter as m on m.activityID = a.id').where(where).field('m.*').distinct('m.*').select();
     let mList = [];
+    console.log(1111)
+    console.log(matter)
+    console.log(2222)
     for (let item of matter) {
       let mr = await this.model('matter_relation').where({
           'relationID':'102',
@@ -348,8 +347,27 @@ module.exports = class extends Base {
   }
   async testAction(){
     const param = this.post();
-    let back = await this.model('matter_relation').where({'matter_a':param.matter, 'matter_b':param.matter, _logic: 'or'})
-      .group('relationID').field('relation,relationID,COUNT(*) as count').select();
-    return this.success(back)
+    // let back = await this.model('matter_relation').where({'matter_a':param.matter, 'matter_b':param.matter, _logic: 'or'})
+    //   .group('relationID').field('relation,relationID,COUNT(*) as count').select();
+    // return this.success(back)
+    let back = await this.model('matter_repeat').select();
+    let list = [1,2,3,4,5,6,7,8,9];
+    let e = [];
+    list.forEach( async function(item) {
+      e.push({
+        'matter_a': "param.matter",
+        'matter_b': "item.matterID",
+        'relationID': "item.relationID",
+        'relation': "item.relation",
+        'createUserID': "param.userId",
+        'createUserName': "userInfo.name",
+        'createOrgID': "userInfo.orgID",
+        'createOrgName': "userInfo.orgName"
+      })
+      // await think.model("matter_repeat").where({"id":item}).select()
+      await think.model("matter").select()
+    })
+    console.log(e.length)
+    return this.success(e)
   }
 };

+ 4 - 4
src/controller/search/commonQuery.js

@@ -793,15 +793,15 @@ module.exports = class extends Base {
         whereMatter['lfReasonID'] = ['IN',m.lfReasonID];
       }
       // 所属内容分类
-      if (m.hasOwnProperty('contentClassifyID') & m.contentClassifyID !=='') {//逐级查询,单选
+      if (m.hasOwnProperty('contentClassifyID') && m.contentClassifyID !=='' && m.contentClassifyID !== null) {//逐级查询,单选
         if (m.contentClassifyID.substr(0,3) === "003") {
           // 纪检监察类,只查主要问题
           whereMatter['_complex'] = {
-            "contentClassifyID":["LIKE",data.contentClassifyID + '%'],
-            "ContentClassifyID":["LIKE","%,"+ data.contentClassifyID + '%'],
+            "contentClassifyID":["LIKE",m.contentClassifyID + '%'],
+            "ContentClassifyID":["LIKE","%,"+ m.contentClassifyID + '%'],
           }
         }else {
-          whereMatter['contentClassifyID'] = ['LIKE',data.contentClassifyID + '%']
+          whereMatter['contentClassifyID'] = ['LIKE',m.contentClassifyID + '%']
         }
       }
       // 信访问题所属系统

+ 1 - 1
src/handle/repeat.js

@@ -16,7 +16,7 @@ async function upRepeat(a,b){ // aԴͷmatterID
       'matter_list': a + ',' + b,
       'content': matter.abstract,
       'count':2,
-      // 'person_name':matter.activity.person.name
+      'person_name':matter.activity.person.name
     };
     await think.model('matter_repeat').add(data);
     return true