浏览代码

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

sand 8 年之前
父节点
当前提交
fd1c7b8a36

+ 18 - 13
src/main/java/com/yihu/wlyy/service/app/disease/PatientDiseaseService.java

@ -415,24 +415,29 @@ public class PatientDiseaseService extends BaseService {
     * 更新患者疾病到redis
     */
    public void updateToRedis() {
        String sql = "select * from wlyy_patient_disease where del = '1'";
        String sql = "select * from wlyy_patient_disease";
        List<Map<String, Object>> patientDiseases = jdbcTemplate.queryForList(sql);
        Map<String, JSONArray> diseases = new HashMap<>();
        if (patientDiseases != null) {
            for (Map<String, Object> map : patientDiseases) {
                JSONObject disease = new JSONObject();
                disease.put("disease", map.get("disease"));
                disease.put("diseaseName", map.get("disease_name"));
                disease.put("del", map.get("del"));
                disease.put("signType", map.get("sign_type"));
                if (diseases.containsKey(map.get("patient").toString())) {
                    diseases.get(map.get("patient").toString()).put(disease);
                } else {
                    JSONArray jsonArray = new JSONArray();
                    jsonArray.put(disease);
                    diseases.put(map.get("patient").toString(), jsonArray);
                if(!diseases.containsKey(map.get("patient").toString())){
                    diseases.put(map.get("patient").toString(), new JSONArray());
                }
                if(map.get("del").toString().equals("1")) {
                    JSONObject disease = new JSONObject();
                    disease.put("disease", map.get("disease"));
                    disease.put("diseaseName", map.get("disease_name"));
                    disease.put("del", map.get("del"));
                    disease.put("signType", map.get("sign_type"));
                    if (diseases.containsKey(map.get("patient").toString())) {
                        diseases.get(map.get("patient").toString()).put(disease);
                    } else {
                        JSONArray jsonArray = new JSONArray();
                        jsonArray.put(disease);
                        diseases.put(map.get("patient").toString(), jsonArray);
                    }
                }
            }
        }

+ 107 - 0
src/main/java/com/yihu/wlyy/service/common/QrcodeService.java

@ -1,7 +1,9 @@
package com.yihu.wlyy.service.common;
import com.yihu.wlyy.entity.address.Hospital;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.repository.address.TownDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.service.BaseService;
@ -30,6 +32,8 @@ public class QrcodeService extends BaseService {
    private DoctorDao doctorDao;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private TownDao townDao;
    /**
     * 所有医生二维码生成
@ -104,6 +108,39 @@ public class QrcodeService extends BaseService {
        return true;
    }
    /**
     * 生成区二维码
     *
     * @param town
     * @param token
     * @return
     * @throws Exception
     */
    public boolean makeTownQrcode(String town,String token) throws Exception{
        try{
            Town twn = townDao.findByCode(town);
            if (twn != null) {
                // 二维码内容
                String content = "tw_" + twn.getCode() + "_" + twn.getName();
                // 二维码图片文件名
                String fileName = twn.getCode();
                String path = QrcodeService.class.getResource("/").getPath().replace("/WEB-INF/classes/", "")
                        + File.separator + "qrcode";
                // 通过微信接口生成区二维码
                makeQrcodeFromWeiXin(content, fileName.replaceAll("\r\n", ""), path, token);
                return true;
            } else {
                throw new Exception("can not find town info");
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 社区二维码生成打包为zip
     *
@ -250,6 +287,74 @@ public class QrcodeService extends BaseService {
        }
    }
    /**
     * 区二维码生成打包为zip
     *
     * @param city
     * @param token
     * @return
     * @throws Exception
     */
    public File downLoadTownQrcodes(String city,String token) throws Exception{
        // 查找所有医生
        Iterable<Town> towns = null;
        String zipFileName = "town_qrcode";
        if (StringUtils.isNotEmpty(city)) {
            towns = townDao.findByCity(city);
        } else {
            towns = townDao.findAll();
        }
        String path = QrcodeService.class.getResource("/").getPath().replace("/WEB-INF/classes/", "")
                + File.separator + "qrcode_download";
        File file = new File(path);
        // 删除文件夹、文件
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files != null && files.length > 0) {
                for (File f : files) {
                    f.delete();
                }
            }
            file.delete();
        }
        if (towns != null) {
            for (Town town : towns) {
                if (StringUtils.isNotEmpty(city)) {
                    zipFileName = town.getCity();
                }
                // 二维码内容
                String content = "tw_" + town.getCode() + "_" + town.getName();
                // 二维码图片文件名
                String fileName = town.getName() + "_" + town.getCode();
                if (StringUtils.isEmpty(fileName)) {
                    continue;
                }
                // 通过微信接口生成医生二维码
                makeQrcodeFromWeiXin(content, fileName.replaceAll("\r\n", ""), path, token);
            }
            File zipFile = new File(path.replace("qrcode_download", "") + zipFileName + ".zip");
            if (zipFile.exists()) {
                zipFile.delete();
            }
            // 打包文件夹
            if (fileToZip(path, path.replace("qrcode_download", ""), zipFileName)) {
                return new File(path.replace("qrcode_download", "") + zipFileName + ".zip");
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    /**
     * 打包文件夹
     *
@ -388,4 +493,6 @@ public class QrcodeService extends BaseService {
            throw new Exception(e.getMessage());
        }
    }
}

+ 99 - 0
src/main/java/com/yihu/wlyy/web/common/qrcode/QrcodeController.java

@ -85,6 +85,28 @@ public class QrcodeController extends WeixinBaseController {
        }
    }
    /**
     * 生成区二维码
     *
     * @param town
     * @return
     */
    @RequestMapping(value = "/town")
    @ResponseBody
    public String makeTownQrcode(String town){
        try{
            if(qrcodeService.makeTownQrcode(town,getAccessToken())){
                return write(200,"生成二维码成功!");
            }else{
                return error(-1,"生成二维码失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"生成二维码失败!");
        }
    }
    /**
     * 下载某个社区的二维码
     *
@ -127,6 +149,47 @@ public class QrcodeController extends WeixinBaseController {
        }
    }
    /**
     * 下载某个区的二维码
     *
     * @param town
     * @param response
     */
    @RequestMapping(value = "/town_img")
    public void downloadTownQrcode(String town, HttpServletResponse response){
        try{
            File file = new File(QrcodeController.class.getResource("/").getPath().replace("/WEB-INF/classes/", "") +
                    File.separator +"qrcode" + File.separator + town + ".png");
            boolean flag = false;
            if(!file.exists()){
                flag = qrcodeService.makeTownQrcode(town,getAccessToken());
            }else{
                flag = true;
            }
            if(flag = true) {
                response.setCharacterEncoding("utf-8");
                String path = request.getSession().getServletContext().getRealPath("/")
                        + File.separator + "qrcode" + File.separator + town + ".png";
                InputStream inputStream = new FileInputStream(path);
                OutputStream outputStream = response.getOutputStream();
                byte[] b = new byte[2048];
                int length = 0;
                while ((length = inputStream.read(b)) > 0) {
                    outputStream.write(b, 0, length);
                }
                outputStream.close();
                inputStream.close();
            }else{
                response.setStatus(404);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 下载某个医生的二维码
@ -297,4 +360,40 @@ public class QrcodeController extends WeixinBaseController {
        }
    }
    /**
     * 下载某个城市的区的二维码图片
     *
     * @param city
     * @param response
     */
    @RequestMapping(value = "/download/towns")
    public void downloadTownQrcodes(String city,HttpServletResponse response){
        try{
            File file = qrcodeService.downLoadTownQrcodes(city,getAccessToken());
            if(file != null){
                response.setCharacterEncoding("utf-8");
                response.setContentType("multipart/form-data");
                response.setHeader("Content-Disposition", "attachment;fileName=towns_qrcode.zip");
                InputStream inputStream = new FileInputStream(file);
                OutputStream outputStream = response.getOutputStream();
                byte[] b = new byte[2048];
                int length = 0;
                while ((length = inputStream.read(b)) > 0) {
                    outputStream.write(b, 0, length);
                }
                outputStream.close();
                inputStream.close();
            }else{
                response.setStatus(500);
            }
        }catch (Exception e){
            e.printStackTrace();
            response.setStatus(500);
        }
    }
}

+ 29 - 0
src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -148,6 +148,35 @@ public class WeiXinEventProcess {
            article.put("Description","请点击查看社区详情");
            article.put("PicUrl",picUrl);
            articles.add(article);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
        } else if(StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("tw_") ||
                eventKey.startsWith("qrscene_tw_"))){
            // 配置信息
            Properties systemConf = SystemConf.getInstance().getSystemProperties();
            // 图文信息
            List<Map<String,String>> articles =  new ArrayList<>();
            Map<String,String> article = new HashMap<>();
            // 社区二维码跳转URL
            String url = systemConf.getProperty("doctor_town_qrcode_url");
            // 图片URL
            String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
            // 二维码参数
            String[] keys = eventKey.replace("qrscene_tw_","").replace("tw_","").split("_");
            // 图文消息URL
            url = url.replace("{server}", systemConf.getProperty("wechat_base_url"))
                    .replace("{appId}", systemConf.getProperty("appId"))
                    .replace("{town}",keys[0]);
            //图片地址
            picUrl = picUrl.replace("{server}", systemConf.getProperty("server_url"));
            article.put("Url",url);
            article.put("Title",keys[1]);
            article.put("Description","请点击查看区详情");
            article.put("PicUrl",picUrl);
            articles.add(article);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);

+ 1 - 0
src/main/resources/system.properties

@ -89,6 +89,7 @@ chat_file_path=/var/local/upload/chat
doctor_qrcode_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fssgg%2fhtml%2fdoctor-homepage-new.html&amp;response_type=code&amp;scope=snsapi_base&amp;state={doctorCode}#wechat_redirect
doctor_hos_qrcode_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fqygl%2fhtml%2fsearch-doctor.html&amp;response_type=code&amp;scope=snsapi_base&amp;state={hospital}#wechat_redirect
doctor_subscribe_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fqygl%2fhtml%2fsigning-welcome.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
doctor_town_qrcode_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fqygl%2fhtml%2fsearch-community.html&amp;response_type=code&amp;scope=snsapi_base&amp;state={town}#wechat_redirect
doctor_qrcode_pic_url={server}/images/familycontract.png
doctor_invitel_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&redirect_uri={server}%2fwx%2fhtml%2fssgg%2fhtml%2fdoctor-homepage-new.html&response_type=code&scope=snsapi_base&state={doctorCode}__{invilogcode}__{currentPatient}__{currentZH}#wechat_redirect