MobileConfigController.java
10.6 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
package com.huaheng.config.mobile;
import com.alibaba.fastjson.JSONException;
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.TableDataInfo;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.config.api.domain.*;
import com.huaheng.config.container.service.ContainerService;
import com.huaheng.config.location.service.LocationService;
import com.huaheng.config.material.service.MaterialService;
import com.huaheng.config.material.service.MaterialTypeService;
import com.huaheng.config.receipt.service.ReceiptTypeService;
import com.huaheng.config.shipment.service.ShipmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Api(tags= "物料")
@RestController
@RequestMapping("/mobile")
public class MobileConfigController extends BaseController {
@Resource
private MaterialService materialService;
@Resource
private MaterialTypeService materialTypeService;
@Resource
private LocationService locationService;
@Resource
private ContainerService containerService;
@Resource
private ReceiptTypeService receiptTypeService;
@Resource
private ShipmentTypeService shipmentTypeService;
@PostMapping("/searchMaterialInCondition")
@ApiOperation("移动端查询物料信息")
public TableDataInfo searchMaterialInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
// List<String> companyCodeList = StringUtils.stringToLIST(param.get("companyCode"));
String code = param.get("code");
String name = param.get("name");
String spec = param.get("spec");
String startTime = param.get("startTime");
String endTime = param.get("endTime");
Integer pageNum = Integer.parseInt(param.get("pageNum"));
Integer pageSize = Integer.parseInt(param.get("pageSize"));
LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
materialLambdaQueryWrapper
.eq(Material::getWarehouseCode, SecurityUtils.getWarehouseCode())
.eq(Material::getDeleted, false)
.like(StringUtils.isNotEmpty(code), Material::getCode, code)
.like(StringUtils.isNotEmpty(name), Material::getName, name)
.like(StringUtils.isNotEmpty(spec), Material::getSpec, spec)
.gt(StringUtils.isNotEmpty(startTime), Material::getCreated, startTime)
.le(StringUtils.isNotEmpty(endTime), Material::getCreated, endTime)
.orderByDesc(Material::getCreated);
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
Page<Material> page = new Page<>(pageNum, pageSize);
IPage<Material> iPage = materialService.page(page, materialLambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<Material> list = materialService.list(materialLambdaQueryWrapper);
return getDataTable(list);
}
}
@PostMapping("/addMaterial")
@ApiOperation("移动端增加物料信息")
public AjaxResult addMaterial(@RequestBody @ApiParam(value = "物料号") Material material) throws Exception {
AjaxResult result = materialService.addSave(material);
return result;
}
@PostMapping("/getMaterialType")
@ApiOperation("移动端获取物料类型")
public AjaxResult getMaterialType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
List<MaterialType> materialTypes = materialTypeService.list(materialTypeLambdaQueryWrapper);
return AjaxResult.success(materialTypes);
}
@PostMapping("/createMaterialCode")
@ApiOperation("移动端创建物料编码")
public AjaxResult createMaterialCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String day = df.format(now);
LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
materialLambdaQueryWrapper.like(Material::getCode, day);
materialLambdaQueryWrapper.orderByDesc(Material::getId);
List<Material> materials = materialService.list(materialLambdaQueryWrapper);
int length = materials.size();
//如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
if (length > 0) {
String maxCode = materials.get(0).getCode();
Integer count = Integer.valueOf(maxCode.substring(maxCode.length() - 3, maxCode.length()));
code = day + String.format("%03d", count + 1);
} else {
code = day + "001";
}
return AjaxResult.success("创建物料成功",code);
}
@PostMapping( "/isLocation")
@ApiOperation("判断是不是库位")
@ResponseBody
public AjaxResult isLocation(@RequestBody @ApiParam(value="任务id") Map<String, String> param) {
String code = param.get("code");
if (StringUtils.isEmpty(code)) {
return AjaxResult.error("location不能为空");
}
LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(Location::getCode, code);
Location location = locationService.getOne(queryWrapper);
if(location == null) {
return AjaxResult.error("没有这个库位");
}
return AjaxResult.success("库位存在",code);
}
@PostMapping( "/isContainer")
@ApiOperation("判断是不是库位")
@ResponseBody
public AjaxResult isContainer(@RequestBody @ApiParam(value="任务id") Map<String, String> param) {
String code = param.get("code");
if (StringUtils.isEmpty(code)) {
return AjaxResult.error("location不能为空");
}
LambdaQueryWrapper<Container> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(Container::getCode, code);
Container container = containerService.getOne(queryWrapper);
if(container == null) {
return AjaxResult.error("没有这个容器");
}
return AjaxResult.success("容器存在",code);
}
@PostMapping("/getReceiptType")
@ApiOperation("移动端查询入库类型")
public AjaxResult getReceiptType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
LambdaQueryWrapper<ReceiptType> receiptTypeLambda = Wrappers.lambdaQuery();
List<ReceiptType> receiptType = receiptTypeService.list(receiptTypeLambda);
return AjaxResult.success(receiptType);
}
@PostMapping("/findMaterial")
@ApiOperation("移动端查询物料信息")
public TableDataInfo findMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
Integer pageNum = Integer.parseInt(param.get("pageNum"));
Integer pageSize = Integer.parseInt(param.get("pageSize"));
LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
materialLambdaQueryWrapper.eq(Material::getDeleted, false)
.orderByDesc(Material::getCreated);
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
Page<Material> page = new Page<>(pageNum, pageSize);
IPage<Material> iPage = materialService.page(page, materialLambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<Material> list = materialService.list(materialLambdaQueryWrapper);
return getDataTable(list);
}
}
@PostMapping("/getMaterial")
@ApiOperation("移动端获取物料信息")
public AjaxResult getMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
if (param.get("code") == null || param.get("code").trim().length() < 1) {
throw new JSONException("容器号(code)不能为空");
}
Material material = materialService.findAllByCode(param.get("code"));
if (material == null) {
return AjaxResult.error("没有该物料");
}
MaterialInfo materialInfo = new MaterialInfo();
materialInfo.setMaterialCode(material.getCode());
materialInfo.setMaterialName(material.getName());
materialInfo.setType(material.getSpec());
return AjaxResult.success(materialInfo);
}
@PostMapping("/getShipmentType")
@ApiOperation("移动端查询入库类型")
public AjaxResult getShipmentType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
LambdaQueryWrapper<ShipmentType> shipmentTypeLambda = Wrappers.lambdaQuery();
List<ShipmentType> shipmentTypes = shipmentTypeService.list(shipmentTypeLambda);
return AjaxResult.success(shipmentTypes);
}
@PostMapping("/getLocationFromContainer")
@ApiOperation("手机扫描容器获得库位号")
public AjaxResult getLocationFromContainer(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
if (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
throw new JSONException("容器号(containerCode)不能为空");
}
String containerCode = param.get("containerCode");
Location location = locationService.getLocationByContainerCode(containerCode);
if(location == null) {
return AjaxResult.error("没有该库位");
}
return AjaxResult.success("获取成功",location.getCode());
}
@PostMapping("/getEmptyContainerInLocation")
@ApiOperation("选取空托出库的库位")
public AjaxResult getEmptyContainerInLocation(@RequestBody Map<String, String> param) {
List<Location> list = containerService.getEmptyContainerInLocation(null,null,SecurityUtils.getWarehouseCode());
return AjaxResult.success(list);
}
}