Blame view

src/main/java/com/huaheng/api/general/service/BasicDataApiService.java 13.1 KB
zengbo authored
1
package com.huaheng.api.general.service;
zengbo authored
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;
zengbo authored
6
7
import com.huaheng.pc.general.company.domain.Company;
import com.huaheng.pc.general.company.service.ICompanyService;
zengbo authored
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;
zengbo authored
24
import org.aspectj.weaver.loadtime.Aj;
zengbo authored
25
26
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
zengbo authored
27
28
import org.springframework.transaction.annotation.Transactional;
zengbo authored
29
30
31
32
import java.util.Date;
import java.util.List;

@Component
zengbo authored
33
@Transactional
zengbo authored
34
public class BasicDataApiService {
zengbo authored
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;
zengbo authored
58
59
60
    @Autowired
    ICompanyService companyService;
zengbo authored
61
62
63
64
65
66
67
    /**
     * 物料类别编码通用接口
     * @param dictData
     * @return
     */
    public AjaxResult dict(DictData dictData) {
        int result = 0;
pengcheng authored
68
        //检查字典表,如果没有就添加
zengbo authored
69
        DictData condition = new DictData();
zengbo authored
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());
pengcheng authored
80
                dictType.setDictType(dictData.getDictType());
zengbo authored
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) {
pengcheng authored
88
                        throw new ServiceException("新增字典类型失败!");
zengbo authored
89
90
91
92
93
                    }
                }
                //增新一条字典明细表的记录
                dictData.setHeaderId(dictList.get(0).getId());
                result = dictDataService.insertDictData(dictData);
zengbo authored
94
                if (result < 1) {
pengcheng authored
95
                    throw new ServiceException("新增字典数据失败!");
zengbo authored
96
                }
zengbo authored
97
            }
zengbo authored
98
        }catch (Exception e){
zengbo authored
99
            throw new ServiceException("数据问题。。。");
zengbo authored
100
        }
pengcheng authored
101
        return AjaxResult.success("新增字典成功");
zengbo authored
102
103
104
105
106
107
108
    }

    /**
     * 检查是否存在物料,如果存在就修改,不存在就新增
     * @param material
     * @return
     */
pengcheng authored
109
    @Transactional
zengbo authored
110
111
112
    public AjaxResult material(Material material)    {
        int result = 0;
        Material condition = new Material();
zengbo authored
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);
pengcheng authored
120
121
122
123
124
125
        warehouse=iWarehouseService.selectFirstEntity(warehouse);
        if(warehouse==null){
            return AjaxResult.error("没有该仓库");
        }else {
            material.setWarehouseId(warehouse.getId());
        }
zengbo authored
126
127
128
129
130
131
        company.setCode(material.getCompanyCode());
        company=companyService.selectFirstEntity(company);
        if(company==null){
            return AjaxResult.error("货主不对");
        }
        material.setCompanyId(company.getId());
zengbo authored
132
133
        try {
            condition.setCode(material.getCode());
zengbo authored
134
            condition.setWarehouseCode(warehouseCode);
zengbo authored
135
136
137
138
            Material entity = materialService.selectFirstEntity(condition);
            if (entity == null) {
                result = materialService.insert(material);
                if (result < 1) {
zengbo authored
139
                    throw new ServiceException("新增物料失败!");
zengbo authored
140
141
142
143
144
                }
            } else {
                material.setId(entity.getId());
                result = materialService.updateByModel(material);
                if (result < 1) {
zengbo authored
145
                    throw new ServiceException("修改物料失败!");
zengbo authored
146
                }
zengbo authored
147
            }
pengcheng authored
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);
zengbo authored
156
        }catch (Exception e){
zengbo authored
157
            throw new ServiceException("数据问题。。。");
zengbo authored
158
        }
zengbo authored
159
        return AjaxResult.success("新增物料成功");
zengbo authored
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();
zengbo authored
172
173
174
        try {
            user1.setLoginName(user.getLoginName());
            //判断系统中是否有该用户,如果有则更新,如果没有则新增
zengbo authored
175
176
177
178
179
            if(user.getLoginName()==null) {
                return AjaxResult.error("没有Name");
            }
                if (iUserService.selectmen(user.getLoginName()) == null) {
                result = iUserService.insertUser(user);
zengbo authored
180
                if (result < 1) {
zengbo authored
181
                    throw new ServiceException("新增人员档案失败!");
zengbo authored
182
183
184
185
                } else {
                    return AjaxResult.success("新增人员档案成功!");
                }
            } else {
zengbo authored
186
                result = iUserService.updateUser(user);
zengbo authored
187
                if (result < 1) {
zengbo authored
188
                    throw new ServiceException("更新人员档案失败!");
zengbo authored
189
190
191
                } else {
                    return AjaxResult.success("更新人员档案成功!");
                }
zengbo authored
192
            }
zengbo authored
193
        }catch (Exception e){
zengbo authored
194
            throw new ServiceException("数据问题。。。");
zengbo authored
195
196
197
198
        }
    }
