package com.zjrs.ggfw.dzsbk.blo.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.mohrss.leaf.core.framework.domain.blo.impl.BLOImpl;
import com.zjrs.ggfw.dzsbk.blo.SignBLO;
import com.zjrs.ggfw.dzsbk.entity.RsInterfaceLogMapper;
import com.zjrs.ggfw.dzsbk.entity.VRsDzsbkQfMapper;
import com.zjrs.ggfw.dzsbk.po.RsInterfaceLog;
import com.zjrs.ggfw.dzsbk.po.VRsDzsbkQf;
import com.zjrs.ggfw.portal.entity.VRsGgfwUserMapper;
import com.zjrs.ggfw.portal.po.VRsGgfwUser;
import org.springframework.stereotype.Service;

@Service
public class SignBLOImpl extends BLOImpl implements SignBLO {

    @Resource
    VRsDzsbkQfMapper vRsDzsbkQfMapper;
    
    @Resource
    VRsGgfwUserMapper vRsGgfwUserMapper;
    
    @Resource
    RsInterfaceLogMapper rsInterfaceLogMapper;
    
    @Override
    public VRsDzsbkQf getRsDzsbkQf(String userid,String channelNo) {
    	QueryWrapper<VRsDzsbkQf> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("userid", userid);//用户ID
    	queryWrapper.eq("rownum", 1);
    	return vRsDzsbkQfMapper.selectOne(queryWrapper);
    }
    
    @Override
    public void saveRsDzsbkQf(VRsDzsbkQf vRsDzsbkQf) {
    	if(StringUtils.isNotBlank(vRsDzsbkQf.getRsDzsbkQfLsh())) {
    		vRsDzsbkQfMapper.updateById(vRsDzsbkQf);
    	}else {
    		vRsDzsbkQfMapper.insert(vRsDzsbkQf);
    	}
    }
    
    @Override
    public VRsDzsbkQf getWeChatRsDzsbkQf(String openid,String channelNo) {
    	QueryWrapper<VRsDzsbkQf> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("openid", openid);//微信公众号用户ID
    	queryWrapper.eq("rownum", 1);
    	return vRsDzsbkQfMapper.selectOne(queryWrapper);
    }
    
    @Override
    public VRsDzsbkQf getWeChatRsDzsbkQfByAuth(String authToken) {
    	QueryWrapper<VRsDzsbkQf> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("auth_token", authToken);//微信实名授权
    	queryWrapper.eq("rownum", 1);
    	return vRsDzsbkQfMapper.selectOne(queryWrapper);
    }
    
    @Override
    public VRsGgfwUser saveRsGgfwUser(VRsGgfwUser vRsGgfwUser) {
    	QueryWrapper<VRsGgfwUser> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("zjlx", vRsGgfwUser.getZjlx());
    	queryWrapper.eq("zjhm", vRsGgfwUser.getZjhm());
    	queryWrapper.eq("rownum", 1);
    	VRsGgfwUser VRsGgfwUserTmp = vRsGgfwUserMapper.selectOne(queryWrapper);
    	if(VRsGgfwUserTmp != null) {
    		vRsGgfwUser.setUserid(VRsGgfwUserTmp.getUserid());
    		vRsGgfwUserMapper.updateById(vRsGgfwUser);
    	}
    	return vRsGgfwUser;
    }
    
    @Override
    public void saveRsInterfaceLog(RsInterfaceLog rsInterfaceLog) {
    	if(StringUtils.isNotBlank(rsInterfaceLog.getRsInterfaceLogLsh())) {
    		rsInterfaceLogMapper.updateById(rsInterfaceLog);
    	}
    }
}    