feat:url二维码

This commit is contained in:
dzc committed 2025-05-08 19:34:09 +08:00
1 parent 61a16acef6
commit 03621c3d05
7 files changed
+142 -81

No files matched your search

@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
@@ -22,94 +23,100 @@ import java.time.LocalDateTime;
public class HardDoorCabinetEntity extends Model<HardDoorCabinetEntity> {
/**
* 编号
*/
/**
* 编号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="编号")
@Schema(description = "编号")
private Long id;
/**
* 智能柜编号
*/
@Schema(description="智能柜编号")
/**
* 智能柜编号
*/
@Schema(description = "智能柜编号")
private Long hardDoorId;
/**
* 货柜编号(1,2)
*/
@Schema(description="货柜编号(1,2)")
/**
* 货柜编号(1,2)
*/
@Schema(description = "货柜编号(1,2)")
private Integer cabinetNo;
/**
* 锁在线1:在线;2:离线;
*/
@Schema(description="锁在线1:在线;2:离线;")
/**
* 锁在线1:在线;2:离线;
*/
@Schema(description = "锁在线1:在线;2:离线;")
private String isLockOnline;
/**
* 锁状态1:开锁;2:关锁;
*/
@Schema(description="锁状态1:开锁;2:关锁;")
/**
* 锁状态1:开锁;2:关锁;
*/
@Schema(description = "锁状态1:开锁;2:关锁;")
private Integer lockStatus;
/**
* 门状态1:门关;2:门开
*/
@Schema(description="门状态1:门关;2:门开")
/**
* 门状态1:门关;2:门开
*/
@Schema(description = "门状态1:门关;2:门开")
private Integer doorStatus;
/**
* 货柜售卖状态1:在售;2:停售
*/
@Schema(description="货柜售卖状态1:在售;2:停售")
/**
* 货柜售卖状态1:在售;2:停售
*/
@Schema(description = "货柜售卖状态1:在售;2:停售")
private Integer saleStatus;
/**
* 二维码
*/
@Schema(description="二维码")
/**
* 二维码
*/
@Schema(description = "二维码")
private String qrCode;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建人")
/**
* url二维码
*/
@Schema(description = "url二维码")
private String urlQrCode;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改人")
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改时间")
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "修改时间")
private LocalDateTime updateTime;
/**
* 删除标记
*/
/**
* 删除标记
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description="删除标记")
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除标记")
private String delFlag;
/**
* 租户ID
*/
@Schema(description="租户ID")
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}
@@ -72,7 +72,8 @@ public class HardDoorManagerController {
@Operation(summary = "刷新智能柜货柜二维码", description = "刷新智能柜货柜二维码")
@GetMapping("/refresh-qr-code")
public R refreshQrCode(@RequestParam Long hardDoorId, @RequestParam Integer cabinetNo) {
return R.ok(hardDoorCabinetService.refreshQrCode(hardDoorId, cabinetNo));
hardDoorCabinetService.refreshQrCode(hardDoorId, cabinetNo);
return R.ok();
}
@Operation(summary = "音量修改", description = "音量修改")
@@ -21,5 +21,5 @@ public interface HardDoorCabinetService extends IService<HardDoorCabinetEntity>
/**
* 刷新智能柜货柜二维码
*/
String refreshQrCode(Long hardDoorId, Integer cabinetNo);
void refreshQrCode(Long hardDoorId, Integer cabinetNo);
}
@@ -38,6 +38,8 @@ import java.util.Map;
@Service
public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMapper, HardDoorCabinetEntity> implements HardDoorCabinetService {
private static final String TAG = "智能柜货柜";
private final RemoteFileService remoteFileService;
@Override
@@ -89,33 +91,56 @@ public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMappe
* 刷新智能柜货柜二维码
*/
@Override
public String refreshQrCode(Long hardDoorId, Integer cabinetNo) {
public void refreshQrCode(Long hardDoorId, Integer cabinetNo) {
// 查找货柜
HardDoorCabinetEntity cabinetDetail = baseMapper.selectOne(new LambdaQueryWrapper<HardDoorCabinetEntity>()
.eq(HardDoorCabinetEntity::getHardDoorId, hardDoorId)
.eq(HardDoorCabinetEntity::getCabinetNo, cabinetNo)
);
if (ObjectUtil.isEmpty(cabinetDetail)) throw new RuntimeException("货柜不存在");
String qrCode = generateQrCode(cabinetDetail);
String urlQrCode = generateUrlQrCode(cabinetDetail);
// 更新
HardDoorCabinetEntity updateObj = new HardDoorCabinetEntity();
updateObj.setId(cabinetDetail.getId());
updateObj.setQrCode(qrCode);
updateObj.setUrlQrCode(urlQrCode);
baseMapper.updateById(updateObj);
}
// 生成二维码
private String generateQrCode(HardDoorCabinetEntity detail) {
HardDoorCabinetCodeVo cabinetCodeVo = new HardDoorCabinetCodeVo();
cabinetCodeVo.setHardDoorId(String.valueOf(hardDoorId));
cabinetCodeVo.setCabinetNo(String.valueOf(cabinetNo));
// 生成二维码
cabinetCodeVo.setHardDoorId(String.valueOf(detail.getHardDoorId()));
cabinetCodeVo.setCabinetNo(String.valueOf(detail.getCabinetNo()));
String fileName = String.format("%s-%s.png", detail.getHardDoorId(), System.currentTimeMillis());
String coeContent = Base64.encode(JSONUtil.toJsonStr(cabinetCodeVo));
try {
byte[] bytes = QRCodeImageGenerator.generateQrCodeImage(coeContent, 300);
MultipartFile multipartFile = new MockMultipartFile("file", hardDoorId + "-" + System.currentTimeMillis() + ".png", "image/png", new ByteArrayInputStream(bytes));
MultipartFile multipartFile = new MockMultipartFile("file", fileName, "image/png", new ByteArrayInputStream(bytes));
R upload = remoteFileService.innerUpload(multipartFile, null, null, null);
Map data = (Map) upload.getData();
String url = (String) data.get("url");
// 更新
HardDoorCabinetEntity updateObj = new HardDoorCabinetEntity();
updateObj.setId(cabinetDetail.getId());
updateObj.setQrCode(url);
baseMapper.updateById(updateObj);
return url;
return (String) data.get("url");
} catch (Exception e) {
log.error("refreshQrCode刷新智能柜货柜二维码,hardDoorId:{},cabinetNo:{}", hardDoorId, cabinetNo, e);
throw new RuntimeException("刷新二维码失败");
log.error("|{}|生成url二维码,dto:|{}|error:|{}|", TAG, JSONUtil.toJsonStr(detail), e.getMessage());
return null;
}
}
// 生成url二维码
private String generateUrlQrCode(HardDoorCabinetEntity detail) {
HardDoorCabinetCodeVo cabinetCodeVo = new HardDoorCabinetCodeVo();
String fileName = String.format("%s-%s.png", detail.getHardDoorId(), System.currentTimeMillis());
String coeContent = String.format("https://stgl.pj.gov.cn/h5/#/pages/cabinet/buy?hardDoorId=%s&cabinetNo=%s", detail.getHardDoorId(), detail.getCabinetNo());
try {
byte[] bytes = QRCodeImageGenerator.generateQrCodeImage(coeContent, 300);
MultipartFile multipartFile = new MockMultipartFile("file", fileName, "image/png", new ByteArrayInputStream(bytes));
R upload = remoteFileService.innerUpload(multipartFile, null, null, null);
Map data = (Map) upload.getData();
return (String) data.get("url");
} catch (Exception e) {
log.error("|{}|生成url二维码,dto:|{}|error:|{}|", TAG, JSONUtil.toJsonStr(detail), e.getMessage());
return null;
}
}
}
@@ -78,6 +78,12 @@ public class MchManageEntity extends Model<MchManageEntity> {
@Schema(description = "商户收款码,自动生成")
private String collectionCode;
/**
* 商户收款码(url形式),自动生成
*/
@Schema(description = "商户收款码(url形式),自动生成")
private String collectionUrlCode;
/**
* 商户轮播图,逗号分隔
*/
@@ -39,7 +39,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -50,6 +49,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* 商户管理
@@ -301,10 +301,12 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
MchManageEntity mchDetail = baseMapper.selectById(mchId);
if (ObjectUtil.isEmpty(mchDetail)) return;
try {
String string = generateMchOrder(mchDetail);
String qrcode = generateMchQrCode(mchDetail);
String urlQrcode = generateUrlQrCode(mchDetail);
MchManageEntity updateEntity = new MchManageEntity();
updateEntity.setId(mchDetail.getId());
updateEntity.setCollectionCode(string);
updateEntity.setCollectionCode(qrcode);
updateEntity.setCollectionUrlCode(urlQrcode);
updateById(updateEntity);
} catch (Exception e) {
e.printStackTrace();
@@ -328,7 +330,8 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
}
private String generateMchOrder(MchManageEntity mchDetail) {
// 生成钱包二维码
private String generateMchQrCode(MchManageEntity mchDetail) {
try {
MchCollectionCodeVo mchCollectionCode = new MchCollectionCodeVo();
mchCollectionCode.setId(String.valueOf(mchDetail.getId()));
@@ -348,6 +351,24 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
}
// 生成url二维码
private String generateUrlQrCode(MchManageEntity mchDetail) {
String url = String.format("https://stgl.pj.gov.cn/h5/#/pages/pay/scanPay?id=%s", mchDetail.getId());
String fileName = String.format("%s-%s.png", mchDetail.getId(), System.currentTimeMillis());
try {
Drawing2D drawing = new Drawing2D();
byte[] bytes = QRCodeImageGenerator.generateQrCodeImage(url, 300);
byte[] mchCodeByte = drawing.drawImage(new ByteArrayInputStream(bytes)).setTitleTextStyle().drawingCenterText(mchDetail.getName()).getBytes();
MultipartFile multipartFile = new MockMultipartFile("file", fileName, "image/png", new ByteArrayInputStream(mchCodeByte));
R upload = remoteFileService.innerUpload(multipartFile, null, null, null);
Map data = (Map) upload.getData();
return (String) data.get("url");
} catch (Exception e) {
log.error("|{}|生成url二维码,dto:|{}|error:|{}|", TAG, JSON.toJSONString(mchDetail), e.getMessage());
return null;
}
}
private boolean existName(String name, String types, Long id) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<MchManageEntity>()
.eq(ObjectUtil.isNotEmpty(name), MchManageEntity::getName, name)
@@ -36,6 +36,7 @@
a.catgory_id,
a.logo_pic,
a.collection_code,
a.collection_url_code,
a.swiper_pic,
a.phone,
a.address_des,