Blame view

src/main/java/com/huaheng/api/general/service/BasicDataApiService.java 16.4 KB
zengbo authored
1
package com.huaheng.api.general.service;
zengbo authored
2
3

import com.huaheng.common.exception.service.ServiceException;
pengcheng authored
4
import com.huaheng.common.utils.StringUtils;
zengbo authored
5
6
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
zengbo authored
7
8
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.service.ICompanyService;
zengbo authored
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;
pengcheng authored
21
22
import com.huaheng.pc.system.dict.mapper.DictDataMapper;
import com.huaheng.pc.system.dict.mapper.DictTypeMapper;
zengbo authored
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;
zengbo authored
27
import org.aspectj.weaver.loadtime.Aj;
zengbo authored
28
29
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
zengbo authored
30
31
import org.springframework.transaction.annotation.Transactional;
pengcheng authored
32
import javax.annotation.Resource;
zengbo authored
33
34
35
36
import java.util.Date;
import java.util.List;

@Component
zengbo authored
37
@Transactional
zengbo authored
38
public class BasicDataApiService {
zengbo authored
39
40
41
42
43
44
45
    @Autowired
    IDictTypeService dictTypeService;
    @Autowired
    IDictDataService dictDataService;
    @Autowired
    IMaterialService materialService;
pengcheng authored
46
47
48
49
    @Resource
    private DictTypeMapper dictTypeMapper;
    @Resource
    private DictDataMapper dictDataMapper;
zengbo authored
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;
zengbo authored
66
67
68
    @Autowired
    ICompanyService companyService;
zengbo authored
69
70
71
72
73
74
    /**
     * 物料类别编码通用接口
     * @param dictData
     * @return
     */
    public AjaxResult dict(DictData dictData) {
pengcheng authored
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("没有字典键值");
        }
zengbo authored
87
        int result = 0;
pengcheng authored
88
89
90
91
92
93
        Warehouse warehouse =new Warehouse();
        warehouse.setCode(dictData.getWarehouseCode());
        warehouse = iWarehouseService.selectFirstEntity(warehouse);
        if (warehouse == null) {
            return AjaxResult.error("数据出现问题,系统没有该仓库");
        }
pengcheng authored
94
        //检查字典表,如果没有就添加
zengbo authored
95
        DictData condition = new DictData();
zengbo authored
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());
pengcheng authored
106
                dictType.setDictType(dictData.getDictType());
zengbo authored
107
108
109
                List<DictType> dictList = dictTypeService.selectDictTypeList(dictType);
                if (dictList.size() < 1) {
                    dictType.setWarehouseId(dictData.getWarehouseId());
pengcheng authored
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);
                    }
pengcheng authored
117
                    dictList.add(dictType);
zengbo authored
118
                    if (result < 1) {
pengcheng authored
119
                        throw new ServiceException("新增字典类型失败!");
zengbo authored
120
121
122
123
                    }
                }
                //增新一条字典明细表的记录
                dictData.setHeaderId(dictList.get(0).getId());
pengcheng authored
124
125
126
127
128
                if(StringUtils.isEmpty(dictData.getCreateBy())) {
                    result = dictDataService.insertDictData(dictData);
                }else {
                    result=dictDataMapper.insertDictData(dictData);
                }
zengbo authored
129
                if (result < 1) {
pengcheng authored
130
                    throw new ServiceException("新增字典数据失败!");
zengbo authored
131
                }
zengbo authored
132
            }
zengbo authored
133
        }catch (Exception e){
pengcheng authored
134
            throw new ServiceException("字典数据有误!!");
zengbo authored
135
        }
pengcheng authored
136
        return AjaxResult.success("新增字典成功");
zengbo authored
137
138
139
140
141
142
143
    }

    /**
     * 检查是否存在物料,如果存在就修改,不存在就新增
     * @param material
     * @return
     */
pengcheng authored
144
    @Transactional
zengbo authored
145
146
147
    public AjaxResult material(Material material)    {
        int result = 0;
        Material condition = new Material();
zengbo authored
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("公司代码有误!!");
zengbo authored
156
157
        }
        warehouse.setCode(warehouseCode);
pengcheng authored
158
159
        warehouse=iWarehouseService.selectFirstEntity(warehouse);
        if(warehouse==null){
160
            return AjaxResult.error("没有该仓库!!");
pengcheng authored
161
162
163
        }else {
            material.setWarehouseId(warehouse.getId());
        }
zengbo authored
164
165
166
        company.setCode(material.getCompanyCode());
        company=companyService.selectFirstEntity(company);
        if(company==null){
167
            return AjaxResult.error("没有该货主!!");
zengbo authored
168
169
        }
        material.setCompanyId(company.getId());
zengbo authored
170
171
        try {
            condition.setCode(material.getCode());
zengbo authored
172
            condition.setWarehouseCode(warehouseCode);
zengbo authored
173
174
175
176
            Material entity = materialService.selectFirstEntity(condition);
            if (entity == null) {
                result = materialService.insert(material);
                if (result < 1) {
zengbo authored
177
                    throw new ServiceException("新增物料失败!");
zengbo authored
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("更新物流成功!");
                }
zengbo authored
188
            }
pengcheng authored
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);
zengbo authored
197
        }catch (Exception e){
198
            throw new ServiceException("物料数据问题");
zengbo authored
199
        }
zengbo authored
200
        return AjaxResult.success("新增物料成功");
zengbo authored
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("没有人员名称!!");
        }
