Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

liubing 3 years ago
parent
commit
debc1618ff

+ 11 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/servicePackage/ServicePackageRecordDO.java

@ -2,6 +2,7 @@ package com.yihu.jw.entity.base.servicePackage;
import com.yihu.jw.entity.UuidIdentityEntityWithCreateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
@ -26,6 +27,7 @@ public class ServicePackageRecordDO extends UuidIdentityEntityWithCreateTime imp
     * 居民id
     */
    private String patient;
    private String teamCode;//服务团队id
    public String getSignId() {
        return signId;
@ -50,4 +52,13 @@ public class ServicePackageRecordDO extends UuidIdentityEntityWithCreateTime imp
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "team_code")
    public String getTeamCode() {
        return teamCode;
    }
    public void setTeamCode(String teamCode) {
        this.teamCode = teamCode;
    }
}

+ 1 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/servicePackage/ServicePackageSignRecordDO.java

@ -137,4 +137,5 @@ public class ServicePackageSignRecordDO extends UuidIdentityEntityWithCreateTime
    public void setPackageList(List<Map<String,Object>> packageList) {
        this.packageList = packageList;
    }
}

+ 39 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/OnlineContactEndpoint.java

@ -0,0 +1,39 @@
package com.yihu.jw.care.endpoint.patient;
import com.yihu.jw.care.service.patient.OnlineContactService;
import com.yihu.jw.restmodel.web.Envelop;
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.*;
/***
 * @ClassName: OnlineContactEndpoint
 * @Description: 在线联系
 * @Auther: shi kejing
 * @Date: 2021/8/11 16:43
 */
@RestController
@RequestMapping("online" )
@Api(tags = "在线联系", description = "在线联系")
public class OnlineContactEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private OnlineContactService service;
    @GetMapping(value = "getOnLineObj")
    @ApiOperation(value = "获取在线联系")
    public Envelop getOnLineObj(
            @ApiParam(name = "patient", value = "居民id") @RequestParam(value = "patient", required = true) String patient) {
        try{
            return success("获取成功",service.getOnLineObj(patient));
        }catch (Exception e){
            return failedException2(e);
        }
    }
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PatientEndpoint.java

