自动生成换电工单
This commit is contained in:
parent
3dc6762f8d
commit
753318acad
@ -55,4 +55,12 @@ public interface OperationsFeignClient {
|
||||
@GetMapping("/ebikeBikeInfo/api/bikeInfo")
|
||||
JsonResult<FeignEbikeUserBikeInfo> bikeInfo(@RequestParam("bikeCode")String bikeCode);
|
||||
|
||||
/**
|
||||
* 根据EcuSn生成换电工单
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/ebikeBikeOrder/batterySwapOrder")
|
||||
JsonResult<FeignEbikeUserBikeInfo> batterySwapOrder(@RequestParam("ecuSn")String ecuSn);
|
||||
|
||||
}
|
||||
|
||||
@ -1,12 +1,22 @@
|
||||
package com.cdzy.operations.controller;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.operations.enums.BikeOrderHandleState;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeOrder;
|
||||
import com.cdzy.operations.service.EbikeBikeOrderService;
|
||||
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 org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cdzy.operations.model.entity.table.EbikeBikeOrderTableDef.EBIKE_BIKE_ORDER;
|
||||
|
||||
/**
|
||||
* 工单信息 控制层。
|
||||
@ -16,64 +26,12 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ebikeBikeOrder")
|
||||
@Validated
|
||||
public class EbikeBikeOrderController {
|
||||
|
||||
@Resource
|
||||
private EbikeBikeOrderService ebikeBikeOrderService;
|
||||
|
||||
/**
|
||||
* 添加工单信息。
|
||||
*
|
||||
* @param ebikeBikeOrder 工单信息
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public boolean save(@RequestBody EbikeBikeOrder ebikeBikeOrder) {
|
||||
return ebikeBikeOrderService.save(ebikeBikeOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除工单信息。
|
||||
*
|
||||
* @param id 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@DeleteMapping("remove/{id}")
|
||||
public boolean remove(@PathVariable Long id) {
|
||||
return ebikeBikeOrderService.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键更新工单信息。
|
||||
*
|
||||
* @param ebikeBikeOrder 工单信息
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
@PutMapping("update")
|
||||
public boolean update(@RequestBody EbikeBikeOrder ebikeBikeOrder) {
|
||||
return ebikeBikeOrderService.updateById(ebikeBikeOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有工单信息。
|
||||
*
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public List<EbikeBikeOrder> list() {
|
||||
return ebikeBikeOrderService.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据工单信息主键获取详细信息。
|
||||
*
|
||||
* @param id 工单信息主键
|
||||
* @return 工单信息详情
|
||||
*/
|
||||
@GetMapping("getInfo/{id}")
|
||||
public EbikeBikeOrder getInfo(@PathVariable Long id) {
|
||||
return ebikeBikeOrderService.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询工单信息。
|
||||
@ -82,8 +40,25 @@ public class EbikeBikeOrderController {
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public Page<EbikeBikeOrder> page(Page<EbikeBikeOrder> page) {
|
||||
return ebikeBikeOrderService.page(page);
|
||||
public JsonResult<?> page(PageParam page, Integer orderType,String bikeCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_BIKE_ORDER.HANDLE_STATE.eq(BikeOrderHandleState.UNPROCESSED))
|
||||
.where(EBIKE_BIKE_ORDER.ORDER_TYPE.eq(orderType, Objects.nonNull(orderType)))
|
||||
.where(EBIKE_BIKE_ORDER.BIKE_CODE.eq(bikeCode, StringUtil.hasText(bikeCode)));
|
||||
Page<EbikeBikeOrder> orderPage = ebikeBikeOrderService.page(page.getPage(), queryWrapper);
|
||||
return JsonResult.success(orderPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成换电工单。
|
||||
*
|
||||
* @param ecuSn 中控编码
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("batterySwapOrder")
|
||||
public JsonResult<?> batterySwapOrder(String ecuSn) {
|
||||
ebikeBikeOrderService.createBatterySwapOrder(ecuSn);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package com.cdzy.operations.enums;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-11-25
|
||||
*/
|
||||
public interface BikeOrderHandleState {
|
||||
|
||||
/**
|
||||
* 未处理
|
||||
*/
|
||||
int UNPROCESSED = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 已接单
|
||||
*/
|
||||
int RECEIVED = 1;
|
||||
|
||||
/**
|
||||
* 已处理
|
||||
*/
|
||||
int PROCESSED = 2;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.cdzy.operations.enums;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-11-25
|
||||
*/
|
||||
public interface BikeOrderType {
|
||||
|
||||
/**
|
||||
* 巡检
|
||||
*/
|
||||
int INSPECTION = 1;
|
||||
|
||||
/**
|
||||
* 换电
|
||||
*/
|
||||
int BATTERY_SWAP = 2;
|
||||
|
||||
/**
|
||||
* 调度
|
||||
*/
|
||||
int DISPATCH = 3;
|
||||
|
||||
/**
|
||||
* 维修
|
||||
*/
|
||||
int REPAIR = 4;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.cdzy.operations.model.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -51,15 +52,17 @@ public class EbikeBikeOrder implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onUpdateValue = "now()")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 删除状态(1已删除)
|
||||
* 删除状态
|
||||
*/
|
||||
private Boolean isDeleted;
|
||||
|
||||
@ -76,7 +79,8 @@ public class EbikeBikeOrder implements Serializable {
|
||||
/**
|
||||
* 处理状态
|
||||
*/
|
||||
private String handleState;
|
||||
@Column(onInsertValue = "0")
|
||||
private Integer handleState;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
package com.cdzy.operations.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 工单信息。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-11-24
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeBikeOrderVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆编号
|
||||
*/
|
||||
@NotNull(message = "车辆编号不能为空")
|
||||
private String bikeCode;
|
||||
|
||||
/**
|
||||
* 工单编号
|
||||
*/
|
||||
private Long orderCode;
|
||||
|
||||
/**
|
||||
* 工单类型:1 巡检工单 2 换电工单 3 调度工单 4 维修工单
|
||||
*/
|
||||
private Integer orderType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 删除状态(1已删除)
|
||||
*/
|
||||
private Boolean isDeleted;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
private LocalDateTime deletedAt;
|
||||
|
||||
/**
|
||||
* 处理人ID
|
||||
*/
|
||||
private Long receiverId;
|
||||
|
||||
/**
|
||||
* 处理状态
|
||||
*/
|
||||
private Integer handleState;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
private LocalDateTime handleAt;
|
||||
|
||||
/**
|
||||
* 处理结果
|
||||
*/
|
||||
private String handleResult;
|
||||
|
||||
/**
|
||||
* 是否有效调度工单
|
||||
*/
|
||||
private Boolean isValidDispatch;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createdBy;
|
||||
|
||||
}
|
||||
@ -11,4 +11,9 @@ import com.cdzy.operations.model.entity.EbikeBikeOrder;
|
||||
*/
|
||||
public interface EbikeBikeOrderService extends IService<EbikeBikeOrder> {
|
||||
|
||||
/**
|
||||
* 根据EcuSn生成车辆换电工单
|
||||
* @param ecuSn 中控编码
|
||||
*/
|
||||
void createBatterySwapOrder(String ecuSn);
|
||||
}
|
||||
|
||||
@ -1,18 +1,63 @@
|
||||
package com.cdzy.operations.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeOrder;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.operations.enums.BikeOrderType;
|
||||
import com.cdzy.operations.enums.BikeStatus;
|
||||
import com.cdzy.operations.mapper.EbikeBikeOrderMapper;
|
||||
import com.cdzy.operations.mapper.EbikeEcuInfoMapper;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeInfo;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeOrder;
|
||||
import com.cdzy.operations.service.EbikeBikeOrderService;
|
||||
import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.cdzy.operations.model.entity.table.EbikeBikeInfoTableDef.EBIKE_BIKE_INFO;
|
||||
import static com.cdzy.operations.model.entity.table.EbikeBikeOrderTableDef.EBIKE_BIKE_ORDER;
|
||||
import static com.cdzy.operations.model.entity.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO;
|
||||
|
||||
/**
|
||||
* 工单信息 服务层实现。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-11-24
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper, EbikeBikeOrder> implements EbikeBikeOrderService{
|
||||
public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper, EbikeBikeOrder> implements EbikeBikeOrderService {
|
||||
|
||||
private static final SnowFlakeIDKeyGenerator snowFlakeIDKeyGenerator = new SnowFlakeIDKeyGenerator();
|
||||
|
||||
@Resource
|
||||
EbikeEcuInfoMapper ebikeEcuInfoMapper;
|
||||
|
||||
@Override
|
||||
public void createBatterySwapOrder(String ecuSn) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(EBIKE_BIKE_INFO.ALL_COLUMNS)
|
||||
.where(EBIKE_ECU_INFO.ECU_SN.eq(ecuSn))
|
||||
.where(EBIKE_BIKE_INFO.STATUS.eq(BikeStatus.LAUNCH))
|
||||
.leftJoin(EBIKE_BIKE_INFO).on(EBIKE_BIKE_INFO.ECU_ID.eq(EBIKE_ECU_INFO.ECU_ID));
|
||||
EbikeBikeInfo bikeInfo = ebikeEcuInfoMapper.selectOneByQueryAs(queryWrapper, EbikeBikeInfo.class);
|
||||
if (bikeInfo == null) {
|
||||
log.error("创建换电工单失败,中控编号不存在或未绑定车辆、车辆未上架,ecuSn={} ", ecuSn);
|
||||
throw new EbikeException("创建换电工单失败,中控编号错误");
|
||||
}
|
||||
queryWrapper.clear();
|
||||
queryWrapper.where(EBIKE_BIKE_ORDER.BIKE_CODE.eq(bikeInfo.getBikeCode()));
|
||||
EbikeBikeOrder bikeOrder = this.mapper.selectOneByQuery(queryWrapper);
|
||||
if (bikeOrder != null) {
|
||||
log.error("车辆已存在换电工单,bikeCode={} ", bikeInfo.getBikeCode());
|
||||
throw new EbikeException("车辆已存在换电工单");
|
||||
}
|
||||
EbikeBikeOrder ebikeBikeOrder = EbikeBikeOrder.builder()
|
||||
.bikeCode(bikeInfo.getBikeCode())
|
||||
.orderCode(snowFlakeIDKeyGenerator.nextId())
|
||||
.orderType(BikeOrderType.BATTERY_SWAP)
|
||||
.build();
|
||||
this.mapper.insert(ebikeBikeOrder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ class EbikeOperationsApplicationTests {
|
||||
void contextLoads() throws IOException {
|
||||
SnowFlakeIDKeyGenerator generator = new SnowFlakeIDKeyGenerator();
|
||||
long nextId = generator.nextId();
|
||||
redisUtil.saveDispatchOrder(nextId, "2", 60L, TimeUnit.SECONDS);
|
||||
redisUtil.saveDispatchOrder(nextId, "2", 16L, TimeUnit.HOURS);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,8 @@ public class ReoprtHandler {
|
||||
char isMoving = binary.charAt(BitSwitch.IS_MOVING);
|
||||
ResGPSDto resGpsDto = objectMapper.convertValue(param, ResGPSDto.class);
|
||||
if (resGpsDto.getSoc() > 0 && resGpsDto.getSoc() < 20) {
|
||||
//TODO:生成换电工单
|
||||
//生成换电工单
|
||||
operateFeignClient.batterySwapOrder(deviceId);
|
||||
}
|
||||
resGpsDto.setEcuSn(deviceId);
|
||||
resGpsDto.setHelmetExit(helmet);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user