Kaynağa Gözat

fixed 商品化专利

zero 1 yıl önce
ebeveyn
işleme
dfda8b97ed

+ 4 - 4
src/main/java/cn/cslg/pas/common/config/WebSocketConfig.java

@@ -6,8 +6,8 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
 
 @Configuration
 public class WebSocketConfig {
-    @Bean
-    public ServerEndpointExporter serverEndpointExporter() {
-        return new ServerEndpointExporter();
-    }
+//    @Bean
+//    public ServerEndpointExporter serverEndpointExporter() {
+//        return new ServerEndpointExporter();
+//    }
 }

+ 2 - 0
src/main/java/cn/cslg/pas/common/model/request/QueryRequest.java

@@ -24,4 +24,6 @@ public class QueryRequest {
     private Integer productId;
     //商品化专利标识
     private String from;
+    //专利详情中商品化专用ids
+    private List<Integer> productIds;
 }

+ 2 - 12
src/main/java/cn/cslg/pas/common/vo/business/SelectProductVO.java

@@ -1,5 +1,6 @@
 package cn.cslg.pas.common.vo.business;
 
+import cn.cslg.pas.common.model.request.StringRequest;
 import lombok.Data;
 
 @Data
@@ -7,16 +8,5 @@ public class SelectProductVO {
 
     private String patentNo;
 
-    private String name;
-
-    private String companyName;
-
-    private String categoryName;
-    //0不分组 1类别 2公司
-    private Integer type;
-
-    //页码
-    private Long pageNum;
-    //页的大小
-    private Long pageSize;
+    private StringRequest queryRequest;
 }

+ 2 - 2
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -305,8 +305,8 @@ public class PatentController {
     @Operation(summary = "根据专利号查询商品化专利")
     @PostMapping("/selectProductByPatentNo")
     public Response selectProductByPatentNo(@RequestBody SelectProductVO vo) throws Exception {
-        SelectProductMapDTO mapDTO = patentService.selectProductByPatentNo(vo);
-        return Response.success(mapDTO);
+        Records records = (Records) patentService.selectProductByPatentNo(vo);
+        return Response.success(records);
     }
 
     @Operation(summary = "添加商品化专利")

+ 78 - 33
src/main/java/cn/cslg/pas/service/business/ProductService.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.model.request.GroupRequest;
 import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.LoginUtils;
+import cn.cslg.pas.common.utils.StringUtils;
 import cn.cslg.pas.common.vo.business.PersonVO;
 import cn.cslg.pas.common.vo.business.ProductVO;
 import cn.cslg.pas.domain.business.*;
@@ -17,6 +18,7 @@ import cn.cslg.pas.mapper.ProductMapper;
 import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.permissions.PermissionService;
 import cn.cslg.pas.service.query.FormatQueryService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -26,6 +28,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -35,6 +38,7 @@ import java.util.stream.Collectors;
 
 /**
  * 产品的Service层
+ *
  * @Author xiexiang
  * @Date 2023/10/26
  */
@@ -69,8 +73,29 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Object queryMessage(QueryRequest queryRequest) throws Exception {
-        List<String> sqls = formatQueryService.reSqls(queryRequest,"product");
-       sqls= this.loadSearchSql(sqls);
+        List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
+        sqls = this.loadSearchSql(sqls);
+        //根据sql查询产品信息
+        List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
+        //查询总数
+        Long total = productMapper.getProductCount(sqls.get(0));
+        //装载产品信息
+        this.loadProduct(productVOS);
+        //装载返回信息
+        Records records = new Records();
+        records.setCurrent(queryRequest.getCurrent());
+        records.setSize(queryRequest.getSize());
+        records.setData(productVOS);
+        records.setTotal(total);
+        return records;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public Object selectProduct(QueryRequest queryRequest) throws Exception {
+        List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
+        sqls = this.loadSearchSql(sqls);
+        sqls = this.loadProductIdsSql(sqls, queryRequest.getProductIds());
+
         //根据sql查询产品信息
         List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
         //查询总数
@@ -88,6 +113,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 新增产品
+     *
      * @param object
      * @param files
      * @return
@@ -140,10 +166,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         }
         //判断可见类型:
         Integer showType = productDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = productDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds != null && showPersonIds.size() != 0){
+            if (showPersonIds != null && showPersonIds.size() != 0) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductPerson assoProductPerson = new AssoProductPerson();
                     assoProductPerson.setProductId(product.getId());
@@ -161,11 +187,11 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
                 }
             }
         }
