package org.springblade.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.system.service.IOASyncService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  oa数据同步
 * @author bfhuange
 * @date 2024/8/23
 */
@Tag(name = "oa数据同步", description = "oa数据同步")
@RequestMapping("/oa")
@RestController
@RequiredArgsConstructor
public class OAController {

    private final IOASyncService oaService;

    /**
     *  增量同步公司和部门并推送MK
     * @return
     */
    @ApiLog("系统管理-机构管理-增量同步")
    @Operation(summary = "增量同步公司和部门并推送MK")
    @PostMapping("/syncCompanyAndDeptAndPushMK")
    @PreAuth("hasPermission('oasync:org:inc')")
    public R<Boolean> syncCompanyAndDeptAndPushMK() {
        oaService.syncCompanyAndDeptAndPushMK(false);
        return R.data(true);
    }

    /**
     *  全量同步公司和部门并推送MK
     * @return
     */
    @ApiLog("系统管理-机构管理-全量同步")
    @Operation(summary = "全量同步公司和部门并推送MK")
    @PostMapping("/syncAllCompanyAndDeptAndPushMK")
    @PreAuth("hasPermission('oasync:org:all')")
    public R<Boolean> syncAllCompanyAndDeptAndPushMK() {
        oaService.syncCompanyAndDeptAndPushMK(true);
        return R.data(true);
    }

    /**
     *  增量同步人员并推送MK
     * @return
     */
    @ApiLog("系统管理-用户管理-增量同步")
    @Operation(summary = "增量同步人员并推送MK")
    @PostMapping("/syncPersonAndPushMK")
    @PreAuth("hasPermission('oasync:person:inc')")
    public R<Boolean> syncPersonAndPushMK() {
        oaService.syncPersonAndPushMK(false);
        return R.data(true);
    }

    /**
     *  全量同步人员并推送MK
     * @return
     */
    @ApiLog("系统管理-用户管理-全量同步")
    @Operation(summary = "全量同步人员并推送MK")
    @PostMapping("/syncAllPersonAndPushMK")
    @PreAuth("hasPermission('oasync:person:all')")
    public R<Boolean> syncAllPersonAndPushMK() {
        oaService.syncPersonAndPushMK(true);
        return R.data(true);
    }
}
