package com.bonus.sgzb.material.controller;

import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.Logical;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.base.api.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import com.bonus.sgzb.material.service.RepairTestInputService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author 10488
 * 修试入库
 */
@RestController
@RequestMapping("/RepairTestInput")
public class RepairTestInputController extends BaseController {

    @Resource(name = "RepairTestInputService")
    private RepairTestInputService service;

    @ApiOperation(value = "获取修试后入库列表")
    @GetMapping("getRepairedList")
    @RequiresPermissions("warehousing:repair:list")
    public TableDataInfo getRepairedList(RepairTestInputDto dto){
        startPage();
        List<RepairTestInputVo> list = service.getRepairedList(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取修试后入库列表")
    @PostMapping("getAppRepairedList")
    @RequiresPermissions("warehousing:repair:list")
    public AjaxResult getAppRepairedList(@Validated @RequestBody RepairTestInputDto dto){
        List<RepairTestInputVo> list = service.getRepairedList(dto);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "获取修试后入库列表-详情")
    @GetMapping("getRepairedDetailList")
    @RequiresPermissions(value = {"warehousing:repair:view","warehousing:repair:auditing"}, logical = Logical.OR)
    public TableDataInfo getRepairedDetailList(RepairTestInputDto dto){
        startPage();
        List<RepairTestInputDetailVo> list = service.getRepairedDetailList(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取修试后入库列表-详情")
    @PostMapping("getAppRepairedDetailList")
    @RequiresPermissions(value = {"warehousing:repair:view","warehousing:repair:auditing"}, logical = Logical.OR)
    public AjaxResult getAppRepairedDetailList(@Validated @RequestBody RepairTestInputDto dto){
        List<RepairTestInputDetailVo> list = service.getRepairedDetailList(dto);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "修试后入库-入库操作")
    @PreventRepeatSubmit
    @RequiresPermissions("warehousing:repair:auditing")
    @PostMapping("inputByType")
    public AjaxResult inputByType(@RequestBody RepairTestInputDto dto){
        return service.inputByType(dto);
    }

    /**
     * 修试入库导出
     */
    @ApiOperation("修试入库导出")
    @Log(title = "修试入库导出", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public void export(HttpServletResponse response, RepairTestInputDto bean)
    {
        List<RepairTestInputDetailVo> list = service.exportList(bean);
        ExcelUtil<RepairTestInputDetailVo> util = new ExcelUtil<RepairTestInputDetailVo>(RepairTestInputDetailVo.class);
        util.exportExcel(response, list, "修试入库数据");
    }
}
