diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/TowerAlarmMapper.xml b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/TowerAlarmMapper.xml index af8b82b0b..9f2b622da 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/TowerAlarmMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/TowerAlarmMapper.xml @@ -808,7 +808,14 @@ diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/controller/FlowExceptionLogController.java b/src/main/java/com/zhgd/xmgl/modules/xz/controller/FlowExceptionLogController.java index 9284ef251..a3c43e17f 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/controller/FlowExceptionLogController.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/controller/FlowExceptionLogController.java @@ -1,33 +1,39 @@ package com.zhgd.xmgl.modules.xz.controller; +import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.zhgd.annotation.OperLog; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiImplicitParams; -import java.util.HashMap; -import springfox.documentation.annotations.ApiIgnore; - -import java.util.List; - import com.zhgd.jeecg.common.api.vo.Result; -import org.apache.commons.collections.MapUtils; +import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; +import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; import com.zhgd.xmgl.modules.xz.entity.FlowExceptionLog; import com.zhgd.xmgl.modules.xz.service.IFlowExceptionLogService; - -import org.simpleframework.xml.core.Validate; -import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; - +import org.apache.commons.collections.MapUtils; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.runtime.ProcessInstance; +import org.simpleframework.xml.core.Validate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @Title: Controller * @Description: 工作流异常日志 * @author: pds - * @date: 2024-07-23 + * @date: 2024-07-23 * @version: V1.0 */ @RestController @@ -35,85 +41,125 @@ import org.springframework.web.bind.annotation.*; @Slf4j @Api(tags = "工作流异常日志相关Api") public class FlowExceptionLogController { - @Autowired - private IFlowExceptionLogService flowExceptionLogService; + @Lazy + @Autowired + IFlowExceptionLogService flowExceptionLogService; + @Lazy + @Autowired + RuntimeService runtimeService; + @Lazy + @Autowired + private ISystemUserService systemUserService; - /** - * 分页列表查询 - * @return - */ + /** + * 分页列表查询 + * + * @return + */ @OperLog(operModul = "工作流异常日志管理", operType = "分页查询", operDesc = "分页列表查询工作流异常日志信息") - @ApiOperation(value = "分页列表查询工作流异常日志信息", notes = "分页列表查询工作流异常日志信息", httpMethod="GET") - @ApiImplicitParams({ - @ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"), - @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"), - }) - @GetMapping(value = "/page") - public Result> queryPageList(@ApiIgnore @RequestParam HashMap param) { - return Result.success(flowExceptionLogService.queryPageList(param)); - } + @ApiOperation(value = "分页列表查询工作流异常日志信息", notes = "分页列表查询工作流异常日志信息", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"), + }) + @GetMapping(value = "/page") + public Result> queryPageList(@ApiIgnore @RequestParam HashMap param) { + return Result.success(flowExceptionLogService.queryPageList(param)); + } - /** - * 列表查询 - * @return - */ + /** + * 列表查询 + * + * @return + */ @OperLog(operModul = "工作流异常日志管理", operType = "列表查询", operDesc = "列表查询工作流异常日志信息") - @ApiOperation(value = "列表查询工作流异常日志信息", notes = "列表查询工作流异常日志信息", httpMethod="GET") - @GetMapping(value = "/list") - public Result> queryList(@ApiIgnore @RequestParam HashMap param) { - return Result.success(flowExceptionLogService.queryList(param)); - } + @ApiOperation(value = "列表查询工作流异常日志信息", notes = "列表查询工作流异常日志信息", httpMethod = "GET") + @GetMapping(value = "/list") + public Result> queryList(@ApiIgnore @RequestParam HashMap param) { + return Result.success(flowExceptionLogService.queryList(param)); + } - /** - * 添加 - * @param flowExceptionLog - * @return - */ + /** + * 添加 + * + * @param flowExceptionLog + * @return + */ @OperLog(operModul = "工作流异常日志管理", operType = "添加", operDesc = "添加工作流异常日志信息") - @ApiOperation(value = "添加工作流异常日志信息", notes = "添加工作流异常日志信息" , httpMethod="POST") - @PostMapping(value = "/add") - public Result add(@RequestBody @Validate FlowExceptionLog flowExceptionLog) { - flowExceptionLogService.add(flowExceptionLog); - return Result.ok(); - } - - /** - * 编辑 - * @param flowExceptionLog - * @return - */ - @OperLog(operModul = "工作流异常日志管理", operType = "编辑", operDesc = "编辑工作流异常日志信息") - @ApiOperation(value = "编辑工作流异常日志信息", notes = "编辑工作流异常日志信息" , httpMethod="POST") - @PostMapping(value = "/edit") - public Result edit(@RequestBody FlowExceptionLog flowExceptionLog) { - flowExceptionLogService.edit(flowExceptionLog); - return Result.ok(); - } - - /** - * 通过id删除 - * @return - */ - @OperLog(operModul = "工作流异常日志管理", operType = "删除", operDesc = "删除工作流异常日志信息") - @ApiOperation(value = "删除工作流异常日志信息", notes = "删除工作流异常日志信息" , httpMethod="POST") - @ApiImplicitParam(name = "id", value = "工作流异常日志ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}") - @PostMapping(value = "/delete") - public Result delete(@ApiIgnore @RequestBody HashMap map) { - flowExceptionLogService.delete(MapUtils.getString(map, "id")); + @ApiOperation(value = "添加工作流异常日志信息", notes = "添加工作流异常日志信息", httpMethod = "POST") + @PostMapping(value = "/add") + public Result add(@RequestBody @Validate FlowExceptionLog flowExceptionLog) { + flowExceptionLogService.add(flowExceptionLog); return Result.ok(); - } + } - /** - * 通过id查询 - * @param id - * @return - */ + @OperLog(operModul = "工作流异常日志管理", operType = "添加", operDesc = "从工作流添加工作流异常日志信息") + @ApiOperation(value = "从工作流添加工作流异常日志信息", notes = "从工作流添加工作流异常日志信息", httpMethod = "POST") + @PostMapping(value = "/flow/add") + public Result addFromFlow(@RequestBody @Validate Map param) { + log.info("从工作流添加工作流异常日志信息:{}", JSON.toJSONString(param)); + String instanceId = MapUtils.getString(param, "instanceId"); + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult(); + Date startTime = processInstance.getStartTime(); + String processDefinitionName = processInstance.getProcessDefinitionName(); + String startUserId = processInstance.getStartUserId(); + String projectSn = processInstance.getTenantId(); + FlowExceptionLog log = new FlowExceptionLog(); + log.setApprovalNumber(instanceId); + log.setApprovalType(processDefinitionName); + log.setProjectSn(projectSn); + log.setLaunchTime(startTime); + HashMap map = new HashMap<>(16); + map.put("userId", startUserId); + map.put("projectSn", projectSn); + List userList = systemUserService.getProjectChildernSystemUserList(map); + log.setLauncherName(CollUtil.isNotEmpty(userList) ? userList.get(0).getRealName() : null); + log.setLaunchEnterpriseName(CollUtil.isNotEmpty(userList) ? userList.get(0).getEnterpriseName() : null); + log.setExceptionDetail("网络超时"); + flowExceptionLogService.add(log); + return Result.ok(); + } + + /** + * 编辑 + * + * @param flowExceptionLog + * @return + */ + @OperLog(operModul = "工作流异常日志管理", operType = "编辑", operDesc = "编辑工作流异常日志信息") + @ApiOperation(value = "编辑工作流异常日志信息", notes = "编辑工作流异常日志信息", httpMethod = "POST") + @PostMapping(value = "/edit") + public Result edit(@RequestBody FlowExceptionLog flowExceptionLog) { + flowExceptionLogService.edit(flowExceptionLog); + return Result.ok(); + } + + /** + * 通过id删除 + * + * @return + */ + @OperLog(operModul = "工作流异常日志管理", operType = "删除", operDesc = "删除工作流异常日志信息") + @ApiOperation(value = "删除工作流异常日志信息", notes = "删除工作流异常日志信息", httpMethod = "POST") + @ApiImplicitParam(name = "id", value = "工作流异常日志ID", paramType = "body", required = true, dataType = "String", example = "{\"id\":\"1\"}") + @PostMapping(value = "/delete") + public Result delete(@ApiIgnore @RequestBody HashMap map) { + flowExceptionLogService.delete(MapUtils.getString(map, "id")); + return Result.ok(); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ @OperLog(operModul = "工作流异常日志管理", operType = "通过id查询", operDesc = "通过id查询工作流异常日志信息") - @ApiOperation(value = "通过id查询工作流异常日志信息", notes = "通过id查询工作流异常日志信息" , httpMethod="GET") - @ApiImplicitParam(name = "id", value = "工作流异常日志ID", paramType = "query", required = true, dataType = "Integer") - @GetMapping(value = "/queryById") - public Result queryById(@RequestParam(name="id",required=true) String id) { - return Result.success(flowExceptionLogService.queryById(id)); - } + @ApiOperation(value = "通过id查询工作流异常日志信息", notes = "通过id查询工作流异常日志信息", httpMethod = "GET") + @ApiImplicitParam(name = "id", value = "工作流异常日志ID", paramType = "query", required = true, dataType = "Integer") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name = "id", required = true) String id) { + return Result.success(flowExceptionLogService.queryById(id)); + } } diff --git a/src/main/java/com/zhgd/xmgl/util/EmailUtils.java b/src/main/java/com/zhgd/xmgl/util/EmailUtils.java index 492bec12c..66f11aaa0 100644 --- a/src/main/java/com/zhgd/xmgl/util/EmailUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/EmailUtils.java @@ -3,11 +3,9 @@ package com.zhgd.xmgl.util; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zhgd.xmgl.base.EmailService; import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; -import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import com.zhgd.xmgl.modules.worker.service.impl.EnterpriseInfoServiceImpl; import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl; import com.zhgd.xmgl.modules.xz.entity.FlowExceptionLog; @@ -33,7 +31,6 @@ import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Optional; /** * 发送邮件工具类 MailUtil @@ -49,6 +46,9 @@ public class EmailUtils implements EmailService { @Lazy @Autowired RuntimeService runtimeService; + @Lazy + @Autowired + IFlowExceptionLogService flowExceptionLogService; /** * Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用 */ @@ -60,6 +60,15 @@ public class EmailUtils implements EmailService { */ @Value("${spring.mail.from}") private String from; + @Lazy + @Autowired + private ISystemUserService systemUserService; + @Lazy + @Autowired + private WorkerInfoServiceImpl workerInfoService; + @Lazy + @Autowired + private EnterpriseInfoServiceImpl enterpriseInfoService; public static void main(String[] args) { EmailUtils mailService = new EmailUtils(); @@ -157,21 +166,10 @@ public class EmailUtils implements EmailService { } } - @Lazy - @Autowired - IFlowExceptionLogService flowExceptionLogService; - @Lazy - @Autowired - private ISystemUserService systemUserService; - @Lazy - @Autowired - private WorkerInfoServiceImpl workerInfoService; - @Lazy - @Autowired - private EnterpriseInfoServiceImpl enterpriseInfoService; /** * 保存异常并发送工作流异常邮件 - * @param paramStr + * + * @param paramStr * @param e * @param subject * @param url @@ -203,8 +201,8 @@ public class EmailUtils implements EmailService { map.put("userId", startUserId); map.put("projectSn", projectSn); List userList = systemUserService.getProjectChildernSystemUserList(map); - log.setLauncherName(CollUtil.isNotEmpty(userList)?userList.get(0).getRealName():null); - log.setLaunchEnterpriseName(CollUtil.isNotEmpty(userList)?userList.get(0).getEnterpriseName():null); + log.setLauncherName(CollUtil.isNotEmpty(userList) ? userList.get(0).getRealName() : null); + log.setLaunchEnterpriseName(CollUtil.isNotEmpty(userList) ? userList.get(0).getEnterpriseName() : null); log.setExceptionDetail(detail); flowExceptionLogService.add(log); }