public void savePersonnelNotice() throws IOException {
HttpServletResponse response = getResponse();
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
String backString = "0";// 添加成功
String noticeTitle = getRequest().getParameter("noticetitle");// 公告标题
String noticeContent = getRequest().getParameter("noticecontent");// 公告内容
int yesOrNoStick = Integer.parseInt(getRequest().getParameter("yesOrNoStick"));// 是否置顶
String noticeId = getRequest().getParameter("noticeid");// 公告id
int yesOrNoNews=Integer.parseInt(getRequest().getParameter("yesOrNoNews"));//是否最新
String uploadFiles=getRequest().getParameter("uploadFiles");//获取附件名
Integer personnelNoticeTypeId=Integer.parseInt(getRequest().getParameter("personnelNoticeType"));//人事公告类别id
String queryString;
if (noticeTitle != null && noticeTitle != "") {
if (noticeId != null && noticeId != "") {// 判断是否重复
queryString = "from PersonnelNotice where noticeTitle='"+ noticeTitle + "'and id!='" + noticeId + "'";
} else {
queryString = "from PersonnelNotice where noticeTitle='"+ noticeTitle + "'";
}
List<PersonnelNotice> personnellist = searchManager.find(queryString);
// 判断置顶是否超过5个
String stickGreaterThanFive = "from PersonnelNotice where yesOrNoStick=1";
if (personnellist.size() > 0) {// 如果存在
backString = "1"; // 人事公告名称已经存在
}else {// 如果不存在
if (noticeId == null||noticeId.equals("")) {
if(((searchManager.find(stickGreaterThanFive).size()) >= Constants.INTFIVE)&&(yesOrNoStick==1)){
backString = "4";
}else{
personnelnotice = new PersonnelNotice();
backString = "2";// 添加
}
} else {//是编辑
queryString = "from PersonnelNotice where id='" + noticeId+ "'";
List<PersonnelNotice> personnelnoticelist = searchManager.find(queryString);
if (personnelnoticelist.size() > 0) {
personnelnotice = personnelnoticelist.get(0);
if(((searchManager.find(stickGreaterThanFive).size()) >= Constants.INTFIVE)&&(yesOrNoStick==1)
&&(personnelnotice.getYesOrNoStick().equals(Constants.TWO))){
backString = "4";
}else{
backString = "3";
}
}
}
if(!backString.equals("4")){
personnelnotice.setNoticeTitle(noticeTitle);
personnelnotice.setNoticeContent(noticeContent);
personnelnotice.setCreateDate(new Date());
personnelnotice.setYesOrNoStick(yesOrNoStick);
personnelnotice.setYesOrNoNews(yesOrNoNews);
personnelnotice.setEnclosureName(uploadFiles);
PersonnelNoticeType personnelNoticeType=personnelNoticeTypeManager
.getPersonnelNoticeTypeById(personnelNoticeTypeId);
personnelnotice.setPersonnelNoticeType(personnelNoticeType);
searchManager.saveOrUpdate(personnelnotice);
}
}
}
PrintWriter out = response.getWriter();
out.print(backString);
out.close();
}
public String addPersonnelNoticeType(String id,String userName) {
String backString="";
if(checkPersonnelNoticeTypeNameExist(id,userName).equals("1")){
//用户名已经存在
return "1";
}else{
if(id==null || id.equals("")){
personnelNoticeType=new PersonnelNoticeType();
backString="2";
}else{
personnelNoticeType=personnelNoticeTypeDao.getPersonnelNoticeTypeByid(Integer.parseInt(id));
backString="3";
}
personnelNoticeType.setName(userName);
personnelNoticeType.setCreateTime(new Date());
personnelNoticeTypeDao.savePersonnelNoticeType(personnelNoticeType);
return backString;
}
}