|
@@ -11,6 +11,7 @@ import com.yunzhi.marketing.xlk.service.IInstitutionService;
|
11
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
12
|
import org.springframework.stereotype.Service;
|
13
|
13
|
|
|
14
|
+import java.time.LocalDateTime;
|
14
|
15
|
import java.util.List;
|
15
|
16
|
|
16
|
17
|
/**
|
|
@@ -34,47 +35,30 @@ public class InstitutionServiceImpl extends ServiceImpl<InstitutionMapper, Insti
|
34
|
35
|
*/
|
35
|
36
|
@Override
|
36
|
37
|
public ResponseBean saveInstitution(Institution institution) {
|
37
|
|
- int institutionCodeLength = institution.getInstitutionCode().length();
|
38
|
|
- if (institutionCodeLength != 2 && institutionCodeLength != 4 && institutionCodeLength != 6){
|
39
|
|
- return ResponseBean.error("请输入合法长度的code", ResponseBean.ERROR_UNAVAILABLE);
|
40
|
|
- }
|
41
|
38
|
|
|
39
|
+ Institution parentInstitution = institutionMapper.selectById(institution.getParentInstitutionId());
|
42
|
40
|
// 根据code获取机构
|
43
|
41
|
LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
44
|
|
- queryWrapper.eq(Institution::getInstitutionCode,institution.getInstitutionCode());
|
45
|
|
- Institution childInstitution = institutionMapper.selectOne(queryWrapper);
|
46
|
|
- if (null != childInstitution){
|
47
|
|
- return ResponseBean.error("此组织机构code已存在", ResponseBean.ERROR_UNAVAILABLE);
|
48
|
|
- }
|
49
|
|
-
|
50
|
|
- // 判断组织机构长度
|
51
|
|
- // 集团插入
|
52
|
|
- if (institutionCodeLength == 2){
|
53
|
|
- institution.setType(1);
|
54
|
|
- }
|
55
|
|
-
|
56
|
|
- // 子区域插入
|
57
|
|
- if (institutionCodeLength == 4){
|
58
|
|
- Institution blocInstitution = getChildInstitution(institution.getInstitutionCode(), 0, 2);
|
59
|
|
- if (null == blocInstitution){
|
60
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
61
|
|
- }
|
62
|
|
- institution.setType(2);
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- // 子区域插入
|
66
|
|
- if (institutionCodeLength == 6){
|
67
|
|
- Institution blocInstitution = getChildInstitution(institution.getInstitutionCode(), 0, 2);
|
68
|
|
- if (null == blocInstitution){
|
69
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
|
42
|
+ queryWrapper.eq(Institution::getParentInstitutionId,institution.getParentInstitutionId());
|
|
43
|
+ queryWrapper.orderByDesc(Institution::getInstitutionCode);
|
|
44
|
+ List<Institution> institutions = institutionMapper.selectList(queryWrapper);
|
|
45
|
+ if (institutions.size() > 0) {
|
|
46
|
+ Institution lastInstitution = institutions.get(0);
|
|
47
|
+ String institutionCode = lastInstitution.getInstitutionCode();
|
|
48
|
+ String firstCode = institutionCode.substring(0, institutionCode.length() - 2);
|
|
49
|
+ String lastCode = institutionCode.substring(institutionCode.length() - 2);
|
|
50
|
+ String currentCode =String.valueOf(Integer.parseInt(lastCode) + 1);
|
|
51
|
+ if (currentCode.length() == 1) {
|
|
52
|
+ institution.setInstitutionCode(firstCode + "0" +currentCode);
|
|
53
|
+ }else {
|
|
54
|
+ institution.setInstitutionCode(firstCode + currentCode);
|
70
|
55
|
}
|
71
|
56
|
|
72
|
|
- Institution cityInstitution = getChildInstitution(institution.getInstitutionCode(), 2, 4);
|
73
|
|
- if (null == cityInstitution){
|
74
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
75
|
|
- }
|
76
|
|
- institution.setType(3);
|
|
57
|
+ }else {
|
|
58
|
+ institution.setInstitutionCode(parentInstitution.getInstitutionCode() + "01");
|
77
|
59
|
}
|
|
60
|
+
|
|
61
|
+ institution.setCreateDate(LocalDateTime.now());
|
78
|
62
|
institutionMapper.insert(institution);
|
79
|
63
|
|
80
|
64
|
return ResponseBean.success(institution);
|
|
@@ -107,50 +91,7 @@ public class InstitutionServiceImpl extends ServiceImpl<InstitutionMapper, Insti
|
107
|
91
|
*/
|
108
|
92
|
@Override
|
109
|
93
|
public ResponseBean updateInstitution(Institution institution) {
|
110
|
|
- int institutionCodeLength = institution.getInstitutionCode().length();
|
111
|
|
- if (institutionCodeLength != 2 && institutionCodeLength != 4 && institutionCodeLength != 6){
|
112
|
|
- return ResponseBean.error("请输入合法长度的code", ResponseBean.ERROR_UNAVAILABLE);
|
113
|
|
- }
|
114
|
|
-
|
115
|
|
- // 根据code获取机构
|
116
|
|
- LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
117
|
|
- queryWrapper.eq(Institution::getInstitutionCode,institution.getInstitutionCode());
|
118
|
|
- queryWrapper.ne(Institution::getInstitutionCode,institution.getInstitutionCode());
|
119
|
|
- Institution childInstitution = institutionMapper.selectOne(queryWrapper);
|
120
|
|
- if (null != childInstitution){
|
121
|
|
- return ResponseBean.error("此组织机构code已存在", ResponseBean.ERROR_UNAVAILABLE);
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- // 判断组织机构长度
|
125
|
|
- // 集团插入
|
126
|
|
- if (institutionCodeLength == 2){
|
127
|
|
- institution.setType(1);
|
128
|
|
- }
|
129
|
|
-
|
130
|
|
- // 子区域插入
|
131
|
|
- if (institutionCodeLength == 4){
|
132
|
|
- Institution blocInstitution = getChildInstitution(institution.getInstitutionCode(), 0, 1);
|
133
|
|
- if (null == blocInstitution){
|
134
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
135
|
|
- }
|
136
|
|
- institution.setType(2);
|
137
|
|
- }
|
138
|
|
-
|
139
|
|
- // 子区域插入
|
140
|
|
- if (institutionCodeLength == 6){
|
141
|
|
- Institution blocInstitution = getChildInstitution(institution.getInstitutionCode(), 0, 1);
|
142
|
|
- if (null == blocInstitution){
|
143
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- Institution cityInstitution = getChildInstitution(institution.getInstitutionCode(), 2, 3);
|
147
|
|
- if (null == cityInstitution){
|
148
|
|
- return ResponseBean.error("请输入合法的有层级的code", ResponseBean.ERROR_UNAVAILABLE);
|
149
|
|
- }
|
150
|
|
- institution.setType(3);
|
151
|
|
- }
|
152
|
94
|
institutionMapper.updateById(institution);
|
153
|
|
-
|
154
|
95
|
return ResponseBean.success(institution);
|
155
|
96
|
}
|
156
|
97
|
|