📄 useraction.java
字号:
package com.isoftstone.isscrmweb.web.struts.user;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.pontifex.commons.exchange.ExcelImport;
import org.pontifex.commons.exchange.ExcelImportImpl;
import org.pontifex.util.StringUtil;
import com.isoftstone.isscrmweb.web.logic.user.EmpInfoLogic;
import com.isoftstone.isscrmweb.web.mapping.Empinfo;
import com.isoftstone.isscrmweb.web.mapping.Wordbook;
import com.isoftstone.isscrmweb.web.struts.AbstractDynamicAction;
import com.lowagie.text.Cell;
import com.lowagie.text.Chapter;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Section;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;
/**
*
* @author Songzou
*
*/
public class UserAction extends AbstractDynamicAction {
private EmpInfoLogic empInfoLogic;
public void setEmpInfoLogic(EmpInfoLogic empInfoLogic) {
this.empInfoLogic = empInfoLogic;
}
/**
* 员工工号检测
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward usercodecheck(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String message = "";
if(empInfoLogic.checkCanAdd(request.getParameter("empcode"))){
message="1" ;//不存在,可以注册
}else{
message="0" ;//存在,不允许注册
}
response.setCharacterEncoding("GBK");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write(message);
out.flush();
out.close();
return null;
}
// 查询所有用户信息-分页查询
public ActionForward empList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Empinfo empinfo = (Empinfo)fillBean(Empinfo.class);
Wordbook deptword = new Wordbook();
Wordbook addressword = new Wordbook();
empinfo.setPerPageRows(16);
empinfo.setWordbookByDeptid(deptword);
empinfo.setWordbookByWorkid(addressword);
String deptid = request.getParameter("deptid");
String addressid = request.getParameter("addressid");
if(StringUtil.isNotEmpty(deptid)){
deptword.setWordid(deptid);
}
if(StringUtil.isNotEmpty(addressid)){
addressword.setWordid(addressid);
}
Map map = empInfoLogic.getEmpList(empinfo) ;
request.setAttribute("map", map);
return mapping.findForward("userList");
}
// 跳转到添加页面
public ActionForward addUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("map", empInfoLogic.findEmpInfoAdd());
return mapping.findForward("adduser");
}
/**
* 员工添加保存
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward userinfoAddSave(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Empinfo empInfo = (Empinfo) this.fillBean(Empinfo.class);
String deptid = request.getParameter("deptid");
String degreeid = request.getParameter("degreeid");
String jobid = request.getParameter("jobid");
String workid = request.getParameter("workid");
Wordbook word = new Wordbook();
word.setWordid(deptid);
empInfo.setWordbookByDeptid(word);
word = new Wordbook();
word.setWordid(degreeid);
empInfo.setWordbookByDegreeid(word);
word = new Wordbook();
word.setWordid(jobid);
empInfo.setWordbookByJobid(word);
word = new Wordbook();
word.setWordid(workid);
empInfo.setWordbookByWorkid(word);
int num = empInfoLogic.saveEmpInfo(empInfo);
List<String> list = null;
switch(num){
case 0://员工工号已经存在
list = new ArrayList<String>();
list.add(makeHref("userAction.do?method=empList","返回"));
list.add(makeHref("userAction.do?method=addUser","重新添加"));
return viewAndMessage("员工工号已经存在!",list);
case 1://添加成功
list = new ArrayList<String>();
list.add(makeHref("userAction.do?method=empList","返回"));
list.add(makeHref("userAction.do?method=addUser","继续添加"));
return viewAndSuccess("员工信息添加成功,帐户已生成:"+empInfo.getEmpcode(),list);
}
return null;
}
// 跳转到添加页面
public ActionForward queryDetail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String empid = request.getParameter("empid");
request.setAttribute("empInfo", empInfoLogic.findEmpInfoDetail(empid));
return mapping.findForward("userdetail");
}
/**
* 员工信息批量导入请求
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward empImport(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("empImport");
}
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward empImportSave(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ExcelImport fileimport = new ExcelImportImpl(servletContext,request);
System.out.println(fileimport.readExcel());
List<String> list = new ArrayList<String>();
list.add(makeHref("userAction.do?method=empList","看看"));
return viewAndSuccess("成功!",list);
}
/**
* 报表测试 ???????
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward printEmpInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String downloadName = "下载";
downloadName = URLEncoder.encode(downloadName, "utf-8");
response.reset();
response.flushBuffer();
response.setContentType("application/pdf;charset=GBK");
response.setHeader("Content-disposition","inline; filename=foobar.pdf" );
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
ByteArrayOutputStream buffer= new ByteArrayOutputStream();
PdfWriter.getInstance(document, buffer);
//PdfWriter writer =
document.open();
document.add(new Paragraph("Hello World"));
document.add(new Paragraph("First page of the document."));
document.add(new Paragraph("Some more text on the first page with different color and font type.", FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new java.awt.Color(255, 150, 200))));
Paragraph title1 = new Paragraph("Chapter 1",FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new java.awt.Color(0, 0, 255)));
Chapter chapter1 = new Chapter(title1, 1);
chapter1.setNumberDepth(0);
Paragraph title11 = new Paragraph("This is Section 1 in Chapter 1", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new java.awt.Color(255, 0, 0)));
Section section1 = chapter1.addSection(title11);
Paragraph someSectionText = new Paragraph("This text comes as part of section 1 of chapter 1.");
section1.add(someSectionText);
someSectionText = new Paragraph("Following is a 3 X 2 table.");
section1.add(someSectionText);
Table t = new Table(3,2);
t.setBorderColor(new Color(220, 255, 100));
t.setPadding(1);
t.setSpacing(1);
t.setBorderWidth(1);
Cell c1 = new Cell("header1");
c1.setHeader(true);
t.addCell(c1);
c1 = new Cell("Header2");
t.addCell(c1);
c1 = new Cell("Header3");
t.addCell(c1);
t.endHeaders();
t.addCell("1.1");
t.addCell("1.2");
t.addCell("1.3");
section1.add(t);
document.add(chapter1);
document.close();
DataOutput output = new DataOutputStream(response.getOutputStream());
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0;i < bytes.length; i++ ) {
output.writeByte(bytes[i]);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -