| | |
| | | package com.ks.codegenerator.controller; |
| | | |
| | | import com.ks.codegenerator.utils.AndroidBuilder; |
| | | import com.ks.codegenerator.utils.ServiceBuilder; |
| | | import com.ks.codegenerator.vo.ServiceVO; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.yeshi.utils.JsonUtil; |
| | |
| | | |
| | | //生成service |
| | | @RequestMapping("createService") |
| | | public void service(String name, String pks, String subpks, PrintWriter out, HttpServletRequest request) { |
| | | if (StringUtil.isNullOrEmpty(name) || StringUtil.isNullOrEmpty(pks) || StringUtil.isNullOrEmpty(subpks)) { |
| | | out.print(JsonUtil.loadFalseResult("项目名称,项目包名,应用包名不能为空")); |
| | | public void service(ServiceVO vo, PrintWriter out, HttpServletRequest request) { |
| | | if (StringUtil.isNullOrEmpty(vo.getName()) || StringUtil.isNullOrEmpty(vo.getPks()) || StringUtil.isNullOrEmpty(vo.getSubpks()) || StringUtil.isNullOrEmpty(vo.getChineseName())) { |
| | | out.print(JsonUtil.loadFalseResult("参数不完整")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(vo.getSqlDataBaseName()) || StringUtil.isNullOrEmpty(vo.getSqlTablePrefix()) || StringUtil.isNullOrEmpty(vo.getMongoDataBaseName())) { |
| | | out.print(JsonUtil.loadFalseResult("参数不完整")); |
| | | return; |
| | | } |
| | | |
| | | |
| | | String rootPath = request.getServletContext().getRealPath("cache"); |
| | | try { |
| | | String path = new ServiceBuilder().setCacheDir(rootPath).setName(name).setPks(pks).setSubpks(subpks).build(); |
| | | String path = new ServiceBuilder().setCacheDir(rootPath).setName(vo.getName()).setPks(vo.getPks()).setSubpks(vo.getSubpks()).setProjectChineseName(vo.getChineseName()).setMongoDatabaseName(vo.getMongoDataBaseName()).setSqlDatabaseName(vo.getSqlDataBaseName()).setSqlTablePrefix(vo.getSqlTablePrefix()).build(); |
| | | out.print(JsonUtil.loadTrueResult(path)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("downloadServiceZIP") |
| | | @RequestMapping("createAndroid") |
| | | public void android(String name, String pks, PrintWriter out, HttpServletRequest request) { |
| | | if (StringUtil.isNullOrEmpty(name) || StringUtil.isNullOrEmpty(pks)) { |
| | | out.print(JsonUtil.loadFalseResult("项目名称,项目包名不能为空")); |
| | | return; |
| | | } |
| | | String rootPath = request.getServletContext().getRealPath("cache"); |
| | | try { |
| | | String path = new AndroidBuilder().setCacheDir(rootPath).setName(name).setPks(pks).build(); |
| | | out.print(JsonUtil.loadTrueResult(path)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadFalseResult(e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("downloadZIP") |
| | | public void downloadServiceZIP(String name, HttpServletResponse response) throws IOException { |
| | | if (!new File(name).exists()) { |
| | | response.sendError(406, "问价已被删除"); |
| | | response.sendError(406, "文件已被删除"); |
| | | return; |
| | | } |
| | | response.setHeader("content-disposition", "attachment;filename=" + new File(name).getName()); |
| | |
| | | out.write(buffer, 0, len); |
| | | } |
| | | in.close(); |
| | | |
| | | } |
| | | |
| | | |