📄 humanfileaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.y2.hr.human.file.web.action;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;
import com.y2.hr.config.filesecondkind.bean.ConfigFileSecondKind;
import com.y2.hr.config.filethirdkind.bean.ConfigFileThirdKind;
import com.y2.hr.config.major.bean.ConfigMajor;
import com.y2.hr.config.users.bean.Users;
import com.y2.hr.human.file.bean.HumanFile;
import com.y2.hr.human.file.biz.HumanFileBiz;
import com.y2.hr.human.file.web.form.HumanFileForm;
import com.y2.hr.salary.standard.bean.SalaryStandard;
import com.y2.hr.salary.standard.biz.StandardBiz;
/**
* 人事档案相关操作
*/
public class HumanFileAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* 业务对象
*/
private HumanFileBiz humanBiz = null;
public void setHumanBiz(HumanFileBiz humanBiz) {
this.humanBiz = humanBiz;
}
// 2008-2-7肖鹏,张杰修改 start
private StandardBiz standardBiz = null;
public void setStandardBiz(StandardBiz standardBiz) {
this.standardBiz = standardBiz;
}
// 2008-2-7肖鹏,张杰修改 end
/**
* 每页要显示的记录条数(由spring配置文件注入)
*/
private int pageSize;
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/**
* 执行添加人事档案操作
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward doAddHumanFile(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HumanFileForm frm = (HumanFileForm) form;
HumanFile bean = new HumanFile();
try {
BeanUtils.copyProperties(bean, frm);
bean.setRegistTime(new Date());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
// 2008-2-7肖鹏,张杰修改 start
double salary_sum = this.standardBiz.getSalarySum(frm
.getSalaryStandardId());
long salarySum = (long) salary_sum;
bean.setSalarySum(salarySum);
// 2008-2-7肖鹏,张杰修改 end
boolean flag = humanBiz.add(bean);
if (flag) {
String hql = "select h.humanId from HumanFile h where h.humanIdCard = ? ";
// 身份证号唯一,可以得到ID号
String humanId = humanBiz.uniqueSearch(hql, frm.getHumanIdCard())
.toString();
request.setAttribute("msg", "<font color='red'>登记成功</font>");
request.setAttribute("humanId", humanId);
return mapping.findForward("uploadImg");
} else {
// 添加失败则重新添加
request.setAttribute("msg", getAlert("插入失败,请检查身份证号码是否已经存在!"));
return mapping.findForward("load");
}
}
/**
* 此方法为addHumanFile页面的DropDownList标签加载相关参数
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward toLoadOptions(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 设置添加标识,以表明该页第一次已经加载过了
request.setAttribute("isPostBack", true);
this.setHumanSource(request);
return mapping.findForward("add");
}
/**
* 验证身份证号码是否存在(不允许有相同的身份证号码)
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws UnsupportedEncodingException
* @throws IOException
*/
public ActionForward toCheckExists(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException, IOException {
String cardId = request.getParameter("cardId");
String hql = "from HumanFile where humanIdCard = '" + cardId + "'";
HumanFile hf = (HumanFile) humanBiz.uniqueSearch(hql, null);
PrintWriter out = new PrintWriter(new OutputStreamWriter(response
.getOutputStream(), "gbk"));
if (hf != null) {
out.print("true");
} else {
out.print("false");
}
out.flush();
out.close();
return null;
}
/**
* 加载未复核的人事资源档案并分页
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward toLoadUncheckHumanFile(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
int pageId = 1;
try {
pageId = Integer.parseInt(request.getParameter("currPageId"));
} catch (Exception e) {
pageId = 1;
}
String hql = "from HumanFile where (checkStatus is NULL or checkStatus = 0) and (humanFileStatus is null or humanFileStatus =1 )";
String hql1 = "select count(h.hufId) from HumanFile h where (humanFileStatus is null or humanFileStatus =1 ) and (h.checkStatus is NULL or h.checkStatus = 0)";
int recordCount = Integer.parseInt(humanBiz.uniqueSearch(hql1, null)
.toString());
List humanList = humanBiz.paginationSearch(pageSize, pageId, hql);
request.setAttribute("recordCount", recordCount);
request.setAttribute("humanList", humanList);
request.setAttribute("currPageId", pageId);
request.setAttribute("pageSize", pageSize);
return mapping.findForward("checkHumanFile");
}
/**
* 加载选定的人事资源档案
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward toWaitHumanFile(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
int id = 0;
try {
id = Integer.parseInt(request.getParameter("id"));
} catch (Exception e) {
return mapping.findForward("checkOk");
}
String hql = "from HumanFile where hufId = " + id;
HumanFile hf = (HumanFile) humanBiz.uniqueSearch(hql, new Object[] {});
request.setAttribute("human", hf);
setHumanSource(request);
return mapping.findForward("toAudit");
}
/**
* 复核人事资源档案
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward doCheckHumanFile(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
HumanFileForm hff = (HumanFileForm) form;
HumanFile human = new HumanFile();
try {
BeanUtils.copyProperties(human, hff);
human.setCheckStatus((short) 1);
String username = this.getUserName(request);
human.setChecker(username);
human.setCheckTime(new Date());
humanBiz.modify(human);
request.setAttribute("msg", getAlert("复核成功!"));
return mapping.findForward("checkOk");
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
/**
* 上传文件或附件
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward doUpload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String humanId = request.getParameter("humanId");
String type = request.getParameter("type");
HumanFileForm frm = (HumanFileForm) form;
FormFile file = frm.getHumanPictures();
int size = file.getFileSize();
if (size > 5242880) {
request.setAttribute("msg", getAlert("上传的文件太大"));
request.setAttribute("humanId", humanId);
return mapping.findForward("uploadFail");
}
String postfixName = file.getFileName().substring(
file.getFileName().lastIndexOf("."));
// 上传文件名:humanId.后缀名
String fileName = humanId + postfixName;
String filePath = null;
if ("1".equals(type)) {
filePath = servlet.getServletContext().getRealPath("/upload/img");
} else {
filePath = servlet.getServletContext()
.getRealPath("/upload/attach");
}
// 上传
OutputStream os = null;
try {
os = new FileOutputStream(filePath + "/" + humanId + postfixName);
os.write(file.getFileData());
os.flush();
if ("1".equals(type)) {
String hql = "update HumanFile set humanPicture = ? where humanId = ?";
humanBiz.update(hql, fileName, humanId);
} else {
String hql = "update HumanFile set attachmentName = ? where humanId = ?";
humanBiz.update(hql, fileName, humanId);
}
request.setAttribute("msg", getAlert("上传成功"));
return mapping.findForward("uploadOk");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
/**
* 重新上传照片或附件
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward doReupload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String humanId = request.getParameter("humanId");
String type = request.getParameter("type");
HumanFileForm frm = (HumanFileForm) form;
FormFile file = frm.getHumanPictures();
int size = file.getFileSize();
if (size > 5242880) {
request.setAttribute("msg", getAlert("上传的文件太大"));
request.setAttribute("humanId", humanId);
return mapping.findForward("uploadFail");
}
String postfixName = file.getFileName().substring(
file.getFileName().lastIndexOf("."));
// 上传文件名:humanId.后缀名
String fileName = humanId + postfixName;
String filePath = null;
if ("1".equals(type)) {
filePath = servlet.getServletContext().getRealPath("/upload/img");
} else {
filePath = servlet.getServletContext()
.getRealPath("/upload/attach");
}
// 上传
OutputStream os = null;
try {
os = new FileOutputStream(filePath + "/" + humanId + postfixName);
os.write(file.getFileData());
os.flush();
if ("1".equals(type)) {
String hql = "update HumanFile set humanPicture = ? where humanId = ?";
humanBiz.update(hql, fileName, humanId);
} else {
String hql = "update HumanFile set attachmentName = ? where humanId = ?";
humanBiz.update(hql, fileName, humanId);
}
request.setAttribute("msg", getAlert("上传成功"));
return mapping.findForward("reuploadOk");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
/**
* 加载级联选项
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward toLoadLevel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String id = request.getParameter("id");
int level = Integer.parseInt(request.getParameter("level"));
String hql = null;
// 1 代表要加载二级机构
if (1 == level) {
hql = "from ConfigFileSecondKind where firstKindId = " + id;
}
// 2 代表要加载三级机构
else if (2 == level) {
hql = "from ConfigFileThirdKind where secondKindId = " + id;
}
// 3 代表要加载职位名称
else if (3 == level) {
hql = "from ConfigMajor where majorKindId =" + id;
}
List levelList = humanBiz.search(hql);
PrintWriter out = null;
try {
out = new PrintWriter(new OutputStreamWriter(response
.getOutputStream(), "gbk"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 传递XML
response.setContentType("text/xml;charset=GBK");
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
xml.append("<levels>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -