package com.ebts.generator.service.impl;

import com.ebts.common.core.entity.Result;
import com.ebts.common.core.text.Convert;
import com.ebts.generator.dao.GenTableColumnDao;
import com.ebts.generator.entity.GenTableColumn;
import com.ebts.generator.service.GenTableColumnService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 业务字段 服务层实现
 *
 * @author binlin
 */
@Service
public class GenTableColumnServiceImpl implements GenTableColumnService {

    @Resource
    private GenTableColumnDao genTableColumnDao;

    /**
     * 查询业务字段列表
     *
     * @param tableId 业务字段编号
     * @return 业务字段集合
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Result<List<GenTableColumn>> selectGenTableColumnListByTableId(Long tableId) {
        List<GenTableColumn> columnList = genTableColumnDao.selectGenTableColumnListByTableId(tableId);
        if (columnList.size() != 0) {
            return Result.ok(columnList);
        } else {
            return Result.info();
        }
    }

    /**
     * 新增业务字段
     *
     * @param genTableColumn 业务字段信息
     * @return 结果
     */
    @Override
    public int insertGenTableColumn(GenTableColumn genTableColumn) {
        return genTableColumnDao.insertGenTableColumn(genTableColumn);
    }

    /**
     * 修改业务字段
     *
     * @param genTableColumn 业务字段信息
     * @return 结果
     */
    @Override
    public int updateGenTableColumn(GenTableColumn genTableColumn) {
        List<GenTableColumn> genTableColumns = new ArrayList<GenTableColumn>();
        genTableColumns.add(genTableColumn);
        return genTableColumnDao.updateGenTableColumn(genTableColumns);
    }

    /**
     * 删除业务字段对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGenTableColumnByIds(String ids) {
        return genTableColumnDao.deleteGenTableColumnByIds(Convert.toLongArray(ids));
    }
}
