package cn.pluss.platform.notify.impl;

import cn.pluss.platform.PushService;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.config.MqttSendMessage;
import cn.pluss.platform.constants.Constant;
import cn.pluss.platform.deviceStock.DeviceStockService;
import cn.pluss.platform.deviceVoiceBox.DeviceVoiceBoxMsgService;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.enums.PayMessageType;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.merchantOrder.MerchantOrderService;
import cn.pluss.platform.merchantOrderSplit.MerchantOrderSplitDetailService;
import cn.pluss.platform.notify.NotifyMessageService;
import cn.pluss.platform.ty.Ys4GEnum;
import cn.pluss.platform.ty.Ys4GTypeEnum;
import cn.pluss.platform.user.UserVoiceService;
import cn.pluss.platform.user.impl.GeneralPushUtil;
import cn.pluss.platform.util.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
public class NotifyMessageServiceImpl implements NotifyMessageService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private MerchantOrderService merchantOrderService;

    @Autowired
    private MerchantBaseInfoService merchantBaseInfoService;

    @Autowired
    private DeviceVoiceBoxMsgService deviceVoiceBoxMsgService;

    @Autowired
    private DeviceStockService deviceStockService;

    @Autowired
    private MqttSendMessage mqttSendMessage;

    @Autowired
    private PushService pushService;

    @Setter(onMethod_ = {@Autowired})
    private RestTemplate restTemplate;

    @Autowired
    private UserVoiceService userVoiceService;

    @Autowired
    private GeneralPushUtil generalPushUtil;

    @Resource
    private MerchantOrderSplitDetailService merchantOrderSplitDetailService;


    @Retryable(value = Exception.class, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 1.5))
    @Override
    public void sendNotifyMessage(MerchantOrder order, Map<String, Object> params) throws Exception {
        logger.info("===============>开始支付成功，向下游推送支付结果通知，通知地址:{},通知参数:{}<=============", order.getMercNotifyUrl(), params);
        if (StringUtil.isEmpty(order.getMercNotifyUrl())) {
            logger.info("===============>上送的异步通知地址为空，推送失败<=============");
            return;
        }
        String nofifyUrl = order.getMercNotifyUrl();
        String json = ResultGenerator.genSuccessJsonResult("成功", params).toJSONString();
        String result = null;
        try {
            result = restTemplate.postForObject(nofifyUrl, json, String.class);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception();
        }
        logger.info("===============>下游返回消息内容为:{}<=============", result);
        if (StringUtil.isEmpty(result)) {
            throw new Exception();
        }
        JSONObject jsonObject = null;
        try {
            if(Constant.RESULT_CODE_SUCCESS.equalsIgnoreCase(result)){
                if(StringUtil.isEmpty(params.get("msgType")) || "01".equals(params.get("msgType"))){
                    UpdateWrapper<MerchantOrder> updateOrder = new UpdateWrapper<MerchantOrder>();
                    updateOrder.eq("id", order.getId());
                    updateOrder.set("mercNotifyStatus", "1");
                    updateOrder.set("mercRemark", result);
                    merchantOrderService.update(updateOrder);
                }
                return;
            }else{
                jsonObject = JSONObject.parseObject(result);
                if (Constant.RESULT_CODE_SUCCESS.equalsIgnoreCase(jsonObject.getString("code"))) {
                    if(StringUtil.isEmpty(params.get("msgType")) || "01".equals(params.get("msgType"))){
                        UpdateWrapper<MerchantOrder> updateOrder = new UpdateWrapper<MerchantOrder>();
                        updateOrder.eq("id", order.getId());
                        updateOrder.set("mercNotifyStatus", "1");
                        updateOrder.set("mercRemark", jsonObject.getString("msg"));
                        merchantOrderService.update(updateOrder);
                    }
                    return;
                } else {
                    order.setMercRemark(jsonObject.getString("msg"));
                    throw new Exception();
                }
            }
        } catch (JSONException e) {
            order.setMercRemark(result);
            logger.info("===============>下游未返回正确的json格式数据:{}<=============", result);
            throw new Exception();
        }

    }

    @Retryable(value = Exception.class, maxAttempts = 5, backoff = @Backoff(delay = 5000, multiplier = 1.5))
    @Override
    public void sendNotifyMessage(String notifyUrl, Map<String, Object> params) throws Exception{
        String json = ResultGenerator.genSuccessJsonResult("处理成功", params).toJSONString();
        String result = null;
        try {
            result = restTemplate.postForObject(notifyUrl, json, String.class);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception();
        }
        logger.info("===============>下游返回消息内容为:{}<=============", result);
        if (StringUtil.isEmpty(result)) {
            throw new Exception();
        }
        JSONObject jsonObject = null;
        try {
            if(Constant.RESULT_CODE_SUCCESS.equalsIgnoreCase(result)){
                return;
            }else{
                jsonObject = JSONObject.parseObject(result);
                if (Constant.RESULT_CODE_SUCCESS.equalsIgnoreCase(jsonObject.getString("code"))) {
                    return;
                }
            }
        } catch (JSONException e) {
            logger.info("===============>下游未返回正确的json格式数据:{}<=============", result);
            throw new Exception();
        }
    }

    @Override
    public void sendMqttMessage(MerchantOrder order, Date payDate, String type, JSONObject object, String mercId,int payType){
        if ("pay".equals(type)) {
            sendPayMqttMessage(order, payDate,payType);
            if ("10".equals(order.getOrderType())) {
                MerchantBaseInfo merchant = merchantBaseInfoService.getMerchantBaseInfoByMerchantCode(order.getMerchantCode());
                logger.info("================>【线上店来单消息】推送商户,商户merchantCode参数:{}<===============", order.getMerchantCode());
                if (merchant != null) {
                    //实例化Timer类
                    Timer timer = new Timer();
                    timer.schedule(new TimerTask() {
                        public void run() {
                            pushService.pushMsg(String.valueOf(merchant.getUserId()), pushService.MAKE_ORDER);
                        }
                    }, 2000);
                }
            }
        } else if ("cancel".equals(type)) {
            sendCancelPayMqttMessage(object, mercId,order);
        }
    }

    /**
     * 发送支付消息
     * @param order
     * @param type
     * @param params
     * @param mercId
     */
    @Override
    public void sendPayMessage(MerchantOrder order, String type, JSONObject params, String mercId) {
        sendLowerPayNotifyCallback(order);
        String orderType = order.getOrderType();
        int val = PayMessageType.PLAIN_PAY.getValue();
        //会员充值
        if("3".equals(orderType) || "5".equals(orderType)){
            val = PayMessageType.MEMBER_RECHARGE.getValue();
        }
        sendMqttMessage(order,order.getTransDt(),type,params,mercId,val);

    }

    /**
     * 推送消息
     * @param order
     */
    @Override
    public void sendLowerPayNotifyCallback(MerchantOrder order) {
        log.info("====================>进入下游订单支付成功推送操作<====================");
        JSONObject notifyMap = new JSONObject();
        notifyMap.put("msgType","01");
        notifyMap.put("channelTradeNo",order.getThirdTransNo());
        notifyMap.put("mercOrderNo",order.getMercOrderNo());
        notifyMap.put("mercUserId",order.getMercUserId());
        notifyMap.put("payAmt",order.getConsumeFee().toString());
        notifyMap.put("payTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(order.getTransDt()));
        notifyMap.put("payWay",order.getPayTypeCode().contains("0") || "aliPay".equals(order.getPayTypeCode()) ? "ZFBZF" : "WXZF");
        notifyMap.put("orderNumber",order.getOrderNumber());
        notifyMap.put("status","1");
        String key = "4c8d277b0f274604af68e590cc0b3e6b";
        MerchantBaseInfo merchant = merchantBaseInfoService.getMerchantBaseInfoByMerchantCode(order.getMerchantCode());
        if(merchant != null && StringUtil.isNotEmpty(merchant.getMd5Key())){
            key = merchant.getMd5Key();
        }
        String signStr = SignUtils.getSignContent(notifyMap) + "&key="+key;
        log.info("下游通知签名字符串：{}",signStr);
        String nSign = MD5Util.MD5Encode(signStr, "UTF-8");
        notifyMap.put("sign",nSign);
        try {
            sendNotifyMessage(order,notifyMap);
        } catch (Exception e) {
            log.info("====================>进入下游推送异步通知异常，异常信息:{}<====================",e);
        }
    }

    @Override
    public void sendLowerSplitNotify(MerchantOrderSplit orderSplit) {
        if(StringUtil.isNotEmpty(orderSplit.getNotifyUrl())){
            log.info("【分账通知推送】订单号：{}",orderSplit.getOrderNumber());
            JSONObject notify = new JSONObject();
            notify.put("msgType","03");
            notify.put("orderNumber",orderSplit.getOrderNumber());
            notify.put("mercOrderNo",orderSplit.getMercOrderNo());
            notify.put("divStatus",orderSplit.getDivStatus());
            notify.put("divisionMode",orderSplit.getDivisionMode());
            notify.put("merchantCode",orderSplit.getMerchantCode());
            notify.put("merchantName",orderSplit.getMerchantName());
            notify.put("orderAmt",orderSplit.getOrderAmt().toString());
            notify.put("remark",orderSplit.getRemark());
            Integer divStatus = orderSplit.getDivStatus();
            if(divStatus == 1 || divStatus == 2){
                JSONArray divList = new JSONArray(16);
                List<MerchantOrderSplitDetail> detailList = orderSplit.getDetailList();
                if(detailList == null){
                    detailList = merchantOrderSplitDetailService.listByOrderNumber(orderSplit.getOrderNumber());
                }
                if(!detailList.isEmpty()){
                    for (MerchantOrderSplitDetail detail:detailList) {
                        JSONObject divObj = new JSONObject(16);
                        divObj.put("merchantCode",detail.getMerchantCode());
                        divObj.put("merchantName",detail.getMerchantName());
                        divObj.put("finalAmt",detail.getFinalAmt().toString());
                        divList.add(divObj);
                    }
                    notify.put("divList",divList);
                }
            }
            String key = "4c8d277b0f274604af68e590cc0b3e6b";
            MerchantBaseInfo merchant = merchantBaseInfoService.getMerchantBaseInfoByMerchantCode(orderSplit.getMerchantCode());
            if(merchant != null && StringUtil.isNotEmpty(merchant.getMd5Key())){
                key = merchant.getMd5Key();
            }
            String signStr = SignUtils.getSignContent(notify) + "&key="+key;
            log.info("下游通知签名字符串：{}",signStr);
            String nSign = MD5Util.MD5Encode(signStr, "UTF-8");
            notify.put("sign",nSign);
            try {
                sendNotifyMessage(orderSplit.getNotifyUrl(),notify);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void sendCancelPayMessage(JSONObject params) {
        logger.info("===============>【取消支付】,推送mqtt取消支付通知开始,请求参数:{}<===============", params);
        String mercId = params.getString("mercId");
        String userId = params.getString("userId");
        UserVoice voice = userVoiceService.getByUserId(Long.valueOf(userId));
        if(UserVoice.ENABLE.equals(voice.getPayCancel())){
            generalPushUtil.sendAllPlatByUserIdCancel(Arrays.asList(userId),null,null);
        }
        MerchantOrder order = params.getObject("order",MerchantOrder.class);
        if(order == null){
            order = new MerchantOrder();
            String money = StringUtil.isEmpty(params.getString("money")) ? "100.00" : params.getString("money");
            order.setConsumeFee(Double.valueOf(money));
            order.setOrderNumber(StringUtil.getBillno());
        }
        JSONObject object = new JSONObject();
        object.put("type", "trans_cancel");
        object.put("orderId", order.getOrderNumber());
        object.put("cancelTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        try {
            sendMqttMessage(order, null, "cancel", object, mercId, PayMessageType.PLAIN_PAY.getValue());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("===============>【取消支付】,推送mqtt取消支付通知异常,异常信息:{}<===============", e.getMessage());
        }
    }

    private void sendCancelPayMqttMessage(JSONObject object, String storeId,MerchantOrder order) {
        QueryWrapper<DeviceStock> boxQueryWrapper = new QueryWrapper<DeviceStock>()
                .eq("actMercId", storeId).eq("status", "3").likeRight("code", "YYX");
        List<DeviceStock> list = deviceStockService.list(boxQueryWrapper);
        for (DeviceStock stock : list) {
            DeviceVoiceBoxMsg deviceMsg = new DeviceVoiceBoxMsg();
            try {
                sendDeviceMessage(stock,deviceMsg,"2",null,order.getOrderNumber(),order.getConsumeFee()+"",
                        object,PayMessageType.PLAIN_PAY.getValue(), null);
            }catch (Exception e){
                logger.error("【音箱消息】推送异常，设备编号：{}，异常信息：{}",stock.getDeviceNo(),e.getMessage());
            }
        }
    }

    private void saveBoxMessage(JSONObject object, DeviceStock stock,String type,String orderNumber,DeviceVoiceBoxMsg deviceMsg) {
        deviceMsg.setBody(object.toJSONString());
        deviceMsg.setCreateTime(new Date());
        deviceMsg.setType(type);
        deviceMsg.setOrderNumber(orderNumber);
        deviceMsg.setRequestId(UUID.randomUUID().toString().replace("-","").toUpperCase());
        deviceMsg.setDeviceNo(stock.getSnNo());
        deviceVoiceBoxMsgService.save(deviceMsg);
    }

    private void sendPayMqttMessage(MerchantOrder order, Date payDate,int payType) {
        QueryWrapper<MerchantBaseInfo> merchantQuery = new QueryWrapper<MerchantBaseInfo>()
                .eq("merchantCode", order.getMerchantCode());
        MerchantBaseInfo merchant = merchantBaseInfoService.getOne(merchantQuery);
        if (merchant != null) {
            QueryWrapper<DeviceStock> boxQueryWrapper = new QueryWrapper<DeviceStock>()
                    .eq("actMercId", merchant.getId()).eq("status", "3").likeRight("code", "YYX");
            List<DeviceStock> list = deviceStockService.list(boxQueryWrapper);
            if (!list.isEmpty()) {
                String amount = new BigDecimal(String.valueOf(order.getConsumeFee())).multiply(new BigDecimal(100)).intValue() + "";
                String discount = order.getDiscount() == null ? BigDecimal.ZERO.toString() : BigDecimal.valueOf(order.getDiscount()).stripTrailingZeros().toPlainString();
                for (DeviceStock stock : list) {
                    DeviceVoiceBoxMsg deviceMsg = new DeviceVoiceBoxMsg();
                    try {
                        sendDeviceMessage(stock,deviceMsg,"1",payDate,order.getOrderNumber(),amount,null,payType,discount);
                    }catch (Exception e){
                        logger.error("【音箱消息】推送异常，设备编号：{}，异常信息：{}",stock.getDeviceNo(),e.getMessage());
                    }
                }
            }
        }
    }
    /**
     * @description:发送设备消息
     * @date: 2021/9/1 13:53
     * @param stock: 设备信息
     * @param deviceMsg: 设备信息记录
     * @param msgType:消息类型
     * @param payDate:支付时间
     * @param orderNumber:订单号
     * @param amount:金额
     * @param amount:金额
     */
    private void sendDeviceMessage(DeviceStock stock, DeviceVoiceBoxMsg deviceMsg, String msgType
            , Date payDate, String orderNumber,String amount,JSONObject reqData,int payType,String discount) {
        //支付消息播报
        logger.info("【音箱消息】推送开始,设备编号:{},设备类型:{},消息类型：{}",stock.getDeviceNo(),stock.getType(),msgType);
        if ("WIFI".equalsIgnoreCase(stock.getType())) {
            JSONObject body = new JSONObject();
            if("1".equals(msgType)){
                body.put("type", "transOrder");
                body.put("amount", amount);
                body.put("orderId", StringUtil.getBillno());
                body.put("paymentChannel", "SYBZF");
                body.put("transTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(payDate));
            }else{
                body = reqData;
            }
            logger.info("【WIFI音箱消息】推送开始,设备编号:{},消息内容:{}",stock.getDeviceNo(),body.toString());
            try {
                saveBoxMessage(body, stock,msgType,orderNumber,deviceMsg);
                Map<String, String> respMap = mqttSendMessage.sendMqttMessage(stock.getDeviceNo(), body);
                if(respMap != null && respMap.size() > 0){
                    logger.info("【WIFI音箱】消息推送成功,设备编号：{}，响应信息：{}",stock.getDeviceNo(),JSONObject.toJSONString(respMap));
                    deviceMsg.setRespBody(JSONObject.toJSONString(respMap));
                    deviceVoiceBoxMsgService.updateById(deviceMsg);
                }else{
                    logger.error("【WIFI音箱】消息推送失败,设备编号：{}",stock.getDeviceNo());
                }
            }catch (Exception e){
                logger.error("【WIFI音箱】推送异常,设备编号:{},异常信息:{}",stock.getDeviceNo(),e.getMessage());
                e.printStackTrace();
            }
        }else if("4G".equalsIgnoreCase(stock.getType())){
            JSONObject body = get4GCommonMessageParams();
            String amt = new BigDecimal(amount).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            body.put("devName", stock.getDeviceNo());
            body.put("money", amt);
            if("1".equals(msgType)){
                body.put("biz_type", "1");
                // 1为收款成功
                String type = "1";
                if(payType != PayMessageType.PLAIN_PAY.getValue()){
                    JSONObject money = new JSONObject(2);
                    money.put("amount",amt);
                    money.put("discount",discount);
                    if(payType == PayMessageType.MEMBER_CONSUME.getValue()){
                        type = "46";
                    }else if(payType == PayMessageType.MEMBER_RECHARGE.getValue()){
                        type = "44";
                    }
                    body.put("money",money);
                }
                body.put("broadCastType", type);
            }else{
                body.put("broadCastType", "24");
            }
            try {
                saveBoxMessage(body, stock,msgType,orderNumber,deviceMsg);
                String response = send4GMessage(body,Ys4GEnum.BSJ_4G_YYS.getDomain(),Ys4GTypeEnum.BSJ.getCode());
                if(StringUtil.isNotEmpty(response)){
                    logger.info("【4G音箱】推送成功,设备编号：{}，响应信息：{}",stock.getDeviceNo(),response);
                    deviceMsg.setRespBody(response);
                    deviceVoiceBoxMsgService.updateById(deviceMsg);
                }else{
                    logger.error("【4G音箱】推送失败,设备编号：{}",stock.getDeviceNo());
                }
            }catch (Exception e){
                logger.error("【4G音箱】推送异常,设备编号：{}，异常信息:{}",stock.getDeviceNo(),e.getMessage());
                e.printStackTrace();
            }
        }else if("4G_TY".equalsIgnoreCase(stock.getType())){
            JSONObject body = get4GTyParams(amount,stock,msgType);
            saveBoxMessage(body, stock,msgType,orderNumber,deviceMsg);
            String response = send4GMessage(body,Ys4GEnum.TY_4G_YYS.getDomain(), Ys4GTypeEnum.TY.getCode());
            if(StringUtil.isNotEmpty(response)){
                logger.info("【天喻4G音箱】推送成功,设备编号：{}，响应信息：{}",stock.getDeviceNo(),response);
                deviceMsg.setRespBody(response);
                deviceVoiceBoxMsgService.updateById(deviceMsg);
            }else{
                logger.error("【天喻4G音箱】推送失败,设备编号：{}",stock.getDeviceNo());
            }
        }
    }
    /**
     * 推送4G音箱消息
     * @date: 2021/12/10 11:41
     * @param body:
     * @param domain:
     * @param code:
     * @return java.lang.String
     */
    private String send4GMessage(JSONObject body, String domain, String code) {
        if(Ys4GTypeEnum.TY.getCode().equals(code)){
            String response = restTemplate.postForObject(domain, body, String.class);
            logger.info("【天喻4G云音箱消息推送】返回参数：{}<======================", response);
            return response;
        }else if(Ys4GTypeEnum.BSJ.getCode().equals(code)){
            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(domain);
            body.forEach((s, o) -> {
                try {
                    builder.queryParam(s, URLEncoder.encode(o.toString(), "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            });
            UriComponents uriComponents = builder.build(true);
            String response = restTemplate.getForObject(uriComponents.toUri(), String.class);
//            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(domain);
//            body.entrySet().stream().forEach(o -> builder.queryParam(o.getKey(),o.getValue()));
//            String requestUrl = builder.build().encode().toString();
//            String response = restTemplate.getForObject(requestUrl, String.class);
            logger.info("【博实结4G云音箱消息推送】返回参数：{}<======================", response);
            return response;
        }
        return null;
    }

    /**
     * @description:组装天喻4G音箱公共参数
     * @date: 2021/12/6 18:16
     * @param amount:
     * @return com.alibaba.fastjson.JSONObject
     */
    private JSONObject get4GTyParams(String amount,DeviceStock deviceStock,String msgType) {
        JSONObject params = new JSONObject();
        params.put("accessKeyId",Ys4GEnum.TY_4G_YYS.getAppId());
        params.put("requestId", UUID.randomUUID().toString());
        params.put("timestamp",String.valueOf(System.currentTimeMillis()));
        params.put("deviceId",deviceStock.getDeviceNo());
        if("1".equals(msgType)){
            params.put("requestData",new BigDecimal(amount).divide(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_UP).toString());
            params.put("payType","08");
        }else{
            params.put("payType","16");
            params.put("requestData",amount);
        }
        String sign = SignUtils.getSignSha256(params,Ys4GEnum.TY_4G_YYS.getSecret());
        params.put("sign",sign);
        return params;
    }

    /**
     * 获取公共请求参数
     *
     * @return
     */
    private JSONObject get4GCommonMessageParams() {
        JSONObject params = new JSONObject();
        params.put("appId", Ys4GEnum.BSJ_4G_YYS.getAppId());
        params.put("timestamp", System.currentTimeMillis());
        String requestId = UUID.randomUUID().toString();
        params.put("requestId", requestId);
        params.put("userCode", Ys4GEnum.BSJ_4G_YYS.getAppId());
        String signContent = SignUtils.getSignContent1(params, Ys4GEnum.BSJ_4G_YYS.getSecret());
        String token = MD5Util.MD5Encode(signContent, "UTF-8").toUpperCase();
        params.put("token", token);
        return params;
    }

    @Recover
    public void recover(Exception e, MerchantOrder order) {
        logger.info("===========>推送完成，未接收到有效返回，捕获的异常为:{}<==============", e);
        if (StringUtil.isNotEmpty(order.getId())) {
            UpdateWrapper<MerchantOrder> updateOrder = new UpdateWrapper<MerchantOrder>();
            updateOrder.eq("id", order.getId());
            updateOrder.set("mercNotifyStatus", "2");
            if (StringUtil.isNotEmpty(order.getMercRemark())) {
                updateOrder.set("mercRemark", order.getMercRemark());
            }
            merchantOrderService.update(updateOrder);
        }
    }
}