pengcheng authored
219
220
221
222
223
224
        if(user.getDeptId()==null){
            return AjaxResult.error("没有部门ID!!");
        }
        if(iDeptService.selectDeptById(user.getDeptId())==null){
            return AjaxResult.error("系统没有此部门!!");
        }
zengbo authored
225
226
227
        try {
            user1.setLoginName(user.getLoginName());
            //判断系统中是否有该用户,如果有则更新,如果没有则新增
zengbo authored
228
                if (iUserService.selectmen(user.getLoginName()) == null) {
229
                result = iUserService.insertUser(user);
zengbo authored
230
                if (result < 1) {
zengbo authored
231
                    throw new ServiceException("新增人员档案失败!");
zengbo authored
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("更新人员档案成功!");
//                }
zengbo authored
243
            }
zengbo authored
244
        }catch (Exception e){
zengbo authored
245
            throw new ServiceException("数据问题。。。");
zengbo authored
246
247
248
249
        }
    }
zengbo authored
250
zengbo authored
251
252
253
254
255
    /**
     * 部门档案通用接口
     * @param dept
     * @return
     */
256
    public AjaxResult dept(Dept dept){
zengbo authored
257
        int result = 0;
258
        if (dept.getCode()==null || dept.getCode()==""){
259
260
            return AjaxResult.error("部门编码不能为空!!");
        }
zengbo authored
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("新增部门档案成功!");
zengbo authored
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("更新部门档案成功!");
//                }
zengbo authored
279
            }
280
        }catch (Exception e){
zengbo authored
281
            throw new ServiceException("数据问题。。。");
zengbo authored
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("客户代码不能为空!!");
        }
zengbo authored
296
        try {
zengbo authored
297
298
299
            Warehouse warehouse=new Warehouse();
            warehouse.setCode(customer.getWarehouseCode());
            warehouse=iWarehouseService.selectFirstEntity(warehouse);
300
            if(warehouse==null ||customer.getWarehouseCode()==null||customer.getWarehouseCode()==""){
zengbo authored
301
302
303
304
305
                return AjaxResult.error("没有该仓库");
            }else {
                customer.setWarehouseId(warehouse.getId());
            }
                customer1.setCode(customer.getCode());
pengcheng authored
306
                customer1.setWarehouseCode(customer.getWarehouseCode());
zengbo authored
307
308
309
            Customer rs = iCustomerService.selectFirstEntity(customer1);
            if ( rs == null) {
                result = iCustomerService.insert(customer);
zengbo authored
310
                if (result < 1) {
zengbo authored
311
                    throw new ServiceException("新增客户档案失败!");
zengbo authored
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("更新客户档案成功!");
//                }
zengbo authored
324
            }
zengbo authored
325
        }catch (Exception e){
zengbo authored
326
            throw new ServiceException("数据问题。。。");
zengbo authored
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();
zengbo authored
338
        try {
zengbo authored
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("仓库编码不能为空!!");
zengbo authored
345
            }
zengbo authored
346
            warehouse1.setCode(warehouse.getCode());
zengbo authored
347
            //判断系统中是否有该仓库,若有则更新,若无则新增
zengbo authored
348
349
350
            Warehouse rs = iWarehouseService.selectFirstEntity(warehouse1);
            if (rs == null) {
                result = iWarehouseService.insertWarehouseAndDict(warehouse);
zengbo authored
351
                if (result < 1) {
zengbo authored
352
                    throw new ServiceException("新增仓库档案失败!");
zengbo authored
353
354
355
                } else {
                    return AjaxResult.success("新增仓库档案成功!");
                }
zengbo authored
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("更新仓库档案成功!");
//                }
zengbo authored
365
            }
zengbo authored
366
        }catch (Exception e){
367
            throw new ServiceException("仓库数据问题。。。");
zengbo authored
368
369
370
371
372
373
374
375
376
        }
    }

    /**
     * 供应商档案通用接口
     * @param supplier
     * @return
     */
    public AjaxResult supplier(Supplier supplier){
pengcheng authored
377
378
379
        Warehouse warehouse=new Warehouse();
        warehouse.setCode(supplier.getWarehouseCode());
        warehouse=iWarehouseService.selectFirstEntity(warehouse);
380
        if(warehouse==null || supplier.getWarehouseCode()==null||supplier.getWarehouseCode()==""){
pengcheng authored
381
382
383
384
            return AjaxResult.error("没有该仓库");
        }else {
            supplier.setWarehouseId(warehouse.getId());
        }
385
        if(supplier.getCode()==null||supplier.getCode()==""){
pengcheng authored
386
            return AjaxResult.error("没有供应商代码");
zengbo authored
387
        }
zengbo authored
388
        int result = 0;
zengbo authored
389
        try {
pengcheng authored
390
391
            Supplier supplierB=new Supplier();
            supplierB.setCode(supplier.getCode());
pengcheng authored
392
            supplierB.setWarehouseCode(supplier.getWarehouseCode());
zengbo authored
393
            supplierB=iSupplierService.selectFirstEntity(supplierB);
pengcheng authored
394
395
            if (supplierB== null) {
                result = iSupplierService.insert(supplier);
zengbo authored
396
                if (result < 1) {
zengbo authored
397
                    throw new ServiceException("新增供应商失败!");
zengbo authored
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("更新供应商成功!");
//                }
zengbo authored
410
            }
zengbo authored
411
        }catch (Exception e){
412
            throw new ServiceException("供应商数据问题。。。");
zengbo authored
413
414
415
        }
    }
}