package com.xhpc.general.service;

import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.general.domain.EtTokenEntity;
import com.xhpc.general.mapper.XhpcEtTokenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * program: ruoyi
 * User: HongYun
 * Date:2021-09-10 14
 */
@Service
public class XhpcTeTokenServiceImpl implements IXhpcEtTokenService {

    @Autowired
    private XhpcEtTokenMapper xhpcEtTokenMapper;

    @Override
    public List<EtTokenEntity> list(String operatorId, String operatorId3irdpty) {

        return xhpcEtTokenMapper.selectBy(operatorId, operatorId3irdpty);
    }

    @Override
    public AjaxResult delete(Integer id) {

        int result = xhpcEtTokenMapper.deleteBy(id);
        return result==1? AjaxResult.success() :AjaxResult.error();
    }

    @Override
    public AjaxResult add(String operatorId, String operatorId3irdpty, String secretTokenType,String dataSecret, String dataSecretiv, String operatorSecret, String sigSecret, Boolean encrypt, String urlPrefix) {

        int checkExistsSign = xhpcEtTokenMapper.checkExistsBy(operatorId, operatorId3irdpty, secretTokenType);
        if(checkExistsSign!=0){
            return AjaxResult.error("该密钥设置已存在");
        }else {
            int result = xhpcEtTokenMapper.insertBy(operatorId, operatorId3irdpty, secretTokenType, dataSecret, dataSecretiv, operatorSecret, sigSecret, encrypt, urlPrefix);
            return result==1? AjaxResult.success():AjaxResult.error();
        }
    }
}
