package com.yccrc.kede.test;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yccrc.generator.domain.*;
import com.yccrc.generator.service.IGenTableColumnService;
import com.yccrc.generator.service.IGenTableService;

import lombok.extern.slf4j.Slf4j;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = com.yccrc.KedeApplication.class)
@Slf4j
public class GeneratorTest {
	
	@Autowired
	IGenTableService genTableService;
	
	@Autowired
	IGenTableColumnService genTableColumnService;
	
	@Test
	public void testGenerator() {
		String tableName = "enterprise_log";
		
	
		GenTable genTable = genTableService.lambdaQuery().eq(GenTable::getTableName, tableName).one();
		if(genTable!=null) {
			log.info("清除{}在代码生成业务表中的数据",tableName);
			//重新初始下内容
			LambdaQueryWrapper<GenTableColumn> queryWrapper = Wrappers.lambdaQuery();
			genTableColumnService.remove(queryWrapper.eq(GenTableColumn::getTableId, genTable.getTableId()));
			genTableService.removeById(genTable);
		}
		log.info("查询{}的表结构",tableName);
		genTable = genTableService.selectDbTableListByName(tableName);
		
		log.info("初始化{}的代码生成业务表数据",tableName);
		
		genTableService.importGenTable(Arrays.asList(genTable));
		
		log.info("生成{}的业务代码",tableName);
		genTableService.generatorCode(tableName);
	}
	

	
}