根据申请填写的部门动态分配流程审批人

This commit is contained in:
wangliwen 2022-04-20 15:05:19 +08:00
parent 004537b865
commit cc1778e40b
16 changed files with 492 additions and 409 deletions

View File

@ -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<HistoricActivityInstance> highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime()
List<HistoricActivityInstance> highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime()
.asc().list();
//高亮环节id集合
List<String> highLightedActivitis = new ArrayList<String>();
@ -87,29 +89,31 @@ public class ActHistoryService {
}
//高亮线路id集合
List<String> highLightedFlows = getHighLightedFlows(definitionEntity,highLightedActivitList);
List<String> 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<String> getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity,
List<HistoricActivityInstance> historicActivityInstances) {
List<HistoricActivityInstance> historicActivityInstances) {
List<String> 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<HistoricProcessInstance> list = query.listPage((curPage-1)*limit, limit);
List<HistoricProcessInstance> list = query.listPage((curPage - 1) * limit, limit);
List<ProcessInstanceDTO> listInstance = new ArrayList<>();
if(!list.isEmpty()){
if (!list.isEmpty()) {
this.converHistoricProcessInstance(list, listInstance);
}
@ -202,14 +207,14 @@ public class ActHistoryService {
}
private void converHistoricProcessInstance(List<HistoricProcessInstance> list, List<ProcessInstanceDTO> 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<ProcessInstanceDTO> pageData = this.getHistoryProcessInstancePage(params);
List<ProcessInstanceDTO> list = pageData.getList();
for(ProcessInstanceDTO dto : list){
if(dto.isEnded()){
for (ProcessInstanceDTO dto : list) {
if (dto.isEnded()) {
continue;
}
List<Task> listTask = taskService.createTaskQuery().processInstanceId(dto.getProcessInstanceId()).list();
List<TaskDTO> 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<HistoricProcessInstance> list = query.list();
List<HistoricProcessInstance> list = query.list();
List<ProcessInstanceDTO> listInstance = new ArrayList<>();
if(!list.isEmpty()){
if (!list.isEmpty()) {
this.converHistoricProcessInstance(list, listInstance);
} else {
return null;

View File

@ -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<String, Object> 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

View File

@ -29,4 +29,11 @@ public interface SysDeptDao extends BaseDao<SysDeptEntity> {
*/
List<Long> getSubDeptIdList(String id);
/**
* 根据名称获取部门所有信息
* @param name
* @return
*/
SysDeptEntity getByName(String name);
}

View File

@ -6,10 +6,9 @@ import org.apache.ibatis.annotations.Mapper;
/**
* 角色管理
*
*/
@Mapper
public interface SysRoleDao extends BaseDao<SysRoleEntity> {
SysRoleEntity getByName(String name);
}

View File

@ -10,26 +10,33 @@ import java.util.Map;
/**
* 系统用户
*
*/
@Mapper
public interface SysUserDao extends BaseDao<SysUserEntity> {
List<SysUserEntity> getList(Map<String, Object> params);
List<SysUserEntity> getList(Map<String, Object> 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<Long> getUserIdListByDeptId(List<Long> deptIdList);
/**
* 根据部门ID,查询用户ID列表
*/
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
/**
* 获取该部门拥有该权限的用户信息
* @param deptId
* @param roleId
* @return
*/
SysUserEntity getByDeptIdAndRoleId(@Param("deptId") Long deptId, @Param("roleId") Long roleId);
}

View File

@ -28,4 +28,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
* @param id 部门ID
*/
List<Long> getSubDeptIdList(Long id);
SysDeptDTO getByName(String name);
}

View File

@ -28,4 +28,6 @@ public interface SysRoleService extends BaseService<SysRoleEntity> {
void delete(Long[] ids);
SysRoleDTO getByName(String name);
}

View File

@ -11,39 +11,41 @@ import java.util.Map;
/**
* 系统用户
*
*/
public interface SysUserService extends BaseService<SysUserEntity> {
PageData<SysUserDTO> page(Map<String, Object> params);
PageData<SysUserDTO> page(Map<String, Object> params);
List<SysUserDTO> list(Map<String, Object> params);
List<SysUserDTO> list(Map<String, Object> 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<Long> getUserIdListByDeptId(List<Long> deptIdList);
/**
* 根据部门ID,查询用户Id列表
*/
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId);
}

View File

@ -24,131 +24,141 @@ import java.util.*;
@Service
public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntity> implements SysDeptService {
@Autowired
private SysUserService sysUserService;
@Autowired
private SysUserService sysUserService;
@Override
public List<SysDeptDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
}
@Override
public List<SysDeptDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
}
//查询部门列表
List<SysDeptEntity> entityList = baseDao.getList(params);
//查询部门列表
List<SysDeptEntity> entityList = baseDao.getList(params);
List<SysDeptDTO> dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class);
List<SysDeptDTO> 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<Long> subDeptList = getSubDeptIdList(entity.getId());
if(subDeptList.contains(entity.getPid())){
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
}
//上级部门不能为下级部门
List<Long> 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<Long> 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<Long> 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<Long> getSubDeptIdList(Long id) {
List<Long> deptIdList = baseDao.getSubDeptIdList("%" + id + "%");
deptIdList.add(id);
@Override
public List<Long> getSubDeptIdList(Long id) {
List<Long> 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);
}
//所有部门的idpid列表
List<SysDeptEntity> 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<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
for(SysDeptEntity entity : deptList){
map.put(entity.getId(), entity);
}
//所有部门的idpid列表
List<SysDeptEntity> deptList = baseDao.getIdAndPidList();
//递归查询所有上级部门ID列表
List<Long> pidList = new ArrayList<>();
getPidTree(pid, map, pidList);
//list转map
Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
for (SysDeptEntity entity : deptList) {
map.put(entity.getId(), entity);
}
return StringUtils.join(pidList, ",");
}
//递归查询所有上级部门ID列表
List<Long> pidList = new ArrayList<>();
getPidTree(pid, map, pidList);
private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> 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<Long, SysDeptEntity> map, List<Long> 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);
}
}

View File

@ -24,103 +24,110 @@ import java.util.Map;
/**
* 角色
*
*/
@Service
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> 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<SysRoleDTO> page(Map<String, Object> params) {
IPage<SysRoleEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
@Override
public PageData<SysRoleDTO> page(Map<String, Object> params) {
IPage<SysRoleEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, SysRoleDTO.class);
}
return getPageData(page, SysRoleDTO.class);
}
@Override
public List<SysRoleDTO> list(Map<String, Object> params) {
List<SysRoleEntity> entityList = baseDao.selectList(getWrapper(params));
@Override
public List<SysRoleDTO> list(Map<String, Object> params) {
List<SysRoleEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class);
}
return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class);
}
private QueryWrapper<SysRoleEntity> getWrapper(Map<String, Object> params){
String name = (String)params.get("name");
private QueryWrapper<SysRoleEntity> getWrapper(Map<String, Object> params) {
String name = (String) params.get("name");
QueryWrapper<SysRoleEntity> wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotBlank(name), "name", name);
QueryWrapper<SysRoleEntity> wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotBlank(name), "name", name);
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
List<Long> deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId());
wrapper.in(deptIdList != null, "dept_id", deptIdList);
}
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
List<Long> 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);
}
}

