jiangping
2023-12-15 e2b0e215d7f208a8f40aadb5ff05cd0f3088f0d9
server/dmvisit_admin/src/main/java/com/doumee/task/ScheduleTool.java
@@ -2,6 +2,7 @@
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.service.business.impl.hksync.HkSyncImgServiceImpl;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
@@ -29,9 +30,8 @@
@EnableScheduling
public class ScheduleTool {
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    private HkSyncImgServiceImpl hkSyncImgService;
    /**
     * 是否开发者
     */
@@ -43,60 +43,10 @@
     * 缓存省市区
     * @throws Exception
     */
    @Scheduled(fixedDelay=24*60*60*1000)
    public void cacheCampus() throws Exception {
    }
     /**
     * 每天凌晨重置所有订单code类初始值
     * @throws Exception
     */
    @Scheduled(cron="0 0 0 * * ?")
    public void resetOrderCodes() throws Exception {
    @Scheduled(fixedDelay= 60*1000)
    public void downloadHkImg() throws Exception {
        hkSyncImgService.downHKImgs(0);
    }
    /**
     * 发送get请求
     * @param url 请求URL
     * @param param 请求参数 key:value url携带参数 或者无参可不填
     * @return
     */
    public  String doGet(String url, Map<String, String> param) {
        // 创建Httpclient对象
        CloseableHttpClient httpclient = HttpClients.createDefault();
        String resultString = "";
        CloseableHttpResponse response = null;
        try {
            // 创建uri
            URIBuilder builder = new URIBuilder(url);
            if (param != null) {
                for (String key : param.keySet()) {
                    builder.addParameter(key, param.get(key));
                }
            }
            URI uri = builder.build();
            // 创建http GET请求
            HttpGet httpGet = new HttpGet(uri);
            // 执行请求
            response = httpclient.execute(httpGet);
            // 判断返回状态是否为200
            if (response.getStatusLine().getStatusCode() == 200) {
                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (response != null) {
                    response.close();
                }
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return resultString;
    }
}