Browse Source

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

Conflicts:
	common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationTemplateDetailDO.java
yeshijie 3 năm trước cách đây
mục cha
commit
b85c898dc8

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

@ -0,0 +1,60 @@
package com.yihu.jw.entity.care.role;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.iot.gateway.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.util.Date;
/**
 * 医生角色
 */
@Entity
@Table(name = "wlyy_role")
@SequenceGenerator(name="id_generated", sequenceName="wlyy_role")
public class DoctorRole extends IdEntity {
    private String code;        // 角色编码
    private String name;        // 角色名称
    private String czy;       // 操作员
    private Date czrq;       // 操作日期
    @Column(name = "code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "czy")
    public String getCzy() {
        return czy;
    }
    public void setCzy(String czy) {
        this.czy = czy;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "czrq")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 42 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/role/DoctorRoleRealm.java

@ -0,0 +1,42 @@
package com.yihu.jw.entity.care.role;
import com.yihu.jw.entity.iot.gateway.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
 * 医生角色权限区域
 **/
@Entity
@Table(name = "wlyy_role_area")
@SequenceGenerator(name="id_generated", sequenceName="wlyy_role_area")
public class DoctorRoleRealm extends IdEntity {
    // 角色编码
    private String roleCode;
    // 区域编码
    private String areaCode;
    @Column(name = "role_code")
    public String getRoleCode() {
        return roleCode;
    }
    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }
    @Column(name = "area_code")
    public String getAreaCode() {
        return areaCode;
    }
    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }
}

+ 61 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/role/WlyyUserRole.java

@ -0,0 +1,61 @@
package com.yihu.jw.entity.care.role;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.iot.gateway.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.util.Date;
/**
 * 医生角色
 */
@Entity
@Table(name = "wlyy_user_role")
@SequenceGenerator(name="id_generated", sequenceName="wlyy_user_role")
public class WlyyUserRole extends IdEntity {
    private String user;    // 用户编码
    private String role;    // 角色编码
    private String czy;     // 操作员
    private Date czrq;      // 操作日期
    @Column(name = "user")
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }
    @Column(name = "role")
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
    public String getCzy() {
        return czy;
    }
    @Column(name = "czy")
    public void setCzy(String czy) {
        this.czy = czy;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "czrq")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 19 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/role/DoctorRoleDao.java

@ -0,0 +1,19 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.care.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 DoctorRoleDao 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);
}

+ 17 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/role/DoctorRoleRealmDao.java

@ -0,0 +1,17 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.care.dao.role;
import com.yihu.jw.entity.care.role.DoctorRoleRealm;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface DoctorRoleRealmDao extends PagingAndSortingRepository<DoctorRoleRealm, Long> {
    List<DoctorRoleRealm> findByRoleCode(String roleCode);
}

+ 15 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/role/UserRoleDao.java

@ -0,0 +1,15 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.care.dao.role;
import com.yihu.jw.entity.care.role.WlyyUserRole;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface UserRoleDao extends PagingAndSortingRepository<WlyyUserRole, Long> {
}

+ 4 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/doctor/DoctorEndpoint.java

