Commit ac2b1cf7 authored by muhong's avatar muhong

新增 名称联想

parent b1fa3c20
...@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; ...@@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.FavoritesItemsRelation; import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import java.util.List; import java.util.List;
import java.util.Map;
public interface FavoritesItemsRelationDao { public interface FavoritesItemsRelationDao {
int insert(FavoritesItemsRelation record); int insert(FavoritesItemsRelation record);
...@@ -17,4 +18,5 @@ public interface FavoritesItemsRelationDao { ...@@ -17,4 +18,5 @@ public interface FavoritesItemsRelationDao {
long countByItemId(Long itemId); long countByItemId(Long itemId);
boolean isCollected(Long userId, Long itemId); boolean isCollected(Long userId, Long itemId);
long countByFavoritesId(Long favoritesId); long countByFavoritesId(Long favoritesId);
List<Map<String, Object>> findItemIdByCount();
} }
...@@ -2,16 +2,16 @@ package com.wwdz.ch.db.impl; ...@@ -2,16 +2,16 @@ package com.wwdz.ch.db.impl;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites; import com.wwdz.ch.db.dao.FavoritesItemsRelationDao;
import com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper;
import com.wwdz.ch.db.domain.FavoritesItemsRelation; import com.wwdz.ch.db.domain.FavoritesItemsRelation;
import com.wwdz.ch.db.domain.FavoritesItemsRelationExample; 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 com.xxdxxs.db.component.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Map;
@Repository @Repository
public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao { public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao {
...@@ -106,4 +106,9 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao ...@@ -106,4 +106,9 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao
JdbcHelper.ifPresent(favoritesId, criteria::andFavoritesIdEqualTo); JdbcHelper.ifPresent(favoritesId, criteria::andFavoritesIdEqualTo);
return favoritesItemsRelationMapper.countByExample(example); return favoritesItemsRelationMapper.countByExample(example);
} }
@Override
public List<Map<String, Object>> findItemIdByCount() {
return favoritesItemsRelationMapper.selectItemIdByCount();
}
} }
...@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
public interface FavoritesItemsRelationMapper { public interface FavoritesItemsRelationMapper {
...@@ -50,4 +51,6 @@ public interface FavoritesItemsRelationMapper { ...@@ -50,4 +51,6 @@ public interface FavoritesItemsRelationMapper {
int updateByExampleSelective(@Param("record") FavoritesItemsRelation record, @Param("example") FavoritesItemsRelationExample example); int updateByExampleSelective(@Param("record") FavoritesItemsRelation record, @Param("example") FavoritesItemsRelationExample example);
int updateByExample(@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 @@ ...@@ -244,4 +244,7 @@
</if> </if>
limit 1 limit 1
</select> </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> </mapper>
\ No newline at end of file
...@@ -76,10 +76,17 @@ public class ItemServiceImpl implements ItemService { ...@@ -76,10 +76,17 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public Result recommend() { public Result recommend() {
try { try {
CoinRequestDto coinRequestDto = new CoinRequestDto(); List<Map<String, Object>> list = favoritesItemsRelationDao.findItemIdByCount();
coinRequestDto.setName(""); if (CollectionUtils.isEmpty(list)) {
List<String> names = itemDao.findNames(coinRequestDto); return Result.success();
return Result.success(names); }
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) { } catch (Exception e) {
logger.error("搜索推荐失败", e); logger.error("搜索推荐失败", e);
return Result.failed("搜索推荐失败"); 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