用户管理模块
1、数据新增事务回滚提交处理 2、页面必填样式错位优化 3、cgi接口相关国际化添加 app协议导出字段调整
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.nis.web.service.configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -9,20 +11,28 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.eclipse.jetty.util.ajax.JSON;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.ui.Model;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.configuration.AppPolicyCfg;
|
||||
import com.nis.domain.configuration.CfgIndexInfo;
|
||||
import com.nis.domain.configuration.UserManage;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.dao.configuration.AppCfgDao;
|
||||
import com.nis.web.dao.configuration.IpCfgDao;
|
||||
import com.nis.web.dao.configuration.UserManageDao;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.BaseService;
|
||||
import com.nis.web.service.SpringContextHolder;
|
||||
|
||||
@Service
|
||||
public class UserManageService extends BaseService{
|
||||
@@ -45,77 +55,128 @@ public class UserManageService extends BaseService{
|
||||
return userManageDao.getUserById(id);
|
||||
}
|
||||
|
||||
public void save(UserManage entity,Model model, HttpServletRequest request){
|
||||
Date createTime=new Date();
|
||||
if(entity.getId()==null){
|
||||
public static String getMessageIp(String[] oldIp,String[] ip){
|
||||
String ips=null;
|
||||
for (int i = 0; i < oldIp.length; i++) {
|
||||
boolean flag=true;
|
||||
for (int j = 0; j < ip.length; j++) {
|
||||
if(oldIp[i].equals(ip[j])){
|
||||
flag=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag){
|
||||
if(ips==null){
|
||||
ips=oldIp[i];
|
||||
}else{
|
||||
ips=ips+","+oldIp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void saveip(UserManage entity,String ips,Model model, HttpServletRequest request){
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
try {
|
||||
entity.setCreateTime(createTime);
|
||||
entity.setCreatorId(entity.getCurrentUser().getId());
|
||||
entity.setIsValid(Constants.VALID_NO);
|
||||
userManageDao.insert(entity);
|
||||
//cgi接口添加
|
||||
String[] ipArray = entity.getServerIp().split(",");
|
||||
for(String ip :ipArray){
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
UserManage user=userManageDao.getUserByLoginName(entity.getUserName());
|
||||
if(user==null){
|
||||
entity.setServerIp(ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).insert(entity);
|
||||
}else{
|
||||
user.setServerIp(user.getServerIp()+","+ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).update(user);
|
||||
}
|
||||
//cgi接口添加
|
||||
//循环调用接口增加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ip);
|
||||
params.put("server_ip", ips);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_CREATE,request);
|
||||
//返回处理
|
||||
}
|
||||
} catch (MaatConvertException e) {
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_CREATE ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map = (Map<String, String>) JSON.parse(recv);
|
||||
String error = map.get("error");
|
||||
if (!StringUtil.isEmpty(error)) {
|
||||
batchSqlSession.rollback();
|
||||
} else {
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("获取编译ID出错");
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
entity.setEditTime(createTime);
|
||||
entity.setEditorId(entity.getCurrentUser().getId());
|
||||
//获取修改之前数据
|
||||
UserManage olduser=userManageDao.getUserById(String.valueOf(entity.getId()));
|
||||
userManageDao.update(entity);
|
||||
//cgi接口删除旧数据
|
||||
String[] ipArray = olduser.getServerIp().split(",");
|
||||
for(String ip :ipArray){
|
||||
//循环调用接口删除
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", olduser.getUserName());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
||||
//返回处理
|
||||
|
||||
} finally {
|
||||
if (batchSqlSession != null) {
|
||||
batchSqlSession.close();
|
||||
}
|
||||
if(StringUtil.isEmpty(entity.getUserName())){
|
||||
entity.setUserName(olduser.getUserName());
|
||||
}
|
||||
if(StringUtil.isEmpty(entity.getUserPwd())){
|
||||
entity.setUserPwd(olduser.getUserPwd());
|
||||
}
|
||||
String[] newIpArray = entity.getServerIp().split(",");
|
||||
for(String newIp :newIpArray){
|
||||
//循环调用接口添加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", newIp);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_CREATE,request);
|
||||
//返回处理
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("获取编译ID出错");
|
||||
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void updateip(UserManage entity,String ips,int num,Model model, HttpServletRequest request){
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
try {
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
if(num==0){
|
||||
UserManage olduser=userManageDao.getUserById(String.valueOf(entity.getId()));
|
||||
//接口旧数据删除
|
||||
//cgi接口删除旧数据
|
||||
String[] ipArray = olduser.getServerIp().split(",");
|
||||
for(String ip :ipArray){
|
||||
//循环调用接口删除
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ip);
|
||||
params.put("user_name", olduser.getUserName());
|
||||
Map<String,String> map=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
||||
//返回处理
|
||||
}
|
||||
entity.setServerIp(ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).update(entity);
|
||||
}else{
|
||||
UserManage user=userManageDao.getUserById(String.valueOf(entity.getId()));
|
||||
user.setServerIp(user.getServerIp()+","+ips);
|
||||
((UserManageDao) batchSqlSession.getMapper(UserManageDao.class)).update(user);
|
||||
}
|
||||
// cgi接口添加
|
||||
// 循环调用接口增加
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("server_ip", ips);
|
||||
params.put("user_name", entity.getUserName());
|
||||
params.put("user_pwd", entity.getUserPwd());
|
||||
String url = Constants.IP_REUSE_CALL_CGI_URL + Constants.NTC_IP_REUSE_USER_CREATE;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map = (Map<String, String>) JSON.parse(recv);
|
||||
String error = map.get("error");
|
||||
if (!StringUtil.isEmpty(error)) {
|
||||
batchSqlSession.rollback();
|
||||
} else {
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (batchSqlSession != null) {
|
||||
batchSqlSession.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> getUrl(Map<String, Object> params,String urlType,HttpServletRequest request){
|
||||
Map<String,String> map=new HashMap<String,String>();
|
||||
try{
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ urlType ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
logger.info("查询结果:" + recv);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
map=(Map<String,String>)JSON.parse(recv);
|
||||
}
|
||||
@@ -134,7 +195,6 @@ public class UserManageService extends BaseService{
|
||||
try{
|
||||
String url =Constants.IP_REUSE_CALL_CGI_URL+ Constants.NTC_IP_REUSE_USER_GET ;
|
||||
String recv = HttpClientUtil.getCGI(url, params, request);
|
||||
logger.info("查询结果:" + recv);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
map=(Map<String,String>)JSON.parse(recv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user