LocationServiceImpl.java
6.97 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
package com.huaheng.pc.config.location.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.mapper.LocationMapper;
@Service("LocationService")
public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> implements LocationService{
@Resource
private LocationService locationService;
@Resource
private LocationTypeService locationTypeService;
@Resource
private ZoneService zoneService;
@Resource
private LocationMapper locationMapper;
//新增库位,需要建立code,并判断是否重复
@Override
public AjaxResult addsave(Location location){
//库区与库位类型的匹配判断
if(!location.getZoneCode().equals(location.getLocationType())){
throw new ServiceException(location.getLocationType()+"的库位类型与"+location.getZoneCode()+"库区不匹配");
}
//创建库位编码code
String prefix = location.getLocationType().substring(1);
String code = MessageFormat.format("{0}{1}-{2}-{3}-{4}",
prefix,
String.format("%02d", location.getIRow()),
String.format("%02d", location.getIColumn()),
String.format("%02d", location.getILayer()),
String.format("%02d", location.getIGrid()));
//判断code是否重复
LambdaQueryWrapper<Location> lam = Wrappers.lambdaQuery();
lam.eq(Location::getWarehouseCode,ShiroUtils.getWarehouseCode())
.eq(Location::getCode,code);
if(this.getOne(lam)!=null){
return AjaxResult.error("该位置已有库位生成,请重新输入位置");
}
//插入数据库
location.setCode(code);
location.setWarehouseCode(ShiroUtils.getWarehouseCode());
location.setCreatedBy(ShiroUtils.getLoginName());
Boolean flag=this.save(location);
if(flag == false){
return AjaxResult.error("新增库位失败,插入数据库时失败");
}
return AjaxResult.success("新增库位成功");
}
@Override
public boolean insertLocation(Location location) {
/* 判断库位类型编码是否存在*/
LambdaQueryWrapper<LocationType> typelambda = Wrappers.lambdaQuery();
typelambda.eq(LocationType::getCode,location.getLocationType())
.select(LocationType::getCode);
List<Map<String, Object>> list = locationTypeService.listMaps(typelambda);
if (list.size() < 1){
throw new ServiceException("库位类型编码不存在");
}
/* 判断库区编码是否存在*/
LambdaQueryWrapper<Zone> zoneLambda= Wrappers.lambdaQuery();
zoneLambda.eq(Zone::getCode, location.getZoneCode())
.select(Zone::getCode);
list = zoneService.listMaps(zoneLambda);
if (list.size() < 1){
throw new ServiceException("库区编码不存在");
}
if(!location.getZoneCode().equals(location.getLocationType())){
throw new ServiceException(location.getLocationType()+"的库位类型与"+location.getZoneCode()+"库区不匹配");
}
String prefix = location.getLocationType().substring(1);
List<Location> locations = new ArrayList<>();
for (int i=1; i<=location.getIRow().intValue(); i++) {
for (int j=1; j<=location.getIColumn().intValue(); j++) {
for (int k=1; k<=location.getILayer().intValue(); k++) {
for (int m=1; m<=location.getIGrid().intValue(); m++) {
//Integer roadway = (j / 2) + 1;
Location param = new Location();
param.setIRow(i);
param.setIColumn(j);
param.setILayer(k);
param.setIGrid(m);
param.setZoneCode(location.getZoneCode());
param.setLocationType(location.getLocationType());
param.setStatus(location.getStatus());
param.setWarehouseCode(ShiroUtils.getWarehouseCode());
param.setCreatedBy(ShiroUtils.getLoginName());
param.setLastUpdatedBy(ShiroUtils.getLoginName());
String code = MessageFormat.format("{0}{1}-{2}-{3}-{4}",
prefix,
String.format("%02d", i),
String.format("%02d", j),
String.format("%02d", k),
String.format("%02d", m));
LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(Location::getCode,code)
.eq(Location::getWarehouseCode,ShiroUtils.getWarehouseCode());
List<Location> locationList = locationService.list(queryWrapper);
if (locationList.size() == 0) {
param.setCode(code);
locations.add(param);
}
}
}
}
}
Boolean result = locationService.saveBatch(locations);
return result;
}
@Override
public void updateStatus(String locationCode, String status) {
if (StringUtils.isNotEmpty(locationCode)) {
locationMapper.updateStatus(ShiroUtils.getWarehouseCode(), locationCode, status);
}
}
/**
* 通过定位规则查找库位
* @param locatingRule
* @return
*/
public String position(String locatingRule){
return locationMapper.position(locatingRule).getCode();
}
/**
* 修改容器和库位状态
* */
@Override
public void updateContainerCodeAndStatus(String locationCode, String containerCode, String status) {
if (StringUtils.isNotEmpty(locationCode) || StringUtils.isNotEmpty(containerCode))
locationMapper.updateContainerCodeAndStatus(ShiroUtils.getWarehouseCode(), locationCode, containerCode, status);
}
}