浏览代码

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

yeshijie 7 年之前
父节点
当前提交
f0397cbbb7

+ 32 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -0,0 +1,32 @@
package com.yihu.wlyy.event;
import com.yihu.wlyy.redis.RedisThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
/**
 * Created by lyr-pc on 2017/3/10.
 */
@Service
public class ApplicationEvent implements ApplicationListener<ContextRefreshedEvent> {
    private Logger logger = LoggerFactory.getLogger(ApplicationEvent.class);
    @Autowired
    private RedisThread redisThread;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent ContextRefreshedEvent) {
        try {
            // 启动redis 消息队列线程
            logger.info("redis message start");
            new Thread(redisThread).start();
            logger.info("redis message end");
        } catch (Exception e) {
            logger.info("redis message start failed");
        }
    }
}

+ 23 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/redis/RedisThread.java

@ -1,10 +1,12 @@
package com.yihu.wlyy.redis;
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
/**
 * Created by Trick on 2017/8/7.
@ -16,9 +18,27 @@ public class RedisThread implements Runnable {
    private String url;
    @Autowired
    private RedisMsgPubSubListener redisMsgPubSubListener;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PrescriptionService prescriptionService;
    @Override
    public void run() {
        Jedis jedis = new Jedis(url);
        jedis.subscribe(redisMsgPubSubListener, SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title"));
        String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
        while (true){
            redisTemplate.watch(key);
            String message = redisTemplate.opsForList().rightPop(key);
            redisTemplate.unwatch();
            if(StringUtils.isEmpty(message)){
                try{
                    Thread.sleep(1000L);//如果没有读取到记录,等待1秒
                }catch (Exception e){
                    e.printStackTrace();
                }
            }else {
                prescriptionService.redisMessage(message);
            }
        }
    }
}

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java

@ -88,6 +88,8 @@ public class PrescriptionInfoService extends BaseService {
    private static final String tnb = "HP0047";
    @Autowired
    private PrescriptionExpressageService expressageService;
    @Autowired
    private PrescriptionService prescriptionService;
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
@ -385,6 +387,9 @@ public class PrescriptionInfoService extends BaseService {
                //审核通过模板消息
                sendRMess(code, 1);
                //获取智业待结算接口,更新药品金额
                prescriptionService.getPerscriptionInfoCostFromPayInfo(p.getCode());
                return 1;
            } else {
                p.setStatus(PrescriptionLog.PrescriptionLogStatus.add_error.getValue());

+ 20 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java

@ -76,6 +76,26 @@ public class PrescriptionService extends BaseService {
        return prescriptionDao.findByCode(prescriptionCode);
    }
    /**
     * redis 消息队列
     * @param message
     */
    public void redisMessage(String message){
        logger.info("redis_onMessage...:"+message);
        //this.unsubscribe();
        try{
            JSONObject json = JSONObject.parseObject(message);
            String title =  json.getString("title");
            if("dispensingComplete".equals(title)){//配药完成
                //药品配送完成,提醒取药
                String prescriptionCode = json.getString("prescription");
                dispensingComplete(prescriptionCode);
            }
        }catch (Exception e){
            logger.error("redis_error...",e);
        }
    }
    /**
     * 配药完成
     * @param code

+ 0 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -124,11 +124,6 @@ public class JwPrescriptionService {
     * @throws Exception
     */
    public String saveRecipe(String prescriptionCode) throws Exception{
        try {
        }catch (Exception e){
        }
        String url = jwUrl + "/third/prescription/saveRecipe";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("prescriptionCode", prescriptionCode));