Commit 0a3f1b93 authored by tangtuo's avatar tangtuo

优化部分代码

parent 26bf7529
package com.fzm.common.entity.vo;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Nft;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author tangtuo
* @date 2021/7/1 17:54
*/
@Data
@NoArgsConstructor
public class CollectionNftVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("类目id")
private Integer categoryId;
@ApiModelProperty("类目")
private String category;
@ApiModelProperty("名称")
private String name;
......@@ -26,11 +29,11 @@ public class CollectionNftVo {
@ApiModelProperty("nft编号")
private String nftId;
public CollectionNftVo(Nft nft) {
public CollectionNftVo(Nft nft, Category category) {
this.id = nft.getId();
this.theme = nft.getTheme();
this.nftId = nft.getNftId();
this.categoryId = nft.getCategoryId();
this.category = category.getCategoryName();
this.name = nft.getName();
}
}
......@@ -2,6 +2,7 @@ package com.fzm.common.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.vo.CollectionNftVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -22,4 +23,6 @@ public interface NftMapper extends BaseMapper<Nft> {
* @return
*/
List<Nft> list(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("categoryId") Integer categoryId);
List<CollectionNftVo> getCollectionList(@Param("list") List<Integer> list);
}
......@@ -8,4 +8,6 @@ import com.fzm.common.entity.Category;
* @date 2021/7/1 14:35
*/
public interface CategoryService extends IService<Category> {
Category getCategoryById(Integer categoryId);
}
......@@ -6,10 +6,23 @@ import com.fzm.common.mapper.CategoryMapper;
import com.fzm.common.service.CategoryService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author tangtuo
* @date 2021/7/1 14:36
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
@Override
public Category getCategoryById(Integer categoryId) {
List<Category> list = list();
for (Category category : list) {
if (categoryId.equals(category.getId())) {
return category;
}
}
return null;
}
}
......@@ -13,6 +13,7 @@ import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.mapper.NftMapper;
import com.fzm.common.service.CategoryService;
import com.fzm.common.service.NftService;
import com.fzm.common.service.UserService;
import com.fzm.common.utils.JsonUtil;
......@@ -47,6 +48,9 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
@Resource
private NftMapper nftMapper;
@Resource
private CategoryService categoryService;
@Value("${chain.para.contract-name}")
private String contractName;
......@@ -93,8 +97,7 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
return new ArrayList<>();
}
List<Integer> ids = set.stream().map(Integer::valueOf).collect(Collectors.toList());
List<Nft> nfts = nftMapper.selectBatchIds(ids);
return nfts.stream().map(CollectionNftVo::new).collect(Collectors.toList());
return nftMapper.getCollectionList(ids);
}
@Override
......
......@@ -12,4 +12,18 @@
limit #{pageNum},#{pageSize}
</select>
<select id="getCollectionList" resultType="com.fzm.common.entity.vo.CollectionNftVo">
select a.id,
a.name,
a.theme,
a.nft_id,
b.category_name as category
from tb_nft a left join tb_category b on a.category_id = b.id
where a.id in (
<foreach collection="list" item="id" separator=",">
#{id}
</foreach>
)
</select>
</mapper>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.fzm.portal.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.User;
import com.fzm.common.entity.vo.CollectionNftVo;
......@@ -10,6 +11,7 @@ import com.fzm.common.entity.vo.NftVo;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.CategoryService;
import com.fzm.common.service.NftService;
import com.fzm.common.service.UserService;
import com.fzm.common.utils.OssUtil;
......@@ -44,6 +46,9 @@ public class NftController {
@Resource
private UserService userService;
@Resource
private CategoryService categoryService;
@SaCheckLogin
@PostMapping("/publish")
......@@ -109,11 +114,14 @@ public class NftController {
@ApiOperation(value = "获取我的nft列表")
public ResponseModel<Map<String, Object>> listCurrent(@ApiParam(value = "类目id,查询全部的时候传null") @RequestParam(required = false) Integer categoryId) {
List<Nft> list = nftService.listCurrent(categoryId, StpUtil.getLoginIdAsInt());
List<CollectionNftVo> nftVoList = list.stream().map(CollectionNftVo::new).collect(Collectors.toList());
List<CollectionNftVo> nftVoList = list.stream()
.map(nft -> new CollectionNftVo(nft, categoryService.getCategoryById(nft.getCategoryId())))
.collect(Collectors.toList());
HashMap<String, Object> result = new HashMap<>(4);
result.put("list", nftVoList);
result.put("size", nftVoList.size());
return ResponseModel.success(result);
}
}
......@@ -11,7 +11,6 @@
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<property name="LOG_HOME" value="logs"/>
<springProfile name="local">
<property name="LOG_HOME" value="logs"/>
</springProfile>
<springProfile name="dev">
<property name="LOG_HOME" value="logs"/>
......
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