Przeglądaj źródła

我的家人模块代码提交

liuwenbin 6 lat temu
rodzic
commit
2aedb0c8e8

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/message/service/MessageService.java

@ -139,7 +139,7 @@ public class MessageService extends BaseJpaService<BaseMessageDO, MessageDao> {
                " AND b.platform = '"+platform+"' " +
                " AND b.receiver = '"+code+"' " +
                " AND b.del = 1 " +
                " AND m.read_state = "+readState;
                " AND b.read_state = "+readState;
        return jdbcTemplate.queryForList(sql);
    }

+ 121 - 0
business/base-service/src/main/java/com/yihu/jw/utils/PinYinUtil.java

@ -0,0 +1,121 @@
package com.yihu.jw.utils;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class PinYinUtil {
	/** 
     * 获取汉字串拼音首字母,英文字符不变 
     * @param chinese 汉字串 
     * @return 汉语拼音首字母 
     */ 
    public static String getFirstSpell(String chinese) { 
        StringBuffer pybf = new StringBuffer();
        char[] arr = chinese.toCharArray();
        HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
        defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            for (int i = 0; i < arr.length; i++) {
                    if (arr[i] > 128) {
                            try {
                                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat);
                                    if (temp != null) {
                                            pybf.append(temp[0].charAt(0));
                                    }
                            } catch (BadHanyuPinyinOutputFormatCombination e) {
                                    e.printStackTrace();
                            }
                    } else {
                            pybf.append(arr[i]);
                    }
            }
            return pybf.toString().replaceAll("\\W", "").trim();
    } 
    /** 
     * 获取汉字串拼音,英文字符不变 
     * @param chinese 汉字串 
     * @return 汉语拼音 
     */ 
    public static String getFullSpell(String chinese) { 
            StringBuffer pybf = new StringBuffer(); 
            char[] arr = chinese.toCharArray(); 
            HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); 
            defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); 
            defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); 
            for (int i = 0; i < arr.length; i++) { 
                    if (arr[i] > 128) { 
                            try { 
                                    pybf.append(PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat)[0]); 
                            } catch (BadHanyuPinyinOutputFormatCombination e) { 
                                    e.printStackTrace(); 
                            } 
                    } else { 
                            pybf.append(arr[i]); 
                    } 
            } 
            return pybf.toString(); 
    }
    /**
     * 字符串按拼音排序
     * @param list
     * @return
     */
    public static Map<String,List<Object>> pingYinSortByString(List<String> list){
            Map<String,List<Object>>  map =  new LinkedHashMap<>();
            String[] alphatables = {"a", "b", "c", "d", "e", "f", "g", "h", "i",
                    "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
            for (String alpha : alphatables){
                    for(String one:list){
                            String firstSpell = PinYinUtil.getFirstSpell(one).substring(0,1);
                            if (alpha.equals(firstSpell)){
                                    List<Object> resultList = null;
                                    if(map.get(alpha)==null){
                                            resultList = new ArrayList();
                                    }else{
                                            resultList = map.get(alpha);
                                    }
                                    resultList.add(one);
                                    map.put(alpha,resultList);
                            }
                    }
            }
            return map;
    }
    /**
    * 字符串按拼音排序
    * @param
    * @return
    */
    public static Map<String,Object> pingYinSort(List<Map<String,Object>> result){
            Map<String,Object>  map =  new LinkedHashMap <>();
            String[] alphatables = {"a", "b", "c", "d", "e", "f", "g", "h", "i",
                    "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
            if (result.size() > 0) {
                    for (String alpha : alphatables){
                            List<Map<String,Object>> resultList = new ArrayList<>();
                            for (Map<String,Object> one : result){
                                    String name = String.valueOf(one.get("name"));
                                    String firstSpell = PinYinUtil.getFirstSpell(name).substring(0,1);
                                    if (alpha.equals(firstSpell)){
                                            resultList.add(one);
                                            map.put(alpha,resultList);
                                    }
                            }
                    }
                    return map;
            } else {
                    return map;
            }
    }
}

+ 8 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/patient/PatientRequestMapping.java

@ -60,6 +60,14 @@ public class PatientRequestMapping {
        public static final String myFamilyBindList  = "/myFamilyBindList";
        public static final String scanQRcode  = "/scanQRcode";
        public static final String messageToBinding  = "/messageToBinding";
        public static final String cancelBindFamily  = "/cancelBindFamily";
        public static final String updateAuthorizeById  = "/updateAuthorizeById";
    }
    public static class MyMessage extends Basic {
        public static final String PREFIX  = "/myMessage";
        public static final String messageList  = "/messageList";
        public static final String myDoctorList  = "/myDoctorList";
    }

+ 1 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientApplyLogDao.java

@ -23,6 +23,6 @@ public interface PatientApplyLogDao extends PagingAndSortingRepository<PatientAp
    @Query("update PatientApplyLog t set t.status = ?1 where t.id=?2 ")
    int updateStatusById(Integer status,Integer id);
    @Query("select l from PatientApplyLog l where l.createUser=?1 and l.familyMemberCode=?2 and l.del=1 and l.status in(1,2) and l.failureTime<?3 and l.familyBindRole=?4")
    @Query("select l from PatientApplyLog l where l.createUser=?1 and l.familyMemberCode=?2 and l.del=1 and l.status in(1,2) and l.failureTime>=?3 and l.familyBindRole=?4")
    PatientApplyLog findValidOne(String createUser,String familyMemberCode,Date failureTime,Integer familyBindRole);
}

