@RequestMapping(params = "transEditor")
@ResponseBody
public AjaxJson transEditor(HttpServletRequest request, String id)
throws Exception {
AjaxJson j = new AjaxJson();
String ids[] = id.split(",");
String no = "";
String yes = "";
for (int i = 0; i < ids.length; i++) {
if (StringUtil.isNotEmpty(ids[i])) {
List<CgFormHeadEntity> cffList = cgFormFieldService
.findByProperty(CgFormHeadEntity.class, "tableName",
ids[i]);
if (cffList.size() > 0) {
if (no != "")
no += ",";
no += ids[i];
continue;
}
List<Columnt> list = new JeecgReadTable()
.readOriginalTableColumn(ids[i]);
CgFormHeadEntity cgFormHead = new CgFormHeadEntity();
cgFormHead.setJformType(1);
cgFormHead.setIsCheckbox("Y");
cgFormHead.setIsDbSynch("Y");
cgFormHead.setIsTree("N");
cgFormHead.setQuerymode("group");
cgFormHead.setTableName(ids[i].toLowerCase());
cgFormHead.setIsPagination("Y");
cgFormHead.setContent(ids[i]);
cgFormHead.setJformVersion("1");
List<CgFormFieldEntity> columnsList = new ArrayList<CgFormFieldEntity>();
for (int k = 0; k < list.size(); k++) {
Columnt columnt = list.get(k);
String fieldName = columnt.getFieldDbName();
CgFormFieldEntity cgFormField = new CgFormFieldEntity();
cgFormField.setFieldName(columnt.getFieldDbName()
.toLowerCase());
if (StringUtil.isNotEmpty(columnt.getFiledComment()))
cgFormField.setContent(columnt.getFiledComment());
else
cgFormField.setContent(columnt.getFieldName());
cgFormField.setIsKey("N");
cgFormField.setIsShow("Y");
cgFormField.setIsShowList("Y");
cgFormField.setOrderNum(k + 2);
cgFormField.setQueryMode("group");
cgFormField.setLength(0);
cgFormField.setFieldLength(120);
cgFormField.setPointLength(0);
cgFormField.setShowType("text");
cgFormField.setIsNull(columnt.getNullable());
if("id".equalsIgnoreCase(fieldName)){
String[] pkTypeArr = {"java.lang.Integer","java.lang.Long"};
String idFiledType = columnt.getFieldType();
if(Arrays.asList(pkTypeArr).contains(idFiledType)){
//如果主键是数字类型,则设置为自增长
cgFormHead.setJformPkType("NATIVE");
}else{
//否则设置为UUID
cgFormHead.setJformPkType("UUID");
}
cgFormField.setIsKey("Y");
cgFormField.setIsShow("N");
cgFormField.setIsShowList("N");
}
if ("java.lang.Integer".equalsIgnoreCase(columnt.getFieldType())){
cgFormField.setType(DataBaseConst.INT);
}else if ("java.lang.Long".equalsIgnoreCase(columnt.getFieldType())) {
cgFormField.setType(DataBaseConst.INT);
} else if ("java.util.Date".equalsIgnoreCase(columnt.getFieldType())) {
cgFormField.setType(DataBaseConst.DATE);
cgFormField.setShowType("date");
} else if ("java.lang.Double".equalsIgnoreCase(columnt.getFieldType())
||"java.lang.Float".equalsIgnoreCase(columnt.getFieldType())) {
cgFormField.setType(DataBaseConst.DOUBLE);
} else if ("java.math.BigDecimal".equalsIgnoreCase(columnt.getFieldType())) {
cgFormField.setType(DataBaseConst.BIGDECIMAL);
} else if (columnt.getFieldType().contains("blob")) {
cgFormField.setType(DataBaseConst.BLOB);
columnt.setCharmaxLength(null);
} else {
cgFormField.setType(DataBaseConst.STRING);
}
if (StringUtil.isNotEmpty(columnt.getCharmaxLength())) {
if (Long.valueOf(columnt.getCharmaxLength()) >= 3000) {
cgFormField.setType(DataBaseConst.TEXT);
cgFormField.setShowType(DataBaseConst.TEXTAREA);
try{//有可能长度超出int的长度
cgFormField.setLength(Integer.valueOf(columnt.getCharmaxLength()));
}catch(Exception e){}
} else {
cgFormField.setLength(Integer.valueOf(columnt
.getCharmaxLength()));
}
} else {
if (StringUtil.isNotEmpty(columnt.getPrecision())) {
cgFormField.setLength(Integer.valueOf(columnt
.getPrecision()));
}
//update-begin--Author:zhangdaihao Date:20140212 for:[001]oracle下number类型,数据库表导出表单,默认长度为0同步失败
else{
if(cgFormField.getType().equals(DataBaseConst.INT)){
cgFormField.setLength(10);
}
}
//update-end--Author:zhangdaihao Date:20140212 for:[001]oracle下number类型,数据库表导出表单,默认长度为0同步失败
if (StringUtil.isNotEmpty(columnt.getScale()))
cgFormField.setPointLength(Integer.valueOf(columnt
.getScale()));
}
columnsList.add(cgFormField);
}
cgFormHead.setColumns(columnsList);
cgFormFieldService.saveTable(cgFormHead, "");
if (yes != "")
yes += ",";
yes += ids[i];
}
}
Map<String, String> map = new HashMap<String, String>();
map.put("no", no);
map.put("yes", yes);
j.setObj(map);
return j;
}