|
|
|
@ -5,16 +5,24 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.sale.admin.constant.ConstantStatus;
|
|
|
|
|
import com.glxp.sale.admin.constant.ConstantType;
|
|
|
|
|
import com.glxp.sale.admin.dao.basic.BussinessTypeDao;
|
|
|
|
|
import com.glxp.sale.admin.dao.inout.*;
|
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDao;
|
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvProductDetailDao;
|
|
|
|
|
import com.glxp.sale.admin.dao.inventory.InvWarehouseDao;
|
|
|
|
|
import com.glxp.sale.admin.entity.basic.BussinessTypeEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.OrderEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.StockOrderEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inout.WarehouseEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductDetailEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.inventory.InvProductEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.param.SystemParamConfigEntity;
|
|
|
|
|
import com.glxp.sale.admin.req.inout.OrderFilterRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inout.OrderQueryRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inout.StockOrderFilterRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inventory.FilterInvProductDetailRequest;
|
|
|
|
|
import com.glxp.sale.admin.req.inventory.FilterInvProductRequest;
|
|
|
|
|
import com.glxp.sale.admin.res.inout.StockOrderResponse;
|
|
|
|
|
import com.glxp.sale.admin.service.inout.OrderService;
|
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
@ -24,11 +32,14 @@ import com.glxp.sale.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.sale.common.util.ResultVOUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -52,6 +63,14 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
SystemParamConfigService systemParamConfigService;
|
|
|
|
|
@Resource
|
|
|
|
|
GennerOrderUtils gennerOrderUtils;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvProductDao invProductDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private InvProductDetailDao invProductDetailDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private StockOrderDetailDao stockOrderDetailDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private OrderDetailDao orderDetailDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<OrderEntity> listOrders(OrderQueryRequest orderQueryRequest) {
|
|
|
|
@ -294,5 +313,101 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<OrderEntity> filterOrderForDelete(String billNo) {
|
|
|
|
|
OrderEntity orderEntity = orderDao.selectByBillNo(billNo);
|
|
|
|
|
if (null == orderEntity) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
//查询码表中所有的单据号
|
|
|
|
|
List<String> orderIds = codesDao.selectOrderIdsByOrderId(orderEntity.getId());
|
|
|
|
|
if (orderIds.size() > 1) {
|
|
|
|
|
orderIds.removeIf(s -> s.equals(orderEntity.getId()));
|
|
|
|
|
} else {
|
|
|
|
|
return Collections.singletonList(orderEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<OrderEntity> orderEntities = orderDao.selectByIds(orderIds);
|
|
|
|
|
orderEntities.add(0, orderEntity);
|
|
|
|
|
return orderEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteOrders(List<String> ids) {
|
|
|
|
|
for (String id : ids) {
|
|
|
|
|
log.info("开始删除单号为:" + id + "的单据");
|
|
|
|
|
//查询扫码单据
|
|
|
|
|
OrderFilterRequest orderFilterRequest = new OrderFilterRequest();
|
|
|
|
|
orderFilterRequest.setId(id);
|
|
|
|
|
OrderEntity orderEntity = orderDao.findOne(orderFilterRequest);
|
|
|
|
|
if (orderEntity.getStatus() == 4) {
|
|
|
|
|
//查询库存详情
|
|
|
|
|
FilterInvProductDetailRequest filterInvProductDetailRequest = new FilterInvProductDetailRequest();
|
|
|
|
|
filterInvProductDetailRequest.setOrderIdFk(id);
|
|
|
|
|
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
|
|
|
|
|
Map<String, List<InvProductDetailEntity>> invProductDetailMap = invProductDetailEntities.stream().collect(Collectors.groupingBy(InvProductDetailEntity::getProductIdFk));
|
|
|
|
|
|
|
|
|
|
List<InvProductEntity> invProductList = new ArrayList<>(invProductDetailMap.keySet().size());
|
|
|
|
|
for (String productIdFk : invProductDetailMap.keySet()) {
|
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
|
filterInvProductRequest.setRelIdFk(productIdFk);
|
|
|
|
|
List<InvProductEntity> invProductEntities = invProductDao.filterInvProduct(filterInvProductRequest);
|
|
|
|
|
InvProductEntity invProductEntity = invProductEntities.get(0);
|
|
|
|
|
List<InvProductDetailEntity> temp = invProductDetailMap.get(productIdFk);
|
|
|
|
|
String mainAction = temp.get(0).getMainAction();
|
|
|
|
|
int sum = temp.stream().mapToInt(InvProductDetailEntity::getCount).sum();
|
|
|
|
|
if (mainAction.equals(ConstantType.TYPE_PUT)) {
|
|
|
|
|
//入库,在原有库存基础上减库存
|
|
|
|
|
int count = invProductEntity.getInCount() - sum;
|
|
|
|
|
invProductEntity.setInCount(count);
|
|
|
|
|
} else if (mainAction.equals(ConstantType.TYPE_OUT)) {
|
|
|
|
|
//出库,在原有库存上增加库存
|
|
|
|
|
int count = invProductEntity.getOutCount() + sum;
|
|
|
|
|
invProductEntity.setOutCount(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invProductList.add(invProductEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除单据相关数据,更新库存
|
|
|
|
|
try {
|
|
|
|
|
//更新库存
|
|
|
|
|
for (InvProductEntity invProductEntity : invProductList) {
|
|
|
|
|
invProductDao.updateInvProduct(invProductEntity);
|
|
|
|
|
}
|
|
|
|
|
//删除库存详情
|
|
|
|
|
invProductDetailDao.deleteByOrderId(id);
|
|
|
|
|
//删除码详情
|
|
|
|
|
codesDao.deleteByOrderId(id);
|
|
|
|
|
//查询业务单据
|
|
|
|
|
StockOrderFilterRequest stockOrderFilterRequest = new StockOrderFilterRequest();
|
|
|
|
|
stockOrderFilterRequest.setBillNo(orderEntity.getErpFk());
|
|
|
|
|
StockOrderEntity stockOrderEntity = stockOrderDao.findOne(stockOrderFilterRequest);
|
|
|
|
|
//删除业务单据详情
|
|
|
|
|
stockOrderDetailDao.deleteByOrderIdFk(stockOrderEntity.getId());
|
|
|
|
|
//删除业务单据
|
|
|
|
|
stockOrderDao.deleteById(stockOrderEntity.getId());
|
|
|
|
|
//删除扫码单据详情
|
|
|
|
|
orderDetailDao.deleteByOrderId(id);
|
|
|
|
|
//删除扫码单据
|
|
|
|
|
orderDao.deleteById(id);
|
|
|
|
|
log.info("单号为:" + id + " 的单据已删除");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("删除单据失败", e);
|
|
|
|
|
throw new RuntimeException("删除单据失败");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//未验收单据
|
|
|
|
|
orderDao.deleteById(id);
|
|
|
|
|
orderDetailDao.deleteByOrderId(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateOrderInfo(String actDate, String auditTime, List<String> orderIds) {
|
|
|
|
|
return orderDao.updateOrderTime(actDate, auditTime, DateUtil.getDateTime(), orderIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|