常用方法整理

一、动态生成下拉选
(1)

$.ajax({
			type : "POST",
			dataType : "json",
			url : serverUrl.url + '/room_order/queryRoomCode',
			cache : false,
			async : false,
			success : function(result) {
					if (result.code == 0) {
						//判断是否有值
						if (result.data.length>0) {
						     roomCode=result.data;
						 	 //遍历结果生成option
						     var  clientHtml='';
                             $.each(roomCode, function(index, code) {
                             		if(code.room_code!=null&&code.room_code!=''){
                                			clientHtml+='<option value="'+code.room_code+'">'+code.room_code+'</option>';
                               		}
                                })
                                //拼接
                               if(clientHtml!=''){
                                			$("#room_code").html(clientHtml);
                              }	
                            	     			     	
						   }  
						   
					    } else {
					    
					    }
				},
				error : function() {
				}
			});

(2)

	var zyHtml = "";
	$.ajax({
		type : "POST",
		dataType : "json",
		url : serverUrl.url + serverUrl.queryDictionariesByTypeList,
		data:{"dictType":"5"},
		cache : false,
		async : false,
		success : function(result) {
			if (result.returnCode == 0) {
				//遍历添加菜单
				if (result.obj.length > 0) {
					
					zyArray = result.obj;
					///承办单位
					$.each(zyArray, function(index, zyObj) {
						if (zyObj) {
							zyHtml = zyHtml
									+ '<option value="'+zyObj.dict_content+'">'
									+ zyObj.dict_content + '</option>';
						   }
					})
				}
				var speciality_cate = $("#speciality_category");
				if (zyHtml != '') {
					speciality_cate.append(zyHtml);
				}
			} else {

			}
		},
		error : function() {
		}
	});

二、获取复选框选中的值

var a = [];
if(a.length==0){
		layer.msg("密码包含元素至少选择一项!", {
				icon : 0
		});
		return;
}
$("input[name='pwd_include']:checked").each(function(i) {
		a.push($(this).val());
})
var include = a.join("-");

附:动态选中复选框

			var vals = policyInfo.pwd_include.split("-");
			var boxes = document.getElementsByName("pwd_include");
			for(i=0;i<boxes.length;i++){
					for(j=0;j<vals.length;j++){
						     if(boxes[i].value == vals[j]){
						            boxes[i].checked = true;
						            break;
						     }
					}
			}

三、获取下拉选选中的值

var selects = document.getElementById("pwd_bits");
var indexs = selects.selectedIndex;  //选中项的索引
var pwdBits = selects.options[indexs].value;

附:动态选中下拉选选项

var select = document.getElementById("pwd_bits");  
for (var i = 0; i < select.options.length; i++){  
		if (select.options[i].value == policyInfo.pwd_bit){  
				select.options[i].selected = true;  
				break;  
		}  
}

四、获取单选按钮选中的值

var policy_status;
var radio = document.getElementsByName("status"); 
for (i=0; i<radio.length; i++) { 
		if (radio[i].checked) { 
		      policy_status = radio[i].value;
		} 
}

附:动态选中单选按钮

if(policyInfo.policy_status==1){
		 $("#s1").removeAttr("checked");
		 $("#s2").attr("checked","checked");                            
}

五、获取input、textarea的值

var remark = document.getElementById('remark').value;

六、laydate只选择时分

<style>
		.selTime {
		    font-size: 13px;
		    width: 148%;
		    height: 35px;
		    color: #333;
		    margin-left: -15px;
		    margin-top: -10px;
		    border: none;
		    text-align: center;
		}
</style>

$(".layui-input-date").each(function (i) {
         layui.laydate.render({
                   elem: this,
                   trigger: 'click',
                   type:'time',
                   format:"HH:mm",
                   btns: ['clear', 'confirm'],
                   ready: formatminutes,
                   done: function (value, date) {
                           if (res && res.data[i]) {
                                  $.extend(res.data[i], {'timeSel': value})
                           }
                     }
          });
});
//清空秒                   
function formatminutes(date){
           $($(".laydate-time-list li ol")[2]).find("li").remove(); 
 }

七、自定义编辑表格

