| | |
| | | import org.jeecg.modules.eam.constant.InspectionStatus; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrder; |
| | | import org.jeecg.modules.eam.service.IEamInspectionOrderService; |
| | | import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService; |
| | | import org.jeecg.modules.mdc.util.ThrowableUtil; |
| | | import org.jeecg.modules.quartz.entity.QuartzJob; |
| | | import org.jeecg.modules.quartz.entity.SysQuartzLog; |
| | |
| | | import org.jeecg.modules.quartz.service.ISysQuartzLogService; |
| | | import org.jeecg.modules.qywx.message.vo.TemplateCard; |
| | | import org.jeecg.modules.qywx.message.vo.TemplateCardEntity; |
| | | import org.jeecg.modules.system.entity.MdcProductionEquipment; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.service.impl.ThirdAppWechatEnterpriseServiceImpl; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } |
| | | long startTime = System.currentTimeMillis(); |
| | | try { |
| | | //查询所有待点检的工单 |
| | | List<EamInspectionOrder> waitOrderList = eamInspectionOrderService.list(new LambdaQueryWrapper<EamInspectionOrder>() |
| | | .eq(EamInspectionOrder::getInspectionStatus, InspectionStatus.WAIT_INSPECTION.name()) |
| | | .eq(EamInspectionOrder::getDelFlag, CommonConstant.DEL_FLAG_0)); |
| | | if (!waitOrderList.isEmpty()) { |
| | | //查询所有未领取待点检的工单 |
| | | List<EamInspectionOrder> unReceivedOrderList = eamInspectionOrderService.selectUnReceivedInspectionOrder(); |
| | | if (!unReceivedOrderList.isEmpty()) { |
| | | //有待点检工单,推送企业微信消息 |
| | | //查询所有操作工 |
| | | List<SysUser> userList = sysUserService.list(new LambdaQueryWrapper<SysUser>() |
| | | .eq(SysUser::getPost, BusinessCodeConst.PCR0001) |
| | | .eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0) |
| | | .eq(SysUser::getStatus, CommonConstant.USER_UNFREEZE)); |
| | | if (userList.isEmpty()) { |
| | | log.error("系统未设置操作工用户,无法推送工单领取提醒消息"); |
| | | quartzLog.setIsSuccess(0); |
| | | quartzLog.setParams("系统未设置操作工用户,无法推送工单领取提醒消息"); |
| | | } else { |
| | | TemplateCard templateCard = new TemplateCard(); |
| | | String toUsers = userList.stream().map(SysUser::getUsername).collect(Collectors.joining(",")); |
| | | String touser = wechatEnterpriseService.getTouser(toUsers, false); |
| | | templateCard.setTouser(touser); |
| | | TemplateCardEntity templateCardEntity = new TemplateCardEntity(); |
| | | templateCard.setTemplate_card(templateCardEntity); |
| | | templateCardEntity.setTask_id(waitOrderList.get(0).getId()); |
| | | TemplateCardEntity.MainTitle mainTitle = new TemplateCardEntity.MainTitle(); |
| | | mainTitle.setTitle("设备点检"); |
| | | templateCardEntity.setMain_title(mainTitle); |
| | | templateCardEntity.setSub_title_text("您有待领取点检工单,请进入系统领取"); |
| | | TemplateCardEntity.CardAction cardAction = new TemplateCardEntity.CardAction(); |
| | | cardAction.setType(1); |
| | | cardAction.setUrl(cardActionUrl); |
| | | templateCardEntity.setCard_action(cardAction); |
| | | JSONObject jsonObject = wechatEnterpriseService.sendTemplateCardMsg(templateCard, true); |
| | | Integer errcode = (Integer) jsonObject.get("errcode"); |
| | | if (errcode == 0) { |
| | | log.info("推送待领取点检工单企业微信消息成功,{}", jsonObject.toJSONString()); |
| | | quartzLog.setIsSuccess(0); |
| | | quartzLog.setParams(jsonObject.toJSONString()); |
| | | Map<String, List<EamInspectionOrder>> unReceivedOrderMap = unReceivedOrderList.stream() |
| | | .collect(Collectors.groupingBy(EamInspectionOrder::getOrgId)); |
| | | StringBuilder message = new StringBuilder(); |
| | | for (String orgId : unReceivedOrderMap.keySet()) { |
| | | //查询该产线下的所有操作工 |
| | | List<UserSelector> userSelectorList = sysUserService.selectOperatorList(null, orgId, BusinessCodeConst.PCR0001); |
| | | if (userSelectorList.isEmpty()) { |
| | | log.error("系统未设置操作工用户,无法推送工单领取提醒消息"); |
| | | message.append("系统未设置操作工用户,无法推送工单领取提醒消息").append("\n"); |
| | | } else { |
| | | log.error("推送待领取点检工单企业微信消息失败,{}", jsonObject.toJSONString()); |
| | | quartzLog.setIsSuccess(-1); |
| | | quartzLog.setExceptionDetail(jsonObject.toJSONString()); |
| | | String toUsers = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.joining(",")); |
| | | String touser = wechatEnterpriseService.getTouser(toUsers, false); |
| | | //构造消息体内容 |
| | | TemplateCard templateCard = new TemplateCard(); |
| | | templateCard.setTouser(touser); |
| | | TemplateCardEntity templateCardEntity = new TemplateCardEntity(); |
| | | templateCard.setTemplate_card(templateCardEntity); |
| | | templateCardEntity.setTask_id(UUID.randomUUID().toString().replaceAll("-", "")); |
| | | TemplateCardEntity.MainTitle mainTitle = new TemplateCardEntity.MainTitle(); |
| | | mainTitle.setTitle("设备点检"); |
| | | templateCardEntity.setMain_title(mainTitle); |
| | | templateCardEntity.setSub_title_text("您有待领取点检工单,请进入系统领取"); |
| | | TemplateCardEntity.CardAction cardAction = new TemplateCardEntity.CardAction(); |
| | | cardAction.setType(1); |
| | | cardAction.setUrl(cardActionUrl); |
| | | templateCardEntity.setCard_action(cardAction); |
| | | JSONObject jsonObject = wechatEnterpriseService.sendTemplateCardMsg(templateCard, true); |
| | | Integer errcode = (Integer) jsonObject.get("errcode"); |
| | | if (errcode == 0) { |
| | | log.info("推送待领取点检工单企业微信消息成功,{}", jsonObject.toJSONString()); |
| | | message.append("推送待领取点检工单企业微信消息成功,").append(jsonObject.toJSONString()).append("\n"); |
| | | } else { |
| | | log.error("推送待领取点检工单企业微信消息失败,{}", jsonObject.toJSONString()); |
| | | message.append("推送待领取点检工单企业微信消息失败,").append(jsonObject.toJSONString()).append("\n"); |
| | | } |
| | | } |
| | | } |
| | | quartzLog.setIsSuccess(0); |
| | | quartzLog.setExceptionDetail(message.toString()); |
| | | } else { |
| | | log.info("无待领取点检工单,无需推送工单领取提醒消息"); |
| | | quartzLog.setIsSuccess(0); |