
package com.tmerclub.cloud.supplier.controller.supplier;

import com.tmerclub.cloud.api.auth.bo.UidInfoBO;
import com.tmerclub.cloud.api.supplier.vo.SupplierApiDetailVO;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.supplier.service.SupplierDetailService;
import com.tmerclub.cloud.supplier.vo.SupplierUserSimpleVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Author lth
 * @Date 2021/5/12 20:27
 */
@RequestMapping("/s/apply_supplier/supplier_user")
@RestController("supplierSupplierUserController")
@Tag(name = "supplier-供应商用户信息")
public class ApplySupplierUserController {

    @Autowired
    private SupplierDetailService supplierDetailService;

    @GetMapping("/info")
    @Operation(summary = "登录供应商用户信息", description = "获取当前登录供应商用户的用户信息")
    public ServerResponseEntity<SupplierUserSimpleVO> info() {
        UidInfoBO uidInfoBO = AuthUserContext.get();
        SupplierUserSimpleVO supplierUserSimple = new SupplierUserSimpleVO();
        supplierUserSimple.setIsAdmin(uidInfoBO.getIsAdmin());
        supplierUserSimple.setIsPassShop(uidInfoBO.getIsPassShop());
        supplierUserSimple.setTenantId(uidInfoBO.getTenantId());
        supplierUserSimple.setUserId(uidInfoBO.getUserId());
        supplierUserSimple.setUserName(uidInfoBO.getUsername());
        if (!Objects.equals(uidInfoBO.getTenantId(), Constant.DEFAULT_SUPPLIER_ID)) {
            SupplierApiDetailVO supplierDetail = supplierDetailService.getBySupplierId(uidInfoBO.getTenantId());
            supplierUserSimple.setAvatar(supplierDetail.getSupplierLogo());
            supplierUserSimple.setSupplierName(supplierDetail.getSupplierName());
        }
        return ServerResponseEntity.success(supplierUserSimple);
    }
}
