CompanyServiceImpl.java
4.72 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
package com.huaheng.pc.config.company.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.mapper.CompanyMapper;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;
import com.huaheng.pc.system.user.domain.UserCompany;
import com.huaheng.pc.system.user.mapper.UserCompanyMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service("companyService")
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
@Resource
private CompanyMapper companyMapper;
@Resource
private UserCompanyMapper userCompanyMapper;
@Resource
private WarehouseCompanyService warehouseCompanyService;
@Override
public List<Company> selectCompanyByCurrentUserId() {
return companyMapper.selectCompanyByUserId(ShiroUtils.getUserId(), ShiroUtils.getWarehouseCode());
}
/**
* 查询出仓库所有的货主,并且根据用户id查询对应的货主,包含的就将flag赋为true
* @param
* @return
*/
@Override
public List<Company> selectCompanyByUserId(Integer id) {
if (id == 0) {
id = ShiroUtils.getUserId();
}
UserCompany condition = new UserCompany();
condition.setUserId(id);
List<UserCompany> userCompanys = userCompanyMapper.selectListEntityByEqual(condition);
Company company = new Company();
company.setWarehouseCode(ShiroUtils.getWarehouseCode());
List<Company> companys = companyMapper.selectByWarehouseCode(company);
for (Company companyItem : companys)
{
for (UserCompany userCompanyItem : userCompanys)
{
if (companyItem.getId().equals(userCompanyItem.getCompanyId()))
{
companyItem.setFlag(true);
break;
}
}
}
return companys;
}
@Override
public AjaxResult addCompany(Company company) {
String[] warehouse = company.getWarehouseCode().split(",");
//更新货主
company.setCreatedBy(ShiroUtils.getLoginName());
company.setLastUpdatedBy(ShiroUtils.getLoginName());
this.save(company);
//添加货主仓库关联
WarehouseCompany record = new WarehouseCompany();
for (int i=0; i<warehouse.length-1; i++)
{
record.setCompanyId(company.getId());
record.setCompanyCode(company.getCode());
record.setWarehouseCode(warehouse[i]);
warehouseCompanyService.save(record);
}
return AjaxResult.success("更新成功!");
}
@Override
public AjaxResult updateCompany(Company company) {
if (company.getId() == null) {
return AjaxResult.error("id为空!");
}
String[] warehouse = company.getWarehouseCode().split(",");
LambdaQueryWrapper<WarehouseCompany> lambdaQueryWrapper = Wrappers.lambdaQuery();
warehouseCompanyService.remove(lambdaQueryWrapper.eq(WarehouseCompany::getCompanyId, company.getId()));
//添加货主仓库关联
WarehouseCompany record = new WarehouseCompany();
for (int i=0; i<warehouse.length; i++)
{
record.setCompanyId(company.getId());
record.setCompanyCode(company.getCode());
record.setWarehouseCode(warehouse[i]);
warehouseCompanyService.save(record);
}
//更新货主
company.setLastUpdatedBy(ShiroUtils.getLoginName());
this.updateById(company);
return AjaxResult.success("更新成功!");
}
@Override
public List<Map<String, Object>> getCode(){
LambdaQueryWrapper<Company> lambda = Wrappers.lambdaQuery();
lambda.select(Company::getCode, Company::getId, Company::getName)
.eq(Company::getWarehouseCode, ShiroUtils.getWarehouseCode());
return this.listMaps(lambda);
}
@Override
public List<Company> selectListEntityByEqual(Company condition) {
return companyMapper.selectListEntityByEqual(condition);
}
@Override
public List<Company> loginGetCompany(Integer userId, String warehouseCode) {
return companyMapper.loginGetCompany(userId,warehouseCode);
}
}