117 lines
3.7 KiB
Java
117 lines
3.7 KiB
Java
package com.cdzy.operations.controller;
|
|
|
|
import com.cdzy.common.ex.EbikeException;
|
|
import com.cdzy.common.model.request.PageParam;
|
|
import com.cdzy.common.model.response.JsonResult;
|
|
import com.cdzy.operations.enums.BatteryStatus;
|
|
import com.cdzy.operations.model.entity.EbikeBatteryInfo;
|
|
import com.cdzy.operations.model.vo.EbikeBatteryInfoIdVo;
|
|
import com.cdzy.operations.model.vo.EbikeBatteryInfoVo;
|
|
import com.cdzy.operations.service.EbikeBatteryInfoService;
|
|
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.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
import static com.cdzy.operations.model.entity.table.EbikeBatteryInfoTableDef.EBIKE_BATTERY_INFO;
|
|
|
|
/**
|
|
* 电池基本信息 控制层。
|
|
*
|
|
* @author attiya
|
|
* @since 2025-09-15
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/ebikeBatteryInfo")
|
|
public class EbikeBatteryInfoController {
|
|
|
|
@Resource
|
|
private EbikeBatteryInfoService ebikeBatteryInfoService;
|
|
|
|
/**
|
|
* 生产电池二维码。
|
|
*
|
|
* @param ebikeBatteryInfo 电池基本信息
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
*/
|
|
@PostMapping("addBattery")
|
|
public JsonResult<?> save(@RequestBody EbikeBatteryInfoVo ebikeBatteryInfo) throws Exception {
|
|
ebikeBatteryInfoService.addBattery(ebikeBatteryInfo);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 绑定电池二维码。
|
|
*
|
|
* @param batteryId 电池ID
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
*/
|
|
@GetMapping("bind")
|
|
public JsonResult<?> bind(@RequestParam("batteryId")Long batteryId){
|
|
EbikeBatteryInfo batteryInfo = ebikeBatteryInfoService.getById(batteryId);
|
|
if (batteryInfo == null) {
|
|
throw new EbikeException("电池ID错误");
|
|
}
|
|
batteryInfo.setStatus(BatteryStatus.BIND);
|
|
ebikeBatteryInfoService.updateById(batteryInfo);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 批量绑定电池二维码。
|
|
*
|
|
* @param ids 电池ID集合
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
*/
|
|
@GetMapping("batchBind")
|
|
public JsonResult<?> batchBind(@RequestBody EbikeBatteryInfoIdVo ids){
|
|
UpdateChain.of(EbikeBatteryInfo.class)
|
|
.set(EbikeBatteryInfo::getStatus, BatteryStatus.BIND)
|
|
.where(EbikeBatteryInfo::getBatteryId).in(ids.getBatteryIds());
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 根据主键删除电池二维码信息。
|
|
*
|
|
* @param batteryId 主键
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
*/
|
|
@PostMapping("remove")
|
|
public JsonResult<?> remove(@RequestParam(value = "batteryId") Long batteryId) {
|
|
ebikeBatteryInfoService.removeById(batteryId);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
|
|
/**
|
|
* 查询所有电池二维码信息。
|
|
*
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping("list")
|
|
public JsonResult<?> list() {
|
|
List<EbikeBatteryInfo> list = ebikeBatteryInfoService.list();
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 分页查询电池二维码信息。
|
|
*
|
|
* @param pageParam 分页对象
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("page")
|
|
public JsonResult<?> page(PageParam pageParam,Integer status) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(EBIKE_BATTERY_INFO.STATUS.eq(status, Objects.nonNull(status)));
|
|
Page<EbikeBatteryInfo> page = ebikeBatteryInfoService.page(pageParam.getPage(),queryWrapper);
|
|
return JsonResult.success(page);
|
|
}
|
|
|
|
}
|