Commit ac2b1cf7 authored by muhong's avatar muhong

新增 名称联想

parent b1fa3c20
......@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import java.util.List;
import java.util.Map;
public interface FavoritesItemsRelationDao {
int insert(FavoritesItemsRelation record);
......@@ -17,4 +18,5 @@ public interface FavoritesItemsRelationDao {
long countByItemId(Long itemId);
boolean isCollected(Long userId, Long itemId);
long countByFavoritesId(Long favoritesId);
List<Map<String, Object>> findItemIdByCount();
}
......@@ -2,16 +2,16 @@ package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao;
import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.FavoritesItemsRelationExample;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao;
import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper;
import com.xxdxxs.db.component.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
@Repository
public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao {
......@@ -106,4 +106,9 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao
JdbcHelper.ifPresent(favoritesId, criteria::andFavoritesIdEqualTo);
return favoritesItemsRelationMapper.countByExample(example);
}
@Override
public List<Map<String, Object>> findItemIdByCount() {
return favoritesItemsRelationMapper.selectItemIdByCount();
}
}
......@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface FavoritesItemsRelationMapper {
......@@ -50,4 +51,6 @@ public interface FavoritesItemsRelationMapper {
int updateByExampleSelective(@Param("record") FavoritesItemsRelation record, @Param("example") FavoritesItemsRelationExample example);
int updateByExample(@Param("record") FavoritesItemsRelation record, @Param("example") FavoritesItemsRelationExample example);
List<Map<String, Object>> selectItemIdByCount();
}
\ No newline at end of file
......@@ -244,4 +244,7 @@
</if>
limit 1
</select>
<select id="selectItemIdByCount" resultType="java.util.Map">
select item_id,count(*) from favorites_items_relation group by item_id order by count(*) limit 20
</select>
</mapper>
\ No newline at end of file
......@@ -76,10 +76,17 @@ public class ItemServiceImpl implements ItemService {
@Override
public Result recommend() {
try {
CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setName("");
List<String> names = itemDao.findNames(coinRequestDto);
return Result.success(names);
List<Map<String, Object>> list = favoritesItemsRelationDao.findItemIdByCount();
if (CollectionUtils.isEmpty(list)) {
return Result.success();
}
Random random = new Random();
int index = random.nextInt(20);
Long itemId = (Long) list.get(index).get("item_id");
Item item = itemDao.findDetails(itemId);
Map<String, Object> map = new HashMap<>();
map.put("name", item.getName());
return Result.success(map);
} catch (Exception e) {
logger.error("搜索推荐失败", e);
return Result.failed("搜索推荐失败");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment