package com.bonus.material.toolProcess.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.tool.domain.ToolEntity;
import com.bonus.material.toolProcess.domain.ToolApplyDetailsEntity;
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
import com.bonus.material.toolProcess.service.ToolApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/toolApply")
@Api(value = "工具录入单", tags = "工具录入单")
public class ToolApplyController extends BaseController {
    @Resource
    private ToolApplyService toolApplyService;

    /**
     * 工具申请单表格
     *
     * @param entity 实体
     * @return 表格
     */
    @ApiOperation(value = "工具录入表格")
    @GetMapping("/list")
    public TableDataInfo list(ToolApplyEntity entity) {
        try {
            startPage();
            List<ToolApplyEntity> list = toolApplyService.list(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    /**
     * 工具申请单表格
     *
     * @param entity 实体
     * @return 表格
     */
    @ApiOperation(value = "工具录入表格")
    @GetMapping("/listReview")
    public TableDataInfo listReview(ToolApplyEntity entity) {
        try {
            startPage();
            List<ToolApplyEntity> list = toolApplyService.listReview(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    /**
     * 工具申请单表格
     *
     * @param entity 实体
     * @return 表格
     */
    @ApiOperation(value = "工具录入表格")
    @GetMapping("/listEncoding")
    public TableDataInfo listEncoding(ToolApplyDetailsEntity entity) {
        try {
            startPage();
            List<ToolApplyDetailsEntity> list = toolApplyService.listEncoding(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    /**
     * 工具录入新增
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ToolApplyEntity entity) {
        return toolApplyService.add(entity);
    }

    /**
     * 工具录入删除
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ToolApplyEntity entity) {
        return toolApplyService.delete(entity);
    }


    /**
     * 工具录入删除
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入删除")
    @PostMapping("/deleteDetail")
    public AjaxResult delete(@RequestBody ToolApplyDetailsEntity entity) {
        return toolApplyService.deleteDetail(entity);
    }


    /**
     * 工具录入删除
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入删除")
    @PostMapping("/deleteTool")
    public AjaxResult deleteTool(Integer id) {
        return toolApplyService.deleteTool(id);
    }


    /**
     * 工具录入申请单表格
     *
     * @param entity 实体
     * @return 表格
     */
    @ApiOperation(value = "工具录入申请单表格")
    @GetMapping("/listByApplyId")
    public TableDataInfo listByApplyId(ToolApplyDetailsEntity entity) {
        try {
            startPage();
            List<ToolApplyDetailsEntity> list = toolApplyService.listByApplyId(entity);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    /**
     * 工具录入申请单表格
     *
     * @param entity 实体
     * @return 表格
     */
    @ApiOperation(value = "工具录入申请单表格")
    @GetMapping("/listWarehousingToolByApplyId")
    public AjaxResult listWarehousingToolByApplyId(ToolApplyDetailsEntity entity) {
        return toolApplyService.listWarehousingToolByApplyId(entity);
    }

    /**
     * 工具录入新增
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入新增")
    @PostMapping("/addDetail")
    public AjaxResult addDetail(@RequestBody List<ToolApplyDetailsEntity> entity) {
        return toolApplyService.addDetail(entity);
    }


    /**
     * 工具录入新增
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入修改")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody ToolApplyEntity entity) {
        return toolApplyService.update(entity);
    }


    /**
     * 工具录入新增
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入修改")
    @PostMapping("/updateDetail")
    public AjaxResult updateDetail(@RequestBody ToolApplyDetailsEntity entity) {
        return toolApplyService.updateDetail(entity);
    }


    /**
     * 工具录入新增
     *
     * @param entity 实体
     * @return 结果
     */
    @ApiOperation(value = "工具录入修改")
    @PostMapping("/updateAllDetail")
    public AjaxResult updateAllDetail(@RequestBody ToolApplyDetailsEntity entity) {
        return toolApplyService.updateAllDetail(entity);
    }


    /**
     * 工具类型树
     *
     * @param entity 实体
     * @return 树结构
     */
    @ApiOperation(value = "工具类型树")
    @GetMapping("/getTreeSelect")
    public AjaxResult getTreeSelect(ToolEntity entity) {
        return toolApplyService.getTreeSelect(entity);
    }


}
