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

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.bonus.canteen.core.device.domain.ApkDTO;
import com.bonus.common.log.enums.OperaType;
//import com.bonus.canteen.core.device.common.annotation.PreventRepeatSubmit;
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.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.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.canteen.core.device.domain.DeviceAppVersion;
import com.bonus.canteen.core.device.service.IDeviceAppVersionService;
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_app_version")
public class DeviceAppVersionController extends BaseController {
    @Autowired
    private IDeviceAppVersionService deviceAppVersionService;

    /**
     * 查询版本列表
     */
    @ApiOperation(value = "查询版本列表")
    //@RequiresPermissions("device:version:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceAppVersion deviceAppVersion) {
        startPage();
        List<DeviceAppVersion> list = deviceAppVersionService.selectDeviceAppVersionList(deviceAppVersion);
        return getDataTable(list);
    }

    /**
     * 导出版本列表
     */
    @ApiOperation(value = "导出版本列表")
    //@PreventRepeatSubmit
    //@RequiresPermissions("device:version:export")
    @SysLog(title = "版本", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出版本")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceAppVersion deviceAppVersion) {
        List<DeviceAppVersion> list = deviceAppVersionService.selectDeviceAppVersionList(deviceAppVersion);
        ExcelUtil<DeviceAppVersion> util = new ExcelUtil<DeviceAppVersion>(DeviceAppVersion.class);
        util.exportExcel(response, list, "版本数据");
    }

    /**
     * 获取版本详细信息
     */
    @ApiOperation(value = "获取版本详细信息")
    //@RequiresPermissions("device:version:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(deviceAppVersionService.selectDeviceAppVersionById(id));
    }

    /**
     * 新增版本
     */
    @ApiOperation(value = "新增版本")
    @SysLog(title = "版本", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增版本")
    @PostMapping
    public AjaxResult add(@RequestBody DeviceAppVersion deviceAppVersion) {
        try {
            return toAjax(deviceAppVersionService.insertDeviceAppVersion(deviceAppVersion));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改版本
     */
    @ApiOperation(value = "修改版本")
    //@PreventRepeatSubmit
    //@RequiresPermissions("device:version:edit")
    @SysLog(title = "版本", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改版本")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody DeviceAppVersion deviceAppVersion) {
        try {
            return toAjax(deviceAppVersionService.updateDeviceAppVersion(deviceAppVersion));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除版本
     */
    @ApiOperation(value = "删除版本")
    //@PreventRepeatSubmit
    //@RequiresPermissions("device:version:remove")
    @SysLog(title = "版本", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除版本")
	@PostMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(deviceAppVersionService.deleteDeviceAppVersionByIds(ids));
    }


    @ApiOperation(value = "上传APK")
    @PostMapping({"/uploadApk"})
    public AjaxResult uploadApk(@RequestBody @Valid ApkDTO dto) {
        return this.deviceAppVersionService.uploadApk(dto);
    }
}
