SmartUserRelationServiceImpl.java
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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);
}
}