mitao
3 天以前 d058d56898cbaa185e5f5ac9294804975084fabf
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
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.dto.asset.AssetInventoryTaskDTO;
import com.ruoyi.system.dto.asset.AssetInventoryTaskItemDTO;
import com.ruoyi.system.dto.asset.AssetInventoryTaskItemUpdateDTO;
import com.ruoyi.system.dto.asset.AssetInventoryUserUpdateDTO;
import com.ruoyi.system.query.AssertInventoryQuery;
import com.ruoyi.system.query.InventoryTaskQuery;
import com.ruoyi.system.service.AssetInventoryTaskService;
import com.ruoyi.system.vo.asset.AssetInventoryTaskDetailVO;
import com.ruoyi.system.vo.asset.AssetInventoryTaskVO;
import com.ruoyi.system.vo.asset.AssetMainInventoryVO;
import com.ruoyi.system.vo.asset.InventoryTaskStatisticsVO;
import com.ruoyi.system.vo.asset.InventoryTaskTabVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.validation.Valid;
import java.util.List;
 
/**
 * <p>
 * 盘点任务表 前端控制器
 * </p>
 *
 * @author WuGuanFengYue
 * @since 2025-09-15
 */
@Slf4j
@Api(tags = {"资产盘点相关接口"})
@Validated
@RestController
@RequestMapping("/asset-inventory-task")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AssetInventoryTaskController {
    private final AssetInventoryTaskService assetInventoryTaskService;
 
    @ApiOperation("资产盘点列表")
    @PostMapping("/page")
    public R<IPage<AssetInventoryTaskVO>> getInventoryTaskPage(@RequestBody AssertInventoryQuery query){
        IPage<AssetInventoryTaskVO> page = assetInventoryTaskService.getInventoryTaskPage(query);
        return R.ok(page);
    }
 
    @ApiOperation("创建盘点任务")
    @PostMapping("/create")
    public R<String> createInventoryTask(@RequestBody @Valid AssetInventoryTaskDTO dto){
        log.info("创建盘点任务,查询参数:{}", dto);
        boolean result = assetInventoryTaskService.createInventoryTask(dto);
        return result ? R.ok("创建成功") : R.fail("创建失败");
    }
 
    @ApiOperation(value ="删除盘点任务")
    @DeleteMapping("/{id}")
    public R<?> deleteById(@ApiParam(name = "id",value = "盘点任务ID",required = true) @PathVariable Integer id){
        assetInventoryTaskService.deleteById(id);
        return R.ok();
    }
 
    @ApiOperation("获取盘点任务选项卡数据")
    @PostMapping("/tab-data")
    public R<List<InventoryTaskTabVO>> getInventoryTaskTabData(){
        try {
            List<InventoryTaskTabVO> data = assetInventoryTaskService.getInventoryTaskTabData();
            log.info("成功获取盘点任务选项卡数据,数量:{}", data.size());
            return R.ok(data);
 
        } catch (Exception e) {
            log.error("获取盘点任务选项卡数据失败", e);
            return R.fail("获取数据失败:" + e.getMessage());
        }
    }
 
    @ApiOperation("获取盘点任务详情")
    @GetMapping("/detail/{id}")
    public R<AssetInventoryTaskDetailVO> getDetail(@ApiParam(name = "id", value = "盘点任务ID") @PathVariable Integer id) {
        return R.ok(assetInventoryTaskService.getDetail(id));
    }
 
    @ApiOperation("根据任务ID获取盘点资产列表(开始盘点页面)")
    @PostMapping("/list-by-task-id")
    public R<IPage<AssetMainInventoryVO>> getListByTaskId(@Valid @RequestBody InventoryTaskQuery query) {
        return R.ok(assetInventoryTaskService.getListByTaskId(query));
    }
 
    @ApiOperation("获取盘点任务统计数据")
    @GetMapping("/statistics/{id}")
    public R<InventoryTaskStatisticsVO> getInventoryTaskStatistics(
            @ApiParam(name = "id", value = "盘点任务ID", required = true)
            @PathVariable Integer id) {
        try {
            InventoryTaskStatisticsVO statistics = assetInventoryTaskService.getInventoryTaskStatistics(id);
            log.info("成功获取盘点任务统计数据,任务ID:{},统计数据:{}", id, statistics);
            return R.ok(statistics);
        } catch (Exception e) {
            log.error("获取盘点任务统计数据失败,任务ID:{}", id, e);
            return R.fail("获取统计数据失败:" + e.getMessage());
        }
    }
 
    @ApiOperation("开始盘点")
    @GetMapping("/start/{id}")
    public R<?> start(@ApiParam(name = "id", value = "盘点任务ID", required = true)
                           @PathVariable Integer id){
        assetInventoryTaskService.start(id);
        return R.ok();
    }
 
    @ApiOperation("修改盘点人")
    @PostMapping("/update-inventory-user")
    public R<String> updateInventoryUser(
            @ApiParam(name = "dto", value = "修改盘点人请求参数", required = true)
            @RequestBody @Valid AssetInventoryUserUpdateDTO dto) {
        log.info("接收到修改盘点人请求,参数:{}", dto);
        assetInventoryTaskService.updateInventoryUser(dto);
        return R.ok("修改成功");
    }
 
    @ApiOperation("盘点结果处理")
    @PostMapping("/result")
    public R<?> handleResult(@Valid @RequestBody List<AssetInventoryTaskItemDTO> dtoList) {
        assetInventoryTaskService.handleResult(dtoList);
        return R.ok();
    }
 
    @ApiOperation("取消盘点")
    @PostMapping("/cancel/{id}")
    public R<?> cancel (@ApiParam(name = "id", value = "盘点任务ID", required = true)
                            @PathVariable Integer id){
        if (assetInventoryTaskService.cancel(id)) {
            return R.ok();
        } else {
            return R.fail("取消失败");
        }
    }
 
    @ApiOperation("保存盘点")
    @PostMapping("/save")
    public R<?> saveInventory(@Valid @RequestBody List<AssetInventoryTaskItemUpdateDTO> dtoList) {
        assetInventoryTaskService.saveInventory(dtoList);
        return R.ok();
    }
}