CompanyServiceImpl.java
5 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
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.exception.service.ServiceException;
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 org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
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
@Transactional(rollbackFor = Exception.class)
public AjaxResult addCompany(Company company) {
/*货主新增时只针对当前登录仓库*/
company.setDeleted(false);
//添加货主及仓库关联
WarehouseCompany record = new WarehouseCompany();
LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
companyLambdaQueryWrapper.eq(Company::getCode,company.getCode());
companyLambdaQueryWrapper.eq(Company::getWarehouseCode,company.getWarehouseCode());
Company tmp = this.getOne(companyLambdaQueryWrapper);
if(!StringUtils.isNull(tmp)){
return AjaxResult.error("货主编码重复,请重新输入编码!");
}
int c = companyMapper.insertReturnId(company);
if(c < 1){
throw new ServiceException("插入货主失败!");
}
record.setCompanyId(company.getId());
record.setCompanyCode(company.getCode());
record.setWarehouseCode(company.getWarehouseCode());
Boolean w = warehouseCompanyService.save(record);
if(!w){
throw new ServiceException("插入货主仓库关联失败!");
}
return AjaxResult.success("新增货主成功!");
}
/**
* 修改货主
* */
@Override
public AjaxResult updateCompany(Company company) {
//无法修改货主仓库,当前货主新增仓库时,新增该仓库的货主
if (company.getId() == null) {
return AjaxResult.error("货主ID为空!");
}
//更新货主
company.setLastUpdatedBy(ShiroUtils.getLoginName());
company.setLastUpdated(new Date());
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);
}
}