package com.xjhs.findmemerchant.controller; import com.xjhs.findmemerchant.common.ApiResult; import com.xjhs.findmemerchant.dto.MerchantDto; import com.xjhs.findmemerchant.entity.Merchant; import com.xjhs.findmemerchant.service.MerchantService; import com.xjhs.findmemerchant.vo.merchant.MerchantUpdateVo; import com.xjhs.findmemerchant.vo.merchant.MerchantVerifyVo; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.security.Principal; /** * 商家管理接口 */ @Slf4j @RestController @RequestMapping("/merchant") @RequiredArgsConstructor public class MerchantController { private final MerchantService merchantService; /** * 查询当前登录商家详情 * * @param merchant @ignore 当前商家 * @return 商家详情信息 */ @GetMapping public ApiResult getMerchant(@AuthenticationPrincipal Merchant merchant) { return this.merchantService.getById(merchant.getId()) .map(ApiResult::data) .orElse(ApiResult.fail("商家信息不存在")); } /** * 更新当前登录商家信息 * * @param merchant @ignore 当前商家 * @param merchantUpdateVo 更新参数 * @return 商家信息 */ @PutMapping public ApiResult updateMerchant(@AuthenticationPrincipal Merchant merchant, @Valid @RequestBody MerchantUpdateVo merchantUpdateVo) { try { var dto = this.merchantService.updateMerchant(merchant.getId(), merchantUpdateVo); return ApiResult.data(dto); } catch (Exception e) { return ApiResult.fail(e.getMessage()); } } /** * 当前商家验证 * * @param merchant @ignore 当前商家 * @param merchantVerifyVo 验证参数 * @return 商家信息 */ @PostMapping("/verify") public ApiResult verifyMerchant(@AuthenticationPrincipal Merchant merchant, @Valid @RequestBody MerchantVerifyVo merchantVerifyVo) { try { var dto = this.merchantService.verifyMerchant(merchant.getId(), merchantVerifyVo.getIdCardNo(), merchantVerifyVo.getRealName()); return ApiResult.data(dto); } catch (Exception e) { return ApiResult.fail(e.getMessage()); } } }