CompanyDictServiceImpl.java
13.2 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.laowu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laowu.common.exception.HttpException;
import com.laowu.dto.company.AddCompanyDTO;
import com.laowu.dto.company.CompanyDTO;
import com.laowu.dto.company.DeleteCompanyDTO;
import com.laowu.dto.company.StationCompanyDTO;
import com.laowu.mapper.*;
import com.laowu.model.*;
import com.laowu.service.CompanyDictService;
import com.laowu.util.ConstantUtils;
import com.laowu.vo.company.CompanyUpdateHistoryVO;
import com.laowu.vo.company.CompanyVO;
import com.laowu.vo.company.RelateWorkVO;
import com.laowu.vo.team.TotalTeamsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* <p>
* 企业管理表 服务实现类
* </p>
*
* @author Tuyp
* @since 2023-02-16
*/
@Service
public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, CompanyDictDO> implements CompanyDictService {
@Autowired
private CompanyPhotoMapper companyPhotoMapper;
@Autowired
private CompanyLabelMapper companyLabelMapper;
@Autowired
private CompanyRelateWorkMapper companyRelateWorkMapper;
@Autowired
private CompanyUpdateHistoryMapper companyUpdateHistoryMapper;
@Autowired
private PositionDictMapper positionDictMapper;
@Autowired
private WorkstationDictMapper workstationDictMapper;
public IPage<CompanyVO> company(CompanyDTO companyDTO) {
Page pager = new Page(companyDTO.getPageNum(), companyDTO.getPageSize());
IPage<CompanyVO> company = this.baseMapper.company(pager, companyDTO.getCompanyName(), companyDTO.getProvince(), companyDTO.getCity(), companyDTO.getCounty());
List<CompanyVO> records = company.getRecords();
for (CompanyVO companyVO : records) {
//图
List<CompanyPhotoDO> companyPhotoDOS = companyPhotoMapper.selectList(new QueryWrapper<CompanyPhotoDO>()
.lambda()
.eq(CompanyPhotoDO::getCompanyId, companyVO.getId()));
companyVO.setCompanyPhotoDOS(companyPhotoDOS);
//标签
List<CompanyLabelDO> companyLabelDOS = companyLabelMapper.selectList(new QueryWrapper<CompanyLabelDO>()
.lambda()
.eq(CompanyLabelDO::getCompanyId, companyVO.getId()));
companyVO.setCompanyLabelDOS(companyLabelDOS);
//关联业务
List<RelateWorkVO> relateWorkDOS = companyRelateWorkMapper.relateWork(companyVO.getId());
companyVO.setRelateWorkVOS(relateWorkDOS);
//历史
List<CompanyUpdateHistoryVO> companyUpdateHistoryVOS = companyUpdateHistoryMapper.companyUpdateHistory(companyVO.getId());
companyVO.setCompanyUpdateHistoryVOS(companyUpdateHistoryVOS);
}
return company;
}
@Transactional(rollbackFor = Exception.class)
public String deleteCompany(DeleteCompanyDTO deleteCompanyDTO) {
this.baseMapper.deleteById(deleteCompanyDTO.getId());
companyPhotoMapper.delete(new QueryWrapper<CompanyPhotoDO>()
.lambda()
.eq(CompanyPhotoDO::getCompanyId, deleteCompanyDTO.getId()));
companyLabelMapper.delete(new QueryWrapper<CompanyLabelDO>()
.lambda()
.eq(CompanyLabelDO::getCompanyId, deleteCompanyDTO.getId()));
companyRelateWorkMapper.delete(new QueryWrapper<CompanyRelateWorkDO>()
.lambda()
.eq(CompanyRelateWorkDO::getCompanyId, deleteCompanyDTO.getId()));
CompanyUpdateHistoryDO companyUpdateHistoryDO = new CompanyUpdateHistoryDO();
companyUpdateHistoryDO.setOpr("删除了企业");
companyUpdateHistoryDO.setAdministerId(deleteCompanyDTO.getUserId());
companyUpdateHistoryDO.setModule(deleteCompanyDTO.getModule());
companyUpdateHistoryMapper.insert(companyUpdateHistoryDO);
return ConstantUtils.DELETE_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String addCompany(AddCompanyDTO addCompanyDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<CompanyDictDO>()
.lambda()
.eq(CompanyDictDO::getCompanyName, addCompanyDTO.getCompanyName()));
if (count > 0) {
throw new HttpException(30001);
}
CompanyDictDO companyDictDO = new CompanyDictDO();
BeanUtils.copyProperties(addCompanyDTO, companyDictDO);
if (null != addCompanyDTO.getStationId()) {
WorkstationDictDO workstationDictDO = workstationDictMapper.selectById(addCompanyDTO.getStationId());
if (null != workstationDictDO) {
companyDictDO.setCompanyOrigin(workstationDictDO.getWorkstationName());
}
}
this.baseMapper.insert(companyDictDO);
List<CompanyPhotoDO> companyPhotoDOS = addCompanyDTO.getCompanyPhotoDOS();
for (CompanyPhotoDO companyPhotoDO : companyPhotoDOS) {
companyPhotoDO.setCompanyId(companyDictDO.getId());
companyPhotoMapper.insert(companyPhotoDO);
}
List<CompanyLabelDO> companyLabelDOList = addCompanyDTO.getCompanyLabelDOS();
for (CompanyLabelDO companyLabelDO : companyLabelDOList) {
companyLabelDO.setCompanyId(companyDictDO.getId());
companyLabelMapper.insert(companyLabelDO);
}
Long stationId = addCompanyDTO.getStationId();
if (null != stationId) {
CompanyRelateWorkDO companyRelateWorkDO = new CompanyRelateWorkDO();
companyRelateWorkDO.setCompanyId(companyDictDO.getId());
companyRelateWorkDO.setStationId(stationId);
companyRelateWorkMapper.insert(companyRelateWorkDO);
}
//记录 日志
CompanyUpdateHistoryDO companyUpdateHistoryDO = new CompanyUpdateHistoryDO();
companyUpdateHistoryDO.setAdministerId(addCompanyDTO.getUserId());
companyUpdateHistoryDO.setModule(addCompanyDTO.getModule());
companyUpdateHistoryDO.setOpr("创建了企业");
companyUpdateHistoryDO.setCompanyId(companyDictDO.getId());
companyUpdateHistoryMapper.insert(companyUpdateHistoryDO);
return ConstantUtils.ADD_SUCCESS;
}
@Transactional
public String updateCompany(AddCompanyDTO addCompanyDTO) {
CompanyDictDO companyDictDO = this.baseMapper.selectById(addCompanyDTO.getId());
CompanyDictDO companyDictDO1 = new CompanyDictDO();
BeanUtils.copyProperties(addCompanyDTO, companyDictDO1);
this.baseMapper.updateById(companyDictDO1);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("变更了“");
List<CompanyPhotoDO> companyPhotoDOS = addCompanyDTO.getCompanyPhotoDOS();
//图片
if (null != companyPhotoDOS) {
companyPhotoMapper.delete(new QueryWrapper<CompanyPhotoDO>()
.lambda()
.eq(CompanyPhotoDO::getCompanyId, addCompanyDTO.getId()));
for (CompanyPhotoDO companyPhotoDO : companyPhotoDOS) {
companyPhotoDO.setCompanyId(addCompanyDTO.getId());
companyPhotoMapper.insert(companyPhotoDO);
}
stringBuffer.append("企业图片、");
}
//标签
List<CompanyLabelDO> companyLabelDOS = addCompanyDTO.getCompanyLabelDOS();
if (null != companyLabelDOS) {
companyLabelMapper.delete(new QueryWrapper<CompanyLabelDO>()
.lambda()
.eq(CompanyLabelDO::getCompanyId, addCompanyDTO.getId()));
for (CompanyLabelDO companyLabelDO : companyLabelDOS) {
companyLabelDO.setCompanyId(addCompanyDTO.getId());
companyLabelMapper.insert(companyLabelDO);
}
stringBuffer.append("企业标签、");
}
if (null != companyDictDO.getCompanyName() && !companyDictDO.getCompanyName().equals(addCompanyDTO.getCompanyName())) {
stringBuffer.append("企业名称、");
}
if (null != companyDictDO.getProvince() && !companyDictDO.getProvince().equals(addCompanyDTO.getProvince())) {
stringBuffer.append("省、");
}
if (null != companyDictDO.getCity() && !companyDictDO.getCity().equals(addCompanyDTO.getCity())) {
stringBuffer.append("市、");
}
if (null != companyDictDO.getCounty() && !companyDictDO.getCounty().equals(addCompanyDTO.getCounty())) {
stringBuffer.append("县、");
}
if (null != companyDictDO.getPositionId() && !companyDictDO.getPositionId().equals(addCompanyDTO.getPositionId())) {
stringBuffer.append("经营范围、");
}
if (null != companyDictDO.getCompanyCode() && !companyDictDO.getCompanyCode().equals(addCompanyDTO.getCompanyCode())) {
stringBuffer.append("企业代码、");
}
if (null != companyDictDO.getCompanyDesc() && !companyDictDO.getCompanyDesc().equals(addCompanyDTO.getCompanyDesc())) {
stringBuffer.append("企业简介、");
}
String opr = stringBuffer.substring(0, stringBuffer.length() - 1) + "”";
//修改了哪些信息
CompanyUpdateHistoryDO companyUpdateHistoryDO = new CompanyUpdateHistoryDO();
companyUpdateHistoryDO.setModule(addCompanyDTO.getModule());
companyUpdateHistoryDO.setAdministerId(addCompanyDTO.getUserId());
companyUpdateHistoryDO.setCompanyId(addCompanyDTO.getId());
companyUpdateHistoryDO.setOpr(opr);
companyUpdateHistoryMapper.insert(companyUpdateHistoryDO);
return ConstantUtils.SUCCESS_UPDATE;
}
public CompanyVO oneCompany(CompanyDictDO companyDictDO) {
CompanyVO companyVO = new CompanyVO();
CompanyDictDO companyDictDO1 = this.baseMapper.selectById(companyDictDO.getId());
BeanUtils.copyProperties(companyDictDO1, companyVO);
if (null != companyDictDO1.getPositionId()) {
PositionDictDO positionDictDO = positionDictMapper.selectById(companyDictDO1.getPositionId());
companyVO.setPositionType(positionDictDO.getPositionType());
}
List<CompanyPhotoDO> companyPhotoDOS = companyPhotoMapper.selectList(new QueryWrapper<CompanyPhotoDO>()
.lambda()
.eq(CompanyPhotoDO::getCompanyId, companyDictDO1.getId()));
companyVO.setCompanyPhotoDOS(companyPhotoDOS);
List<CompanyLabelDO> companyLabelDOS = companyLabelMapper.selectList(new QueryWrapper<CompanyLabelDO>()
.lambda()
.eq(CompanyLabelDO::getCompanyId, companyDictDO1.getId()));
companyVO.setCompanyLabelDOS(companyLabelDOS);
//关联业务
List<RelateWorkVO> relateWorkDOS = companyRelateWorkMapper.relateWork(companyDictDO.getId());
companyVO.setRelateWorkVOS(relateWorkDOS);
//历史
List<CompanyUpdateHistoryVO> companyUpdateHistoryVOS = companyUpdateHistoryMapper.companyUpdateHistory(companyVO.getId());
companyVO.setCompanyUpdateHistoryVOS(companyUpdateHistoryVOS);
return companyVO;
}
public TotalTeamsVO totalCount(WorkstationDictDO workstationDictDO) {
TotalTeamsVO totalTeamsVO = new TotalTeamsVO();
Integer count = this.baseMapper.stationCompanyCount(workstationDictDO.getId());
totalTeamsVO.setCount(count);
return totalTeamsVO;
}
public IPage stationCompany(StationCompanyDTO stationCompanyDTO) {
Page pager = new Page(stationCompanyDTO.getPageNum(), stationCompanyDTO.getPageSize());
IPage<CompanyVO> company = this.baseMapper.stationCompany(pager, stationCompanyDTO.getStationId(), stationCompanyDTO.getCompanyName(), stationCompanyDTO.getProvince(), stationCompanyDTO.getCompanyName(), stationCompanyDTO.getCounty());
List<CompanyVO> records = company.getRecords();
for (CompanyVO companyVO : records) {
//图
List<CompanyPhotoDO> companyPhotoDOS = companyPhotoMapper.selectList(new QueryWrapper<CompanyPhotoDO>()
.lambda()
.eq(CompanyPhotoDO::getCompanyId, companyVO.getId()));
companyVO.setCompanyPhotoDOS(companyPhotoDOS);
//标签
List<CompanyLabelDO> companyLabelDOS = companyLabelMapper.selectList(new QueryWrapper<CompanyLabelDO>()
.lambda()
.eq(CompanyLabelDO::getCompanyId, companyVO.getId()));
companyVO.setCompanyLabelDOS(companyLabelDOS);
//关联业务
List<RelateWorkVO> relateWorkDOS = companyRelateWorkMapper.relateWork(companyVO.getId());
companyVO.setRelateWorkVOS(relateWorkDOS);
//历史
List<CompanyUpdateHistoryVO> companyUpdateHistoryVOS = companyUpdateHistoryMapper.companyUpdateHistory(companyVO.getId());
companyVO.setCompanyUpdateHistoryVOS(companyUpdateHistoryVOS);
}
return company;
}
}