wangjun пре 4 година
родитељ
комит
2bbb551021
16 измењених фајлова са 1282 додато и 49 уклоњено
  1. 18 0
      business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreDao.java
  2. 81 0
      business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/service/BaseDrugStoreService.java
  3. 34 5
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
  4. 65 13
      business/base-service/src/main/java/com/yihu/jw/hospital/survey/service/SurveyService.java
  5. 1 0
      business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java
  6. 3 0
      business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientBusinessDao.java
  7. 32 0
      business/base-service/src/main/java/com/yihu/jw/utils/CountDistance.java
  8. 751 0
      business/base-service/src/main/java/com/yihu/jw/utils/ImUtil.java
  9. 1 1
      common/common-entity/src/main/java/com/yihu/jw/entity/IntegerIdentityEntity.java
  10. 151 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/area/BaseDrugStoreDO.java
  11. 9 0
      common/common-entity/src/main/java/com/yihu/jw/entity/hospital/survey/WlyySurveyTemplateDO.java
  12. 9 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java
  13. 30 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/hospital/survey/WlyySurveyTemplateVO.java
  14. 68 0
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/drugstore/BaseDrugStoreEndpoint.java
  15. 9 4
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/survey/SurveyEndpoint.java
  16. 20 26
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/service/consult/BasePatientBusinessService.java

+ 18 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/dao/BaseDrugStoreDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.hospital.drugstore.dao;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface BaseDrugStoreDao extends PagingAndSortingRepository<BaseDrugStoreDO, String>, JpaSpecificationExecutor<BaseDrugStoreDO> {
    @Query(value = " from  BaseDrugStoreDO  where (drugStoreName like %?1% or ?1 is null ) or ( hospitalName like %?1% or ?1 is null)")
    List<BaseDrugStoreDO> findDrugByName(String storeName);
    @Query(value = " from  BaseDrugStoreDO  where drugStoreCode =?1 and hospitalCode = ?2 ")
    BaseDrugStoreDO findDrugByNameAndCode(String drugStoreCode,String hospitalCode);
}

+ 81 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/drugstore/service/BaseDrugStoreService.java

@ -0,0 +1,81 @@
package com.yihu.jw.hospital.drugstore.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.j2objc.annotations.AutoreleasePool;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
import com.yihu.jw.hospital.drugstore.dao.BaseDrugStoreDao;
import com.yihu.jw.hospital.message.dao.BaseBannerDoctorDao;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.utils.CountDistance;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.provider.HibernateUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class BaseDrugStoreService extends BaseJpaService<BaseDrugStoreDO, BaseDrugStoreDao> {
    @Autowired
    private BaseDrugStoreDao baseDrugStoreDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private HibenateUtils hibenateUtils;
   //根据经纬度计算距离通过代码
   public List<BaseDrugStoreDO> countDistanceListIncode(String latitude,String longitude,String drugStoreName,String hospitalName) throws ParseException {
       List<BaseDrugStoreDO> list = new ArrayList<>();
       if (StringUtils.isNotEmpty(drugStoreName)||StringUtils.isNotEmpty(hospitalName)){
           list = baseDrugStoreDao.findDrugByName(drugStoreName);
       }else {
           String filters= null;
           list= this.search(filters);
       }
       List<BaseDrugStoreDO> resultlist = new ArrayList<>();
       CountDistance countDistance = new CountDistance();
       latitude=StringUtils.isEmpty(latitude)?"0":latitude;
       longitude=StringUtils.isEmpty(longitude)?"0":longitude;
        for (BaseDrugStoreDO baseDrugStoreDO:list){
            double storeLatitude = Double.parseDouble(baseDrugStoreDO.getLatitude());
            double storeLongitude = Double.parseDouble(baseDrugStoreDO.getLongitude());
            double distance = countDistance.getDistance(Double.parseDouble(latitude),Double.parseDouble(longitude),storeLatitude,storeLongitude);
            baseDrugStoreDO.setDistance(distance);
        }
        list.stream().sorted((x,y)->Double.compare(x.getDistance(),y.getDistance()));
        return list;
   }
       //根据经纬度计算距离sql
    public List<Map<String,Object>> countDistanceList(String latitude,String longitude,String drugStoreName,Integer page,Integer pageSize){
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT\n" +
                "    DISTINCT t.id as \"id\" ,(\n" +
                "    round(6371392.89 * acos (\n" +
                "    cos ( radians("+latitude+") )\n" +
                "    * cos( radians( t.latitude  ) )\n" +
                "    * cos( radians( t.longitude ) - radians("+longitude+") )\n" +
                "    + sin ( radians("+latitude+") )\n" +
                "    * sin( radians( t.latitude ) )\n" +
                "    ),2\n" +
                "    ) )AS distance,\n" +
                "t.drug_store_name as \"drugStoreName\""+
                "    FROM base_drug_store t where 1=1");
        if (StringUtils.isNotEmpty(drugStoreName)){
            sql.append(" and t.drug_store_name like '%"+drugStoreName+"%'");
        }
        sql.append(" ORDER BY distance asc");
        System.out.println(sql.toString());
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql.toString(),page,pageSize);
        return list;
    }
}

+ 34 - 5
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -8,6 +8,7 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.doctor.dao.BaseDoctorPatientDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.base.dict.DictDeptDescDO;
import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -40,6 +41,7 @@ import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.doctor.dao.DoctorWorkTimeDao;
import com.yihu.jw.hospital.doctor.dao.PatientRegisterTimeDao;
import com.yihu.jw.hospital.doctor.dao.WlyyDoctorOnlineTimeDao;
import com.yihu.jw.hospital.drugstore.dao.BaseDrugStoreDao;
import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.mapping.service.DoctorMappingService;
@ -244,6 +246,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    private BaseSensitiveFilterWordsService baseSensitiveFilterWordsService;
    @Autowired
    private BaseBannerDoctorDao baseBannerDoctorDao;
    @Autowired
    private BaseDrugStoreDao baseDrugStoreDao;
