package com.luozhihui.project.controller;
import com.luozhihui.project.common.ApiResponse;
import com.luozhihui.project.entity.User;
import com.luozhihui.project.mapper.UserInfoMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class UserInfoController{
    @Resource
    UserInfoMapper userInfoMapper;
//    更新个人信息
    @PostMapping("/upuserinfo")
    public ApiResponse updateUser( User user) {
//        通过userid更新个人信息
        User existingUserinfo = userInfoMapper.findById(Integer.valueOf(user.getUserId()));
        if (existingUserinfo != null) {
            existingUserinfo.setPhone(user.getPhone());
            existingUserinfo.setUserName(user.getUserName());
            existingUserinfo.setPassWord(user.getPassWord());
            existingUserinfo.setIdCard(user.getIdCard());
            existingUserinfo.setDriverLicense(user.getDriverLicense());
            userInfoMapper.update(existingUserinfo);
            return new ApiResponse(null, 200, "用户信息更新成功");
        } else {
            return new ApiResponse(null, 404, "用户不存在");
        }
    }
    @PostMapping("/RealUser")
    public ApiResponse RealUser( User user) {
//        通过userid更新个人信息
        User existingUserinfo = userInfoMapper.findById(Integer.valueOf(user.getUserId()));
        if (existingUserinfo != null) {
            existingUserinfo.setPhone(user.getPhone());
            existingUserinfo.setUserName(user.getUserName());
            existingUserinfo.setIdCard(user.getIdCard());
            existingUserinfo.setDriverLicense(user.getDriverLicense());
            userInfoMapper.update(existingUserinfo);
            return new ApiResponse(null, 200, "用户实名成功");
        } else {
            return new ApiResponse(null, 404, "用户不存在");
        }
    }
}

