package com.by4cloud.platformx.device.controller;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.StrUtil;
|
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<DeviceInventory> 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.eq(StringUtils.checkValNotNull(deviceInventory.getInventoryStatus()),DeviceInventory::getInventoryStatus,deviceInventory.getInventoryStatus());
|
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<DeviceInventory> wrapper = new QueryWrapper<>();
|
wrapper.lambda().eq(DeviceInventory::getDeviceId,deviceInventory.getDeviceId())
|
.eq(DeviceInventory::getSerialNo,deviceInventory.getSerialNo());
|
List<DeviceInventory> 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<DeviceInventory> wrapper = new QueryWrapper<>();
|
wrapper.lambda().eq(DeviceInventory::getDeviceId,deviceInventory.getDeviceId())
|
.eq(DeviceInventory::getSerialNo,deviceInventory.getSerialNo());
|
List<DeviceInventory> 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<DeviceInventory> 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<DeviceInventory> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("device_id",deviceId);
|
queryWrapper.eq("inventory_status","1");
|
return R.ok(deviceInventoryService.list(queryWrapper));
|
}
|
|
/**
|
* 设备下所有报废序列号下拉
|
* @return
|
*/
|
@GetMapping("/getDropdowmScrapList/{deviceId}" )
|
public R getDropdowmScrapList(@PathVariable("deviceId")Long deviceId) {
|
QueryWrapper<DeviceInventory> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("device_id",deviceId);
|
queryWrapper.eq("inventory_status","4");
|
return R.ok(deviceInventoryService.list(queryWrapper));
|
}
|
|
/**
|
* 租赁状态下的设备租赁详情
|
* @return
|
*/
|
@GetMapping("/getReleaseDetail/{id}" )
|
public R getReleaseDetail(@PathVariable("id")Long id) {
|
return deviceInventoryService.getReleaseDetail(id);
|
}
|
|
/**
|
* 设备更新照片
|
* @param deviceInventory 库存表
|
* @return R
|
*/
|
@SysLog("设备更新照片" )
|
@PutMapping("/uploadPic")
|
public R uploadPic(@RequestBody DeviceInventory deviceInventory) {
|
return R.ok(deviceInventoryService.updateById(deviceInventory));
|
}
|
|
/**
|
* 修改库存表
|
* @param id 库存表
|
* @return R
|
*/
|
@SysLog("设备归还入库" )
|
@GetMapping("/return/{id}")
|
public R returnDevice(@PathVariable("id")Long id) {
|
return deviceInventoryService.returnDevice(id);
|
}
|
}
|