package com.kingtom.shengtai.api.controller;

import com.kingtom.kirin.api.security.SaSecurityUtils;
import com.kingtom.kirin.core.common.base.Result;
import com.kingtom.kirin.core.common.exception.AppException;
import com.kingtom.shengtai.api.model.UserJoinOrgParam;
import com.kingtom.shengtai.app.affair.service.AffairService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 应用模块名称</p>
 * 代码描述</p>
 * Copyright: Copyright (C) 2024 , Inc. All rights reserved. <p>
 * Company: 成都诚唐科技有限责任公司</p>
 *
 * @author wany
 * @since 2024/1/2
 */
@RestController
@RequestMapping("/affair_ext")
@Tag(name = "AffairExtController", description = "审核相关扩展接口。")
public class AffairExtController{

    @Autowired
    private AffairService affairService;

    @PostMapping("/UserJoinOrgAffair")
    @Operation(description = "创建待办：用户加入组织")
    public Result<String> createUserJoinOrgAffair(@RequestBody UserJoinOrgParam param){
        String name = param.getName();
        if(StringUtils.isEmpty(name)){
            throw new AppException("人员名称不能为空！");
        }
        String phone = param.getPhone();
        if(StringUtils.isEmpty(name)){
            throw new AppException("人员手机号不能为空！");
        }
        String userId = SaSecurityUtils.findSessionData().getUserId();
        affairService.createUserJoinOrgAffair(userId, name, phone);
        return Result.ok(null);
    }

    @PostMapping("/SupplierAffair")
    @Operation(description = "创建待办：申请成为供应商")
    public Result<String> createSupplierAffair(@RequestBody String data){
        String userId = SaSecurityUtils.findSessionData().getUserId();
        affairService.createSupplierAffair(userId, data);
        return Result.ok(null);
    }

}