View File

@ -28,135 +28,143 @@ import java.util.Map;
/**
* 系统用户
*
*/
@Service
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> 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<SysUserDTO> page(Map<String, Object> params) {
//转换成like
paramsToLike(params, "username");
@Override
public PageData<SysUserDTO> page(Map<String, Object> params) {
//转换成like
paramsToLike(params, "username");
//分页
IPage<SysUserEntity> page = getPage(params, Constant.CREATE_DATE, false);
//分页
IPage<SysUserEntity> 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<SysUserEntity> list = baseDao.getList(params);
//查询
List<SysUserEntity> list = baseDao.getList(params);
return getPageData(list, page.getTotal(), SysUserDTO.class);
}
return getPageData(list, page.getTotal(), SysUserDTO.class);
}
@Override
public List<SysUserDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
}
@Override
public List<SysUserDTO> list(Map<String, Object> params) {
//普通管理员只能查询所属部门及子部门的数据
UserDetail user = SecurityUser.getUser();
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
}
List<SysUserEntity> entityList = baseDao.getList(params);
List<SysUserEntity> 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<Long> getUserIdListByDeptId(List<Long> deptIdList) {
return baseDao.getUserIdListByDeptId(deptIdList);
}
@Override
public List<Long> getUserIdListByDeptId(List<Long> 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);
}
}

View File

