2026-01-09 12:20:24 +08:00
|
|
|
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;
|
2026-01-09 12:20:44 +08:00
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
2026-01-09 12:20:24 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.security.Principal;
|
|
|
|
|
|
2026-01-09 12:20:44 +08:00
|
|
|
/**
|
|
|
|
|
* 商家管理接口
|
|
|
|
|
*/
|
2026-01-09 12:20:24 +08:00
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/merchant")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class MerchantController {
|
|
|
|
|
private final MerchantService merchantService;
|
|
|
|
|
|
2026-01-09 12:20:44 +08:00
|
|
|
/**
|
|
|
|
|
* 查询当前登录商家详情
|
|
|
|
|
*
|
|
|
|
|
* @param merchant @ignore 当前商家
|
|
|
|
|
* @return 商家详情信息
|
|
|
|
|
*/
|
2026-01-09 12:20:24 +08:00
|
|
|
@GetMapping
|
2026-01-09 12:20:44 +08:00
|
|
|
public ApiResult<MerchantDto> getMerchant(@AuthenticationPrincipal Merchant merchant) {
|
|
|
|
|
return this.merchantService.getById(merchant.getId())
|
|
|
|
|
.map(ApiResult::data)
|
|
|
|
|
.orElse(ApiResult.fail("商家信息不存在"));
|
2026-01-09 12:20:24 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 12:20:44 +08:00
|
|
|
/**
|
|
|
|
|
* 更新当前登录商家信息
|
|
|
|
|
*
|
|
|
|
|
* @param merchant @ignore 当前商家
|
|
|
|
|
* @param merchantUpdateVo 更新参数
|
|
|
|
|
* @return 商家信息
|
|
|
|
|
*/
|
2026-01-09 12:20:24 +08:00
|
|
|
@PutMapping
|
2026-01-09 12:20:44 +08:00
|
|
|
public ApiResult<MerchantDto> 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());
|
2026-01-09 12:20:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 12:20:44 +08:00
|
|
|
/**
|
|
|
|
|
* 当前商家验证
|
|
|
|
|
*
|
|
|
|
|
* @param merchant @ignore 当前商家
|
|
|
|
|
* @param merchantVerifyVo 验证参数
|
|
|
|
|
* @return 商家信息
|
|
|
|
|
*/
|
2026-01-09 12:20:24 +08:00
|
|
|
@PostMapping("/verify")
|
2026-01-09 12:20:44 +08:00
|
|
|
public ApiResult<MerchantDto> 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());
|
2026-01-09 12:20:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|