|
|
@@ -13,7 +13,9 @@ import cn.com.taiji.core.repo.jpa.user.StaffRepo; |
|
|
|
import cn.com.taiji.core.repo.request.invw.InvwWarehousePageRequest; |
|
|
|
import cn.com.taiji.invw.dto.warehouse.*; |
|
|
|
import cn.com.taiji.invw.manager.AbstractInvwManager; |
|
|
|
import cn.com.taiji.invw.model.MyFinals; |
|
|
|
import cn.com.taiji.invw.model.warehouse.InvwWarehouseIdNameModel; |
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@@ -21,6 +23,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class InvwWarehouseManagerImpl extends AbstractInvwManager implements InvwWarehouseManager { |
|
|
@@ -45,12 +48,15 @@ public class InvwWarehouseManagerImpl extends AbstractInvwManager implements Inv |
|
|
|
req.setInsertTimeEnd(request.getInsertTimeEnd().plusDays(1).atStartOfDay()); |
|
|
|
} |
|
|
|
Staff staff = staffRepo.findByStaffId(request.getStaffId()); |
|
|
|
if (staff == null) throw new ManagerException("员工非法!"); |
|
|
|
// 如果不是管理员,只能查询本渠道的仓库 |
|
|
|
if (!"MANAGER".equals(staff.getIdentityType())) { |
|
|
|
String agencyId = staff.getAgencyId(); |
|
|
|
if (!hasText(agencyId)) throw new ManagerException("渠道获取失败!"); |
|
|
|
req.setAgencyId(agencyId); |
|
|
|
if (staff == null) { |
|
|
|
throw new ManagerException("员工非法!"); |
|
|
|
} |
|
|
|
// 如果不是管理员,已及非黔通的只能查询本渠道的仓库 |
|
|
|
if (ObjectUtils.isNotEmpty(staff)){ |
|
|
|
req.setAgencyId(staff.getAgencyId()); |
|
|
|
if ("MANAGER".equals(staff.getIdentityType()) || MyFinals.QTZL_AGENCY_ID.equals(staff.getAgencyId())){ |
|
|
|
req.setAgencyId(null); |
|
|
|
} |
|
|
|
} |
|
|
|
return warehouseRepo.page(req).convertResult(this::convert); |
|
|
|
} |
|
|
@@ -146,81 +152,76 @@ public class InvwWarehouseManagerImpl extends AbstractInvwManager implements Inv |
|
|
|
if (warehouse == null) { |
|
|
|
throw new ManagerException("仓库不存在"); |
|
|
|
} |
|
|
|
//一级仓库 |
|
|
|
if (!hasText(req.getName())) { |
|
|
|
throw new ManagerException("仓库名称不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 一级仓库 |
|
|
|
if (warehouse.getWarehouseLevel() == 1) { |
|
|
|
if (hasText(req.getParentId()) || hasText(req.getAgencyId())) { |
|
|
|
if (!warehouse.getParentId().equals(req.getParentId()) || !warehouse.getAgencyId().equals(req.getAgencyId())) { |
|
|
|
throw new ManagerException("一级仓库只能修改仓库名称"); |
|
|
|
} |
|
|
|
if (hasText(req.getName())) { |
|
|
|
warehouse.setName(req.getName()); |
|
|
|
warehouse.setUpdateTime(LocalDateTime.now()); |
|
|
|
warehouseRepo.saveAndFlush(warehouse); |
|
|
|
} |
|
|
|
warehouse.setName(req.getName()); |
|
|
|
} else if (warehouse.getWarehouseLevel() == 2) { |
|
|
|
//二级仓库 |
|
|
|
if (hasText(req.getParentId()) || hasText(req.getAgencyId())) { |
|
|
|
//查询下级仓库 |
|
|
|
List<InvwWarehouse> warehouseList = warehouseRepo.findChiByIdAndStatus(warehouse.getId(), EnableStatus.ENABLE); |
|
|
|
if (warehouseList.size() > 0) { |
|
|
|
throw new ManagerException("该仓库有下级仓库,只能修改仓库名称"); |
|
|
|
} |
|
|
|
long obuCount = obuDetailsRepo.findCountByStoreCode(warehouse.getCode()); |
|
|
|
if (obuCount > 0) { |
|
|
|
throw new ManagerException("该仓库有设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
long cardCount = cardDetailsRepo.findCountByStoreCode(warehouse.getCode()); |
|
|
|
if (cardCount > 0) { |
|
|
|
throw new ManagerException("该仓库有设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
if (hasText(req.getParentId())) { |
|
|
|
InvwWarehouse parentWarehouse = warehouseRepo.findById(req.getParentId()).orElse(null); |
|
|
|
if (parentWarehouse == null) { |
|
|
|
throw new ManagerException("上级仓库不存在"); |
|
|
|
} |
|
|
|
warehouse.setWarehouseLevel(parentWarehouse.getWarehouseLevel() + 1); |
|
|
|
warehouse.setParentId(req.getParentId()); |
|
|
|
} |
|
|
|
if (hasText(req.getAgencyId())) { |
|
|
|
warehouse.setAgencyId(req.getAgencyId()); |
|
|
|
} |
|
|
|
// 二级仓库 |
|
|
|
boolean canModifyStructure = canModifyWarehouseStructure(warehouse.getId(), warehouse.getCode()); |
|
|
|
|
|
|
|
if (!canModifyStructure && (!warehouse.getParentId().equals(req.getParentId()) || !warehouse.getAgencyId().equals(req.getAgencyId()))) { |
|
|
|
throw new ManagerException("该仓库有下级仓库或设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
if (hasText(req.getName())) { |
|
|
|
warehouse.setName(req.getName()); |
|
|
|
|
|
|
|
if (hasText(req.getParentId())) { |
|
|
|
InvwWarehouse parentWarehouse = warehouseRepo.findById(req.getParentId()).orElseThrow(() -> new ManagerException("上级仓库不存在")); |
|
|
|
warehouse.setParentId(parentWarehouse.getId()); |
|
|
|
warehouse.setWarehouseLevel(parentWarehouse.getWarehouseLevel() + 1); |
|
|
|
} else { |
|
|
|
throw new ManagerException("上级仓库不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (hasText(req.getAgencyId())) { |
|
|
|
warehouse.setAgencyId(req.getAgencyId()); |
|
|
|
} |
|
|
|
warehouse.setUpdateTime(LocalDateTime.now()); |
|
|
|
warehouseRepo.saveAndFlush(warehouse); |
|
|
|
|
|
|
|
warehouse.setName(req.getName()); |
|
|
|
} else if (warehouse.getWarehouseLevel() == 3) { |
|
|
|
//三级仓库 |
|
|
|
if (hasText(req.getParentId()) || hasText(req.getChannelId())) { |
|
|
|
long obuCount = obuDetailsRepo.findCountByStoreCode(warehouse.getCode()); |
|
|
|
if (obuCount > 0) { |
|
|
|
throw new ManagerException("该仓库有设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
long cardCount = cardDetailsRepo.findCountByStoreCode(warehouse.getCode()); |
|
|
|
if (cardCount > 0) { |
|
|
|
throw new ManagerException("该仓库有设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
if (hasText(req.getParentId())) { |
|
|
|
InvwWarehouse parentWarehouse = warehouseRepo.findById(req.getParentId()).orElse(null); |
|
|
|
if (parentWarehouse == null) { |
|
|
|
throw new ManagerException("上级仓库不存在"); |
|
|
|
} |
|
|
|
warehouse.setWarehouseLevel(parentWarehouse.getWarehouseLevel() + 1); |
|
|
|
warehouse.setParentId(req.getParentId()); |
|
|
|
} |
|
|
|
warehouse.setChannelId(req.getChannelId()); |
|
|
|
// 三级仓库 |
|
|
|
if (!req.getAgencyId().equals(warehouse.getAgencyId())) { |
|
|
|
throw new ManagerException("三级仓库不能修改渠道"); |
|
|
|
} |
|
|
|
|
|
|
|
boolean canModifyStructure = canModifyWarehouseStructure(warehouse.getId(), warehouse.getCode()); |
|
|
|
|
|
|
|
if (!canModifyStructure && (!Objects.equals(warehouse.getParentId(), req.getParentId()) || |
|
|
|
!Objects.equals(warehouse.getChannelId(), req.getChannelId()))) { |
|
|
|
throw new ManagerException("该仓库有设备,只能修改仓库名称"); |
|
|
|
} |
|
|
|
if (hasText(req.getName())) { |
|
|
|
warehouse.setName(req.getName()); |
|
|
|
|
|
|
|
if (hasText(req.getParentId())) { |
|
|
|
InvwWarehouse parentWarehouse = warehouseRepo.findById(req.getParentId()).orElseThrow(() -> new ManagerException("上级仓库不存在")); |
|
|
|
warehouse.setParentId(parentWarehouse.getId()); |
|
|
|
warehouse.setWarehouseLevel(parentWarehouse.getWarehouseLevel() + 1); |
|
|
|
} |
|
|
|
warehouse.setUpdateTime(LocalDateTime.now()); |
|
|
|
warehouseRepo.saveAndFlush(warehouse); |
|
|
|
warehouse.setChannelId(req.getChannelId()); |
|
|
|
warehouse.setName(req.getName()); |
|
|
|
} |
|
|
|
|
|
|
|
warehouse.setUpdateTime(LocalDateTime.now()); |
|
|
|
warehouseRepo.saveAndFlush(warehouse); |
|
|
|
persistOperateLog(OperateType.UPDATE_WAREHOUSE, warehouse.getId(), req.getOrderSource(), findOpenIdByToken(req.getAccessToken()), "仓库修改"); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean canModifyWarehouseStructure(String warehouseId, String warehouseCode) { |
|
|
|
// 检查是否有下级仓库 |
|
|
|
List<InvwWarehouse> warehouseList = warehouseRepo.findChiByIdAndStatus(warehouseId, EnableStatus.ENABLE); |
|
|
|
if (!warehouseList.isEmpty()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
// 检查设备数量 |
|
|
|
long obuCount = obuDetailsRepo.findCountByStoreCode(warehouseCode); |
|
|
|
long cardCount = cardDetailsRepo.findCountByStoreCode(warehouseCode); |
|
|
|
return obuCount == 0 && cardCount == 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void delete(InvwWarehouseDeleteRequestDTO req) throws ManagerException { |
|
|
|
InvwWarehouse warehouse = warehouseRepo.findByIdAndStatus(req.getId(), EnableStatus.ENABLE); |