package com.bonus.material.devchange.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
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.devchange.domain.*;
import com.bonus.material.devchange.service.DevChangeService;

import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/decChange")
@Api(value = "设备台账", tags = "设备台账")
public class DevChangeController extends BaseController {

    @Autowired
    private DevChangeService service;

    @ApiOperation(value = "查询系统最大的特征值")
    @PostMapping("/getMaxFeature")
    public AjaxResult getMaxFeature() {
        return service.getMaxFeature();
    }


    @ApiOperation(value = "出库设备列表")
    @GetMapping("/list")
    public TableDataInfo devList(DevChangeVo vo) {
        startPage();
        List<DevChangeVo> list = service.selectDevInfoList(vo);
        return getDataTable(list);
    }

    /**
     * 查询在库 的status =1
     * status =0 出库
     * status=4退役
     * <p>
     * 5 维修
     *
     * @param vo
     * @return
     */
    @ApiOperation(value = "查询工程下拉选集合")
    @PostMapping("/getProList")
    public AjaxResult list(@RequestBody JjProjectVo vo) {
        List<JjProjectVo> list = service.getProList(vo);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "查询工程下拉选集合")
    @PostMapping("/getVoltageLevel")
    public AjaxResult getVoltageLevel(@RequestBody JjProjectVo vo) {
        List<Map<String, Object>> list = service.getVoltageLevel(vo);
        return AjaxResult.success(list);
    }


    @ApiOperation(value = "新增出库")
    @PostMapping("/addChangeInfo")
    public AjaxResult addChangeInfo(@RequestBody CsDeviceChangeVo vo) {
        return service.addChangeInfo(vo);
    }


    @ApiOperation(value = "入库和维修")
    @PostMapping("/updateDevChangeInfo")
    public AjaxResult updateDevChangeInfo(@RequestBody CsDeviceChangeVo vo) {
        return service.updateDevChangeInfo(vo);
    }

    @ApiOperation(value = "入库、报废")
    @PostMapping("/updateDevChangeInfo2")
    public AjaxResult updateDevChangeInfo2(@RequestBody CsDeviceChangeVo vo) {
        return service.updateDevChangeInfo2(vo);
    }

    @ApiOperation(value = "入库、报废")
    @PostMapping("/updateDevChangeInfo3")
    public AjaxResult updateDevChangeInfo3(@RequestBody CsDeviceChangeVo vo) {
        return service.updateDevChangeInfo3(vo);
    }


    @ApiOperation(value = "导出设备流转台账")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsDeviceChangeVo vo) {
        List<CsDeviceChangeVo> list = service.getDevChangeList(vo);
        ExcelUtil<CsDeviceChangeVo> util = new ExcelUtil<CsDeviceChangeVo>(CsDeviceChangeVo.class);
        util.exportExcel(response, list, "设备流转台账");
    }

    @ApiOperation(value = "导出设备流转台账")
    @PostMapping("/exportR")
    public void exportR(HttpServletResponse response, CsDeviceChange csDeviceChange) {
        List<CsDeviceChange> list = service.getDevChangeRList(csDeviceChange);
        ExcelUtil<CsDeviceChange> util = new ExcelUtil<CsDeviceChange>(CsDeviceChange.class);
        util.exportExcel(response, list, "设备流转台账");
    }


    @ApiOperation(value = "设备流转台账记录")
    @GetMapping("/getDevChangeList")
    public TableDataInfo getDevChangeList(CsDeviceChangeVo vo) {
        startPage();
        List<CsDeviceChangeVo> list = service.getDevChangeList(vo);
        return getDataTable(list);
    }

    @ApiOperation(value = "导出设备流转台账详情")
    @PostMapping("/exportDetails")
    public void exportDetails(HttpServletResponse response, CsDeviceChangeDetailsVo vo) {
        List<DevChangeVo> list = service.getDevDetails(vo);
        ExcelUtil<DevChangeVo> util = new ExcelUtil<DevChangeVo>(DevChangeVo.class);
        util.exportExcel(response, list, "导出设备流转台账详情");
    }

    @ApiOperation(value = "导出设备流转台账详情")
    @PostMapping("/exportDetailsRetire")
    public void exportDetailsRetire(HttpServletResponse response, CsDeviceChangeDetailsVo vo) {
        List<DevChangeVo> list = service.getDevDetails(vo);
        ExcelUtil<DevChangeVo> util = new ExcelUtil<DevChangeVo>(DevChangeVo.class);
        util.exportExcel(response, list, "导出设备流转台账详情");
    }


    @ApiOperation(value = "导出设备流转台账详情")
    @PostMapping("/exportDetailsRepair")
    public void exportDetailsRepair(HttpServletResponse response, CsDeviceChangeDetailsVo vo) {
        List<DevChangeVo> list = service.getDevDetails(vo);
        ExcelUtil<DevChangeVo> util = new ExcelUtil<DevChangeVo>(DevChangeVo.class);
        util.exportExcel(response, list, "导出设备流转台账详情");
    }

    @ApiOperation(value = "出库记录单")
    @PostMapping("/getDevDetails")
    public AjaxResult getDevDetails(@RequestBody CsDeviceChangeDetailsVo vo) {
        return AjaxResult.success(service.getDevDetails(vo));
    }

    /**
     * 获取添加设备详情
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取添加设备详情")
    @GetMapping("/getDevDetailsInfo")
    public AjaxResult getDevDetailsInfo(CsDeviceDetails dto) {
        try {
            startPage();
            List<CsDeviceDetails> list = service.getDevDetailsInfo(dto);
            return AjaxResult.success(getDataTable(list));
        } catch (Exception e) {
            logger.error("获取添加设备详情异常:{}", e.getMessage());
            return AjaxResult.error("查询失败，请联系管理员");
        }
    }

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

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

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

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


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

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

    /**
     * 自用审核
     *
     * @param csDeviceInfo
     * @return
     */
    @ApiOperation(value = "自用审核")
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody CsDeviceInfo csDeviceInfo) {
        return service.approve(csDeviceInfo);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/out")
    public AjaxResult out(@RequestBody CsDeviceDetails entity) {
        return service.out(entity);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/orderOut")
    public AjaxResult orderOut(@RequestBody CsDeviceDetails entity) {
        return service.orderOut(entity);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/outAll")
    public AjaxResult outAll(@RequestBody CsDeviceDetails entity) {
        return service.outAll(entity);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/orderOutAll")
    public AjaxResult orderOutAll(@RequestBody CsDeviceDetails entity) {
        return service.orderOutAll(entity);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/orderOutCancel")
    public AjaxResult orderOutCancel(@RequestBody CsDeviceDetails entity) {
        return service.orderOutCancel(entity);
    }



    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/outCancel")
    public AjaxResult outCancel(@RequestBody CsDeviceDetails entity) {
        return service.outCancel(entity);
    }


    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/orderOutCancelAll")
    public AjaxResult orderOutCancelAll(@RequestBody CsDeviceDetails entity) {
        return service.orderOutCancelAll(entity);
    }

    /**
     * 审核出库
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "审核出库")
    @PostMapping("/outCancelAll")
    public AjaxResult outCancelAll(@RequestBody CsDeviceDetails entity) {
        return service.outCancelAll(entity);
    }


    @ApiOperation(value = "获取申请一级列表")
    @GetMapping("/getOutboundList")
    public TableDataInfo getOutboundList(CsDeviceInfo dto) {
        try {
            startPage();
            List<CsDeviceInfo> list = service.getOutboundList(dto);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


}
