Pārlūkot izejas kodu

杭州后台管理员权限

liubing 3 gadi atpakaļ
vecāks
revīzija
8a46452d99

+ 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 api_success ="success";
        public static final String saveRole ="/saveRole";
        public static final String saveRole ="/saveRole";
        public static final String findRoleNameExist ="/findRoleNameExist";
        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);
}

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

@ -0,0 +1,97 @@
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);
        }
    }
}

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

@ -0,0 +1,106 @@
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);
    }
}