|
|
|
@ -1,13 +1,18 @@
|
|
|
|
|
package com.os.ems.info.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import com.os.common.exception.ServiceException;
|
|
|
|
|
import com.os.common.utils.StringUtils;
|
|
|
|
|
import com.os.ems.info.mapper.SparePartsInventoryCheckMapper;
|
|
|
|
|
import com.os.ems.info.domain.SparePartsInventoryCheck;
|
|
|
|
|
import com.os.ems.info.service.ISparePartsInventoryCheckService;
|
|
|
|
|
import com.os.ems.info.util.InventoryQuantityUpdater;
|
|
|
|
|
import com.os.common.utils.DateUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 备件盘点记录明细Service业务层处理
|
|
|
|
@ -21,6 +26,9 @@ public class SparePartsInventoryCheckServiceImpl implements ISparePartsInventory
|
|
|
|
|
@Autowired
|
|
|
|
|
private SparePartsInventoryCheckMapper sparePartsInventoryCheckMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private InventoryQuantityUpdater inventoryQuantityUpdater;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询备件盘点记录明细
|
|
|
|
|
*
|
|
|
|
@ -52,9 +60,22 @@ public class SparePartsInventoryCheckServiceImpl implements ISparePartsInventory
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int insertSparePartsInventoryCheck(SparePartsInventoryCheck sparePartsInventoryCheck)
|
|
|
|
|
{
|
|
|
|
|
return sparePartsInventoryCheckMapper.insertSparePartsInventoryCheck(sparePartsInventoryCheck);
|
|
|
|
|
// 验证必要参数
|
|
|
|
|
if (sparePartsInventoryCheck.getInventoryObjid() == null) {
|
|
|
|
|
throw new ServiceException("库存记录ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int result = sparePartsInventoryCheckMapper.insertSparePartsInventoryCheck(sparePartsInventoryCheck);
|
|
|
|
|
|
|
|
|
|
// 如果插入成功,更新主表的剩余数量
|
|
|
|
|
if (result > 0) {
|
|
|
|
|
inventoryQuantityUpdater.updateRemainingQuantityByLatestCheck(sparePartsInventoryCheck.getInventoryObjid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -64,9 +85,17 @@ public class SparePartsInventoryCheckServiceImpl implements ISparePartsInventory
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int updateSparePartsInventoryCheck(SparePartsInventoryCheck sparePartsInventoryCheck)
|
|
|
|
|
{
|
|
|
|
|
return sparePartsInventoryCheckMapper.updateSparePartsInventoryCheck(sparePartsInventoryCheck);
|
|
|
|
|
int result = sparePartsInventoryCheckMapper.updateSparePartsInventoryCheck(sparePartsInventoryCheck);
|
|
|
|
|
|
|
|
|
|
// 如果更新成功,同步更新主表的剩余数量
|
|
|
|
|
if (result > 0 && sparePartsInventoryCheck.getInventoryObjid() != null) {
|
|
|
|
|
inventoryQuantityUpdater.updateRemainingQuantityByLatestCheck(sparePartsInventoryCheck.getInventoryObjid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -76,9 +105,31 @@ public class SparePartsInventoryCheckServiceImpl implements ISparePartsInventory
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int deleteSparePartsInventoryCheckByIds(Long[] ids)
|
|
|
|
|
{
|
|
|
|
|
return sparePartsInventoryCheckMapper.deleteSparePartsInventoryCheckByIds(ids);
|
|
|
|
|
if (ids == null || ids.length == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 先查询要删除的记录,收集相关的库存ID
|
|
|
|
|
Set<Long> inventoryObjids = new HashSet<>();
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
SparePartsInventoryCheck check = sparePartsInventoryCheckMapper.selectSparePartsInventoryCheckById(id);
|
|
|
|
|
if (check != null && check.getInventoryObjid() != null) {
|
|
|
|
|
inventoryObjids.add(check.getInventoryObjid());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int result = sparePartsInventoryCheckMapper.deleteSparePartsInventoryCheckByIds(ids);
|
|
|
|
|
|
|
|
|
|
// 如果删除成功,批量更新相关库存记录的剩余数量
|
|
|
|
|
if (result > 0 && !inventoryObjids.isEmpty()) {
|
|
|
|
|
Long[] objidArray = inventoryObjids.toArray(new Long[0]);
|
|
|
|
|
inventoryQuantityUpdater.batchUpdateRemainingQuantity(objidArray);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -88,9 +139,20 @@ public class SparePartsInventoryCheckServiceImpl implements ISparePartsInventory
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int deleteSparePartsInventoryCheckById(Long id)
|
|
|
|
|
{
|
|
|
|
|
return sparePartsInventoryCheckMapper.deleteSparePartsInventoryCheckById(id);
|
|
|
|
|
// 先查询要删除的记录,获取库存ID
|
|
|
|
|
SparePartsInventoryCheck checkToDelete = sparePartsInventoryCheckMapper.selectSparePartsInventoryCheckById(id);
|
|
|
|
|
|
|
|
|
|
int result = sparePartsInventoryCheckMapper.deleteSparePartsInventoryCheckById(id);
|
|
|
|
|
|
|
|
|
|
// 如果删除成功,同步更新主表的剩余数量
|
|
|
|
|
if (result > 0 && checkToDelete != null && checkToDelete.getInventoryObjid() != null) {
|
|
|
|
|
inventoryQuantityUpdater.updateRemainingQuantityByLatestCheck(checkToDelete.getInventoryObjid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|