package com.kidgrow.generator.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.kidgrow.common.model.PageResult;
|
import com.kidgrow.generator.mapper.SysGeneratorMapper;
|
import com.kidgrow.generator.service.SysGeneratorService;
|
import com.kidgrow.generator.utils.GenUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.MapUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.io.ByteArrayOutputStream;
|
import java.io.IOException;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.zip.ZipOutputStream;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/24 09:40 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
@Slf4j
|
@Service
|
public class SysGeneratorServiceImpl extends ServiceImpl implements SysGeneratorService {
|
@Autowired
|
private SysGeneratorMapper sysGeneratorMapper;
|
|
@Override
|
public PageResult<Map<String, Object>> queryList(Map<String, Object> map) {
|
Page<Map<String, Object>> page = new Page<>(MapUtils.getInteger(map, "page"), MapUtils.getInteger(map, "limit"));
|
|
List<Map<String, Object>> list = sysGeneratorMapper.queryList(page, map);
|
return PageResult.<Map<String, Object>>builder().data(list).code(0).count(page.getTotal()).build();
|
}
|
|
@Override
|
public Map<String, String> queryTable(String tableName) {
|
return sysGeneratorMapper.queryTable(tableName);
|
}
|
|
@Override
|
public List<Map<String, String>> queryColumns(String tableName) {
|
return sysGeneratorMapper.queryColumns(tableName);
|
}
|
|
@Override
|
public byte[] generatorCode(String[] tableNames) {
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
try (
|
ZipOutputStream zip = new ZipOutputStream(outputStream)
|
) {
|
for (String tableName : tableNames) {
|
//查询表信息
|
Map<String, String> table = queryTable(tableName);
|
//查询列信息
|
List<Map<String, String>> columns = queryColumns(tableName);
|
//生成代码
|
GenUtils.generatorCode(table, columns, zip);
|
}
|
} catch (IOException e) {
|
log.error("generatorCode-error: ", e);
|
}
|
return outputStream.toByteArray();
|
}
|
}
|