@ -822,10 +826,33 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //2.物流信息
        WlyyPrescriptionExpressageDO expressageDO = objectMapper.readValue(expressageJson, WlyyPrescriptionExpressageDO.class);
        expressageDO.setDel(1);
        expressageDO.setCreateTime(new Date());
        expressageDO.setOutpatientId(outpatient.getId());
        prescriptionExpressageDao.save(expressageDO);
        if (0==expressageDO.getOneselfPickupFlg()){
            System.out.println("进入物流信息");
            expressageDO.setDel(1);
            expressageDO.setCreateTime(new Date());
            expressageDO.setOutpatientId(outpatient.getId());
            prescriptionExpressageDao.save(expressageDO);
        }else {
            System.out.println("写入自取信息");
            String drugStoreCode = expressageDO.getHospitalCode();
            BaseDrugStoreDO baseDrugStoreDO = baseDrugStoreDao.findOne(drugStoreCode);
            if (null!=baseDrugStoreDO){
                expressageDO.setCityCode(baseDrugStoreDO.getCityCode());
                expressageDO.setCityName(baseDrugStoreDO.getCityName());
                expressageDO.setProvinceCode(baseDrugStoreDO.getProvinceCode());
                expressageDO.setProvinceName(baseDrugStoreDO.getProvinceName());
                expressageDO.setTownCode(baseDrugStoreDO.getTownCode());
                expressageDO.setTownName(baseDrugStoreDO.getTownName());
                expressageDO.setHospitalCode(baseDrugStoreDO.getDrugStoreCode());
                expressageDO.setHospitalName(baseDrugStoreDO.getHospitalName());
                expressageDO.setHospitalAddress(baseDrugStoreDO.getAddress());
            }
            expressageDO.setDel(1);
            expressageDO.setCreateTime(new Date());
            expressageDO.setOutpatientId(outpatient.getId());
            prescriptionExpressageDao.save(expressageDO);
        }
        //3.创建候诊室
        createRoom(outpatient, chargeType);
@ -841,7 +868,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @return
     */
    public Boolean createRoom(WlyyOutpatientDO outpatientDO, String chargeType) {
        System.out.println("进入创建候诊室");
        WlyyHospitalWaitingRoomDO waitingRoom = new WlyyHospitalWaitingRoomDO();
        waitingRoom.setDept(outpatientDO.getDept());
@ -851,6 +878,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //是否是有协同门诊医生
        if (StringUtils.isNotBlank(outpatientDO.getGeneralDoctor())) {
            System.out.println("是否是有协同门诊医生");
            waitingRoom.setGeneralDoctor(outpatientDO.getGeneralDoctor());
            waitingRoom.setGeneralDoctorName(outpatientDO.getGeneralDoctorName());
        }
@ -5771,6 +5799,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @return
     */
    public SystemMessageDO sendOutPatientMes(WlyyOutpatientDO outpatient,boolean payFlag) {
        System.out.println("发送新增门诊信息");
        SystemMessageDO systemMessageDO = new SystemMessageDO();
        String msg = "";
        JSONObject data = new JSONObject();

+ 65 - 13
business/base-service/src/main/java/com/yihu/jw/hospital/survey/service/SurveyService.java

@ -1,10 +1,17 @@
package com.yihu.jw.hospital.survey.service;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.j2objc.annotations.AutoreleasePool;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientBusinessDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.hospital.survey.*;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.survey.dao.*;
import com.yihu.jw.patient.dao.BasePatientBusinessDao;
import com.yihu.jw.restmodel.hospital.consult.WlyyHospitalSysDictVO;
import com.yihu.jw.restmodel.hospital.survey.*;
import com.yihu.jw.restmodel.web.MixEnvelop;
@ -13,11 +20,14 @@ import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.PercentageUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.EntityUtils;
import com.yihu.jw.utils.ImUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -64,6 +74,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    private SurveyUserAnswerDao surveyUserAnswerDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private ImUtil imUtil;
    @Autowired
    private BasePatientBusinessDao basePatientBusinessDao;
    @Value("${wechat.flag}")
    private boolean flag;
    /**
     * 查询字典
     * 1.surveyLabel;2.surveyScreenLabel
@ -283,6 +301,7 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                " t.template_comment AS templateComment, " +
                " t.organization, " +
                " t.creater, " +
                " t.creater_code, " +
                " t.create_time AS createTime, " +
                " t.del, " +
                " t.update_time AS updateTime" +
@ -363,13 +382,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        String sqlUsed = "select t.used as \"used\" from wlyy_knowledge_article_user t where t.relation_code = '"+templateCode +"'";
        if(StringUtils.isNotEmpty(userCode)){
            sqlUsed += " and t.user_code = '"+userCode+"'";
            System.out.println(sqlUsed);
            List<Map<String,Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
            if (listUsed.size()>0){
                String used = null!=listUsed.get(0).get("used")?listUsed.get(0).get("used").toString():"0";
                templateVO.setUsed(Integer.valueOf(used));
            }
        }
        System.out.println(sqlUsed);
        List<Map<String,Object>> listUsed = hibenateUtils.createSQLQuery(sqlUsed);
        if (listUsed.size()>0){
            String used = null!=listUsed.get(0).get("used")?listUsed.get(0).get("used").toString():"0";
            templateVO.setUsed(Integer.valueOf(used));
        }
        List<WlyySurveyTemplateQuestionDO> tqDOs = surveyTemplateQuestionDao.findByTemplateCodeAndDelOrderBySortAsc(tempId,"1");
        if(tqDOs!=null&&tqDOs.size()>0){
            //设置问题
@ -411,6 +431,11 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    public Boolean saveSurveyTemplate(String tempJson,String tempQJson,String tempOpJson,String labelJson,String labelInspJson)throws Exception{
        WlyySurveyTemplateDO temp = objectMapper.readValue(tempJson,WlyySurveyTemplateDO.class);
        String doctor = temp.getCreaterCode();
        BaseDoctorDO baseDoctorDO  = baseDoctorDao.findById(doctor);
        if (null!=baseDoctorDO){
            temp.setCreater(baseDoctorDO.getName());
        }
        temp = surveyTemplateDao.save(temp);
        //删除原有问题
@ -615,6 +640,14 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
                answerDO.setSurverUserId(surveyUserDO.getId());
            }
            surveyUserAnswerDao.save(answerDOs);
            BasePatientBusinessDO basePatientBusinessDO = basePatientBusinessDao.findByDoctorPatientRelationCode(surveyUserDO.getPatient(),surveyUserDO.getSurveyTempCode(),surveyUserDO.getDoctor());
            JSONObject object = new JSONObject();
            if (null!=basePatientBusinessDO){
                object.put("title",surveyUserDO.getSurveyTempTitle());
                object.put("content",answerDOs);
                object.put("id",surveyUserDO.getSurveyTempCode());
            }
            imUtil.sendImMsg(basePatientBusinessDO.getDoctor(), basePatientBusinessDO.getDoctorName(), basePatientBusinessDO.getSessionId(), "36", object.toJSONString(),"1");
        }
        return true;
    }
@ -644,7 +677,11 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        WlyySurveyTemplateVO templateVO = convertToModel(templateDO,WlyySurveyTemplateVO.class);
        templateVO.setLabels(findSurveyTemplateLabel(tempId));
        templateVO.setInsplabels(findSurveyInspTemplateLabel(tempId));
        BaseDoctorDO doctor = baseDoctorDao.findById(templateDO.getCreaterCode());
        if (null!=doctor){
            templateVO.setVisitDept(doctor.getVisitDept());
            templateVO.setVisitDeptName(doctor.getVisitDeptName());
        }
        //查询所有答题过的用户,计算答题总数
        List<WlyySurveyUserDO> surveyUsers = surveyUserDao.findBySurveyTempCodeAndStatus(templateVO.getId(),1);
        Integer total =0;
@ -765,12 +802,12 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
    /**
     * 查询
     * @param title
     * @param page
     * @param size
     * @param
     * @param
     * @param
     * @return
     */
    public MixEnvelop findAnswerList(String tempId,String patient,String title,Integer page,Integer size){
    public MixEnvelop findAnswerList(String tempId,String patient,String patientName,String title,Integer page,Integer size){
        String totalSql ="SELECT " +
                " COUNT(1) AS total" +
@ -786,6 +823,9 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        if(StringUtils.isNotBlank(tempId)){
            totalSql += " AND t.survey_temp_code = '"+tempId+"' ";
        }
        if(StringUtils.isNotBlank(patientName)){
            totalSql += " AND t.patient_name like  '%"+patientName+"%' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
@ -818,11 +858,23 @@ public class SurveyService extends BaseJpaService<WlyySurveyQuestionDO, SurveyQu
        if(StringUtils.isNotBlank(patient)){
            sql += " AND t.patient = '"+patient+"' ";
        }
        if(StringUtils.isNotBlank(patientName)){
            sql += " AND t.patient_name like  '%"+patientName+"%' ";
        }
        if(StringUtils.isNotBlank(tempId)){
            sql += " AND t.survey_temp_code = '"+tempId+"' ";
        }
        sql += " ORDER BY t.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
        sql += " ORDER BY t.create_time DESC " ;
        if (flag){
            sql+="LIMIT"+ (page - 1) * size + "," + size + " ";
        }else {
            sql ="SELECT * FROM\n" +
                    "( SELECT A.*, ROWNUM RN FROM\n" +
                    "    ("+sql+") A \n" +
                    "    WHERE ROWNUM <= "+page*size+" ) \n" +
                    "       WHERE RN >= "+((page-1)*size+1);
        }
        System.out.println(sql);
        List<WlyySurveyUserVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyySurveyUserVO.class));
        if(list!=null&&list.size()>0){

+ 1 - 0
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -774,6 +774,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
                 businessOrderDO = new BusinessOrderDO();
             }
        }
        System.out.println(relationCode+"----"+relationName+"----"+orderCategory+"----"+remark+"----"+patient+"----"+patientName+"----"+doctor+"----"+payPrice+"----");
        businessOrderDO.setOrderNo("HLWYY"+System.currentTimeMillis()+(int)(Math.random()*900)+100);
        businessOrderDO.setCreateTime(new Date());
        businessOrderDO.setUpdateTime(new Date());

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientBusinessDao.java

@ -16,4 +16,7 @@ public interface BasePatientBusinessDao extends PagingAndSortingRepository<BaseP
    @Query("select a from BasePatientBusinessDO a where a.del=1 and a.patient=?1 and a.relationCode=?2")
    BasePatientBusinessDO findByPatientAndRelationCodeAndDel(String patient,String relationCode);
    @Query("from BasePatientBusinessDO a where a.del=1 and a.patient=?1 and a.relationCode=?2 and a.doctor = ?3")
    BasePatientBusinessDO findByDoctorPatientRelationCode(String patient,String relationCode,String doctor);
}

+ 32 - 0
business/base-service/src/main/java/com/yihu/jw/utils/CountDistance.java

@ -0,0 +1,32 @@
package com.yihu.jw.utils;
public class CountDistance {
    private static double EARTH_RADIUS = 6378.137;// 6378.137赤道半径6378137
    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }
    /**
     * 通过经纬度计算两点之间的距离(单位:米)
     * @param latone
     * @param lngone
     * @param lattwo
     * @param lngtwo
     * @return
     */
    public  double getDistance(double latone, double lngone, double lattwo, double lngtwo) {
        double radlatone = rad(latone);
        double radlattwo = rad(lattwo);
        double a = radlatone - radlattwo;
        double b = rad(lngone) - rad(lngtwo);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radlatone) * Math.cos(radlattwo)
                * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000d) / 10000d;
        s = s*1000;
        return s;
    }
}

