package com.hwrj.cloud.admin.service.impl;

import com.hwrj.cloud.admin.mapper.UmsMemberPlatformMapper;
import com.hwrj.cloud.admin.model.UmsMemberPlatform;
import com.hwrj.cloud.admin.model.UmsMemberPlatformExample;
import com.hwrj.cloud.admin.service.UmsMemberPlatformService;
import com.hwrj.cloud.security.util.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import java.util.List;

public class UmsMemberPlatformServiceImpl implements UmsMemberPlatformService {
    @Autowired
    private UmsMemberPlatformMapper umsMemberPlatformMapper;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Override
    public int addUmsMemberPlatformService(UmsMemberPlatform umsMemberPlatform) {
        UmsMemberPlatformExample example= new UmsMemberPlatformExample();
        UmsMemberPlatformExample.Criteria criteria = example.createCriteria();
        criteria.andOpenidEqualTo(umsMemberPlatform.getOpenid());
        if (!StringUtils.isEmpty(umsMemberPlatform.getUnionid())){
            criteria.andUnionidEqualTo(umsMemberPlatform.getUnionid());
        }
        List<UmsMemberPlatform> umsMemberPlatforms = umsMemberPlatformMapper.selectByExample(example);
        if (umsMemberPlatforms != null && umsMemberPlatforms.size()>1){
            UmsMemberPlatform umsMemberPlatform1 = umsMemberPlatforms.get(0);

        }else {
            int insert = umsMemberPlatformMapper.insert(umsMemberPlatform);

            if (insert>0){
                UmsMemberPlatformExample example1= new UmsMemberPlatformExample();
                UmsMemberPlatformExample.Criteria criteria1 = example.createCriteria();
                criteria1.andOpenidEqualTo(umsMemberPlatform.getOpenid());
                if (!StringUtils.isEmpty(umsMemberPlatform.getUnionid())){
                    criteria1.andUnionidEqualTo(umsMemberPlatform.getUnionid());
                }
                List<UmsMemberPlatform> umsMemberPlatforms1 = umsMemberPlatformMapper.selectByExample(example);
                UmsMemberPlatform umsMemberPlatform1 = umsMemberPlatforms1.get(0);

            }
        }
        return 0;
    }
}
