package com.mortals.xhx.module.member.service.impl;

import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.BaseMapper;
import com.mortals.xhx.busiz.wechat.WechatBaseReq;
import com.mortals.xhx.common.code.OneThingRespCodeEnum;
import com.mortals.xhx.module.member.model.MemberQuery;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.member.dao.MemberDao;
import com.mortals.xhx.module.member.model.MemberEntity;
import com.mortals.xhx.module.member.service.MemberService;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
* <p>Title: 微信会员基本信息</p>
* <p>Description: MemberService service接口 </p>
* <p>Copyright: Copyright &reg;  </p>
* @version 1.0.0
*/
@Service("memberService")
public class MemberServiceImpl extends AbstractCRUDServiceImpl<MemberDao, MemberEntity, Long> implements MemberService {

    @Override
    public void checkMember(WechatBaseReq req) {
        //校验已经存在
        MemberEntity memberEntity = this.selectOne(new MemberQuery().openId(req.getOpenid()), null);
        if (!ObjectUtils.isEmpty(memberEntity)) {
            throw new AppException("已认证登记身份信息");
        }

        //todo 请求外部身份证识别


        MemberEntity entity = BaseMapper.INSTANCE.weChat2Entity(req);
        entity.setCreateTime(new Date());
        entity.setCreateUser("admin");
        this.save(entity);
    }
}