+ 751 - 0
business/base-service/src/main/java/com/yihu/jw/utils/ImUtil.java

@ -0,0 +1,751 @@
package com.yihu.jw.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
 * IM工具类
 * @author huangwenjie
 */
@Component
public class ImUtil {
	
	@Autowired
	private HttpClientUtil HttpClientUtil;
	
	@Value("${im.im_list_get}")
	private String im_host;
	
	
	public enum ContentType {
		plainText("信息", "1"),
		image("图片信息", "2"),
		audio("创建处方", "3"),
		article("文章信息", "4"),
		goTo("跳转信息,求组其他医生或者邀请其他医生发送的推送消息", "5"),
		topicBegin("议题开始", "6"),
		topicEnd("议题结束", "7"),
		personalCard("个人名片", "18"),
		messageForward("消息转发", "19"),
		topicInto("进入议题", "14"),
		video("视频", "12"),
		system("系统消息", "13"),
		prescriptionCheck("续方审核消息消息", "15"),
		prescriptionBloodStatus("续方咨询血糖血压咨询消息", "16"),
		prescriptionFollowupContent("续方咨询随访问卷消息", "17"),
		Rehabilitation("康复计划发送","20"),
		Reservation("转诊预约发送","21"),
		Know("已知悉","22");
		
		private String name;
		private String value;
		ContentType(String name, String value) {
			this.name = name;
			this.value = value;
		}
		
		public String getName() {
			return name;
		}
		
		public void setName(String name) {
			this.name = name;
		}
		
		public String getValue() {
			return value;
		}
		
		public void setValue(String value) {
			this.value = value;
		}
	}
	
