61.员工信息管理Extjs 页面
1.员工信息管理jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript">
var empGrid = new empInfoGridPanel();
tabId = Ext.getCmp('mainTab').getActiveTab().id.split('_')[1];
juage(tabId,"emp",empGrid,"emp");
</script>
<div id="emp"></div>
2.员工信息管理js gridPanel表格
/**
* @author sux
* @time 2011-1-15
* @desc
* 注意各个TabPanel中的id都不要相同,若有相同则造成显示异常
*/
Ext.namespace("hrmsys.employee"); empInfoGridPanel = Ext.extend(Ext.grid.GridPanel,{
id:'empInfo',
constructor:function(){
Ext.QuickTips.init(); empInfoStore = new Ext.data.JsonStore({
url:'emp_list.action',
root:'root',
totalProperty:'totalProperty',
fields:['empId','empName','empSex',
{name:'department',convert:function(v){return v.deptName}},
{name:'job',convert:function(v){return v.jobName}}]
});
//多选按钮
var sm = new Ext.grid.CheckboxSelectionModel();
var number = new Ext.grid.RowNumberer(); empInfoGridPanel.superclass.constructor.call(this,{
viewConfig:{
forceFit: true
},
width:Ext.getCmp('mainTab').getActiveTab().getInnerWidth(),
height:Ext.getCmp('mainTab').getActiveTab().getInnerHeight(),
/**表格高度自适应 document.body.clientHeight浏览器页面高度 start**/
monitorResize:true,
doLayout:function(){
this.setWidth(document.body.clientWidth-205);
this.setHeight(document.body.clientHeight-140);
Ext.grid.GridPanel.prototype.doLayout.call(this);
},
sm:sm,
columns:[
number,sm,
{
header: '员工工号',
dataIndex: 'empId',
align: 'center'
},{
header: '员工姓名',
dataIndex: 'empName',
align: 'center'
},{
header: '员工性别',
dataIndex: 'empSex',
align: 'center',
renderer: function(value){
if(value == 1) return "男";
else return "女";
}
},{
header: '部门名称',
dataIndex: 'department',
align: 'center'
},{
header: '职位',
dataIndex: 'job',
align: 'center'
}],
store:empInfoStore,
//添加遮罩
loadMask:{msg:'数据正在加载中,请稍后!'}, tbar:new Ext.Toolbar({
bodyStyle: 'padding-left: 5px;',
//depart.js中定义了depart
items:['部门:',new depart("员工"),' 条目:',{
// Ext xtype : "combo" 下拉选择框
xtype:'combo',
mode:'local',//加载本地数据,必须加入
store:new Ext.data.SimpleStore({
fields:['name','value'],
data: [["","无"],['empId','工号'],['empName','姓名']]
}),
//下拉框中显示的值
displayField:'value',
//是隐藏的一个值
valueField:'name',
id:'emp_condition',
width:50,
autoLoad:true,
listWidth:50,
//是否可编辑
editable:false,
/*默认值 为query,当输入框有值时下拉列表将根据该值只显示过滤后的列表数据,可设置为all,不执行过滤*/
triggerAction:'all'
},' 内容:',{
xtype:'textfield',
id:'emp_conditionValue',
width:80,
listeners:{
specialkey:function(field, e){//添加回车事件
if(e.getKey()==Ext.EventObject.ENTER){
// Ext.getCmp('empInfo').viewJob;
}
}
}
},{
text: '添加',
handler: this.empAddFn
},{
text: '修改',
handler: this.empUpdateFn
},{
text: '详情',
handler: this.empDetailFn
}]
}), bbar:new PagingToolbar(empInfoStore,20)
}); empInfoStore.load({
params:{
deptId:"",
start:0,
limit:20
}
});
},
//查询
viewJob:function(){
var deptValue = Ext.getCmp('deptValue员工').getValue();
var condition = Ext.getCmp('emp_condition').getValue();
var conditionValue = Ext.getCmp('emp_conditionValue').getValue(); empInfoStore.load({
params: {
deptId: deptValue,
condition: condition,
conditionValue: conditionValue,
start: 0,
limit: 20
}
});
},
empDelFn: function(){
gridDel('empInfo','empId', 'emp_delete.action');
},
//添加员工信息
empAddFn: function(){
var empUpdateWin = new EmpUpdateWin();
empUpdateWin.show();
},
//修改员工信息
empUpdateFn: function(){
var empUpdateWin = new EmpUpdateWin();
empUpdateWin.title = '职员信息修改'; var selectionModel = Ext.getCmp('empInfo').getSelectionModel();
var record = selectionModel.getSelections(); if(record.length!=1){
Ext.Msg.alert('提示','请选择一个');
return;
} var empId = record[0].get('empId');
Ext.getCmp('empForm').getForm().load({
method: 'post',
url: 'emp_intoUpdate.action',
params: {
empId: empId
},
success: function(form, action){
var obj = Ext.util.JSON.decode(action.response.responseText);
Ext.getCmp("deptValue所在部门").setRawValue(obj[0].department.deptName);
Ext.getCmp("jobValue职位").setRawValue(obj[0].job.jobName);
}
})
empUpdateWin.show();
},
empDetailFn: function(){
var empDetailWin = new EmpDetailWin();
var selectionModel = Ext.getCmp('empInfo').getSelectionModel();
var record = selectionModel.getSelections();
if(record.length != 1){
Ext.Msg.alert('提示','请选择一个');
return;
}
var empId = record[0].get('empId');
Ext.getCmp('empDetailId').getForm().load({
url: 'emp_intoUpdate.action',
method: 'post',
params: {
empId: empId
}
})
empDetailWin.show();
}
});
3。添加员工信息弹窗

