|
@@ -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)
|
|
|
}
|
|
|
};
|