123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package com.caimei.controller.admin.auth;
- import com.caimei.annotation.CurrentUser;
- import com.caimei.model.ResponseJson;
- import com.caimei.model.po.SysUser;
- import com.caimei.service.auth.DownloadService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- /**
- * @author Aslee
- * @date 2021/5/14
- */
- @Api(tags = "下载API")
- @Slf4j
- @RestController
- @RequiredArgsConstructor
- @RequestMapping("/download")
- public class DownloadApi {
- private static final Logger logger = LoggerFactory.getLogger(DownloadApi.class);
- @Value("${caimei.imageDomain}")
- private String imageDomain;
- private final DownloadService downloadService;
- @ApiOperation("下载文件")
- @ApiImplicitParam(name = "ossName",value = "oss名称")
- @GetMapping("/file")
- public void downloadFile(String ossName,String fileName, HttpServletRequest request, HttpServletResponse response) {
- try {
- downloadService.downloadFile(ossName, fileName, request, response);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @ApiOperation("下载机构导入模板")
- @GetMapping("/auth/template")
- public void downloadAuthTemplate(HttpServletRequest request, HttpServletResponse response){
- try {
- downloadService.downloadAuthTemplate(request, response);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @ApiOperation("一键下载机构授权牌/设备授权牌/机构二维码/设备二维码")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "authIds", required = false, value = "勾选中的机构id,以,隔开"),
- @ApiImplicitParam(name = "type", required = false, value = "1机构授权牌,2.设备授权牌,3机构二维码,4设备二维码")
- })
- @GetMapping("/shop/image")
- public void downloadImage(String authIds, Integer type, HttpServletRequest request, HttpServletResponse response) throws Exception {
- if (StringUtils.isEmpty(authIds) || null == type) {
- return;
- }
- downloadService.downloadShopImage(authIds, type, request, response);
- }
- @ApiOperation("excel导出机构信息")
- @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
- @GetMapping("/auth/excel")
- public ResponseJson downloadAuthData(String authIds, HttpServletResponse response) {
- if (StringUtils.isEmpty(authIds)) {
- return ResponseJson.error("机构id不能为空");
- }
- return downloadService.downloadAuthData(authIds, response);
- }
- @ApiOperation("excel导出设备信息")
- @ApiImplicitParam(name = "authIds", required = true, value = "机构id,以,隔开")
- @GetMapping("/product/excel")
- public ResponseJson downloadProductData(String authIds, HttpServletRequest request, HttpServletResponse response) throws IOException {
- if (StringUtils.isEmpty(authIds)) {
- return ResponseJson.error("机构id不能为空");
- }
- return downloadService.downloadProductData(authIds, request, response);
- }
- @GetMapping("/Clubuser/excel")
- public ResponseJson downloadClubuserlistInfo(@CurrentUser SysUser sysUser,String clubUserIds, HttpServletResponse response){
- // if (StringUtils.isEmpty(clubUserIds)) {
- // return ResponseJson.error("用户id不能为空");
- // }
- Integer authUserId=null;
- if (null != sysUser && 1 != sysUser.getId()) {
- // 获取供应商用户id
- Integer userIdentity = sysUser.getUserIdentity();
- authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
- if (null == authUserId) {
- return ResponseJson.error("供应商用户id不能为空", null);
- }
- } else if (null == authUserId) {
- return ResponseJson.error("供应商用户id不能为空", null);
- }
- //clubUserIds为空则导出全部数据
- return downloadService.downloadClubuserlistInfo(authUserId,clubUserIds,response);
- }
- }
|