工作中的小bug

工作中的小bug,第1张

工作中的小bug

项目中添加测试配置


    org.springframework.boot
    spring-boot-starter-test

写单元测试

@RunWith(SpringRunner.class)
@SpringBootTest
public class PosTest {

    @Autowired
    private SendMessageService messageService;

    @Test
    public void testGetSalesOrder() {
        String omsString = "{"cancelReason":"哈喽","createUserId":"OMS","id":"540","offset":0,"orderCode":"TSF22011809144500010","orderId":"TSF22011809144500010","orderType":"MDDBRK","ownerCode":"85000321","pageNo":0,"pageSize":0,"totalPage":0,"warehouseCode":"CSMDZ"}";

        try {
            messageService.sendData(MessageConstant.POS_OMS_EXCHANGE,
                    MessageConstant.POS_OMS_EXCHANGE_RK_CANCEL, omsString);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

}
这个是关于mq调试的案例

接受方

@RabbitListener(queues = MessageConstant.POS_OMS_QUEUE_CANCEL, autoStartup = "true", errorHandler = "handlerListenerQueueError")
private void cancelAllot(String parameter, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws Exception {
    logger.info("开始进行取消调拨单 *** 作,参数:{}", parameter);
    JSonObject omsCancelInfo = JSONObject.parseObject(parameter);
    // Map omsCancelMap = (Map) JSON.parse(parameter);
    String allotId = (String) omsCancelInfo.get("orderCode");
    String orderType = (String) omsCancelInfo.get("orderType");
    //1.根据调拨单id查询主调拨单信息
    if (!StringUtils.isEmpty(allotId) && !StringUtils.isEmpty(orderType) && orderType.equals("MDDBRK")) {
        AllotStockBillInfo allotStockBillInfo = new AllotStockBillInfo();
        allotStockBillInfo.setAllotId(allotId);
        List allInfos = stockDao.getAllInfos(allotStockBillInfo);
        logger.info("------调拨单查询结果:{}", JSON.toJSonString(allInfos));
        if (!CollectionUtils.isEmpty(allInfos)) {
                //2.如果状态名不为空并且是待签收状态-进行状态更改
                    allotStockBillInfo.setBillStatus(CompassConstant.CANCEL_ALLOT_CODE);
                    allotStockBillInfo.setBillStatusName(CompassConstant.CANCEL_ALLOT_NAME);
                    allotStockBillInfo.setRemark(CompassConstant.CANCEL_ALLOT_REMARK);
                    try {
                        stockDao.updateAllotStatusByAllotId(allotStockBillInfo);
                        logger.info("大仓取消调拨单成功,调拨单号:{}", allotId);
                    } catch (Exception e) {
                        noticeLogger.warn("大仓取消调拨单失败需要人工处理:{}" ,allotId);
                        logger.error("大仓取消调拨单失败需要人工处理:{}" ,allotId);
                        logger.error("大仓取消调拨单异常", e);
                    }
                } else {

                    //3.如果不是待签收状态就通知人工
                    String msg = "该笔调拨单不存在:";
                    noticeLogger.warn(msg+allotId);
                    logger.info(  msg+allotId);
                }

        } else {
            logger.info("传输该笔订单信息有误,调拨单号:{}", allotId);
        }

    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5709533.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存