Quellcode durchsuchen

Merge branch 'dev' of trick9191/patient-co-management into dev

trick9191 vor 8 Jahren
Ursprung
Commit
00a3a5df90

+ 90 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/aop/ObserverRequiredAOP.java

@ -0,0 +1,90 @@
package com.yihu.wlyy.aop;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/**
 * Created by Trick on 2017/6/24.
 */
@Aspect
@Component
public class ObserverRequiredAOP {
    //Controller层切点
    @Pointcut("execution(* com.yihu.wlyy.web..*.*(..))")
    public void controllerAspect() {
    }
    public ObserverRequiredAOP() {
        //System.out.println("Observer---------------------------------------");
    }
    @Around("controllerAspect() && @annotation(com.yihu.wlyy.aop.ObserverRequired)")
    public Object checkToken(ProceedingJoinPoint point) throws Throwable {
        Object o = null;
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        String error = "";
        try {
            response.setCharacterEncoding("UTF-8");
            JSONObject json = getAgent(request);
            String observer = json.has("observer") ? json.getString("observer") : "";
            if(StringUtils.isNotBlank(observer)&&"1".equals(observer)){
                PrintWriter writer=response.getWriter();
                writer.write(error(403, "该操作没有权限"));
                writer.flush();
                return o;
            }
        }catch (Exception e){
            //return o;
        }
         o = point.proceed();
        return o;
    }
    public String write(int code, String msg) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("msg", msg);
            return json.toString();
        } catch (Exception e) {
            return null;
        }
    }
    public String error(int code, String msg) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("msg", msg);
            return json.toString();
        } catch (Exception e) {
            return null;
        }
    }
    public JSONObject getAgent(HttpServletRequest request) {
        try {
            String userAgent = request.getHeader("userAgent");
            if (StringUtils.isEmpty(userAgent)) {
                userAgent = request.getHeader("User-Agent");
            }
            System.out.println("userAgent:" + userAgent);
            return new JSONObject(userAgent);
        } catch (Exception e) {
            return null;
        }
    }
}

+ 14 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/aop/observerRequired.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.aop;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
 * Created by Trick on 2017/6/24.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ObserverRequired {
}

