无关风月
5 天以前 acbe0c6c601ff1368002d701631a43a2c00b61f5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetInventoryTaskController.java
@@ -1,8 +1,37 @@
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>
@@ -12,9 +41,119 @@
 * @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();
    }
}