package com.ruoyi.model.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.model.mapper.AppletAmountLogMapper;
import com.ruoyi.model.domain.AppletAmountLog;
import com.ruoyi.model.service.IAppletAmountLogService;

/**
 * 金额明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-28
 */
@Service
public class AppletAmountLogServiceImpl extends ServiceImpl<AppletAmountLogMapper, AppletAmountLog> implements IAppletAmountLogService
{
    @Autowired
    private AppletAmountLogMapper appletAmountLogMapper;

    /**
     * 查询金额明细
     * 
     * @param id 金额明细主键
     * @return 金额明细
     */
    @Override
    public AppletAmountLog selectAppletAmountLogById(Long id)
    {
        return appletAmountLogMapper.selectById(id);
    }

    /**
     * 查询金额明细列表
     * 
     * @param appletAmountLog 金额明细
     * @return 金额明细
     */
    @Override
    public List<AppletAmountLog> selectAppletAmountLogList(AppletAmountLog appletAmountLog)
    {

        /*
        * <where>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="moneyType != null "> and money_type = #{moneyType}</if>
            <if test="nameValue != null  and nameValue != ''"> and name_value like concat('%', #{nameValue}, '%')</if>
        </where>
        * */

        if (appletAmountLog == null){
            return list();
        }

        return lambdaQuery()
                .eq(StringUtils.isNotEmpty(appletAmountLog.getTitle()), AppletAmountLog::getTitle, appletAmountLog.getTitle())
                .eq(appletAmountLog.getAmount() != null, AppletAmountLog::getAmount, appletAmountLog.getAmount())
                .eq(appletAmountLog.getUserId() != null, AppletAmountLog::getUserId, appletAmountLog.getUserId())
                .eq(appletAmountLog.getMoneyType() != null, AppletAmountLog::getMoneyType, appletAmountLog.getMoneyType())
                .eq(appletAmountLog.getNameValue() != null, AppletAmountLog::getNameValue, appletAmountLog.getNameValue())
                .list();

//        return appletAmountLogMapper.selectAppletAmountLogList(appletAmountLog);
    }

    /**
     * 新增金额明细
     * 
     * @param appletAmountLog 金额明细
     * @return 结果
     */
    @Override
    public int insertAppletAmountLog(AppletAmountLog appletAmountLog)
    {
        appletAmountLog.setCreateTime(DateUtils.getNowDate());
        return appletAmountLogMapper.insert(appletAmountLog);
    }

    /**
     * 修改金额明细
     * 
     * @param appletAmountLog 金额明细
     * @return 结果
     */
    @Override
    public int updateAppletAmountLog(AppletAmountLog appletAmountLog)
    {
        appletAmountLog.setUpdateTime(DateUtils.getNowDate());
        return appletAmountLogMapper.updateById(appletAmountLog);
    }

    /**
     * 批量删除金额明细
     * 
     * @param ids 需要删除的金额明细主键
     * @return 结果
     */
    @Override
    public int deleteAppletAmountLogByIds(Long[] ids)
    {
        return appletAmountLogMapper.deleteAppletAmountLogByIds(ids);
    }

    /**
     * 删除金额明细信息
     * 
     * @param id 金额明细主键
     * @return 结果
     */
    @Override
    public int deleteAppletAmountLogById(Long id)
    {
        return appletAmountLogMapper.deleteAppletAmountLogById(id);
    }
}
