|
|
@ -1,9 +1,6 @@ |
|
|
|
package com.ruoyi.aftersales.service.impl; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.ruoyi.aftersales.domain.AfterSalesShippingDevice; |
|
|
@ -15,12 +12,18 @@ import com.ruoyi.common.exception.BusinessException; |
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.ruoyi.common.utils.ShiroUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.system.domain.SysSalesShippingInform; |
|
|
|
import com.ruoyi.system.mapper.SysSalesShippingInformMapper; |
|
|
|
import com.ruoyi.warehouse.domain.WarehouseOutOrder; |
|
|
|
import com.ruoyi.warehouse.mapper.WarehouseOutOrderMapper; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.ruoyi.aftersales.mapper.AftersalesOutOrderMapper; |
|
|
|
import com.ruoyi.aftersales.domain.AftersalesOutOrder; |
|
|
|
import com.ruoyi.aftersales.service.IAftersalesOutOrderService; |
|
|
|
import com.ruoyi.common.core.text.Convert; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
/** |
|
|
|
* 售后维护设备出库Service业务层处理 |
|
|
@ -40,6 +43,12 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
|
@Autowired |
|
|
|
private AfterSalesShippingDeviceMapper afterSalesShippingDeviceMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WarehouseOutOrderMapper warehouseOutOrderMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysSalesShippingInformMapper shippingInformMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询售后维护设备出库 |
|
|
|
* |
|
|
@ -148,24 +157,87 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
|
* @param aftersalesOutOrder |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public int updateMaintenanceEquipmentOne(AftersalesOutOrder aftersalesOutOrder) { |
|
|
|
|
|
|
|
String outOrderCode = aftersalesOutOrder.getOutOrderCode(); |
|
|
|
int updateResult = 0; |
|
|
|
|
|
|
|
// 定义一个StringBuilder来收集所有缺少SN号的设备ID
|
|
|
|
StringBuilder missingSnIds = new StringBuilder(); |
|
|
|
//物料信息主表的数据
|
|
|
|
List<AftersalesOutOrderDetail> needShippingDeviceMaterialsOne = this.getNeedShippingDeviceMaterialsOne(aftersalesOutOrder); |
|
|
|
if (!CollectionUtils.isEmpty(needShippingDeviceMaterialsOne)){ |
|
|
|
List<SelectShippingDeviceVO> selectShippingDeviceVOList = aftersalesOutOrder.getSelectShippingDeviceVOList(); |
|
|
|
if (CollectionUtils.isEmpty(selectShippingDeviceVOList)){ |
|
|
|
throw new BusinessException("请展开物料详情并添加要出货的设备"); |
|
|
|
} |
|
|
|
|
|
|
|
// boolean anyNullSnCode = selectShippingDeviceVOList.stream().anyMatch(item -> item.getSnCode() == null);
|
|
|
|
// if (anyNullSnCode){
|
|
|
|
// throw new BusinessException("请展开物料详情并填写每个设备的SN号");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 遍历 selectShippingDeviceVOList 列表
|
|
|
|
selectShippingDeviceVOList.forEach(item -> { |
|
|
|
// 检查 SnCode 是否为空
|
|
|
|
if (item.getSnCode() == null) { |
|
|
|
// 如果是第一次添加,不加前缀“、”,否则加上
|
|
|
|
if (missingSnIds.length() > 0) { |
|
|
|
missingSnIds.append("、"); |
|
|
|
} |
|
|
|
missingSnIds.append(item.getShippingDeviceId()); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 检查是否有任何设备缺少SN号
|
|
|
|
if (missingSnIds.length() > 0) { |
|
|
|
throw new BusinessException(missingSnIds.toString() + " SN未维护,请维护"); |
|
|
|
} |
|
|
|
|
|
|
|
/* 缺少校验规则,后续补充 |
|
|
|
* 2.1、已选出货设备,是否可用(状态:可用,即未被其他出库单添加或报损),若不可用,则弹窗提示“CHSB20240808004、CHSB20240808005.不可用,请重新添加 |
|
|
|
* */ |
|
|
|
|
|
|
|
for (SelectShippingDeviceVO selectShippingDeviceVO : selectShippingDeviceVOList) { |
|
|
|
AfterSalesShippingDevice afterSalesShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
afterSalesShippingDevice.setShippingDeviceId(selectShippingDeviceVO.getShippingDeviceId()); |
|
|
|
afterSalesShippingDevice.setAddShippingDeviceFlag("0"); |
|
|
|
afterSalesShippingDevice.setOutOrderCode(outOrderCode); |
|
|
|
updateResult = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(afterSalesShippingDevice); |
|
|
|
if (updateResult <= 0){ |
|
|
|
throw new BusinessException("更新出货设备信息失败"); |
|
|
|
String shippingDeviceId = selectShippingDeviceVO.getShippingDeviceId(); |
|
|
|
AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
tempShippingDevice.setShippingDeviceId(shippingDeviceId); |
|
|
|
tempShippingDevice.setSnCode(selectShippingDeviceVO.getSnCode()); |
|
|
|
|
|
|
|
int updateShippingDeviceResult = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(tempShippingDevice); |
|
|
|
if (updateShippingDeviceResult <= 0){ |
|
|
|
throw new BusinessException("更新设备数据失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return updateResult; |
|
|
|
} |
|
|
|
//更新出库单
|
|
|
|
WarehouseOutOrder warehouseOutOrder = new WarehouseOutOrder(); |
|
|
|
//更改状态未待确认发货
|
|
|
|
warehouseOutOrder.setOutOrderCode(outOrderCode); |
|
|
|
warehouseOutOrder.setWarehouseOutStatus("2"); |
|
|
|
int updateWarehouseResult = warehouseOutOrderMapper.updateWarehouseOutOrderByCode(warehouseOutOrder); |
|
|
|
if (updateWarehouseResult <= 0){ |
|
|
|
throw new BusinessException("更新销售售后通知单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
//更新销售出货通知单
|
|
|
|
SysSalesShippingInform sysSalesShippingInform = new SysSalesShippingInform(); |
|
|
|
sysSalesShippingInform.setOutOrderCode(outOrderCode); |
|
|
|
sysSalesShippingInform.setWarehouseOutStatus("2"); |
|
|
|
int updateShippingInformResult = shippingInformMapper.updateSysSalesShippingInformByOutOrderCode(sysSalesShippingInform); |
|
|
|
if (updateShippingInformResult <= 0){ |
|
|
|
throw new BusinessException("更新销售出货通知单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新售后维护设备出库单
|
|
|
|
aftersalesOutOrder.setWarehouseOutStatus("2"); |
|
|
|
int result = aftersalesOutOrderMapper.updateAftersalesOutOrder(aftersalesOutOrder); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -225,22 +297,41 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
|
* */ |
|
|
|
@Override |
|
|
|
public List<SelectShippingDeviceVO> getThisSalesOrderShippingDevices(AftersalesOutOrder aftersalesOutOrder) { |
|
|
|
// 输入验证
|
|
|
|
if (aftersalesOutOrder == null || StringUtils.isEmpty(aftersalesOutOrder.getRelatedOrderCode()) && |
|
|
|
StringUtils.isEmpty(aftersalesOutOrder.getSalesOrderCode())) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
|
|
|
|
List<SelectShippingDeviceVO> selectShippingDeviceVOS = new ArrayList<>(); |
|
|
|
String materialNo = aftersalesOutOrder.getMaterialNo(); |
|
|
|
|
|
|
|
String relatedOrderCode = aftersalesOutOrder.getRelatedOrderCode(); |
|
|
|
String salesOrderCode = aftersalesOutOrder.getSalesOrderCode(); |
|
|
|
// 优先使用销售订单号关联
|
|
|
|
if (StringUtils.isNotEmpty(salesOrderCode)){ |
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceBySalesOrderCode(salesOrderCode); |
|
|
|
convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); |
|
|
|
}else { |
|
|
|
// 关联订单号可能存在逗号分隔的情况
|
|
|
|
String[] splitRelatedOrderCode = relatedOrderCode.split(","); |
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectBatchShippingDeviceBySalesOrderCode(splitRelatedOrderCode); |
|
|
|
if (StringUtils.isNotEmpty(aftersalesOutOrder.getSalesOrderCode())) { |
|
|
|
AfterSalesShippingDevice tempAfterSalesShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
tempAfterSalesShippingDevice.setMaterialNo(materialNo); |
|
|
|
tempAfterSalesShippingDevice.setSalesOrderCode(aftersalesOutOrder.getSalesOrderCode()); |
|
|
|
|
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceByOrderCodeAndMaterialNo(tempAfterSalesShippingDevice); |
|
|
|
convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); |
|
|
|
|
|
|
|
// 提前返回
|
|
|
|
return selectShippingDeviceVOS; |
|
|
|
} |
|
|
|
|
|
|
|
// 处理关联订单号
|
|
|
|
String relatedOrderCode = aftersalesOutOrder.getRelatedOrderCode(); |
|
|
|
Arrays.stream(relatedOrderCode.split(",")) |
|
|
|
.map(String::trim) |
|
|
|
.forEach(code -> { |
|
|
|
AfterSalesShippingDevice tempAfterSalesShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
tempAfterSalesShippingDevice.setMaterialNo(materialNo); |
|
|
|
tempAfterSalesShippingDevice.setSalesOrderCode(code); |
|
|
|
|
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDeviceByOrderCodeAndMaterialNo(tempAfterSalesShippingDevice); |
|
|
|
convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); |
|
|
|
}); |
|
|
|
|
|
|
|
return selectShippingDeviceVOS; |
|
|
|
} |
|
|
|
|
|
|
@ -253,13 +344,14 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
|
|
|
|
|
List<SelectShippingDeviceVO> selectShippingDeviceVOS = new ArrayList<>(); |
|
|
|
String outOrderCode = aftersalesOutOrder.getOutOrderCode(); |
|
|
|
String materialNo = aftersalesOutOrder.getMaterialNo(); |
|
|
|
List<SelectShippingDeviceVO> thisSalesOrderShippingDevices = this.getThisSalesOrderShippingDevices(aftersalesOutOrder); |
|
|
|
// 查找到当前销售订单的出货设备ID集合
|
|
|
|
List<String> currentShippingDeviceIds = thisSalesOrderShippingDevices.stream() |
|
|
|
.map(SelectShippingDeviceVO::getShippingDeviceId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
//查找到所有出货设备id集合
|
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectAllShippingDevices(); |
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectShippingDevicesByMaterialNo(materialNo); |
|
|
|
|
|
|
|
//保留是否添加出货设备等于1的,以及等于0且出库单号等于本单据的
|
|
|
|
List<AfterSalesShippingDevice> filteredDevices = afterSalesShippingDevices.stream().filter(device -> "1".equals(device.getAddShippingDeviceFlag()) |
|
|
@ -289,4 +381,35 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 展示第一次维护设备出库,已经添加了的出货设备 |
|
|
|
* */ |
|
|
|
@Override |
|
|
|
public List<SelectShippingDeviceVO> showAddShippingDevicesOne(AftersalesOutOrder aftersalesOutOrder) { |
|
|
|
String outOrderCode = aftersalesOutOrder.getOutOrderCode(); |
|
|
|
String materialNo = aftersalesOutOrder.getMaterialNo(); |
|
|
|
List<SelectShippingDeviceVO> selectShippingDeviceVOS = new ArrayList<>(); |
|
|
|
AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
tempShippingDevice.setMaterialNo(materialNo); |
|
|
|
tempShippingDevice.setOutOrderCode(outOrderCode); |
|
|
|
List<AfterSalesShippingDevice> afterSalesShippingDevices = afterSalesShippingDeviceMapper.selectHasAddShippingDevice(tempShippingDevice); |
|
|
|
convertToDeviceVOs(afterSalesShippingDevices, selectShippingDeviceVOS); |
|
|
|
|
|
|
|
return selectShippingDeviceVOS; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 逻辑删除出货设备(也就是取消关联) |
|
|
|
* */ |
|
|
|
@Override |
|
|
|
public int deleteAftersalesShippingDeviceById(String shippingDeviceId) { |
|
|
|
|
|
|
|
AfterSalesShippingDevice tempShippingDevice = new AfterSalesShippingDevice(); |
|
|
|
tempShippingDevice.setAddShippingDeviceFlag("1"); |
|
|
|
tempShippingDevice.setShippingDeviceId(shippingDeviceId); |
|
|
|
tempShippingDevice.setOutOrderCode(""); |
|
|
|
int updateAfterSalesShippingDevice = afterSalesShippingDeviceMapper.updateAfterSalesShippingDevice(tempShippingDevice); |
|
|
|
return updateAfterSalesShippingDevice; |
|
|
|
} |
|
|
|
} |
|
|
|