package com.bweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.channel.gas.shell.CqShellPetroleumRequestService;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpUtils;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.MD5Util;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.MqttProviderConfig;
import com.hfkj.device.sanmisen.PrinterTemplate;
import com.hfkj.entity.BsGasClassGroupTask;
import com.hfkj.entity.BsGasOrder;
import com.hfkj.entity.SecUser;
import com.hfkj.model.GasClassGroupTaskDataCount;
import com.hfkj.model.ResponseData;
import com.hfkj.service.gas.BsGasClassGroupTaskService;
import com.hfkj.service.gas.BsGasOrderService;
import com.hfkj.service.sec.SecUserLoginLogService;
import com.hfkj.service.sec.SecUserService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
import com.hfkj.sysenum.SecUserStatusEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value="/test")
@Api(value="测试")
public class TestController {
	Logger log = LoggerFactory.getLogger(TestController.class);

	@Resource
	private SecUserService secUserService;
	@Resource
	private SecUserLoginLogService secUserLoginLogService;

	@RequestMapping(value="gasSyncPayment",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "壳牌推送")
	public ResponseData gasSyncPayment() {
		try {

			JSONObject response = HttpsUtils.doGet("https://oil.dctpay.com/crest/gasOrder/queryOilOrder?orderNo=240804110524374697");

			BsGasOrder gasOrder = JSONObject.parseObject(response.getJSONObject("return_data").toJSONString(), BsGasOrder.class);

			// 推送加好油【重庆壳牌】
			JSONObject object = CqShellPetroleumRequestService.gasSyncPayment("CT"+gasOrder.getOrderNo(),
					gasOrder.getMerNo(),
					gasOrder.getPayTime(),
					gasOrder.getGasRefuelPrice(),
					gasOrder.getGasOilNo(),
					gasOrder.getGasGunNo(),
					gasOrder.getPayablePrice(),
					gasOrder.getTotalDeductionPrice()
			);
			return ResponseMsgUtil.success(object);

		} catch (Exception e) {
			log.error("error!",e);
			return ResponseMsgUtil.exception(e);
		}
	}

	@Resource
	private MqttProviderConfig mqttProviderConfig;
	@Resource
	private BsGasOrderService gasOrderService;
	
	@Resource
	private BsGasClassGroupTaskService gasClassGroupTaskService;
	@RequestMapping(value="oilReceipt",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "壳牌推送")
	public ResponseData oilReceipt() {
		try {
			JSONObject param = new JSONObject();
			param.put("id", System.currentTimeMillis());
			param.put("type", 5);
			//param.put("vType", 0);
			//param.put("vMessage", "嗨加油新订单，加油金额"+gasOrder.getGasRefuelPrice()+"元，请注意查收");

			// param.put("contents", PrinterTemplate.oilReceipt(1, gasOrderService.getDetailByOrderNo("240726140647722244"), new HashMap<>(), false));
			BsGasClassGroupTask groupTask = gasClassGroupTaskService.getDetailById(187L);
			GasClassGroupTaskDataCount dataCount = gasClassGroupTaskService.countGroupTaskData(groupTask.getMerId(), groupTask.getClassNum(), groupTask.getId(), groupTask.getStatus(), groupTask.getStartTime(), groupTask.getEndTime());

			param.put("contents", PrinterTemplate.classGroupCountTemp(dataCount ,true));
			mqttProviderConfig.publish(1, false, "SW242300044/submsg", param.toJSONString());

			return ResponseMsgUtil.success("");

		} catch (Exception e) {
			log.error("error!",e);
			return ResponseMsgUtil.exception(e);
		}
	}



}
