📄 affichedao.java
字号:
package com.oa.module.pub.affiche;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import com.oa.util.ToolUtil;
import com.oa.util.XPage;
public class AfficheDAO {
private JdbcTemplate jdbcTemplate;
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public List getAffiche() {
String sql = " select a.*,use.uname from taffiche a" +
" left join tuser use on use.uno=a.funo" +
" where astate='1' order by asend_time desc";
try {
List list = this.jdbcTemplate.queryForList(sql);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public Map getAfficheById(int aid) {
String sql = " select a.*,use.uname,u.uname as fname from taffiche a" +
" left join tuser u on u.uno=a.funo" +
" left join tuser use on use.uno=a.uno" +
" where a.aid="+aid;
try {
Map map =this.jdbcTemplate.queryForMap(sql);
return map;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public XPage getAfficheList(String type,String atitle, String begintime, String endtime, int currentPage, int count) {
XPage page=new XPage();
//开始设置xpage
page.setCurrentPage(currentPage);
page.setCount(count);
Session session = null;
String hql = "from Taffiche a where 1=1";
String path = "/oa/affiche.do?";
if(type.equals("query")){
path = path + "method=query&";//显示给用户看
}else{
path = path + "method=editlist&";
}
if(atitle!=null&&!atitle.trim().equals("")){
hql = hql + " and atitle like :title";
path = path + "atitle="+atitle+"&";
}
if(begintime!=null&&!begintime.trim().equals("")&&endtime!=null&&!endtime.trim().equals("")){
hql = hql + " and (asend_time between :begin and :end )";
path = path + "begin="+begintime+"&end="+endtime+"&";
}
if(begintime!=null&&!begintime.trim().equals("")&&endtime==null){//只有一个数据
hql = hql + " and asend_time= :begin";
path = path + "begin="+begintime+"&";
}
if(begintime==null&&endtime!=null&&!endtime.trim().equals("")){//只有一个数据
hql = hql + " and asend_time=:end";
path = path + "end="+endtime+"&";
}
System.out.println(path);
page.setPath(path);
hql = hql+" order by asend_time desc";
try {
session = this.sessionFactory.openSession();
Query query = session.createQuery(hql);
if(atitle!=null&&!atitle.trim().equals("")){
query.setParameter("title","%"+atitle+"%");
}
if(begintime!=null&&!begintime.trim().equals("")&&endtime!=null&&!endtime.trim().equals("")){
query.setParameter("begin",begintime);
query.setParameter("end",endtime);
}
if(begintime!=null&&!begintime.trim().equals("")&&endtime==null){//只有一个数据
query.setParameter("begin",begintime);
}
if(begintime==null&&endtime!=null&&!endtime.trim().equals("")){//只有一个数据
query.setParameter("end",endtime);
}
//获取总记录数
int allcount=query.list().size();
page.setAllCount(allcount);
//得到分页显示数据
query.setFirstResult((currentPage-1)*count);
query.setMaxResults(count);
List list = query.list();
page.setList(list);
} catch (Exception e) {
e.printStackTrace();
}
return page;
}
public boolean addAffiche(final AfficheForm afficheForm) {
String sql =" insert into taffiche (aid,atitle,acontent,affixname,affixpath,asend_time,areal_time,funo,amemo)"+
" values(seq_t_affiche.nextval,?,?,?,?,?,?,?,?)";
try {
this.jdbcTemplate.update(sql,new PreparedStatementSetter(){
public void setValues(PreparedStatement pstm) throws SQLException {
// TODO 自动生成方法存根
pstm.setString(1,afficheForm.getAtitle());
pstm.setString(2,afficheForm.getAcontent());
pstm.setString(3,afficheForm.getAffixname());
pstm.setString(4,afficheForm.getAffixpath());
pstm.setString(5,afficheForm.getAsendTime());
pstm.setString(6,afficheForm.getArealTime());
pstm.setString(7,afficheForm.getUno());
pstm.setString(8,afficheForm.getAmemo());
}
});
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据插入出错了");
return false;
}
}
public boolean updateAffiche(AfficheForm afficheForm) {
String sql =" update taffiche set atitle=?,acontent=?,affixname=?,affixpath=?,areal_time=?,amemo=?"+
" where aid=?";
try {
this.jdbcTemplate.update(sql,new Object[]{afficheForm.getAtitle(),afficheForm.getAcontent(),afficheForm.getAffixname(),
afficheForm.getAffixpath(),afficheForm.getArealTime(),afficheForm.getAmemo(),new Integer(afficheForm.getAid())});
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据修改出错了");
return false;
}
}
public boolean deleteAfficheById(int aid) {
String sql =" delete from taffiche where aid=?";
try {
this.jdbcTemplate.update(sql,new Object[]{new Integer(aid)});
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据删除出错了");
return false;
}
}
public String getFilePath(String sql) {
try {
String path = (String)this.jdbcTemplate.queryForObject(sql,String.class);
return path;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public List getNotAudit() {
String sql = " select a.*,use.uname from taffiche a" +
" left join tuser use on use.uno=a.funo" +
" where astate='0' order by asend_time desc";
try {
List list = this.jdbcTemplate.queryForList(sql);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean auditAfficheById(int aid, String flag) {
String sql =" update taffiche set astate=? where aid=?";
try {
this.jdbcTemplate.update(sql,new Object[]{flag,new Integer(aid)});
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据修改出错了");
return false;
}
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void renovateDataBase() {
//取出原始数据
String sql = "select aid,asend_time,aregu_time from taffiche ";
try {
List list = this.jdbcTemplate.queryForList(sql);
for (int i = 0; i < list.size(); i++) {
Map map = (Map)list.get(i);
String sendTime = (String) map.get("asend_time");
String regulate = (String) map.get("aregu_time");
int aid = Integer.parseInt(map.get("aid").toString());
int minute = ToolUtil.parseInt(regulate);
String date = ToolUtil.plusTime(sendTime,minute);
String nowdate = ToolUtil.getNowDate();
if (date.compareTo(nowdate)<0){//超过规定时间
//改变审核状态为已通过
String sql2 = "update taffiche set astate=1 where aid=? and astate=0";
this.jdbcTemplate.update(sql2,new Object[]{new Integer(aid)});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -