
package org.sky.scientific.service.impl;

import lombok.AllArgsConstructor;
import org.sky.core.log.exception.ServiceException;
import org.sky.core.mp.base.BaseServiceImpl;
import org.sky.scientific.mapper.DepartmentMapper;
import org.sky.scientific.mapper.TechnicianMapper;
import org.sky.scientific.mapper.XmJdxbgMapper;
import org.sky.scientific.pojo.entity.XmJdxbgEntity;
import org.sky.scientific.pojo.vo.XmJdxbgVO;
import org.sky.scientific.service.IXmJdxbgService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 科研项目-项目实施-阶段性报告 服务实现类
 *
 * @author Kd
 * @since 2025-07-01
 */
@Service
@AllArgsConstructor
public class XmJdxbgServiceImpl extends BaseServiceImpl<XmJdxbgMapper, XmJdxbgEntity> implements IXmJdxbgService {

	private final TechnicianMapper technicianMapper;
	private final DepartmentMapper departmentMapper;

	@Override
	public List<XmJdxbgVO> listByXmId(Long xmId) {
		List<XmJdxbgVO> list = baseMapper.listByXmId(xmId);
		for (XmJdxbgVO vo : list) {
			vo.getXmEntity().setXmfzrxm(technicianMapper.getNameById(vo.getXmEntity().getXmfzr()));
			vo.getXmEntity().setXmsqdw(departmentMapper.getFullNameById(vo.getXmEntity().getXmsqdwid()));
		}
		return list;
	}

	@Override
	public boolean submit(XmJdxbgEntity xmJdxbg) {
		if (xmJdxbg.getXmId() == null) {
			throw new ServiceException("请选择科研项目");
		}
		return this.saveOrUpdate(xmJdxbg);
	}

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

	@Override
	public XmJdxbgVO selectById(Long id) {

		XmJdxbgVO vo = baseMapper.selectByPrimaryKey(id);

		vo.getXmEntity().setXmfzrxm(technicianMapper.getNameById(vo.getXmEntity().getXmfzr()));
		vo.getXmEntity().setXmsqdw(departmentMapper.getFullNameById(vo.getXmEntity().getXmsqdwid()));

		return vo;
	}

}
