货位管理增加货位编码及地址唯一性校验

This commit is contained in:
pangshenghao
2023-06-05 17:14:10 +08:00
parent a5151bf051
commit 7eadb387e0

View File

@@ -18,6 +18,7 @@ import org.nl.acs.device.service.dto.StorageCellDto;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.StringUtils;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
@@ -110,15 +111,26 @@ public class StorageCellServiceImpl implements StorageCellService {
@Override
@Transactional(rollbackFor = Exception.class)
public void create(StorageCellDto dto) {
JSONArray arr;
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
if(dto.getAddress()!=0) {
arr = wo.query("address ='" + dto.getAddress() + "'").getResultJSONArray(0);
if (arr.size() != 0) {
throw new BadRequestException("AGV编码非0时不能重复");
}
}
arr = wo.query("storage_code ='" + dto.getStorage_code() + "'").getResultJSONArray(0);
if(arr.size()!=0){
throw new BadRequestException("货位编码不能重复!");
}
String currentUsername = SecurityUtils.getCurrentUsername();
String now = DateUtil.now();
dto.setStorage_id(IdUtil.simpleUUID());
dto.setCreate_by(currentUsername);
dto.setUpdate_by(currentUsername);
dto.setUpdate_time(now);
dto.setCreate_time(now);
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
wo.insert(json);
deviceService.addDeviceCodeByAddress(dto);
@@ -131,12 +143,25 @@ public class StorageCellServiceImpl implements StorageCellService {
StorageCellDto entity = this.findById(dto.getStorage_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
JSONArray arr;
if(dto.getAddress()!=0) {
arr = wo.query("address ='" + dto.getAddress() + "'and storage_id <>'"+dto.getStorage_id() + "'").getResultJSONArray(0);
if (arr.size() != 0) {
throw new BadRequestException("AGV编码非0时不能重复");
}
}
arr = wo.query("storage_code ='" + dto.getStorage_code() + "'and storage_id <>'"+dto.getStorage_id()+ "'").getResultJSONArray(0);
if(arr.size()!=0){
throw new BadRequestException("货位编码不能重复!");
}
String currentUsername = SecurityUtils.getCurrentUsername();
String now = DateUtil.now();
dto.setUpdate_time(now);
dto.setUpdate_by(currentUsername);
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
wo.update(json);
deviceService.updateDeviceCodeByAddress(dto);