WareHouseController.java
5.2 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
package com.huaheng.system.controller;
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.conditions.update.LambdaUpdateWrapper;
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.text.Convert;
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.security.annotation.PreAuthorize;
import com.huaheng.system.api.domain.Warehouse;
import com.huaheng.system.service.ISysUserService;
import com.huaheng.system.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/warehouse")
@Api(value = "仓库", tags = "仓库")
public class WareHouseController extends BaseController {
@Resource
private WarehouseService warehouseService;
@Resource
private ISysUserService userService;
/**
* 查询仓库列表
*/
@GetMapping("/list")
@ApiOperation(value = "查询仓库", notes = "查询仓库")
public TableDataInfo list(Warehouse warehouse,
String createdBegin,
String createdEnd) {
LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQuery();
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
lambdaQueryWrapper.gt(StrUtil.isNotEmpty(createdBegin), Warehouse::getCreated, createdBegin)
.lt(StrUtil.isNotEmpty(createdEnd), Warehouse::getCreated, createdEnd)
.eq(StrUtil.isNotEmpty(warehouse.getCode()), Warehouse::getCode, warehouse.getCode())
.like(StrUtil.isNotEmpty(warehouse.getName()), Warehouse::getName, warehouse.getName())
.eq(Warehouse::getDeleted, false)
.orderByDesc(Warehouse::getCreated);
/**
* 使用分页查询
*/
if (ObjectUtil.isNotNull(pageNum) && ObjectUtil.isNotNull(pageSize)) {
Page<Warehouse> page = new Page<>(pageNum, pageSize);
IPage<Warehouse> iPage = warehouseService.page(page, lambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<Warehouse> list = warehouseService.list(lambdaQueryWrapper);
return getDataTable(list);
}
}
/**
* 通过用户名获取可以登陆的仓库列表
*/
@GetMapping("/getWarehouseByUserCode")
@ApiOperation(value = "通过用户名获取可以用的仓库列表 ", notes = "通过用户名获取可以用的仓库列表")
public AjaxResult getWarehouseByUserCode(String username) {
if (StrUtil.isNotEmpty(username)) {
List<Map<String, Object>> list = userService.getWarehouseByUserCode(username);
return AjaxResult.success(list);
} else {
return AjaxResult.error("用户名不能为空");
}
}
/**
* 新增保存仓库
*/
@PreAuthorize(hasAnyPermi = "config:warehouse:list")
@GetMapping("/{code}")
public AjaxResult getByCode(@PathVariable("code") String code) {
return AjaxResult.success(warehouseService.getByCode(code));
}
/**
* 新增保存仓库
*/
@PreAuthorize(hasAnyPermi = "config:warehouse:add")
@PostMapping
public AjaxResult addSave(@RequestBody Warehouse warehouse) {
return toAjax(warehouseService.save(warehouse));
}
/**
* 修改保存仓库
*/
@PreAuthorize(hasAnyPermi = "config:warehouse:edit")
@PutMapping
public AjaxResult editSave(@RequestBody Warehouse warehouse) {
return toAjax(warehouseService.updateById(warehouse));
}
/**
* 删除仓库
*/
@PreAuthorize(hasAnyPermi = "config:warehouse:remove")
@DeleteMapping
public AjaxResult remove(String codes) {
if (StringUtils.isEmpty(codes)) {
return AjaxResult.error("id不能为空");
}
for (String code : Convert.toStrArray(codes)) {
LambdaUpdateWrapper<Warehouse> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.eq(Warehouse::getCode, code)
.set(Warehouse::getDeleted, true);
warehouseService.update(updateWrapper);
}
return AjaxResult.success("删除成功!");
}
@ApiIgnore
@GetMapping("/getAll")
public List<Warehouse> getAll() {
LambdaQueryWrapper<Warehouse> queryWrapper = Wrappers.lambdaQuery();
return warehouseService.list();
}
}