busiuserdao.java

来自「用JAVA环境开发的人力资源管理系统」· Java 代码 · 共 130 行

JAVA
130
字号
package com.liyu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.liyu.beans.ContractInfo;
import com.liyu.beans.PersonBaseInfo;
import com.liyu.beans.PersonResourceInfo;


public class BusiUserDao extends JdbcDaoSupport{
	private static final String GET_PERSONBASEINFO_SQL = "SELECT * FROM PERSON_BASE_INFO";
	private static final String GET_PERSONRESOURCEINFO_SQL = "SELECT * FROM PERSON_RESOURCE_INFO WHERE PERSON_NAME=?";
	private static final String GET_CONTRACTINFO_SQL = "SELECT * FROM CONTRACT_INFO WHERE CONTRACT_CHARGE=?";
	
	private static final String DEL_PERSONBASEINFO_SQL = "DELETE FROM PERSON_BASE_INFO WHERE PERSON_NAME=?";
	private static final String DEL_PERSONRESOURCEINFO_SQL = "DELETE FROM PERSON_RESOURCE_INFO WHERE PERSON_NAME=? AND PERSON_JOBS=?";
	private static final String DEL_CONTRACTINFO_SQL = "DELETE FROM CONTRACT_INFO WHERE CONTRACT_CHARGE=? AND CONTRACT_TITLE=?";
//	
//	public static final String SAXFLG ="F";
//	private static final String SAXNAME= "女";
//	
	public static final String JOBSFLG ="SalesManager";
	private static final String JOBSNAME= "销售经理";
	public static final String JOBSFLG1 ="Manager";
	private static final String JOBSNAME1= "总经理";
//	public static final String DEPARTFLG ="SalesDepartmentOne";
//	private static final String DEPARTNAME= "试剂部";
	public List getPersonBaseInfo(){
		return(List) this.getJdbcTemplate().query(GET_PERSONBASEINFO_SQL,new personBaseInfoListExtractor());
		//return null;
	}
	private static class personBaseInfoListExtractor implements ResultSetExtractor {
		public Object extractData(ResultSet rs) throws SQLException,
				DataAccessException {
			PersonBaseInfo personBaseInfo = new PersonBaseInfo();
			List list = new ArrayList();
			while(rs.next()) {
				personBaseInfo = new PersonBaseInfo();			
				personBaseInfo.setPersonName(StringUtils.defaultString(rs.getString("PERSON_NAME")));
				personBaseInfo.setPersonSax(StringUtils.defaultString(rs.getString("PERSON_SAX")));
				personBaseInfo.setPersonBrith(StringUtils.defaultString(rs.getString("PERSON_BRITH")));
				personBaseInfo.setPersonEntryDate(StringUtils.defaultString(rs.getString("PERSON_ENTRY_DATE")));
//				if (personBaseInfo.getPersonSax().equals(SAXFLG)){
//				    personBaseInfo.setPersonSax(SAXNAME);
//				}else{
//				    personBaseInfo.setPersonSax("男");
//				}
				list.add(personBaseInfo);
			}
			return list;
		}
	}
	
	public PersonResourceInfo getPersonResourceInfo(String person_name){
		return (PersonResourceInfo)this.getJdbcTemplate().query(GET_PERSONRESOURCEINFO_SQL,new Object[]{person_name}, new personResourceInfoptExtractor());
	}
	private static class personResourceInfoptExtractor implements ResultSetExtractor {

		public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
			if (!rs.next()) {
				return null;
			}

			PersonResourceInfo personResourceInfo = new PersonResourceInfo();
			
			personResourceInfo.setPersonDepart((StringUtils.defaultString(rs.getString("PERSON_DEPART"))));
			personResourceInfo.setPersonJobs ((StringUtils.defaultString(rs.getString("PERSON_JOBS"))));
			personResourceInfo.setPersonName(StringUtils.defaultString(rs.getString("PERSON_NAME")));
			
//			if (personResourceInfo.getPersonDepart().equals(DEPARTFLG)){
//			    personResourceInfo.setPersonDepart(DEPARTNAME);
//			}else{
//			    personResourceInfo.setPersonDepart("仪器部");
//			}
			if (personResourceInfo.getPersonJobs().equals(JOBSFLG)){
			    personResourceInfo.setPersonJobsName(JOBSNAME);
			}else if (personResourceInfo.getPersonJobs().equals(JOBSFLG1)){
			    personResourceInfo.setPersonJobsName(JOBSNAME1);
			}else{
			    personResourceInfo.setPersonJobsName("销售人员");
			}
			return personResourceInfo;
		}
	}
	
	
	public ContractInfo getContractInfo(String person_name){
		return (ContractInfo)this.getJdbcTemplate().query(GET_CONTRACTINFO_SQL,new Object[]{person_name},new contractInfoptExtractor());
		
	}
	private static class contractInfoptExtractor implements ResultSetExtractor {

		public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
			if (!rs.next()) {
				return null;
			}

			ContractInfo contractInfo = new ContractInfo();
			
			contractInfo.setContractCharge(StringUtils.defaultString(rs.getString("CONTRACT_CHARGE")));
			contractInfo.setContractContent(StringUtils.defaultString(rs.getString("CONTRACT_CONTENT")));
			contractInfo.setContractTitle(StringUtils.defaultString(rs.getString("CONTRACT_TITLE")));
			return contractInfo;
		}
	}
	
	public int delPersonBaseInfo(String PERSON_NAME){
		return this.getJdbcTemplate().
		update(DEL_PERSONBASEINFO_SQL,new Object[]{PERSON_NAME});
	}
	
	public int delPersonResourceInfo(String PERSON_NAME,String PERSON_JOBS){
		return this.getJdbcTemplate().
		update(DEL_PERSONRESOURCEINFO_SQL,new Object[]{PERSON_NAME,PERSON_JOBS});
	}
	
	public int delContractInfo(String CONTRACT_CHARGE,String CONTRACT_TITLE){
		return this.getJdbcTemplate().
		update(DEL_CONTRACTINFO_SQL,new Object[]{CONTRACT_CHARGE,CONTRACT_TITLE});
	}
}

⌨️ 快捷键说明

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