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

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.processStep.vo.*;
import com.cf.imes.module.executor.dal.dataobject.processStep.ProcessStepDO;
import com.cf.imes.module.executor.service.processStep.ProcessStepService;

@Tag(name = "管理后台 - 生产单工序步骤")
@RestController
@RequestMapping("/executor/process-step")
@Validated
public class ProcessStepController {

    @Resource
    private ProcessStepService processStepService;

    @PostMapping("/create")
    @Operation(summary = "创建生产单工序步骤")
    @PreAuthorize("@ss.hasPermission('executor:process-step:create')")
    public CommonResult<Long> createProcessStep(@Valid @RequestBody ProcessStepSaveReqVO createReqVO) {
        return success(processStepService.createProcessStep(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新生产单工序步骤")
    @PreAuthorize("@ss.hasPermission('executor:process-step:update')")
    public CommonResult<Boolean> updateProcessStep(@Valid @RequestBody ProcessStepSaveReqVO updateReqVO) {
        processStepService.updateProcessStep(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除生产单工序步骤")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('executor:process-step:delete')")
    public CommonResult<Boolean> deleteProcessStep(@RequestParam("id") Long id) {
        processStepService.deleteProcessStep(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得生产单工序步骤")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('executor:process-step:query')")
    public CommonResult<ProcessStepRespVO> getProcessStep(@RequestParam("id") Long id) {
        ProcessStepDO processStep = processStepService.getProcessStep(id);
        return success(BeanUtils.toBean(processStep, ProcessStepRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得生产单工序步骤分页")
    @PreAuthorize("@ss.hasPermission('executor:process-step:query')")
    public CommonResult<PageResult<ProcessStepRespVO>> getProcessStepPage(@Valid ProcessStepPageReqVO pageReqVO) {
        PageResult<ProcessStepDO> pageResult = processStepService.getProcessStepPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ProcessStepRespVO.class));
    }

}