package com.dxhy.core.job.service.impl;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.core.job.dao.SysUserDao;
import com.dxhy.core.job.entity.SysUserEntity;
import com.dxhy.core.job.service.SysUserService;
import com.dxhy.core.util.HttpRequestUtils;
import com.dxhy.core.util.ObjectUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 系统用户
 *
 */
@Service("sysUserService")
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
    @Value("${license.uid:}")
    private String uid;
    @Value("${license.secret:}")
    private String secret;
    @Value("${license.je:}")
    private String je;
    @Value("${license.licenseUrl:}")
    private String licenseUrl;
    @Value("${signature.url:}")
    private String signatureUrl;
    @Value("${signature.appKey:}")
    private String appKey;
    @Value("${signature.appSecret:}")
    private String appSecret;
    @Value("${signature.tokenUrl:}")
    private String tokenUrl;


    public String getToken() {
        Map<String, String> map = new HashMap<>();
        map.put("appKey", appKey);
        map.put("appSecret", appSecret);
        String requestStr = JSON.toJSONString(map);
        log.info("签章token获取" + requestStr);
        try {
            String responseStr = HttpRequestUtils.httpPost(requestStr, tokenUrl);
            JSONObject jsonObject = JSON.parseObject(responseStr);
            return jsonObject.getString("access_token");
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return null;
        }
    }
}
