package com.yihu.jw.wechat.service;

import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
import com.yihu.jw.entity.base.wx.WxPayLogDO;
import com.yihu.jw.wechat.dao.WxAccessTokenDao;
import com.yihu.jw.wechat.dao.WxPayLogDao;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class WxPayLogService extends BaseJpaService<WxPayLogDO, WxPayLogDao> {

    @Autowired
    private WxPayLogDao wxPayLogDao;

    public void createLog(Map<String,String> map,String orderPar,Map<String,Object> orderRes){

        WxPayLogDO wxPayLogDO = new WxPayLogDO();
        wxPayLogDO.setSeqNo(map.get("out_trade_no"));
        wxPayLogDO.setOpenId(map.get("openid"));
        wxPayLogDO.setType(0);

        wxPayLogDO.setOrderParams(orderPar);
        wxPayLogDO.setOrderResponse(orderRes.get("wxPayResult").toString());
        String return_code = orderRes.get("return_code").toString();
        if("SUCCESS".equalsIgnoreCase(return_code)){
            wxPayLogDO.setOrderStatus(1);
        }else{
            wxPayLogDO.setOrderStatus(-1);
        }
        wxPayLogDO.setCreateTime(new Date());
        wxPayLogDO.setPayStatus(0);
        this.save(wxPayLogDO);
    }


}
