``action;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.system.common.CommonFunction;
import com.system.common.IpUtils;
import com.system.file.utils.FilePath;
import com.system.model.Access;
import com.system.model.FtpAccess;
import com.system.model.Role;
import com.system.model.User;
import com.system.model.UserLinkAccess;
import com.system.model.UserLinkRole;
import com.system.server.UserService;
import com.system.utils.AccessTree;
import com.system.utils.TimeUtils;
import com.system.utils.Tools;
import com.system.utils.UuidUtil;
@SuppressWarnings("serial")
public class UserAction extends com.system.action.SystemAction {
public UserService userService;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
private User user = new User();
//中转到新增页面
public String useradd(){
//ToSendDBThread tt = new ToSendDBThread();
///tt.setDingdan("00e4770b99404d08bd727e34810fd437");
//tt.setTf_name(UserUtils.getUser(request).getTf_name());
//tt.start();
//log.info("程序:跳转到用户添加页面.");
request.setAttribute("depts", Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12") ? FilePath. LOCAL_CONFIG_LFF_ROOT_PATH+"/select/depts.txt": FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/depts.txt"));
request.setAttribute("offices",Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12") ? FilePath. LOCAL_CONFIG_LFF_ROOT_PATH+"/select/offices.txt": FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/offices.txt"));
request.setAttribute("dutys", Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12") ? FilePath.LOCAL_CONFIG_LFF_ROOT_PATH+"/select/dutys.txt":FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/dutys.txt"));
return "useradd";
}
public String useredit(){
//log.info("程序:跳转到用户信息编辑页面.");
user = userService.findById(request);
request.setAttribute("user", user);
request.setAttribute("depts", Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12") ? FilePath. LOCAL_CONFIG_LFF_ROOT_PATH+"/select/depts.txt": FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/depts.txt"));
request.setAttribute("offices", Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12")? FilePath. LOCAL_CONFIG_LFF_ROOT_PATH+"/select/offices.txt": FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/offices.txt"));
request.setAttribute("dutys", Tools.getModel(IpUtils.getHostIp().equals("10.1.126.12")?FilePath. LOCAL_CONFIG_LFF_ROOT_PATH+"/select/dutys.txt":FilePath.LOCAL_CONFIG_ROOT_PATH+"/select/dutys.txt"));
return "useredit";
}
//添加用户信息
public String addOrUpdateUser(){
//log.info("程序:用户信息添加或编辑执行程序.");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String tf_id = request.getParameter("tf_id");
String tf_name = request.getParameter("tf_name");
String tf_workId = request.getParameter("tf_workId");
String tf_dept = request.getParameter("tf_dept");
String tf_offices = request.getParameter("tf_offices");
String tf_duty = request.getParameter("tf_duty");
String tf_email = request.getParameter("tf_email");
String tf_right = "Y";
String tf_inputmen = ((User)request.getSession().getAttribute("login")).getTf_name();
String tf_inputdate = sdf.format(new Date());
User flag = userService.findByTf_workId(tf_workId);
if(tf_id!=null&&!"".equals(tf_id)){//当员工编号参数部位空是 修改该员工信息
userService.update(request);
}else{//否则 添加员工信息
if(flag != null){
request.setAttribute("errMsg", "此工号在系统中已存在,请确认后再提交信息");
return "errMsg";
}else{
user.setTf_name(tf_name);
user.setTf_workId(tf_workId);
user.setTf_password(CommonFunction.fu_GenPasswordWithId(tf_workId,"ims@byd"));
user.setTf_dept(tf_dept);
user.setTf_offices(tf_offices);
user.setTf_duty(tf_duty);
user.setTf_email(tf_email);
user.setTf_right(tf_right);
user.setTf_inputdate(tf_inputdate);
user.setTf_inputmen(tf_inputmen);
userService.save(user);
}
}
return SUCCESS;
}
@SuppressWarnings("unchecked")
public String sysUser(){
lockUser();
//log.info("程序:跳转到用户信息列表查看页面.");
List<User> list = (List<User>) systemService.findListByHql("from User u where u.tf_right = 'Y' order by u.tf_lastLoginTime desc");
request.setAttribute("result", list);
request.getRemoteAddr();
request.getLocalAddr();
// System.out.println("客户端Ip:"+request.getLocalAddr().toString());
// System.out.println("服务器Ip:"+IpUtils.getHostIp());
return "sysUser";
}
@SuppressWarnings("unchecked")
public void lockUser(){
List<User> list = (List<User>) systemService.findListByHql("from User u where u.tf_right = 'Y' order by u.tf_lastLoginTime desc");
for(int i = 0;i < list.size();i++){
String stime = list.get(i).getTf_lastLoginTime();
String etime = "";
etime = sdf.format(new Date());
if(stime == null){
stime = list.get(i).getTf_inputdate();
}
long date = TimeUtils.getDaySub(stime, etime);
if(date > 120){
User user = list.get(i);
user.setTf_right("N");
systemService.update(user);
}
}
}
/**
* 密码初始化
*/
public String setPass(){
String tf_workId = request.getParameter("tf_workId");
User user = userService.findByTf_workId(tf_workId);
user.setTf_password(CommonFunction.fu_GenPasswordWithId(tf_workId,"ims@byd"));
systemService.update(user);
return SUCCESS;
}
public static void main(String[] args) {
}
@SuppressWarnings("unchecked")
public String userSetAccessUI(){
String tf_user_id = res.getParameter(request, "tf_id", "");
List<AccessTree> list = new ArrayList<AccessTree>();
String hql = "from Access a where a.tf_access = '已分配' order by a.tf_subGroup,a.tf_group,a.tf_desc";
List<Access> accList = (List<Access>) systemService.findListByHql(hql);
for(int i = 0;i < accList.size();i++){
String pdHql = "from UserLinkAccess r where r.tf_user_id = '"+ tf_user_id +"' and r.tf_access_id = '"+ accList.get(i).getTf_id() +"'";
int total = systemService.getTotal(pdHql);
AccessTree at = new AccessTree();
at.setTf_id(accList.get(i).getTf_id());
at.setTf_name(accList.get(i).getTf_desc());
at.setTf_group(accList.get(i).getTf_subGroup());
at.setTf_writer(accList.get(i).getTf_writer());
if(total == 1){
at.setTf_flag(true);
}else{
at.setTf_flag(false);
}
list.add(at);
}
request.setAttribute("tf_user_id", tf_user_id);
request.setAttribute("list", list);
return "userSetAccessUI";
}
@SuppressWarnings("unchecked")
public String userSetAccess(){
String tf_user_id = res.getParameter(request, "user_id","");
String hql = "from UserLinkAccess r where r.tf_user_id = '"+ tf_user_id +"'";
List<UserLinkAccess> list = (List<UserLinkAccess>) systemService.findListByHql(hql);
String[] accessIDs = request.getParameterValues("id");
List<String> addList = new ArrayList<String>();
List<String> delList = new ArrayList<String>();
//增加权限筛选
if(accessIDs == null){
if(list != null && list.size()>0){
for(int i = 0;i < list.size();i++){
systemService.delete(list.get(i));
}
}
}else{
if(accessIDs.length > 0){
for(int i = 0;i < accessIDs.length;i++){
boolean flag = true;
for(int j = 0;j < list.size();j++){
if(accessIDs[i].equals(list.get(j).getTf_access_id())){
flag = false;
break;
}
}
if(flag){
addList.add(accessIDs[i]);
}
}
//删除权限筛选
if(list.size()>0){
for(int i = 0;i < list.size();i++){
boolean flag = true;//默认删除
for(int j = 0;j < accessIDs.length;j++){
if(list.get(i).getTf_access_id().equals(accessIDs[j])){
flag = false;
break;
}
}
if(flag){
delList.add(list.get(i).getTf_access_id());
}
}
}
//执行增加
if(addList.size()>0){
for(int j = 0;j < addList.size();j++){
UserLinkAccess r = new UserLinkAccess();
r.setTf_id(UuidUtil.get32UUID());
r.setTf_user_id(tf_user_id);
r.setTf_access_id(addList.get(j));
systemService.save(r);
}
}
//执行删除
if(delList.size()>0){
for(int j = 0;j < delList.size();j++){
String del_hql = "from UserLinkAccess r where r.tf_user_id = '"+ tf_user_id +"' and r.tf_access_id = '"+ delList.get(j) +"'";
UserLinkAccess r = (UserLinkAccess) systemService.findObjectByHql(del_hql);
systemService.delete(r);
}
}
}
}
return SUCCESS;
}
@SuppressWarnings("unchecked")
public String userSetRoleUI(){
String tf_user_id = res.getParameter(request, "tf_id", "");
List<AccessTree> list = new ArrayList<AccessTree>();
String hql = "from Role r order by r.tf_name";
List<Role> roleList = (List<Role>) systemService.findListByHql(hql);
for(int i = 0;i < roleList.size();i++){
String pdHql = "from UserLinkRole r where r.tf_user_id = '"+ tf_user_id +"' and r.tf_role_id = '"+ roleList.get(i).getTf_id() +"'";
int total = systemService.getTotal(pdHql);
AccessTree at = new AccessTree();
at.setTf_id(roleList.get(i).getTf_id());
at.setTf_name(roleList.get(i).getTf_name());
if(total == 1){
at.setTf_flag(true);
}else{
at.setTf_flag(false);
}
list.add(at);
}
request.setAttribute("tf_user_id", tf_user_id);
request.setAttribute("list", list);
return "userSetRoleUI";
}
@SuppressWarnings("unchecked")
public String userSetRole(){
String tf_user_id = res.getParameter(request, "user_id","");
String hql = "from UserLinkRole r where r.tf_user_id = '"+ tf_user_id +"'";
List<UserLinkRole> list = (List<UserLinkRole>) systemService.findListByHql(hql);
String[] roleIDs = request.getParameterValues("id");
List<String> addList = new ArrayList<String>();
List<String> delList = new ArrayList<String>();
//增加权限筛选
if(roleIDs == null){
if(list != null && list.size()>0){
for(int i = 0;i < list.size();i++){
systemService.delete(list.get(i));
}
}
}else{
if(roleIDs.length > 0){
for(int i = 0;i < roleIDs.length;i++){
boolean flag = true;
for(int j = 0;j < list.size();j++){
if(roleIDs[i].equals(list.get(j).getTf_role_id())){
flag = false;
break;
}
}
if(flag){
addList.add(roleIDs[i]);
}
}
//删除权限筛选
if(list.size()>0){
for(int i = 0;i < list.size();i++){
boolean flag = true;//默认删除
for(int j = 0;j < roleIDs.length;j++){
if(list.get(i).getTf_role_id().equals(roleIDs[j])){
flag = false;
break;
}
}
if(flag){
delList.add(list.get(i).getTf_role_id());
}
}
}
//执行增加
if(addList.size()>0){
for(int j = 0;j < addList.size();j++){
UserLinkRole r = new UserLinkRole();
r.setTf_id(UuidUtil.get32UUID());
r.setTf_user_id(tf_user_id);
r.setTf_role_id(addList.get(j));
systemService.save(r);
}
}
//执行删除
if(delList.size()>0){
for(int j = 0;j < delList.size();j++){
String del_hql = "from UserLinkRole r where r.tf_user_id = '"+ tf_user_id +"' and r.tf_role_id = '"+ delList.get(j) +"'";
UserLinkRole r = (UserLinkRole) systemService.findObjectByHql(del_hql);
systemService.delete(r);
}
}
}
}
return SUCCESS;
}
//获取用户FTP权限
public String userFtpAccessUI(){
String tf_id = res.getParameter(request, "tf_id", "");//用户ID
FtpAccess ftp = (FtpAccess) systemService.findObjectByHql("from FtpAccess f where f.tf_uid = '"+ tf_id +"'");
if(ftp == null){
ftp = new FtpAccess();
ftp.setTf_ftp("A0B0C0D0E0F0G0H0I0J0K0");
ftp.setTf_id("");
ftp.setTf_uid(tf_id);
}
request.setAttribute("ftp", ftp);
return "userFtpAccessUI";
}
//修改ftp权限
public String editUserFtpAccess(){
String tf_id = res.getParameter(request, "tf_id", "");
String tf_uid = res.getParameter(request, "tf_uid", "");
String tf_ftp = "A"+res.getParameter(request, "tf_a", "0")+"B"+res.getParameter(request, "tf_b", "0")+"C"+res.getParameter(request, "tf_c", "0")
+"D"+res.getParameter(request, "tf_d", "0")+"E"+res.getParameter(request, "tf_e", "0")+"F"+res.getParameter(request, "tf_f", "0")+"G"+res.getParameter(request, "tf_g", "0")
+"H"+res.getParameter(request, "tf_h", "0")+"I"+res.getParameter(request, "tf_i", "0")+"J"+res.getParameter(request, "tf_j", "0")+"K"+res.getParameter(request, "tf_k", "0")
+"L"+res.getParameter(request, "tf_l", "0");
if("".equals(tf_id) || tf_id == null){
//增加
FtpAccess ftp = new FtpAccess();
ftp.setTf_id(UuidUtil.get32UUID());
ftp.setTf_uid(tf_uid);
ftp.setTf_ftp(tf_ftp);
systemService.save(ftp);
}else{
//修改
FtpAccess ftp = (FtpAccess) systemService.findObjectByHql("from FtpAccess f where f.tf_id = '"+ tf_id +"'");
ftp.setTf_ftp(tf_ftp);
systemService.update(ftp);
}
return SUCCESS;
}
/**
* 禁用/启用
*/
public String updateUser(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String tf_id = res.getParameter(request, "tf_id", "");
String tf_right = res.getParameter(request, "tf_right", "");
User user = (User) systemService.findObjectByHql("from User u where u.tf_id = '"+ tf_id + "'");
user.setTf_right(tf_right);
user.setTf_lastLoginTime(sdf.format(new Date()));
user.setTf_inputdate(sdf.format(new Date()));
user.setTf_inputmen(((User)request.getSession().getAttribute("login")).getTf_name());
systemService.update(user);
return SUCCESS;
}
/**
* 用户信息查找
*/
@SuppressWarnings("unchecked")
public String searchUser(){
String tf_search = res.getParameter(request, "tf_search", "");
//System.out.println("from User u where u.tf_name like '%"+ tf_search +"%' or u.tf_workId like '%"+ tf_search +"%' or u.tf_dept like '%"+ tf_search +"%' or u.tf_offices like '%"+ tf_search +"%' or u.tf_duty like '%"+ tf_search +"%' order by u.tf_inputdate desc");
List<User> list = (List<User>) systemService.findListByHql("from User u where u.tf_name like '%"+ tf_search +"%' or u.tf_workId like '%"+ tf_search +"%' or u.tf_dept like '%"+ tf_search +"%' or u.tf_offices like '%"+ tf_search +"%' or u.tf_duty like '%"+ tf_search +"%' order by u.tf_inputdate desc");
request.setAttribute("result", list);
return "sysUser";
}
}
package com.system.common;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import sun.misc.BASE64Encoder;
public class CommonFunction {
public static String getDelay(String t1,String t2){
//时间差计算
String result = "";
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = df.parse(t1);
Date date = df.parse(t2);
long l=now.getTime()-date.getTime();
long day=l/(24*60*60*1000);
long hour=(l/(60*60*1000)-day*24);
//long min=((l/(60*1000))-day*24*60-hour*60);
//long s=(l/1000-day*24*60*60-hour*60*60-min*60);
//System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");
result = ""+day+"天"+hour+"小时";
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public static String fu_GenPasswordWithId(String q, String p) {
return EncoderByMd5(q + " " + p);
}
public static String EncoderByMd5(String str) {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
BASE64Encoder base64en = new BASE64Encoder();
String newstr = null;
try {
newstr = base64en.encode(md5.digest(str.getBytes("utf-8")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return newstr;
}
/**
*
private static int base64DecodeChars[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1,
-1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
public static String base64decode(String str) {
char c1, c2, c3, c4;
int i, len;
String out;
len = str.length();
i = 0;
out = "";
while (i < len) {
do {
c1 = (char) base64DecodeChars[str.charAt(i++) & 0xff];
} while (i < len && c1 == -1);
if (c1 == -1)
break;
do {
c2 = (char) base64DecodeChars[str.charAt(i++) & 0xff];
} while (i < len && c2 == -1);
if (c2 == -1)
break;
out += (char) ((c1 << 2) | ((c2 & 0x30) >> 4));
do {
c3 = (char) (str.charAt(i++) & 0xff);
if (c3 == 61)
return out;
c3 = (char) base64DecodeChars[c3];
} while (i < len && c3 == -1);
if (c3 == -1)
break;
out += (char) (((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
do {
c4 = (char) (str.charAt(i++) & 0xff);
if (c4 == 61)
return out;
c4 = (char) base64DecodeChars[c4];
} while (i < len && c4 == -1);
if (c4 == -1)
break;
out += (char) (((c3 & 0x03) << 6) | c4);
}
return out;
}
*/
//获取年周,例:1547-2015年47周
public static String getYearWeek(){
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int week = 0;
if(year == 2017){
week = c.get(Calendar.WEEK_OF_YEAR) + 1;
}else{
week = c.get(Calendar.WEEK_OF_YEAR);
}
String weeks = "000"+week;
weeks = weeks.substring(weeks.length()-2, weeks.length());
String years = year+"";
String yearWeek = years.substring(2,4)+weeks;
System.out.println(yearWeek);
return yearWeek;
}
public static void main(String[] args) throws ParseException {
System.out.println(Boolean.parseBoolean("true"));
}
/**
* 获取批号 AA-ZZ
*/
public static String getRlot(String rLot){
String result = "";
if(!"".equals(rLot)){
int lota = 0;
int lotb = 0;
char[] chars = rLot.toCharArray();
for(int i = 0 ; i < chars.length; i++){
if(i==0)
lota = (int)chars[i];
else if(i==1)
lotb = (int)chars[i];
}
//判断a是否+1
do{
lotb = lotb + 1;
}while(lotb == 73 || lotb == 79);
//b为Z时a进1
if(lotb > 90){
lotb = lotb - 26;
do{
lota = lota + 1;
}while(lota == 73 || lota == 79);
}
if(lota > 90){
result = "ERROR";
}else{
result = (char)lota+""+(char)lotb;
}
}else{
result = "AA";
}
return result;
}
}