package com.zcloud.primeport.web;


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.primeport.api.MkmjApprovalUserServiceI;
import com.zcloud.primeport.dto.MkmjApprovalUserAddCmd;
import com.zcloud.primeport.dto.MkmjApprovalUserPageQry;
import com.zcloud.primeport.dto.MkmjApprovalUserUpdateCmd;
import com.zcloud.primeport.dto.clientobject.AvailableResultCO;
import com.zcloud.primeport.dto.clientobject.MkmjApprovalUserCO;
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 makejava
 * @Date 2026-03-05 11:33:16
 */
@Api(tags = "一级口门门禁审批人")
@RequestMapping("/${application.gateway}/mkmjApprovalUser")
@RestController
@AllArgsConstructor
public class MkmjApprovalUserController {
    private final MkmjApprovalUserServiceI mkmjApprovalUserService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<MkmjApprovalUserCO> add(@Validated @RequestBody MkmjApprovalUserAddCmd cmd) {
        return mkmjApprovalUserService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<MkmjApprovalUserCO> page(@RequestBody MkmjApprovalUserPageQry qry) {
        qry.setCorpId(AuthContext.getTenantId());
        return mkmjApprovalUserService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<MkmjApprovalUserCO> listAll(MkmjApprovalUserPageQry qry) {
        return MultiResponse.of(mkmjApprovalUserService.listAll(qry));
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<MkmjApprovalUserCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(mkmjApprovalUserService.getInfoById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable("id") Long id) {
        mkmjApprovalUserService.remove(id);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("校验审批人是否已录入")
    @GetMapping("/checkExistByUserId/{userId}")
    public SingleResponse<AvailableResultCO> checkExistByUserId(@PathVariable("userId") Long userId) {
        return mkmjApprovalUserService.checkExistByUserId(userId);
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody MkmjApprovalUserUpdateCmd mkmjApprovalUserUpdateCmd) {
        mkmjApprovalUserService.edit(mkmjApprovalUserUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

