package com.hx.phip.service.order.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.common.service.CommonService; import com.hx.exception.TipsException; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.common.*; import com.hx.phiappt.constants.tool.*; import com.hx.phiappt.constants.tool.model.MessageTemplate; import com.hx.phiappt.constants.tool.order.OrderUtil; import com.hx.phiappt.model.*; import com.hx.phiappt.model.consume.ConsumePay; import com.hx.phiappt.model.coupon.Coupon; import com.hx.phiappt.model.coupon.CouponNumber; import com.hx.phiappt.model.coupon.CouponOrderDiscountLog; import com.hx.phiappt.model.memberLevel.MemberLevel; import com.hx.phiappt.model.order.*; import com.hx.phiappt.model.user.UserProjectItem; import com.hx.phiappt.model.userStatus.UserStatusLog; import com.hx.phip.config.CustomParameter; import com.hx.phip.dao.mapper.*; import com.hx.phip.service.OrdersTotalService; import com.hx.phip.service.ProjectService; import com.hx.phip.service.order.OrderService; import com.hx.phip.service.order.OrderServiceV2; import com.hx.phip.util.OrdersSnapshotUtil; import com.hx.phip.util.api.ApiPlatformUtil; import com.hx.phip.util.api.*; import com.hx.resultTool.Result; import com.hx.util.DateUtil; import com.hx.util.StringUtils; import com.hx.warehouse.feign.WOrderService; import com.hz.crm.feign.FGoodsSkuService; import com.hz.his.dto.gzh.GzhTemplateVO; import com.hz.his.feign.service.marketing.MOrderService; import com.hz.his.feign.service.phisAdmin.SGzhTemplateService; import com.hz.his.feign.service.sync.SyncOrderService; import com.platform.constants.PlatformPattern; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; /** * 开单实现类 * * @Author: zhouxiang * @Date: 2022/09/19/15:32 * @Description: */ @Transactional @Service public class OrderServiceV2Impl implements OrderServiceV2 { //log4j日志 private static Logger logger = LoggerFactory.getLogger(OrderServiceV2Impl.class.getName()); // 固定线程池 ExecutorService threadPool = Executors.newFixedThreadPool(10); private static List orderTypeList= Arrays.asList(OrderTotalConstants.TYPE_RECHARGE,OrderTotalConstants.TYPE_TURN_RECHARGE); @Resource private SystemParameterMapper systemParameterMapper; @Resource private OrdersTotalService ordersTotalService; @Resource private CustomParameter customParameter; @Resource private ProjectService projectService; @Resource private CommonService commonService; @Resource private SGzhTemplateService sGzhTemplateService; @Resource private FGoodsSkuService fGoodsSkuService; @Resource private MOrderService mOrderService; @Resource private WOrderService wOrderService; @Resource private OrderService orderService; @Override public Map orderCreate(OrdersTotal ordersTotal, List items, Integer type, List orderDeveloperList, Map operator,Shop shop, UserMoney userMoney, User user,PlatformApplication platformApplication, CommonService commonService) { //定义总订单金额初始字段 //总订单订单售价总金额 BigDecimal totalPrice=BigDecimal.ZERO; //总订单订单原价总金额 BigDecimal oriTotal=BigDecimal.ZERO; //总订单应付支付总金额 BigDecimal shouldOrderTotal=BigDecimal.ZERO; //总订单的优惠总金额 BigDecimal discountTotal=BigDecimal.ZERO; //非主线任务节点报错标记 Integer nodeType=0; //是否老带新 Integer isOldBringNew =BaseEntity.NO; //是否初诊单 Integer isBothTheOne =BaseEntity.NO; //返回参数 Map data=new HashMap<>(); //开单节点日志 OrdersNodeLog ordersNodeLog = new OrdersNodeLog(); StringBuilder orderCreate = new StringBuilder(); SqlSentence sqlSentence=new SqlSentence(); Map appIdMap = new HashMap<>(); sqlSentence.setM(appIdMap); //主线业务 //业务逻辑判断(商品限制、订单重复等) OrderCreateUtil.businessJudge(ordersTotal,items,user,shop,ordersTotalService,commonService); /** * 计算订单金额信息(计算请求参数的一级子订单) * 1、充值订单不需要系统计算金额,充多少是多少 * 2、商品、项目、促销、卡项、卡向内等均系统计算订单金额 * 3、处理活动规则(主要处理是满减、满折扣情况),对总订单金额进行扣减 */ if(orderTypeList.contains(ordersTotal.getType())){ //订单充值总金额 totalPrice=ordersTotal.getTotal(); //订单应付付总金额 shouldOrderTotal=ordersTotal.getTotal(); }else { Map handOrderItemMap = OrderCreateUtil.handOrderItem(ordersTotal, items, totalPrice, shouldOrderTotal,discountTotal,oriTotal, commonService, systemParameterMapper); totalPrice= (BigDecimal) handOrderItemMap.get("totalPrice"); shouldOrderTotal= (BigDecimal) handOrderItemMap.get("shouldOrderTotal"); discountTotal= (BigDecimal) handOrderItemMap.get("discountTotal"); oriTotal= (BigDecimal) handOrderItemMap.get("oriTotal"); items= (List) handOrderItemMap.get("items"); } //处理活动规则,活动规则如果是满减、折扣,则订单应付金额需要扣减活动规则金额,(目前只有充值订单才能用到活动规则) if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType()) && ordersTotal.getActivityIds() !=null && ordersTotal.getActivityIds().size()>0){ ordersTotal.setShouldTotal(totalPrice); BigDecimal price=OrderAddUtil.activityRule(ordersTotal,commonService,operator,userMoney,customParameter,user,0); if(price !=BigDecimal.ZERO){ ordersTotal.setActivityTotal(shouldOrderTotal.subtract(price)); shouldOrderTotal=price; } } //处理订单基本信息(总订单和子订单) //处理总订单开发人,默认客户的所属顾问,注意如果是crm开单的传什么就是什么 OrderCreateUtil.handUserDeveloper(ordersTotal,user,orderTypeList,commonService); //构架总订单基本信息,金额信息,并保存(orderTotal、orderInfo) OrderCreateUtil.setOrderTotal(ordersTotal, shop, totalPrice, shouldOrderTotal, discountTotal, operator.get("operatorId"),operator.get("operatorName"),Integer.valueOf(operator.get("operatorType")),oriTotal,type,user,systemParameterMapper, platformApplication,commonService); ordersTotal = OrderCreateUtil.createOrder(ordersTotal, operator, user, userMoney, commonService); //保存活动规则信息(目前只有充值订单才能用到活动规则) OrderCreateUtil.insertActivity(ordersTotal.getActivityIds(),ordersTotal,commonService); //非主线业务 try { //判断是否是初诊单 nodeType=3; orderCreate.append("-开始判断是否是初诊单"); // 改集中工具类 复制于翔爷代码 统一方便修改代码 isBothTheOne = OrderUtil.checkIsBothTheOne(ordersTotal, commonService, VisitRecordMapper.class); orderCreate.append("-结束判断是否是初诊单"); //订单如果为复诊单那么就是老带新订单,对应禅道需求编号694 // if(isBothTheOne !=null && isBothTheOne==OrderInfo.CONSULTATION){ // isOldBringNew=BaseEntity.YES; // } //判断是否老带新 nodeType=1; orderCreate.append("-开始判断是否老带新"); // 改集中工具类 复制于翔爷代码 统一方便修改代码 ordersTotal.getOrderInfo().setIsBothTheOne(isBothTheOne); isOldBringNew = OrderUtil.checkOldBringNew(ordersTotal, commonService, VisitRecordMapper.class); orderCreate.append("-结束判断是否老带新"); nodeType=2; nodeType=4; }catch (Exception e){ String nodeText=""; if(nodeType>=1 && nodeType<2){ nodeText="判断是否老带新失败"; orderCreate.append("-判断是否老带新失败,异常信息:"+e.getMessage()); }else if(nodeType>=3 && nodeType<4){ nodeText="判断是否是初诊单失败"; orderCreate.append("-判断是否是初诊单失败,异常信息:"+e.getMessage()); } //记录非主线日志(处理到具体节点(成功和失败)) ordersNodeLog.setCommonType(OrdersNodeLog.TYPE_COMMON_ORDER_CREATE); ordersNodeLog.setContent(orderCreate.toString()); ordersNodeLog.setOrderId(ordersTotal.getId()); commonService.insert(OrdersNodeLogMapper.class,ordersNodeLog); //异常发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),nodeText,commonService,customParameter); logger.info("开单"+nodeText+",异常原因:{}",e.getMessage(),e); e.printStackTrace(); } //主线业务 //保存订单其他信息(对象:orderInfo) String activityName = OrderCreateUtil.saveOrderInfo(ordersTotal, user,isOldBringNew,isBothTheOne, commonService); //保存一级子订单和处理二级子订单信息(orderItem、orderItemSon) if(!orderTypeList.contains(ordersTotal.getType())){ //创建子订单 OrderCreateUtil.createOrderItem(ordersTotal, items,projectService,commonService,sqlSentence,appIdMap); } //生成订单日志 commonService.insert(OrderLogMapper.class, ApiOrderUtil.setOrderLog(ordersTotal, null, operator.get("operatorId"), operator.get("operatorName"), activityName, 0, OrderLogConstants.LOG_TYPE_CREATE)); //保存绑定的其他开发人集合信息 OrderAddUtil.creatDeveloperList(ordersTotal, orderDeveloperList,commonService); //营销助手审批,如果订单有折扣 if(StringUtils.isEmpty(ordersTotal.getKoapOrderId())&& ordersTotal.getOrderInfo()!=null) { OrderCreateUtil.approvalMarketing(ordersTotal,mOrderService,commonService); } //返回phis订单号、phis订单id data.put("orderNo",ordersTotal.getOrderNo()); data.put("orderId",ordersTotal.getId()); return data; } @Override public Map orderPayMoney(Integer type, OrdersTotal ordersTotal, User user,User payUser, Shop shop, OrderInfo info, List orderItemList, Map operator, UserMoney userMoney, String total, JSONArray amountList, JSONArray userCouponIds, JSONObject jsonObject) { String message=""; //订单优惠券金额 BigDecimal couponAfterAmount =BigDecimal.ZERO; //用户支付方式集合,用于同步到his系统 JSONArray hisPayList=new JSONArray(); //接口返回参数map Map data=new HashMap<>(); //订单节点日志 OrdersNodeLog ordersNodeLog = new OrdersNodeLog(); StringBuilder orderNodeBuilder = new StringBuilder(); // if(userCouponIds!=null && userCouponIds.size()>0){ // //获取优惠券金额 // couponAfterAmount = CouponTool.handCouponAmout(ordersTotal.getShouldTotal(), coupon); // } orderNodeBuilder.append("开始结账"); /** * 处理优惠券金额,先计算优惠金额因为优惠券金额也需要参加到业务判断金额是否符合 */ if(userCouponIds!=null && userCouponIds.size()>0){ orderNodeBuilder.append("-开始处理优惠券信息"); CouponNumber couponNumber=null; Coupon coupon=null; //判断优惠券是否可以使用,以及保存订单使用优惠券记录,以及线下券核销操作 for(int i=0;i objectMap = OrderPayMoneyUtil.handPayMethod(amountList, ordersTotal, commonService, customParameter); //总订单 ordersTotal= (OrdersTotal) objectMap.get("ordersTotal"); //一级子订单用户实际支付金额,该Map用于统计用户按照项目部分付款 MapitemMap= (Map) objectMap.get("itemMap"); //订单的已支付现金金额(微信/支付宝支付/其他) BigDecimal payTotal= (BigDecimal) objectMap.get("payTotal"); //订单的已支付储值金金额 BigDecimal payRecharge= (BigDecimal) objectMap.get("payRecharge"); //订单的已支付增值金金额 BigDecimal payIncrement= (BigDecimal) objectMap.get("payIncrement"); //订单现金支付总金额 BigDecimal snapPayTotal= (BigDecimal) objectMap.get("snapPayTotal"); //订单现金支付总金额 BigDecimal snapExecuteTotal= (BigDecimal) objectMap.get("snapExecuteTotal"); //用户支付方式集合,用于同步到his系统 hisPayList= (JSONArray) objectMap.get("hisPayList"); //存储卡项id,用户判断用户是否使用的是卡包进行结算 List cardIds= (List) objectMap.get("cardIds"); orderNodeBuilder.append("-结束处理订单支付记录"); /** * 处理充值订单-增加储值金 */ if(orderTypeList.contains(ordersTotal.getType())){ orderNodeBuilder.append("-开始处理充值订单增加储值金"); OrderPayMoneyUtil.handRecharge(ordersTotal, amountList, objectMap, commonService); orderNodeBuilder.append("-结束处理充值订单增加储值金"); } /** * 处理订单基本信息(总订单和子订单) */ orderNodeBuilder.append("-开始处理订单基本信息"); //更改订单基本信息(商品、项目、促销、卡项、卡集基本信息) //更新一级子订单或者二级子订单(需要处理未执行划扣金额、项目生成未执行划扣、商品生成提货单(目前没有库存不处理)、促销、卡项(目前不处理)、卡包) ordersTotal.getOrderInfo().setSnapPayTotal(snapPayTotal); ordersTotal.getOrderInfo().setSnapExecuteTotal(snapExecuteTotal); if(!orderTypeList.contains(ordersTotal.getType())){ OrderPayMoneyUtil.payHandOrderItem(orderItemList,ordersTotal, itemMap,operator ,userMoney,cardIds,user, couponAfterAmount,wOrderService,payTotal, payRecharge,payIncrement,commonService,customParameter); } //更新总订单状态、金额信息、记录日志 OrderPayUtil.payHandleOrderTotal(operator, ordersTotal, payTotal, payRecharge, couponAfterAmount,payIncrement,commonService); orderNodeBuilder.append("-结束处理订单基本信息"); /** * 处理活动规则 */ orderNodeBuilder.append("-开始处理活动规则"); OrderPayMoneyUtil.handActivity(ordersTotal, user, operator, userMoney,commonService,customParameter); orderNodeBuilder.append("-结束处理活动规则"); //非主线业务 /** * 用户升降级(调用航爷) 金额=用户支付的实付现金金额(不包含储值金) */ if(snapPayTotal !=null && snapPayTotal.compareTo(BigDecimal.ZERO) == 1){ try { orderNodeBuilder.append("-开始处理用户升降级"); UserLevelUtil.order(ordersTotal.getUserId(),ordersTotal.getId(),snapPayTotal,ordersTotal.getAppIdCode()); orderNodeBuilder.append("-结束处理用户升降级"); }catch (Exception e){ String snapshot="处理用户升降级失败"; orderNodeBuilder.append("-处理用户升降级失败,异常原因:"+e.getMessage()); logger.error("处理用户升降级失败:" + e.getMessage()); //发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),snapshot,commonService,customParameter); } } //用户活跃状态处理(先暂时不处理) /** * 快照 */ //订单快照 if(OrderTotalConstants.STATUS_PAY == ordersTotal.getStatus() || OrderTotalConstants.STATUS_DONE == ordersTotal.getStatus()){ // 状态 已支付与已完成 try { orderNodeBuilder.append("-开始处理订单快照"); OrdersSnapshotUtil.createOrdersSnapshot(customParameter, ordersTotal.getId(), commonService); orderNodeBuilder.append("-结束处理订单快照"); } catch (Exception e) { String snapshot="处理订单快照失败"; orderNodeBuilder.append("-处理订单快照失败,异常原因:"+e.getMessage()); logger.error("生成快照失败:" + e.getMessage()); //发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),snapshot,commonService,customParameter); message=e.getMessage(); } } Integer synHisOrderType=0; /** * 同步 */ // try { // //同步开单-同步订单到领建 // if(ordersTotal.getHisSynStatus()==1){ // orderNodeBuilder.append("-开始处理创建订单同步订单到领建"); // synHisOrderType=1; // String hisOrderId = OrderCreateUtil.syncOrder(ordersTotal, operator,ordersTotal.getOrderNo(),customParameter,commonService); // if(StringUtils.isEmpty(hisOrderId)){ // throw new PlatTipsException(PlatformCode.ERROR_TIPS,"同步领建失败!领建标识为空"); // } // data.put("hisOrderId",hisOrderId); // ordersTotal.setHisOrderId(hisOrderId); // orderNodeBuilder.append("-结束处理创建订单同步订单到领建"); // // //同步结账-同步订单到领建 // orderNodeBuilder.append("-开始处理结账同步订单到领建"); // synHisOrderType=2; // //封装支付方式,如果结账采用了优惠券,封装支付方式为优惠券到领建,如果是积分封装支付方式为积分 // OrderPayMoneyUtil.synOrderPayWay(ordersTotal, couponAfterAmount, hisPayList); // //将p-his结账的订单同步到领建系统 // SynOrderUtil.synPayOrder(operator, ordersTotal, shop.getApiId(), hisPayList,customParameter,commonService); // orderNodeBuilder.append("-结束处理结账同步订单到领建"); // } // // // //同步结账-如果是卡包支付则需要扣减领建卡包次数操作(调用同步中心接口) // if(OrderTotalConstants.TYPE_CARD_BAG.equals(ordersTotal.getType())){ // orderNodeBuilder.append("-开始处理结账扣减领建卡包次数"); // synHisOrderType=3; // //因为p-his开的已有卡项订单是用普通项目开过去的,所以这里需要调用同步中心接口扣减已有卡项次数,切掉领建该方法也需要去掉 // RefundUtil.handHisCardBag(commonService, customParameter, ordersTotal,0); // orderNodeBuilder.append("-结束理结账扣减领建卡包次数"); // } // }catch (Exception e){ // String sysPhiskin=""; // switch (synHisOrderType){ // case 1: // sysPhiskin="领建创建订单失败"; // orderNodeBuilder.append("-领建创建订单失败,异常原因:"+e.getMessage());break; // case 2: // sysPhiskin="领建结账同步失败"; // orderNodeBuilder.append("-领建结账同步失败,异常原因:"+e.getMessage());break; // case 3: // sysPhiskin="领建扣减卡包同步失败"; // orderNodeBuilder.append("-领建扣减卡包同步失败,异常原因:"+e.getMessage());break; // } // logger.info("同步订单到领建异常(创建、结账、卡包扣减)!,异常原因:{}",e.getMessage(),e); // JSONObject object = new JSONObject(); // object.put("ordersTotal",ordersTotal); // object.put("type",0); // object.put("operator",operator.toString()); // object.put("shopApiId",shop.getApiId()); // object.put("hisPayList",hisPayList.toString()); // //同步结账或扣减领建卡包次数异常失败,保存重发记录,发送企业微信通知给开发人 // OrderCreateUtil.orderSendNoticeResendRecord(ordersTotal, e, object,"/phip/resend/order/create/pay/cardBag","同步订单到领建异常(创建、结账、卡包扣减)!",synHisOrderType,commonService,customParameter); // //发送企业微信通知给工作人员 // SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),sysPhiskin,commonService,customParameter); // message=e.getMessage(); // } try { //同步结账-同步到康博佳 if(PlatformPattern.PROD.equals(customParameter.getPlatformPattern()) && StringUtils.noNull(ordersTotal.getKoapOrderId())){ orderNodeBuilder.append("-开始处理同步康博佳结账"); //将p-his结账的订单同步到康博佳系统 SynOrderUtil.synKoapPayOrder(operator, ordersTotal, hisPayList,customParameter,commonService); orderNodeBuilder.append("-结束处理同步康博佳结账"); } }catch (Exception e){ String koapPay="处理同步康博佳结账失败"; orderNodeBuilder.append("-处理同步康博佳结账失败,异常原因:"+e.getMessage()); logger.info("同步结账-同步订单到康博佳异常!,异常原因:{}",e.getMessage(),e); //封装请求参数 JSONObject object = new JSONObject(); object.put("ordersTotal",ordersTotal); object.put("operator",operator.toString()); object.put("hisPayList",hisPayList.toString()); //结账同步到康博佳失败,保存重发记录,发送企业微信通知给开发人 OrderCreateUtil.orderSendNoticeResendRecord(ordersTotal, e, object,"接口名称","同步结账-同步订单到康博佳异常!",synHisOrderType,commonService,customParameter); //发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),koapPay,commonService,customParameter); message=e.getMessage(); } //结账成功发送公众号通知给用户 -异步 try { sendPublicNo(ordersTotal.getId(),commonService); }catch (Exception e){ logger.info("结账成功发送公众号通知给用户异常 -异步:{}",e.getMessage(),e); } //返回phis订单号、phis订单id data.put("orderId",ordersTotal.getId()); data.put("orderCode",ordersTotal.getOrderNo()); //记录日志(处理到具体节点(成功和失败)) orderNodeBuilder.append("-结束结账订单"); ordersNodeLog.setCommonType(OrdersNodeLog.TYPE_COMMON_ORDER_PAY); ordersNodeLog.setContent(orderNodeBuilder.toString()); ordersNodeLog.setOrderId(ordersTotal.getId()); commonService.insert(OrdersNodeLogMapper.class,ordersNodeLog); }catch (Exception e){ String mainBusiness="结账失败"; orderNodeBuilder.append("-结账失败,异常原因:"+e.getMessage()); logger.info("结账异常:{}",e.getMessage(),e); //异常发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),mainBusiness,commonService,customParameter); message=e.getMessage(); //记录日志(处理到具体节点(成功和失败)) orderNodeBuilder.append("-结束结账订单"); ordersNodeLog.setCommonType(OrdersNodeLog.TYPE_COMMON_ORDER_PAY); ordersNodeLog.setContent(orderNodeBuilder.toString()); ordersNodeLog.setOrderId(ordersTotal.getId()); commonService.insert(OrdersNodeLogMapper.class,ordersNodeLog); throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账失败,异常原因:"+e.getMessage()); } data.put("message",message); return data; } @Override public String getHisOrderNo(String hisOrderId, String orderId, SqlSentence sqlSentence, Map paramMap, SyncOrderService syncOrderService, CommonService commonService) { String hisOrderNo=""; OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,orderId); if (ordersTotal != null && StringUtils.noNull(hisOrderId)) { try { hisOrderNo = SynOrderUtil.getOrderById(hisOrderId, orderId, sqlSentence, paramMap, syncOrderService, commonService); } catch (Exception ex) { logger.info("查询领建订单号异常:领建订单标识{},预约订单标识:{}",hisOrderId,orderId,ex); } } return hisOrderNo; } @Override @Async public void getExecution(Object orderId,User user) { Map map=new HashMap<>(); SqlSentence sqlSentence = new SqlSentence(); StringBuilder sql = new StringBuilder(); sqlSentence.setM(map); map.put("orderId",orderId); map.put("type", OrderItemConstants.TYPE_PROJECT); sqlSentence.setSqlSentence(" type=#{m.type} and orderId=#{m.orderId}"); int itemCount = commonService.selectCount(OrderItemMapper.class, sqlSentence); int sonCount = commonService.selectCount(OrderItemSonMapper.class, sqlSentence); if(itemCount==0 && sonCount==0){ logger.info("异步获取未执行划扣itemId提示:一级子订单符合项目条数:{},二级子订单条数:{}",itemCount,sonCount); return; } OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,orderId); if(ordersTotal==null){ logger.info("异步获取未执行划扣itemId提示:根据订单标识未找到订单信息!"); return; } if(StringUtils.isEmpty(ordersTotal.getHisOrderId())){ logger.info("异步获取未执行划扣itemId提示:该订单没有领建标识!p-his订单标识:{}",ordersTotal.getId()); return; } sqlSentence.setSqlSentence("SELECT id,commonId,type FROM order_item WHERE orderId=#{m.orderId} "); List orderItems=commonService.selectList(OrderItemMapper.class,sqlSentence); if(orderItems==null || orderItems.size()==0){ logger.info("异步获取未执行划扣itemId提示:根据订单标识未找到一级子订单信息!"); return; } List itemIds = orderItems.stream().map(o -> o.getId()).collect(Collectors.toList()); sqlSentence.setSqlSentence("SELECT id,goodsId,type FROM order_item_source WHERE orderId=#{m.orderId} "); List orderItemSons=commonService.selectList(OrderItemSonMapper.class,sqlSentence); if(orderItemSons!=null && orderItemSons.size()>0){ itemIds.addAll(orderItemSons.stream().map(o->o.getId()).collect(Collectors.toList())); } sql.append("SELECT id,orderItemId,commonId FROM user_project_item WHERE commonId in( "); SqlSplicingTool.selectBuilderIn(sql,itemIds); sqlSentence.setSqlSentence(sql.toString()); List userProjectItems=commonService.selectList(UserProjectItemMapper.class,sqlSentence); if(userProjectItems==null || userProjectItems.size()==0){ logger.info("异步获取未执行划扣itemId提示:根据订单的一级子订单标识未找到用户未划扣信息!"); return; } Map userProjectItemMap = userProjectItems.stream().collect(Collectors.toMap(o -> o.getCommonId(),o->o)); JSONObject object = new JSONObject(); object.put("start", DateUtil.formatDate_3(new Date())); object.put("end",DateUtil.formatDate_3(new Date())); object.put("customerId",user.getApiId()); String returnData = ApiPlatformUtil.getExecution(customParameter, object.toJSONString()); if(StringUtils.noNull(returnData)){ JSONObject jsonObject = JSONObject.parseObject(returnData); String code = jsonObject.getString("code"); if("100".equals(code)){ JSONObject data = jsonObject.getJSONObject("data"); if(!data.isEmpty()){ JSONArray content = data.getJSONArray("content"); for(int j=0;j map=new HashMap<>(); sqlSentence.setM(map); map.put("isDel",BaseEntity.NO); map.put("orderId",orderId); sqlSentence.setSqlSentence("select * from consume_pay where orderId=#{m.orderId} and isDel=#{m.isDel}"); List consumePays=commonService.selectList(ConsumePayMapper.class,sqlSentence); sqlSentence.setSqlSentence("select * from coupon_order_discount_log where orderId=#{m.orderId} and isDel=#{m.isDel}"); List couponOrderDiscountLog=commonService.selectList(CouponOrderDiscountLogMapper.class,sqlSentence); String payMethod=""; String ln="\r\n"; if(consumePays==null ||consumePays.size()==0){ payMethod=payMethod.concat("实付:").concat(ln).concat("1、储值金:0,").concat(ln).concat("2、增值金:0").concat(ln).concat("3、优惠券抵扣:0"); }if(consumePays!=null && consumePays.size()>0){ String storedValueFund="0"; String valueAddedFund="0"; String couponDisAmout="0"; for (int i = 0; i < consumePays.size(); i++) { ConsumePay consumePay = consumePays.get(i); if(PayMethodTypeConstants.PAY_ADD_FUND.equals(consumePay.getNumberNo())){ valueAddedFund=consumePay.getActualTotal().toString(); } if(PayMethodTypeConstants.PAY_STORED.equals(consumePay.getNumberNo())){ storedValueFund=consumePay.getActualTotal().toString(); } if(!(PayMethodTypeConstants.PAY_ADD_FUND.equals(consumePay.getNumberNo()) || PayMethodTypeConstants.PAY_STORED.equals(consumePay.getNumberNo()))){ int num=i+4; if(i==consumePays.size()-1){ if(PayMethodTypeConstants.PAY_CARD.equals(consumePay.getNumberNo())){ payMethod=payMethod+num+"、"+consumePay.getName()+":"+"-"; }else{ payMethod=payMethod+num+"、"+consumePay.getName()+":"+consumePay.getActualTotal(); } }else { payMethod=payMethod+num+"、"+consumePay.getName()+":"+consumePay.getActualTotal()+ln; } } } if(couponOrderDiscountLog!=null && couponOrderDiscountLog.size()>0){ couponDisAmout=couponOrderDiscountLog.stream().collect(Collectors.summingDouble(o->o.getDiscountTotal().doubleValue())).toString(); // couponDisAmout=couponOrderDiscountLog.getDiscountTotal().toString(); } payMethod="实付:"+ln+String.format("1、储值金: %s "+ln+"2、增值金: %s "+ln+"3、优惠券抵扣: %s "+ln,storedValueFund,valueAddedFund,couponDisAmout).concat(payMethod); } if(ordersTotal!=null) { GzhTemplateVO gzhTemplateVO = new GzhTemplateVO(); UserUnionHis unionHis = getUserUnionHisByUserId(ordersTotal.getUserId()); if (unionHis ==null || StringUtils.isEmpty(unionHis.getOpenId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "该用户没有openId,用户标识:" + ordersTotal.getUserId()); } JSONObject object = new JSONObject(); JSONObject first = new JSONObject(); first.put("value", "您好,您的订单已付款成功,点击查看明细"); object.put("first", first); String status = OrderTotalConstants.STATUS_PAY == ordersTotal.getStatus() ? "已支付" : ""; JSONObject keyword1 = new JSONObject(); keyword1.put("value", ordersTotal.getOrderNo()); object.put("keyword1", keyword1); JSONObject keyword2 = new JSONObject(); keyword2.put("value", status); object.put("keyword2", keyword2); JSONObject keyword3 = new JSONObject(); keyword3.put("value", ordersTotal.getShouldTotal()); object.put("keyword3", keyword3); JSONObject keyword4 = new JSONObject(); keyword4.put("value", DateUtil.formatDate(ordersTotal.getCreateTime(),"yyyy-MM-dd HH:mm")); object.put("keyword4", keyword4); // remark 备注 JSONObject remark = new JSONObject(); remark.put("value", payMethod); object.put("remark", remark); //String url = String.format("/pages/Order_Description/order_payment?hisId=%s", ordersTotal.getId()); //2023-02-06 批量确定订单 String url = "/packages/order/orderConfirm"; gzhTemplateVO.setTouser(unionHis.getOpenId()); if(PlatformPattern.PROD.equals(customParameter.getPlatformPattern())){ gzhTemplateVO.setTemplateId("NWnxYJ_3gNV0OAxtmYWcf5cB12qFMUnLYmqoKFrkp4I"); // gzhTemplateVO.setTemplateId("5GqBNAWzbln7IlGR0I0SouA8IU8xVciy7w2iLt-zxBI"); }else{ gzhTemplateVO.setTemplateId("5GqBNAWzbln7IlGR0I0SouA8IU8xVciy7w2iLt-zxBI"); } gzhTemplateVO.setUrl(url); gzhTemplateVO.setType(1); gzhTemplateVO.setData(object.toJSONString()); logger.info("请求发送公众号通知方法-打印请求发送公众号通知参数:{}", JSONObject.toJSONString(gzhTemplateVO)); Result result = sGzhTemplateService.template(gzhTemplateVO); logger.info("请求发送公众号通知方法-返回数据:{}", JSONObject.toJSONString(result)); if (result != null) { result.checkTips(); } else { throw new TipsException("请求发送公众号通知方法,返回数据为空!"); } } }catch (Exception e){ logger.error("结账发送用户公众号消息失败",e.getMessage(),e); throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账发送用户公众号消息失败!"); } } @Override @Async public void sendUserConsultant(String userId,String orderNo,String orderId,JSONObject commissionObject, CommonService commonService) { OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,orderId); if(ordersTotal!=null){ try { SqlSentence sqlSentence = new SqlSentence(); Map map=new HashMap<>(); sqlSentence.setM(map); map.put("orderId",ordersTotal.getId()); map.put("isDel",BaseEntity.NO); sqlSentence.setSqlSentence("select * from orders_info where orderId=#{m.orderId} and isDel=#{m.isDel}"); OrderInfo orderInfo = commonService.selectOne(OrderInfoMapper.class, sqlSentence); if(orderInfo!=null && orderInfo.getIsOldBringNew()==null){ orderInfo.setIsOldBringNew(BaseEntity.NO); } User user=commonService.selectOneByKeyBlob(UserMapper.class,userId); if(user!=null && StringUtils.noNull(user.getHisCorpUserId())){ Employee employee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getHisCorpUserId()); if(employee!=null && StringUtils.noNull(employee.getUserId())){ // 企业微信员工标识有更新时推送企业微信消息 // 获取token String at = AppoitmentWeiXinCorpMpUtil.getApplicationAccessToken(customParameter.getCorpAppId(),customParameter.getCorpMpSecret(),commonService); if (at != null && orderInfo.getIsOldBringNew()==BaseEntity.YES) { BigDecimal newMoney=commissionObject.getBigDecimal("beInviterMoney")==null?BigDecimal.ZERO:commissionObject.getBigDecimal("beInviterMoney"); BigDecimal oldMoney=commissionObject.getBigDecimal("inviterMoney")==null?BigDecimal.ZERO:commissionObject.getBigDecimal("inviterMoney"); String oldUserName=StringUtils.isEmpty(commissionObject.getString("oldUserName"))?"":commissionObject.getString("oldUserName"); String newUserNmae=StringUtils.isEmpty(commissionObject.getString("newUserName"))?"":commissionObject.getString("newUserName"); String sendDate = MessageTemplate.sendIsOldUserConsultant(employee.getUserId(),orderNo, customParameter.getCorpMpAppId(), newMoney,oldMoney,oldUserName,newUserNmae); SendMessageTool.sendMessge(sendDate,at); }else if(at!=null){ String sendDate = MessageTemplate.sendUserConsultant(employee.getUserId(),orderNo, customParameter.getCorpMpAppId(), user.getName()); SendMessageTool.sendMessge(sendDate,at); } }else{ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"结账成功发送企业微信通知给用户所属顾问,员工找不到userId!"); } }else{ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"结账成功发送企业微信通知给用户所属顾问,用户找不到或者用户所属顾问为空!"); } }catch (Exception e){ logger.error("结账成功发送企业微信通知给用户所属顾问消息失败",e.getMessage(),e); throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账成功发送企业微信通知给用户所属顾问消息失败!"); } }else{ logger.error("结账成功发送企业微信通知给用户所属顾问消息失败,未找到总订单信息!订单标识:{}",orderId); throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账成功发送企业微信通知给用户所属顾问消息失败,未找到总订单信息!"); } } @Override public void newMarketingRejectAduit(String commonId, Integer commonType, String examEmplId, String examEmplName) { JbpmParamUtil.newMarketingRejectAduit(commonId,commonType,examEmplId,examEmplName,commonService); } @Override public void newMarketingSuccessAduit(String commonId, Integer commonType, String examEmplId, String examEmplName) { JbpmParamUtil.newMarketingSuccessAduit(commonId,commonType,examEmplId,examEmplName,commonService); } @Override public void statementPerformanceInfo(String orderId) { logger.info("进入保存报表"); //新增收录确认表 PerformanceInfoTool.handOrderPerformanceInfo(commonService,orderId ,BaseEntity.NO); } @Override public void statementConsultantCash(String orderId) { //记录咨询师现金业绩报表数据 ConsultantCashReportTool.handConsultantCash(commonService, orderId); } /** * 获取用户的openId * @param userId 用户id * @return 返回 */ private UserUnionHis getUserUnionHisByUserId(String userId){ SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("isDel", BaseEntity.NO); sqlValue.put("userId", userId); String sql = "SELECT openId from gzh_focus_record WHERE userId = #{m.userId} AND isDel = #{m.isDel} ORDER BY createTime DESC LIMIT 1"; sqlSentence.sqlSentence(sql, sqlValue); return commonService.selectOne(UserUnionHisMapper.class, sqlSentence); } }