Browse Source

fixed record

zero 1 year ago
parent
commit
4dacc12cba

+ 10 - 0
src/main/java/com/example/xiaoshiweixinback/domain/SearchRecord.java

@@ -52,4 +52,14 @@ public class SearchRecord extends BaseEntity<SearchRecord> {
      */
     private String personUuid;
 
+    /**
+     * 图片guid
+     */
+    private String guid;
+
+    /**
+     * 图片描述
+     */
+    private String description;
+
 }

+ 4 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/searchRecord/AddSearchRecordDTO.java

@@ -18,4 +18,8 @@ public class AddSearchRecordDTO {
     private Date searchTime;
 
     private String personUuid;
+
+    private String guid;
+
+    private String description;
 }

+ 2 - 2
src/main/java/com/example/xiaoshiweixinback/entity/dto/searchRecord/SelectSearchRecordDTO.java

@@ -11,8 +11,8 @@ public class SelectSearchRecordDTO {
 
     private Date searchTime;
 
-    private Long pageNum;
+    private Long current;
 
-    private Long pageSize;
+    private Long size;
 
 }

+ 14 - 12
src/main/java/com/example/xiaoshiweixinback/service/AssoPersonCategoryService.java

@@ -13,6 +13,7 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -31,15 +32,14 @@ public class AssoPersonCategoryService extends ServiceImpl<AssoPersonCategoryMap
     public List<Integer> getChoosedProductCategoryIds() {
         List<Integer> ids = new ArrayList<>();
         try {
-           PersonnelVO personnelVO =cacheUtil.getLoginUser(LoginUtils.getToken());
-        LambdaQueryWrapper<AssoPersonCategory> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(AssoPersonCategory::getPersonUuid, personnelVO.getUuid());
-        List<AssoPersonCategory> assoPersonCategories = this.list(queryWrapper);
-        if (assoPersonCategories.size() > 0) {
-            ids = assoPersonCategories.stream().map(AssoPersonCategory::getProductCategoryId).collect(Collectors.toList());
-        }
-        }
-        catch (Exception e){
+            PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
+            LambdaQueryWrapper<AssoPersonCategory> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(AssoPersonCategory::getPersonUuid, personnelVO.getUuid());
+            List<AssoPersonCategory> assoPersonCategories = this.list(queryWrapper);
+            if (assoPersonCategories.size() > 0) {
+                ids = assoPersonCategories.stream().map(AssoPersonCategory::getProductCategoryId).collect(Collectors.toList());
+            }
+        } catch (Exception e) {
             return ids;
         }
         return ids;
@@ -48,9 +48,11 @@ public class AssoPersonCategoryService extends ServiceImpl<AssoPersonCategoryMap
 
     @Transactional(rollbackFor = Exception.class)
     public void concernCategory(ConcernCategoryDTO concernCategoryDTO) {
-        PersonnelVO personnelVO =cacheUtil.getLoginUser(LoginUtils.getToken());;
-        List<Integer> ids = concernCategoryDTO.getCategoryIds();
-
+        PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
+        List<Integer> ids = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(concernCategoryDTO.getCategoryIds())) {
+            ids = concernCategoryDTO.getCategoryIds();
+        }
         LambdaQueryWrapper<AssoPersonCategory> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(AssoPersonCategory::getPersonUuid, personnelVO.getUuid());
         List<AssoPersonCategory> assoPersonCategories = this.list(queryWrapper);

+ 9 - 4
src/main/java/com/example/xiaoshiweixinback/service/SearchRecordService.java

@@ -20,6 +20,8 @@ import com.example.xiaoshiweixinback.entity.vo.searchRecord.SelectSearchRecordVO
 import com.example.xiaoshiweixinback.mapper.SearchRecordMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
@@ -41,20 +43,23 @@ public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchR
 
     /**
      * 添加或更新检索记录
+     *
      * @param vo
      * @return
      */
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public Integer addSearchRecord(AddSearchRecordDTO vo) {
         if (ToolUtil.isEmpty(vo)) {
             throw new BusinessException(ExceptionEnum.THE_PARAMETER_EXCEPTION);
         }
         Integer id = vo.getId();
-        SearchRecord record = new SearchRecord();
-        BeanUtil.copy(vo, record);
         if (id != null) {
             SearchRecord searchRecord = searchRecordMapper.selectById(id);
+            BeanUtil.copy(vo, searchRecord);
             searchRecord.updateById();
         } else {
+            SearchRecord record = new SearchRecord();
+            BeanUtil.copy(vo, record);
             PersonnelVO personnelVO = cacheUtils.getLoginUser(LoginUtils.getToken());
             record.setPersonUuid(personnelVO.getUuid());
             record.insert();
@@ -69,8 +74,8 @@ public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchR
      * @return
      */
     public Records searchRecords(SelectSearchRecordDTO searchRecordDTO) {
-        Long pageNum = searchRecordDTO.getPageNum();
-        Long pageSize = searchRecordDTO.getPageSize();
+        Long pageNum = searchRecordDTO.getCurrent();
+        Long pageSize = searchRecordDTO.getSize();
         Integer productId = searchRecordDTO.getProductId();
         Page<SearchRecord> page = new Page<>(pageNum, pageSize);
         Page<SearchRecord> record = searchRecordMapper.selectPage(page, new LambdaQueryWrapper<SearchRecord>()

+ 20 - 1
src/main/java/com/example/xiaoshiweixinback/service/common/EsDenseVectorService.java

@@ -23,16 +23,20 @@ import com.example.xiaoshiweixinback.domain.Product;
 import com.example.xiaoshiweixinback.domain.es.PatentVector;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
+import com.example.xiaoshiweixinback.entity.dto.searchRecord.AddSearchRecordDTO;
 import com.example.xiaoshiweixinback.entity.product.ProductIdDTO;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
 import com.example.xiaoshiweixinback.mapper.ProductMapper;
+import com.example.xiaoshiweixinback.service.SearchRecordService;
 import com.example.xiaoshiweixinback.service.importPatent.FormatQueryService;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.io.File;
@@ -55,6 +59,9 @@ public class EsDenseVectorService {
     private GetVectorService getVectorService;
 
     @Autowired
+    private SearchRecordService searchRecordService;
+
+    @Autowired
     private ProductMapper productMapper;
 
     /**
@@ -64,6 +71,7 @@ public class EsDenseVectorService {
      * @return
      * @throws IOException
      */
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public Records getPatentVectors(EsPatentVectorDTO dto,File file) throws Exception {
         Long pageNum = dto.getPageNum();
         Long pageSize = dto.getPageSize();
@@ -142,7 +150,18 @@ public class EsDenseVectorService {
         records.setCurrent(pageNum);
         records.setSize(pageSize);
         records.setData(vectorVos);
-        records.setTotal(total <= vectorVos.size() ? total : vectorVos.size());
+        long count = total <= vectorVos.size() ? total : vectorVos.size();
+        records.setTotal(count);
+
+        //添加检索历史
+        AddSearchRecordDTO recordDTO = new AddSearchRecordDTO();
+        recordDTO.setProductId(dto.getProductId());
+        recordDTO.setDescription(dto.getDescription());
+        recordDTO.setGuid(file.getPath());
+        recordDTO.setSearchCondition(condition);
+        recordDTO.setAllNum(Integer.parseInt(String.valueOf(count)));
+        recordDTO.setSearchTime(new Date());
+        searchRecordService.addSearchRecord(recordDTO);
         return records;
     }