增加获取订阅消息二维码接口

This commit is contained in:
yijiegong 2024-09-27 10:46:32 +08:00
parent 6a4da2891b
commit 57e4a9261b
7 changed files with 78 additions and 41 deletions

View File

@ -1,8 +1,8 @@
package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.annotation.AnonymousAccess;
import cn.ysk.cashier.dto.shop.*;
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
import cn.ysk.cashier.dto.shop.ShopInfoUpdateDTO;
import cn.ysk.cashier.dto.shop.ShopMsgRemoveDTO;
import cn.ysk.cashier.dto.shop.ShopMsgStateDTO;
import cn.ysk.cashier.pojo.shop.TbFullShopId;
import cn.ysk.cashier.service.shop.MsgService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/api/msg")
@ -26,53 +25,49 @@ public class MsgController {
/**
* 获取所有订阅消息用户
*
* @return
*/
@AnonymousAccess
@GetMapping("/all")
public ResponseEntity<Page<TbFullShopId>> all(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam Integer shopId,
@RequestParam(required = false) String nickName,
@RequestParam(required = false) String openId,
@RequestParam(required = false) Integer state,
@RequestParam(required = false) Integer type
) {
public ResponseEntity<Page<TbFullShopId>> all(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam Integer shopId,
@RequestParam(required = false) String nickName,
@RequestParam(required = false) String openId,
@RequestParam(required = false) Integer state,
@RequestParam(required = false) Integer type) {
Page<TbFullShopId> all = msgService.all(page, size, shopId, nickName, openId, state, type);
return ResponseEntity.ok(all);
}
@AnonymousAccess
@PutMapping("/shopState")
public ResponseEntity<Boolean> shopMsgState(
@Valid @RequestBody ShopMsgStateDTO shopMsgStateDTO
) {
public ResponseEntity<Boolean> shopMsgState(@Valid @RequestBody ShopMsgStateDTO shopMsgStateDTO) {
return ResponseEntity.of(msgService.updateShopState(shopMsgStateDTO));
}
@AnonymousAccess
@DeleteMapping
public ResponseEntity<Boolean> removeSubUser(
@Valid @RequestBody ShopMsgRemoveDTO shopMsgRemoveDTO
) {
public ResponseEntity<Boolean> removeSubUser(@Valid @RequestBody ShopMsgRemoveDTO shopMsgRemoveDTO) {
return ResponseEntity.of(msgService.removeSubUser(shopMsgRemoveDTO));
}
@AnonymousAccess
@PutMapping("/info")
public ResponseEntity<Boolean> updateInfo(
@Valid @RequestBody ShopInfoUpdateDTO shopInfoUpdateDTO
) {
public ResponseEntity<Boolean> updateInfo(@Valid @RequestBody ShopInfoUpdateDTO shopInfoUpdateDTO) {
return ResponseEntity.of(msgService.updateInfo(shopInfoUpdateDTO));
}
@AnonymousAccess
@GetMapping("/state")
public ResponseEntity<HashMap<String, Object>> updateInfo(
@RequestParam Integer shopId
) {
public ResponseEntity<HashMap<String, Object>> updateInfo(@RequestParam Integer shopId) {
return ResponseEntity.ok(msgService.getInfo(shopId, null));
}
/**
* 获取订阅当前用户店库存预警消息的二维码
*
* @param shopId 店铺id
* @return 订阅二维码url
*/
@GetMapping("/subQrCode")
public ResponseEntity<String> getSubQrCode(@RequestParam String shopId) {
return msgService.getSubQrCodeUrl(shopId);
}
}

View File

@ -3,19 +3,35 @@ package cn.ysk.cashier.service.impl.shopimpl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import cn.ysk.cashier.domain.QiniuContent;
import cn.ysk.cashier.dto.shop.ShopInfoUpdateDTO;
import cn.ysk.cashier.dto.shop.ShopMsgRemoveDTO;
import cn.ysk.cashier.dto.shop.ShopMsgStateDTO;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import cn.ysk.cashier.mybatis.entity.TbShopMsgState;
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
import cn.ysk.cashier.mybatis.mapper.TbShopOpenIdMapper;
import cn.ysk.cashier.mybatis.service.TbShopMsgStateService;
import cn.ysk.cashier.pojo.shop.TbFullShopId;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.service.QiNiuService;
import cn.ysk.cashier.service.shop.MsgService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dianguang.cloud.ossservice.service.OSSFactory;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@ -25,10 +41,16 @@ import java.util.Optional;
public class MsgServiceImpl implements MsgService {
private final TbShopOpenIdMapper shopOpenIdMapper;
private final TbShopMsgStateService shopMsgStateService;
private final TbShopInfoRepository tbShopInfoRepository;
private final ResourceLoader resourceLoader;
private final QiNiuService qiNiuService;
public MsgServiceImpl(TbShopOpenIdMapper shopOpenIdMapper, TbShopMsgStateService shopMsgStateService) {
public MsgServiceImpl(TbShopOpenIdMapper shopOpenIdMapper, TbShopMsgStateService shopMsgStateService, TbShopInfoRepository tbShopInfoRepository, ResourceLoader resourceLoader, QiNiuService qiNiuService) {
this.shopOpenIdMapper = shopOpenIdMapper;
this.shopMsgStateService = shopMsgStateService;
this.tbShopInfoRepository = tbShopInfoRepository;
this.resourceLoader = resourceLoader;
this.qiNiuService = qiNiuService;
}
@Override
@ -134,4 +156,25 @@ public class MsgServiceImpl implements MsgService {
return data;
}
@Override
public ResponseEntity<String> getSubQrCodeUrl(String shopId) {
TbShopInfo shopInfo = tbShopInfoRepository.getById(Integer.valueOf(shopId));
if (shopInfo == null || shopInfo.getId() == 0) {
return ResponseEntity.badRequest().body("店铺信息错误");
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
try {
InputStream inputStream = resource.getInputStream();
String url = StrUtil.format("https://invoice.sxczgkj.cn/index/wechat/weuserk?shopId={}", shopId);
QrCodeUtil.generate(url, new QrConfig(500, 500).
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);
QiniuContent content = qiNiuService.uploadByte(outputStream.toByteArray(), qiNiuService.findCloud());
return ResponseEntity.ok(content.getUrl());
} catch (Exception e) {
return ResponseEntity.badRequest().body("生成二维码失败");
}
}
}

View File

@ -6,6 +6,7 @@ import cn.ysk.cashier.dto.shop.ShopMsgStateDTO;
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
import cn.ysk.cashier.pojo.shop.TbFullShopId;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.http.ResponseEntity;
import java.util.HashMap;
import java.util.Optional;
@ -20,4 +21,6 @@ public interface MsgService {
Optional<Boolean> updateInfo(ShopInfoUpdateDTO shopInfoUpdateDTO);
HashMap<String, Object> getInfo(Integer shopId, Integer type);
ResponseEntity<String> getSubQrCodeUrl(String shopId);
}

View File

@ -1,6 +1,5 @@
package cn.ysk.cashier.utils;
import cn.hutool.core.util.IdUtil;
import cn.ysk.cashier.dto.shop.ExportTableStsDataDto;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
@ -8,13 +7,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static cn.ysk.cashier.utils.FileUtil.SYS_TEM_DIR;
/**
* @author yijiegong
*/
@ -64,14 +60,10 @@ public class FileUtils {
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");
try (ServletOutputStream out = response.getOutputStream()) {
//
// workbook.write(outputStream);
workbook.write(out);
out.flush();
} catch (IOException e) {
// 更详细的错误处理
e.printStackTrace();
// 可以考虑返回一个错误响应给客户端
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -18,10 +18,10 @@ package cn.ysk.cashier.service;
import cn.ysk.cashier.domain.QiniuConfig;
import cn.ysk.cashier.domain.QiniuContent;
import cn.ysk.cashier.service.dto.QiniuQueryCriteria;
import com.aliyun.teaopenapi.models.Config;
import com.dianguang.cloud.ossservice.config.CloudStorageConfig;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import com.aliyun.teaopenapi.models.Config;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

View File

@ -3,8 +3,10 @@ package cn.ysk.cashier.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.domain.QiniuConfig;
import cn.ysk.cashier.exception.BadRequestException;
import com.aliyun.oss.OSS;
import com.aliyun.teaopenapi.models.Config;
import com.dianguang.cloud.ossservice.config.CloudStorageConfig;
import com.dianguang.cloud.ossservice.model.DateUtils;
import com.dianguang.cloud.ossservice.service.OSSFactory;
import com.qiniu.common.QiniuException;
import com.qiniu.storage.BucketManager;
@ -23,6 +25,7 @@ import cn.ysk.cashier.utils.PageUtil;
import cn.ysk.cashier.utils.QueryHelp;
import cn.ysk.cashier.utils.ValidationUtil;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
@ -33,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**