2018-11-27 09:54:40 +08:00
|
|
|
package com.nis.web.service.configuration;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
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.google.gson.Gson;
|
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
import com.nis.domain.basics.IpReuseIpCfg;
|
|
|
|
|
import com.nis.domain.configuration.UserManage;
|
|
|
|
|
import com.nis.domain.log.NtcIpLog;
|
|
|
|
|
import com.nis.domain.maat.LogRecvData;
|
|
|
|
|
import com.nis.domain.maat.MaatCfg;
|
|
|
|
|
import com.nis.domain.maat.ToMaatBean;
|
|
|
|
|
import com.nis.domain.maat.ToMaatResult;
|
|
|
|
|
import com.nis.exceptions.MaatConvertException;
|
|
|
|
|
import com.nis.util.ConfigServiceUtil;
|
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
import com.nis.util.StringUtil;
|
|
|
|
|
import com.nis.util.httpclient.HttpClientUtil;
|
|
|
|
|
import com.nis.web.dao.configuration.UserManageDao;
|
|
|
|
|
import com.nis.web.security.UserUtils;
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class UserManageService extends BaseService{
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
protected UserManageDao userManageDao;
|
|
|
|
|
|
|
|
|
|
public Page<UserManage> findPage(Page<UserManage> page, UserManage entity) {
|
|
|
|
|
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
|
|
|
|
|
entity.setPage(page);
|
|
|
|
|
List<UserManage> list=userManageDao.findList(entity);
|
|
|
|
|
page.setList(list);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
public UserManage getUserByLoginName(String userName) {
|
|
|
|
|
return userManageDao.getUserByLoginName(userName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserManage getUserById(String id) {
|
|
|
|
|
return userManageDao.getUserById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save(UserManage entity,Model model, HttpServletRequest request){
|
|
|
|
|
Date createTime=new Date();
|
|
|
|
|
if(entity.getId()==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){
|
|
|
|
|
//循环调用接口增加
|
2018-11-28 19:06:14 +08:00
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("server_ip", ip);
|
|
|
|
|
params.put("user_name", entity.getUserName());
|
|
|
|
|
params.put("user_pwd", entity.getUserPwd());
|
|
|
|
|
LogRecvData<UserManage> fromJson=getUrl(params,Constants.NTC_IP_REUSE_USER_CREATE,request);
|
|
|
|
|
//返回处理
|
|
|
|
|
if (fromJson.getStatus().intValue() == 200) {
|
|
|
|
|
}else{
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
String url="?cmd=UserCreate&server_ip="+ip+"&user_name="+entity.getUserName()+"&user_pwd="+entity.getUserPwd();
|
|
|
|
|
System.out.println(url);
|
2018-11-28 19:06:14 +08:00
|
|
|
}*/
|
|
|
|
|
} catch (MaatConvertException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.info("获取编译ID出错");
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
}else{
|
2018-11-28 19:06:14 +08:00
|
|
|
try {
|
2018-11-27 09:54:40 +08:00
|
|
|
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){
|
|
|
|
|
//循环调用接口删除
|
2018-11-28 19:06:14 +08:00
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("server_ip", ip);
|
|
|
|
|
params.put("user_name", olduser.getUserName());
|
|
|
|
|
LogRecvData<UserManage> fromJson=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
|
|
|
|
//返回处理
|
|
|
|
|
if (fromJson.getStatus().intValue() == 200) {
|
|
|
|
|
}else{
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
}*/
|
|
|
|
|
if(StringUtil.isEmpty(entity.getUserName())){
|
|
|
|
|
entity.setUserName(olduser.getUserName());
|
|
|
|
|
}
|
|
|
|
|
if(StringUtil.isEmpty(entity.getUserPwd())){
|
|
|
|
|
entity.setUserPwd(olduser.getUserPwd());
|
|
|
|
|
}
|
2018-11-28 19:06:14 +08:00
|
|
|
/* String[] newIpArray = entity.getServerIp().split(",");
|
2018-11-27 09:54:40 +08:00
|
|
|
for(String newIp :newIpArray){
|
|
|
|
|
//循环调用接口添加
|
2018-11-28 19:06:14 +08:00
|
|
|
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());
|
|
|
|
|
LogRecvData<UserManage> fromJson=getUrl(params,Constants.NTC_IP_REUSE_USER_CREATE,request);
|
|
|
|
|
//返回处理
|
|
|
|
|
if (fromJson.getStatus().intValue() == 200) {
|
|
|
|
|
}else{
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
logger.info("获取编译ID出错");
|
|
|
|
|
throw new MaatConvertException("<spring:message code=\"request_service_failed\"/>");
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
}
|
2018-11-28 19:06:14 +08:00
|
|
|
public LogRecvData<UserManage> getUrl(Map<String, Object> params,String urlType,HttpServletRequest request){
|
|
|
|
|
LogRecvData<UserManage> fromJson = new LogRecvData<UserManage>();
|
2018-11-27 09:54:40 +08:00
|
|
|
try{
|
2018-11-28 19:06:14 +08:00
|
|
|
String url ="URL"+ urlType ;
|
|
|
|
|
String recv = HttpClientUtil.getCGI(url, params, request);
|
2018-11-27 09:54:40 +08:00
|
|
|
logger.info("查询结果:" + recv);
|
|
|
|
|
if (StringUtils.isNotBlank(recv)) {
|
|
|
|
|
Gson gson = new GsonBuilder().create();
|
2018-11-28 19:06:14 +08:00
|
|
|
fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<UserManage>>(){}.getType());
|
2018-11-27 09:54:40 +08:00
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("查询失败", e);
|
2018-11-27 18:14:06 +08:00
|
|
|
}
|
2018-11-28 19:06:14 +08:00
|
|
|
return fromJson;
|
2018-11-27 18:14:06 +08:00
|
|
|
}
|
|
|
|
|
|
2018-11-28 19:06:14 +08:00
|
|
|
/* //根据vpn服务器ip获取用户vpn服务器ip信息
|
|
|
|
|
public UserManage getUser(String serverIp,HttpServletRequest request){
|
2018-11-27 18:14:06 +08:00
|
|
|
UserManage user=new UserManage();
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("server_ip", serverIp);
|
|
|
|
|
try{
|
2018-11-28 19:06:14 +08:00
|
|
|
String url ="URL"+ Constants.NTC_IP_REUSE_USER_LIST ;
|
|
|
|
|
//String recv = HttpClientUtil.getCGI(url, params, request);
|
|
|
|
|
String recv="{\"data\":{\"list\":[{\"userName\":\"zhangsan\",\"createOn\":\"2018-11-01 14:51:12 \",\"updatedOn\":\"2018-11-02 10:54:07 \",\"outgoingUnicastPackets\":\"537,962\",\"outgoingUnicastTotalSize\":\"278,885\",\"outgoingBroadcastPackets\":\"51,130,890\""
|
|
|
|
|
+ ",\"outgoingBroadcastTotalSize\":\"4781,154\",\"incomingUnicastPackets\":\"454,121\",\"incomingUnicastTotalSize\":\"45,565\",\"incomingBroadcastPackets\":\"454,4545\""
|
|
|
|
|
+ ",\"incomingBroadcastTotalSize\":\"4781,154\",\"numberOfLogins\":\"124\"}]}}";
|
|
|
|
|
recv=HttpClientUtil.galaxyMessageFormat(recv);
|
2018-11-27 18:14:06 +08:00
|
|
|
logger.info("查询结果:" + recv);
|
|
|
|
|
if (StringUtils.isNotBlank(recv)) {
|
|
|
|
|
Gson gson = new GsonBuilder().create();
|
|
|
|
|
LogRecvData<UserManage> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<UserManage>>(){}.getType());
|
2018-11-28 19:06:14 +08:00
|
|
|
user=fromJson.getData().getList().get(0);
|
2018-11-27 18:14:06 +08:00
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("查询失败", e);
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
return user;
|
2018-11-28 19:06:14 +08:00
|
|
|
}*/
|
2018-11-27 09:54:40 +08:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param isAudit
|
|
|
|
|
* @param isValid
|
|
|
|
|
* @param ids compileIds
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-11-28 19:06:14 +08:00
|
|
|
public void delete(Integer isValid,String ids,HttpServletRequest request){
|
|
|
|
|
/*try{*/
|
2018-11-27 09:54:40 +08:00
|
|
|
String[] idArray = ids.split(",");
|
|
|
|
|
List<UserManage> userList=new ArrayList<UserManage>();
|
|
|
|
|
for(String id :idArray){
|
|
|
|
|
UserManage entity = new UserManage();
|
|
|
|
|
entity=userManageDao.getUserById(id);
|
|
|
|
|
if(entity!=null){
|
|
|
|
|
userList.add(entity);
|
|
|
|
|
}
|
|
|
|
|
entity.setId(Long.valueOf(id));
|
|
|
|
|
entity.setIsValid(isValid);
|
|
|
|
|
entity.setEditorId(UserUtils.getUser().getId());
|
|
|
|
|
entity.setEditTime(new Date());
|
|
|
|
|
userManageDao.update(entity);
|
|
|
|
|
}
|
|
|
|
|
//cgi接口删除旧数据
|
2018-11-28 19:06:14 +08:00
|
|
|
/* for (int i = 0; i < userList.size(); i++) {
|
2018-11-27 09:54:40 +08:00
|
|
|
String[] ipArray = userList.get(i).getServerIp().split(",");
|
|
|
|
|
for(String ip :ipArray){
|
|
|
|
|
//循环调用接口删除
|
2018-11-28 19:06:14 +08:00
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("server_ip", ip);
|
|
|
|
|
params.put("user_name",userList.get(i).getUserName());
|
|
|
|
|
LogRecvData<UserManage> fromJson=getUrl(params,Constants.NTC_IP_REUSE_USER_DELETE,request);
|
|
|
|
|
//返回处理
|
|
|
|
|
if (fromJson.getStatus().intValue() == 200) {
|
|
|
|
|
}else{
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-28 19:06:14 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("查询失败", e);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 17:50:33 +08:00
|
|
|
public List<UserManage> findUsers() {
|
|
|
|
|
return userManageDao.findUsers();
|
|
|
|
|
}
|
2018-11-27 09:54:40 +08:00
|
|
|
}
|
2018-11-28 19:06:14 +08:00
|
|
|
|