package com.sysu.admin.controller.crop.executor_table;

import com.sysu.admin.support.base.BaseService;
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.Query;
import java.util.List;

@Service
public class ExecutorTableService extends BaseService<ExecutorTable, PKRP> {

    @Autowired
    ExecutorTableRepository executorTableRepository;

    public String getTableNames(Long executor){
        Query query = mEntityManager.createQuery("select e.pk.tableName from ExecutorTable e where e.pk.executor = " + executor);
        List<String> executorTableList = query.getResultList();
        StringBuffer stringBuffer = new StringBuffer(executorTableList.size() * 15);
        for(String executorTable : executorTableList){
            stringBuffer.append(executorTable);
            stringBuffer.append(",");
        }
        stringBuffer.deleteCharAt(stringBuffer.length() - 1);
        return stringBuffer.toString();
    }

    @Override
    public JpaPlusRepository<ExecutorTable, PKRP> r() {
        return executorTableRepository;
    }
}