+ 106 - 106
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -27,112 +27,112 @@ public class DoctorInterceptor extends BaseInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
//        try {
//            request.setCharacterEncoding("UTF-8");
//            request.setAttribute("log-start", new Date().getTime());
//            response.setCharacterEncoding("UTF-8");
//            JSONObject json = getAgent(request);
//
//            if (json == null) {
//                // 未登录
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                return false;
//            }
//
//            if (json.has("uid") && json.has("admin_token") && StringUtils.isNotEmpty(json.getString("admin_token"))) {
//                String adminToken = SystemConf.getInstance().getSystemProperties().getProperty("admin_token");
//                String adminUid = SystemConf.getInstance().getSystemProperties().getProperty("admin_uid");
//                if (json.getString("uid").equals(adminUid) && json.getString("admin_token").equals(adminToken)) {
//                    return true;
//                }
//            }
//
//            String tokenStr = json.has("token") ? json.getString("token") : "";
//            String uid = json.has("uid") ? json.getString("uid") : "";
//            String imei = json.has("imei") ? json.getString("imei") : "";
//            String observer = json.has("observer") ? json.getString("observer") : "";
//            //如果是观察者直接返回true
//            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
//                Class cls = ((HandlerMethod) handler).getBeanType();
//                RequestMapping clsRm = (RequestMapping) cls.getAnnotation(RequestMapping.class);
//                Method method = ((HandlerMethod) handler).getMethod();
//                RequestMapping mthRm = method.getAnnotation(RequestMapping.class);
//                String url = "";
//                String urlCls = "";
//                String urlMth = "";
//                if (clsRm.value() != null && clsRm.value().length > 0) {
//                    urlCls = clsRm.value()[0];
//                }
//                if (mthRm.value() != null && mthRm.value().length > 0) {
//                    urlMth = mthRm.value()[0];
//                }
//                if (StringUtils.isNotEmpty(urlCls)) {
//                    url += urlCls.startsWith("/") ? urlCls : ("/" + urlCls);
//                }
//                if (StringUtils.isNotEmpty(urlMth)) {
//                    url += urlMth.startsWith("/") ? urlMth : ("/" + urlMth);
//                }
//                url = url.replace("\\", "/").replace("//", "/");
//                CudUrl cudUrl = cudUrlDao.findByUrl(url);
//
//                if (url.equals("/doctor/consult/readed")) {
//                    response.getOutputStream().write(write(200, "操作成功").getBytes());
//                    return false;
//                }
//
//                if (cudUrl != null) {
//                    if (StringUtils.isNotEmpty(cudUrl.getMethod()) &&
//                            request.getMethod().toUpperCase().compareTo(cudUrl.getMethod()) != 0) {
//                        return true;
//                    } else {
//                        response.getOutputStream().write(error(403, "该操作没有权限").getBytes());
//                        return false;
//                    }
//                }
//
//                return true;
//            }
//            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                return false;
//            }
//
//            Token token = SystemData.doctorTokens.get(uid);
//            if (token == null) {
//                token = tokenDao.findByPatient(uid, 2);
//                if (token != null) {
//                    // 加入缓存
//                    SystemData.doctorTokens.put(uid, token);
//                }
//            }
//            if (token == null || token.getPlatform() != 2) {
//                // 未登录
//                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//                flag = false;
//            } else {
//                if (token.getTimeout().getTime() < new Date().getTime()) {
//                    // 登录超时
//                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
//                    flag = false;
//                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
//                    // 别处登录
//                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
//                    flag = false;
//                } else {
//                    // 一天只更新一次
//                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
//                        // 今天未更新,则更新缓存
//                        token.setCzrq(new Date());
//                        // 更新内存
//                        SystemData.doctorTokens.put(uid, token);
//                        // 更新数据库
//                        tokenDao.save(token);
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        try {
            request.setCharacterEncoding("UTF-8");
            request.setAttribute("log-start", new Date().getTime());
            response.setCharacterEncoding("UTF-8");
            JSONObject json = getAgent(request);
            if (json == null) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            if (json.has("uid") && json.has("admin_token") && StringUtils.isNotEmpty(json.getString("admin_token"))) {
                String adminToken = SystemConf.getInstance().getSystemProperties().getProperty("admin_token");
                String adminUid = SystemConf.getInstance().getSystemProperties().getProperty("admin_uid");
                if (json.getString("uid").equals(adminUid) && json.getString("admin_token").equals(adminToken)) {
                    return true;
                }
            }
            String tokenStr = json.has("token") ? json.getString("token") : "";
            String uid = json.has("uid") ? json.getString("uid") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            //如果是观察者直接返回true
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
                Class cls = ((HandlerMethod) handler).getBeanType();
                RequestMapping clsRm = (RequestMapping) cls.getAnnotation(RequestMapping.class);
                Method method = ((HandlerMethod) handler).getMethod();
                RequestMapping mthRm = method.getAnnotation(RequestMapping.class);
                String url = "";
                String urlCls = "";
                String urlMth = "";
                if (clsRm.value() != null && clsRm.value().length > 0) {
                    urlCls = clsRm.value()[0];
                }
                if (mthRm.value() != null && mthRm.value().length > 0) {
                    urlMth = mthRm.value()[0];
                }
                if (StringUtils.isNotEmpty(urlCls)) {
                    url += urlCls.startsWith("/") ? urlCls : ("/" + urlCls);
                }
                if (StringUtils.isNotEmpty(urlMth)) {
                    url += urlMth.startsWith("/") ? urlMth : ("/" + urlMth);
                }
                url = url.replace("\\", "/").replace("//", "/");
                CudUrl cudUrl = cudUrlDao.findByUrl(url);
                if (url.equals("/doctor/consult/readed")) {
                    response.getOutputStream().write(write(200, "操作成功").getBytes());
                    return false;
                }
                if (cudUrl != null) {
                    if (StringUtils.isNotEmpty(cudUrl.getMethod()) &&
                            request.getMethod().toUpperCase().compareTo(cudUrl.getMethod()) != 0) {
                        return true;
                    } else {
                        response.getOutputStream().write(error(403, "该操作没有权限").getBytes());
                        return false;
                    }
                }
                return true;
            }
            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            Token token = SystemData.doctorTokens.get(uid);
            if (token == null) {
                token = tokenDao.findByPatient(uid, 2);
                if (token != null) {
                    // 加入缓存
                    SystemData.doctorTokens.put(uid, token);
                }
            }
            if (token == null || token.getPlatform() != 2) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                flag = false;
            } else {
                if (token.getTimeout().getTime() < new Date().getTime()) {
                    // 登录超时
                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
                    flag = false;
                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
                    // 别处登录
                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
                    flag = false;
                } else {
                    // 一天只更新一次
                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        SystemData.doctorTokens.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

+ 85 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/ObserverRequiredInterceptor.java

@ -0,0 +1,85 @@
package com.yihu.wlyy.interceptors;
import com.yihu.wlyy.aop.ObserverRequired;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
 * Created by Trick on 2017/6/24.
 */
public class ObserverRequiredInterceptor  implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        Object[] ars = mi.getArguments();
        HttpServletRequest request =null;
        HttpServletResponse response = null;
        for(Object o :ars){
            if(o instanceof HttpServletRequest){
                request = (HttpServletRequest) o;
            }
            if(o instanceof HttpServletResponse){
                response = (HttpServletResponse) o;
            }
        }
        if(request!=null&&response!=null){
            JSONObject json = getAgent(request);
            String tokenStr = json.has("token") ? json.getString("token") : "";
            String uid = json.has("uid") ? json.getString("uid") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            //if(StringUtils.isNotBlank(observer)&&"1".equals(observer)){
                if(mi.getMethod().isAnnotationPresent(ObserverRequired.class)){
                    System.out.println("----------this method is added @ObserverRequired-------------------------");
                    response.getOutputStream().write(error(403, "该操作没有权限").getBytes());
                    return null;
                }
            //}
        }
        //执行被拦截的方法,切记,如果此方法不调用,则被拦截的方法不会被执行。
        return mi.proceed();
    }
    public JSONObject getAgent(HttpServletRequest request) {
        try {
            String userAgent = request.getHeader("userAgent");
            if (StringUtils.isEmpty(userAgent)) {
                userAgent = request.getHeader("User-Agent");
            }
            System.out.println("userAgent:" + userAgent);
            return new JSONObject(userAgent);
        } catch (Exception e) {
            return null;
        }
    }
    public String write(int code, String msg) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("msg", msg);
            return json.toString();
        } catch (Exception e) {
            return null;
        }
    }
    public String error(int code, String msg) {
        try {
            JSONObject json = new JSONObject();
            json.put("status", code);
            json.put("msg", msg);
            return json.toString();
        } catch (Exception e) {
            return null;
        }
    }
}

