需求申请监听器

This commit is contained in:
wangliwen 2022-04-25 17:05:48 +08:00
parent 2756ed523b
commit 01728a8cfb
4 changed files with 140 additions and 4 deletions

View File

@ -0,0 +1,132 @@
package io.renren.modules.demanData.listener;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import io.renren.modules.demanData.dto.TDemandDataDTO;
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;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.*;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
*
*/
@Component
public class DemandDataListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate {
private static Logger logger = LoggerFactory.getLogger(DemandDataListener.class);
@Value("${big_date.name}")
private String bigDateDeptName; // 大数据局名称
@Value("${big_date.assignee_role_name}")
private String roleName; // 具备审批的角色名称
@Autowired
private SysRoleService sysRoleService;
@Autowired
private TaskService taskService;
@Autowired
private SysUserService sysUserService;
@Autowired
private SysRoleUserService sysRoleUserService;
@Autowired
private SysDeptService sysDeptService;
@Override
public void notify(DelegateExecution execution) throws Exception {
}
@Override
public void execute(DelegateExecution execution) throws Exception {
}
@Override
public void notify(DelegateTask delegateTask) {
logger.error("----------------------进入能力需求受理者1节点---------------------------");
logger.info("事件类型:" + delegateTask.getEventName());
SysRoleDTO roleDTO = sysRoleService.getByName(roleName);
logger.error("roleDTOId:" + roleDTO.getId());
final String eventName = delegateTask.getEventName();
switch (eventName) {
case EVENTNAME_CREATE:
create(delegateTask, roleDTO);
break;
default:
logger.info("未处理该事件:" + eventName);
}
}
/**
* Called when an event has been fired
*
* @param event the event
*/
@Override
public void onEvent(ActivitiEvent event) {
}
/**
* @return whether or not the current operation should fail when this listeners execution
* throws an exception.
*/
@Override
public boolean isFailOnException() {
return false;
}
private void create(DelegateTask delegateTask, final SysRoleDTO roleDTO) {
Map<String, Object> kv = delegateTask.getVariables();
Gson gson = new Gson();
JsonElement jsonElement = gson.toJsonTree(kv);
TDemandDataDTO demandDataDTO = gson.fromJson(jsonElement, TDemandDataDTO.class);
if (demandDataDTO != null) {
logger.info(JSONObject.toJSONString(demandDataDTO));
SysDeptDTO deptDTO =
sysDeptService.get(Long.valueOf(demandDataDTO.getApplyUserDeptId()));
SysUserDTO userDTO = null;
if (deptDTO.getId() != null) {
userDTO = sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId()); // 搜出审批人
}
if (userDTO != null) {
logger.error("审批人id:" + userDTO.getId());
taskService.setAssignee(delegateTask.getId(), userDTO.getId().toString());
} else {
logger.error("未查到该部门对应的 " + roleName);
taskService.setAssignee(delegateTask.getId(), "1513432847327199233");
}
} else { // 填入大数据审批人
logger.info("大数据局名称:" + bigDateDeptName);
SysDeptDTO deptDTO = sysDeptService.getByName(bigDateDeptName);
logger.info("roleDTOId:" + roleDTO.getId());
SysUserDTO userDTO = sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId());
if (userDTO != null) {
logger.info("大数据审批人id:" + userDTO.getId());
taskService.setAssignee(delegateTask.getId(), userDTO.getId().toString());
} else {
taskService.setAssignee(delegateTask.getId(), "1513432847327199233");
logger.info("未查到大数据部门对应 " + roleName);
}
}
}
}

View File

@ -22,8 +22,9 @@ public class TDemandDataServiceImpl extends CrudServiceImpl<TDemandDataDao, TDem
@Override @Override
public QueryWrapper<TDemandDataEntity> getWrapper(Map<String, Object> params) { public QueryWrapper<TDemandDataEntity> getWrapper(Map<String, Object> params) {
QueryWrapper<TDemandDataEntity> wrapper = new QueryWrapper<>(); QueryWrapper<TDemandDataEntity> wrapper = new QueryWrapper<>();
if (params.containsKey("flag")) {
wrapper.eq("flag", params.get("flag"));
}
return wrapper; return wrapper;
} }

View File

@ -120,8 +120,9 @@ public class ResourceController {
@ApiImplicitParam(name = "source", value = "请求来源", paramType = "string", dataType = "string") @ApiImplicitParam(name = "source", value = "请求来源", paramType = "string", dataType = "string")
}) })
//@RequiresPermissions("resource:resource:save") //@RequiresPermissions("resource:resource:save")
public Result save(@RequestBody ResourceDTO dto, String source) { public Result save(@RequestBody ResourceDTO dto, @RequestParam String source) {
// 效验数据 // 效验数据
logger.info("source:" + source);
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
if ("f".equals(source)) { if ("f".equals(source)) {
dto.setDelFlag(2); // 来自前端页面 走审批流程 dto.setDelFlag(2); // 来自前端页面 走审批流程

View File

@ -78,7 +78,9 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
BeanUtils.copyProperties(dto, resourceEntity); BeanUtils.copyProperties(dto, resourceEntity);
Long resourceID = IdWorker.getId(resourceEntity); Long resourceID = IdWorker.getId(resourceEntity);
resourceEntity.setId(resourceID); resourceEntity.setId(resourceID);
if (dto.getDelFlag() == null) {
resourceEntity.setDelFlag(0); resourceEntity.setDelFlag(0);
}
resourceDao.insert(resourceEntity); resourceDao.insert(resourceEntity);
BeanUtils.copyProperties(resourceEntity, dto); BeanUtils.copyProperties(resourceEntity, dto);