SmartUserRelationServiceImpl.java 2.61 KB
package com.glsx.smart.service.impl;

import com.glsx.smart.dao.entity.SmartUserRelation;
import com.glsx.smart.dao.mapper.SmartUserRelationMapper;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.SmartUserRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-15
 */
@Slf4j
@Service
public class SmartUserRelationServiceImpl implements SmartUserRelationService {
    @Resource
    private SmartUserRelationMapper relationMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return relationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertOrUpdate(SmartUserRelation userRelation) {
        if (userRelation.getId() == null) {
            return relationMapper.insertSelective(userRelation);
        } else {
            SmartUserRelation record = relationMapper.selectByPrimaryKey(
                    userRelation.getId());
            if (record != null) {
                return relationMapper.updateByPrimaryKeySelective(userRelation);
            } else {
                throw new BusinessException(ResultEnum.ID_NOT_FOUND);
            }
        }
    }

    @Override
    public synchronized Long insertSelective(SmartUserRelation record) {
        SmartUserRelation request = new SmartUserRelation();
        request.setPhone(record.getPhone());
        request.setChannel(record.getChannel());  //涂鸦
        SmartUserRelation user = relationMapper.getSingle(request);
        if(user != null && user.getId() > 0L){
            record.setId(user.getId());
            relationMapper.updateByPrimaryKeySelective(record);
        } else{
            relationMapper.insertSelective(record);
        }
        return record.getId();
    }

    @Override
    public SmartUserRelation getSingle(SmartUserRelation record) {
        return relationMapper.getSingle(record);
    }

    @Override
    public SmartUserRelation selectByPrimaryKey(Long id) {
        return relationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SmartUserRelation record) {
        return relationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateBatchSelective(List<SmartUserRelation> list) {
        return relationMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert(List<SmartUserRelation> list) {
        return relationMapper.batchInsert(list);
    }

}