整车绑定功能实现
This commit is contained in:
parent
c409ec8b52
commit
d514c43a42
@ -0,0 +1,22 @@
|
|||||||
|
package com.cdzy.operations.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author attiya
|
||||||
|
* @since 2025-10-21
|
||||||
|
*/
|
||||||
|
public interface InventoryType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电池
|
||||||
|
*/
|
||||||
|
int BATTERY = 1;
|
||||||
|
/**
|
||||||
|
* 头盔
|
||||||
|
*/
|
||||||
|
int HELMET = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车架
|
||||||
|
*/
|
||||||
|
int BIKE = 3;
|
||||||
|
}
|
||||||
@ -24,14 +24,6 @@ public class EbikeBikeBindVo implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 运营商ID
|
|
||||||
*/
|
|
||||||
@NotNull(message = "运营商ID不能为空")
|
|
||||||
private Long operatorId;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆编号
|
* 车辆编号
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -4,20 +4,27 @@ import cn.dev33.satoken.stp.StpUtil;
|
|||||||
import com.cdzy.common.ex.EbikeException;
|
import com.cdzy.common.ex.EbikeException;
|
||||||
import com.cdzy.operations.enums.BatteryStatus;
|
import com.cdzy.operations.enums.BatteryStatus;
|
||||||
import com.cdzy.operations.enums.BikeStatus;
|
import com.cdzy.operations.enums.BikeStatus;
|
||||||
import com.cdzy.operations.mapper.EbikeBatteryInfoMapper;
|
import com.cdzy.operations.mapper.*;
|
||||||
import com.cdzy.operations.mapper.EbikeBikeInfoMapper;
|
|
||||||
import com.cdzy.operations.mapper.EbikeEcuInfoMapper;
|
|
||||||
import com.cdzy.operations.model.entity.EbikeBatteryInfo;
|
import com.cdzy.operations.model.entity.EbikeBatteryInfo;
|
||||||
import com.cdzy.operations.model.entity.EbikeBikeInfo;
|
import com.cdzy.operations.model.entity.EbikeBikeInfo;
|
||||||
import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
||||||
|
import com.cdzy.operations.model.entity.EbikeInventoryRecord;
|
||||||
import com.cdzy.operations.model.vo.EbikeBikeBindVo;
|
import com.cdzy.operations.model.vo.EbikeBikeBindVo;
|
||||||
|
import com.cdzy.operations.model.vo.EbikeInventoryVo;
|
||||||
import com.cdzy.operations.service.EbikeBikeInfoService;
|
import com.cdzy.operations.service.EbikeBikeInfoService;
|
||||||
|
import com.cdzy.operations.service.EbikeInventoryService;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.cdzy.operations.model.entity.table.EbikeBatteryInfoTableDef.EBIKE_BATTERY_INFO;
|
import static com.cdzy.operations.model.entity.table.EbikeBatteryInfoTableDef.EBIKE_BATTERY_INFO;
|
||||||
|
import static com.cdzy.operations.model.entity.table.EbikeBikeInfoTableDef.EBIKE_BIKE_INFO;
|
||||||
import static com.cdzy.operations.model.entity.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO;
|
import static com.cdzy.operations.model.entity.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +42,14 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
|||||||
@Resource
|
@Resource
|
||||||
EbikeEcuInfoMapper ebikeEcuInfoMapper;
|
EbikeEcuInfoMapper ebikeEcuInfoMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
EbikeInventoryService inventoryService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
EbikeInventoryRecordMapper recordMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void bind(EbikeBikeBindVo bindVo) {
|
public void bind(EbikeBikeBindVo bindVo) {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_BATTERY_INFO.BATTERY_CODE.eq(bindVo.getBatteryCode()))
|
.where(EBIKE_BATTERY_INFO.BATTERY_CODE.eq(bindVo.getBatteryCode()))
|
||||||
@ -52,7 +66,59 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
|||||||
throw new EbikeException("该中控不存在");
|
throw new EbikeException("该中控不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Objects.equals(batteryInfo.getOperatorId(), ecuInfo.getOperatorId())) {
|
||||||
|
throw new EbikeException("所选组件属于不同的运营商");
|
||||||
|
}
|
||||||
|
Long operatorId = batteryInfo.getOperatorId();
|
||||||
|
|
||||||
|
queryWrapper.clear();
|
||||||
|
queryWrapper.where(EBIKE_BIKE_INFO.BATTERY_ID.eq(batteryInfo.getBatteryId()))
|
||||||
|
.or(EBIKE_BIKE_INFO.ECU_ID.eq(ecuInfo.getEcuId()))
|
||||||
|
.or(EBIKE_BIKE_INFO.BIKE_CODE.eq(bindVo.getBikeCode()));
|
||||||
|
EbikeBikeInfo info = this.mapper.selectOneByQuery(queryWrapper);
|
||||||
|
if (info != null){
|
||||||
|
throw new EbikeException("车辆绑定配件中存已绑定整车的配件");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<EbikeInventoryRecord> list = new ArrayList<>();
|
||||||
|
for (int i = 1; i < 4; i++) {
|
||||||
|
if (i != 2) {
|
||||||
|
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
|
||||||
|
.operatorId(operatorId)
|
||||||
|
.inventoryType(i)
|
||||||
|
.inventoryNum(-1)
|
||||||
|
.build();
|
||||||
|
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
|
||||||
|
.operatorId(inventoryVo.getOperatorId())
|
||||||
|
.inventoryType(inventoryVo.getInventoryType())
|
||||||
|
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
|
||||||
|
.createdBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.build();
|
||||||
|
list.add(inventoryRecord);
|
||||||
|
|
||||||
|
//TODO:优化为批量削减库存(需要更复杂的校验
|
||||||
|
inventoryService.reduceInventory(inventoryVo);
|
||||||
|
}
|
||||||
|
if (i == 2 && bindVo.getHasHelme()) {
|
||||||
|
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
|
||||||
|
.operatorId(operatorId)
|
||||||
|
.inventoryType(i)
|
||||||
|
.inventoryNum(-1)
|
||||||
|
.build();
|
||||||
|
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
|
||||||
|
.operatorId(inventoryVo.getOperatorId())
|
||||||
|
.inventoryType(inventoryVo.getInventoryType())
|
||||||
|
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
|
||||||
|
.createdBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.build();
|
||||||
|
list.add(inventoryRecord);
|
||||||
|
inventoryService.reduceInventory(inventoryVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recordMapper.insertBatch(list);
|
||||||
|
|
||||||
EbikeBikeInfo bikeInfo = EbikeBikeInfo.builder()
|
EbikeBikeInfo bikeInfo = EbikeBikeInfo.builder()
|
||||||
|
.operatorId(operatorId)
|
||||||
.bikeCode(bindVo.getBikeCode())
|
.bikeCode(bindVo.getBikeCode())
|
||||||
.batteryId(batteryInfo.getBatteryId())
|
.batteryId(batteryInfo.getBatteryId())
|
||||||
.ecuId(ecuInfo.getEcuId())
|
.ecuId(ecuInfo.getEcuId())
|
||||||
@ -61,8 +127,5 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
|||||||
.createdBy(StpUtil.getLoginIdAsLong())
|
.createdBy(StpUtil.getLoginIdAsLong())
|
||||||
.build();
|
.build();
|
||||||
this.mapper.insert(bikeInfo);
|
this.mapper.insert(bikeInfo);
|
||||||
|
|
||||||
//TODO: 消减库存
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user