package com.xhkjedu.sapi.controller.cloud;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.cloud.TCloudSync;
import com.xhkjedu.sapi.service.cloud.CloudSyncService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* @author ywx
* @classname TCloudSyncController
* @description
* @date 2021/05/06 15:42
**/
@RestController
@RequestMapping("csync")
public class CloudSyncController {
    @Resource
    private CloudSyncService cloudSyncService;

    @PostMapping("/list")
    public ResultVo list(@RequestBody TCloudSync sync) {
        Integer page = sync.getPage();
        Integer pageSize = sync.getPageSize();
        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<Map> list = cloudSyncService.findAll(sync);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0,"获取同步任务列表成功",pageResult);
    }

    @PostMapping("/sync")
    @Action("同步任务-同步")
    public ResultVo sync(@RequestBody TCloudSync sync) {
        N_Utils.validation(new Object[]{sync.getCreateid(), "创建人id", 1
                ,sync.getCloudcode(),"平台码",2,sync.getSyncnum(),"一次同步数量",1});
        return cloudSyncService.sync(sync);
    }

    /**
     * @Description 获取同步类型
     * @Date 2023/10/13 15:15
     * @Author YWX
     * @Param []
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_module")
    public ResultVo listModule() {
        return cloudSyncService.listModule();
    }
}
