//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hand.app.esignHclc.service.impl;

import com.hand.app.esignHclc.dto.Lm005Hclc;
import com.hand.app.esignHclc.dto.SignInfoHclc;
import com.hand.app.esignHclc.dto.SignInfoHclcFace;
import com.hand.app.esignHclc.mapper.Lm005HclcMapper;
import com.hand.app.esignHclc.service.IOrganSignInfoHclcService;
import com.hand.app.esignHclc.service.ISignInfoHclcFaceService;
import com.hand.app.esignHclc.service.ISignInfoHclcService;
import com.hand.hap.core.IRequest;
import com.hand.hap.system.service.impl.BaseServiceImpl;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SignInfoHclcFaceServiceImpl extends BaseServiceImpl<SignInfoHclcFace> implements ISignInfoHclcFaceService {
    @Autowired
    private ISignInfoHclcService signInfoHclcService;
    @Autowired
    private IOrganSignInfoHclcService organSignInfoHclcService;
    @Autowired
    private Lm005HclcMapper lm005HclcMapper;
    private final Object lock = new Object();

    public SignInfoHclcFaceServiceImpl() {
    }

    public void postAuthResult(IRequest iRequest, JSONObject params) {
        Object var3 = this.lock;
        synchronized(this.lock) {
            SignInfoHclcFace signInfoHclcFace = new SignInfoHclcFace();
            signInfoHclcFace.setFaceauthId(Long.valueOf(params.get("contextId").toString()));
            signInfoHclcFace = (SignInfoHclcFace)this.selectByPrimaryKey(iRequest, signInfoHclcFace);
            if (Objects.nonNull(signInfoHclcFace) && !signInfoHclcFace.getAuthStatus().equalsIgnoreCase("SUCCESS")) {
                SignInfoHclc signInfoHclc = new SignInfoHclc();
                signInfoHclc.setOpenId(signInfoHclcFace.getOpenId());
                signInfoHclc = (SignInfoHclc)this.signInfoHclcService.selectByPrimaryKey(iRequest, signInfoHclc);
                if (params.get("success").toString().equalsIgnoreCase("true")) {
                    signInfoHclcFace.setAuthStatus("SUCCESS");
                    signInfoHclcFace.setVerifyCode(params.get("success").toString());
                    signInfoHclcFace = (SignInfoHclcFace)this.updateByPrimaryKey(iRequest, signInfoHclcFace);
                    if (!signInfoHclc.getFaceauthStatus().equalsIgnoreCase("SUCCESS")) {
                        signInfoHclc.setFaceauthStatus("SUCCESS");
                    }

                    if (signInfoHclcFace.getAuthType().equalsIgnoreCase("2") && !signInfoHclc.getOrgauthStatus().equalsIgnoreCase("SUCCESS")) {
                        signInfoHclc.setOrgauthStatus("SUCCESS");
                    }

                    if (signInfoHclc.getCtitype().compareTo(1L) == 0 || signInfoHclcFace.getAuthType().equalsIgnoreCase("2")) {
                        Lm005Hclc lm005Hclc = new Lm005Hclc();
                        lm005Hclc.setCtino(signInfoHclc.getIdNo());
                        List<Lm005Hclc> lm005Hclcs = this.lm005HclcMapper.select(lm005Hclc);
                        Iterator var8 = lm005Hclcs.iterator();

                        while(var8.hasNext()) {
                            Lm005Hclc hclc = (Lm005Hclc)var8.next();
                            hclc.setOpenId(signInfoHclc.getOpenId());
                            this.lm005HclcMapper.updateByPrimaryKey(hclc);
                        }

                        if (lm005Hclcs.size() > 0) {
                            signInfoHclc.setBindFlag("1");
                        }
                    }

                    signInfoHclc = (SignInfoHclc)this.signInfoHclcService.updateByPrimaryKey(iRequest, signInfoHclc);
                    if (signInfoHclc.getBindFlag().equalsIgnoreCase("Y") && Objects.isNull(signInfoHclc.getAccountId())) {
                        if (signInfoHclc.getCtitype().compareTo(1L) == 0) {
                            this.signInfoHclcService.addPersonAccount(iRequest, signInfoHclc.getOpenId());
                        } else {
                            this.organSignInfoHclcService.addOrgansAccount(iRequest, signInfoHclc.getOpenId());
                        }
                    }
                }
            }

        }
    }
}
