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 ...
随机推荐
- vue-cli的项目加入骨架屏
在原生APP中我们经常可以看到,打开app时候,内容还没出来,app会被别的内容替代,这样很好的提升了用户体验.那么在webApp中,我们如何避免白屏的尴尬情况呢?可以通过 vue-skeleton- ...
- jquery 五星评价(图片实现)
1111 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- 队列的头函数使用C++
queue queue模板类的定义在<queue>头文件中. 与stack模板类很相似,queue模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的 ...
- x shell 连接不上本地虚拟机
登陆虚拟机服务器 输入ipconfig查看ip 地址(如果提示命令不存在,输入 ip addr) 输出结果中看标记处是否出现ip地址.我的打开后这里是没有地址的 然后输入 vi /etc/syscon ...
- java一维数组的声明、初始化及排序
public class TestArray { public static void main(String[] args) { /** 数组声明及动态初始化 int a[] = new int[a ...
- language support图标消失
在控制台下输入sudo apt-get install language-selector-gnome即可
- 关于python字典中文显示的处理办法
最近工作中遇到字典包含中文,显示\uxxxx的问题,怎么转换都无法输入正常的中文:{"gc": "\u4eba\u751f\u7f8e\u597d", &quo ...
- Keil uVision “已停止工作”
之前一直受这个问题的困扰,但是因为只是下载程序,下载镜像文件完事就算了.随便keil挂掉. 今天要调试程序,发现开启调试keil就挂掉了,烦. 解决办法参见: http://218.244.144.1 ...
- Spring MVC_Hello World
[Hello World] 步骤: (1)加入jar包, (2)在web.xml中配置DispatcherServlet, (3)加入Spring MVC的配置文件, (4)编写处理请求的处理器,并标 ...
- js中匿名函数的N种写法
匿名函数没有实际名字,也没有指针,怎么执行? 关于匿名函数写法,很发散~ +号是让函数声明转换为函数表达式.汇总一下 最常见的用法: 代码如下: (function() { alert('water ...