收藏增加数量和图片
This commit is contained in:
@@ -105,4 +105,16 @@ public class UserHistoryController extends BaseController
|
|||||||
{
|
{
|
||||||
return toAjax(userHistoryService.deleteUserHistoryByIds(ids));
|
return toAjax(userHistoryService.deleteUserHistoryByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询历史数量
|
||||||
|
*/
|
||||||
|
public AjaxResult historyNum(){
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
// 查询历史数量
|
||||||
|
//userHistoryService.findNumsByUserId();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,5 +36,10 @@ public class UserCollect extends BaseEntity
|
|||||||
@Excel(name = "歌单类型 音乐类型 ordinary 混音mixing")
|
@Excel(name = "歌单类型 音乐类型 ordinary 混音mixing")
|
||||||
private String collectType;
|
private String collectType;
|
||||||
|
|
||||||
|
// 歌单图片
|
||||||
|
private String img;
|
||||||
|
|
||||||
|
private Long musicNum;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.entity.UserCollect;
|
|||||||
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接口
|
||||||
@@ -62,4 +63,14 @@ public interface UserCollectMapper
|
|||||||
public int deleteUserCollectByIds(Long[] ids);
|
public int deleteUserCollectByIds(Long[] ids);
|
||||||
|
|
||||||
UserCollect selectUserCollectAndUserId(@Param("userId") Long userId,@Param("musicId") String musicId);
|
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;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import com.ruoyi.common.core.domain.entity.MusicCollect;
|
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.MusicCollectMapper;
|
||||||
|
import com.ruoyi.system.mapper.MusicInfoMapper;
|
||||||
|
import com.ruoyi.system.mapper.UserCollectMapper;
|
||||||
import com.ruoyi.system.service.IMusicCollectService;
|
import com.ruoyi.system.service.IMusicCollectService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -19,6 +23,10 @@ public class MusicCollectServiceImpl implements IMusicCollectService
|
|||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private MusicCollectMapper musicCollectMapper;
|
private MusicCollectMapper musicCollectMapper;
|
||||||
|
@Autowired
|
||||||
|
private UserCollectMapper userCollectMapper;
|
||||||
|
@Autowired
|
||||||
|
private MusicInfoMapper musicInfoMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询【请填写功能名称】
|
* 查询【请填写功能名称】
|
||||||
@@ -53,6 +61,12 @@ public class MusicCollectServiceImpl implements IMusicCollectService
|
|||||||
@Override
|
@Override
|
||||||
public int insertMusicCollect(MusicCollect musicCollect)
|
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);
|
return musicCollectMapper.insertMusicCollect(musicCollect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户收藏音乐Service业务层处理
|
* 用户收藏音乐Service业务层处理
|
||||||
@@ -48,7 +50,25 @@ public class UserCollectServiceImpl implements IUserCollectService
|
|||||||
@Override
|
@Override
|
||||||
public List<UserCollect> selectUserCollectList(UserCollect userCollect)
|
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="createTime" column="create_time" />
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
<result property="collectType" column="collect_type" />
|
<result property="collectType" column="collect_type" />
|
||||||
|
<result property="img" column="img" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectUserCollectVo">
|
<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>
|
</sql>
|
||||||
|
|
||||||
<select id="selectUserCollectList" parameterType="UserCollect" resultMap="UserCollectResult">
|
<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="createTime != null">create_time,</if>
|
||||||
<if test="updateTime != null">update_time,</if>
|
<if test="updateTime != null">update_time,</if>
|
||||||
<if test="collectType != null">collect_type,</if>
|
<if test="collectType != null">collect_type,</if>
|
||||||
|
<if test="img != null">img,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="id != null">#{id},</if>
|
<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="createTime != null">#{createTime},</if>
|
||||||
<if test="updateTime != null">#{updateTime},</if>
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
<if test="collectType != null">#{collectType},</if>
|
<if test="collectType != null">#{collectType},</if>
|
||||||
|
<if test="img != null">#{img},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@@ -82,4 +85,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<select id="selectUserCollectAndUserId" resultMap="UserCollectResult">
|
<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 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>
|
||||||
|
|
||||||
|
<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>
|
</mapper>
|
||||||
Reference in New Issue
Block a user