package com.greenorange.promotion.service.settle.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenorange.promotion.model.dto.userAccount.UserAccountAddRequest;
import com.greenorange.promotion.model.dto.userAccount.UserAccountUpdateRequest;
import com.greenorange.promotion.model.entity.UserAccount;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.settle.UserAccountService;
import com.greenorange.promotion.mapper.UserAccountMapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

/**
* @author 35880
* @description 针对表【user_account(用户账户表)】的数据库操作Service实现
* @createDate 2025-05-11 01:44:18
*/
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount>
    implements UserAccountService{


    @Resource
    private CommonService commonService;


    /**
     * 小程序端用户添加用户账户
     */
    @Override
    public void addUserAccount(UserAccountAddRequest userAccountAddRequest, HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        UserAccount userAccount = commonService.copyProperties(userAccountAddRequest, UserAccount.class);
        userAccount.setUserId(userId);
        this.save(userAccount);
    }


    /**
     * 小程序端用户根据id修改用户账户信息
     */
    @Override
    public void updateUserAccount(UserAccountUpdateRequest userAccountUpdateRequest, HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        UserAccount userAccount = commonService.copyProperties(userAccountUpdateRequest, UserAccount.class);
        userAccount.setUserId(userId);
        this.updateById(userAccount);
    }
}




