package com.zcloud.basic.info.web;


import com.zcloud.basic.info.api.RzUserServiceI;
import com.zcloud.basic.info.dto.RzUserAddCmd;
import com.zcloud.basic.info.dto.RzUserPageQry;
import com.zcloud.basic.info.dto.RzUserListQry;
import com.zcloud.basic.info.dto.RzUserUpdateCmd;
import com.zcloud.basic.info.dto.RzUserRemoveCmd;
import com.zcloud.basic.info.dto.clientobject.RzUserCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.basic.info.plan.DockingRZUserPlanJob;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author SondonYong
 * @Date 2025-12-02 17:15:56
 */
@Api(tags = "人资人员信息表")
@RequestMapping("/${application.gateway}/rzUser")
@RestController
@AllArgsConstructor
public class RzUserController {
    private final RzUserServiceI rzUserService;

    private final DockingRZUserPlanJob dockingRZPlanJob;
    @ApiOperation("手动调用获取人资人员信息定时")
    @PostMapping("/dockingRZ")
    public Response dockingRZ(){
        dockingRZPlanJob.execute("");
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<RzUserCO> add(@Validated @RequestBody RzUserAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return rzUserService.add(cmd);
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody RzUserUpdateCmd cmd) {
        rzUserService.edit(cmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<RzUserCO> page(@RequestBody RzUserPageQry qry) {
        return rzUserService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @PostMapping("/listAll")
    public MultiResponse<RzUserCO> listAll(@RequestBody RzUserListQry qry) {
        return rzUserService.list(qry);
    }

    @ApiOperation("详情")
    @GetMapping("/getInfoById")
    public SingleResponse<RzUserCO> getInfoById(@RequestParam(value = "id") Long id) {
        return rzUserService.getInfoById(id);
    }

    @ApiOperation("删除")
    @PutMapping("/remove")
    public Response remove(@RequestParam(value = "id") Long id) {
        rzUserService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @PutMapping("/removeBatch")
    public Response removeBatch(@Validated @RequestBody RzUserRemoveCmd cmd) {
        rzUserService.removeBatch(cmd.getIds());
        return SingleResponse.buildSuccess();
    }

}

