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.material.domain.ReturnOfMaterialsInfo;
import com.bonus.sgzb.material.service.ReturnOfMaterialsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author lsun
 */
@Api(tags = " 退料入库")
@RestController
@RequestMapping("/returnOfMaterialsInfo")
public class ReturnOfMaterialsInfoController extends BaseController {
    @Autowired
    private ReturnOfMaterialsInfoService returnOfMaterialsInfoService;

    /**
     * 获取机具退料入库列表
     */
    @ApiOperation(value = "获取机具退料入库列表")
    @GetMapping("/getReturnOfMaterialsInfoAll")
    public TableDataInfo getReturnOfMaterialsInfoAll(ReturnOfMaterialsInfo bean) {
        startPage();
        List<ReturnOfMaterialsInfo> list = returnOfMaterialsInfoService.getReturnOfMaterialsInfoAll(bean);
        return getDataTable(list);
    }


    /**
     * 获取设备信息
     */
    @ApiOperation(value = "获取设备信息")
    @GetMapping("/getTypeList")
    public AjaxResult getTypeList(String level) {
        List<ReturnOfMaterialsInfo> list = returnOfMaterialsInfoService.getTypeList(level);
        return AjaxResult.success(list);
    }

    /**
     * 获取设备信息
     */
    @ApiOperation(value = "获取设备类型-app")
    @GetMapping("/getMaTypeList")
    public AjaxResult getMaTypeList(String level) {
        List<ReturnOfMaterialsInfo> list = returnOfMaterialsInfoService.getMaTypeList(level);
        return AjaxResult.success(list);
    }
    /**
     * 获取设备信息
     */
    @ApiOperation(value = "根据设备规格-app")
    @GetMapping("/getInfoListByType")
    public AjaxResult getInfoListByType(String level, String parentId) {
        List<ReturnOfMaterialsInfo> list = returnOfMaterialsInfoService.getInfoListByType(level, parentId);
        return AjaxResult.success(list);
    }

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

}
