|
|
@@ -7,7 +7,6 @@ import com.google.zxing.common.BitMatrix;
|
|
|
import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import shop.alien.store.service.TableAppQrCodeService;
|
|
|
import shop.alien.util.ali.AliOSSUtil;
|
|
|
@@ -16,7 +15,7 @@ import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
|
/**
|
|
|
- * APP 桌码:仅编码 storeId + tableNumber,不依赖微信接口
|
|
|
+ * APP 桌码:编码 storeId + tableId(store_table 主键),不依赖微信接口
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -28,33 +27,32 @@ public class TableAppQrCodeServiceImpl implements TableAppQrCodeService {
|
|
|
private final AliOSSUtil aliOSSUtil;
|
|
|
|
|
|
@Override
|
|
|
- public String generateTableAppQrCodeAndUpload(Integer storeId, String tableNumber, Integer menuType) {
|
|
|
- if (storeId == null || StringUtils.isBlank(tableNumber)) {
|
|
|
- throw new IllegalArgumentException("storeId与tableNumber不能为空");
|
|
|
+ public String generateTableAppQrCodeAndUpload(Integer storeId, Integer tableId, Integer menuType) {
|
|
|
+ if (storeId == null || tableId == null) {
|
|
|
+ throw new IllegalArgumentException("storeId与tableId不能为空");
|
|
|
}
|
|
|
int m = (menuType != null && menuType == 2) ? 2 : 1;
|
|
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
payload.put("storeId", storeId);
|
|
|
- payload.put("tableNumber", tableNumber.trim());
|
|
|
+ payload.put("tableId", tableId);
|
|
|
payload.put("menuType", m);
|
|
|
String content = payload.toJSONString();
|
|
|
|
|
|
byte[] png = encodeQrPng(content, QR_SIZE);
|
|
|
- String safeNum = tableNumber.trim().replaceAll("[^a-zA-Z0-9_-]", "_");
|
|
|
String ossPath = String.format(
|
|
|
- "qrcode/table/app/%d_%s_%d.png",
|
|
|
+ "qrcode/table/app/%d_%d_%d.png",
|
|
|
storeId,
|
|
|
- safeNum,
|
|
|
+ tableId,
|
|
|
System.currentTimeMillis());
|
|
|
|
|
|
ByteArrayInputStream in = new ByteArrayInputStream(png);
|
|
|
String url = aliOSSUtil.uploadFile(in, ossPath);
|
|
|
- if (StringUtils.isBlank(url)) {
|
|
|
+ if (url == null || url.isEmpty()) {
|
|
|
log.error("上传APP桌码到OSS失败, ossPath={}", ossPath);
|
|
|
throw new RuntimeException("上传APP桌码到OSS失败");
|
|
|
}
|
|
|
- log.info("APP桌码生成并上传成功, storeId={}, tableNumber={}, menuType={}, url={}", storeId, tableNumber, m, url);
|
|
|
+ log.info("APP桌码生成并上传成功, storeId={}, tableId={}, menuType={}, url={}", storeId, tableId, m, url);
|
|
|
return url;
|
|
|
}
|
|
|
|