/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.User;
import com.yami.shop.bean.model.UserExtension;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.dao.UserExtensionMapper;
import com.yami.shop.dao.UserMapper;
import com.yami.shop.service.UserExtensionService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户扩展信息
 *
 * @author LGH
 * @date 2020-02-26 16:03:14
 */
@Service
@AllArgsConstructor
public class UserExtensionServiceImpl extends ServiceImpl<UserExtensionMapper, UserExtension> implements UserExtensionService {

    private final UserExtensionMapper userExtensionMapper;
    private final UserMapper userMapper;

    @Override
    public Page<UserExtension> getPage(PageParam<UserExtension> page, UserExtension userExtension) {
        return userExtensionMapper.getPage(page,userExtension);
    }

    @Override
    public void setUserLevelBylevelId(Integer level) {
        userExtensionMapper.setUserLevelBylevelId(level);
    }

    @Override
    public void setMaxUserLevelByLevelId(Integer level, Integer minNeedGrowth, Integer maxNeedGrowth) {
        userExtensionMapper.serMaxUserLavelByLevelId(level,minNeedGrowth,maxNeedGrowth);
    }

    @Override
    public void updateBatchByUserId(List<UserExtension> userExtensions) {
        userExtensionMapper.updateBatchByUserId(userExtensions);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMemberByTime(List<User> userList, List<UserExtension> userExtensions) {
        userMapper.updateBatchById(userList);

        updateBatchById(userExtensions);
    }
}
