package com.xhpc.payment.service.impl;

import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.payment.domain.XhpcRefundAudit;
import com.xhpc.common.domain.XhpcRefundOrder;
import com.xhpc.payment.mapper.XhpcRefundAuditMapper;
import com.xhpc.payment.mapper.XhpcRefundOrderMapper;
import com.xhpc.payment.service.IXhpcRefundAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 退款审核信息 服务层
 *
 * @author ruoyi
 */
@Service
public class XhpcRefundAuditServiceImpl implements IXhpcRefundAuditService {

    @Autowired
    private XhpcRefundAuditMapper xhpcRefundAuditMapper;

    @Autowired
    private XhpcRefundOrderMapper xhpcRefundOrderMapper;

    @Autowired
    private XhpcUserAccountStatementServiceImpl xhpcUserAccountStatementService;

    /**
     * 新增 退款审核
     *
     * @param xhpcRefundAudit 退款审核
     */
    @Override
    @Transactional
    public AjaxResult insert(XhpcRefundAudit xhpcRefundAudit) {
        XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
        xhpcRefundOrder.setRefundOrderId(xhpcRefundAudit.getRefundOrderId());
        xhpcRefundOrder.setExamineStatus(xhpcRefundAudit.getStatus());
        xhpcRefundOrder.setCreateTime(new Date());
        xhpcRefundOrder.setStatus(StatusConstants.REFUND_ORDER_STATUS_WAIT);

        int updateStatus = xhpcRefundOrderMapper.updateExamineStatus(xhpcRefundOrder);
        if (updateStatus == 0) {
            return AjaxResult.error();
        }
        xhpcRefundAudit.setCreateTime(new Date());
        xhpcRefundAuditMapper.insert(xhpcRefundAudit);
        return null;
    }

    /**
     * 退款审核列表
     *
     * @param refundOrderId
     * @return
     */
    @Override
    public List<Map<String, Object>> list(Long refundOrderId) {
        return xhpcRefundAuditMapper.list(refundOrderId);
    }

    @Override
    public int updateCommunityPersonnelMoney(Long communityPersonnelId, BigDecimal surplusMoney,Integer isRefundApplication) {
        return xhpcRefundAuditMapper.updateCommunityPersonnelMoney(communityPersonnelId, surplusMoney,isRefundApplication);
    }

    @Override
    public Map<String, Object> getCommunityPersonnelById(Long userId, String tenantId) {
        return xhpcRefundAuditMapper.getCommunityPersonnelById(userId, tenantId);
    }

    @Override
    public Map<String, Object> getXhpcAppInternetUserById(Long userId, String tenantId) {
        return xhpcRefundAuditMapper.getXhpcAppInternetUserById(userId, tenantId);
    }
}
