kongdeqiang
2025-03-24 18d187869d098a2893d79acdadc7d7a99aad28e6
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
181
182
183
184
185
186
package com.by4cloud.platformx.device.controller;
 
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.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.log.annotation.SysLog;
import com.by4cloud.platformx.device.entity.DeviceDemandPlan;
import com.by4cloud.platformx.device.entity.DeviceDemandSub;
import com.by4cloud.platformx.device.entity.DeviceDemandTotal;
import com.by4cloud.platformx.device.service.DeviceDemandSubService;
import com.by4cloud.platformx.device.service.DeviceDemandTotalService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 设备需求计划项目子表
 *
 * @author pig
 * @date 2025-03-05 14:58:41
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/deviceDemandTotal" )
@Tag(description = "deviceDemandTotal" , name = "设备需求计划项目子表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DeviceDemandTotalController {
 
    private final  DeviceDemandTotalService deviceDemandTotalService;
    private final DeviceDemandSubService deviceDemandSubService;
 
    /**
     * 分页查询
     * @param page 分页对象
     * @param deviceDemandTotal 设备需求计划项目子表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_view')" )
    public R getDeviceDemandTotalPage(@ParameterObject Page page, @ParameterObject DeviceDemandTotal deviceDemandTotal) {
        LambdaQueryWrapper<DeviceDemandTotal> wrapper = Wrappers.lambdaQuery();
        return R.ok(deviceDemandTotalService.page(page, wrapper));
    }
 
 
    /**
     * 通过id查询设备需求计划项目子表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        DeviceDemandTotal demandTotal = deviceDemandTotalService.getById(id);
        QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(DeviceDemandSub::getTotalId,demandTotal.getId());
        List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
        demandTotal.setSubList(list);
        return R.ok(demandTotal);
    }
 
    /**
     * 通过id查询设备需求计划项目子表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/getByPlanId/{id}" )
    public R getByPlanId(@PathVariable("id" ) Long id) {
        QueryWrapper<DeviceDemandTotal> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(DeviceDemandTotal::getPlanId,id);
        return R.ok(deviceDemandTotalService.list(wrapper));
    }
 
 
    /**
     * 新增设备需求计划项目子表
     * @param deviceDemandTotal 设备需求计划项目子表
     * @return R
     */
    @Operation(summary = "新增设备需求计划项目子表" , description = "新增设备需求计划项目子表" )
    @SysLog("新增设备需求计划项目子表" )
    @PostMapping
    public R save(@RequestBody DeviceDemandTotal deviceDemandTotal) {
        if(deviceDemandTotal.getPlanId()==null){
            return R.failed("计划id必传");
        }
        deviceDemandTotalService.save(deviceDemandTotal);
        List<DeviceDemandSub> subList = deviceDemandTotal.getSubList();
        for (DeviceDemandSub deviceDemandSub : subList) {
            deviceDemandSub.setTotalId(deviceDemandTotal.getId());
            deviceDemandSubService.save(deviceDemandSub);
        }
        return R.ok("添加成功");
    }
 
    /**
     * 修改设备需求计划项目子表
     * @param deviceDemandTotal 设备需求计划项目子表
     * @return R
     */
    @Operation(summary = "修改设备需求计划项目子表" , description = "修改设备需求计划项目子表" )
    @SysLog("修改设备需求计划项目子表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_edit')" )
    public R updateById(@RequestBody DeviceDemandTotal deviceDemandTotal) {
        List<DeviceDemandSub> subList = deviceDemandTotal.getSubList();
        QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(DeviceDemandSub::getTotalId,deviceDemandTotal.getId());
        List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
        deviceDemandSubService.removeBatchByIds(list);
        for (DeviceDemandSub deviceDemandSub : subList) {
            deviceDemandSub.setTotalId(deviceDemandTotal.getId());
            deviceDemandSubService.save(deviceDemandSub);
        }
        return R.ok(deviceDemandTotalService.updateById(deviceDemandTotal));
    }
 
    /**
     * 通过id删除设备需求计划项目子表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除设备需求计划项目子表" , description = "通过id删除设备需求计划项目子表" )
    @SysLog("通过id删除设备需求计划项目子表" )
    @GetMapping("/deleteById/{id}")
    public R deleteById(@PathVariable("id" ) Long id) {
        DeviceDemandTotal byId = deviceDemandTotalService.getById(id);
        if(byId != null){
            deviceDemandTotalService.removeById(id);
            QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(DeviceDemandSub::getTotalId,byId.getId());
            List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
            deviceDemandSubService.removeBatchByIds(list);
        }else {
            return R.failed("未查询到该项目");
        }
        return R.ok();
    }
 
//    /**
//     * 通过id删除设备需求计划项目子表
//     * @param ids id列表
//     * @return R
//     */
//    @Operation(summary = "通过id删除设备需求计划项目子表" , description = "通过id删除设备需求计划项目子表" )
//    @SysLog("通过id删除设备需求计划项目子表" )
//    @DeleteMapping
//    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_del')" )
//    public R removeById(@RequestBody Long[] ids) {
//        return R.ok(deviceDemandTotalService.removeBatchByIds(CollUtil.toList(ids)));
//    }
 
 
    /**
     * 导出excel 表格
     * @param deviceDemandTotal 查询条件
        * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_export')" )
    public List<DeviceDemandTotal> export(DeviceDemandTotal deviceDemandTotal,Long[] ids) {
        return deviceDemandTotalService.list(Wrappers.lambdaQuery(deviceDemandTotal).in(ArrayUtil.isNotEmpty(ids), DeviceDemandTotal::getId, ids));
    }
}