package com.bonus.canteen.core.device.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.device.domain.DeviceSearchDTO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.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.common.log.annotation.SysLog;
import com.bonus.canteen.core.device.domain.DeviceInfo;
import com.bonus.canteen.core.device.service.IDeviceInfoService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 设备资料Controller
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Api(tags = "设备资料接口")
@RestController
@RequestMapping("/device_info")
public class DeviceInfoController extends BaseController {
    @Resource
    private IDeviceInfoService deviceInfoService;

    /**
     * 查询设备资料列表
     */
    @ApiOperation(value = "查询设备资料列表")
    @GetMapping("/list")
    public TableDataInfo list(DeviceInfo deviceInfo) {
        startPage();
        List<DeviceInfo> list = deviceInfoService.selectDeviceInfoList(deviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备资料列表
     */
    @ApiOperation(value = "导出设备资料列表")
    @SysLog(title = "设备资料", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出设备资料")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceInfo deviceInfo) {
        List<DeviceInfo> list = deviceInfoService.selectDeviceInfoList(deviceInfo);
        ExcelUtil<DeviceInfo> util = new ExcelUtil<DeviceInfo>(DeviceInfo.class);
        util.exportExcel(response, list, "设备资料数据");
    }

    /**
     * 获取设备资料详细信息
     */
    @ApiOperation(value = "获取设备资料详细信息")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
        return success(deviceInfoService.selectDeviceInfoByDeviceId(deviceId));
    }

    /**
     * 新增设备资料
     */
    @ApiOperation(value = "新增设备资料")
    @SysLog(title = "设备资料", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增设备资料")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DeviceInfo deviceInfo) {
        try {
            return toAjax(deviceInfoService.insertDeviceInfo(deviceInfo));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改设备资料
     */
    @ApiOperation(value = "修改设备资料")
    @SysLog(title = "设备资料", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改设备资料")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody DeviceInfo deviceInfo) {
        try {
            return toAjax(deviceInfoService.updateDeviceInfo(deviceInfo));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除设备资料
     */
    @ApiOperation(value = "删除设备资料")
    @SysLog(title = "设备资料", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除设备资料")
	@PostMapping("/del/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds) {
        return toAjax(deviceInfoService.deleteDeviceInfoByDeviceIds(deviceIds));
    }


}
