采购方式金额,数量统计

Controller层

/**
	 * 采购方式金额,数量统计
	 * @param year
	 * @return
	 */
	@GetMapping("/queryPlanDate")
	@ApiOperation(value = "采购计划金额,数量查询", notes = "传入年限")
	@ApiOperationSupport(order = 34)
	public R<PlanQueryListVO> queryPlanDate(@RequestParam("year") String year) {
		 return R.data(planService.queryPlanDate(year));
	}

Service层

    /**
     * 采购方式金额,数量统计
     *
     * @param year
     * @return
     */
    @Override
    public PlanQueryListVO queryPlanDate(String year) {
        List<Long> childCompanyIdList = new ArrayList<>();
        Long companyId = WebUtils.getCompanyId();
//        ResultData<List<Long>> childOrgsResultData = baseOrganizationApiService.getChildOrgs(companyId, "1");
//        if(childOrgsResultData ==null ||childOrgsResultData.getCode() != Constants.REQ_CODE_SUCC){
//            throw new EbsException("获取公司子公司失败!");
//        }
//        List<Long> childCompanyIdList = childOrgsResultData.getData();
        childCompanyIdList.add(companyId);

        List<Plan> planList = planMapper.queryPlanDate(year,childCompanyIdList);
        if (CollectionUtils.isEmpty(planList)) {
            return new PlanQueryListVO();
        }
        List<PlanQueryListVO> planQueryLists = new ArrayList<>();
        List<String> advicePurchaseList = planList.stream().map(Plan::getAdvicePurchaseMode)
                .distinct().collect(Collectors.toList());
        List<ValSetOutputVO> valSets = baseValsetApiService.getValSet("PURCHASE_MODE", null);
        Map<String, String> jobMap = valSets.stream().filter(x -> "10".equals(x.getParentVal()))
                .collect(Collectors.toMap(ValSetOutputVO::getVal, ValSetOutputVO::getName, (x, y) -> x));
        PlanQueryListVO planQueryList = new PlanQueryListVO();
        DecimalFormat decimal = new DecimalFormat("#0.00");
        List<Plan> plans = new ArrayList<>();
        //计算金额,数量
        for (String advicePurchase : advicePurchaseList) {
            //校验需求方建议采购方式
            if (StringUtil.isNotBlank(jobMap.get(advicePurchase))) {
                List<Plan> collPlan = planList.stream().filter(e -> e.getAdvicePurchaseMode().equals(advicePurchase))
                        .collect(Collectors.toList());
                plans.addAll(collPlan);
                //已完成
                List<Plan> collect = collPlan.stream().filter(e -> e.getUseOfStatus().equals("20")).collect(Collectors.toList());
                //正在实施
                List<Plan> proList = collPlan.stream().filter(e -> e.getUseOfStatus().equals("10")).collect(Collectors.toList());
                //计算已下达金额
                BigDecimal reduceTotal = collPlan.stream()
                        .map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //计算已完成金额
                BigDecimal completeList = collect.stream()
                        .map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //计算正在实施金额
                BigDecimal processList = proList.stream()
                        .map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                planQueryList = new PlanQueryListVO();
                planQueryList.setBudgetAmount(decimal.format(reduceTotal));
                planQueryList.setCompleteAmount(decimal.format(completeList));
                planQueryList.setProcessAmount(decimal.format(processList));
                planQueryList.setPurchaseMode(jobMap.get(advicePurchase));
                planQueryList.setCompleteNumber(collect.size());
                planQueryList.setProcessNumber(proList.size());
                planQueryList.setNumber(collPlan.size());
                planQueryLists.add(planQueryList);

            }
        }
        //计算总数
        PlanQueryListVO planQuery = getPlanList(plans, planQueryLists, decimal);
        return planQuery;
    }

    /**
     * 计算总数
     *
     * @param planList
     * @param planQueryLists
     * @param decimal
     * @return
     */
    private PlanQueryListVO getPlanList(List<Plan> planList, List<PlanQueryListVO> planQueryLists, DecimalFormat decimal) {
        BigDecimal budgetAmounts = planList.stream().map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal completeAmounts = planList.stream().filter(e -> "20".equals(e.getUseOfStatus()))
                .map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal processAmounts = planList.stream().filter(e -> "10".equals(e.getUseOfStatus()))
                .map(Plan::getBudgetAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        PlanQueryListVO planQuery = new PlanQueryListVO();
        planQuery.setPlanQueryListVOList(planQueryLists);
        planQuery.setBudgetAmounts(decimal.format(budgetAmounts));
        planQuery.setCompleteAmounts(decimal.format(completeAmounts));
        planQuery.setProcessAmounts(decimal.format(processAmounts));
        planQuery.setNumbers(planList.size());
        List<Plan> coll = planList.stream().filter(e -> "20".equals(e.getUseOfStatus())).collect(Collectors.toList());
        List<Plan> col = planList.stream().filter(e -> "10".equals(e.getUseOfStatus())).collect(Collectors.toList());
        planQuery.setCompleteNumbers(coll.size());
        planQuery.setProcessNumbers(col.size());
        return planQuery;
    }

/**
 * 采购方式金额,数量统计
 * @param year
 * @return
 */
 
mapper 接口
List<Plan> queryPlanDate(@Param("year") String year,@Param("childCompanyIdList")List<Long> childCompanyIdList);

mapper层

<select id="queryPlanDate" resultMap="planResultMap">
      SELECT
      p.id,p.budget_amount,p.use_of_status,
       (CASE WHEN p.central_purchase_mode IS NOT NULL AND p.central_purchase_mode !=""  THEN p.central_purchase_mode
       WHEN p.master_purchase_mode  IS NOT NULL AND p.master_purchase_mode !="" THEN p.master_purchase_mode
       WHEN p.branch_purchase_mode IS NOT NULL  AND  p.branch_purchase_mode !="" THEN p.branch_purchase_mode
       ELSE p.advice_purchase_mode END) AS advice_purchase_mode
      FROM
         pls_plan_notice pn JOIN pls_plan_apply pa ON pn.id=pa.notice_id
      JOIN pls_plan_apply_relation par ON  pa.id=par.apply_id
      JOIN  pls_plan p ON par.plan_id=p.id
      WHERE
      pn.is_deleted = '0'
      AND pa.is_deleted='0'
      AND par.is_deleted='0'
      AND p.is_deleted='0'
      AND pa.apply_type='1'
      AND p.is_release='1'
      AND pn.year= #{year}
      AND p.demand_org_id in
        <foreach collection="childCompanyIdList" item="mode" index="index" open="(" separator=","
                 close=")">
            #{mode}
        </foreach>
    </select>


 <!-- 通用查询映射结果 -->
    <resultMap id="planResultMap" type="com.cntaiping.pls.plan.main.entity.Plan">
        <result column="id" property="id"/>
        <result column="item_id" property="itemId"/>
        <result column="item_seq" property="itemSeq"/>
        <result column="item_code" property="itemCode"/>
        <result column="item_name" property="itemName"/>
        <result column="merge_code" property="mergeCode"/>
        <result column="plan_code" property="planCode"/>
        <result column="item_product_name" property="itemProductName"/>
        <result column="item_product_code" property="itemProductCode"/>
        <result column="item_descr" property="itemDescr"/>
        <result column="advice_purchase_mode" property="advicePurchaseMode"/>
        <result column="advice_start_date" property="adviceStartDate"/>
        <result column="budget_amount" property="budgetAmount"/>
        <result column="budget_amount_currency" property="budgetAmountCurrency"/>
        <result column="budget_exchange_rate" property="budgetExchangeRate"/>
        <result column="budget_amount_cny" property="budgetAmountCny"/>
        <result column="purchasing_years" property="purchasingYears"/>
        <result column="own_master_org_id" property="ownMasterOrgId"/>
        <result column="own_master_org_name" property="ownMasterOrgName"/>
        <result column="demand_org_id" property="demandOrgId"/>
        <result column="demand_org_name" property="demandOrgName"/>
        <result column="demand_org_dept_id" property="demandOrgDeptId"/>
        <result column="demand_org_dept_name" property="demandOrgDeptName"/>
        <result column="demand_user_id" property="demandUserId"/>
        <result column="demand_user_name" property="demandUserName"/>
        <result column="perform_org_id" property="performOrgId"/>
        <result column="perform_org_name" property="performOrgName"/>
        <result column="perform_org_dept_id" property="performOrgDeptId"/>
        <result column="perform_org_dept_name" property="performOrgDeptName"/>
        <result column="central_purchase_mode" property="centralPurchaseMode"/>
        <result column="central_start_date" property="centralStartDate"/>
        <result column="master_purchase_mode" property="masterPurchaseMode"/>
        <result column="master_start_date" property="masterStartDate"/>
        <result column="branch_purchase_mode" property="branchPurchaseMode"/>
        <result column="branch_start_date" property="branchStartDate"/>
        <result column="company_name" property="companyName"/>
        <result column="is_XinChang" property="isXinchang"/>
        <result column="remark" property="remark"/>
        <result column="report_time" property="reportTime"/>
        <result column="operation_org_dept" property="operationOrgDept"/>
        <result column="excute_amount" property="excuteAmount"/>
        <result column="usable_amount" property="usableAmount"/>
        <result column="use_of_status" property="useOfStatus"/>
        <result column="use_of_desc" property="useOfDesc"/>
        <result column="manual_apply_id" property="manualApplyId"/>
        <result column="manual_apply_code" property="manualApplyCode"/>
        <result column="manual_apply_name" property="manualApplyName"/>
        <result column="manual_apply_desc" property="manualApplyDesc"/>
        <result column="meeting_time" property="meetingTime"/>
        <result column="meeting_result" property="meetingResult"/>
        <result column="meeting_result_remark" property="meetingResultRemark"/>
        <result column="is_release" property="isRelease"/>
        <result column="release_time" property="releaseTime"/>
        <result column="is_close" property="isClose"/>
        <result column="operation_stage" property="operationStage"/>
        <result column="rebuild_plan_id" property="rebuildPlanId"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user_id" property="updateUserId"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值