package com.bonus.material.back.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.back.domain.BackCsDeviceDetails;
import com.bonus.material.back.domain.BackCsDeviceInfo;
import com.bonus.material.back.domain.BackCsDeviceVo;
import com.bonus.material.back.service.BackChangeService;
import com.bonus.material.devchange.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * 装备退库
 * @author ma_sh
 */
@RestController
@RequestMapping("/backChange")
@Api(value = "装备退库", tags = "装备退库")
@Slf4j
public class BackChangeController extends BaseController {

    @Resource
    private BackChangeService service;
    /**
     * 获取添加设备详情
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取添加设备详情")
    @GetMapping("/getDevDetailsInfo")
    public AjaxResult getDevDetailsInfo(BackCsDeviceDetails dto) {
        List<BackCsDeviceDetails> list = service.getDevDetailsInfo(dto);
        return AjaxResult.success(list);
    }

    /**
     * 新增退库申请
     *
     * @param csDeviceVo
     * @return
     */
    @ApiOperation(value = "新增退库申请")
    @PostMapping("/addDevDetails")
    public AjaxResult addDevDetails(@RequestBody BackCsDeviceVo csDeviceVo) {
        return service.addDevDetails(csDeviceVo);
    }

    /**
     * 修改退库申请
     *
     * @param csDeviceVo
     * @return
     */
    @ApiOperation(value = "修改退库申请")
    @PostMapping("/updateDevDetails")
    public AjaxResult updateDevDetails(@RequestBody BackCsDeviceVo csDeviceVo) {
        return service.updateDevDetails(csDeviceVo);
    }

    /**
     * 删除退库申请
     *
     * @param csDeviceInfo
     * @return
     */
    @ApiOperation(value = "删除退库申请")
    @PostMapping("/deleteDevDetails")
    public AjaxResult deleteDevDetails(@RequestBody BackCsDeviceInfo csDeviceInfo) {
        return service.deleteDevDetails(csDeviceInfo);
    }

    /**
     * 获取设备详情
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取设备详情")
    @GetMapping("/getDevDetailsById")
    public AjaxResult getDevDetailsById(BackCsDeviceDetails dto) {
        try {
            BackCsDeviceVo devInfo = service.getDevDetailsById(dto);
            return AjaxResult.success(devInfo);
        } catch (Exception e) {
            log.error("查询失败，请联系管理员:{}", e.getMessage());
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

    /**
     * 获取申请一级列表
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取申请一级列表")
    @GetMapping("/getList")
    public AjaxResult getList(BackCsDeviceInfo dto) {
        try {
            startPage();
            List<BackCsDeviceInfo> list = service.getList(dto);
            return AjaxResult.success(getDataTable(list));
        } catch (Exception e) {
            log.error("查询失败，请联系管理员:{}", e.getMessage());
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

    /**
     * 退库审核
     *
     * @return
     */
    @ApiOperation(value = "退库审核")
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody BackCsDeviceDetails backCsDeviceDetails) {
        return service.approve(backCsDeviceDetails);
    }

}
