diff --git a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java index 486ed414..dafa65f3 100644 --- a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java +++ b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActHistoryService.java @@ -22,6 +22,8 @@ import org.activiti.engine.task.Task; import org.activiti.image.ProcessDiagramGenerator; import org.activiti.spring.ProcessEngineFactoryBean; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -41,6 +43,7 @@ import java.util.Map; */ @Service public class ActHistoryService { + private static Logger logger = LoggerFactory.getLogger(ActHistoryService.class); @Autowired protected RepositoryService repositoryService; @@ -64,20 +67,19 @@ public class ActHistoryService { private SysUserService sysUserService; - public void getProcessInstanceDiagram(String processInstanceId, HttpServletResponse response) throws Exception { - if(StringUtils.isEmpty(processInstanceId)){ + if (StringUtils.isEmpty(processInstanceId)) { return; } - HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()); processEngineConfiguration = processEngine.getProcessEngineConfiguration(); Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration); ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator(); - ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity)repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId()); + ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId()); - List highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime() + List highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime() .asc().list(); //高亮环节id集合 List highLightedActivitis = new ArrayList(); @@ -87,29 +89,31 @@ public class ActHistoryService { } //高亮线路id集合 - List highLightedFlows = getHighLightedFlows(definitionEntity,highLightedActivitList); + List highLightedFlows = getHighLightedFlows(definitionEntity, highLightedActivitList); ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult(); - if(null != execution) { + if (null != execution) { highLightedActivitis.add(execution.getActivityId()); } - InputStream imageStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitis,highLightedFlows,"宋体","宋体", "宋体",null,1.0); + InputStream imageStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitis, highLightedFlows, "宋体", "宋体", "宋体", null, 1.0); - response.setHeader("Content-Type","image/png"); + response.setHeader("Content-Type", "image/png"); response.setHeader("Cache-Control", "no-store, no-cache"); - BufferedImage bufferedImage = ImageIO.read(imageStream); + BufferedImage bufferedImage = ImageIO.read(imageStream); ImageIO.write(bufferedImage, "png", response.getOutputStream()); } + /** * 获取需要高亮的线 + * * @param processDefinitionEntity * @param historicActivityInstances * @return */ private List getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity, - List historicActivityInstances) { + List historicActivityInstances) { List highFlows = new ArrayList<>(); for (int i = 0; i < historicActivityInstances.size() - 1; i++) { ActivityImpl activityImpl = processDefinitionEntity.findActivity(historicActivityInstances.get(i).getActivityId()); @@ -119,17 +123,17 @@ public class ActHistoryService { for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) { HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j); HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + 1); - if (Math.abs(activityImpl1.getStartTime().getTime()-activityImpl2.getStartTime().getTime()) < 200) { + if (Math.abs(activityImpl1.getStartTime().getTime() - activityImpl2.getStartTime().getTime()) < 200) { ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl2.getActivityId()); sameStartTimeNodes.add(sameActivityImpl2); } else { break; } } - for(int j = i+1; j < historicActivityInstances.size() - 1; j++){ + for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) { HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j); - if(null != historicActivityInstances.get(i).getEndTime()){ - if (Math.abs(activityImpl1.getStartTime().getTime()-historicActivityInstances.get(i).getEndTime().getTime()) < 200) { + if (null != historicActivityInstances.get(i).getEndTime()) { + if (Math.abs(activityImpl1.getStartTime().getTime() - historicActivityInstances.get(i).getEndTime().getTime()) < 200) { ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl1.getActivityId()); sameStartTimeNodes.add(sameActivityImpl2); } @@ -151,50 +155,51 @@ public class ActHistoryService { HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery(); Integer curPage = 1; Integer limit = 10; - if(params.get(Constant.PAGE) != null){ - curPage = Integer.parseInt((String)params.get(Constant.PAGE)); + if (params.get(Constant.PAGE) != null) { + curPage = Integer.parseInt((String) params.get(Constant.PAGE)); } - if(params.get(Constant.LIMIT) != null){ - limit = Integer.parseInt((String)params.get(Constant.LIMIT)); + if (params.get(Constant.LIMIT) != null) { + limit = Integer.parseInt((String) params.get(Constant.LIMIT)); } - if(StringUtils.isNotEmpty((String)params.get("processInstanceId"))){ - query.processInstanceId((String)params.get("processInstanceId")); + if (StringUtils.isNotEmpty((String) params.get("processInstanceId"))) { + query.processInstanceId((String) params.get("processInstanceId")); } - if(StringUtils.isNotEmpty((String)params.get("businessKey"))){ - query.processInstanceBusinessKey((String)params.get("businessKey")); + if (StringUtils.isNotEmpty((String) params.get("businessKey"))) { + query.processInstanceBusinessKey((String) params.get("businessKey")); } - if(StringUtils.isNotEmpty((String)params.get("processDefinitionId"))){ - query.processDefinitionId((String)params.get("processDefinitionId")); + if (StringUtils.isNotEmpty((String) params.get("processDefinitionId"))) { + query.processDefinitionId((String) params.get("processDefinitionId")); } - if(StringUtils.isNotEmpty((String)params.get("ended"))){ - if("true".equals((String)params.get("ended"))){ + if (StringUtils.isNotEmpty((String) params.get("ended"))) { + logger.info("ended参数值为:" + (String) params.get("ended")); + if ("true".equals((String) params.get("ended"))) { query.finished(); - } else if("false".equals((String)params.get("ended"))){ + } else if ("false".equals((String) params.get("ended"))) { query.unfinished(); } } - if(null != params.get("finishedBeginTime")){ + if (null != params.get("finishedBeginTime")) { query.finishedAfter((Date) params.get("finishedBeginTime")); } - if(null != params.get("finishedEndTime")){ + if (null != params.get("finishedEndTime")) { query.finishedBefore((Date) params.get("finishedEndTime")); } - if(null != params.get("startBeginTime")){ + if (null != params.get("startBeginTime")) { query.startedAfter((Date) params.get("startBeginTime")); } - if(null != params.get("startEndTime")){ + if (null != params.get("startEndTime")) { query.startedBefore((Date) params.get("startEndTime")); } - if(StringUtils.isNotEmpty((String)params.get("startBy"))){ - query.startedBy((String)params.get("startBy")); + if (StringUtils.isNotEmpty((String) params.get("startBy"))) { + query.startedBy((String) params.get("startBy")); } query.orderByProcessInstanceStartTime().desc(); - List list = query.listPage((curPage-1)*limit, limit); + List list = query.listPage((curPage - 1) * limit, limit); List listInstance = new ArrayList<>(); - if(!list.isEmpty()){ + if (!list.isEmpty()) { this.converHistoricProcessInstance(list, listInstance); } @@ -202,14 +207,14 @@ public class ActHistoryService { } private void converHistoricProcessInstance(List list, List listInstance) { - for(HistoricProcessInstance historicProcessInstance : list){ + for (HistoricProcessInstance historicProcessInstance : list) { ProcessInstanceDTO dto = new ProcessInstanceDTO(); dto.setProcessDefinitionId(historicProcessInstance.getProcessDefinitionId()); dto.setProcessInstanceId(historicProcessInstance.getId()); dto.setProcessDefinitionVersion(historicProcessInstance.getProcessDefinitionVersion()); dto.setProcessDefinitionName(historicProcessInstance.getProcessDefinitionName()); dto.setProcessDefinitionKey(historicProcessInstance.getProcessDefinitionKey()); - if(null != historicProcessInstance.getEndTime()){ + if (null != historicProcessInstance.getEndTime()) { dto.setEnded(true); } else { dto.setEnded(false); @@ -226,6 +231,7 @@ public class ActHistoryService { /** * 我发起的流程 * 根据登录用户信息获取处理中的示例和任务信息 + * * @param params * @return */ @@ -233,16 +239,16 @@ public class ActHistoryService { params.put("startBy", SecurityUser.getUserId().toString()); PageData pageData = this.getHistoryProcessInstancePage(params); List list = pageData.getList(); - for(ProcessInstanceDTO dto : list){ - if(dto.isEnded()){ + for (ProcessInstanceDTO dto : list) { + if (dto.isEnded()) { continue; } List listTask = taskService.createTaskQuery().processInstanceId(dto.getProcessInstanceId()).list(); List taskDTOList = new ArrayList<>(); - for(Task task : listTask){ + for (Task task : listTask) { TaskDTO taskDTO = new TaskDTO(); this.convertTaskInfo(task, taskDTO); - if(StringUtils.isNotEmpty(taskDTO.getAssignee())){ + if (StringUtils.isNotEmpty(taskDTO.getAssignee())) { SysUserDTO userDTO = sysUserService.get(Long.valueOf(taskDTO.getAssignee())); taskDTO.setAssigneeName(userDTO.getRealName()); } @@ -255,6 +261,7 @@ public class ActHistoryService { /** * 转换Task对象 + * * @param task * @param dto */ @@ -271,16 +278,16 @@ public class ActHistoryService { public ProcessInstanceDTO getHistoryProcessInstanceByBusinessKey(String procDefKey, String businessKey) { HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery(); - if(StringUtils.isNotEmpty(businessKey)){ + if (StringUtils.isNotEmpty(businessKey)) { query.processInstanceBusinessKey(businessKey); } - if(StringUtils.isNotEmpty(procDefKey)){ + if (StringUtils.isNotEmpty(procDefKey)) { query.processDefinitionKey(procDefKey); } - List list = query.list(); + List list = query.list(); List listInstance = new ArrayList<>(); - if(!list.isEmpty()){ + if (!list.isEmpty()) { this.converHistoricProcessInstance(list, listInstance); } else { return null; diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java b/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java index 983a862b..822f9c3d 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java @@ -3,6 +3,10 @@ package io.renren.modules.processForm.listener; import com.google.gson.Gson; import com.google.gson.JsonElement; import io.renren.modules.processForm.dto.TAbilityApplicationDTO; +import io.renren.modules.sys.dto.SysDeptDTO; +import io.renren.modules.sys.dto.SysRoleDTO; +import io.renren.modules.sys.dto.SysUserDTO; +import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysRoleService; import io.renren.modules.sys.service.SysRoleUserService; import io.renren.modules.sys.service.SysUserService; @@ -21,6 +25,8 @@ import java.util.Map; public class CorrectionListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate { private static Logger logger = LoggerFactory.getLogger(CorrectionListener.class); + private static String roleName = "部门审批人"; + @Autowired private SysRoleService sysRoleService; @Autowired @@ -29,23 +35,28 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti private SysUserService sysUserService; @Autowired private SysRoleUserService sysRoleUserService; + @Autowired + private SysDeptService sysDeptService; @Override public void notify(DelegateTask delegateTask) { - logger.info("进入DelegateTask"); - logger.info("EventName:" + delegateTask.getEventName()); - logger.info("Owner:" + delegateTask.getOwner()); Map kv = delegateTask.getVariables(); Gson gson = new Gson(); JsonElement jsonElement = gson.toJsonTree(kv); TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class); logger.info(abilityApplicationDTO.toString()); - abilityApplicationDTO.getUnit(); - + SysDeptDTO deptDTO = sysDeptService.getByName(abilityApplicationDTO.getUnit()); + logger.info("deptDTOId:" + deptDTO.getId()); + SysRoleDTO roleDTO = sysRoleService.getByName(roleName); + logger.info("roleDTOId:" + roleDTO.getId()); delegateTask.setAssignee("1513432847327199233"); - String taskKey = delegateTask.getTaskDefinitionKey(); - taskService.setAssignee(delegateTask.getId(), "1516307964617076737"); - String processDefinitionId = delegateTask.getProcessDefinitionId(); + SysUserDTO userDTO = sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId()); + if (userDTO != null) { + logger.info("审批人id:" + userDTO.getId()); + taskService.setAssignee(delegateTask.getId(), userDTO.getId().toString()); + } else { + logger.info("未查到该部门对应 " + roleName); + } } @Override diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java index 78896104..98a8816c 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java @@ -29,4 +29,11 @@ public interface SysDeptDao extends BaseDao { */ List getSubDeptIdList(String id); + /** + * 根据名称获取部门所有信息 + * @param name + * @return + */ + SysDeptEntity getByName(String name); + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysRoleDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysRoleDao.java index 8a4d5e28..9797b51d 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysRoleDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysRoleDao.java @@ -6,10 +6,9 @@ import org.apache.ibatis.annotations.Mapper; /** * 角色管理 - * */ @Mapper public interface SysRoleDao extends BaseDao { - + SysRoleEntity getByName(String name); } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java index 34a7ada2..77367991 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysUserDao.java @@ -10,26 +10,33 @@ import java.util.Map; /** * 系统用户 - * */ @Mapper public interface SysUserDao extends BaseDao { - List getList(Map params); + List getList(Map params); - SysUserEntity getById(Long id); + SysUserEntity getById(Long id); - SysUserEntity getByUsername(String username); + SysUserEntity getByUsername(String username); - int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword); + int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword); - /** - * 根据部门ID,查询用户数 - */ - int getCountByDeptId(Long deptId); + /** + * 根据部门ID,查询用户数 + */ + int getCountByDeptId(Long deptId); - /** - * 根据部门ID,查询用户ID列表 - */ - List getUserIdListByDeptId(List deptIdList); + /** + * 根据部门ID,查询用户ID列表 + */ + List getUserIdListByDeptId(List deptIdList); + + /** + * 获取该部门拥有该权限的用户信息 + * @param deptId + * @param roleId + * @return + */ + SysUserEntity getByDeptIdAndRoleId(@Param("deptId") Long deptId, @Param("roleId") Long roleId); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java index 779cf662..12dd7d85 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java @@ -28,4 +28,6 @@ public interface SysDeptService extends BaseService { * @param id 部门ID */ List getSubDeptIdList(Long id); + + SysDeptDTO getByName(String name); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysRoleService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysRoleService.java index 233d7377..bfbd17e7 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysRoleService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysRoleService.java @@ -28,4 +28,6 @@ public interface SysRoleService extends BaseService { void delete(Long[] ids); + SysRoleDTO getByName(String name); + } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java index 35af46c4..a27655b1 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysUserService.java @@ -11,39 +11,41 @@ import java.util.Map; /** * 系统用户 - * */ public interface SysUserService extends BaseService { - PageData page(Map params); + PageData page(Map params); - List list(Map params); + List list(Map params); - SysUserDTO get(Long id); + SysUserDTO get(Long id); - SysUserDTO getByUsername(String username); + SysUserDTO getByUsername(String username); - void save(SysUserDTO dto); + void save(SysUserDTO dto); - void update(SysUserDTO dto); + void update(SysUserDTO dto); - void delete(Long[] ids); + void delete(Long[] ids); - /** - * 修改密码 - * @param id 用户ID - * @param newPassword 新密码 - */ - void updatePassword(Long id, String newPassword); + /** + * 修改密码 + * + * @param id 用户ID + * @param newPassword 新密码 + */ + void updatePassword(Long id, String newPassword); - /** - * 根据部门ID,查询用户数 - */ - int getCountByDeptId(Long deptId); + /** + * 根据部门ID,查询用户数 + */ + int getCountByDeptId(Long deptId); - /** - * 根据部门ID,查询用户Id列表 - */ - List getUserIdListByDeptId(List deptIdList); + /** + * 根据部门ID,查询用户Id列表 + */ + List getUserIdListByDeptId(List deptIdList); + + SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId); } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java index 3584236b..395ff8b1 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java @@ -24,131 +24,141 @@ import java.util.*; @Service public class SysDeptServiceImpl extends BaseServiceImpl implements SysDeptService { - @Autowired - private SysUserService sysUserService; + @Autowired + private SysUserService sysUserService; - @Override - public List list(Map params) { - //普通管理员,只能查询所属部门及子部门的数据 - UserDetail user = SecurityUser.getUser(); - if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { - params.put("deptIdList", getSubDeptIdList(user.getDeptId())); - } + @Override + public List list(Map params) { + //普通管理员,只能查询所属部门及子部门的数据 + UserDetail user = SecurityUser.getUser(); + if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", getSubDeptIdList(user.getDeptId())); + } - //查询部门列表 - List entityList = baseDao.getList(params); + //查询部门列表 + List entityList = baseDao.getList(params); - List dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class); + List dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class); - return TreeUtils.build(dtoList); - } + return TreeUtils.build(dtoList); + } - @Override - public SysDeptDTO get(Long id) { - //超级管理员,部门ID为null - if(id == null){ - return null; - } + @Override + public SysDeptDTO get(Long id) { + //超级管理员,部门ID为null + if (id == null) { + return null; + } - SysDeptEntity entity = baseDao.getById(id); + SysDeptEntity entity = baseDao.getById(id); - return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class); - } + return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void save(SysDeptDTO dto) { - SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysDeptDTO dto) { + SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); - entity.setPids(getPidList(entity.getPid())); - insert(entity); - } + entity.setPids(getPidList(entity.getPid())); + insert(entity); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void update(SysDeptDTO dto) { - SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysDeptDTO dto) { + SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); - //上级部门不能为自身 - if(entity.getId().equals(entity.getPid())){ - throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); - } + //上级部门不能为自身 + if (entity.getId().equals(entity.getPid())) { + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } - //上级部门不能为下级部门 - List subDeptList = getSubDeptIdList(entity.getId()); - if(subDeptList.contains(entity.getPid())){ - throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); - } + //上级部门不能为下级部门 + List subDeptList = getSubDeptIdList(entity.getId()); + if (subDeptList.contains(entity.getPid())) { + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } - entity.setPids(getPidList(entity.getPid())); - updateById(entity); - } + entity.setPids(getPidList(entity.getPid())); + updateById(entity); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long id) { - //判断是否有子部门 - List subList = getSubDeptIdList(id); - if(subList.size() > 1){ - throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); - } + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + //判断是否有子部门 + List subList = getSubDeptIdList(id); + if (subList.size() > 1) { + throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); + } - //判断部门下面是否有用户 - int count = sysUserService.getCountByDeptId(id); - if(count > 0){ - throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR); - } + //判断部门下面是否有用户 + int count = sysUserService.getCountByDeptId(id); + if (count > 0) { + throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR); + } - //删除 - baseDao.deleteById(id); - } + //删除 + baseDao.deleteById(id); + } - @Override - public List getSubDeptIdList(Long id) { - List deptIdList = baseDao.getSubDeptIdList("%" + id + "%"); - deptIdList.add(id); + @Override + public List getSubDeptIdList(Long id) { + List deptIdList = baseDao.getSubDeptIdList("%" + id + "%"); + deptIdList.add(id); - return deptIdList; - } + return deptIdList; + } - /** - * 获取所有上级部门ID - * @param pid 上级ID - */ - private String getPidList(Long pid){ - //顶级部门,无上级部门 - if(Constant.DEPT_ROOT.equals(pid)){ - return Constant.DEPT_ROOT + ""; - } + @Override + public SysDeptDTO getByName(String name) { + if (StringUtils.isEmpty(name)) { + return null; + } + SysDeptEntity entity = baseDao.getByName(name); + return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class); + } - //所有部门的id、pid列表 - List deptList = baseDao.getIdAndPidList(); + /** + * 获取所有上级部门ID + * + * @param pid 上级ID + */ + private String getPidList(Long pid) { + //顶级部门,无上级部门 + if (Constant.DEPT_ROOT.equals(pid)) { + return Constant.DEPT_ROOT + ""; + } - //list转map - Map map = new HashMap<>(deptList.size()); - for(SysDeptEntity entity : deptList){ - map.put(entity.getId(), entity); - } + //所有部门的id、pid列表 + List deptList = baseDao.getIdAndPidList(); - //递归查询所有上级部门ID列表 - List pidList = new ArrayList<>(); - getPidTree(pid, map, pidList); + //list转map + Map map = new HashMap<>(deptList.size()); + for (SysDeptEntity entity : deptList) { + map.put(entity.getId(), entity); + } - return StringUtils.join(pidList, ","); - } + //递归查询所有上级部门ID列表 + List pidList = new ArrayList<>(); + getPidTree(pid, map, pidList); - private void getPidTree(Long pid, Map map, List pidList) { - //顶级部门,无上级部门 - if(Constant.DEPT_ROOT.equals(pid)){ - return ; - } + return StringUtils.join(pidList, ","); + } - //上级部门存在 - SysDeptEntity parent = map.get(pid); - if(parent != null){ - getPidTree(parent.getPid(), map, pidList); - } + private void getPidTree(Long pid, Map map, List pidList) { + //顶级部门,无上级部门 + if (Constant.DEPT_ROOT.equals(pid)) { + return; + } - pidList.add(pid); - } + //上级部门存在 + SysDeptEntity parent = map.get(pid); + if (parent != null) { + getPidTree(parent.getPid(), map, pidList); + } + + pidList.add(pid); + } } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysRoleServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysRoleServiceImpl.java index 4d6884f0..0ec92399 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysRoleServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysRoleServiceImpl.java @@ -24,103 +24,110 @@ import java.util.Map; /** * 角色 - * */ @Service public class SysRoleServiceImpl extends BaseServiceImpl implements SysRoleService { - @Autowired - private SysRoleMenuService sysRoleMenuService; - @Autowired - private SysRoleDataScopeService sysRoleDataScopeService; - @Autowired - private SysRoleUserService sysRoleUserService; - @Autowired - private SysDeptService sysDeptService; + @Autowired + private SysRoleMenuService sysRoleMenuService; + @Autowired + private SysRoleDataScopeService sysRoleDataScopeService; + @Autowired + private SysRoleUserService sysRoleUserService; + @Autowired + private SysDeptService sysDeptService; - @Override - public PageData page(Map params) { - IPage page = baseDao.selectPage( - getPage(params, Constant.CREATE_DATE, false), - getWrapper(params) - ); + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); - return getPageData(page, SysRoleDTO.class); - } + return getPageData(page, SysRoleDTO.class); + } - @Override - public List list(Map params) { - List entityList = baseDao.selectList(getWrapper(params)); + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); - return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class); - } + return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class); + } - private QueryWrapper getWrapper(Map params){ - String name = (String)params.get("name"); + private QueryWrapper getWrapper(Map params) { + String name = (String) params.get("name"); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.like(StringUtils.isNotBlank(name), "name", name); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StringUtils.isNotBlank(name), "name", name); - //普通管理员,只能查询所属部门及子部门的数据 - UserDetail user = SecurityUser.getUser(); - if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { - List deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId()); - wrapper.in(deptIdList != null, "dept_id", deptIdList); - } + //普通管理员,只能查询所属部门及子部门的数据 + UserDetail user = SecurityUser.getUser(); + if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + List deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId()); + wrapper.in(deptIdList != null, "dept_id", deptIdList); + } - return wrapper; - } + return wrapper; + } - @Override - public SysRoleDTO get(Long id) { - SysRoleEntity entity = baseDao.selectById(id); + @Override + public SysRoleDTO get(Long id) { + SysRoleEntity entity = baseDao.selectById(id); - return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class); - } + return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void save(SysRoleDTO dto) { - SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysRoleDTO dto) { + SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); - //保存角色 - insert(entity); + //保存角色 + insert(entity); - //保存角色菜单关系 - sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); + //保存角色菜单关系 + sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); - //保存角色数据权限关系 - sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); - } + //保存角色数据权限关系 + sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void update(SysRoleDTO dto) { - SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysRoleDTO dto) { + SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); - //更新角色 - updateById(entity); + //更新角色 + updateById(entity); - //更新角色菜单关系 - sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); + //更新角色菜单关系 + sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); - //更新角色数据权限关系 - sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); - } + //更新角色数据权限关系 + sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long[] ids) { - //删除角色 - baseDao.deleteBatchIds(Arrays.asList(ids)); + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除角色 + baseDao.deleteBatchIds(Arrays.asList(ids)); - //删除角色用户关系 - sysRoleUserService.deleteByRoleIds(ids); + //删除角色用户关系 + sysRoleUserService.deleteByRoleIds(ids); - //删除角色菜单关系 - sysRoleMenuService.deleteByRoleIds(ids); + //删除角色菜单关系 + sysRoleMenuService.deleteByRoleIds(ids); - //删除角色数据权限关系 - sysRoleDataScopeService.deleteByRoleIds(ids); - } + //删除角色数据权限关系 + sysRoleDataScopeService.deleteByRoleIds(ids); + } + + @Override + public SysRoleDTO getByName(String name) { + if (StringUtils.isEmpty(name)) { + return null; + } + return ConvertUtils.sourceToTarget(baseDao.getByName(name), SysRoleDTO.class); + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java index 3b93c576..7fdc78da 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java @@ -28,135 +28,143 @@ import java.util.Map; /** * 系统用户 - * */ @Service public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { - @Autowired - private SysRoleUserService sysRoleUserService; - @Autowired - private SysDeptService sysDeptService; - @Autowired - private SysUserPostService sysUserPostService; + @Autowired + private SysRoleUserService sysRoleUserService; + @Autowired + private SysDeptService sysDeptService; + @Autowired + private SysUserPostService sysUserPostService; - @Override - public PageData page(Map params) { - //转换成like - paramsToLike(params, "username"); + @Override + public PageData page(Map params) { + //转换成like + paramsToLike(params, "username"); - //分页 - IPage page = getPage(params, Constant.CREATE_DATE, false); + //分页 + IPage page = getPage(params, Constant.CREATE_DATE, false); - //普通管理员,只能查询所属部门及子部门的数据 - UserDetail user = SecurityUser.getUser(); - if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { - params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); - } + //普通管理员,只能查询所属部门及子部门的数据 + UserDetail user = SecurityUser.getUser(); + if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); + } - //查询 - List list = baseDao.getList(params); + //查询 + List list = baseDao.getList(params); - return getPageData(list, page.getTotal(), SysUserDTO.class); - } + return getPageData(list, page.getTotal(), SysUserDTO.class); + } - @Override - public List list(Map params) { - //普通管理员,只能查询所属部门及子部门的数据 - UserDetail user = SecurityUser.getUser(); - if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { - params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); - } + @Override + public List list(Map params) { + //普通管理员,只能查询所属部门及子部门的数据 + UserDetail user = SecurityUser.getUser(); + if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); + } - List entityList = baseDao.getList(params); + List entityList = baseDao.getList(params); - return ConvertUtils.sourceToTarget(entityList, SysUserDTO.class); - } + return ConvertUtils.sourceToTarget(entityList, SysUserDTO.class); + } - @Override - public SysUserDTO get(Long id) { - SysUserEntity entity = baseDao.getById(id); + @Override + public SysUserDTO get(Long id) { + SysUserEntity entity = baseDao.getById(id); - return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); - } + return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); + } - @Override - public SysUserDTO getByUsername(String username) { - SysUserEntity entity = baseDao.getByUsername(username); - return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); - } + @Override + public SysUserDTO getByUsername(String username) { + SysUserEntity entity = baseDao.getByUsername(username); + return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void save(SysUserDTO dto) { - SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysUserDTO dto) { + SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); - //密码加密 - String password = PasswordUtils.encode(entity.getPassword()); - entity.setPassword(password); + //密码加密 + String password = PasswordUtils.encode(entity.getPassword()); + entity.setPassword(password); - //保存用户 - entity.setSuperAdmin(SuperAdminEnum.NO.value()); - insert(entity); + //保存用户 + entity.setSuperAdmin(SuperAdminEnum.NO.value()); + insert(entity); - //保存角色用户关系 - sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); + //保存角色用户关系 + sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); - //保存用户岗位关系 - sysUserPostService.saveOrUpdate(entity.getId(), dto.getPostIdList()); - } + //保存用户岗位关系 + sysUserPostService.saveOrUpdate(entity.getId(), dto.getPostIdList()); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void update(SysUserDTO dto) { - SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysUserDTO dto) { + SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); - //密码加密 - if(StringUtils.isBlank(dto.getPassword())){ - entity.setPassword(null); - }else{ - String password = PasswordUtils.encode(entity.getPassword()); - entity.setPassword(password); - } + //密码加密 + if (StringUtils.isBlank(dto.getPassword())) { + entity.setPassword(null); + } else { + String password = PasswordUtils.encode(entity.getPassword()); + entity.setPassword(password); + } - //更新用户 - updateById(entity); + //更新用户 + updateById(entity); - //更新角色用户关系 - sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); + //更新角色用户关系 + sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); - //保存用户岗位关系 - sysUserPostService.saveOrUpdate(entity.getId(), dto.getPostIdList()); - } + //保存用户岗位关系 + sysUserPostService.saveOrUpdate(entity.getId(), dto.getPostIdList()); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long[] ids) { - //删除用户 - baseDao.deleteBatchIds(Arrays.asList(ids)); + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除用户 + baseDao.deleteBatchIds(Arrays.asList(ids)); - //删除角色用户关系 - sysRoleUserService.deleteByUserIds(ids); + //删除角色用户关系 + sysRoleUserService.deleteByUserIds(ids); - //删除用户岗位关系 - sysUserPostService.deleteByUserIds(ids); - } + //删除用户岗位关系 + sysUserPostService.deleteByUserIds(ids); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void updatePassword(Long id, String newPassword) { - newPassword = PasswordUtils.encode(newPassword); + @Override + @Transactional(rollbackFor = Exception.class) + public void updatePassword(Long id, String newPassword) { + newPassword = PasswordUtils.encode(newPassword); - baseDao.updatePassword(id, newPassword); - } + baseDao.updatePassword(id, newPassword); + } - @Override - public int getCountByDeptId(Long deptId) { - return baseDao.getCountByDeptId(deptId); - } + @Override + public int getCountByDeptId(Long deptId) { + return baseDao.getCountByDeptId(deptId); + } - @Override - public List getUserIdListByDeptId(List deptIdList) { - return baseDao.getUserIdListByDeptId(deptIdList); - } + @Override + public List getUserIdListByDeptId(List deptIdList) { + return baseDao.getUserIdListByDeptId(deptIdList); + } + + @Override + public SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId) { + if (roleId == null) { + return null; + } + SysUserEntity entity = baseDao.getByDeptIdAndRoleId(deptId, roleId); + return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); + } } diff --git a/renren-admin/src/main/resources/application-prod.yml b/renren-admin/src/main/resources/application-prod.yml index 8e237325..21683997 100644 --- a/renren-admin/src/main/resources/application-prod.yml +++ b/renren-admin/src/main/resources/application-prod.yml @@ -31,4 +31,7 @@ spring: merge-sql: false wall: config: - multi-statement-allow: true \ No newline at end of file + multi-statement-allow: true +resource: + root_url: 15.2.21.238 + path: /home/yth/files/ \ No newline at end of file diff --git a/renren-admin/src/main/resources/application.yml b/renren-admin/src/main/resources/application.yml index 5ce8003a..c95bebd2 100644 --- a/renren-admin/src/main/resources/application.yml +++ b/renren-admin/src/main/resources/application.yml @@ -1,7 +1,7 @@ #上传的静态资源配置 resource: - root_url: 127.0.0.1 - path: E:\liwen\ + root_url: 15.2.21.238 + path: /home/yth/files/ # Tomcat server: tomcat: diff --git a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml index e62a1eeb..3a569cfb 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml @@ -29,4 +29,9 @@ select id from sys_dept where pids like #{id} + + \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/sys/SysRoleDao.xml b/renren-admin/src/main/resources/mapper/sys/SysRoleDao.xml index b6b9b97b..6257530a 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysRoleDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysRoleDao.xml @@ -3,5 +3,7 @@ - + \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml index ed6972b4..fb848d71 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml @@ -3,51 +3,62 @@ - + - + - + - - update sys_user set password = #{newPassword} where id = #{id} - + + update sys_user set password = #{newPassword} where id = #{id} + - + - + + + \ No newline at end of file