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

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.*;

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.module.executor.controller.admin.process.vo.*;
import com.cf.imes.module.executor.dal.dataobject.process.OrderProcessDO;
import com.cf.imes.module.executor.service.process.OrderProcessService;

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

    @Resource
    private OrderProcessService orderProcessService;

    @PostMapping("/create")
    @Operation(summary = "创建生产单工序组")
    @PreAuthorize("@ss.hasPermission('production:manager-list:putInto')")
    public CommonResult<Long> createOrderProcess(@Valid @RequestBody OrderProcessSaveReqVO createReqVO) {
        return success(orderProcessService.createOrderProcess(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新生产单工序组")
    @PreAuthorize("@ss.hasPermission('executor:order-process:update')")
    public CommonResult<Boolean> updateOrderProcess(@Valid @RequestBody OrderProcessSaveReqVO updateReqVO) {
        orderProcessService.updateOrderProcess(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/get")
    @Operation(summary = "获得生产单工序组")
    @Parameter(name = "orderId", description = "生产单编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('executor:order-process:query')")
    public CommonResult<OrderProcessRespVO> getOrderProcess(@RequestParam("orderId") Long orderId) {
        OrderProcessDO orderProcess = orderProcessService.getOrderProcess(orderId);
        return success(BeanUtils.toBean(orderProcess, OrderProcessRespVO.class));
    }

}