|
|
@@ -0,0 +1,141 @@
|
|
|
+package com.izouma.uwip.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.izouma.uwip.domain.Handle;
|
|
|
+import com.izouma.uwip.domain.InternationalPatent;
|
|
|
+import com.izouma.uwip.domain.Patent;
|
|
|
+import com.izouma.uwip.dto.InternationalPatentDTO;
|
|
|
+import com.izouma.uwip.dto.PageQuery;
|
|
|
+import com.izouma.uwip.enums.*;
|
|
|
+import com.izouma.uwip.exception.BusinessException;
|
|
|
+import com.izouma.uwip.repo.InternationalPatentRepo;
|
|
|
+import com.izouma.uwip.repo.PatentRepo;
|
|
|
+import com.izouma.uwip.utils.JpaUtils;
|
|
|
+import com.izouma.uwip.utils.ObjUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Path;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class InternationalPatentService {
|
|
|
+
|
|
|
+ private final InternationalPatentRepo internationalPatentRepo;
|
|
|
+ private final PatentRepo patentRepo;
|
|
|
+ private final AttachmentService attachmentService;
|
|
|
+ private final PartnerService partnerService;
|
|
|
+
|
|
|
+ public Page<InternationalPatent> all(PageQuery pageQuery) {
|
|
|
+ return internationalPatentRepo.findAll(JpaUtils.toSpecification(pageQuery, InternationalPatent.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ public InternationalPatent saveDTO(InternationalPatentDTO record, Long userId) {
|
|
|
+ if (record.getIid() != null) {
|
|
|
+ InternationalPatent orig = internationalPatentRepo.findById(record.getIid())
|
|
|
+ .orElseThrow(new BusinessException("无记录"));
|
|
|
+ InternationalPatent iPatent = new InternationalPatent(record);
|
|
|
+ ObjUtils.merge(orig, iPatent);
|
|
|
+ orig = internationalPatentRepo.save(orig);
|
|
|
+
|
|
|
+ Patent orig1 = patentRepo.findById(record.getPatentId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ Patent patent = new Patent();
|
|
|
+ BeanUtil.copyProperties(record, patent);
|
|
|
+ ObjUtils.mergePatent(orig1, patent);
|
|
|
+ List<Handle> handleList = orig1.getHandle();
|
|
|
+ if (handleList == null) {
|
|
|
+ handleList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ handleList.add(Handle.builder()
|
|
|
+ .workflow(record.getWorkflow().toString())
|
|
|
+ .userId(userId)
|
|
|
+ .checkAt(LocalDateTime.now())
|
|
|
+ .build());
|
|
|
+ orig1.setHandle(handleList);
|
|
|
+ if (ObjectUtil.isNull(record.getApplyStatus()) || !ApplyStatus.COMPLETED.equals(record.getApplyStatus())) {
|
|
|
+ orig1.setApplyStatus(this.getApplyStatus(record.getWorkflow()));
|
|
|
+ }
|
|
|
+ patentRepo.save(orig1);
|
|
|
+
|
|
|
+ // 保存附件
|
|
|
+ if (CollectionUtils.isNotEmpty(record.getAttachments())) {
|
|
|
+ attachmentService.batchSave(record.getAttachments(), userId, record.getIid());
|
|
|
+ }
|
|
|
+ return orig;
|
|
|
+ }
|
|
|
+
|
|
|
+ Patent patent = new Patent();
|
|
|
+ BeanUtil.copyProperties(record, patent);
|
|
|
+ patent.setSort(patentRepo.findMax());
|
|
|
+
|
|
|
+ //寰球案号
|
|
|
+ PatentType type = patent.getType();
|
|
|
+ patent.setUwNo(partnerService.getUwNo(patent.getClientPartnerId(), CaseType.valueOf(type.name()), CaseStage.PCT, patent
|
|
|
+ .getSort()));
|
|
|
+ patent.setApplyStatus(ApplyStatus.APPLY_STAGE);
|
|
|
+ patent = patentRepo.save(patent);
|
|
|
+
|
|
|
+ InternationalPatent iPatent = new InternationalPatent(record);
|
|
|
+ iPatent.setPatentId(patent.getId());
|
|
|
+ iPatent = internationalPatentRepo.save(iPatent);
|
|
|
+
|
|
|
+ // 保存附件
|
|
|
+ if (CollectionUtils.isNotEmpty(record.getAttachments())) {
|
|
|
+ attachmentService.batchSave(record.getAttachments(), userId, record.getIid());
|
|
|
+ }
|
|
|
+ return iPatent;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyStatus getApplyStatus(InternationalWorkflow workflow) {
|
|
|
+ switch (workflow) {
|
|
|
+ case ADD_SUPPLIERS://待添加供应商
|
|
|
+ case SUPPLIER_MATERIALS://供应商反馈文件
|
|
|
+ case MAINTAIN_CASE://申请号/申请日
|
|
|
+ return ApplyStatus.APPLY_STAGE;//申请阶段
|
|
|
+ case OFFICIAL_CIRCULATION://待官文流转
|
|
|
+ case SUPPLEMENTARY_REPLY://待补正答复
|
|
|
+ case REPLY_SUBMISSION://待上传答复意见书
|
|
|
+ case CONFIRM_REPLY://待确认答复状态
|
|
|
+ return ApplyStatus.SUBSTANTIVE_STAGE;// 实审阶段
|
|
|
+ default://不答复终止
|
|
|
+ return ApplyStatus.COMPLETED;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<InternationalPatent> allDTO(PageQuery pageQuery) {
|
|
|
+ return internationalPatentRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ Path<Object> patent = root.get("patent");
|
|
|
+ if (StrUtil.isNotBlank(pageQuery.getSearch())) {
|
|
|
+ List<Predicate> or = new ArrayList<>();
|
|
|
+ or.add(criteriaBuilder.like(patent.get("name"), "%" + pageQuery.getSearch() + "%"));
|
|
|
+ or.add(criteriaBuilder.like(patent.get("uwNo"), "%" + pageQuery.getSearch() + "%"));
|
|
|
+ and.add(criteriaBuilder.or(or.toArray(new Predicate[0])));
|
|
|
+ }
|
|
|
+ Map<String, Object> query = pageQuery.getQuery();
|
|
|
+ query.keySet().forEach(key -> {
|
|
|
+ if (JpaUtils.isExistField(key, InternationalPatent.class)) {
|
|
|
+ Predicate predicate = JpaUtils.getPredicate(key, query.get(key), InternationalPatent.class, root, criteriaBuilder, false);
|
|
|
+ if (ObjectUtil.isNotNull(predicate)) {
|
|
|
+ and.add(predicate);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Predicate predicate = JpaUtils.getPredicate(key, query.get(key), Patent.class, root, criteriaBuilder, true);
|
|
|
+ if (ObjectUtil.isNotNull(predicate)) {
|
|
|
+ and.add(predicate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }
|
|
|
+}
|