-        if(assoProductPeople != null && assoProductPeople.size() != 0){
+        if (assoProductPeople != null && assoProductPeople.size() != 0) {
             assoProductPersonService.saveBatch(assoProductPeople);
         }
         //判断文件是否为空
-        if(files != null && files.size() != 0) {
+        if (files != null && files.size() != 0) {
             try {
                 //调用上传文件接口
                 List<String> guids = fileManagerService.uploadFileGetGuid(files);
@@ -190,6 +216,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 删除产品
+     *
      * @param ids
      * @return
      */
@@ -218,6 +245,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 更新产品
+     *
      * @param object
      * @param files
      * @return
@@ -226,7 +254,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     public Object updateMessage(Object object, List<MultipartFile> files) {
         //object to updateProductDTO
         UpdateProductDTO updateProductDTO = (UpdateProductDTO) object;
-        if(updateProductDTO == null || updateProductDTO.getId() == null){
+        if (updateProductDTO == null || updateProductDTO.getId() == null) {
             throw new XiaoShiException("参数错误");
         }
         //获取登陆人信息 用于设置创建人
@@ -244,7 +272,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(Product::getName, name);
         List<Product> products = this.list(queryWrapper);
-        if(!updateProductDTO.getName().equals(product.getName()) && products.size() != 0){
+        if (!updateProductDTO.getName().equals(product.getName()) && products.size() != 0) {
             throw new XiaoShiException("名称重复");
         }
         BeanUtils.copyProperties(updateProductDTO, product);
@@ -279,10 +307,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         }
         //判断可见类型:
         Integer showType = updateProductDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = updateProductDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds != null && showPersonIds.size() != 0){
+            if (showPersonIds != null && showPersonIds.size() != 0) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductPerson assoProductPerson = new AssoProductPerson();
                     assoProductPerson.setProductId(product.getId());
@@ -300,7 +328,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
                 }
             }
         }
-        if(assoProductPeople != null && assoProductPeople.size() != 0){
+        if (assoProductPeople != null && assoProductPeople.size() != 0) {
             assoProductPersonService.saveBatch(assoProductPeople);
         }
         /**
@@ -313,20 +341,20 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
         //获取更新后的附件ids
         List<String> updateFileGuIds = new ArrayList<>();
-        if(updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0){
+        if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
             updateFileGuIds = updateProductDTO.getGuids();
             fileGuIds.retainAll(updateFileGuIds);
         }
         //做差获得被删除的文件id
-        if(fileGuIds.size() != 0){
+        if (fileGuIds.size() != 0) {
             //根据文件id删除产品与文件关联表记录
             LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
             deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);
             assoProductFileService.remove(deleteWrapper);
             //远程删除服务器上的文件
-            try{
+            try {
                 fileManagerService.deleteFileFromFMS(fileGuIds);
-            } catch (Exception e){
+            } catch (Exception e) {
 
             }
         }
@@ -353,7 +381,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     }
 
     @Override
-    public GroupVO getGroup(GroupRequest groupRequest,String tableName) throws Exception {
+    public GroupVO getGroup(GroupRequest groupRequest, String tableName) throws Exception {
         return null;
     }
 
@@ -369,6 +397,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 装载productVO
+     *
      * @param productVOS
      * @throws IOException
      */
@@ -377,7 +406,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         List<Integer> ids = new ArrayList<>();
         productVOS.forEach(
                 item -> {
-                    if(item.getCreateId() != null){
+                    if (item.getCreateId() != null) {
                         createIds.add(item.getCreateId());
                     }
                     if (item.getId() != null) {
@@ -409,8 +438,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         if (guids.size() != 0) {
             String res = fileManagerService.getSystemFileFromFMS(guids);
             systemFiles = JSONObject.parseArray(res, SystemFile.class);
-            if(systemFiles==null){
-                systemFiles=new ArrayList<>();
+            if (systemFiles == null) {
+                systemFiles = new ArrayList<>();
             }
         }
 
@@ -418,7 +447,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         for (ProductVO productVO : productVOS) {
             //装载人员信息
             Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productVO.getCreateId())).findFirst().orElse(null);
-            if(personnel != null){
+            if (personnel != null) {
                 productVO.setCreateName(personnel.getPersonnelName());
             } else {
                 throw new XiaoShiException("未获取到当前登陆人信息");
@@ -497,23 +526,39 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     //装载查询语句
     //装载查询语句
-    private List<String> loadSearchSql(List<String> sqls){
-        PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
-        String id =personnelVO.getId();
-        Integer tenantId =personnelVO.getTenantId();
-        String rootSql ="product.create_id="+id+" or(product.show_type =0 and product.tenant_id ="+tenantId+") or ( product.id in (select product_id from asso_product_person where" +
-                " person_id="+id+" and role=0)) or (product.show_type=2 and  product.id in (select product_id from asso_product_person where" +
-                " person_id="+id+" and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
-                " person_id="+id+" and role=2))";
-        if(sqls.get(0)!=null&&!sqls.get(0).equals(""))
-        {
-            sqls.set(0,"("+rootSql+") and"+"("+sqls.get(0)+")");
+    private List<String> loadSearchSql(List<String> sqls) {
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        String id = personnelVO.getId();
+        Integer tenantId = personnelVO.getTenantId();
+        String rootSql = "product.create_id=" + id + " or(product.show_type =0 and product.tenant_id =" + tenantId + ") or ( product.id in (select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=0)) or (product.show_type=2 and  product.id in (select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=2))";
+        if (sqls.get(0) != null && !sqls.get(0).equals("")) {
+            sqls.set(0, "(" + rootSql + ")" + " and " + "(" + sqls.get(0) + ")");
 
+        } else {
+            sqls.set(0, rootSql);
         }
-        else {
-            sqls.set(0,rootSql);
+
+        return sqls;
+
+    }
+
+    //装载查询产品语句
+    private List<String> loadProductIdsSql(List<String> sqls, List<Integer> ids) {
+        String rootSql = "";
+        if (CollectionUtils.isEmpty(ids)) {
+            rootSql = "product.id in " + "(" + 0 + ")";
+        } else {
+            rootSql = "product.id in " + "(" + String.join(",", ids.stream().map(Object::toString).collect(Collectors.toList())) + ")";
         }
 
+        if (sqls.get(0) != null && !sqls.get(0).equals("")) {
+            sqls.set(0, "(" + rootSql + ")" + " and " + "(" + sqls.get(0) + ")");
+        } else {
+            sqls.set(0, rootSql);
+        }
         return sqls;
 
     }

+ 15 - 60
src/main/java/cn/cslg/pas/service/business/es/EsPatentService.java

@@ -29,6 +29,7 @@ import cn.cslg.pas.domain.es.*;
 import cn.cslg.pas.mapper.ProductCategoryMapper;
 import cn.cslg.pas.mapper.ProductMapper;
 import cn.cslg.pas.service.business.CommonService;
+import cn.cslg.pas.service.business.ProductService;
 import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.permissions.PermissionService;
 import cn.cslg.pas.service.query.FormatQueryService;
@@ -79,6 +80,9 @@ public class EsPatentService {
     @Autowired
     private ProductCategoryMapper productCategoryMapper;
 
+    @Autowired
+    private ProductService productService;
+
     /**
      * 根据专利号查询专利详情
      *
@@ -321,12 +325,12 @@ public class EsPatentService {
      * @return
      * @throws IOException
      */
-    public SelectProductMapDTO selectProductByPatentNo(SelectProductVO vo) throws IOException {
+    public Object selectProductByPatentNo(SelectProductVO vo) throws Exception {
         String patentNo = vo.getPatentNo();
-        Long pageNum = vo.getPageNum();
-        Long pageSize = vo.getPageSize();
-        Integer type = vo.getType();
-        List<SelectProductDTO> list = new ArrayList<>();
+        QueryRequest queryRequest = new QueryRequest();
+        if (ObjectUtils.isNotEmpty(vo.getQueryRequest())) {
+            queryRequest = vo.getQueryRequest();
+        }
         List<Integer> productIds = new ArrayList<>();
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
@@ -338,7 +342,10 @@ public class EsPatentService {
         //授权号
         Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
         Query bool = QueryBuilders.bool(i -> i.should(q1, q2, q3));
-        builder.query(bool);
+        Query q = QueryBuilders.exists(i -> i.field("product_id"));
+        Query query = QueryBuilders.hasParent(parent -> parent.parentType("patent").query(bool));
+        Query bool1 = QueryBuilders.bool(i -> i.must(q,query));
+        builder.query(bool1);
 
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<Hit<Patent>> hits = response.hits().hits();
@@ -349,60 +356,8 @@ public class EsPatentService {
             }
         }
 
-        List<Product> products = productMapper.selectBatchIds(productIds);
-        if (!CollectionUtils.isEmpty(products)) {
-            for (Product product : products) {
-                ProductCategory category = new ProductCategory();
-                if (product.getCategoryId() != null) {
-                     category = productCategoryMapper.selectById(product.getCategoryId());
-                }
-                SelectProductDTO dto = new SelectProductDTO();
-                BeanUtils.copyProperties(product, dto);
-                //获取产品类别名称
-                dto.setCategoryName(category.getName());
-                list.add(dto);
-            }
-        }
-
-        List<Personnel> personnels = new ArrayList<>();
-        List<String> createIds = list.stream().map(SelectProductDTO::getCreateId).collect(Collectors.toList());
-        if (!CollectionUtils.isEmpty(createIds)) {
-            String res = permissionService.getPersonnelByIdsFromPCS(createIds);
-            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(res);
-            personnels = com.alibaba.fastjson.JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
-        }
-
-        for (SelectProductDTO dto : list) {
-            //装载创建人人员信息
-            Personnel personnel = personnels.stream().filter(item -> item.getId().equals(dto.getCreateId())).findFirst().orElse(null);
-            if (personnel != null) {
-                dto.setCreateName(personnel.getPersonnelName());
-            }
-        }
-
-        List<SelectProductDTO> sortList = list.stream().sorted(Comparator.comparing(SelectProductDTO::getMarketTime).reversed()).collect(Collectors.toList());
-        List<SelectProductDTO> filterList = sortList.stream().filter(i -> StringUtils.isNotEmpty(vo.getName()) && i.getName().equals(vo.getName()))
-                .filter(i -> StringUtils.isNotEmpty(vo.getCategoryName()) && i.getCategoryName().equals(vo.getCategoryName()))
-                .filter(i -> StringUtils.isNotEmpty(vo.getCompanyName()) && i.getCompanyName().equals(vo.getCompanyName()))
-                .collect(Collectors.toList());
-        SelectProductMapDTO mapDTO = new SelectProductMapDTO();
-        if (type == 0) {
-            Map<String, List<SelectProductDTO>> map = new HashMap<>();
-            List<SelectProductDTO> returnData = filterList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
-            map.put("无分组", returnData);
-            mapDTO.setProductMap(map);
-            mapDTO.setTotal(Long.valueOf(String.valueOf(filterList.size())));
-        } else if (type == 1) {
-            Map<String, List<SelectProductDTO>> collect = filterList.stream().collect(Collectors.groupingBy(SelectProductDTO::getCategoryName));
-            mapDTO.setProductMap(collect);
-            mapDTO.setTotal(Long.valueOf(String.valueOf(collect.keySet().size())));
-        } else if (type == 2) {
-            Map<String, List<SelectProductDTO>> collect = filterList.stream().collect(Collectors.groupingBy(SelectProductDTO::getCompanyName));
-            mapDTO.setProductMap(collect);
-            mapDTO.setTotal(Long.valueOf(String.valueOf(collect.keySet().size())));
-        }
-
-        return mapDTO;
+        queryRequest.setProductIds(productIds.stream().distinct().collect(Collectors.toList()));
+        return productService.selectProduct(queryRequest);
     }
 
     /**

+ 5 - 0
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -38,6 +38,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -470,6 +471,10 @@ public class EventServiceTests {
         calendar.add(Calendar.DAY_OF_MONTH, 1);
         Date date1 = calendar.getTime();
         System.out.println(date1);
+
+        List<Integer> list = Arrays.asList(1, 2, 3);
+        String result = String.join(",", String.join(",", list.stream().map(Object::toString).collect(Collectors.toList())));
+        System.out.println(result); // 输出: 1,2,3
     }
 
 }