package com.zd.airbottle.controller;

import com.zd.airbottle.domain.QpSpecification;
import com.zd.airbottle.domain.dto.QpSpecificationDto;
import com.zd.airbottle.domain.vo.QpSpecificationVo;
import com.zd.airbottle.service.IQpSpecificationService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 气瓶规格Controller
 *
 * @author zd
 * @date 2022-05-09
 */
@RestController
@Api(tags = "【气瓶规格】")
@RequestMapping("/specification")
public class QpSpecificationController extends BaseController<QpSpecification> {
    @Autowired
    private IQpSpecificationService qpSpecificationService;

    /**
     * 查询气瓶规格列表
     */
    @PreAuthorize(hasPermi = "airbottle:specification:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询气瓶规格列表")
    public TableDataInfo<QpSpecificationVo> list(QpSpecification qpSpecification) {
        startPage();
        List<QpSpecification> qpSpecifications = qpSpecificationService.selectQpSpecificationList(qpSpecification);
        TableDataInfo<QpSpecification> dataTable = getDataTable(qpSpecifications);
        TableDataInfo<QpSpecificationVo> dataInfo=new TableDataInfo<>();
        BeanUtils.copyProperties(dataTable,dataInfo);
        if (!qpSpecifications.isEmpty()){
            dataInfo.setRows(qpSpecificationService.list(qpSpecifications));
        }
        return dataInfo;
    }

    /**
     * 获取气瓶规格详细信息
     */
    @ApiOperation(value = "获取气瓶规格详细信息")
    @PreAuthorize(hasPermi = "airbottle:specification:query")
    @GetMapping(value = "/{id}")
    public ResultData<QpSpecificationVo> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(qpSpecificationService.getById(id));
    }

    /**
     * 新增气瓶规格
     */
    @ApiOperation(value = "新增气瓶规格")
    @PreAuthorize(hasPermi = "airbottle:specification:add")
    @Log(title = "气瓶规格", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData<Boolean> add(@RequestBody QpSpecificationDto specificationDto) {
        return ResultData.result(qpSpecificationService.insertQpSpecification(specificationDto));
    }

    /**
     * 修改气瓶规格
     */
    @ApiOperation(value = "修改气瓶规格")
    @PreAuthorize(hasPermi = "airbottle:specification:edit")
    @Log(title = "气瓶规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData<Boolean> edit(@RequestBody QpSpecificationDto specificationDto) {
        return ResultData.result(qpSpecificationService.updateQpSpecification(specificationDto));
    }

    /**
     * 删除气瓶规格
     */
    @ApiOperation(value = "删除气瓶规格")
    @PreAuthorize(hasPermi = "airbottle:specification:remove")
    @Log(title = "气瓶规格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData<Boolean> remove(@PathVariable Long[] ids) {
        return ResultData.result(qpSpecificationService.deleteQpSpecificationByIds(ids));
    }
}
