收藏增加数量和图片
This commit is contained in:
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.entity.UserCollect;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户收藏音乐Mapper接口
|
||||
@@ -62,4 +63,14 @@ public interface UserCollectMapper
|
||||
public int deleteUserCollectByIds(Long[] ids);
|
||||
|
||||
UserCollect selectUserCollectAndUserId(@Param("userId") Long userId,@Param("musicId") String musicId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据collectIds 查询出歌单数量
|
||||
* @param collectIdList
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> selectNumUserCollectIdList(List<Long> collectIdList);
|
||||
|
||||
int updateImgByCollectId(UserCollect userCollect);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.MusicCollect;
|
||||
import com.ruoyi.common.core.domain.entity.MusicInfo;
|
||||
import com.ruoyi.common.core.domain.entity.UserCollect;
|
||||
import com.ruoyi.system.mapper.MusicCollectMapper;
|
||||
import com.ruoyi.system.mapper.MusicInfoMapper;
|
||||
import com.ruoyi.system.mapper.UserCollectMapper;
|
||||
import com.ruoyi.system.service.IMusicCollectService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -19,6 +23,10 @@ public class MusicCollectServiceImpl implements IMusicCollectService
|
||||
{
|
||||
@Autowired
|
||||
private MusicCollectMapper musicCollectMapper;
|
||||
@Autowired
|
||||
private UserCollectMapper userCollectMapper;
|
||||
@Autowired
|
||||
private MusicInfoMapper musicInfoMapper;
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
@@ -53,6 +61,12 @@ public class MusicCollectServiceImpl implements IMusicCollectService
|
||||
@Override
|
||||
public int insertMusicCollect(MusicCollect musicCollect)
|
||||
{
|
||||
// 查询出音乐图片
|
||||
MusicInfo musicInfo = musicInfoMapper.selectByMusicId(musicCollect.getMusicId().toString());
|
||||
UserCollect userCollect = new UserCollect();
|
||||
userCollect.setImg(musicInfo.getImgAddr());
|
||||
userCollect.setCollectId(musicCollect.getCollectId());
|
||||
userCollectMapper.updateImgByCollectId(userCollect);
|
||||
return musicCollectMapper.insertMusicCollect(musicCollect);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户收藏音乐Service业务层处理
|
||||
@@ -48,7 +50,25 @@ public class UserCollectServiceImpl implements IUserCollectService
|
||||
@Override
|
||||
public List<UserCollect> selectUserCollectList(UserCollect userCollect)
|
||||
{
|
||||
return userCollectMapper.selectUserCollectList(userCollect);
|
||||
List<UserCollect> list = userCollectMapper.selectUserCollectList(userCollect);
|
||||
//list 获取歌单音乐数量 和 获取歌单某张图片
|
||||
Long collectId = userCollect.getCollectId();
|
||||
|
||||
List<Long> collectIdList = list.stream().map(UserCollect::getCollectId).collect(Collectors.toList());
|
||||
|
||||
if (!collectIdList.isEmpty()) {
|
||||
List<Map<String, Object>> collectNums = userCollectMapper.selectNumUserCollectIdList(collectIdList);
|
||||
|
||||
// 将查询到的歌单音乐数量设置到对应的UserCollect对象中
|
||||
list.forEach(item -> {
|
||||
Map<String, Object> collectNum = collectNums.stream()
|
||||
.filter(map -> (item.getCollectId()).equals(map.get("collectId")))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
item.setMusicNum(collectNum != null ? (Long) collectNum.get("num") : 0L);
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,10 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="collectType" column="collect_type" />
|
||||
<result property="img" column="img" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectUserCollectVo">
|
||||
select id, user_id, collect_id, collect_name, create_time, update_time, collect_type from user_collect
|
||||
select id, user_id, collect_id, collect_name, create_time, update_time, collect_type,img from user_collect
|
||||
</sql>
|
||||
|
||||
<select id="selectUserCollectList" parameterType="UserCollect" resultMap="UserCollectResult">
|
||||
@@ -43,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="collectType != null">collect_type,</if>
|
||||
<if test="img != null">img,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
@@ -52,6 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="collectType != null">#{collectType},</if>
|
||||
<if test="img != null">#{img},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -82,4 +85,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="selectUserCollectAndUserId" resultMap="UserCollectResult">
|
||||
SELECT uc.* FROM music_collect mc LEFT JOIN user_collect uc on uc.collect_id=mc.collect_id WHERE mc.music_id=#{musicId} and uc.user_id=#{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectNumUserCollectIdList" resultType="java.util.Map">
|
||||
SELECT
|
||||
uc.collect_id as "collectId",
|
||||
COUNT(mc.music_id) as "num"
|
||||
FROM
|
||||
user_collect uc
|
||||
LEFT JOIN
|
||||
music_collect mc ON uc.collect_id = mc.collect_id
|
||||
WHERE
|
||||
uc.collect_id IN
|
||||
<foreach item="collectId" collection="list" open="(" separator="," close=")">
|
||||
#{collectId}
|
||||
</foreach>
|
||||
GROUP BY
|
||||
uc.collect_id
|
||||
</select>
|
||||
|
||||
<update id="updateImgByCollectId">
|
||||
update user_collect set img=#{img} where collectId = #{collectId}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user