+ 9 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientFamilyMemberDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.patient.dao.myFamily;
import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -29,4 +30,12 @@ public interface PatientFamilyMemberDao extends PagingAndSortingRepository<BaseP
    @Query("select m from BasePatientFamilyMemberDO m where m.del=1 and m.patient=?1")
    List<BasePatientFamilyMemberDO> getByPatientAndFamilyMember(String patient);
    @Modifying
    @Query("update BasePatientFamilyMemberDO m set m.isAuthorize = ?1 where m.id=?2 ")
    int updateAuthorizeById(Integer isAuthorize,String id);
    @Modifying
    @Query("update BasePatientFamilyMemberDO m set m.del = ?1 where m.id=?2 ")
    int updateDelById(Integer del,String id);
}

+ 31 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myFamily/MyFamilyEndpoint.java

@ -175,6 +175,7 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = PatientRequestMapping.MyFamily.myFamilyBindList)
    @ApiOperation(value = "我绑定的记录")
    public Envelop myFamilyBindList(
@ -221,4 +222,34 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
            return failed(e.getMessage());
        }
    }
    @PostMapping(value = PatientRequestMapping.MyFamily.cancelBindFamily)
    @ApiOperation(value = "解除绑定家人")
    public Envelop cancelBindFamily(
            @ApiParam(name = "familyMemberId", value = "familyMemberId", required = true)
            @RequestParam(value = "familyMemberId",required = true) String familyMemberId) throws Exception {
        try{
            myFamilyService.cancelBindFamily(familyMemberId);
            return success();
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
    @PostMapping(value = PatientRequestMapping.MyFamily.updateAuthorizeById)
    @ApiOperation(value = "更新代管授权")
    public Envelop updateAuthorizeById(
            @ApiParam(name = "isAuthorize", value = "0:未授权,1:已授权", required = true)
            @RequestParam(value = "isAuthorize",required = true) Integer isAuthorize,
            @ApiParam(name = "familyMemberId", value = "familyMemberId", required = true)
            @RequestParam(value = "familyMemberId",required = true) String familyMemberId) throws Exception {
        try{
            myFamilyService.updateAuthorizeById(isAuthorize,familyMemberId);
            return success();
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
}

+ 65 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myMessage/MyMessageEndpoint.java

@ -0,0 +1,65 @@
package com.yihu.jw.patient.endpoint.myMessage;
import com.yihu.jw.patient.service.message.MyDoctorListService;
import com.yihu.jw.patient.service.message.MyMessageService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.patient.PatientRequestMapping;
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 java.util.List;
import java.util.Map;
/**
 * @author liuwenbin on 2018/12/10.
 */
@RestController
@RequestMapping(PatientRequestMapping.MyMessage.PREFIX)
@Api(value = "居民的我的消息模块", description = "居民的我的消息模块", tags = {"居民端 - 我的消息"})
public class MyMessageEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private MyMessageService myMessageService;
    @Autowired
    private MyDoctorListService myDoctorListService;
    @GetMapping(value = PatientRequestMapping.MyMessage.messageList)
    @ApiOperation(value = "获取我的消息列表")
    public Envelop messageList(
            @ApiParam(name = "patient", value = "居民code", required = false)
            @RequestParam(value = "patient",required = false) String patient,
            @ApiParam(name = "page", value = "页码,从第一页开始", required = true)
            @RequestParam(value = "page",required = true) Integer page,
            @ApiParam(name = "pageSize", value = "每页总数", required = true)
            @RequestParam(value = "pageSize",required = true) Integer pageSize) throws Exception {
        try{
            List<Map<String,Object>> messageList = myMessageService.messageList(getUID(patient),page,pageSize);
            return success(messageList);
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = PatientRequestMapping.MyMessage.myDoctorList)
    @ApiOperation(value = "获取医生通讯录")
    public Envelop myDoctorList(
            @ApiParam(name = "patient", value = "居民code", required = false)
            @RequestParam(value = "patient",required = false) String patient,
            @ApiParam(name = "condition", value = "搜索条件,医生姓名/医院", required = false)
            @RequestParam(value = "condition",required = false) String condition) throws Exception {
        try{
            Map<String,Object> messageMap = myDoctorListService.myDoctorList(getUID(patient),condition);
            return success(messageMap);
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
}

+ 58 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/message/MyDoctorListService.java

@ -0,0 +1,58 @@
package com.yihu.jw.patient.service.message;
import com.yihu.jw.utils.PinYinUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
/**
 * @author liuwenbin on 2018/12/10.
 */
@Service
public class MyDoctorListService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public Map<String,Object> myDoctorList(String patient, String condition)throws Exception{
        String sql = myDoctorListSql(patient,condition);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        Map<String,Object> map = PinYinUtil.pingYinSort(list);
        return map;
    }
    public String myDoctorListSql(String patient, String condition){
        String sql ="SELECT " +
                " r.sign_doctor as doctor, " +
                " r.sign_doctor_name as name, " +
                " r.hospital as hospital, " +
                " r.hospital_name as hospitalName" +
                " FROM " +
                " base_service_package_sign_record r " +
                " WHERE " +
                " ( " +
                "  r.patient IN ( " +
                "   SELECT " +
                "    m.family_member  " +
                "   FROM " +
                "    base_patient_family_member m " +
                "   WHERE " +
                "    m.patient = '"+patient+"' " +
                "   AND m.del = 1 " +
                "   AND m.is_authorize = 1 " +
                "  ) " +
                "  OR r.patient = '"+patient+"' " +
                " ) " +
                " AND r. STATUS = 2 " ;
        if(!StringUtils.isEmpty(condition)){
            sql+=" AND r.sign_doctor_name like '%"+condition+"%' " +
                    " AND r.hospital_name like '%"+condition+"%'";
        }
        return sql;
    }
}

+ 21 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/message/MyMessageService.java

@ -0,0 +1,21 @@
package com.yihu.jw.patient.service.message;
import com.yihu.jw.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
 * @author liuwenbin on 2018/12/10.
 */
@Service
public class MyMessageService {
    @Autowired
    private MessageService messageService;
    public List<Map<String,Object>> messageList(String code,Integer page,Integer pageSize){//1微信端/患者端,2医生APP端
        return messageService.messageList(1,code,page,pageSize);
    }
}

+ 54 - 13
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/MyFamilyService.java

@ -102,7 +102,7 @@ public class MyFamilyService {
        BasePatientDO patientDO = patientService.findByIdAndDel(patient);
        //1、检验手机号码是否有存在账号,
        BasePatientDO familyPatient = patientService.findByMobileAndDel(familyMobile);
        Long time = 1000*60*60*Long.valueOf(qrCodeFailurTime);
        Long time = 1000*60*60*24*Long.valueOf(qrCodeFailurTime);
        if(familyPatient==null){
            //2、没有存在账号的,预注册一个账号,调用预注册接口
            Map<String,Object> map = patientService.bespeakRegist(familyMobile,time);
@ -120,10 +120,14 @@ public class MyFamilyService {
            patientApplyLog.setFamilyMemberName(familyPatient.getName());
            patientApplyLog.setFamilyMemberCode(familyPatient.getId());
            patientApplyLog.setDel(1);
            patientApplyLog.setStatus(1);
            patientApplyLog.setCreateTime(new Date());
            patientApplyLog.setCreateUser(familyPatient.getId());
            patientApplyLog.setCreateUser(patientDO.getId());
            patientApplyLog.setCreateUserName(patientDO.getName());
            patientApplyLog.setFamilyBindRole(familyBindRole);
            Long failurTime = System.currentTimeMillis()+time;
            patientApplyLog.setFailureTime(new Date(failurTime));
            patientApplyLog = patientApplyLogService.save(patientApplyLog);
            //4、发送绑定家人的系统消息
            BaseMessageDO messageDO = new BaseMessageDO();
            messageDO.setReceiver(familyPatient.getId());
@ -132,8 +136,8 @@ public class MyFamilyService {
            messageDO.setSenderName(patientDO.getName());
            messageDO.setSenderPhoto(patientDO.getPhoto());
            messageDO.setTitle("家人绑定");
            messageDO.setMsgDigest(null);
            messageDO.setMsgContent(null);
            messageDO.setMsgDigest("");
            messageDO.setMsgContent("");
            messageDO.setMsgTypeCode("010801");
            messageDO.setMsgTypeName("");
            messageDO.setPlatform(platform);
@ -141,11 +145,14 @@ public class MyFamilyService {
            messageDO.setReadonly(0);
            messageDO.setDel("1");
            messageDO.setCreateTime(new Date());
            messageDO.setRelationData(patientApplyLog.getId()+"");
            messageService.save(messageDO);
        }else{
            Long failurTime = System.currentTimeMillis()+time;
            patientApplyLog.setFailureTime(new Date(failurTime));
            patientApplyLog = patientApplyLogService.save(patientApplyLog);
        }
        Long failurTime = System.currentTimeMillis()+time;
        patientApplyLog.setFailureTime(new Date(failurTime));
        patientApplyLog = patientApplyLogService.save(patientApplyLog);
//        PatientApplyLog patientApplyLog = createFamilyQrCode(request,familyPatient,wechatId,patient,familyBindRole);
@ -418,11 +425,12 @@ public class MyFamilyService {
            BasePatientDO familyMember = patientService.findByIdAndDel(one.getFamilyMember());
            map.put("photo",familyMember.getPhoto());//头像
            map.put("name",familyMember.getName());//姓名
            map.put("roleName",role.get(one.getFamilyRelation()+1));//角色名称
            map.put("roleName",role.get(one.getFamilyRelation()-1));//角色名称
            map.put("mobile",familyMember.getMobile());//手机号码
            map.put("isAuthorize",one.getIsAuthorize());//0:未授权,1:已授权
            map.put("familyMemberId",one.getId());
            map.put("patientId",familyMember.getId());
            map.put("familyPatientId",familyMember.getId());
            map.put("patientId",patient);
            map.put("type",1);
            resultList.add(map);
        }
@ -433,15 +441,20 @@ public class MyFamilyService {
            BasePatientDO familyMember = patientService.findByIdAndDel(one.get("family_member_code")+"");
            map.put("photo",familyMember.getPhoto());//头像
            map.put("name",familyMember.getName());//姓名
            map.put("roleName",role.get(Integer.valueOf(one.get("family_bind_role")+"")+1));//角色名称
            map.put("roleName",role.get(Integer.valueOf(one.get("family_bind_role")+"")-1));//角色名称
            map.put("mobile",familyMember.getMobile());//手机号码
            //有效期
            Date failurTime = (Date)one.get("failure_time");
            Long l = failurTime.getTime()-System.currentTimeMillis();
            Long day24 = 1000*60*60*24L;
            map.put("day",l/day24);
            if(l%day24>0){
                map.put("day",(l/day24)+1);
            }else{
                map.put("day",l/day24);
            }
            map.put("patientApplyId",one.get("id"));
            map.put("patientId",familyMember.getId());
            map.put("familyPatientId",familyMember.getId());
            map.put("patientId",patient);
            map.put("type",2);
            resultList.add(map);
        }
@ -452,7 +465,7 @@ public class MyFamilyService {
            BasePatientDO familyMember = patientService.findByIdAndDel(one.get("family_member_code")+"");
            map.put("photo",familyMember.getPhoto());//头像
            map.put("name",familyMember.getName());//姓名
            map.put("roleName",role.get(Integer.valueOf(one.get("family_bind_role")+"")+1));//角色名称
            map.put("roleName",role.get(Integer.valueOf(one.get("family_bind_role")+"")-1));//角色名称
            map.put("mobile",familyMember.getMobile());//手机号码
            Integer status = null;
            if("1".equals(one.get("status")+"")||"2".equals(one.get("status")+"")){
@ -462,6 +475,8 @@ public class MyFamilyService {
            }
            map.put("status",one.get("status"));//状态
            map.put("statusName",getStatusName(status));//状态名称;
            map.put("familyPatientId",familyMember.getId());
            map.put("patientId",patient);
            map.put("type",3);
            resultList.add(map);
        }
@ -521,6 +536,32 @@ public class MyFamilyService {
        }
    }
    /**
     * 解除绑定
     * @param familyMemberId
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public void cancelBindFamily(String familyMemberId) throws Exception{
        int i = patientFamilyMemberService.cancelBindFamily(familyMemberId);
        if(i<0){
            throw new Exception("update data failur !");
        }
    }
    /**
     * 更新授权
     * @param familyMemberId
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateAuthorizeById(Integer isAuthorize,String familyMemberId) throws Exception{
        int i = patientFamilyMemberService.updateAuthorizeById(isAuthorize,familyMemberId);
        if(i<0){
            throw new Exception("update data failur !");
        }
    }
    /**
     * 家庭关系转换

+ 1 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/PatientApplyLogService.java

@ -54,7 +54,7 @@ public class PatientApplyLogService extends BaseJpaService<PatientApplyLog, Pati
    //invalid 无效
    public List<Map<String, Object>> findInvalidByPatient(String patient){
        String sql = "select l.* from patient_apply_for_log l where l.create_user='"+patient+"' and l.del=1 and (l.status in (4,5) or (l.failure_time>='"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss")+"' and l.status in (1,2))) limit 0,10";
        String sql = "select l.* from patient_apply_for_log l where l.create_user='"+patient+"' and l.del=1 and (l.status in (4,5) or (l.failure_time<='"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss")+"' and l.status in (1,2))) limit 0,10";
        return jdbcTemplate.queryForList(sql);
    }

+ 8 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/PatientFamilyMemberService.java

@ -52,4 +52,12 @@ public class PatientFamilyMemberService extends BaseJpaService<BasePatientFamily
        return patientFamilyMemberDao.getByPatientAndFamilyMember(patient);
    }
    public Integer cancelBindFamily(String id){
        return patientFamilyMemberDao.updateDelById(0,id);
    }
    public Integer updateAuthorizeById(Integer isAuthorize,String id){
        return patientFamilyMemberDao.updateAuthorizeById(isAuthorize,id);
    }
}