package cn.iocoder.yudao.module.bpm.controller.admin.oa;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procure.BpmOAProcureListEditReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procure.BpmOAProcureRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procure.BpmOAProcureSaveReqVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAProcureConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAProcureDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAProcureService;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - OA 采购申请")
@RestController
@RequestMapping("/bpm/oa-procure")
@Validated
public class BpmOAProcureController {

    @Resource
    private BpmOAProcureService bpmOaProcureService;

    @PostMapping("/create")
    @Operation(summary = "创建OA 采购申请")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-procure:create')")
    public CommonResult<Long> createOaProcure(@Valid @RequestBody BpmOAProcureSaveReqVO createReqVO) {
        return success(bpmOaProcureService.createOaProcure(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新OA 采购申请")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-procure:update')")
    public CommonResult<Boolean> updateOaProcure(@Valid @RequestBody BpmOAProcureSaveReqVO updateReqVO) {
        bpmOaProcureService.updateOaProcure(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除OA 采购申请")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('bpm:oa-procure:delete')")
    public CommonResult<Boolean> deleteOaProcure(@RequestParam("id") Long id) {
        bpmOaProcureService.deleteOaProcure(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得OA 采购申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-procure:query')")
    public CommonResult<BpmOAProcureRespVO> getOaProcure(@RequestParam("id") Long id) {
        BpmOAProcureDO oaProcure = bpmOaProcureService.getOaProcure(id);
        return success(BpmOAProcureConvert.INSTANCE.convert(oaProcure));
    }


    @PostMapping("/updatePayFlagByIds")
    @Operation(summary = "根据ids修改支付状态")
    public CommonResult<?> updatePayFlagByIds(@RequestBody BpmOAProcureListEditReqVO vo) {
        bpmOaProcureService.updatePayFlagByIds(vo);
        return success("操作成功");
    }

}
