package cn.stylefeng.guns.modular.business.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.util.StrUtil;
|
import cn.stylefeng.guns.modular.business.dto.request.SysSmsSendParamRequest;
|
import cn.stylefeng.guns.modular.business.service.IAreaService;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
|
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
|
import cn.stylefeng.roses.kernel.customer.modular.request.CustomerIdRequest;
|
import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService;
|
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
|
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
|
@Api(tags = "C端用户")
|
@RestController
|
@ApiResource(name = "C端用户个人信息修改")
|
public class CustomerInfoBizController {
|
|
@Resource
|
private IAreaService areaService;
|
|
@Resource
|
private CustomerService customerService;
|
|
@Resource
|
private SysSmsInfoService sysSmsInfoService;
|
|
@ApiOperation(value = "发送验证码短信")
|
@PostResource(name = "发送验证码短信", path = "/sms/sendMessageByPhone", requiredLogin = false, requiredPermission = false)
|
public ResponseData<Boolean> sendMessageByPhone(@RequestBody SysSmsSendParamRequest req) {
|
if (StrUtil.isNotBlank(req.getPhone())) {
|
long count = customerService.count(
|
Wrappers.<Customer>lambdaQuery()
|
.eq(Customer::getAccount, req.getPhone())
|
.eq(Customer::getStatusFlag, StatusEnum.ENABLE.getCode())
|
);
|
Assert.isTrue(count > 0, "手机号不存在");
|
}
|
|
SysSmsSendParam sysSmsSendParam = BeanUtil.copyProperties(req, SysSmsSendParam.class);
|
return new SuccessResponseData<>(sysSmsInfoService.sendShortMessage(sysSmsSendParam));
|
}
|
|
/**
|
* 获取个人信息
|
*/
|
@ApiOperation("获取个人信息")
|
@GetResource(name = "获取个人信息", path = "/customerInfo/getPersonInfo", requiredPermission = false)
|
public ResponseData<CustomerInfo> getPersonInfo(CustomerIdRequest customerRequest) {
|
if (customerRequest.getCustomerId() == null) {
|
// 获取当前登录用户信息
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
Long userId = loginUser.getUserId();
|
customerRequest.setCustomerId(userId);
|
}
|
CustomerInfo customerInfo = customerService.getCustomerInfoById(customerRequest.getCustomerId());
|
if (customerInfo != null && StrUtil.isNotBlank(customerInfo.getCityCode())) {
|
customerInfo.setCityCodeStr(areaService.getNameByCodeAddPrefix("/", customerInfo.getCityCode()));
|
}
|
return new SuccessResponseData<>(customerInfo);
|
}
|
|
}
|