	/**
	 * 发送消息
	 * @param senderId 发送者的code
	 * @param receiverId 接受者code
	 * @param contentType 消息类型 1二维码内容
	 * @param content 消息内容
	 * @return
	 */
	public String sendMessage(String senderId,String receiverId,String contentType,String content){
		String imAddr = im_host + "api/v2/message/send";
		JSONObject params = new JSONObject();
		params.put("sender_id", senderId);
		params.put("sender_name", receiverId);
		params.put("content_type", contentType);
		params.put("content", content);
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	
	/**
	 * 获取医生统计数据
	 * status reply 为空值是是该医生总咨询量
	 *
	 * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param adminTeamCode
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getConsultData(String user, Integer adminTeamCode, Integer status, Integer reply) {
		String imAddr = im_host + "api/v2/sessions/topics/count/reply";
		imAddr = imAddr + "?user=" + user;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (adminTeamCode != null) {
			imAddr += ("&adminTeamCode=" + adminTeamCode);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	
	public void updateTopics(String topicId, String jsonValue) {
		String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
		JSONObject params = new JSONObject();
		params.put("topic_id", topicId);
		params.put("data", jsonValue);
		HttpClientUtil.putBody(imAddr, params);
	}
	
	/**
	 * 当前医生下当前团队列表接口
	 * 获取团队内医生的健康咨询状况
	 * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 *
	 * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param adminTeamCode 行政团队code
	 * @param page
	 * @param pagesize
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getTeamConsultByStatus(String user, Integer adminTeamCode, Integer status, Integer reply, int page, int pagesize) {
		String imAddr = im_host + "api/v2/sessions/healthTeamTopics";
		imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
		if (adminTeamCode != null) {
			imAddr += ("&adminTeamCode=" + adminTeamCode);
		}
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	
	/**
	 * 列表接口
	 * 获取团队内医生的健康咨询状况
	 * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 *
	 * @param user     团队就把团队的医生合并起来用,隔开(医生编码)
	 * @param page
	 * @param pagesize
	 * @param status
	 * @param reply
	 * @return
	 */
	public String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
		String imAddr = im_host + "api/v2/sessions/healthTopics";
		imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	
	/**
	 * 咨询列表
	 * @param user
	 * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 * @param reply
	 * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
	 * @param page
	 * @param pagesize
	 * @return
	 */
	public String getConsultByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime,int page,int pagesize){
		String imAddr = im_host + "api/v2/sessions/topicListByType";
		imAddr = imAddr + "?user="+user + "&page=" + page + "&pagesize=" + pagesize;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		if (type != null) {
			imAddr += ("&type=" + type);
		}
		if (patientName != null) {
			imAddr += ("&patientName=" + patientName);
		}
		if (startTime != null) {
			imAddr += ("&startTime=" + startTime);
		}
		if (endTime != null) {
			imAddr += ("&endTime=" + endTime);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	
	/**
	 * 咨询列表总数
	 * @param user
	 * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
	 * @param reply
	 * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
	 * @return
	 */
	public String getConsultCountByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime){
		String imAddr = im_host + "api/v2/sessions/topicListCountByType";
		imAddr = imAddr + "?user="+user;
		if (status != null) {
			imAddr += ("&status=" + status);
		}
		if (reply != null) {
			imAddr += ("&reply=" + reply);
		}
		if (type != null) {
			imAddr += ("&type=" + type);
		}
		if (patientName != null) {
			imAddr += ("&patientName=" + patientName);
		}
		if (startTime != null) {
			imAddr += ("&startTime=" + startTime);
		}
		if (endTime != null) {
			imAddr += ("&endTime=" + endTime);
		}
		String response = HttpClientUtil.get(imAddr, "UTF-8");
		return response;
	}
	
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages";
		System.out.println("im地址"+imAddr);
		JSONObject params = new JSONObject();
		params.put("sender_id", from);
		params.put("sender_name", fromName);
		params.put("content_type", contentType);
		params.put("content", content);
		params.put("session_id", sessionId);
		params.put("business_type", businessType);
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	
	/**
	 * 更新会话状态
	 *
	 * @param sessionId 会话ID
	 * @param status    状态
	 */
	public String updateSessionStatus(String sessionId, String status) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
		JSONObject params = new JSONObject();
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	
	/**
	 * 更新会话状态
	 *
	 * @param sessionId 会话ID
	 * @param status    状态
	 */
	public String updateTopicEvaluate(String sessionId, String status) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
		JSONObject params = new JSONObject();
		String response = HttpClientUtil.postBody(imAddr, params);
		return response;
	}
	
	
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent,String patient_name,int patient_sex,int patient_age) {
		String url = im_host + "api/v2/sessions/topic/" + topicId + "/messages";
		JSONObject params = new JSONObject();
		params.put("sender_id", from);
		params.put("sender_name", fromName);
		params.put("patient_name", patient_name);
		params.put("patient_sex", patient_sex);
		params.put("patient_age", patient_age);
		params.put("content_type", contentType);
		params.put("content", content);
		params.put("topic_id", topicId);
		params.put("agent", agent);
		String response = HttpClientUtil.postBody(url, params);
		return response;
	}
	
	/**
	 * 发送进入im消息
	 * IM: ParticipantUpdate:'/:session_id/participant/update'
	 *
	 * @param from
	 * @param sessionId
	 * @param topicId
	 * @return
	 */
	public String sendIntoTopicIM(String from, String sessionId, String topicId, String content, String intoUser, String intoUserName) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/into";
		JSONObject params = new JSONObject();
		params.put("sender_id", from);
		params.put("topic_id", topicId);
		params.put("into_user", intoUser);
		params.put("into_user_name", intoUserName);
		params.put("content", content);
		String response = HttpClientUtil.postBody(url, params);
		return response;
	}
	
	
	/**
	 * 更新会话成员(新增或删除)
	 * @param sessionId 会话id
	 * @param user 新增的成员id
	 * @param oldUserId  删除的成员id
	 */
	public String updateParticipant(String sessionId, String user,String oldUserId) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId );
		params.put("user_id", user );
		if(!StringUtils.isEmpty(oldUserId)){
			params.put("old_user_id", oldUserId);
		}
		return HttpClientUtil.postBody(imAddr, params);
	}
	
	/**
	 * 更新消息内容
	 * @param sessionId 会话id
	 * @param sessionType 会话类型
	 * @param msgId  消息id
	 * @param content  消息内容
	 */
	public String updateMessage(String sessionId, String sessionType,String msgId,String content) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/messages/"+ msgId +"/update";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId );
		params.put("session_type", sessionType );
		params.put("message_id", msgId );
		params.put("content", content );
		return HttpClientUtil.postBody(imAddr, params);
	}
	
	/**
	 * 结束议题
	 *
	 * @param topicId     议题ID
	 * @param endUser     结束人
	 * @param endUserName 结束人名字
	 * @param sessionId   会话ID
	 */
	public JSONObject endTopics(String sessionId, String endUser, String endUserName, String topicId) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/ended";
		JSONObject params = new JSONObject();
		params.put("session_id", sessionId);
		params.put("end_user", endUser);
		params.put("end_user_name", endUserName);
		params.put("topic_id", topicId);
		String ret = HttpClientUtil.postBody(imAddr, params);
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	
	
	/**
	 * 议题邀请人员
	 *
	 * @param user      结束人名字
	 * @param sessionId 会话ID
	 */
	public void updateTopicUser(String sessionId, String user) {
		String imAddr = im_host + "api/v2/sessions/" + sessionId + "/participants/" + user;
		JSONObject params = new JSONObject();
		params.put("user", user + ":" + 0);
		HttpClientUtil.putBody(imAddr, params);
	}
	
	/**
	 * 创建议题
	 *
	 * @param topicId      议题ID
	 * @param topicName    议题名称
	 * @param participants 成员
	 */
	public JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
		String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
		JSONObject params = new JSONObject();
		params.put("topic_id", topicId);
		params.put("topic_name", topicName);
		params.put("participants", participants.toString());
		params.put("messages", messages.toString());
		params.put("session_id", sessionId);
		params.put("session_type", sessionType);
		String ret = HttpClientUtil.postBody(imAddr, params);
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	
	/**
	 * 判断会话是否存在
	 */
	public Boolean sessionIsExist(String sessionId) {
		Boolean re = false;
		String url = im_host + "api/v2/sessions/isExist?session_id="+sessionId;
		JSONObject params = new JSONObject();
		String ret = HttpClientUtil.get(url, "UTF-8");
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
			if(obj.getInteger("status") ==200&&sessionId.equals(obj.getString("sessionId"))){
				String sessionStatus = obj.getString("sessionId");
				if (StringUtils.isNoneBlank(sessionStatus)){
					String sessionStatusUrl = im_host + "api/v2/sessions/"+sessionId+"/status?status=0&sessionId="+sessionId;
					JSONObject object = new JSONObject();
					String rs = HttpClientUtil.postBody(sessionStatusUrl, object);
				}
				re = true;
			}
		} catch (Exception e) {
			return null;
		}
		return re;
	}
	
	/**
	 * 创建会话(system)
	 */
	public JSONObject createSession(JSONObject participants, String sessionType, String sessionName, String sessionId) {
		String imAddr = im_host + "api/v2/sessions";
		JSONObject params = new JSONObject();
		params.put("participants", participants.toString());
		params.put("session_name", sessionName);
		params.put("session_type", sessionType);
		params.put("session_id", sessionId);
		String ret = HttpClientUtil.postBody(imAddr, params);
		JSONObject obj = null;
		try {
			obj = JSON.parseObject(ret);
		} catch (Exception e) {
			return null;
		}
		return obj;
	}
	
	/**
	 * 获取会话实例的消息对象
	 *
	 * @param senderId
	 * @param senderName
	 * @param title
	 * @param description
	 * @param images
	 * @param agent
	 * @return
	 */
	public JSONObject getCreateTopicMessage(String senderId, String senderName, String title, String description, String images, String agent) {
		JSONObject messages = new JSONObject();
		messages.put("description", description);
		messages.put("title", title);
		messages.put("img", images);
		messages.put("sender_id", senderId);
		messages.put("sender_name", senderName);
		messages.put("agent", agent);
		return messages;
	}
	
	public JSONObject getTopicMessage(String topicId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
		String url = im_host
				+ "api/v2/sessions/topic/" + topicId + "/messages?topic_id=" + topicId + "&end=" + startMsgId
				+ "&start=" + (endMsgId == null ? "" : endMsgId) + "&page=" + page + "&pagesize=" + pagesize + "&user=" + uid;
		try {
			String ret = HttpClientUtil.get(url, "UTF-8");
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException(obj.getString("message"));
			} else {
				return obj.getJSONObject("data");
			}
		} catch (Exception e) {
			return null;
		}
		
	}
	
	public JSONArray getSessionMessage(String sessionId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/messages?session_id=" + sessionId + "&user=" + uid + "&start_message_id=" + startMsgId + "&end_message_id=" + endMsgId + "&page=" + page + "&pagesize=" + pagesize;
		try {
			String ret = HttpClientUtil.get(url, "UTF-8");
			JSONArray obj = JSON.parseArray(ret);
			return obj;
		} catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 删除对应的成员信息在MUC模式中
	 *
	 * @param userId
	 * @param oldUserId
	 * @param sessionId
	 * @return
	 */
	public JSONObject deleteMucUser(String userId, String oldUserId, String sessionId) throws Exception {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participant/update";
		try {
			JSONObject params = new JSONObject();
			params.put("user_id", userId);
			params.put("old_user_id", oldUserId);
			params.put("session_id", sessionId);
			String ret = HttpClientUtil.postBody(url, params);
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException("人员更换失败!");
			} else {
				return obj;
			}
		} catch (Exception e) {
			throw new RuntimeException("人员更换失败!");
		}
	}
	/**
	 * 删除会话人员
	 * @param sessionId
	 * @param participants
	 * @return
	 */
	public JSONObject deleteParticipants(String sessionId,String participants){
		String url  = im_host+"api/v2/sessions/"+sessionId+"/participants/"+participants;
		String rs = HttpClientUtil.doDelete(url,null,null);
		JSONObject obj = JSONObject.parseObject(rs);
		if (obj.getInteger("status")==-1){
			throw new RuntimeException("删除会话人员失败!");
		}else {
			return obj;
		}
	}
	
	
	/**
	 * 获取议题
	 *
	 * @param topicId
	 * @return
	 */
	public JSONObject getTopic(String topicId) throws Exception {
		String url = im_host + "api/v2/sessions/topics/" + topicId + "?topic_id=" + topicId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			JSONObject obj = JSON.parseObject(ret);
			if (obj.getInteger("status") == -1) {
				throw new RuntimeException("获取议题失败!");
			} else {
				return obj;
			}
		} catch (Exception e) {
			throw new RuntimeException("获取议题失败!");
		}
	}
	
	/**
	 * 获取会话成员
	 *
	 * @param sessionId
	 * @return
	 * @throws Exception
	 */
	public JSONArray getParticipants(String sessionId) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			return JSON.parseArray(ret);
		} catch (Exception e) {
			throw new RuntimeException("获取会话成员!sessionId =" + sessionId);
		}
	}
	
	/**
	 * 获取会话成员
	 *
	 * @param sessionId
	 * @return
	 * @throws Exception
	 */
	public JSONArray getSessions(String sessionId) {
		String url = im_host + "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
		try {
			String ret = HttpClientUtil.get(url, "utf-8");
			return JSON.parseArray(ret);
		} catch (Exception e) {
			throw new RuntimeException("获取议题失败!");
		}
	}
	
	public JSONObject cleanMessageToRedis(String sessionId){
		String url = im_host + "api/v2/message/dataMessage?sessionId="+sessionId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	
	public JSONObject cleanMessageLastFetchTime(String sessionId,String userId){
		String url = im_host + "api/v2/message/cleanMessageLastFetchTimeToRedis?sessionId="+sessionId+"&userId="+userId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	
	
	/**
	 * 根据session和userid获取单个会话
	 * @param sessionId
	 * @param userId
	 * @return
	 */
	public JSONObject getSingleSessionInfo(String sessionId,String userId){
		String url = im_host + "api/v2/sessions/" + sessionId + "/session?user_id=" + userId;
		try {
			String ret = HttpClientUtil.get(url,"utf-8");
			return JSON.parseObject(ret);
		} catch (Exception e) {
			throw new RuntimeException("操作失败!");
		}
	}
	
	/**
	 * 发送消息给IM
	 *
	 * @param from        来自
	 * @param to
	 * @param contentType 1文字 2图片消息
	 * @param content     内容
	 */
	public String sendIM(String from, String to, String contentType, String content) {
		String imAddr = im_host + "api/v1/chats/pm";
		List<NameValuePair> params = new ArrayList<>();
		params.add(new BasicNameValuePair("from", from));
		params.add(new BasicNameValuePair("to", to));
		params.add(new BasicNameValuePair("contentType", contentType));
		params.add(new BasicNameValuePair("content", content));
		String response = HttpClientUtil.post(imAddr, params, "UTF-8");
		return response;
	}
	
	
	public static final String SESSION_TYPE_MUC = "1";
	public static final String SESSION_TYPE_P2P = "2";
	public static final String SESSION_TYPE_GROUP = "3";
	public static final String SESSION_TYPE_SYSTEM = "0";
	public static final String SESSION_TYPE_PRESCRIPTION = "8";//续方
	public static final String SESSION_TYPE_EXAMINATION = "9";//在线复诊-图文
	public static final String SESSION_TYPE_ONDOOR_NURSING = "11";//上门护理
	public static final String SESSION_TYPE_COLLABORATION_HOSPITAL = "12";///互联网医院协同门诊
	public static final String SESSION_TYPE_GUIDANCE_HOSPITAL = "14";//互联网医院居民导诊聊天
	public static final String SESSION_TYPE_GENERAL_EXPERT = "15";//全科医生发起求助专科医生的专家咨询
	public static final String SESSION_TYPE_EXAMINATION_VIDEO = "16";//在线复诊-视频
	public static final String SESSION_TYPE_MUC_VIDEO = "17";//专家-视频
	public static final String SESSION_TYPE_GUIDANCE_ASSISTANT = "18";//导诊助手
	public static final String SESSION_STATUS_PROCEEDINGS = "0";
	public static final String SESSION_STATUS_END = "1";
	
	public static final String CONTENT_TYPE_TEXT = "1";
	
	
	/**
	 *按会话类型获取会话总数
	 * @param userid
	 * @param type
	 * @param status
	 * @return
	 */
	public Integer sessionCountByType(String userid,Integer type,Integer status){
		String url = im_host + "api/v2/sessions/sessionCountByType?user_id="+userid+"&type="+type+"&status="+status;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
		if(obj.getInteger("status") ==200){
			return obj.getInteger("count");
		}else{
			return 0;
		}
	}
	
	/**
	 *获取所有会话未读消息数。
	 * @param userid
	 * @param type
	 * @return
	 */
	public Integer SessionsUnreadMessageCount(String userid,String type){
		String url = im_host + "api/v2/sessions/unread_message_count?user_id="+userid+"&type="+type;
		String ret = HttpClientUtil.get(url,"utf-8");
		JSONObject obj = JSON.parseObject(ret);
//		if(obj.getInteger("count") ==200){
		return obj.getInteger("count");
//		}else{
//			return 0;
//		}
	}
}

+ 1 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/IntegerIdentityEntity.java

@ -25,7 +25,7 @@ public abstract class IntegerIdentityEntity implements Serializable {
//==========mysql 环境 id策略 end======================================================
//==========Oracle 环境id策略 =========================================================
   /*@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_generated")*/
  /* @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_generated")*/
//==========Oracle 环境id策略 =========================================================
    public Integer getId() {
        return id;

+ 151 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/area/BaseDrugStoreDO.java

@ -0,0 +1,151 @@
package com.yihu.jw.entity.base.area;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "base_drug_store")
public class BaseDrugStoreDO extends UuidIdentityEntityWithOperator {
    private String hospitalCode;
    private String hospitalName;
    private String provinceCode;
    private String provinceName;
    private String cityCode;
    private String cityName;
    private String townCode;
    private String townName;
    private String longitude;
    private String latitude;
    private String address;
    private String drugStoreCode;
    private String drugStoreName;
    private Integer isDel;
    @Transient
    private double distance ;
    @Transient
    public double getDistance() {
        return distance;
    }
    public void setDistance(double distance) {
        this.distance = distance;
    }
    @Column(name = "address")
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    @Column(name = "hospital_code")
    public String getHospitalCode() {
        return hospitalCode;
    }
    public void setHospitalCode(String hospitalCode) {
        this.hospitalCode = hospitalCode;
    }
    @Column(name = "hospital_name")
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    @Column(name = "province_code")
    public String getProvinceCode() {
        return provinceCode;
    }
    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }
    @Column(name = "province_name")
    public String getProvinceName() {
        return provinceName;
    }
    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }
    @Column(name = "city_code")
    public String getCityCode() {
        return cityCode;
    }
    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }
    @Column(name = "city_name")
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    @Column(name = "town_code")
    public String getTownCode() {
        return townCode;
    }
    public void setTownCode(String townCode) {
        this.townCode = townCode;
    }
    @Column(name = "town_name")
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
    @Column(name = "longitude")
    public String getLongitude() {
        return longitude;
    }
    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }
    @Column(name = "latitude")
    public String getLatitude() {
        return latitude;
    }
    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }
    @Column(name = "drug_store_code")
    public String getDrugStoreCode() {
        return drugStoreCode;
    }
    public void setDrugStoreCode(String drugStoreCode) {
        this.drugStoreCode = drugStoreCode;
    }
    @Column(name = "drug_store_name")
    public String getDrugStoreName() {
        return drugStoreName;
    }
    public void setDrugStoreName(String drugStoreName) {
        this.drugStoreName = drugStoreName;
    }
    @Column(name = "is_del")
    public Integer getIsDel() {
        return isDel;
    }
    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }
}

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/survey/WlyySurveyTemplateDO.java

