package com.bonus.zlpt.equip.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.log.annotation.Log;
import com.bonus.zlpt.common.log.enums.BusinessType;
import com.bonus.zlpt.common.security.annotation.RequiresPermissions;

import com.bonus.zlpt.equip.api.domain.UpOff;
import com.bonus.zlpt.equip.api.domain.dto.UpOffDto;
import com.bonus.zlpt.equip.api.domain.vo.DevInfoVo;
import com.bonus.zlpt.equip.api.domain.vo.MaDevInfoVo;
import io.swagger.annotations.Api;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.zlpt.equip.service.IUpOffService;

/**
 * 设备上下架管理
Controller
 * 
 * @author xsheng
 * @date 2023-12-02
 */
@Api(tags = "装备上下架接口")
@RestController
@RequestMapping("/off")
public class UpOffController extends BaseController
{
    @Autowired
    private IUpOffService upOffService;




    /**
     * 查询设备上下架管理
列表
     */
    @RequiresPermissions("equip:off:list")
    @GetMapping("/list")
    public TableDataInfo list(UpOff upOff)
    {
        startPage();
        List<UpOff> list = upOffService.selectUpOffList(upOff);
        return getDataTable(list);
    }

    /**
     * 设备上下架审批管理
     * @return
     */
    @PostMapping("/selectList")
    public TableDataInfo selectList(@RequestBody UpOffDto upOffDto){

        startPage();
        List<MaDevInfoVo> devInfoVos = upOffService.selectList(upOffDto);
        return getDataTable(devInfoVos);

    }


    /**
     * 审批获取详细数据
     * @return
     */
    @PostMapping("/selectInfo")
    public AjaxResult selectInfo(@RequestBody List<Long> ids){

        return success(upOffService.selectInfo(ids));
    }

    /**
     * 导出设备上下架管理
列表
     */
    @RequiresPermissions("equip:off:export")
    @Log(title = "设备上下架管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpOff upOff)
    {
        List<UpOff> list = upOffService.selectUpOffList(upOff);
        ExcelUtil<UpOff> util = new ExcelUtil<UpOff>(UpOff.class);
        util.exportExcel(response, list, "设备上下架管理数据");
    }

    /**
     * 获取设备上下架管理
详细信息
     */
    @RequiresPermissions("equip:off:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(upOffService.selectUpOffById(id));
    }

    /**
     * 新增设备上下架管理

     */
 //   @RequiresPermissions("equip:off:add")
    @Log(title = "设备上下架管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<UpOff> upOffList)
    {
        if (upOffList.size()==0){
            return warn("传入参数为空！");
        }
        return toAjax(upOffService.insertUpOff(upOffList));
    }

    /**
     * 修改设备上下架管理

     */
    //@RequiresPermissions("equip:off:edit")
    @Log(title = "设备上下架管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpOff upOff)
    {
        return toAjax(upOffService.updateUpOff(upOff));
    }

    /**
     * 删除设备上下架管理

     */
 //   @RequiresPermissions("equip:off:remove")
    @Log(title = "设备上下架管理", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public AjaxResult remove(@RequestBody  Long[] ids)
    {
        return toAjax(upOffService.deleteUpOffByIds(ids));
    }

    /**
     * 商品批量上下架
     * @param upOffList
     * @return
     */
    @Log(title = "设备上下架管理", businessType = BusinessType.INSERT)
    @PostMapping("/upOffList")
    public AjaxResult upOffList(@RequestBody List<UpOff> upOffList)
    {
        if (upOffList.size()==0){
            return warn("传入参数为空！");
        }
        return toAjax(upOffService.UpdateUpOffLIst(upOffList));
    }


}
