package com.xiaoniu.subsystem.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xiaoniu.common.core.result.R;
import com.xiaoniu.common.core.utils.BeanUtil;
import com.xiaoniu.subsystem.business.domain.DemandTotal;
import com.xiaoniu.subsystem.business.domain.Expense;
import com.xiaoniu.subsystem.business.domain.dto.DemandTotalPageDTO;
import com.xiaoniu.subsystem.business.domain.vo.DemandTotalVO;
import com.xiaoniu.subsystem.business.domain.vo.ExpenseVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.xiaoniu.subsystem.business.service.IDemandTotalService;

import java.util.Arrays;

/**
 * 需求报名统计管理表 控制器
 *
 * @author sunsongtao
 * @since 2024-12-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/demand/total")
@Tag(name = "需求报名统计管理表", description = "需求报名统计管理表接口")
public class DemandTotalController {

    private IDemandTotalService demandTotalService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @Operation(summary = "详情", description = "传入demandTotal")
    public R<DemandTotalVO> detail(@Parameter(description = "主键", required = true) @RequestParam Long expenseId) {
        DemandTotal detail = demandTotalService.getById(expenseId);
        return R.data(BeanUtil.copy(detail, DemandTotalVO.class));
    }

    /**
     * 分页 需求报名统计管理表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @Operation(summary = "分页", description = "传入demandTotal")
    public R<IPage<DemandTotalVO>>list(DemandTotalPageDTO dto){
        IPage<DemandTotal> pages=  demandTotalService.page(new Page<>(dto.getPageNum(), dto.getPageSize()),
                new LambdaQueryWrapper<DemandTotal>(BeanUtil.copy(dto,DemandTotalVO.class)));
        return R.data(BeanUtil.copy(pages, DemandTotalVO.class));
    }


    /**
     * 新增 需求报名统计管理表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @Operation(summary = "新增", description = "传入demandTotal")
    public R save(@Valid @RequestBody DemandTotal demandTotal){
        return R.status(demandTotalService.save(demandTotal));
    }

    /**
     * 修改 需求报名统计管理表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @Operation(summary = "修改", description = "传入demandTotal")
    public R update(@Valid @RequestBody DemandTotal demandTotal){
        return R.status(demandTotalService.updateById(demandTotal));
    }

    /**
     * 新增或修改 需求报名统计管理表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @Operation(summary = "新增或修改", description = "传入demandTotal")
    public R submit(@Valid @RequestBody DemandTotal demandTotal){
        return R.status(demandTotalService.saveOrUpdate(demandTotal));
    }

    
    /**
     * 删除 需求报名统计管理表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @Operation(summary = "逻辑删除", description = "传入ids")
    public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids){
        return R.status(demandTotalService.removeByIds(Arrays.stream(ids.split(",")).toList()));
    }

    
}
