|
@ -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;
|
|
|
}
|