Commit 198ea7f3 authored by tangtuo's avatar tangtuo

优化我的nft列表接口

parent 69a2cd26
...@@ -42,4 +42,6 @@ public interface NftMapper extends BaseMapper<Nft> { ...@@ -42,4 +42,6 @@ public interface NftMapper extends BaseMapper<Nft> {
* @return * @return
*/ */
List<NftListVo> page(@Param("categoryId") Integer categoryId, @Param("name") String name, @Param("telephone") String telephone, @Param("theme") String theme, @Param("status") Integer status, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate); List<NftListVo> page(@Param("categoryId") Integer categoryId, @Param("name") String name, @Param("telephone") String telephone, @Param("theme") String theme, @Param("status") Integer status, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate);
List<CollectionNftVo> listCurrent(@Param("categoryId") Integer categoryId, @Param("userId") Integer userId);
} }
...@@ -11,8 +11,5 @@ import java.util.List; ...@@ -11,8 +11,5 @@ import java.util.List;
*/ */
public interface CategoryService extends IService<Category> { public interface CategoryService extends IService<Category> {
Category getCategoryById(Integer categoryId);
List<Category> listAll(); List<Category> listAll();
} }
...@@ -56,7 +56,7 @@ public interface NftService extends IService<Nft> { ...@@ -56,7 +56,7 @@ public interface NftService extends IService<Nft> {
* @param userId * @param userId
* @return * @return
*/ */
List<Nft> listCurrent(Integer categoryId, Integer userId); List<CollectionNftVo> listCurrent(Integer categoryId, Integer userId);
/** /**
* 生成nft编号 * 生成nft编号
......
...@@ -17,17 +17,6 @@ import java.util.List; ...@@ -17,17 +17,6 @@ import java.util.List;
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService { public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
@Override @Override
public Category getCategoryById(Integer categoryId) {
List<Category> list = list();
for (Category category : list) {
if (categoryId.equals(category.getId())) {
return category;
}
}
return null;
}
@Override
@Cacheable(value = "category", key = "'list'") @Cacheable(value = "category", key = "'list'")
public List<Category> listAll() { public List<Category> listAll() {
return list(); return list();
......
...@@ -270,15 +270,8 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -270,15 +270,8 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
} }
@Override @Override
public List<Nft> listCurrent(Integer categoryId, Integer userId) { public List<CollectionNftVo> listCurrent(Integer categoryId, Integer userId) {
QueryWrapper<Nft> queryWrapper = new QueryWrapper<>(); return nftMapper.listCurrent(categoryId,userId);
queryWrapper.eq("user_id", userId);
queryWrapper.ne("nft_hash", "");
if (categoryId != null) {
queryWrapper.eq("category_id", categoryId);
}
queryWrapper.orderByDesc("publish_time");
return nftMapper.selectList(queryWrapper);
} }
@Override @Override
......
...@@ -76,4 +76,20 @@ ...@@ -76,4 +76,20 @@
publish_time DESC publish_time DESC
</select> </select>
<select id="listCurrent" resultType="com.fzm.common.entity.vo.CollectionNftVo">
select a.id,
a.name,
a.cover,
a.theme,
a.nft_id,
a.is_commemorate,
b.category_name as category
from tb_nft a left join tb_category b on a.category_id = b.id
where a.user_id = #{userId} and a.nft_hash != ''
<if test="categoryId != null">
and a.category_id = #{categoryId}
</if>
order by a.publish_time desc
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -93,8 +93,8 @@ public class NftController { ...@@ -93,8 +93,8 @@ public class NftController {
@GetMapping("/list") @GetMapping("/list")
@ApiOperation(value = "获取nft列表") @ApiOperation(value = "获取nft列表")
public ResponseModel<List<Nft>> list(@ApiParam(value = "当前页码") @RequestParam Integer pageNum, public ResponseModel<List<Nft>> list(@ApiParam(value = "当前页码") @RequestParam Integer pageNum,
@ApiParam(value = "每页记录数") @RequestParam Integer pageSize, @ApiParam(value = "每页记录数") @RequestParam Integer pageSize,
@ApiParam(value = "类目id,查询所有的时候传null") @RequestParam(required = false) Integer categoryId) { @ApiParam(value = "类目id,查询所有的时候传null") @RequestParam(required = false) Integer categoryId) {
pageNum = (pageNum - 1) * pageSize; pageNum = (pageNum - 1) * pageSize;
List<Nft> list = nftService.list(pageNum, pageSize, categoryId); List<Nft> list = nftService.list(pageNum, pageSize, categoryId);
...@@ -130,10 +130,7 @@ public class NftController { ...@@ -130,10 +130,7 @@ public class NftController {
@ApiOperation(value = "获取我的nft列表") @ApiOperation(value = "获取我的nft列表")
public ResponseModel<Map<String, Object>> listCurrent(@ApiParam(value = "类目id,查询全部的时候传null") @RequestParam(required = false) Integer categoryId) throws Exception { public ResponseModel<Map<String, Object>> listCurrent(@ApiParam(value = "类目id,查询全部的时候传null") @RequestParam(required = false) Integer categoryId) throws Exception {
Integer userId = JwtUtil.getUserIdFromToken(request.getHeader("Authorization")); Integer userId = JwtUtil.getUserIdFromToken(request.getHeader("Authorization"));
List<Nft> list = nftService.listCurrent(categoryId, userId); List<CollectionNftVo> list = nftService.listCurrent(categoryId, userId);
List<CollectionNftVo> nftVoList = list.stream()
.map(nft -> new CollectionNftVo(nft, categoryService.getCategoryById(nft.getCategoryId())))
.collect(Collectors.toList());
User user = userService.getById(userId); User user = userService.getById(userId);
// 生成二维码 // 生成二维码
HashMap<String, Object> qrCodeMap = new HashMap<>(); HashMap<String, Object> qrCodeMap = new HashMap<>();
...@@ -142,8 +139,8 @@ public class NftController { ...@@ -142,8 +139,8 @@ public class NftController {
qrCodeMap.put("wallet", user.getWallet()); qrCodeMap.put("wallet", user.getWallet());
String qrCode = QRCodeUtil.encode(JsonUtil.toJson(qrCodeMap), null, false); String qrCode = QRCodeUtil.encode(JsonUtil.toJson(qrCodeMap), null, false);
HashMap<String, Object> result = new HashMap<>(8); HashMap<String, Object> result = new HashMap<>(8);
result.put("list", nftVoList); result.put("list", list);
result.put("size", nftVoList.size()); result.put("size", list.size());
result.put("qrCode", qrCode); result.put("qrCode", qrCode);
return ResponseModel.success(result); return ResponseModel.success(result);
} }
......
package com.fzm.portal;
/**
* @author tangtuo
* @date 2021/8/5 14:21
*/
public class Test {
public static void main(String[] args) {
}
}
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