package com.xhpc.payment.service.impl;

import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.utils.SecurityUtils;
import com.xhpc.common.domain.XhpcSettingConfig;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.common.util.LogUserUtils;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.payment.mapper.XhpcSettingConfigMapper;
import com.xhpc.payment.service.IXhpcSettingConfigService;
import com.xhpc.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.security.DenyAll;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yuyang
 * @date 2022/2/14 14:44
 */
@Service
public class XhpcSettingConfigImpl implements IXhpcSettingConfigService {

    @Autowired
    private XhpcSettingConfigMapper xhpcSettingConfigMapper;
    @Autowired
    private LogUserUtils logUserUtils;
    @Autowired
    private TokenService tokenService;

    @Override
    public R insertXhpcSettingConfig(XhpcSettingConfig xhpcSettingConfig) {
        int i = xhpcSettingConfigMapper.insertXhpcSettingConfig(xhpcSettingConfig);
        if(i>0){
            return R.ok();
        }
        return R.fail("保存失败");
    }

    @Override
    public R updateXhpcSettingConfig(XhpcSettingConfig xhpcSettingConfig) {
        int i = xhpcSettingConfigMapper.updateXhpcSettingConfig(xhpcSettingConfig);
        if(i>0){
            return R.ok();
        }
        return R.fail("保存失败");
    }

    @Override
    public Map<String,Object> getXhpcSettingConfigStatus(Integer status) {

        LoginUser logUser = tokenService.getLoginUser();
        if(logUser==null){
            return new HashMap<>();
        }
        String tenantId = logUser.getTenantId();
        return xhpcSettingConfigMapper.getXhpcSettingConfigStatus(status,tenantId);
    }
}
