Browse Source

wlyy_service 增加动态获取系统参数

huangwenjie 7 years ago
parent
commit
4e0812e234

+ 5 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/common/SystemConfig.java

@ -4,6 +4,8 @@ import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
@ -18,6 +20,9 @@ public class SystemConfig {
    // 系统配置文件
    private Properties systemProperties;
    //从system_properties表中取到的系统参数集,key参数key,value参数值
    public static Map<String,String> sysPropertiesSets = new HashMap<>();
    public static SystemConfig getInstance() {
        if (systemConf == null) {
            synchronized (lock) {

+ 45 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/CommonController.java

@ -0,0 +1,45 @@
package com.yihu.wlyy.service.controller;
import com.yihu.wlyy.service.common.model.Result;
import com.yihu.wlyy.service.service.common.InitiSysProService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * 公共请求接口
 * @author huangwenjie
 * @date 2017/8/22 21:06
 */
@Controller
@RestController
@RequestMapping(value = "/common/")
@Api(description = "长处方接口")
public class CommonController {
    private static Logger logger = LoggerFactory.getLogger(CommonController.class);
    @Autowired
    private InitiSysProService initiSysProService;
    @RequestMapping(value = "startInitiSysProperties",method = RequestMethod.POST)
    @ApiOperation("重新执行系统参数初始化")
    public Result startInitiSysProperties(){
        try {
            logger.info("START===执行系统参数初始化");
            initiSysProService.startInitiSysProperties();
            logger.info("END===执行系统参数初始化");
            return Result.success("重新执行系统参数初始化成功!",true);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.info("ERROR===执行系统参数初始化:"+ex.getMessage());
            return Result.error(ex.getMessage());
        }
    }
}

+ 21 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/dao/common/SystemPropertiesDao.java

@ -0,0 +1,21 @@
package com.yihu.wlyy.service.dao.common;
import com.yihu.wlyy.service.entity.common.SystemProperties;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author huangwenjie
 * @date 2017/8/22 20:43
 */
public interface SystemPropertiesDao extends
        PagingAndSortingRepository<SystemProperties, Long>,
        JpaSpecificationExecutor<SystemProperties> {
    @Query("select a from SystemProperties a where a.client = ?1 and a.isdel = 0 ")
    List<SystemProperties> findSystemPropertiesByClientAndSpaValue(Integer client);
}

+ 59 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/entity/common/SystemProperties.java

@ -0,0 +1,59 @@
package com.yihu.wlyy.service.entity.common;
import com.yihu.wlyy.service.common.model.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @author huangwenjie
 * @date 2017/8/22 20:27
 */
@Entity
@Table(name = "system_properties")
public class SystemProperties  extends IdEntity {
    //工程类型-0:wlyy,1:wlyy_service
    private Integer client;
    //参数key
    private String key;
    //参数值
    private String value;
    //0为有效,1为删除状态
    private Integer isdel;
    public Integer getClient() {
        return client;
    }
    public void setClient(Integer client) {
        this.client = client;
    }
    public String getKey() {
        return key;
    }
    public void setKey(String key) {
        this.key = key;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public Integer getIsdel() {
        return isdel;
    }
    public void setIsdel(Integer isdel) {
        this.isdel = isdel;
    }
}

+ 34 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/event/ApplicationEvent.java

@ -0,0 +1,34 @@
package com.yihu.wlyy.service.event;
import com.yihu.wlyy.service.service.common.InitiSysProService;
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;
/**
 *启动执行系统参数初始化
 *@author huangwenjie
 *@date 2017/8/22 22:25
 */
@Service
public class ApplicationEvent implements ApplicationListener<ContextRefreshedEvent> {
    private Logger logger = LoggerFactory.getLogger(ApplicationEvent.class);
    @Autowired
    private InitiSysProService initiSysProService;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent ContextRefreshedEvent) {
        try {
            logger.info("START===开始执行执行系统参数初始化");
            initiSysProService.startInitiSysProperties();
            logger.info("END===成功执行系统参数初始化");
        } catch (Exception e) {
            logger.info("ERROR===执行系统参数初始化失败:"+e.getMessage());
        }
    }
}

+ 57 - 0
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/common/InitiSysProService.java

@ -0,0 +1,57 @@
package com.yihu.wlyy.service.service.common;
import com.yihu.wlyy.service.common.CommonContent;
import com.yihu.wlyy.service.common.SystemConfig;
import com.yihu.wlyy.service.dao.common.SystemPropertiesDao;
import com.yihu.wlyy.service.entity.common.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author huangwenjie
 * @date 2017/8/22 20:01
 */
@Service("InitiSysProService")
public class InitiSysProService {
    @Autowired
    private SystemPropertiesDao systemPropertiesDao;
    /**
     * 重新执行系统参数初始化
     */
    public void startInitiSysProperties() throws Exception{
        if(!SystemConfig.sysPropertiesSets.isEmpty()){
            SystemConfig.sysPropertiesSets.clear();
        }
        Map<String,String> sysPropertiesSets = new HashMap<>();
        List<SystemProperties> sysvalueList = systemPropertiesDao.findSystemPropertiesByClientAndSpaValue(1);
        if(!sysvalueList.isEmpty()){
            for (SystemProperties systemProperties : sysvalueList) {
                sysPropertiesSets.put(systemProperties.getKey(),systemProperties.getValue());
            }
            SystemConfig.sysPropertiesSets = sysPropertiesSets;
        }
    }
//
//    public String returnSysProValue(String key) throws Exception {
//        if(CommonContent.sysPropertiesSets.keySet().contains(key)){
//            return  CommonContent.sysPropertiesSets.get(key);
//        }else{
//            boolean result = this.startInitiSysProperties();
//            if(result){
//                return  CommonContent.sysPropertiesSets.get(key);
//            }else{
//                throw new Exception("无法获取系统参数,key:"+key);
//            }
//        }
//    }
}

+ 11 - 8
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionCAService.java

@ -25,8 +25,6 @@ public class PrescriptionCAService {
    private String MODIFY_PASSWD = "XMCAF_SOFT_ModifyRealNameSoftCertCalledPasswd"; //修改实名软证书调用保护口令
    private String VERIFY_SIGN = "XMCA3_JMSVR_verifySignOnMultiServer"; //验证签名(带多服务器负载均衡)
    private String caUrl = SystemConfig.getInstance().getCAUrl();
    private String caNamespace = SystemConfig.getInstance().getCANamespace();
    private String unifiedCallInterface = "XMCA6_UnifiedCallInterface";
    @Autowired
    private LogService logService;
@ -58,8 +56,12 @@ public class PrescriptionCAService {
    /**
     * CA认证服务二次封装
     */
    private String postCAServer(String urlString,String namespace,String api, Map<String,String> params) throws Exception
    private String postCAServer(String api, Map<String,String> params) throws Exception
    {
        String urlString = SystemConfig.sysPropertiesSets.get("ca_url");
        String namespace = SystemConfig.sysPropertiesSets.get("ca_namespace");
        String msgBody = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                         "<root>\n";
        if(params!=null && params.size()>0)
@ -96,7 +98,7 @@ public class PrescriptionCAService {
            params.put("strUserIdcardNum",strUserIdcardNum);
            body = objectMapper.writeValueAsString(params);
            re = postCAServer(caUrl, caNamespace, action, params);
            re = postCAServer(action, params);
            if(StringUtil.isEmpty(re))
            {
@ -145,7 +147,7 @@ public class PrescriptionCAService {
            body = objectMapper.writeValueAsString(params);
            re = postCAServer(caUrl,caNamespace,action, params);
            re = postCAServer(action, params);
            if(StringUtil.isEmpty(re))
            {
@ -193,7 +195,8 @@ public class PrescriptionCAService {
            params.put("strUserIdcardNum",strUserIdcardNum);
            body = objectMapper.writeValueAsString(params);
            re = postCAServer(caUrl, caNamespace, action, params);
            re = postCAServer(action, params);
            if(StringUtil.isEmpty(re))
            {
@ -241,7 +244,7 @@ public class PrescriptionCAService {
            params.put("strNewCalledPasswd",strNewCalledPasswd);
            body = objectMapper.writeValueAsString(params);
            re = postCAServer(caUrl, caNamespace, action, params);
            re = postCAServer(action, params);
            if(StringUtil.isEmpty(re))
            {
@ -294,7 +297,7 @@ public class PrescriptionCAService {
            params.put("strOriginalData",strOriginalData);
            body = objectMapper.writeValueAsString(params);
            re = postCAServer(caUrl,caNamespace,action, params);
            re = postCAServer(action, params);
            if(StringUtil.isEmpty(re))
            {

+ 4 - 2
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionService.java

@ -673,7 +673,8 @@ public class PrescriptionService extends ZysoftBaseService{
        String[] hospitalMapping = getHospitalMapping(prescription.getHospital()); //获取机构映射
        String hospital = hospitalMapping[0];
        String licence = hospitalMapping[1];
//        String licence = hospitalMapping[1];
        String licence = "5YGl5bq35LmL6Lev";
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);
@ -702,7 +703,8 @@ public class PrescriptionService extends ZysoftBaseService{
        String[] hospitalMapping = getHospitalMapping(prescription.getHospital()); //获取机构映射
        String hospital = hospitalMapping[0];
        String licence = hospitalMapping[1];
//        String licence = hospitalMapping[1];
        String licence = "5YGl5bq35LmL6Lev";
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);