package com.njzscloud.supervisory.money.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.security.util.SecurityUtil;
import com.njzscloud.supervisory.money.mapper.MoneyAccountMapper;
import com.njzscloud.supervisory.money.pojo.entity.MoneyAccountEntity;
import com.njzscloud.supervisory.money.pojo.result.MoneyAccountResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 资金账户表
 */
@Slf4j
@Service
public class MoneyAccountService extends ServiceImpl<MoneyAccountMapper, MoneyAccountEntity> implements IService<MoneyAccountEntity> {

    /**
     * 新增
     */
    public void add(MoneyAccountEntity moneyAccountEntity) {
        moneyAccountEntity.setUserId(SecurityUtil.currentUserId());
        this.save(moneyAccountEntity);
    }

    /**
     * 修改
     */
    public void modify(MoneyAccountEntity moneyAccountEntity) {
        this.updateById(moneyAccountEntity);
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    public void del(List<Long> ids) {
        this.removeBatchByIds(ids);
    }

    /**
     * 详情
     */
    public MoneyAccountEntity detail(Long id) {
        return this.getById(id);
    }

    /**
     * 分页查询
     */
    public PageResult<MoneyAccountResult> paging(PageParam pageParam, MoneyAccountEntity moneyAccountEntity) {
        Page<MoneyAccountResult> page = new Page<>(pageParam.getCurrent(), pageParam.getSize());
        IPage<MoneyAccountResult> result = baseMapper.selectMoneyAccountWithName(page, moneyAccountEntity);
        return PageResult.of(result);
    }

}
