//package com.ssm.Listener;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.rabbitmq.client.Channel;
//import com.ssm.manage.response.GenericResponse;
//import com.ssm.manage.utils.SessionHelp;
//import com.ssm.core.utils.ChuangLanSmsUtil;
//import com.ssm.manage.entity.AccountTradeRecord;
//import com.ssm.manage.entity.BaseStore;
//import com.ssm.manage.entity.CashSignatureFile;
//import com.ssm.manage.entity.SmsException;
//import com.ssm.manage.query.CashListRequest;
//import com.ssm.manage.service.SsmCashService;
//import com.ssm.manage.utils.Constant;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.messaging.handler.annotation.Headers;
//import org.springframework.messaging.handler.annotation.Payload;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.math.BigDecimal;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Component
//@Configuration
//@Slf4j
//public class SsmCashListener {
//    private static final String CASH_TOPIC_CHANGEGE = "cash_exchange";
//    private static final String CASH_QUEUE = "cash_queue";
//    @Autowired
//    private SsmCashService ssmCashService;
//
//    /**
//     * 监听主队列~
//     *
//     * @param message
//     * @param map
//     * @param channel
//     * @throws InterruptedException
//     * @throws IOException
//     */
//    @RabbitListener(queues = CASH_QUEUE)
//    public void sendMiss(Message message, @Headers Map<String, Object> map, Channel channel) throws InterruptedException, IOException {
//        Map map1 = JSON.parseObject(message.getBody(), Map.class);
////        JSONObject jsonObject = JSON.parse(message.getBody());
////        JSONObject parseObject = JSON.parseObject(message.toString());
////        List<CashListRequest> listRequests = parseObject.getJSONArray("cashListRequests").toJavaList(CashListRequest.class);
////        BigDecimal spendMoney = parseObject.getBigDecimal("spendMoney");
////        BigDecimal consumeMoney = parseObject.getBigDecimal("consumeMoney");
////        Integer spendCount = parseObject.getInteger("spendCount");
////        Integer consumeCount = parseObject.getInteger("consumeCount");
////        String projectName = parseObject.getString("projectName");
////        String memberPhone = parseObject.getString("memberPhone");
//
//        JSONObject tradeRecordObj = (JSONObject) map1.get("accountTradeRecord");
//        AccountTradeRecord accountTradeRecord = tradeRecordObj.toJavaObject(AccountTradeRecord.class);
//        JSONObject storeObj = (JSONObject) map1.get("baseStore");
//        BaseStore baseStore = storeObj.toJavaObject(BaseStore.class);
//
//        if (Constant.account_type_recharge_consume.equals(accountTradeRecord.getAccountType())) {
//            if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
//                try {
//                    ChuangLanSmsUtil.sendCashByRechargeSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getAccountSpendMoney(), accountTradeRecord.getAccountConsumeMoney());
//                } catch (Exception e) {
//                    log.error("SsmCashListener.sendMiss:", e);
//                    //即放入死信队列-推送后续队列内消息即为抢单失败-
//                    channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//                }
//            }
//        } else if (Constant.account_type_project_consume.equals(accountTradeRecord.getAccountType())) {//疗程卡支付
//            //设置短信账户 发送 否则不发送
//            if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
//                try {
//                    ChuangLanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
//                } catch (Exception e) {
//                    log.error("SsmCashListener.sendMiss:", e);
//                    //即放入死信队列-推送后续队列内消息即为抢单失败-
//                    channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//                }
//            }
//        }
//        //手动设置ACK接收确认当前消息消费完毕
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
//
//    /**
//     * 监听死信队列-即发送短信失败
//     *
//     * @param message
//     * @param map
//     * @param channel
//     * @throws InterruptedException
//     * @throws IOException
//     */
//    @RabbitListener(queues = "deal_queue")
//    public static void sendMiss2(Message message, @Headers Map<String, Object> map, Channel channel) throws InterruptedException, IOException {
//        String msg = new String(message.getBody(), "UTF-8");
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        log.error("SsmCashListener.sendMiss2:", "短信发送失败");
//    }
//
//}
