|
1
|
package com.huaheng.api.general.service;
|
|
2
3
|
import com.huaheng.common.exception.service.ServiceException;
|
|
4
|
import com.huaheng.common.utils.StringUtils;
|
|
5
6
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
7
8
|
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.service.ICompanyService;
|
|
9
10
11
12
13
14
15
16
17
18
19
20
|
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;
|
|
21
22
|
import com.huaheng.pc.system.dict.mapper.DictDataMapper;
import com.huaheng.pc.system.dict.mapper.DictTypeMapper;
|
|
23
24
25
26
|
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;
|
|
27
|
import org.aspectj.weaver.loadtime.Aj;
|
|
28
29
|
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
|
|
30
31
|
import org.springframework.transaction.annotation.Transactional;
|
|
32
|
import javax.annotation.Resource;
|
|
33
34
35
36
|
import java.util.Date;
import java.util.List;
@Component
|
|
37
|
@Transactional
|
|
38
|
public class BasicDataApiService {
|
|
39
40
41
42
43
44
45
|
@Autowired
IDictTypeService dictTypeService;
@Autowired
IDictDataService dictDataService;
@Autowired
IMaterialService materialService;
|
|
46
47
48
49
|
@Resource
private DictTypeMapper dictTypeMapper;
@Resource
private DictDataMapper dictDataMapper;
|
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
@Autowired
IUserService iUserService;
@Autowired
IDeptService iDeptService;
@Autowired
ICustomerService iCustomerService;
@Autowired
IWarehouseService iWarehouseService;
@Autowired
ISupplierService iSupplierService;
|
|
66
67
68
|
@Autowired
ICompanyService companyService;
|
|
69
70
71
72
73
74
|
/**
* 物料类别编码通用接口
* @param dictData
* @return
*/
public AjaxResult dict(DictData dictData) {
|
|
75
76
77
78
79
80
81
82
83
84
85
86
|
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("没有字典键值");
}
|
|
87
|
int result = 0;
|
|
88
89
90
91
92
93
|
Warehouse warehouse =new Warehouse();
warehouse.setCode(dictData.getWarehouseCode());
warehouse = iWarehouseService.selectFirstEntity(warehouse);
if (warehouse == null) {
return AjaxResult.error("数据出现问题,系统没有该仓库");
}
|
|
94
|
//检查字典表,如果没有就添加
|
|
95
|
DictData condition = new DictData();
|
|
96
97
98
99
100
101
102
103
104
105
|
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());
|
|
106
|
dictType.setDictType(dictData.getDictType());
|
|
107
108
109
|
List<DictType> dictList = dictTypeService.selectDictTypeList(dictType);
if (dictList.size() < 1) {
dictType.setWarehouseId(dictData.getWarehouseId());
|
|
110
111
112
113
114
115
116
|
dictType.setCreateBy(dictData.getCreateBy());
dictType.setCreateTime(dictData.getCreateTime());
if(StringUtils.isEmpty(dictType.getCreateBy())) {
result = dictTypeService.insertDictType(dictType);
}else {
result=dictTypeMapper.insertDictType(dictType);
}
|
|
117
|
dictList.add(dictType);
|
|
118
|
if (result < 1) {
|
|
119
|
throw new ServiceException("新增字典类型失败!");
|
|
120
121
122
123
|
}
}
//增新一条字典明细表的记录
dictData.setHeaderId(dictList.get(0).getId());
|
|
124
125
126
127
128
|
if(StringUtils.isEmpty(dictData.getCreateBy())) {
result = dictDataService.insertDictData(dictData);
}else {
result=dictDataMapper.insertDictData(dictData);
}
|
|
129
|
if (result < 1) {
|
|
130
|
throw new ServiceException("新增字典数据失败!");
|
|
131
|
}
|
|
132
|
}
|
|
133
|
}catch (Exception e){
|
|
134
|
throw new ServiceException("字典数据有误!!");
|
|
135
|
}
|
|
136
|
return AjaxResult.success("新增字典成功");
|
|
137
138
139
140
141
142
143
|
}
/**
* 检查是否存在物料,如果存在就修改,不存在就新增
* @param material
* @return
*/
|
|
144
|
@Transactional
|
|
145
146
147
|
public AjaxResult material(Material material) {
int result = 0;
Material condition = new Material();
|
|
148
149
150
|
Warehouse warehouse=new Warehouse();
Company company=new Company();
String warehouseCode=material.getWarehouseCode();
|
|
151
152
153
154
155
|
if(material.getCode()==null || material.getCode()=="") {
return AjaxResult.error("存货编码不能为空!!");
}
if (warehouseCode ==null || warehouseCode==""||material.getCompanyCode()==null||material.getCompanyCode()==""){
return AjaxResult.error("公司代码有误!!");
|
|
156
157
|
}
warehouse.setCode(warehouseCode);
|
|
158
159
|
warehouse=iWarehouseService.selectFirstEntity(warehouse);
if(warehouse==null){
|
|
160
|
return AjaxResult.error("没有该仓库!!");
|
|
161
162
163
|
}else {
material.setWarehouseId(warehouse.getId());
}
|
|
164
165
166
|
company.setCode(material.getCompanyCode());
company=companyService.selectFirstEntity(company);
if(company==null){
|
|
167
|
return AjaxResult.error("没有该货主!!");
|
|
168
169
|
}
material.setCompanyId(company.getId());
|
|
170
171
|
try {
condition.setCode(material.getCode());
|
|
172
|
condition.setWarehouseCode(warehouseCode);
|
|
173
174
175
176
|
Material entity = materialService.selectFirstEntity(condition);
if (entity == null) {
result = materialService.insert(material);
if (result < 1) {
|
|
177
|
throw new ServiceException("新增物料失败!");
|
|
178
179
|
}
} else {
|
|
180
181
182
183
184
185
186
187
|
// return AjaxResult.error("已有该物料,无法进行修改!!");
material.setId(entity.getId());
result = materialService.updateByModel(material);
if (result < 1) {
throw new ServiceException("更新物料失败!");
}else {
return AjaxResult.success("更新物流成功!");
}
|
|
188
|
}
|
|
189
190
191
192
193
194
195
196
|
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);
|
|
197
|
}catch (Exception e){
|
|
198
|
throw new ServiceException("物料数据问题");
|
|
199
|
}
|
|
200
|
return AjaxResult.success("新增物料成功");
|
|
201
202
203
204
205
206
207
208
209
210
211
212
|
}
/**
* 人员档案通用接口
* @param user
* @return
*/
public AjaxResult user(User user){
int result = 0;
User user1 = new User();
|
|
213
214
215
216
217
218
|
if(user.getLoginName()==null || user.getLoginName()=="") {
return AjaxResult.error("没有人员编码!!");
}
if (user.getUserName()==null || user.getUserName()==""){
return AjaxResult.error("没有人员名称!!");
}
|
|
219
220
221
222
223
224
|
if(user.getDeptId()==null){
return AjaxResult.error("没有部门ID!!");
}
if(iDeptService.selectDeptById(user.getDeptId())==null){
return AjaxResult.error("系统没有此部门!!");
}
|
|
225
226
227
|
try {
user1.setLoginName(user.getLoginName());
//判断系统中是否有该用户,如果有则更新,如果没有则新增
|
|
228
|
if (iUserService.selectmen(user.getLoginName()) == null) {
|
|
229
|
result = iUserService.insertUser(user);
|
|
230
|
if (result < 1) {
|
|
231
|
throw new ServiceException("新增人员档案失败!");
|
|
232
233
234
235
|
} else {
return AjaxResult.success("新增人员档案成功!");
}
} else {
|
|
236
237
238
239
240
241
242
|
return AjaxResult.error("已有该人员档案,无法进行修改!");
// result = iUserService.updateUser(user);
// if (result < 1) {
// throw new ServiceException("更新人员档案失败!");
// } else {
// return AjaxResult.success("更新人员档案成功!");
// }
|
|
243
|
}
|
|
244
|
}catch (Exception e){
|
|
245
|
throw new ServiceException("数据问题。。。");
|
|
246
247
248
249
|
}
}
|
|
250
|
|
|
251
252
253
254
255
|
/**
* 部门档案通用接口
* @param dept
* @return
*/
|
|
256
|
public AjaxResult dept(Dept dept){
|
|
257
|
int result = 0;
|
|
258
|
if (dept.getCode()==null || dept.getCode()==""){
|
|
259
260
|
return AjaxResult.error("部门编码不能为空!!");
}
|
|
261
|
try {
|
|
262
263
264
265
266
267
268
|
Dept rs = iDeptService.selectDepts(dept.getCode());
if (rs == null) {
result = iDeptService.insertDept(dept);
if (result < 1){
throw new ServiceException("新增部门档案失败!");
}else {
return AjaxResult.success("新增部门档案成功!");
|
|
269
|
}
|
|
270
271
272
273
274
275
276
277
278
|
}else {
return AjaxResult.error("已有该部门档案,无法进行修改!");
// dept.setId(rs.getId());
// result = iDeptService.updateDept(dept);
// if (result < 1){
// throw new ServiceException("更新部门档案失败!");
// }else {
// return AjaxResult.success("更新部门档案成功!");
// }
|
|
279
|
}
|
|
280
|
}catch (Exception e){
|
|
281
|
throw new ServiceException("数据问题。。。");
|
|
282
283
284
285
286
287
288
289
290
291
292
|
}
}
/**
* 客户档案通用接口
* @param customer
* @return
*/
public AjaxResult customer(Customer customer){
int result = 0;
Customer customer1 = new Customer();
|
|
293
294
295
|
if(customer.getCode()==null||customer.getCode()=="") {
return AjaxResult.error("客户代码不能为空!!");
}
|
|
296
|
try {
|
|
297
298
299
|
Warehouse warehouse=new Warehouse();
warehouse.setCode(customer.getWarehouseCode());
warehouse=iWarehouseService.selectFirstEntity(warehouse);
|
|
300
|
if(warehouse==null ||customer.getWarehouseCode()==null||customer.getWarehouseCode()==""){
|
|
301
302
303
304
305
|
return AjaxResult.error("没有该仓库");
}else {
customer.setWarehouseId(warehouse.getId());
}
customer1.setCode(customer.getCode());
|
|
306
|
customer1.setWarehouseCode(customer.getWarehouseCode());
|
|
307
308
309
|
Customer rs = iCustomerService.selectFirstEntity(customer1);
if ( rs == null) {
result = iCustomerService.insert(customer);
|
|
310
|
if (result < 1) {
|
|
311
|
throw new ServiceException("新增客户档案失败!");
|
|
312
313
314
315
|
} else {
return AjaxResult.success("新增客户档案成功!");
}
} else {
|
|
316
317
318
319
320
321
322
323
|
return AjaxResult.error("已有该客户,无法进行修改!!");
// customer.setId(rs.getId());
// result = iCustomerService.updateByModel(customer);
// if (result < 1) {
// throw new ServiceException("更新客户档案失败!");
// } else {
// return AjaxResult.success("更新客户档案成功!");
// }
|
|
324
|
}
|
|
325
|
}catch (Exception e){
|
|
326
|
throw new ServiceException("数据问题。。。");
|
|
327
328
329
330
331
332
333
334
335
336
337
|
}
}
/**
* 仓库档案通用接口
* @param warehouse
* @return
*/
public AjaxResult warehouse(Warehouse warehouse){
int result = 0;
Warehouse warehouse1 = new Warehouse();
|
|
338
|
try {
|
|
339
340
341
342
|
Company company= companyService.selectEntityById(warehouse.getCompanyId());
if(company==null){
return AjaxResult.error("没有该货主");
}
|
|
343
344
|
if(warehouse.getCode()==null||warehouse.getCode()=="") {
return AjaxResult.error("仓库编码不能为空!!");
|
|
345
|
}
|
|
346
|
warehouse1.setCode(warehouse.getCode());
|
|
347
|
//判断系统中是否有该仓库,若有则更新,若无则新增
|
|
348
349
350
|
Warehouse rs = iWarehouseService.selectFirstEntity(warehouse1);
if (rs == null) {
result = iWarehouseService.insertWarehouseAndDict(warehouse);
|
|
351
|
if (result < 1) {
|
|
352
|
throw new ServiceException("新增仓库档案失败!");
|
|
353
354
355
|
} else {
return AjaxResult.success("新增仓库档案成功!");
}
|
|
356
|
} else {
|
|
357
358
359
360
361
362
363
364
|
return AjaxResult.error("已有该仓库,无法进行修改!");
// warehouse.setId(rs.getId());
// result = iWarehouseService.updateByModel(warehouse);
// if (result < 1) {
// throw new ServiceException("更新仓库档案失败!");
// } else {
// return AjaxResult.success("更新仓库档案成功!");
// }
|
|
365
|
}
|
|
366
|
}catch (Exception e){
|
|
367
|
throw new ServiceException("仓库数据问题。。。");
|
|
368
369
370
371
372
373
374
375
376
|
}
}
/**
* 供应商档案通用接口
* @param supplier
* @return
*/
public AjaxResult supplier(Supplier supplier){
|
|
377
378
379
|
Warehouse warehouse=new Warehouse();
warehouse.setCode(supplier.getWarehouseCode());
warehouse=iWarehouseService.selectFirstEntity(warehouse);
|
|
380
|
if(warehouse==null || supplier.getWarehouseCode()==null||supplier.getWarehouseCode()==""){
|
|
381
382
383
384
|
return AjaxResult.error("没有该仓库");
}else {
supplier.setWarehouseId(warehouse.getId());
}
|
|
385
|
if(supplier.getCode()==null||supplier.getCode()==""){
|
|
386
|
return AjaxResult.error("没有供应商代码");
|
|
387
|
}
|
|
388
|
int result = 0;
|
|
389
|
try {
|
|
390
391
|
Supplier supplierB=new Supplier();
supplierB.setCode(supplier.getCode());
|
|
392
|
supplierB.setWarehouseCode(supplier.getWarehouseCode());
|
|
393
|
supplierB=iSupplierService.selectFirstEntity(supplierB);
|
|
394
395
|
if (supplierB== null) {
result = iSupplierService.insert(supplier);
|
|
396
|
if (result < 1) {
|
|
397
|
throw new ServiceException("新增供应商失败!");
|
|
398
399
400
401
|
} else {
return AjaxResult.success("新增供应商成功!");
}
} else {
|
|
402
403
404
405
406
407
408
409
|
return AjaxResult.error("已有该供应商,无法修改!!");
// supplier.setId(supplierB.getId());
// result = iSupplierService.updateByModel(supplier);
// if (result < 1) {
// throw new ServiceException("更新供应商失败!");
// } else {
// return AjaxResult.success("更新供应商成功!");
// }
|
|
410
|
}
|
|
411
|
}catch (Exception e){
|
|
412
|
throw new ServiceException("供应商数据问题。。。");
|
|
413
414
415
|
}
}
}
|