* @return
*/
@RequestMapping(params = "dogenerateOne2Many")
@ResponseBody
public void dogenerateOne2Many(CodeParamEntity codeParamEntityIn,GenerateSubListEntity subTableListEntity,HttpServletRequest request,HttpServletResponse response){
AjaxJson j = new AjaxJson();
//step.1 设置主表
//从前台获取:codeParamEntityIn
//step.2 设置子表集合
//从前台获取:subTabParamIn,并设置外键字段
try{
//step.3 填充主表的所有智能表单配置
String mainTable = codeParamEntityIn.getTableName();
//主表的智能表单配置
GenerateEntity mainG = new GenerateEntity();
mainG.setProjectPath(subTableListEntity.getProjectPath());
CgFormHeadEntity mCgFormHead = cgFormFieldService.getCgFormHeadByTableName(mainTable);
getCgformConfig(mCgFormHead, mainG);
//step.4 填充子表的所有智能表单配置
Map<String,GenerateEntity> subsG = new HashMap<String,GenerateEntity>();
List<SubTableEntity> subTabParamIn = subTableListEntity.getSubTabParamIn();
for(SubTableEntity po:subTabParamIn){
String sTableName = po.getTableName();
CgFormHeadEntity cgSubHead = cgFormFieldService.getCgFormHeadByTableName(sTableName);
List<CgFormFieldEntity> colums = cgSubHead.getColumns();
String[] foreignKeys =getForeignkeys(colums);
po.setForeignKeys(foreignKeys);
GenerateEntity subG = new GenerateEntity();
getCgformConfig(cgSubHead, subG);
subG.setEntityName(po.getEntityName());
subG.setEntityPackage(po.getEntityPackage());
subG.setFieldRowNum(1);
subG.setFtlDescription(po.getFtlDescription());
subG.setForeignKeys(foreignKeys);
subG.setTableName(po.getTableName());
subG.setProjectPath(subTableListEntity.getProjectPath());
subsG.put(sTableName, subG);
}
codeParamEntityIn.setSubTabParam(subTabParamIn);
//step.5 一对多(父子表)数据模型,代码生成
CgformCodeGenerateOneToMany.oneToManyCreate(subTabParamIn, codeParamEntityIn,mainG,subsG);
j.setMsg("成功生成增删改查->功能:"+codeParamEntityIn.getFtlDescription());
}catch (Exception e) {
e.printStackTrace();
j.setMsg(e.getMessage());
throw new RuntimeException(e.getMessage());
}
try {
String projectPath = URLEncoder.encode(subTableListEntity.getProjectPath(), "UTF-8");
Cookie cookie = new Cookie("cookie_projectPath",projectPath );
cookie.setMaxAge(60*60*24*30); //cookie 保存30天
response.addCookie(cookie);
response.getWriter().print(j.getJsonStr());
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
}