DownloadApi.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.caimei.controller.admin.auth;
  2. import com.caimei.annotation.CurrentUser;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.po.SysUser;
  5. import com.caimei.service.auth.DownloadService;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiImplicitParam;
  8. import io.swagger.annotations.ApiImplicitParams;
  9. import io.swagger.annotations.ApiOperation;
  10. import lombok.RequiredArgsConstructor;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.io.IOException;
  22. /**
  23. * @author Aslee
  24. * @date 2021/5/14
  25. */
  26. @Api(tags = "下载API")
  27. @Slf4j
  28. @RestController
  29. @RequiredArgsConstructor
  30. @RequestMapping("/download")
  31. public class DownloadApi {
  32. private static final Logger logger = LoggerFactory.getLogger(DownloadApi.class);
  33. @Value("${caimei.imageDomain}")
  34. private String imageDomain;
  35. private final DownloadService downloadService;
  36. @ApiOperation("下载文件")
  37. @ApiImplicitParam(name = "ossName",value = "oss名称")
  38. @GetMapping("/file")
  39. public void downloadFile(String ossName,String fileName, HttpServletRequest request, HttpServletResponse response) {
  40. try {
  41. downloadService.downloadFile(ossName, fileName, request, response);
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. @ApiOperation("下载机构导入模板")
  47. @GetMapping("/auth/template")
  48. public void downloadAuthTemplate(HttpServletRequest request, HttpServletResponse response){
  49. try {
  50. downloadService.downloadAuthTemplate(request, response);
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55. @ApiOperation("一键下载机构授权牌/设备授权牌/机构二维码/设备二维码")
  56. @ApiImplicitParams({
  57. @ApiImplicitParam(name = "authIds", required = false, value = "勾选中的机构id,以,隔开"),
  58. @ApiImplicitParam(name = "type", required = false, value = "1机构授权牌,2.设备授权牌,3机构二维码,4设备二维码")
  59. })
  60. @GetMapping("/shop/image")
  61. public void downloadImage(String authIds, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
  62. if (StringUtils.isEmpty(authIds) || null == type) {
  63. return;
  64. }
  65. downloadService.downloadShopImage(authIds, type, request, response);
  66. }
  67. @ApiOperation("excel导出机构信息")
  68. @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
  69. @GetMapping("/auth/excel")
  70. public ResponseJson downloadAuthData(String authIds, HttpServletResponse response) {
  71. if (StringUtils.isEmpty(authIds)) {
  72. return ResponseJson.error("机构id不能为空");
  73. }
  74. return downloadService.downloadAuthData(authIds, response);
  75. }
  76. @ApiOperation("excel导出设备信息")
  77. @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
  78. @GetMapping("/product/excel")
  79. public ResponseJson downloadProductData(String authIds, HttpServletRequest request, HttpServletResponse response) throws IOException {
  80. if (StringUtils.isEmpty(authIds)) {
  81. return ResponseJson.error("机构id不能为空");
  82. }
  83. return downloadService.downloadProductData(authIds, request, response);
  84. }
  85. @GetMapping("/Clubuser/excel")
  86. public ResponseJson downloadClubuserlistInfo(@CurrentUser SysUser sysUser,String clubUserIds, HttpServletResponse response){
  87. // if (StringUtils.isEmpty(clubUserIds)) {
  88. // return ResponseJson.error("用户id不能为空");
  89. // }
  90. Integer authUserId=null;
  91. if (null != sysUser && 1 != sysUser.getId()) {
  92. // 获取供应商用户id
  93. Integer userIdentity = sysUser.getUserIdentity();
  94. authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  95. if (null == authUserId) {
  96. return ResponseJson.error("供应商用户id不能为空", null);
  97. }
  98. } else if (null == authUserId) {
  99. return ResponseJson.error("供应商用户id不能为空", null);
  100. }
  101. //clubUserIds为空则导出全部数据
  102. return downloadService.downloadClubuserlistInfo(authUserId,clubUserIds,response);
  103. }
  104. }