package com.bonus.zlpt.equip.controller;

import java.util.List;
import java.util.Map;

import com.bonus.zlpt.equip.api.domain.DevInfo;
import com.bonus.zlpt.equip.api.domain.dto.InforMationDto;
import com.bonus.zlpt.equip.api.domain.vo.DevInfoVo;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import com.bonus.zlpt.equip.service.IDevInfoService;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;

/**
 * 设备信息Controller
 *
 * @author xsheng
 * @date 2023-12-02
 */
@RestController
@RequestMapping("/dev")
@Api(value = "设备信息",tags = "设备管理")
public class DevInfoController extends BaseController
{
    @Autowired
    private IDevInfoService devInfoService;

    /**
     * 查询设备信息列表
     */
    //@RequiresPermissions("equip:info:list")
    @ApiOperation(value = "装备列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody DevInfoVo devInfo)
    {
        startPage(devInfo.getPageNum(), devInfo.getPageSize());
        List<DevInfoVo> list = devInfoService.selectDevInfoList(devInfo);
        return getDataTable(list);
    }

    @RequiresPermissions("equip:info:list")
    @ApiOperation(value = "装备推荐列表")
    @GetMapping("/hotList")
    public TableDataInfo hotList(DevInfoVo devInfo)
    {
        startPage(devInfo.getPageNum(),devInfo.getPageSize());
        List<DevInfoVo> list = devInfoService.selectDevInfoHotList(devInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备信息列表
     */
    @RequiresPermissions("equip:info:export")
    @ApiOperation(value = "导出装备信息")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevInfoVo devInfo)
    {
        List<DevInfoVo> list = devInfoService.selectDevInfoList(devInfo);
        ExcelUtil<DevInfoVo> util = new ExcelUtil<DevInfoVo>(DevInfoVo.class);
        util.exportExcel(response, list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @RequiresPermissions("equip:info:query")
    @ApiOperation(value = "装备详情")
    @GetMapping(value = "/{maId}")
    public AjaxResult getInfo(@PathVariable("maId") Long maId)
    {
        return success(devInfoService.selectDevInfoByMaId(maId));
    }

    /**
     * 新增设备信息
     */
    //@RequiresPermissions("equip:info:add")
    @ApiOperation(value = "新增装备")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevInfo devInfo)
    {
        return toAjax(devInfoService.insertDevInfo(devInfo));
    }

    /**
     * 修改设备信息
     */
    @RequiresPermissions("equip:info:edit")
    @ApiOperation(value = "更新装备")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevInfo devInfo)
    {
        return toAjax(devInfoService.updateDevInfo(devInfo));
    }

    /**
     * 删除设备信息
     */
    @RequiresPermissions("equip:info:remove")
    @ApiOperation(value = "删除装备")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public AjaxResult remove(@RequestBody Long[] maIds)
    {
        return toAjax(devInfoService.deleteDevInfoByMaIds(maIds));
    }


    /**
     * 设备信息录入
     * @param inforMationDto
     * @return
     */
    @ApiOperation(value = "装备信息录入")
    @PostMapping("/insertInforMationDto")
    public AjaxResult insertInforMationDto(@RequestBody InforMationDto inforMationDto)
    {
        return toAjax(devInfoService.insertInforMationDto(inforMationDto));
    }


    /**
     * 统计装备
     * @return
     */
    @ApiOperation(value = "装备统计")
    @GetMapping("/sumType")
    public AjaxResult sumType()
    {
        Map<String, Integer> sumType =devInfoService.sumType();
        return success(sumType);
    }
}
