package com.yhy.module.core.controller.admin.resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.yhy.module.core.controller.admin.resource.vo.ResourceMergedPageReqVO;
import com.yhy.module.core.controller.admin.resource.vo.ResourceMergedRespVO;
import com.yhy.module.core.controller.admin.resource.vo.ResourceMergedSaveReqVO;
import com.yhy.module.core.service.resource.ResourceMergedService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "管理后台 - 复合工料机")
@RestController
@RequestMapping("/core/resource/merged")
@Validated
public class ResourceMergedController {

    @Resource
    private ResourceMergedService resourceMergedService;

    @PostMapping("/create")
    @Operation(summary = "创建复合工料机")
    @PreAuthorize("@ss.hasPermission('core:resource:create')")
    public CommonResult<Long> createResourceMerged(@Valid @RequestBody ResourceMergedSaveReqVO createReqVO) {
        return success(resourceMergedService.createResourceMerged(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新复合工料机")
    @PreAuthorize("@ss.hasPermission('core:resource:update')")
    public CommonResult<Boolean> updateResourceMerged(@Valid @RequestBody ResourceMergedSaveReqVO updateReqVO) {
        resourceMergedService.updateResourceMerged(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除复合工料机")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('core:resource:delete')")
    public CommonResult<Boolean> deleteResourceMerged(@RequestParam("id") Long id) {
        resourceMergedService.deleteResourceMerged(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得复合工料机")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:resource:query')")
    public CommonResult<ResourceMergedRespVO> getResourceMerged(@RequestParam("id") Long id) {
        ResourceMergedRespVO respVO = resourceMergedService.getResourceMerged(id);
        return success(respVO);
    }

    @GetMapping("/page")
    @Operation(summary = "获得复合工料机分页")
    @PreAuthorize("@ss.hasPermission('core:resource:query')")
    public CommonResult<PageResult<ResourceMergedRespVO>> getResourceMergedPage(@Valid ResourceMergedPageReqVO pageReqVO) {
        PageResult<ResourceMergedRespVO> pageResult = resourceMergedService.getResourceMergedPage(pageReqVO);
        return success(pageResult);
    }
}
