diff --git a/order-management-invoice/src/main/java/com/dxhy/order/invoice/module/invoice/service/impl/OrderInvoiceInfoServiceImpl.java b/order-management-invoice/src/main/java/com/dxhy/order/invoice/module/invoice/service/impl/OrderInvoiceInfoServiceImpl.java index e152315..01372e9 100644 --- a/order-management-invoice/src/main/java/com/dxhy/order/invoice/module/invoice/service/impl/OrderInvoiceInfoServiceImpl.java +++ b/order-management-invoice/src/main/java/com/dxhy/order/invoice/module/invoice/service/impl/OrderInvoiceInfoServiceImpl.java @@ -9,6 +9,8 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.dxhy.base.common.constant.ConfigureConstant; import com.dxhy.base.common.constant.OrderInfoEnum; import com.dxhy.base.common.constant.OrderManagementConstant; @@ -19,7 +21,12 @@ import com.dxhy.base.file.common.ExcelReadContext; import com.dxhy.base.file.handle.ExcelExportHandle; import com.dxhy.base.service.module.base.model.SalerWarning; import com.dxhy.base.service.module.base.service.SalerWarningService; +import com.dxhy.base.service.module.buyer.model.BuyerEntity; +import com.dxhy.base.service.module.buyer.service.BuyerService; import com.dxhy.base.service.module.thirdservice.simsback.service.SimsBackService; +import com.dxhy.base.service.module.thirdservice.user.model.DeptEntity; +import com.dxhy.base.service.module.thirdservice.user.service.UserInfoService; +import com.dxhy.base.service.openapi.protocol.qd.PageGfxxReq; import com.dxhy.base.service.utils.DesensitizeUtil; import com.dxhy.base.sms.utils.MessageSenderUtil; import com.dxhy.base.sms.vo.AttachmentVo; @@ -83,6 +90,7 @@ import com.github.pagehelper.PageInfo; import com.github.pagehelper.page.PageMethod; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.joda.time.DateTime; @@ -195,6 +203,12 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { @Resource private OrderInfoQdGtgmfMapper orderInfoQdGtgmfMapper; + @Resource + private UserInfoService userInfoService; + + @Resource + private BuyerService buyerService; + /** * 作用: @@ -1880,6 +1894,7 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { String pushType = fpYxTsMqData.getPushType(); String emailAddress = fpYxTsMqData.getEmailAddress(); + //发票流水号为空 if (StringUtils.isEmpty(fpqqlsh)) { log.error("发票流水号:{},流水号为空不交付邮件!", fpqqlsh); @@ -1895,18 +1910,42 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { fphm = orderInvoiceInfo.getSdfphm(); } + //从大B获取配置信息 + DeptEntity deptEntity = userInfoService.querySysDeptEntity(orderInvoiceInfo.getXhfNsrsbh(), orderInvoiceInfo.getEntId()); + + log.info("大B邮箱配置信息:{}", JSONObject.toJSONString(deptEntity)); + if (ObjectUtils.isEmpty(deptEntity)) { + OrderInvoiceInfo orderInvoiceInfoUpdate = new OrderInvoiceInfo(); + orderInvoiceInfoUpdate.setFpqqlsh(orderInvoiceInfo.getFpqqlsh()); + orderInvoiceInfoUpdate.setEmailPushStatus(OrderInfoEnum.EMAIL_PUSH_STATUS_3.getKey()); + orderInvoiceInfoUpdate.setEmailPushSbyy("获取大B邮箱配置失败"); + updateOrderInvoiceInfoByFpqqlsh(orderInvoiceInfoUpdate, shList); + log.error("获取大B邮箱配置失败"); + return R.error("获取大B邮箱配置失败"); + } + if (ConfigureConstant.STRING_0.equals(deptEntity.getEmailSend())) { + OrderInvoiceInfo orderInvoiceInfoUpdate = new OrderInvoiceInfo(); + orderInvoiceInfoUpdate.setFpqqlsh(orderInvoiceInfo.getFpqqlsh()); + orderInvoiceInfoUpdate.setEmailPushStatus(OrderInfoEnum.EMAIL_PUSH_STATUS_1.getKey()); + orderInvoiceInfoUpdate.setEmailPushSbyy("邮箱推送未开启"); + updateOrderInvoiceInfoByFpqqlsh(orderInvoiceInfoUpdate, shList); + log.info("税号-{}未开启邮箱推送", JSON.toJSONString(shList)); + return R.error("税号-{}未开启邮箱推送", JSON.toJSONString(shList)); + } + + //如果为自动推送,红票数据不交付邮件 //如果为手动,交付红票邮件 if (ConfigureConstant.STRING_1.equals(pushType)) { - if (OrderInfoEnum.INVOICE_BILLING_TYPE_1.getKey().equals(orderInvoiceInfo.getKplx())) { - log.error("发票代码:{},发票号码:{},红票数据不交付邮件!", fpdm, fphm); - OrderInvoiceInfo orderInvoiceInfoUpdate = new OrderInvoiceInfo(); - orderInvoiceInfoUpdate.setFpqqlsh(orderInvoiceInfo.getFpqqlsh()); - orderInvoiceInfoUpdate.setEmailPushStatus(OrderInfoEnum.EMAIL_PUSH_STATUS_0.getKey()); - orderInvoiceInfoUpdate.setEmailPushSbyy("红票数据不交付邮件"); - updateOrderInvoiceInfoByFpqqlsh(orderInvoiceInfoUpdate, shList); - return R.error("发票代码:" + fpdm + ",发票号码:" + fphm + ",红票数据不交付邮件!"); - } +// if (OrderInfoEnum.INVOICE_BILLING_TYPE_1.getKey().equals(orderInvoiceInfo.getKplx())) { +// log.error("发票代码:{},发票号码:{},红票数据不交付邮件!", fpdm, fphm); +// OrderInvoiceInfo orderInvoiceInfoUpdate = new OrderInvoiceInfo(); +// orderInvoiceInfoUpdate.setFpqqlsh(orderInvoiceInfo.getFpqqlsh()); +// orderInvoiceInfoUpdate.setEmailPushStatus(OrderInfoEnum.EMAIL_PUSH_STATUS_0.getKey()); +// orderInvoiceInfoUpdate.setEmailPushSbyy("红票数据不交付邮件"); +// updateOrderInvoiceInfoByFpqqlsh(orderInvoiceInfoUpdate, shList); +// return R.error("发票代码:" + fpdm + ",发票号码:" + fphm + ",红票数据不交付邮件!"); +// } //自动交付数据,需要防止并发操作,增加redis和数据库双重逻辑判断,优先判断redis状态,如果已发送,跳过处理,再判断数据库状态,如果为已发送,跳过处理 String pushEmailRedis = redisService.get(String.format(RedisConstant.REDIS_PUSH_EMAIL, orderInvoiceInfo.getFpqqlsh())); if (ConfigureConstant.STRING_1.equals(pushEmailRedis)) { @@ -1934,6 +1973,18 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { OrderInvoiceInfo orderInvoiceInfoUpdate = new OrderInvoiceInfo(); orderInvoiceInfoUpdate.setFpqqlsh(orderInvoiceInfo.getFpqqlsh()); + + //购方信息获取邮箱 + if (StringUtils.isBlank(emailAddress)){ + PageGfxxReq pageGfxxReq = new PageGfxxReq(); + pageGfxxReq.setGfmc(orderInvoiceInfo.getGhfMc()); + pageGfxxReq.setXhfNsrsbh(orderInvoiceInfo.getXhfNsrsbh()); + BuyerEntity buyerEntity = buyerService.queryBuyerInfo(pageGfxxReq); + if (ObjectUtil.isNotNull(buyerEntity)){ + emailAddress = buyerEntity.getEmail(); + } + } + //存在邮箱的话用邮箱进行推送 if (StringUtils.isNotBlank(emailAddress)) { @@ -1962,7 +2013,7 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { EmailContent emailContent = buildEmailContent(orderInvoiceInfo, emailAddressList, terminalCode); if (ObjectUtil.isNotNull(emailContent)) { //调用邮件服务 - Map sendEmail = sendEmail(emailContent); + Map sendEmail = sendEmail(emailContent, orderInvoiceInfo); //根据调用邮件服务的结果更新数据库 if (!ConfigureConstant.STRING_0000.equals(String.valueOf(sendEmail.get(OrderManagementConstant.CODE)))) { @@ -2166,7 +2217,7 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { DateUtil.formatDateTime(orderInvoiceInfo.getCreateTime()), OrderCommonUtils.getFpzlDmMc(orderInvoiceInfo.getFpzlDm()), sbyy}); emailContent.setTo(toArr); // 发送邮件 - sendEmail(emailContent); + sendEmail(emailContent, orderInvoiceInfo); } } @@ -2184,7 +2235,7 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { * @author yaoxuguang * @date 2021-12-13 */ - private Map sendEmail(EmailContent emailContent) { + private Map sendEmail(EmailContent emailContent, OrderInvoiceInfo orderInvoiceInfo) { String emailSendType = invoiceConfig.getEmailSendType(); Map resultMap = new HashMap<>(3); if (SEND_TYPE_0.equals(emailSendType)) { @@ -2213,14 +2264,26 @@ public class OrderInvoiceInfoServiceImpl implements OrderInvoiceInfoService { }); mailContent.setAttachmentVos(attachmentVoList); } + //从大B获取配置信息 + DeptEntity deptEntity = userInfoService.querySysDeptEntity(orderInvoiceInfo.getXhfNsrsbh(), orderInvoiceInfo.getEntId()); + + log.info("大B邮箱配置信息:{}", JSONObject.toJSONString(deptEntity)); + if (ObjectUtils.isEmpty(deptEntity)) { + log.error("获取大B邮箱配置失败"); + resultMap.put(OrderManagementConstant.CODE, ConfigureConstant.STRING_9999); + resultMap.put(OrderManagementConstant.ALL_MESSAGE, "获取大B邮箱配置失败"); + return resultMap; + } + boolean isBlank = ObjectUtils.isEmpty(deptEntity) || StringUtils.isBlank(deptEntity.getSendAddress()); + //发件方信息 SendMailVo sendVo = new SendMailVo(); //发件方邮箱 - sendVo.setSendAddress(invoiceConfig.getSendAddress()); + sendVo.setSendAddress(isBlank ? invoiceConfig.getSendAddress() : deptEntity.getSendAddress()); //发件方第三方授权码 - sendVo.setAuthPassword(invoiceConfig.getAuthPassword()); + sendVo.setAuthPassword(isBlank ? invoiceConfig.getAuthPassword() : deptEntity.getAuthPassword()); //发件方名称 - sendVo.setSendName(invoiceConfig.getSendName()); + sendVo.setSendName(isBlank ? invoiceConfig.getSendName() : deptEntity.getSendName()); //发件方邮件服务器 sendVo.setSmtpServer(invoiceConfig.getSmtpServer()); //邮件服务器端口 diff --git a/order-management-order/src/main/java/com/dxhy/order/consumer/config/rabbitmq/OrderSaveGhfInfoHandler.java b/order-management-order/src/main/java/com/dxhy/order/consumer/config/rabbitmq/OrderSaveGhfInfoHandler.java index bca3b49..c2fdeb2 100644 --- a/order-management-order/src/main/java/com/dxhy/order/consumer/config/rabbitmq/OrderSaveGhfInfoHandler.java +++ b/order-management-order/src/main/java/com/dxhy/order/consumer/config/rabbitmq/OrderSaveGhfInfoHandler.java @@ -2,12 +2,14 @@ package com.dxhy.order.consumer.config.rabbitmq; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson2.JSONObject; import com.dxhy.base.common.model.OrderInfo; import com.dxhy.base.common.utils.JsonUtils; import com.dxhy.base.common.utils.NsrsbhUtils; import com.dxhy.base.rabbitmq.rabbitplugin.listener.BaseListener; import com.dxhy.base.service.module.buyer.model.BuyerEntity; import com.dxhy.base.service.module.buyer.service.BuyerService; +import com.dxhy.base.service.openapi.protocol.qd.PageGfxxReq; import com.dxhy.order.baseservice.model.OrderInvoiceInfo; import com.dxhy.order.consumer.modules.order.service.OrderInfoService; import com.dxhy.order.consumer.utils.BeanTransitionUtils; @@ -77,8 +79,19 @@ public class OrderSaveGhfInfoHandler implements BaseListener { OrderInfo orderInfo = orderInfoService.queryOrderInfoByFpqqlsh(orderInvoiceInfo.getFpqqlsh(), NsrsbhUtils.transShListByNsrsbh(orderInvoiceInfo.getXhfNsrsbh())); //购方税号不为空的数据,进行保存 if (ObjectUtil.isNotNull(orderInfo) && StringUtils.isNotBlank(orderInfo.getGhfNsrsbh())) { + PageGfxxReq pageGfxxReq = new PageGfxxReq(); + pageGfxxReq.setGfmc(orderInvoiceInfo.getGhfMc()); + pageGfxxReq.setXhfNsrsbh(orderInvoiceInfo.getXhfNsrsbh()); + BuyerEntity buyerEntityOld = buyerService.queryBuyerInfo(pageGfxxReq); BuyerEntity buyerEntity = BeanTransitionUtils.createBuyerEntity(orderInfo, orderInfo.getGhfId()); + if (buyerEntityOld != null){ + if (StringUtils.isBlank(buyerEntity.getEmail())){ + buyerEntity.setEmail(buyerEntityOld.getEmail()); + } + } + log.info("saveGhfxx{}", JSONObject.toJSONString(buyerEntity)); + buyerService.saveOrUpdateBuyerInfo(buyerEntity); log.info("{}保存购方消息成功", LOGGER_MSG); diff --git a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/model/DeptEntity.java b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/model/DeptEntity.java index 5479f0c..e6f453a 100644 --- a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/model/DeptEntity.java +++ b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/model/DeptEntity.java @@ -176,4 +176,22 @@ public class DeptEntity implements Serializable { * 组织类型(0:虚拟组织,1:实体组织) */ private String groupType; + /** + * '邮箱' + */ + private String sendAddress; + /** + * '授权码' + */ + private String authPassword; + /** + * '发送方名称' + */ + private String sendName; + + /** + * '是否启用邮箱' + */ + private String emailSend; + } diff --git a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/UserInfoService.java b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/UserInfoService.java index 3fda6b6..0808337 100644 --- a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/UserInfoService.java +++ b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/UserInfoService.java @@ -80,4 +80,13 @@ public interface UserInfoService { */ DeptEntity querySysDeptEntityFromUrl(String taxpayerCode, String taxpayerName, String entId); + + /** + * 根据税号获取部门信息 + * + * @param xhfNsrsbh + * @param entId + * @return + */ + DeptEntity querySysDeptEntity(String xhfNsrsbh, String entId); } diff --git a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/impl/UserInfoServiceImpl.java b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/impl/UserInfoServiceImpl.java index 38782fd..71f0f19 100644 --- a/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/impl/UserInfoServiceImpl.java +++ b/sims-base-service/src/main/java/com/dxhy/base/service/module/thirdservice/user/service/impl/UserInfoServiceImpl.java @@ -585,4 +585,32 @@ public class UserInfoServiceImpl implements UserInfoService { }); } } + + @Override + public DeptEntity querySysDeptEntity(String taxpayerCode, String entId) { + Map paraMap = new HashMap<>(2); + paraMap.put(ConfigureConstant.STRING_TAXPAYER_CODE, taxpayerCode); + paraMap.put("ompDeptId", entId); + Map headMap = new HashMap<>(2); + headMap.put("Content-Type", ConfigureConstant.STRING_APPLICATION_JSON); + try { + + String queryTaxInfo = userCenterConfig.getBigBQueryOrgInfoByCode(); + + log.info("{},获取企业信息的接口,url:{},入参:{}", LOGGER_MSG, queryTaxInfo, JsonUtils.getInstance().toJsonString(paraMap)); + String result = HttpUtils.doPostWithHeader(queryTaxInfo, JsonUtils.getInstance().toJsonString(paraMap), headMap); + log.info("{}调用用户信息获取信息为:{}", LOGGER_MSG, result); + if (StringUtils.isNotBlank(result)) { + JSONObject jsonObject = JSON.parseObject(result); + if (!jsonObject.isEmpty() && ConfigureConstant.STRING_0000.equals(jsonObject.get(OrderManagementConstant.CODE))) { + return JsonUtils.getInstance().parseObject(jsonObject.getString(OrderManagementConstant.DATA), DeptEntity.class); + } + + } + } catch (Exception e) { + log.error("{}调用用户信息获取服务异常", LOGGER_MSG, e); + return null; + } + return null; + } }