Merge remote-tracking branch 'origin/main'

This commit is contained in:
dzl 2025-05-20 17:46:18 +08:00
commit 1147431a33
3 changed files with 151 additions and 62 deletions

View File

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Map; import java.util.Map;
/** /**
* 部件的相关接口 * 车辆部件的相关接口
*/ */
@RestController @RestController
@RequestMapping("/ebikeComponent") @RequestMapping("/ebikeComponent")
@ -18,8 +18,8 @@ public class EbikeComponentController {
@Autowired @Autowired
EbikeComponentService ebikeComponentService; EbikeComponentService ebikeComponentService;
/*** /**
* 中控设备部件入库接口 * 中控设备部件入库暂存 stockInType 1暂存2入库
* @param params * @param params
* @return * @return
*/ */
@ -28,9 +28,8 @@ public class EbikeComponentController {
return ebikeComponentService.ecuStorageSave(params); return ebikeComponentService.ecuStorageSave(params);
} }
/**
/*** * 设备部件作废 通用
* 设备部件作废接口 通用
* @param componentEnterRecordId * @param componentEnterRecordId
* @return * @return
*/ */
@ -38,9 +37,8 @@ public class EbikeComponentController {
public JsonResult<?> invalidateDevicePart(@RequestParam(name="componentEnterRecordId")String componentEnterRecordId) { public JsonResult<?> invalidateDevicePart(@RequestParam(name="componentEnterRecordId")String componentEnterRecordId) {
return ebikeComponentService.invalidateDevicePart(componentEnterRecordId); return ebikeComponentService.invalidateDevicePart(componentEnterRecordId);
} }
/**
/*** * 设备部件取消通用
* 设备部件取消接口通用
* @param componentEnterRecordId * @param componentEnterRecordId
* @return * @return
*/ */

View File

@ -41,10 +41,10 @@ public class ReqDevicePartStockInDto {
/** /**
* 入库数量表示该批次部件的数量 * 入库数量表示该批次部件的数量
*/ */
private int enterQuantity; private Integer enterQuantity;
/** /**
* 入库类型1 表示暂存2 表示入库 * 入库类型0或空 表示暂存1 表示入库
*/ */
private Integer stockInType; private Integer stockInType;

View File

@ -55,25 +55,78 @@ public class EbikeComponentServiceImpl implements EbikeComponentService {
} }
/*** /***
* 中控设备部件入库接口 * 中控设备部件入库接口,暂存
* @param params * @param params
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public JsonResult<?> ecuStorageSave(ReqDevicePartStockInDto params){ public JsonResult<?> ecuStorageSave(ReqDevicePartStockInDto params) {
//判断是 Integer stockInType = params.getStockInType();
//查询部件价格 String userId = getStaffId(); // 获取当前操作用户ID
QueryWrapper queryWrapper = new QueryWrapper(); Long orgId = getOrgId(); // 获取当前操作用户所在组织ID
queryWrapper.eq("id",params.getComponentType()); EbikeComponentTypeInfo ebikeComponentTypeInfo = getComponentTypeInfo(params.getComponentType()); // 获取部件信息
EbikeComponentTypeInfo ebikeComponentTypeInfo = ebikeComponentTypeInfoMapper.selectOneById(queryWrapper);
StaffFeign staffFeign = getStaffFeignInfo();
// 获取当前操作用户
String userId = staffFeign.getStaffId().toString();
Long orgId = staffFeign.getOrgId();
//判断 // 获取或新增部件记录
String componentEnterRecordId = params.getComponentEnterRecordId(); EbikeComponentEnterRecords ebikeComponentEnterRecords = buildEnterRecord(params, userId, ebikeComponentTypeInfo,stockInType);
saveOrUpdateEnterRecord(ebikeComponentEnterRecords, params.getComponentEnterRecordId());
String componentEnterRecordId = ebikeComponentEnterRecords.getComponentEnterRecordId();
if(params.getEbikeEcuEnterRecords().size()>0){
// 删除原有的ECU入库记录并保存新的记录
deleteAndInsertEcuEnterRecords(componentEnterRecordId, params.getEbikeEcuEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId);
if (stockInType == 1) {
updateInventoryCount(ebikeComponentTypeInfo, orgId, params.getEbikeEcuEnterRecords().size());
}
}else if(params.getEbikeBatteryEnterRecords().size()>0){
// 删除原有的电池入库记录并保存新的记录
deleteAndInsertBatteryRecords(componentEnterRecordId, params.getEbikeBatteryEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId);
if (stockInType == 1) {
updateInventoryCount(ebikeComponentTypeInfo, orgId, params.getEbikeBatteryEnterRecords().size());
}
}else if(params.getEbikeHelmetEnterRecords().size()>0){
// 删除原有的头盔入库记录并保存新的记录
deleteAndInsertHelmetEnterRecords(componentEnterRecordId, params.getEbikeHelmetEnterRecords(), stockInType, ebikeComponentTypeInfo, userId, orgId);
if (stockInType == 1) {
updateInventoryCount(ebikeComponentTypeInfo, orgId, params.getEbikeHelmetEnterRecords().size());
}
}else {
//部件数量 enterQuantity 更新部件库
Integer enterQuantity = params.getEnterQuantity();
if (stockInType == 1) {
updateInventoryCount(ebikeComponentTypeInfo, orgId,enterQuantity);
}
}
return JsonResult.success("成功");
}
/*
获取用户Id
*/
private String getStaffId() {
StaffFeign staffFeign = getStaffFeignInfo();
return staffFeign.getStaffId().toString();
}
/*
获取组织Id
*/
private Long getOrgId() {
StaffFeign staffFeign = getStaffFeignInfo();
return staffFeign.getOrgId();
}
/**
* 获取车辆部件类型表信息
* @param componentType
* @return
*/
private EbikeComponentTypeInfo getComponentTypeInfo(String componentType) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("id", componentType);
return ebikeComponentTypeInfoMapper.selectOneById(queryWrapper);
}
private EbikeComponentEnterRecords buildEnterRecord(ReqDevicePartStockInDto params, String userId, EbikeComponentTypeInfo ebikeComponentTypeInfo,Integer stockInType) {
EbikeComponentEnterRecords ebikeComponentEnterRecords = new EbikeComponentEnterRecords(); EbikeComponentEnterRecords ebikeComponentEnterRecords = new EbikeComponentEnterRecords();
ebikeComponentEnterRecords.setOwningRegion(params.getOwningRegion()); ebikeComponentEnterRecords.setOwningRegion(params.getOwningRegion());
ebikeComponentEnterRecords.setComponentEnterRecordId(params.getComponentType()); ebikeComponentEnterRecords.setComponentEnterRecordId(params.getComponentType());
@ -81,36 +134,73 @@ public class EbikeComponentServiceImpl implements EbikeComponentService {
ebikeComponentEnterRecords.setComponentPrice(ebikeComponentTypeInfo.getPrice()); ebikeComponentEnterRecords.setComponentPrice(ebikeComponentTypeInfo.getPrice());
ebikeComponentEnterRecords.setCreatedUser(userId); ebikeComponentEnterRecords.setCreatedUser(userId);
ebikeComponentEnterRecords.setCreatedAt(LocalDateTime.now()); ebikeComponentEnterRecords.setCreatedAt(LocalDateTime.now());
ebikeComponentEnterRecords.setState("1");//已入库 ebikeComponentEnterRecords.setState(stockInType==1 ? "1":"0"); // 暂存为 0 入库为1
if(componentEnterRecordId==null){ //新增 return ebikeComponentEnterRecords;
}
private void saveOrUpdateEnterRecord(EbikeComponentEnterRecords ebikeComponentEnterRecords, String componentEnterRecordId) {
if (componentEnterRecordId == null) { // 新增
ebikeComponentEnterRecordsMapper.insert(ebikeComponentEnterRecords); ebikeComponentEnterRecordsMapper.insert(ebikeComponentEnterRecords);
}else{ } else { // 编辑或新增
//查询表中是否存在一条记录
QueryWrapper query = new QueryWrapper(); QueryWrapper query = new QueryWrapper();
query.eq("component_enter_record_id", componentEnterRecordId); query.eq("component_enter_record_id", componentEnterRecordId);
long l = ebikeComponentEnterRecordsMapper.selectCountByQuery(query); long count = ebikeComponentEnterRecordsMapper.selectCountByQuery(query);
if(l>0){//编辑 if (count > 0) {
ebikeComponentEnterRecords.setComponentEnterRecordId(componentEnterRecordId); ebikeComponentEnterRecords.setComponentEnterRecordId(componentEnterRecordId);
ebikeComponentEnterRecordsMapper.update(ebikeComponentEnterRecords); ebikeComponentEnterRecordsMapper.update(ebikeComponentEnterRecords);
}else{ } else {
ebikeComponentEnterRecordsMapper.insert(ebikeComponentEnterRecords); ebikeComponentEnterRecordsMapper.insert(ebikeComponentEnterRecords);
} }
} }
componentEnterRecordId=ebikeComponentEnterRecords.getComponentEnterRecordId(); }
//判断数据是否存在 存在则更新 否则插入 删除这次记录的所有 重新插入 private void deleteAndInsertEcuEnterRecords(String componentEnterRecordId, List<EbikeEcuEnterRecords> enterRecords, Integer stockInType, EbikeComponentTypeInfo ebikeComponentTypeInfo, String userId, Long orgId) {
// 删除原有的ECU入库记录
QueryWrapper query = new QueryWrapper(); QueryWrapper query = new QueryWrapper();
query.eq("component_enter_record_id", componentEnterRecordId); query.eq("component_enter_record_id", componentEnterRecordId);
ebikeEcuEnterRecordsMapper.deleteByQuery(query); ebikeEcuEnterRecordsMapper.deleteByQuery(query);
//保存ecu入库记录 // 插入新的ECU入库记录
List<EbikeEcuEnterRecords> enterRecords = params.getEbikeEcuEnterRecords(); for (EbikeEcuEnterRecords record : enterRecords) {
for(EbikeEcuEnterRecords record:enterRecords){
record.setComponentEnterRecordId(componentEnterRecordId); record.setComponentEnterRecordId(componentEnterRecordId);
ebikeEcuEnterRecordsMapper.insert(record); ebikeEcuEnterRecordsMapper.insert(record);
//部件仓库明细的插入 只有入库的时候才写入 写入后就不可删除了 只能通过状态控制 if (stockInType == 1) { // 仅在入库时执行
saveComponentInventory(record.getEcuSn(),record.getEcuCode(), ebikeComponentTypeInfo, userId, orgId);
}
}
}
private void deleteAndInsertHelmetEnterRecords(String componentEnterRecordId, List<EbikeHelmetEnterRecords> ebikeHelmetEnterRecords, Integer stockInType, EbikeComponentTypeInfo ebikeComponentTypeInfo, String userId, Long orgId) {
// 删除原有的头盔入库记录
QueryWrapper query = new QueryWrapper();
query.eq("component_enter_record_id", componentEnterRecordId);
ebikeHelmetEnterRecordsMapper.deleteByQuery(query);
// 插入新的头盔入库记录
for (EbikeHelmetEnterRecords record : ebikeHelmetEnterRecords) {
record.setComponentEnterRecordId(componentEnterRecordId);
ebikeHelmetEnterRecordsMapper.insert(record);
if (stockInType == 1) { // 仅在入库时执行
saveComponentInventory(record.getHelmetCode(),"", ebikeComponentTypeInfo, userId, orgId);
}
}
}
private void deleteAndInsertBatteryRecords(String componentEnterRecordId, List<EbikeBatteryEnterRecords> ebikeBatteryEnterRecords, Integer stockInType, EbikeComponentTypeInfo ebikeComponentTypeInfo, String userId, Long orgId) {
// 删除原有的电池入库记录
QueryWrapper query = new QueryWrapper();
query.eq("component_enter_record_id", componentEnterRecordId);
ebikeBatteryEnterRecordsMapper.deleteByQuery(query);
// 插入新的电池入库记录
for (EbikeBatteryEnterRecords record : ebikeBatteryEnterRecords) {
record.setComponentEnterRecordId(componentEnterRecordId);
ebikeBatteryEnterRecordsMapper.insert(record);
if (stockInType == 1) { // 仅在入库时执行
saveComponentInventory(record.getBatteryCode(),"", ebikeComponentTypeInfo, userId, orgId);
}
}
}
private void saveComponentInventory(String ItemCode,String SerialNumber, EbikeComponentTypeInfo ebikeComponentTypeInfo, String userId, Long orgId) {
EbikeComponentInventory ebikeComponentInventory = new EbikeComponentInventory(); EbikeComponentInventory ebikeComponentInventory = new EbikeComponentInventory();
ebikeComponentInventory.setItemCode(record.getEcuCode()); ebikeComponentInventory.setItemCode(ItemCode);
ebikeComponentInventory.setSerialNumber(record.getEcuCode()); ebikeComponentInventory.setSerialNumber(SerialNumber);
ebikeComponentInventory.setComponentType(ebikeComponentTypeInfo.getId()); ebikeComponentInventory.setComponentType(ebikeComponentTypeInfo.getId());
ebikeComponentInventory.setComponentName(ebikeComponentTypeInfo.getName()); ebikeComponentInventory.setComponentName(ebikeComponentTypeInfo.getName());
ebikeComponentInventory.setComponentPrice(ebikeComponentTypeInfo.getPrice()); ebikeComponentInventory.setComponentPrice(ebikeComponentTypeInfo.getPrice());
@ -118,31 +208,32 @@ public class EbikeComponentServiceImpl implements EbikeComponentService {
ebikeComponentInventory.setBrand(ebikeComponentTypeInfo.getBrand()); ebikeComponentInventory.setBrand(ebikeComponentTypeInfo.getBrand());
ebikeComponentInventory.setLastUpdatedAt(LocalDateTime.now()); ebikeComponentInventory.setLastUpdatedAt(LocalDateTime.now());
ebikeComponentInventory.setLastUpdatedUser(userId); ebikeComponentInventory.setLastUpdatedUser(userId);
ebikeComponentInventory.setState(1);//已入库 ebikeComponentInventory.setState(1); // 已入库
ebikeComponentInventoryMapper.insert(ebikeComponentInventory); ebikeComponentInventoryMapper.insert(ebikeComponentInventory);
} }
int size = enterRecords.size();
// 根据部件类型编号查询部件类型 新增或更新 统计表 private void updateInventoryCount(EbikeComponentTypeInfo ebikeComponentTypeInfo, Long orgId, int size) {
QueryWrapper query1 = new QueryWrapper(); QueryWrapper query1 = new QueryWrapper();
query1.eq("code", ebikeComponentTypeInfo.getId()); query1.eq("code", ebikeComponentTypeInfo.getId());
EbikeComponentInventorycount ebikeComponentInventorycount = ebikeComponentInventorycountMapper.selectOneByQuery(query1); EbikeComponentInventorycount ebikeComponentInventorycount = ebikeComponentInventorycountMapper.selectOneByQuery(query1);
if (ebikeComponentInventorycount == null) {
ebikeComponentInventorycount = new EbikeComponentInventorycount();
ebikeComponentInventorycount.setOrgId(orgId); ebikeComponentInventorycount.setOrgId(orgId);
ebikeComponentInventorycount.setCode(ebikeComponentTypeInfo.getId()); ebikeComponentInventorycount.setCode(ebikeComponentTypeInfo.getId());
ebikeComponentInventorycount.setName(ebikeComponentTypeInfo.getName()); ebikeComponentInventorycount.setName(ebikeComponentTypeInfo.getName());
ebikeComponentInventorycount.setBrand(ebikeComponentTypeInfo.getBrand()); ebikeComponentInventorycount.setBrand(ebikeComponentTypeInfo.getBrand());
ebikeComponentInventorycount.setUnit(ebikeComponentTypeInfo.getUnit()); ebikeComponentInventorycount.setUnit(ebikeComponentTypeInfo.getUnit());
ebikeComponentInventorycount.setPrice(ebikeComponentTypeInfo.getPrice()); ebikeComponentInventorycount.setPrice(ebikeComponentTypeInfo.getPrice());
if(ebikeComponentInventorycount==null){
ebikeComponentInventorycount.setCount(size); ebikeComponentInventorycount.setCount(size);
ebikeComponentInventorycountMapper.insert(ebikeComponentInventorycount); ebikeComponentInventorycountMapper.insert(ebikeComponentInventorycount);
}else { } else {
ebikeComponentInventorycount.setCount(size+ebikeComponentInventorycount.getCount()); ebikeComponentInventorycount.setCount(ebikeComponentInventorycount.getCount() + size);
ebikeComponentInventorycountMapper.update(ebikeComponentInventorycount); ebikeComponentInventorycountMapper.update(ebikeComponentInventorycount);
} }
return JsonResult.success("入库成功");
} }
/*** /***
* 设备部件作废接口 通用 * 设备部件作废接口 通用
* @param componentEnterRecordId * @param componentEnterRecordId