package com.srs.stureg.service.impl;

import java.util.List;
import com.srs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.srs.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.srs.stureg.domain.SrsRegInfo;
import com.srs.stureg.mapper.PayMoneyMapper;
import com.srs.stureg.domain.PayMoney;
import com.srs.stureg.service.IPayMoneyService;

/**
 * 网上缴费情况Service业务层处理
 * 
 * @author 邓
 * @date 2023-05-20
 */
@Service
public class PayMoneyServiceImpl implements IPayMoneyService 
{
    @Autowired
    private PayMoneyMapper payMoneyMapper;

    /**
     * 查询网上缴费情况
     * 
     * @param id 网上缴费情况主键
     * @return 网上缴费情况
     */
    @Override
    public PayMoney selectPayMoneyById(Long id)
    {
        return payMoneyMapper.selectPayMoneyById(id);
    }

    /**
     * 查询网上缴费情况列表
     * 
     * @param payMoney 网上缴费情况
     * @return 网上缴费情况
     */
    @Override
    public List<PayMoney> selectPayMoneyList(PayMoney payMoney)
    {
        return payMoneyMapper.selectPayMoneyList(payMoney);
    }

    /**
     * 新增网上缴费情况
     * 
     * @param payMoney 网上缴费情况
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPayMoney(PayMoney payMoney)
    {
        payMoney.setCreateTime(DateUtils.getNowDate());
        int rows = payMoneyMapper.insertPayMoney(payMoney);
        insertSrsRegInfo(payMoney);
        return rows;
    }

    /**
     * 修改网上缴费情况
     * 
     * @param payMoney 网上缴费情况
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePayMoney(PayMoney payMoney)
    {
        payMoney.setUpdateTime(DateUtils.getNowDate());
        payMoneyMapper.deleteSrsRegInfoByRegisterId(payMoney.getId());
        insertSrsRegInfo(payMoney);
        return payMoneyMapper.updatePayMoney(payMoney);
    }

    /**
     * 批量删除网上缴费情况
     * 
     * @param ids 需要删除的网上缴费情况主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePayMoneyByIds(Long[] ids)
    {
        payMoneyMapper.deleteSrsRegInfoByRegisterIds(ids);
        return payMoneyMapper.deletePayMoneyByIds(ids);
    }

    /**
     * 删除网上缴费情况信息
     * 
     * @param id 网上缴费情况主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePayMoneyById(Long id)
    {
        payMoneyMapper.deleteSrsRegInfoByRegisterId(id);
        return payMoneyMapper.deletePayMoneyById(id);
    }

    /**
     * 新增注册信息
信息
     * 
     * @param payMoney 网上缴费情况对象
     */
    public void insertSrsRegInfo(PayMoney payMoney)
    {
        List<SrsRegInfo> srsRegInfoList = payMoney.getSrsRegInfoList();
        Long id = payMoney.getId();
        if (StringUtils.isNotNull(srsRegInfoList))
        {
            List<SrsRegInfo> list = new ArrayList<SrsRegInfo>();
            for (SrsRegInfo srsRegInfo : srsRegInfoList)
            {
                srsRegInfo.setRegisterId(id);
                list.add(srsRegInfo);
            }
            if (list.size() > 0)
            {
                payMoneyMapper.batchSrsRegInfo(list);
            }
        }
    }
}
