车辆二维码基础功能
This commit is contained in:
parent
8807202d7c
commit
4d3017eb93
@ -12,6 +12,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,7 +40,7 @@ public class EbikeBatteryInfoController {
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("addBattery")
|
||||
public JsonResult<?> save(@RequestBody EbikeBatteryInfoVo ebikeBatteryInfo) throws Exception {
|
||||
public JsonResult<?> save(@RequestBody @Validated EbikeBatteryInfoVo ebikeBatteryInfo) throws Exception {
|
||||
ebikeBatteryInfoService.addBattery(ebikeBatteryInfo);
|
||||
return JsonResult.success();
|
||||
}
|
||||
@ -71,7 +72,7 @@ public class EbikeBatteryInfoController {
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("batchBind")
|
||||
public JsonResult<?> batchBind(@RequestBody EbikeBatteryInfoIdVo ids) {
|
||||
public JsonResult<?> batchBind(@RequestBody @Validated EbikeBatteryInfoIdVo ids) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_BATTERY_INFO.BATTERY_ID.in(ids.getBatteryIds()))
|
||||
.where(EBIKE_BATTERY_INFO.STATUS.eq(BatteryStatus.BIND));
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
package com.cdzy.operations.controller;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeQr;
|
||||
import com.cdzy.operations.model.vo.EbikeBikeQrVo;
|
||||
import com.cdzy.operations.service.EbikeBikeQrService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cdzy.operations.model.entity.table.EbikeBikeQrTableDef.EBIKE_BIKE_QR;
|
||||
|
||||
/**
|
||||
* 车辆二维码 控制层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ebikeBikeQr")
|
||||
public class EbikeBikeQrController {
|
||||
|
||||
@Resource
|
||||
private EbikeBikeQrService ebikeBikeQrService;
|
||||
|
||||
/**
|
||||
* 生成车辆二维码。
|
||||
*
|
||||
* @param qrVo 生成二维码参数
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("addEbikeQr")
|
||||
public JsonResult<?> addEbikeQr(@RequestBody EbikeBikeQrVo qrVo) throws Exception {
|
||||
ebikeBikeQrService.addEbikeQr(qrVo);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除。
|
||||
*
|
||||
* @param bikeQrId 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@GetMapping("remove")
|
||||
public JsonResult<?> remove(Long bikeQrId) {
|
||||
ebikeBikeQrService.removeById(bikeQrId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有。
|
||||
*
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public JsonResult<?> list() {
|
||||
List<EbikeBikeQr> list = ebikeBikeQrService.list();
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询。
|
||||
*
|
||||
* @param pageParam 分页对象
|
||||
* @param bikeQrCode 二维码编号
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public JsonResult<?> page(PageParam pageParam, String bikeQrCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_BIKE_QR.BIKE_QR_CODE.eq(bikeQrCode, StringUtil.hasText(bikeQrCode)));
|
||||
Page<EbikeBikeQr> page = ebikeBikeQrService.page(pageParam.getPage(), queryWrapper);
|
||||
return JsonResult.success(page);
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.cdzy.operations.model.entity.EbikeInventory;
|
||||
import com.cdzy.operations.model.vo.EbikeInventoryVo;
|
||||
import com.cdzy.operations.service.EbikeInventoryService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -29,7 +30,7 @@ public class EbikeInventoryController {
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("addInventory")
|
||||
public JsonResult<?> addInventory(@RequestBody EbikeInventoryVo ebikeInventory) throws Exception {
|
||||
public JsonResult<?> addInventory(@RequestBody @Validated EbikeInventoryVo ebikeInventory) throws Exception {
|
||||
ebikeInventoryService.addInventory(ebikeInventory);
|
||||
return JsonResult.success();
|
||||
}
|
||||
@ -41,7 +42,7 @@ public class EbikeInventoryController {
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("reduceInventory")
|
||||
public JsonResult<?> reduceInventory(@RequestBody EbikeInventoryVo ebikeInventory) {
|
||||
public JsonResult<?> reduceInventory(@RequestBody @Validated EbikeInventoryVo ebikeInventory) {
|
||||
ebikeInventoryService.reduceInventory(ebikeInventory);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
package com.cdzy.operations.controller;
|
||||
|
||||
/**
|
||||
* 车辆二维码 控制层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-15
|
||||
*/
|
||||
public class EbikeQrController {
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.cdzy.operations.enums;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
public interface BikeQrStatus {
|
||||
int UN_BIND = 0;
|
||||
int BIND = 1;
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.cdzy.operations.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeQr;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
public interface EbikeBikeQrMapper extends BaseMapper<EbikeBikeQr> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package com.cdzy.operations.model.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆二维码 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("ebike_bike_qr")
|
||||
public class EbikeBikeQr implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 车辆二维码ID
|
||||
*/
|
||||
@Id
|
||||
private Long bikeQrId;
|
||||
|
||||
/**
|
||||
* 运营商ID
|
||||
*/
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 二维码Code
|
||||
*/
|
||||
private String bikeQrCode;
|
||||
|
||||
/**
|
||||
* 二维码地址
|
||||
*/
|
||||
private String bikeQr;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private Timestamp createdAt;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createdBy;
|
||||
|
||||
/**
|
||||
* 绑定状态:0-未绑定 1-已绑定
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@Column(isLogicDelete = true)
|
||||
private Boolean isDeleted;
|
||||
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.cdzy.operations.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -26,11 +27,13 @@ public class EbikeBatteryInfoVo implements Serializable {
|
||||
/**
|
||||
* 运营商ID
|
||||
*/
|
||||
@NotNull(message = "运营商ID不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 电池数量
|
||||
*/
|
||||
@NotNull(message = "电池数量不能为空")
|
||||
private Integer batteryNum;
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
package com.cdzy.operations.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 电池基本信息。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-15
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeBikeQrVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 运营商ID
|
||||
*/
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 二维码数量
|
||||
*/
|
||||
private Integer qrNum;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.cdzy.operations.service;
|
||||
|
||||
import com.cdzy.operations.model.vo.EbikeBikeQrVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeQr;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
public interface EbikeBikeQrService extends IService<EbikeBikeQr> {
|
||||
|
||||
/**
|
||||
* 生成车辆二维码
|
||||
* @param qrVo 生成二维码参数
|
||||
*/
|
||||
void addEbikeQr(EbikeBikeQrVo qrVo) throws Exception;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.cdzy.operations.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.operations.mapper.EbikeBatteryInfoMapper;
|
||||
import com.cdzy.operations.model.entity.EbikeBatteryInfo;
|
||||
import com.cdzy.operations.model.vo.EbikeBatteryInfoVo;
|
||||
@ -36,6 +37,9 @@ public class EbikeBatteryInfoServiceImpl extends ServiceImpl<EbikeBatteryInfoMap
|
||||
@Override
|
||||
public void addBattery(EbikeBatteryInfoVo ebikeBatteryInfo) throws Exception {
|
||||
Integer batteryNum = ebikeBatteryInfo.getBatteryNum();
|
||||
if (batteryNum <= 0){
|
||||
throw new EbikeException("生成二维码数量不能小于/等于0");
|
||||
}
|
||||
Long operatorId = ebikeBatteryInfo.getOperatorId();
|
||||
List<String> list = VehicleNumberUtil.generateBatteryNumbersList(batteryNum);
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
package com.cdzy.operations.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.operations.enums.BikeQrStatus;
|
||||
import com.cdzy.operations.mapper.EbikeBikeQrMapper;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeQr;
|
||||
import com.cdzy.operations.model.vo.EbikeBikeQrVo;
|
||||
import com.cdzy.operations.service.EbikeBikeQrService;
|
||||
import com.cdzy.operations.utils.MinioUtil;
|
||||
import com.cdzy.operations.utils.QRGenUtil;
|
||||
import com.cdzy.operations.utils.VehicleNumberUtil;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
@Service
|
||||
public class EbikeBikeQrServiceImpl extends ServiceImpl<EbikeBikeQrMapper, EbikeBikeQr> implements EbikeBikeQrService{
|
||||
|
||||
private static final String bikeUrl = "/bike-qr/";
|
||||
|
||||
private static final String bikeSuffix = ".jpg";
|
||||
|
||||
@Resource
|
||||
MinioUtil minioUtil;
|
||||
|
||||
@Override
|
||||
public void addEbikeQr(EbikeBikeQrVo qrVo) throws Exception {
|
||||
Long operatorId = qrVo.getOperatorId();
|
||||
Integer qrNum = qrVo.getQrNum();
|
||||
if (qrNum <= 0){
|
||||
throw new EbikeException("生成二维码数量不能小于/等于0");
|
||||
}
|
||||
List<String> list = VehicleNumberUtil.generateVehicleNumbersList(qrNum);
|
||||
List<InputStream> streamList = new ArrayList<>();
|
||||
List<String> names = new ArrayList<>();
|
||||
List<EbikeBikeQr> qrList = new ArrayList<>();
|
||||
for (int i = 0; i < qrNum; i++) {
|
||||
//二维码生成
|
||||
String code = list.get(i);
|
||||
ByteArrayInputStream byteArrayInputStream = QRGenUtil.generateQRCodeInputStearm(code, code);
|
||||
streamList.add(byteArrayInputStream);
|
||||
names.add(bikeUrl+code +bikeSuffix);
|
||||
EbikeBikeQr ebikeBikeQr = EbikeBikeQr.builder()
|
||||
.operatorId(operatorId)
|
||||
.bikeQrCode(code)
|
||||
.bikeQr(minioUtil.getQrShowUrl(bikeUrl+code +bikeSuffix))
|
||||
.createdBy(StpUtil.getLoginIdAsLong())
|
||||
.status(BikeQrStatus.UN_BIND)
|
||||
.build();
|
||||
qrList.add(ebikeBikeQr);
|
||||
}
|
||||
minioUtil.batchUploadFiles(streamList,names);
|
||||
|
||||
saveBatch(qrList);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user