|
@ -1,10 +1,22 @@ |
|
|
package com.qs.serve.modules.bir.service.impl; |
|
|
package com.qs.serve.modules.bir.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
|
|
|
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods; |
|
|
import com.qs.serve.modules.bir.entity.so.BirBudgetTargetSo; |
|
|
import com.qs.serve.modules.bir.entity.so.BirBudgetTargetSo; |
|
|
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirBaseDispatchVo; |
|
|
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirBaseReportVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirBudgetTargetVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirBudgetTargetVo; |
|
|
|
|
|
import com.qs.serve.modules.bir.mapper.BirActivityCenterGoodsMapper; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
|
|
import com.qs.serve.modules.bms.service.BmsRegion2Service; |
|
|
|
|
|
import com.qs.serve.modules.bms.service.BmsRegionService; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -36,6 +48,176 @@ import java.util.stream.Collectors; |
|
|
public class BirBudgetTargetServiceImpl extends ServiceImpl<BirBudgetTargetMapper,BirBudgetTarget> implements BirBudgetTargetService { |
|
|
public class BirBudgetTargetServiceImpl extends ServiceImpl<BirBudgetTargetMapper,BirBudgetTarget> implements BirBudgetTargetService { |
|
|
|
|
|
|
|
|
private BmsSupplierService bmsSupplierService; |
|
|
private BmsSupplierService bmsSupplierService; |
|
|
|
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
|
|
|
private BmsRegion2Service bmsRegion2Service; |
|
|
|
|
|
private BmsRegionService bmsRegionService; |
|
|
|
|
|
private BirActivityCenterGoodsMapper birActivityCenterGoodsMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<BirBaseReportVo> listBaseVo(BirBudgetTargetSo query) { |
|
|
|
|
|
List<BirBaseReportVo> returnList = new ArrayList<>(); |
|
|
|
|
|
query.setLoadType(query.getLoadType()-1); |
|
|
|
|
|
LocalDateTime endMonth = query.getYearMonthEnd(); |
|
|
|
|
|
LocalDateTime startMonth = query.getYearMonthStart(); |
|
|
|
|
|
query.setYearMonthStartQuery(startMonth.getYear()*100 + startMonth.getMonthValue()); |
|
|
|
|
|
query.setYearMonthEndQuery(endMonth.getYear()*100 + endMonth.getMonthValue()); |
|
|
|
|
|
query.setSelectCenterFlag(0); |
|
|
|
|
|
if(CollUtil.isNotEmpty(query.getCenterList())){ |
|
|
|
|
|
query.setSelectCenterFlag(1); |
|
|
|
|
|
} |
|
|
|
|
|
if(query.getLoadType()==0) { |
|
|
|
|
|
BmsSupplier supplier = bmsSupplierService.getById(query.getTargetId()); |
|
|
|
|
|
if(supplier==null){ |
|
|
|
|
|
Assert.throwEx("找不到该客户!"); |
|
|
|
|
|
} |
|
|
|
|
|
List<String> supplierIds = new ArrayList<>(); |
|
|
|
|
|
List<String> supplierCodes = new ArrayList<>(); |
|
|
|
|
|
supplierIds.add(supplier.getId()); |
|
|
|
|
|
query.setSupplierIds(supplierIds); |
|
|
|
|
|
supplierCodes.add(supplier.getCode()); |
|
|
|
|
|
query.setSupplierCodes(supplierCodes); |
|
|
|
|
|
}else if(query.getLoadType()==1){ |
|
|
|
|
|
BmsSupplier param4Supplier = new BmsSupplier(); |
|
|
|
|
|
param4Supplier.setCurrUserId(query.getTargetId()); |
|
|
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectSupplierList(param4Supplier); |
|
|
|
|
|
List<String> supplierIds = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getId) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierIds(supplierIds); |
|
|
|
|
|
|
|
|
|
|
|
List<String> supplierCodes = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getCode) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierCodes(supplierCodes); |
|
|
|
|
|
}else if(query.getLoadType()==2){ |
|
|
|
|
|
BmsRegion2 targetRegion = bmsRegion2Service.getById(query.getTargetId()); |
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.eq(BmsSupplier::getBookCode,"001"); |
|
|
|
|
|
if(targetRegion.getLevel()==1){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegion2First,query.getTargetId()); |
|
|
|
|
|
}else if(targetRegion.getLevel()==2){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegion2Second,query.getTargetId()); |
|
|
|
|
|
}else if(targetRegion.getLevel()==3){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegion2Third,query.getTargetId()); |
|
|
|
|
|
}else{ |
|
|
|
|
|
Assert.throwEx("行政区域查询失败!"); |
|
|
|
|
|
} |
|
|
|
|
|
List<BmsSupplier> supplierList = bmsSupplierService.list(lqw); |
|
|
|
|
|
List<String> supplierIds = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getId) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierIds(supplierIds); |
|
|
|
|
|
List<String> supplierCodes = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getCode) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierCodes(supplierCodes); |
|
|
|
|
|
}else if(query.getLoadType()==3){ |
|
|
|
|
|
BmsRegion targetRegion = bmsRegionService.getById(query.getTargetId()); |
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.eq(BmsSupplier::getBookCode,"001"); |
|
|
|
|
|
|
|
|
|
|
|
if(targetRegion.getLevel()==1){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegionFirst,query.getTargetId()); |
|
|
|
|
|
}else if(targetRegion.getLevel()==2){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegionSecond,query.getTargetId()); |
|
|
|
|
|
}else if(targetRegion.getLevel()==3){ |
|
|
|
|
|
lqw.eq(BmsSupplier::getRegionThird,query.getTargetId()); |
|
|
|
|
|
}else{ |
|
|
|
|
|
Assert.throwEx("销售区域查询失败!"); |
|
|
|
|
|
} |
|
|
|
|
|
List<BmsSupplier> supplierList = bmsSupplierService.list(lqw); |
|
|
|
|
|
List<String> supplierIds = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getId) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierIds(supplierIds); |
|
|
|
|
|
List<String> supplierCodes = supplierList.stream() |
|
|
|
|
|
.map(BmsSupplier::getCode) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
|
|
query.setSupplierCodes(supplierCodes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<BirActivityCenterGoods> birActivityCenterGoodsList = new ArrayList<>(); |
|
|
|
|
|
List<BirBaseDispatchVo> birBaseDispatchVoList = new ArrayList<>(); |
|
|
|
|
|
if(query.getSupplierIds().size()>2000 || query.getSupplierCodes().size()>2000){ |
|
|
|
|
|
List<String> supplierIds = query.getSupplierIds(); |
|
|
|
|
|
List<String> supplierCodes = query.getSupplierCodes(); |
|
|
|
|
|
|
|
|
|
|
|
List<List<String>> supplierIdList = CollectionUtil.createList(supplierIds,2000); |
|
|
|
|
|
List<List<String>> supplierCodeList = CollectionUtil.createList(supplierCodes,2000); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<supplierIdList.size();i++){ |
|
|
|
|
|
List<String> tempIds = supplierIdList.get(i); |
|
|
|
|
|
tempIds.add("-99"); |
|
|
|
|
|
query.setSupplierIds(tempIds); |
|
|
|
|
|
List<String> tempCodes = supplierCodeList.get(i); |
|
|
|
|
|
tempCodes.add("-99"); |
|
|
|
|
|
query.setSupplierCodes(tempCodes); |
|
|
|
|
|
|
|
|
|
|
|
List<BirActivityCenterGoods> tempActivityCenterGoodsList = birActivityCenterGoodsMapper.list4BirBudgetTarget(query); |
|
|
|
|
|
List<BirBaseDispatchVo> tempBaseDispatchVoList = birActivityCenterGoodsMapper.list4DispatchSqlserver(query); |
|
|
|
|
|
birActivityCenterGoodsList.addAll(tempActivityCenterGoodsList); |
|
|
|
|
|
birBaseDispatchVoList.addAll(tempBaseDispatchVoList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
//防止传入空数组,导致SQL查出所有客户
|
|
|
|
|
|
List<String> supplierIds = query.getSupplierIds(); |
|
|
|
|
|
supplierIds.add("-99"); |
|
|
|
|
|
query.setSupplierIds(supplierIds); |
|
|
|
|
|
List<String> supplierCodes = query.getSupplierCodes(); |
|
|
|
|
|
supplierCodes.add("-99"); |
|
|
|
|
|
query.setSupplierCodes(supplierCodes); |
|
|
|
|
|
|
|
|
|
|
|
birActivityCenterGoodsList = birActivityCenterGoodsMapper.list4BirBudgetTarget(query); |
|
|
|
|
|
birBaseDispatchVoList = birActivityCenterGoodsMapper.list4DispatchSqlserver(query); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final int TOTAL_MONTH = 12; |
|
|
|
|
|
for (int y = startMonth.getYear(); y <= endMonth.getYear(); y++) { |
|
|
|
|
|
for (int m = 1; m <= TOTAL_MONTH; m++) { |
|
|
|
|
|
//防止多空白行
|
|
|
|
|
|
if(y == startMonth.getYear() && m < startMonth.getMonthValue()){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if(y == endMonth.getYear() && m > endMonth.getMonthValue()){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
returnList.add(initBaseVo(birActivityCenterGoodsList,birBaseDispatchVoList, m, y)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return returnList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private BirBaseReportVo initBaseVo(List<BirActivityCenterGoods> birActivityCenterGoodsList, |
|
|
|
|
|
List<BirBaseDispatchVo> birBaseDispatchVoList, int month, int year){ |
|
|
|
|
|
BirBaseReportVo vo = new BirBaseReportVo(); |
|
|
|
|
|
vo.setYearMonthNum(year*100 + month); |
|
|
|
|
|
vo.setDispatchAmt(BigDecimal.ZERO); |
|
|
|
|
|
vo.setTotalRealAmt(BigDecimal.ZERO); |
|
|
|
|
|
vo.setTotalRealRate(BigDecimal.ZERO); |
|
|
|
|
|
vo.setYear(year+""); |
|
|
|
|
|
vo.setMonth(month+""); |
|
|
|
|
|
|
|
|
|
|
|
if(birActivityCenterGoodsList.size()>0){ |
|
|
|
|
|
BigDecimal totalRealAmt = birActivityCenterGoodsList.stream().filter(a->a.getKeyNum().equals(vo.getYearMonthNum())) |
|
|
|
|
|
.map(a->a.getSplitUsedAmount()==null?BigDecimal.ZERO:a.getSplitUsedAmount()) |
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
vo.setTotalRealAmt(totalRealAmt); |
|
|
|
|
|
} |
|
|
|
|
|
if(birBaseDispatchVoList.size()>0){ |
|
|
|
|
|
BigDecimal dispatchAmt = birBaseDispatchVoList.stream().filter(a->a.getYearMonthNum().equals(vo.getYearMonthNum())) |
|
|
|
|
|
.map(a->a.getDispatchAmt()==null?BigDecimal.ZERO:a.getDispatchAmt()) |
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
vo.setDispatchAmt(dispatchAmt); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(vo.getDispatchAmt().compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
|
|
vo.setTotalRealRate(vo.getTotalRealAmt().divide(vo.getDispatchAmt(), 2, RoundingMode.DOWN)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return vo; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<BirBudgetTargetVo> listVo(BirBudgetTargetSo query) { |
|
|
public List<BirBudgetTargetVo> listVo(BirBudgetTargetSo query) { |
|
|