Commit c3359e5f by danmo

活码新增下载及批量下载接口

1 parent d61114e6
package com.linkwechat.web.controller.wecom; package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.linkwechat.common.annotation.Log; import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController; import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult; import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo; import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType; import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.query.qr.WeQrAddQuery; import com.linkwechat.wecom.domain.query.qr.WeQrAddQuery;
import com.linkwechat.wecom.domain.query.qr.WeQrCodeListQuery; import com.linkwechat.wecom.domain.query.qr.WeQrCodeListQuery;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo; import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeScanCountVo; import com.linkwechat.wecom.domain.vo.qr.WeQrCodeScanCountVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeUserVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
import com.linkwechat.wecom.service.IWeQrCodeService; import com.linkwechat.wecom.service.IWeQrCodeService;
import com.linkwechat.wecom.service.event.WeEventPublisherService; import com.linkwechat.wecom.service.event.WeEventPublisherService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -18,7 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,7 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author danmo * @author danmo
...@@ -34,9 +45,6 @@ public class WeQrCodeController extends BaseController { ...@@ -34,9 +45,6 @@ public class WeQrCodeController extends BaseController {
@Autowired @Autowired
private IWeQrCodeService weQrCodeService; private IWeQrCodeService weQrCodeService;
@Autowired
private WeEventPublisherService weEventPublisherService;
@ApiOperation(value = "新增活码", httpMethod = "POST") @ApiOperation(value = "新增活码", httpMethod = "POST")
@Log(title = "活码管理", businessType = BusinessType.INSERT) @Log(title = "活码管理", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
...@@ -87,9 +95,49 @@ public class WeQrCodeController extends BaseController { ...@@ -87,9 +95,49 @@ public class WeQrCodeController extends BaseController {
return AjaxResult.success(weQrCodeScanCount); return AjaxResult.success(weQrCodeScanCount);
} }
@GetMapping("/test") /**
public AjaxResult test() { * 员工活码批量下载
weEventPublisherService.register("123","213","213","123"); *
return AjaxResult.success(); * @param ids 员工活码ids
* @param request 请求
* @param response 输出
* @throws Exception
*/
@ApiOperation(value = "员工活码批量下载", httpMethod = "GET")
@Log(title = "活码管理", businessType = BusinessType.OTHER)
@GetMapping("/batch/download")
public void batchDownload(@RequestParam("ids") List<Long> ids, HttpServletRequest request, HttpServletResponse response) throws IOException {
List<WeQrCodeDetailVo> qrCodeList = weQrCodeService.getQrDetailByQrIds(ids);
if(CollectionUtil.isNotEmpty(qrCodeList)){
List<Map<String, String>> fileList = qrCodeList.stream().map(item -> {
Map<String, String> fileMap = new HashMap<>();
List<WeQrScopeUserVo> userVoList = item.getQrUserInfos().stream().map(WeQrScopeVo::getWeQrUserList).flatMap(Collection::stream).collect(Collectors.toList());
String fileName = userVoList.stream().map(WeQrScopeUserVo::getUserName).collect(Collectors.joining(","));
fileMap.put("fileName", fileName);
fileMap.put("url", item.getQrCode());
return fileMap;
}).collect(Collectors.toList());
FileUtils.batchDownloadFile(fileList, response.getOutputStream());
}
}
/**
* 员工活码下载
*
* @param id 员工活码id
* @param request 请求
* @param response 输出
* @throws Exception
*/
@ApiOperation(value = "员工活码下载", httpMethod = "GET")
@Log(title = "活码管理", businessType = BusinessType.OTHER)
@GetMapping("/download")
public void download(@RequestParam("id") Long id, HttpServletRequest request, HttpServletResponse response) throws IOException {
WeQrCodeDetailVo qrDetail = weQrCodeService.getQrDetail(id);
if (StringUtils.isEmpty(qrDetail.getQrCode())){
throw new CustomException("活码不存在");
}else {
FileUtils.downloadFile(qrDetail.getQrCode(), response.getOutputStream());
}
} }
} }
...@@ -32,12 +32,19 @@ public interface IWeQrCodeService extends IService<WeQrCode> { ...@@ -32,12 +32,19 @@ public interface IWeQrCodeService extends IService<WeQrCode> {
/** /**
* 获取活码详情 * 获取活码详情
* @param qrId * @param qrId 活码id
* @return * @return
*/ */
WeQrCodeDetailVo getQrDetail(Long qrId); WeQrCodeDetailVo getQrDetail(Long qrId);
/** /**
* 获取活码详情
* @param qrIds 活码id
* @return
*/
List<WeQrCodeDetailVo> getQrDetailByQrIds(List<Long> qrIds);
/**
* 获取活码列表 * 获取活码列表
* @return list * @return list
*/ */
...@@ -54,4 +61,5 @@ public interface IWeQrCodeService extends IService<WeQrCode> { ...@@ -54,4 +61,5 @@ public interface IWeQrCodeService extends IService<WeQrCode> {
* @return WeQrCodeScanCountVo * @return WeQrCodeScanCountVo
*/ */
WeQrCodeScanCountVo getWeQrCodeScanCount(WeQrCodeListQuery qrCodeListQuery); WeQrCodeScanCountVo getWeQrCodeScanCount(WeQrCodeListQuery qrCodeListQuery);
} }
...@@ -107,6 +107,11 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i ...@@ -107,6 +107,11 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
} }
@Override @Override
public List<WeQrCodeDetailVo> getQrDetailByQrIds(List<Long> qrIds) {
return this.baseMapper.getQrDetailByQrIds(qrIds);
}
@Override
public PageInfo<WeQrCodeDetailVo> getQrCodeList(WeQrCodeListQuery qrCodeListQuery) { public PageInfo<WeQrCodeDetailVo> getQrCodeList(WeQrCodeListQuery qrCodeListQuery) {
List<WeQrCodeDetailVo> weQrCodeList = new ArrayList<>(); List<WeQrCodeDetailVo> weQrCodeList = new ArrayList<>();
List<Long> qrCodeIdList = this.baseMapper.getQrCodeList(qrCodeListQuery); List<Long> qrCodeIdList = this.baseMapper.getQrCodeList(qrCodeListQuery);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!