|
|
|
@ -55,7 +55,9 @@ import com.glxp.api.util.IntUtil;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
|
import com.glxp.api.util.udi.FilterUdiUtils;
|
|
|
|
|
import com.glxp.api.util.udi.UdiCalCountUtil;
|
|
|
|
|
import io.netty.util.internal.ThrowableUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
|
import org.apache.regexp.RE;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -849,8 +851,6 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
@Override
|
|
|
|
|
public void scanInvSfOrderGenerateSfOrder() {
|
|
|
|
|
log.info("扫描处理第三方收费明细生成单据定时任务开始");
|
|
|
|
|
// List<ThrInvOrderDetail> list = thrInvOrderDetailMapper.selectSourceTypeList(Constant.THR_INV_SF_ORDER_TYPE);
|
|
|
|
|
|
|
|
|
|
List<ThrInvOrder> thrInvOrders = thrInvOrderMapper.selectList(new LambdaQueryWrapper<ThrInvOrder>()
|
|
|
|
|
.eq(ThrInvOrder::getSourceType, Constant.THR_INV_SF_ORDER_TYPE)
|
|
|
|
|
.lt(ThrInvOrder::getGenStatus, 3));
|
|
|
|
@ -858,111 +858,125 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
if (CollUtil.isNotEmpty(thrInvOrders)) {
|
|
|
|
|
|
|
|
|
|
for (ThrInvOrder thrInvOrder : thrInvOrders) {
|
|
|
|
|
List<ThrInvOrderDetail> thrInvOrderDetails = thrInvOrderDetailMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<ThrInvOrderDetail>()
|
|
|
|
|
.and(o -> o.isNull(ThrInvOrderDetail::getHandleStatus).or().ne(ThrInvOrderDetail::getHandleStatus, 1)).
|
|
|
|
|
eq(ThrInvOrderDetail::getOrderIdFk, thrInvOrder.getBillNo())
|
|
|
|
|
);
|
|
|
|
|
if (CollectionUtil.isEmpty(thrInvOrderDetails)) continue;
|
|
|
|
|
//通过单号获取单据信息
|
|
|
|
|
QueryWrapper<ThrInvOrder> qw = new QueryWrapper<>();
|
|
|
|
|
qw.eq("billNo", thrInvOrder.getBillNo());
|
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = bussinessTypeService.findByAction(thrInvOrder.getBillType());
|
|
|
|
|
List<ThrInvOrderDetail> addThrInvOrderDetails = new ArrayList<>();
|
|
|
|
|
List<ThrInvOrderDetail> updateThrInvOrderDetails = new ArrayList<>();
|
|
|
|
|
List<Long> delThrInvOrderDetailIds = new ArrayList<>();
|
|
|
|
|
List<String> delThrCodes = new ArrayList<>();
|
|
|
|
|
if (thrInvOrder.getSourceType() == Constant.THR_INV_SF_ORDER_TYPE) {//走组套
|
|
|
|
|
log.info("走组套");
|
|
|
|
|
AtomicInteger fullGen = new AtomicInteger();
|
|
|
|
|
thrInvOrderDetails.forEach(item -> {
|
|
|
|
|
Long relId = item.getRelId();
|
|
|
|
|
if (ObjectUtil.isNull(relId)) {
|
|
|
|
|
String thrCode = item.getThrCode();
|
|
|
|
|
Integer count = Integer.valueOf(item.getReCount());
|
|
|
|
|
List<BasicSkProjectDetailEntity> skProjectDetailEntityList = basicDestinyRelService.filterDestinyRelListByPId(thrCode);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0) {
|
|
|
|
|
delThrInvOrderDetailIds.add(item.getId());
|
|
|
|
|
skProjectDetailEntityList.forEach(sk -> {
|
|
|
|
|
ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail();
|
|
|
|
|
BeanUtils.copyProperties(item, thrInvOrderDetail);
|
|
|
|
|
thrInvOrderDetail.setId(null);
|
|
|
|
|
thrInvOrderDetail.setOrderIdFk(thrInvOrder.getBillNo());
|
|
|
|
|
thrInvOrderDetail.setRelId(sk.getRelId());
|
|
|
|
|
thrInvOrderDetail.setSupId(sk.getSupId() + "");
|
|
|
|
|
thrInvOrderDetail.setHandleStatus(1);
|
|
|
|
|
thrInvOrderDetail.setToBillNo(null);
|
|
|
|
|
|
|
|
|
|
Integer skCount = sk.getCount();
|
|
|
|
|
if (skCount != null && skCount > 0) {
|
|
|
|
|
thrInvOrderDetail.setReCount(String.valueOf(skCount * count));
|
|
|
|
|
}
|
|
|
|
|
addThrInvOrderDetails.add(thrInvOrderDetail);
|
|
|
|
|
delThrCodes.add(thrCode);
|
|
|
|
|
});
|
|
|
|
|
fullGen.getAndIncrement();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
updateThrInvOrderDetails.add(item);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (thrInvOrderDetails.size() == fullGen.intValue()) {
|
|
|
|
|
thrInvOrder.setGenStatus(2);
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
} else if (thrInvOrder.getGenStatus() < 1 && fullGen.intValue() > 0) {
|
|
|
|
|
thrInvOrder.setGenStatus(2);
|
|
|
|
|
try {
|
|
|
|
|
ThrInvOrder temp = thrInvOrderMapper.selectById(thrInvOrder.getId());
|
|
|
|
|
if (temp.getGenStatus() < 3) {
|
|
|
|
|
thrInvOrder.setGenStatus(4);
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
} else {
|
|
|
|
|
//如果该单据还在生成中则跳过
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {//不走组套
|
|
|
|
|
log.info("不走组套");
|
|
|
|
|
String thirdSysFk = thrInvOrder.getThirdSysFk();
|
|
|
|
|
List<String> thrCodes = thrInvOrderDetails.stream().filter(x -> ObjectUtil.isNull(x.getRelId()))
|
|
|
|
|
.map(ThrInvOrderDetail::getThrCode).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(thrCodes)) {
|
|
|
|
|
MainIdRelIdAndProductResponse map = udiRelevanceService.selectMainIdRelIdAndProductMap(thrCodes, thirdSysFk);
|
|
|
|
|
Map<String, UdiRelevanceEntity> mainIdRelIdMap = map.getMainIdRelIdMap();
|
|
|
|
|
|
|
|
|
|
List<ThrInvOrderDetail> thrInvOrderDetails = thrInvOrderDetailMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<ThrInvOrderDetail>()
|
|
|
|
|
.and(o -> o.isNull(ThrInvOrderDetail::getHandleStatus).or().ne(ThrInvOrderDetail::getHandleStatus, 1)).
|
|
|
|
|
eq(ThrInvOrderDetail::getOrderIdFk, thrInvOrder.getBillNo())
|
|
|
|
|
);
|
|
|
|
|
if (CollectionUtil.isEmpty(thrInvOrderDetails)) continue;
|
|
|
|
|
//通过单号获取单据信息
|
|
|
|
|
QueryWrapper<ThrInvOrder> qw = new QueryWrapper<>();
|
|
|
|
|
qw.eq("billNo", thrInvOrder.getBillNo());
|
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = bussinessTypeService.findByAction(thrInvOrder.getBillType());
|
|
|
|
|
List<ThrInvOrderDetail> addThrInvOrderDetails = new ArrayList<>();
|
|
|
|
|
List<ThrInvOrderDetail> updateThrInvOrderDetails = new ArrayList<>();
|
|
|
|
|
List<Long> delThrInvOrderDetailIds = new ArrayList<>();
|
|
|
|
|
List<String> delThrCodes = new ArrayList<>();
|
|
|
|
|
if (thrInvOrder.getSourceType() == Constant.THR_INV_SF_ORDER_TYPE) {//走组套
|
|
|
|
|
log.info("走组套");
|
|
|
|
|
AtomicInteger fullGen = new AtomicInteger();
|
|
|
|
|
thrInvOrderDetails.forEach(item -> {
|
|
|
|
|
if (ObjectUtil.isNull(item.getRelId())) {
|
|
|
|
|
Long relId = item.getRelId();
|
|
|
|
|
if (ObjectUtil.isNull(relId)) {
|
|
|
|
|
String thrCode = item.getThrCode();
|
|
|
|
|
Long relId = mainIdRelIdMap.get(thrCode).getId();
|
|
|
|
|
if (ObjectUtil.isNotNull(relId)) {
|
|
|
|
|
item.setRelId(relId);
|
|
|
|
|
item.setHandleStatus(1);
|
|
|
|
|
item.setToBillNo(null);
|
|
|
|
|
updateThrInvOrderDetails.add(item);
|
|
|
|
|
//校验产品是否被供应商关联
|
|
|
|
|
CompanyProductRelevanceEntity udiRlSupEntity = udiRlSupService.selOneByRlId(relId);
|
|
|
|
|
if (udiRlSupEntity != null)
|
|
|
|
|
item.setSupId(udiRlSupEntity.getCustomerId());
|
|
|
|
|
Integer count = Integer.valueOf(item.getReCount());
|
|
|
|
|
List<BasicSkProjectDetailEntity> skProjectDetailEntityList = basicDestinyRelService.filterDestinyRelListByPId(thrCode);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0) {
|
|
|
|
|
delThrInvOrderDetailIds.add(item.getId());
|
|
|
|
|
skProjectDetailEntityList.forEach(sk -> {
|
|
|
|
|
ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail();
|
|
|
|
|
BeanUtils.copyProperties(item, thrInvOrderDetail);
|
|
|
|
|
thrInvOrderDetail.setId(null);
|
|
|
|
|
thrInvOrderDetail.setOrderIdFk(thrInvOrder.getBillNo());
|
|
|
|
|
thrInvOrderDetail.setRelId(sk.getRelId());
|
|
|
|
|
thrInvOrderDetail.setSupId(sk.getSupId() + "");
|
|
|
|
|
thrInvOrderDetail.setHandleStatus(1);
|
|
|
|
|
thrInvOrderDetail.setToBillNo(null);
|
|
|
|
|
|
|
|
|
|
Integer skCount = sk.getCount();
|
|
|
|
|
if (skCount != null && skCount > 0) {
|
|
|
|
|
thrInvOrderDetail.setReCount(String.valueOf(skCount * count));
|
|
|
|
|
}
|
|
|
|
|
addThrInvOrderDetails.add(thrInvOrderDetail);
|
|
|
|
|
delThrCodes.add(thrCode);
|
|
|
|
|
});
|
|
|
|
|
fullGen.getAndIncrement();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
updateThrInvOrderDetails.add(item);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (thrInvOrderDetails.size() == fullGen.intValue()) {
|
|
|
|
|
thrInvOrder.setGenStatus(2);
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
} else if (thrInvOrder.getGenStatus() < 1 && fullGen.intValue() > 0) {
|
|
|
|
|
thrInvOrder.setGenStatus(2);
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {//不走组套
|
|
|
|
|
log.info("不走组套");
|
|
|
|
|
String thirdSysFk = thrInvOrder.getThirdSysFk();
|
|
|
|
|
List<String> thrCodes = thrInvOrderDetails.stream().filter(x -> ObjectUtil.isNull(x.getRelId()))
|
|
|
|
|
.map(ThrInvOrderDetail::getThrCode).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(thrCodes)) {
|
|
|
|
|
MainIdRelIdAndProductResponse map = udiRelevanceService.selectMainIdRelIdAndProductMap(thrCodes, thirdSysFk);
|
|
|
|
|
Map<String, UdiRelevanceEntity> mainIdRelIdMap = map.getMainIdRelIdMap();
|
|
|
|
|
|
|
|
|
|
thrInvOrderDetails.forEach(item -> {
|
|
|
|
|
if (ObjectUtil.isNull(item.getRelId())) {
|
|
|
|
|
String thrCode = item.getThrCode();
|
|
|
|
|
Long relId = mainIdRelIdMap.get(thrCode).getId();
|
|
|
|
|
if (ObjectUtil.isNotNull(relId)) {
|
|
|
|
|
item.setRelId(relId);
|
|
|
|
|
item.setHandleStatus(1);
|
|
|
|
|
item.setToBillNo(null);
|
|
|
|
|
updateThrInvOrderDetails.add(item);
|
|
|
|
|
//校验产品是否被供应商关联
|
|
|
|
|
CompanyProductRelevanceEntity udiRlSupEntity = udiRlSupService.selOneByRlId(relId);
|
|
|
|
|
if (udiRlSupEntity != null)
|
|
|
|
|
item.setSupId(udiRlSupEntity.getCustomerId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除原来的明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(delThrInvOrderDetailIds)) {
|
|
|
|
|
thrInvOrderDetailMapper.deleteBatchIds(delThrInvOrderDetailIds);
|
|
|
|
|
}
|
|
|
|
|
//删除原来的明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(delThrCodes)) {
|
|
|
|
|
thrInvOrderDetailMapper.deleteBatchByThrCodeIds(delThrCodes);
|
|
|
|
|
}
|
|
|
|
|
//新增明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(addThrInvOrderDetails)) {
|
|
|
|
|
thrInvOrderDetailMapper.insertBatch(addThrInvOrderDetails);
|
|
|
|
|
genOrder(thrInvOrder, bussinessTypeEntity, addThrInvOrderDetails);
|
|
|
|
|
}
|
|
|
|
|
//更新明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(updateThrInvOrderDetails)) {
|
|
|
|
|
thrInvOrderDetailMapper.updateBatchById(updateThrInvOrderDetails);
|
|
|
|
|
genOrder(thrInvOrder, bussinessTypeEntity, updateThrInvOrderDetails);
|
|
|
|
|
//删除原来的明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(delThrInvOrderDetailIds)) {
|
|
|
|
|
thrInvOrderDetailMapper.deleteBatchIds(delThrInvOrderDetailIds);
|
|
|
|
|
}
|
|
|
|
|
//删除原来的明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(delThrCodes)) {
|
|
|
|
|
thrInvOrderDetailMapper.deleteBatchByThrCodeIds(delThrCodes);
|
|
|
|
|
}
|
|
|
|
|
//新增明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(addThrInvOrderDetails)) {
|
|
|
|
|
thrInvOrderDetailMapper.insertBatch(addThrInvOrderDetails);
|
|
|
|
|
genOrder(thrInvOrder, bussinessTypeEntity, addThrInvOrderDetails);
|
|
|
|
|
}
|
|
|
|
|
//更新明细
|
|
|
|
|
if (CollectionUtil.isNotEmpty(updateThrInvOrderDetails)) {
|
|
|
|
|
thrInvOrderDetailMapper.updateBatchById(updateThrInvOrderDetails);
|
|
|
|
|
genOrder(thrInvOrder, bussinessTypeEntity, updateThrInvOrderDetails);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error("生成单据异常", ExceptionUtils.getStackTrace(e));
|
|
|
|
|
thrInvOrder.setGenStatus(2);
|
|
|
|
|
thrInvOrder.setRemark(new Date() + "出现异常");
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1032,6 +1046,7 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
}
|
|
|
|
|
thrInvOrderDetailMapper.updateBatchById(thrInvOrderDetails);
|
|
|
|
|
thrInvOrder.setToBillNo(toBillNo);
|
|
|
|
|
thrInvOrder.setGenStatus(3);
|
|
|
|
|
thrInvOrderMapper.updateById(thrInvOrder);
|
|
|
|
|
ioOrderService.insertOrder(ioOrderEntity);
|
|
|
|
|
ioOrderDetailBizService.batchInsertBizs(newOrderDetailBiz);
|
|
|
|
|