|
@@ -41,6 +41,7 @@ import co.elastic.clients.elasticsearch.core.*;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.TrackHits;
|
|
import co.elastic.clients.elasticsearch.core.search.TrackHits;
|
|
import co.elastic.clients.json.JsonData;
|
|
import co.elastic.clients.json.JsonData;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -228,11 +229,11 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
if (type == 0) {
|
|
if (type == 0) {
|
|
if (!CollectionUtils.isEmpty(patent.getMergeApplicant())) {
|
|
if (!CollectionUtils.isEmpty(patent.getMergeApplicant())) {
|
|
List<PatentMergePerson> mergeApplicant = patent.getMergeApplicant();
|
|
List<PatentMergePerson> mergeApplicant = patent.getMergeApplicant();
|
|
- for (PatentMergePerson mergePerson : mergeApplicant) {
|
|
|
|
- if (mergedName.contains(mergePerson.getName().toLowerCase(Locale.ROOT))) {
|
|
|
|
- mergePerson.setName(name);
|
|
|
|
- mergePerson.setIfMerged(true);
|
|
|
|
- mergePerson.setMergedNum(num);
|
|
|
|
|
|
+ for (PatentMergePerson applicant : mergeApplicant) {
|
|
|
|
+ if (mergedName.contains(applicant.getName().toLowerCase(Locale.ROOT))) {
|
|
|
|
+ applicant.setName(name);
|
|
|
|
+ applicant.setIfMerged(true);
|
|
|
|
+ applicant.setMergedNum(num);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
List<PatentMergePerson> applicantList = new ArrayList<>();
|
|
List<PatentMergePerson> applicantList = new ArrayList<>();
|
|
@@ -541,7 +542,6 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
|
|
|
|
List<String> mergeList = new ArrayList<>();
|
|
List<String> mergeList = new ArrayList<>();
|
|
if (StringUtils.isNotEmpty(condition)) {
|
|
if (StringUtils.isNotEmpty(condition)) {
|
|
-// total = this.loadConditionMergeList(totalAgg,mergeList,condition,operate,total,pageNum.intValue(),pageSize.intValue());
|
|
|
|
Aggregate terms = totalAgg.nested().aggregations().get("terms");
|
|
Aggregate terms = totalAgg.nested().aggregations().get("terms");
|
|
List<StringTermsBucket> termsBucketList = terms.sterms().buckets().array();
|
|
List<StringTermsBucket> termsBucketList = terms.sterms().buckets().array();
|
|
if (condition.contains("AND") && operate.equals("AND")) {
|
|
if (condition.contains("AND") && operate.equals("AND")) {
|
|
@@ -604,6 +604,7 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
GetAllPersonDTO dto = new GetAllPersonDTO();
|
|
GetAllPersonDTO dto = new GetAllPersonDTO();
|
|
dto.setName(name);
|
|
dto.setName(name);
|
|
dto.setMergeId(person.getId());
|
|
dto.setMergeId(person.getId());
|
|
|
|
+ dto.setProjectId(person.getProjectId());
|
|
dto.setType(person.getType());
|
|
dto.setType(person.getType());
|
|
dto.setRemark(person.getRemark());
|
|
dto.setRemark(person.getRemark());
|
|
dto.setAbbreviation(person.getAbbreviation());
|
|
dto.setAbbreviation(person.getAbbreviation());
|
|
@@ -1486,4 +1487,248 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //--------------------------------------------------------------------------
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public Integer commonMerge(MergePersonCommonVO commonVO) throws Exception {
|
|
|
|
+ Integer mergeId = null;
|
|
|
|
+ if (commonVO.getId() != null) {
|
|
|
|
+ MergePerson person = mergePersonMapper.selectById(commonVO.getId());
|
|
|
|
+ List<String> names = JSON.parseArray(person.getMergedName(), String.class);
|
|
|
|
+ String delDiffName = "";
|
|
|
|
+ if (!commonVO.getName().equals(person.getName())) {
|
|
|
|
+ names.add(person.getName());
|
|
|
|
+ delDiffName = person.getName();
|
|
|
|
+ }
|
|
|
|
+ load(commonVO, names, person,delDiffName);
|
|
|
|
+ } else {
|
|
|
|
+ load(commonVO, new ArrayList<>(), null, null);
|
|
|
|
+ }
|
|
|
|
+ return mergeId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Integer merge(MergePersonCommonVO commonVO, List<String> list, String delDiffName) throws Exception {
|
|
|
|
+ Integer projectId = commonVO.getProjectId();
|
|
|
|
+ Integer type = commonVO.getType();
|
|
|
|
+ String name = commonVO.getName();
|
|
|
|
+ //保存合并记录
|
|
|
|
+ Integer mergeId = saveMerge(commonVO, list,delDiffName);
|
|
|
|
+ //查询合并后的数据
|
|
|
|
+ if (StringUtils.isNotEmpty(delDiffName)) {
|
|
|
|
+ list.add(delDiffName);
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = searchChildDoc(list, type, projectId);
|
|
|
|
+ //更新合并后的数据
|
|
|
|
+ final int num = CollectionUtils.isEmpty(hits) ? 1 : hits.size();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String id = hit.id();
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ createPatent(patent, type, list, name, num);
|
|
|
|
+ Integer count = updateChild(patent, id, hit.routing());
|
|
|
|
+ if (count < 0) {
|
|
|
|
+ throw new XiaoShiException("合并失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return mergeId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Integer load(MergePersonCommonVO commonVO, List<String> names, MergePerson person,String delDiffName) throws Exception {
|
|
|
|
+ Integer mergeId = null;
|
|
|
|
+ Integer projectId = commonVO.getProjectId();
|
|
|
|
+ Integer type = commonVO.getType();
|
|
|
|
+ List<GetAllPersonDTO> mergePersonDTOS = commonVO.getMergePersonDTOS();
|
|
|
|
+ List<GetAllPersonDTO> delMergePersonDTOS = commonVO.getDelMergePersonDTOS();
|
|
|
|
+ if (!CollectionUtils.isEmpty(mergePersonDTOS)) {
|
|
|
|
+ List<Integer> mergeIds = mergePersonDTOS.stream().map(GetAllPersonDTO::getMergeId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
+ if (!CollectionUtils.isEmpty(mergeIds)) {
|
|
|
|
+ List<MergePerson> personList = mergePersonMapper.selectBatchIds(mergeIds);
|
|
|
|
+ for (MergePerson mergePerson : personList) {
|
|
|
|
+ List<String> getNames = JSON.parseArray(mergePerson.getMergedName(), String.class);
|
|
|
|
+ names.addAll(getNames);
|
|
|
|
+ String personName = mergePerson.getName();
|
|
|
|
+ loadNewChild(type, projectId, personName,false);
|
|
|
|
+ }
|
|
|
|
+ mergePersonMapper.deleteBatchIds(mergeIds);
|
|
|
|
+ }
|
|
|
|
+ List<String> mergeNameList = mergePersonDTOS.stream().filter(i -> i.getMergeId() == null).map(GetAllPersonDTO::getName).collect(Collectors.toList());
|
|
|
|
+ if (!CollectionUtils.isEmpty(mergeNameList)) {
|
|
|
|
+ names.addAll(mergeNameList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(delMergePersonDTOS)) {
|
|
|
|
+ List<String> delNames = delMergePersonDTOS.stream().map(GetAllPersonDTO::getName).collect(Collectors.toList());
|
|
|
|
+ names.removeAll(delNames);
|
|
|
|
+ loadNewChild(type, projectId, person.getName(),true);
|
|
|
|
+ }
|
|
|
|
+ if (commonVO.getId() != null) {
|
|
|
|
+ mergePersonMapper.deleteById(commonVO.getId());
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(names)) {
|
|
|
|
+ List<String> collect = names.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ if (!CollectionUtils.isEmpty(collect)) {
|
|
|
|
+ mergeId = merge(commonVO, collect,delDiffName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return mergeId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void loadNewChild(Integer type, Integer projectId, String personName,boolean flag) throws Exception {
|
|
|
|
+ List<Hit<Patent>> hits = searchChild(type, projectId, personName);
|
|
|
|
+ List<String> patentIds = new ArrayList<>();
|
|
|
|
+ List<PatentMergePerson> list = new ArrayList<>();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String routing = hit.routing();
|
|
|
|
+ patentIds.add(routing);
|
|
|
|
+ if (flag) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ if (type == 0) {
|
|
|
|
+ if (!CollectionUtils.isEmpty(patent.getMergeApplicant())) {
|
|
|
|
+ List<PatentMergePerson> applicant = patent.getMergeApplicant();
|
|
|
|
+ List<PatentMergePerson> collect = applicant.stream().filter(i -> i.getIfMerged().equals(Boolean.TRUE)).collect(Collectors.toList());
|
|
|
|
+ list.addAll(collect);
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(patent.getMergeRightHolder())) {
|
|
|
|
+ List<PatentMergePerson> rights = patent.getMergeRightHolder();
|
|
|
|
+ List<PatentMergePerson> collect = rights.stream().filter(i -> i.getIfMerged().equals(Boolean.TRUE)).collect(Collectors.toList());
|
|
|
|
+ list.addAll(collect);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (!CollectionUtils.isEmpty(patent.getMergeInventor())) {
|
|
|
|
+ List<PatentMergePerson> inventors = patent.getMergeInventor();
|
|
|
|
+ List<PatentMergePerson> collect = inventors.stream().filter(i -> i.getIfMerged().equals(Boolean.TRUE)).collect(Collectors.toList());
|
|
|
|
+ list.addAll(collect);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //删除原子文档
|
|
|
|
+ deleteChild(patentIds, type, projectId);
|
|
|
|
+ //查询父文档拿出对应type的数据后添加新的子文档
|
|
|
|
+ searchPatent(patentIds, type, projectId);
|
|
|
|
+ if (flag) {
|
|
|
|
+ List<String> collect = list.stream().map(PatentMergePerson::getName).distinct().filter(i -> !i.equals(personName)).collect(Collectors.toList());
|
|
|
|
+ if (!CollectionUtils.isEmpty(collect)) {
|
|
|
|
+ for (String key : collect) {
|
|
|
|
+ LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
|
|
|
|
+ .eq(MergePerson::getProjectId, projectId)
|
|
|
|
+ .eq(MergePerson::getName, key)
|
|
|
|
+ .eq(MergePerson::getType,type);
|
|
|
|
+ MergePerson mergePerson = mergePersonMapper.selectOne(wrapper);
|
|
|
|
+ String mergedName = mergePerson.getMergedName();
|
|
|
|
+ List<String> mergedNames = JSONArray.parseArray(mergedName, String.class);
|
|
|
|
+ againMerge(mergedNames,type,projectId,key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void againMerge(List<String> list, Integer type, Integer projectId, String name) throws Exception {
|
|
|
|
+ List<Hit<Patent>> hits = searchChildDoc(list, type, projectId);
|
|
|
|
+ //更新合并后的数据
|
|
|
|
+ final int num = CollectionUtils.isEmpty(hits) ? 1 : hits.size();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String id = hit.id();
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ createPatent(patent, type, list, name, num);
|
|
|
|
+ Integer count = updateChild(patent, id, hit.routing());
|
|
|
|
+ if (count < 0) {
|
|
|
|
+ throw new XiaoShiException("合并失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //新增合并记录
|
|
|
|
+ private Integer saveMerge(MergePersonCommonVO vo, List<String> mergeNames, String delDiffName) {
|
|
|
|
+ List<GetAllPersonDTO> mergePersonDTOS = vo.getMergePersonDTOS();
|
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(mergeNames)) {
|
|
|
|
+ names = mergeNames;
|
|
|
|
+ } else {
|
|
|
|
+ names = mergePersonDTOS.stream().map(GetAllPersonDTO::getName).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(delDiffName)) {
|
|
|
|
+ names.remove(delDiffName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取登陆人信息 用于设置创建人
|
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
|
+ //判断是否名称重复
|
|
|
|
+ LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
|
|
|
|
+ .eq(MergePerson::getProjectId, vo.getProjectId())
|
|
|
|
+ .eq(MergePerson::getType, vo.getType())
|
|
|
|
+ .eq(MergePerson::getName, vo.getName());
|
|
|
|
+ List<MergePerson> list = mergePersonMapper.selectList(wrapper);
|
|
|
|
+ if (!list.isEmpty()) {
|
|
|
|
+ throw new XiaoShiException("合并名称不可重复");
|
|
|
|
+ }
|
|
|
|
+ MergePerson person = new MergePerson();
|
|
|
|
+ BeanUtils.copyProperties(vo, person);
|
|
|
|
+ person.setMergedName(JSONArray.toJSONString(names));
|
|
|
|
+ person.setCreateId(personnelVO.getId());
|
|
|
|
+ person.setCreateTime(new Date());
|
|
|
|
+ person.insert();
|
|
|
|
+ return person.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询合并记录并更新合并记录
|
|
|
|
+ private MergePerson editMergePerson(MergePersonCommonVO vo) {
|
|
|
|
+ //获取登陆人信息 用于设置创建人
|
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
|
+ //判断是否名称重复
|
|
|
|
+ LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
|
|
|
|
+ .eq(MergePerson::getProjectId, vo.getProjectId())
|
|
|
|
+ .eq(MergePerson::getName, vo.getName())
|
|
|
|
+ .eq(MergePerson::getType,vo.getType())
|
|
|
|
+ .ne(BaseEntity::getId, vo.getId());
|
|
|
|
+ List<MergePerson> list = mergePersonMapper.selectList(wrapper);
|
|
|
|
+ if (!list.isEmpty()) {
|
|
|
|
+ throw new XiaoShiException("合并名称不可重复");
|
|
|
|
+ }
|
|
|
|
+ //获取专利合并记录
|
|
|
|
+ MergePerson person = mergePersonMapper.selectById(vo.getId());
|
|
|
|
+ BeanUtils.copyProperties(vo, person);
|
|
|
|
+ person.setCreateId(personnelVO.getId());
|
|
|
|
+ person.setCreateTime(new Date());
|
|
|
|
+ person.updateById();
|
|
|
|
+ return person;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Hit<Patent>> searchChildDoc(List<String> mergedNames,Integer type,Integer projectId) throws IOException {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ List<Query> queries = new ArrayList<>();
|
|
|
|
+ if (type == 0) {
|
|
|
|
+ for (String mergedName : mergedNames) {
|
|
|
|
+ //合并申请人
|
|
|
|
+ Query idQ1 = QueryBuilders.term(i -> i.field("merge_applicant.project_id").value(projectId));
|
|
|
|
+ Query q1 = QueryBuilders.term(i -> i.field("merge_applicant.name.raw").value(mergedName));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(idQ1, q1));
|
|
|
|
+ Query query1 = QueryBuilders.nested(i -> i.path("merge_applicant").query(bool));
|
|
|
|
+ //合并权利人
|
|
|
|
+ Query idQ2 = QueryBuilders.term(i -> i.field("merge_right_holder.project_id").value(projectId));
|
|
|
|
+ Query q2 = QueryBuilders.term(i -> i.field("merge_right_holder.name.raw").value(mergedName));
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.must(idQ2, q2));
|
|
|
|
+ Query query2 = QueryBuilders.nested(i -> i.path("merge_right_holder").query(bool1));
|
|
|
|
+ queries.add(query1);
|
|
|
|
+ queries.add(query2);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (String mergedName : mergedNames) {
|
|
|
|
+ Query idQ = QueryBuilders.term(i -> i.field("merge_inventor.project_id").value(projectId));
|
|
|
|
+ Query q = QueryBuilders.term(i -> i.field("merge_inventor.name.raw").value(mergedName));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(idQ, q));
|
|
|
|
+ Query query = QueryBuilders.nested(i -> i.path("merge_inventor").query(bool));
|
|
|
|
+ queries.add(query);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(queries));
|
|
|
|
+ builder.query(query);
|
|
|
|
+ builder.size(1000);
|
|
|
|
+ builder.trackTotalHits(TrackHits.of(i -> i.enabled(true)));
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ return response.hits().hits();
|
|
|
|
+ }
|
|
}
|
|
}
|