代码下载改动

This commit is contained in:
20932067@zju.edu.cn 2021-02-28 22:00:49 +08:00
parent 290036d38c
commit e9e8ae6abe
5 changed files with 31 additions and 4 deletions

View File

@ -74,3 +74,10 @@ export function synchDb(tableName) {
method: 'get'
})
}
//下载接口
export function downloadCode(tableNames){
return request({
url:'/tool/gen/batchGenCode?tables=' + tableNames,
method:'get'
})
}

View File

@ -178,7 +178,7 @@
</template>
<script>
import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
import { listTable, previewTable, delTable, genCode, synchDb, downloadCode } from "@/api/tool/gen";
import importTable from "./importTable";
import { downLoadZip } from "@/utils/zipdownload";
import hljs from "highlight.js/lib/highlight";
@ -269,6 +269,10 @@ export default {
this.msgSuccess("成功生成到自定义路径:" + row.genPath);
});
} else {
// downloadCode(tableNames).then(res =>{
// this.download(res.msg);
// })
// // todo
downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "hchyun");
}
},

View File

@ -38,6 +38,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
os.write(b, 0, length);
}
} catch (IOException e) {
System.out.println(e);
throw e;
} finally {
if (os != null) {

View File

@ -21,6 +21,13 @@ public class Config {
private static String profile;
public void setProfile(String profile){
Config.profile = profile;
}
public static String getProfile() {
return profile;
}

View File

@ -9,6 +9,7 @@ import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.hchyun.generator.aop.Log;
import com.hchyun.generator.config.Config;
import com.hchyun.generator.enums.GenBusinessType;
import com.hchyun.generator.utils.GenBaseController;
import com.hchyun.generator.utils.GenReturnConstants;
@ -207,22 +208,29 @@ public class GenController extends GenBaseController {
String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data);
compress(data);
// if (compress(data)){
// return AjaxResult.success("hchyun.zip");
// }else {
// return AjaxResult.error();
// }
}
/**
* 将bytes流写入到本地
* @param bytes
*/
public static void compress(byte[] bytes) {
public boolean compress(byte[] bytes) {
try {
FileOutputStream fileOutputStream = new FileOutputStream("F:\\Work\\表白\\huhyun.zip");
String dir = Config.getProfile()+"/hchyun.zip";
FileOutputStream fileOutputStream = new FileOutputStream(dir);
fileOutputStream.write(bytes);
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**