package com.by4cloud.platformx.business.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.by4cloud.platformx.business.dto.ZBJTStatisticDTO; import com.by4cloud.platformx.business.entity.AnnualPlan; import com.by4cloud.platformx.business.entity.AnnualPlanKey; import com.by4cloud.platformx.business.entity.AnnualTarget; import com.by4cloud.platformx.business.entity.BipDict; import com.by4cloud.platformx.business.mapper.*; import com.by4cloud.platformx.business.service.ZBJTStatisticService; import com.by4cloud.platformx.business.vo.*; import com.by4cloud.platformx.common.core.util.R; import lombok.RequiredArgsConstructor; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class ZBJTStatisticServiceImpl implements ZBJTStatisticService { private final ContractMapper contractMapper; private final PaymentSlipMapper paymentSlipMapper; private final ContractInvoiceMapper contractInvoiceMapper; private final AnnualPlanMapper annualPlanMapper; private final AnnualPlanKeyMapper annualPlanKeyMapper; private final AnnualTargetMapper annualTargetMapper; private final ContractSubjectMatterMapper contractSubjectMatterMapper; private final ContractOutBoundMapper contractOutBoundMapper; private final BipDictMapper bipDictMapper; private final PaymentReceiveMapper paymentReceiveMapper; private final HistoryOverdueMapper historyOverdueMapper; @Override public R zyxszbwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); HomeZbjtVo hk = paymentSlipMapper.homeZbjtYearAndMon(monstart,monend,yearstart,yearend, monstartLastYear,monendLastYear,yearstartLastYear,yearendLastYear); list = handlezBJTVo("货款回收",list,hk,queryDTO.getYearMonth().substring(0,4), queryDTO.getYearMonth().substring(5), "3"); HomeZbjtVo kp = contractInvoiceMapper.homeZbjtYearAndMon(monstart,monend,yearstart,yearend); list = handlezBJTVo("销售收入",list,kp,queryDTO.getYearMonth().substring(0,4), queryDTO.getYearMonth().substring(5), "2"); HomeZbjtVo htqd = contractMapper.homeZbjtYearAndMon(monstart,monend,yearstart,yearend); list = handlezBJTVo("新增合同",list,htqd,queryDTO.getYearMonth().substring(0,4), queryDTO.getYearMonth().substring(5), "1"); return R.ok(list); } private List handlezBJTVo(String xm,List list, HomeZbjtVo kp,String curYear,String curMonth,String planType) { ZyxszbwcqkVo vosmj = new ZyxszbwcqkVo(); vosmj.setXm(xm); vosmj.setDw("石煤机"); ZyxszbwcqkVo vosgb = new ZyxszbwcqkVo(); vosgb.setXm(xm); vosgb.setDw("石工泵"); ZyxszbwcqkVo vojxc = new ZyxszbwcqkVo(); vojxc.setXm(xm); vojxc.setDw("邢台厂"); ZyxszbwcqkVo votf = new ZyxszbwcqkVo(); votf.setXm(xm); votf.setDw("通方厂"); ZyxszbwcqkVo voymj = new ZyxszbwcqkVo(); voymj.setXm(xm); voymj.setDw("一煤机"); ZyxszbwcqkVo vozb = new ZyxszbwcqkVo(); vozb.setXm(xm); vozb.setDw("装备集团"); List compIds = new ArrayList<>(); compIds.add(2089995177814495234L); compIds.add(2089996921978040321L); compIds.add(2089997578009128962L); compIds.add(2101966257365045249L); //装备 vosmj.setDrwc(kp.safeAddAll(kp.getSmjbr(),kp.getSgbbr(),kp.getJxcbr(),kp.getTfbr(),null)); AnnualPlanTotalVo planListZB = annualPlanMapper.selectPlanYear(curYear, planType); if (ObjUtil.isNotNull(planListZB)) { AnnualPlanTotalVo planzb = BeanUtil.copyProperties(planListZB, AnnualPlanTotalVo.class); BigDecimal curMonAmount = planzb.getMonthAmount(curMonth); vozb.setDyjh(curMonAmount); vozb.setDywc(kp.safeAddAll(kp.getSmjby(),kp.getSgbby(),kp.getJxcby(),kp.getTfby(),null)); if (vozb.getDyjh().compareTo(new BigDecimal("0")) > 0) { vozb.setYjhwc(vozb.getDywc().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } BigDecimal qnby = kp.safeAddAll(kp.getSmjqnby(),kp.getSgbqnby(),kp.getJxcqnby(),kp.getTfqnby(),null); BigDecimal qnbytb = vozb.getDywc().subtract(qnby); if (qnby.compareTo(new BigDecimal("0"))>0){ BigDecimal qnbytqb = qnbytb.divide(qnby,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vozb.setYtqb(qnbytqb.setScale(2,RoundingMode.HALF_UP)+"%"); } vozb.setNdjh(planzb.getTotalAmount()); BigDecimal yearAmount = planzb.getTotalAmount(); vozb.setLjjh(planzb.getToMonTotalAmount(curMonth)); vozb.setLjwc(kp.safeAddAll(kp.getSmjbn(),kp.getSgbbn(),kp.getJxcbn(),kp.getTfbn(),null)); if (vozb.getLjjh().compareTo(new BigDecimal("0")) > 0) { vozb.setNjhwc(vozb.getLjwc().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } BigDecimal qnbn = kp.safeAddAll(kp.getSmjqnbn(),kp.getSgbqnbn(),kp.getJxcqnbn(),kp.getTfqnbn(),null); BigDecimal qnbntb = vozb.getLjwc().subtract(qnby); if (qnbn.compareTo(new BigDecimal("0"))>0){ BigDecimal qnbntqb = qnbntb.divide(qnbn,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vozb.setYtqb(qnbntqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } //石煤机收入 AnnualPlan planListSMJ = annualPlanMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlan::getPlanYear, curYear).eq(AnnualPlan::getPlanType, planType) .in(AnnualPlan::getCompId, compIds).last("limit 1")); vosmj.setDrwc(kp.getSmjbr()); if (ObjUtil.isNotNull(planListSMJ)) { AnnualPlanTotalVo plansmj = BeanUtil.copyProperties(planListSMJ, AnnualPlanTotalVo.class); BigDecimal curMonAmount = plansmj.getMonthAmount(curMonth); vosmj.setDyjh(curMonAmount); if (ObjUtil.isNotNull(kp.getSmjby()) && kp.getSmjby().compareTo(new BigDecimal("0")) > 0) { vosmj.setDywc(kp.getSmjby()); vosmj.setYjhwc(kp.getSmjby().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnby())&& kp.getSmjqnby().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vosmj.getDywc().subtract(kp.getSmjqnby()); BigDecimal tqb = tb.divide(kp.getSmjqnby(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vosmj.setYtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } vosmj.setNdjh(plansmj.getTotalAmount()); BigDecimal yearAmount = plansmj.getTotalAmount(); vosmj.setLjjh(plansmj.getToMonTotalAmount(curMonth)); vosmj.setLjwc(kp.getSmjbn()); if (ObjUtil.isNotNull(kp.getSmjbn()) && kp.getSmjbn().compareTo(new BigDecimal("0")) > 0) { vosmj.setNjhwc(kp.getSmjbn().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnbn())&& kp.getSmjqnbn().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vosmj.getLjwc().subtract(kp.getSmjqnbn()); BigDecimal tqb = tb.divide(kp.getSmjqnbn(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vosmj.setNtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } //石工泵收入 vosgb.setDrwc(kp.getSgbbr()); AnnualPlan planListSRSGB = annualPlanMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlan::getPlanYear, curYear).eq(AnnualPlan::getPlanType, planType) .eq(AnnualPlan::getCompId, 2056556196124250113L).last("limit 1")); if (ObjUtil.isNotNull(planListSRSGB)) { AnnualPlanTotalVo plansgb = BeanUtil.copyProperties(planListSRSGB, AnnualPlanTotalVo.class); BigDecimal curMonAmount = plansgb.getMonthAmount(curMonth); vosgb.setDyjh(curMonAmount); if (ObjUtil.isNotNull(kp.getSgbby()) && kp.getSgbby().compareTo(new BigDecimal("0")) > 0) { vosgb.setDywc(kp.getSgbby()); vosgb.setYjhwc(kp.getSgbby().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnby())&& kp.getSmjqnby().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vosgb.getDywc().subtract(kp.getSmjqnby()); BigDecimal tqb = tb.divide(kp.getSmjqnby(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vosgb.setYtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } vosgb.setNdjh(plansgb.getTotalAmount()); BigDecimal yearAmount = plansgb.getTotalAmount(); vosgb.setLjjh(plansgb.getToMonTotalAmount(curMonth)); vosgb.setLjwc(kp.getSgbbn()); if (ObjUtil.isNotNull(kp.getSgbbn()) && kp.getSgbbn().compareTo(new BigDecimal("0")) > 0) { vosgb.setNjhwc(kp.getSgbbn().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnbn())&& kp.getSmjqnbn().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vosgb.getLjwc().subtract(kp.getSmjqnbn()); BigDecimal tqb = tb.divide(kp.getSmjqnbn(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vosgb.setNtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } //通方公司收入 votf.setDrwc(kp.getTfbr()); AnnualPlan planListSRTFGS = annualPlanMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlan::getPlanYear, curYear).eq(AnnualPlan::getPlanType, planType) .eq(AnnualPlan::getCompId, 2056556421857497090L).last("limit 1")); if (ObjUtil.isNotNull(planListSRTFGS)) { AnnualPlanTotalVo plantf = BeanUtil.copyProperties(planListSRTFGS, AnnualPlanTotalVo.class); BigDecimal curMonAmount = plantf.getMonthAmount(curMonth); votf.setDyjh(curMonAmount); if (ObjUtil.isNotNull(kp.getTfby()) && kp.getTfby().compareTo(new BigDecimal("0")) > 0) { votf.setDywc(kp.getTfby()); votf.setYjhwc(kp.getTfby().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnby())&& kp.getSmjqnby().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = votf.getDywc().subtract(kp.getSmjqnby()); BigDecimal tqb = tb.divide(kp.getSmjqnby(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); votf.setYtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } votf.setNdjh(plantf.getTotalAmount()); BigDecimal yearAmount = plantf.getTotalAmount(); votf.setLjjh(plantf.getToMonTotalAmount(curMonth)); votf.setLjwc(kp.getTfbn()); if (ObjUtil.isNotNull(kp.getTfbn()) && kp.getTfbn().compareTo(new BigDecimal("0")) > 0) { votf.setNjhwc(kp.getTfbn().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnbn())&& kp.getSmjqnbn().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = votf.getLjwc().subtract(kp.getSmjqnbn()); BigDecimal tqb = tb.divide(kp.getSmjqnbn(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); votf.setNtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } //机械厂收入 vojxc.setDrwc(kp.getJxcbr()); AnnualPlan planListSRJXC = annualPlanMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlan::getPlanYear, curYear).eq(AnnualPlan::getPlanType, planType) .eq(AnnualPlan::getCompId, 2056556317461270529L).last("limit 1")); if (ObjUtil.isNotNull(planListSRJXC)) { AnnualPlanTotalVo planjxc = BeanUtil.copyProperties(planListSRJXC, AnnualPlanTotalVo.class); BigDecimal curMonAmount = planjxc.getMonthAmount(curMonth); vojxc.setDyjh(curMonAmount); if (ObjUtil.isNotNull(kp.getJxcby()) && kp.getJxcby().compareTo(new BigDecimal("0")) > 0) { vojxc.setDywc(kp.getJxcby()); vojxc.setYjhwc(kp.getJxcby().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnby())&& kp.getSmjqnby().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vojxc.getDywc().subtract(kp.getSmjqnby()); BigDecimal tqb = tb.divide(kp.getSmjqnby(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vojxc.setYtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } vojxc.setNdjh(planjxc.getTotalAmount()); BigDecimal yearAmount = planjxc.getTotalAmount(); vojxc.setLjjh(planjxc.getToMonTotalAmount(curMonth)); vojxc.setLjwc(kp.getJxcbn()); if (ObjUtil.isNotNull(kp.getJxcbn()) && kp.getJxcbn().compareTo(new BigDecimal("0")) > 0) { vojxc.setNjhwc(kp.getJxcbn().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnbn())&& kp.getSmjqnbn().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = vojxc.getLjwc().subtract(kp.getSmjqnbn()); BigDecimal tqb = tb.divide(kp.getSmjqnbn(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vojxc.setNtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } //一煤机收入 voymj.setDrwc(kp.getYmjbr()); AnnualPlan planListHYMJ = annualPlanMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlan::getPlanYear, curYear).eq(AnnualPlan::getPlanType, planType) .eq(AnnualPlan::getCompId, 2056556535640576002L).last("limit 1")); if (ObjUtil.isNotNull(planListHYMJ)) { AnnualPlanTotalVo planymj = BeanUtil.copyProperties(planListHYMJ, AnnualPlanTotalVo.class); BigDecimal curMonAmount = planymj.getMonthAmount(curMonth); voymj.setDyjh(curMonAmount); if (ObjUtil.isNotNull(kp.getYmjby()) && kp.getYmjby().compareTo(new BigDecimal("0")) > 0) { voymj.setDywc(kp.getYmjby()); voymj.setYjhwc(kp.getYmjby().divide(curMonAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnby())&& kp.getSmjqnby().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = voymj.getDywc().subtract(kp.getSmjqnby()); BigDecimal tqb = tb.divide(kp.getSmjqnby(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); voymj.setYtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } voymj.setNdjh(planymj.getTotalAmount()); BigDecimal yearAmount = planymj.getTotalAmount(); voymj.setLjjh(planymj.getToMonTotalAmount(curMonth)); voymj.setLjwc(kp.getYmjbn()); if (ObjUtil.isNotNull(kp.getYmjbn()) && kp.getYmjbn().compareTo(new BigDecimal("0")) > 0) { voymj.setNjhwc(kp.getYmjbn().divide(yearAmount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } if (ObjUtil.isNotNull(kp.getSmjqnbn())&& kp.getSmjqnbn().compareTo(new BigDecimal("0")) > 0){ BigDecimal tb = voymj.getLjwc().subtract(kp.getSmjqnbn()); BigDecimal tqb = tb.divide(kp.getSmjqnbn(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); voymj.setNtqb(tqb.setScale(2,RoundingMode.HALF_UP)+"%"); } } list.add(vosmj); list.add(vosgb); list.add(vojxc); list.add(votf); list.add(voymj); list.add(vozb); return list; } @Override public R yszkwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastMon = DateUtil.offsetMonth(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastMon = DateUtil.offsetMonth(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(Integer.valueOf(queryDTO.getYearMonth().substring(0,4))-1+"-12-01 00:00:00"); Date yearend = DateUtil.parseDateTime(Integer.valueOf(queryDTO.getYearMonth().substring(0,4))-1+"-12-31 23:59:59"); List list = paymentReceiveMapper.yszkwcqk(monstart,monend,yearstart,yearend,monstartLastMon,monendLastMon); if(CollUtil.isNotEmpty(list)){ list.stream().forEach(item->{ item.setQctq(item.getYsdy().subtract(item.getYsqc())); item.setSyhb(item.getYsdy().subtract(item.getYssy())); }); } YszkwcqkVo jtys = new YszkwcqkVo(); jtys.setDw("集团"); jtys.setLb("应收"); jtys.setYsdy(list.stream().filter(item->item.getLb().equals("应收")).map(YszkwcqkVo::getYsdy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtys.setYsqc(list.stream().filter(item->item.getLb().equals("应收")).map(YszkwcqkVo::getYsqc).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtys.setYssy(list.stream().filter(item->item.getLb().equals("应收")).map(YszkwcqkVo::getYssy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtys.setQctq(jtys.getYsdy().subtract(jtys.getYsqc())); jtys.setSyhb(jtys.getYsdy().subtract(jtys.getYssy())); YszkwcqkVo jtsx = new YszkwcqkVo(); jtsx.setDw("集团"); jtsx.setLb("赊销"); jtsx.setYsdy(list.stream().filter(item->item.getLb().equals("赊销")).map(YszkwcqkVo::getYsdy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtsx.setYsqc(list.stream().filter(item->item.getLb().equals("赊销")).map(YszkwcqkVo::getYsqc).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtsx.setYssy(list.stream().filter(item->item.getLb().equals("赊销")).map(YszkwcqkVo::getYssy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtsx.setQctq(jtys.getYsdy().subtract(jtys.getYsqc())); jtsx.setSyhb(jtys.getYsdy().subtract(jtys.getYssy())); YszkwcqkVo jtxj = new YszkwcqkVo(); jtxj.setDw("集团"); jtxj.setLb("小计"); jtxj.setYsdy(list.stream().filter(item->item.getLb().equals("小计")).map(YszkwcqkVo::getYsdy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtxj.setYsqc(list.stream().filter(item->item.getLb().equals("小计")).map(YszkwcqkVo::getYsqc).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtxj.setYssy(list.stream().filter(item->item.getLb().equals("小计")).map(YszkwcqkVo::getYssy).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jtxj.setQctq(jtys.getYsdy().subtract(jtys.getYsqc())); jtxj.setSyhb(jtys.getYsdy().subtract(jtys.getYssy())); list.add(jtys); list.add(jtsx); list.add(jtxj); return R.ok(list); } @Override public R gcpbkwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); //新增合同 List itemVoListMon = contractSubjectMatterMapper.gcpbkwcqk(monstart,monend); List itemVoListMonLastYear = contractSubjectMatterMapper.gcpbkwcqk(monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListMon)){ itemVoListMon.stream().forEach(item->{ GcpbkwcqkVo vo = new GcpbkwcqkVo(); vo.setXm("新增合同"); vo.setBkmc(item.getBkmc()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonLastYear)){ itemVoListMonLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setYtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } }); } list.add(vo); }); } List itemVoListYear = contractSubjectMatterMapper.gcpbkwcqk(yearstart,yearend); List itemVoListYearLastYear = contractSubjectMatterMapper.gcpbkwcqk(yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYear)){ BigDecimal ljzh = itemVoListYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add); for (GcpbkwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYear ) { if (StrUtil.equals(vo.getBkmc(),itemVo.getBkmc())&&StrUtil.equals(vo.getXm(),"新增合同")){ vo.setLjwc(itemVo.getWc()); if (ljzh.compareTo(new BigDecimal("0"))>0){ BigDecimal zb = vo.getLjwc().divide(ljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setBnzb(zb.setScale(2,RoundingMode.HALF_UP)+"%"); } } if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ BigDecimal qnljzh = itemVoListYearLastYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add); itemVoListYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&StrUtil.equals(vo.getXm(),"新增合同")&& item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setNtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } if (qnljzh.compareTo(new BigDecimal("0"))>0){ BigDecimal qnzb = item1.getWc().divide(qnljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); if (StrUtil.isNotBlank(vo.getBnzb())){ BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0,vo.getBnzb().length()-1)); vo.setZtqb(bnzb.subtract(qnzb)+"%"); } } }); } } } } //销售收入 List itemVoSRListMon = contractOutBoundMapper.gcpbkwcqk(monstart,monend); List itemVoListSRMonLastYear = contractOutBoundMapper.gcpbkwcqk(monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoSRListMon)){ itemVoSRListMon.stream().forEach(item->{ GcpbkwcqkVo vo = new GcpbkwcqkVo(); vo.setXm("销售收入"); vo.setBkmc(item.getBkmc()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListSRMonLastYear)){ itemVoListSRMonLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setYtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } }); } list.add(vo); }); } List itemVoListSRYear = contractOutBoundMapper.gcpbkwcqk(yearstart,yearend); List itemVoListSRYearLastYear = contractOutBoundMapper.gcpbkwcqk(yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListSRYear)){ BigDecimal ljzh = itemVoListSRYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add); for (GcpbkwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListSRYear ) { if (StrUtil.equals(vo.getBkmc(),itemVo.getBkmc())&&StrUtil.equals(vo.getXm(),"销售收入")){ vo.setLjwc(itemVo.getWc()); if (ljzh.compareTo(new BigDecimal("0"))>0){ BigDecimal zb = vo.getLjwc().divide(ljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setBnzb(zb.setScale(2,RoundingMode.HALF_UP)+"%"); } } if (CollUtil.isNotEmpty(itemVoListSRYearLastYear)){ BigDecimal qnljzh = itemVoListSRYearLastYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add); itemVoListSRYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&StrUtil.equals(vo.getXm(),"销售收入")&& item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setNtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } if (qnljzh.compareTo(new BigDecimal("0"))>0){ BigDecimal qnzb = item1.getWc().divide(qnljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); if (StrUtil.isNotBlank(vo.getBnzb())){ BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0,vo.getBnzb().length()-1)); vo.setZtqb(bnzb.subtract(qnzb)+"%"); } } }); } } } } //货款回收 List itemVoListSKMon = contractSubjectMatterMapper.gcpbkwcqkBySK(monstart,monend); List itemVoListSKMonLastYear = contractSubjectMatterMapper.gcpbkwcqkBySK(monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListSKMon)){ itemVoListSKMon.stream().forEach(item->{ GcpbkwcqkVo vo = new GcpbkwcqkVo(); vo.setXm("货款回收"); vo.setBkmc(item.getBkmc()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListSKMonLastYear)){ itemVoListSKMonLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setYtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } }); } list.add(vo); }); } List itemVoListSKYear = contractSubjectMatterMapper.gcpbkwcqkBySK(yearstart,yearend); List itemVoListSKYearLastYear = contractSubjectMatterMapper.gcpbkwcqkBySK(yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListSKYear)){ for (GcpbkwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListSKYear ) { if (StrUtil.equals(vo.getBkmc(),itemVo.getBkmc())&&StrUtil.equals(vo.getXm(),"货款回收")){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListSKYearLastYear)){ BigDecimal qnljzh = itemVoListSKYearLastYear.stream().map(item->item.getWc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add); itemVoListSKYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getBkmc(),item1.getBkmc())&&StrUtil.equals(vo.getXm(),"货款回收")&& item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getDywc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setNtqb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } if (qnljzh.compareTo(new BigDecimal("0"))>0){ BigDecimal qnzb = item1.getWc().divide(qnljzh,10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); if (StrUtil.isNotBlank(vo.getBnzb())){ BigDecimal bnzb = new BigDecimal(vo.getBnzb().substring(0,vo.getBnzb().length()-1)); vo.setZtqb(bnzb.subtract(qnzb)+"%"); } } }); } } } } return R.ok(list); } @Override public R sckfzdgzwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); //新增合同 List itemVoListMon = contractSubjectMatterMapper.sckfzdgzwcqk(monstart,monend); if (CollUtil.isNotEmpty(itemVoListMon)){ itemVoListMon.stream().forEach(item->{ SckfzdgzwcqkVo vo = new SckfzdgzwcqkVo(); vo.setDw(item.getDw()); vo.setXm(item.getXm()); vo.setDywc(item.getWc()); Long compId = null; if (StrUtil.equals(item.getDw(),"石煤机")){ compId = 2089995177814495234L; } if (StrUtil.equals(item.getDw(),"石工泵")){ compId = 2056556196124250113L; } if (StrUtil.equals(item.getDw(),"通方厂")){ compId = 2056556317461270529L; } if (StrUtil.equals(item.getDw(),"邢台厂")){ compId = 2056556421857497090L; } AnnualPlanKey plan = annualPlanKeyMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualPlanKey::getPlanYear, queryDTO.getYearMonth().substring(0,4)).eq(AnnualPlanKey::getPlanType, item.getCode()) .eq(AnnualPlanKey::getCompId, compId).last("limit 1")); if (ObjUtil.isNotNull(plan)){ vo.setDyjh(plan.getMonthAmount(queryDTO.getYearMonth().substring(5))); vo.setLjjh(plan.getToMonTotalAmount(queryDTO.getYearMonth().substring(5))); if (vo.getDyjh().compareTo(new BigDecimal("0"))>0){ vo.setYwcl(vo.getDywc().divide(vo.getDyjh(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2,RoundingMode.HALF_UP)+"%"); } } list.add(vo); }); } List itemVoListYear = contractSubjectMatterMapper.sckfzdgzwcqk(yearstart,yearend); List itemVoListYearLastYear = contractSubjectMatterMapper.sckfzdgzwcqk(yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYear)){ for (SckfzdgzwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYear ) { if (StrUtil.equals(vo.getDw(),itemVo.getDw())&&StrUtil.equals(vo.getXm(),itemVo.getXm())){ vo.setLjwc(itemVo.getWc()); if (ObjUtil.isNotNull(vo.getLjjh())&&vo.getLjjh().compareTo(new BigDecimal("0"))>0){ vo.setLjwcl(vo.getLjwc().divide(vo.getLjjh(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2,RoundingMode.HALF_UP)+"%"); } } if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ itemVoListYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getDw(),item1.getDw())&&StrUtil.equals(vo.getXm(),itemVo.getXm())&& item1.getWc().compareTo(new BigDecimal("0"))>0){ BigDecimal percent = vo.getLjwc().subtract(item1.getWc()).divide(item1.getWc(),10,RoundingMode.HALF_UP).multiply(new BigDecimal("100")); vo.setLjtb(percent.setScale(2,RoundingMode.HALF_UP)+"%"); } }); } } } } return R.ok(list); } @Override public R pjdxcksxywwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); if (true){ //配件开票 List itemVoListMon = contractInvoiceMapper.pjsxywwcqk("1",monstart,monend); List itemVoListMonrLastYear = contractInvoiceMapper.pjsxywwcqk("1",monstartLastYear,monstartLastYear); if (CollUtil.isNotEmpty(itemVoListMon)){ itemVoListMon.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ itemVoListMon.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ vo.setQnwc(itemVoListMonrLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYear = contractInvoiceMapper.pjsxywwcqk("1",yearstart,yearend); List itemVoListYearLastYear = contractInvoiceMapper.pjsxywwcqk("1",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYear)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYear ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ itemVoListYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"配件")&&StrUtil.equals(vo.getLb(),"销售收入")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ vo.setQntq(itemVoListYearLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } //配件合同 List itemVoListMonHT = contractMapper.pjsxywwcqkHT("1",monstart,monend); List itemVoListMonrHTLastYear = contractMapper.pjsxywwcqkHT("1",monstartLastYear,monstartLastYear); if (CollUtil.isNotEmpty(itemVoListMonHT)){ itemVoListMonHT.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ itemVoListMonrHTLastYear.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ vo.setQnwc(itemVoListMonrHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYearHT = contractMapper.pjsxywwcqkHT("1",yearstart,yearend); List itemVoListYearHTLastYear = contractMapper.pjsxywwcqkHT("1",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYearHT)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYearHT ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ itemVoListYearHTLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(item1.getWc())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"配件")&&StrUtil.equals(vo.getLb(),"新增合同")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ vo.setQntq(itemVoListYearHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } } if (true){ //大修开票 List itemVoListMon = contractInvoiceMapper.dxsxywwcqk("2",monstart,monend); List itemVoListMonrLastYear = contractInvoiceMapper.dxsxywwcqk("2",monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListMon)){ itemVoListMon.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ itemVoListMon.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ vo.setQnwc(itemVoListMonrLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYear = contractInvoiceMapper.dxsxywwcqk("2",yearstart,yearend); List itemVoListYearLastYear = contractInvoiceMapper.dxsxywwcqk("2",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYear)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYear ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ itemVoListYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"大修")&&StrUtil.equals(vo.getLb(),"销售收入")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ vo.setQntq(itemVoListYearLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } //大修合同 List itemVoListMonHT = contractMapper.dxsxywwcqkHT("2",monstart,monend); List itemVoListMonrHTLastYear = contractMapper.dxsxywwcqkHT("2",monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListMonHT)){ itemVoListMonHT.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ itemVoListMonrHTLastYear.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ vo.setQnwc(itemVoListMonrHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYearHT = contractMapper.dxsxywwcqkHT("2",yearstart,yearend); List itemVoListYearHTLastYear = contractMapper.dxsxywwcqkHT("2",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYearHT)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYearHT ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ itemVoListYearHTLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"大修")&&StrUtil.equals(vo.getLb(),"新增合同")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ vo.setQntq(itemVoListYearHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } } if (true){ //出口开票 List itemVoListMon = contractInvoiceMapper.cksxywwcqk("1",monstart,monend); List itemVoListMonrLastYear = contractInvoiceMapper.cksxywwcqk("1",monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListMon)){ itemVoListMon.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ itemVoListMon.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrLastYear)){ vo.setQnwc(itemVoListMonrLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYear = contractInvoiceMapper.cksxywwcqk("1",yearstart,yearend); List itemVoListYearLastYear = contractInvoiceMapper.cksxywwcqk("1",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYear)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYear ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ itemVoListYearLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"出口")&&StrUtil.equals(vo.getLb(),"销售收入")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearLastYear)){ vo.setQntq(itemVoListYearLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } //配件合同 List itemVoListMonHT = contractMapper.cksxywwcqkHT("1",monstart,monend); List itemVoListMonrHTLastYear = contractMapper.cksxywwcqkHT("1",monstartLastYear,monendLastYear); if (CollUtil.isNotEmpty(itemVoListMonHT)){ itemVoListMonHT.stream().forEach(item->{ PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(item.getYw()); vo.setLb(item.getLb()); vo.setDw(item.getDw()); vo.setDywc(item.getWc()); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ itemVoListMonrHTLastYear.stream().forEach(item1-> { if (StrUtil.equals(vo.getYw(),item1.getYw())&&StrUtil.equals(vo.getLb(),item1.getLb())&& StrUtil.equals(vo.getDw(),item1.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQnwc(item1.getWc()); vo.setYtb(vo.getDywc().subtract(item1.getWc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } }); } list.add(vo); }); PjdxcksxywwcqkVo vo = new PjdxcksxywwcqkVo(); vo.setYw(itemVoListMon.get(0).getYw()); vo.setLb(itemVoListMon.get(0).getLb()); vo.setDw("集团"); vo.setDywc(itemVoListMon.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListMonrHTLastYear)){ vo.setQnwc(itemVoListMonrHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setYtb(vo.getDywc().subtract(vo.getQnwc())); if (vo.getQnwc().compareTo(new BigDecimal("0"))>0) { vo.setYtqb(vo.getYtb().divide(vo.getQnwc(), 2, RoundingMode.HALF_UP) + "%"); } } list.add(vo); } List itemVoListYearHT = contractMapper.cksxywwcqkHT("1",yearstart,yearend); List itemVoListYearHTLastYear = contractMapper.cksxywwcqkHT("1",yearstartLastYear,yearendLastYear); if (CollUtil.isNotEmpty(list)&&CollUtil.isNotEmpty(itemVoListYearHT)){ for (PjdxcksxywwcqkVo vo:list ) { for (GcpbkwcqkItemVo itemVo:itemVoListYearHT ) { if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())){ vo.setLjwc(itemVo.getWc()); } if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ itemVoListYearHTLastYear.stream().forEach(item1->{ if (StrUtil.equals(vo.getYw(),itemVo.getYw())&&StrUtil.equals(vo.getLb(),itemVo.getLb())&& StrUtil.equals(vo.getDw(),itemVo.getDw())&&item1.getWc().compareTo(new BigDecimal("0"))>0){ vo.setQntq(item1.getWc()); vo.setLjtb(vo.getLjwc().subtract(item1.getWc())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } }); } } if (StrUtil.equals(vo.getYw(),"出口")&&StrUtil.equals(vo.getLb(),"新增合同")&& StrUtil.equals(vo.getDw(),"集团")){ vo.setLjwc(itemVoListYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); if (CollUtil.isNotEmpty(itemVoListYearHTLastYear)){ vo.setQntq(itemVoListYearHTLastYear.stream().map(GcpbkwcqkItemVo::getWc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vo.setLjtb(vo.getLjwc().subtract(vo.getQntq())); if (vo.getQntq().compareTo(new BigDecimal("0"))>0) { vo.setLjtqb(vo.getLjtb().divide(vo.getQntq(), 2, RoundingMode.HALF_UP) + "%"); } } } } } } if (CollUtil.isNotEmpty(list)){ String[] arrLb = {"销售收入", "新增合同"}; String[] arrDw = {"石煤机", "石工泵", "邢台厂", "通方厂","集团"}; for (int i = 0; i < arrLb.length; i++) { for (int j = 0; j < arrDw.length; j++) { PjdxcksxywwcqkVo vosmj = new PjdxcksxywwcqkVo(); vosmj.setYw("以上三项合计"); String lb = arrLb[i]; String dw = arrDw[j]; vosmj.setLb(lb); vosmj.setDw(dw); vosmj.setDywc(list.stream().filter(item->item.getLb().equals(lb)&&item.getDw().equals(dw)).collect(Collectors.toList()) .stream().map(item->item.getDywc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vosmj.setQnwc(list.stream().filter(item->item.getLb().equals(lb)&&item.getDw().equals(dw)).collect(Collectors.toList()) .stream().map(item->item.getQnwc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vosmj.setYtb(vosmj.getDywc().subtract(vosmj.getQnwc())); if (vosmj.getQnwc().compareTo(new BigDecimal("0"))>0){ vosmj.setYtqb(vosmj.getYtb().divide(vosmj.getQnwc(),2,RoundingMode.HALF_UP)+"%"); } vosmj.setLjwc(list.stream().filter(item->item.getLb().equals(lb)&&item.getDw().equals(dw)).collect(Collectors.toList()) .stream().map(item->item.getLjwc()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vosmj.setQntq(list.stream().filter(item->item.getLb().equals(lb)&&item.getDw().equals(dw)).collect(Collectors.toList()) .stream().map(item->item.getQntq()).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); vosmj.setLjtb(vosmj.getLjwc().subtract(vosmj.getQntq())); if (vosmj.getQntq().compareTo(new BigDecimal("0"))>0){ vosmj.setLjtqb(vosmj.getLjtb().divide(vosmj.getQntq(),2,RoundingMode.HALF_UP)+"%"); } list.add(vosmj); } } } return R.ok(list); } @Override public R cpxzhtwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); List itemVoListDY = contractSubjectMatterMapper.cpxzhtwcqk(monstart,monend); List itemVoListLJ = contractSubjectMatterMapper.cpxzhtwcqk(yearstart,yearend); List itemVoListQN = contractSubjectMatterMapper.cpxzhtwcqk(yearstartLastYear,yearendLastYear); List indexList = new ArrayList<>(); if (CollUtil.isNotEmpty(itemVoListDY)){ for (int i = 0; i < itemVoListDY.size(); i++) { CpxssrwcqkItemVo item = itemVoListDY.get(i); CpxssrwcqkVo vo = new CpxssrwcqkVo(); vo.setXm(item.getXm()); BipDict dict = bipDictMapper.selectOne(Wrappers.lambdaQuery().eq(BipDict::getDictKey,"zb-cpmc") .eq(BipDict::getParentId,0).eq(BipDict::getDictName,item.getXm()).last("limit 1")); if (ObjUtil.isNull(dict)) { vo.setDyxsl(item.getXsl()); vo.setDyxssr(item.getXssr()); if (CollUtil.isNotEmpty(itemVoListLJ)) { itemVoListLJ.stream().forEach(item1 -> { if (StrUtil.equals(vo.getXm(), item1.getXm())) { vo.setLjxsl(item1.getXsl()); vo.setLjxssr(item1.getXssr()); } }); } if (CollUtil.isNotEmpty(itemVoListQN)) { itemVoListQN.stream().forEach(item1 -> { if (StrUtil.equals(vo.getXm(), item1.getXm())) { vo.setQnljxsl(item1.getXsl()); vo.setQnljxssr(item1.getXssr()); vo.setTqbxsl(vo.getLjxsl().subtract(vo.getQnljxsl())); vo.setTqbxssr(vo.getLjxssr().subtract(vo.getQnljxssr())); } }); } }else { indexList.add(i); } list.add(vo); } indexList.add(itemVoListDY.size()); for (int i = 0; i < indexList.size()-1; i++) { List sublist = list.subList(i,i+1); list.get(i).setDyxsl(sublist.stream().map(item->item.getDyxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setDyxssr(sublist.stream().map(item->item.getDyxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setLjxsl(sublist.stream().map(item->item.getLjxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setLjxssr(sublist.stream().map(item->item.getLjxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setQnljxsl(sublist.stream().map(item->item.getQnljxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setQnljxssr(sublist.stream().map(item->item.getQnljxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setTqbxsl(list.get(i).getLjxsl().subtract(list.get(i).getQnljxsl())); list.get(i).setTqbxssr(list.get(i).getLjxssr().subtract(list.get(i).getQnljxssr())); } } return R.ok(list); } @Override public R snqqwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); List list = historyOverdueMapper.snqqwcqk(monstart,monend,yearstart,yearend); if (CollUtil.isNotEmpty(list)){ list.stream().forEach(item->{ Long compId = null; if (StrUtil.equals(item.getDw(),"石煤机")){ compId = 2089995177814495234L; } if (StrUtil.equals(item.getDw(),"石工泵")){ compId = 2056556196124250113L; } if (StrUtil.equals(item.getDw(),"通方厂")){ compId = 2056556317461270529L; } if (StrUtil.equals(item.getDw(),"邢台厂")){ compId = 2056556421857497090L; } if (StrUtil.isNotBlank(item.getCode())) { AnnualTarget plan = annualTargetMapper.selectOne(Wrappers.lambdaQuery() .eq(AnnualTarget::getPlanYear, queryDTO.getYearMonth().substring(0, 4)) .eq(AnnualTarget::getPlanType, item.getCode()) .eq(AnnualTarget::getCompId, compId).last("limit 1")); if (ObjUtil.isNotNull(plan)) { item.setNdzb(plan.getTotalAmount()); if (item.getNdzb().compareTo(new BigDecimal("0")) > 0) { item.setZbwcl(item.getLjwcqh().divide(item.getNdzb(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } } }else { List planList = annualTargetMapper.selectList(Wrappers.lambdaQuery() .eq(AnnualTarget::getPlanYear, queryDTO.getYearMonth().substring(0, 4)) .eq(AnnualTarget::getCompId, compId)); if(CollUtil.isNotEmpty(planList)){ BigDecimal total = new BigDecimal("0"); for (AnnualTarget plan:planList ) { total = total.add(plan.getTotalAmount()); } item.setNdzb(total); if (item.getNdzb().compareTo(new BigDecimal("0")) > 0) { item.setZbwcl(item.getLjwcqh().divide(item.getNdzb(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } } } }); SnqqwcqkVo jt3n = new SnqqwcqkVo(); jt3n.setDw("集团"); jt3n.setXm("3年"); jt3n.setNdzb(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年")).map(SnqqwcqkVo::getNdzb).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3n.setDywcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年")).map(SnqqwcqkVo::getDywcqq).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3n.setDywcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年")).map(SnqqwcqkVo::getDywcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3n.setLjwcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年")).map(SnqqwcqkVo::getLjwcqq).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3n.setLjwcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年")).map(SnqqwcqkVo::getLjwcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); if (jt3n.getNdzb().compareTo(new BigDecimal("0")) > 0) { jt3n.setZbwcl(jt3n.getLjwcqh().divide(jt3n.getNdzb(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } SnqqwcqkVo jt3nys = new SnqqwcqkVo(); jt3nys.setDw("集团"); jt3nys.setXm("3年以上"); jt3nys.setNdzb(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年以上")).map(SnqqwcqkVo::getNdzb).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3nys.setDywcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年以上")).map(SnqqwcqkVo::getDywcqq).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3nys.setDywcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年以上")).map(SnqqwcqkVo::getDywcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3nys.setLjwcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年以上")).map(SnqqwcqkVo::getLjwcqq).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jt3nys.setLjwcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"3年以上")).map(SnqqwcqkVo::getLjwcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); if (jt3nys.getNdzb().compareTo(new BigDecimal("0")) > 0) { jt3nys.setZbwcl(jt3n.getLjwcqh().divide(jt3n.getNdzb(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } SnqqwcqkVo jthj = new SnqqwcqkVo(); jthj.setDw("集团"); jthj.setXm("合计"); jthj.setNdzb(list.stream().filter(item->StrUtil.equals(item.getXm(),"小计")).map(SnqqwcqkVo::getNdzb).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jthj.setDywcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"小计")).map(SnqqwcqkVo::getDywcqq).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jthj.setDywcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"小计")).map(SnqqwcqkVo::getDywcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); jthj.setLjwcqq(list.stream().filter(item->StrUtil.equals(item.getXm(),"小计")).map(SnqqwcqkVo::getLjwcqq).filter(Objects::nonNull ).reduce(BigDecimal.ZERO,BigDecimal::add)); jthj.setLjwcqh(list.stream().filter(item->StrUtil.equals(item.getXm(),"小计")).map(SnqqwcqkVo::getLjwcqh).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); if (jthj.getNdzb().compareTo(new BigDecimal("0")) > 0) { jthj.setZbwcl(jthj.getLjwcqh().divide(jthj.getNdzb(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) .setScale(2, RoundingMode.HALF_UP) + "%"); } list.add(jt3n); list.add(jt3nys); list.add(jthj); } return R.ok(list); } @Override public R cpxssrwcqk(ZBJTStatisticDTO queryDTO) { if (StrUtil.isBlank(queryDTO.getYearMonth())){ return R.failed("查询年月不能为空"); } List list = new ArrayList<>(); Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"); Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-01 00:00:00"),-1); Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"); Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"); Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0,4)+"-01-01 00:00:00"),-1); Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth()+"-31 23:59:59"),-1); List itemVoListDY = contractOutBoundMapper.cpxssrwcqk(monstart,monend); List itemVoListLJ = contractOutBoundMapper.cpxssrwcqk(yearstart,yearend); List itemVoListQN = contractOutBoundMapper.cpxssrwcqk(yearstartLastYear,yearendLastYear); List indexList = new ArrayList<>(); if (CollUtil.isNotEmpty(itemVoListDY)){ for (int i = 0; i < itemVoListDY.size(); i++) { CpxssrwcqkItemVo item = itemVoListDY.get(i); CpxssrwcqkVo vo = new CpxssrwcqkVo(); vo.setXm(item.getXm()); BipDict dict = bipDictMapper.selectOne(Wrappers.lambdaQuery().eq(BipDict::getDictKey,"zb-cpmc") .eq(BipDict::getParentId,0).eq(BipDict::getDictName,item.getXm()).last("limit 1")); if (ObjUtil.isNull(dict)) { vo.setDyxsl(item.getXsl()); vo.setDyxssr(item.getXssr()); if (CollUtil.isNotEmpty(itemVoListLJ)) { itemVoListLJ.stream().forEach(item1 -> { if (StrUtil.equals(vo.getXm(), item1.getXm())) { vo.setLjxsl(item1.getXsl()); vo.setLjxssr(item1.getXssr()); } }); } if (CollUtil.isNotEmpty(itemVoListQN)) { itemVoListQN.stream().forEach(item1 -> { if (StrUtil.equals(vo.getXm(), item1.getXm())) { vo.setQnljxsl(item1.getXsl()); vo.setQnljxssr(item1.getXssr()); vo.setTqbxsl(vo.getLjxsl().subtract(vo.getQnljxsl())); vo.setTqbxssr(vo.getLjxssr().subtract(vo.getQnljxssr())); } }); } }else { indexList.add(i); } list.add(vo); } indexList.add(itemVoListDY.size()); for (int i = 0; i < indexList.size()-1; i++) { List sublist = list.subList(i,i+1); list.get(i).setDyxsl(sublist.stream().map(item->item.getDyxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setDyxssr(sublist.stream().map(item->item.getDyxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setLjxsl(sublist.stream().map(item->item.getLjxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setLjxssr(sublist.stream().map(item->item.getLjxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setQnljxsl(sublist.stream().map(item->item.getQnljxsl()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setQnljxssr(sublist.stream().map(item->item.getQnljxssr()).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add)); list.get(i).setTqbxsl(list.get(i).getLjxsl().subtract(list.get(i).getQnljxsl())); list.get(i).setTqbxssr(list.get(i).getLjxssr().subtract(list.get(i).getQnljxssr())); } } return R.ok(list); } }