diff --git a/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterController.java b/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterController.java index dd431592..9d166567 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterController.java +++ b/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -109,10 +110,12 @@ public class AbilityCenterController { processStartDTO.setVariables(variables); ProcessInstanceDTO dto = actRunningService.startOfBusinessKey(processStartDTO); - if (Long.valueOf(dto.getBusinessKey()) != null) { - // 仿照请求接口 /processForm/tabilityapplication/updateInstanceId - tAbilityApplicationService.updateInstanceId(dto.getProcessInstanceId(), Long.valueOf(dto.getBusinessKey())); - } + // 仿照请求接口 /processForm/tabilityapplication/updateInstanceId + CompletableFuture.runAsync(() -> { + if (Long.valueOf(dto.getBusinessKey()) != null) { + tAbilityApplicationService.updateInstanceId(dto.getProcessInstanceId(), Long.valueOf(dto.getBusinessKey())); + } + }); return dto; }).filter(index -> ObjectUtil.isNotNull(index)).collect(Collectors.toList())); } diff --git a/renren-admin/src/main/java/io/renren/common/controller/CommentController.java b/renren-admin/src/main/java/io/renren/common/controller/CommentController.java new file mode 100644 index 00000000..eaacef34 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/controller/CommentController.java @@ -0,0 +1,99 @@ +package io.renren.common.controller; + + +import io.renren.common.page.PageData; +import io.renren.common.utils.Result; +import io.renren.modules.activiti.dto.ProcessInstanceDTO; +import io.renren.modules.activiti.dto.ProcessStartDTO; +import io.renren.modules.activiti.service.ActProcessService; +import io.renren.modules.activiti.service.ActRunningService; +import io.renren.modules.demandComment.dto.TDemandCommentDTO; +import io.renren.modules.demandComment.service.TDemandCommentService; +import io.renren.modules.processForm.service.TAbilityApplicationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.codehaus.jackson.map.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +@Api(tags = "") +@RestController +@RequestMapping("/comment/center") +public class CommentController { + + @Autowired + private ActProcessService actProcessService; + @Autowired + private TAbilityApplicationService tAbilityApplicationService; + @Autowired + private ActRunningService actRunningService; + @Autowired + private TDemandCommentService tDemandCommentService; + @Autowired + private JdbcTemplate jdbcTemplate; + private static Logger logger = LoggerFactory.getLogger(CommentController.class); + + private static String key = "comment_review"; + + private static Map params = new HashMap() { + { + put("isLatestVersion", true); // 取最新版本 + put("key", key); // 限定 + } + }; + + /** + * 批量进行批量能力申请 + * + * @param tDemandCommentDTO + * @return + */ + @PostMapping(value = "/apply") + @ApiOperation("批量进行评论审核申请") + public Result apply(@RequestBody TDemandCommentDTO tDemandCommentDTO) { + // 仿照请求接口 /act/process/lastestPage + PageData> page = actProcessService.page(params); + if (page.getTotal() <= 0) { // + return new Result().error("联系管理员添加流程"); + } + if (tDemandCommentDTO.getId() == null) { + return new Result().error("参数异常"); + } + tDemandCommentDTO = tDemandCommentService.get(tDemandCommentDTO.getId()); + if (tDemandCommentDTO.getId() == null) { + return new Result().error("该评论不存在"); + } + tDemandCommentDTO.setDelFlag(2); // 待审核 + tDemandCommentDTO.setCompleteEntry(Boolean.TRUE); + tDemandCommentService.update(tDemandCommentDTO); + + // 仿照请求接口 /act/running/startOfBusinessKey + ProcessStartDTO processStartDTO = new ProcessStartDTO(); + processStartDTO.setBusinessKey(tDemandCommentDTO.getId().toString()); + processStartDTO.setProcessDefinitionKey(key); //限定 + ObjectMapper oMapper = new ObjectMapper(); + Map variables = oMapper.convertValue(tDemandCommentDTO, Map.class); + processStartDTO.setVariables(variables); + ProcessInstanceDTO dto = actRunningService.startOfBusinessKey(processStartDTO); + + tDemandCommentDTO.setDelFlag(3); // 审核中 + tDemandCommentService.update(tDemandCommentDTO); + + CompletableFuture.runAsync(() -> { + if (Long.valueOf(dto.getBusinessKey()) != null) { + jdbcTemplate.update(String.format("UPDATE t_demand_comment SET instance_id = '%s' WHERE id = %s", dto.getProcessInstanceId(), dto.getBusinessKey())); + } + }); + return new Result().ok(dto); + } +} diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java b/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java index 310de68b..3e46677e 100644 --- a/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java @@ -104,7 +104,7 @@ public class TDemandCommentController { @ApiOperation("保存") @LogOperation("保存") // @RequiresPermissions("demandComment:tdemandcomment:save") - public Result save(@RequestBody TDemandCommentDTO dto) { + public Result save(@RequestBody TDemandCommentDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); TDemandDataDTO dto1 = @@ -115,9 +115,10 @@ public class TDemandCommentController { if (dto1.getFlag() != 3) { return new Result().error("该评论主题未审批通过!"); } + dto.setDelFlag(1); tDemandCommentService.save(dto); - return new Result(); + return new Result().ok(dto); } @PutMapping diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/listener/CommentListener.java b/renren-admin/src/main/java/io/renren/modules/demandComment/listener/CommentListener.java new file mode 100644 index 00000000..ffcd2300 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/listener/CommentListener.java @@ -0,0 +1,143 @@ +package io.renren.modules.demandComment.listener; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import io.renren.common.annotation.ActivitiNoticeOperation; +import io.renren.modules.demandComment.dto.TDemandCommentDTO; +import io.renren.modules.demandComment.service.TDemandCommentService; +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.Date; +import java.util.Map; + +/** + * 大数据局动态审批人 + */ +@Component +public class CommentListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate { + private static Logger logger = LoggerFactory.getLogger(CommentListener.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; + @Autowired + private TDemandCommentService tDemandCommentService; + + @Override + public void notify(DelegateExecution delegateExecution) throws Exception { + logger.error("----------------------进入审批结束节点---------------------------"); + delegateExecution.getProcessBusinessKey(); + final String eventName = delegateExecution.getEventName(); + switch (eventName) { + case EVENTNAME_END: + endTake(delegateExecution.getVariables()); + break; + } + + } + + /** + * 结束审批 + * + * @param kv + */ + private void endTake(Map kv) { // 进入最后结束节点 + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, (JsonDeserializer) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong())); + + Gson gson = builder.create(); + JsonElement jsonElement = gson.toJsonTree(kv); + TDemandCommentDTO tDemandCommentDTO = gson.fromJson(jsonElement, TDemandCommentDTO.class); + if (tDemandCommentDTO != null) { + if (tDemandCommentDTO.getReject() != null && tDemandCommentDTO.getReject() == Boolean.TRUE) { // 存在被拒绝的节点 + tDemandCommentDTO.setDelFlag(1); + tDemandCommentService.update(tDemandCommentDTO); + logger.error("评论审核不通过不通过!申请id:" + tDemandCommentDTO.getId()); + } else { + tDemandCommentDTO.setDelFlag(0); + tDemandCommentService.update(tDemandCommentDTO); + logger.error("审批通过!评论id:" + tDemandCommentDTO.getId()); + } + } + } + + @Override + public void execute(DelegateExecution delegateExecution) throws Exception { + + } + + @Override + @ActivitiNoticeOperation(value = "评论审核", process = "评论审核流程") + public void notify(DelegateTask delegateTask) { + logger.error("事件类型:" + delegateTask.getEventName()); + final String eventName = delegateTask.getEventName(); + switch (eventName) { + case EVENTNAME_CREATE: + createEvent(delegateTask); + break; + default: + logger.error("未处理该事件:" + eventName); + } + } + + @Override + public void onEvent(ActivitiEvent activitiEvent) { + + } + + @Override + public boolean isFailOnException() { + return false; + } + + /** + * 节点创建时动态分配大数据局审批人 + * + * @param delegateTask + */ + private void createEvent(DelegateTask delegateTask) { + logger.error("大数据局名称:" + bigDateDeptName); + SysDeptDTO deptDTO = sysDeptService.getByName(bigDateDeptName); + logger.error("deptDTOId:" + deptDTO.getId()); + SysRoleDTO roleDTO = sysRoleService.getByName(roleName); + logger.error("roleDTOId:" + roleDTO.getId()); + SysUserDTO userDTO = sysUserService.getByDeptIdAndRoleId(deptDTO.getId(), roleDTO.getId()); + + if (userDTO != null) { + logger.error("审批人id:" + userDTO.getId()); + taskService.setAssignee(delegateTask.getId(), userDTO.getId().toString()); + } else { + delegateTask.setAssignee("1516728698224427010"); + logger.error("未查到该部门对应 " + roleName); + } + } +} diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java index 5a720728..9253d0e9 100644 --- a/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java @@ -76,23 +76,30 @@ public class TDemandCommentServiceImpl extends CrudServiceImpl { // 发起人 - Optional tDemandDataDTO = Optional.ofNullable(tDemandDataService.get(tDemandCommentDTO.getTargetId())); - Optional sysUserDTO = Optional.ofNullable(sysUserService.get(tDemandDataDTO.isPresent() ? tDemandDataDTO.get().getCreator() : null)); - String content = "【评论】" + (sysUserDTO.isPresent() ? sysUserDTO.get().getRealName() : "") + "您发起的需求 " + tDemandDataDTO.orElse(new TDemandDataDTO()).getDemandSubject() + "有新的评论,请前往查看详情"; - SysNoticeDTO dto = new SysNoticeDTO(); - dto.setType(2); - dto.setTitle("需求评论系统通知"); - dto.setContent(content); // 通知内容 - dto.setReceiverType(1); - dto.setReceiverTypeIds(tDemandDataDTO.isPresent() ? tDemandDataDTO.get().getCreator().toString() : ""); - dto.setStatus(NoticeStatusEnum.SEND.value()); - dto.setSenderName("流程系统"); - dto.setSenderDate(new Date()); - dto.setCreator(sysUserService.getByUsername("admin").getId()); - dto.setCreateDate(new Date()); - dto.setFrom("评论"); - sysNoticeService.save(dto); - }); + } + + @Override + public void update(TDemandCommentDTO tDemandCommentDTO) { + super.update(tDemandCommentDTO); + if (tDemandCommentDTO.getDelFlag() == 0) { + CompletableFuture.runAsync(() -> { // 发起人 + Optional tDemandDataDTO = Optional.ofNullable(tDemandDataService.get(tDemandCommentDTO.getTargetId())); + Optional sysUserDTO = Optional.ofNullable(sysUserService.get(tDemandDataDTO.isPresent() ? tDemandDataDTO.get().getCreator() : null)); + String content = "【评论】" + (sysUserDTO.isPresent() ? sysUserDTO.get().getRealName() : "") + "您发起的需求 " + tDemandDataDTO.orElse(new TDemandDataDTO()).getDemandSubject() + "有新的评论,请前往查看详情"; + SysNoticeDTO dto = new SysNoticeDTO(); + dto.setType(2); + dto.setTitle("需求评论系统通知"); + dto.setContent(content); // 通知内容 + dto.setReceiverType(1); + dto.setReceiverTypeIds(tDemandDataDTO.isPresent() ? tDemandDataDTO.get().getCreator().toString() : ""); + dto.setStatus(NoticeStatusEnum.SEND.value()); + dto.setSenderName("流程系统"); + dto.setSenderDate(new Date()); + dto.setCreator(sysUserService.getByUsername("admin").getId()); + dto.setCreateDate(new Date()); + dto.setFrom("评论"); + sysNoticeService.save(dto); + }); + } } } \ No newline at end of file diff --git a/renren-admin/src/main/resources/db/V2.0__comment_add_col.sql b/renren-admin/src/main/resources/db/V2.0__comment_add_col.sql new file mode 100644 index 00000000..9423b926 --- /dev/null +++ b/renren-admin/src/main/resources/db/V2.0__comment_add_col.sql @@ -0,0 +1 @@ +ALTER TABLE `t_demand_comment` ADD COLUMN `instance_id` varchar(64) NULL COMMENT '流程实例ID'; \ No newline at end of file