package com.bonus.material.warehousing.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.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.warehousing.domain.WarehousingEntity;
import com.bonus.material.warehousing.service.WarehousingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/warehousing")
@Api(value = "录入申请", tags = "录入申请")
public class WarehousingController extends BaseController {
    @Resource
    private WarehousingService service;

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


    /**
     * 新增入库记录
     *
     * @param warehousing 入库实体
     * @return 是否成功
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WarehousingEntity warehousing) {
        return service.add(warehousing);
    }

    /**
     * 根据id删除入库记录（逻辑删除）
     *
     * @param id 主键id
     * @return 是否成功
     */
    @PostMapping("/deleteById")
    public AjaxResult deleteById(Integer id) {
        return service.deleteById(id);
    }

    /**
     * 根据id更新入库记录
     *
     * @param warehousing 入库实体
     * @return 是否成功
     */
    @PostMapping("/updateById")
    public AjaxResult updateById(@RequestBody WarehousingEntity warehousing) {
        return service.updateById(warehousing);
    }

    /**
     * 根据id查询入库记录
     *
     * @param id 主键id
     * @return 入库实体
     */
    @GetMapping("/getById")
    public AjaxResult getById(Integer id) {
        return service.getById(id);
    }

    /**
     * 批量提交
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchSubmission/{ids}")
    public AjaxResult batchSubmission(@PathVariable("ids") Integer[] ids) {
        return service.batchSubmission(ids);
    }


    /**
     * 批量提交
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchApproval/{ids}")
    public AjaxResult batchApproval(@PathVariable("ids") Integer[] ids) {
        return service.batchApproval(ids);
    }

    /**
     * 批量提交
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchRejection/{ids}")
    public AjaxResult batchRejection(@PathVariable("ids") Integer[] ids) {
        return service.batchRejection(ids);
    }


    @PostMapping("/getDevDetails")
    public AjaxResult getDevDetails(Integer id) {
        return service.getDevDetails(id);
    }


}