+ 26 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/util/SignTeamAndGroupRunnable.java

@ -12,6 +12,8 @@ import com.yihu.wlyy.util.IdCardUtil;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.orm.jpa.JpaTransactionManager;
@ -22,6 +24,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
@ -33,6 +36,7 @@ import java.util.UUID;
/**
 * Created by lyr-pc on 2016/10/11.
 */
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Service
public class SignTeamAndGroupRunnable implements Runnable {
@ -55,6 +59,28 @@ public class SignTeamAndGroupRunnable implements Runnable {
        this.end = end;
    }
    public SignTeamAndGroupRunnable() {
    }
    public long getStart() {
        return start;
    }
    public SignTeamAndGroupRunnable setStart(long start) {
        this.start = start;
        return this;
    }
    public long getEnd() {
        return end;
    }
    public SignTeamAndGroupRunnable setEnd(long end) {
        this.end = end;
        return this;
    }
    public String getCode() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

+ 63 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SpringUtil.java

@ -0,0 +1,63 @@
package com.yihu.wlyy.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringUtil.applicationContext == null) {
            SpringUtil.applicationContext = applicationContext;
        }
    }
    //获取applicationContext
    public static ApplicationContext
    getApplicationContext() {
        return applicationContext;
    }
    //通过name获取 Bean.
    public static Object
    getBean(String name) {
        return getApplicationContext().getBean(name);
    }
    //通过class获取Bean.
    public static<T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }
    //通过name,以及Clazz返回指定的Bean
    public static<T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }
}

