Commit d7abe822 authored by 张俊's avatar 张俊

单位变更开发

parent d65819ed
package net.cdkj.gjj.adapter.config;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
/**
* 把RestTemplate注入Spring IOC容器
*
* @author cr949
*/
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
RestTemplate restTemplate = restTemplateBuilder.build();
// 设置HTTP request (请求)和response (响应)的转换器
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
//错误响应处理
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(HttpStatus statusCode) {
return true;
}
@Override
public void handleError(ClientHttpResponse response) {
}
});
return restTemplate;
}
}
\ No newline at end of file
package net.cdkj.gjj.adapter.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
public class InternalUtils {
/**
* 判断一个实体对象是否为空
*
* @param obj
* @return
*/
public static boolean isNullOrEmpty(Object obj) {
if (obj == null)
return true;
if (obj instanceof CharSequence)
return ((CharSequence) obj).length() == 0;
if (obj instanceof Collection)
return ((Collection) obj).isEmpty();
if (obj instanceof Map)
return ((Map) obj).isEmpty();
if (obj instanceof Object[]) {
Object[] object = (Object[]) obj;
if (object.length == 0) {
return true;
}
boolean empty = true;
for (int i = 0; i < object.length; i++) {
if (!isNullOrEmpty(object[i])) {
empty = false;
break;
}
}
return empty;
}
return false;
}
/**
* 获取当天零点零分零秒的时间戳和当天24点的时间戳
*
* @return
*/
public static String currentTime(int type) {
String time = null;
if (type == 0) {
// 获取当天零点零分零秒的时间戳
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 0);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
time = df2.format(curentDay.getTime().getTime());
System.out.println(time);
} else if (type == 24) {
// 获取当天24点零分零秒的时间戳,即第二天零点时间
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 24);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
time = df2.format(curentDay.getTime().getTime());
System.out.println(time);
}
return time;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment