中控批量入库
This commit is contained in:
parent
a2e40fedbd
commit
7801e20d4b
@ -3,6 +3,7 @@ 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.EbikeEcuInfo;
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoBatchVo;
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoVo;
|
||||
import com.cdzy.operations.service.EbikeEcuInfoService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@ -38,6 +39,18 @@ public class EbikeEcuInfoController {
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量入库。
|
||||
*
|
||||
* @param batchVo 中控信息
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("batchSave")
|
||||
public JsonResult<?> batchSave(@Validated @RequestBody EbikeEcuInfoBatchVo batchVo) {
|
||||
ebikeEcuInfoService.batchSave(batchVo);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除中控基本信息。
|
||||
*
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 中控基本信息 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-15
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeEcuInfoBatchVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 运营商ID
|
||||
*/
|
||||
@NotNull(message = "运营商ID不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 中控编号
|
||||
*/
|
||||
@NotNull(message = "中控编号不能为空")
|
||||
private List<String> ecuCodes;
|
||||
|
||||
/**
|
||||
* 中控SN码
|
||||
*/
|
||||
@NotNull(message = "中控SN码不能为空")
|
||||
private List<String> ecuSns;
|
||||
|
||||
/**
|
||||
* 中控品牌
|
||||
*/
|
||||
@NotNull(message = "中控品牌不能为空")
|
||||
private Integer ecuBrand;
|
||||
|
||||
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.cdzy.operations.service;
|
||||
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoBatchVo;
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
||||
@ -12,5 +13,15 @@ import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
||||
*/
|
||||
public interface EbikeEcuInfoService extends IService<EbikeEcuInfo> {
|
||||
|
||||
/**
|
||||
* 中控入库
|
||||
* @param ebikeEcuInfo 中控信息
|
||||
*/
|
||||
void saveEcu(EbikeEcuInfoVo ebikeEcuInfo);
|
||||
|
||||
/**
|
||||
* 批量入库
|
||||
* @param batchVo 入库信息
|
||||
*/
|
||||
void batchSave(EbikeEcuInfoBatchVo batchVo);
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.cdzy.operations.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoBatchVo;
|
||||
import com.cdzy.operations.model.vo.EbikeEcuInfoVo;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.cdzy.operations.model.entity.EbikeEcuInfo;
|
||||
@ -9,6 +11,9 @@ import com.cdzy.operations.service.EbikeEcuInfoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 中控基本信息 服务层实现。
|
||||
*
|
||||
@ -32,4 +37,27 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
|
||||
.build();
|
||||
ebikeEcuInfoMapper.insert(ebikeEcuInfoEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchSave(EbikeEcuInfoBatchVo batchVo) {
|
||||
Integer ecuBrand = batchVo.getEcuBrand();
|
||||
Long operatorId = batchVo.getOperatorId();
|
||||
List<String> ecuCodes = batchVo.getEcuCodes();
|
||||
List<String> ecuSns = batchVo.getEcuSns();
|
||||
if (ecuCodes.size() != ecuSns.size()) {
|
||||
throw new EbikeException("中控编号与中控SN码数量不对应");
|
||||
}
|
||||
List<EbikeEcuInfo> list = new ArrayList<>();
|
||||
for (int i = 0; i < ecuCodes.size(); i++) {
|
||||
EbikeEcuInfo ebikeEcuInfoEntity = EbikeEcuInfo.builder()
|
||||
.operatorId(operatorId)
|
||||
.ecuCode(ecuCodes.get(i))
|
||||
.ecuSn(ecuSns.get(i))
|
||||
.ecuBrand(ecuBrand)
|
||||
.createdBy(StpUtil.getLoginIdAsLong())
|
||||
.build();
|
||||
list.add(ebikeEcuInfoEntity);
|
||||
}
|
||||
saveBatch(list);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user