265278a2c16fef0cd126fe60883e33d4cc741771.svn-base
3.36 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
88
89
90
91
92
93
94
95
96
97
98
package com.phxl.modules.goods.service.ctcareprov;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.phxl.common.utils.BaseException;
import com.phxl.common.utils.IdUtil;
import com.phxl.modules.goods.dao.ctcareprov.CTCareProvDao;
import com.phxl.modules.goods.entity.ctcareprov.CTCareProv;
import java.util.*;
@Service
public class CTCareProvService{
@Autowired
private CTCareProvDao cTCareProvDao;
/**
* 日志对象
*/
protected Logger logger = LoggerFactory.getLogger(getClass());
public boolean batchSaveOrUpdate(List<CTCareProv> careProvs) {
boolean success = false;
try {
checkCTCareProv(careProvs);
} catch (Exception e) {
throw new BaseException(e.getMessage());
}
if (CollectionUtils.isNotEmpty(careProvs)) {
List<String> codes = new ArrayList<String>();
for (CTCareProv ctCareProv : careProvs) {
String ryCode = ctCareProv.getMfmedStaffCode();
codes.add(ryCode);
}
Map<String,Object> map = new HashMap<String, Object>();
map.put("ryCodes",codes);
List<CTCareProv> exsitList = cTCareProvDao.batchSelect(map);
List<CTCareProv> insertList = new ArrayList<CTCareProv>();
List<CTCareProv> updateList = new ArrayList<CTCareProv>();
for (CTCareProv ctCareProv : careProvs) {
boolean flag = false;
for (CTCareProv exsitCtCareProv : exsitList) {
if (ctCareProv.getMfmedStaffCode().equals(exsitCtCareProv.getMfmedStaffCode())) {
ctCareProv.setId(exsitCtCareProv.getId());
flag = true;
}
}
if (!flag) {
ctCareProv.setId(IdUtil.uuid());
insertList.add(ctCareProv);
}else{
updateList.add(ctCareProv);
}
}
if(CollectionUtils.isNotEmpty(updateList)){
cTCareProvDao.batchUpdate(updateList);
}
if(CollectionUtils.isNotEmpty(insertList)){
cTCareProvDao.batchInsert(insertList);
}
success = true;
}
return success;
}
private void checkCTCareProv(List<CTCareProv> careProvs) {
if(careProvs == null || careProvs.size() == 0){
logger.error("无相应人员资料信息");
throw new BaseException("无相应人员资料信息");
}
for (CTCareProv ctCareProv : careProvs) {
String mfmedStaffCode = ctCareProv.getMfmedStaffCode();
if (StringUtils.isEmpty(mfmedStaffCode)) {
logger.error("人员资料人员代码不能为空");
throw new BaseException("人员资料人员代码不能为空");
}
String logonUser = ctCareProv.getLogonUser();
if (StringUtils.isEmpty(logonUser)) {
logger.error("人员资料登陆账号不能为空");
throw new BaseException("人员资料登陆账号不能为空");
}
String realName = ctCareProv.getRealName();
if (StringUtils.isEmpty(realName)) {
logger.error("人员资料真实账号不能为空");
throw new BaseException("人员资料真实账号不能为空");
}
}
}
}