package com.goer.project.model.modelProject.service.impl;

import java.util.List;
import com.goer.common.utils.DateUtils;
import com.goer.project.model.dataType.mapper.DataTypeMapper;
import com.goer.project.model.modelDbs.mapper.ModelDbsMapper;
import com.goer.project.model.modelEntity.mapper.ModelEntityMapper;
import com.goer.project.model.modelField.mapper.ModelFieldMapper;
import com.goer.project.model.modelVersion.mapper.ModelVersionMapper;
import com.goer.project.model.modelVersionChanges.mapper.ModelVersionChangesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.goer.project.model.modelProject.mapper.ModelProjectMapper;
import com.goer.project.model.modelProject.domain.ModelProject;
import com.goer.project.model.modelProject.service.IModelProjectService;
import com.goer.common.utils.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 模型对象Service业务层处理
 * 
 * @author goer
 * @date 2022-01-17
 */
@Service
public class ModelProjectServiceImpl implements IModelProjectService 
{
    @Autowired
    private ModelProjectMapper modelProjectMapper;

    @Autowired
    private ModelDbsMapper modelDbsMapper;

    @Autowired
    private DataTypeMapper dataTypeMapper;

    @Autowired
    private ModelEntityMapper modelEntityMapper;

    @Autowired
    private ModelFieldMapper modelFieldMapper;

    @Autowired
    private ModelVersionMapper modelVersionMapper;

    @Autowired
    private ModelVersionChangesMapper modelVersionChangesMapper;

    /**
     * 查询模型对象
     * 
     * @param id 模型对象主键
     * @return 模型对象
     */
    @Override
    public ModelProject selectModelProjectById(Long id)
    {
        return modelProjectMapper.selectModelProjectById(id);
    }

    /**
     * 查询模型对象列表
     * 
     * @param modelProject 模型对象
     * @return 模型对象
     */
    @Override
    public List<ModelProject> selectModelProjectList(ModelProject modelProject)
    {
        return modelProjectMapper.selectModelProjectList(modelProject);
    }

    /**
     * 新增模型对象
     * 
     * @param modelProject 模型对象
     * @return 结果
     */
    @Override
    @Transactional
    public int insertModelProject(ModelProject modelProject)
    {
        modelProject.setCreateTime(DateUtils.getNowDate());
        modelProjectMapper.insertModelProject(modelProject);
        modelProjectMapper.initDataType(modelProject);
        return modelProjectMapper.initModelField(modelProject);
    }

    /**
     * 修改模型对象
     * 
     * @param modelProject 模型对象
     * @return 结果
     */
    @Override
    public int updateModelProject(ModelProject modelProject)
    {
        modelProject.setUpdateTime(DateUtils.getNowDate());
        return modelProjectMapper.updateModelProject(modelProject);
    }

    /**
     * 批量删除模型对象
     * 
     * @param ids 需要删除的模型对象主键
     * @return 结果
     */
    @Override
    public int deleteModelProjectByIds(String ids)
    {
        int ret = 0;
        Long[] idArr = Convert.toLongArray(ids);
        for (Long id : idArr) {
            ret = ret + modelVersionChangesMapper.deleteModelVersionChangesByProjectId(id);
            ret = ret + modelVersionMapper.deleteModelVersionByProjectId(id);
            ret = ret + modelFieldMapper.deleteModelFieldByProjectId(id);
            ret = ret + modelEntityMapper.deleteModelEntityByProjectId(id);
            ret = ret + dataTypeMapper.deleteDataTypeByProjectId(id);
            ret = ret + modelDbsMapper.deleteModelDbsByProjectId(id);
            ret = ret + modelProjectMapper.deleteModelProjectById(id);
        }
        return ret;
    }

    /**
     * 删除模型对象信息
     * 
     * @param id 模型对象主键
     * @return 结果
     */
    @Override
    public int deleteModelProjectById(Long id)
    {
        return modelProjectMapper.deleteModelProjectById(id);
    }
}
