zoukankan      html  css  js  c++  java
  • 61.员工信息管理Extjs 页面

    1.员工信息管理jsp

    1 <%@ page language="java" pageEncoding="UTF-8"%>
    2 <script type="text/javascript">
    3     var empGrid = new empInfoGridPanel();
    4     tabId = Ext.getCmp('mainTab').getActiveTab().id.split('_')[1];
    5     juage(tabId,"emp",empGrid,"emp");
    6 </script>
    7 <div id="emp"></div>

    2.员工信息管理js  gridPanel表格

      1 /**
      2  * @author sux
      3  * @time 2011-1-15
      4  * @desc 
      5  * 注意各个TabPanel中的id都不要相同,若有相同则造成显示异常
      6  */
      7 Ext.namespace("hrmsys.employee");
      8 
      9 empInfoGridPanel = Ext.extend(Ext.grid.GridPanel,{
     10     id:'empInfo',
     11     constructor:function(){
     12         Ext.QuickTips.init();
     13         
     14         empInfoStore = new Ext.data.JsonStore({
     15             url:'emp_list.action',
     16             root:'root',
     17             totalProperty:'totalProperty',
     18             fields:['empId','empName','empSex',
     19                     {name:'department',convert:function(v){return v.deptName}},
     20                     {name:'job',convert:function(v){return v.jobName}}]
     21         });
     22         //多选按钮
     23         var sm = new Ext.grid.CheckboxSelectionModel();
     24         var number = new Ext.grid.RowNumberer();
     25         
     26         empInfoGridPanel.superclass.constructor.call(this,{
     27             viewConfig:{
     28                 forceFit: true
     29             },
     30             Ext.getCmp('mainTab').getActiveTab().getInnerWidth(),
     31             height:Ext.getCmp('mainTab').getActiveTab().getInnerHeight(),
     32             /**表格高度自适应 document.body.clientHeight浏览器页面高度 start**/
     33             monitorResize:true,
     34             doLayout:function(){
     35                 this.setWidth(document.body.clientWidth-205);
     36                 this.setHeight(document.body.clientHeight-140);
     37                 Ext.grid.GridPanel.prototype.doLayout.call(this); 
     38             },
     39             sm:sm,
     40             columns:[
     41                      number,sm,
     42                     {
     43                         header: '员工工号',
     44                         dataIndex: 'empId',
     45                         align: 'center'
     46                     },{
     47                         header: '员工姓名',
     48                         dataIndex: 'empName',
     49                         align: 'center'
     50                     },{
     51                         header: '员工性别',
     52                         dataIndex: 'empSex',
     53                         align: 'center',
     54                         renderer: function(value){
     55                             if(value == 1)     return "男";
     56                             else return "女";
     57                         }
     58                     },{
     59                         header: '部门名称',
     60                         dataIndex: 'department',
     61                         align: 'center'
     62                     },{
     63                         header: '职位',
     64                         dataIndex: 'job',
     65                         align: 'center'
     66                     }],
     67                 store:empInfoStore,
     68                 //添加遮罩
     69                 loadMask:{msg:'数据正在加载中,请稍后!'},
     70                 
     71                 tbar:new Ext.Toolbar({
     72                     bodyStyle: 'padding-left: 5px;',
     73                     //depart.js中定义了depart
     74                     items:['部门:',new depart("员工"),'&nbsp;条目:',{
     75                         // Ext xtype : "combo" 下拉选择框 
     76                         xtype:'combo',
     77                         mode:'local',//加载本地数据,必须加入
     78                         store:new Ext.data.SimpleStore({
     79                             fields:['name','value'],
     80                             data: [["","无"],['empId','工号'],['empName','姓名']]
     81                         }),
     82                         //下拉框中显示的值
     83                         displayField:'value',
     84                         //是隐藏的一个值
     85                         valueField:'name',
     86                         id:'emp_condition',
     87                         50,
     88                         autoLoad:true,
     89                         listWidth:50,
     90                         //是否可编辑
     91                         editable:false,
     92                         /*默认值 为query,当输入框有值时下拉列表将根据该值只显示过滤后的列表数据,可设置为all,不执行过滤*/
     93                         triggerAction:'all'
     94                     },'&nbsp;内容:',{
     95                         xtype:'textfield',
     96                         id:'emp_conditionValue',
     97                         80,
     98                         listeners:{
     99                             specialkey:function(field, e){//添加回车事件
    100                                 if(e.getKey()==Ext.EventObject.ENTER){
    101                                     // Ext.getCmp('empInfo').viewJob;
    102                                 }
    103                             }
    104                         }
    105                     },{
    106                             text: '添加',
    107                             handler: this.empAddFn
    108                         },{
    109                             text: '修改',
    110                             handler: this.empUpdateFn
    111                         },{
    112                             text: '详情',
    113                             handler: this.empDetailFn
    114                         }]
    115                 }),
    116                 
    117                 bbar:new PagingToolbar(empInfoStore,20)
    118         });
    119         
    120         empInfoStore.load({
    121             params:{
    122                 deptId:"",
    123                 start:0,
    124                 limit:20
    125             }
    126         });
    127     },
    128     //查询
    129     viewJob:function(){
    130         var deptValue = Ext.getCmp('deptValue员工').getValue();
    131         var condition = Ext.getCmp('emp_condition').getValue();
    132         var conditionValue = Ext.getCmp('emp_conditionValue').getValue();
    133         
    134         empInfoStore.load({
    135             params: {
    136                 deptId: deptValue,
    137                 condition: condition,
    138                 conditionValue: conditionValue,
    139                 start: 0,
    140                 limit: 20
    141             }
    142         });     
    143     },
    144     empDelFn: function(){
    145         gridDel('empInfo','empId', 'emp_delete.action');
    146     },
    147     //添加员工信息
    148     empAddFn: function(){
    149         var empUpdateWin = new EmpUpdateWin();
    150         empUpdateWin.show();
    151     },
    152     //修改员工信息
    153     empUpdateFn: function(){
    154         var empUpdateWin = new EmpUpdateWin();
    155         empUpdateWin.title = '职员信息修改';
    156         
    157         var selectionModel = Ext.getCmp('empInfo').getSelectionModel();
    158         var record = selectionModel.getSelections();
    159         
    160         if(record.length!=1){
    161             Ext.Msg.alert('提示','请选择一个');
    162             return;
    163         }
    164         
    165         var empId = record[0].get('empId');
    166         Ext.getCmp('empForm').getForm().load({
    167             method: 'post',
    168             url: 'emp_intoUpdate.action',
    169             params: {
    170                 empId: empId
    171             },
    172             success: function(form, action){
    173                 var obj = Ext.util.JSON.decode(action.response.responseText);
    174                 Ext.getCmp("deptValue所在部门").setRawValue(obj[0].department.deptName);
    175                 Ext.getCmp("jobValue职位").setRawValue(obj[0].job.jobName);
    176             }
    177         })
    178         empUpdateWin.show();
    179     },
    180     empDetailFn: function(){
    181         var empDetailWin = new EmpDetailWin();
    182         var selectionModel = Ext.getCmp('empInfo').getSelectionModel();
    183         var record = selectionModel.getSelections();
    184         if(record.length != 1){
    185             Ext.Msg.alert('提示','请选择一个');
    186             return;
    187         }
    188         var empId = record[0].get('empId');
    189         Ext.getCmp('empDetailId').getForm().load({
    190             url: 'emp_intoUpdate.action',
    191             method: 'post',
    192             params: {
    193                 empId: empId
    194             }
    195         })
    196         empDetailWin.show();
    197     }
    198 });

    3。添加员工信息弹窗

    4.添加员工窗口页面js

     1 EmpUpdateWin = Ext.extend(Ext.Window,{
     2     id:'empUpdateWinId',
     3     constructor:function(){
     4         //添加职员信息
     5         var empForm = new addEmpForm();
     6         
     7         EmpUpdateWin.superclass.constructor.call(this, {
     8             model:true,
     9              825,
    10             items: [empForm]
    11         });
    12     }
    13 });

    5.

      1 /**
      2  * 添加职员Form
      3  * @author sux
      4  * @param {Object} width
      5  * @memberOf {TypeName} 
      6  */
      7 addEmpForm = Ext.extend(Ext.form.FormPanel,{
      8     id:'empForm',
      9     //url: 'emp_save.action',
     10     //构造方法中的width参数为TabPanel的宽度
     11     constructor:function(width){
     12         width = (width-750)/2;
     13         Ext.QuickTips.init();
     14         var deptObject = new DepartJob("所在部门","emp.department.deptId"); //实例化部门
     15         jobObject = new Job("职位","emp.job.jobId",deptObject); //实例化职位
     16         
     17         jobObject.on('expand', function(comboBox){
     18             var deptId = Ext.getCmp("deptValue所在部门").getValue();
     19             this.getStore().load({
     20                 params: {
     21                     deptId: deptId
     22                 }
     23             })
     24         });
     25         
     26         var reader = new Ext.data.JsonReader({},[{
     27             name: 'emp.empId', mapping: 'empId'
     28         },{//json时间格式转为ext,time为json中显示的一部分
     29             name: 'emp.empBirth', mapping: 'empBirth.time', dateFormat : 'time', type: 'date'
     30         },{
     31             name: 'emp.empSex', mapping: 'empSex'
     32         },{
     33             name: 'emp.empPost', mapping: 'empPost'
     34         },{
     35             name: 'emp.empBank', mapping: 'empBank'
     36         },{
     37             name: 'emp.empNationality', mapping: 'empNationality'
     38         },{
     39             name: 'emp.empSchool', mapping: 'empSchool'
     40         },{
     41             name: 'emp.empName', mapping: 'empName'
     42         },{
     43             name: 'emp.empTelephone', mapping: 'empTelephone'
     44         },{
     45             name: 'emp.empEmail', mapping: 'empEmail'
     46         },{
     47             name: 'emp.empMobilephone', mapping: 'empMobilephone'
     48         },{
     49             name: 'emp.empIdcard', mapping: 'empIdcard'
     50         },{
     51             name: 'emp.empAccount', mapping: 'empAccount'
     52         },{
     53             name: 'emp.empOrigin', mapping: 'empOrigin'
     54         },{
     55             name: 'emp.empEducation', mapping: 'empEducation'
     56         },{
     57             name: 'emp.empPhoto', mapping: 'empPhoto', convert: function(v){if(v != '')Ext.get('emp_photo').dom.src=v;}
     58         },{
     59             name: 'emp.empNation', mapping: 'empNation'
     60         },{
     61             name: 'emp.empProfession', mapping: 'empProfession'
     62         },{
     63             name: 'emp.empAddress', mapping: 'empAddress'
     64         },{
     65             name: 'emp.department.deptId', mapping: 'department.deptId'
     66         },{
     67             name: 'emp.job.jobId', mapping: 'job.jobId'
     68         }])
     69         addEmpForm.superclass.constructor.call(this,{
     70             //var windowWidth =   window.screen.availWidth;获取屏幕宽度
     71             //bodyStyle: 'margin-left:'+width+'px;', //将下面的panel显示在中间
     72             frame: true,
     73             reader: reader,
     74             items:[{
     75                 768,
     76                 html: '<center><h1>员工信息</h1></center><br/>'
     77             },{
     78                 //可以用fieldset来进行内部分组
     79                 xtype:'fieldset',
     80                 title: '个人信息',
     81                 defaults:{
     82                     bodyStyle: 'padding-right: 30px;'
     83                 },
     84                 768,
     85                 layout:'table',//表格布局
     86                 labelAlign: 'right',
     87                 labelWidth: 60,
     88                 frame: true,
     89                 layoutConfig: {//3列
     90                     columns: 3
     91                 },
     92                 items:[{
     93                     layout:'form',
     94                     //columnWidth: .33, // column列布局
     95                     defaults:{
     96                         xtype: 'textfield',
     97                          150
     98                     },
     99                     items:[{
    100                         fieldLabel: '工号',
    101                         name: 'emp.empId',
    102                         allowBlank: false,
    103                         msgTarget: 'side',
    104                         blankText: '工号不能为空',
    105                         emptyText: '不能为空',
    106                         id: 'empAddId',
    107                         listeners: {'blur':hrmsys.util.common.empId}
    108                     },{
    109                         xtype: 'datefield',
    110                         fieldLabel: '出生日期',
    111                         name: 'emp.empBirth',
    112                         format: 'Y-m-d',
    113                         allowBlank: false,
    114                         editable: false,
    115                         msgTarget: 'side',
    116                         blankText: '出生日期不能为空',
    117                         emptyText: '不能为空'
    118                     },{
    119                         xtype: 'numberfield', //只能为数字
    120                         fieldLabel: 'QQ',
    121                         //emptyText: '只能为数字',
    122                         name: 'emp.empQq'
    123                     },{
    124                         fieldLabel: '性别',
    125                         xtype: 'panel',
    126                         layout: 'column',
    127                         bodyStyle: 'padding:0px 0px 10px 30px;',
    128                         items:[{
    129                             columnWidth: .5,
    130                             xtype: 'radio',
    131                             boxLabel: '男',
    132                             checked: true,
    133                             inputValue: 1, //此处特别注意inputValue
    134                             name: 'emp.empSex'
    135                         },{
    136                             columnWidth: .5,
    137                             xtype: 'radio',
    138                             boxLabel: '女',
    139                             inputValue: 0,
    140                             name: 'emp.empSex'    
    141                         }]
    142                     },{
    143                         xtype: 'numberfield',
    144                         fieldLabel: '邮编',
    145                         allowBlank: false,
    146                         msgTarget: 'side',
    147                         blankText: '邮编不能为空',
    148                         emptyText: '只能为数字',
    149                         regex: /^[1-9]d{5}$/,
    150                         regexText: '邮编格式不正确',
    151                         name: 'emp.empPost'
    152                     },{
    153                         fieldLabel: '开户银行',
    154                         allowBlank: false,
    155                         msgTarget: 'side',
    156                         blankText: '开户银行不能为空',
    157                         emptyText: '不能为空',
    158                         name: 'emp.empBank'
    159                     },{
    160                         fieldLabel: '国籍',
    161                         allowBlank: false,
    162                         msgTarget: 'side',
    163                         blankText: '国籍不能为空',
    164                         emptyText: '不能为空',
    165                         name: 'emp.empNationality'
    166                     },{
    167                         fieldLabel: '毕业学校',
    168                         allowBlank: false,
    169                         msgTarget: 'side',
    170                         blankText: '毕业学校不能为空',
    171                         emptyText: '不能为空',
    172                         name: 'emp.empSchool'
    173                     }]
    174                 },{
    175                     layout: 'form',
    176                     //columnWidth: .33,
    177                     defaults: {
    178                         xtype: 'textfield',
    179                          150
    180                     },
    181                     items: [{
    182                         fieldLabel: '姓名',
    183                         allowBlank: false,
    184                         msgTarget: 'side',
    185                         blankText: '用户名不能为空',
    186                         emptyText: '不能为空',
    187                         name: 'emp.empName'
    188                     },{
    189                         fieldLabel: '电话',
    190                         name: 'emp.empTelephone',
    191                         msgTarget: 'side',
    192                         regex: /^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/,
    193                         regexText: '电话格式不正确'
    194                     },{
    195                         fieldLabel: 'e-mail',
    196                         emptyText: '不能为空',
    197                         allowBlank: false,
    198                         blankText: '邮箱不能为空',
    199                         vtype: 'email', //自带的邮箱校验
    200                         msgTarget: 'side',
    201                         vtypeText: '请输入正确的邮箱格式',
    202                         name: 'emp.empEmail'
    203                     },{
    204                         fieldLabel: '手机',
    205                         allowBlank: false,
    206                         msgTarget: 'side',
    207                         blankText: '手机号不能为空',
    208                         emptyText: '不能为空',
    209                         name: 'emp.empMobilephone',
    210                         regex: /(^0?[1][358][0-9]{9}$)/,
    211                         regexText: '手机格式不正确'                                
    212                     },{
    213                         fieldLabel: '身份证',
    214                         allowBlank: false,
    215                         msgTarget: 'side',
    216                         blankText: '身份证号不能为空',
    217                         regex: /^(d{14}|d{17})(d|[xX])$/,
    218                         regexText: '身份证格式不正确',
    219                         emptyText: '不能为空',
    220                         name: 'emp.empIdcard'
    221                     },{
    222                         xtype: 'numberfield',
    223                         fieldLabel: '开户账号',
    224                         allowBlank: false,
    225                         msgTarget: 'side',
    226                         blankText: '账号不能为空',
    227                         emptyText: '只能为数字',
    228                         name: 'emp.empAccount'
    229                     },{
    230                         fieldLabel: '籍贯',
    231                         allowBlank: false,
    232                         msgTarget: 'side',
    233                         blankText: '籍贯不能为空',
    234                         emptyText: '不能为空',
    235                         name: 'emp.empOrigin'
    236                     },{
    237                         fieldLabel: '学历',
    238                         allowBlank: false,
    239                         msgTarget: 'side',
    240                         blankText: '学历不能为空',
    241                         emptyText: '不能为空',
    242                         name: 'emp.empEducation'
    243                     }]
    244                 },{ 
    245                     //rowspan: 5,
    246                     layout: 'form',
    247                     defaults: {
    248                         xtype: 'textfield',
    249                          150
    250                     },
    251                     items: [{
    252                         xtype: 'textfield', //注意此处为textfield, inputType: 'image'
    253                         fieldLabel: '照片',
    254                         inputType: 'image',
    255                          130,
    256                         height: 125,
    257                         id: 'emp_photo',
    258                         autoCreate : {
    259                         tag : "input",
    260                         type : "image",
    261                         src : "img/default.gif",
    262                         name: 'emp.empPhoto'
    263                         //autocomplete:  "off"
    264                         }
    265                     },{
    266                         style: 'margin-left: 110px;',
    267                         xtype: 'button',
    268                          50,
    269                         text: '上传照片',
    270                         handler: upload
    271                     },{
    272                         xtype: 'textfield',
    273                         fieldLabel: '民族',
    274                         allowBlank: false,
    275                         msgTarget: 'side',
    276                         blankText: '民族不能为空',
    277                         emptyText: '不能为空',
    278                         name: 'emp.empNation'
    279                     },{
    280                         xtype: 'textfield',
    281                         fieldLabel: '专业',
    282                         allowBlank: false,
    283                         msgTarget: 'side',
    284                         blankText: '专业不能为空',
    285                         emptyText: '不能为空',
    286                         name: 'emp.empProfession'
    287                     }]
    288                 },{
    289                     colspan: 3,
    290                     layout: 'form',
    291                     items: [{
    292                         xtype: 'textfield',
    293                         fieldLabel: '地址',
    294                          640,
    295                         allowBlank: false,
    296                         msgTarget: 'side',
    297                         blankText: '地址不能为空',
    298                         emptyText: '不能为空',
    299                         name: 'emp.empAddress'
    300                 }]
    301                 }]
    302                 },{
    303                     xtype: 'fieldset',
    304                     title: '部门',
    305                      768,
    306                     layout: 'column',
    307                     defaultType: 'textfield',
    308                     defaults: {
    309                         labelWidth: 60,
    310                         labelAlign: 'right'
    311                     },
    312                     items: [{
    313                         columnWidth: .32,
    314                         layout: 'form',
    315                         xtype: 'panel',
    316                         items: [deptObject]
    317                     },{
    318                         columnWidth: .32,
    319                         layout: 'form',
    320                         xtype: 'panel',
    321                         items: [jobObject]
    322                     }]
    323                 },{
    324                     xtype: 'panel',
    325                      750,
    326                     buttonAlign: 'center',
    327                     buttons: [{
    328                         text: '保存',
    329                         handler: function(){
    330                             if(!Ext.getCmp('empForm').getForm().isValid()){
    331                                 return;
    332                             }
    333                             Ext.getCmp('empForm').getForm().submit({
    334                                 url: 'emp_save.action',
    335                                 method: 'post',
    336                                 waitTitle: '提示',
    337                                 waitMsg: '正在保存数据...',
    338                                 success: saveSuccess,
    339                                 failure: saveFailure,
    340                                 scope: this,
    341                                 params: {empPhoto: Ext.get('emp_photo').dom.src}
    342                             });
    343                         }
    344                     },{
    345                         text: '关闭',
    346                         handler: function(){
    347                             //Ext.getCmp('empForm').getForm().reset();
    348                             //Ext.get('emp_photo').dom.src = 'img/default.gif';
    349                             Ext.getCmp('empUpdateWinId').destroy();
    350                         }
    351                     }]
    352                 }]
    353             });
    354         }
    355     });
    356             
    357 
    358 //上传窗体显示
    359 upload = function(){
    360     uploadWin = new UploadWin();//实例化上传窗体
    361     uploadWin.show();//显示窗体
    362 }
    363 
    364 //保存成功操作
    365 //保存成功操作
    366 saveSuccess = function(form, action){
    367     Ext.Msg.confirm('提示', action.result.msg, function(button, text){
    368         Ext.getCmp('empForm').getForm().reset();
    369         Ext.get('emp_photo').dom.src = 'img/default.gif';
    370         if(button == "yes"){
    371             Ext.getCmp('empUpdateWinId').destroy();//销毁窗体
    372             Ext.getCmp("empInfo").getStore().load({
    373             params: {
    374                 deptId: "",
    375                 start: 0,
    376                 limit: 20
    377             }
    378         });
    379         }
    380     });
    381 };
    382 //保存失败操作
    383 saveFailure = function(form, action){
    384     Ext.Msg.alert('提示','连接失败');
    385 }

    7. 上传文件

     1 /**
     2  * @author sux
     3  * @date 2011-1-30
     4  * @desc 上传窗体
     5  */
     6 UploadWin = Ext.extend(Ext.Window,{
     7     id: 'upLoad',
     8     uploadPanel: null,
     9     constructor: function(){    
    10         this.uploadPanel =  new Ext.form.FormPanel({
    11             fileUpload:true,////允许上传
    12             baseCls: 'x-plain',//作用在面板元素上的CSS样式类 (默认为 'x-panel')
    13             layout: 'form',
    14             labelWidth: 60,
    15             id: 'uploadformPanel',
    16             items: [{
    17                 xtype: 'fileuploadfield',//引入插件
    18                 //inputType: 'file',
    19                 fieldLabel: '上传照片',
    20                 //allowBlank: false,
    21                 id: 'photo',
    22                 name: 'upload',
    23                 buttonText: '选择'
    24             }]
    25         });
    26         
    27         //调用父类构造方法
    28         UploadWin.superclass.constructor.call(this,{
    29             title: '上传照片',
    30             modal: true,
    31              300,
    32             height: 130,
    33             plain: true,
    34             bodyStyle: 'padding: 15px;',
    35             items:[this.uploadPanel],
    36             buttonAlign: 'center',
    37             buttons:[{
    38                 text: '确定',
    39                 handler: function(){
    40                     Ext.getCmp('uploadformPanel').getForm().submit({
    41                         url: 'emp_upload.action',
    42                         method: 'post',
    43                         waitTitle: '提示',
    44                         waitMsg: '正在上传,请稍后...',
    45                         success: uploadSuccess,
    46                         failure: uploadFailure,
    47                         scope: this
    48                     });
    49                 }
    50             },{
    51                 text: '取消',
    52                 handler: function(){
    53                     Ext.getCmp('uploadformPanel').getForm().reset();
    54                     Ext.get('emp_photo').dom.src = 'img/default.gif';
    55                     uploadWin.destroy();
    56                 }
    57             }]
    58         })
    59     }
    60 });
    61 uploadSuccess = function(form,action){
    62     //console.log('success');
    63     Ext.getCmp('uploadformPanel').getForm().reset();
    64     uploadWin.destroy();
    65     Ext.Msg.alert('提示',action.result.msg,function(){
    66         Ext.getCmp('emp_photo').getEl().dom.src = action.result.path;
    67     });
    68 }
    69 uploadFailure = function(form,action){
    70     //console.log('failure');
    71     Ext.Msg.alert('提示', '连接失败');
    72 };

    id为photo为上传路径

    8.

      1 package com.hrmsys.action;
      2 
      3 import java.io.File;
      4 import java.io.IOException;
      5 import java.io.PrintWriter;
      6 import java.io.UnsupportedEncodingException;
      7 import java.util.ArrayList;
      8 import java.util.List;
      9 
     10 import javax.servlet.http.HttpServletResponse;
     11 
     12 import org.apache.struts2.ServletActionContext;
     13 
     14 import com.hrmsys.bean.EmployeeBean;
     15 import com.hrmsys.model.Employee;
     16 import com.hrmsys.model.User;
     17 import com.hrmsys.service.EmpService;
     18 import com.hrmsys.service.JobChangeService;
     19 import com.hrmsys.util.ConditionValidate;
     20 import com.hrmsys.util.CurrentDate;
     21 import com.hrmsys.util.FileExport;
     22 import com.hrmsys.util.SequenceBuilder;
     23 import com.opensymphony.xwork2.ActionContext;
     24 
     25 public class EmpAction extends BaseAction{
     26     private EmpService empService;
     27     private Employee emp;
     28     private List<EmployeeBean> empBeans;
     29     private JobChangeService jobChangeService;
     30     /**
     31      * 由于dept和job常用,故单独成一js文件
     32      * 但在与struts整合时不便将属性名绑定到name,
     33      * 故此单独定义deptId和jobId属性
     34      */
     35     private String deptId = null;
     36     private String jobId  = null;
     37     private String empPhoto = null;
     38     /**
     39      * 配置文件中的参数会通过setter方法注入
     40      * rePath获取savePath的值
     41      */
     42     private String rePath = null;
     43     /**
     44      * 查询条目
     45      */
     46     private String condition;
     47     /**
     48      * 查询内容
     49      */
     50     private String conditionValue;
     51     /**
     52      * 保存的路径
     53      */
     54     private String savePath; 
     55     /**
     56      * 上传的文件内容 
     57      */
     58     private File upload;
     59     /**
     60      * 保存的文件名
     61      */
     62     private String uploadFileName;
     63     /**
     64      * 上传的文件种类
     65      */
     66     private String uploadContentType;
     67     private String empId;
     68     private String ids;
     69     private String start;
     70     private String limit;
     71     
     72     /************方法**********************************************/
     73     /**
     74      * 清单
     75      */
     76     public void list(){
     77         String json = null;
     78         json = empService.getByHQL(deptId, condition, conditionValue, start, limit);
     79         this.setStart(null);
     80         this.setLimit(null);
     81         this.out(json);
     82     }
     83     /**
     84      * 保存员工信息
     85      */
     86     public void save(){
     87         log.info("save start....");
     88         log.info(this.getEmpPhoto());
     89         String msg = "保存失败";
     90         HttpServletResponse response = this.getResponse();
     91         User user = (User)ActionContext.getContext().getSession().get("user");
     92         emp.setEmpPhoto(this.getEmpPhoto());
     93         emp.setEmpAddDate(CurrentDate.getDate());
     94         emp.setEmpAddPerson(user.getUserName());
     95         msg = empService.save(emp);
     96         this.out("{success: true, msg: '"+msg+"'}");
     97     }
     98     /**
     99      * 员工头像上传
    100      */
    101     public void upload(){
    102         log.info("upload start...");
    103         log.info("uploadFileName="+this.getUploadFileName());
    104         //重命名
    105         String fileName = SequenceBuilder.getSequence()+this.getUploadFileName().substring(this.getUploadFileName().indexOf(".")); 
    106         String msg = empService.uploadPhoto(this.getSavePath()+"\"+fileName, this.getUpload());
    107         this.out("{success: true, msg: '"+msg+"', path: '"+this.rePath+"/"+fileName+"'}");
    108     }
    109     /**
    110      * 根据工号判断是否存在此员工
    111      */
    112     public void isExist(){
    113         String empName = empService.isExistByEmpId(empId);
    114         this.out(empName);
    115     }
    116     
    117     public void unique(){
    118         String emp = empService.unique(empId);
    119         this.out(emp);
    120     }
    121     
    122     public void delete(){
    123         String filePath = ServletActionContext.getRequest().getRealPath(savePath);
    124         String msg = empService.delete(ids, filePath);
    125         this.out("{success: true, msg: '"+msg+"'}");
    126     }
    127     
    128     public void intoUpdate(){
    129         String empJson = empService.listByEmpId(empId);
    130         this.out(empJson);
    131     }
    132     /**
    133      * 详细员工pdf报表预览
    134      */
    135     public String detailPdfReport(){
    136         empBeans = empService.getEmpList(empId);
    137         return "detailPdf";
    138     }
    139     public String simplePdfReport(){
    140         empBeans = empService.getEmpList(empId);
    141         return "simplePdf";
    142     }
    143     /**
    144      * 导出详细报表pdf
    145      */
    146     public void detailPdfExport(){
    147         empService.pdfExport(empId, this.getResponse(),"员工详细信息.pdf","detailEmp.jasper");
    148     }
    149     /**
    150      * 导出员工简单信息pdf
    151      */
    152     public void simplePdfExport(){
    153         empService.pdfExport(empId, this.getResponse(),"员工简单信息.pdf", "simpleEmp.jasper");
    154     }
    155     /**
    156      * 导出员工简单信息Excel
    157      */
    158     public void detailXlsExport(){
    159         empService.xlsExport(this.getResponse(), "员工信息.xls");
    160     }
    161     /*********getter and setter ***********/
    162     public EmpService getEmpService() {
    163         return empService;
    164     }
    165 
    166     public void setEmpService(EmpService empService) {
    167         this.empService = empService;
    168     }
    169 
    170     public String getDeptId() {
    171         return deptId;
    172     }
    173 
    174     public void setDeptId(String deptId) {
    175         this.deptId = deptId;
    176     }
    177 
    178     public String getCondition() {
    179         return condition;
    180     }
    181 
    182     public void setCondition(String condition) {
    183         this.condition = condition;
    184     }
    185 
    186     public String getConditionValue() {
    187         return conditionValue;
    188     }
    189 
    190     public void setConditionValue(String conditionValue) {
    191         this.conditionValue = conditionValue;
    192     }
    193 
    194     public Employee getEmp() {
    195         return emp;
    196     }
    197 
    198     public void setEmp(Employee emp) {
    199         this.emp = emp;
    200     }
    201     public String getJobId() {
    202         return jobId;
    203     }
    204     public void setJobId(String jobId) {
    205         this.jobId = jobId;
    206     }
    207     public String getSavePath() {
    208         //struts.xml中配置savePath参数,且获取文件夹的真实地址
    209         return ServletActionContext.getRequest().getRealPath(savePath);
    210     }
    211     public void setSavePath(String savePath) {
    212         this.rePath = savePath;
    213         this.savePath = savePath;
    214     }
    215     public File getUpload() {
    216         return upload;
    217     }
    218     public void setUpload(File upload) {
    219         this.upload = upload;
    220     }
    221     public String getUploadFileName() {
    222         return uploadFileName;
    223     }
    224     public void setUploadFileName(String uploadFileName) {
    225         this.uploadFileName = uploadFileName;
    226     }
    227     public String getUploadContentType() {
    228         return uploadContentType;
    229     }
    230     public void setUploadContentType(String uploadContentType) {
    231         this.uploadContentType = uploadContentType;
    232     }
    233     public String getEmpPhoto() {
    234         return empPhoto;
    235     }
    236     public void setEmpPhoto(String empPhoto) {
    237         this.empPhoto = empPhoto;
    238     }
    239     public JobChangeService getJobChangeService() {
    240         return jobChangeService;
    241     }
    242     public void setJobChangeService(JobChangeService jobChangeService) {
    243         this.jobChangeService = jobChangeService;
    244     }
    245     public String getEmpId() {
    246         return empId;
    247     }
    248     public void setEmpId(String empId) {
    249         this.empId = empId;
    250     }
    251     public String getIds() {
    252         return ids;
    253     }
    254     public void setIds(String ids) {
    255         this.ids = ids;
    256     }
    257     public List<EmployeeBean> getEmpBeans() {
    258         return empBeans;
    259     }
    260     public void setEmpBeans(List<EmployeeBean> empBeans) {
    261         this.empBeans = empBeans;
    262     }
    263     public String getStart() {
    264         return start;
    265     }
    266     public void setStart(String start) {
    267         this.start = start;
    268     }
    269     public String getLimit() {
    270         return limit;
    271     }
    272     public void setLimit(String limit) {
    273         this.limit = limit;
    274     }
    275     
    276 }

    9.

      1 package com.hrmsys.service.impl;
      2 
      3 import java.io.File;
      4 import java.io.FileInputStream;
      5 import java.io.FileNotFoundException;
      6 import java.io.FileOutputStream;
      7 import java.io.IOException;
      8 import java.util.ArrayList;
      9 import java.util.List;
     10 
     11 import javax.servlet.http.HttpServletResponse;
     12 
     13 import net.sf.json.JSONArray;
     14 
     15 import com.hrmsys.bean.EmployeeBean;
     16 import com.hrmsys.bean.PageBean;
     17 import com.hrmsys.dao.EmployeeDAO;
     18 import com.hrmsys.enums.StaticValue;
     19 import com.hrmsys.model.Department;
     20 import com.hrmsys.model.Employee;
     21 import com.hrmsys.service.EmpService;
     22 import com.hrmsys.util.ConditionValidate;
     23 import com.hrmsys.util.FileExport;
     24 
     25 public class EmpServiceImpl implements EmpService {
     26 
     27     private EmployeeDAO empDAO;
     28 
     29     @Override
     30     public int findNumByDept(Department dept) {
     31         List<Employee> emps = empDAO.findByDept(dept);
     32         if (emps != null)
     33             return emps.size();
     34         return 0;
     35     }
     36 
     37     public EmployeeDAO getEmpDAO() {
     38         return empDAO;
     39     }
     40 
     41     public void setEmpDAO(EmployeeDAO empDAO) {
     42         this.empDAO = empDAO;
     43     }
     44 
     45     @Override
     46     public String getAll(String start, String limit) {
     47         List<Employee> emps = empDAO.findAll(Integer.parseInt(start), Integer.parseInt(limit));
     48         String json = null;
     49         if (emps.size() != 0) {
     50             json = JSONArray.fromObject(emps).toString();
     51         }
     52         int totalProperty = empDAO.findTotal(Employee.class);
     53         return "{totalProperty:"+totalProperty+",root:"+json+"}";
     54     }
     55 
     56     @Override
     57     public String findByDeptId(String deptId) {
     58         Department dept = new Department();
     59         dept.setDeptId(deptId);
     60         List<Employee> emps = empDAO.findByDept(dept);
     61         String json = JSONArray.fromObject(emps).toString();
     62         return json;
     63     }
     64 
     65     @Override
     66     public String getByHQL(String deptId, String condition,
     67             String conditionValue, String start, String limit) {
     68         
     69         PageBean pageBean = empDAO.findByHQL(deptId, condition,
     70                 conditionValue, Integer.parseInt(start), Integer.parseInt(limit));
     71         String json = JSONArray.fromObject(pageBean.getRoot()).toString();
     72         return "{totalProperty:"+pageBean.getTotalProperty()+",root:"+json+"}";
     73     }
     74 
     75     @Override
     76     public String save(Employee emp) {
     77         if (empDAO.saveOrUpdate(emp)) {
     78             return StaticValue.SAVE_SUCCESS;
     79         }
     80         return StaticValue.SAVE_FAILURE;
     81     }
     82 
     83     @Override
     84     public String uploadPhoto(String savePath, File upload) {
     85         boolean flag = true;
     86         String msg = null;
     87         try {
     88             FileOutputStream fos = new FileOutputStream(savePath);
     89             FileInputStream fis = new FileInputStream(upload);
     90             byte[] buffer = new byte[1024];
     91             int len = 0;
     92             while ((len = fis.read(buffer)) > 0) {
     93                 fos.write(buffer, 0, len);
     94             }
     95         } catch (FileNotFoundException e) {
     96             flag = false;
     97             e.printStackTrace();
     98         } catch (IOException e) {
     99             flag = false;
    100             e.printStackTrace();
    101         } finally {
    102             if (flag) {
    103                 msg = StaticValue.UPLOAD_SUCCESS;
    104             } else {
    105                 msg = StaticValue.UPLOAD_FAILURE;
    106             }
    107         }
    108         return msg;
    109     }
    110 
    111     @Override
    112     public String isExistByEmpId(String empId) {
    113         Employee emp = empDAO.findByEmpId(empId);
    114         if(null != emp){
    115             return emp.getEmpName();
    116         }
    117         return "";
    118     }
    119 
    120     @Override
    121     public String unique(String empId) {
    122         Employee emp = empDAO.findByEmpId(empId);
    123         if(null != emp){
    124             return JSONArray.fromObject(emp).toString();
    125         }
    126         return "";
    127     }
    128     
    129     @Override
    130     public String delete(String ids, String filePath) {
    131         String[] empIds = ids.split(",");
    132         for(String empId : empIds){
    133             Employee emp = empDAO.findByEmpId(empId);
    134             String urlPath = emp.getEmpPhoto();
    135             if(urlPath.indexOf("default.gif") < 0){ //默认图片不删除 
    136                 int position = urlPath.lastIndexOf("/");
    137                 File file=new File(filePath +"\"+ urlPath.substring(position, urlPath.length()));
    138                  if(file.exists() && file.isFile())
    139                   file.delete();
    140             }
    141         }
    142         if(empDAO.deleteByEmpId(empIds)){
    143             return StaticValue.DELETE_SUCCESS;
    144         }
    145         return StaticValue.DELETE_FAILURE;
    146     }
    147 
    148     @Override
    149     public String listByEmpId(String empId) {
    150         Employee emp = empDAO.findByEmpId(empId);
    151         return JSONArray.fromObject(emp).toString();
    152     }    
    153 
    154     public List<EmployeeBean> packageEmp(List<Employee> emps) {
    155         List<EmployeeBean> empBeans = new ArrayList<EmployeeBean>();
    156         for(Employee emp : emps){
    157             EmployeeBean empBean = new EmployeeBean();
    158             empBean.setEmpAccount(emp.getEmpAccount());
    159             empBean.setEmpAddress(emp.getEmpAddress());
    160             empBean.setEmpBank(emp.getEmpBank());
    161             empBean.setEmpBirth(emp.getEmpBirth());
    162             empBean.setEmpEducation(emp.getEmpEducation());
    163             empBean.setEmpEmail(emp.getEmpEmail());
    164             empBean.setEmpId(emp.getEmpId());
    165             empBean.setEmpIdcard(emp.getEmpIdcard());
    166             empBean.setEmpMobilephone(emp.getEmpMobilephone());
    167             empBean.setEmpName(emp.getEmpName());
    168             empBean.setEmpNation(emp.getEmpNation());
    169             empBean.setEmpNationality(emp.getEmpNation());
    170             empBean.setEmpOrigin(emp.getEmpOrigin());
    171             empBean.setEmpPhoto(emp.getEmpPhoto());
    172             empBean.setEmpPost(emp.getEmpPost());
    173             empBean.setEmpProfession(emp.getEmpProfession());
    174             empBean.setEmpQq(emp.getEmpQq());
    175             empBean.setEmpSchool(emp.getEmpSchool());
    176             if(emp.getEmpSex() == 1){
    177                 empBean.setEmpSex("男");
    178             }else{
    179                 empBean.setEmpSex("女");
    180             }
    181             empBean.setEmpTelephone(emp.getEmpTelephone());
    182             empBean.setJob(emp.getJob().getJobName());
    183             empBean.setDept(emp.getDepartment().getDeptName());
    184             empBeans.add(empBean);
    185         }
    186     
    187         return empBeans;
    188     }
    189 
    190     @Override
    191     public void pdfExport(String empId, HttpServletResponse response, String filename, String jasper) {
    192         Employee emp = null;
    193         List<Employee> emps = new ArrayList<Employee>();
    194         if(!"all".equals(empId) && ConditionValidate.isEmpty(empId)){
    195             emp = empDAO.findByEmpId(empId);
    196             emps.add(emp);
    197         }else{
    198             emps = empDAO.findAll(Employee.class);
    199         }
    200         List<EmployeeBean> empBeans = packageEmp(emps);
    201         FileExport fileExport = new FileExport();
    202         fileExport.exportPDF(empBeans, filename,jasper, response);
    203         
    204     }
    205 
    206     @Override
    207     public List<EmployeeBean> getEmpList(String empId) {
    208         List<Employee> emps = new ArrayList<Employee>();
    209         Employee emp = empDAO.findByEmpId(empId);
    210         emps.add(emp);
    211         return this.packageEmp(emps);
    212     }
    213 
    214     @Override
    215     public void xlsExport(HttpServletResponse response, String filename) {
    216         List<Employee> emps = empDAO.findAll(Employee.class);
    217         List<EmployeeBean> empBeans = this.packageEmp(emps);
    218         FileExport fileExport = new FileExport();
    219         fileExport.exportXls(empBeans, filename, response);
    220     }
    221 
    222 }
  • 相关阅读:
    set-find
    set-equal_range
    set-equal_range
    set-erase
    php 抽象类 静态 单体设计模式
    Servlet 工作原理解析
    职场上一个人情商高的十种表现
    快速学习一门新技术入门
    php中14中排序方式的实现
    php中对Mysql数据库的访问操作
  • 原文地址:https://www.cnblogs.com/sharpest/p/7652302.html
Copyright © 2011-2022 走看看