@ -41,7 +41,7 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "testException")
    @ApiOperation(value = "测试异常")
    public String testException2(String type) throws Exception {
//        patientService.intiPatient();
        if("1".equals(type)){
            throw new NullPointerException();
        }else if("2".equals(type)){

+ 56 - 21
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/sign/SignEndpoint.java

@ -67,7 +67,7 @@ public class SignEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "findSignDoctor")
    @ApiOperation(value = "查找签约医生")
    public ListEnvelop findSignDoctor (
            @ApiParam(name = "patient", value = "医生code", required = true)
            @ApiParam(name = "patient", value = "居民code", required = true)
            @RequestParam(value = "patient",required = true) String patient,
            @ApiParam(name = "orgCode", value = "医院code", required = false)
            @RequestParam(value = "orgCode",required = false) String orgCode) throws Exception {
@ -192,6 +192,30 @@ public class SignEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "findPatientSignList")
    @ApiOperation(value = "获取签约服务包记录")
    public ListEnvelop findPatientSignList (
            @ApiParam(name = "patient", value = "patient", required = true)
            @RequestParam(value = "patient") String patient) throws Exception {
        try{
            return ListEnvelop.getSuccess("查询成功",servicePackageService.findPatientSignList(patient));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
    @GetMapping(value = "signPackageDetail")
    @ApiOperation(value = "获取签约服务包记录详情")
    public ObjEnvelop signPackageDetail (
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) throws Exception {
        try{
            return ObjEnvelop.getSuccess("查询成功",servicePackageService.signPackageDetail(id));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "servicePackageSign")
    @ApiOperation(value = "分配服务包-签约")
    @ObserverRequired
@ -200,32 +224,47 @@ public class SignEndpoint extends EnvelopRestEndpoint {
            @RequestParam String jsonData,
            @ApiParam(name = "patientId", value = "居民id", required = true)
            @RequestParam String patientId,
            @ApiParam(name = "signYear", value = "签约时长 0长期 1 1年 2 2年", required = true)
            @RequestParam String signYear,
            @ApiParam(name = "doctorId", value = "医生id", required = true)
            @RequestParam String doctorId) {
        try{
           JSONObject result  = servicePackageService.servicePackageSign(jsonData,doctorId,patientId);
           JSONObject result  = servicePackageService.servicePackageSign(jsonData,doctorId,patientId,signYear);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return Envelop.getError(result.getString(ResponseContant.resultMsg));
            }
            servicePackageService.setPatientServiceItems(result.getJSONObject("resultMsg").getString("patient"));
            return Envelop.getSuccess("分配成功");
            return Envelop.getSuccess("签约成功");
        }catch (Exception e){
            if (e.getMessage().contains("重复签约服务项目")){
                return failed("分配失败,"+e.getMessage(),-1);
                return failed("签约失败,"+e.getMessage(),-1);
            }
            return failedException2(e);
        }
    }
    @GetMapping(value = "findServicePackageByOrgCode")
    @ApiOperation(value = "获取服务包")
    public ListEnvelop<List<Map<String,Object>>> findServicePackageByOrgCode (
            @ApiParam(name = "orgCode", value = "机构code", required = false)
            @RequestParam(value = "orgCode",required = false)  String orgCode) {
        try{
            return ListEnvelop.getSuccess("获取成功",servicePackageService.findServicePackageByOrgCode(orgCode));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
    @GetMapping(value = "servicePackagePage")
    @ApiOperation(value = "获取服务包分页")
    public PageEnvelop<List<Map<String,Object>>> servicePackagePage (
            @ApiParam(name = "orgCode", value = "机构code", required = false)
            @RequestParam(value = "orgCode",required = false)  String orgCode,
            @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 {
        try{
            return servicePackageService.servicePackagePage(page, size);
            return servicePackageService.servicePackagePage(page, size,orgCode);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
@ -269,8 +308,6 @@ public class SignEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "status",required = false) Integer status,
            @ApiParam(name = "levelConclusion", value = "评估结果/等级结论", required = false)
            @RequestParam(value = "levelConclusion",required = false) Integer levelConclusion,
            @ApiParam(name = "servicePackageStatus", value = "服务包分配(0未分配,1已分配)", required = false)
            @RequestParam(value = "servicePackageStatus",required = false) Integer servicePackageStatus,
            @ApiParam(name = "type", value = "type 0当年 1全部", required = false)
            @RequestParam(value = "type",required = false,defaultValue = "0") Integer type,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
@ -278,7 +315,7 @@ public class SignEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        try{
            return capacityAssessmentRecordService.assessmentPage(doctorId,patientId, name, type,page, size, status, levelConclusion, servicePackageStatus);
            return capacityAssessmentRecordService.assessmentPage(doctorId,patientId, name, type,page, size, status, levelConclusion);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
@ -503,18 +540,6 @@ public class SignEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value="getServerDoctorByPackage")
    @ApiOperation(value = "根据服务包,服务项目获取对应的服务医生")
    public ListEnvelop getServerDoctorByPackage(@ApiParam(name="packageId",value = "服务包id",required = true)
                       @RequestParam(value = "packageId")String packageId,
                       @ApiParam(name="serverItem",value = "服务项目code",required = true)
                       @RequestParam(value = "serverItem")String serverItem){
        try {
            return ListEnvelop.getSuccess("查询成功",servicePackageService.getServerDoctorByPackage(packageId,serverItem));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
    @GetMapping(value="getServerDoctorAll")
    @ApiOperation(value = "获取所有服务医生")
@ -562,4 +587,14 @@ public class SignEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value="signPackageDoctorList")
    @ApiOperation(value = "签约服务包医生列表")
    public ListEnvelop signPackageDoctorList(@ApiParam(name="pateint",value = "姓名或身份证",required = true)
                                      @RequestParam(value = "pateint",required = true)String pateint){
        try {
            return ListEnvelop.getSuccess("查询成功",servicePackageService.signPackageDoctorList(pateint));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
}

+ 2 - 11
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/consult/ConsultTeamService.java

@ -14,9 +14,7 @@ import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
import com.yihu.jw.entity.care.assistance.EmergencyAssistanceDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
import com.yihu.jw.entity.care.securitymonitoring.SecurityMonitoringOrderDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.dao.ConsultDao;
@ -24,23 +22,16 @@ import com.yihu.jw.im.dao.ConsultTeamDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.sms.service.TXYSmsService;
import com.yihu.jw.sms.service.ZBSmsService;
import com.yihu.jw.utils.EntityUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.yihu.jw.rm.hospital.BaseHospitalRequestMapping.PatientIM.patientInfo;
/**
 * Created by yeshijie on 2020/12/23.
 */
@ -233,7 +224,7 @@ public class ConsultTeamService {
        }
        //加入团队医生
        List<Map<String,Object>> doctorList = servicePackageService.fingdDoctorByPaitenId(patient,"emergencyAssistance");
        List<Map<String,Object>> doctorList = servicePackageService.fingdDoctorByPaitenId(patient);
        for(Map<String,Object> map:doctorList){
            participants.put(String.valueOf(map.get("id")), 0);
        }
@ -440,7 +431,7 @@ public class ConsultTeamService {
        //加入团队医生
        List<Map<String,Object>> doctorList = servicePackageService.fingdDoctorByPaitenId(patient,"preventLost");
        List<Map<String,Object>> doctorList = servicePackageService.fingdDoctorByPaitenId(patient);
        for(Map<String,Object> map:doctorList){
            participants.put(String.valueOf(map.get("id")), 0);
        }

+ 18 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/CarePatientService.java

@ -214,10 +214,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg,"修改成功");
        if(jsonObject1!=null){
            result = servicePackageService.servicePackageSign(jsonObject1.toJSONString(),doctorId,patientBrief.getId());
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.success) {
                servicePackageService.setPatientServiceItems(patientBrief.getId());
            }
//            result = servicePackageService.servicePackageSign(jsonObject1.toJSONString(),doctorId,patientBrief.getId());
        }
        return result;
    }
@ -571,4 +568,21 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
        }
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
    public void intiPatient(){
        String sql = "SELECT * from base_patient WHERE residential_area is not null and `password` is null";
        List<BasePatientDO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(BasePatientDO.class));
        for (BasePatientDO patient:list){
            patient.setEnabled(1);
            patient.setLocked(0);
            String salt = UUID.randomUUID().toString().substring(0,5);
            String idcard = patient.getIdcard();
            String  pw = idcard.substring(idcard.length()-6);
            patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
            patient.setSalt(salt);
        }
        patientDao.save(list);
    }
}

+ 109 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/patient/OnlineContactService.java

@ -0,0 +1,109 @@
package com.yihu.jw.care.service.patient;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/***
 * @ClassName: OnlineContactService
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/8/11 16:47
 */
@Service
public class OnlineContactService extends BaseJpaService<BasePatientDO, BasePatientDao> {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ImUtil imUtil;
    public JSONObject getOnLineObj(String patient){
        JSONObject obj = new JSONObject();
        String zlySql = "SELECT d.id,d.name,d.photo FROM base_doctor d,base_service_package_sign_record spsr\n" +
                "WHERE d.del = 1 AND d.doctor_level = 2 AND d.id = spsr.sign_doctor AND spsr.`status` = 1 AND spsr.patient = '"+patient+"'";
        String jsSql = "SELECT p.id,p.`name`,p.photo,pfm.family_relation familyRelation,p.archive_type\n" +
                "FROM base_patient_family_member pfm,base_patient p\n" +
                "WHERE pfm.del = 1 AND pfm.family_member = p.id AND p.patient_status = 1 AND pfm.patient = '"+patient+"'";
        String fwzSql = "SELECT o.`code`,o.`name`,o.photo,o.mobile,o.address\n" +
                "FROM base_doctor_hospital dh,base_org o,base_service_package_sign_record spsr\n" +
                "WHERE dh.del = 1 AND o.del = 1 AND spsr.`status` = 1 AND spsr.sign_doctor = dh.doctor_code\n" +
                "AND dh.org_code = o.`code` AND spsr.patient = '"+patient+"' GROUP BY o.`code`";
        List<Map<String,Object>> zlyList = jdbcTemplate.queryForList(zlySql);
        List<Map<String,Object>> jsList = jdbcTemplate.queryForList(jsSql);
        List<Map<String,Object>> fwzList = jdbcTemplate.queryForList(fwzSql);
        if (zlyList.size() > 0){
            for (int i=0;i<zlyList.size();i++){
                JSONObject helperObj = new JSONObject();
                helperObj.put("id",zlyList.get(i).get("id"));
                helperObj.put("name",zlyList.get(i).get("name"));
                helperObj.put("photo",zlyList.get(i).get("photo"));
                Integer onLineFlag =0;
                String onLineStr = imUtil.findByUserIdAndType(zlyList.get(i).get("id").toString(),"helper");
                JSONObject oneLineObj = JSONObject.parseObject(onLineStr);
                if (200 == oneLineObj.getInteger("status")){
                    if (oneLineObj.getInteger("data")>0){
                        onLineFlag=1;
                    }
                }
                helperObj.put("onLineFlag", onLineFlag);
                obj.put("helperObj",helperObj);
            }
        }
        if (jsList.size() > 0){
            for (int i=0;i<jsList.size();i++){
                JSONObject familyObj = new JSONObject();
                familyObj.put("id",jsList.get(i).get("id"));
                familyObj.put("name",jsList.get(i).get("name"));
                familyObj.put("photo",jsList.get(i).get("photo"));
                familyObj.put("familyRelation",jsList.get(i).get("familyRelation"));
                String archive_type = null;
                Integer onLineFlag =0;
                switch (jsList.get(i).get("archive_type").toString()){
                    case "1":
                        archive_type = "older";//老人
                        break;
                    case "2":
                        archive_type = "child";//新生儿
                        break;
                }
                if (StringUtils.isNotBlank(archive_type)){
                    String onLineStr = imUtil.findByUserIdAndType(jsList.get(i).get("id").toString(),archive_type);
                    JSONObject oneLineObj = JSONObject.parseObject(onLineStr);
                    if (200 == oneLineObj.getInteger("status")){
                        if (oneLineObj.getInteger("data")>0){
                            onLineFlag=1;
                        }
                    }
                }
                familyObj.put("onLineFlag", onLineFlag);
                obj.put("familyObj",familyObj);
            }
        }
        if (fwzList.size() > 0){
            for (int i=0;i<fwzList.size();i++){
                JSONObject serStationObj = new JSONObject();
                serStationObj.put("code",fwzList.get(i).get("code"));
                serStationObj.put("name",fwzList.get(i).get("name"));
                serStationObj.put("photo",fwzList.get(i).get("photo"));
                serStationObj.put("mobile",fwzList.get(i).get("mobile"));
                serStationObj.put("address",fwzList.get(i).get("address"));
                obj.put("serStationObj",serStationObj);
            }
        }
        return obj;
    }
}

+ 1 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/ArchiveService.java

@ -6,9 +6,7 @@ import com.yihu.jw.care.dao.sign.ArchiveDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.apply.PatientBedApplyDo;
import com.yihu.jw.entity.care.archive.ArchiveDO;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
@ -95,7 +93,7 @@ public class ArchiveService extends BaseJpaService<ArchiveDO, ArchiveDao> {
            filters += " and a.sign_status = "+signStatus;
        }
        if(StringUtils.isNotBlank(name)){
            filters += " and p.name like '%"+name+"%'";
            filters += " and (p.name like '%"+name+"%' or p.idcard like '%"+name+"%')";
        }
        if (signStatus!=null&&signStatus==1){//已签约不按建档查询,只要该居民服务医生就在列表中
            filters+=" UNION " +

+ 2 - 6
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/CapacityAssessmentRecordService.java

@ -143,8 +143,8 @@ public class CapacityAssessmentRecordService extends BaseJpaService<CapacityAsse
    }
    public PageEnvelop<List<Map<String,Object>>> assessmentPage(String doctorId,String patientId,String name,int type, int page, int size,
                    Integer status,Integer levelConclusion,Integer servicePackageStatus){
        String sql = "SELECT c.id,c.patient,c.assessment_time,c.service_package_status servicePackageStatus, " +
                    Integer status,Integer levelConclusion){
        String sql = "SELECT c.id,c.patient,c.assessment_time, " +
                "c.`status`,c.level_conclusion levelConclusion,c.org_code orgCode,c.org_name orgName,p.name,p.photo,p.mobile,p.sex,p.idcard  ";
        String countSql = "SELECT count(*) ";
@ -167,9 +167,6 @@ public class CapacityAssessmentRecordService extends BaseJpaService<CapacityAsse
        if(levelConclusion!=null){
            filters += " and c.level_conclusion = "+levelConclusion;
        }
        if(servicePackageStatus!=null){
            filters += " and c.service_package_status = "+servicePackageStatus;
        }
        if(!StringUtil.isEmpty(name)){
            filters += " and (c.name like '%"+name+"%' or c.idcard like '%"+name+"%') ";
        }
@ -183,7 +180,6 @@ public class CapacityAssessmentRecordService extends BaseJpaService<CapacityAsse
            map.put("assessmentTime", map.get("assessment_time").toString().substring(0,19));
            map.put("age", IdCardUtil.getAgeForIdcard(idcard));
            map.put("levelConclusionName",dictService.fingByNameAndCode(ConstantUtil.DICT_LEVEL_CONCLUSION,String.valueOf(map.get("levelConclusion"))));
            map.put("servicePackageStatusName",dictService.fingByNameAndCode(ConstantUtil.DICT_SERVICEPACKAGESTATUS,String.valueOf(map.get("servicePackageStatus"))));
            map.put("statusName",dictService.fingByNameAndCode(ConstantUtil.DICT_CAPACITY_AGREE_STATUS,String.valueOf(map.get("status"))));
        }
        Long count = jdbcTemplate.queryForObject(countSql+filters,Long.class);

+ 143 - 117
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/ServicePackageService.java

@ -14,7 +14,6 @@ import com.yihu.jw.entity.base.servicePackage.ServicePackageRecordDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
import com.yihu.jw.entity.care.apply.PatientBedApplyDo;
import com.yihu.jw.entity.care.archive.ArchiveDO;
import com.yihu.jw.entity.care.sign.CapacityAssessmentRecordDO;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientMedicardCardService;
@ -87,11 +86,11 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
                "FROM " +
                " base_service_package_sign_record sr, " +
                " base_service_package_record r, " +
                " base_service_package_item i, " +
                " base_service_package i, " +
                " base_org o " +
                "WHERE " +
                " sr.id = r.sign_id and sr.status=1 and sr.patient = '"+patient+"' " +
                "AND r.service_package_id = i.service_package_id " +
                "AND r.service_package_id = i.id " +
                "AND i.del = 1 " +
                "and i.org_code = o.code " +
                "AND sr.`status` = 1 ";
@ -120,12 +119,12 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
                "FROM " +
                " base_service_package_sign_record sr, " +
                " base_service_package_record r, " +
                " base_service_package_item i, " +
                " base_service_package i, " +
                " base_team_member m,base_doctor d  " +
                "WHERE " +
                " sr.id = r.sign_id and sr.status=1 and sr.patient = '"+patient+"'" +
                " AND r.service_package_id = i.service_package_id " +
                "AND i.del = 1 and m.team_code = i.team_code and m.doctor_code = d.id " +
                " AND r.service_package_id = i.id " +
                "AND i.del = 1  and m.team_code = r.team_code and sr.id=r.sign_id and m.doctor_code = d.id " +
                "               and m.del = '1'";
        if(StringUtils.isNoneBlank(orgCode)){
            sql += " and i.org_code = '"+orgCode+"' " ;
@ -134,39 +133,6 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        return list;
    }
    /**
     * 获取居民签约的服务项
     * @param patientId
     * @return
     */
    public List<String> getPatientServiceItems(String patientId){
        String key = "serviceItem:"+patientId;
        List<String> res;
        if(redisTemplate.hasKey(key)){
            long size = redisTemplate.opsForList().size(key);
            res = redisTemplate.opsForList().range(key,0,size);
        }else{
            res = fingServiceItemsCodeByPatientId(patientId);
            redisTemplate.opsForList().leftPushAll(key,res);
        }
        return res;
    }
    /**
     * 每次修改服务项重新设置res的服务项值
     * @param patientId
     */
    public void setPatientServiceItems(String patientId){
        String key = "serviceItem:"+patientId;
        if(redisTemplate.hasKey(key)){
            redisTemplate.delete(key);
        }
        List<String> res = fingServiceItemsCodeByPatientId(patientId);
        if(res!=null&&res.size()>0){
            redisTemplate.opsForList().leftPushAll(key,res);
        }
    }
    /**
     * 查找居民的签约服务项
@ -174,7 +140,7 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
     * @return
     */
    public List<Map<String,Object>> fingServiceItemsByPatientId(String patientId){
        String sql = "SELECT DISTINCT i.code,i.name,i.team_code from base_service_package_sign_record sr,base_service_package_record r, " +
        String sql = "SELECT DISTINCT i.code,i.name,r.team_code from base_service_package_sign_record sr,base_service_package_record r, " +
                " base_service_package_item i  where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
                "  and i.del = 1 and sr.`status`=1 and  sr.patient  = '"+patientId+"' ";
        return jdbcTemplate.queryForList(sql);
@ -216,10 +182,8 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
     * @param signId
     */
    public List<Map<String,Object>> fingdDoctorBySignId(String signId,Integer level){
        String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r, " +
                "base_service_package_item i,base_team_member m,base_doctor d " +
                "WHERE sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code and m.doctor_code = d.id " +
        String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r,base_team_member m,base_doctor d " +
                "WHERE sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id and m.doctor_code = d.id " +
                "and m.del = '1' and d.doctor_level = " + level+
                " and sr.id = '"+signId+"' ";
        return jdbcTemplate.queryForList(sql);
@ -229,29 +193,13 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
     * 根据居民和服务项查找医生
     * @param patientId
     */
    public List<Map<String,Object>> fingdDoctorByPaitenId(String patientId,String serviceItem){
        String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r,  " +
                "               base_service_package_item i,base_team_member m,base_doctor d  " +
                "               WHERE sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id  " +
                "               and i.del = 1 and m.team_code = i.team_code and m.doctor_code = d.id " +
                "               and m.del = '1' and sr.patient = '"+patientId+"' " +
                "and i.`code` = '"+serviceItem+"'";
    public List<Map<String,Object>> fingdDoctorByPaitenId(String patientId){
        String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r,base_team_member m,base_doctor d  " +
                "               WHERE sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id and m.doctor_code = d.id " +
                "               and m.del = '1' and sr.patient = '"+patientId+"' " ;
        return jdbcTemplate.queryForList(sql);
    }
    /**
     * 根据服务包id查找医生/助老员
     * @param packageId
     */
    public List<Map<String,Object>> fingdDoctorByPackageId(String packageId,Integer level){
        String sql = "SELECT DISTINCT d.id,d.name from base_service_package_record r, " +
                "base_service_package_item i,base_team_member m,base_doctor d " +
                "WHERE r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code and m.doctor_code = d.id " +
                "and m.del = '1' and d.doctor_level = " + level+
                " and r.id = '"+packageId+"' ";
        return jdbcTemplate.queryForList(sql);
    }
    /**
     * 根据签约记录查找服务包
@ -277,11 +225,9 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        String sql = "SELECT DISTINCT sr.patient,sr.id,sr.start_time,p.name,p.sex,p.idcard,p.openid,p.photo ";
        String countSql = "SELECT count(DISTINCT sr.patient) ";
        String filters = " from base_service_package_sign_record sr,base_service_package_record r, " +
                "base_service_package_item i,base_team_member m,base_patient p " +
                "WHERE sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code and p.id = sr.patient " +
                "and m.doctor_code = '"+doctorId+"' and m.del = '1' and sr.`status`=1 ";
        String filters = " from base_service_package_sign_record sr,base_service_package_record r,base_team_member m,base_patient p " +
                "WHERE  sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id and p.id = sr.patient " +
                "and m.doctor_code = '"+doctorId+"' and m.del = '1'  ";
        if(!StringUtil.isEmpty(name)){
            filters += " and sr.name like '%"+name+"%' ";
@ -309,11 +255,9 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
     * @return
     */
    public int getSignTotal(String doctorId){
        String sql = "SELECT COUNT(DISTINCT sr.patient) from base_service_package_sign_record sr,base_service_package_record r, " +
                "base_service_package_item i,base_team_member m " +
                "WHERE sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code " +
                "and m.doctor_code = '"+doctorId+"' and m.del = '1' and sr.`status`=1 ";
        String sql = "SELECT COUNT(DISTINCT sr.patient) from base_service_package_sign_record sr,base_service_package_record r,base_team_member m " +
                "WHERE sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id" +
                "and m.doctor_code = '"+doctorId+"' and m.del = '1' ";
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
@ -324,11 +268,12 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
     * @param doctorId
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject servicePackageSign(String jsonData,String doctorId,String patientId) throws Exception{
    public JSONObject servicePackageSign(String jsonData,String doctorId,String patientId,String signYear) throws Exception{
        BasePatientDO patientDO = patientDao.findById(patientId);
        JSONObject result = new JSONObject();
        ServicePackageSignRecordDO signRecordDO = objectMapper.readValue(jsonData, ServicePackageSignRecordDO.class);
        signRecordDO.setPatient(patientId);
        signRecordDO.setName(patientDO.getName());
        List<ServicePackageRecordDO> recordDOList = signRecordDO.getRecordDOList();
        String signId = signRecordDO.getId();
        List<String> idList = new ArrayList<>();
@ -338,9 +283,15 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
                BaseDoctorDO doctorDO = doctorDao.findById(doctorId);
                //需要新增签约记录
                signRecordDO.setStatus(1);
                int year;
                if("0".equals(signYear)){
                    year = 100;
                }else{
                    year = Integer.valueOf(signYear);
                }
                signRecordDO.setStartTime(new Date());
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.YEAR,1);
                cal.add(Calendar.YEAR,year);
                signRecordDO.setEndTime(cal.getTime());
                signRecordDO.setSignDoctor(doctorId);
                signRecordDO.setSignDoctorName(doctorDO.getName());
@ -354,15 +305,24 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
                    archiveDao.save(archiveDO);
                }
            }else{
                ArchiveDO archiveDO = archiveDao.findByPatientAndDoctorCode(patientId,doctorId);
                if(archiveDO!=null){
                    archiveDO.setSignStatus(1);
                    archiveDao.save(archiveDO);
                }
                signId = signRecordDOs.get(0).getId();
                List<ServicePackageRecordDO> existList = servicePackageRecordDao.findBySignId(signId);
                idList = existList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
                //不能重复签约
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                result.put(ResponseContant.resultMsg,"请勿重复签约");
                return result;
//                ArchiveDO archiveDO = archiveDao.findByPatientAndDoctorCode(patientId,doctorId);
//                if(archiveDO!=null){
//                    archiveDO.setSignStatus(1);
//                    archiveDao.save(archiveDO);
//                }
//                signId = signRecordDOs.get(0).getId();
//                List<ServicePackageRecordDO> existList = servicePackageRecordDao.findBySignId(signId);
//                idList = existList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
            }
        }else{
            //不能重复签约
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"请勿重复签约");
            return result;
        }
        //服务项目 emergencyAssistance 只能签约一个
@ -376,12 +336,12 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
            ServicePackageRecordDO recordDO = iterator.next();
            recordDO.setPatient(patientId);
            recordDO.setSignId(signId);
            if (idList.contains(recordDO.getServicePackageId())) {
                iterator.remove();//使用迭代器的删除方法删除
            }
//            if (idList.contains(recordDO.getServicePackageId())) {
//                iterator.remove();//使用迭代器的删除方法删除
//            }
        }
        if(recordDOList.size()>0){
/*        if(recordDOList.size()>0){
            List<String> packages = recordDOList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
            String packagesId = packages.stream().map(String::valueOf).collect(Collectors.joining("','"));
            sqlItem = "select item.`code`,item.name from base_service_package_item item " +
@ -392,10 +352,10 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
               String message = "重复签约服务项目:"+newItem.get("emergencyAssistance").get(0).get("name").toString();
               throw new Exception(message);
           }
        }
        CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
        capacityAssessmentRecordDO.setServicePackageStatus(1);
        capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
        }*/
//        CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
//        capacityAssessmentRecordDO.setServicePackageStatus(1);
//        capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
        servicePackageRecordDao.save(recordDOList);
        //修改床位生请状态为已完成
@ -410,15 +370,31 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        return result;
    }
    public List<ServicePackageDO> findServicePackageByOrgCode( String orgCode){
        String sql = "SELECT p.*  ";
        String filters = "from base_service_package p " +
                "WHERE p.del = 1 ";
        if(!StringUtil.isBlank(orgCode)){
            filters += " and p.org_code = '"+orgCode+"'";
        }
        filters += " ORDER BY p.create_time DESC ";
        List<ServicePackageDO> list = jdbcTemplate.query(sql+filters,new BeanPropertyRowMapper<>(ServicePackageDO.class));
        return list;
    }
    public PageEnvelop<List<Map<String,Object>>> servicePackagePage(int page, int size){
    public PageEnvelop<List<Map<String,Object>>> servicePackagePage(int page, int size,String orgCode){
        String sql = "SELECT p.id,p.`name`,p.type,p.introduce,p.num  ";
        String countSql = "SELECT count(*) ";
        String filters = "from base_service_package p " +
                "WHERE p.del = 1 ";
        if(!StringUtil.isBlank(orgCode)){
            filters += " and p.org_code = '"+orgCode+"'";
        }
        String orderBy = " ORDER BY p.create_time DESC " +
                "LIMIT "+ (page - 1) * size + "," + size;
@ -428,10 +404,6 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
            String id = map.get("id").toString();
            List<ServicePackageItemDO> itemDOList = servicePackageItemDao.findByServicePackageId(id);
            map.put("detail",itemDOList);
            List<Map<String,Object>> doctorList = fingdDoctorByPackageId(id,1);
            List<Map<String,Object>> helperList = fingdDoctorByPackageId(id,2);
            map.put("doctorList",doctorList);
            map.put("helperList",helperList);
        }
        Long count = jdbcTemplate.queryForObject(countSql+filters,Long.class);
        return PageEnvelop.getSuccessListWithPage("success",list,page,size,count);
@ -501,8 +473,7 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
    public List<Map<String, Object>> servicePackageByTopicType(String patient, String topicType)
    {
        String sql="\n" +
                "select  DISTINCT item.code serverItem,item.name,pack.introduce,pack.type packageType,pack.`name` packageName \n" +
        String sql="select  DISTINCT item.code serverItem,item.name,pack.introduce,pack.type packageType,pack.`name` packageName \n" +
                "from base_service_package_record re, base_service_package_item item,base_service_package pack \n" +
                "where re.service_package_id = item.service_package_id and item.service_package_id = pack.id\n" +
                " and pack.del=1 and  item.topic_item='"+topicType+"' and re.sign_id in (\n" +
@ -511,24 +482,11 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        return result;
    }
    public List<Map<String,Object>> getServerDoctorByPackage(String packageId,String serverItem){
        String sql="select DISTINCT doc.id doctor,CONCAT(doc.`name`,\n" +
                "CASE WHEN doc.doctor_level=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile\n" +
                "from base_service_package_item item ,base_service_package pack,base_team_member mem,base_doctor doc\n" +
                "where item.`code`='"+serverItem+"' and item.service_package_id='"+packageId+"' and item.service_package_id = pack.id " +
                "and item.team_code = mem.team_code and mem.doctor_code = doc.id and mem.del=1 and pack.del=1 ";
        List<Map<String,Object>>result = jdbcTemplate.queryForList(sql);
        return result;
    }
    public List<Map<String,Object>> getServerDoctorAll(String patient,String onlineFlag){
        String sql="select DISTINCT doc.id doctor,CONCAT(doc.`name`,CASE WHEN doc.doctor_level=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile,0 as onLineFlag\n" +
                "from base_service_package_item item ,base_service_package pack,base_team_member mem,base_doctor doc\n" +
                "where item.service_package_id in (\n" +
                "SELECT spc.service_package_id FROM base_service_package_record spc ,base_service_package_sign_record spsr\n" +
                "WHERE spc.patient = '"+patient+"' AND spsr.status = 1 AND spsr.patient = spc.patient\n" +
                ") and item.service_package_id = pack.id\n" +
                "and item.team_code = mem.team_code and mem.doctor_code = doc.id and mem.del=1 and pack.del=1 and item.del = 1";
        String sql="select DISTINCT doc.id doctor,CONCAT(doc.`name`,CASE WHEN doc.doctor_level=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile,0 as onLineFlag " +
                "from base_service_package_sign_record spsr,base_service_package_record r,base_team_member mem,base_doctor doc " +
                "WHERE spsr.patient = '"+patient+"' AND spsr.status = 1  " +
                "and r.team_code = mem.team_code and spsr.id=r.sign_id and mem.doctor_code = doc.id and mem.del=1 ";
        List<Map<String,Object>>result = jdbcTemplate.queryForList(sql);
        if ("1".equals(onlineFlag)){//展示是否在线
            String listStr = imUtil.getOnlineListByType("helper");
@ -582,4 +540,72 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
        }
        return jdbcTemplate.queryForList(sql);
    }
    /**
     * 查找居民签约记录
     * @param patient
     */
    public List<Map<String,Object>> findPatientSignList(String patient){
        String sql = "SELECT r.id,r.team_code teamCode,sr.id signId, DATE_FORMAT(sr.create_time,'%Y-%m-%d %H:%i:%S') createTime, " +
                " DATE_FORMAT(sr.start_time,'%Y-%m-%d %H:%i:%S')  startTime, " +
                " DATE_FORMAT(sr.end_time,'%Y-%m-%d %H:%i:%S') endTime,p.name,sr.`status`,p.org_code orgCode,p.org_name orgName " +
                "FROM " +
                " base_service_package_sign_record sr, " +
                " base_service_package_record r, " +
                " base_service_package p " +
                "WHERE " +
                " sr.id = r.sign_id and r.service_package_id = p.id " +
                "AND sr.patient = '"+patient+"' ORDER BY sr.create_time desc";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        String doctorSql = "SELECT d.name from base_team_member t,base_doctor d WHERE t.team_code = ? and t.doctor_code = d.id and d.del = 1 and t.del =1";
        for(Map<String,Object> map:list){
            List<String> doctorList = new ArrayList<>();
            if(map.get("teamCode")!=null){
                String teamCode = map.get("teamCode")+"";
                try {
                    doctorList = jdbcTemplate.queryForList(doctorSql,String.class, teamCode);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            map.put("doctorList",doctorList);
        }
        return list;
    }
    /**
     * 签约服务包详情
     * @param id
     */
    public Map<String,Object> signPackageDetail(String id){
        String orgSql = "SELECT o.id,o.code,o.name,o.address,o.photo FROM " +
                " base_org o, " +
                " base_service_package_record r, " +
                " base_service_package p " +
                "WHERE " +
                " p.org_code = o.code and r.service_package_id = p.id " +
                "AND r.id = '"+id+"' ";
        String doctorSql = "SELECT d.* from base_team_member t,base_doctor d,base_service_package_record r,base_service_package_sign_record sr" +
                " WHERE r.id = '"+id+"' and r.sign_id=sr.id and t.team_code = r.team_code and t.doctor_code = d.id and d.del = 1 and t.del =1";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(orgSql);
        Map<String,Object> result = list.get(0);
        List<BaseDoctorDO> doctorDOList = jdbcTemplate.query(doctorSql, new BeanPropertyRowMapper(BaseDoctorDO.class));
        result.put("doctorDOList",doctorDOList);
        return result;
    }
    /**
     * 签约服务包医生列表
     */
    public List<Map<String,Object>> signPackageDoctorList(String pateint){
        String sql = "SELECT d.id,d.name,d.photo,r.id detailId,h.org_code orgCode,h.org_name orgName,d.job_title_code jobTitleCode,d.job_title_name jobTitleName" +
                " from base_team_member t,base_doctor d,base_service_package_record r,base_service_package_sign_record sr" +
                ",base_doctor_hospital h" +
                " WHERE sr.patient = '"+pateint+"'and sr.status=1  and r.sign_id=sr.id and t.team_code = r.team_code " +
                " and t.doctor_code = d.id and d.del = 1 and t.del =1 and h.doctor_code = d.id and h.del=1";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
}