IBaseService:
添加实体:Serializable add(Object entity);
添加实体集合:void add(Collection entity);
添加/修改实体:void addOrModify(Object entity);
添加/修改实体集合:void addOrModify(Collection entity);
删除实体:void delete(Object entity);
根据实体类型和实体ID删除实体:void delete(Class entityClass, Serializable id);
删除实体集合:void deleteMore(Collection collection);
根据实体类型和实体ID集合删除多个实体:void deleteMore(Class entityClass, Collection<String> ids);
修改实体:void modify(Object entity);
根据实体ID和实体类型查找实体对象:Object query(Class entityClass, Serializable id);
根据查询语句执行查询,返回所有结果:List query(String queryString);
根据查询语句和参数表执行查询,返回所有结果:List query(String queryString, Map parMap) ;
根据查询语句和参数值执行查询,返回所有结果:List query(String queryString, Object... values) ;
根据查询语句,从指定位置查找若干条连续记录:List query(String queryString, int firstResult, int maxResults);
根据查询语句和参数表,从指定位置查找若干条连续记录:List query(String hql, Map parMap, int firstResult, int maxResults);
执行最多返回一条结果的查询语句,返回该对象:Object queryUnique(String queryString);
根据查询语句和参数表,执行最多返回一条结果的查询语句,返回该对象:Object queryUnique(String queryString, Map parMap) ;
根据查询语句和参数值执行查询:Object queryUnique(String queryString, Object... values) ;
获得查询结果的记录条数:public long count(String hql);public Long count(String hql, Map parMap);
public void execute(String hql); public void execute(String hql, Map parMap); public void execute(String hql, Object... values);
interface IExpertService extends IBaseService:
添加专家:String addExpert(Expert expert);
删除专家:void deleteExperts(List<String> expertids);
组装学科信息:String(学科代码加名称) getDiscipline(String discipline(学科代码));
设置参评和退评:void setReview(List<String> expertids(专家id), int label(参评状态0退评,1参评), String notReviewerReason(退评原因));
获取评价等级,下拉框:Map fetchTalentLevel();
根据高校代码生成专家清单:String(压缩包路径) createExpertZip12(String universityCode(高校代码));
按高校导出专家库:String(压缩包路径) createExpertZip(String universityCode);
根据模版导出专家库:InputStream exportExcel(String universityCode(按高校导出,如果等于null表示导入所有高校的专家)); InputStream exportExcel();
interface IFinanceService extends IBaseService:
经费核算初始化: Map init(int year, double planFee, double youthFee);
根据比例宏观核算:Map checkByRate(Map initMap, Map setMap);
List initCheckById(Map dataMap, String disType, String area, String proType);
Map checkById(Map dataMap, List<String> idsList1, List<String> idsList2, String disType, String area, String proType, Double planFee, Double youthFee);
List initCheckZcById(Map dataMap, String disType);
Map checkZcById(Map dataMap, List<String> idsList, String disType);
Boolean finish(Map dataMap);
BaseService implements IBaseService:
Serializable add(Object entity) { return baseDao.add(entity);}
add(Collection collection) {for (Object entity : collection) { baseDao.add(entity);}}
addOrModify(Object entity) {baseDao.addOrModify(entity);}
addOrModify(Collection collection) {for (Object entity : collection) {baseDao.addOrModify(entity); }}
delete(Object entity) { baseDao.delete(entity); }
delete(Class entityClass, Serializable id) {baseDao.delete(entityClass, id);}
删除多条记录:deleteMore(Collection collection) { for (Object entity : collection) { baseDao.delete(entity); }}
删除多条记录:deleteMore(Class entityClass, Collection<String> entityIds) {for (String entityId : entityIds) {baseDao.delete(entityClass, entityId);}}
modify(Object entity) {baseDao.modify(entity);}
query(Class entityClass, Serializable id) {return baseDao.query(entityClass, id);}
List query(String queryString) {return baseDao.query(queryString);}
List query(String queryString, Map paraMap) {return baseDao.query(queryString, paraMap);}
List query(String queryString, Object... values) {return baseDao.query(queryString, values);}
List query(String queryString, int firstResult, int maxResults) {return baseDao.query(queryString, firstResult,maxResults); }
List query(String queryString, Map paraMap, int firstResult, int maxResults) { return baseDao.query(queryString, paraMap, firstResult, maxResults);}
Object queryUnique(String queryString) {return baseDao.queryUnique(queryString);}
Object queryUnique(String queryString, Map paraMap) {return baseDao.queryUnique(queryString, paraMap);}
Object queryUnique(String queryString, Object... values) { return baseDao.queryUnique(queryString, values);}
long count(String hql) { return baseDao.count(hql);}
Long count(String hql, Map parMap) {return baseDao.count(hql, parMap);}
void execute(String hql) {baseDao.execute(hql);}
void execute(String hql, Map parMap) {baseDao.execute(hql, parMap);}
void execute(String hql, Object... values) {baseDao.execute(hql, values);}
class ExpertService extends BaseService implements IExpertService:
String addExpert(Expert expert) {String expertId = (String) this.add(expert);return expertId;}
群删专家:void deleteExperts(List<String> expertIds) {if (expertIds != null) {for (int i = 0; i < expertIds.size(); i++) {this.delete(Expert.class, expertIds.get(i));}}}
组装学科信息:String getDiscipline(String discipline) {
// map对象中用于value存学科
String value = "";
if (discipline != null) {
// 拆分后的学科代码
List<String> disids = new ArrayList<String>();
discipline = discipline.replaceAll("\\s+", "");
// 临时
String disvalue = "";
// 学科值
List<Object> disvas;
// 将学科代码组装成list
do {
if (discipline.indexOf(";") < 0) {// 没有了
disvalue = discipline;
disids.add(disvalue);
break;
} else {
disvalue = discipline.substring(0, discipline.indexOf(";"));
discipline = discipline.substring(discipline.indexOf(";") + 1);
disids.add(disvalue);
}
} while (!discipline.isEmpty());// 直到为空
// 遍历disids找到其名称并拼接为一个字符串,以逗号隔开
if (!disids.isEmpty()) {// 如果学科不为空
String test ="select s.code, min(s.name) from SystemOption s where s.code = '" + disids.get(0) + "'";// 测试
for (int j = 1; j < disids.size(); j++) {
test += " or s.code = '" + disids.get(j) + "'";
}
test += " group by s.code";
disvas = this.query(test);
if (disvas != null && !disvas.isEmpty()) {
Object[] o;
int disSize = disvas.size();
for (int j = 0; j < disSize-1; j++ ) {//除去最后一个
o = (Object[]) disvas.get(j);
value += o[0].toString() + o[1].toString() + ";";
}
o = (Object[]) disvas.get(disSize-1);//最后一个,不需要分号
value += o[0].toString() + o[1].toString();
}else{
value = discipline;//如果没有,则返回原数字
}
}
}
return value;
}
设置专家参评状态
* @param expertids待操作的专家ID
* @param label参评状态0退评,1参评:
public void setReview(List<String> expertIds, int label, String notReviewerReason) {
if (expertIds == null || label != 0 && label != 1) {
return;
}
Map application = ActionContext.getContext().getApplication();
Integer defaultYear = (Integer) application.get("defaultYear");
for (int i = 0; i < expertIds.size(); i++) {
Expert expert = (Expert) this.query(Expert.class, expertIds.get(i));
expert.setIsReviewer(label);
expert.setReason(notReviewerReason);//设置退评原因
if (label == 0) {// 如果是退评,删除当前年评审项目的信息
Map paraMap = new HashMap();
paraMap.put("defaultYear", defaultYear);
paraMap.put("reviewerId", expert.getId());
List<GeneralReviewer> prs = this.query("select pr from GeneralReviewer pr where pr.year = :defaultYear and pr.reviewer.id = :reviewerId", paraMap);
for (GeneralReviewer pr : prs) {
this.add(new GeneralReviewerUpdate(pr, 0, 1));
this.delete(pr);
}
}
}
}
public Map fetchTalentLevel(){
Map map = new LinkedHashMap();
List list = this.query("select distinct e.rating from Expert e order by e.rating asc");
for (Object object : list) {
map.put((String)object, (String)object);
}
return map;
}
根据高校代码生成专家清单
* @param universityCode 高校代码
* @return 压缩包路径
public String createExpertZip12(String universityCode) {
String realPath = ServletActionContext.getServletContext().getRealPath("/");
try {
University university = (University) query(University.class, universityCode);
String destFolder = "data/expert/archive/" + universityCode + "/" + universityCode + university.getName() + "专家表";
//生成目录
FileTool.mkdir_p(realPath + destFolder);
FileUtils.copyFile(new File(realPath + "data/expert/template/support.dll"), new File(realPath + destFolder + "/suppot.dll"));
FileUtils.copyFile(new File(realPath + "data/expert/template/expert.xls"), new File(realPath + destFolder + "/" + universityCode + university.getName() + "专家表.xls"));
FileUtils.copyFile(new File(realPath + "data/expert/template/readme.doc"), new File(realPath + destFolder + "/专家表使用说明.doc"));
FileUtils.copyFile(new File(realPath + "data/expert/template/expert.xls"), new File(realPath + destFolder + "/专家表模板.xls"));
try {
InputStream inp = new FileInputStream(realPath + destFolder + "/专家表模板.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
row.getCell(0).setCellValue(row.getCell(0).getStringCellValue().replace("专家表", university.getName() + "专家表"));
FileOutputStream fileOut = new FileOutputStream(realPath + destFolder + "/专家表模板.xls");
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
String destFile = realPath + destFolder + "/" + universityCode + university.getName() + "专家表.xls";
fillExpertExcel(universityCode, university.getName(), destFile);
// Zip打包
ZipUtil.zip(realPath + "data/expert/archive/" + universityCode, realPath + "data/expert/archive/" + universityCode + university.getName() + "专家表.zip");
// 删除临时文件夹
FileTool.rm_fr(realPath + "data/expert/archive/" + universityCode);
return destFolder + universityCode + university.getName() + "专家表.zip";
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@SuppressWarnings("unchecked")
public void fillExpertExcel(String universityCode, String universityName, String filePath) {
List<SystemOption> soList = query(" select so from SystemOption so where so.standard = ? ", "[GBT13745-2009]");
Map<String,String> map = new HashMap<String, String>();
for(int i = 0; i < soList.size(); i++) {
map.put(soList.get(i).getCode(), soList.get(i).getName());
}
List<Expert> expertList = query(" select e from Expert e where e.universityCode = ? order by e.department asc, e.name asc ", universityCode);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
InputStream inp = new FileInputStream(filePath);
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row;
row = sheet.getRow(0);
row.getCell(0).setCellValue(row.getCell(0).getStringCellValue().replace("专家表", universityName + "专家表"));
System.out.println("expertList.size() " + expertList.size());
for(int i = 0; i < expertList.size(); i++) {
Expert expert = expertList.get(i);
row = sheet.createRow(2 + i);
row.createCell(0).setCellValue(expert.getName());
row.createCell(1).setCellValue(expert.getGender());
row.createCell(2).setCellValue(expert.getBirthday() == null ? "" : df.format(expert.getBirthday()));
//row.createCell(3).setCellValue(expert);
//row.createCell(4).setCellValue(expert);
row.createCell(5).setCellValue(expert.getIdCardNumber() == null ? "" : "身份证");
row.createCell(6).setCellValue(expert.getIdCardNumber());
row.createCell(7).setCellValue(expert.getJob());
row.createCell(8).setCellValue(universityName);
row.createCell(9).setCellValue(expert.getDepartment());
//row.createCell(9).setCellValue(expert);
row.createCell(11).setCellValue(expert.getOfficePhone());
row.createCell(12).setCellValue(expert.getOfficePostcode());
//row.createCell(12).setCellValue(expert);
row.createCell(14).setCellValue(expert.getHomePhone());
//row.createCell(14).setCellValue(expert);
//row.createCell(15).setCellValue(expert);
row.createCell(17).setCellValue(expert.getEmail());
row.createCell(18).setCellValue(expert.getMobilePhone());
//row.createCell(18).setCellValue(expert);
row.createCell(20).setCellValue(expert.getOfficeAddress());
//row.createCell(20).setCellValue(expert);
//row.createCell(21).setCellValue(expert);
row.createCell(23).setCellValue(expert.getDegree());
row.createCell(24).setCellValue(expert.getSpecialityTitle());
row.createCell(25).setCellValue(expert.getLanguage());
row.createCell(26).setCellValue(expert.getIsDoctorTutor());
//row.createCell(26).setCellValue();
//row.createCell(27).setCellValue(expert);
row.createCell(29).setCellValue(initDiscipline(map, expert.getDiscipline()));
//row.createCell(29).setCellValue(expert);
row.createCell(31).setCellValue(expert.getResearchField());
//row.createCell(31).setCellValue(expert);
row.createCell(33).setCellValue(expert.getPartTime());
//row.createCell(33).setCellValue(expert);
//row.createCell(34).setCellValue("一般");
row.createCell(36).setCellValue(expert.getAward());
row.createCell(37).setCellValue(expert.getMoeProject());
row.createCell(38).setCellValue(expert.getNationalProject());
}
FileOutputStream fileOut = new FileOutputStream(filePath);
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
HibernateBaseDao extends HibernateDaoSupport implements IHibernateBaseDao:
Serializable add(Object entity) {return getHibernateTemplate().save(entity);}
addOrModify(Object entity) { getHibernateTemplate().saveOrUpdate(entity);}
delete(Object entity) {Object persistentEntity = getHibernateTemplate().merge(entity);getHibernateTemplate().delete(persistentEntity);}
delete(Class entityClass, Serializable id) {Object persistentEntity = getHibernateTemplate().get(entityClass, id);getHibernateTemplate().delete(persistentEntity);}
modify(Object entity) {getHibernateTemplate().update(entity);}
Object query(Class entityClass, Serializable id) {return getHibernateTemplate().get(entityClass, id);}
List query(String queryString) {return getHibernateTemplate().find(queryString);}
List query(String queryString, Map paraMap) {return query(queryString, paraMap, null, null);}
List query(final String queryString, Object... values) {return getHibernateTemplate().find(queryString, values);}
List query(String queryString, Integer firstResult, Integer maxResults) {return query(queryString, null, firstResult, maxResults);}
List query(final String queryString, final Map paraMap, final Integer firstResult, final Integer maxResults) {
// System.out.println(queryString);
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery(queryString);
if (paraMap != null) {
query.setProperties(paraMap);
}
if (firstResult != null) {
query.setFirstResult(firstResult);
}
if (maxResults != null) {
query.setMaxResults(maxResults);
}
return query.list();
}
});
}
Object queryUnique(String queryString) {return queryUnique(queryString, new HashMap());}
Object queryUnique(final String queryString, final Map paraMap) {
return getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery(queryString);
if (paraMap != null) {
query.setProperties(paraMap);
}
return query.uniqueResult();
}
});
}
Object queryUnique(final String queryString, final Object... values) {
return getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery(queryString);
for (int position = 0; position < values.length; position++) {
query.setParameter(position, values[position]);
}
return query.uniqueResult();
}
});
}
long count(String queryString) {return count(queryString, null);}
long count(final String queryString, final Map paraMap) {
String queryStringLowerCase = queryString.toLowerCase();
String countQueryString = "select count(*) " + queryString.substring(queryString.indexOf("from"));
if (queryStringLowerCase.contains("group by") || queryStringLowerCase.contains("distinct")) {
return query(countQueryString, paraMap).size();
} else {
return (Long) queryUnique(countQueryString, paraMap);
}
}
void execute(String statement) {execute(statement, new HashMap());}
execute(final String statement, final Map paraMap) {
// System.out.println(statement);
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery(statement);
if (paraMap != null) {
query.setProperties(paraMap);
}
query.executeUpdate();
return null;
}
});
}
void execute(final String statement, Object... values) {getHibernateTemplate().bulkUpdate(statement, values);}
flush() {getHibernateTemplate().flush();}
clear() {getHibernateTemplate().clear();}
boolean contains(Object entity) {return getHibernateTemplate().contains(entity);}
evict(Object entity) {getHibernateTemplate().evict(entity);}
Object merge(Object entity) {return (Object)getHibernateTemplate().merge(entity);}
persist(Object entity) {getHibernateTemplate().persist(entity);}
refresh(Object entity) {getHibernateTemplate().refresh(entity);}
Iterator iterate(String queryString) { return getHibernateTemplate().iterate(queryString);}
Iterator iterate(String queryString, Object... values) {return getHibernateTemplate().iterate(queryString, values);}
Object execute(HibernateCallback callback) {return getHibernateTemplate().execute(callback);}
interface IBaseDao {
public Serializable add(final Object entity);
public void addOrModify(final Object entity);
public void delete(final Object entity);
public void delete(final Class entityClass, final Serializable id);
public void modify(final Object entity);
public Object query(final Class entityClass, final Serializable id);
public List query(final String queryString);
public List query(final String queryString, final Map paraMap);
public List query(final String queryString, Object... values);
public List query(final String queryString, final Integer firstResult, final Integer maxResults);
public List query(final String queryString, final Map paraMap, final Integer firstResult, final Integer maxResults);
public Object queryUnique(final String queryString);
public Object queryUnique(final String queryString, final Map paraMap);
public Object queryUnique(final String queryString, Object... values);
public long count(final String queryString);
public long count(final String queryString, final Map paraMap);
public void execute(final String statement);
public void execute(final String statement, final Map paraMap);
public void execute(final String statement, Object... values);
interface IHibernateBaseDao extends IBaseDao {
public void flush();
public void clear();
public boolean contains(Object entity);
public void evict(Object entity);
public Object merge(Object entity);
public void persist(Object entity);
public void refresh(Object entity);
public Iterator iterate(String queryString);
public Iterator iterate(String queryString, Object... values);
public Session _getSession();
public void _releaseSession(Session session);
public Object execute(HibernateCallback callback);
class JdbcDao:
List<String[]> query(String sql) {
return jdbcTemplate.query(sql, new ResultSetExtractor<List<String[]>>() {
public List<String[]> extractData(ResultSet rs) throws SQLException {
int columnNumber = rs.getMetaData().getColumnCount();
List res = new ArrayList();
while(rs.next()) {
String[] objs = new String[columnNumber];
for (int i = 0; i < columnNumber; i++) {
objs[i] = rs.getString(i + 1);
}
res.add(objs);
}
return res;
}
});
}
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
SqlBaseDao extends HibernateDaoSupport implements IBaseDao {
public Serializable add(Object entity) {
throw new RuntimeException("未实现的方法");
}
public void addOrModify(Object entity) {
throw new RuntimeException("未实现的方法");
}
public void delete(Object entity) {
throw new RuntimeException("未实现的方法");
}
public void delete(Class entityClass, Serializable id) {
throw new RuntimeException("未实现的方法");
}
public void modify(Object entity) {
throw new RuntimeException("未实现的方法");
}
public Object query(Class entityClass, Serializable id) {
throw new RuntimeException("未实现的方法");
}
public List query(String queryString) {
return query(queryString, null, null, null);
}
public List query(String queryString, Map paraMap) {
return query(queryString, paraMap, null, null);
}
public List query(String queryString, Object... values) {
throw new RuntimeException("未实现的方法");
}
public List query(String queryString, Integer firstResult, Integer maxResults) {
return query(queryString, null, firstResult, maxResults);
}
public List query(final String queryString, final Map paraMap, final Integer firstResult, final Integer maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
//difference from HibernateBaseDao
Query query = session.createSQLQuery(queryString);
if (paraMap != null) {
query.setProperties(paraMap);
}
if (firstResult != null) {
query.setFirstResult(firstResult);
}
if (maxResults != null) {
query.setMaxResults(maxResults);
}
return query.list();
}
});
}
public Object queryUnique(String queryString) {
return queryUnique(queryString, new HashMap());
}
public Object queryUnique(final String queryString, final Map paraMap) {
return getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
//difference from HibernateBaseDao
Query query = session.createSQLQuery(queryString);
if (paraMap != null) {
query.setProperties(paraMap);
}
return query.uniqueResult();
}
});
}
public Object queryUnique(String queryString, Object... values) {
throw new RuntimeException("未实现的方法");
}
public long count(String queryString) {
return count(queryString, null);
}
public long count(String queryString, Map paraMap) {
String countQueryString = "select count(*) from (" + queryString + ")";
BigDecimal cnt = (BigDecimal) queryUnique(countQueryString, paraMap);
return cnt.longValue();
}
public void execute(String statement) {
execute(statement, new HashMap());
}
public void execute(String statement, Object... values) {
throw new RuntimeException("未实现的方法");
}
public void execute(final String statement, final Map paraMap) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createSQLQuery(statement);
if (paraMap != null) {
query.setProperties(paraMap);
}
query.executeUpdate();
return null;
}
});
}
}