CompanyController.java
7.33 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
package com.huaheng.system.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.core.utils.StringUtils;
import com.huaheng.common.core.web.controller.BaseController;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.core.web.page.PageDomain;
import com.huaheng.common.core.web.page.TableDataInfo;
import com.huaheng.common.core.web.page.TableSupport;
import com.huaheng.common.log.annotation.Log;
import com.huaheng.common.log.enums.BusinessType;
import com.huaheng.common.security.annotation.PreAuthorize;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.system.api.domain.Company;
import com.huaheng.system.domain.WarehouseCompany;
import com.huaheng.system.service.CompanyService;
import com.huaheng.system.service.WarehouseCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.lang.management.PlatformManagedObject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/company")
@Api(value = "货主", tags = "货主")
public class CompanyController extends BaseController {
@Resource
private CompanyService companyService;
@Resource
private WarehouseCompanyService warehouseCompanyService;
@GetMapping("/companies")
@ApiOperation(value = "根据用户id和仓库编码获取货主")
@Log(title = "根据用户id和仓库编码获取货主", businessType = BusinessType.GRANT)
public List<Company> queryByUserIdAndWare(Long userId, String warehouseCode) {
return companyService.selectCompanyByCurrentUserId(userId, warehouseCode);
}
@GetMapping("/selectCompanyByCurrentUserId")
@ApiOperation(value = "根据用户id和仓库编码获取货主")
@Log(title = "根据用户id和仓库编码获取货主", businessType = BusinessType.GRANT)
public List<Company> selectCompanyByCurrentUserId(String userId, String warehouseCode) {
return companyService.selectCompanyByCurrentUserId(Long.parseLong(userId), warehouseCode);
}
@PreAuthorize(hasPermi = "config:company:list")
@GetMapping("/list")
@ApiOperation(value = "获取货主列表")
@Log(title = "获取货主列表", businessType = BusinessType.GRANT)
public TableDataInfo list(Company company, String beginTime, String endTime) {
LambdaQueryWrapper<Company> lambdaQueryWrapper = Wrappers.lambdaQuery();
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
LambdaQueryWrapper<WarehouseCompany> wrapper = Wrappers.lambdaQuery();
wrapper.eq(WarehouseCompany::getWarehouseCode, SecurityUtils.getWarehouseCode());
List<WarehouseCompany> warehouseCompanyList = warehouseCompanyService.list(wrapper);
List<String> companyCodeList = warehouseCompanyList.stream().map(WarehouseCompany::getCompanyCode).collect(Collectors.toList());
lambdaQueryWrapper.gt(StrUtil.isNotEmpty(beginTime), Company::getCreated, beginTime)
.apply(StringUtils.isNotEmpty(endTime),
"date_format (created,'%Y-%m-%d') <= date_format('" + endTime + "','%Y-%m-%d')")
.eq(Company::getWarehouseCode, SecurityUtils.getWarehouseCode())
.like(StrUtil.isNotBlank(company.getCode()) && StrUtil.isNotEmpty(company.getCode()), Company::getCode, company.getCode())
.like(StrUtil.isNotBlank(company.getCode()) && StrUtil.isNotEmpty(company.getName()), Company::getName, company.getName())
.in(Company::getCode, companyCodeList)
.eq(Company::getDeleted, false)
.orderByDesc(Company::getId);
if (ObjectUtil.isNotNull(pageNum) && ObjectUtil.isNotNull(pageSize)) {
/**
* 使用分页查询
*/
Page<Company> page = new Page<>(pageNum, pageSize);
IPage<Company> iPage = companyService.page(page, lambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<Company> list = companyService.list(lambdaQueryWrapper);
return getDataTable(list);
}
}
@PreAuthorize(hasAnyPermi = "config:company:add")
@Log(title = "新增货主", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation(value = "新增货主")
public AjaxResult addSave(@RequestBody Company company) {
if (StrUtil.isEmpty(company.getCode()) && StrUtil.isEmpty(company.getName())) {
return AjaxResult.error("货主编码和名称不能为空!");
}
company.setWarehouseCode(SecurityUtils.getWarehouseCode());
return companyService.addCompany(company);
}
@ApiOperation(value = "修改货主")
@PreAuthorize(hasAnyPermi = "config:company:edit")
@Log(title = "修改货主", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult editSave(@RequestBody Company company) {
return companyService.updateCompany(company);
}
/**
* 删除货主
*/
@PreAuthorize(hasAnyPermi = "config:company:remove")
@Log(title = "删除货主", businessType = BusinessType.DELETE)
@DeleteMapping
@ApiOperation(value = "删除货主")
@Transactional(rollbackFor = Exception.class)
public AjaxResult remove(@ApiParam(value = "货主id") @RequestParam String ids) {
if (StrUtil.isEmpty(ids)) {
return AjaxResult.error("id不能为空");
}
for (Integer id : Convert.toIntArray(ids)) {
Company company = new Company();
company.setId(id);
company.setDeleted(true);
companyService.updateById(company);
}
return AjaxResult.success("删除成功!");
}
@ApiOperation(value = "获取货主")
@PreAuthorize(hasAnyPermi = "config:company:edit")
@Log(title = "获取货主", businessType = BusinessType.GRANT)
@GetMapping("/{code}")
public AjaxResult getCompanyCode(@PathVariable String code) {
return AjaxResult.success(companyService.getCompanyByCode(code));
}
@ApiOperation(value = "获取用户可操作货主")
@PreAuthorize(hasAnyPermi = "config:company:query")
@Log(title = "获取用户可操作货主", businessType = BusinessType.GRANT)
@GetMapping("/getCompaniesByToken")
public List<Company> getCompaniesByToken() {
LambdaQueryWrapper<Company> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(Company::getCode, SecurityUtils.getCompanyList());
return companyService.list(queryWrapper);
}
@ApiIgnore
@GetMapping("/getAll")
@Log(title = "获取所有货主", businessType = BusinessType.GRANT)
public List<Company> getAll() {
return companyService.list();
}
}