package com.web.controller.business;

import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighOrder;
import com.hai.enum_type.OrderStatusEnum;
import com.hai.enum_type.UserObjectTypeEnum;
import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.order.model.OrderThirdPartyModel;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderPayType;
import com.web.config.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "hltRecharge")
@Api(value = "汇联通订单业务")
public class OrderHltRechargeController {


    private static Logger log = LoggerFactory.getLogger(OrderThirdPartyController.class);

    @Resource
    private UserCenter userCenter;

    @Resource
    private OrderService orderService;


    @RequestMapping(value = "/getOrderList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询汇联通充值订单列表")
    public ResponseData getOrderList(@RequestParam(name = "orderNo", required = false) String orderNo,
                                     @RequestParam(name = "memPhone", required = false) String memPhone,
                                     @RequestParam(name = "memCardNo", required = false) String memCardNo,
                                     @RequestParam(name = "payType", required = false) Integer payType,
                                     @RequestParam(name = "status", required = false) Integer status,
                                     @RequestParam(name = "companyId", required = false) Long companyId,
                                     @RequestParam(name = "createTimeS", required = false) Long createTimeS,
                                     @RequestParam(name = "createTimeE", required = false) Long createTimeE,
                                     @RequestParam(name = "payTimeS", required = false) Long payTimeS,
                                     @RequestParam(name = "payTimeE", required = false) Long payTimeE,
                                     @RequestParam(name = "productType", required = false) Integer productType,
                                     @RequestParam(name = "finishTimeS", required = false) Long finishTimeS,
                                     @RequestParam(name = "finishTimeE", required = false) Long finishTimeE,
                                     @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                     @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                     HttpServletRequest request) {
        try {

            UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class);
            if (userInfoModel == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, "");
            }
            Map<String,Object> map = new HashMap<>();
            if (userInfoModel.getSecUser().getObjectType().equals(UserObjectTypeEnum.type0.getType())) {
                map.put("companyId" , companyId);
            } else if (userInfoModel.getSecUser().getObjectType().equals(UserObjectTypeEnum.type1.getType())) {
                map.put("companyId", userInfoModel.getBsCompany().getId());
            } else {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, "");
            }
            map.put("createTimeS", createTimeS);
            map.put("createTimeE", createTimeE);
            map.put("payTimeS", payTimeS);
            map.put("payTimeE", payTimeE);
            map.put("finishTimeS", finishTimeS);
            map.put("finishTimeE", finishTimeE);
            map.put("orderNo", orderNo);
            map.put("memPhone", memPhone);
            map.put("memCardNo", memCardNo);
            map.put("productType", productType);
            map.put("status", status);
            map.put("payType", payType);

            PageHelper.startPage(pageNum,pageSize);
            return ResponseMsgUtil.success(new PageInfo<>(orderService.getOrderList(map)));

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

    @RequestMapping(value="/getOrderDetail",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询订单详情")
    public ResponseData getOrderDetail(@RequestParam(name = "orderNo", required = true) String orderNo) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("tradeOrder", orderService.getOrderDetailByNo(orderNo));

            return ResponseMsgUtil.success(map);

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



}
