| | |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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.admin.api.entity.SysDeptRelation; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.log.annotation.SysLog; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import com.by4cloud.platformx.device.constant.MaxSizeContant; |
| | | import com.by4cloud.platformx.device.entity.Device; |
| | | import com.by4cloud.platformx.device.entity.DeviceInventory; |
| | | import com.by4cloud.platformx.device.entity.InvestmentPlan; |
| | | import com.by4cloud.platformx.device.service.DeviceInventoryService; |
| | | import com.by4cloud.platformx.device.service.DeviceService; |
| | | import com.by4cloud.platformx.device.service.JcMaxSizeService; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; |
| | | import io.swagger.v3.oas.annotations.security.SecurityRequirement; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | public class DeviceController { |
| | | |
| | | private final DeviceService deviceService; |
| | | private final DeviceInventoryService inventoryService; |
| | | private final JcMaxSizeService maxSizeService; |
| | | |
| | | /** |
| | | * 分页查询 |
| | |
| | | wrapper.eq(Device::getReqStatus,1); |
| | | wrapper.like(StrUtil.isNotBlank(device.getNumber()),Device::getNumber,device.getNumber()); |
| | | wrapper.like(StrUtil.isNotBlank(device.getName()),Device::getName,device.getName()); |
| | | return R.ok(deviceService.page(page, wrapper)); |
| | | wrapper.orderByDesc(Device::getCreateTime); |
| | | Page<Device> page1 = deviceService.page(page, wrapper); |
| | | for (Device device1 : page1.getRecords()) { |
| | | QueryWrapper<DeviceInventory> wrapper1 = new QueryWrapper<>(); |
| | | wrapper1.lambda().eq(DeviceInventory::getDeviceId,device1.getId()) |
| | | .eq(DeviceInventory::getInventoryStatus,1); |
| | | long count = inventoryService.count(wrapper1); |
| | | device1.setNum(Integer.parseInt(count+"")); |
| | | } |
| | | return R.ok(page1); |
| | | } |
| | | /** |
| | | * 分页查询 |
| | |
| | | wrapper.like(StrUtil.isNotBlank(device.getNumber()),Device::getNumber,device.getNumber()); |
| | | wrapper.like(StrUtil.isNotBlank(device.getName()),Device::getName,device.getName()); |
| | | return R.ok(deviceService.page(page, wrapper)); |
| | | } |
| | | |
| | | @Operation(summary = "根据设备分类获取设备" , description = "根据设备分类获取设备" ) |
| | | @GetMapping("/getByClassId" ) |
| | | public R getByClassId(@ParameterObject Device device) { |
| | | LambdaQueryWrapper<Device> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.eq(Device::getReqStatus,1); |
| | | wrapper.eq(Device::getClassId,device.getClassId()); |
| | | wrapper.like(StrUtil.isNotBlank(device.getName()),Device::getName,device.getName()); |
| | | return R.ok(deviceService.list(wrapper)); |
| | | } |
| | | |
| | | |
| | |
| | | @Operation(summary = "审批通过" , description = "审批通过" ) |
| | | @PostMapping("/pass" ) |
| | | public R passById(@RequestBody Device device) { |
| | | if(StringUtils.isBlank(device.getNumber())){ |
| | | return R.failed("请填写设备编号"); |
| | | } |
| | | device.setNumber(maxSizeService.nextNo(MaxSizeContant.DEVICE_NUM)); |
| | | device.setReqStatus(1); |
| | | deviceService.updateById(device); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 审批拒绝 |
| | | * @param id id |
| | | * @return R |
| | | */ |
| | | @Operation(summary = "审批拒绝" , description = "审批拒绝" ) |
| | | @GetMapping("/kill/{id}" ) |
| | | public R killById(@PathVariable("id" ) Long id) { |
| | | Device byId = deviceService.getById(id); |
| | | @GetMapping("/kill" ) |
| | | public R killById(@ParameterObject Device device) { |
| | | Device byId = deviceService.getById(device.getId()); |
| | | byId.setReqStatus(2); |
| | | if(StringUtils.isNotBlank(device.getRemark())){ |
| | | byId.setRemark(device.getRemark()); |
| | | } |
| | | deviceService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | |
| | | @Operation(summary = "新增出租设备清单表" , description = "新增出租设备清单表" ) |
| | | @SysLog("新增出租设备清单表" ) |
| | | @PostMapping |
| | | @PreAuthorize("@pms.hasPermission('platformx_device_add')" ) |
| | | public R save(@RequestBody Device device) { |
| | | if(device.getReqStatus() == 0){ |
| | | device.setReqCompId(SecurityUtils.getUser().getDeptId()); |
| | | if(device.getReqStatus()==0){ |
| | | return R.ok(deviceService.save(device)); |
| | | } |
| | | return R.ok(deviceService.save(device)); |
| | | device.setNumber(maxSizeService.nextNo(MaxSizeContant.DEVICE_NUM)); |
| | | device.setReleaseDate(new Date()); |
| | | return R.ok(deviceService.save(device)); |
| | | } |
| | | |
| | | /** |
| | | * 三级单位新增设备清单 |
| | | * @param device 三级单位新增设备清单 |
| | | * @return R |
| | | */ |
| | | @Operation(summary = "三级单位新增设备清单" , description = "三级单位新增设备清单" ) |
| | | @SysLog("新增出租设备清单表" ) |
| | | @PostMapping("/childAdd") |
| | | public R childAdd(@RequestBody Device device) { |
| | | device.setReqStatus(0); |
| | | return R.ok(deviceService.save(device)); |
| | | } |
| | | |
| | | /** |
| | | * 修改出租设备清单表 |
| | |
| | | @PutMapping |
| | | @PreAuthorize("@pms.hasPermission('platformx_device_edit')" ) |
| | | public R updateById(@RequestBody Device device) { |
| | | return R.ok(deviceService.updateById(device)); |
| | | Device byId = deviceService.getById(device.getId()); |
| | | if(StringUtils.isNotBlank(byId.getNumber())){ |
| | | byId.setNumber(maxSizeService.nextNo(MaxSizeContant.DEVICE_NUM)); |
| | | byId.setReleaseDate(new Date()); |
| | | } |
| | | return R.ok(deviceService.updateById(device)); |
| | | } |
| | | |
| | | /** |
| | |
| | | public List<Device> export(Device device,Long[] ids) { |
| | | return deviceService.list(Wrappers.lambdaQuery(device).in(ArrayUtil.isNotEmpty(ids), Device::getId, ids)); |
| | | } |
| | | |
| | | /** |
| | | * 所有设备下拉 |
| | | * @return |
| | | */ |
| | | @GetMapping("/getDropdowmList" ) |
| | | public R getDeviceList() { |
| | | return R.ok(deviceService.list()); |
| | | } |
| | | } |