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