/* 使得下拉框与单元格刚好合适 */       
td .layui-form-select{
	margin-top: -10px;
	margin-left: -15px;
	margin-right: -15px;
}
.selTime {
    font-size: 13px;
    width: 148%;
    height: 35px;
    color: #333;
    margin-left: -15px;
    margin-top: -10px;
    border: none;
    text-align: center;
}
.selTime1 {
    font-size: 13px;
    width: 80px;
    height: 35px;
    color: #333;
    margin-left: -15px;
    margin-top: -10px;
    border: none;
}
.layui-laydate-content>.layui-laydate-list {
padding-bottom: 0px;
overflow: hidden;
}
.layui-laydate-content>.layui-laydate-list>li{
width:50%
}
.merge-box .scrollbox .merge-list {
padding-bottom: 5px;
}

function getData() {
     	   var  data={
            "project_id":trainProjectId,
          };
     	 layui.use('table', function(){
       	table = layui.table;
       	table.render({
       	    elem: '#baomingTable',
       	    id : "jsSelect",
       	    method : "POST",
    		url : serverUrl.url + "/courseHour/queryCourseHourByProject",
    		where : data
    		,page: true 
		    ,limit:10
		    ,height:450
		    ,even: true
		    ,loading:true
       	    ,cols: [[ 
	       	     {field: 'tearch_name',align:'center', title: '姓名',width:'7%'},
	       	     {field: 'erp_number',align:'center', title: 'ERP编号',width:'8%'},
	       	     {field: 'teachers_category',align:'center', title: '师资类型',width:'8%'},
	       	     {field: 'department', align:'center',title: '工作单位',width:'12%'},
	       	     {field: 'course_type', align:'center',title: '课时类型',width:'8%',sort:false,templet: function (row) {
	       	     	var tem = [];
	       	     //	name='jtcyGxmc'  lay-verify='' lay-search='' lay-filter='sss'
	    			tem.push("<select class='typeSel'>"+
	    			'<option value=""></option>'+
	    			'<option value="0" >监考</option>'+
	    			'<option value="1" >出题</option>'+
	    			'<option value="2" >阅卷</option>'+
	    			'<option value="3" >授课</option>'+
	    			'<option value="4" >编写方案</option></select>');
	       	     	return tem.join('<font></font>')
	       	     }},
	       	     {field: 'course_content',edit: 'text', align:'center',title: '课时内容',width:'10%'},
	       	     {field: 'course_date', align:'center',title: '日期',width:'7%',templet:function (row) {
	       	     	var tem = [];
	       	     	tem.push("<input type='text' autocomplete='off' id='courseDate' name='timeSel1' value=\'" + (row.course_date || '') + "' class='selTime1 layui-input input-date'>");
	       	     	return tem.join('<font></font>')
	       	     }},
	       	     {field: 'course_start_time', align:'center',title: '开始时间',width:'7%',templet:function (row) {
	       	     	var tem = [];
	       	     	tem.push("<input type='text' autocomplete='off' id='startTime' name='timeSel' value=\'" + (row.course_start_time || '') + "' class='selTime layui-input layui-input-date'>");
	       	     	return tem.join('<font></font>')
	       	     }},
	       	     {field: 'course_end_time', align:'center',title: '结束时间',width:'7%',templet:function (row) {
	       	     	var tem = [];
	       	     	tem.push("<input autocomplete='off' type='text' id='endTime' name='timeSel' value=\'" + (row.course_end_time || '') + "' class='selTime layui-input layui-input-date'>");
	       	     	return tem.join('<font></font>')
	       	     }},
	       	     {field: 'course_hour', title: '课时',edit: 'text',align:'center',width:'6%'},
	       	     {field: 'courseRemarks', title: '备注',edit: 'text',align:'center',width:'15%'},
	       	     {fixed: 'right', title:'操作', align:'center',templet:function (row) {
	       	     	var tem = [];
	    			tem.push('<a class="layui-icon" lay-event="del">&#xe640;</a>');
	       	     	return tem.join('<font></font>')
	       	     }}
       	    ]],done: function (res, curr, count) {
            		//日期控件
                    $(".layui-input-date").each(function (i) {
                        layui.laydate.render({
                            elem: this,
                            trigger: 'click',
                            type:'time',
                            format:"HH:mm",
                            btns: ['clear', 'confirm'],
                            ready: formatminutes,
                            done: function (value, date) {
                                if (res && res.data[i]) {
                                    $.extend(res.data[i], {'timeSel': value})
                                }
                            }
                        });
                    });
                    
                    function formatminutes(date){
            			$($(".laydate-time-list li ol")[2]).find("li").remove();  //清空秒 
        			}
                    
                    $(".input-date").each(function (i) {
                        layui.laydate.render({
                            elem: this,
                            trigger: 'click',
                            type:'date',
                            format:"yyyy-MM-dd",
                            done: function (value, date) {
                                if (res && res.data[i]) {
                                    $.extend(res.data[i], {'timeSel1': value})
                                }
                            }
                        });
                    });
                    
                  //  var select = document.getElementById('typeSel'+selectedNum);
                     var selects =$('.typeSel');
                    for(var i = 0; i < count; i++){
                    	var select =selects[i];
                    
    					//alert(res.data[i].course_type);
    					for (var j = 0; j < select.options.length; j++){
	        				if (select.options[j].value == res.data[i].course_type){
	            				select.options[j].selected=true;
	        				}
    					}
    					
    				}
    				layui.form.render();
    				
            }

       	  });
       	  	
       	});
		};
		
		function updateCacheOrForm(tableId, tableCacheId, op){
		   op = op || "form";
		   var divForm = $("#" + tableId).next();
		   var tableCache = table.cache[tableCacheId]; 
		   var trJqs = divForm.find(".layui-table-body tr");
		   trJqs.each(function(){
		    	var trJq = $(this);
		    	var dataIndex = trJq.attr("data-index");
		    	trJq.find("td").each(function(){
		     		var tdJq = $(this);
		     		var fieldName = tdJq.attr("data-field");
		     		//var fieldName = selectJq.eq(0).attr("name");
		     		//更新select数据
		     		var selectJq = tdJq.find("select");
		     		var inputJq = tdJq.find("input");
		     		if(selectJq.length == 1){
		      			if(op == "cache"){
		       				tableCache[dataIndex][fieldName] = selectJq.eq(0).val();
		      			}else if(op == "form"){
		       				selectJq.eq(0).val(tableCache[dataIndex][fieldName])
		      			}
		     		}else if(inputJq.length == 1){
		      			if(op == "cache"){
		       				tableCache[dataIndex][fieldName] = inputJq.eq(0).val();
		      			}else if(op == "form"){
		       				inputJq.eq(0).val(tableCache[dataIndex][fieldName])
		      			}
		     		}
		    	});
		   });
		   return tableCache;
  }
  
		function tdTitle(){
	    
	    	var vfds=updateCacheOrForm("baomingTable", "jsSelect", "cache");
	    	var Jdata = JSON.stringify(vfds);
	    	//var arr = Jdata.split(",");
	    	for(j = 0,len=vfds.length; j < len; j++) {
	    		//var teacherName_tem
 				var courseType_tmp=vfds[i].course_type;
			 	var courseContent_tmp=vfds[i].course_content;
			 	var courseHour_tmp=vfds[i].course_hour;
			 	var courseDate_tmp=vfds[i].course_date;
			 	var startTime_tmp=vfds[i].course_start_time;
			 	var endTime_tmp=vfds[i].course_end_time;
			 	var aa=j+1;
			 	//var remarks_tmp=vfds[i].remarks;
			 	if(courseType_tmp==null||courseType_tmp==undefined||startTime_tmp==""){
			 		layer.msg('第'+aa+"行课时类型不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			 	if(courseContent_tmp==null||courseContent_tmp==undefined||courseContent_tmp==""){
			 		layer.msg('第'+aa+"行课时内容不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			 	if(courseHour_tmp==null||courseHour_tmp==undefined||courseHour_tmp==""){
			 		layer.msg('第'+aa+"行课时不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			 	if(courseDate_tmp==null||courseDate_tmp==undefined||courseDate_tmp==""){
			 		layer.msg('第'+aa+"行日期不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			 	if(startTime_tmp==null||startTime_tmp==undefined||startTime_tmp==""){
			 		layer.msg('第'+aa+"行开始时间不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			 	if(endTime_tmp==null||endTime_tmp==undefined||endTime_tmp==""){
			 		layer.msg('第'+aa+"行结束时间不能为空!", {
						icon : 0
					});
					return;
					//break;
			 	}
			}
    			//console.log('******aaaaaaa*****'+courseType);
	    	
     		//console.log('******aaaaaaa*****'+arr);
     		var data = {
     				"Jdata":Jdata,
     				"courseProjectId":courseProjectId,
     				"userType":user_type
     		};
     		$.ajax({
			type : "POST",
			dataType : "json",
			url : serverUrl.url + "/courseHour/updateCourseHourById",
			data : data,
			cache : false,
			success : function(result) {
				if (result.returnCode == 0) {
					layer.msg('更新成功', {
						icon : 0
					});
					isSave=1;
					isAgree=1;
					$(".layui-laypage-btn").click();
					parent.getData();
				} else {
					layer.msg('<a style="color:red">' + result.reason
							+ '</a>', {
						icon : 2
					});
				}
			},
			  error: function() {
			 
			}  
		});
     
	  //      $(element).attr('title','点击单元格可进行编辑');
	 //   });
	};

八、动态拼接表格

function getData(){
	   var  tableHtml='';
	   $.ajax({
			type: 'POST',
           dataType: 'Json',
           url: serverUrl.url + serverUrl.findStuFileDetail,
           async: false,
           data:{"userId":userId},
           cache : false,
           success: function (result) {
           	if(result.returnCode==0){
           	 var obj = result.obj;
                var user=obj.user;
                //用户基础信息
                $("#stuName").html(user.name);
                $("#orgName").text(user.unit);
                $("#mobile").text(user.mobile);
                $("#address").text(user.contactAddress);
                $("#postion").text(user.position);
                $("#email").text(user.email);
                $("#mz").text(user.nationality);
                $("#sex").text(user.sexStr);
                $("#birthDate").text(user.birthString);
                $("#idCard").text(user.idNumber);
           	 var classVoList=obj.classVoList;
           	  
           	 if(classVoList.length>0){
           		 
    		     $.each(classVoList,function(i,classVo){
    		    	 tableHtml=tableHtml
    		    	 +'<table class="mdt table table-striped jambo_table bulk_action">'
                     +'<tbody>'
                     +'<tr style="text-align:center;height:50px"><td colspan="4" style="font-weight:600;font-size:16px; ">'+classVo.startTime+'-'+classVo.endTime+ "     "+classVo.classmodel.className+'</td></tr>'
                      +'<tr>'
                     +'<td style="width:25%;text-align:center"><label>项目负责人:</label></td>'
                      +' <td id="hostManager" style="width:25%;text-align:center" class="tableInput1">'+classVo.fzr+'</td>'
                      +' <td style="width:25%;text-align:center"><label>班主任:</label></td>'
                       +'<td id="hostManagerPhone" style="width:25%;text-align:center" class="tableInput1">'+classVo.classTeacher+'</td>'
                       +'</tr>'
                       +'<tr style="text-align:center">'
                      +'<td style="width:20%"   style="text-align:right"><label>序号</label></td>'
                      +'<td style="width:47%" colspan="2"  style="text-align:center"><label>考核项目</label></td>'
                      +'<td style="width:33%" style="text-align:center"><label>成绩</label></td>'
                       +'</tr>'
    		    	 var stuGradeList=classVo.stuGradeList;
           	         if(stuGradeList.length>0){
           	    	 //显示考核
           	    	  $.each(stuGradeList,function(j,stu){
           	    		tableHtml=tableHtml +'<tr style="text-align:center">'
                          +'<td style="width:20%"   style="text-align:right">'+stu.number+'</td>'
                          +'<td style="width:47%" colspan="2"  style="text-align:center">'+stu.check_project_id+'</td>'
                          +'<td style="width:33%" style="text-align:center">'+stu.score+'</td>'
                           +'</tr>';
           	    	      })
           	            }
           	      tableHtml=tableHtml+'</tbody></table>'
    		      })
    		     }
           	    $("#tableId").html(tableHtml);
               }
           },
           error: function (){},
	 		complete: function(){}
       });
   }

九、导出

// 导出老师名单列表(xf)
	public void outTeacherList(HttpServletResponse response,String teacherName,String erp_number,String id_number,String phone,String teachers_category,String primary_course,String tearching_areas,String job_title) throws Exception {
		// 查询结果
		/*List<Map<String, String>> list = hibernateDao.queryForListWithSql(SqlFileUtil.get("selectTeacherList"),
				new Object[] {});*/
         String sql=ExportSql.selectTeacherList(teacherName, erp_number, id_number, phone,teachers_category,primary_course,tearching_areas,job_title);
		List<Map<String, String>> list = hibernateDao.queryForListWithSql(sql);
		Calendar now = Calendar.getInstance();
		String fileName = now.get(Calendar.YEAR) + "-" + (now.get(Calendar.MONTH) + 1) + "-"
				+ now.get(Calendar.DAY_OF_MONTH) + java.net.URLDecoder.decode("-教师列表", "UTF-8") + ".xls";
		// 设置响应头,控制浏览器下载该文件
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment; filename=" + new String(fileName.getBytes("GB2312"), "ISO8859-1"));

		HSSFWorkbook workbook = new HSSFWorkbook();
		String outName = "教师名单列表";
		String[] chinaNames = { "姓名", "性别", "身份证号码", "出生日期", "手机号码", "邮箱", "工作单位", "部门", "职位职称", "ERP编号", "授课领域",
				"师资类别", "主讲课程", "简介", "备注" };
		String[] cols = { "tearch_name", "sex", "id_number", "birthdate", "phone", "email", "work_unit", "department",
				"job_title", "erp_number", "tearching_areas", "teachers_category", "primary_course", "introduction",
				"remark" };
		int[] widths = { 15, 10, 25, 20, 20,20, 20, 15, 20, 20,15, 15, 25, 25, 15 };
		List<Map<String, Object>> outInfos = new ArrayList<Map<String, Object>>();
		HashMap<String, Object> rmap = new HashMap<String, Object>();
		rmap.put("list", list);
		List<Map<String, String>> tempList = (List<Map<String, String>>) rmap.get("list");
		for (Map<String, String> temMap : tempList) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put(cols[0], temMap.get("tearch_name"));
			Object sex1 = temMap.get("sex");
			String sex = String.valueOf(sex1);
			if(sex.equals("0")){
				sex="女";
			}else if (sex.equals("1")){
				sex="男";
			}
			map.put(cols[1], sex);
			map.put(cols[2], temMap.get("id_number"));
			map.put(cols[3], temMap.get("birthdate"));
			map.put(cols[4], temMap.get("phone"));
			map.put(cols[5], temMap.get("email"));
			map.put(cols[6], temMap.get("work_unit"));
			map.put(cols[7], temMap.get("department"));
			map.put(cols[8], temMap.get("job_title"));
			map.put(cols[9], temMap.get("erp_number"));
			map.put(cols[10], temMap.get("tearching_areas"));
			map.put(cols[11], temMap.get("teachers_category"));
			map.put(cols[12], temMap.get("primary_course"));
			map.put(cols[13], temMap.get("introduction"));
			map.put(cols[14], temMap.get("remark"));
			outInfos.add(map);
		}

		workbook = new OutExcelUtil().outExcel(workbook, response, chinaNames, cols, outInfos, outName, 0, "", widths);
		OutputStream out = response.getOutputStream();
		workbook.write(out);
		out.flush();
		out.close();

	}

十、下载模板

public void outTeacherModel(HttpServletResponse response) throws Exception {
			// 查询结果
			List<Map<String, String>> list = new ArrayList<Map<String, String>>();
			 Map<String, String> map1 = new HashMap<String, String>();
			 map1.put("tearch_name","例:张三(必填)");
			 map1.put("sex","例:男(必填)");
			 map1.put("id_number","例:340122xxx(必填)");
			 map1.put("birthdate","例:2012.12.10(必填)");
			 map1.put("phone","例:139xxx(必填)");
			 map1.put("email","例:152xx@163.com(必填)");
			 map1.put("work_unit","例:智慧校园(必填)");
			 map1.put("department","例:安全部(必填)");
			 map1.put("job_title","例:主任(必填)");
			 map1.put("erp_number","例:必须为ERP+xxxxxx(必填)");
			 map1.put("tearching_areas","例:哲学(必填)");
			 map1.put("teachers_category","例:1.系统内老师2.系统外老师 3.专职老师(3选一(必填项))");
			 map1.put("primary_course","例:xxxxx(必填)");
			 map1.put("introduction","例:xxxxx(选填)");
			 map1.put("remark","必须严格按照模板填写(选填)");
			 list.add(map1);

			Calendar now = Calendar.getInstance();
			String fileName = now.get(Calendar.YEAR) + "-" + (now.get(Calendar.MONTH) + 1) + "-"
					+ now.get(Calendar.DAY_OF_MONTH) + java.net.URLDecoder.decode("-教师列表模板", "UTF-8") + ".xls";
			// 设置响应头,控制浏览器下载该文件
			response.setContentType("application/vnd.ms-excel");
			response.setHeader("Content-Disposition",
					"attachment; filename=" + new String(fileName.getBytes("GB2312"), "ISO8859-1"));

			HSSFWorkbook workbook = new HSSFWorkbook();
			String outName = "教师列表模板";
			String[] chinaNames = { "姓名", "性别", "身份证号码", "出生日期", "手机号码", "邮箱", "工作单位", "部门", "职位职称", "ERP编号", "授课领域",
					"师资类别", "主讲课程", "简介", "备注" };
			String[] cols = { "tearch_name", "sex", "id_number", "birthdate", "phone", "email", "work_unit", "department",
					"job_title", "erp_number", "tearching_areas", "teachers_category", "primary_course", "introduction",
					"remark" };
			int[] widths = { 25, 15, 30, 25, 25,25, 25, 25, 25, 25, 25, 50, 25, 25, 25 };
			List<Map<String, Object>> outInfos = new ArrayList<Map<String, Object>>();
			HashMap<String, Object> rmap = new HashMap<String, Object>();
			rmap.put("list", list);
			List<Map<String, String>> tempList = (List<Map<String, String>>) rmap.get("list");
			for (Map<String, String> temMap : tempList) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put(cols[0], temMap.get("tearch_name"));
				map.put(cols[1], temMap.get("sex"));
				map.put(cols[2], temMap.get("id_number"));
				map.put(cols[3], temMap.get("birthdate"));
				map.put(cols[4], temMap.get("phone"));
				map.put(cols[5], temMap.get("email"));
				map.put(cols[6], temMap.get("work_unit"));
				map.put(cols[7], temMap.get("department"));
				map.put(cols[8], temMap.get("job_title"));
				map.put(cols[9], temMap.get("erp_number"));
				map.put(cols[10], temMap.get("tearching_areas"));
				map.put(cols[11], temMap.get("teachers_category"));
				map.put(cols[12], temMap.get("primary_course"));
				map.put(cols[13], temMap.get("introduction"));
				map.put(cols[14], temMap.get("remark"));
				outInfos.add(map);
			}

			workbook = new OutExcelUtil().outExcel(workbook, response, chinaNames, cols, outInfos, outName, 0, "", widths);
			OutputStream out = response.getOutputStream();
			workbook.write(out);
			out.flush();
			out.close();

		}

十一、导入

// 批量导入(xf)
	public Map<String, String> importTeacherInfo(Map<String, Object> paramsMap, MultipartFile file) throws Exception {
		String directoryPath = paramsMap.get("directoryPath").toString();
		String creatorId = paramsMap.get("createBy").toString();
		Map<String, String> ret = new HashMap<String, String>();
		List<HashMap<String, String>> lists = new ArrayList<HashMap<String, String>>();
		String exName = "";
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		if (file.getOriginalFilename().lastIndexOf(".") != -1)
			exName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);

		exName = "." + exName.toLowerCase();
		String fileName = uuid + exName;
		File targetFile = new File(directoryPath, fileName);
		// 检测目标文件是否存在,不存在则创建文件夹
		if (!targetFile.exists())
			targetFile.mkdirs();
		file.transferTo(targetFile);
		int type = ExcelUtils.TYPE_XLS;
		if (exName == null) {
			ret.put("success", "1");
		}
		if (exName.equals(".xlsx")) {
			type = ExcelUtils.TYPE_XLSX;
		} else if (exName.equals(".xls")) {

		} else {
			ret.put("success", "1");
		}
		List<String> excelCol = Arrays.asList("姓名", "性别", "身份证号码", "出生日期", "手机号码", "邮箱", "工作单位", "部门", "职位职称", "ERP编号", "授课领域",
				"师资类别", "主讲课程", "简介", "备注");
		List<String> tableCol = Arrays.asList("tearch_name", "sex", "id_number", "birthdate", "phone", "email",
				"work_unit", "department", "job_title", "erp_number", "tearching_areas", "teachers_category",
				"primary_course", "introduction", "remark");
		Integer sexNo = 0;
		String is_system="";
		lists = ExcelUtils.Excel2List(targetFile, type, excelCol, tableCol);
		for (int i = 1; i < lists.size(); i++) {
         
			Map<String, String> map = (Map<String, String>) lists.get(i);
			//String phone = null;
			String tearcherId = GUID.getRandomId();
			String tearch_name = map.get("tearch_name");
			/*
			 * if (tearchName == null || "".equals(tearchName)) { ret.put("msg",
			 * "姓名为空"); return ret; }
			 */
			String sex = map.get("sex");
			if (sex == null || "".equals(sex)) {
				ret.put("msg", "性别为空");
				return ret;
			}
			if ("男".equals(sex)) {
				sexNo = 1;
			} else if ("女".equals(sex)) {
				sexNo = 0;
			}
			String id_number = map.get("id_number");
			if (id_number == null || "".equals(id_number)) {
				ret.put("msg", "身份证号码为空");
				return ret;
			}
		
			 String birthdate = map.get("birthdate");
			
			if (birthdate == null || "".equals(birthdate)) {
				ret.put("msg", "出生日期为空");
				return ret;
			}
			 
			
			
			String phone = map.get("phone");
			if (phone == null || "".equals(phone)) {
				ret.put("msg", "手机号码为空");
				return ret;
			}
			String email = map.get("email");
			if (email == null || "".equals(email)) {
				ret.put("msg", "邮箱为空");
				return ret;
			}
			String work_unit = map.get("work_unit");
			if (work_unit == null || "".equals(work_unit)) {
				ret.put("msg", "工作单位为空");
				return ret;
			}
			String department = map.get("department");
			if (department == null || "".equals(department)) {
				ret.put("msg", "工作部门为空");
				return ret;
			}
			String job_title = map.get("job_title");
			if (job_title == null || "".equals(job_title)) {
				ret.put("msg", "职位职称为空");
				return ret;
			}
			String erp_number = map.get("erp_number");
			if (erp_number == null || "".equals(erp_number)) {
				ret.put("msg", "ERP编号为空");
				return ret;
			}
			String tearching_areas = map.get("tearching_areas");
			if (tearching_areas == null || "".equals(tearching_areas)) {
				ret.put("msg", "授课领域为空");
				return ret;
			}
			String teachers_category = map.get("teachers_category");
			if (teachers_category == null || "".equals(teachers_category)) {
				ret.put("msg", "师资类别为空");
				return ret;
			}
			if(teachers_category.equals("系统内老师")){
				is_system="0";
			}else if(teachers_category.equals("系统外老师")){
				is_system="1";
			}else if(teachers_category.equals("专职老师")){
				is_system="2";
			}
			String primary_course = map.get("primary_course");
			if (primary_course == null || "".equals(primary_course)) {
				ret.put("msg", "主讲课程为空");
				return ret;
			}
			String introduction = map.get("introduction");
			
			String remark = map.get("remark");
			
			// 存入数据库
			hibernateDao.executeSqlUpdate(SqlFileUtil.get("addNewTeacher1"),
					new Object[] { is_system,tearcherId, tearch_name, sexNo, id_number, birthdate, phone, email, work_unit,
							department, job_title, teachers_category, tearching_areas, erp_number, introduction, remark,
							1, creatorId,primary_course });
		}
		ret.put("success", "1");
		return ret;
	}

十二、关联条件可为空sql

SELECT A.*,B.*,C.name as auditerName,A.status as courseStatus,D.name as class_teacher,E.name as bjfzr,F.name as writer,DATE_FORMAT(A.create_date,'%Y-%m-%d') as createDate,DATE_FORMAT(A.audit_date,'%Y-%m-%d') as audit_date FROM t_project_class_hour A left join t_train_project B on A.project_id=B.train_project_id left join t_sys_user C on IF(A.audit_id is NULL,1=0,A.audit_id = C.user_id) left join t_sys_user F on A.applicant_id=F.user_id left join  t_sys_user D on 1=1 left join  t_sys_user E on 1=1  WHERE A.applicant_id=' ' AND A.is_exist=1 AND A.create_date >= DATE_FORMAT('"+startTime+"','%Y-%m-%d %H:%i:%s') and DATE_FORMAT('"+endTime+"','%Y-%m-%d %H:%i:%s') > A.create_date and B.project_principal_id=D.user_id and B.project_principal_id=E.user_id ORDER BY A.create_date DESC LIMIT 0,10
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值