LAPTOP-KB9HII50\70708 преди 2 години
родител
ревизия
0a8bb509d0

+ 79 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/doctor/BaseDoctorRoleInfoEndpoint.java

@ -17,7 +17,6 @@ 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.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -44,6 +43,85 @@ public class BaseDoctorRoleInfoEndpoint extends EnvelopRestEndpoint {
    private BaseDoctorRoleDictService baseDoctorRoleDictService;
    @PostMapping(value = "createRole")
    @ApiOperation(value = "创建")
    public Envelop createRole(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam(value = "jsonData", required = true)  String jsonData ){
        JSONObject jsonObject = baseDoctorRoleDictService.createRoleInfo(jsonData);
        if (jsonObject.getInteger("status")==-1) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("msg"));
    }
    @PostMapping(value = "updateRoleInfo")
    @ApiOperation(value = "修改")
    public Envelop updateRoleInfo(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam(value = "jsonData", required = true)  String jsonData ){
        JSONObject jsonObject = baseDoctorRoleDictService.updateRoleInfo(jsonData);
        if (jsonObject.getInteger("status")==-1) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("msg"));
    }
    @GetMapping(value = "getOneRoleInfo")
    @ApiOperation(value = "查询某一个角色")
    public Envelop getOneRoleInfo(
            @ApiParam(name = "roleId", value = "根据角色标识查询某一个角色信息")
            @RequestParam(value = "roleId", required = true) Integer roleId) throws Exception {
        JSONObject team = baseDoctorRoleDictService.getOneRoleInfo(roleId);
        if (team.getInteger("status")==-1) {
            return failed(team.getString("msg"));
        }
        return ObjEnvelop.getSuccess(team.getString("msg"),team.get("obj"));
    }
    /**
     * 生效或失效某个角色
     *
     * @param id
     * @param status
     * @return
     * @throws Exception
     */
    @PostMapping(value = "enableOrDisable")
    @ApiOperation(value = "生效或失效某个角色")
    public Envelop enableOrDisable(
            @ApiParam(name = "id", value = "角色Id")
            @RequestParam(value = "id", required = true) Integer id,
            @ApiParam(name = "status", value = "生效或失效标识")
            @RequestParam(value = "status", required = true) String status) throws Exception {
        JSONObject jsonObject = baseDoctorRoleDictService.enableOrDisable(id, status);
        if (jsonObject.getInteger("status")==-1) {
            return failed(jsonObject.getString("msg"));
        }
        return success("成功");
    }
    @GetMapping(value = "rolePage")
    @ApiOperation(value = "获取角色信息列表分页")
    public PageEnvelop<BaseDoctorRoleDictDO> rolePage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @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 {
        List<BaseDoctorRoleDictDO> baseDoctorRoleInfos = baseDoctorRoleDictService.search(fields, filters, sorts, page, size);
        int count = (int) baseDoctorRoleDictService.getCount(filters);
        return success(baseDoctorRoleInfos, count, page, size, BaseDoctorRoleDictDO.class);
    }
    @PostMapping(value = BaseRequestMapping.BaseDoctorRoleInfo.CREATE)
    @ApiOperation(value = "创建")
    public Envelop create(

+ 40 - 98
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorRoleDictService.java

@ -1,24 +1,20 @@
package com.yihu.jw.base.service.doctor;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.doctor.BaseDoctorRoleDictDao;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDictDO;
import com.yihu.jw.entity.base.doctor.BaseModuleRoleDO;
import com.yihu.jw.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
@Service
public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDictDO, BaseDoctorRoleDao> {
@ -26,8 +22,7 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
    private BaseDoctorRoleDictDao baseDoctorRoleDictDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private BaseModuleRoleService baseModuleRoleService;
    /**
     * 创建角色信息
     *
@ -35,61 +30,39 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject createRoleInfo(String jsonData, JSONObject userAgent) {
    public JSONObject createRoleInfo(String jsonData) {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(jsonData)) {
            result.put("msg", "parameter jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        JSONObject jsonObject = JSONObject.parseObject(jsonData);
        JSONObject role = jsonObject.getJSONObject("role");
        JSONArray module = jsonObject.getJSONArray("module");
        if (null == role || CollectionUtils.isEmpty(module) ) {
            result.put("msg", "parameter role or module of jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            result.put("message", "参数错误");
            result.put("status", -1);
            return result;
        }
        JSONObject role = JSONObject.parseObject(jsonData);
        if(StringUtils.isEmpty(role.getString("name")) || role.getString("name").length() > 50){
            result.put("msg", "角色名称必填,但是请不要超过50个字符!");
            result.put("response", ConstantUtils.FAIL);
            result.put("status", -1);
            return result;
        }
        //组装角色信息
        BaseDoctorRoleDictDO roleInfoDO = null;
        try {
            roleInfoDO = objectMapper.readValue(role.toJSONString(), BaseDoctorRoleDictDO.class);
            roleInfoDO.setCreateTime(new Date());
        } catch (IOException e) {
            result.put("msg", "convert role jsonObject to BaseDoctorRoleInfoDO failed," + e.getCause());
            result.put("response", ConstantUtils.FAIL);
            e.printStackTrace();
            result.put("msg", "类型转换失败");
            result.put("status", -1);
            return result;
        }
        roleInfoDO.setCode(randomString(30));
        this.save(roleInfoDO);
        //组装角色与模块的关联关系
        List<BaseModuleRoleDO> moduleRoleDOList = new ArrayList<>();
        BaseModuleRoleDO moduleRoleDO = null;
        for (Object obj : module) {
            try {
                moduleRoleDO = objectMapper.readValue(obj.toString(), BaseModuleRoleDO.class);
                moduleRoleDO.setRoleCode(roleInfoDO.getCode());
                moduleRoleDOList.add(moduleRoleDO);
            } catch (IOException e) {
                result.put("msg", "convert org jsonObject to BaseOrgUserDO failed," + e.getCause());
                result.put("response", ConstantUtils.FAIL);
                return result;
            }
        }
        baseModuleRoleService.batchInsert(moduleRoleDOList);
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg", moduleRoleDO);
        baseDoctorRoleDictDao.save(roleInfoDO);
        result.put("status", 200);
        result.put("obj", roleInfoDO);
        result.put("msg", "sucess");
        return result;
    }
    /**
     * 修改角色
     *
@ -100,18 +73,11 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
    public JSONObject updateRoleInfo(String jsonData) {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(jsonData)) {
            result.put("msg", "parameter jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        JSONObject jsonObject = JSONObject.parseObject(jsonData);
        JSONObject role = jsonObject.getJSONObject("role");
        JSONArray module = jsonObject.getJSONArray("module");
        if (null == role || CollectionUtils.isEmpty(module) ) {
            result.put("msg", "parameter role or module of jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            result.put("msg", "参数错误");
            result.put("status", -1);
            return result;
        }
        JSONObject role = JSONObject.parseObject(jsonData);
        //修改角色信息
        BaseDoctorRoleDictDO roleInfoDO = null;
        BaseDoctorRoleDictDO oldRoleInfo = null;
@ -119,45 +85,24 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
            roleInfoDO = objectMapper.readValue(role.toJSONString(), BaseDoctorRoleDictDO.class);
        } catch (IOException e) {
            result.put("msg", "convert user jsonObject to UserDO failed," + e.getCause());
            result.put("response", ConstantUtils.FAIL);
            e.printStackTrace();
            result.put("msg", "类型转换失败");
            result.put("status", -1);
            return result;
        }
        try {
            oldRoleInfo = baseDoctorRoleDictDao.findById(roleInfoDO.getId()).orElse(null);;
        } catch (Exception e) {
            result.put("msg", "not role exist for id:" + roleInfoDO.getId());
            result.put("response", ConstantUtils.FAIL);
            result.put("msg", "角色id不存在");
            result.put("status", -1);
            return result;
        }
        oldRoleInfo.setCode(roleInfoDO.getCode());
        oldRoleInfo.setName(roleInfoDO.getName());
        this.save(oldRoleInfo);
        baseDoctorRoleDictDao.save(oldRoleInfo);
        //修改角色与模块关联关系
        Set<Object> roleIdList = baseModuleRoleService.findModuleIdList(roleInfoDO.getCode());
        BaseModuleRoleDO moduleRoleDO = null;
        try {
            for (Object obj : module) {
                moduleRoleDO = objectMapper.readValue(obj.toString(), BaseModuleRoleDO.class);
                moduleRoleDO.setRoleCode(roleInfoDO.getCode());
                if (roleIdList.contains(moduleRoleDO.getId())) {
                    roleIdList.remove(moduleRoleDO.getId());
                }
                baseModuleRoleService.save(moduleRoleDO);
            }
        } catch (IOException e) {
            result.put("msg", "convert module jsonObject to BaseModuleRoleDO failed," + e.getCause());
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        // 表示没有删除,只有修改
        if (roleIdList.size() > 0) {
            baseModuleRoleService.delete(roleIdList.toArray());
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("status", 200);
        result.put("msg", roleInfoDO);
        return result;
    }
@ -169,27 +114,24 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
     * @param roleId 角色id
     * @return
     */
    public JSONObject getOneRoleInfo(Integer roleId) throws Exception{
    public JSONObject getOneRoleInfo(Integer roleId){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(roleId)){
            result.put("msg","parameter roleId is null ");
            result.put("response",ConstantUtils.FAIL);
            result.put("msg","参数错误");
            result.put("status", -1);
            return result;
        }
        //角色基本信息
        BaseDoctorRoleDictDO roleInfoDO = baseDoctorRoleDictDao.findById(roleId.toString()).orElse(null);;
        if(null == roleInfoDO){
            result.put("msg","Role not exist for id:" + roleId);
            result.put("response",ConstantUtils.FAIL);
            result.put("msg", "角色id不存在");
            result.put("status", -1);
            return result;
        }
        List<BaseModuleRoleDO> moduleRoleDOList =  baseModuleRoleService.findModuleListByRoleCode(roleInfoDO.getCode());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("role",roleInfoDO);
        jsonObject.put("module",moduleRoleDOList);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",jsonObject);
        result.put("status", 200);
        result.put("obj",roleInfoDO);
        result.put("msg","success");
        return result;
    }
@ -204,19 +146,19 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
    public JSONObject enableOrDisable(Integer roleId,String del){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(roleId) || StringUtils.isEmpty(del)){
            result.put("msg","parameter id or del is null");
            result.put("response",ConstantUtils.FAIL);
            result.put("msg","参数错误");
            result.put("status", -1);
            return result;
        }
        BaseDoctorRoleDictDO roleInfoDO = baseDoctorRoleDictDao.findById(roleId.toString()).orElse(null);;
        if( null == roleInfoDO ){
            result.put("msg","role not exist for id:" + roleId);
            result.put("response",ConstantUtils.FAIL);
            result.put("msg", "角色id不存在");
            result.put("status", -1);
            return result;
        }
        roleInfoDO.setDel(del);
        this.save(roleInfoDO);
        result.put("response",ConstantUtils.SUCCESS);
        baseDoctorRoleDictDao.save(roleInfoDO);
        result.put("status", 200);
        return result;
    }
@ -234,7 +176,7 @@ public class BaseDoctorRoleDictService extends BaseJpaService<BaseDoctorRoleDict
            return result;
        }
        List<BaseDoctorRoleDictDO> roleInfoDO = baseDoctorRoleDictDao.getByname(name);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("response",200);
        result.put("msg",null == roleInfoDO);
        return result;
    }