|
|
@ -6,10 +6,12 @@ import com.qs.serve.common.model.dto.DateSplitDTO; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
import com.qs.serve.common.util.AuthContextUtils; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.common.util.DateSplitUtil; |
|
|
|
import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; |
|
|
|
import com.qs.serve.modules.bir.entity.so.BirCostRoiSo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirRoiCostItemVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
import com.qs.serve.modules.erp.entity.ErpDispatchData; |
|
|
@ -18,6 +20,7 @@ import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsActivity; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsCostApply; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsActivityMapper; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -29,6 +32,7 @@ import com.qs.serve.modules.bir.mapper.BirRoiRateMapper; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.Month; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
@ -102,68 +106,10 @@ public class BirRoiRateServiceImpl extends ServiceImpl<BirRoiRateMapper,BirRoiRa |
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(currMonthNum); |
|
|
|
BmsSupplier bmsSupplier = bmsSupplierMapper.selectById(supplierId); |
|
|
|
List<String> supplierCodeList = new ArrayList<>(); |
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.select(BmsSupplier::getId,BmsSupplier::getCode); |
|
|
|
if(loadType.equals(0)){ |
|
|
|
//0->客户
|
|
|
|
supplierCodeList.add(bmsSupplier.getCode()); |
|
|
|
costDTO.setSupplierId(supplierId); |
|
|
|
}else if (loadType.equals(1)){ |
|
|
|
//1->申请人的客户
|
|
|
|
String userId = AuthContextUtils.getSysUserId(); |
|
|
|
costDTO.setNotSupplierId(supplierId); |
|
|
|
costDTO.setUserId(userId); |
|
|
|
//加载用户的其它供应商编码
|
|
|
|
BmsSupplier param4Supplier = new BmsSupplier(); |
|
|
|
param4Supplier.setUserId(userId); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectSupplierList(param4Supplier); |
|
|
|
List<String> supplierCodes = supplierList.stream() |
|
|
|
.filter(a->!a.getId().equals(supplierId)).map(BmsSupplier::getCode) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
supplierCodeList.addAll(supplierCodes); |
|
|
|
}else if(loadType.equals(2)){ |
|
|
|
//2->客户的行政区域
|
|
|
|
if(checkNotNullVale(bmsSupplier.getRegion2Fourthly())){ |
|
|
|
lqw.eq(BmsSupplier::getRegion2Fourthly,bmsSupplier.getRegion2Fourthly()); |
|
|
|
}else if (checkNotNullVale(bmsSupplier.getRegion2Third())){ |
|
|
|
lqw.eq(BmsSupplier::getRegion2Third,bmsSupplier.getRegion2Third()); |
|
|
|
} if (checkNotNullVale(bmsSupplier.getRegion2Second())){ |
|
|
|
lqw.eq(BmsSupplier::getRegion2Second,bmsSupplier.getRegion2Second()); |
|
|
|
} if (checkNotNullVale(bmsSupplier.getRegion2First())){ |
|
|
|
lqw.eq(BmsSupplier::getRegion2First,bmsSupplier.getRegion2First()); |
|
|
|
}else{ |
|
|
|
lqw.eq(BmsSupplier::getId,"0"); |
|
|
|
} |
|
|
|
}else if(loadType.equals(3)){ |
|
|
|
//3->客户的销售区域
|
|
|
|
if(checkNotNullVale(bmsSupplier.getRegionFourthly())){ |
|
|
|
lqw.eq(BmsSupplier::getRegionFourthly,bmsSupplier.getRegionFourthly()); |
|
|
|
}else if (checkNotNullVale(bmsSupplier.getRegionThird())){ |
|
|
|
lqw.eq(BmsSupplier::getRegionThird,bmsSupplier.getRegionThird()); |
|
|
|
} if (checkNotNullVale(bmsSupplier.getRegionSecond())){ |
|
|
|
lqw.eq(BmsSupplier::getRegionSecond,bmsSupplier.getRegionSecond()); |
|
|
|
} if (checkNotNullVale(bmsSupplier.getRegionFirst())){ |
|
|
|
lqw.eq(BmsSupplier::getRegionFirst,bmsSupplier.getRegionFirst()); |
|
|
|
}else{ |
|
|
|
lqw.eq(BmsSupplier::getId,"0"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (loadType.equals(2)||loadType.equals(3)){ |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(lqw); |
|
|
|
List<String> supplierIds = supplierList.stream().map(BmsSupplier::getId) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
List<String> supplierCodes = supplierList.stream().map(BmsSupplier::getCode) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
supplierCodeList.addAll(supplierCodes); |
|
|
|
//防止空值
|
|
|
|
supplierIds.add("0"); |
|
|
|
costDTO.setSupplierIds(supplierIds); |
|
|
|
} |
|
|
|
//防止空值
|
|
|
|
supplierCodeList.add("0"); |
|
|
|
//设置查询条件和返回客户CODELIST
|
|
|
|
List<String> supplierCodeList = setBiroiCostDTOAndFindSupplierCodes(costDTO,supplierId,loadType,param.getUserId()); |
|
|
|
|
|
|
|
List<BirRoiCostItemVo> costItemVoList = this.queryRoiCostItems(costDTO); |
|
|
|
|
|
|
|
//发货单
|
|
|
@ -228,5 +174,207 @@ public class BirRoiRateServiceImpl extends ServiceImpl<BirRoiRateMapper,BirRoiRa |
|
|
|
return val!=null&&!val.equals("0"); |
|
|
|
} |
|
|
|
|
|
|
|
public Float getYtdPercent(List<BirRoiCostItemVo> list){ |
|
|
|
Float ytdPercent = null; |
|
|
|
|
|
|
|
LocalDate currMonth = LocalDate.now(); |
|
|
|
if(currMonth.getMonthValue()==1){ |
|
|
|
return ytdPercent; |
|
|
|
} |
|
|
|
|
|
|
|
BigDecimal costAmt = BigDecimal.ZERO; |
|
|
|
BigDecimal dispatchAmt = BigDecimal.ZERO; |
|
|
|
|
|
|
|
int currMonthNum = currMonth.getYear()*100 + currMonth.getMonthValue(); |
|
|
|
int startMonthNum = currMonth.getYear()*100 + 1; |
|
|
|
|
|
|
|
for(BirRoiCostItemVo vo:list){ |
|
|
|
if(vo.getYearMonth()<=currMonthNum && vo.getYearMonth()>=startMonthNum){ |
|
|
|
costAmt = costAmt.add(vo.getCostAmt()); |
|
|
|
dispatchAmt = dispatchAmt.add(vo.getDispatchAmt()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(dispatchAmt.compareTo(BigDecimal.ZERO)>0) { |
|
|
|
ytdPercent = costAmt.divide(dispatchAmt,4, RoundingMode.HALF_UP).floatValue(); |
|
|
|
} |
|
|
|
|
|
|
|
return ytdPercent; |
|
|
|
} |
|
|
|
|
|
|
|
public Float getQtdPercent(List<BirRoiCostItemVo> list){ |
|
|
|
Float qtdPercent = null; |
|
|
|
|
|
|
|
LocalDate currMonth = LocalDate.now(); |
|
|
|
if(currMonth.getMonthValue()==1){ |
|
|
|
return qtdPercent; |
|
|
|
} |
|
|
|
// 获取当前季度的第一个月
|
|
|
|
Month firstMonthOfQuarter = currMonth.getMonth().firstMonthOfQuarter(); |
|
|
|
// 获取当季第一个月的整数表示
|
|
|
|
int firstMonthInteger = firstMonthOfQuarter.getValue(); |
|
|
|
|
|
|
|
if(firstMonthInteger == currMonth.getMonthValue()){ |
|
|
|
return qtdPercent; |
|
|
|
} |
|
|
|
|
|
|
|
int currMonthNum = currMonth.getYear()*100 + currMonth.getMonthValue(); |
|
|
|
int startMonthNum = currMonth.getYear()*100 + firstMonthInteger; |
|
|
|
|
|
|
|
BigDecimal costAmt = BigDecimal.ZERO; |
|
|
|
BigDecimal dispatchAmt = BigDecimal.ZERO; |
|
|
|
|
|
|
|
for(BirRoiCostItemVo vo:list){ |
|
|
|
if(vo.getYearMonth()<=currMonthNum && vo.getYearMonth()>=startMonthNum){ |
|
|
|
costAmt = costAmt.add(vo.getCostAmt()); |
|
|
|
dispatchAmt = dispatchAmt.add(vo.getDispatchAmt()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(dispatchAmt.compareTo(BigDecimal.ZERO)>0) { |
|
|
|
qtdPercent = costAmt.divide(dispatchAmt,4, RoundingMode.HALF_UP).floatValue(); |
|
|
|
} |
|
|
|
|
|
|
|
return qtdPercent; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public YtdQtdToOAVo buildYtdAndQtdData(TbsCostApply apply){ |
|
|
|
YtdQtdToOAVo vo = new YtdQtdToOAVo(); |
|
|
|
getYtdData(vo,apply.getSupplierId().toString(), apply.getUserId()); |
|
|
|
getQtdData(vo,apply.getSupplierId().toString(), apply.getUserId()); |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
private void getYtdData(YtdQtdToOAVo vo,String supplierId,String userId){ |
|
|
|
LocalDate currMonth = LocalDate.now(); |
|
|
|
if(currMonth.getMonthValue()==1){ |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
int currMonthNum = currMonth.getYear()*100 + currMonth.getMonthValue(); |
|
|
|
int startMonthNum = currMonth.getYear()*100 + 1; |
|
|
|
|
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(currMonthNum); |
|
|
|
|
|
|
|
Float customerPercent = getPercenDateByLoadType(0,costDTO,supplierId,userId); |
|
|
|
Float userPercent = getPercenDateByLoadType(1,costDTO,supplierId,userId);; |
|
|
|
Float region2Percent = getPercenDateByLoadType(2,costDTO,supplierId,userId);; |
|
|
|
Float regionPercent = getPercenDateByLoadType(3,costDTO,supplierId,userId);; |
|
|
|
|
|
|
|
vo.setYtdCustomerPercent(customerPercent); |
|
|
|
vo.setYtdUserPercent(userPercent); |
|
|
|
vo.setYtdRegion2Percent(region2Percent); |
|
|
|
vo.setYtdRegionPercent(regionPercent); |
|
|
|
} |
|
|
|
|
|
|
|
private void getQtdData(YtdQtdToOAVo vo,String supplierId,String userId){ |
|
|
|
LocalDate currMonth = LocalDate.now(); |
|
|
|
if(currMonth.getMonthValue()==1){ |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
Month firstMonthOfQuarter = currMonth.getMonth().firstMonthOfQuarter(); |
|
|
|
// 获取当季第一个月的整数表示
|
|
|
|
int firstMonthInteger = firstMonthOfQuarter.getValue(); |
|
|
|
|
|
|
|
if(firstMonthInteger == currMonth.getMonthValue()){ |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
int currMonthNum = currMonth.getYear()*100 + currMonth.getMonthValue(); |
|
|
|
int startMonthNum = currMonth.getYear()*100 + firstMonthInteger; |
|
|
|
|
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(currMonthNum); |
|
|
|
|
|
|
|
Float customerPercent = getPercenDateByLoadType(0,costDTO,supplierId,userId); |
|
|
|
Float userPercent = getPercenDateByLoadType(1,costDTO,supplierId,userId);; |
|
|
|
Float region2Percent = getPercenDateByLoadType(2,costDTO,supplierId,userId);; |
|
|
|
Float regionPercent = getPercenDateByLoadType(3,costDTO,supplierId,userId);; |
|
|
|
|
|
|
|
vo.setQtdCustomerPercent(customerPercent); |
|
|
|
vo.setQtdUserPercent(userPercent); |
|
|
|
vo.setQtdRegion2Percent(region2Percent); |
|
|
|
vo.setQtdRegionPercent(regionPercent); |
|
|
|
} |
|
|
|
|
|
|
|
private Float getPercenDateByLoadType(Integer loadType,BirRoiCostDTO oriCostDTO,String supplierId,String userId){ |
|
|
|
BirRoiCostDTO costDTO = CopierUtil.copy(oriCostDTO,new BirRoiCostDTO()); |
|
|
|
List<String> supplierCodeList = setBiroiCostDTOAndFindSupplierCodes(costDTO, supplierId, loadType, userId); |
|
|
|
Float tempPercent = getPercentDate(costDTO,supplierCodeList); |
|
|
|
return tempPercent; |
|
|
|
} |
|
|
|
|
|
|
|
private Float getPercentDate(BirRoiCostDTO costDTO,List<String> supplierCodeList){ |
|
|
|
Float percent = null; |
|
|
|
|
|
|
|
Integer startMonthNum = costDTO.getStartMonthNum(); |
|
|
|
Integer endMonthNum = costDTO.getEndMonthNum(); |
|
|
|
BigDecimal dispatchSumAmt = dispatchDataMapper.querySumCostAmt(startMonthNum,endMonthNum,supplierCodeList); |
|
|
|
|
|
|
|
if(dispatchSumAmt == null || dispatchSumAmt.compareTo(BigDecimal.ZERO)<=0) { |
|
|
|
return percent; |
|
|
|
} |
|
|
|
|
|
|
|
BigDecimal costSumAmt = baseMapper.querySumAmt(costDTO); |
|
|
|
percent = costSumAmt.divide(dispatchSumAmt,4, RoundingMode.HALF_UP).floatValue(); |
|
|
|
return percent; |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> setBiroiCostDTOAndFindSupplierCodes(BirRoiCostDTO costDTO,String supplierId,Integer loadType,String userId){ |
|
|
|
BmsSupplier bmsSupplier = bmsSupplierMapper.selectById(supplierId); |
|
|
|
List<String> supplierCodeList = new ArrayList<>(); |
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.select(BmsSupplier::getId,BmsSupplier::getCode); |
|
|
|
if(loadType.equals(0)){ |
|
|
|
//0->客户
|
|
|
|
supplierCodeList.add(bmsSupplier.getCode()); |
|
|
|
costDTO.setSupplierId(supplierId); |
|
|
|
}else if (loadType.equals(1)){ |
|
|
|
//1->申请人的客户
|
|
|
|
costDTO.setUserId(userId); |
|
|
|
//加载用户的其它供应商编码
|
|
|
|
BmsSupplier param4Supplier = new BmsSupplier(); |
|
|
|
param4Supplier.setCurrUserId(userId); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectSupplierList(param4Supplier); |
|
|
|
List<String> supplierCodes = supplierList.stream() |
|
|
|
.map(BmsSupplier::getCode) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
supplierCodeList.addAll(supplierCodes); |
|
|
|
}else if(loadType.equals(2)){ |
|
|
|
//2->客户的行政区域
|
|
|
|
if (checkNotNullVale(bmsSupplier.getRegion2Second())){ |
|
|
|
lqw.eq(BmsSupplier::getRegion2Second,bmsSupplier.getRegion2Second()); |
|
|
|
}else{ |
|
|
|
lqw.eq(BmsSupplier::getId,"0"); |
|
|
|
} |
|
|
|
}else if(loadType.equals(3)){ |
|
|
|
//3->客户的销售区域
|
|
|
|
if (checkNotNullVale(bmsSupplier.getRegionSecond())){ |
|
|
|
lqw.eq(BmsSupplier::getRegionSecond,bmsSupplier.getRegionSecond()); |
|
|
|
}else{ |
|
|
|
lqw.eq(BmsSupplier::getId,"0"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (loadType.equals(2)||loadType.equals(3)){ |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(lqw); |
|
|
|
List<String> supplierIds = supplierList.stream().map(BmsSupplier::getId) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
List<String> supplierCodes = supplierList.stream().map(BmsSupplier::getCode) |
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
|
supplierCodeList.addAll(supplierCodes); |
|
|
|
//防止空值
|
|
|
|
supplierIds.add("0"); |
|
|
|
costDTO.setSupplierIds(supplierIds); |
|
|
|
} |
|
|
|
//防止空值
|
|
|
|
supplierCodeList.add("0"); |
|
|
|
return supplierCodeList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|