Commit 0a3f1b93 authored by tangtuo's avatar tangtuo

优化部分代码

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