shiyunteng
8 天以前 cc59b65bc63b839127c29775bcd410dd407de66d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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<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.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("/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));
    }
}