package com.chinacreator.video.restful.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.dto.DataOutPipe;
import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.mapper.DictionaryDao;
import com.chinacreator.video.restful.service.BackBusiOrderAsynService;
import com.chinacreator.video.restful.service.ChannelSyncService;
import com.chinacreator.video.restful.service.HsQueryVipService;
import com.chinacreator.video.restful.service.MuorderService;
import com.chinacreator.video.restful.util.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
 * 供华盛小程序使用，查询用户近三个月的权益
 * zhengrong.yan
 * 202206907
 */
@RestController
public class HsQueryVipController {

    private static Logger logger = Logger.getLogger(String.valueOf(HsQueryVipController.class));

    private static Logger log = Logger.getLogger("hsqueryvip");

    @Autowired
    private HsQueryVipService service;

    /**
     * POST方式办理业务
     *
     * @param inputObj
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/hsqueryvip", method = RequestMethod.POST, produces = "application/json")
    public DataOutPipe<?> order(@RequestBody(required = false) OrderInfo orderInfo, HttpServletRequest request) throws Exception {
        DataOutPipe outpipe = new DataOutPipe();
        Map<String, Object> logmap = new HashMap<String, Object>();
        logmap.put("forward", "hsqueryvip");
        logmap.put("reqData", orderInfo);
        String resultcode = "";
        String errorinfo = "";
		JSONArray jsonArray = new JSONArray();
//		System.out.println(orderInfo);
        try {
            orderInfo.setTimes(System.currentTimeMillis() + "");
            service.busiCheck(orderInfo);
            jsonArray = service.busiOper(orderInfo);
            resultcode = "0";
            errorinfo = "";
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof BussinessException) {
                resultcode = ((BussinessException) e).getCode();
                errorinfo = ((BussinessException) e).getMessage();
            } else {
                resultcode = "8000";
                errorinfo = "出现异常，" + e.getMessage();
            }
        } finally {
            logmap.put("resultcode", resultcode);
            logmap.put("errorinfo", errorinfo);
            logmap.put("rspData", jsonArray);
            log.info(JSON.toJSONString(logmap));
            outpipe.setResultcode(resultcode);
            outpipe.setErrorinfo(errorinfo);
            outpipe.setData(jsonArray);
            return outpipe;
        }
    }
}
