package com.huiju.estateagents.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.common.CommConstant;
import com.huiju.estateagents.entity.TaCustomImg;
import com.huiju.estateagents.mapper.TaCustomImgMapper;
import com.huiju.estateagents.service.ITaCustomImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-12-17
 */
@Service
public class TaCustomImgServiceImpl extends ServiceImpl<TaCustomImgMapper, TaCustomImg> implements ITaCustomImgService {

    @Autowired
    private TaCustomImgMapper taCustomImgMapper;

    @Override
    public boolean countCustomImg(TaCustomImg taCustomImg, Integer orgId) {
        ResponseBean responseBean = new ResponseBean();
        QueryWrapper<TaCustomImg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("img_type", taCustomImg.getImgType());
        queryWrapper.eq("org_id", orgId);
        if (taCustomImg.getImgId() != null){
            queryWrapper.ne("img_id", taCustomImg.getImgId());
        }
        TaCustomImg indexTacustomImg = taCustomImgMapper.selectOne(queryWrapper);
        if (indexTacustomImg != null){
            responseBean.addError("您已新增了推荐图，请勿重新添加");
            return false;
        }
        return true;
    }
}
