package com.cf.imes.module.manage.controller.admin.patching;


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.manage.controller.admin.patching.vo.*;
import com.cf.imes.module.manage.service.patching.PatchingPlateService;
import com.cf.imes.module.manage.dal.dataobject.patching.MachineDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.cf.imes.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 补板")
@RestController
@RequestMapping("/manage/patching")
@Validated
public class PatchingPlateController {


    @Resource
    private PatchingPlateService patchingPlateService;



    @GetMapping("/searchPage")
    @Operation(summary = "批量加入补板查询")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<PageResult<PatchingPlateRespVO>> patchingSearchPlate(@Valid PatchingPlatePageReqVO pageReqVO){

        PageResult<PatchingPlateRespVO> patchingPlateRespVOPageResult = patchingPlateService.patchingSearchPlate(pageReqVO);

        return success(patchingPlateRespVOPageResult);

    }





    @GetMapping("/searchPlate")
    @Operation(summary = "查询详细的板件")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<PageResult<PatchingDetailRespVO>> searchPlateDetail(@Valid PatchingPlatePageReqVO pageReqVO){

        PageResult<PatchingDetailRespVO> plateDetailsRespVOPageResult = patchingPlateService.searchPlateDetail(pageReqVO);

        return success(plateDetailsRespVOPageResult);

    }






    @GetMapping("/searchPatchingList")
    @Operation(summary = "加入的板件信息")
    @Parameter(name = "plateId", description = "板件ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<PatchingDetailRespVO> searchPatchingList(@Valid @RequestParam("plateId") Long plateId){

        return success(patchingPlateService.searchPatchingList(plateId));


    }






    @GetMapping("/optimizeLayout")
    @Operation(summary = "优化排版")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<List<PatchingDetailRespVO>> optimizeLayout(@Valid PatchingDetailReqVO reqVO){

        List<PatchingDetailRespVO> patchingDetailRespVOS = patchingPlateService.optimizeLayout(reqVO);

        return  success(patchingDetailRespVOS);


    }







    @PostMapping("/insertPatching")
    @Operation(summary = "新增补板详情表")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<Boolean> insertPatching(@Valid @RequestBody PatchingReqVO reqVO){

        patchingPlateService.insertPatching(reqVO);

        return  success(true);


    }







    @GetMapping("/search")
    @Operation(summary = "查询所有的机台")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<List<MachineDO>> searchMachine(){

        return success(patchingPlateService.searchMachine());

    }






    @GetMapping("/searchPatchNC")
    @Operation(summary = "导出 NC 所需要的数据")
    @PreAuthorize("@ss.hasPermission('manage:patching:query')")
    public CommonResult<List<PatchingDetailRespVO>> searchPatchNC(@Valid PatchingDetailReqVO reqVO){

        List<PatchingDetailRespVO> patchingDetailRespVOS = patchingPlateService.optimizeLayout(reqVO);

        return success(patchingDetailRespVOS);

    }




}
