/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */
package com.qunzhixinxi.hnqz.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qunzhixinxi.hnqz.admin.entity.WmDeptBudget;
import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
import com.qunzhixinxi.hnqz.admin.entity.output.BudgetViewOutput;
import com.qunzhixinxi.hnqz.admin.mapper.WmDeptBudgetMapper;
import com.qunzhixinxi.hnqz.admin.service.WmDeptBudgetService;
import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 *
 * @author xyz
 * @date 2021-04-26 18:05:10
 */
@Service
@AllArgsConstructor
public class WmDeptBudgetServiceImpl extends ServiceImpl<WmDeptBudgetMapper, WmDeptBudget> implements WmDeptBudgetService {

	private final WmDeptBudgetMapper wmDeptBudgetMapper;
	private final WmScorePackageService wmScorePackageService;

	@Override
	public IPage getBudgetViewPage(Page page, WmDeptBudget wmDeptBudget) {
		IPage iPage = wmDeptBudgetMapper.getBudgetViewPage(page,wmDeptBudget);
		List<BudgetViewOutput> outputList = iPage.getRecords();
		for (BudgetViewOutput output : outputList) {
			Integer score = 0;
			WmScorePackage condition = new WmScorePackage();
			condition.setSendPackageDeptId(output.getDeclareDept()+"");
			condition.setDeptId(output.getDeptId()+"");
			condition.setBelongDate(output.getBelongDate());
			condition.setPackageType1("1");
			List<WmScorePackage> packageList = wmScorePackageService.list(Wrappers.query(condition));
			for (WmScorePackage wmScorePackage : packageList) {
				score+=wmScorePackage.getScore();
			}
			output.setScoreIssue(score);
		}
//		return wmDeptBudgetMapper.getBudgetViewPage(page,wmDeptBudget);
		return iPage;
	}

	@Override
	public IPage getBudgetEntViewPage(Page page, WmDeptBudget wmDeptBudget) {

		IPage iPage = wmDeptBudgetMapper.getBudgetEntViewPage(page, wmDeptBudget);
		List<BudgetViewOutput> outputList = iPage.getRecords();
		for (BudgetViewOutput output : outputList) {
			Integer score = 0;
			WmScorePackage condition = new WmScorePackage();
			condition.setSendPackageDeptId(output.getDeclareDept()+"");
			condition.setDeptId(output.getDeptId()+"");
			condition.setBelongDate(output.getBelongDate());
			condition.setPackageType1("1");
			List<WmScorePackage> packageList = wmScorePackageService.list(Wrappers.query(condition));
			for (WmScorePackage wmScorePackage : packageList) {
				score+=wmScorePackage.getScore();
			}
			output.setScoreIssue(score);
		}
//		return wmDeptBudgetMapper.getBudgetEntViewPage(page,wmDeptBudget);
		return iPage;
	}
}
