demon пре 8 година
родитељ
комит
f0d5ba5a28

+ 18 - 0
hos-web-framework/src/main/java/com/yihu/hos/web/framework/dao/SQLGeneralDAO.java

@ -94,6 +94,24 @@ public class SQLGeneralDAO implements XSQLGeneralDAO {
        return dataGridResult;
    }
    public DataGridResult getDataGridResult( Query query , Integer page, Integer rows) {
        DataGridResult dataGridResult = new DataGridResult();
        if (page != null && rows != null) {
            dataGridResult.setPageSize(rows.intValue());
            dataGridResult.setCurrPage(page.intValue());
            dataGridResult.setTotalCount(query.list().size());
            query.setMaxResults(rows.intValue());
            query.setFirstResult((page.intValue() - 1) * rows.intValue());
            dataGridResult.setDetailModelList(query.list());
        } else {
            List list = query.list();
            dataGridResult.setDetailModelList(list);
            dataGridResult.setTotalCount(list.size());
        }
        return dataGridResult;
    }
    public void beginTransaction() throws Exception {
        this.hibernateTemplate.getSessionFactory().getCurrentSession().getTransaction().begin();
    }

+ 4 - 4
src/main/java/com/yihu/hos/listeners/ApplicationStart.java

@ -9,7 +9,7 @@ import com.yihu.hos.web.framework.model.bo.ServiceFlow;
import com.yihu.hos.system.service.FlowManager;
import com.yihu.hos.web.framework.constant.DateConvert;
import com.yihu.hos.tenant.model.TenantModel;
import com.yihu.hos.tenant.service.TenatService;
import com.yihu.hos.tenant.service.TenantService;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -30,8 +30,8 @@ public class ApplicationStart implements ServletContextListener {
    @Value("${spring.administrators}")
    private String saasAdmin;
    @Resource(name = TenatService.BEAN_ID)
    private TenatService tenatService;
    @Resource(name = TenantService.BEAN_ID)
    private TenantService tenantService;
    @Autowired
    private ServiceFlowEventService serviceFlowEventService;
@ -43,7 +43,7 @@ public class ApplicationStart implements ServletContextListener {
    public void contextInitialized(ServletContextEvent context) {
        //切换到主库
        try {
            TenantModel tenantModel = tenatService.findTenantByName(saasAdmin);
            TenantModel tenantModel = tenantService.findTenantByName(saasAdmin);
            if (tenantModel!=null){
                LocalContext.getContext().setAttachment(ContextAttributes.SCHEMA, tenantModel.getSchema());
            }

+ 4 - 2
src/main/java/com/yihu/hos/system/controller/SystemController.java

@ -59,7 +59,7 @@ public class SystemController {
     */
    @RequestMapping("loginAction")
    @ResponseBody
    public Result loginAction(HttpServletRequest request,String user,String password) {
    public ActionResult loginAction(HttpServletRequest request,String user,String password) {
        try {
            HttpSession session = request.getSession();
            return ehr.loginAction(session,user, password);
@ -67,7 +67,9 @@ public class SystemController {
        catch (Exception ex)
        {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
            ActionResult result = new ActionResult(false,"登录失败!密码错误!");
            result.setData(ex.getMessage());
            return result;
        }
    }

+ 23 - 8
src/main/java/com/yihu/hos/system/service/SystemManager.java

@ -1,13 +1,14 @@
package com.yihu.hos.system.service;
import com.yihu.hos.common.constants.ContextAttributes;
import com.yihu.hos.tenant.model.TenantSession;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.system.model.SystemUser;
import com.yihu.hos.system.service.intf.ISystemManager;
import com.yihu.hos.system.service.intf.IUserManager;
import com.yihu.hos.tenant.model.TenantSession;
import com.yihu.hos.web.framework.model.ActionResult;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
@ -21,12 +22,16 @@ public class SystemManager implements ISystemManager {
    @Autowired
    private IUserManager userManager;
    @Value("${spring.administrators}")
    private String saasAdmin;
    /*
    登录操作
     */
    @Override
    public  Result loginAction(HttpSession session,String user,String password) throws Exception
    public  ActionResult loginAction(HttpSession session,String user,String password) throws Exception
    {
        ActionResult result = null;
        TenantSession tenantSession = (TenantSession)session.getAttribute(ContextAttributes.TENANT_SESSION);
        //特殊账户
        if(user.equals("admin") && password.equals("JKZL"))
@ -35,29 +40,39 @@ public class SystemManager implements ISystemManager {
            userInfo.setLoginCode("admin");
            userInfo.setUserName("管理员");
            session.setAttribute("userInfo",userInfo);
            tenantSession.setUserCode("admin");
            tenantSession.setUserCode("admin");//设置租户code
            tenantSession.setRole("admin");//标识为管理员账号
            session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
            return Result.success("登录成功!");
            result = new ActionResult(true,"登录成功!");
            result.setData(tenantSession);
            return result;
        }
        //根据用户名/密码到总平台校验
        SystemUser userInfo = userManager.getUserByLoginCode(user);
        if(userInfo==null)
        {
            return Result.error("登录失败!用户不存在!");
            result = new ActionResult(false,"登录失败!用户不存在!");
            return result;
        }
        else{
            String saltValue =userInfo.getSaltValue();
            String userPassword = userInfo.getPassword();
            if(userPassword.equals(DigestUtils.md5Hex(password + saltValue)))
            {
                if (saasAdmin.equals(user)){
                    tenantSession.setRole("admin");//标识为管理员账号
                }
                tenantSession.setUserCode(user);
                session.setAttribute(ContextAttributes.TENANT_SESSION, tenantSession);
                session.setAttribute("userInfo",userInfo);
                return Result.success("登录成功!");
                result = new ActionResult(true,"登录成功!");
                result.setData(tenantSession);
                return result;
            }
            else{
                return Result.error("登录失败!密码错误!");
                result = new ActionResult(false,"登录失败!密码错误!");
                return result;
            }
        }

+ 2 - 2
src/main/java/com/yihu/hos/system/service/intf/ISystemManager.java

@ -1,6 +1,6 @@
package com.yihu.hos.system.service.intf;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.ActionResult;
import javax.servlet.http.HttpSession;
@ -9,7 +9,7 @@ import javax.servlet.http.HttpSession;
 */
public interface ISystemManager {
    Result loginAction(HttpSession session, String user, String password) throws Exception;
    ActionResult loginAction(HttpSession session, String user, String password) throws Exception;
}

+ 180 - 0
src/main/java/com/yihu/hos/tenant/controller/TenantController.java

@ -0,0 +1,180 @@
package com.yihu.hos.tenant.controller;
import com.yihu.hos.tenant.model.TenantModel;
import com.yihu.hos.tenant.service.TenantService;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 *  租户管理
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/12/16.
 */
@RequestMapping("/tenant")
@Controller
public class TenantController extends BaseController{
    @Resource(name = TenantService.BEAN_ID)
    private TenantService tenantService;
    /**
     *  租户管理界面
     *
     * @param model
     * @return
     */
    @RequestMapping("/initial")
    public String appInitial(Model model) {
        model.addAttribute("contentPage", "tenant/tenant");
        return "partView";
    }
    /**
     * 租户列表
     *
     * @param request
     * @return
     */
    @RequestMapping("/getTenantList")
    @ResponseBody
    public Result getAppList(HttpServletRequest request,String name,String valid) {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("name", name);
            params.put("valid", valid);
            String page = StringUtils.isEmpty(request.getParameter("page")) ? "1" : request.getParameter("page");
            String rows = StringUtils.isEmpty(request.getParameter("rows")) ? "10" : request.getParameter("rows");
            params.put("page", page);
            params.put("rows", rows);
            Result result = tenantService.getTenantList(params);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
    /**
     * 租户修改页面
     * @param model
     * @param id
     * @param categoryId
     * @return
     */
    @RequestMapping("/editorTenant")
    public String editorTenant(Model model, Long id, String flag, String categoryId) {
        try {
            TenantModel tenantModel = null;
            if (id != null) {
                tenantModel = tenantService.getTenantById(id);
            }  else {
                tenantModel = new TenantModel();
            }
            model.addAttribute("model", tenantModel);
            model.addAttribute("flag", flag);
            model.addAttribute("categoryId", categoryId);
            model.addAttribute("contentPage", "/tenant/editorTenant");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "pageView";
    }
    /**
     * 租户详情页
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/tenantDetail")
    public String tenantDetail(Model model, Long id) {
        try {
            TenantModel tenantModel = null;
            if (id != null ) {
                tenantModel = tenantService.getTenantById(id);
            }  else {
                tenantModel = new TenantModel();
            }
            model.addAttribute("model", tenantModel);
            model.addAttribute("contentPage", "/tenant/tenantDetail");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "pageView";
    }
    /**
     * 新增租户信息
     * @param request
     * @return
     */
    @RequestMapping("addTenant")
    @ResponseBody
    public Result addTenant(HttpServletRequest request) {
        try {
            TenantModel obj = new TenantModel();
            BeanUtils.populate(obj, request.getParameterMap());
            obj.setCreated(new Date());
            return tenantService.addTenant(obj);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
    /**
     * 删除租户信息
     * @param request
     * @return
     */
    @RequestMapping("/deleteTenant")
    @ResponseBody
    public Result deleteTenant(HttpServletRequest request) {
        try {
            String id = request.getParameter("id");
            tenantService.deleteTenant(Long.parseLong(id));
            return Result.success("删除成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败!");
        }
    }
    /**
     * 修改租户信息
     */
    @RequestMapping("updateTenant")
    @ResponseBody
    public Result updateTenant(HttpServletRequest request) {
        try {
            TenantModel obj = new TenantModel();
            BeanUtils.populate(obj, request.getParameterMap());
            return tenantService.updateTenant(obj);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
}

+ 40 - 0
src/main/java/com/yihu/hos/tenant/dao/TenantDao.java

@ -2,9 +2,13 @@ package com.yihu.hos.tenant.dao;
import com.yihu.hos.tenant.model.TenantModel;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
/**
 * @author HZY
@ -21,4 +25,40 @@ public class TenantDao extends SQLGeneralDAO {
        List<TenantModel> list = (List<TenantModel>) super.hibernateTemplate.find("from TenantModel s where s.name=? and s.valid = 1", name);
        return list;
    }
    /**\
     * 分页列表
     * @param params
     * @return
     * @throws Exception
     */
    public Result getTenantList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from TenantModel t where 1=1 ");
        Object valid = params.get("valid");
        Object name = params.get("name");
        if (!StringUtils.isEmpty(valid)) //是否有效
        {
            sb.append(" and t.valid = :valid");
        }
        //用户名过滤
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and (t.name like ? or t.loginName like ?)");
        }
        sb.append(" order by t.created desc");
        Query query = super.hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(sb.toString());
        if (!StringUtils.isEmpty(valid)) //是否有效
        {
            query.setInteger("valid",Integer.parseInt(valid.toString()));
        }
        if (!StringUtils.isEmpty(name)) {
            query.setString(0, "%" + name.toString() + "%");
            query.setString(1, "%" + name.toString() + "%");
        }
        return super.getDataGridResult(query, Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }
}

+ 10 - 0
src/main/java/com/yihu/hos/tenant/model/TenantModel.java

@ -19,6 +19,7 @@ public class TenantModel extends IdModel {
    private String code;
    private String name;
    private String loginName;
    private String password;
    private String schema;
    private Date created;
@ -46,6 +47,15 @@ public class TenantModel extends IdModel {
        this.name = name;
    }
    @Column(name="login_name")
    public String getLoginName() {
        return loginName;
    }
    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }
    @Column(name="password")
    public String getPassword() {
        return password;

+ 11 - 0
src/main/java/com/yihu/hos/tenant/model/TenantSession.java

@ -3,6 +3,7 @@ package com.yihu.hos.tenant.model;
import java.util.UUID;
/**
 *  租户缓存信息
 * @created Airhead 2016/11/16.
 */
public class TenantSession {
@ -11,6 +12,8 @@ public class TenantSession {
    private String schema;
    private String tenant;
    private String role;//角色类型;admin:管理员,null :普通租户
    public TenantSession() {
    }
@ -26,6 +29,14 @@ public class TenantSession {
        this.token = token;
    }
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
    public String getSchema() {
        return schema;
    }

+ 4 - 4
src/main/java/com/yihu/hos/tenant/service/AuthenticateService.java

@ -21,8 +21,8 @@ public class AuthenticateService {
    @Autowired
    private UserDao userDao;
    @Resource(name = TenatService.BEAN_ID)
    private TenatService tenatService;
    @Resource(name = TenantService.BEAN_ID)
    private TenantService tenantService;
    public boolean isAuth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
@ -46,7 +46,7 @@ public class AuthenticateService {
    public boolean auth(HttpSession httpSession, String tenantName) throws Exception {
        //授权租户,切换到指定数据库,需要先清除原先的数据库指定,切回global_db表,获取租户信息
        LocalContext.getContext().removeAttachment(ContextAttributes.SCHEMA);
        TenantModel tenantModel = tenatService.findTenantByName(tenantName);
        TenantModel tenantModel = tenantService.findTenantByName(tenantName);
        //TODO:现在只是简单逻辑,需要修改成安全逻辑
        if (tenantModel == null ) {
            return false;
@ -58,7 +58,7 @@ public class AuthenticateService {
//        if (userModel == null || !password.equals(userModel.getPassword())) {
//            return "User Auth Failed";
//        }
        httpSession.setAttribute(ContextAttributes.TENANT_SESSION, new TenantSession(tenantModel.getName(), tenantModel.getSchema()));
        httpSession.setAttribute(ContextAttributes.TENANT_SESSION, new TenantSession(tenantModel.getLoginName(), tenantModel.getSchema()));
        return true;
    }

+ 78 - 0
src/main/java/com/yihu/hos/tenant/service/TenantService.java

@ -0,0 +1,78 @@
package com.yihu.hos.tenant.service;
import com.yihu.hos.tenant.dao.TenantDao;
import com.yihu.hos.tenant.model.TenantModel;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/12/2.
 */
@Service("TenantService")
public class TenantService {
    public static final String BEAN_ID = "TenantService";
    @Autowired
    private TenantDao tenantDao;
    public TenantModel findTenantByName(String name) throws Exception {
        List<TenantModel> list = tenantDao.getTenantList(name);
        if (list!=null && !list.isEmpty()){
            return list.get(0);
        }
        return null;
    }
    public Result getTenantList(Map<String, Object> params) throws Exception {
        return tenantDao.getTenantList(params);
    }
    public TenantModel getTenantById(Long id) throws Exception {
        return tenantDao.getEntity(TenantModel.class,id);
    }
    public Result addTenant(TenantModel obj) throws Exception {
        String code = UUID.randomUUID().toString();
        obj.setCode(code);
        obj.setCreated(new Date());
        obj.setCreatedUnix(0);
        obj.setUpdated(new Date());
        obj.setUpdatedUnix(0);
        tenantDao.saveEntity(obj);
        return Result.success("保存成功");
    }
    @Transactional
    public Result updateTenant(TenantModel obj) throws Exception {
        TenantModel tenant = tenantDao.getEntity(TenantModel.class, obj.getId());
        tenant.setName(obj.getName());
        tenant.setLoginName(obj.getLoginName());
        tenant.setSchema(obj.getSchema());
        tenant.setPassword(obj.getPassword());
        tenant.setValid(obj.getValid());
        tenant.setUpdated(new Date());
        tenant.setUpdatedUnix(1);
        tenantDao.updateEntity(tenant);
        return Result.success("更新成功");
    }
    @Transactional
    public Result deleteTenant(Long id) throws Exception {
        TenantModel systemApp = tenantDao.getEntity(TenantModel.class, id);
        tenantDao.deleteEntity(systemApp);
        return Result.success("删除成功");
    }
}

+ 0 - 31
src/main/java/com/yihu/hos/tenant/service/TenatService.java

@ -1,31 +0,0 @@
package com.yihu.hos.tenant.service;
import com.yihu.hos.tenant.dao.TenantDao;
import com.yihu.hos.tenant.model.TenantModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/12/2.
 */
@Service("TenatService")
public class TenatService {
    public static final String BEAN_ID = "TenatService";
    @Autowired
    private TenantDao tenantDao;
    public TenantModel findTenantByName(String name) throws Exception {
        List<TenantModel> list = tenantDao.getTenantList(name);
        if (list!=null && !list.isEmpty()){
            return list.get(0);
        }
        return null;
    }
}

+ 2 - 2
src/main/resources/application.yml

@ -43,13 +43,13 @@ spring:
    show-sql: false
  data:
    mongodb:
      host: 172.19.103.86
      host: 172.19.103.57
      port: 27017
      username: esb
      password: esb
      authenticationDatabase: admin
  activemq:
    broker-url: tcp://172.19.103.86:61616?wireFormat.maxInactivityDuration=0
    broker-url: tcp://172.19.103.57:61616?wireFormat.maxInactivityDuration=0
    user: admin
    password: admin
    pooled: false

+ 1 - 1
src/main/resources/config/dbhelper.properties

@ -4,5 +4,5 @@ defaultUser = hos
defaultPassword = hos
mongodbUri=mongodb://esb:esb@172.19.103.86:27017/?authSource=admin
mongodbUri=mongodb://esb:esb@172.19.103.57:27017/?authSource=admin
mongodbName=hos

+ 12 - 3
src/main/webapp/WEB-INF/ehr/jsp/common/indexJs.jsp

@ -26,6 +26,7 @@
        }
    });
    //判断是否登录
    function isLogin() {
        $.ajax({ //获取是否
@ -61,6 +62,10 @@
            $(".l-layout-left").css({background: "#dce6f0"})
            var tenantManager = [
                {id: 200, text: '租户管理', icon: '${staticRoot}/images/index/menu5_icon.png'},
                {id: 201, pid: 200, text: '租户管理', url: '${contextRoot}/tenant/initial'},
            ]
            //菜单列表
            var menu = [
                //标准管理
@ -108,6 +113,11 @@
                {id: 94, pid: 9, text: '菜单按钮配置', url: '${contextRoot}/menu/menuAction/initial'},
                {id: 95, pid: 9, text: '数据源配置', url: '${contextRoot}/datasource/configSources'},
            ];
            var userRole = localStorage.getItem("userRole");
            if(userRole=="admin"){
                //是管理中心用户,则添加租户管理模块
                menu = menu.concat(tenantManager);
            }
            me.menuTree = $('#ulTree').ligerTree({
                data: menu,
                idFieldName: 'id',
@ -150,7 +160,7 @@
                            cache: false,
                            success: function (data) {
                                if (data.successFlg) {
                                    debugger
                                    localStorage.removeItem("userRole");
                                    location.href = "${contextRoot}/"+data.data+"/loginPage";
                                }
                                else {
@ -338,7 +348,6 @@
                    $.each($("div[class='l-body l-selected']", me.menuTree.tree), function () {
                        $(this).removeClass("l-selected");
                    });
                    debugger
                    for (var i = 0; i < nodeText.length; i++) {
                        if ($(nodeText[i]).text().indexOf(text) >= 0) {
                            var id = $(nodeText[i]).closest("li").attr("id");
@ -403,7 +412,7 @@
                                    cache: false,
                                    success: function (data) {
                                        if (data.successFlg) {
                                            debugger
                                            localStorage.removeItem("userRole");
                                            location.href = "${contextRoot}/"+data.data+"/loginPage";
                                        }
                                        else {

+ 2 - 0
src/main/webapp/WEB-INF/ehr/jsp/common/loginJs.jsp

@ -31,6 +31,8 @@
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        var tenantSession = data.data;
                        localStorage.setItem("userRole",tenantSession.role);
                        location.href = "${contextRoot}/indexPage";
                    }
                    else{

+ 76 - 0
src/main/webapp/WEB-INF/ehr/jsp/tenant/editorTenant.jsp

@ -0,0 +1,76 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<!--######应用管理页面 > 应用详情模板页######-->
<div id="div_info_form" class="m-form-inline" style="padding-top:10px;" data-role-form>
    <input id="flag" value="${flag}" style="display: none">
    <div class="m-form-group">
        <label><span class="red">*&nbsp;</span>租户名称:</label>
        <div class="m-form-control ">
            <div class="l-text">
                <input type="text" class="l-text-field required" placeholder="请输入租户名称" name="name"/>
            </div>
        </div>
    </div>
    <div class="m-form-group">
        <label><span class="red">*&nbsp;</span>登录名:</label>
        <div class="m-form-control">
            <div class="l-text">
                <input type="text" class="l-text-field required" placeholder="请输入租户登录名" name="loginName"/>
            </div>
        </div>
    </div>
    <div class="m-form-group">
        <label><span class="red">*&nbsp;</span>登录密码:</label>
        <div class="m-form-control">
            <div class="l-text">
                <input type="text" class="l-text-field required" placeholder="请输入租户登录密码" name="password"/>
            </div>
        </div>
    </div>
    <div class="m-form-group">
        <label><span class="red">*&nbsp;</span>数据库名:</label>
        <div class="m-form-control">
            <div class="l-text">
                <input type="text" class="l-text-field required" placeholder="请输入租户数据库名" name="schema"/>
            </div>
        </div>
    </div>
    <div class="m-form-group">
        <label><span class="red">*&nbsp;</span>状态:</label>
        <div class="m-form-control ">
            <div class="l-text">
                <input type="text" id="valid"  class="l-text-field required" name="valid">
            </div>
        </div>
    </div>
    <!-- 隐藏字段 -->
    <div class="m-form-group" style="display: none;">
        <input name="id" hidden="hidden"/>
        <input name="code" hidden="hidden"/>
    </div>
    <div class="m-form-bottom">
        <div id="btnCancel" class="l-button l-button-no">
            <span>关闭</span>
        </div>
        <div id="btnEditor" class="l-button" style="display:none">
            <span>编辑</span>
        </div>
        <div id="btnSave" class="l-button">
            <span>保存</span>
        </div>
    </div>
</div>
<style>
    .m-form-group label{width: 135px;}
    .btnGrayUp.required{border: #FF7777 1px solid; float: left;}
</style>

+ 127 - 0
src/main/webapp/WEB-INF/ehr/jsp/tenant/editorTenantJs.jsp

@ -0,0 +1,127 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script type="text/javascript">
    /* *************************** 模块初始化 ***************************** */
    var editorParam = {
        //form
        actionUrl:"${contextRoot}/tenant/addTenant",
        init: function () {
            this.toDisable();
            this.bindEvents();
            this.initForm();
        },
        toDisable: function () {
            if ($("#flag").val()=='disabled') {
                $("#btnEditor").show();
                $("#btnSave").hide();
                $("input[name='name']").attr("disabled", "disabled");
                $("input[name='loginName']").attr("disabled", "disabled");
                $("input[name='passward']").attr("disabled", "disabled");
                $("input[name='schema']").attr("disabled", "disabled");
                $("input[name='valid']").attr("disabled", "disabled");
            }
        },
        initForm: function () {
            var me = this;
           var data;
            var modelString = "${model.id}";
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                var valid = "${model.valid}";
                liger.get("valid").selectValue(valid);
               data={
                    id: "${model.id}",
                    name: "${model.name}",
                   loginName: "${model.loginName}",
                   valid: valid,
                   password: "${model.password}",
                   schema: "${model.schema}",
                };
                me.actionUrl = "${contextRoot}/tenant/updateTenant";
            }else{
                liger.get("valid").selectValue("1");//默认有效
            }
            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    name:"required",
                    loginName:"required",
                    password:"required",
                    scheme:"required",
                    valid: {
                        required:true
                    }
                },
            });
        },
        bindEvents: function () {
            var me = this;
            $(".m-form-bottom").on("click","#btnSave",function () {
                $("#btnSave").css("pointer-events","none");
                $("#name_icon").removeClass("required");
                if($("#name_icon").val()=="") {
                    $("#name_icon").addClass("required");
                    if(!$("#div_info_form").ligerAutoForm("validate")){
                        return;
                    }
                    return;
                }
                if(!$("#div_info_form").ligerAutoForm("validate")){
                    return;
                }
                var data = $("#div_info_form").ligerAutoForm("getData");
                $.ajax({ //ajax处理
                    type: "POST",
                    url : me.actionUrl,
                    dataType : "json",
                    data:data,
                    cache:false,
                    success :function(data){
                        if(data.successFlg) {
                            parent.app.dialogSuccess(data.message);
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                        $("#btnSave").css("pointer-events","");
                    },
                    error :function(data){
                        $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        $("#btnSave").css("pointer-events","");
                    }
                });
            });
            $(".m-form-bottom").on("click","#btnEditor",function () {
                        $("#btnEditor").hide();
                        $("#btnSave").show();
                        $("input[name='name']").removeAttr("disabled");
                        $("input[name='loginName']").removeAttr("disabled");
                        $("input[name='password']").removeAttr("disabled");
                        $("input[name='schema']").removeAttr("disabled");
                        $("input[name='valid']").removeAttr("disabled");
                        $("#flag").val("");
            });
            $(".m-form-bottom").on("click","#btnCancel",function () {
                parent.tenant.dialog.close();
            });
            $("#valid").ligerComboBox({data : [{"value":"有效","code":"1"},{"value":"无效","code":"0"}],
                cancelable:false,
                onSuccess:function(data){
                }});
        }
    };
    $(function () {
        editorParam.init();
    });
</script>
<script type="text/javascript" src="${staticRoot}/lib/jquery/jqueryform.js"></script>

+ 32 - 0
src/main/webapp/WEB-INF/ehr/jsp/tenant/tenant.jsp

@ -0,0 +1,32 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!--######用户管理页面Title设置######-->
<!-- ####### 页面部分 ####### -->
<div class="m-content">
    <!-- ####### 查询条件部分 ####### -->
    <div class="m-form-inline">
        <div class="m-form-group">
            <div class="m-form-control">
                <input type="text" id="txtName" class="l-text-field" placeholder="请输入租户名称"/>
            </div>
            <div class="m-form-control" >
                <label>状态:</label>
                <input type="text" id="valid" class="l-text-field" />
            </div>
            <div class="m-form-control right" >
                <div id="div_new_record" class="l-button">
                    <span><spring:message code="btn.create"/></span>
                </div>
            </div>
        </div>
    </div>
    <!--######菜单信息表######-->
    <div id="div_grid">
    </div>
</div>

+ 170 - 0
src/main/webapp/WEB-INF/ehr/jsp/tenant/tenantJs.jsp

@ -0,0 +1,170 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script>
    /* *************************** 模块初始化 ***************************** */
    var tenant = {
        grid: null,
        dialog: null,
        init: function () {
            this.bindEvents();
            this.initForm();
        },
        initForm: function () {
            var me = this;
            $('.m-retrieve-area').show();
            $("#txtName").ligerSearch({
                onClick:function(value){
                    me.reloadGrid();
            }});
            var tenantStatus = liger.get("valid").value;
            if(tenantStatus ==undefined || tenantStatus ==null || tenantStatus.length<=0){
                liger.get("valid").selectValue("");
            }
            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/tenant/getTenantList',
                parms: {
                    name: $('#txtName').val(),
                    valid:tenantStatus
                },
                columns: [
                    {display: '租户名称', id: 'id', name: 'name', width: '20%'},
                    {display: '租户代码', name: 'code', width: '15%'},
                    {display: '数据库名', name: 'schema', width: '15%'},
                    {display: '状态', name: 'valid', width: '10%',align: 'center', render: function (rowdata, rowindex, value) {
                        if(rowdata.valid==1 ){
                            return ' <div style="vertical-align:middle;margin-top: 10px;"><span>有效  </span></div>';
                        }else if(rowdata.valid==0){
                            return ' <div style="vertical-align:middle;margin-top: 10px;"><span>无效 </span></div>';
                        }
                    }},
                    {
                        display: '操作', name: 'operator', width: '40%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:350px;">';
                        html += "<a class=\"m-btn\" style=\"padding-right:10px\" onclick=\"tenant.editorDialog('"+row.id+"','disabled')\">查看详情</a>";
                        html += "<a class=\"m-btn-edit\" onclick=\"tenant.editorDialog('"+row.id+"','')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"tenant.delete('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                onDblClickRow: function (row) {
                    me.editorDialog(row.id);
                }
            });
        },
        bindEvents: function () {
            var me = this;
            var flag = false;
            $('#div_new_record').click(function () {
                me.editorDialog();
            });
            $("#valid").ligerComboBox({data : [{"value":"全部","code":""},{"value":"有效","code":"1"},{"value":"无效","code":"0"}],
                cancelable:false,
                initIsTriggerEvent: false,
                onSelected: function (value)
                {
                    if (flag) {
                        me.reloadGrid();
                    } else {
                        flag = true;
                    }
                },
                onSuccess:function(data){
                }});
            $(".l-text").css("display","inline-block");
            $(".l-text-wrapper").css("display","inline-block");
        },
        delete:function(id){
            var message = "确定要删除该应用信息吗?";
            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/tenant/deleteTenant",
                        dataType : "json",
                        data:{id:id},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                tenant.grid.reload();
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        //刷新列表数据
        reloadGrid: function () {
            this.grid.set({
                parms: {name: $('#txtName').val(),valid:$('#valid_val').val()}
            });
            this.grid.reload();
        },
        //编辑弹窗
        editorDialog: function (id, flag) {
            var me = this;
            var title = "新增租户";
            var params = null;
            if (id != undefined && id != null) {
                title = "编辑租户";
                params = {"id": id, "flag": flag};
            }
            me.dialog = $.ligerDialog.open({
                height: 600,
                width: 500,
                title: title,
                url: '${contextRoot}/tenant/editorTenant',
                //load: true,
                urlParms: params
            });
        },
        dialogDetail: function (id) {
            var me = this;
            var title = "应用详情";
            var params = null;
            if (id != undefined && id != null) {
                params = {"id": id};
            }
            me.dialog = $.ligerDialog.open({
                height: 500,
                width: 500,
                title: title,
                url: '${contextRoot}/tenant/tenantDetail',
                //load: true,
                urlParms: params
            });
        },
    anthorize: function (id) {
        },
        //弹窗返回
        dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            tenant.reloadGrid();
            tenant.dialog.close();
        }
    };
    $(function () {
        tenant.init();
    });
</script>