|
@@ -1,11 +1,29 @@
|
|
|
package com.example.xiaoshiweixinback.service;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.BeanUtil;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.ToolUtil;
|
|
|
import com.example.xiaoshiweixinback.domain.SearchRecord;
|
|
|
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.searchRecord.AddSearchRecordDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.searchRecord.SelectSearchRecordDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
+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.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author admin
|
|
@@ -15,6 +33,63 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchRecord> {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SearchRecordMapper searchRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtil cacheUtils;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ searchRecord.updateById();
|
|
|
+ } else {
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(LoginUtils.getToken());
|
|
|
+ record.setPersonUuid(personnelVO.getUuid());
|
|
|
+ record.insert();
|
|
|
+ id = record.getId();
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Records searchRecords(SelectSearchRecordDTO searchRecordDTO) {
|
|
|
+ Long pageNum = searchRecordDTO.getPageNum();
|
|
|
+ Long pageSize = searchRecordDTO.getPageSize();
|
|
|
+ Integer productId = searchRecordDTO.getProductId();
|
|
|
+ Page<SearchRecord> page = new Page<>(pageNum, pageSize);
|
|
|
+ Page<SearchRecord> record = searchRecordMapper.selectPage(page, new LambdaQueryWrapper<SearchRecord>()
|
|
|
+ .eq(ToolUtil.isNotEmpty(productId), SearchRecord::getProductId, productId)
|
|
|
+ .orderByDesc(SearchRecord::getSearchTime));
|
|
|
+ List<SelectSearchRecordVO> recordVOS = new ArrayList<>();
|
|
|
+ List<SearchRecord> list = record.getRecords();
|
|
|
+ if (ToolUtil.isNotEmpty(list)) {
|
|
|
+ list.forEach(i -> {
|
|
|
+ SelectSearchRecordVO recordVO = new SelectSearchRecordVO();
|
|
|
+ BeanUtil.copy(i, recordVO);
|
|
|
+ recordVOS.add(recordVO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(pageNum);
|
|
|
+ records.setSize(pageSize);
|
|
|
+ records.setTotal(page.getTotal());
|
|
|
+ records.setData(recordVOS);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Integer> removeSearchRecords(List<Integer> ids) {
|
|
|
+ if (!CollectionUtils.isEmpty(ids)) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_PARAMETER_EXCEPTION);
|
|
|
+ }
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|