| | |
| | | import com.sinata.appointment.constants.ApprovalNodeCode; |
| | | import com.sinata.appointment.constants.ApprovalTaskStatus; |
| | | import com.sinata.appointment.entity.ApprovalTask; |
| | | import com.sinata.appointment.entity.AppointmentVisitor; |
| | | import com.sinata.appointment.entity.AppointmentOrder; |
| | | import com.sinata.appointment.entity.BizVisitReason; |
| | | import com.sinata.appointment.entity.MpUser; |
| | | import com.sinata.appointment.integration.WechatMiniGateway; |
| | | import com.sinata.appointment.mapper.ApprovalTaskMapper; |
| | | import com.sinata.appointment.mapper.AppointmentVisitorMapper; |
| | | import com.sinata.appointment.mapper.BizVisitReasonMapper; |
| | | import com.sinata.appointment.mapper.MpUserMapper; |
| | | import java.time.LocalDate; |
| | |
| | | public class IntegrationWechatService { |
| | | |
| | | private static final String APPROVAL_RESULT_TEMPLATE_ID = |
| | | "4FQovCBNFM7rth42AWHTusHajO788eT9VpplSN4ZG2s"; |
| | | "rIJpfN51_q818RTpJAqTe5ssTwWCHnxDM5rpq64uuKM"; |
| | | private static final String NOTICE_RESULT_TEMPLATE_ID = |
| | | "GC1S3T2qHCbz8ow130u7elRczuqW6Z8q54mKRCYE-xo"; |
| | | "Wip0ODJgybZpeFpcvev_0GK1wQXEqZw-LHOjS-UyDLw"; |
| | | private static final String APPROVAL_RESULT_PAGE = "pages/record/index"; |
| | | private static final String APPROVAL_TODO_TEMPLATE_ID = |
| | | "BX49OBHvRcoYiCw0ZLqx04BiWQ9KaEQwuVth_Lh_M2A"; |
| | | "QlNwG99WXWztRDgtlLcE0fHxfY2VwaX8PRMrwGpEync"; |
| | | private static final String APPROVAL_TODO_PAGE = "pages/reviewList/index"; |
| | | private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | private static final DateTimeFormatter TEMPLATE_TIME_FORMATTER = |
| | |
| | | private final WechatMiniGateway wechatMiniGateway; |
| | | private final MpUserMapper mpUserMapper; |
| | | private final ApprovalTaskMapper approvalTaskMapper; |
| | | private final AppointmentVisitorMapper appointmentVisitorMapper; |
| | | private final BizVisitReasonMapper bizVisitReasonMapper; |
| | | |
| | | @Async |
| | |
| | | return; |
| | | } |
| | | Map<String, String> templateData = new LinkedHashMap<>(); |
| | | templateData.put("thing1", approved ? "审核通过" : "审核未通过"); |
| | | templateData.put("thing2", abbreviate(resolveSubmitterName(submitter), 20)); |
| | | templateData.put("time3", buildVisitTemplateTimeValue(order)); |
| | | templateData.put("thing4", abbreviate(buildVisitReasonText(order), 20)); |
| | | templateData.put("phrase4", approved ? "通过" : "未通过"); |
| | | templateData.put("time2", buildVisitTemplateTimeValue(order)); |
| | | templateData.put("thing5", approved ? "预约审核通过" : "预约审核未通过"); |
| | | wechatMiniGateway.sendSubscribeMessage( |
| | | submitter.getOpenId(), APPROVAL_RESULT_TEMPLATE_ID, APPROVAL_RESULT_PAGE, templateData); |
| | | log.info( |
| | |
| | | return; |
| | | } |
| | | Map<String, String> templateData = new LinkedHashMap<>(); |
| | | templateData.put("thing6", buildVisitorCountText(visitorCount)); |
| | | templateData.put("time18", buildVisitTemplateTimeValue(order)); |
| | | templateData.put("thing20", abbreviate(buildNoticeBusinessTypeText(order, approved), 20)); |
| | | MpUser submitter = loadSubmitter(order); |
| | | templateData.put("name1", abbreviate(resolveSubmitterName(submitter), 10)); |
| | | templateData.put("number36", buildVisitorCountNumber(visitorCount)); |
| | | templateData.put("date3", buildVisitTemplateTimeValue(order)); |
| | | int successCount = 0; |
| | | int skippedCount = 0; |
| | | int failedCount = 0; |
| | |
| | | continue; |
| | | } |
| | | Map<String, String> templateData = new LinkedHashMap<>(); |
| | | templateData.put("thing1", abbreviate(buildTodoTaskName(order), 20)); |
| | | templateData.put("thing3", abbreviate(String.join("、", entry.getValue()), 20)); |
| | | MpUser submitter = loadSubmitter(order); |
| | | templateData.put("name1", abbreviate(resolveSubmitterName(submitter), 10)); |
| | | templateData.put("number15", buildVisitorCountNumber(countVisitors(order))); |
| | | templateData.put("time16", buildVisitTemplateTimeValue(order)); |
| | | templateData.put("thing5", abbreviate(buildVisitReasonText(order), 20)); |
| | | try { |
| | | wechatMiniGateway.sendSubscribeMessage( |
| | | user.getOpenId(), APPROVAL_TODO_TEMPLATE_ID, APPROVAL_TODO_PAGE, templateData); |
| | |
| | | } |
| | | |
| | | private String resolveSubmitterName(MpUser submitter) { |
| | | if (submitter == null) { |
| | | return "预约人"; |
| | | } |
| | | if (StringUtils.hasText(submitter.getNickName())) { |
| | | return submitter.getNickName().trim(); |
| | | } |
| | |
| | | return submitter.getMobile().trim(); |
| | | } |
| | | return "预约人"; |
| | | } |
| | | |
| | | private MpUser loadSubmitter(AppointmentOrder order) { |
| | | if (order == null || order.getSubmitterId() == null) { |
| | | return null; |
| | | } |
| | | return mpUserMapper.selectOne( |
| | | new LambdaQueryWrapper<MpUser>() |
| | | .eq(MpUser::getDelFlag, 0) |
| | | .eq(MpUser::getId, order.getSubmitterId()) |
| | | .last("limit 1")); |
| | | } |
| | | |
| | | private String buildVisitTimeText(AppointmentOrder order) { |
| | |
| | | return reasonCode; |
| | | } |
| | | |
| | | private String buildVisitorCountText(int visitorCount) { |
| | | return Math.max(visitorCount, 0) + "人"; |
| | | private String buildVisitorCountNumber(int visitorCount) { |
| | | return String.valueOf(Math.max(visitorCount, 0)); |
| | | } |
| | | |
| | | private String buildNoticeBusinessTypeText(AppointmentOrder order, boolean approved) { |
| | | String reason = buildVisitReasonText(order); |
| | | if (!StringUtils.hasText(reason)) { |
| | | return approved ? "预约通过" : "预约驳回"; |
| | | private int countVisitors(AppointmentOrder order) { |
| | | if (order == null || order.getId() == null) { |
| | | return 0; |
| | | } |
| | | return reason; |
| | | Long count = |
| | | appointmentVisitorMapper.selectCount( |
| | | new LambdaQueryWrapper<AppointmentVisitor>() |
| | | .eq(AppointmentVisitor::getDelFlag, 0) |
| | | .eq(AppointmentVisitor::getOrderId, order.getId())); |
| | | return count == null ? 0 : count.intValue(); |
| | | } |
| | | |
| | | private String buildTodoTaskName(AppointmentOrder order) { |