package com.zcloud.basic.info.web;


import cn.hutool.json.JSONArray;
import com.zcloud.basic.info.api.RzUserRecordServiceI;
import com.zcloud.basic.info.command.RzUserRecordAddExe;
import com.zcloud.basic.info.dto.RzUserRecordAddCmd;
import com.zcloud.basic.info.dto.RzUserRecordPageQry;
import com.zcloud.basic.info.dto.RzUserRecordListQry;
import com.zcloud.basic.info.dto.RzUserRecordUpdateCmd;
import com.zcloud.basic.info.dto.RzUserRecordRemoveCmd;
import com.zcloud.basic.info.dto.clientobject.RzUserRecordCO;
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-05 14:00:37
 */
@Api(tags = "人资每日变动记录")
@RequestMapping("/${application.gateway}/rzUserRecord")
@RestController
@AllArgsConstructor
public class RzUserRecordController {
    private final RzUserRecordServiceI rzUserRecordService;
    private final RzUserRecordAddExe rzUserRecordAddExe;

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

    @ApiOperation("手动模拟拉取人资变动信息定时")
    @PostMapping("/getRZChange")
    public Response getRZChange(@RequestBody JSONArray jsonArray){
        rzUserRecordAddExe.executeJsonArray(jsonArray);
        return SingleResponse.buildSuccess();
    }


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

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

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<RzUserRecordCO> page(@RequestBody RzUserRecordPageQry qry) {
        return rzUserRecordService.listPage(qry);
    }

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

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

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

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

}

