package com.hotent.project.manager.impl;

import java.util.Arrays;
import java.util.List;

import com.hotent.sys.persistence.manager.DataDictManager;
import com.hotent.sys.persistence.model.DataDict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.util.BeanUtils;
import com.hotent.project.dao.CostProjectTaskMaterialDao;
import com.hotent.project.manager.CostProjectTaskMaterialManager;
import com.hotent.project.model.CostProjectTaskMaterial;
import javax.annotation.Resource;


/**
 * 任务定制-报送资料要求 服务实现类
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-10-09
 */
@Service
public class CostProjectTaskMaterialManagerImpl extends BaseManagerImpl<CostProjectTaskMaterialDao, CostProjectTaskMaterial> implements CostProjectTaskMaterialManager {


	@Resource
	DataDictManager dataDictManager;


	@Override
	public CostProjectTaskMaterial getDetail(String id) {
    	CostProjectTaskMaterial costProjectTaskMaterial = this.get(id);
    	if (BeanUtils.isEmpty(costProjectTaskMaterial)) {
    		throw new RuntimeException("任务定制-报送资料要求不存在");
    	}
		return costProjectTaskMaterial;
	}

	@Override
	@Transactional
	public void createOrUpdate(CostProjectTaskMaterial costProjectTaskMaterial) {
		//新建或更新
		this.saveOrUpdate(costProjectTaskMaterial);
	}

	@Override
	@Transactional
	public void deleteById(String id) {
		this.removeById(id);
	}

	@Override
	@Transactional
	public void batchDelete(String[] ids) {
		this.removeByIds(Arrays.asList(ids));
	}

	@Override
	public List<CostProjectTaskMaterial> listByTaskId(String taskId) {
		QueryWrapper<CostProjectTaskMaterial> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("task_id", taskId);
		queryWrapper.orderByAsc("order_num");
		List<CostProjectTaskMaterial> list = this.list(queryWrapper);
		for (CostProjectTaskMaterial costProjectTaskMaterial : list) {
			DataDict byDictKey = dataDictManager.getByDictKey("1976557733440159744", costProjectTaskMaterial.getInformationType());
			if (!BeanUtils.isEmpty(byDictKey)){
				costProjectTaskMaterial.setInformationTypeName(byDictKey.getName());
			}

		}

		return list;
	}

}
