Browse Source

增加质控规则管理

chendi 8 years ago
parent
commit
d544d3702d

+ 205 - 0
src/main/java/com/yihu/hos/qc/controller/RuleController.java

@ -0,0 +1,205 @@
package com.yihu.hos.qc.controller;
import com.google.common.base.Splitter;
import com.yihu.hos.qc.model.RuleModel;
import com.yihu.hos.qc.service.RuleService;
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.CollectionUtils;
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.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 质控规则管理
 *
 * @author CD
 * @vsrsion 1.0
 * Created at 2017/05/05.
 */
@RequestMapping("/rule")
@Controller
public class RuleController extends BaseController {
    @Resource(name = RuleService.BEAN_ID)
    private RuleService ruleService;
    /**
     * 质控规则管理界面
     *
     * @param model
     * @return
     */
    @RequestMapping("/initial")
    public String ruleInitial(Model model) {
        model.addAttribute("contentPage", "qc/rule");
        return "partView";
    }
    /**
     * 质控规则列表
     *
     * @param request
     * @return
     */
    @RequestMapping("/getRuleList")
    @ResponseBody
    public Result getAppList(HttpServletRequest request, String name, String valid) {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("name", name);
            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 = ruleService.getRuleList(params);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
    /**
     * 质控规则修改页面
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/editorRule")
    public String editoruleRule(Model model, String id) {
        try {
            RuleModel ruleModel = null;
            if (id != null) {
                ruleModel = ruleService.getRuleById(id);
            } else {
                ruleModel = new RuleModel();
            }
            model.addAttribute("model", ruleModel);
            model.addAttribute("contentPage", "/qc/editorRule");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "pageView";
    }
    /**
     * 质控规则详情页
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/ruleDetail")
    public String ruleDetail(Model model, String id) {
        try {
            RuleModel ruleModel = null;
            if (id != null) {
                ruleModel = ruleService.getRuleById(id);
            } else {
                ruleModel = new RuleModel();
            }
            model.addAttribute("model", ruleModel);
            model.addAttribute("contentPage", "/rule/ruleDetail");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "pageView";
    }
    /**
     * 新增质控规则s信息
     *
     * @param request
     * @return
     */
    @RequestMapping("addRule")
    @ResponseBody
    public Result addRule(HttpServletRequest request) {
        try {
            RuleModel obj = new RuleModel();
            BeanUtils.populate(obj, request.getParameterMap());
            return ruleService.addRule(obj);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
    /**
     * 删除质控规则信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/deleteRule")
    @ResponseBody
    public Result deleteRule(HttpServletRequest request) {
        try {
            String id = request.getParameter("id");
            ruleService.deleteRule(id);
            return Result.success("删除成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败!");
        }
    }
    /**
     * 批量删除质控规则信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/deleteRuleBatch")
    @ResponseBody
    public Result deleteRuleBatch(HttpServletRequest request) {
        try {
            String idList = request.getParameter("idList");
            List<String> ids = Splitter.on(",").trimResults().splitToList(idList);
            if (!CollectionUtils.isEmpty(ids)) {
                for (String id :
                        ids) {
                    ruleService.deleteRule(id);
                }
            }
            return Result.success("删除成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败!");
        }
    }
    /**
     * 修改质控规则信息
     */
    @RequestMapping("updateRule")
    @ResponseBody
    public Result updateRule(HttpServletRequest request) {
        try {
            RuleModel obj = new RuleModel();
            BeanUtils.populate(obj, request.getParameterMap());
            return ruleService.updateRule(obj);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.error(ex.getMessage());
        }
    }
}

+ 48 - 0
src/main/java/com/yihu/hos/qc/dao/RuleDao.java

@ -0,0 +1,48 @@
package com.yihu.hos.qc.dao;
import com.yihu.hos.qc.model.RuleModel;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
/**
 * @author CD
 * @vsrsion 1.0
 * Created at 2017/05/05.
 */
@Repository("ruleDao")
public class RuleDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "ruleDao";
    public Result getRuleList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from RuleModel r where 1=1 ");
        Object name = params.get("name");
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and r.name like '%" + name + "%'");
        }
        return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }
    public List<RuleModel> getRuleList(String name) throws Exception {
        StringBuilder sb = new StringBuilder("from RuleModel r where 1=1 ");
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and r.name like '%" + name + "%'");
        }
        return (List<RuleModel>) super.hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(sb.toString());
    }
    public List<RuleModel> getAllByIdList(List<String> idList) {
        Session session = getCurrentSession();
        Criteria criteria = session.createCriteria(RuleModel.class);
        criteria.add(Restrictions.in("id", idList));
        return criteria.list();
    }
}

+ 82 - 0
src/main/java/com/yihu/hos/qc/model/RuleModel.java

@ -0,0 +1,82 @@
package com.yihu.hos.qc.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
 * ss
 * 质控表
 *
 * @author CD
 * @vsrsion 1.0
 * Created at 2017/05/05.
 */
@Entity
@Table(name = "qc_rule")
public class RuleModel implements java.io.Serializable {
    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "uuid")
    @Column(name = "id")
    private String id;
    @Column(name = "name")
    private String name;
    @Column(name = "type")
    private String type;//分类
    @Column(name = "description")
    private String describe;//描述
    @Column(name = "rule")
    private String rule;//规则
    @Column(name = "error_code")
    private String error_code;//统一错误代码
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getDescribe() {
        return describe;
    }
    public void setDescribe(String describe) {
        this.describe = describe;
    }
    public String getRule() {
        return rule;
    }
    public void setRule(String rule) {
        this.rule = rule;
    }
    public String getError_code() {
        return error_code;
    }
    public void setError_code(String error_code) {
        this.error_code = error_code;
    }
}

