Commit 8c81975d authored by muhong's avatar muhong

修改 藏馆的收藏品和收藏册数量

parent b5239edf
...@@ -139,6 +139,55 @@ public class MediaUtil { ...@@ -139,6 +139,55 @@ public class MediaUtil {
return map; return map;
} }
/**
* 通过文件头判断图片格式
*
* @param inputStream
* @return
* @throws IOException
*/
public static String imgType(InputStream inputStream) throws IOException {
// 读取文件前几位
byte[] fileHeader = new byte[4];
int read = inputStream.read(fileHeader, 0, fileHeader.length);
inputStream.close();
// 转为十六进制字符串
String header = bytes2Hex(fileHeader);
if (header.contains("FFD8FF")) {
return "jpg";
} else if (header.contains("89504E47")) {
return "png";
} else if (header.contains("47494638")) {
return "gif";
} else if (header.contains("424D")) {
return "bmp";
} else if (header.contains("52494646")) {
return "webp";
} else if (header.contains("49492A00")) {
return "tif";
} else {
return "unknown";
}
}
/**
* 转为十六进制字符串
*
* @param bytes
* @return
*/
public static String bytes2Hex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(b & 0xff);
sb.append(hex.length() == 2 ? hex : ("0" + hex));
}
return sb.toString();
}
public static void main(String[] args) { public static void main(String[] args) {
String vedioUrl = "https://cdn.wanwudezhi.com/static/web-static/video/53596700878a572ca4fae35243aaa819.mp4"; String vedioUrl = "https://cdn.wanwudezhi.com/static/web-static/video/53596700878a572ca4fae35243aaa819.mp4";
String url = getImageByCutVedio(vedioUrl); String url = getImageByCutVedio(vedioUrl);
......
...@@ -128,7 +128,7 @@ public interface FavoritesItemsRelationDao { ...@@ -128,7 +128,7 @@ public interface FavoritesItemsRelationDao {
* @param userId * @param userId
* @return * @return
*/ */
long countByUserId(Long userId); long countByUserId(Long userId, List<Long> itemIds);
/** /**
* 连表查询获取藏品的图片 * 连表查询获取藏品的图片
......
...@@ -15,7 +15,6 @@ import org.springframework.util.CollectionUtils; ...@@ -15,7 +15,6 @@ import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
@Repository @Repository
public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao { public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao {
...@@ -143,10 +142,11 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao ...@@ -143,10 +142,11 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao
} }
@Override @Override
public long countByUserId(Long userId) { public long countByUserId(Long userId, List<Long> itemIds) {
FavoritesItemsRelationExample example = new FavoritesItemsRelationExample(); FavoritesItemsRelationExample example = new FavoritesItemsRelationExample();
FavoritesItemsRelationExample.Criteria criteria = example.createCriteria(); FavoritesItemsRelationExample.Criteria criteria = example.createCriteria();
JdbcHelper.ifPresent(userId, criteria::andUserIdEqualTo); JdbcHelper.ifPresent(userId, criteria::andUserIdEqualTo);
JdbcHelper.ifPresent(itemIds, criteria::andItemIdNotIn);
return favoritesItemsRelationMapper.countByExample(example); return favoritesItemsRelationMapper.countByExample(example);
} }
......
...@@ -209,7 +209,8 @@ public class FavoritesServiceImpl implements FavoritesService { ...@@ -209,7 +209,8 @@ public class FavoritesServiceImpl implements FavoritesService {
@Override @Override
public Result favoritesNum(FavoritesRequestDto dto) { public Result favoritesNum(FavoritesRequestDto dto) {
try { try {
long itemNum = favoritesItemsRelationDao.countByUserId(dto.getUserId()); List<Long> itemIds = itemCommonService.getOnlyOneselfItemIdsByUserId(dto.getUserId());
long itemNum = favoritesItemsRelationDao.countByUserId(dto.getUserId(), itemIds);
long favoritesNum = favoritesDao.countByUserId(dto.getUserId()); long favoritesNum = favoritesDao.countByUserId(dto.getUserId());
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("itemNum", itemNum); map.put("itemNum", itemNum);
......
...@@ -68,6 +68,11 @@ public class ItemCommonServiceImpl implements ItemCommonService { ...@@ -68,6 +68,11 @@ public class ItemCommonServiceImpl implements ItemCommonService {
return itemDao.findOnlyOneselfItems(userId); return itemDao.findOnlyOneselfItems(userId);
} }
@Override
public List<Long> getOnlyOneselfItemIdsByUserId(Long userId) {
return itemDao.findOnlyOneselfItems(userId);
}
@Override @Override
public void getPageViews(UserInfo userInfo) { public void getPageViews(UserInfo userInfo) {
long followersNumber = 0; long followersNumber = 0;
......
...@@ -15,13 +15,21 @@ public interface ItemCommonService { ...@@ -15,13 +15,21 @@ public interface ItemCommonService {
void getNicknameAvatar(Long itemId, ItemResponseVo vo); void getNicknameAvatar(Long itemId, ItemResponseVo vo);
/** /**
* 获取仅自己可见的用户发布的藏品 * 获取登录用户仅自己可见的用户发布的藏品
* *
* @param token * @param token
* @return * @return
*/ */
List<Long> getOnlyOneselfItemIds(String token); List<Long> getOnlyOneselfItemIds(String token);
/**
* 获取被查询用户仅自己可见的用户发布的藏品
*
* @param userId
* @return
*/
List<Long> getOnlyOneselfItemIdsByUserId(Long userId);
/** /**
* 获取关注粉丝收藏和浏览量 * 获取关注粉丝收藏和浏览量
* *
......
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