@ -20,12 +20,21 @@ public class WlyySurveyTemplateDO {
    private String title;//模板标题',
    private String templateComment;//模板说明',
    private String creater;//创建人',
    private String createrCode;//创建人code',
    private String organization;//发布机构',
    private String del;//删除标志(1正常,0删除)',
    private Integer used;//常用量',
    private Date createTime;//创建时间',
    private Date updateTime;//修改时间',
    public String getCreaterCode() {
        return createrCode;
    }
    public void setCreaterCode(String createrCode) {
        this.createrCode = createrCode;
    }
    @Id
    @Column(name = "id", unique = true, nullable = false)
    public String getId() {

+ 9 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -748,4 +748,13 @@ public class BaseRequestMapping {
        public static final String queryHealthIdCard  = "/queryHealthIdCard";
    }
    /**
     * 药店管理接口
     */
    public static class drugStoreManage extends Basic {
        public static final String PREFIX  = "/drugStore";
        public static final String findDrugstore  = "/findDrugstore";
        public static final String findDrugstoreByDistance  = "/findDrugstoreByDistance";
    }
}

+ 30 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/hospital/survey/WlyySurveyTemplateVO.java

@ -21,6 +21,8 @@ public class WlyySurveyTemplateVO extends UuidIdentityVO {
    private String templateComment;//模板说明',
    @ApiModelProperty(value = "创建人", example = "模块1")
    private String creater;//创建人',
    @ApiModelProperty(value = "创建人code", example = "模块1")
    private String createrCode;//创建人name',
    @ApiModelProperty(value = "发布机构", example = "模块1")
    private String organization;//发布机构',
    @ApiModelProperty(value = "删除标志(1正常,0删除)", example = "模块1")
@ -41,6 +43,34 @@ public class WlyySurveyTemplateVO extends UuidIdentityVO {
    private Integer answerCount;//修改时间',
    @ApiModelProperty(value = "是否常用", example = "模块1")
    private Integer used;//是否常用1常用0不常用,
    @ApiModelProperty(value = "出诊科室code", example = "模块1")
    private String visitDept;
    @ApiModelProperty(value = "出诊科室名称", example = "模块1")
    private String visitDeptName;
    public String getCreaterCode() {
        return createrCode;
    }
    public void setCreaterCode(String createrCode) {
        this.createrCode = createrCode;
    }
    public String getVisitDept() {
        return visitDept;
    }
    public void setVisitDept(String visitDept) {
        this.visitDept = visitDept;
    }
    public String getVisitDeptName() {
        return visitDeptName;
    }
    public void setVisitDeptName(String visitDeptName) {
        this.visitDeptName = visitDeptName;
    }
    public Integer getUsed() {
        return used;

+ 68 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/drugstore/BaseDrugStoreEndpoint.java

@ -0,0 +1,68 @@
package com.yihu.jw.hospital.endpoint.drugstore;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.base.area.BaseProvinceDO;
import com.yihu.jw.hospital.drugstore.service.BaseDrugStoreService;
import com.yihu.jw.restmodel.base.area.BaseProvinceVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.management.MXBean;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = BaseRequestMapping.drugStoreManage.PREFIX)
@Api(value = "药店管理", description = "药店管理接口", tags = {"药店管理接口"})
public class BaseDrugStoreEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private BaseDrugStoreService baseDrugStoreService;
    @GetMapping(value = BaseRequestMapping.drugStoreManage.findDrugstore)
    @ApiOperation(value = "药店查询")
    public MixEnvelop findDrugstore (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<BaseDrugStoreDO> baseProvinces = baseDrugStoreService.search(fields, filters, sorts, page, size);
        int count = (int)baseDrugStoreService.getCount(filters);
        MixEnvelop mixEnvelop = new MixEnvelop();
        mixEnvelop.setDetailModelList(baseProvinces);
        mixEnvelop.setCurrPage(page);
        mixEnvelop.setTotalCount(count);
        mixEnvelop.setPageSize(size);
        return mixEnvelop;
    }
    @GetMapping(value = BaseRequestMapping.drugStoreManage.findDrugstoreByDistance)
    @ApiOperation(value = "药店距离查询")
    public MixEnvelop findDrugstoreBydistance (
            @ApiParam(name = "latitude", value = "经度")
            @RequestParam(value = "latitude", required = false) String latitude,
            @ApiParam(name = "longitude", value = "纬度")
            @RequestParam(value = "longitude", required = false) String longitude,
            @ApiParam(name = "drugStoreName", value = "药店名称")
            @RequestParam(value = "drugStoreName", required = false) String drugStoreName,
            @ApiParam(name = "hospitalName", value = "医院名称")
            @RequestParam(value = "hospitalName", required = false) String hospitalName) throws Exception {
        List<BaseDrugStoreDO> list = baseDrugStoreService.countDistanceListIncode(latitude,longitude,drugStoreName,hospitalName);
        MixEnvelop mixEnvelop = new MixEnvelop();
        mixEnvelop.setDetailModelList(list);
        return mixEnvelop;
    }
}

+ 9 - 4
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/survey/SurveyEndpoint.java

@ -107,7 +107,7 @@ public class SurveyEndpoint extends EnvelopRestEndpoint {
    public ObjEnvelop findSurveyTemplateById(@ApiParam(name = "tempId", value = "模板ID")
                                             @RequestParam(value = "tempId",required = true) String tempId,
                                             @ApiParam(name = "userCode", value = "当前用户id")
                                             @RequestParam(value = "userCode",required = true) String userCode ) throws Exception {
                                             @RequestParam(value = "userCode",required = false) String userCode ) throws Exception {
        return success(surveyService.findSurveyTemplateById(tempId,userCode));
    }
@ -159,6 +159,7 @@ public class SurveyEndpoint extends EnvelopRestEndpoint {
        return success(surveyService.findSurveyByDept(dept));
    }
    @GetMapping(value = BaseHospitalRequestMapping.WlyySurvey.findSurveyByDeptAndPatient)
    @ApiOperation(value = "模板-查询部门下发放的问卷用户答题情况")
    public ListEnvelop findSurveyByDeptAndPatient(@ApiParam(name = "dept", value = "科室")
@ -225,13 +226,15 @@ public class SurveyEndpoint extends EnvelopRestEndpoint {
                                     @RequestParam(value = "tempId",required = false) String tempId,
                                     @ApiParam(name = "patient", value = "标题")
                                     @RequestParam(value = "patient",required = false) String patient,
                                     @ApiParam(name = "patientName", value = "患者名字")
                                         @RequestParam(value = "patientName",required = false) String patientName,
                                     @ApiParam(name = "title", value = "标题")
                                     @RequestParam(value = "title",required = false) String title,
                                     @ApiParam(name = "page", value = "第几页,1开始")
                                     @RequestParam(value = "page",required = true)Integer page,
                                     @ApiParam(name = "size", value = "每页大小")
                                     @RequestParam(value = "size",required = true)Integer size)throws Exception {
        return surveyService.findAnswerList(tempId,patient,title,page,size);
        return surveyService.findAnswerList(tempId,patient,patientName,title,page,size);
    }
    //=================
@ -241,13 +244,15 @@ public class SurveyEndpoint extends EnvelopRestEndpoint {
                                     @RequestParam(value = "title",required = false) String title,
                               @ApiParam(name = "doctor", value = "医生id")
                                     @RequestParam(value = "doctor",required = false) String doctor,
                               @ApiParam(name = "used", value = "是否常用")
                               @ApiParam(name = "used", value = "used")
                                     @RequestParam(value = "used",required = false) Integer used,
                                  @ApiParam(name = "labelCode", value = "labelCode")
                                      @RequestParam(value = "labelCode",required = false) String labelCode,
                               @ApiParam(name = "page", value = "第几页,1开始",defaultValue = "1")
                                     @RequestParam(value = "page",required = true,defaultValue = "1")Integer page,
                               @ApiParam(name = "pageSize", value = "每页大小",defaultValue = "10")
                                     @RequestParam(value = "pageSize",required = true,defaultValue = "10")Integer pageSize)throws Exception {
        return businessService.getUsedList(title,doctor,used,page,pageSize);
        return businessService.getUsedList(title,doctor,labelCode,used,page,pageSize);
    }
    @GetMapping(value = BaseHospitalRequestMapping.WlyySurvey.setUsed)

+ 20 - 26
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/service/consult/BasePatientBusinessService.java

@ -16,6 +16,7 @@ import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.hospital.survey.WlyySurveyLabelInfoVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
@ -210,9 +211,10 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
		knowledgeArticleUserDao.save(knowledgeArticleUserDO);
		surveyTemplateDao.save(wlyySurveyTemplateDO);
	}
	public MixEnvelop getUsedList(String title, String doctor, Integer used, Integer page, Integer pageSize) {
	public MixEnvelop getUsedList(String title, String doctor,String labelCode,  Integer used, Integer page, Integer pageSize) {
		StringBuffer sql = new StringBuffer();
		MixEnvelop mixEnvelop = new MixEnvelop();
		sql.append("SELECT " +
				" t.id, " +
				" b.used as \"used\","+
@ -220,6 +222,7 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
				" t.template_comment AS templateComment, " +
				" t.organization, " +
				" t.creater, " +
				" t.creater_code, " +
				" t.create_time AS createTime, " +
				" t.del, " +
				" t.update_time AS updateTime" +
@ -228,17 +231,23 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
		//1为查询常用
		if (null != used) {
			if (1 == used) {
				sql.append("JOIN wlyy_knowledge_article_user b on t.id = b.relation_code ");
				sql.append("JOIN wlyy_survey_label_info i ON t.id = i.survey_temp_code where 1=1");
				if (StringUtils.isNotEmpty(labelCode)){
					sql.append(" JOIN wlyy_survey_label_info i on t.id = i.survey_temp_code ");
				}
				sql.append(" JOIN wlyy_knowledge_article_user b on t.id = b.relation_code where 1=1 ");
				sql.append(" and b.used = 1");
				if (StringUtils.isNotEmpty(doctor)) {
				if (StringUtils.isNotEmpty(title)) {
					sql.append(" and t.title like '%" + title + "%'");
				}
				if (StringUtils.isNotEmpty(doctor)) {
					sql.append(" and t.creater = '" + doctor + "'");
					sql.append(" and b.user_code ='"+doctor+"'");
				}
				if (StringUtils.isNotEmpty(labelCode)){
					sql.append(" and i.label_code = '"+labelCode+"'");
				}
				System.out.println(sql);
				String sqlCount = "select Count(1) as \"total\" from ("+sql+") l";
				List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql.toString(), page, pageSize);
				List<Map<String, Object>> listCount = hibenateUtils.createSQLQuery(sqlCount);
@ -251,14 +260,9 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
						List<WlyySurveyLabelInfoVO>  wlyySurveyLabelInfoVOS= surveyService.findSurveyTemplateLabel(null==map.get("id")?"":map.get("id").toString());
						String createTime = null == map.get("createTime") ? "" : map.get("createTime").toString();
                        String updateTime = null == map.get("updateTime") ? "" : map.get("updateTime").toString();
						String creater = null == map.get("creater") ? "" : map.get("creater").toString();
						map.put("create_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                        map.put("update_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
						map.put("createTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                        map.put("updateTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
						map.put("labels",wlyySurveyLabelInfoVOS);
						BaseDoctorDO doctorDO = doctorDao.findById(creater);
						if (null!=doctor){
							map.put("doctrName", doctorDO.getName());
						}
					}
				}
				mixEnvelop.setPageSize(pageSize);
@ -286,13 +290,8 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
						map.put("labels",wlyySurveyLabelInfoVOS);
                        String createTime = null == map.get("createTime") ? "" : map.get("createTime").toString();
                        String updateTime = null == map.get("updateTime") ? "" : map.get("updateTime").toString();
                        map.put("create_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                        map.put("update_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
                        String creater = null == map.get("creater") ? "" : map.get("creater").toString();
						BaseDoctorDO doctorDO = doctorDao.findById(creater);
						if (null!=doctor){
							map.put("doctrName", doctorDO.getName());
						}
                        map.put("createTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                        map.put("updateTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
					}
				}
				mixEnvelop.setPageSize(pageSize);
@ -324,13 +323,8 @@ public class BasePatientBusinessService extends BaseJpaService<BasePatientBusine
					map.put("labels",wlyySurveyLabelInfoVOS);
                    String createTime = null == map.get("createTime") ? "" : map.get("createTime").toString();
                    String updateTime = null == map.get("updateTime") ? "" : map.get("updateTime").toString();
                    map.put("create_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                    map.put("update_time", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
					String creater = null == map.get("creater") ? "" : map.get("creater").toString();
					BaseDoctorDO doctorDO = doctorDao.findById(creater);
					if (null!=doctor){
						map.put("doctrName", doctorDO.getName());
					}
                    map.put("createTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(createTime)));
                    map.put("updateTime", DateUtil.dateToStrLong(DateUtil.strToDateLong(updateTime)));
				}
			}