Ver código fonte

调整取药码二维码生成方式

liuwenbin 7 anos atrás
pai
commit
35d5d306c5

+ 30 - 45
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionDispensaryCodeService.java

@ -7,7 +7,9 @@ import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo;
import com.yihu.wlyy.repository.prescription.PrescriptionDispensaryCodeDao;
import com.yihu.wlyy.repository.prescription.PrescriptionInfoDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.QrcodeService;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.util.QrcodeUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.fastdfs.FastDFSUtil;
import org.apache.commons.lang3.StringUtils;
@ -22,8 +24,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
@ -66,8 +67,9 @@ public class PrescriptionDispensaryCodeService extends BaseService {
                case 4:timeLimit = 7*24*60*60*31*12;break;//近一年
            }
        }
        List<Object> params = new ArrayList<>();
        String precriptionSql = "select p2.*,p1.diagnosis as diagnosis ,p3.address as address from wlyy_prescription_dispensary_code p2 left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code where p1.patient=? and p2.type=?  and p2.is_Use=0 ";
        List<Object> params = new ArrayList<>();//p2.*,p1.diagnosis as diagnosis ,p3.address as address
        String precriptionSql = "select p1.status , p1.diagnosis ,p3.address as address,p2.prescription_code as prescriptionCode,p2.code as dispensaryCode,p2.type  from wlyy_prescription_dispensary_code p2 " +
                " left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code where p1.patient=? and p2.type=?  and p2.is_Use=0 ";
        params.add(patientCode);
        params.add(type);
        if(status!=null){
@ -84,8 +86,8 @@ public class PrescriptionDispensaryCodeService extends BaseService {
        List<Map<String, Object>> result = jdbcTemplate.queryForList(precriptionSql,params.toArray());
        List<Map<String, Object>> result2 = new ArrayList<>();
        for (Map<String, Object> m:result) {
            List<PrescriptionInfo> list = prescriptionInfoDao.findByPrescriptionCode(m.get("prescription_code").toString());
            m.put("data",list);
            List<PrescriptionInfo> list = prescriptionInfoDao.findByPrescriptionCode(m.get("prescriptionCode").toString());
            m.put("prescriptionInfo",list);
            result2.add(m);
        }
        JSONArray array = new JSONArray(result2);
@ -110,7 +112,7 @@ public class PrescriptionDispensaryCodeService extends BaseService {
    //生成居民端取药码
    @Transactional
    public PrescriptionDispensaryCode savePatientQRCode(String token,String prescriptionCode){
    public PrescriptionDispensaryCode savePatientQRCode(String token,String prescriptionCode) throws Exception {
        //获取年月日8位数
        Calendar cal  = Calendar.getInstance();
        String year = String.valueOf(cal.get(Calendar.YEAR));
@ -129,8 +131,9 @@ public class PrescriptionDispensaryCodeService extends BaseService {
            }
        }
        // 生成二维码
        ObjectNode imgNode = makeQrcodeFromWeiXin(token,code);
        //Prescription类  取药类型:1 自取 2快递配送 3健管师配送
        InputStream ipt = QrcodeUtil.createQrcode(code,300,"png");
        ObjectNode imgNode = FastDFSUtil.upload(ipt,"png","QRCode_"+System.currentTimeMillis());
//        Prescription类  取药类型:1 自取 2快递配送 3健管师配送
        String fileUrl = fastdfs_file_url + imgNode.get("groupName").toString().replaceAll("\"","")
                + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"","");
@ -142,12 +145,11 @@ public class PrescriptionDispensaryCodeService extends BaseService {
        prescriptionDispensaryCode.setPrescriptionCode(prescriptionCode);
        prescriptionDispensaryCode.setType(1);
        return prescriptionDispensaryCodeDao.save(prescriptionDispensaryCode);
    }
    //生成配送员(健管师)取药码
    //生成配送员(健管师)(2、取药码  2、配送码)
    @Transactional
    public PrescriptionDispensaryCode saveDoctorQRCode(String code,String token,String prescriptionCode){
    public PrescriptionDispensaryCode saveQRCode(String code,String token,String prescriptionCode,Integer type) throws Exception {
        String jgsCode= "";
        synchronized (obj2){
            boolean bl = true;
@ -159,49 +161,23 @@ public class PrescriptionDispensaryCodeService extends BaseService {
        }
        //String jgsID= "";//配送员用户ID后4位
//        String jgsCode = code+"1234";//code+jgsID.substring(jgsID.length()-4);
        ObjectNode imgNode2 = makeQrcodeFromWeiXin(token,jgsCode);
        String fileUrl = fastdfs_file_url + imgNode2.get("groupName").toString().replaceAll("\"","")
                + "/" + imgNode2.get("remoteFileName").toString().replaceAll("\"","");
        // 生成二维码
        InputStream ipt = QrcodeUtil.createQrcode(code,300,"png");
        ObjectNode imgNode = FastDFSUtil.upload(ipt,"png","QRCode_"+System.currentTimeMillis());
//        Prescription类  取药类型:1 自取 2快递配送 3健管师配送
        String fileUrl = fastdfs_file_url + imgNode.get("groupName").toString().replaceAll("\"","")
                + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"","");
        //新增配送员处方取码记录
        PrescriptionDispensaryCode prescriptionDispensaryCode = new PrescriptionDispensaryCode();
        prescriptionDispensaryCode.setCode(jgsCode);
        prescriptionDispensaryCode.setCreateTime(new Date());
        prescriptionDispensaryCode.setImgUrl(fileUrl);
        prescriptionDispensaryCode.setPrescriptionCode(prescriptionCode);
        prescriptionDispensaryCode.setType(2);
        prescriptionDispensaryCode.setType(type);
        return prescriptionDispensaryCodeDao.save(prescriptionDispensaryCode);
    }
    //在微信端生成二维码,并上传FastFDS
    public ObjectNode makeQrcodeFromWeiXin(String token,String content){
        String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token;
        String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + content + "\"}}}";
        String result = httpUtil.sendPost(token_url, params);
        if (!StringUtils.isEmpty(result)) {
            JSONObject json = new JSONObject(result);
            // 下载二维码图片
            URL urlGet = null;
            try {
                urlGet = new URL("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="
                        + URLEncoder.encode(json.get("ticket").toString(), "UTF-8"));
                HttpURLConnection connection = (HttpURLConnection) urlGet.openConnection();
                connection.connect();
                ObjectNode imgNode = FastDFSUtil.upload(connection.getInputStream(),"png","QRCode_"+System.currentTimeMillis());
                return imgNode;
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    //随机生成匹配数字
    public  String randomString(String base, int length) {
@ -213,4 +189,13 @@ public class PrescriptionDispensaryCodeService extends BaseService {
        }
        return sb.toString();
    }
    public Map<String, Object> getQrcode(String dispensaryCode ,String patientCode ,Integer type){
        String sql = "select p2.code as dispensaryCode,p2.img_url,p3.hospital_name as hospitalName  from wlyy_prescription_dispensary_code p2 " +
                " left join  wlyy_prescription p1 on p2.prescription_code=p1.code LEFT JOIN wlyy_prescription_expressage p3 on p1.code=p3.prescription_code " +
                " where p2.prescription_code=? and p1.patient=? and p2.type=?  and p2.is_Use=0 ";
        Map<String, Object> result = jdbcTemplate.queryForMap(sql,dispensaryCode,patientCode,type);
        return result;
    }
}

+ 33 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/QrcodeUtil.java

@ -6,6 +6,7 @@ import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
@ -49,4 +50,36 @@ public class QrcodeUtil {
        MatrixToImageWriter.writeToFile(bitMatrix, imgType, outputFile);
        return outputFile;
    }
    /**
     * 创建二维码
     * @param content
     * @return
     */
    public static InputStream createQrcode(String content,int size,String imgType) {
        byte[] imagesStream=null;
        ByteArrayOutputStream os = null;
        try {
            HashMap<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put(EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
              BarcodeFormat.QR_CODE, size, size, hints);
             os = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(bitMatrix, imgType, os);
            return new ByteArrayInputStream(os.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

+ 76 - 38
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionCodeController.java

@ -13,6 +13,8 @@ import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
 * Created by Trick on 2017/7/25.
 */
@ -36,49 +38,49 @@ public class PrescriptionCodeController extends BaseController{
     *  type 1、居民端扫码列表 2、配送员(健管师)扫码列表
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    @ObserverRequired
    public String list(
            @RequestParam(value = "status",required = false) Integer status,
            @RequestParam(value = "timeType",required = false) Integer timeType,
            @RequestParam(value = "page",required = true) Integer page,
            @RequestParam(value = "pagesize",required = true) Integer pagesize) {
        //getUID()
        try{
            JSONArray result = prescriptionDispensaryCodeService.findByStatusAndTime(timeType,getUID(),status,page,pagesize,2);
            return result.toString();
        }catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
//    @RequestMapping(value = "/list",method = RequestMethod.GET)
//    @ResponseBody
//    @ObserverRequired
//    public String list(
//            @RequestParam(value = "status",required = false) Integer status,
//            @RequestParam(value = "timeType",required = false) Integer timeType,
//            @RequestParam(value = "page",required = true) Integer page,
//            @RequestParam(value = "pagesize",required = true) Integer pagesize) {
//        //getUID()
//        try{
//            JSONArray result = prescriptionDispensaryCodeService.findByStatusAndTime(timeType,getUID(),status,page,pagesize,2);
//            return result.toString();
//        }catch (Exception e) {
//            error(e);
//            return error(-1, "查询失败!");
//        }
//
//    }
    /**
     * 判断医生端是否有待取的药的接口
     * @return
     */
    @RequestMapping(value = "/whetherHaveCode", method = RequestMethod.GET)
    @ResponseBody
    @ObserverRequired
    public String whetherHaveCode() {
        try{
            JSONObject json = new JSONObject();
//        String patientCode = getUID();
            int count = prescriptionDispensaryCodeService.dispensaryCodeCount(getUID(),2);
            if (count > 0) {
                json.put("data", true);
                return json.toString();
            }
            json.put("data", false);
            return json.toString();
        }catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
//    @RequestMapping(value = "/whetherHaveCode", method = RequestMethod.GET)
//    @ResponseBody
//    @ObserverRequired
//    public String whetherHaveCode() {
//        try{
//            JSONObject json = new JSONObject();
////        String patientCode = getUID();
//            int count = prescriptionDispensaryCodeService.dispensaryCodeCount(getUID(),2);
//            if (count > 0) {
//                json.put("data", true);
//                return json.toString();
//            }
//            json.put("data", false);
//            return json.toString();
//        }catch (Exception e) {
//            error(e);
//            return error(-1, "查询失败!");
//        }
//
//    }
    /**
     * 确认配送 二维码方式
@ -102,4 +104,40 @@ public class PrescriptionCodeController extends BaseController{
        }
    }
    /**
     * 医生端获取取药码
     * @param dispensaryCode
     * @return
     */
    @RequestMapping(value = "/dispensaryCode/getDoctorDispensaryQrcode", method = RequestMethod.GET)
    @ObserverRequired
    public String getDoctorDispensaryQrcode(@RequestParam(value = "dispensaryCode",required = true) String dispensaryCode) {
        try{
            Map<String, Object> map = prescriptionDispensaryCodeService.getQrcode(dispensaryCode,getRepUID(),2);
            return write(200, "获取配送员取药码成功!", "data", map);
        }catch (Exception e) {
            error(e);
            return error(-1, "获取配送员取药码失败!");
        }
    }
    /**
     * 医生端获取配送码
     * @param dispensaryCode
     * @return
     */
    @RequestMapping(value = "/dispensaryCode/getDoctorDeliveryQrcode", method = RequestMethod.GET)
    @ObserverRequired
    public String getDoctorDeliveryQrcode(@RequestParam(value = "dispensaryCode",required = true) String dispensaryCode) {
        try{
            Map<String, Object> map = prescriptionDispensaryCodeService.getQrcode(dispensaryCode,getRepUID(),3);
            return write(200, "获取配送员配送码成功!", "data", map);
        }catch (Exception e) {
            error(e);
            return error(-1, "获取配送员配送码失败!");
        }
    }
}

+ 72 - 28
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/prescription/PatientPrescriptionController.java

@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
@ -58,13 +59,13 @@ public class PatientPrescriptionController extends WeixinBaseController {
        try {
            PrescriptionDispensaryCode prescriptionDispensaryCode = prescriptionDispensaryCodeService.savePatientQRCode(getAccessToken(),prescriptionCode);
            if (prescriptionDispensaryCode == null) {
                return error(-1, "生成居民二维码失败!");
                return error(-1, "生成居民取药码失败!");
            } else {
                return write(200, "生成居民二维码成功!", "code", prescriptionDispensaryCode.getCode());
                return write(200, "生成居民取药码成功!", "code", prescriptionDispensaryCode.getCode());
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "生成居民二维码失败!");
            return error(-1, "生成居民取药码失败!");
        }
    }
@ -80,19 +81,61 @@ public class PatientPrescriptionController extends WeixinBaseController {
            @RequestParam(value = "code",required = true) String code){
        try {
            PrescriptionDispensaryCode prescriptionDispensaryCode = prescriptionDispensaryCodeService.saveDoctorQRCode(code,getAccessToken(),prescriptionCode);
            PrescriptionDispensaryCode prescriptionDispensaryCode = prescriptionDispensaryCodeService.saveQRCode(code,getAccessToken(),prescriptionCode,2);
            if (prescriptionDispensaryCode == null) {
                return error(-1, "生成配送员二维码失败!");
                return error(-1, "生成配送员取药码失败!");
            } else {
                return write(200, "生成配送员二维码成功!", "code", prescriptionDispensaryCode.getCode());
                return write(200, "生成配送员取药码成功!", "code", prescriptionDispensaryCode.getCode());
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "生成配送员二维码失败!");
            return error(-1, "生成配送员取药码失败!");
        }
    }
    /**
     *生成配送员配送码
     * @return
     */
    @RequestMapping(value = "/dispensaryCode/saveDoctorQRDeliveryCode",method = RequestMethod.GET)
    @ResponseBody
    @ObserverRequired
    public String saveDoctorQRDeliveryCode(
            @RequestParam(value = "prescriptionCode",required = true) String prescriptionCode,
            @RequestParam(value = "code",required = true) String code){
        try {
            PrescriptionDispensaryCode prescriptionDispensaryCode = prescriptionDispensaryCodeService.saveQRCode(code,getAccessToken(),prescriptionCode,3);
            if (prescriptionDispensaryCode == null) {
                return error(-1, "生成配送员配送码失败!");
            } else {
                return write(200, "生成配送员配送码成功!", "code", prescriptionDispensaryCode.getCode());
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "生成配送员配送码失败!");
        }
    }
    /**
     * 居民端获取取药码
     * @param dispensaryCode
     * @return
     */
    @RequestMapping(value = "/dispensaryCode/getPatientQrcode", method = RequestMethod.GET)
    public String getPatientQrcode(@RequestParam(value = "dispensaryCode",required = true) String dispensaryCode) {
        try{
            Map<String, Object> map = prescriptionDispensaryCodeService.getQrcode(dispensaryCode,getRepUID(),1);
            return write(200, "获取居民取药码成功!", "data", map);
        }catch (Exception e) {
            error(e);
            return error(-1, "获取取药码失败!");
        }
    }
    /**
     * 显示居民所有的取药码列表
     * @param status
@ -112,8 +155,9 @@ public class PatientPrescriptionController extends WeixinBaseController {
            @RequestParam(value = "pagesize",required = true) Integer pagesize) {
        //getUID()"a663d0cf7f8c4d38a8327cedc921e65f"
        try {
            JSONArray result = prescriptionDispensaryCodeService.findByStatusAndTime(timeType,getUID(),status,page,pagesize,1);
            return result.toString();
            JSONArray result = prescriptionDispensaryCodeService.findByStatusAndTime(timeType,getRepUID(),status,page,pagesize,1);
            return write(200, "获取信息成功!", "result", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
@ -124,25 +168,25 @@ public class PatientPrescriptionController extends WeixinBaseController {
     * 判断该居民是否有待取的药的接口
     * @return
     */
    @RequestMapping(value = "/dispensaryCode/whetherHaveCode", method = RequestMethod.GET)
    @ResponseBody
    //@ObserverRequired
    public String whetherHaveCode() {
        try {
            JSONObject json = new JSONObject();
//        String patientCode = getUID();
            int count = prescriptionDispensaryCodeService.dispensaryCodeCount(getUID(),1);
            if (count > 0) {
                json.put("data", true);
                return json.toString();
            }
            json.put("data", false);
            return json.toString();
        }catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
//    @RequestMapping(value = "/dispensaryCode/whetherHaveCode", method = RequestMethod.GET)
//    @ResponseBody
//    //@ObserverRequired
//    public String whetherHaveCode() {
//        try {
//            JSONObject json = new JSONObject();
////        String patientCode = getUID();
//            int count = prescriptionDispensaryCodeService.dispensaryCodeCount(getUID(),1);
//            if (count > 0) {
//                json.put("data", true);
//                return json.toString();
//            }
//            json.put("data", false);
//            return json.toString();
//        }catch (Exception e) {
//            error(e);
//            return error(-1, "查询失败!");
//        }
//    }
    /**
     * 订单跟踪 包含处方药品信息 订单记录  支付记录