package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsMaterialsCheckPlan;
import com.ktg.iscs.domain.IsMaterialsPlanCabinet;
import com.ktg.iscs.domain.dto.checkPlan.AddCheckPlanDTO;
import com.ktg.iscs.domain.dto.plan.PlanDTO;
import com.ktg.iscs.service.IIsMaterialsCheckPlanService;
import com.ktg.iscs.service.IIsMaterialsPlanCabinetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物资检查计划Controller
 *
 * @author cgj
 * @date 2025-01-14
 */
@Api(tags = "物资检查计划")
@RestController
@RequestMapping("/iscs/plan")
public class IsMaterialsCheckPlanController extends BaseController
{
    @Autowired
    private IIsMaterialsCheckPlanService isMaterialsCheckPlanService;
    @Autowired
    private IIsMaterialsPlanCabinetService iIsMaterialsPlanCabinetService;

    @ApiOperation("查询物资检查计划-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsCheckPlan", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:plan:list')")
    @GetMapping("/getIsMaterialsCheckPlanPage")
    public CommonResult<Page<IsMaterialsCheckPlan>> getIsMaterialsCheckPlanPage(Page<IsMaterialsCheckPlan> page, PlanDTO dto)
    {
        Page<IsMaterialsCheckPlan> result = isMaterialsCheckPlanService.getIsMaterialsCheckPlanPage(page, dto);
        return CommonResult.success(result);
    }

    @ApiOperation("查询物资检查计划柜子签名")
    @PreAuthorize("@ss.hasPermi('iscs:plan:list')")
    @GetMapping("/getCheckPlanCabinetList")
    public CommonResult<List<IsMaterialsPlanCabinet>> getCheckPlanCabinetList(IsMaterialsPlanCabinet dto)
    {
        List<IsMaterialsPlanCabinet> result = iIsMaterialsPlanCabinetService.getCheckPlanCabinetList(dto);
        return CommonResult.success(result);
    }

    @ApiOperation("导出物资检查计划列表")
    @Parameter(name = "isMaterialsCheckPlan", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:plan:export')")
    @Log(title = "物资检查计划", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsCheckPlan")
    public void exportIsMaterialsCheckPlan(HttpServletResponse response, IsMaterialsCheckPlan isMaterialsCheckPlan)
    {
        Page<IsMaterialsCheckPlan> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsMaterialsCheckPlan> list = isMaterialsCheckPlanService.page(page, Wrappers.<IsMaterialsCheckPlan>lambdaQuery()
                .orderByDesc(IsMaterialsCheckPlan::getPlanId)).getRecords();
        ExcelUtil<IsMaterialsCheckPlan> util = new ExcelUtil<IsMaterialsCheckPlan>(IsMaterialsCheckPlan.class);
        util.exportExcel(response, list, "物资检查计划数据");
    }

    @ApiOperation("获取物资检查计划详细信息")
    @Parameter(name = "planId", description = "planId")
    @PreAuthorize("@ss.hasPermi('iscs:plan:query')")
    @GetMapping(value = "/selectIsMaterialsCheckPlanById")
    public CommonResult<IsMaterialsCheckPlan> selectIsMaterialsCheckPlanById(Long planId)
    {
        return CommonResult.success(isMaterialsCheckPlanService.selectIsMaterialsCheckPlanById(planId));
    }

    @ApiOperation("新增物资检查计划")
    @PreAuthorize("@ss.hasPermi('iscs:plan:add')")
    @Log(title = "物资检查计划", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMaterialsCheckPlan")
    public CommonResult<Boolean> insertIsMaterialsCheckPlan(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") AddCheckPlanDTO dto)
    {
        return CommonResult.success(isMaterialsCheckPlanService.insertIsMaterialsCheckPlan(dto));
    }

    @ApiOperation("修改物资检查计划")
    @PreAuthorize("@ss.hasPermi('iscs:plan:edit')")
    @Log(title = "物资检查计划", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsCheckPlan")
    public CommonResult<Boolean> updateIsMaterialsCheckPlan(@RequestBody @Parameter(name = "dto", description = "修改数据类,放到body") AddCheckPlanDTO dto)
    {
        return CommonResult.success(isMaterialsCheckPlanService.updateIsMaterialsCheckPlan(dto));
    }

    @ApiOperation("删除物资检查计划")
    @PreAuthorize("@ss.hasPermi('iscs:plan:remove')")
    @Log(title = "物资检查计划", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsCheckPlanByPlanIds")
    public CommonResult<Boolean> deleteIsMaterialsCheckPlanByPlanIds(String planIds)
    {
        return CommonResult.success(isMaterialsCheckPlanService.deleteIsMaterialsCheckPlanByPlanIds(planIds));
    }

}
