赞
踩
- package cn.jeeweb.modules.vrgateway.controller;
-
- import cn.jeeweb.core.common.controller.BaseCRUDController;
- import cn.jeeweb.core.model.AjaxJson;
- import cn.jeeweb.core.query.data.Queryable;
- import cn.jeeweb.core.security.shiro.authz.annotation.RequiresPathPermission;
- import cn.jeeweb.modules.sys.entity.Role;
- import cn.jeeweb.modules.sys.entity.User;
- import cn.jeeweb.modules.sys.service.IRoleService;
- import cn.jeeweb.modules.sys.service.IUserService;
- import cn.jeeweb.modules.sys.utils.UserUtils;
- import cn.jeeweb.modules.vrgateway.entity.VrGateway;
- import cn.jeeweb.modules.vrgateway.service.IVrGatewayService;
- import cn.jeeweb.modules.vrgateway.util.ExecuteLinux;
- import cn.jeeweb.modules.vrgateway.util.WriteXml;
- import cn.jeeweb.modules.vrline.service.IVrUserLineService;
- import java.io.PrintStream;
- import java.util.ArrayList;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.hibernate.criterion.DetachedCriteria;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- @Controller
- @RequestMapping({"${admin.url.prefix}/vrgateway/vrgateway"})
- @RequiresPathPermission("vrgateway:vrgateway")
- public class VrGatewayController extends BaseCRUDController<VrGateway, String>
- {
-
- @Autowired
- private IUserService iUserService;
-
- @Autowired
- private IRoleService iRoleService;
-
- @Autowired
- private IVrGatewayService iVrGatewayService;
-
- @Autowired
- private IVrUserLineService iVrUserLineService;
-
- public void preEdit(VrGateway entity, Model model, HttpServletRequest request, HttpServletResponse response)
- {
- User user = UserUtils.getUser();
- List roleList = UserUtils.getRoleList();
- boolean flag = false;
- boolean dlsflag = false;
- boolean yysflag = false;
- for (Role r : roleList) {
- if ("cjgly".equals(r.getCode())) {
- flag = true;
- }
- if ("dls".equals(r.getCode())) {
- dlsflag = true;
- }
- if ("yys".equals(r.getCode())) {
- yysflag = true;
- }
- }
- List userList = new ArrayList();
- String sql = "select * from sys_user where del_flag='0'";
- if (flag) {
- userList = this.iUserService.listEntityByAliasSql(sql, null);
- } else if (dlsflag) {
- sql = sql + " and create_by ='" + user.getId() + "'";
- userList = this.iUserService.listEntityByAliasSql(sql, null);
- userList.add(user);
- } else if (yysflag) {
- sql = sql + " and yysId ='" + user.getId() + "'";
- userList = this.iUserService.listEntityByAliasSql(sql, null);
- userList.add(user);
- }
- request.setAttribute("userList", userList);
- request.setAttribute("vrgateway", entity);
- super.preEdit(entity, model, request, response);
- }
-
- public void preAjaxList(Queryable queryable, DetachedCriteria detachedCriteria, HttpServletRequest request, HttpServletResponse response)
- {
- User user = UserUtils.getUser();
- List roleList = UserUtils.getRoleList();
- boolean flag = false;
- boolean yysFlag = false;
- boolean dlsFlag = false;
- for (Role r : roleList) {
- if ("cjgly".equals(r.getCode())) {
- flag = true;
- }
- if ("yys".equals(r.getCode())) {
- yysFlag = true;
- }
- if ("dls".equals(r.getCode())) {
- dlsFlag = true;
- }
- }
- if (yysFlag)
- queryable.addCondition("yysId", user);
- else if (dlsFlag) {
- queryable.addCondition("dlsId", user);
- }
- else if (!flag) {
- queryable.addCondition("gatewayUser", user);
- }
-
- super.preAjaxList(queryable, detachedCriteria, request, response);
- }
-
- public AjaxJson create(Model model, VrGateway entity, BindingResult result, HttpServletRequest request, HttpServletResponse response)
- {
- String id = request.getParameter("userIdstr");
- if ((id != null) && (!"".equals(id))) {
- User user = (User)this.iUserService.get(id);
- entity.setGatewayUser(user);
- }
- User dquser = UserUtils.getUser();
- Role dqrole = UserUtils.getRole();
- if ("dls".equals(dqrole.getCode())) {
- entity.setDlsId(dquser);
- if ((dquser.getYysId() != null) && (!"".equals(dquser.getYysId())))
- entity.setYysId(UserUtils.get(dquser.getYysId()));
- }
- else if ("yys".equals(dqrole.getCode())) {
- entity.setYysId(dquser);
- if ((id != null) && (!"".equals(id))) {
- List roleList = this.iRoleService.findListByUserId(id);
- User user = (User)this.iUserService.get(id);
- for (Role r : roleList) {
- if ("dls".equals(r.getCode())) {
- entity.setDlsId(UserUtils.get(id));
- }
- if ("DLSGLY".equals(r.getCode())) {
- if ((user.getDlsId() != null) && (!"".equals(user.getDlsId()))) {
- entity.setDlsId(UserUtils.get(user.getDlsId()));
- }
- if ((user.getYysId() != null) && (!"".equals(user.getYysId())))
- entity.setYysId(UserUtils.get(user.getYysId()));
- }
- }
- }
- }
- else if ("DLSGLY".equals(dqrole.getCode())) {
- if ((dquser.getDlsId() != null) && (!"".equals(dquser.getDlsId()))) {
- entity.setDlsId(UserUtils.get(dquser.getDlsId()));
- }
- if ((dquser.getYysId() != null) && (!"".equals(dquser.getYysId()))) {
- entity.setYysId(UserUtils.get(dquser.getYysId()));
- }
- }
- WriteXml wx = new WriteXml();
- wx.writeXmlGoip(entity.getGatewayUserId(), entity.getPassword(), entity.getGatewayUserId() + ".xml");
- ExecuteLinux el = new ExecuteLinux();
- el.executeNewFlow();
- return super.create(model, entity, result, request, response);
- }
-
- public AjaxJson update(Model model, VrGateway entity, BindingResult result, HttpServletRequest request, HttpServletResponse response)
- {
- String id = request.getParameter("userIdstr");
- VrGateway vg = (VrGateway)get(entity.getId());
- String sql = "update vr_gateway vg set vg.gatewayName='" + entity.getGatewayName() + "',vg.gatewayUserId='" + entity.getGatewayUserId() + "',vg.password='" + entity.getPassword() + "'";
- if ((id != null) && (!"".equals(id))) {
- User user = (User)this.iUserService.get(id);
- sql = sql + ", vg.gatewayUser='" + user.getId() + "'";
- } else {
- sql = sql + ", vg.gatewayUser=null";
- }
- User dquser = UserUtils.getUser();
- Role dqrole = UserUtils.getRole();
- if ("dls".equals(dqrole.getCode())) {
- sql = sql + ", vg.dlsId='" + dquser.getId() + "',vg.yysId='" + dquser.getYysId() + "'";
- }
- else if ("yys".equals(dqrole.getCode())) {
- if ((id != null) && (!"".equals(id))) {
- List roleList = this.iRoleService.findListByUserId(id);
- User user = (User)this.iUserService.get(id);
- for (Role r : roleList) {
- if ("dls".equals(r.getCode())) {
- sql = sql + ", vg.dlsId='" + user.getId() + "',vg.yysId='" + user.getYysId() + "'";
- }
- if ("DLSGLY".equals(r.getCode()))
- sql = sql + ", vg.dlsId='" + user.getDlsId() + "',vg.yysId='" + user.getYysId() + "'";
- }
- }
- }
- else if ("DLSGLY".equals(dqrole.getCode())) {
- sql = sql + ", vg.dlsId='" + dquser.getDlsId() + "',vg.yysId='" + dquser.getYysId() + "'";
- }
-
- sql = sql + " where vg.id='" + entity.getId() + "'";
-
- WriteXml wx = new WriteXml();
- WriteXml.deleteFile(vg.getGatewayUserId() + ".xml");
- wx.writeXmlGoip(entity.getGatewayUserId(), entity.getPassword(), entity.getGatewayUserId() + ".xml");
- ExecuteLinux el = new ExecuteLinux();
- el.executeNewFlow();
- this.iVrGatewayService.executeSql(sql, null);
- AjaxJson aj = new AjaxJson();
- aj.success("修改成功");
- return aj;
- }
-
- public AjaxJson delete(String id)
- {
- String sql = "select * from vr_user_line where gateWay = '" + id + "'";
- List list = this.iVrUserLineService.listByAliasSql(sql, null);
- if (list.size() > 0) {
- AjaxJson aj = new AjaxJson();
- aj.fail("请先删除线路,在删除网关");
- return aj;
- }
-
- VrGateway vg = (VrGateway)get(id);
- WriteXml wx = new WriteXml();
- WriteXml.deleteFile(vg.getGatewayUserId() + ".xml");
- return super.delete(id);
- }
- @RequestMapping(value={"/undo"}, method={org.springframework.web.bind.annotation.RequestMethod.GET, org.springframework.web.bind.annotation.RequestMethod.POST})
- public void undo(String id, HttpServletRequest request, HttpServletResponse response) {
- System.out.println("------------------------------------------------0000000000000000000000000000000000000");
- try
- {
- ExecuteLinux el = new ExecuteLinux();
- el.executeNewFlow();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
青藤ai电销机器人系统部署
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。