Commit 019ec8d6 authored by tangtuo's avatar tangtuo

修改文件下载的接口

查询类目的接口
parent 057c13d9
......@@ -6,8 +6,10 @@ import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
......@@ -26,9 +28,9 @@ public class CategoryController {
@Resource
private CategoryService categoryService;
/*@GetMapping("/list")
@ApiOperation(value = "查询所有类目信息")
public ResponseModel<List<Category>> list() {
return ResponseModel.success(categoryService.getByPid());
}*/
@GetMapping("/list")
@ApiOperation(value = "查询所有类目信息", notes = "如果查所有一级目录的话,pid传0或者空值")
public ResponseModel<List<Category>> list(@ApiParam(value = "父id,对应的是一级目录的id") @RequestParam(required = false, defaultValue = "0") Integer pid) {
return ResponseModel.success(categoryService.getByPid(pid));
}
}
......@@ -3,7 +3,9 @@ package com.fzm.admin.controller;
import com.fzm.common.annotation.Authentication;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.vo.NftListVo;
import com.fzm.common.entity.vo.NftVo;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.NftFileService;
import com.fzm.common.service.NftService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
......@@ -26,6 +28,9 @@ public class NftController {
@Resource
private NftService nftService;
@Resource
private NftFileService nftFileService;
@GetMapping("/list")
@ApiOperation(value = "查询nft列表")
public ResponseModel<PageInfo<NftListVo>> list(@ApiParam(value = "页码", required = true) @RequestParam Integer pageNum,
......@@ -37,7 +42,7 @@ public class NftController {
@ApiParam(value = "上架状态 0-未上架 1-已上架") @RequestParam(required = false) Integer status,
@ApiParam(value = "创建开始日期,yyyy-MM-dd格式") @RequestParam(required = false) String start,
@ApiParam(value = "创建截止日期,yyyy-MM-dd格式") @RequestParam(required = false) String end) {
PageInfo<NftListVo> page = nftService.page(pageNum, pageSize, categoryId,secondCategoryId, name, telephone, status, start, end);
PageInfo<NftListVo> page = nftService.page(pageNum, pageSize, categoryId, secondCategoryId, name, telephone, status, start, end);
return ResponseModel.success(page);
}
......@@ -67,13 +72,16 @@ public class NftController {
@ApiOperation(value = "查看详情")
@PostMapping("/detail/{id}")
public ResponseModel<Nft> getById(@ApiParam(value = "nft主键") @PathVariable Integer id) {
return ResponseModel.success(nftService.getById(id));
public ResponseModel<NftVo> getById(@ApiParam(value = "nft主键") @PathVariable Integer id) {
Nft nft = nftService.getById(id);
NftVo nftVo = new NftVo(nft, null, null);
nftVo.setFileList(nftFileService.getByNftId(id));
return ResponseModel.success(nftVo);
}
@ApiOperation(value = "下载文件")
@PostMapping("/download/{id}")
public void download(@ApiParam(value = "nft主键") @PathVariable Integer id) {
nftService.download(id);
@PostMapping("/download/{fileId}")
public void download(@ApiParam(value = "文件id") @PathVariable Integer fileId) {
nftFileService.downloadFile(fileId);
}
}
......@@ -68,14 +68,14 @@ public class NftVo {
this.author = nft.getAuthor();
this.name = nft.getName();
this.synopsis = nft.getSynopsis();
this.publisher = user.getNickname();
this.publisher = user != null ? user.getNickname() : "";
this.wallet = nft.getPublishAddress();
this.publishTime = nft.getPublishTime();
this.userId = nft.getUserId();
this.collection = false;
this.nftHash = nft.getNftHash();
this.nftNum = nft.getNftNum();
this.owner=owner.getNickname();
this.ownerAddress=owner.getWallet();
this.owner = owner != null ? owner.getNickname() : "";
this.ownerAddress = owner != null ? owner.getWallet() : "";
}
}
......@@ -19,4 +19,11 @@ public interface NftFileService extends IService<NftFile> {
* @return
*/
List<NftFile> getByNftId(Integer nftId);
/**
* 下载文件
*
* @param fileId
*/
void downloadFile(Integer fileId);
}
......@@ -106,12 +106,6 @@ public interface NftService extends IService<Nft> {
*/
Boolean offShelf(Integer id);
/**
* 下载附件
*
* @param id
*/
void download(Integer id);
/**
* 发行nft
......
......@@ -4,11 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.common.entity.AuthPerson;
import com.fzm.common.entity.NftFile;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.mapper.AuthPersonMapper;
import com.fzm.common.mapper.NftFileMapper;
import com.fzm.common.mapper.NftMapper;
import com.fzm.common.service.AuthPersonService;
import com.fzm.common.service.NftFileService;
import com.fzm.common.utils.OssUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -24,10 +27,22 @@ public class NftFileServiceImpl extends ServiceImpl<NftFileMapper, NftFile> impl
@Resource
private NftFileMapper nftFileMapper;
@Resource
private OssUtil ossUtil;
@Override
public List<NftFile> getByNftId(Integer nftId) {
QueryWrapper<NftFile> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("nft_id", nftId);
return nftFileMapper.selectList(queryWrapper);
}
@Override
public void downloadFile(Integer fileId) {
NftFile file = getById(fileId);
if (file == null) {
throw GlobalException.newException(ResultCode.DATA_ERROR, String.format("没找到id为 %s 的文件详情", fileId));
}
ossUtil.downloadFile(file.getFileUrl(), file.getFileName());
}
}
......@@ -306,7 +306,7 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
if (StringUtils.isNotBlank(end)) {
endDate = DateUtil.parse(end + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
}
List<NftListVo> list = nftMapper.page(categoryId,secondCategoryId, name, telephone, status, startDate, endDate);
List<NftListVo> list = nftMapper.page(categoryId, secondCategoryId, name, telephone, status, startDate, endDate);
return new PageInfo<>(list);
}
......@@ -346,15 +346,6 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
return updateById(nft);
}
@Override
public void download(Integer id) {
Nft nft = getById(id);
if (nft == null) {
throw GlobalException.newException(ResultCode.DATA_ERROR, "没找到此nft详情");
}
}
public static void main(String[] args) {
String str = "{\"author\":\"金庸\",\"publisher\":\"1boYWAeq12vkodh69nLU68WyiPuaT3ZAs\",\"hash\":\"80758630e76e5990b4de0e913ba42c5e\"}";
String hex = HexUtil.encodeHexStr(str, CharsetUtil.CHARSET_UTF_8);
......
......@@ -199,9 +199,9 @@ public class NftController {
@Authentication
@ApiOperation(value = "下载文件")
@PostMapping("/download/{id}")
public void download(@ApiParam(value = "nft主键") @PathVariable Integer id) {
nftService.download(id);
@PostMapping("/download/{fileId}")
public void download(@ApiParam(value = "文件id") @PathVariable Integer fileId) {
nftFileService.downloadFile(fileId);
}
@Authentication
......
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