CompanyServiceImpl.java
9.83 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
package com.huaheng.pc.general.company.service;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
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.domain.CompanyWu;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.CompanyMapper;
import com.huaheng.pc.general.company.mapper.CompanyMapperAuto;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.service.IWarehouseService;
import com.huaheng.pc.inventory.inventory.domain.Inventory;
import com.huaheng.pc.inventory.inventory.service.IInventoryService;
import com.huaheng.pc.system.user.domain.UserCompany;
import com.huaheng.pc.system.user.mapper.UserCompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service("company")
public class CompanyServiceImpl implements ICompanyService {
@Resource
private UserCompanyMapper userCompanyMapper;
@Resource
private CompanyMapperAuto aotuMapper;
@Resource
private CompanyMapper companyMapper;
@Autowired
private IWarehouseService warehouseService;
@Resource
private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;
@Resource
private IInventoryService inventoryService;
@Override
public List<Company> selectListEntityByLike(Company condition) {
return aotuMapper.selectListEntityByLike(condition);
}
@Override
public List<Company> selectListEntityByEqual(Company condition) {
return aotuMapper.selectListEntityByEqual(condition);
}
@Override
public Company selectFirstEntity(Company condition) {
Company item = aotuMapper.selectFirstEntity(condition);
return item;
}
@Override
public Company selectEntityById(Integer id) {
return aotuMapper.selectEntityById(id);
}
@Override
public List<Map<String, Object>> selectListMapByEqual(String columns, Company condition) {
return aotuMapper.selectListMapByEqual(columns, condition);
}
@Override
public Map<String, Object> selectFirstMap(String columns, Company condition) {
Map<String, Object> item = aotuMapper.selectFirstMap(columns, condition);
return item;
}
@Override
public int insert(Company record) {
return aotuMapper.insert(record);
}
@Override
public int updateByModel(Company record) {
return aotuMapper.updateByModel(record);
}
@Override
public int updateByCondition(Company record, Company condition) {
return aotuMapper.updateByCondition(record, condition);
}
@Override
public int deleteById(Integer id) {
return aotuMapper.deleteById(id);
}
@Override
public int deleteByCondition(Company condition) {
return aotuMapper.deleteByCondition(condition);
}
@Override
public List<Company> selectCompanyList(Company condition) {
return companyMapper.selectCompanyList(condition);
}
@Override
public List<Company> getEnableCompanyList() {
Company condition = new Company();
condition.setDeleted(false);
condition.setEnable(true);
condition.setWarehouseId(ShiroUtils.getWarehouseId());
return companyMapper.getCurrentCompanyList(condition);
}
/**
* 查询用户对应的货主
*
* @return 结果
*/
@Override
public List<Company> selectCompanyByCurrentUserId()
{
List<Company> list = companyMapper.selectCompanyByUserId(ShiroUtils.getUserId(), ShiroUtils.getWarehouseId());
return list;
}
/**
* 查询出仓库所有的货主,并且根据用户id查询对应的货主,包含的就将flag赋为true
* @param userId
* @return
*/
@Override
public List<Company> selectCompanyByUserId(Integer userId) {
UserCompany condition = new UserCompany();
condition.setUserId(userId);
List<UserCompany> userCompanys = userCompanyMapper.selectListEntityByEqual(condition);
Company company = new Company();
company.setWarehouseId(ShiroUtils.getWarehouseId());
List<Company> companys = companyMapper.selectCompanyList(company);
for (Company companyItem : companys)
{
for (UserCompany userCompanyItem : userCompanys)
{
if (companyItem.getId() == userCompanyItem.getCompanyId())
{
companyItem.setFlag(true);
break;
}
}
}
return companys;
}
@Override
public List<Map<String, Object>> getCompanyParentId() {
Company company=new Company();
company.setDeleted(false);
company.setEnable(true);
// company.setType("holdingCompany");
List<Map<String, Object>> result = companyMapper.CompanyParent(company);
return result;
}
@Override
public List<Map<String, Object>> getWarehouseList(Integer id) {
List<Map<String, Object>> warehouseList = warehouseService.selectListMapByEqual("id,code,name,enable", new Warehouse());
WarehouseCompany warehouseCompany = new WarehouseCompany();
warehouseCompany.setCompanyId(id);
List<Map<String, Object>> warehouseIds = warehouseCompanyMapperAuto.selectListMapByEqual("warehouseId", warehouseCompany);
for (Map<String, Object> item:warehouseList) {
item.put("flag",false);
item.put("value", item.get("id").toString() + "," + item.get("code").toString());
for (Map<String, Object> warehouseId:warehouseIds) {
if (item.get("id").toString().equals(warehouseId.get("warehouseId").toString())) {
item.put("flag",true);
break;
}
}
}
return warehouseList;
}
@Override
public AjaxResult deletedCompany(String ids) {
if (StringUtils.isEmpty(ids))
return AjaxResult.error("id不能为空");
for (Integer id : Convert.toIntArray(ids))
{
Company company = this.selectEntityById(id);
Inventory inventory = new Inventory();
inventory.setWarehouseCode(ShiroUtils.getWarehouseCode());
inventory.setCompanyCode(company.getCode());
Map<String, Object> map = inventoryService.selectFirstMap("id", inventory);
if (map != null) {
return AjaxResult.error("货主编码(" + company.getCode() +")还有库存,不能删除!");
}
company.setDeleted(true);
company.setLastUpdatedBy(ShiroUtils.getLoginName());
this.updateByModel(company);
WarehouseCompany condition = new WarehouseCompany();
condition.setCompanyId(id);
warehouseCompanyMapperAuto.deleteByCondition(condition);
}
return AjaxResult.success("删除成功!");
}
@Override
public AjaxResult updateCompany(Company company) {
if (company.getId() == null)
return AjaxResult.error("id为空!");
String[] warehouse = company.getWarehouseCode().split(",");
//删除货主仓库关联
WarehouseCompany condition = new WarehouseCompany();
condition.setCompanyId(company.getId());
warehouseCompanyMapperAuto.deleteByCondition(condition);
//添加货主仓库关联
WarehouseCompany record = new WarehouseCompany();
for (int i=0; i<warehouse.length-1; i=i+2)
{
record.setCompanyId(company.getId());
record.setCompanyCode(company.getCode());
record.setWarehouseId(Integer.valueOf(warehouse[i]));
record.setWarehouseCode(warehouse[i+1]);
warehouseCompanyMapperAuto.insert(record);
}
//更新货主
company.setLastUpdatedBy(ShiroUtils.getLoginName());
this.updateByModel(company);
return AjaxResult.success("更新成功!");
}
@Override
public AjaxResult addCompany(Company company) {
String[] warehouse = company.getWarehouseCode().split(",");
//更新货主
company.setCreatedBy(ShiroUtils.getLoginName());
company.setLastUpdatedBy(ShiroUtils.getLoginName());
this.insert(company);
//添加货主仓库关联
WarehouseCompany record = new WarehouseCompany();
for (int i=0; i<warehouse.length-1; i=i+2)
{
record.setCompanyId(company.getId());
record.setCompanyCode(company.getCode());
record.setWarehouseId(Integer.valueOf(warehouse[i]));
record.setWarehouseCode(warehouse[i+1]);
warehouseCompanyMapperAuto.insert(record);
}
return AjaxResult.success("更新成功!");
}
@Override
public AjaxResult checkwarehouseCompany(String code) {
WarehouseCompany warehouseCompany = new WarehouseCompany();
warehouseCompany.setCompanyCode(code);
List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
if (list == null || list.size() == 0){
throw new ServiceException("系统没有该货主");
}else {
return AjaxResult.success("请继续");
}
}
@Override
public WarehouseCompany selcetIWCBycode(WarehouseCompany code) {
return companyMapper.selcetIWCBycode(code);
}
@Override
public CompanyWu selectCompanyWu(CompanyWu companyWu) {
return companyMapper.selectCompanyWu(companyWu);
}
}