+ 4 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/util/ManagerUtilController.java

@ -9,8 +9,10 @@ import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.common.util.ManageUtilService;
import com.yihu.wlyy.service.common.util.SignTeamAndGroupRunnable;
import com.yihu.wlyy.util.SpringUtil;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
@ -219,7 +221,8 @@ public class ManagerUtilController extends BaseController {
    @RequestMapping(value = "/sign_team_group_thread")
    public String getErrorPage(long start, long end) {
        try {
            new Thread(new SignTeamAndGroupRunnable(start, end)).start();
            new Thread(SpringUtil.getBean(SignTeamAndGroupRunnable.class)
                    .setEnd(end).setStart(start)).start();
            return write(200, "启动成功");
        } catch (Exception e) {
            return error(-1, "启动失败");

+ 12 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.web.statistic;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.service.app.statistics.StatisticsAllService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
@ -127,7 +128,7 @@ public class StatisticsController extends BaseController {
     * @param level2_type 指标代码 例如性别 1 男 2 女  不传就返回男和女的总和
     * @return
     */
        @RequestMapping("/total")
    @RequestMapping("/total")
    @ResponseBody
    public String getIndexTotal(@RequestParam(required = true) String endDate,
                                @RequestParam(required = true) String area,
@ -818,7 +819,7 @@ public class StatisticsController extends BaseController {
                             @RequestParam(required = true)String type){
        try {
            return write(200, "查询成功", "data", statisticsService.getAvgLine(getUID(),startDate,endDate,type));
           // return write(200, "查询成功", "data", statisticsService.getAvgLine("xh1D201703150222",startDate,endDate,type));
            // return write(200, "查询成功", "data", statisticsService.getAvgLine("xh1D201703150222",startDate,endDate,type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
@ -874,10 +875,10 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getTeamDoctorConsultCount")
    @ResponseBody
    public String getTeamDoctorConsultCount(@RequestParam(required = true)String teamCode,
                                             @RequestParam(required = true)String startDate,
                                             @RequestParam(required = true)String endDate,
                                             @RequestParam(required = true)String type,
                                             @RequestParam(required = true)String doctor){
                                            @RequestParam(required = true)String startDate,
                                            @RequestParam(required = true)String endDate,
                                            @RequestParam(required = true)String type,
                                            @RequestParam(required = true)String doctor){
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorConsultCount(teamCode,startDate,endDate,type,doctor));
        } catch (Exception e) {
@ -1231,10 +1232,10 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getTeamDoctorEduLine")
    @ResponseBody
    public String getTeamDoctorEduLine(@RequestParam(required = true)String teamCode,
                                 @RequestParam(required = true)String startDate,
                                 @RequestParam(required = true)String endDate,
                                 @RequestParam(required = true)String type,
                                 @RequestParam(required = true)String doctor){
                                       @RequestParam(required = true)String startDate,
                                       @RequestParam(required = true)String endDate,
                                       @RequestParam(required = true)String type,
                                       @RequestParam(required = true)String doctor){
        try {
            return write(200, "查询成功", "data", statisticsService.getTeamDoctorEduLine(teamCode,startDate,endDate,type,doctor));
        } catch (Exception e) {
@ -1283,6 +1284,7 @@ public class StatisticsController extends BaseController {
    @RequestMapping("/getDotorInfo")
    @ResponseBody
    @ObserverRequired
    public String getDotorInfo(@RequestParam(required = true)String code){
        try {
            return write(200, "查询成功", "data", statisticsService.getDoctorInfo(code));

+ 219 - 217
patient-co-wlyy/src/main/resources/applicationContext.xml

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:task="http://www.springframework.org/schema/task"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	   xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
@ -15,222 +15,224 @@
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
	   default-lazy-init="true">
	<description>Spring公共配置 </description>
	<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
	<context:component-scan base-package="com.yihu.wlyy">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
	</context:component-scan>
	
	<task:annotation-driven />
	<!-- aop:aspectj-autoproxy proxy-target-class="true" / -->
	
	<!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 -->  
       default-lazy-init="true">
    <description>Spring公共配置</description>
    <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
    <context:component-scan base-package="com.yihu.wlyy">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <task:annotation-driven/>
    <!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 -->
    <!-- task:scheduled-tasks scheduler="followUpScheduler">
        <task:scheduled ref="followUpTask" method="push" cron="0 0 6 * * *"/>  
    </task:scheduled-tasks>
    <task:scheduler id="followUpScheduler" pool-size="10"/ -->
	<!-- Jpa Entity Manager 配置 -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" autowire-candidate="default">
		<property name="dataSource" ref="dataSource"/>
		<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
		<property name="packagesToScan" value="com.yihu.wlyy.entity"/>
		<property name="jpaProperties">
			<props>
				<!-- 命名规则 My_NAME->MyName -->
				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>
	<bean id="entityManagerFactoryHealth" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="dataSourceHealth"/>
		<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapterHealth"/>
		<property name="packagesToScan" value="com.yihu.wlyy.health.entity"/>
		<property name="jpaProperties">
			<props>
				<!-- 命名规则 My_NAME->MyName -->
				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>
	
	<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
		<property name="databasePlatform">
			<bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
				<constructor-arg ref="dataSource"/>
			</bean>
		</property>
	</bean>
	<bean id="hibernateJpaVendorAdapterHealth" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
		<property name="databasePlatform">
			<bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
				<constructor-arg ref="dataSourceHealth"/>
			</bean>
		</property>
	</bean>
	<!-- Spring Data Jpa配置 -->
 	<jpa:repositories base-package="com.yihu.wlyy.repository"  transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
	<jpa:repositories base-package="com.yihu.wlyy.health.repository"  transaction-manager-ref="transactionManagerHealth" entity-manager-factory-ref="entityManagerFactoryHealth"/>
	<!-- Jpa 事务配置 -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory"/>
	</bean>
	<!-- Jpa 事务配置 -->
	<bean id="transactionManagerHealth" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactoryHealth"/>
	</bean>
	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
	<tx:annotation-driven transaction-manager="transactionManagerHealth" proxy-target-class="true" />
	<!-- JSR303 Validator定义 -->
 	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
 	
 	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" />
    <!-- Jpa Entity Manager 配置 -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          autowire-candidate="default">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
        <property name="packagesToScan" value="com.yihu.wlyy.entity"/>
        <property name="jpaProperties">
            <props>
                <!-- 命名规则 My_NAME->MyName -->
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
    <bean id="entityManagerFactoryHealth" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSourceHealth"/>
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapterHealth"/>
        <property name="packagesToScan" value="com.yihu.wlyy.health.entity"/>
        <property name="jpaProperties">
            <props>
                <!-- 命名规则 My_NAME->MyName -->
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
    <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform">
            <bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
                <constructor-arg ref="dataSource"/>
            </bean>
        </property>
    </bean>
    <bean id="hibernateJpaVendorAdapterHealth" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform">
            <bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
                <constructor-arg ref="dataSourceHealth"/>
            </bean>
        </property>
    </bean>
    <!-- Spring Data Jpa配置 -->
    <jpa:repositories base-package="com.yihu.wlyy.repository" transaction-manager-ref="transactionManager"
                      entity-manager-factory-ref="entityManagerFactory"/>
    <jpa:repositories base-package="com.yihu.wlyy.health.repository" transaction-manager-ref="transactionManagerHealth"
                      entity-manager-factory-ref="entityManagerFactoryHealth"/>
    <!-- Jpa 事务配置 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- Jpa 事务配置 -->
    <bean id="transactionManagerHealth" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryHealth"/>
    </bean>
    <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
    <tx:annotation-driven transaction-manager="transactionManagerHealth" proxy-target-class="true"/>
    <!-- JSR303 Validator定义 -->
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
    <!--quartz任务调度器名称,调度器只能加载与名称相同的任务-->
	<!--<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton">-->
		<!--<property name="dataSource" ref="dataSource"/>-->
		<!--<property name="configLocation" value="classpath:/quartz.properties" />-->
		<!--<property name="autoStartup" value="true"/>-->
	<!--</bean>-->
	<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxIdle" value="${redis.maxIdle}"/>
		<property name="maxTotal" value="${redis.maxActive}"/>
		<property name="maxWaitMillis" value="${redis.maxWait}"/>
		<property name="testOnBorrow" value="${redis.testOnBorrow}"/>
	</bean>
	<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
		<property name="hostName" value="${redis.host}"></property>
		<property name="port" value="${redis.port}"></property>
		<property name="password" value="${redis.password}"></property>
		<property name="database" value="0"></property>
		<property name="poolConfig" ref="poolConfig"></property>
	</bean>
	<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
		<property name="connectionFactory" ref="connectionFactory"/>
	</bean>
	<util:properties id="sys" location="classpath*:/system.properties"/>
	<beans>
		<context:property-placeholder ignore-unresolvable="true"
									  location="classpath*:/application.properties" />
		<!-- 数据源配置, 使用Tomcat JDBC连接池 -->
		<bean id="dataSourceHealth" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<!-- Connection Info -->
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${health.jdbc.url}" />
			<property name="username" value="${health.jdbc.username}" />
			<property name="password" value="${health.jdbc.password}" />
			<!-- Connection Pooling Info -->
			<property name="maxActive" value="${jdbc.pool.maxActive}" />
			<property name="maxIdle" value="${jdbc.pool.maxIdle}" />
			<property name="minIdle" value="0" />
			<property name="defaultAutoCommit" value="false" />
		</bean>
	</beans>
	<!-- production环境 -->
 	<beans profile="production">
 		<context:property-placeholder ignore-unresolvable="true"
			location="classpath*:/application.properties" />
		
		<!-- 数据源配置, 使用Tomcat JDBC连接池 -->
		<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<!-- Connection Info -->
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
		
			<!-- Connection Pooling Info -->
			<property name="maxActive" value="${jdbc.pool.maxActive}" />
			<property name="maxIdle" value="${jdbc.pool.maxIdle}" />
			<property name="minIdle" value="0" />
			<property name="defaultAutoCommit" value="false" />
		</bean>
		<!-- 数据源配置,使用应用服务器的数据库连接池 -->
		<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->
	</beans>
	
	<!-- local development环境 -->
	<beans profile="development">
		<context:property-placeholder ignore-resource-not-found="true"
			location="classpath*:/application.properties,
          			  classpath*:/application.development.properties" />
		<!-- Tomcat JDBC连接池 -->
		<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
			<property name="defaultAutoCommit" value="false" />
		</bean>
	</beans>
	<!-- functional test 环境 -->
	<beans profile="functional">
		<context:property-placeholder ignore-resource-not-found="true"
			location="classpath*:/application.properties,
    <!--<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton">-->
    <!--<property name="dataSource" ref="dataSource"/>-->
    <!--<property name="configLocation" value="classpath:/quartz.properties" />-->
    <!--<property name="autoStartup" value="true"/>-->
    <!--</bean>-->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxIdle" value="${redis.maxIdle}"/>
        <property name="maxTotal" value="${redis.maxActive}"/>
        <property name="maxWaitMillis" value="${redis.maxWait}"/>
        <property name="testOnBorrow" value="${redis.testOnBorrow}"/>
    </bean>
    <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.host}"></property>
        <property name="port" value="${redis.port}"></property>
        <property name="password" value="${redis.password}"></property>
        <property name="database" value="0"></property>
        <property name="poolConfig" ref="poolConfig"></property>
    </bean>
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="connectionFactory"/>
    </bean>
    <util:properties id="sys" location="classpath*:/system.properties"/>
    <beans>
        <context:property-placeholder ignore-unresolvable="true"
                                      location="classpath*:/application.properties"/>
        <!-- 数据源配置, 使用Tomcat JDBC连接池 -->
        <bean id="dataSourceHealth" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <!-- Connection Info -->
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${health.jdbc.url}"/>
            <property name="username" value="${health.jdbc.username}"/>
            <property name="password" value="${health.jdbc.password}"/>
            <!-- Connection Pooling Info -->
            <property name="maxActive" value="${jdbc.pool.maxActive}"/>
            <property name="maxIdle" value="${jdbc.pool.maxIdle}"/>
            <property name="minIdle" value="0"/>
            <property name="defaultAutoCommit" value="false"/>
        </bean>
    </beans>
    <!-- production环境 -->
    <beans profile="production">
        <context:property-placeholder ignore-unresolvable="true"
                                      location="classpath*:/application.properties"/>
        <!-- 数据源配置, 使用Tomcat JDBC连接池 -->
        <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <!-- Connection Info -->
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <!-- Connection Pooling Info -->
            <property name="maxActive" value="${jdbc.pool.maxActive}"/>
            <property name="maxIdle" value="${jdbc.pool.maxIdle}"/>
            <property name="minIdle" value="0"/>
            <property name="defaultAutoCommit" value="false"/>
        </bean>
        <!-- 数据源配置,使用应用服务器的数据库连接池 -->
        <!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->
    </beans>
    <!-- local development环境 -->
    <beans profile="development">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath*:/application.properties,
          			  classpath*:/application.development.properties"/>
        <!-- Tomcat JDBC连接池 -->
        <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="defaultAutoCommit" value="false"/>
        </bean>
    </beans>
    <!-- functional test 环境 -->
    <beans profile="functional">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath*:/application.properties,
          			  classpath*:/application.functional.properties,
          			  classpath*:/application.functional-local.properties" />
		<!-- Tomcat JDBC连接池 -->
		<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
			<property name="defaultAutoCommit" value="false" />
		</bean>
		<!-- 初始化数据表结构 -->
		<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
			<jdbc:script location="classpath:sql/${db.type}/schema.sql" />
		</jdbc:initialize-database>
	</beans>
	<!-- unit test环境 -->
	<beans profile="test">
	 	<context:property-placeholder ignore-resource-not-found="true"
			location="classpath*:/application.properties,
          			  classpath*:/application.test.properties" />
		<!-- Spring Simple连接池 -->
		<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
			<property name="driverClass" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
		</bean>
		<!-- 初始化数据表结构 与默认数据-->
		<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
			<jdbc:script location="classpath:sql/mysql/schema.sql" />
			<!-- jdbc:script location="classpath:data/h2/import-data.sql" encoding="UTF-8"/ -->
		</jdbc:initialize-database>
	</beans>
          			  classpath*:/application.functional-local.properties"/>
        <!-- Tomcat JDBC连接池 -->
        <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="defaultAutoCommit" value="false"/>
        </bean>
        <!-- 初始化数据表结构 -->
        <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
            <jdbc:script location="classpath:sql/${db.type}/schema.sql"/>
        </jdbc:initialize-database>
    </beans>
    <!-- unit test环境 -->
    <beans profile="test">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath*:/application.properties,
          			  classpath*:/application.test.properties"/>
        <!-- Spring Simple连接池 -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
            <property name="driverClass" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
        </bean>
        <!-- 初始化数据表结构 与默认数据-->
        <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
            <jdbc:script location="classpath:sql/mysql/schema.sql"/>
            <!-- jdbc:script location="classpath:data/h2/import-data.sql" encoding="UTF-8"/ -->
        </jdbc:initialize-database>
    </beans>
</beans>

+ 13 - 12
patient-co-wlyy/src/main/webapp/WEB-INF/spring-mvc.xml

@ -1,20 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:task="http://www.springframework.org/schema/task"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
	   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
	<!-- 自动扫描且只扫描@Controller -->
	<context:component-scan base-package="com.yihu.wlyy" use-default-filters="false">
	<context:component-scan base-package="com.yihu.wlyy" >
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
	</context:component-scan>
	<aop:aspectj-autoproxy proxy-target-class="true" expose-proxy="true"> </aop:aspectj-autoproxy>
	<task:annotation-driven />
    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
@ -75,7 +76,7 @@
			<value>4096</value>
		</property>
	</bean>
	
	<mvc:interceptors>
		<mvc:interceptor>
	        <mvc:mapping path="/patient/**"/>
@ -90,5 +91,5 @@
	        <bean class="com.yihu.wlyy.interceptors.UserInterceptor"/>
	    </mvc:interceptor>
	</mvc:interceptors>
    
</beans>