|
|
@ -7,24 +7,30 @@ import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.modules.bir.entity.BirRoiRate; |
|
|
|
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.BirReportVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirRoiCostItemVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.BudgetPlanVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.*; |
|
|
|
import com.qs.serve.modules.bir.mapper.BirReportAccountBookMapper; |
|
|
|
import com.qs.serve.modules.bir.mapper.BirRoiRateMapper; |
|
|
|
import com.qs.serve.modules.bir.service.BirReportAccountBookService; |
|
|
|
import com.qs.serve.modules.bir.service.BirRoiRateService; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsCostCenter; |
|
|
|
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.vo.BmsRegionTreeVo; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
import com.qs.serve.modules.bms.service.BmsCostCenterService; |
|
|
|
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.erp.entity.dto.ErpDispatchSumVo; |
|
|
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
|
|
|
import com.qs.serve.modules.goods.entity.dto.TbsCenterDto; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsCenterType; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudgetPlan; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsCostApply; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsScheduleItem; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemMapper; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetLogService; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetPlanService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
@ -36,6 +42,7 @@ import java.math.RoundingMode; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.Month; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -50,64 +57,145 @@ public class BirReportAccountBookServiceImpl implements BirReportAccountBookServ |
|
|
|
|
|
|
|
private final BirReportAccountBookMapper birReportAccountBookMapper; |
|
|
|
private final BmsRegionService bmsRegionService; |
|
|
|
private final BmsRegion2Service bmsRegion2Service; |
|
|
|
private final BmsSupplierService bmsSupplierService; |
|
|
|
private final BmsCostCenterService bmsCostCenterService; |
|
|
|
private final TbsBudgetPlanService tbsBudgetPlanService; |
|
|
|
private final TbsBudgetLogMapper tbsBudgetLogMapper; |
|
|
|
private final TbsScheduleItemMapper tbsScheduleItemMapper; |
|
|
|
private final ErpDispatchDataMapper erpDispatchDataMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public BirReportVo getReportAccountBookData(String type){ |
|
|
|
public BirAccountReportVo getReportAccountBookData(String type,String year){ |
|
|
|
|
|
|
|
BirReportVo vo = new BirReportVo(); |
|
|
|
BirAccountReportVo vo = new BirAccountReportVo(); |
|
|
|
|
|
|
|
Map<String,String> map = new HashMap<>(); |
|
|
|
map.put("result",""); |
|
|
|
birReportAccountBookMapper.getReportHeader(map); |
|
|
|
List<List<BirCenterCostRateMain>> itemDataList = new ArrayList<>(); |
|
|
|
|
|
|
|
String headerString = map.get("result"); |
|
|
|
List<HeaderOption> headerOptions = Arrays.stream(headerString.split(",")).map(a->{ |
|
|
|
String temp = a.trim(); |
|
|
|
if(temp.contains("as")){ |
|
|
|
temp = a.split("as")[1].trim(); |
|
|
|
} |
|
|
|
return new HeaderOption(temp); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<String> headerList = tbsScheduleItemMapper.getItemNames(year); |
|
|
|
|
|
|
|
|
|
|
|
List<List<Map<String,Object>>> list = new ArrayList<>(); |
|
|
|
if(headerList.size()==0){ |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
if(type.equals(TbsCenterType.saleRegion.name())){ |
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookRegion(); |
|
|
|
//
|
|
|
|
// List<BmsRegionTreeVo> regionList = bmsRegionService.getTree(false);
|
|
|
|
// List<List<Map<String,Object>>> regionDataList = regionList.stream().map(a->
|
|
|
|
// itemList.stream().filter(i->i.get("成本中心编码").toString().startsWith(a.getCode())).collect(Collectors.toList())
|
|
|
|
// ).filter(p->p.size()!=0).collect(Collectors.toList());
|
|
|
|
//
|
|
|
|
// headerOptions = headerOptions.stream().map(a->{
|
|
|
|
// if(a.getName().startsWith("成本中心")){
|
|
|
|
//
|
|
|
|
// }else{
|
|
|
|
//// a.setIsSum(true);
|
|
|
|
// a.setDecimalLength(2);
|
|
|
|
// a.setAlign("right");
|
|
|
|
// }
|
|
|
|
// return a;
|
|
|
|
// }).collect(Collectors.toList());
|
|
|
|
//
|
|
|
|
// list = regionDataList;
|
|
|
|
list.add(itemList); |
|
|
|
List<BmsRegion> bmsRegionList = bmsRegionService.list(); |
|
|
|
Map<String,BmsRegion> bmsRegionMap = bmsRegionList.stream().collect(Collectors.toMap(BmsRegion::getId, Function.identity())); |
|
|
|
|
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookRegion(year); |
|
|
|
|
|
|
|
Map<String,List<BirCenterCostRateMain>> mainList = itemList.stream().map(i->{ |
|
|
|
BirCenterCostRateMain main = new BirCenterCostRateMain(); |
|
|
|
|
|
|
|
BmsRegion center2 = bmsRegionMap.get(i.get("center_id")); |
|
|
|
if(center2==null){ |
|
|
|
return main; |
|
|
|
}else{ |
|
|
|
main.setCenter2(new TbsCenterDto(center2)); |
|
|
|
} |
|
|
|
|
|
|
|
BmsRegion center1 = bmsRegionMap.get(center2.getPid()); |
|
|
|
if(center1==null){ |
|
|
|
main.setCenter1(new TbsCenterDto(center2)); |
|
|
|
}else{ |
|
|
|
main.setCenter1(new TbsCenterDto(center1)); |
|
|
|
} |
|
|
|
|
|
|
|
List<BirCenterCostRateItem> seasonList = headerList.stream().map(a-> new BirCenterCostRateItem(i,"【"+a+"】")).collect(Collectors.toList()); |
|
|
|
main.setSeasonList(seasonList); |
|
|
|
main.setYearInfo(new BirCenterCostRateItem(i,"【全年】")); |
|
|
|
|
|
|
|
return main; |
|
|
|
}).filter(a->a.getCenter2()!=null).collect(Collectors.groupingBy(a->a.getCenter1().getId())); |
|
|
|
|
|
|
|
itemDataList.addAll(mainList.values()); |
|
|
|
}else if(type.equals(TbsCenterType.bizRegion.name())){ |
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookBizRegion(); |
|
|
|
list.add(itemList); |
|
|
|
List<BmsRegion2> bmsRegionList = bmsRegion2Service.list(); |
|
|
|
Map<String,BmsRegion2> bmsRegionMap = bmsRegionList.stream().collect(Collectors.toMap(BmsRegion2::getId, Function.identity())); |
|
|
|
|
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookBizRegion(year); |
|
|
|
|
|
|
|
Map<String,List<BirCenterCostRateMain>> mainList = itemList.stream().map(i->{ |
|
|
|
BirCenterCostRateMain main = new BirCenterCostRateMain(); |
|
|
|
|
|
|
|
BmsRegion2 center2 = bmsRegionMap.get(i.get("center_id")); |
|
|
|
if(center2==null){ |
|
|
|
return main; |
|
|
|
}else{ |
|
|
|
main.setCenter2(new TbsCenterDto(center2)); |
|
|
|
main.setCenter1(new TbsCenterDto(center2)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<BirCenterCostRateItem> seasonList = headerList.stream().map(a-> new BirCenterCostRateItem(i,"【"+a+"】")).collect(Collectors.toList()); |
|
|
|
main.setSeasonList(seasonList); |
|
|
|
main.setYearInfo(new BirCenterCostRateItem(i,"【全年】")); |
|
|
|
|
|
|
|
return main; |
|
|
|
}).filter(a->a.getCenter2()!=null).collect(Collectors.groupingBy(a->a.getCenter1().getId())); |
|
|
|
|
|
|
|
itemDataList.addAll(mainList.values()); |
|
|
|
}else if(type.equals(TbsCenterType.customer.name())){ |
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookCustomer(); |
|
|
|
list.add(itemList); |
|
|
|
|
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookCustomer(year); |
|
|
|
List<String> supperIds = itemList.stream().map(i->i.get("center_id").toString()).collect(Collectors.toList()); |
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.in(BmsSupplier::getId,supperIds); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierService.list(lqw); |
|
|
|
Map<String,BmsSupplier> supplierMap = supplierList.stream().collect(Collectors.toMap(BmsSupplier::getId, Function.identity())); |
|
|
|
|
|
|
|
|
|
|
|
List<BirCenterCostRateMain> mainList = itemList.stream().map(i->{ |
|
|
|
BirCenterCostRateMain main = new BirCenterCostRateMain(); |
|
|
|
|
|
|
|
BmsSupplier supplier = supplierMap.get(i.get("center_id")); |
|
|
|
if(supplier==null){ |
|
|
|
return main; |
|
|
|
}else{ |
|
|
|
main.setCenter2(new TbsCenterDto(supplier)); |
|
|
|
main.setCenter1(new TbsCenterDto(supplier)); |
|
|
|
} |
|
|
|
|
|
|
|
List<BirCenterCostRateItem> seasonList = headerList.stream().map(a-> new BirCenterCostRateItem(i,"【"+a+"】")).collect(Collectors.toList()); |
|
|
|
main.setSeasonList(seasonList); |
|
|
|
main.setYearInfo(new BirCenterCostRateItem(i,"【全年】")); |
|
|
|
|
|
|
|
return main; |
|
|
|
}).filter(a->a.getCenter2()!=null).collect(Collectors.toList()); |
|
|
|
itemDataList.add(mainList); |
|
|
|
|
|
|
|
}else if(type.equals(TbsCenterType.center.name())){ |
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookCenter(); |
|
|
|
list.add(itemList); |
|
|
|
List<Map<String,Object>> itemList = birReportAccountBookMapper.reportAccountBookCenter(year); |
|
|
|
List<String> centerIds = itemList.stream().map(i->i.get("center_id").toString()).collect(Collectors.toList()); |
|
|
|
|
|
|
|
LambdaQueryWrapper<BmsCostCenter> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.in(BmsCostCenter::getId,centerIds); |
|
|
|
List<BmsCostCenter> bmsCostCenterList = bmsCostCenterService.list(lqw); |
|
|
|
Map<String,BmsCostCenter> bmsCostCenterMap = bmsCostCenterList.stream().collect(Collectors.toMap(a->a.getId().toString(), Function.identity())); |
|
|
|
|
|
|
|
List<BirCenterCostRateMain> mainList = itemList.stream().map(i->{ |
|
|
|
BirCenterCostRateMain main = new BirCenterCostRateMain(); |
|
|
|
|
|
|
|
BmsCostCenter costCenter = bmsCostCenterMap.get(i.get("center_id")); |
|
|
|
if(costCenter==null){ |
|
|
|
return main; |
|
|
|
}else{ |
|
|
|
main.setCenter2(new TbsCenterDto(costCenter)); |
|
|
|
main.setCenter1(new TbsCenterDto(costCenter)); |
|
|
|
} |
|
|
|
|
|
|
|
List<BirCenterCostRateItem> seasonList = headerList.stream().map(a-> new BirCenterCostRateItem(i,"【"+a+"】")).collect(Collectors.toList()); |
|
|
|
main.setSeasonList(seasonList); |
|
|
|
main.setYearInfo(new BirCenterCostRateItem(i,"【全年】")); |
|
|
|
|
|
|
|
return main; |
|
|
|
}).filter(a->a.getCenter2()!=null).collect(Collectors.toList()); |
|
|
|
itemDataList.add(mainList); |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetPlan> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudgetPlan::getBudgetYear,"2023"); |
|
|
|
lqw.eq(TbsBudgetPlan::getBudgetYear,year); |
|
|
|
TbsBudgetPlan tbsBudgetPlan = tbsBudgetPlanService.getOne(lqw); |
|
|
|
|
|
|
|
BudgetPlanVo budgetPlanVo = new BudgetPlanVo(); |
|
|
@ -120,8 +208,11 @@ public class BirReportAccountBookServiceImpl implements BirReportAccountBookServ |
|
|
|
BigDecimal usedAmount = tbsBudgetLogMapper.countUsedBudgetAmount(); |
|
|
|
budgetPlanVo.setUsedAmout(usedAmount); |
|
|
|
|
|
|
|
vo.setHeaderList(headerOptions); |
|
|
|
vo.setItemList(list); |
|
|
|
BigDecimal realSaleAmount = erpDispatchDataMapper.querySumCostAmt(Integer.parseInt(year+"01"),Integer.parseInt(year+"12"),null); |
|
|
|
budgetPlanVo.setRealSaleAmount(realSaleAmount); |
|
|
|
|
|
|
|
vo.setHeaderList(headerList); |
|
|
|
vo.setItemList(itemDataList); |
|
|
|
vo.setBudgetPlanVo(budgetPlanVo); |
|
|
|
return vo; |
|
|
|
} |
|
|
|