@ -31,4 +31,7 @@ spring:
merge-sql: false
wall:
config:
multi-statement-allow: true
multi-statement-allow: true
resource:
root_url: 15.2.21.238
path: /home/yth/files/

View File

@ -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:

View File

@ -29,4 +29,9 @@
select id from sys_dept where pids like #{id}
</select>
<select id="getByName" resultType="io.renren.modules.sys.entity.SysDeptEntity">
select t1.*,(select t2.name from sys_dept t2 where t2.id=t1.pid)parentName from sys_dept t1
where t1.name = #{name}
</select>
</mapper>

View File

@ -3,5 +3,7 @@
<mapper namespace="io.renren.modules.sys.dao.SysRoleDao">
<select id="getByName" resultType="io.renren.modules.sys.entity.SysRoleEntity">
SELECT * FROM sys_role WHERE `name` = #{name}
</select>
</mapper>

View File

@ -3,51 +3,62 @@
<mapper namespace="io.renren.modules.sys.dao.SysUserDao">
<select id="getList" resultType="io.renren.modules.sys.entity.SysUserEntity">
select t1.*, (select t2.name from sys_dept t2 where t2.id=t1.dept_id) deptName
from sys_user t1, sys_user_post t3 where t1.id = t3.user_id and t1.super_admin = 0
<if test="username != null and username.trim() != ''">
and t1.username like #{username}
</if>
<if test="deptId != null and deptId.trim() != ''">
and t1.dept_id = #{deptId}
</if>
<if test="postId != null and postId.trim() != ''">
and t3.post_id = #{postId}
</if>
<if test="gender != null and gender.trim() != ''">
and t1.gender = #{gender}
</if>
<if test="deptIdList != null">
and t1.dept_id in
<foreach item="id" collection="deptIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="getList" resultType="io.renren.modules.sys.entity.SysUserEntity">
select t1.*, (select t2.name from sys_dept t2 where t2.id=t1.dept_id) deptName
from sys_user t1, sys_user_post t3 where t1.id = t3.user_id and t1.super_admin = 0
<if test="username != null and username.trim() != ''">
and t1.username like #{username}
</if>
<if test="deptId != null and deptId.trim() != ''">
and t1.dept_id = #{deptId}
</if>
<if test="postId != null and postId.trim() != ''">
and t3.post_id = #{postId}
</if>
<if test="gender != null and gender.trim() != ''">
and t1.gender = #{gender}
</if>
<if test="deptIdList != null">
and t1.dept_id in
<foreach item="id" collection="deptIdList" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="getById" resultType="io.renren.modules.sys.entity.SysUserEntity">
select t1.*, (select t2.name from sys_dept t2 where t2.id=t1.dept_id) deptName from sys_user t1
where t1.id = #{value}
</select>
<select id="getById" resultType="io.renren.modules.sys.entity.SysUserEntity">
select t1.*, (select t2.name from sys_dept t2 where t2.id=t1.dept_id) deptName from sys_user t1
where t1.id = #{value}
</select>
<select id="getByUsername" resultType="io.renren.modules.sys.entity.SysUserEntity">
select * from sys_user where username = #{value}
</select>
<select id="getByUsername" resultType="io.renren.modules.sys.entity.SysUserEntity">
select * from sys_user where username = #{value}
</select>
<update id="updatePassword">
update sys_user set password = #{newPassword} where id = #{id}
</update>
<update id="updatePassword">
update sys_user set password = #{newPassword} where id = #{id}
</update>
<select id="getCountByDeptId" resultType="int">
select count(*) from sys_user where dept_id = #{value}
</select>
<select id="getCountByDeptId" resultType="int">
select count(*) from sys_user where dept_id = #{value}
</select>
<select id="getUserIdListByDeptId" resultType="Long">
select id from sys_user where dept_id in
<foreach item="deptId" collection="list" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<select id="getUserIdListByDeptId" resultType="Long">
select id from sys_user where dept_id in
<foreach item="deptId" collection="list" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<select id="getByDeptIdAndRoleId" resultType="io.renren.modules.sys.entity.SysUserEntity">
SELECT t2.*,( SELECT t3.NAME FROM sys_dept t3 WHERE t3.id = t2.dept_id )
FROM
sys_role_user t1,
sys_user t2
WHERE
t2.id = t1.user_id
AND t1.role_id = #{roleId}
AND t2.dept_id = #{deptId}
</select>
</mapper>