⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deptserviceimpl.java

📁 本源码为教学管理信息系统
💻 JAVA
字号:
package com.wygl.xtgl.service;

import java.util.List;

import net.sf.hibernate.HibernateException;

import com.wygl.service.AbstractService;
import com.wygl.xtgl.domain.Department;

public class DeptServiceImpl extends AbstractService implements DeptService{   
	/**查询信息*/
	public List queryList()throws Exception{
		try {
			return dbDao.queryObjects("from Department as dept where dept.dwjb <> '0'");			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**查询对象*/
	public Object queryById(String id)throws Exception{
		try {
			return dbDao.queryObjectById(Department.class,id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**删除信息*/
	public String delete(List ids)throws Exception{
		try {
			if(ids==null||ids.size()==0)	return "false";
			for(int i=0;i<ids.size();i++){
				String  hql = "from Employee as e where e.department.dwdm='"+ids.get(i)+"'";
				List list = (List)dbDao.queryObjects(hql);
				if(list.size()>0) return "false";
			}
			dbDao.deleteObjects(Department.class,ids);
			return "true";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "true";
	}
   	/**保存信息*/
	public String save(Object obj)throws Exception{
		Department dept=(Department)obj;
		try{
			if (checkRepeat(dept) <= 0 ) {//校验录入内容是否重复
				if(dept.getDwdm()==null || dept.getDwdm().equals("")){
					dept.setDwdm(getMaxCode());
					dbDao.addObject(dept);
				}else{
					dbDao.updateObject(dept);
				}
			}else{
    			return "false";
    		}
	    }catch (HibernateException e) {
	        return "error";
	    }
	    return "true";
	}
	/*提取最大号*/
	public String getMaxCode() throws Exception{
		try{
			//找出当前最大号	
			String maxCode = (String)dbDao.queryObjects("select max(dept.dwdm) from Department as dept ").get(0);
			String curCode;
			if (maxCode.length() == 2) {
				curCode = "001";
			}else{
				String code_temp = maxCode;
				System.out.println("Ttttttttt=="+maxCode);
				curCode = Integer.toString(Integer.valueOf(code_temp).intValue() + 1);
				if (curCode.length() == 1) {
					curCode = "00"+curCode;
				}else if (curCode.length() == 2) {
					curCode = "0"+curCode;
				}
			}
			return curCode;
	    }catch (HibernateException e) {
	        return "error";
	    }
	}
	/**校验输入重复*/
	public int checkRepeat(Object obj) throws Exception {
		try {
			Department dept=(Department)obj;
			String str = "from Department as dept where dept.dwmc ='"+dept.getDwmc()+"'";
			if(dept.getDwdm()==null || dept.getDwdm().equals("")){
				return dbDao.queryObjectsCount(str);
			}else{
				return dbDao.queryObjectsCount(str+" and dept.dwdm <> '"+dept.getDwdm()+"'");    	
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		} 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -