首页
IT
登录
6mi
u
盘
搜
搜 索
IT
江岸dao
江岸dao
xiaoxiao
2021-03-25
144
<?
php
package
com
.
svse
.
action
;
import
java.io.File
;
import
java.io.PrintWriter
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Random
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.struts2.ServletActionContext
;
import
com.svse.entity.TEmp
;
import
com.svse.entity.TPart
;
import
com.svse.service.EmpService
;
import
com.svse.service.PartService
;
import
com.svse.util.MyPage
;
public
class
EmpAction
{
private
EmpService
empService
=
null
;
private
PartService
partService
=
null
;
private
List
ar
;
private
TEmp
emp
;
private
int
eid
;
private
List
arpart
=
new
ArrayList
();
private
int
begin
=
1
;
private
List
arr
=
new
ArrayList
();
private
MyPage
myPage
=
new
MyPage
();
//pis
private
int
pis
=
1
;
private
String
name
;
private
String
psw
;
//联合查询
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPsw
()
{
return
psw
;
}
public
void
setPsw
(
String
psw
)
{
this
.
psw
=
psw
;
}
public
int
getPis
()
{
return
pis
;
}
public
void
setPis
(
int
pis
)
{
this
.
pis
=
pis
;
}
public
int
getBegin
()
{
return
begin
;
}
public
void
setBegin
(
int
begin
)
{
this
.
begin
=
begin
;
}
public
List
getArr
()
{
return
arr
;
}
public
void
setArr
(
List
arr
)
{
this
.
arr
=
arr
;
}
public
MyPage
getMyPage
()
{
return
myPage
;
}
public
void
setMyPage
(
MyPage
myPage
)
{
this
.
myPage
=
myPage
;
}
public
List
getArpart
()
{
return
arpart
;
}
public
void
setArpart
(
List
arpart
)
{
this
.
arpart
=
arpart
;
}
public
EmpService
getEmpService
()
{
return
empService
;
}
public
void
setEmpService
(
EmpService
empService
)
{
this
.
empService
=
empService
;
}
public
PartService
getPartService
()
{
return
partService
;
}
public
void
setPartService
(
PartService
partService
)
{
this
.
partService
=
partService
;
}
public
List
getAr
()
{
return
ar
;
}
public
void
setAr
(
List
ar
)
{
this
.
ar
=
ar
;
}
public
TEmp
getEmp
()
{
return
emp
;
}
public
void
setEmp
(
TEmp
emp
)
{
this
.
emp
=
emp
;
}
public
int
getEid
()
{
return
eid
;
}
public
void
setEid
(
int
eid
)
{
this
.
eid
=
eid
;
}
//分页$$$
public
void
allpage
(){
// 查找共有多少条记录
int
count
=
this
.
empService
.
getCount
(
pis
);
// 共有多少页
int
pages
=
this
.
myPage
.
getAllPage
(
count
);
begin
=
count
==
0
?
0
:
begin
;
int
up
=
this
.
myPage
.
getUp
(
begin
);
int
next
=
this
.
myPage
.
getNext
(
begin
,
pages
);
HttpServletRequest
request
=
ServletActionContext
.
getRequest
();
request
.
setAttribute
(
"begin"
,
new
Integer
(
begin
));
request
.
setAttribute
(
"up"
,
new
Integer
(
up
));
request
.
setAttribute
(
"next"
,
new
Integer
(
next
));
request
.
setAttribute
(
"pages"
,
new
Integer
(
pages
));
request
.
setAttribute
(
"count"
,
new
Integer
(
count
));
// 造结果集
for
(
int
i
=
1
;
i
<=
pages
;
i
++)
{
TEmp
tEmp
=
new
TEmp
();
tEmp
.
setPage
(
i
);
arr
.
add
(
tEmp
);
}
}
//全查询$$$
public
String
all
(){
//分页
allpage
();
//查询emp的所有数据
this
.
ar
=
this
.
empService
.
getAllEmpPage
(
begin
,
15
,
pis
);
//查询pis=0的部门所有数据
this
.
arpart
=
this
.
partService
.
getAllPart1
(
0
);
//将部门刚刚查询pis=0的所有数据遍历出来
for
(
int
i
=
0
;
i
<
arpart
.
size
();
i
++)
{
//用部门实体类将刚刚遍历出来的几条数据放在里面
TPart
t
=(
TPart
)
arpart
.
get
(
i
);
//将员工表的数据遍历出来
for
(
int
j
=
0
;
j
<
ar
.
size
();
j
++)
{
//用员工表实体类将员工遍历出来的数据放在里面
TEmp
e
=
(
TEmp
)
ar
.
get
(
j
);
//定义a代表表部门表中获取的id,
//b代表员工表相关联的部门表的id
int
a
=
t
.
getPId
();
int
b
=
e
.
getTPart
().
getPId
();
//再将其们相对比,要是等于的情况下就执行
if
(
a
==
b
){
//将员工表的is写入为0(此时为未删除is)
e
.
setEIs
(
0
);
//实例化一个部门实体类
TPart
tp
=
new
TPart
();
//将部门的id写入为-1
tp
.
setPId
(-
1
);
//将部门id为1的写入到员工表对应的部门表
e
.
setTPart
(
tp
);
//再将员工表进行修改
this
.
empService
.
updateEmp
(
e
);
}
}
}
//部门主管$$
this
.
arpart
=
this
.
partService
.
getAllPart1
(
0
);
this
.
ar
=
this
.
empService
.
getAllEmpPage
(
begin
,
15
,
pis
);
flag
();
//判断pis是否等于一,等于一时候返回查询所有,等于0的时候就返回回收站
if
(
pis
==
1
){
return
"myall"
;
}
else
{
return
"recovery"
;
}
}
//点击增加查询所在部门##
public
String
arpart
(){
this
.
arpart
=
this
.
partService
.
getAllPartPage
(
begin
,
15
,
1
);
for
(
int
i
=
0
;
i
<
arpart
.
size
();
i
++)
{
TPart
t
=
(
TPart
)
arpart
.
get
(
i
);
if
(
t
.
getPId
()==
0
){
arpart
.
remove
(
i
);
i
--;
}
}
return
"myadd"
;
}
public
void
xiugai
(){
List
ar
=
this
.
empService
.
getAllEmpPage
(
begin
,
15
,
1
);
TEmp
e
=
this
.
emp
;
for
(
int
i
=
0
;
i
<
ar
.
size
();
i
++)
{
TEmp
e1
=
(
TEmp
)
ar
.
get
(
i
);
//判断用户名是否重复
if
(
e1
.
getELoginname
().
equals
(
emp
.
getELoginname
())){
break
;
}
int
a
=
e
.
getTPart
().
getPId
();
int
b
=
e1
.
getTPart
().
getPId
();
System
.
out
.
println
(
a
+
" + "
+
b
);
if
(
a
==
b
){
int
a1
=
e
.
getEFlag
();
int
b1
=
e1
.
getEFlag
();
if
(
a1
==
b1
){
e1
.
setEFlag
(
0
);
e1
.
setEAdmin
(
0
);
System
.
out
.
println
(
a1
+
" + "
+
b1
);
this
.
empService
.
updateEmp
(
e1
);
}
}
}
}
//增加$$
public
String
add
(){
xiugai
();
emp
.
setEIs
(
1
);
emp
.
setEImg
(
sc
());
this
.
empService
.
addEmp
(
emp
);
pis
=
1
;
return
this
.
all
();
}
//查询一个$$
public
String
one
(){
this
.
emp
=
this
.
empService
.
getOneEmp
(
eid
);
this
.
arpart
=
this
.
partService
.
getAllPart1
(
1
);
return
"myupp"
;
}
//员工恢复表里面的点击恢复返回选择部门列表$$
public
String
one1
(){
this
.
emp
=
this
.
empService
.
getOneEmp
(
eid
);
this
.
arpart
=
this
.
partService
.
getAllPart1
(
1
);
System
.
out
.
println
(
emp
.
getETruename
()+
"+"
+
emp
.
getEIs
()+
"+"
+
emp
.
getEId
());
return
"myupp1"
;
}
//修改$$
public
String
upp
(){
xiugai
();
emp
.
setEIs
(
1
);
this
.
empService
.
updateEmp
(
emp
);
return
this
.
all
();
}
//恢复按钮操作调到查询所有主页面$$
public
String
upp1
(){
TEmp
e
=
this
.
empService
.
getOneEmp
(
emp
.
getEId
());
e
.
setEIs
(
1
);
TPart
t
=
new
TPart
();
t
.
setPId
(
emp
.
getTPart
().
getPId
());
e
.
setTPart
(
t
);
this
.
empService
.
updateEmp
(
e
);
return
this
.
all
();
}
//撤销操作##
public
String
remove1
(){
//根据ID查出所有的信息
TEmp
e
=
this
.
empService
.
getOneEmp
(
eid
);
//PIS设为0
e
.
setEIs
(
0
);
//定义一个TPart实体类,把PID 设为待议
TPart
p
=
new
TPart
();
p
.
setPId
(-
1
);
e
.
setTPart
(
p
);
//执行修改方法
this
.
empService
.
updateEmp
(
e
);
return
this
.
all
();
}
// 上传$$
public
String
sc
()
{
// 文件上传到哪儿
String
path
=
ServletActionContext
.
getRequest
().
getRealPath
(
"/upload"
);
// 文件改名
String
newname
=
getNewName
(
emp
.
getScFileName
());
File
f
=
new
File
(
path
,
newname
);
try
{
FileUtils
.
copyFile
(
emp
.
getSc
(),
f
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
mying
=
"/upload/"
+
newname
;
return
mying
;
}
private
String
getNewName
(
String
scFileName
)
{
String
result
=
""
;
// 得到源文件的后缀名
String
lastname
=
scFileName
.
substring
(
scFileName
.
lastIndexOf
(
"."
));
// 创建一个日期
Date
d
=
new
Date
();
SimpleDateFormat
ff
=
new
SimpleDateFormat
(
"yyyyMMddhhmmss"
);
String
time
=
ff
.
format
(
d
);
// 得到一个随机数
Random
ran
=
new
Random
();
int
num
=
ran
.
nextInt
(
10000000
);
result
=
time
+
num
+
lastname
;
return
result
;
}
//判断用户名$
public
String
myname
(){
int
result
=
0
;
try
{
String
ename
=
new
String
(
name
.
getBytes
(
"ISO8859_1"
),
"utf-8"
);
int
t
=
this
.
empService
.
getName
(
ename
);
HttpServletResponse
response
=
ServletActionContext
.
getResponse
();
response
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
if
(
t
>
0
){
result
=
1
;
}
out
.
println
(
result
);
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
//登录
public
String
login
(){
int
result
=
0
;
try
{
TEmp
e
=
new
TEmp
();
String
ename
=
new
String
(
name
.
getBytes
(
"ISO8859_1"
),
"utf-8"
);
String
epsw
=
new
String
(
psw
.
getBytes
(
"ISO8859_1"
),
"utf-8"
);
e
.
setELoginname
(
ename
);
e
.
setEPsw
(
epsw
);
int
t
=
this
.
empService
.
login
(
e
);
System
.
out
.
println
(
"t1="
+
t
);
HttpServletResponse
response
=
ServletActionContext
.
getResponse
();
response
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
if
(
t
>
0
){
result
=
1
;
}
out
.
println
(
result
);
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
//部门主管及权限的判断
public
void
flag
(){
//将ar的多少条数据遍历下几条
for
(
int
i
=
0
;
i
<
ar
.
size
();
i
++)
{
//定义一个e等于刚刚遍历出来的几条数据
TEmp
e
=
(
TEmp
)
ar
.
get
(
i
);
//若eflag等于0就显示。。。
e
.
setFlag
(
e
.
getEFlag
()==
0
?
"普工"
:
"部门主管"
);
//若eadmin等于0就显示。。。
e
.
setAdmin
(
e
.
getEAdmin
()==
0
?
"普工操作者"
:
"部门主管"
);
}
}
//联合查询 刷新页面
public
String
union1
(){
//部门下拉框增加一个“请选择”
TPart
t
=
new
TPart
();
//将部门id设为0,名称设为请选择
t
.
setPId
(
0
);
t
.
setPName
(
"请选择"
);
//部门列表为0位置上为t,也就是请选择
arpart
.
add
(
0
,
t
);
//定义一个aa等于部门表查询is=1的集合
List
aa
=
this
.
partService
.
getAllPart1
(
1
);
//将部门is等于1的多少条数据,统统遍历再增加放在arpart列表中
for
(
int
i
=
0
;
i
<
aa
.
size
();
i
++)
{
arpart
.
add
(
aa
.
get
(
i
));
}
//1.性别类
//JSP页面接收的是int类型,转换成String类型
//先指定一下性别是String类型
String
sex
=
""
;
//获取员工表的数据=1,就sex返回一个男
if
(
emp
.
getESex
().
equals
(
"1"
)){
sex
=
"男"
;
}
else
if
(
emp
.
getESex
().
equals
(
"2"
)){
sex
=
"女"
;
}
else
{
sex
=
""
;
}
//2.部门类
//判断pid是否等于0,如果等于0默认查询全部部门
String
pid
=
""
;
//获取部门表的id等于0就什么都不输出,否则就按照原id输出显示
if
(
emp
.
getTPart
().
getPId
()==
0
){
pid
=
""
;
}
else
{
pid
=
emp
.
getTPart
().
getPId
().
toString
();
}
//3.分页
allpage
();
//联合查询(int begin,int pages,String name,String sex,String pid)
this
.
ar
=
this
.
empService
.
getAllEmpUnion
(
1
,
15
,
emp
.
getETruename
(),
sex
,
pid
);
//4.转换 部门主管
flag
();
return
"union1"
;
}
//联合查询
public
String
union
(){
//部门下拉框增加一个“请选择”
TPart
t
=
new
TPart
();
t
.
setPId
(
0
);
t
.
setPName
(
"请选择"
);
arpart
.
add
(
0
,
t
);
List
aa
=
this
.
partService
.
getAllPart1
(
1
);
for
(
int
i
=
0
;
i
<
aa
.
size
();
i
++)
{
arpart
.
add
(
aa
.
get
(
i
));
}
allpage
();
this
.
ar
=
this
.
empService
.
getAllEmpPage
(
begin
,
15
,
pis
);
flag
();
return
"union"
;
}
//模拟百度查询下拉
public
String
vague
(){
try
{
String
xname
=
new
String
(
name
.
getBytes
(
"ISO8859_1"
),
"utf-8"
);
//模糊like查询
List
ar
=
this
.
empService
.
getByNameLike
(
xname
);
HttpServletResponse
response
=
ServletActionContext
.
getResponse
();
response
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
print
(
"<table>"
);
for
(
int
i
=
0
;
i
<
ar
.
size
();
i
++)
{
TEmp
e
=
(
TEmp
)
ar
.
get
(
i
);
out
.
print
(
"<tr><td οndblclick='getA(this)'>"
+
e
.
getETruename
()+
"</td></tr>"
);
}
out
.
print
(
"</table>"
);
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
转载请注明原文地址: https://ju.6miu.com/read-8332.html
技术
最新回复
(
0
)