package com.zcloud.basic.info.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.basic.info.api.CorpInfoXgfServiceI;
import com.zcloud.basic.info.dto.CorpInfoXgfAddCmd;
import com.zcloud.basic.info.dto.CorpInfoXgfPageQry;
import com.zcloud.basic.info.dto.CorpInfoXgfUpdateCmd;
import com.zcloud.basic.info.dto.clientobject.CorpInfoXgfCO;
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 zhaokai
 * @Date 2025-10-31 10:52:09
 */
@Api(tags = "企业相关方信息-废弃")
@RequestMapping("/${application.gateway}/corpInfoXgf")
@RestController
@AllArgsConstructor
public class CorpInfoXgfController {
    private final CorpInfoXgfServiceI corpInfoXgfService;

    @ApiOperation("新增相关方企业")
    @PostMapping("/save")
    public SingleResponse<CorpInfoXgfCO> add(@Validated @RequestBody CorpInfoXgfAddCmd cmd) {

        return corpInfoXgfService.add(cmd);
    }

    @ApiOperation("相关方企业分页")
    @PostMapping("/list")
    public PageResponse<CorpInfoXgfCO> page(@RequestBody CorpInfoXgfPageQry qry) {
        return corpInfoXgfService.listPage(qry);
    }

    @ApiOperation("相关方企业详情")
    @PostMapping("/info/{id}")
    public SingleResponse<CorpInfoXgfCO> getInfoById(@PathVariable("id") Long id) {
        if(id==null){
            SSOUser ssoUser = AuthContext.getCurrentUser();
            id = ssoUser.getTenantId();
        }
        return SingleResponse.of(corpInfoXgfService.info(id));
    }

    @ApiOperation("相关方企业删除")
    @PostMapping("/remove/{id}")
    public Response remove(@PathVariable("id") Long id) {
        corpInfoXgfService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        corpInfoXgfService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("相关方企业修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody CorpInfoXgfUpdateCmd corpInfoXgfUpdateCmd) {
        corpInfoXgfService.edit(corpInfoXgfUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

