386 lines
15 KiB
Java
386 lines
15 KiB
Java
package com.nis.web.controller.configuration;
|
||
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.ui.Model;
|
||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
||
import com.nis.domain.Page;
|
||
import com.nis.domain.ServiceConfigInfo;
|
||
import com.nis.domain.basics.ServiceDictInfo;
|
||
import com.nis.domain.configuration.BaseIpCfg;
|
||
import com.nis.domain.configuration.RequestInfo;
|
||
import com.nis.util.Constants;
|
||
import com.nis.web.controller.BaseController;
|
||
|
||
/**
|
||
* IP相关配置控制类
|
||
* @author dell
|
||
*
|
||
*/
|
||
@Controller
|
||
@RequestMapping("${adminPath}/cfg/ip")
|
||
public class IpCfgController extends BaseController{
|
||
|
||
@RequestMapping(value = {"ipWhiteList"})
|
||
public String ipWhiteList(Model model,BaseIpCfg baseIpCfg,HttpServletRequest request,HttpServletResponse response) {
|
||
return "/cfg/ipWhiteList";
|
||
}
|
||
|
||
|
||
@RequestMapping(value = {"ipWhiteForm"})
|
||
public String ipWhiteForm() {
|
||
return "/cfg/ipWhiteForm";
|
||
}
|
||
|
||
@RequestMapping(value = {"list"})
|
||
public String ipCfgList(Model model,Integer audit,Integer pageNo,Integer pageSize,String cfgName,@ModelAttribute("ipCfg")BaseIpCfg ipCfg,HttpServletRequest request,HttpServletResponse response) {
|
||
model.addAttribute("cfgName", cfgName);
|
||
model.addAttribute("audit", audit);
|
||
if(ipCfg!=null){
|
||
Integer serviceId=ipCfg.getServiceId();
|
||
logger.info("servcice id is "+serviceId);
|
||
if(serviceId!=null){
|
||
model.addAttribute("serviceId", serviceId);
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
String tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
logger.info("table name is "+tableName);
|
||
ipCfg.setTableName(tableName);
|
||
Page<BaseIpCfg> searchPage=new Page<BaseIpCfg>(request, response, 1);
|
||
if(pageNo!=null) searchPage.setPageNo(pageNo);
|
||
if(pageSize!=null) searchPage.setPageSize(pageSize);
|
||
if(ipCfg.getPage()!=null){
|
||
if(!StringUtils.isBlank(ipCfg.getPage().getOrderBy()));
|
||
searchPage.setOrderBy(ipCfg.getPage().getOrderBy());
|
||
}
|
||
Page<BaseIpCfg> page = ipCfgService.findPage(searchPage, ipCfg);
|
||
model.addAttribute("page", page);
|
||
model.addAttribute("action", ipCfg.getAction());
|
||
model.addAttribute("tableName", tableName);
|
||
List<RequestInfo> requestInfos=requestInfoService.getValidRequestInfo();
|
||
model.addAttribute("requestInfos", requestInfos);
|
||
List<ServiceDictInfo> fls=serviceDictInfoService.findAllFlDict();
|
||
model.addAttribute("fls", fls);
|
||
List<ServiceDictInfo> xzs=serviceDictInfoService.findAllXzDict();
|
||
model.addAttribute("xzs", xzs);
|
||
List<ServiceDictInfo> lables=serviceDictInfoService.findAllLableDict();
|
||
model.addAttribute("lables", lables);
|
||
}
|
||
}else{
|
||
logger.error("未获取到正确的serviceId");
|
||
}
|
||
}
|
||
}
|
||
|
||
return "/cfg/ipCfgList";
|
||
}
|
||
|
||
|
||
@RequestMapping(value = {"form"})
|
||
public String ipCfgForm(int action,String cfgName,Integer serviceId,Model model,HttpServletRequest request,HttpServletResponse response) {
|
||
model.addAttribute("cfgName", cfgName);
|
||
model.addAttribute("serviceId", serviceId);
|
||
model.addAttribute("action", action);
|
||
logger.info("sercice id is "+serviceId);
|
||
if(serviceId!=null){
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
String tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
logger.info("table name is "+tableName);
|
||
String className=ipCfgService.getClassName(tableName);
|
||
logger.info("class name is "+className);
|
||
String packageName=BaseIpCfg.class.getPackage().getName();
|
||
try {
|
||
//通过反射获得BaseIpCfg的子类的实例,并调用子类的initDefaultValue初始化默认值
|
||
Class clazz=Class.forName(packageName+"."+className);
|
||
BaseIpCfg ipcfg=(BaseIpCfg)clazz.newInstance();
|
||
ipcfg.setTableName(tableName);
|
||
ipcfg.initDefaultValue();
|
||
ipcfg.setAction(action);
|
||
ipcfg.setServiceId(serviceId);
|
||
model.addAttribute("_cfg", ipcfg);
|
||
long compileId=this.getCompileId();
|
||
model.addAttribute("tableName", tableName);
|
||
List<RequestInfo> requestInfos=requestInfoService.getValidRequestInfo();
|
||
model.addAttribute("requestInfos", requestInfos);
|
||
List<ServiceDictInfo> fls=serviceDictInfoService.findFlDict();
|
||
model.addAttribute("fls", fls);
|
||
List<ServiceDictInfo> xzs=serviceDictInfoService.findXzDict();
|
||
model.addAttribute("xzs", xzs);
|
||
List<ServiceDictInfo> lables=serviceDictInfoService.findLableDict();
|
||
model.addAttribute("lables", lables);
|
||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||
// TODO Auto-generated catch block
|
||
logger.error("打开新增IP窗口失败",e);
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
logger.error("未获取到正确的serviceId");
|
||
}
|
||
|
||
return "/cfg/ipCfgForm";
|
||
}
|
||
@RequestMapping(value = {"updateForm"})
|
||
public String updateIpCfgForm(String tableName,int action,long cfgId,String cfgName,Integer serviceId,Model model,HttpServletRequest request,HttpServletResponse response) {
|
||
model.addAttribute("cfgName", cfgName);
|
||
model.addAttribute("serviceId", serviceId);
|
||
model.addAttribute("action", action);
|
||
if(!StringUtils.isBlank(tableName)){
|
||
logger.info("table name is "+tableName);
|
||
BaseIpCfg searchBean=new BaseIpCfg();
|
||
searchBean.setCfgId(cfgId);
|
||
searchBean.setTableName(tableName);
|
||
BaseIpCfg ipCfg=ipCfgService.getIpCfgById(searchBean);
|
||
model.addAttribute("_cfg", ipCfg);
|
||
model.addAttribute("tableName", tableName);
|
||
List<RequestInfo> requestInfos=requestInfoService.getAllRequestInfo();
|
||
model.addAttribute("requestInfos", requestInfos);
|
||
List<ServiceDictInfo> fls=serviceDictInfoService.findAllFlDict();
|
||
model.addAttribute("fls", fls);
|
||
List<ServiceDictInfo> xzs=serviceDictInfoService.findAllXzDict();
|
||
model.addAttribute("xzs", xzs);
|
||
List<ServiceDictInfo> lables=serviceDictInfoService.findAllLableDict();
|
||
model.addAttribute("lables", lables);
|
||
}else if(serviceId!=null){
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
logger.info("table name is "+tableName);
|
||
BaseIpCfg searchBean=new BaseIpCfg();
|
||
searchBean.setCfgId(cfgId);
|
||
searchBean.setTableName(tableName);
|
||
BaseIpCfg ipCfg=ipCfgService.getIpCfgById(searchBean);
|
||
model.addAttribute("_cfg", ipCfg);
|
||
model.addAttribute("tableName", tableName);
|
||
List<RequestInfo> requestInfos=requestInfoService.getAllRequestInfo();
|
||
model.addAttribute("requestInfos", requestInfos);
|
||
List<ServiceDictInfo> fls=serviceDictInfoService.findAllFlDict();
|
||
model.addAttribute("fls", fls);
|
||
List<ServiceDictInfo> xzs=serviceDictInfoService.findAllXzDict();
|
||
model.addAttribute("xzs", xzs);
|
||
List<ServiceDictInfo> lables=serviceDictInfoService.findAllLableDict();
|
||
model.addAttribute("lables", lables);
|
||
|
||
}
|
||
}
|
||
}else{
|
||
logger.error("未获取到正确的表名");
|
||
}
|
||
|
||
return "/cfg/ipCfgForm";
|
||
}
|
||
|
||
/**
|
||
*
|
||
* addIpCfg(新增IP配置)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*String
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@RequestMapping(value = {"saveOrUpdateCfg"})
|
||
public String saveOrUpdateIpCfg(String cfgName,Model model, BaseIpCfg ipCfg) {
|
||
model.addAttribute("cfgName",cfgName);
|
||
model.addAttribute("cfgType", "ip");
|
||
logger.info("saveOrUpdateIpCfg loaded");
|
||
if(ipCfg==null){
|
||
logger.error("无法保存空的配置!");
|
||
addMessage(model,"保存失败!");
|
||
}else if(!StringUtils.isBlank(ipCfg.getTableName())){
|
||
int serviceId=ipCfg.getServiceId();
|
||
long compileId=getCompileId();
|
||
ipCfg.setIsValid(Constants.VALID_NO);
|
||
ipCfg.setIsAudit(Constants.AUDIT_NOT_YET);
|
||
ipCfg.setCompileId(compileId);
|
||
if(ipCfg.getCfgId()==null){
|
||
ipCfg.setCreatorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setCreateTime(new Date());
|
||
ipCfgService.addIpCfg(ipCfg);
|
||
}else{
|
||
ipCfg.setEditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setEditTime(new Date());
|
||
ipCfgService.updateIpCfg(ipCfg);
|
||
}
|
||
model.addAttribute("serviceId",serviceId);
|
||
model.addAttribute("action",ipCfg.getAction());
|
||
model.addAttribute("tableName", ipCfg.getTableName());
|
||
addMessage(model,"保存成功,正在为您跳转页面...");
|
||
}else if(ipCfg.getServiceId()!=null){
|
||
int serviceId=ipCfg.getServiceId();
|
||
model.addAttribute("serviceId",serviceId);
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
String tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
long compileId=getCompileId();
|
||
ipCfg.setTableName(tableName);
|
||
ipCfg.setCreatorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setCreateTime(new Date());
|
||
ipCfg.setIsValid(Constants.VALID_NO);
|
||
ipCfg.setIsAudit(Constants.AUDIT_NOT_YET);
|
||
ipCfg.setCompileId(compileId);
|
||
if(ipCfg.getCfgId()==null){
|
||
ipCfg.setCreatorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setCreateTime(new Date());
|
||
}else{
|
||
ipCfg.setEditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setEditTime(new Date());
|
||
ipCfgService.updateIpCfg(ipCfg);
|
||
}
|
||
model.addAttribute("action",ipCfg.getAction());
|
||
model.addAttribute("tableName", ipCfg.getTableName());
|
||
addMessage(model,"保存成功,正在为您跳转页面...");
|
||
}
|
||
}
|
||
}else{
|
||
addMessage(model,"保存失败!");
|
||
logger.error("无法确定IP配置的表名!");
|
||
}
|
||
return "/cfg/resultPage";//StringEscapeUtils.escapeHtml4("?serviceId="+ipCfg.getServiceId()+"&action="+ipCfg.getAction()+"&cfgName="+cfgName);
|
||
}
|
||
|
||
/**
|
||
*
|
||
* auditIpCfg(审核IP配置)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*String
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@RequestMapping(value = {"auditCfg"})
|
||
public String auditIpCfg(String cfgName,BaseIpCfg ipCfg,Model model) {
|
||
model.addAttribute("cfgName", cfgName);
|
||
if(ipCfg==null){
|
||
logger.error("无法审核空的配置!");
|
||
}else if(!StringUtils.isBlank(ipCfg.getTableName())){
|
||
int audit=ipCfgService.getIsAudit(ipCfg);
|
||
if(audit==Constants.AUDIT_YES&&ipCfg.getIsAudit()!=Constants.AUDIT_NOT_YES){
|
||
logger.error("审核通过的配置只能取消审核通过!");
|
||
}else{
|
||
ipCfg.setAuditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setAuditTime(new Date());
|
||
|
||
if(ipCfg.getIsAudit()==Constants.AUDIT_NOT_YES){//取消审核通过,设置有效标志为0
|
||
ipCfg.setIsValid(Constants.VALID_NO);
|
||
}else if(ipCfg.getIsAudit()==Constants.AUDIT_YES){//审核通过,设置有效标志为1
|
||
ipCfg.setIsValid(Constants.VALID_YES);
|
||
}
|
||
int result=ipCfgService.auditIpCfg(ipCfg);
|
||
}
|
||
}else if(ipCfg.getServiceId()!=null){
|
||
int serviceId=ipCfg.getServiceId();
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
String tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
ipCfg.setTableName(tableName);
|
||
int audit=ipCfgService.getIsAudit(ipCfg);
|
||
if(audit==Constants.AUDIT_YES&&ipCfg.getIsAudit()!=Constants.AUDIT_NOT_YES){
|
||
logger.error("审核通过的配置只能取消审核通过!");
|
||
}else{
|
||
ipCfg.setAuditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setAuditTime(new Date());
|
||
|
||
if(ipCfg.getIsAudit()==Constants.AUDIT_NOT_YES){//取消审核通过,设置有效标志为0
|
||
ipCfg.setIsValid(Constants.VALID_NO);
|
||
}else if(ipCfg.getIsAudit()==Constants.AUDIT_YES){//审核通过,设置有效标志为1
|
||
ipCfg.setIsValid(Constants.VALID_YES);
|
||
}
|
||
int result=ipCfgService.auditIpCfg(ipCfg);
|
||
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
logger.error("无法确定IP配置的表名!");
|
||
}
|
||
return "redirect:" + adminPath + "/cfg/ip/list?serviceId="+ipCfg.getServiceId()+"&action="+ipCfg.getAction()+"&cfgName"+cfgName;
|
||
}
|
||
/**
|
||
*
|
||
* auditIpCfg(删除IP配置,逻辑删除)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*String
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
@RequestMapping(value = {"deleteCfg"})
|
||
public String deleteIpCfg(String tableName,int action,long cfgId,String cfgName,Integer serviceId,Model model) {
|
||
model.addAttribute("cfgName", cfgName);
|
||
model.addAttribute("serviceId", serviceId);
|
||
model.addAttribute("action", action);
|
||
model.addAttribute("cfgType", "ip");
|
||
if(!StringUtils.isBlank(tableName)){
|
||
int audit=ipCfgService.getIsAudit(tableName,cfgId);
|
||
//未审核时可删除
|
||
if(audit!=Constants.AUDIT_YES){
|
||
BaseIpCfg ipCfg=new BaseIpCfg();
|
||
ipCfg.setCfgId(cfgId);
|
||
ipCfg.setTableName(tableName);
|
||
ipCfg.setEditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setEditTime(new Date());
|
||
ipCfg.setIsValid(Constants.VALID_DEL);
|
||
int result=ipCfgService.deleteIpCfg(ipCfg);
|
||
model.addAttribute("tableName", tableName);
|
||
addMessage(model,"删除成功,正在为您跳转页面...");
|
||
}else{
|
||
logger.error("通过审核的配置不能删除!");
|
||
}
|
||
|
||
}else if(serviceId!=null){
|
||
ServiceConfigInfo serviceConfigInfo=serviceConfigInfoService.findSysServiceConfigInfo(serviceId);
|
||
if(serviceConfigInfo!=null){
|
||
tableName=serviceConfigInfo.getTableName();
|
||
if(!StringUtils.isBlank(tableName)){
|
||
BaseIpCfg ipCfg=new BaseIpCfg();
|
||
ipCfg.setCfgId(cfgId);
|
||
ipCfg.setTableName(tableName);
|
||
int audit=ipCfgService.getIsAudit(ipCfg);
|
||
//未审核时可删除
|
||
if(audit!=Constants.AUDIT_YES){
|
||
ipCfg.setEditorId(ipCfg.getCurrentUser().getId());
|
||
ipCfg.setEditTime(new Date());
|
||
ipCfg.setIsValid(Constants.VALID_DEL);
|
||
int result=ipCfgService.deleteIpCfg(ipCfg);
|
||
model.addAttribute("tableName", tableName);
|
||
addMessage(model,"删除成功,正在为您跳转页面...");
|
||
}else{
|
||
logger.error("通过审核的配置不能删除!");
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
logger.error("无法确定IP配置的表名!");
|
||
}
|
||
return "/cfg/resultPage";
|
||
}
|
||
/**
|
||
*
|
||
* getCompileId(获取编译ID)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*long
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
protected long getCompileId(){
|
||
return 0;
|
||
}
|
||
}
|