package com.by4cloud.platformx.device.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.common.core.util.R; import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; import com.by4cloud.platformx.common.log.annotation.SysLog; import com.by4cloud.platformx.device.entity.DeviceDemandPlan; import com.by4cloud.platformx.device.entity.DeviceInventory; import com.by4cloud.platformx.device.service.DeviceInventoryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springdoc.api.annotations.ParameterObject; import org.springframework.http.HttpHeaders; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.List; /** * 库存表 * * @author pig * @date 2025-03-13 10:22:39 */ @RestController @RequiredArgsConstructor @RequestMapping("/deviceInventory" ) @Tag(description = "deviceInventory" , name = "库存表管理" ) @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class DeviceInventoryController { private final DeviceInventoryService deviceInventoryService; /** * 分页查询 * @param page 分页对象 * @param deviceInventory 库存表 * @return */ @Operation(summary = "分页查询" , description = "分页查询" ) @GetMapping("/page" ) public R getDeviceInventoryPage(@ParameterObject Page page, @ParameterObject DeviceInventory deviceInventory) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.like(StringUtils.isNotBlank(deviceInventory.getDeviceNumber()),DeviceInventory::getDeviceNumber,deviceInventory.getDeviceNumber()); wrapper.like(StringUtils.isNotBlank(deviceInventory.getSerialNo()),DeviceInventory::getSerialNo,deviceInventory.getSerialNo()); wrapper.like(StringUtils.isNotBlank(deviceInventory.getName()),DeviceInventory::getName,deviceInventory.getName()); wrapper.orderByDesc(DeviceInventory::getCreateTime); return R.ok(deviceInventoryService.page(page, wrapper)); } /** * 通过id查询库存流水表 * @param id id * @return R */ @Operation(summary = "通过id查询" , description = "通过id查询" ) @GetMapping("/{id}" ) public R getById(@PathVariable("id" ) Long id) { return R.ok(deviceInventoryService.getById(id)); } /** * 新增库存流水表 * @param deviceInventory 库存表 * @return R */ @Operation(summary = "新增库存表" , description = "新增库存表" ) @SysLog("新增库存流水表" ) @PostMapping public R save(@RequestBody DeviceInventory deviceInventory) { if(deviceInventory.getDeviceId()==null){ return R.failed("请选择设备清单"); } if(deviceInventory.getSerialNo()==null){ return R.failed("请填写设备序列号"); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda().eq(DeviceInventory::getDeviceId,deviceInventory.getDeviceId()) .eq(DeviceInventory::getSerialNo,deviceInventory.getSerialNo()); List list = deviceInventoryService.list(wrapper); if(list !=null && list.size()>0){ return R.failed("已存在该序列号,请重新添加"); } return R.ok(deviceInventoryService.save(deviceInventory)); } /** * 修改库存表 * @param deviceInventory 库存表 * @return R */ @SysLog("修改库存表" ) @PutMapping public R updateById(@RequestBody DeviceInventory deviceInventory) { if(deviceInventory.getDeviceId()==null){ return R.failed("请选择设备清单"); } if(deviceInventory.getSerialNo()==null){ return R.failed("请填写设备序列号"); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda().eq(DeviceInventory::getDeviceId,deviceInventory.getDeviceId()) .eq(DeviceInventory::getSerialNo,deviceInventory.getSerialNo()); List list = deviceInventoryService.list(wrapper); if(list !=null && list.size()>0){ DeviceInventory deviceInventory1 = list.get(0); if(!deviceInventory1.getId().equals(deviceInventory.getId())){ return R.failed("已存在该序列号,请重新添加"); } } return R.ok(deviceInventoryService.updateById(deviceInventory)); } /** * 通过id删除库存流水表 * @param ids id列表 * @return R */ @Operation(summary = "通过id删除库存表" , description = "通过id删除库存表" ) @SysLog("通过id删除库存流水表" ) @DeleteMapping public R removeById(@RequestBody Long[] ids) { return R.ok(deviceInventoryService.removeBatchByIds(CollUtil.toList(ids))); } /** * 导出excel 表格 * @param deviceInventory 查询条件 * @param ids 导出指定ID * @return excel 文件流 */ @ResponseExcel @GetMapping("/export") @PreAuthorize("@pms.hasPermission('platformx_DeviceInventory_export')" ) public List export(DeviceInventory deviceInventory,Long[] ids) { return deviceInventoryService.list(Wrappers.lambdaQuery(deviceInventory).in(ArrayUtil.isNotEmpty(ids), DeviceInventory::getId, ids)); } /** * 设备下所有序列号下拉 * @return */ @GetMapping("/getDropdowmList/{deviceId}" ) public R getDeviceList(@PathVariable("deviceId")Long deviceId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("device_id",deviceId); queryWrapper.eq("inventory_status","1"); return R.ok(deviceInventoryService.list(queryWrapper)); } /** * 租赁状态下的设备租赁详情 * @return */ @GetMapping("/getReleaseDetail/{id}" ) public R getReleaseDetail(@PathVariable("id")Long id) { return deviceInventoryService.getReleaseDetail(id); } }