zengbo authored
199
zengbo authored
200
201
202
203
204
205
206
    /**
     * 部门档案通用接口
     * @param dept
     * @return
     */
    public AjaxResult dept(Dept dept){
        int result = 0;
zengbo authored
207
        try {
zengbo authored
208
209
210
            Dept rs = iDeptService.selectDepts(dept.getCode());
                if (rs == null) {
                result = iDeptService.insertDepts(dept);
zengbo authored
211
                if (result < 1){
zengbo authored
212
                    throw new ServiceException("新增部门档案失败!");
zengbo authored
213
214
215
                }else {
                    return AjaxResult.success("新增部门档案成功!");
                }
zengbo authored
216
            }else {
zengbo authored
217
218
                dept.setId(rs.getId());
                result = iDeptService.updateDept(dept);
zengbo authored
219
                if (result < 1){
zengbo authored
220
                    throw new ServiceException("更新部门档案失败!");
zengbo authored
221
222
223
                }else {
                    return AjaxResult.success("更新部门档案成功!");
                }
zengbo authored
224
            }
zengbo authored
225
        }catch (Exception e){
zengbo authored
226
            throw new ServiceException("数据问题。。。");
zengbo authored
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();
zengbo authored
238
        try {
zengbo authored
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);
pengcheng authored
245
            if(warehouse==null || customer.getWarehouseCode()==null){
zengbo authored
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);
zengbo authored
254
                if (result < 1) {
zengbo authored
255
                    throw new ServiceException("新增客户档案失败!");
zengbo authored
256
257
258
259
                } else {
                    return AjaxResult.success("新增客户档案成功!");
                }
            } else {
zengbo authored
260
261
                customer.setId(rs.getId());
                result = iCustomerService.updateByModel(customer);
zengbo authored
262
                if (result < 1) {
zengbo authored
263
                    throw new ServiceException("更新客户档案失败!");
zengbo authored
264
265
266
                } else {
                    return AjaxResult.success("更新客户档案成功!");
                }
zengbo authored
267
            }
zengbo authored
268
        }catch (Exception e){
zengbo authored
269
            throw new ServiceException("数据问题。。。");
zengbo authored
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();
zengbo authored
281
        try {
zengbo authored
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");
            }
zengbo authored
289
            warehouse1.setCode(warehouse.getCode());
zengbo authored
290
            //判断系统中是否有该仓库,若有则更新,若无则新增
zengbo authored
291
292
293
            Warehouse rs = iWarehouseService.selectFirstEntity(warehouse1);
            if (rs == null) {
                result = iWarehouseService.insertWarehouseAndDict(warehouse);
zengbo authored
294
                if (result < 1) {
zengbo authored
295
                    throw new ServiceException("新增仓库档案失败!");
zengbo authored
296
297
298
                } else {
                    return AjaxResult.success("新增仓库档案成功!");
                }
zengbo authored
299
            } else {
zengbo authored
300
301
                warehouse.setId(rs.getId());
                result = iWarehouseService.updateByModel(warehouse);
zengbo authored
302
                if (result < 1) {
zengbo authored
303
                    throw new ServiceException("更新仓库档案失败!");
zengbo authored
304
305
306
                } else {
                    return AjaxResult.success("更新仓库档案成功!");
                }
zengbo authored
307
            }
zengbo authored
308
        }catch (Exception e){
zengbo authored
309
            throw new ServiceException("数据问题。。。");
zengbo authored
310
311
312
313
314
315
316
317
318
        }
    }

    /**
     * 供应商档案通用接口
     * @param supplier
     * @return
     */
    public AjaxResult supplier(Supplier supplier){
pengcheng authored
319
320
321
        Warehouse warehouse=new Warehouse();
        warehouse.setCode(supplier.getWarehouseCode());
        warehouse=iWarehouseService.selectFirstEntity(warehouse);
pengcheng authored
322
        if(warehouse==null || supplier.getWarehouseCode()==null){
pengcheng authored
323
324
325
326
            return AjaxResult.error("没有该仓库");
        }else {
            supplier.setWarehouseId(warehouse.getId());
        }
zengbo authored
327
328
329
        if(supplier.getCode()==null){
            return AjaxResult.error("没有code");
        }
zengbo authored
330
        int result = 0;
zengbo authored
331
        try {
pengcheng authored
332
333
            Supplier supplierB=new Supplier();
            supplierB.setCode(supplier.getCode());
zengbo authored
334
            supplierB=iSupplierService.selectFirstEntity(supplierB);
pengcheng authored
335
336
            if (supplierB== null) {
                result = iSupplierService.insert(supplier);
zengbo authored
337
                if (result < 1) {
zengbo authored
338
                    throw new ServiceException("新增供应商失败!");
zengbo authored
339
340
341
342
                } else {
                    return AjaxResult.success("新增供应商成功!");
                }
            } else {
pengcheng authored
343
344
                supplier.setId(supplierB.getId());
                result = iSupplierService.updateByModel(supplier);
zengbo authored
345
                if (result < 1) {
zengbo authored
346
                    throw new ServiceException("更新供应商失败!");
zengbo authored
347
348
349
                } else {
                    return AjaxResult.success("更新供应商成功!");
                }
zengbo authored
350
            }
zengbo authored
351
        }catch (Exception e){
pengcheng authored
352
            throw new ServiceException("数据问题。。。");
zengbo authored
353
354
355
        }
    }
}