@ -53,9 +53,11 @@ public class DoctorEndpoint extends EnvelopRestEndpoint {
    @ApiOperation(value = "获取医生详情")
    public ObjEnvelop doctorInfo (
            @ApiParam(name = "doctorId", value = "医生id", required = true)
            @RequestParam(value = "doctorId",required = true) String doctorId) throws Exception {
            @RequestParam(value = "doctorId",required = true) String doctorId,
            @ApiParam(name = "isRole", value = "是否返回角色(1是 0否)", required = false)
            @RequestParam(value = "isRole",required = false) String isRole) throws Exception {
        try{
            return ObjEnvelop.getSuccess("查询成功",doctorService.doctorInfo(doctorId));
            return ObjEnvelop.getSuccess("查询成功",doctorService.doctorInfo(doctorId,isRole));
        }catch (Exception e){
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败");

+ 16 - 7
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/doctor/CareDoctorService.java

@ -1,5 +1,6 @@
package com.yihu.jw.care.service.doctor;
import com.yihu.jw.care.service.role.RoleService;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.DoctorSpecialDiseaseDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -34,21 +35,29 @@ public class CareDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
    private StringRedisTemplate redisTemplate;
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private RoleService roleService;
    /**
     * 获取医生详情
     * @return
     */
    public Map<String,Object> doctorInfo(String doctorId){
    public Map<String,Object> doctorInfo(String doctorId,String isRole){
        String sql = "SELECT d.id,d.name,d.photo,d.introduce,d.mobile,d.idcard,d.sex,h.dept_code deptCode,h.dept_name deptName,d.job_title_code jobTitleCode,d.job_title_name jobTitleName ";
        sql += "from base_doctor d left join base_doctor_hospital h on d.id = h.doctor_code  and h.del = 1" +
                "WHERE d.id = '"+doctorId+"' ";
        sql += " ,h.org_code orgCode,h.org_name orgName from base_doctor d left join base_doctor_hospital h on d.id = h.doctor_code  and h.del = 1" +
                " WHERE d.id = '"+doctorId+"' limit 1 ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        for (Map<String,Object> map :list){
            String idcard = map.get("idcard").toString();
            map.put("age", IdCardUtil.getAgeForIdcard(idcard));
        Map<String,Object> map = list.get(0);
        String idcard = map.get("idcard").toString();
        map.put("age", IdCardUtil.getAgeForIdcard(idcard));
        if("1".equals(isRole)){
            //获取医生角色和区域权限
            List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(map.get("id").toString());
            map.put("userRole", roleMap);
        }
        return list.get(0);
        return map;
    }
    /**

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

@ -0,0 +1,218 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.jw.care.service.role;
import com.yihu.jw.care.dao.role.DoctorRoleDao;
import com.yihu.jw.care.dao.role.DoctorRoleRealmDao;
import com.yihu.jw.care.service.doctor.CareDoctorService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 医生角色管理类.
 */
@Service("doctorRoleService")
@Transactional(rollbackFor = Exception.class)
public class RoleService extends BaseJpaService<DoctorRole, DoctorRoleDao> {
    @Autowired
    private DoctorRoleDao doctorRoleDao;
    @Autowired
    private DoctorRoleRealmDao doctorRoleRealmDao;
    private Clock clock = Clock.DEFAULT;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private CareDoctorService doctorInfoService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取用户角色列表
     */
    public List<DoctorRole> getUserRole(String user) {
        return doctorRoleDao.findUserRole(user);
    }
    /**
     * 区域去末尾零
     */
    private String getShortArea(String area) {
        char strs[] = area.toCharArray();// 将字符串转化成字符数组
        String last = "";
        for (int i = area.length() - 1; i >= 0; i--) {
            if ('0' == strs[i]) {
                last += "0";
            } else {
                break;
            }
        }
        if (last.length() > 0) {
            return area.substring(0, area.lastIndexOf(last));
        } else {
            return area;
        }
    }
    /**
     * 获取角色区域
     */
    public List<Map<String, String>> getUserRoleAndArea(String user) {
        List<Map<String, String>> re = new ArrayList<>();
        List<DoctorRole> roleList = doctorRoleDao.findUserRole(user);
        int resultLevel = 5;
        for (DoctorRole one : roleList) {
            if(resultLevel>roleConverse(one.getCode())){
                resultLevel=roleConverse(one.getCode());
            }
        }
        if (roleList != null && roleList.size() > 0) {
            //遍历角色
            for (DoctorRole role : roleList) {
                if(role.getCode().length()!=6&&role.getCode().length()!=10){
                    continue;
                }
                Map<String, String> map = new HashMap<>();
                map.put("code", role.getCode());
                map.put("name", role.getName());
                //获取区域权限
                String areaString = "";
                List<DoctorRoleRealm> areaList = doctorRoleRealmDao.findByRoleCode(role.getCode());
                if (areaList != null && areaList.size() > 0) {
                    //获取最大权限区域
                    List<String> areas = new ArrayList<>();
                    List<String> orgs = new ArrayList<>();
                    for (DoctorRoleRealm areaItem : areaList) {
                        String currentArea = areaItem.getAreaCode();
                        int currentLength = currentArea.length();
                        if (currentLength == 6) //区域
                        {
                            areas.add(currentArea);
                        } else {               //机构
                            orgs.add(currentArea);
                        }
                    }
                    //区域权限重复校验
                    for (int i = areas.size() - 1; i >= 0; i--) {
                        String currentArea = areas.get(i);
                        for (int j = 0; j < areas.size() - i - 1; j++) {
                            String shortArea = getShortArea(areas.get(j));
                            if (currentArea.startsWith(shortArea))   //包含则移除
                            {
                                areas.remove(i);
                            }
                        }
                    }
                    //机构权限重复校验
                    for (int m = orgs.size() - 1; m >= 0; m--) {
                        String currentOrg = orgs.get(m);
                        for (int n = 0; n < areas.size() - m - 1; n++) {
                            String shortArea = getShortArea(areas.get(n));
                            if (currentOrg.startsWith(shortArea))   //包含则移除
                            {
                                orgs.remove(m);
                            }
                        }
                    }
                    for (String item : areas) {
                        areaString += item + ",";
                    }
                    for (String item : orgs) {
                        areaString += item + ",";
                    }
                    areaString = areaString.substring(0, areaString.length() - 1);
                }
                map.put("areas", areaString);
                map.put("level",roleConverse(role.getCode())+"");
                map.put("isManage", "1");
                if(resultLevel==roleConverse(role.getCode())){
                    map.put("high", "1");
                }else{
                    map.put("high", "0");
                }
                re.add(map);
            }
        }
        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;
        }
    }
    public Map<String,Object> findManageUserRole(String doctor){
        String sql ="SELECT " +
                " r.id, " +
                " r.`code`, " +
                " r.`name`, " +
                " r.description " +
                " FROM " +
                " manage_role_user m " +
                " JOIN manage_roles r ON m.role_id = r.id " +
                " WHERE " +
                " m.user_code = '"+doctor+"' and r.`code` ='dispatcher' ";
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        if(rs!=null&&rs.size()>0){
            return rs.get(0);
        }
        return null;
    }
    public List<Map<String,Object>> queryDispatcherInfoByHospital(String hospital){
        String sql ="SELECT " +
                " d.`code`, " +
                " d.`name`, " +
                " d.`hospital_name` as hospitalName " +
                " FROM " +
                " manage_role_user m " +
                " JOIN manage_roles r ON m.role_id = r.id " +
                " JOIN (select code,name,hospital_name from wlyy_doctor where hospital = '"+ hospital +"') as d ON m.user_code = d.code" +
                " WHERE " +
                " r.code = 'dispatcher'";
        return jdbcTemplate.queryForList(sql);
    }
}