<div class="portlet box ltblue" xmlns:th="http://www.w3.org/1999/xhtml">
|
<div class="portlet-title">
|
基本信息
|
<div class="caption">
|
<i class="icon-reorder"></i>
|
</div>
|
<div class="tools">
|
<a href="javascript:;" class="collapse" onclick="portlet_body_ShowOrHide(this);"></a>
|
</div>
|
</div>
|
<div class="portlet-body">
|
<input type="hidden" id="tabletype" name="tabletype" th:value="${tabletype}"/>
|
<input type="hidden" id="isnew" th:value="${isnew}"/>
|
<input type="hidden" id="resourceid" th:value="${resourceid}"/>
|
<input type="hidden" id="primarykeys" th:value="${primarykeys}"/>
|
<table id="sort" class="table table-bordered table-hover">
|
<thead>
|
<tr>
|
<th th:if="${isnew==1}" ></th>
|
<th th:if="${isnew==0}" >字段名称</th>
|
<th th:if="${isnew==0}" >字段类型</th>
|
<th>映射名称</th>
|
<th>映射类型</th>
|
</tr>
|
<tr></tr>
|
</thead>
|
<tbody id="ziDuanMapping">
|
<tr th:each="fields,fieldsStat:${fieldlist}" >
|
<td th:if="${isnew==1 and fields.isPrimaryKey==1}" ><input type="checkbox" name="one" checked="checked" disabled="disabled"/></td>
|
<td th:if="${isnew==1 and fields.isPrimaryKey!=1}" ><input type="checkbox" name="one" checked="checked"/></td>
|
<td th:if="${isnew==0 and fields.isNullAble=='0'}" class="index">
|
<input th:value="${fields.fieldName}" name="fieldName" class="form-control col-sm-9" disabled="disabled"/><span style="color: red;">*</span>
|
</td>
|
<td th:if="${isnew==0 and fields.isNullAble=='1'}" class="index">
|
<input th:value="${fields.fieldName}" name="fieldName" class="form-control col-sm-9" disabled="disabled"/>
|
</td>
|
<td th:if="${isnew==0}" class="index"><input name="fieldType" th:value="${fields.fieldType}" class="form-control col-sm-6" disabled="disabled"/></td>
|
<td class="index">
|
<select th:if="${isnew==0}" class="form-control col-sm-9" id="dataSourceList" name="dataSourceList" onchange="changeFieldType(this);">
|
<option value="">请选择映射字段</option>
|
<option th:each="dataSourceList,dataSourceListStat:${fields.dataSourceList}" th:value="${dataSourceList.ZiDuanType}"
|
th:text="${dataSourceList.ZiDuanName+' | '+dataSourceList.ZiDuanBieMing}" th:selected="(${fields.fieldMappingName}==${dataSourceList.ZiDuanName} or ${fields.fieldName}==${dataSourceList.ZiDuanName})?'true':'false'"></option>
|
</select>
|
<select th:if="${isnew==1}" class="form-control col-sm-9" id="dataSourceList" name="dataSourceList" onchange="changeFieldType(this);" disabled="disabled">
|
<option value="">请选择映射字段</option>
|
<option th:each="dataSourceList,dataSourceListStat:${fields.dataSourceList}" th:value="${dataSourceList.ZiDuanType}"
|
th:text="${dataSourceList.ZiDuanName+' | '+dataSourceList.ZiDuanBieMing}" th:selected="(${fields.fieldMappingName}==${dataSourceList.ZiDuanName} or ${fields.fieldName}==${dataSourceList.ZiDuanName})?'true':'false'"></option>
|
</select>
|
</td>
|
<td class="index"><input id="fieldMappingType" name="fieldMappingType" th:value="${fields.fieldMappingType}" class="form-control col-sm-6" disabled="disabled"/></td>
|
<td class="index"><input type="hidden" id="isNullAble" name="isNullAble" th:value="${fields.isNullAble}" class="form-control col-sm-6" disabled="disabled"/></td>
|
</tr>
|
</tbody>
|
</table>
|
</div>
|
</div>
|
|
|
<div style="height:50px;"></div>
|
<div class="form-actions navbar-fixed-bottom" style="z-index: 0;">
|
<div style="float: left;">
|
<button type="button" id="save" class="btn btn-primary" onclick="save();"><i class="icon-save"></i> 保存</button>
|
</div>
|
</div>
|
|
|
<script th:inline="javascript">
|
/*<![CDATA[*/
|
|
function changeFieldType(obj){
|
var row = $(obj).parent("td").parent("tr");
|
row.find("[name='fieldMappingType']").val(obj.value);
|
}
|
|
function save (){
|
var primarykey =$("#primarykeys").val();
|
var primarykeys = primarykey.split(",");
|
var totalKeys=0;
|
|
var isnew = $("#isnew").val();
|
var fieldlist;
|
if(isnew==1){
|
fieldlist = $("input[name='one']:checked");//选中的复选框
|
}else{
|
fieldlist = $("input[name='fieldMappingType']");
|
}
|
var fieldsArray = new Array();
|
var resourceid=$("#resourceid").val();
|
var fieldconfig = "{\"fieldMappings\":[";
|
var html = ""; //showtablefields 显示的映射字段
|
html += "<table class=\"table table-bordered\">";
|
html += "<thead><tr><th>字段名称</th><th>字段类型</th><th>映射名称</th><th>映射类型</th></tr><tr></tr></thead>";
|
html += "<tbody id=\"ziDuanMapping\">";
|
if(fieldlist.length>0){
|
for(var i=0;i<fieldlist.length;i++){
|
var row = $(fieldlist[i]).parent("td").parent("tr");
|
var fieldName = row.find("[name='fieldName']").val();
|
var fieldType = row.find("[name='fieldType']").val();
|
var isNullAble = row.find("[name='isNullAble']").val();
|
var dataSourceList = row.find("[name='dataSourceList']");
|
var text = dataSourceList.find("option:selected").text();
|
var value = dataSourceList.val();
|
|
for(var j=0;j<primarykeys.length;j++){
|
if(text!='请选择映射字段'){
|
var keytext = text.split(" | ");
|
if(primarykeys[j]==keytext[0]){
|
totalKeys++;
|
}
|
}
|
}
|
|
if(isNullAble=='0' && text=='请选择映射字段'){ //非空
|
alert(fieldName+"字段不能为空,请选择映射字段");
|
return;
|
}
|
if(isnew==0){ //表存在
|
if(value=='字符串' || value=='二进制对象'){
|
if(fieldType.toUpperCase()!='NTEXT' && fieldType.toUpperCase()!='VARCHAR' && fieldType.toUpperCase()!='NVARCHAR' && fieldType.toUpperCase()!='VARCHAR2' && fieldType.toUpperCase()!='NVARCHAR2' && fieldType.toUpperCase()!='CHAR'
|
&& fieldType.toUpperCase()!='NCLOB' && fieldType.toUpperCase()!='BLOB' && fieldType.toUpperCase()!='BINARY' && fieldType.toUpperCase()!='IMAGE'){
|
alert(fieldName+"字段映射类型不匹配");
|
return;
|
}
|
}
|
if(value=='整数'){ //兼容字符串
|
if(fieldType.toUpperCase()!='NUMBER' && fieldType.toUpperCase()!='INT' && fieldType.toUpperCase()!='INTEGER' && fieldType.toUpperCase()!='LONG' && fieldType.toUpperCase()!='SHORT' && fieldType.toUpperCase()!='TINYINT' &&
|
fieldType.toUpperCase()!='VARCHAR' && fieldType.toUpperCase()!='NVARCHAR' && fieldType.toUpperCase()!='VARCHAR2' && fieldType.toUpperCase()!='NVARCHAR2' && fieldType.toUpperCase()!='CHAR'){
|
alert(fieldName+"字段映射类型不匹配");
|
return;
|
}
|
}
|
if(value=='小数'){ //兼容字符串
|
if(fieldType.toUpperCase()!='FLOAT' && fieldType.toUpperCase()!='DECIMAL' && fieldType.toUpperCase()!='DOUBLE' &&
|
fieldType.toUpperCase()!='VARCHAR' && fieldType.toUpperCase()!='NVARCHAR' && fieldType.toUpperCase()!='VARCHAR2' && fieldType.toUpperCase()!='NVARCHAR2' && fieldType.toUpperCase()!='CHAR'){
|
alert(fieldName+"字段映射类型不匹配");
|
return;
|
}
|
}
|
if(value=='时间'){
|
if(fieldType.toUpperCase()!='DATE' && fieldType.toUpperCase()!='DATETIME' && fieldType.toUpperCase()!='TIMESTAMP'){
|
alert(fieldName+"字段映射类型不匹配");
|
return;
|
}
|
}
|
/* if(value=='二进制对象'){
|
if(fieldType.toUpperCase()!='NCLOB' && fieldType.toUpperCase()!='BLOB' && fieldType.toUpperCase()!='BINARY' && fieldType.toUpperCase()!='IMAGE'){
|
alert(fieldName+"字段映射类型不匹配");
|
return;
|
}
|
} */
|
}
|
if(text!='请选择映射字段'){
|
var texts = text.split(" | ");
|
if(fieldsArray.indexOf(texts[0])!=-1){ //存在
|
alert(texts[0]+"映射字段重复.");
|
return;
|
}else{
|
fieldsArray.push(texts[0]);
|
}
|
if($("#tabletype").val()==1){ //属性类型表
|
|
}else{
|
/* if(fieldType=='nvarchar' || fieldType=='varchar' || fieldType=='varchar2' || fieldType=='nvarchar2'){
|
fieldType="text";
|
}
|
if(fieldType=='number' || fieldType=='Integer' || fieldType=='int'){
|
fieldType="long";
|
} */
|
if(value=='字符串'){
|
value="Text";
|
}
|
if(value=='小数'){
|
value="Float";
|
}
|
if(value=='整数'){
|
//查询短整 长整
|
$.ajax({
|
url:'/res/ResManage/ResRegister/selectColumnType',
|
type:'POST',
|
data:{"resourceid":resourceid,"columnName":texts[0]},
|
async:false,
|
dataType:'text',
|
success:function(result){
|
value=result;
|
},
|
error:function(){
|
value="short";
|
}
|
})
|
}
|
if(value=='时间'){
|
value="Date";
|
}
|
if(value=='二进制对象'){
|
value="blob";
|
}
|
}
|
if(isnew==0){
|
fieldconfig += "{ \"fieldName\": \"" + fieldName + "\",\"fieldType\":\""+fieldType+"\",\"fieldMappingName\": \"" + texts[0] + "\",\"fieldMappingType\" : \""+value+"\",\"isNullAble\":\""+isNullAble+"\"},";
|
html += "<tr><td>"+fieldName+"</td><td>"+fieldType+"</td><td>"+texts[0]+"</td><td>"+value+"</td>"
|
}else{
|
fieldconfig += "{ \"fieldName\": \"" + texts[0] + "\",\"fieldType\":\""+value+"\",\"fieldMappingName\": \"" + texts[0] + "\",\"fieldMappingType\" : \""+value+"\",\"isNullAble\":\""+isNullAble+"\"},";
|
html += "<tr><td>"+texts[0]+"</td><td>"+value+"</td><td>"+texts[0]+"</td><td>"+value+"</td>"
|
}
|
}
|
}
|
}
|
if(totalKeys!=primarykeys.length){
|
alert(primarykey+" 中存在未映射的主键!");
|
return;
|
}
|
fieldconfig=fieldconfig.slice(0,fieldconfig.length-1);
|
fieldconfig += "]}";
|
html += "</tbody></table>";
|
window.opener.document.getElementById('isnew').value = isnew;
|
window.opener.document.getElementById('showtablefields').innerHTML = html;
|
window.opener.document.getElementById('tablefields').value = fieldconfig;
|
window.close();
|
}
|
|
/*]]>*/
|
</script>
|