guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
    }
 
}