根据申请填写的部门动态分配流程审批人
This commit is contained in:
parent
004537b865
commit
cc1778e40b
|
@ -22,6 +22,8 @@ import org.activiti.engine.task.Task;
|
||||||
import org.activiti.image.ProcessDiagramGenerator;
|
import org.activiti.image.ProcessDiagramGenerator;
|
||||||
import org.activiti.spring.ProcessEngineFactoryBean;
|
import org.activiti.spring.ProcessEngineFactoryBean;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ActHistoryService {
|
public class ActHistoryService {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ActHistoryService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RepositoryService repositoryService;
|
protected RepositoryService repositoryService;
|
||||||
|
@ -64,9 +67,8 @@ public class ActHistoryService {
|
||||||
private SysUserService sysUserService;
|
private SysUserService sysUserService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getProcessInstanceDiagram(String processInstanceId, HttpServletResponse response) throws Exception {
|
public void getProcessInstanceDiagram(String processInstanceId, HttpServletResponse response) throws Exception {
|
||||||
if(StringUtils.isEmpty(processInstanceId)){
|
if (StringUtils.isEmpty(processInstanceId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||||
|
@ -75,7 +77,7 @@ public class ActHistoryService {
|
||||||
Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration);
|
Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration);
|
||||||
|
|
||||||
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
|
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();
|
.asc().list();
|
||||||
|
@ -87,23 +89,25 @@ public class ActHistoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
//高亮线路id集合
|
//高亮线路id集合
|
||||||
List<String> highLightedFlows = getHighLightedFlows(definitionEntity,highLightedActivitList);
|
List<String> highLightedFlows = getHighLightedFlows(definitionEntity, highLightedActivitList);
|
||||||
|
|
||||||
ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();
|
ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();
|
||||||
if(null != execution) {
|
if (null != execution) {
|
||||||
highLightedActivitis.add(execution.getActivityId());
|
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");
|
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||||
BufferedImage bufferedImage = ImageIO.read(imageStream);
|
BufferedImage bufferedImage = ImageIO.read(imageStream);
|
||||||
ImageIO.write(bufferedImage, "png", response.getOutputStream());
|
ImageIO.write(bufferedImage, "png", response.getOutputStream());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取需要高亮的线
|
* 获取需要高亮的线
|
||||||
|
*
|
||||||
* @param processDefinitionEntity
|
* @param processDefinitionEntity
|
||||||
* @param historicActivityInstances
|
* @param historicActivityInstances
|
||||||
* @return
|
* @return
|
||||||
|
@ -119,17 +123,17 @@ public class ActHistoryService {
|
||||||
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);
|
HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j);
|
||||||
HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + 1);
|
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());
|
ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl2.getActivityId());
|
||||||
sameStartTimeNodes.add(sameActivityImpl2);
|
sameStartTimeNodes.add(sameActivityImpl2);
|
||||||
} else {
|
} else {
|
||||||
break;
|
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);
|
HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j);
|
||||||
if(null != historicActivityInstances.get(i).getEndTime()){
|
if (null != historicActivityInstances.get(i).getEndTime()) {
|
||||||
if (Math.abs(activityImpl1.getStartTime().getTime()-historicActivityInstances.get(i).getEndTime().getTime()) < 200) {
|
if (Math.abs(activityImpl1.getStartTime().getTime() - historicActivityInstances.get(i).getEndTime().getTime()) < 200) {
|
||||||
ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl1.getActivityId());
|
ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl1.getActivityId());
|
||||||
sameStartTimeNodes.add(sameActivityImpl2);
|
sameStartTimeNodes.add(sameActivityImpl2);
|
||||||
}
|
}
|
||||||
|
@ -151,50 +155,51 @@ public class ActHistoryService {
|
||||||
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
|
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
|
||||||
Integer curPage = 1;
|
Integer curPage = 1;
|
||||||
Integer limit = 10;
|
Integer limit = 10;
|
||||||
if(params.get(Constant.PAGE) != null){
|
if (params.get(Constant.PAGE) != null) {
|
||||||
curPage = Integer.parseInt((String)params.get(Constant.PAGE));
|
curPage = Integer.parseInt((String) params.get(Constant.PAGE));
|
||||||
}
|
}
|
||||||
if(params.get(Constant.LIMIT) != null){
|
if (params.get(Constant.LIMIT) != null) {
|
||||||
limit = Integer.parseInt((String)params.get(Constant.LIMIT));
|
limit = Integer.parseInt((String) params.get(Constant.LIMIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty((String)params.get("processInstanceId"))){
|
if (StringUtils.isNotEmpty((String) params.get("processInstanceId"))) {
|
||||||
query.processInstanceId((String)params.get("processInstanceId"));
|
query.processInstanceId((String) params.get("processInstanceId"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty((String)params.get("businessKey"))){
|
if (StringUtils.isNotEmpty((String) params.get("businessKey"))) {
|
||||||
query.processInstanceBusinessKey((String)params.get("businessKey"));
|
query.processInstanceBusinessKey((String) params.get("businessKey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty((String)params.get("processDefinitionId"))){
|
if (StringUtils.isNotEmpty((String) params.get("processDefinitionId"))) {
|
||||||
query.processDefinitionId((String)params.get("processDefinitionId"));
|
query.processDefinitionId((String) params.get("processDefinitionId"));
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotEmpty((String)params.get("ended"))){
|
if (StringUtils.isNotEmpty((String) params.get("ended"))) {
|
||||||
if("true".equals((String)params.get("ended"))){
|
logger.info("ended参数值为:" + (String) params.get("ended"));
|
||||||
|
if ("true".equals((String) params.get("ended"))) {
|
||||||
query.finished();
|
query.finished();
|
||||||
} else if("false".equals((String)params.get("ended"))){
|
} else if ("false".equals((String) params.get("ended"))) {
|
||||||
query.unfinished();
|
query.unfinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(null != params.get("finishedBeginTime")){
|
if (null != params.get("finishedBeginTime")) {
|
||||||
query.finishedAfter((Date) 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"));
|
query.finishedBefore((Date) params.get("finishedEndTime"));
|
||||||
}
|
}
|
||||||
if(null != params.get("startBeginTime")){
|
if (null != params.get("startBeginTime")) {
|
||||||
query.startedAfter((Date) 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"));
|
query.startedBefore((Date) params.get("startEndTime"));
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotEmpty((String)params.get("startBy"))){
|
if (StringUtils.isNotEmpty((String) params.get("startBy"))) {
|
||||||
query.startedBy((String)params.get("startBy"));
|
query.startedBy((String) params.get("startBy"));
|
||||||
}
|
}
|
||||||
query.orderByProcessInstanceStartTime().desc();
|
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<>();
|
List<ProcessInstanceDTO> listInstance = new ArrayList<>();
|
||||||
if(!list.isEmpty()){
|
if (!list.isEmpty()) {
|
||||||
this.converHistoricProcessInstance(list, listInstance);
|
this.converHistoricProcessInstance(list, listInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,14 +207,14 @@ public class ActHistoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void converHistoricProcessInstance(List<HistoricProcessInstance> list, List<ProcessInstanceDTO> listInstance) {
|
private void converHistoricProcessInstance(List<HistoricProcessInstance> list, List<ProcessInstanceDTO> listInstance) {
|
||||||
for(HistoricProcessInstance historicProcessInstance : list){
|
for (HistoricProcessInstance historicProcessInstance : list) {
|
||||||
ProcessInstanceDTO dto = new ProcessInstanceDTO();
|
ProcessInstanceDTO dto = new ProcessInstanceDTO();
|
||||||
dto.setProcessDefinitionId(historicProcessInstance.getProcessDefinitionId());
|
dto.setProcessDefinitionId(historicProcessInstance.getProcessDefinitionId());
|
||||||
dto.setProcessInstanceId(historicProcessInstance.getId());
|
dto.setProcessInstanceId(historicProcessInstance.getId());
|
||||||
dto.setProcessDefinitionVersion(historicProcessInstance.getProcessDefinitionVersion());
|
dto.setProcessDefinitionVersion(historicProcessInstance.getProcessDefinitionVersion());
|
||||||
dto.setProcessDefinitionName(historicProcessInstance.getProcessDefinitionName());
|
dto.setProcessDefinitionName(historicProcessInstance.getProcessDefinitionName());
|
||||||
dto.setProcessDefinitionKey(historicProcessInstance.getProcessDefinitionKey());
|
dto.setProcessDefinitionKey(historicProcessInstance.getProcessDefinitionKey());
|
||||||
if(null != historicProcessInstance.getEndTime()){
|
if (null != historicProcessInstance.getEndTime()) {
|
||||||
dto.setEnded(true);
|
dto.setEnded(true);
|
||||||
} else {
|
} else {
|
||||||
dto.setEnded(false);
|
dto.setEnded(false);
|
||||||
|
@ -226,6 +231,7 @@ public class ActHistoryService {
|
||||||
/**
|
/**
|
||||||
* 我发起的流程
|
* 我发起的流程
|
||||||
* 根据登录用户信息获取处理中的示例和任务信息
|
* 根据登录用户信息获取处理中的示例和任务信息
|
||||||
|
*
|
||||||
* @param params
|
* @param params
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -233,16 +239,16 @@ public class ActHistoryService {
|
||||||
params.put("startBy", SecurityUser.getUserId().toString());
|
params.put("startBy", SecurityUser.getUserId().toString());
|
||||||
PageData<ProcessInstanceDTO> pageData = this.getHistoryProcessInstancePage(params);
|
PageData<ProcessInstanceDTO> pageData = this.getHistoryProcessInstancePage(params);
|
||||||
List<ProcessInstanceDTO> list = pageData.getList();
|
List<ProcessInstanceDTO> list = pageData.getList();
|
||||||
for(ProcessInstanceDTO dto : list){
|
for (ProcessInstanceDTO dto : list) {
|
||||||
if(dto.isEnded()){
|
if (dto.isEnded()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<Task> listTask = taskService.createTaskQuery().processInstanceId(dto.getProcessInstanceId()).list();
|
List<Task> listTask = taskService.createTaskQuery().processInstanceId(dto.getProcessInstanceId()).list();
|
||||||
List<TaskDTO> taskDTOList = new ArrayList<>();
|
List<TaskDTO> taskDTOList = new ArrayList<>();
|
||||||
for(Task task : listTask){
|
for (Task task : listTask) {
|
||||||
TaskDTO taskDTO = new TaskDTO();
|
TaskDTO taskDTO = new TaskDTO();
|
||||||
this.convertTaskInfo(task, taskDTO);
|
this.convertTaskInfo(task, taskDTO);
|
||||||
if(StringUtils.isNotEmpty(taskDTO.getAssignee())){
|
if (StringUtils.isNotEmpty(taskDTO.getAssignee())) {
|
||||||
SysUserDTO userDTO = sysUserService.get(Long.valueOf(taskDTO.getAssignee()));
|
SysUserDTO userDTO = sysUserService.get(Long.valueOf(taskDTO.getAssignee()));
|
||||||
taskDTO.setAssigneeName(userDTO.getRealName());
|
taskDTO.setAssigneeName(userDTO.getRealName());
|
||||||
}
|
}
|
||||||
|
@ -255,6 +261,7 @@ public class ActHistoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换Task对象
|
* 转换Task对象
|
||||||
|
*
|
||||||
* @param task
|
* @param task
|
||||||
* @param dto
|
* @param dto
|
||||||
*/
|
*/
|
||||||
|
@ -271,16 +278,16 @@ public class ActHistoryService {
|
||||||
|
|
||||||
public ProcessInstanceDTO getHistoryProcessInstanceByBusinessKey(String procDefKey, String businessKey) {
|
public ProcessInstanceDTO getHistoryProcessInstanceByBusinessKey(String procDefKey, String businessKey) {
|
||||||
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
|
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
|
||||||
if(StringUtils.isNotEmpty(businessKey)){
|
if (StringUtils.isNotEmpty(businessKey)) {
|
||||||
query.processInstanceBusinessKey(businessKey);
|
query.processInstanceBusinessKey(businessKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty(procDefKey)){
|
if (StringUtils.isNotEmpty(procDefKey)) {
|
||||||
query.processDefinitionKey(procDefKey);
|
query.processDefinitionKey(procDefKey);
|
||||||
}
|
}
|
||||||
List<HistoricProcessInstance> list = query.list();
|
List<HistoricProcessInstance> list = query.list();
|
||||||
List<ProcessInstanceDTO> listInstance = new ArrayList<>();
|
List<ProcessInstanceDTO> listInstance = new ArrayList<>();
|
||||||
if(!list.isEmpty()){
|
if (!list.isEmpty()) {
|
||||||
this.converHistoricProcessInstance(list, listInstance);
|
this.converHistoricProcessInstance(list, listInstance);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -3,6 +3,10 @@ package io.renren.modules.processForm.listener;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import io.renren.modules.processForm.dto.TAbilityApplicationDTO;
|
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.SysRoleService;
|
||||||
import io.renren.modules.sys.service.SysRoleUserService;
|
import io.renren.modules.sys.service.SysRoleUserService;
|
||||||
import io.renren.modules.sys.service.SysUserService;
|
import io.renren.modules.sys.service.SysUserService;
|
||||||
|
@ -21,6 +25,8 @@ import java.util.Map;
|
||||||
public class CorrectionListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate {
|
public class CorrectionListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate {
|
||||||
private static Logger logger = LoggerFactory.getLogger(CorrectionListener.class);
|
private static Logger logger = LoggerFactory.getLogger(CorrectionListener.class);
|
||||||
|
|
||||||
|
private static String roleName = "部门审批人";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleService sysRoleService;
|
private SysRoleService sysRoleService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -29,23 +35,28 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti
|
||||||
private SysUserService sysUserService;
|
private SysUserService sysUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleUserService sysRoleUserService;
|
private SysRoleUserService sysRoleUserService;
|
||||||
|
@Autowired
|
||||||
|
private SysDeptService sysDeptService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notify(DelegateTask delegateTask) {
|
public void notify(DelegateTask delegateTask) {
|
||||||
logger.info("进入DelegateTask");
|
|
||||||
logger.info("EventName:" + delegateTask.getEventName());
|
|
||||||
logger.info("Owner:" + delegateTask.getOwner());
|
|
||||||
Map<String, Object> kv = delegateTask.getVariables();
|
Map<String, Object> kv = delegateTask.getVariables();
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
JsonElement jsonElement = gson.toJsonTree(kv);
|
JsonElement jsonElement = gson.toJsonTree(kv);
|
||||||
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
|
TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class);
|
||||||
logger.info(abilityApplicationDTO.toString());
|
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");
|
delegateTask.setAssignee("1513432847327199233");
|
||||||
String taskKey = delegateTask.getTaskDefinitionKey();
|
SysUserDTO userDTO = sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId());
|
||||||
taskService.setAssignee(delegateTask.getId(), "1516307964617076737");
|
if (userDTO != null) {
|
||||||
String processDefinitionId = delegateTask.getProcessDefinitionId();
|
logger.info("审批人id:" + userDTO.getId());
|
||||||
|
taskService.setAssignee(delegateTask.getId(), userDTO.getId().toString());
|
||||||
|
} else {
|
||||||
|
logger.info("未查到该部门对应 " + roleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,4 +29,11 @@ public interface SysDeptDao extends BaseDao<SysDeptEntity> {
|
||||||
*/
|
*/
|
||||||
List<Long> getSubDeptIdList(String id);
|
List<Long> getSubDeptIdList(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称获取部门所有信息
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysDeptEntity getByName(String name);
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,10 +6,9 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色管理
|
* 角色管理
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysRoleDao extends BaseDao<SysRoleEntity> {
|
public interface SysRoleDao extends BaseDao<SysRoleEntity> {
|
||||||
|
|
||||||
|
SysRoleEntity getByName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysUserDao extends BaseDao<SysUserEntity> {
|
public interface SysUserDao extends BaseDao<SysUserEntity> {
|
||||||
|
@ -32,4 +31,12 @@ public interface SysUserDao extends BaseDao<SysUserEntity> {
|
||||||
* 根据部门ID,查询用户ID列表
|
* 根据部门ID,查询用户ID列表
|
||||||
*/
|
*/
|
||||||
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
|
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取该部门拥有该权限的用户信息
|
||||||
|
* @param deptId
|
||||||
|
* @param roleId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysUserEntity getByDeptIdAndRoleId(@Param("deptId") Long deptId, @Param("roleId") Long roleId);
|
||||||
}
|
}
|
|
@ -28,4 +28,6 @@ public interface SysDeptService extends BaseService<SysDeptEntity> {
|
||||||
* @param id 部门ID
|
* @param id 部门ID
|
||||||
*/
|
*/
|
||||||
List<Long> getSubDeptIdList(Long id);
|
List<Long> getSubDeptIdList(Long id);
|
||||||
|
|
||||||
|
SysDeptDTO getByName(String name);
|
||||||
}
|
}
|
|
@ -28,4 +28,6 @@ public interface SysRoleService extends BaseService<SysRoleEntity> {
|
||||||
|
|
||||||
void delete(Long[] ids);
|
void delete(Long[] ids);
|
||||||
|
|
||||||
|
SysRoleDTO getByName(String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface SysUserService extends BaseService<SysUserEntity> {
|
public interface SysUserService extends BaseService<SysUserEntity> {
|
||||||
|
|
||||||
|
@ -31,6 +30,7 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改密码
|
* 修改密码
|
||||||
|
*
|
||||||
* @param id 用户ID
|
* @param id 用户ID
|
||||||
* @param newPassword 新密码
|
* @param newPassword 新密码
|
||||||
*/
|
*/
|
||||||
|
@ -46,4 +46,6 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
||||||
*/
|
*/
|
||||||
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
|
List<Long> getUserIdListByDeptId(List<Long> deptIdList);
|
||||||
|
|
||||||
|
SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
public List<SysDeptDTO> list(Map<String, Object> params) {
|
public List<SysDeptDTO> list(Map<String, Object> params) {
|
||||||
//普通管理员,只能查询所属部门及子部门的数据
|
//普通管理员,只能查询所属部门及子部门的数据
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
||||||
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
|
params.put("deptIdList", getSubDeptIdList(user.getDeptId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
@Override
|
@Override
|
||||||
public SysDeptDTO get(Long id) {
|
public SysDeptDTO get(Long id) {
|
||||||
//超级管理员,部门ID为null
|
//超级管理员,部门ID为null
|
||||||
if(id == null){
|
if (id == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +70,13 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class);
|
SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class);
|
||||||
|
|
||||||
//上级部门不能为自身
|
//上级部门不能为自身
|
||||||
if(entity.getId().equals(entity.getPid())){
|
if (entity.getId().equals(entity.getPid())) {
|
||||||
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
|
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
//上级部门不能为下级部门
|
//上级部门不能为下级部门
|
||||||
List<Long> subDeptList = getSubDeptIdList(entity.getId());
|
List<Long> subDeptList = getSubDeptIdList(entity.getId());
|
||||||
if(subDeptList.contains(entity.getPid())){
|
if (subDeptList.contains(entity.getPid())) {
|
||||||
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
|
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,13 +89,13 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
//判断是否有子部门
|
//判断是否有子部门
|
||||||
List<Long> subList = getSubDeptIdList(id);
|
List<Long> subList = getSubDeptIdList(id);
|
||||||
if(subList.size() > 1){
|
if (subList.size() > 1) {
|
||||||
throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR);
|
throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断部门下面是否有用户
|
//判断部门下面是否有用户
|
||||||
int count = sysUserService.getCountByDeptId(id);
|
int count = sysUserService.getCountByDeptId(id);
|
||||||
if(count > 0){
|
if (count > 0) {
|
||||||
throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR);
|
throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,13 +111,23 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
return deptIdList;
|
return deptIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysDeptDTO getByName(String name) {
|
||||||
|
if (StringUtils.isEmpty(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SysDeptEntity entity = baseDao.getByName(name);
|
||||||
|
return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有上级部门ID
|
* 获取所有上级部门ID
|
||||||
|
*
|
||||||
* @param pid 上级ID
|
* @param pid 上级ID
|
||||||
*/
|
*/
|
||||||
private String getPidList(Long pid){
|
private String getPidList(Long pid) {
|
||||||
//顶级部门,无上级部门
|
//顶级部门,无上级部门
|
||||||
if(Constant.DEPT_ROOT.equals(pid)){
|
if (Constant.DEPT_ROOT.equals(pid)) {
|
||||||
return Constant.DEPT_ROOT + "";
|
return Constant.DEPT_ROOT + "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +136,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
|
|
||||||
//list转map
|
//list转map
|
||||||
Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
|
Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
|
||||||
for(SysDeptEntity entity : deptList){
|
for (SysDeptEntity entity : deptList) {
|
||||||
map.put(entity.getId(), entity);
|
map.put(entity.getId(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,13 +149,13 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit
|
||||||
|
|
||||||
private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> pidList) {
|
private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> pidList) {
|
||||||
//顶级部门,无上级部门
|
//顶级部门,无上级部门
|
||||||
if(Constant.DEPT_ROOT.equals(pid)){
|
if (Constant.DEPT_ROOT.equals(pid)) {
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//上级部门存在
|
//上级部门存在
|
||||||
SysDeptEntity parent = map.get(pid);
|
SysDeptEntity parent = map.get(pid);
|
||||||
if(parent != null){
|
if (parent != null) {
|
||||||
getPidTree(parent.getPid(), map, pidList);
|
getPidTree(parent.getPid(), map, pidList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色
|
* 角色
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
|
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
|
||||||
|
@ -54,15 +53,15 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntit
|
||||||
return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class);
|
return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private QueryWrapper<SysRoleEntity> getWrapper(Map<String, Object> params){
|
private QueryWrapper<SysRoleEntity> getWrapper(Map<String, Object> params) {
|
||||||
String name = (String)params.get("name");
|
String name = (String) params.get("name");
|
||||||
|
|
||||||
QueryWrapper<SysRoleEntity> wrapper = new QueryWrapper<>();
|
QueryWrapper<SysRoleEntity> wrapper = new QueryWrapper<>();
|
||||||
wrapper.like(StringUtils.isNotBlank(name), "name", name);
|
wrapper.like(StringUtils.isNotBlank(name), "name", name);
|
||||||
|
|
||||||
//普通管理员,只能查询所属部门及子部门的数据
|
//普通管理员,只能查询所属部门及子部门的数据
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
||||||
List<Long> deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId());
|
List<Long> deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId());
|
||||||
wrapper.in(deptIdList != null, "dept_id", deptIdList);
|
wrapper.in(deptIdList != null, "dept_id", deptIdList);
|
||||||
}
|
}
|
||||||
|
@ -123,4 +122,12 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntit
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,7 +28,6 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||||
|
@ -49,7 +48,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||||
|
|
||||||
//普通管理员,只能查询所属部门及子部门的数据
|
//普通管理员,只能查询所属部门及子部门的数据
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
||||||
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
|
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||||
public List<SysUserDTO> list(Map<String, Object> params) {
|
public List<SysUserDTO> list(Map<String, Object> params) {
|
||||||
//普通管理员,只能查询所属部门及子部门的数据
|
//普通管理员,只能查询所属部门及子部门的数据
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) {
|
||||||
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
|
params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +110,9 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||||
SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class);
|
SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class);
|
||||||
|
|
||||||
//密码加密
|
//密码加密
|
||||||
if(StringUtils.isBlank(dto.getPassword())){
|
if (StringUtils.isBlank(dto.getPassword())) {
|
||||||
entity.setPassword(null);
|
entity.setPassword(null);
|
||||||
}else{
|
} else {
|
||||||
String password = PasswordUtils.encode(entity.getPassword());
|
String password = PasswordUtils.encode(entity.getPassword());
|
||||||
entity.setPassword(password);
|
entity.setPassword(password);
|
||||||
}
|
}
|
||||||
|
@ -159,4 +158,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||||
return baseDao.getUserIdListByDeptId(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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,3 +32,6 @@ spring:
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
resource:
|
||||||
|
root_url: 15.2.21.238
|
||||||
|
path: /home/yth/files/
|
|
@ -1,7 +1,7 @@
|
||||||
#上传的静态资源配置
|
#上传的静态资源配置
|
||||||
resource:
|
resource:
|
||||||
root_url: 127.0.0.1
|
root_url: 15.2.21.238
|
||||||
path: E:\liwen\
|
path: /home/yth/files/
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|
|
@ -29,4 +29,9 @@
|
||||||
select id from sys_dept where pids like #{id}
|
select id from sys_dept where pids like #{id}
|
||||||
</select>
|
</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>
|
</mapper>
|
|
@ -3,5 +3,7 @@
|
||||||
|
|
||||||
<mapper namespace="io.renren.modules.sys.dao.SysRoleDao">
|
<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>
|
</mapper>
|
|
@ -50,4 +50,15 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</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>
|
</mapper>
|
Loading…
Reference in New Issue