4.添加员工窗口页面js
EmpUpdateWin = Ext.extend(Ext.Window,{
id:'empUpdateWinId',
constructor:function(){
//添加职员信息
var empForm = new addEmpForm();
EmpUpdateWin.superclass.constructor.call(this, {
model:true,
width: 825,
items: [empForm]
});
}
});
5.
/**
* 添加职员Form
* @author sux
* @param {Object} width
* @memberOf {TypeName}
*/
addEmpForm = Ext.extend(Ext.form.FormPanel,{
id:'empForm',
//url: 'emp_save.action',
//构造方法中的width参数为TabPanel的宽度
constructor:function(width){
width = (width-750)/2;
Ext.QuickTips.init();
var deptObject = new DepartJob("所在部门","emp.department.deptId"); //实例化部门
jobObject = new Job("职位","emp.job.jobId",deptObject); //实例化职位 jobObject.on('expand', function(comboBox){
var deptId = Ext.getCmp("deptValue所在部门").getValue();
this.getStore().load({
params: {
deptId: deptId
}
})
}); var reader = new Ext.data.JsonReader({},[{
name: 'emp.empId', mapping: 'empId'
},{//json时间格式转为ext,time为json中显示的一部分
name: 'emp.empBirth', mapping: 'empBirth.time', dateFormat : 'time', type: 'date'
},{
name: 'emp.empSex', mapping: 'empSex'
},{
name: 'emp.empPost', mapping: 'empPost'
},{
name: 'emp.empBank', mapping: 'empBank'
},{
name: 'emp.empNationality', mapping: 'empNationality'
},{
name: 'emp.empSchool', mapping: 'empSchool'
},{
name: 'emp.empName', mapping: 'empName'
},{
name: 'emp.empTelephone', mapping: 'empTelephone'
},{
name: 'emp.empEmail', mapping: 'empEmail'
},{
name: 'emp.empMobilephone', mapping: 'empMobilephone'
},{
name: 'emp.empIdcard', mapping: 'empIdcard'
},{
name: 'emp.empAccount', mapping: 'empAccount'
},{
name: 'emp.empOrigin', mapping: 'empOrigin'
},{
name: 'emp.empEducation', mapping: 'empEducation'
},{
name: 'emp.empPhoto', mapping: 'empPhoto', convert: function(v){if(v != '')Ext.get('emp_photo').dom.src=v;}
},{
name: 'emp.empNation', mapping: 'empNation'
},{
name: 'emp.empProfession', mapping: 'empProfession'
},{
name: 'emp.empAddress', mapping: 'empAddress'
},{
name: 'emp.department.deptId', mapping: 'department.deptId'
},{
name: 'emp.job.jobId', mapping: 'job.jobId'
}])
addEmpForm.superclass.constructor.call(this,{
//var windowWidth = window.screen.availWidth;获取屏幕宽度
//bodyStyle: 'margin-left:'+width+'px;', //将下面的panel显示在中间
frame: true,
reader: reader,
items:[{
width:768,
html: '<center><h1>员工信息</h1></center><br/>'
},{
//可以用fieldset来进行内部分组
xtype:'fieldset',
title: '个人信息',
defaults:{
bodyStyle: 'padding-right: 30px;'
},
width:768,
layout:'table',//表格布局
labelAlign: 'right',
labelWidth: 60,
frame: true,
layoutConfig: {//3列
columns: 3
},
items:[{
layout:'form',
//columnWidth: .33, // column列布局
defaults:{
xtype: 'textfield',
width: 150
},
items:[{
fieldLabel: '工号',
name: 'emp.empId',
allowBlank: false,
msgTarget: 'side',
blankText: '工号不能为空',
emptyText: '不能为空',
id: 'empAddId',
listeners: {'blur':hrmsys.util.common.empId}
},{
xtype: 'datefield',
fieldLabel: '出生日期',
name: 'emp.empBirth',
format: 'Y-m-d',
allowBlank: false,
editable: false,
msgTarget: 'side',
blankText: '出生日期不能为空',
emptyText: '不能为空'
},{
xtype: 'numberfield', //只能为数字
fieldLabel: 'QQ',
//emptyText: '只能为数字',
name: 'emp.empQq'
},{
fieldLabel: '性别',
xtype: 'panel',
layout: 'column',
bodyStyle: 'padding:0px 0px 10px 30px;',
items:[{
columnWidth: .5,
xtype: 'radio',
boxLabel: '男',
checked: true,
inputValue: 1, //此处特别注意inputValue
name: 'emp.empSex'
},{
columnWidth: .5,
xtype: 'radio',
boxLabel: '女',
inputValue: 0,
name: 'emp.empSex'
}]
},{
xtype: 'numberfield',
fieldLabel: '邮编',
allowBlank: false,
msgTarget: 'side',
blankText: '邮编不能为空',
emptyText: '只能为数字',
regex: /^[1-9]\d{5}$/,
regexText: '邮编格式不正确',
name: 'emp.empPost'
},{
fieldLabel: '开户银行',
allowBlank: false,
msgTarget: 'side',
blankText: '开户银行不能为空',
emptyText: '不能为空',
name: 'emp.empBank'
},{
fieldLabel: '国籍',
allowBlank: false,
msgTarget: 'side',
blankText: '国籍不能为空',
emptyText: '不能为空',
name: 'emp.empNationality'
},{
fieldLabel: '毕业学校',
allowBlank: false,
msgTarget: 'side',
blankText: '毕业学校不能为空',
emptyText: '不能为空',
name: 'emp.empSchool'
}]
},{
layout: 'form',
//columnWidth: .33,
defaults: {
xtype: 'textfield',
width: 150
},
items: [{
fieldLabel: '姓名',
allowBlank: false,
msgTarget: 'side',
blankText: '用户名不能为空',
emptyText: '不能为空',
name: 'emp.empName'
},{
fieldLabel: '电话',
name: 'emp.empTelephone',
msgTarget: 'side',
regex: /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/,
regexText: '电话格式不正确'
},{
fieldLabel: 'e-mail',
emptyText: '不能为空',
allowBlank: false,
blankText: '邮箱不能为空',
vtype: 'email', //自带的邮箱校验
msgTarget: 'side',
vtypeText: '请输入正确的邮箱格式',
name: 'emp.empEmail'
},{
fieldLabel: '手机',
allowBlank: false,
msgTarget: 'side',
blankText: '手机号不能为空',
emptyText: '不能为空',
name: 'emp.empMobilephone',
regex: /(^0?[1][358][0-9]{9}$)/,
regexText: '手机格式不正确'
},{
fieldLabel: '身份证',
allowBlank: false,
msgTarget: 'side',
blankText: '身份证号不能为空',
regex: /^(\d{14}|\d{17})(\d|[xX])$/,
regexText: '身份证格式不正确',
emptyText: '不能为空',
name: 'emp.empIdcard'
},{
xtype: 'numberfield',
fieldLabel: '开户账号',
allowBlank: false,
msgTarget: 'side',
blankText: '账号不能为空',
emptyText: '只能为数字',
name: 'emp.empAccount'
},{
fieldLabel: '籍贯',
allowBlank: false,
msgTarget: 'side',
blankText: '籍贯不能为空',
emptyText: '不能为空',
name: 'emp.empOrigin'
},{
fieldLabel: '学历',
allowBlank: false,
msgTarget: 'side',
blankText: '学历不能为空',
emptyText: '不能为空',
name: 'emp.empEducation'
}]
},{
//rowspan: 5,
layout: 'form',
defaults: {
xtype: 'textfield',
width: 150
},
items: [{
xtype: 'textfield', //注意此处为textfield, inputType: 'image'
fieldLabel: '照片',
inputType: 'image',
width: 130,
height: 125,
id: 'emp_photo',
autoCreate : {
tag : "input",
type : "image",
src : "img/default.gif",
name: 'emp.empPhoto'
//autocomplete: "off"
}
},{
style: 'margin-left: 110px;',
xtype: 'button',
width: 50,
text: '上传照片',
handler: upload
},{
xtype: 'textfield',
fieldLabel: '民族',
allowBlank: false,
msgTarget: 'side',
blankText: '民族不能为空',
emptyText: '不能为空',
name: 'emp.empNation'
},{
xtype: 'textfield',
fieldLabel: '专业',
allowBlank: false,
msgTarget: 'side',
blankText: '专业不能为空',
emptyText: '不能为空',
name: 'emp.empProfession'
}]
},{
colspan: 3,
layout: 'form',
items: [{
xtype: 'textfield',
fieldLabel: '地址',
width: 640,
allowBlank: false,
msgTarget: 'side',
blankText: '地址不能为空',
emptyText: '不能为空',
name: 'emp.empAddress'
}]
}]
},{
xtype: 'fieldset',
title: '部门',
width: 768,
layout: 'column',
defaultType: 'textfield',
defaults: {
labelWidth: 60,
labelAlign: 'right'
},
items: [{
columnWidth: .32,
layout: 'form',
xtype: 'panel',
items: [deptObject]
},{
columnWidth: .32,
layout: 'form',
xtype: 'panel',
items: [jobObject]
}]
},{
xtype: 'panel',
width: 750,
buttonAlign: 'center',
buttons: [{
text: '保存',
handler: function(){
if(!Ext.getCmp('empForm').getForm().isValid()){
return;
}
Ext.getCmp('empForm').getForm().submit({
url: 'emp_save.action',
method: 'post',
waitTitle: '提示',
waitMsg: '正在保存数据...',
success: saveSuccess,
failure: saveFailure,
scope: this,
params: {empPhoto: Ext.get('emp_photo').dom.src}
});
}
},{
text: '关闭',
handler: function(){
//Ext.getCmp('empForm').getForm().reset();
//Ext.get('emp_photo').dom.src = 'img/default.gif';
Ext.getCmp('empUpdateWinId').destroy();
}
}]
}]
});
}
}); //上传窗体显示
upload = function(){
uploadWin = new UploadWin();//实例化上传窗体
uploadWin.show();//显示窗体
} //保存成功操作
//保存成功操作
saveSuccess = function(form, action){
Ext.Msg.confirm('提示', action.result.msg, function(button, text){
Ext.getCmp('empForm').getForm().reset();
Ext.get('emp_photo').dom.src = 'img/default.gif';
if(button == "yes"){
Ext.getCmp('empUpdateWinId').destroy();//销毁窗体
Ext.getCmp("empInfo").getStore().load({
params: {
deptId: "",
start: 0,
limit: 20
}
});
}
});
};
//保存失败操作
saveFailure = function(form, action){
Ext.Msg.alert('提示','连接失败');
}
7. 上传文件
/**
* @author sux
* @date 2011-1-30
* @desc 上传窗体
*/
UploadWin = Ext.extend(Ext.Window,{
id: 'upLoad',
uploadPanel: null,
constructor: function(){
this.uploadPanel = new Ext.form.FormPanel({
fileUpload:true,////允许上传
baseCls: 'x-plain',//作用在面板元素上的CSS样式类 (默认为 'x-panel')
layout: 'form',
labelWidth: 60,
id: 'uploadformPanel',
items: [{
xtype: 'fileuploadfield',//引入插件
//inputType: 'file',
fieldLabel: '上传照片',
//allowBlank: false,
id: 'photo',
name: 'upload',
buttonText: '选择'
}]
}); //调用父类构造方法
UploadWin.superclass.constructor.call(this,{
title: '上传照片',
modal: true,
width: 300,
height: 130,
plain: true,
bodyStyle: 'padding: 15px;',
items:[this.uploadPanel],
buttonAlign: 'center',
buttons:[{
text: '确定',
handler: function(){
Ext.getCmp('uploadformPanel').getForm().submit({
url: 'emp_upload.action',
method: 'post',
waitTitle: '提示',
waitMsg: '正在上传,请稍后...',
success: uploadSuccess,
failure: uploadFailure,
scope: this
});
}
},{
text: '取消',
handler: function(){
Ext.getCmp('uploadformPanel').getForm().reset();
Ext.get('emp_photo').dom.src = 'img/default.gif';
uploadWin.destroy();
}
}]
})
}
});
uploadSuccess = function(form,action){
//console.log('success');
Ext.getCmp('uploadformPanel').getForm().reset();
uploadWin.destroy();
Ext.Msg.alert('提示',action.result.msg,function(){
Ext.getCmp('emp_photo').getEl().dom.src = action.result.path;
});
}
uploadFailure = function(form,action){
//console.log('failure');
Ext.Msg.alert('提示', '连接失败');
};
id为photo为上传路径
8.
package com.hrmsys.action; import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.hrmsys.bean.EmployeeBean;
import com.hrmsys.model.Employee;
import com.hrmsys.model.User;
import com.hrmsys.service.EmpService;
import com.hrmsys.service.JobChangeService;
import com.hrmsys.util.ConditionValidate;
import com.hrmsys.util.CurrentDate;
import com.hrmsys.util.FileExport;
import com.hrmsys.util.SequenceBuilder;
import com.opensymphony.xwork2.ActionContext; public class EmpAction extends BaseAction{
private EmpService empService;
private Employee emp;
private List<EmployeeBean> empBeans;
private JobChangeService jobChangeService;
/**
* 由于dept和job常用,故单独成一js文件
* 但在与struts整合时不便将属性名绑定到name,
* 故此单独定义deptId和jobId属性
*/
private String deptId = null;
private String jobId = null;
private String empPhoto = null;
/**
* 配置文件中的参数会通过setter方法注入
* rePath获取savePath的值
*/
private String rePath = null;
/**
* 查询条目
*/
private String condition;
/**
* 查询内容
*/
private String conditionValue;
/**
* 保存的路径
*/
private String savePath;
/**
* 上传的文件内容
*/
private File upload;
/**
* 保存的文件名
*/
private String uploadFileName;
/**
* 上传的文件种类
*/
private String uploadContentType;
private String empId;
private String ids;
private String start;
private String limit; /************方法**********************************************/
/**
* 清单
*/
public void list(){
String json = null;
json = empService.getByHQL(deptId, condition, conditionValue, start, limit);
this.setStart(null);
this.setLimit(null);
this.out(json);
}
/**
* 保存员工信息
*/
public void save(){
log.info("save start....");
log.info(this.getEmpPhoto());
String msg = "保存失败";
HttpServletResponse response = this.getResponse();
User user = (User)ActionContext.getContext().getSession().get("user");
emp.setEmpPhoto(this.getEmpPhoto());
emp.setEmpAddDate(CurrentDate.getDate());
emp.setEmpAddPerson(user.getUserName());
msg = empService.save(emp);
this.out("{success: true, msg: '"+msg+"'}");
}
/**
* 员工头像上传
*/
public void upload(){
log.info("upload start...");
log.info("uploadFileName="+this.getUploadFileName());
//重命名
String fileName = SequenceBuilder.getSequence()+this.getUploadFileName().substring(this.getUploadFileName().indexOf("."));
String msg = empService.uploadPhoto(this.getSavePath()+"\\"+fileName, this.getUpload());
this.out("{success: true, msg: '"+msg+"', path: '"+this.rePath+"/"+fileName+"'}");
}
/**
* 根据工号判断是否存在此员工
*/
public void isExist(){
String empName = empService.isExistByEmpId(empId);
this.out(empName);
} public void unique(){
String emp = empService.unique(empId);
this.out(emp);
} public void delete(){
String filePath = ServletActionContext.getRequest().getRealPath(savePath);
String msg = empService.delete(ids, filePath);
this.out("{success: true, msg: '"+msg+"'}");
} public void intoUpdate(){
String empJson = empService.listByEmpId(empId);
this.out(empJson);
}
/**
* 详细员工pdf报表预览
*/
public String detailPdfReport(){
empBeans = empService.getEmpList(empId);
return "detailPdf";
}
public String simplePdfReport(){
empBeans = empService.getEmpList(empId);
return "simplePdf";
}
/**
* 导出详细报表pdf
*/
public void detailPdfExport(){
empService.pdfExport(empId, this.getResponse(),"员工详细信息.pdf","detailEmp.jasper");
}
/**
* 导出员工简单信息pdf
*/
public void simplePdfExport(){
empService.pdfExport(empId, this.getResponse(),"员工简单信息.pdf", "simpleEmp.jasper");
}
/**
* 导出员工简单信息Excel
*/
public void detailXlsExport(){
empService.xlsExport(this.getResponse(), "员工信息.xls");
}
/*********getter and setter ***********/
public EmpService getEmpService() {
return empService;
} public void setEmpService(EmpService empService) {
this.empService = empService;
} public String getDeptId() {
return deptId;
} public void setDeptId(String deptId) {
this.deptId = deptId;
} public String getCondition() {
return condition;
} public void setCondition(String condition) {
this.condition = condition;
} public String getConditionValue() {
return conditionValue;
} public void setConditionValue(String conditionValue) {
this.conditionValue = conditionValue;
} public Employee getEmp() {
return emp;
} public void setEmp(Employee emp) {
this.emp = emp;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getSavePath() {
//struts.xml中配置savePath参数,且获取文件夹的真实地址
return ServletActionContext.getRequest().getRealPath(savePath);
}
public void setSavePath(String savePath) {
this.rePath = savePath;
this.savePath = savePath;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getEmpPhoto() {
return empPhoto;
}
public void setEmpPhoto(String empPhoto) {
this.empPhoto = empPhoto;
}
public JobChangeService getJobChangeService() {
return jobChangeService;
}
public void setJobChangeService(JobChangeService jobChangeService) {
this.jobChangeService = jobChangeService;
}
public String getEmpId() {
return empId;
}
public void setEmpId(String empId) {
this.empId = empId;
}
public String getIds() {
return ids;
}
public void setIds(String ids) {
this.ids = ids;
}
public List<EmployeeBean> getEmpBeans() {
return empBeans;
}
public void setEmpBeans(List<EmployeeBean> empBeans) {
this.empBeans = empBeans;
}
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getLimit() {
return limit;
}
public void setLimit(String limit) {
this.limit = limit;
} }
9.
package com.hrmsys.service.impl; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import com.hrmsys.bean.EmployeeBean;
import com.hrmsys.bean.PageBean;
import com.hrmsys.dao.EmployeeDAO;
import com.hrmsys.enums.StaticValue;
import com.hrmsys.model.Department;
import com.hrmsys.model.Employee;
import com.hrmsys.service.EmpService;
import com.hrmsys.util.ConditionValidate;
import com.hrmsys.util.FileExport; public class EmpServiceImpl implements EmpService { private EmployeeDAO empDAO; @Override
public int findNumByDept(Department dept) {
List<Employee> emps = empDAO.findByDept(dept);
if (emps != null)
return emps.size();
return 0;
} public EmployeeDAO getEmpDAO() {
return empDAO;
} public void setEmpDAO(EmployeeDAO empDAO) {
this.empDAO = empDAO;
} @Override
public String getAll(String start, String limit) {
List<Employee> emps = empDAO.findAll(Integer.parseInt(start), Integer.parseInt(limit));
String json = null;
if (emps.size() != 0) {
json = JSONArray.fromObject(emps).toString();
}
int totalProperty = empDAO.findTotal(Employee.class);
return "{totalProperty:"+totalProperty+",root:"+json+"}";
} @Override
public String findByDeptId(String deptId) {
Department dept = new Department();
dept.setDeptId(deptId);
List<Employee> emps = empDAO.findByDept(dept);
String json = JSONArray.fromObject(emps).toString();
return json;
} @Override
public String getByHQL(String deptId, String condition,
String conditionValue, String start, String limit) { PageBean pageBean = empDAO.findByHQL(deptId, condition,
conditionValue, Integer.parseInt(start), Integer.parseInt(limit));
String json = JSONArray.fromObject(pageBean.getRoot()).toString();
return "{totalProperty:"+pageBean.getTotalProperty()+",root:"+json+"}";
} @Override
public String save(Employee emp) {
if (empDAO.saveOrUpdate(emp)) {
return StaticValue.SAVE_SUCCESS;
}
return StaticValue.SAVE_FAILURE;
} @Override
public String uploadPhoto(String savePath, File upload) {
boolean flag = true;
String msg = null;
try {
FileOutputStream fos = new FileOutputStream(savePath);
FileInputStream fis = new FileInputStream(upload);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
} catch (FileNotFoundException e) {
flag = false;
e.printStackTrace();
} catch (IOException e) {
flag = false;
e.printStackTrace();
} finally {
if (flag) {
msg = StaticValue.UPLOAD_SUCCESS;
} else {
msg = StaticValue.UPLOAD_FAILURE;
}
}
return msg;
} @Override
public String isExistByEmpId(String empId) {
Employee emp = empDAO.findByEmpId(empId);
if(null != emp){
return emp.getEmpName();
}
return "";
} @Override
public String unique(String empId) {
Employee emp = empDAO.findByEmpId(empId);
if(null != emp){
return JSONArray.fromObject(emp).toString();
}
return "";
} @Override
public String delete(String ids, String filePath) {
String[] empIds = ids.split(",");
for(String empId : empIds){
Employee emp = empDAO.findByEmpId(empId);
String urlPath = emp.getEmpPhoto();
if(urlPath.indexOf("default.gif") < 0){ //默认图片不删除
int position = urlPath.lastIndexOf("/");
File file=new File(filePath +"\\"+ urlPath.substring(position, urlPath.length()));
if(file.exists() && file.isFile())
file.delete();
}
}
if(empDAO.deleteByEmpId(empIds)){
return StaticValue.DELETE_SUCCESS;
}
return StaticValue.DELETE_FAILURE;
} @Override
public String listByEmpId(String empId) {
Employee emp = empDAO.findByEmpId(empId);
return JSONArray.fromObject(emp).toString();
} public List<EmployeeBean> packageEmp(List<Employee> emps) {
List<EmployeeBean> empBeans = new ArrayList<EmployeeBean>();
for(Employee emp : emps){
EmployeeBean empBean = new EmployeeBean();
empBean.setEmpAccount(emp.getEmpAccount());
empBean.setEmpAddress(emp.getEmpAddress());
empBean.setEmpBank(emp.getEmpBank());
empBean.setEmpBirth(emp.getEmpBirth());
empBean.setEmpEducation(emp.getEmpEducation());
empBean.setEmpEmail(emp.getEmpEmail());
empBean.setEmpId(emp.getEmpId());
empBean.setEmpIdcard(emp.getEmpIdcard());
empBean.setEmpMobilephone(emp.getEmpMobilephone());
empBean.setEmpName(emp.getEmpName());
empBean.setEmpNation(emp.getEmpNation());
empBean.setEmpNationality(emp.getEmpNation());
empBean.setEmpOrigin(emp.getEmpOrigin());
empBean.setEmpPhoto(emp.getEmpPhoto());
empBean.setEmpPost(emp.getEmpPost());
empBean.setEmpProfession(emp.getEmpProfession());
empBean.setEmpQq(emp.getEmpQq());
empBean.setEmpSchool(emp.getEmpSchool());
if(emp.getEmpSex() == 1){
empBean.setEmpSex("男");
}else{
empBean.setEmpSex("女");
}
empBean.setEmpTelephone(emp.getEmpTelephone());
empBean.setJob(emp.getJob().getJobName());
empBean.setDept(emp.getDepartment().getDeptName());
empBeans.add(empBean);
} return empBeans;
} @Override
public void pdfExport(String empId, HttpServletResponse response, String filename, String jasper) {
Employee emp = null;
List<Employee> emps = new ArrayList<Employee>();
if(!"all".equals(empId) && ConditionValidate.isEmpty(empId)){
emp = empDAO.findByEmpId(empId);
emps.add(emp);
}else{
emps = empDAO.findAll(Employee.class);
}
List<EmployeeBean> empBeans = packageEmp(emps);
FileExport fileExport = new FileExport();
fileExport.exportPDF(empBeans, filename,jasper, response); } @Override
public List<EmployeeBean> getEmpList(String empId) {
List<Employee> emps = new ArrayList<Employee>();
Employee emp = empDAO.findByEmpId(empId);
emps.add(emp);
return this.packageEmp(emps);
} @Override
public void xlsExport(HttpServletResponse response, String filename) {
List<Employee> emps = empDAO.findAll(Employee.class);
List<EmployeeBean> empBeans = this.packageEmp(emps);
FileExport fileExport = new FileExport();
fileExport.exportXls(empBeans, filename, response);
} }
61.员工信息管理Extjs 页面的更多相关文章
- 77.招聘信息管理 EXTJS 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- Python函数案例——员工信息管理
员工信息管理 简单的员工信息增删改查程序 表信息 1,Alex Li,22,13651054608,IT,2013‐04‐01 2,Jack Wang,28,13451024608,HR,2015‐0 ...
- 74.资金管理-员工工资配置 extjs 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- 78.员工个人信息保镖页面 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...
- 79.员工薪水报表 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...
- 80.用户管理 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...
- 70.资金管理-福利表管理 Extjs 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- 69.资金管理-税率表管理extjs 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- 76.培训记录信息 Extjs 页面
1.培训记录信息页面jsp <%@ page language="java" import="java.util.*" pageEncoding=&quo ...
随机推荐
- TWaver矢量小试——Android演进路线图
还有半个多月就到春节了,年底相信很多公司都会进行年度总结以及公司发展状况总结,在这过程中难免会用到RoadMap,在这我们也使用TWaver的矢量部分绘制一个Android系统的发展历程.先看效果:什 ...
- sscanf 与 sscanf_s
sscanf 与 sscanf_s 之间的Details sscanf sscanf函数想必大家用的很熟练吧 sscanf函数原型: sscanf(const char* src,format,... ...
- Linux命令学习(2): scp和rsync基本用法与断点续传
版权声明:本文为博主原创文章,未经允许不得转载. 引子 在平常的工作中,我经常需要在远程服务器和本地之间传输文件. 以前我都使用scp命令,直到今天因为网络中断,scp出现了stalled. 因为上传 ...
- 热词解析(9) — hangry
今天给大家介绍一个非常有趣.又超级实用的词!!中文叫"饿极而怒",英文叫... 不知道你有没有这样的经历,当你饿着肚子等着你妈做饭,结果你妈却在麻将桌上不下来,你就越来越饿,越饿越 ...
- const int * 和 int * const 傻傻分不清楚
const int * a和int const *a一样,定义时不是必须初始化,指针可以指向其他变量,但是指向的变量的值不能修改. int * const定义时必须初始化,即必须指明指向哪个变量,定义 ...
- 【Codeforces 442B】Andrey and Problem
[链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...
- Dubbo 是一个分布式服务框架
Dubbo 是一个分布式服务框架-----http://www.cnblogs.com/chanshuyi/p/5144288.html
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array
E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers w ...
- nyoj_127_星际之门(一)_201403282033
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门 ...
- Linux下Ubuntu 操作系统 部署
1.1 先更新系统 环境 更新命令为: apt-get update 1.2 安装jdk 安装JDK命令为:sudo apt-get install o penjdk-7-jdk 1.3 安装tomc ...