package com.yuchen.saas.park.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuchen.saas.park.api.entity.park.PmgBatParkXCPayInfo;
import com.yuchen.saas.park.service.mapper.XcPayInfoMapper;
import com.yuchen.saas.park.service.service.XCPayInfoService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.stereotype.Service;

@Service
public class XCPayInfoServiceImpl extends BaseServiceImpl<XcPayInfoMapper, PmgBatParkXCPayInfo> implements XCPayInfoService {

    @Override
    public PmgBatParkXCPayInfo getByParkId(Long parkId) {
        LambdaQueryWrapper<PmgBatParkXCPayInfo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(PmgBatParkXCPayInfo::getParkId,parkId);
        return getOne(wrapper, false);
    }

    @Override
    public PmgBatParkXCPayInfo getByOidPartner(String oidPartner) {
        LambdaQueryWrapper<PmgBatParkXCPayInfo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(PmgBatParkXCPayInfo::getOidPartner,oidPartner);
        return getOne(wrapper, false);
    }

    @Override
    public R addOrUpdate(PmgBatParkXCPayInfo pmgBatParkXCPayInfo) {
        // 查询该园区是否有过厦门银行支付信息
        PmgBatParkXCPayInfo old = getByParkId(pmgBatParkXCPayInfo.getParkId());
        if (null == old || old.getId().equals(pmgBatParkXCPayInfo.getId())){
            return R.status(saveOrUpdate(pmgBatParkXCPayInfo));
        }
        return R.error("该园区已经存在支付信息");
    }
}
