
package org.sky.scientific.service.impl;

import org.sky.core.log.exception.ServiceException;
import org.sky.core.tool.utils.DateUtil;
import org.sky.core.tool.utils.StringUtil;
import org.sky.scientific.pojo.dto.XmWwxmDTO;
import org.sky.scientific.pojo.entity.XmWwxmEntity;
import org.sky.scientific.pojo.vo.XmWwxmVO;
import org.sky.scientific.excel.XmWwxmExcel;
import org.sky.scientific.mapper.XmWwxmMapper;
import org.sky.scientific.service.IXmWwxmService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.sky.core.mp.base.BaseServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * 项目-委外项目 服务实现类
 *
 * @author Kd
 * @since 2025-06-29
 */
@Service
public class XmWwxmServiceImpl extends BaseServiceImpl<XmWwxmMapper, XmWwxmEntity> implements IXmWwxmService {

	@Override
	public List<XmWwxmExcel> exportXmWwxm(Wrapper<XmWwxmEntity> queryWrapper) {
		List<XmWwxmExcel> xmWwxmList = baseMapper.exportXmWwxm(queryWrapper);
		//xmWwxmList.forEach(xmWwxm -> {
		//	xmWwxm.setTypeName(DictCache.getValue(DictEnum.YES_NO, XmWwxm.getType()));
		//});
		return xmWwxmList;
	}

	@Override
	public boolean physicalDeleteByIds(List<Long> ids) {
		return baseMapper.physicalDeleteByIds(ids);
	}

	@Override
	public IPage<XmWwxmVO> selectPage(IPage<XmWwxmVO> page, XmWwxmDTO wwxmDTO) {
		if (wwxmDTO.getXmId() == null) {
			throw new ServiceException("请选择研发项目");
		}
		if(wwxmDTO.getYearAndMonth() == null){
			wwxmDTO.setYearAndMonth(DateUtil.format(new Date(), DateUtil.PATTERN_YYYY));
		}
		return page.setRecords(baseMapper.selectXmWwxmPage(page, wwxmDTO));
	}

	@Override
	public List<XmWwxmVO> selectSimpleList(String yearAndMonth) {
		if(StringUtil.isBlank(yearAndMonth)){
			throw new ServiceException("参数yearAndMonth不能为空");
		}
		return baseMapper.selectSimpleList(yearAndMonth);
	}

}
