zq-erp/src/main/java/com/matrix/ZqErpApplication.java
@@ -3,6 +3,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableAsync; /** * spring boot入口 @@ -11,6 +12,7 @@ */ @SpringBootApplication @ComponentScan(basePackages = {"com.matrix.**"}) @EnableAsync public class ZqErpApplication { public static void main(String[] args) { zq-erp/src/main/java/com/matrix/component/asyncmessage/AsyncMessageManager.java
New file @@ -0,0 +1,121 @@ /** * projectName: zq-erp * fileName: MessageManager.java * packageName: com.matrix.component.asyncmessage * date: 2021-10-18 14:01 * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved. */ package com.matrix.component.asyncmessage; import cn.hutool.core.collection.CollectionUtil; import com.matrix.core.tools.LogUtil; import com.matrix.core.tools.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * @version: V1.0 * @author: JiangYouYao * @className: AsyncMessageManager * @packageName: com.matrix.component.asyncmessage * @description: 异步消息管理者 * @data: 2021-10-18 14:01 **/ @Component @Order(Ordered.HIGHEST_PRECEDENCE) public class AsyncMessageManager implements ApplicationRunner { @Autowired private List<MessageHandler> obs; private Map<String, List<MessageHandler>> routes; private Map<String, ReentrantLock> lockMap = new HashMap<>(); private Map<String, ConcurrentLinkedQueue> messageQueue = new HashMap<>(); @Override public void run(ApplicationArguments args) throws Exception { if (CollectionUtil.isNotEmpty(obs)) { routes = obs.stream().collect(Collectors.groupingBy(MessageHandler::getRouteKey)); LogUtil.info("异步消息绑定成功,检测到{} 个消费者,共计{}组", obs.size(), routes.size()); } else { LogUtil.info("未检测到异步消息处理类"); } } /** * map 参数的字符串表示,方便快速拼装消息参数 * @param routeKey * @param mapStr */ public void sendMsg(String routeKey, String mapStr,Object... args){ if(StringUtils.isBlank(mapStr)){ throw new IllegalArgumentException("mapStr格式错误:例如:\\\"orderId=123,price=88\\\",mapStr="+mapStr); } mapStr=String.format(mapStr,args); Map<String, Object> param =new HashMap<>(); String[] paramStr = mapStr.split(","); Arrays.asList(paramStr).forEach(item->{ String[] keyValueArr = item.split("="); param.put(keyValueArr[0],keyValueArr[1]); }); sendMsg(routeKey,param); } /** * 根据route 发送消息到对应的消费者 * 这个方法本质上还是同步执行,没有完成效率上的异步解耦,这里做观察者模式主要是为了扩展业务,减少对第三方消息组件的依赖 * 而不是解决性能问题,如果后续需要解决性能问题,在加一个消息队列,然后启动线程从队列中进行消息的消费。 * @param routeKey * @param param */ public void sendMsg(String routeKey, Map<String, Object> param) { if(StringUtils.isBlank(routeKey)){ LogUtil.warn("发送异步消息失败:routeKey为空"); return; } //匹配观察者 List<MessageHandler> lisener = new ArrayList<>(); for (Map.Entry<String, List<MessageHandler>> routesEntry : routes.entrySet()) { if (Pattern.matches(routesEntry.getKey(), routeKey)) { lisener.addAll(routesEntry.getValue()); } } //通知观察者 if (CollectionUtil.isNotEmpty(lisener)) { LogUtil.info("发送异步消息,routeKey={},匹配观察者{}个",routeKey,lisener.size()); for (MessageHandler messageHandler : lisener) { try{ messageHandler.handle(param); }catch (Throwable t){ LogUtil.error("{},处理类执行异常:routeKey={},message={}", messageHandler.getName(),routeKey,t.getMessage()); } } }else{ LogUtil.warn("未匹配到routeKey={},的消费者",routeKey); } } } zq-erp/src/main/java/com/matrix/component/asyncmessage/MessageHandler.java
New file @@ -0,0 +1,40 @@ /** * projectName: zq-erp * fileName: MessageHandler.java * packageName: com.matrix.component.asyncmessage * date: 2021-10-18 13:59 * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved. */ package com.matrix.component.asyncmessage; import java.util.Map; /** * @version: V1.0 * @author: JiangYouYao * @className: MessageHandler * @packageName: com.matrix.component.asyncmessage * @description: 异步消息处理接口 * @data: 2021-10-18 13:59 **/ public interface MessageHandler { /** * 处理类的名字 * @return */ String getName(); /** * 返回任务的路由key * @return */ String getRouteKey(); /** * 实际任务处理方法 * @param param */ void handle(Map<String,Object> param); } zq-erp/src/main/java/com/matrix/component/asyncmessage/TestMessageHander.java
New file @@ -0,0 +1,46 @@ /** * projectName: zq-erp * fileName: TestMessageHander.java * packageName: com.matrix.component.asyncmessage * date: 2021-10-18 16:05 * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved. */ package com.matrix.component.asyncmessage; import com.matrix.core.tools.LogUtil; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.util.Map; /** * @version: V1.0 * @author: JiangYouYao * @className: TestMessageHander * @packageName: com.matrix.component.asyncmessage * @description: 测试观察者 * @data: 2021-10-18 16:05 **/ @Component public class TestMessageHander implements MessageHandler{ @Override public String getName() { return "测试观察者"; } @Override public String getRouteKey() { return "testkey"; } @Override public void handle(Map<String, Object> param) { try { Thread.sleep(1000*5); } catch (InterruptedException e) { e.printStackTrace(); } LogUtil.debug(param.toString()); } } zq-erp/src/main/java/com/matrix/component/asyncmessage/TestMessageHander2.java
New file @@ -0,0 +1,45 @@ /** * projectName: zq-erp * fileName: TestMessageHander.java * packageName: com.matrix.component.asyncmessage * date: 2021-10-18 16:05 * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved. */ package com.matrix.component.asyncmessage; import com.matrix.core.tools.LogUtil; import org.springframework.stereotype.Component; import java.util.Map; /** * @version: V1.0 * @author: JiangYouYao * @className: TestMessageHander * @packageName: com.matrix.component.asyncmessage * @description: 测试观察者 * @data: 2021-10-18 16:05 **/ @Component public class TestMessageHander2 implements MessageHandler{ @Override public String getName() { return "测试观察者"; } @Override public String getRouteKey() { return "55y"; } @Override public void handle(Map<String, Object> param) { try { Thread.sleep(1000*5); } catch (InterruptedException e) { e.printStackTrace(); } LogUtil.debug(param.toString()); } } zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
@@ -5,9 +5,11 @@ import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.rabbitmq.RabiitMqTemplateFactory; import com.matrix.core.tools.LogUtil; import com.matrix.system.shopXcx.mqTask.*; import com.matrix.system.shopXcx.mqTask.OrderOutSotoreTask; import com.matrix.system.shopXcx.mqTask.SalesOrderRefundTask; import com.matrix.system.shopXcx.mqTask.SalesOrderTask; import com.matrix.system.shopXcx.mqTask.TemplateMsgTask; import com.matrix.system.wechart.templateMsg.Task.UniformMsgSentTask; import com.rabbitmq.client.DeliverCallback; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -39,20 +41,10 @@ //订阅模式 public static final String MQ_EXCHANGE_TOPIC = "hive_exchange_fanout"; @Bean ScoreOrderTask ScoreOrderTask() { return new ScoreOrderTask(); } @Bean DeliverCallback OrderDingDingNoticeTask() { return new OrderDingDingNoticeTask(); } OrderTask OrderrCreateTask() { return new OrderTask(); } @Bean SalesOrderTask SalesOrderTask() { return new SalesOrderTask(); @@ -90,16 +82,7 @@ List<MqTask> taskList = new ArrayList<>(); //注册RabbitMq任务 taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_TEMPLATE_MSG + evn,MQTaskRouting.SEND_TEMPLATE_MSG + evn, TemplateMsgTask())); taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.ORDER_OUT_SOTORE + evn,MQTaskRouting.ORDER_OUT_SOTORE + evn, OrderOutSotoreTask())); taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn,MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, UniformMsgSentTask())); taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SHOP_ORDER_REFUND + evn,MQTaskRouting.SHOP_ORDER_REFUND + evn, SalesOrderRefundTask())); //不同任务在不同的队列,但是routingKey一样则可以收到生产者消息 taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.CREATE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,OrderrCreateTask())); taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.SALES_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,SalesOrderTask())); taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.SCORE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,ScoreOrderTask())); taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.DINGDING_NOTICE + evn,MQTaskRouting.CREATE_ORDER + evn, OrderDingDingNoticeTask())); rabiitMqTemplate.binding(taskList); zq-erp/src/main/java/com/matrix/core/exception/GlobleException.java
@@ -63,6 +63,10 @@ return message; } public static RuntimeException instance(String msg) { return new GlobleException(msg); } public String getErrorCode() { return errorCode; } zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
@@ -720,7 +720,7 @@ targetDate = calendar.getTime(); break; default: targetDate = stringToDate("9999-12-31", DATE_FORMAT_DD); targetDate = stringToDate("2099-12-31", DATE_FORMAT_DD); } zq-erp/src/main/java/com/matrix/system/app/action/ApiServiceOrderAction.java
@@ -1,5 +1,6 @@ package com.matrix.system.app.action; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; @@ -30,7 +31,7 @@ import com.matrix.system.hive.service.SysProjServicesService; import com.matrix.system.hive.service.SysProjUseService; import com.matrix.system.hive.service.SysVipInfoService; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -68,6 +69,9 @@ @Autowired private RabiitMqTemplate rabiitMqTemplate; @Autowired private AsyncMessageManager asyncMessageManager; @Value("${evn}") private String evn; @@ -289,7 +293,7 @@ services=projServicesService.findById(services.getId()); UniformMsgParam uniformMsgParam=new UniformMsgParam(services.getCompanyId(),UniformMsgParam.GZH_YYCG); uniformMsgParam.put("serviceId",services.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); return AjaxResult.buildSuccessInstance("确认成功"); } zq-erp/src/main/java/com/matrix/system/hive/action/MoneyCardUseController.java
@@ -1,6 +1,6 @@ package com.matrix.system.hive.action; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.AjaxResult; @@ -13,7 +13,7 @@ import com.matrix.system.hive.dao.MoneyCardUseFlowDao; import com.matrix.system.hive.pojo.CzXkVo; import com.matrix.system.hive.service.*; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -61,10 +61,9 @@ @Value("${evn}") private String evn; @Autowired private RabiitMqTemplate rabiitMqTemplate; private AsyncMessageManager asyncMessageManager; /** * 跳转 充值页面 * @@ -94,7 +93,7 @@ //发送微信公众号提醒 UniformMsgParam uniformMsgParam=new UniformMsgParam(order.getCompanyId(),UniformMsgParam.GZH_CZCG); uniformMsgParam.put("orderId",order.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); result.putInMap("orderId",order.getId()); return result; zq-erp/src/main/java/com/matrix/system/hive/action/OrderController.java
@@ -1,6 +1,7 @@ package com.matrix.system.hive.action; import cn.hutool.core.collection.CollUtil; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; @@ -24,7 +25,7 @@ import com.matrix.system.hive.dao.*; import com.matrix.system.hive.plugin.util.CollectionUtils; import com.matrix.system.hive.service.*; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -104,6 +105,9 @@ @Autowired private SysProjServicesDao sysProjServicesDao; @Autowired private AsyncMessageManager asyncMessageManager; @Value("${evn}") private String evn; @@ -149,7 +153,7 @@ //发送微信公众号提醒 UniformMsgParam uniformMsgParam = new UniformMsgParam(user.getCompanyId(), UniformMsgParam.GZH_GMCG); uniformMsgParam.put("orderId", sysOrder.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); //处理用户购买的产品 zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
@@ -128,7 +128,7 @@ private void setShoppingGoodsInvalidTime(ShoppingGoods shoppingGoods) { // 若未设置购买有效期和消耗有效期,则默认永久有效 // if (shoppingGoods.getBuyDateNum() == null && shoppingGoods.getUseDateNum() == null) { // shoppingGoods.setInvalidTime(DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD)); // shoppingGoods.setInvalidTime(DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD)); // } else { // // 计算失效日期,判断购买有效期和消耗有效期哪个先失效,则为失效日期 // Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); @@ -435,11 +435,11 @@ @Override public Date calInvalidTime(ShoppingGoods shoppingGoods, @NotNull Integer type, Date buyDate) { if (StringUtils.isBlank(shoppingGoods.getBuyValid()) && StringUtils.isBlank(shoppingGoods.getUseValid()) && shoppingGoods.getInvalidTime() == null) { return DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD); return DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); } if (type == 2 && shoppingGoods.getUseDateNum() == null && StringUtils.isNotBlank(shoppingGoods.getBuyDateUnit())) { return DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD); return DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); } if (type == 2 && buyDate == null) { @@ -454,7 +454,7 @@ buyValidDate = buyDate; } Date useValidDate = DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD); Date useValidDate = DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); if (type == 2) { useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); } zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
@@ -1,6 +1,7 @@ package com.matrix.system.hive.service.imp; import com.matrix.component.rabbitmq.RabiitMqTemplate; import cn.hutool.core.collection.CollectionUtil; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.PaginationVO; @@ -31,7 +32,7 @@ import com.matrix.system.score.constant.ScoreSettingConstant; import com.matrix.system.score.entity.ScoreVipDetail; import com.matrix.system.score.service.ScoreVipDetailService; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -42,9 +43,8 @@ import javax.servlet.http.HttpSession; import javax.validation.constraints.NotEmpty; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.*; import java.util.stream.Collectors; /** * @date 2016-07-03 20:53 @@ -124,11 +124,8 @@ @Autowired BusParameterSettingsDao parameterSettingsDao; @Value("${evn}") private String evn; @Autowired private RabiitMqTemplate rabiitMqTemplate; private AsyncMessageManager asyncMessageManager; @Override @@ -264,6 +261,7 @@ /** * 取消订单 * * @param id * @return */ @@ -280,7 +278,7 @@ //发送微信公众号提醒 UniformMsgParam uniformMsgParam = new UniformMsgParam(order.getCompanyId(), UniformMsgParam.GZH_DDQX); uniformMsgParam.put("orderId", order.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); return sysOrderDao.update(order); @@ -469,7 +467,6 @@ } /** * jyy 收款 */ @@ -481,8 +478,8 @@ throw new GlobleException("该订单已经收过款,请刷新页面再试!"); } //检查交易限制调整 checkSealLimit(pageOrder); checkOrder(pageOrder); // 更新收款时间 @@ -520,17 +517,55 @@ } private void checkOrder(SysOrder pageOrder) { //检查交易限制调整 checkSealLimit(pageOrder); //检查业绩设置 checkOrderAchieve(pageOrder); } /** * 检查业绩设置是否合理 * 1、每个订单明细都要有至少一个对应的业绩 * 2、每个订单明细的同类型业绩金额之和不能大于明细支付金额 * * @param pageOrder */ private void checkOrderAchieve(SysOrder pageOrder) { pageOrder.getItems().forEach(item -> { if (CollectionUtil.isEmpty(item.getAchieveList())) { ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); throw GlobleException.instance(shopGoods.getName() + "缺少设置业绩"); } //按业绩类型分组后比较支付金额与业绩金额是否相等 Map<String, List<AchieveNew>> achieveTypeMap = item.getAchieveList().stream().collect(Collectors.groupingBy(AchieveNew::getAchieveType)); Set<Map.Entry<String, List<AchieveNew>>> entries = achieveTypeMap.entrySet(); entries.forEach(entrie -> { double sum = entrie.getValue().stream().mapToDouble(AchieveNew::getGoodsCash).sum(); //todo 目前使用js计算金额可能存在精度的误差展示用0.1屏蔽 if (Math.abs(sum- (item.getZkPrice()*item.getCount()) )>0.1) { ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); throw GlobleException.instance(shopGoods.getName() + "," + entrie.getKey() + "业绩金额与收款金额不一致"); } }); }); } /** * 检查产品销售次数 */ private void checkSealLimit(SysOrder pageOrder) { pageOrder.getItems().forEach(item->{ pageOrder.getItems().forEach(item -> { ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); //最大销售次数检测 Integer maxNum = shopGoods.getCarMaxSaleCount(); if (maxNum != null && maxNum != 0) { Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null); Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(), null); if ((buyNum + item.getCount()) > maxNum) { throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); } @@ -543,11 +578,11 @@ } //每人限购次数检测 Integer onceCount = shopGoods.getIsOnce(); if(onceCount!=null && onceCount!=0){ Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(),pageOrder.getVipId()); if (onceCount != null && onceCount != 0) { Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(), pageOrder.getVipId()); if ((buyOnceCount + item.getCount()) > onceCount) { throw new GlobleException(shopGoods.getName() + "每人限购"+onceCount+"次"); throw new GlobleException(shopGoods.getName() + "每人限购" + onceCount + "次"); } } @@ -556,116 +591,116 @@ } /** * 设置会员消费积分 * * @param pageOrder */ private void addVipScore(SysOrder pageOrder) { SysVipInfo vipInfo=sysVipInfoDao.selectById(pageOrder.getVipId()); SysVipInfo vipInfo = sysVipInfoDao.selectById(pageOrder.getVipId()); List<SysOrderFlow> flows = pageOrder.getFlows(); int [] cashScore={0,0,0}; int[] cashScore = {0, 0, 0}; //现金支付金额 BigDecimal cashPayAmount=flows.stream() .filter(item->(!item.getPayMethod().equals("储值卡"))&&(!item.getPayMethod().equals("欠款"))) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal cashPayAmount = flows.stream() .filter(item -> (!item.getPayMethod().equals("储值卡")) && (!item.getPayMethod().equals("欠款"))) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BusParameterSettings cashConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.CASH_CONSUMPTION, vipInfo.getCompanyId()); if(cashPayAmount!=null &&cashPayAmount.compareTo(BigDecimal.ZERO)>0 &&StringUtils.isNotBlank(cashConsumption.getParamValue())){ if (cashPayAmount != null && cashPayAmount.compareTo(BigDecimal.ZERO) > 0 && StringUtils.isNotBlank(cashConsumption.getParamValue())) { BigDecimal scoreSetting0 = new BigDecimal(cashConsumption.getParamValue()); if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { cashScore[0] = cashPayAmount.divide(scoreSetting0).intValue(); } if(StringUtils.isNotBlank(cashConsumption.getParamValue1())){ if (StringUtils.isNotBlank(cashConsumption.getParamValue1())) { BigDecimal scoreSetting1 = new BigDecimal(cashConsumption.getParamValue1()); if(scoreSetting1.compareTo(BigDecimal.ZERO)>0){ cashScore[1]= cashPayAmount.divide(scoreSetting1).intValue(); if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { cashScore[1] = cashPayAmount.divide(scoreSetting1).intValue(); } } if(StringUtils.isNotBlank(cashConsumption.getParamValue2())){ if (StringUtils.isNotBlank(cashConsumption.getParamValue2())) { BigDecimal scoreSetting2 = new BigDecimal(cashConsumption.getParamValue2()); if(scoreSetting2.compareTo(BigDecimal.ZERO)>0){ cashScore[2]= cashPayAmount.divide(scoreSetting2).intValue(); if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { cashScore[2] = cashPayAmount.divide(scoreSetting2).intValue(); } } } int [] cardScore={0,0,0}; int[] cardScore = {0, 0, 0}; //储值卡本金支付金额 BigDecimal cardPayAmount=flows.stream() .filter(item->item.getPayMethod().equals("储值卡")&&item.getIsGift().equals("N")) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal cardPayAmount = flows.stream() .filter(item -> item.getPayMethod().equals("储值卡") && item.getIsGift().equals("N")) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BusParameterSettings principalBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); if(cardPayAmount!=null &&cardPayAmount.compareTo(BigDecimal.ZERO)>0 &&StringUtils.isNotBlank(principalBalanceConsumption.getParamValue())){ if (cardPayAmount != null && cardPayAmount.compareTo(BigDecimal.ZERO) > 0 && StringUtils.isNotBlank(principalBalanceConsumption.getParamValue())) { BigDecimal scoreSetting0 = new BigDecimal(principalBalanceConsumption.getParamValue()); if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { cardScore[0] = cardPayAmount.divide(scoreSetting0).intValue(); } if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue1())){ if (StringUtils.isNotBlank(principalBalanceConsumption.getParamValue1())) { BigDecimal scoreSetting1 = new BigDecimal(principalBalanceConsumption.getParamValue1()); if(scoreSetting1.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { cardScore[1] = cardPayAmount.divide(scoreSetting1).intValue(); } } if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue2())){ if (StringUtils.isNotBlank(principalBalanceConsumption.getParamValue2())) { BigDecimal scoreSetting2 = new BigDecimal(principalBalanceConsumption.getParamValue2()); if(scoreSetting2.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { cardScore[2] = cardPayAmount.divide(scoreSetting2).intValue(); } } } int [] giftScore={0,0,0}; int[] giftScore = {0, 0, 0}; //储值卡本赠送付金额 BigDecimal giftPayAmount=flows.stream() .filter(item->item.getPayMethod().equals("储值卡")&&item.getIsGift().equals("Y")) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); BigDecimal giftPayAmount = flows.stream() .filter(item -> item.getPayMethod().equals("储值卡") && item.getIsGift().equals("Y")) .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BusParameterSettings bonusBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); if(giftPayAmount!=null &&giftPayAmount.compareTo(BigDecimal.ZERO)>0 &&StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue())){ if (giftPayAmount != null && giftPayAmount.compareTo(BigDecimal.ZERO) > 0 && StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue())) { BigDecimal scoreSetting0 = new BigDecimal(bonusBalanceConsumption.getParamValue()); if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { giftScore[0] = giftPayAmount.divide(scoreSetting0).intValue(); } if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue1())){ if (StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue1())) { BigDecimal scoreSetting1 = new BigDecimal(bonusBalanceConsumption.getParamValue1()); if(scoreSetting1.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { giftScore[1] = giftPayAmount.divide(scoreSetting1).intValue(); } } if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue2())){ if (StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue2())) { BigDecimal scoreSetting2 = new BigDecimal(bonusBalanceConsumption.getParamValue2()); if(scoreSetting2.compareTo(BigDecimal.ZERO)>0) { if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { giftScore[2] = giftPayAmount.divide(scoreSetting2).intValue(); } } } int selfScore=cashScore[0]+cardScore[0]+giftScore[0]; int parentScore=cashScore[1]+cardScore[1]+giftScore[1]; int topParentScore=cashScore[2]+cardScore[2]+giftScore[2]; int selfScore = cashScore[0] + cardScore[0] + giftScore[0]; int parentScore = cashScore[1] + cardScore[1] + giftScore[1]; int topParentScore = cashScore[2] + cardScore[2] + giftScore[2]; //添加自己的积分 if(selfScore>0){ if (selfScore > 0) { scoreVipDetailService.addScore( vipInfo.getId(), pageOrder.getStaffId(), @@ -677,10 +712,10 @@ ); } if(vipInfo.getRecommendId()!=null){ if (vipInfo.getRecommendId() != null) { //推荐注册老带新积分奖励 SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId()); if(parentScore>0){ if (parentScore > 0) { scoreVipDetailService.addScore( referrerVip.getId(), pageOrder.getStaffId(), @@ -692,9 +727,9 @@ ); } //推荐注册二级带新积分奖励 if(referrerVip.getRecommendId()!=null){ if (referrerVip.getRecommendId() != null) { SysVipInfo topVipInfo = sysVipInfoDao.selectById(referrerVip.getRecommendId()); if(topParentScore>0){ if (topParentScore > 0) { scoreVipDetailService.addScore( topVipInfo.getId(), pageOrder.getStaffId(), @@ -725,7 +760,7 @@ ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); // 若是退款,则取负数 if (SysOrder.ORDER_TYPE_REFUND== sourceOrder.getOrderType()) { if (SysOrder.ORDER_TYPE_REFUND == sourceOrder.getOrderType()) { flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); flow.setAmount(flow.getAmount().negate()); flow.setOrderId(sourceOrder.getOldOrderId()); @@ -747,7 +782,7 @@ MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); //修改储值卡余额 cardPaySk(moneyCardUse, sourceOrder, flow); }else{ } else { throw new GlobleException("无效的储值卡支付方式"); } } @@ -759,7 +794,6 @@ sysOrderFlowDao.insert(flow); flowCount++; } } @@ -777,7 +811,7 @@ // 最大发卡数量为0代表不做限制 if (maxNum != null && maxNum != 0) { // 查询该商品已经被购买的次数 Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null); Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(), null); buyNum = (buyNum == null ? 0 : buyNum); if ((buyNum + carItem.getCount()) > maxNum) { throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); @@ -1026,11 +1060,10 @@ } sourceOrder.setArrears(sourceOrder.getArrears() - refundTotal); sourceOrder.setCardPay(sourceOrder.getCardPay()==null?0:sourceOrder.getCardPay() + cardPayTotal); sourceOrder.setCashPay(sourceOrder.getCashPay()==null?0:sourceOrder.getCashPay() + cashPayTotal); sourceOrder.setCardPay(sourceOrder.getCardPay() == null ? 0 : sourceOrder.getCardPay() + cardPayTotal); sourceOrder.setCashPay(sourceOrder.getCashPay() == null ? 0 : sourceOrder.getCashPay() + cashPayTotal); sysOrderDao.update(sourceOrder); } /** @@ -1042,7 +1075,7 @@ public void addOutStore(SysOrder order) { BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, order.getCompanyId()); if(AppConstance.IS_Y.equals(manageStockSetting.getParamValue())){ if (AppConstance.IS_Y.equals(manageStockSetting.getParamValue())) { List<SysOutStoreItem> storeItemList = new ArrayList<>(); @@ -1143,7 +1176,7 @@ sysOutStoreItemDao.batchInsert(realOutStoreItemList); } }else{ } else { LogUtil.debug("不管理库存"); } @@ -1188,7 +1221,7 @@ List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM); assembleList.forEach(item -> { //TODO 补综合卡逻辑 createProjuseByAssemble(order, sysOrderItem, item, null, null,null,0); createProjuseByAssemble(order, sysOrderItem, item, null, null, null, 0); }); //处理综合卡中包含的套餐 @@ -1209,7 +1242,7 @@ * 通过组合关系创建用户项目余次 */ private SysProjUse createProjuseByAssemble(SysOrder order, SysOrderItem sysOrderItem, ShoppingGoodsAssemble goodsAssemble, Long taocanId, Date failTime,String source,Integer maxCount) { ShoppingGoodsAssemble goodsAssemble, Long taocanId, Date failTime, String source, Integer maxCount) { //计算折扣 Double zk = sysOrderItem.getZkPrice() / sysOrderItem.getPrice(); @@ -1217,7 +1250,7 @@ puse.setIsOver(Dictionary.DELETED_N); puse.setOrderItemId(sysOrderItem.getId()); puse.setProjId(goodsAssemble.getAssembleGoodId()); puse.setSurplusCount(goodsAssemble.getTotal()==null?maxCount: goodsAssemble.getTotal()); puse.setSurplusCount(goodsAssemble.getTotal() == null ? maxCount : goodsAssemble.getTotal()); puse.setDeductionNum(goodsAssemble.getDeductionNum()); puse.setProjName(goodsAssemble.getShoppingGoods().getName()); puse.setVipId(order.getVipId()); @@ -1235,16 +1268,16 @@ //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗 boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); if(zsConsumeAchieve){ if(sysOrderItem.getPrice()<=0){ if (zsConsumeAchieve) { if (sysOrderItem.getPrice() <= 0) { //等于0取原价 if (taocanId == null) { puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() ); puse.setPrice(goodsAssemble.getShoppingGoods().getPrice()); } else { puse.setPrice(goodsAssemble.getPrice()); } } }else{ } else { puse.setPrice(0D); } @@ -1297,7 +1330,7 @@ //创建套餐绑定的项目 List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(projId, ShoppingGoods.SHOPPING_GOODS_TYPE_XM); for (ShoppingGoodsAssemble assemble : assembleList) { SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId(),taocanProjUse.getFailTime(),taocanProjUse.getSource(),taocanShoppingGoods.getCarUseCount()); SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId(), taocanProjUse.getFailTime(), taocanProjUse.getSource(), taocanShoppingGoods.getCarUseCount()); sumBanance += tempUse.getBalance(); surplusCount += tempUse.getSurplusCount(); } @@ -1346,9 +1379,9 @@ puse.setSource(Dictionary.TAOCAN_SOURCE_ZS); //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗 boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); if(zsConsumeAchieve){ if (zsConsumeAchieve) { puse.setPrice(sysOrderItem.getShoppingGoods().getSealPice()); }else{ } else { puse.setPrice(0D); } @@ -1357,21 +1390,22 @@ // 设置失效时间 Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null); puse.setFailTime(invalidTime); puse.setBalance(sysOrderItem.getShoppingGoods().getSealPice()*puse.getSurplusCount()); puse.setBalance(sysOrderItem.getShoppingGoods().getSealPice() * puse.getSurplusCount()); sysProjUseDao.insert(puse); } /** * 全是赠送金额,且配置了赠送金额购买计算为赠送 * * @param order * @return */ private boolean isGiftMoneyPay(SysOrder order) { BusParameterSettings giftiIsfree = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.SHOP_MANAGE_GIFTISFREE, order.getCompanyId()); if(giftiIsfree.getParamValue().equals("是")){ return order.getFlows().stream().allMatch(item -> SysOrderFlow.IS_GIFT_Y.equals(item.getIsGift()) && item.getAmount().doubleValue() >0D); }else{ if (giftiIsfree.getParamValue().equals("是")) { return order.getFlows().stream().allMatch(item -> SysOrderFlow.IS_GIFT_Y.equals(item.getIsGift()) && item.getAmount().doubleValue() > 0D); } else { return false; } @@ -1522,12 +1556,12 @@ SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); //原订单设置为退款状态 SysOrder sourceOrder=new SysOrder(); SysOrder sourceOrder = new SysOrder(); sourceOrder.setId(sysOrder.getOldOrderId()); sourceOrder.setIsHasRefund(SysOrder.IS_HAS_REFUND_Y); // sourceOrder.setStatu(Dictionary.ORDER_STATU_TK); sysOrderDao.update(sourceOrder); SysOrder oldOrder=sysOrderDao.selectById(sysOrder.getOldOrderId()); SysOrder oldOrder = sysOrderDao.selectById(sysOrder.getOldOrderId()); sysOrder.setId(null); sysOrder.setStaffId(user.getSuId()); @@ -1546,7 +1580,7 @@ for (SysOrderItem item : sysOrder.getItems()) { //更新原订单明细的可退数量 SysOrderItem oldItem=new SysOrderItem(); SysOrderItem oldItem = new SysOrderItem(); oldItem.setId(item.getId()); oldItem.setRefundCount(item.getCount()); orderItemDao.update(oldItem); @@ -1590,7 +1624,7 @@ MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); //修改储值卡余额 cardPaySk(moneyCardUse, sourceOrder, flow); }else{ } else { throw new GlobleException("无效的储值卡支付方式"); } } @@ -1655,6 +1689,7 @@ /** * 退款退项目,套餐,卡项 * * @param sysOrder */ private void refundProjUse(SysOrder sysOrder) { @@ -1680,7 +1715,7 @@ int sub = sysProjUse.getSurplusCount() - item.getCount(); if (sub < 0) { throw new GlobleException("项目余次不足"); }else if(sub==0){ } else if (sub == 0) { sysProjUse.setIsOver(Dictionary.FLAG_YES_Y); sysProjUse.setStatus(Dictionary.TAOCAN_STATUS_WX); } @@ -1741,7 +1776,7 @@ } BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, sysOrder.getCompanyId()); if(AppConstance.IS_Y.equals(manageStockSetting.getParamValue())){ if (AppConstance.IS_Y.equals(manageStockSetting.getParamValue())) { // 家居产品退库存 if (CollectionUtils.isNotEmpty(returnGoodsList)) { refundInstore(returnGoodsList); zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
@@ -1,7 +1,7 @@ package com.matrix.system.hive.service.imp; import cn.hutool.core.collection.CollUtil; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.PaginationVO; @@ -25,12 +25,11 @@ import com.matrix.system.score.constant.ScoreSettingConstant; import com.matrix.system.score.entity.ScoreVipDetail; import com.matrix.system.score.service.ScoreVipDetailService; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -112,7 +111,7 @@ private ShoppingGoodsService shoppingGoodsService; @Autowired private RabiitMqTemplate rabiitMqTemplate; private AsyncMessageManager asyncMessageManager; @Autowired @@ -124,8 +123,6 @@ @Autowired SysVipInfoDao sysVipInfoDao; @Value("${evn}") private String evn; /** @@ -659,8 +656,7 @@ //发送微信公众号提醒 UniformMsgParam uniformMsgParam = new UniformMsgParam(projServices.getCompanyId(), UniformMsgParam.GZH_FWWC); uniformMsgParam.put("serviceId", projServices.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); return result; } zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjUseServiceImpl.java
@@ -220,9 +220,11 @@ freeze.setOrderItemId(taocan.getId().toString()); freeze.setVipId(taocan.getVipId()); SysProjuseFreeze freezeProj = sysProjuseFreezeDao.selectByOrderItemId(freeze); Date dateAfter = DateUtil.nextNDate(taocan.getFailTime(), freezeProj.getGapDays()); taocan.setFailTime(dateAfter); // todo 因为目前没有在冻结的时候插入冻结记录,所以这里暂时这样处理 if(freezeProj!=null){ Date dateAfter = DateUtil.nextNDate(taocan.getFailTime(), freezeProj.getGapDays()); taocan.setFailTime(dateAfter); } break; default: return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择无效或者冻结的套餐"); zq-erp/src/main/java/com/matrix/system/job/ServiceOvertimeNoticeJob.java
@@ -1,11 +1,12 @@ package com.matrix.system.job; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.core.tools.LogUtil; import com.matrix.system.hive.bean.SysProjServices; import com.matrix.system.hive.dao.SysProjServicesDao; import com.matrix.system.hive.plugin.util.CollectionUtils; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -31,6 +32,8 @@ @Autowired private RabiitMqTemplate rabiitMqTemplate; @Autowired private AsyncMessageManager asyncMessageManager; /** * 每分钟执行一次 */ @@ -44,7 +47,7 @@ //发送微信公众号提醒 UniformMsgParam uniformMsgParam=new UniformMsgParam(projServices.getCompanyId(),UniformMsgParam.GZH_YYDS); uniformMsgParam.put("serviceId",projServices.getId()); rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); } List<Long> noticedIds = needNoticeService.stream().map(SysProjServices::getId).collect(Collectors.toList()); projServicesDao.updateNoticeTimes(noticedIds); zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopDeliveryInfoAction.java
@@ -1,5 +1,6 @@ package com.matrix.system.shopXcx.action; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.core.anotations.RemoveRequestToken; import com.matrix.core.anotations.SaveRequestToken; @@ -24,7 +25,7 @@ import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; import com.matrix.system.shopXcx.dao.ShopLogisticsInfoDao; import com.matrix.system.shopXcx.dao.ShopOrderDao; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -59,6 +60,8 @@ @Autowired SystemDictionaryDao systemDictionaryDao; @Autowired private AsyncMessageManager asyncMessageManager; @Autowired private WxShopOrderUtil wxShopOrderUtil; @@ -170,8 +173,8 @@ shopOrderDao.updateByMap(modifyMap); //发送创建订单的消息 rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, shopOrderDao.selectById(deliveryInfo.getOrderId()).getOrderNo()); String orderNo = shopOrderDao.selectById(deliveryInfo.getOrderId()).getOrderNo(); asyncMessageManager.sendMsg(AsyncMessageRouting.ORDER_OUT_SOTORE ,"orderNo=%s",orderNo); return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); } zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopOrderAction.java
@@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.google.gson.Gson; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.core.anotations.RemoveRequestToken; import com.matrix.core.anotations.SaveRequestToken; import com.matrix.core.constance.MatrixConstance; @@ -28,13 +28,12 @@ import com.matrix.system.shopXcx.bean.*; import com.matrix.system.shopXcx.dao.*; import com.matrix.system.shopXcx.dto.DiscountExplain; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.shopXcx.pojo.ShopOrderQueryPOJO; import com.matrix.system.shopXcx.shopEnum.OrderStatusEnum; import com.matrix.system.shopXcx.vo.LogisticsImportVo; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestMapping; @@ -75,17 +74,15 @@ private SysShopInfoDao sysShopInfoDao; @Autowired private SysVipInfoService vipInfoService; @Autowired private RabiitMqTemplate rabiitMqTemplate; //记录编辑前的值Before_Edit_Value public static final String BEV = "ShopOrder_BEV"; public static final List<LogisticsImportVo> logisticsImportVoLists = new ArrayList<>(); @Autowired private AsyncMessageManager asyncMessageManager; @Value("${evn}") private String evn; /** * 导入快递单 */ @@ -228,7 +225,8 @@ shopOrderDao.updateByMap(modifyMap); //发送创建订单的消息 rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, orderNo); asyncMessageManager.sendMsg(AsyncMessageRouting.ORDER_OUT_SOTORE ,"orderNo=%s"); } }else{ if(ObjectUtil.isEmpty(shopOrder)){ zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopRefundRecordAction.java
@@ -1,5 +1,6 @@ package com.matrix.system.shopXcx.action; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.redis.RedisUserLoginUtils; import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; @@ -26,7 +27,7 @@ import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; import com.matrix.system.shopXcx.dao.ShopOrderDao; import com.matrix.system.shopXcx.dao.ShopRefundRecordDao; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -64,7 +65,8 @@ private ShopDeliveryInfoDao shopDeliveryInfoDao; @Autowired private RedisUserLoginUtils redisUserLoginUtils; @Autowired private AsyncMessageManager asyncMessageManager; @Autowired private ShopCouponRecordDao shopCouponRecordDao; @@ -528,11 +530,7 @@ modifyMap.put("refundCharge", shopRefundRecord.getRefundMoney()); shopOrderDao.updateByMap(modifyMap); rabiitMqTemplate.sendMsg(MQTaskRouting.SHOP_ORDER_REFUND+evn,shopRefundRecord.getOrderId()+""); asyncMessageManager.sendMsg(AsyncMessageRouting.SHOP_ORDER_REFUND ,"orderId=%s", shopRefundRecord.getOrderId()); }catch (Exception e){ LogUtil.debug("退款成功,修改退款表和订单表状态出错。。。", id); zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WXShopOrderAction.java
@@ -1,9 +1,8 @@ package com.matrix.system.shopXcx.api.action; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.redis.RedisUserLoginUtils; import com.matrix.component.wechat.externalInterface.protocol.paramProtocol.BrandWCPayRequestData; import com.matrix.config.RabbitMqConfig; import com.matrix.core.constance.SystemErrorCode; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.AjaxResult; @@ -28,7 +27,7 @@ import com.matrix.system.shopXcx.bean.ShopOrder; import com.matrix.system.shopXcx.bean.ShopPayLog; import com.matrix.system.shopXcx.dao.*; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; @@ -91,7 +90,7 @@ private ShopActivitiesGroupJoinDao shopActivitiesGroupJoinDao; @Autowired private RabiitMqTemplate rabiitMqTemplate; private AsyncMessageManager asyncMessageManager; @Autowired ShoppingGoodsDao shoppingGoodsDao; @@ -224,7 +223,8 @@ } // 根据订单类型创建不同的处理任务 rabiitMqTemplate.sendTopicMsg(RabbitMqConfig.MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.CREATE_ORDER + evn, orderId + ""); asyncMessageManager.sendMsg(AsyncMessageRouting.CREATE_ORDER ,"orderId=%s",orderId); //支付记录 recordPayLog(Integer.valueOf(orderId), 1, order.getOrderNo(), order.getOrderMoney(), "会员卡余额支付成功", ShopOrder.ORDER_PAY_STATUS_SUCCESS); zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java
@@ -1,10 +1,10 @@ package com.matrix.system.shopXcx.api.action; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.wechat.externalInterface.common.Signature; import com.matrix.component.wechat.externalInterface.common.Util; import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.NotifyData; import com.matrix.config.RabbitMqConfig; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.LogUtil; import com.matrix.system.common.bean.BusParameterSettings; @@ -25,7 +25,7 @@ import com.matrix.system.shopXcx.dao.ShopActivitiesGroupJoinUserDao; import com.matrix.system.shopXcx.dao.ShopOrderDao; import com.matrix.system.shopXcx.dao.ShopPayLogDao; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -87,6 +87,8 @@ @Autowired ScoreVipDetailService scoreVipDetailService; @Autowired AsyncMessageManager asyncMessageManager; @Value("${evn}") @@ -196,8 +198,7 @@ } // 根据订单类型创建不同的处理任务 rabiitMqTemplate.sendTopicMsg(RabbitMqConfig.MQ_EXCHANGE_TOPIC +evn, MQTaskRouting.CREATE_ORDER+evn, orderId); asyncMessageManager.sendMsg(AsyncMessageRouting.CREATE_ORDER,"orderId=%s",orderId); threadResult.putInMap("status", "success"); zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopRefundRecordServiceImpl.java
@@ -1,6 +1,6 @@ package com.matrix.system.shopXcx.api.service.impl; import com.matrix.component.rabbitmq.RabiitMqTemplate; import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; import com.matrix.core.exception.GlobleException; import com.matrix.core.tools.DingDingRobotUtil; @@ -13,7 +13,7 @@ import com.matrix.system.shopXcx.api.service.WxShopRefundRecordService; import com.matrix.system.shopXcx.bean.*; import com.matrix.system.shopXcx.dao.*; import com.matrix.system.shopXcx.mqTask.MQTaskRouting; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -52,14 +52,12 @@ @Autowired private BusParameterSettingsDao busParameterSettingsDao; @Autowired private AsyncMessageManager asyncMessageManager; @Value("${wx_pay_debug_onoff}") private boolean isDebug; @Value("${evn}") private String evn; @Autowired private RabiitMqTemplate rabiitMqTemplate; @Override @@ -148,7 +146,8 @@ modifyMap.put("refundCharge", shopRefundRecord.getRefundMoney()); shopOrderDao.updateByMap(modifyMap); rabiitMqTemplate.sendMsg(MQTaskRouting.SHOP_ORDER_REFUND+evn,shopRefundRecord.getOrderId()+""); asyncMessageManager.sendMsg(AsyncMessageRouting.SHOP_ORDER_REFUND ,"orderId=%s" , shopRefundRecord.getOrderId()); //发送退款通知 BusParameterSettings wxOrderNoticeDingdingToken = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WX_ORDER_NOTICE_DINGDING_TOKEN, shopOrder.getCompanyId()); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/AsyncMessageRouting.java
New file @@ -0,0 +1,32 @@ package com.matrix.system.shopXcx.mqTask; /** * 异步任务名称 */ public interface AsyncMessageRouting { String CREATE_VIP = "CREATE_VIP"; String CREATE_ORDER = "CREATE_ORDER"; String SALES_ORDER = "SALES_ORDER"; String SCORE_ORDER = "SCORE_ORDER"; String DINGDING_NOTICE = "DINGDING_NOTICE" ; /** * 发送微信消息 */ String SEND_TEMPLATE_MSG = "SEND_TEMPLATE_MSG"; /** * 发送小程序统一模板消息 */ String SEND_UNIFORM_TEMPLATE_MSG = "SEND_UNIFORM_TEMPLATE_MSG"; /** * 订单退款 */ String SHOP_ORDER_REFUND = "SHOP_ORDER_REFUND"; /** * 订单出库 */ String ORDER_OUT_SOTORE = "ORDER_OUT_SOTORE"; } zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderDingDingNoticeTask.java
@@ -1,6 +1,7 @@ package com.matrix.system.shopXcx.mqTask; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.tools.DingDingRobotUtil; import com.matrix.core.tools.LogUtil; import com.matrix.core.tools.StringUtils; @@ -21,12 +22,13 @@ import java.io.IOException; import java.util.List; import java.util.Map; /** * 微商城订单同步到erp系统 */ @Component public class OrderDingDingNoticeTask implements DeliverCallback { public class OrderDingDingNoticeTask implements MessageHandler { @Autowired @@ -46,8 +48,19 @@ ShopDeliveryInfoDao shopDeliveryInfoDao; @Override public void handle(String consumerTag, Delivery message) throws IOException { String orderIdStr = new String(message.getBody(), "UTF-8"); public String getName() { return "创建订单通知任务"; } @Override public String getRouteKey() { return AsyncMessageRouting.CREATE_ORDER; } @Override public void handle(Map<String,Object> param){ String orderIdStr = (String) param.get("orderId"); Integer orderId=Integer.valueOf(orderIdStr); //获取订单信息 ShopOrder order = shopOrderDao.selectById(orderId); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderOutSotoreTask.java
@@ -1,6 +1,7 @@ package com.matrix.system.shopXcx.mqTask; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.tools.LogUtil; import com.matrix.system.hive.bean.SysOrder; import com.matrix.system.hive.dao.SysOrderDao; @@ -12,11 +13,12 @@ import java.io.IOException; import java.util.List; import java.util.Map; /** * 微商城发货后erp出库 */ public class OrderOutSotoreTask implements DeliverCallback { public class OrderOutSotoreTask implements MessageHandler { @Autowired SysOrderDao sysOrderDao; @@ -25,9 +27,19 @@ SysOrderService orderService; @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getName() { return "微商城发货后erp出库"; } String orderNo = new String(message.getBody(), "UTF-8"); @Override public String getRouteKey() { return AsyncMessageRouting.ORDER_OUT_SOTORE; } @Override public void handle(Map<String,Object> param){ String orderNo = (String) param.get("orderNo"); LogUtil.debug("收到出库订单orderNo={}", orderNo); //获取订单信息 SysOrder sourceOrder = new SysOrder(); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java
@@ -1,6 +1,7 @@ package com.matrix.system.shopXcx.mqTask; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.tools.LogUtil; import com.matrix.core.tools.StringUtils; import com.matrix.system.common.constance.AppConstance; @@ -22,6 +23,7 @@ import com.matrix.system.shopXcx.dao.ShopSkuDao; import com.rabbitmq.client.DeliverCallback; import com.rabbitmq.client.Delivery; import org.apache.logging.log4j.message.Message; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -29,12 +31,13 @@ import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Map; /** * 微商城订单同步到erp系统 */ @Component public class OrderTask implements DeliverCallback { public class OrderTask implements MessageHandler { @Autowired @@ -230,12 +233,20 @@ } @Override public String getName() { return "微商城订单同步到erp系统"; } @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getRouteKey() { return AsyncMessageRouting.CREATE_ORDER; } String orderId = new String(message.getBody(), "UTF-8"); @Override public void handle(Map<String,Object> param) { String orderId = (String) param.get("orderId"); LogUtil.debug("收到创建订单任务orderId={}", orderId); //获取订单信息 ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId)); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.tools.LogUtil; import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao; import com.matrix.system.fenxiao.entity.ShopSalesmanOrder; @@ -17,12 +18,13 @@ import java.io.IOException; import java.util.List; import java.util.Map; /** * 分销订单退款 */ @Component public class SalesOrderRefundTask implements DeliverCallback { public class SalesOrderRefundTask implements MessageHandler { @Autowired @@ -39,9 +41,19 @@ @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getName() { return "分销订单退款"; } String orderId = new String(message.getBody(), "UTF-8"); @Override public String getRouteKey() { return AsyncMessageRouting.SHOP_ORDER_REFUND; } @Override public void handle(Map<String,Object> param){ String orderId = (String) param.get("orderId"); LogUtil.debug("收到分销订单退款任务orderId={}", orderId); QueryWrapper queryWrapper=new QueryWrapper(); queryWrapper.eq("order_id",orderId); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderTask.java
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.tools.LogUtil; import com.matrix.system.common.bean.BusParameterSettings; @@ -37,12 +38,13 @@ import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Map; /** * 分销订单创建 */ @Component public class SalesOrderTask implements DeliverCallback { public class SalesOrderTask implements MessageHandler { @Autowired @@ -89,11 +91,20 @@ private ShopSalesmanGradeDao shopSalesmanGradeDao; @Override public String getName() { return "分销订单创建事件"; } @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getRouteKey() { return AsyncMessageRouting.CREATE_ORDER; } String orderId = new String(message.getBody(), "UTF-8"); @Override public void handle(Map<String,Object> param){ String orderId = (String) param.get("orderId"); LogUtil.debug("收到分销订单任务orderId={}", orderId); //获取订单信息 ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId)); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/ScoreOrderTask.java
@@ -1,6 +1,7 @@ package com.matrix.system.shopXcx.mqTask; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.core.tools.LogUtil; import com.matrix.core.tools.StringUtils; import com.matrix.system.common.bean.BusParameterSettings; @@ -23,12 +24,13 @@ import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; /** * 订单创建积分事件处理 */ @Component public class ScoreOrderTask implements DeliverCallback { public class ScoreOrderTask implements MessageHandler { @Autowired @@ -50,9 +52,19 @@ SysVipInfoDao sysVipInfoDao; @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getName() { return "订单创建积分事件"; } String orderId = new String(message.getBody(), "UTF-8"); @Override public String getRouteKey() { return AsyncMessageRouting.CREATE_ORDER; } @Override public void handle(Map<String,Object> param) { String orderId = (String) param.get("orderId"); LogUtil.debug("收到订单积分任务orderId={}", orderId); //获取订单信息 ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId)); zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/TemplateMsgTask.java
@@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSONObject; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.system.hive.dao.OnlinebookingDao; import com.matrix.system.hive.dao.SysShopInfoDao; import com.matrix.system.shopXcx.dao.ShopProductDao; @@ -13,11 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import java.util.Map; /** * 发送预约成功提醒消息 */ public class TemplateMsgTask implements DeliverCallback { public class TemplateMsgTask implements MessageHandler { @Autowired OnlinebookingDao onlinebookingDao; @@ -34,12 +36,20 @@ @Override public void handle(String consumerTag, Delivery message) throws IOException { public String getName() { return "发送预约成功提醒消息"; } String msg = new String(message.getBody(), "UTF-8"); JSONObject object = JSONObject.parseObject(msg); Integer templateMsgType = (Integer) object.get("templateMsgType"); String content = object.get("content") + ""; @Override public String getRouteKey() { return AsyncMessageRouting.ORDER_OUT_SOTORE; } @Override public void handle(Map<String,Object> param){ Integer templateMsgType = (Integer) param.get("templateMsgType"); String content = param.get("content") + ""; if (TemplateMsgType.APPOINTMENT_SUCCESS.getCode().equals(templateMsgType)) { appointmentSuccess.sendTemplateMsg(content); zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java
@@ -2,29 +2,18 @@ import com.alibaba.fastjson.JSONObject; import com.matrix.system.hive.bean.SysVipInfo; import com.matrix.system.hive.service.SysVipInfoService; import com.matrix.component.asyncmessage.MessageHandler; import com.matrix.component.tools.HttpClientUtil; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.LogUtil; import com.matrix.core.tools.rr.GlueFactory; import com.matrix.system.common.bean.BusParameterSettings; import com.matrix.system.common.constance.AppConstance; import com.matrix.system.common.dao.BusParameterSettingsDao; import com.matrix.system.constance.Dictionary; import com.matrix.system.hive.bean.SysProjServices; import com.matrix.system.hive.bean.SysVipInfo; import com.matrix.system.hive.dao.SysProjServicesDao; import com.matrix.system.hive.dao.SysShopInfoDao; import com.matrix.system.hive.dao.SysVipInfoDao; import com.matrix.system.shopXcx.api.WeChatGzhApiTools; import com.matrix.system.shopXcx.bean.ShopWxtemplateMsg; import com.matrix.system.shopXcx.dao.ShopWxtemplateMsgDao; import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo; import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; import com.matrix.system.wechart.templateMsg.UniformMsgPojo; import com.rabbitmq.client.DeliverCallback; import com.rabbitmq.client.Delivery; import io.swagger.models.auth.In; import org.apache.commons.collections.map.HashedMap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -38,7 +27,7 @@ * @author jyy */ @Component public class UniformMsgSentTask implements DeliverCallback { public class UniformMsgSentTask implements MessageHandler { @Autowired private ShopWxtemplateMsgDao shopWxtemplateMsgDao; @@ -46,19 +35,27 @@ @Autowired private BusParameterSettingsDao busParameterSettingsDao; @Override public String getName() { return "小程序统一消息模板消息发送提醒"; } @Override public String getRouteKey() { return AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG; } /** * 发送模板消息需要传JSONO字符串作为格式 * 例如:{"companyId":17} * companyId 是必须属性 * @param consumerTag * @param message * @throws IOException */ @Override public void handle(String consumerTag, Delivery message) throws IOException { public void handle(Map<String,Object> param){ try { String messages = new String(message.getBody(), "UTF-8"); JSONObject messageJsonParam=JSONObject.parseObject(messages); JSONObject messageJsonParam=JSONObject.parseObject(param.get("messages").toString()); if(!messageJsonParam.containsKey("companyId")||(!messageJsonParam.containsKey("templateCode"))){ LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17,\"templateCode\":10000} companyId 、templateCode 是必须属性"); zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/demo/MsgDemo3.java
@@ -1,12 +1,7 @@ package com.matrix.system.wechart.templateMsg.demo; import com.alibaba.fastjson.JSONObject; import com.matrix.component.tools.HttpClientUtil; import com.matrix.core.pojo.AjaxResult; import com.matrix.system.hive.plugin.util.HttpUtils; import com.matrix.system.shopXcx.api.WeChatGzhApiTools; import com.matrix.system.wechart.templateMsg.Task.UniformMsgSentTask; import com.rabbitmq.client.Delivery; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -26,7 +21,6 @@ @ResponseBody public AjaxResult template() throws IOException { uniformMsgSentTask.handle(null,null); return AjaxResult.buildSuccessInstance("1"); } zq-erp/src/main/resources/config/application.properties
@@ -17,9 +17,14 @@ #spring.datasource.password=hive123!@# #spring.datasource.url=jdbc:mysql://124.70.222.34/hive_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 spring.datasource.username=meidu_data spring.datasource.password=meidu_4321#&@ spring.datasource.url=jdbc:mysql://47.111.134.136/db_meidu_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 #spring.datasource.username=meidu_data #spring.datasource.password=meidu_4321#&@ #spring.datasource.url=jdbc:mysql://47.111.134.136/db_meidu_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=root spring.datasource.url=jdbc:mysql://127.0.0.1:3306/md_test_local?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource zq-erp/src/test/java/com/matrix/TesatAsyncMessage.java
New file @@ -0,0 +1,42 @@ package com.matrix; import com.matrix.component.asyncmessage.AsyncMessageManager; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.util.HashMap; import java.util.Map; /** * 测试类示例 * * @author jiangyouyao * @email 512061637@qq.com * @date 2019年2月25日 */ @RunWith(SpringRunner.class) @SpringBootTest(classes = {ZqErpApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class TesatAsyncMessage { @Autowired AsyncMessageManager asyncMessageManager; @Test public void test() throws IOException { Map<String, Object> param =new HashMap<>(); param.put("test","123"); asyncMessageManager.sendMsg("testkey",param); asyncMessageManager.sendMsg("testkey","test=%s","123456"); } }