package com.cf.imes.module.executor.controller.admin.orderModuleExtra;

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 com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import static com.cf.imes.framework.common.pojo.CommonResult.success;

import com.cf.imes.framework.excel.core.util.ExcelUtils;

import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.cf.imes.module.executor.controller.admin.orderModuleExtra.vo.*;
import com.cf.imes.module.executor.dal.dataobject.orderModuleExtra.OrderModuleExtraDO;
import com.cf.imes.module.executor.service.orderModuleExtra.OrderModuleExtraService;

@Tag(name = "管理后台 - 生产单模块扩充属性表 order_module_extra_N")
@RestController
@RequestMapping("/executor/order-module-extra")
@Validated
public class OrderModuleExtraController {

    @Resource
    private OrderModuleExtraService orderModuleExtraService;

    @PostMapping("/create")
    @Operation(summary = "创建生产单模块扩充属性表 order_module_extra_N")
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:create')")
    public CommonResult<Long> createOrderModuleExtra(@Valid @RequestBody OrderModuleExtraSaveReqVO createReqVO) {
        return success(orderModuleExtraService.createOrderModuleExtra(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新生产单模块扩充属性表 order_module_extra_N")
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:update')")
    public CommonResult<Boolean> updateOrderModuleExtra(@Valid @RequestBody OrderModuleExtraSaveReqVO updateReqVO) {
        orderModuleExtraService.updateOrderModuleExtra(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除生产单模块扩充属性表 order_module_extra_N")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:delete')")
    public CommonResult<Boolean> deleteOrderModuleExtra(@RequestParam("id") Long id) {
        orderModuleExtraService.deleteOrderModuleExtra(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得生产单模块扩充属性表 order_module_extra_N")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:query')")
    public CommonResult<OrderModuleExtraRespVO> getOrderModuleExtra(@RequestParam("id") Long id) {
        OrderModuleExtraDO orderModuleExtra = orderModuleExtraService.getOrderModuleExtra(id);
        return success(BeanUtils.toBean(orderModuleExtra, OrderModuleExtraRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得生产单模块扩充属性表 order_module_extra_N分页")
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:query')")
    public CommonResult<PageResult<OrderModuleExtraRespVO>> getOrderModuleExtraPage(@Valid OrderModuleExtraPageReqVO pageReqVO) {
        PageResult<OrderModuleExtraDO> pageResult = orderModuleExtraService.getOrderModuleExtraPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OrderModuleExtraRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出生产单模块扩充属性表 order_module_extra_N Excel")
    @PreAuthorize("@ss.hasPermission('executor:order-module-extra:export')")
    @OperateLog(type = EXPORT)
    public void exportOrderModuleExtraExcel(@Valid OrderModuleExtraPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<OrderModuleExtraDO> list = orderModuleExtraService.getOrderModuleExtraPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "生产单模块扩充属性表 order_module_extra_N.xls", "数据", OrderModuleExtraRespVO.class,
                        BeanUtils.toBean(list, OrderModuleExtraRespVO.class));
    }

}