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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuchen.saas.park.api.entity.property.SaasParkPropertyBillChargeSetup;
import com.yuchen.saas.park.api.request.SaasParkPropertyBillChargeSetupReq;
import com.yuchen.saas.park.service.mapper.property.SaasParkPropertyBillChargeSetupMapper;
import com.yuchen.saas.park.service.service.property.SaasParkPropertyBillChargeSetupService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 账单收费设置 服务实现类
 * </p>
 *
 * @author miaoqs
 * @since 2024-09-12
 */
@Service
public class SaasParkPropertyBillChargeSetupServiceImpl extends BaseServiceImpl<SaasParkPropertyBillChargeSetupMapper, SaasParkPropertyBillChargeSetup> implements SaasParkPropertyBillChargeSetupService {

    @Override
    public SaasParkPropertyBillChargeSetup detailByParkIdAndCommunityId(SaasParkPropertyBillChargeSetupReq propertyBillChargeSetupReq) {
        return this.getOne(new LambdaQueryWrapper<SaasParkPropertyBillChargeSetup>()
                .eq(SaasParkPropertyBillChargeSetup::getParkId, propertyBillChargeSetupReq.getParkId())
                .eq(SaasParkPropertyBillChargeSetup::getCommunityId, propertyBillChargeSetupReq.getCommunityId()));
    }

    @Override
    public boolean saveOrUpdateByParam(SaasParkPropertyBillChargeSetup propertyBillChargeSetup) {
        if(Func.isEmpty(propertyBillChargeSetup.getId())){
            SaasParkPropertyBillChargeSetup billChargeSetup = this.getOne(new LambdaQueryWrapper<SaasParkPropertyBillChargeSetup>()
                    .eq(SaasParkPropertyBillChargeSetup::getParkId, propertyBillChargeSetup.getParkId())
                    .eq(SaasParkPropertyBillChargeSetup::getCommunityId, propertyBillChargeSetup.getCommunityId()));
            if(Func.isNotEmpty(billChargeSetup)){
                throw new RuntimeException("该项目下已存在该社区配置,不能重复配置");
            }
        }
        return this.saveOrUpdate(propertyBillChargeSetup);
    }

}
