package com.bonus.material.basic.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.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.basic.domain.BmAssetAttributes;
import com.bonus.material.basic.service.BmAssetAttributesService;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 资产属性表(BmAssetAttributes)表控制层
 *
 * @author makejava
 * @since 2024-10-15 10:38:58
 */
@Api(tags = "资产属性管理接口")
@RestController
@RequestMapping("/bm_asset_attributes")
public class BmAssetAttributesController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private BmAssetAttributesService bmAssetAttributesService;

    /**
     * 分页查询
     *
     * @param bmAssetAttributes 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "查询资产属性管理列表")
    @RequiresPermissions("basic:asset:list")
    @GetMapping("/list")
    public AjaxResult queryByPage(BmAssetAttributes bmAssetAttributes) {
        //判断是否分页，用于下拉选
        if (bmAssetAttributes.getIsAll() != null) {
            return AjaxResult.success(bmAssetAttributesService.queryByPage(bmAssetAttributes));
        }
        startPage();
        List<BmAssetAttributes> list = bmAssetAttributesService.queryByPage(bmAssetAttributes);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "查询资产属性管理详细信息")
    @RequiresPermissions("basic:asset:query")
    @GetMapping("/{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return AjaxResult.success(bmAssetAttributesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param bmAssetAttributes 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增资产属性")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:asset:add")
    @SysLog(title = "资产属性管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增资产属性管理")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BmAssetAttributes bmAssetAttributes) {
        return bmAssetAttributesService.insert(bmAssetAttributes);
    }

    /**
     * 编辑数据
     *
     * @param bmAssetAttributes 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "修改资产属性")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:asset:edit")
    @SysLog(title = "资产属性管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->修改资产属性管理")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BmAssetAttributes bmAssetAttributes) {
        return bmAssetAttributesService.update(bmAssetAttributes);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "删除资产属性")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:asset:remove")
    @SysLog(title = "资产属性管理", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除资产属性管理")
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id) {
        return bmAssetAttributesService.deleteById(id);
    }

    /**
     * 导出资产属性管理列表
     */
    @ApiOperation(value = "导出资产属性管理列表")
    @PreventRepeatSubmit
    @RequiresPermissions("basic:asset:export")
    @SysLog(title = "资产属性管理", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出资产属性管理")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmAssetAttributes bmAssetAttributes)
    {
        List<BmAssetAttributes> list = bmAssetAttributesService.queryByPage(bmAssetAttributes);
        ExcelUtil<BmAssetAttributes> util = new ExcelUtil<BmAssetAttributes>(BmAssetAttributes.class);
        util.exportExcel(response, list, "资产属性管理数据");
    }

}

