/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.project.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springblade.modules.project.pojo.entity.WorkFocusProgressEntity;
import org.springblade.modules.project.pojo.vo.WorkFocusProgressInfoVO;
import org.springblade.modules.project.pojo.vo.WorkFocusProgressListVO;
import org.springblade.modules.project.pojo.vo.WorkFocusProgressVO;
import org.springblade.modules.project.pojo.excel.WorkFocusProgressExcel;
import org.springblade.modules.project.mapper.WorkFocusProgressMapper;
import org.springblade.modules.project.service.IWorkFocusProgressService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static io.protostuff.MapSchema.MessageFactories.ConcurrentHashMap;

/**
 * 工作要点完成情况表 服务实现类
 *
 * @author BladeX
 * @since 2024-04-09
 */
@Service
public class WorkFocusProgressServiceImpl extends BaseServiceImpl<WorkFocusProgressMapper, WorkFocusProgressEntity> implements IWorkFocusProgressService {

	@Override
	public IPage<WorkFocusProgressVO> selectWorkFocusProgressPage(IPage<WorkFocusProgressVO> page, WorkFocusProgressVO workFocusProgress) {
		return page.setRecords(baseMapper.selectWorkFocusProgressPage(page, workFocusProgress));
	}


	@Override
	public List<WorkFocusProgressExcel> exportWorkFocusProgress(Wrapper<WorkFocusProgressEntity> queryWrapper) {
		List<WorkFocusProgressExcel> workFocusProgressList = baseMapper.exportWorkFocusProgress(queryWrapper);
		//workFocusProgressList.forEach(workFocusProgress -> {
		//	workFocusProgress.setTypeName(DictCache.getValue(DictEnum.YES_NO, WorkFocusProgress.getType()));
		//});
		return workFocusProgressList;
	}

	@Override
	public WorkFocusProgressListVO queryWorkFocusProgressInfoById(WorkFocusProgressListVO workFocusProgress) {

		// 查询出所有任务计划
		List<WorkFocusProgressVO> workFocusProgresslist = baseMapper.selectWorkFocusList(workFocusProgress);

		WorkFocusProgressListVO workFocusProgressListVO = new WorkFocusProgressListVO();
		List<WorkFocusProgressInfoVO> table3 = new ArrayList<>();
		//分组后的集合
		//Map<Integer, List<WorkFocusProgressVO>> groupList = workFocusProgresslist.stream().collect(Collectors.groupingBy(WorkFocusProgressVO::getYear));
		Map<Integer, List<WorkFocusProgressEntity>> groupList = workFocusProgresslist.stream().collect(Collectors.groupingBy(WorkFocusProgressEntity::getYear));
		for(int kekys : groupList.keySet()){
			List<WorkFocusProgressEntity> table2 = new ArrayList<>();
			List<WorkFocusProgressEntity> table = groupList.get(kekys);
			WorkFocusProgressInfoVO progressInfoVO = new WorkFocusProgressInfoVO();
			progressInfoVO.setYear(kekys+"");
			for(WorkFocusProgressEntity workFocusProgres:table){
				/*if(StringUtils.isNotEmpty(workFocusProgres.getSchedule()) && workFocusProgres.getSchedule().equals("problemInfo") && workFocusProgres.getMonth()==13){ //
					progressInfoVO.setProblemInfo(workFocusProgres.getProgress());
				}else if(StringUtils.isNotEmpty(workFocusProgres.getSchedule()) && workFocusProgres.getSchedule().equals("workSug") && workFocusProgres.getMonth()==14){ //
					progressInfoVO.setWorkSug(workFocusProgres.getProgress());
				}else */
				if(StringUtils.isNotEmpty(workFocusProgres.getSchedule()) && workFocusProgres.getSchedule().equals("unitInfo") && workFocusProgres.getMonth()==13){ //
					progressInfoVO.setUnitInfo(workFocusProgres.getProgress());
				}else if(StringUtils.isNotEmpty(workFocusProgres.getSchedule()) && workFocusProgres.getSchedule().equals("linkInfo") && workFocusProgres.getMonth()==14){ //
					progressInfoVO.setLinkInfo(workFocusProgres.getProgress());
				}else{
					table2.add(workFocusProgres);
				}
			}
			progressInfoVO.setData(table2);
			table3.add(progressInfoVO);
		}
		workFocusProgressListVO.setId(workFocusProgress.getId());
		workFocusProgressListVO.setTable(table3);
		return workFocusProgressListVO;
	}

}
