diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/MsgController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/MsgController.java index 83e37a35..00c0bd11 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/MsgController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/MsgController.java @@ -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> 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> 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 all = msgService.all(page, size, shopId, nickName, openId, state, type); return ResponseEntity.ok(all); } - @AnonymousAccess @PutMapping("/shopState") - public ResponseEntity shopMsgState( - @Valid @RequestBody ShopMsgStateDTO shopMsgStateDTO - ) { + public ResponseEntity shopMsgState(@Valid @RequestBody ShopMsgStateDTO shopMsgStateDTO) { return ResponseEntity.of(msgService.updateShopState(shopMsgStateDTO)); } - @AnonymousAccess @DeleteMapping - public ResponseEntity removeSubUser( - @Valid @RequestBody ShopMsgRemoveDTO shopMsgRemoveDTO - ) { + public ResponseEntity removeSubUser(@Valid @RequestBody ShopMsgRemoveDTO shopMsgRemoveDTO) { return ResponseEntity.of(msgService.removeSubUser(shopMsgRemoveDTO)); } - @AnonymousAccess @PutMapping("/info") - public ResponseEntity updateInfo( - @Valid @RequestBody ShopInfoUpdateDTO shopInfoUpdateDTO - ) { + public ResponseEntity updateInfo(@Valid @RequestBody ShopInfoUpdateDTO shopInfoUpdateDTO) { return ResponseEntity.of(msgService.updateInfo(shopInfoUpdateDTO)); } - @AnonymousAccess @GetMapping("/state") - public ResponseEntity> updateInfo( - @RequestParam Integer shopId - ) { + public ResponseEntity> updateInfo(@RequestParam Integer shopId) { return ResponseEntity.ok(msgService.getInfo(shopId, null)); } + + /** + * 获取订阅当前用户店库存预警消息的二维码 + * + * @param shopId 店铺id + * @return 订阅二维码url + */ + @GetMapping("/subQrCode") + public ResponseEntity getSubQrCode(@RequestParam String shopId) { + return msgService.getSubQrCodeUrl(shopId); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/MsgServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/MsgServiceImpl.java index c0908595..7fee3a3d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/MsgServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/MsgServiceImpl.java @@ -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 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("生成二维码失败"); + } + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/MsgService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/MsgService.java index b893b711..2a60eab5 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/MsgService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/MsgService.java @@ -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 updateInfo(ShopInfoUpdateDTO shopInfoUpdateDTO); HashMap getInfo(Integer shopId, Integer type); + + ResponseEntity getSubQrCodeUrl(String shopId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java index 2f19e43c..8188cad2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/FileUtils.java @@ -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(); - // 可以考虑返回一个错误响应给客户端 } } diff --git a/eladmin-system/src/main/resources/static/logo.jpg b/eladmin-system/src/main/resources/static/logo.jpg new file mode 100644 index 00000000..3958379e Binary files /dev/null and b/eladmin-system/src/main/resources/static/logo.jpg differ diff --git a/eladmin-tools/src/main/java/cn/ysk/cashier/service/QiNiuService.java b/eladmin-tools/src/main/java/cn/ysk/cashier/service/QiNiuService.java index 4da0ce18..fc23714d 100644 --- a/eladmin-tools/src/main/java/cn/ysk/cashier/service/QiNiuService.java +++ b/eladmin-tools/src/main/java/cn/ysk/cashier/service/QiNiuService.java @@ -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; diff --git a/eladmin-tools/src/main/java/cn/ysk/cashier/service/impl/QiNiuServiceImpl.java b/eladmin-tools/src/main/java/cn/ysk/cashier/service/impl/QiNiuServiceImpl.java index 0feb776d..2f513f47 100644 --- a/eladmin-tools/src/main/java/cn/ysk/cashier/service/impl/QiNiuServiceImpl.java +++ b/eladmin-tools/src/main/java/cn/ysk/cashier/service/impl/QiNiuServiceImpl.java @@ -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.*; /**