package com.fjhx.account.service.account.impl;

import cn.hutool.core.util.ObjectUtil;
import com.fjhx.account.entity.account.po.AccountRemainder;
import com.fjhx.account.mapper.account.AccountRemainderMapper;
import com.fjhx.account.service.account.AccountRemainderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.account.entity.account.vo.AccountRemainderVo;
import com.fjhx.account.entity.account.dto.AccountRemainderSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.account.entity.account.dto.AccountRemainderDto;
import cn.hutool.core.bean.BeanUtil;


/**
 * <p>
 * 账户-余额表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-06
 */
@Service
public class AccountRemainderServiceImpl extends ServiceImpl<AccountRemainderMapper, AccountRemainder> implements AccountRemainderService {

    @Override
    public Page<AccountRemainderVo> getPage(AccountRemainderSelectDto dto) {
        IWrapper<AccountRemainder> wrapper = getWrapper();
        wrapper.orderByDesc("ar", AccountRemainder::getId);
        Page<AccountRemainderVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public AccountRemainderVo detail(Long id) {
        AccountRemainder AccountRemainder = this.getById(id);
        AccountRemainderVo result = BeanUtil.toBean(AccountRemainder, AccountRemainderVo.class);
        return result;
    }

    @Override
    public void add(AccountRemainder accountRemainderDto) {
        synchronized (this) {
            if (ObjectUtil.isNotEmpty(accountRemainderDto.getId())) {
                this.updateById(accountRemainderDto);
            } else {
                this.save(accountRemainderDto);
            }
        }

    }

    @Override
    public void edit(AccountRemainderDto accountRemainderDto) {
        this.updateById(accountRemainderDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
