package cn.iocoder.yudao.module.wms.controller.admin.industrycategoryproperty;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wms.controller.admin.industrycategoryproperty.vo.*;
import cn.iocoder.yudao.module.wms.dal.dataobject.industrycategoryproperty.IndustryCategoryPropertyDO;
import cn.iocoder.yudao.module.wms.service.industrycategoryproperty.IndustryCategoryPropertyService;

@Tag(name = "管理后台 - 行业分类属性")
@RestController
@RequestMapping("/wms/industry-category-property")
@Validated
public class IndustryCategoryPropertyController {

    @Resource
    private IndustryCategoryPropertyService industryCategoryPropertyService;

    @PostMapping("/create")
    @Operation(summary = "创建行业分类属性")
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:create')")
    public CommonResult<Long> createIndustryCategoryProperty(@Valid @RequestBody IndustryCategoryPropertySaveReqVO createReqVO) {
        return success(industryCategoryPropertyService.createIndustryCategoryProperty(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新行业分类属性")
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:update')")
    public CommonResult<Boolean> updateIndustryCategoryProperty(@Valid @RequestBody IndustryCategoryPropertySaveReqVO updateReqVO) {
        industryCategoryPropertyService.updateIndustryCategoryProperty(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除行业分类属性")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:delete')")
    public CommonResult<Boolean> deleteIndustryCategoryProperty(@RequestParam("id") Long id) {
        industryCategoryPropertyService.deleteIndustryCategoryProperty(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得行业分类属性")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:query')")
    public CommonResult<IndustryCategoryPropertyRespVO> getIndustryCategoryProperty(@RequestParam("id") Long id) {
        IndustryCategoryPropertyDO industryCategoryProperty = industryCategoryPropertyService.getIndustryCategoryProperty(id);
        return success(BeanUtils.toBean(industryCategoryProperty, IndustryCategoryPropertyRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得行业分类属性分页")
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:query')")
    public CommonResult<PageResult<IndustryCategoryPropertyRespVO>> getIndustryCategoryPropertyPage(@Valid IndustryCategoryPropertyPageReqVO pageReqVO) {
        PageResult<IndustryCategoryPropertyDO> pageResult = industryCategoryPropertyService.getIndustryCategoryPropertyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, IndustryCategoryPropertyRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出行业分类属性 Excel")
    @PreAuthorize("@ss.hasPermission('wms:industry-category-property:export')")
    @OperateLog(type = EXPORT)
    public void exportIndustryCategoryPropertyExcel(@Valid IndustryCategoryPropertyPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<IndustryCategoryPropertyDO> list = industryCategoryPropertyService.getIndustryCategoryPropertyPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "行业分类属性.xls", "数据", IndustryCategoryPropertyRespVO.class,
                        BeanUtils.toBean(list, IndustryCategoryPropertyRespVO.class));
    }

}