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

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.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,20 +67,19 @@ 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();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()); BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
processEngineConfiguration = processEngine.getProcessEngineConfiguration(); processEngineConfiguration = processEngine.getProcessEngineConfiguration();
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();
//高亮环节id集合 //高亮环节id集合
List<String> highLightedActivitis = new ArrayList<String>(); List<String> highLightedActivitis = new ArrayList<String>();
@ -87,29 +89,31 @@ 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
*/ */
private List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity, private List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity,
List<HistoricActivityInstance> historicActivityInstances) { List<HistoricActivityInstance> historicActivityInstances) {
List<String> highFlows = new ArrayList<>(); List<String> highFlows = new ArrayList<>();
for (int i = 0; i < historicActivityInstances.size() - 1; i++) { for (int i = 0; i < historicActivityInstances.size() - 1; i++) {
ActivityImpl activityImpl = processDefinitionEntity.findActivity(historicActivityInstances.get(i).getActivityId()); 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++) { 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;

View File

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

View File

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

View File

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

View File

@ -10,26 +10,33 @@ import java.util.Map;
/** /**
* 系统用户 * 系统用户
*
*/ */
@Mapper @Mapper
public interface SysUserDao extends BaseDao<SysUserEntity> { 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查询用户数 * 根据部门ID查询用户数
*/ */
int getCountByDeptId(Long deptId); int getCountByDeptId(Long deptId);
/** /**
* 根据部门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);
} }

View File

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

View File

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

View File

@ -11,39 +11,41 @@ import java.util.Map;
/** /**
* 系统用户 * 系统用户
*
*/ */
public interface SysUserService extends BaseService<SysUserEntity> { 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 新密码 * @param id 用户ID
*/ * @param newPassword 新密码
void updatePassword(Long id, String newPassword); */
void updatePassword(Long id, String newPassword);
/** /**
* 根据部门ID查询用户数 * 根据部门ID查询用户数
*/ */
int getCountByDeptId(Long deptId); int getCountByDeptId(Long deptId);
/** /**
* 根据部门ID,查询用户Id列表 * 根据部门ID,查询用户Id列表
*/ */
List<Long> getUserIdListByDeptId(List<Long> deptIdList); List<Long> getUserIdListByDeptId(List<Long> deptIdList);
SysUserDTO getByDeptIdAndRoleId(Long deptId, Long roleId);
} }

View File

@ -24,131 +24,141 @@ import java.util.*;
@Service @Service
public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntity> implements SysDeptService { public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntity> implements SysDeptService {
@Autowired @Autowired
private SysUserService sysUserService; private SysUserService sysUserService;
@Override @Override
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()));
} }
//查询部门列表 //查询部门列表
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 @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;
} }
SysDeptEntity entity = baseDao.getById(id); SysDeptEntity entity = baseDao.getById(id);
return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class); return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void save(SysDeptDTO dto) { public void save(SysDeptDTO dto) {
SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class);
entity.setPids(getPidList(entity.getPid())); entity.setPids(getPidList(entity.getPid()));
insert(entity); insert(entity);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(SysDeptDTO dto) { public void update(SysDeptDTO dto) {
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);
} }
entity.setPids(getPidList(entity.getPid())); entity.setPids(getPidList(entity.getPid()));
updateById(entity); updateById(entity);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
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);
} }
//删除 //删除
baseDao.deleteById(id); baseDao.deleteById(id);
} }
@Override @Override
public List<Long> getSubDeptIdList(Long id) { public List<Long> getSubDeptIdList(Long id) {
List<Long> deptIdList = baseDao.getSubDeptIdList("%" + id + "%"); List<Long> deptIdList = baseDao.getSubDeptIdList("%" + id + "%");
deptIdList.add(id); deptIdList.add(id);
return deptIdList; return deptIdList;
} }
/** @Override
* 获取所有上级部门ID public SysDeptDTO getByName(String name) {
* @param pid 上级ID if (StringUtils.isEmpty(name)) {
*/ return null;
private String getPidList(Long pid){ }
//顶级部门无上级部门 SysDeptEntity entity = baseDao.getByName(name);
if(Constant.DEPT_ROOT.equals(pid)){ return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class);
return Constant.DEPT_ROOT + ""; }
}
//所有部门的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 //所有部门的idpid列表
Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size()); List<SysDeptEntity> deptList = baseDao.getIdAndPidList();
for(SysDeptEntity entity : deptList){
map.put(entity.getId(), entity);
}
//递归查询所有上级部门ID列表 //list转map
List<Long> pidList = new ArrayList<>(); Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
getPidTree(pid, map, pidList); 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) { return StringUtils.join(pidList, ",");
//顶级部门无上级部门 }
if(Constant.DEPT_ROOT.equals(pid)){
return ;
}
//上级部门存在 private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> pidList) {
SysDeptEntity parent = map.get(pid); //顶级部门无上级部门
if(parent != null){ if (Constant.DEPT_ROOT.equals(pid)) {
getPidTree(parent.getPid(), map, pidList); 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 @Service
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService { public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {
@Autowired @Autowired
private SysRoleMenuService sysRoleMenuService; private SysRoleMenuService sysRoleMenuService;
@Autowired @Autowired
private SysRoleDataScopeService sysRoleDataScopeService; private SysRoleDataScopeService sysRoleDataScopeService;
@Autowired @Autowired
private SysRoleUserService sysRoleUserService; private SysRoleUserService sysRoleUserService;
@Autowired @Autowired
private SysDeptService sysDeptService; private SysDeptService sysDeptService;
@Override @Override
public PageData<SysRoleDTO> page(Map<String, Object> params) { public PageData<SysRoleDTO> page(Map<String, Object> params) {
IPage<SysRoleEntity> page = baseDao.selectPage( IPage<SysRoleEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false), getPage(params, Constant.CREATE_DATE, false),
getWrapper(params) getWrapper(params)
); );
return getPageData(page, SysRoleDTO.class); return getPageData(page, SysRoleDTO.class);
} }
@Override @Override
public List<SysRoleDTO> list(Map<String, Object> params) { public List<SysRoleDTO> list(Map<String, Object> params) {
List<SysRoleEntity> entityList = baseDao.selectList(getWrapper(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){ 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);
} }
return wrapper; return wrapper;
} }
@Override @Override
public SysRoleDTO get(Long id) { public SysRoleDTO get(Long id) {
SysRoleEntity entity = baseDao.selectById(id); SysRoleEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class); return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void save(SysRoleDTO dto) { public void save(SysRoleDTO dto) {
SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); 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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(SysRoleDTO dto) { public void update(SysRoleDTO dto) {
SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); 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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) { public void delete(Long[] ids) {
//删除角色 //删除角色
baseDao.deleteBatchIds(Arrays.asList(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 @Service
public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService { public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
@Autowired @Autowired
private SysRoleUserService sysRoleUserService; private SysRoleUserService sysRoleUserService;
@Autowired @Autowired
private SysDeptService sysDeptService; private SysDeptService sysDeptService;
@Autowired @Autowired
private SysUserPostService sysUserPostService; private SysUserPostService sysUserPostService;
@Override @Override
public PageData<SysUserDTO> page(Map<String, Object> params) { public PageData<SysUserDTO> page(Map<String, Object> params) {
//转换成like //转换成like
paramsToLike(params, "username"); 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(); 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()));
} }
//查询 //查询
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 @Override
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()));
} }
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 @Override
public SysUserDTO get(Long id) { public SysUserDTO get(Long id) {
SysUserEntity entity = baseDao.getById(id); SysUserEntity entity = baseDao.getById(id);
return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); return ConvertUtils.sourceToTarget(entity, SysUserDTO.class);
} }
@Override @Override
public SysUserDTO getByUsername(String username) { public SysUserDTO getByUsername(String username) {
SysUserEntity entity = baseDao.getByUsername(username); SysUserEntity entity = baseDao.getByUsername(username);
return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); return ConvertUtils.sourceToTarget(entity, SysUserDTO.class);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void save(SysUserDTO dto) { public void save(SysUserDTO dto) {
SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class);
//密码加密 //密码加密
String password = PasswordUtils.encode(entity.getPassword()); String password = PasswordUtils.encode(entity.getPassword());
entity.setPassword(password); entity.setPassword(password);
//保存用户 //保存用户
entity.setSuperAdmin(SuperAdminEnum.NO.value()); entity.setSuperAdmin(SuperAdminEnum.NO.value());
insert(entity); 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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void update(SysUserDTO dto) { public void update(SysUserDTO dto) {
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);
} }
//更新用户 //更新用户
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 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void delete(Long[] ids) { public void delete(Long[] ids) {
//删除用户 //删除用户
baseDao.deleteBatchIds(Arrays.asList(ids)); baseDao.deleteBatchIds(Arrays.asList(ids));
//删除角色用户关系 //删除角色用户关系
sysRoleUserService.deleteByUserIds(ids); sysRoleUserService.deleteByUserIds(ids);
//删除用户岗位关系 //删除用户岗位关系
sysUserPostService.deleteByUserIds(ids); sysUserPostService.deleteByUserIds(ids);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updatePassword(Long id, String newPassword) { public void updatePassword(Long id, String newPassword) {
newPassword = PasswordUtils.encode(newPassword); newPassword = PasswordUtils.encode(newPassword);
baseDao.updatePassword(id, newPassword); baseDao.updatePassword(id, newPassword);
} }
@Override @Override
public int getCountByDeptId(Long deptId) { public int getCountByDeptId(Long deptId) {
return baseDao.getCountByDeptId(deptId); return baseDao.getCountByDeptId(deptId);
} }
@Override @Override
public List<Long> getUserIdListByDeptId(List<Long> deptIdList) { public List<Long> getUserIdListByDeptId(List<Long> deptIdList) {
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);
}
} }

View File

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

View File

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

View File

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

View File

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

View File

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