| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package com.ydtech.modules.admin.service.impl;
- import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto;
- import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisQueryDto;
- import com.ydtech.modules.admin.service.ProfitAnalysisService;
- import com.ydtech.modules.admin.utils.SliceUpDateUtil;
- import com.ydtech.modules.console.dao.ProfitAnalysisMapper;
- import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
- import com.ydtech.modules.inv.dao.InvAccountMapper;
- import com.ydtech.modules.inv.model.InvAccount;
- import com.ydtech.modules.inv.model.InvAccountCardVo;
- import com.ydtech.modules.inv.model.InvAccountExpenses;
- import com.ydtech.utils.BigDecimalUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @version
- * @author: hxl
- * @Date: 2024/7/1 11:36
- * @Description: 控制台-运营数据
- */
- @Service
- public class ProfitAnalysisServiceImpl implements ProfitAnalysisService {
- @Autowired
- private InvAccountMapper invAccountMapper;
- @Autowired
- private InsPlyIncomeMapper insPlyIncomeMapper;
- @Autowired
- private ProfitAnalysisMapper profitAnalysisMapper;
- /**
- * @version
- * @author: hxl
- * @Date: 2024/7/31 17:42
- * @Description: 查询利润数据
- */
- @Override
- public List<ProfitAnalysisDto> queryPage(ProfitAnalysisQueryDto profitAnalysisQueryDto) {
- HashMap<String, String> dateMapByType = getDateMapByType(profitAnalysisQueryDto.getDateType(), profitAnalysisQueryDto.getYear());
- profitAnalysisQueryDto.setBeginDate(dateMapByType.get("startDate"));
- profitAnalysisQueryDto.setEndDate(dateMapByType.get("endDate"));
- List<ProfitAnalysisDto> list = insPlyIncomeMapper.queryPage(profitAnalysisQueryDto);
- return list;
- }
- /**
- * @version
- * @author: whp
- * @Date: 2024/8/16 15:35
- * @Description: 查询利润分析统计
- */
- @Override
- public List<ProfitAnalysisDto> getProfitAnalysisQueryList(ProfitAnalysisQueryDto profitAnalysisQueryDto) {
- HashMap<String, String> dateMapByType = getDateMapByType(profitAnalysisQueryDto.getDateType(), profitAnalysisQueryDto.getYear());
- profitAnalysisQueryDto.setBeginDate(dateMapByType.get("startDate"));
- profitAnalysisQueryDto.setEndDate(dateMapByType.get("endDate"));
- List<ProfitAnalysisDto> profitAnalysisQueryList = insPlyIncomeMapper.getProfitAnalysisQueryList(profitAnalysisQueryDto);
- if(!profitAnalysisQueryList.isEmpty()){
- for (ProfitAnalysisDto profitAnalysisDto : profitAnalysisQueryList) {
- BigDecimal variableCost = BigDecimal.ZERO;
- String yearAndMonth = profitAnalysisDto.getYearAndMonth();
- profitAnalysisQueryDto.setYearAndMonth(yearAndMonth);
- List<ProfitAnalysisDto> profitAnalysisDto1 = insPlyIncomeMapper.changeAmount(profitAnalysisQueryDto);
- for (ProfitAnalysisDto analysisDto : profitAnalysisDto1) {
- String outCardNum = analysisDto.getOutCardNum();
- String enterCardNum = analysisDto.getEnterCardNum();
- InvAccountCardVo outAccount = invAccountMapper.getByCarNumber(outCardNum);
- InvAccountCardVo enterAccount = invAccountMapper.getByCarNumber(enterCardNum);
- if(StringUtils.isNotEmpty(outAccount.getOuterFlag()) && StringUtils.isNotEmpty(enterAccount.getOuterFlag())){
- if(!enterAccount.getOuterFlag().equals(outAccount.getOuterFlag())){
- variableCost=variableCost.add(analysisDto.getApplyAmount());
- }
- }
- }
- profitAnalysisDto.setVariableCost(variableCost);
- }
- }
- return profitAnalysisQueryList;
- }
- @Override
- public List<ProfitAnalysisDto> getProfitAnalysisQueryDetailsList(ProfitAnalysisQueryDto profitAnalysisQueryDto) {
- List<ProfitAnalysisDto> resultList =new ArrayList<>();
- if (StringUtils.isNotEmpty(profitAnalysisQueryDto.getExpensesType()) && "3".equals(profitAnalysisQueryDto.getExpensesType())) {
- List<ProfitAnalysisDto> profitAnalysisDtos = profitAnalysisMapper.selectAccountExpenses(profitAnalysisQueryDto);
- resultList.addAll(profitAnalysisDtos) ;
- List<ProfitAnalysisDto> addVariableCost = new ArrayList<>();
- List<ProfitAnalysisDto> profitAnalysisDto1 = insPlyIncomeMapper.changeAmount(profitAnalysisQueryDto);
- for (ProfitAnalysisDto analysisDto : profitAnalysisDto1) {
- String outCardNum = analysisDto.getOutCardNum();
- String enterCardNum = analysisDto.getEnterCardNum();
- InvAccountCardVo outAccount = invAccountMapper.getByCarNumber(outCardNum);
- InvAccountCardVo enterAccount = invAccountMapper.getByCarNumber(enterCardNum);
- if (StringUtils.isNotEmpty(outAccount.getOuterFlag()) && StringUtils.isNotEmpty(enterAccount.getOuterFlag())) {
- if (!enterAccount.getOuterFlag().equals(outAccount.getOuterFlag())) {
- addVariableCost.add(analysisDto);
- }
- }
- }
- Map<String, BigDecimal> profitAnalysisDtoMap = addVariableCost.stream()
- .collect(Collectors.toMap(
- ProfitAnalysisDto::getExpensesId, // keyMapper,用于提取键(expensesId)
- ProfitAnalysisDto::getApplyAmount, // valueMapper,用于提取初始值(applyAmount)
- BigDecimal::add // mergeFunction,用于处理键冲突(相加 applyAmount)
- ));
- for (ProfitAnalysisDto profitAnalysisDto : resultList) {
- String expensesId = profitAnalysisDto.getExpensesId();
- if (profitAnalysisDtoMap.containsKey(expensesId)) {
- BigDecimal bigDecimal = profitAnalysisDtoMap.get(expensesId);
- profitAnalysisDto.setApplyAmount(bigDecimal);
- }
- }
- }else {
- resultList.addAll(profitAnalysisMapper.getAllAccountExpenses(profitAnalysisQueryDto));
- }
- return getTree(resultList);
- }
- /**
- * 组装树形结构结果集方法
- */
- public List<ProfitAnalysisDto> getTree(List<ProfitAnalysisDto> list){
- return list.stream().filter(accountExpenses -> accountExpenses.getParentId().equals("0"))
- .peek(accountExpenses -> accountExpenses.setChildren(getChildren(accountExpenses,list))).collect(Collectors.toList());
- }
- public List<ProfitAnalysisDto> getChildren(ProfitAnalysisDto user,List<ProfitAnalysisDto> userList){
- return userList.stream().filter(u -> Objects.equals(u.getParentId(),user.getExpensesId())).map(
- u -> {
- u.setChildren(getChildren(u,userList));
- return u;
- }
- ).collect(Collectors.toList());
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/19 11:57
- * @Description: 通过时间类型判断
- */
- private static HashMap<String,String> getDateMapByType(String type, String year) {
- HashMap<String,String> map =new HashMap<>();
- String startDateStr="";
- String endDateStr="";
- if(StringUtils.isBlank(year) && StringUtils.isBlank(type)){
- Calendar cale = Calendar.getInstance();
- int yearNow = cale.get(Calendar.YEAR);
- startDateStr= SliceUpDateUtil.getYearBeginDateStr(yearNow)+" 00:00:00";
- endDateStr= SliceUpDateUtil.getYearEndDateStr(yearNow)+" 23:59:59";
- }else{
- if(StringUtils.isNotBlank(year)){
- startDateStr= SliceUpDateUtil.getYearBeginDateStr(Integer.parseInt(year))+" 00:00:00";
- endDateStr= SliceUpDateUtil.getYearEndDateStr(Integer.parseInt(year))+" 23:59:59";
- }else{
- if(StringUtils.isNotBlank(type)){
- if("1".equals(type)){
- // 一月内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),2)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else if("2".equals(type)){
- // 三月内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),3)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else if("3".equals(type)){
- // 近半年
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),4)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }
- }
- }
- }
- map.put("startDate",startDateStr);
- map.put("endDate",endDateStr);
- return map;
- }
- }
|