Переглянути джерело

Merge branch 'dev' of liubing/wlyy2.0 into dev

liubing 3 роки тому
батько
коміт
44f93b18c2

+ 4 - 1
common/common-entity/sql记录

@ -1786,4 +1786,7 @@ ALTER TABLE birthday_wishes_to_patient MODIFY COLUMN admin_team_code VARCHAR(50)
-- 2022-03-26
ALTER TABLE base_device_health_index add `temperature_value` varchar(20) DEFAULT NULL COMMENT '温度测量值';
ALTER TABLE base_device_health_index add `power_value` varchar(20) DEFAULT NULL COMMENT '剩余电量';
ALTER TABLE base_device_health_index add `at_id` varchar(50) DEFAULT NULL COMMENT 'at';
ALTER TABLE base_device_health_index add `at_id` varchar(50) DEFAULT NULL COMMENT 'at';
--2022-04-12
ALTER TABLE wlyy_role add column `level` tinyint(2) DEFAULT NULL COMMENT '1省2市3区县4机构5团队6医生'

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/role/DoctorRole.java

@ -20,6 +20,7 @@ public class DoctorRole extends IdEntity {
    private String name;        // 角色名称
    private String czy;       // 操作员
    private Date czrq;       // 操作日期
    private Integer level;       // 权限等级 同统计指标 1省2市3区县4机构5团队6医生
    @Column(name = "code")
    public String getCode() {
@ -57,4 +58,13 @@ public class DoctorRole extends IdEntity {
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
    @Column(name = "level")
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
}

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

@ -217,6 +217,7 @@ public class BaseRequestMapping {
        public static final String api_success ="success";
        public static final String saveRole ="/saveRole";
        public static final String findRoleNameExist ="/findRoleNameExist";
        public static final String wlyyUserRole ="/wlyyUserRole";
    }
    /**

+ 21 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/role/WlyyRoleDao.java

@ -0,0 +1,21 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.base.dao.role;
import com.yihu.jw.entity.care.role.DoctorRole;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface WlyyRoleDao extends PagingAndSortingRepository<DoctorRole, Long> {
    @Query(value = "select b.* from wlyy_user_role a,wlyy_role b where a.role = b.code and a.user = ?1",nativeQuery = true)
    List<DoctorRole> findUserRole(String user);
    DoctorRole findByCode(String code);
}

+ 22 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/role/WlyyUserRoleDao.java

@ -0,0 +1,22 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.base.dao.role;
import com.yihu.jw.entity.care.role.WlyyUserRole;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface WlyyUserRoleDao extends PagingAndSortingRepository<WlyyUserRole, Long> {
    @Modifying
    @Query("update WlyyUserRole r set r.role=?1 where r.id=?2")
    void modifyRoleById(String role,Long id);
    @Query("select r from WlyyUserRole r where r.user=?1 and r.role=?2")
    WlyyUserRole findByUserAndRole(String user,String role);
}

+ 108 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/role/WlyyUserRoleEndpoint.java

@ -0,0 +1,108 @@
package com.yihu.jw.base.endpoint.role;
import com.yihu.jw.base.service.role.WlyyUserRoleService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
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.*;
/**
 * Created by Bing on 2022/4/12.
 *  hz医养管理员角色管理
 */
@RestController
@RequestMapping(value = BaseRequestMapping.Role.wlyyUserRole)
@Api(value = "hz医养角色管理", description = "hz医养角色管理", tags = {"wlyy基础服务 - hz医养角色管理"})
public class WlyyUserRoleEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private WlyyUserRoleService wlyyUserRoleService;
    @GetMapping("getAdminList")
    @ApiOperation("获取管理员列表")
    public PageEnvelop getAdminList(@ApiParam(name = "name",value = "姓名")
                                    @RequestParam(value = "name",required = false)String name,
                                    @ApiParam(name = "idcard",value = "身份证")
                                    @RequestParam(value = "idcard",required = false)String idcard,
                                    @ApiParam(name = "mobile",value = "手机号")
                                    @RequestParam(value = "mobile",required = false)String mobile,
                                    @ApiParam(name = "page",value = "page")
                                        @RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                                    @ApiParam(name = "size",value = "手机号")
                                        @RequestParam(value = "size",required = false,defaultValue = "15")Integer size){
        try {
            return wlyyUserRoleService.getAdminList(name,idcard,mobile,page,size);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @GetMapping("getRoleList")
    @ApiOperation("获取权限列表")
    public ObjEnvelop getAdminList(
                                    @ApiParam(name = "level",value = "管理权限等级 1省2市(街道) 3区县4机构5团队(社区)6医生")
                                    @RequestParam(value = "level",required = false,defaultValue = "2")String level){
        try {
            return ObjEnvelop.getSuccess("success",wlyyUserRoleService.getRoleList(level)) ;
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping("delUserRole")
    @ApiOperation("删除角色权限")
    public Envelop delUserRole(@ApiParam(name="id")@RequestParam(value = "id")String id){
        try {
            wlyyUserRoleService.delete(Long.valueOf(id));
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping("modifyUserRole")
    @ApiOperation("修改角色权限信息")
    public Envelop modifyUserRole(@ApiParam(name="id")@RequestParam(value = "id")String id,
                                  @ApiParam(name="role")@RequestParam(value = "role")String role){
        try {
            Integer result =  wlyyUserRoleService.modifyUserRole(id,role);
            if (-1==result){
                return Envelop.getError("不存在该管理权限");
            }if (-2==result){
                return Envelop.getError("未查询此条管理权限,无法修改");
            }
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping("saveUserRole")
    @ApiOperation("新增用户权限")
    public Envelop saveUserRole(@ApiParam(name="json")@RequestParam(value = "json")String json){
        try {
            Integer result =  wlyyUserRoleService.saveUserRole(json);
            return success();
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @GetMapping("getUserRoleById")
    @ApiOperation("根据id获取权限详情")
    public ObjEnvelop getUserRoleById(@ApiParam(name="id")@RequestParam(value = "id")String id){
        try {
            return ObjEnvelop.getSuccess("success",wlyyUserRoleService.getUserRoleById(id));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
}

+ 119 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/role/WlyyUserRoleService.java

@ -0,0 +1,119 @@
package com.yihu.jw.base.service.role;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.base.dao.role.WlyyRoleDao;
import com.yihu.jw.base.dao.role.WlyyUserRoleDao;
import com.yihu.jw.entity.care.role.DoctorRole;
import com.yihu.jw.entity.care.role.WlyyUserRole;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Created by Bing on 2022/4/12.
 */
@Service
public class WlyyUserRoleService extends BaseJpaService<WlyyUserRole, WlyyUserRoleDao> {
    @Autowired
    private WlyyRoleDao wlyyRoleDao;
    @Autowired
    private WlyyUserRoleDao wlyyUserRoleDao;
    /**
     * 获取管理员列表
     * @return
     */
    public PageEnvelop<List<Map<String,Object>>> getAdminList(String name,String idcard,String mobile,Integer page,Integer size){
        page = page>0?page-1:0;
        String sql = " select ur.id,doc.name,doc.idcard,doc.id doctorCode,doc.mobile,ur.role,wr.code,wr.name roleName,wr.level from base_doctor doc " +
                " INNER JOIN wlyy_user_role ur on doc.id = ur.`user` INNER JOIN wlyy_role wr on ur.role = wr.`code` where 1=1 " ;
        String sqlCount = " select count(ur.id) from base_doctor doc " +
                " INNER JOIN wlyy_user_role ur on doc.id = ur.`user` INNER JOIN wlyy_role wr on ur.role = wr.`code` where 1=1 ";
        String filter  = " ";
        if (StringUtils.isNotBlank(name)){
            filter += " and doc.`name`like '%"+name+"%' ";
        }
        if (StringUtils.isNotBlank(idcard)){
            filter += " and doc.idcard like '%"+idcard+"%' ";
        }
        if (StringUtils.isNotBlank(mobile)){
            filter += " and doc.mobile like '%"+mobile+"%' ";
        }
        Long count = jdbcTemplate.queryForObject(sqlCount+filter,Long.class);
        filter += " order by doc.id asc limit "+page*size+","+size;
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql+filter);
        return PageEnvelop.getSuccessListWithPage("success",list,page,size,count);
    }
    /**
     *修改管理员权限
     */
    @Transactional
    public Integer modifyUserRole(String id,String role){
        DoctorRole doctorRole = wlyyRoleDao.findByCode(role);
        if (null==doctorRole){
            return -1;
        }
        WlyyUserRole wlyyUserRole = wlyyUserRoleDao.findOne(Long.valueOf(id));
        if (null==wlyyUserRole){
            return -2;
        }
        wlyyUserRoleDao.modifyRoleById(role,Long.valueOf(id));
        return 1;
    }
    /**
     * 保存新增权限
     */
    public Integer saveUserRole(String json){
        List<WlyyUserRole> userRoles = JSON.parseArray(json,WlyyUserRole.class);
        List<WlyyUserRole> saveRoles = new ArrayList<>();
        if (userRoles.size()>0){
            for (WlyyUserRole tmp:userRoles){
                if (null!= wlyyRoleDao.findByCode(tmp.getRole())){
                    if (null == wlyyUserRoleDao.findByUserAndRole(tmp.getUser(),tmp.getRole())){
                        saveRoles.add(tmp);
                    }
                }
            }
        }
        if (saveRoles.size()>0){
            wlyyUserRoleDao.save(saveRoles);
        }
        return 1;
    }
    /**
     * 获取权限列表
     * @param level 管理权限等级 1省2市(街道) 3区县4机构5团队(社区)6医生
     * @return
     */
    public  List<Map<String,Object>> getRoleList(String level){
        String sql = " select * from wlyy_role where 1=1 ";
        if (StringUtils.isNotBlank(level)){
            sql += " and level='"+level+"' ";
        }
        return jdbcTemplate.queryForList(sql);
    }
    /**
     *根据id获取权限详情
     */
    public Map<String,Object> getUserRoleById(String id){
        String sql = " select ur.id,doc.name,doc.idcard,doc.id doctorCode,doc.mobile,ur.role,wr.code,wr.name roleName,wr.level from base_doctor doc " +
                " INNER JOIN wlyy_user_role ur on doc.id = ur.`user` INNER JOIN wlyy_role wr on ur.role = wr.`code` where ur.id='"+id+"' " ;
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if (list.size()>0){
            return list.get(0);
        }
        return null;
    }
}

+ 27 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/doctor/admin/AdminInfoEndpoint.java

@ -298,8 +298,11 @@ public class AdminInfoEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "getOlderTeamListWithPage")
    @ApiOperation("获取养老服务社区团队列表")
    public PageEnvelop getOlderTeamListWithPage(@ApiParam(name="page",value = "页码",required = true)
                                       @RequestParam(value = "page",required = true,defaultValue = "1") Integer page,
    public PageEnvelop getOlderTeamListWithPage(
                                        @RequestParam(required = false,defaultValue = "330100") String area,
                                        @RequestParam(required = false,defaultValue = "2") String level,
                                        @ApiParam(name="page",value = "页码",required = true)
                                        @RequestParam(value = "page",required = true,defaultValue = "1") Integer page,
                                        @ApiParam(name="size",value = "分页大小",required = true)
                                        @RequestParam(value = "size",required = true,defaultValue = "5") Integer size){
        try {
@ -309,10 +312,31 @@ public class AdminInfoEndpoint extends EnvelopRestEndpoint {
            if(permissionService.noPermission(0,param)){
                return PageEnvelop.getError("该操作没有权限");
            }
            return statisticsService.getOlderTeamListWithPage(page,size);
            return statisticsService.getOlderTeamListWithPage(area,level,page,size);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }
    }
    @GetMapping(value = "statisticsSecurityOlder")
    @ApiOperation(value = "管理端首页安防预警统计分析")
    public ObjEnvelop statisticsSecurityOlder(
            @RequestParam(required = true) String endDate,
            @RequestParam(required = true) String area,
            @RequestParam(required = true) int level,
            @ApiParam(name="type",value="类型:1本周,2本月",defaultValue = "")@RequestParam(required = false) String type) {
        try {
            JSONObject param = new JSONObject();
            String doctorId =  permissionService.getUID();
            param.put("doctorId",doctorId);
            if(permissionService.noPermission(0,param)){
                return ObjEnvelop.getError("该操作没有权限");
            }
            JSONObject result = statisticsService.statisticsSecurityOlder(endDate,area,level, type);
            return success(result);
        } catch (Exception e) {
            return failedObjEnvelopException2(e);
        }
    }
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/statistics/OpenStatisticsEndpoint.java

@ -408,7 +408,7 @@ public class OpenStatisticsEndpoint extends EnvelopRestEndpoint {
                                                @ApiParam(name="size",value = "分页大小",required = true)
                                                @RequestParam(value = "size",required = true,defaultValue = "5") Integer size){
        try {
            return statisticsService.getOlderTeamListWithPage(page,size);
            return statisticsService.getOlderTeamListWithPage(null,null,page,size);
        }catch (Exception e){
            return failedPageEnvelopException2(e);
        }

+ 2 - 17
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/statistics/StatisticsEndpoint.java

@ -211,29 +211,14 @@ public class StatisticsEndpoint extends EnvelopRestEndpoint {
    @GetMapping("olderBindingDeviceStatus")
    @ApiOperation("管理端首页老人接入情况")
    public ObjEnvelop olderBindingDeviceStatus(@RequestParam(required = false) String area,
                                               @RequestParam(required = false) Integer level){
                                               @RequestParam(required = false) String level){
        try {
            return ObjEnvelop.getSuccess("查询成功",statisticsService.olderBindingDeviceStatus(area));
            return ObjEnvelop.getSuccess("查询成功",statisticsService.olderBindingDeviceStatus(area,level));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "statisticsSecurityOlder")
    @ApiOperation(value = "管理端首页安防监护统计分析")
    public ObjEnvelop statisticsSecurityOlder(
            @RequestParam(required = true) String endDate,
            @RequestParam(required = true) String area,
            @RequestParam(required = true) int level,
            @ApiParam(name="type",value="类型:1本周,2本月",defaultValue = "")@RequestParam(required = false) String type) {
        try {
            JSONObject result = statisticsService.statisticsSecurityOlder(endDate,area,level, type);
            return success(result);
        } catch (Exception e) {
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "deviceGrantAndService")
    @ApiOperation("设备分析--投放、照护类型")
    public ObjEnvelop deviceGrantAndService(@RequestParam(required = false) String area,

+ 56 - 23
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/role/RoleService.java

@ -13,6 +13,7 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.care.role.DoctorRole;
import com.yihu.jw.entity.care.role.DoctorRoleRealm;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -85,8 +86,8 @@ public class RoleService extends BaseJpaService<DoctorRole, DoctorRoleDao> {
        int resultLevel = 5;
        for (DoctorRole one : roleList) {
            if(resultLevel>roleConverse(one.getCode())){
                resultLevel=roleConverse(one.getCode());
            if(resultLevel>one.getLevel()){
                resultLevel=one.getLevel();
            }
        }
        if (roleList != null && roleList.size() > 0) {
@ -96,9 +97,9 @@ public class RoleService extends BaseJpaService<DoctorRole, DoctorRoleDao> {
                map.put("code", role.getCode());
                map.put("name", role.getName());
                map.put("areas", "");
                map.put("level",roleConverse(role.getCode())+"");
                map.put("level",role.getLevel()+"");
                map.put("isManage", "1");
                if(resultLevel==roleConverse(role.getCode())){
                if(resultLevel==role.getLevel()){
                    map.put("high", "1");
                }else{
                    map.put("high", "0");
@ -110,25 +111,25 @@ public class RoleService extends BaseJpaService<DoctorRole, DoctorRoleDao> {
        return re;
    }
    /**
     * 角色code转成角色级别
     * @param roleCode 角色code
     * @return 1、省级,2、市级,3、区级,4、机构
     */
    public Integer roleConverse(String roleCode){
        if(roleCode.length()==6){
            if("0".equals(roleCode.substring(3,4))){
                return 1;
            }else if("00".equals(roleCode.substring(4))){
                return 2;
            }else{
                return 3;
            }
        }else{
            return 4;
        }
    }
//    /**
//     * 角色code转成角色级别
//     * @param roleCode 角色code
//     * @return 1、省级,2、市级,3、区级,4、机构
//     */
//    public Integer roleConverse(String roleCode){
//
//        if(roleCode.length()==6){
//            if("0".equals(roleCode.substring(3,4))){
//                return 1;
//            }else if("00".equals(roleCode.substring(4))){
//                return 2;
//            }else{
//                return 3;
//            }
//        }else{
//            return 4;
//        }
//    }
    public Map<String,Object> findManageUserRole(String doctor){
        String sql ="SELECT " +
@ -161,4 +162,36 @@ public class RoleService extends BaseJpaService<DoctorRole, DoctorRoleDao> {
                " r.code = 'dispatcher'";
        return jdbcTemplate.queryForList(sql);
    }
    /**
     * 获取管理员权限与老人数据相关sql
     * @param area
     * @param level
     * @return
     */
    public String getOlderRoleSQL(String area,String level){
        String areaFilter = "";
        String olderFilter = "";
        if (StringUtils.isNotBlank(area)){
            if ("330100".equals(area)){
                return "";
            }else {
                if ("4".equals(level)){
                    areaFilter = " and pack.org_code='"+area+"' ";
                }
                if ("5".equals(level)){//团队
                    areaFilter = " and r.team_code='"+area+"' ";
                }
                if ("4".equals(level)||"5".equals(level)){
                    olderFilter = " and EXISTS ( select 1 from  " +
                            " base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack " +
                            " where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id  and i.del = 1 " +
                            " and sr.`status`=1 and CONVERT(sr.patient USING utf8)  = {patient} " +
                            " and CONVERT(sr.patient USING utf8) not in (SELECT dict_code FROM `base`.`wlyy_hospital_sys_dict` WHERE `dict_name` = 'jkzl_older' or dict_name='jkzl_child') "+areaFilter+" ) ";
                }
            }
        }
        return olderFilter;
    }
}

+ 40 - 29
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/StatisticsService.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.service.patient.CarePatientService;
import com.yihu.jw.care.service.role.RoleService;
import com.yihu.jw.care.util.CommonUtil;
import com.yihu.jw.care.util.ConstantUtil;
import com.yihu.jw.care.vo.NumVo;
@ -83,6 +84,8 @@ public class StatisticsService {
    private String esType;
    @Autowired
    private CarePatientService carePatientService;
    @Autowired
    private RoleService roleService;
    private static final String defalutArea = "330100";
@ -1368,23 +1371,27 @@ public class StatisticsService {
    /**
     * 管理端首页老人接入情况,关联家属
     *
     * @param area 权限范围
     * @param level 1省2市3区县4机构5团队6医生
     * @return
     */
    public JSONObject olderBindingDeviceStatus(String area) {
    public JSONObject olderBindingDeviceStatus(String area,String level) {
        JSONObject result = new JSONObject();
        String filter = "";
        String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_child' or dict_name = 'jkzl_older' ";
        List<Map<String, Object>> listtmp = jdbcTemplate.queryForList(sqltmp);
        if (listtmp.size() > 0) {
            String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
            orgCodes = orgCodes.replaceAll(",", "','");
            filter = " not in ('" + orgCodes + "')";
        }
        String sql = " select count(id) from base_patient  where del=1 and archive_type=1 and id " + filter;
        String olderFilter = roleService.getOlderRoleSQL(area,level);
//        String filter = "";
//        String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_child' or dict_name = 'jkzl_older' ";
//        List<Map<String, Object>> listtmp = jdbcTemplate.queryForList(sqltmp);
//        if (listtmp.size() > 0) {
//            String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
//            orgCodes = orgCodes.replaceAll(",", "','");
//            filter = " not in ('" + orgCodes + "')";
//        }
        String sql = " select count(p.id) from base_patient p  where p.del=1 and p.archive_type=1 " + olderFilter.replace("{patient}","p.id");
        Integer olderCount = jdbcTemplate.queryForObject(sql, Integer.class);
        sql = " select count(DISTINCT p.id) from base_patient p INNER JOIN wlyy_patient_device pd on p.id = pd.user and p.archive_type=1 and pd.del=0 where p.del=1 and p.id " + filter;
        sql = " select count(DISTINCT p.id) from base_patient p INNER JOIN wlyy_patient_device pd on p.id = pd.user and p.archive_type=1 and pd.del=0 where p.del=1  "+
                olderFilter.replace("{patient}","p.id");
        Integer bindingCount = jdbcTemplate.queryForObject(sql, Integer.class);
        //老人接入情况
        result.put("olderCount", olderCount);
@ -1393,18 +1400,13 @@ public class StatisticsService {
        //关联家属
        String sqlfamily = "SELECT COUNT(DISTINCT p.id)  FROM " +
                "base_patient p INNER JOIN base_service_package_sign_record sr " +
                "on p.id = sr.patient and sr.`status`=1 and  p.id not in " +
                "(SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_child' or dict_name = 'jkzl_older') " +
                ",(SELECT DISTINCT fm.family_member from base_patient_family_member fm,base_patient p1 " +
                "base_patient p , (SELECT DISTINCT fm.family_member from base_patient_family_member fm,base_patient p1 " +
                "WHERE p1.id = fm.patient and p1.archive_type = '3') f1 " +
                "WHERE p.del = 1 and p.archive_type =1 and p.id = f1.family_member ";
                "WHERE p.del = 1 and p.archive_type =1 and p.id = f1.family_member "+olderFilter.replace("{patient}","p.id");
        String sqlSign = "SELECT COUNT(DISTINCT p.id) FROM " +
                "base_patient p INNER JOIN base_service_package_sign_record sr " +
                "on p.id = sr.patient and sr.`status`=1 and  p.id not in " +
                "(SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_child' or dict_name = 'jkzl_older') " +
                "WHERE p.del = 1 and p.archive_type =1 ";
                "base_patient p "+
                "WHERE p.del = 1 and p.archive_type =1 "+olderFilter.replace("{patient}","p.id");
        Integer familyOlderCount = jdbcTemplate.queryForObject(sqlfamily, Integer.class);
        Integer familySignCount = jdbcTemplate.queryForObject(sqlSign, Integer.class);
@ -1416,18 +1418,18 @@ public class StatisticsService {
    }
    /**
     * 管理端安防监护新增分析
     * 管理端首页安防预警统计分析
     */
    public JSONObject statisticsSecurityOlder(String endDate, String area, int level, String type) throws Exception {
        JSONObject res = new JSONObject();
        String areaLevel = "4";
        areaLevel = "4";
        SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel0(endDate, endDate, area, level, "46", SaveModel.timeLevel_DDL, areaLevel);
        SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevels(endDate, endDate, area, level, "46", SaveModel.timeLevel_DDL, null, null, "-2,0,1" );
        res.put("index_" + 46 + "_total", saveModel.getResult2().longValue());
        if (StringUtils.isNotBlank(type)) {
            //周/月 增量
            String start = statisticsUtilService.calStart(endDate, type);
            SaveModel saveModelAdd = elasticsearchUtil.findOneDateQuotaLevel0(start, endDate, area, level, "46", SaveModel.timeLevel_ZL, areaLevel);
            SaveModel saveModelAdd = elasticsearchUtil.findOneDateQuotaLevels(start, endDate, area, level, "46", SaveModel.timeLevel_ZL, null,null,"-2,0,1");
            res.put("index_" + 46 + "_add", saveModelAdd.getResult2().longValue());
        }
        JSONArray addDetail = new JSONArray();
@ -1435,16 +1437,25 @@ public class StatisticsService {
            //周/月 增量
            String start = statisticsUtilService.calStart(endDate, type);
            List<SaveModel> saveModelAdds = elasticsearchUtil.findDateQuotaLevelList(start, endDate, area, level, "46", SaveModel.timeLevel_ZL, null,null,"3", null, null, null);
            List<SaveModel> saveModelAdds = elasticsearchUtil.findDateQuotaLevelList(start, endDate, area, level, "46", SaveModel.timeLevel_ZL, null,null,"3", null, "-2,0,1" );
            for (SaveModel saveModelTmp : saveModelAdds) {
                JSONObject json = new JSONObject();
                SaveModel saveMode2 = elasticsearchUtil.findOneDateQuotaLevels(endDate, endDate, area, level, "46", SaveModel.timeLevel_DDL, "3", null, null, saveModelTmp.getSlaveKey3());
                SaveModel saveMode2 = elasticsearchUtil.findOneDateQuotaLevels(endDate, endDate, area, level, "46", SaveModel.timeLevel_DDL, "3", null, "-2,0,1", saveModelTmp.getSlaveKey3());
                json.put("total", saveMode2.getResult2().longValue());
                json.put("num", saveModelTmp.getResult2().longValue());
                json.put("code", saveModelTmp.getSlaveKey3());
                json.put("name", saveModelTmp.getSlaveKey3Name());
                addDetail.add(json);
            }
            SaveModel saveMode2 = elasticsearchUtil.findOneDateQuotaLevels(endDate, endDate, area, level, "53", SaveModel.timeLevel_DDL, null, null, "-2,0,1" );
            SaveModel saveModelTmp = elasticsearchUtil.findOneDateQuotaLevels(start, endDate, area, level, "53", SaveModel.timeLevel_ZL, null, null, "-2,0,1" );
            JSONObject json = new JSONObject();
            json.put("total", saveMode2.getResult2().longValue());
            json.put("num", saveModelTmp.getResult2().longValue());
            json.put("code", "jjhj");
            json.put("name", "紧急呼叫");
            addDetail.add(json);
            System.out.println("1");
        }
        res.put("index_add_detail", addDetail);
        return res;
@ -2397,7 +2408,7 @@ public class StatisticsService {
    }
    public PageEnvelop<List<Map<String,Object>>> getOlderTeamListWithPage(Integer page,Integer size) throws Exception {
    public PageEnvelop<List<Map<String,Object>>> getOlderTeamListWithPage(String area,String level,Integer page,Integer size) throws Exception {
        List<Map<String,Object>> teamList  = new ArrayList<>();
        page = page>0?page-1:0;
        String sql = " select count(distinct org.code) from " +

+ 29 - 20
svr/svr-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/compute/ComputeHelper.java

@ -223,7 +223,7 @@ public class ComputeHelper {
    /**
     * 得到全部医生
     *
     * @return
     * @returncount(distinct
     */
    private List<Map<String,Object>> findAllTeam(String orgType) {
        String sql = " SELECT " +
@ -254,24 +254,27 @@ public class ComputeHelper {
     * @return
     */
    private List<BaseDoctorDO> findAllDoctor(String orgType) {
        String sql = "SELECT " +
                "bd.id AS code , " +
                "bd.name ," +
                "bdh.dept_code," +
                "hd.name AS dept_name," +
                "bdh.org_code," +
                "bdh.org_name," +
                "o.town_code," +
                "o.town_name" +
        String sql = " SELECT" +
                " bd.id AS CODE," +
                " bd.NAME, " +
                " bt.id as dept_code, " +
                " bt.name AS dept_name, " +
                " o.code as org_code, " +
                " o.name as org_name, " +
                " o.town_code, " +
                " o.town_name  " +
                " FROM " +
                "base_doctor_hospital bdh, " +
                "base_doctor bd," +
                "base_org o," +
                "dict_hospital_dept hd " +
                " WHERE bdh.doctor_code = bd.id  " +
                "AND hd.code= bdh.dept_code " +
                "AND o.code = bdh.org_code " +
                "AND bdh.del=1 and o.del=1 and o.code not in(SELECT dict_code FROM `base`.`wlyy_hospital_sys_dict` WHERE `dict_name` = 'jkzl_org')";
                " base_doctor bd, " +
                " base_org o, " +
                " base_team bt, " +
                " base_team_member btm  " +
                " WHERE " +
                " btm.doctor_code = bd.id  " +
                " AND o.CODE = bt.org_code " +
                " and bt.id = btm.team_code " +
                " AND btm.del = 1  " +
                " AND o.del = 1  " +
                " AND o.CODE NOT IN ( SELECT dict_code  FROM `base`.`wlyy_hospital_sys_dict`  WHERE `dict_name` = 'jkzl_org') ";
        if(StringUtils.isNotBlank(orgType)){
            sql += " and o.type = '"+orgType+"'";
        }
@ -288,7 +291,7 @@ public class ComputeHelper {
        //初始化医生的数据
        for (int i = 0; i < teams.size(); i++) {
            Map<String,Object> teamDO = teams.get(i);
                Map<String,Object> teamDO = teams.get(i);
            //排除测试机构
            SaveModel saveModel = new SaveModel();
            saveModel.setCity("330100");
@ -395,7 +398,13 @@ public class ComputeHelper {
            saveModel.setDoctor(one.getCode());
            saveModel.setDoctorName(one.getName());
            saveModel.setDept(one.getDeptCode());
            saveModel.setDeptName(one.getDeptName());
            String deptName = one.getDeptName();
            deptName = deptName.replace("团队","社区");
            deptName = deptName.replace("服务","");
            if(!deptName.contains("社区")){
                deptName = deptName+"社区";
            }
            saveModel.setDeptName(deptName);
            saveModel.setQuotaCode(wlyyJobCongId);
            saveModel.setCreateTime(new Date());
            saveModel.setTimeLevel(timeLevel);