+ 88 - 0
src/main/java/com/yihu/hos/qc/service/RuleService.java

@ -0,0 +1,88 @@
package com.yihu.hos.qc.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.config.MongoConfig;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.qc.dao.RuleDao;
import com.yihu.hos.qc.model.RuleModel;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.zbus.broker.ZbusBroker;
import javax.annotation.Resource;
import java.util.Map;
/**
 * @author CD
 * @vsrsion 1.0
 * Created at 2017/05/05.
 */
@Service("ruleService")
public class RuleService {
    public static final String BEAN_ID = "ruleService";
    static final Logger logger = LoggerFactory.getLogger(RuleService.class);
    @Resource(name = RuleDao.BEAN_ID)
    private RuleDao ruleDao;
    @Value("${spring.data.mongodb.gridFsDatabase}")
    private String dbName;
    @Autowired
    private MongoConfig mongoConfig;
    @Autowired
    private ObjectMapper objectMapper;
    private ZbusBroker zbusBroker;
    @Autowired
    public void setZbusBroker(ZbusBroker zbusBroker) {
        this.zbusBroker = zbusBroker;
    }
    public Result getRuleList(Map<String, Object> params) throws Exception {
        return ruleDao.getRuleList(params);
    }
    public RuleModel getRuleById(String id) throws Exception {
        return ruleDao.getEntity(RuleModel.class, id);
    }
    @Transactional
    public Result addRule(RuleModel obj) throws Exception {
        ruleDao.saveEntity(obj);
        return Result.success("保存成功");
    }
    @Transactional
    public Result updateRule(RuleModel obj) throws Exception {
        RuleModel ruleModel = ruleDao.getEntity(RuleModel.class, obj.getId());
        ruleModel.setName(obj.getName());
        ruleModel.setType(obj.getType());
        ruleModel.setDescribe(obj.getDescribe());
        ruleModel.setRule(obj.getRule());
        ruleModel.setError_code(obj.getError_code());
        return Result.success("更新成功");
    }
    @Transactional
    public Result deleteRule(String id) throws Exception {
        RuleModel ruleModel = ruleDao.getEntity(RuleModel.class, id);
        ruleDao.deleteEntity(ruleModel);
        return Result.success("删除成功");
    }
    /* ==============================服务模块=================================  */
    public Result getRuleServiceList(Map<String, Object> params) throws Exception {
        return ruleDao.getRuleList(params);
    }
}

+ 34 - 0
src/main/webapp/WEB-INF/ehr/jsp/qc/rule.jsp

@ -0,0 +1,34 @@
<%@ 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 right" >
                <div id="div_delete_record" class="l-button" style="background-color: #ec6941;">
                    <span><spring:message code="btn.multi.delete"/></span>
                </div>
                <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>
<style>
    #div_delete_record:hover{background: red !important;}
</style>

+ 210 - 0
src/main/webapp/WEB-INF/ehr/jsp/qc/ruleJs.jsp

@ -0,0 +1,210 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script>
    /* *************************** 模块初始化 ***************************** */
    var rule = {
        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();
            }});
            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/rule/getRuleList',
                parms: {
                    name: $('#txtName').val(),
                },
                checkbox:true,
                columns: [
                    {display: '名称', name: 'name', width: '10%'},
                    {display: '分类', name: 'type', width: '10%',align: 'center', render: function (rowdata, rowindex, value) {
                        if(rowdata.type==1 ){
                            return ' <div style="vertical-align:middle;margin-top: 13px;"><span>完整性  </span></div>';
                        }else if(rowdata.type==2){
                            return ' <div style="vertical-align:middle;margin-top: 13px;"><span>及时性 </span></div>';
                        }else if(rowdata.type==3){
                            return ' <div style="vertical-align:middle;margin-top: 13px;"><span>准确性 </span></div>';
                        }
                    }},
                    {display: '规则描述', name: 'describe', width: '20%'},
                    {display: '脚本(或接口)', name: 'rule', width: '20%'},
                    {display: '统一错误代码', name: 'error_code', width: '20%'
                    },
                    {
                        display: '操作', name: 'operator', width: '20%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:350px;">';
                        html += "<a class=\"m-btn\" style=\"padding-right:10px\" onclick=\"rule.editorDialog('"+row.id+"','disabled')\">查看详情</a>";
                        html += "<a class=\"m-btn-edit\" onclick=\"rule.editorDialog('"+row.id+"','')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"rule.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();
            });
            $('#div_delete_record').click(function(){
                var rows = rule.grid.getSelecteds();
                if(rows.length > 0){
                    var idArr = [];
                    for(var i in rows){
                        idArr.push(rows[i].id);
                    }
                    rule.deleteBatch(idArr.join(","));
                }else{
                    $.ligerDialog.error("请选择要删除的规则信息!");
                    return false;
                }
            })
            $("#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}/rule/deleteRule",
                        dataType : "json",
                        data:{id:id},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                rule.grid.reload();
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        // 批量删除
        deleteBatch: function (idList) {
            var message = "确定要删除选中的规则信息吗?";
            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/rule/deleteRuleBatch",
                        dataType : "json",
                        data:{idList: idList},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {idList
                                $.ligerDialog.success(data.message);
                                rule.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: 400,
                width: 500,
                title: title,
                url: '${contextRoot}/rule/editorRule',
                //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}/rule/ruleDetail',
                //load: true,
                urlParms: params
            });
        },
    anthorize: function (id) {
        },
        //弹窗返回
        dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            rule.reloadGrid();
            rule.dialog.close();
        }
    };
    $(function () {
        rule.init();
    });
</script>