BasicDataApiService.java
18.6 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
package com.huaheng.api.general.service;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.service.ICompanyService;
import com.huaheng.pc.general.customer.domain.Customer;
import com.huaheng.pc.general.customer.service.ICustomerService;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.general.supplier.domain.Supplier;
import com.huaheng.pc.general.supplier.service.ISupplierService;
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.service.IWarehouseService;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.domain.DictType;
import com.huaheng.pc.system.dict.mapper.DictDataMapper;
import com.huaheng.pc.system.dict.mapper.DictTypeMapper;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.system.dict.service.IDictTypeService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
@Transactional
public class BasicDataApiService {
@Autowired
IDictTypeService dictTypeService;
@Autowired
IDictDataService dictDataService;
@Autowired
IMaterialService materialService;
@Resource
private DictTypeMapper dictTypeMapper;
@Resource
private DictDataMapper dictDataMapper;
@Autowired
IUserService iUserService;
@Autowired
IDeptService iDeptService;
@Autowired
ICustomerService iCustomerService;
@Autowired
IWarehouseService iWarehouseService;
@Autowired
ISupplierService iSupplierService;
@Autowired
ICompanyService companyService;
/**
* 物料类别编码通用接口
* @param dictData
* @return
*/
public AjaxResult dict(DictData dictData) {
if(StringUtils.isEmpty(dictData.getWarehouseCode())){
return AjaxResult.error("没有仓库编码");
}
if(StringUtils.isEmpty(dictData.getDictLabel())){
return AjaxResult.error("没有字典标签");
}
if(StringUtils.isEmpty(dictData.getDictType())){
return AjaxResult.error("没有字典类型");
}
if(StringUtils.isEmpty(dictData.getDictValue())){
return AjaxResult.error("没有字典键值");
}
int result = 0;
Warehouse warehouse =new Warehouse();
warehouse.setCode(dictData.getWarehouseCode());
warehouse = iWarehouseService.selectFirstEntity(warehouse);
if (warehouse == null) {
return AjaxResult.error("数据出现问题,系统没有该仓库");
}
//检查字典表,如果没有就添加
DictData condition = new DictData();
try {
condition.setDictType(dictData.getDictType());
condition.setWarehouseCode(dictData.getWarehouseCode());
condition.setDictValue(dictData.getDictValue());
condition.setEnable(true);
List<DictData> dictDatas = dictDataService.selectDictDataList(dictData);
if (dictDatas.size() < 1) {
//找出字典头表的id
DictType dictType = new DictType();
dictType.setWarehouseCode(dictData.getWarehouseCode());
dictType.setDictType(dictData.getDictType());
List<DictType> dictList = dictTypeService.selectDictTypeList(dictType);
if (dictList.size() < 1) {
dictType.setWarehouseId(dictData.getWarehouseId());
dictType.setCreateBy(dictData.getCreateBy());
dictType.setCreateTime(dictData.getCreateTime());
if(StringUtils.isEmpty(dictType.getCreateBy())) {
result = dictTypeService.insertDictType(dictType);
}else {
result=dictTypeMapper.insertDictType(dictType);
}
dictList.add(dictType);
if (result < 1) {
throw new ServiceException("新增字典类型失败!");
}
}
//增新一条字典明细表的记录
dictData.setHeaderId(dictList.get(0).getId());
if(StringUtils.isEmpty(dictData.getCreateBy())) {
result = dictDataService.insertDictData(dictData);
}else {
result=dictDataMapper.insertDictData(dictData);
}
if (result < 1) {
throw new ServiceException("新增字典数据失败!");
}
}
}catch (Exception e){
throw new ServiceException("字典数据有误!!");
}
return AjaxResult.success("新增字典成功");
}
/**
* 检查是否存在物料,如果存在就修改,不存在就新增
* @param material
* @return
*/
@Transactional
public AjaxResult material(Material material) {
int result = 0;
Material condition = new Material();
Warehouse warehouse=new Warehouse();
Company company=new Company();
String warehouseCode=material.getWarehouseCode();
if(material.getCode()==null || material.getCode()=="") {
return AjaxResult.error("存货编码不能为空!!");
}
if (warehouseCode ==null || warehouseCode==""||material.getCompanyCode()==null||material.getCompanyCode()==""){
return AjaxResult.error("公司代码有误!!");
}
warehouse.setCode(warehouseCode);
warehouse=iWarehouseService.selectFirstEntity(warehouse);
if(warehouse==null){
return AjaxResult.error("没有该仓库!!");
}else {
material.setWarehouseId(warehouse.getId());
}
company.setCode(material.getCompanyCode());
company=companyService.selectFirstEntity(company);
if(company==null){
return AjaxResult.error("没有该货主!!");
}
material.setCompanyId(company.getId());
try {
condition.setCode(material.getCode());
condition.setWarehouseCode(warehouseCode);
Material entity = materialService.selectFirstEntity(condition);
if (entity == null) {
result = materialService.insert(material);
if (result < 1) {
throw new ServiceException("新增物料失败!");
}
} else {
// return AjaxResult.error("已有该物料,无法进行修改!!");
material.setId(entity.getId());
result = materialService.updateByModel(material);
if (result < 1) {
throw new ServiceException("更新物料失败!");
}else {
return AjaxResult.success("更新物流成功!");
}
}
DictData dictData=new DictData();
dictData.setHeaderId(17);
dictData.setWarehouseId(material.getWarehouseId());
dictData.setWarehouseCode(material.getWarehouseCode());
dictData.setDictValue(material.getType());
dictData.setDictLabel(material.getDictLabel());
dictData.setDictType("materialType");
this.dict(dictData);
}catch (Exception e){
throw new ServiceException("物料数据问题");
}
return AjaxResult.success("新增物料成功");
}
/**
* 人员档案通用接口
* @param user
* @return
*/
public AjaxResult user(User user){
int result = 0;
User user1 = new User();
if(user.getLoginName()==null || user.getLoginName()=="") {
return AjaxResult.error("没有人员编码!!");
}
if (user.getUserName()==null || user.getUserName()==""){
return AjaxResult.error("没有人员名称!!");
}
if(user.getDeptId()==null){
return AjaxResult.error("没有部门ID!!");
}
if(iDeptService.selectDeptById(user.getDeptId())==null){
return AjaxResult.error("系统没有此部门!!");
}
try {
user1.setLoginName(user.getLoginName());
//判断系统中是否有该用户,如果有则更新,如果没有则新增
if (iUserService.selectmen(user.getLoginName()) == null) {
//默认密码为123456
if(user.getPassword()==null) {
user.setPassword("123456");
}
//默认为普通用户
if(StringUtils.isEmpty(user.getRoleIds())) {
List<Integer> roleIds=new ArrayList<>();
roleIds.add(2);
user.setRoleIds(roleIds);
}
//默认为长沙仓库
if(StringUtils.isEmpty(user.getCompanyIdList())) {
List<Integer> companyIdList = new ArrayList<>();
companyIdList.add(2);
user.setCompanyIdList(companyIdList);
}
result = iUserService.insertUser(user);
if (result < 1) {
throw new ServiceException("新增人员档案失败!");
} else {
return AjaxResult.success("新增人员档案成功!");
}
} else {
return AjaxResult.error("已有该人员档案,无法进行修改!");
// result = iUserService.updateUser(user);
// if (result < 1) {
// throw new ServiceException("更新人员档案失败!");
// } else {
// return AjaxResult.success("更新人员档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("数据问题。。。");
}
}
/**
* 部门档案通用接口
* @param dept
* @return
*/
@Transactional
public AjaxResult dept(Dept dept) {
int result = 0;
String code = dept.getCode();
if (code == null || code == "") {
return AjaxResult.error("部门编码不能为空!!");
}
try {
Dept rs = iDeptService.selectDepts(code);
if (rs == null) {
int x = code.length() % 2;
if (x != 0) {
return AjaxResult.error("部门编码长度应是双数");
} else {
int y = code.length() / 2;
if (y >= 1) {
String scode = code.substring(0, 2);
if (iDeptService.selectDepts(scode) == null) {
dept.setCode(scode);
dept.setParentId(100);
dept.setAncestors("0,100");
dept.setOrderNum("1");
result = iDeptService.insertDept(dept);
if (result < 1) {
throw new ServiceException("新增部门档案失败!");
}
}
}
for (int z = 1; z <=y; z++) {
String sqcode = code.substring(0, 2 * (z - 1));
Dept sdept = iDeptService.selectDepts(sqcode);
String sscode = code.substring(0, 2 * z);
if (iDeptService.selectDepts(sscode) == null) {
dept.setCode(sscode);
dept.setParentId(sdept.getId());
dept.setAncestors(sdept.getAncestors() + "," + sdept.getId());
dept.setOrderNum(String.valueOf(z));
result = iDeptService.insertDept(dept);
if (result < 1) {
throw new ServiceException("新增部门档案失败!");
}
}
}
}
return AjaxResult.success("新增部门成功");
} else {
dept.setId(rs.getId());
int num = iDeptService.updatesDept(dept);
if (num < 1) {
throw new ServiceException("部门修改失败");
} else {
return AjaxResult.success("部门修改成功");
}
}
} catch (Exception e) {
throw new ServiceException("数据问题。。。");
}
}
/**
* 客户档案通用接口
* @param customer
* @return
*/
public AjaxResult customer(Customer customer){
int result = 0;
Customer customer1 = new Customer();
if(customer.getCode()==null||customer.getCode()=="") {
return AjaxResult.error("客户代码不能为空!!");
}
try {
Warehouse warehouse=new Warehouse();
warehouse.setCode(customer.getWarehouseCode());
warehouse=iWarehouseService.selectFirstEntity(warehouse);
if(warehouse==null ||customer.getWarehouseCode()==null||customer.getWarehouseCode()==""){
return AjaxResult.error("没有该仓库");
}else {
customer.setWarehouseId(warehouse.getId());
}
customer1.setCode(customer.getCode());
customer1.setWarehouseCode(customer.getWarehouseCode());
Customer rs = iCustomerService.selectFirstEntity(customer1);
if ( rs == null) {
result = iCustomerService.insert(customer);
if (result < 1) {
throw new ServiceException("新增客户档案失败!");
} else {
return AjaxResult.success("新增客户档案成功!");
}
} else {
return AjaxResult.error("已有该客户,无法进行修改!!");
// customer.setId(rs.getId());
// result = iCustomerService.updateByModel(customer);
// if (result < 1) {
// throw new ServiceException("更新客户档案失败!");
// } else {
// return AjaxResult.success("更新客户档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("数据问题。。。");
}
}
/**
* 仓库档案通用接口
* @param warehouse
* @return
*/
public AjaxResult warehouse(Warehouse warehouse){
int result = 0;
Warehouse warehouse1 = new Warehouse();
try {
Company company= companyService.selectEntityById(warehouse.getCompanyId());
if(company==null){
return AjaxResult.error("没有该货主");
}
if(warehouse.getCode()==null||warehouse.getCode()=="") {
return AjaxResult.error("仓库编码不能为空!!");
}
warehouse1.setCode(warehouse.getCode());
//判断系统中是否有该仓库,若有则更新,若无则新增
Warehouse rs = iWarehouseService.selectFirstEntity(warehouse1);
if (rs == null) {
result = iWarehouseService.insertWarehouseAndDict(warehouse);
if (result < 1) {
throw new ServiceException("新增仓库档案失败!");
} else {
return AjaxResult.success("新增仓库档案成功!");
}
} else {
return AjaxResult.error("已有该仓库,无法进行修改!");
// warehouse.setId(rs.getId());
// result = iWarehouseService.updateByModel(warehouse);
// if (result < 1) {
// throw new ServiceException("更新仓库档案失败!");
// } else {
// return AjaxResult.success("更新仓库档案成功!");
// }
}
}catch (Exception e){
throw new ServiceException("仓库数据问题。。。");
}
}
/**
* 供应商档案通用接口
* @param supplier
* @return
*/
public AjaxResult supplier(Supplier supplier){
Warehouse warehouse=new Warehouse();
warehouse.setCode(supplier.getWarehouseCode());
warehouse=iWarehouseService.selectFirstEntity(warehouse);
if(warehouse==null || supplier.getWarehouseCode()==null||supplier.getWarehouseCode()==""){
return AjaxResult.error("没有该仓库");
}else {
supplier.setWarehouseId(warehouse.getId());
}
if(supplier.getCode()==null||supplier.getCode()==""){
return AjaxResult.error("没有供应商代码");
}
int result = 0;
try {
Supplier supplierB=new Supplier();
supplierB.setCode(supplier.getCode());
supplierB.setWarehouseCode(supplier.getWarehouseCode());
supplierB=iSupplierService.selectFirstEntity(supplierB);
if (supplierB== null) {
result = iSupplierService.insert(supplier);
if (result < 1) {
throw new ServiceException("新增供应商失败!");
} else {
return AjaxResult.success("新增供应商成功!");
}
} else {
return AjaxResult.error("已有该供应商,无法修改!!");
// supplier.setId(supplierB.getId());
// result = iSupplierService.updateByModel(supplier);
// if (result < 1) {
// throw new ServiceException("更新供应商失败!");
// } else {
// return AjaxResult.success("更新供应商成功!");
// }
}
}catch (Exception e){
throw new ServiceException("供应商数据问题。。。");
}
}
}