package com.sptg.estate.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.FaceChargeProjectResidentialUserDto;
import com.sptg.estate.api.entity.FaceChargeProjectResidentialUser;
import com.sptg.estate.biz.mapper.FaceChargeProjectResidentialUserMapper;
import com.sptg.estate.biz.service.FaceChargeProjectResidentialUserServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * title: UnitServiceImpl
 * package: com.sptg.estate.biz.security.impl
 * description: 人脸套餐绑定 服务层实现层
 *
 *             
 *                 
 */
@Service
public class FaceChargeProjectResidentialUserServiceImpl extends ServiceImpl<FaceChargeProjectResidentialUserMapper, FaceChargeProjectResidentialUser> implements FaceChargeProjectResidentialUserServiceInterface {

    @Override
    @Transactional
    public ResultBean<Boolean> addFaceChargeProjectResidentialUser(FaceChargeProjectResidentialUserDto dto){
        FaceChargeProjectResidentialUser faceChargeProjectResidentialUser = new FaceChargeProjectResidentialUser();
        BeanUtils.copyProperties(dto,faceChargeProjectResidentialUser);
        boolean result = this.insert(faceChargeProjectResidentialUser);
        if (!result){
            return new ResultBean<>(ResultEnum.ERROR,false);
        }
        return new ResultBean<>(ResultEnum.SUCCESS,true);
    }

    @Override
    public ResultBean<FaceChargeProjectResidentialUser> findFaceChargeProjectResidentialUser(FaceChargeProjectResidentialUserDto dto){
        Wrapper<FaceChargeProjectResidentialUser> wrapper = new EntityWrapper<>();
        if (null != dto.getUserId()){
            wrapper.eq("l_user_id",dto.getUserId());
        }
        if (null != dto.getTypeItem()){
            wrapper.eq("i_type_item",dto.getTypeItem());
        }
        FaceChargeProjectResidentialUser faceChargeProjectResidentialUser = this.selectOne(wrapper);
        return new ResultBean<>(ResultEnum.SUCCESS,faceChargeProjectResidentialUser);
    }

}
