提交任务框架代码
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.fangjia</groupId>
|
||||
<artifactId>fangjia-job</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<artifactId>fangjia-job-common</artifactId>
|
||||
<name>fangjia-job-common</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.fangjia.job.common.base;
|
||||
|
||||
public class Response {
|
||||
private Boolean status = true;
|
||||
private int code = 200;
|
||||
private String message;
|
||||
private Object data;
|
||||
public Boolean getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(Boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.fangjia.job.common.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 小区分片KEY
|
||||
* @author yinjihuan
|
||||
*/
|
||||
public class DistrictShardingKey {
|
||||
|
||||
public static Map<String, List<String>> provinceCityKeys = new ConcurrentHashMap<String, List<String>>();
|
||||
public static Map<String, List<String>> cityGradeKeys = new ConcurrentHashMap<String, List<String>>();
|
||||
public static Map<String, List<String>> cityZiMuKeys = new ConcurrentHashMap<String, List<String>>();
|
||||
|
||||
static {
|
||||
provinceCityKeys.put("上海", Arrays.asList("上海"));
|
||||
provinceCityKeys.put("云南", Arrays.asList("丽江","大理","临沧","保山","楚雄","西双版纳州","昆明","曲靖","玉溪","昭通","普洱","红河","文山州","德宏州","怒江州","迪庆州"));
|
||||
provinceCityKeys.put("内蒙古", Arrays.asList("呼和浩特","包头","乌海","巴彦淖尔","呼伦贝尔","乌兰察布","赤峰","鄂尔多斯","通辽","兴安盟","锡林郭勒盟","阿拉善盟"));
|
||||
provinceCityKeys.put("北京", Arrays.asList("北京"));
|
||||
provinceCityKeys.put("吉林", Arrays.asList("长春","吉林","松原","延边","四平","辽源","白山","白城","通化"));
|
||||
provinceCityKeys.put("四川", Arrays.asList("成都","绵阳","宜宾","自贡","攀枝花","南充","泸州","资阳","眉山","甘孜州","凉山州","广元","乐山","内江","达州","巴中","遂宁","德阳","广安","雅安","阿坝州"));
|
||||
provinceCityKeys.put("天津", Arrays.asList("天津"));
|
||||
provinceCityKeys.put("宁夏", Arrays.asList("银川","固原","吴忠","中卫","石嘴山"));
|
||||
provinceCityKeys.put("安徽", Arrays.asList("合肥","芜湖","马鞍山","黄山","亳州","六安","淮北","池州","蚌埠","滁州","铜陵","淮南","阜阳","安庆","宣城","宿州"));
|
||||
provinceCityKeys.put("山东", Arrays.asList("烟台","潍坊","临沂","东营","德州","济宁","聊城","莱芜","青岛","济南","威海","淄博","泰安","菏泽","日照","滨州","枣庄"));
|
||||
provinceCityKeys.put("山西", Arrays.asList("太原","临汾","忻州","晋中","阳泉","运城","大同","朔州","长治","吕梁","晋城"));
|
||||
provinceCityKeys.put("广东", Arrays.asList("广州","深圳","东莞","珠海","清远","江门","肇庆","潮州","河源","揭阳","茂名","韶关","梅州","云浮","佛山","中山","湛江","惠州","汕头","阳江","汕尾"));
|
||||
provinceCityKeys.put("广西", Arrays.asList("南宁","桂林","北海","柳州","钦州","百色","来宾","防城港","崇左","贵港","玉林","梧州","河池","贺州"));
|
||||
provinceCityKeys.put("新疆", Arrays.asList("乌鲁木齐","克拉玛依","阿克苏","喀什","昌吉","吐鲁番","哈密","塔城","阿勒泰","博尔塔拉","图木舒克","双河","铁门关","可克达拉","和田","巴音郭楞","克孜勒苏","伊犁","石河子","阿拉尔","五家渠","北屯"));
|
||||
provinceCityKeys.put("江苏", Arrays.asList("扬州","无锡","徐州","镇江","盐城","南京","苏州","常州","南通","泰州","宿迁","连云港","淮安"));
|
||||
provinceCityKeys.put("江西", Arrays.asList("赣州","九江","吉安","新余","萍乡","南昌","景德镇","鹰潭","上饶","宜春","抚州"));
|
||||
provinceCityKeys.put("河北", Arrays.asList("石家庄","唐山","秦皇岛","沧州","张家口","邢台","邯郸","廊坊","保定","衡水","承德"));
|
||||
provinceCityKeys.put("河南", Arrays.asList("洛阳","焦作","平顶山","南阳","开封","信阳","驻马店","漯河","鹤壁","周口","三门峡","济源","郑州","安阳","新乡","许昌","濮阳","商丘"));
|
||||
provinceCityKeys.put("浙江", Arrays.asList("宁波","台州","金华","舟山","杭州","温州","嘉兴","绍兴","湖州","衢州","丽水"));
|
||||
provinceCityKeys.put("海南", Arrays.asList("三亚","三沙","昌江","琼中","五指山","万宁","东方","海口","琼海","乐东","陵水","保亭","儋州","屯昌","澄迈","临高","文昌","白沙","定安"));
|
||||
provinceCityKeys.put("湖北", Arrays.asList("武汉","襄阳","黄石","荆门","咸宁","宜昌","黄冈","鄂州","十堰","随州","孝感","荆州","恩施","仙桃","潜江","天门","神农架"));
|
||||
provinceCityKeys.put("湖南", Arrays.asList("株洲","湘潭","常德","邵阳","益阳","娄底","长沙","张家界","衡阳","岳阳","怀化","郴州","永州","湘西"));
|
||||
provinceCityKeys.put("甘肃", Arrays.asList("定西","白银","酒泉","金昌","陇南","兰州","武威","天水","平凉","张掖","嘉峪关","庆阳","临夏","甘南"));
|
||||
provinceCityKeys.put("福建", Arrays.asList("福州","厦门","宁德","三明","龙岩","泉州","莆田","南平","漳州"));
|
||||
provinceCityKeys.put("西藏", Arrays.asList("拉萨","昌都","日喀则","山南","那曲","阿里","林芝"));
|
||||
provinceCityKeys.put("贵州", Arrays.asList("贵阳","安顺","铜仁","黔西南","六盘水","遵义","毕节","黔东南","黔南"));
|
||||
provinceCityKeys.put("辽宁", Arrays.asList("大连","鞍山","营口","盘锦","本溪","抚顺","沈阳","丹东","铁岭","锦州","朝阳","阜新","葫芦岛","辽阳"));
|
||||
provinceCityKeys.put("重庆", Arrays.asList("重庆"));
|
||||
provinceCityKeys.put("陕西", Arrays.asList("西安","延安","铜川","渭南","商洛","咸阳","汉中","安康","榆林","宝鸡"));
|
||||
provinceCityKeys.put("青海", Arrays.asList("西宁","海东","海北州","黄南州","海南州","玉树州","海西州","果洛州"));
|
||||
provinceCityKeys.put("黑龙江", Arrays.asList("哈尔滨","牡丹江","佳木斯","双鸭山","鹤岗","黑河","大兴安岭","大庆","齐齐哈尔","绥化","鸡西","七台河","伊春"));
|
||||
|
||||
cityGradeKeys.put("1", Arrays.asList("北京","广州","深圳","上海"));
|
||||
cityGradeKeys.put("2", Arrays.asList("成都","西安","重庆","武汉","石家庄","福州","厦门","宁波","大连","无锡","太原","东莞","合肥","贵阳","呼和浩特","哈尔滨","长春","烟台","乌鲁木齐","杭州","南京","天津","沈阳","苏州","长沙","青岛","济南","佛山","郑州","昆明","南昌","兰州","泉州"));
|
||||
cityGradeKeys.put("3", Arrays.asList("扬州","银川","徐州","珠海","吉林","镇江","芜湖","洛阳","桂林","潍坊","西宁","绵阳","株洲","台州","秦皇岛","金华","马鞍山","江门","鞍山","盐城","赣州","柳州","九江","揭阳","茂名","牡丹江","平顶山","本溪","包头","常德","大同","温州","中山","威海","湛江","常州","嘉兴","海口","惠州","邯郸","南通","绍兴","泰州","保定","湖州","连云港","淄博","宜昌","大庆","汕头","衡阳","齐齐哈尔"));
|
||||
cityGradeKeys.put("4", Arrays.asList("三亚","唐山","南宁","襄阳","湘潭","宜宾","自贡","清远","攀枝花","延安","北海","丽江","大理","肇庆","营口","潮州","河源","黄石","焦作","盘锦","韶关","梅州","云浮","舟山","佳木斯","南阳","临沂","临汾","咸阳","廊坊","衢州","宿迁","张家界","六盘水","莆田","玉林","安阳","曲靖","新乡","阳江","玉溪","岳阳","许昌","四平","淮南","淮安","赤峰","榆林"));
|
||||
cityGradeKeys.put("5", Arrays.asList("定西","黄山","安顺","钦州","百色","沧州","东营","德州","亳州","六安","宁德","三沙","临沧","拉萨","南充","泸州","资阳","乌海","邵阳","克拉玛依","巴彦淖尔","荆门","来宾","开封","信阳","固原","驻马店","防城港","铜川","呼伦贝尔","双鸭山","崇左","白银","吉安","鹤岗","海东","黑河","抚顺","张家口","邢台","济宁","聊城","淮北","三明","龙岩","保山","池州","铜仁","乌兰察布","贵港","漯河","松原","眉山","鹤壁","忻州","晋中","益阳","酒泉","新余","周口","莱芜","阳泉","运城","蚌埠","渭南","滁州","铜陵","娄底","咸宁","三门峡","商洛","金昌","陇南","萍乡","吴忠","阿克苏","喀什","昌吉","楚雄","大兴安岭","吐鲁番","哈密","塔城","阿勒泰","博尔塔拉","黔西南","延边","海北州","黄南州","海南州","玉树州","海西州","甘孜州","凉山州","西双版纳州","图木舒克","昌江","济源","琼中","五指山","万宁","东方","双河","铁门关","可克达拉","丹东","遵义","中卫","武威","铁岭","天水","泰安","黄冈","广元","阜阳","辽源","丽水","乐山","菏泽","锦州","汉中","白山","安康","绥化","鄂尔多斯","梧州","鸡西","七台河","白城","朝阳","安庆","朔州","平凉","河池","通化","景德镇","阜新","葫芦岛","衡水","石嘴山","日照","滨州","宣城","宿州","南平","内江","达州","贺州","巴中","昭通","怀化","鄂州","伊春","毕节","十堰","遂宁","郴州","辽阳","宝鸡","张掖","随州","承德","鹰潭","孝感","枣庄","濮阳","嘉峪关","漳州","庆阳","汕尾","上饶","普洱","宜春","德阳","广安","雅安","永州","荆州","商丘","长治","吕梁","抚州","通辽","晋城","和田","巴音郭楞","克孜勒苏","伊犁","红河","昌都","日喀则","山南","那曲","阿里","林芝","兴安盟","锡林郭勒盟","阿拉善盟","临夏","甘南","黔东南","黔南","恩施","湘西","果洛州","阿坝州","文山州","德宏州","怒江州","迪庆州","石河子","仙桃","阿拉尔","琼海","五家渠","潜江","乐东","陵水","保亭","儋州","天门","屯昌","神农架","澄迈","临高","文昌","白沙","定安","北屯"));
|
||||
|
||||
cityZiMuKeys.put("a", Arrays.asList("鞍山","安顺","阿克苏","阿勒泰","安阳","安康","安庆","阿里","阿拉善盟","阿坝州","阿拉尔"));
|
||||
cityZiMuKeys.put("b", Arrays.asList("北京","北海","本溪","包头","百色","亳州","巴彦淖尔","白银","保山","蚌埠","博尔塔拉","保定","白山","白城","滨州","巴中","毕节","宝鸡","巴音郭楞","保亭","白沙","北屯"));
|
||||
cityZiMuKeys.put("c", Arrays.asList("成都","重庆","长春","潮州","常德","沧州","崇左","池州","滁州","昌吉","楚雄","昌江","长沙","常州","赤峰","朝阳","郴州","承德","长治","昌都","澄迈"));
|
||||
cityZiMuKeys.put("d", Arrays.asList("大连","东莞","大理","定西","东营","德州","大同","大兴安岭","东方","大庆","丹东","达州","德阳","德宏州","迪庆州","儋州","定安"));
|
||||
cityZiMuKeys.put("e", Arrays.asList("鄂尔多斯","鄂州","恩施"));
|
||||
cityZiMuKeys.put("f", Arrays.asList("福州","防城港","抚顺","佛山","阜阳","阜新","抚州"));
|
||||
cityZiMuKeys.put("g", Arrays.asList("广州","贵阳","桂林","赣州","固原","贵港","甘孜州","广元","广安","甘南","果洛州"));
|
||||
cityZiMuKeys.put("h", Arrays.asList("合肥","呼和浩特","哈尔滨","河源","黄石","黄山","呼伦贝尔","鹤岗","海东","黑河","淮北","鹤壁","哈密","海北州","黄南州","海南州","海西州","杭州","海口","惠州","邯郸","湖州","衡阳","黄冈","淮南","淮安","菏泽","汉中","河池","葫芦岛","衡水","贺州","怀化","和田","红河"));
|
||||
cityZiMuKeys.put("j", Arrays.asList("吉林","金华","江门","九江","焦作","揭阳","佳木斯","荆门","吉安","济宁","晋中","酒泉","金昌","济源","济南","嘉兴","锦州","鸡西","景德镇","嘉峪关","荆州","晋城"));
|
||||
cityZiMuKeys.put("k", Arrays.asList("克拉玛依","开封","喀什","可克达拉","昆明","克孜勒苏"));
|
||||
cityZiMuKeys.put("l", Arrays.asList("洛阳","柳州","丽江","临沂","临汾","六安","临沧","拉萨","泸州","来宾","聊城","龙岩","漯河","莱芜","娄底","陇南","凉山州","廊坊","兰州","连云港","六盘水","辽源","丽水","乐山","辽阳","吕梁","林芝","临夏","乐东","陵水","临高"));
|
||||
cityZiMuKeys.put("m", Arrays.asList("绵阳","马鞍山","茂名","牡丹江","梅州","眉山"));
|
||||
cityZiMuKeys.put("n", Arrays.asList("宁波","南宁","南阳","宁德","南充","南京","南昌","南通","南平","内江","那曲","怒江州"));
|
||||
cityZiMuKeys.put("p", Arrays.asList("攀枝花","盘锦","平顶山","萍乡","莆田","平凉","濮阳","普洱"));
|
||||
cityZiMuKeys.put("q", Arrays.asList("清远","秦皇岛","钦州","黔西南","琼中","青岛","衢州","泉州","曲靖","齐齐哈尔","七台河","庆阳","黔东南","黔南","琼海","潜江"));
|
||||
cityZiMuKeys.put("r", Arrays.asList("日照","日喀则"));
|
||||
cityZiMuKeys.put("s", Arrays.asList("深圳","石家庄","三亚","韶关","三沙","邵阳","双鸭山","三明","松原","三门峡","商洛","双河","上海","沈阳","苏州","绍兴","宿迁","汕头","四平","绥化","朔州","石嘴山","宿州","十堰","遂宁","随州","汕尾","上饶","商丘","山南","石河子","神农架"));
|
||||
cityZiMuKeys.put("t", Arrays.asList("太原","唐山","台州","铜川","铜仁","铜陵","吐鲁番","塔城","图木舒克","铁门关","天津","泰州","铁岭","天水","泰安","通化","通辽","天门","屯昌"));
|
||||
cityZiMuKeys.put("w", Arrays.asList("全国","武汉","无锡","芜湖","潍坊","乌海","乌兰察布","渭南","吴忠","五指山","万宁","温州","威海","武威","梧州","文山州","五家渠","文昌"));
|
||||
cityZiMuKeys.put("x", Arrays.asList("西安","厦门","徐州","西宁","襄阳","湘潭","乌鲁木齐","信阳","邢台","忻州","新余","咸宁","西双版纳州","咸阳","新乡","许昌","宣城","孝感","兴安盟","锡林郭勒盟","湘西","仙桃"));
|
||||
cityZiMuKeys.put("y", Arrays.asList("扬州","银川","烟台","宜宾","盐城","延安","营口","云浮","益阳","阳泉","运城","延边","玉树州","宜昌","玉林","阳江","玉溪","岳阳","榆林","伊春","鹰潭","宜春","雅安","永州","伊犁"));
|
||||
cityZiMuKeys.put("z", Arrays.asList("珠海","镇江","株洲","自贡","肇庆","舟山","资阳","驻马店","张家口","周口","郑州","中山","湛江","淄博","张家界","遵义","中卫","昭通","张掖","枣庄","漳州"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.fangjia.job.common.core;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import feign.Response;
|
||||
import feign.Util;
|
||||
import feign.codec.Decoder;
|
||||
|
||||
/**
|
||||
* Feign调用Rest API解码用
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class JacksonDecoder implements Decoder {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public JacksonDecoder() {
|
||||
this(Collections.<Module> emptyList());
|
||||
}
|
||||
|
||||
public JacksonDecoder(Iterable<Module> modules) {
|
||||
this(new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModules(modules));
|
||||
}
|
||||
|
||||
public JacksonDecoder(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public Object decode(Response response, Type type) throws IOException {
|
||||
if (response.status() == 404)
|
||||
return Util.emptyValueOf(type);
|
||||
if (response.body() == null)
|
||||
return null;
|
||||
Reader reader = response.body().asReader();
|
||||
if (!reader.markSupported()) {
|
||||
reader = new BufferedReader(reader, 1);
|
||||
}
|
||||
try {
|
||||
// Read the first byte to see if we have any data
|
||||
reader.mark(1);
|
||||
if (reader.read() == -1) {
|
||||
return null; // Eagerly returning null avoids "No content to map
|
||||
// due to end-of-input"
|
||||
}
|
||||
reader.reset();
|
||||
return mapper.readValue(reader, mapper.constructType(type));
|
||||
} catch (RuntimeJsonMappingException e) {
|
||||
if (e.getCause() != null && e.getCause() instanceof IOException) {
|
||||
throw IOException.class.cast(e.getCause());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.fangjia.job.common.core;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import feign.RequestTemplate;
|
||||
import feign.codec.EncodeException;
|
||||
import feign.codec.Encoder;
|
||||
/**
|
||||
* Feign调用Rest API编码用
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class JacksonEncoder implements Encoder {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public JacksonEncoder() {
|
||||
this(Collections.<Module> emptyList());
|
||||
}
|
||||
|
||||
public JacksonEncoder(Iterable<Module> modules) {
|
||||
this(new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.configure(SerializationFeature.INDENT_OUTPUT, true).registerModules(modules));
|
||||
}
|
||||
|
||||
public JacksonEncoder(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public void encode(Object object, Type bodyType, RequestTemplate template) {
|
||||
try {
|
||||
JavaType javaType = mapper.getTypeFactory().constructType(bodyType);
|
||||
template.body(mapper.writerFor(javaType).writeValueAsString(object));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new EncodeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.fangjia.job.common.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
public class DateUtilCustom {
|
||||
/**
|
||||
* 获取昨天的时间范围
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getYesterday() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
DateTime dt = new DateTime();
|
||||
// 昨天
|
||||
DateTime yesterday = dt.minusDays(1);
|
||||
String start = yesterday.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
String end = dt.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
map.put("start", start);
|
||||
map.put("end", end);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月时间范围,截止到当前时间那天
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getCurrentMonth() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
DateTime dt = new DateTime();
|
||||
// 获取当前时间月的第一天
|
||||
LocalDate firstDayOfMonth = dt.toLocalDate().withDayOfMonth(1);
|
||||
String start = firstDayOfMonth.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
String end = dt.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
map.put("start", start);
|
||||
map.put("end", end);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上月时间范围
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getTopMonth() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
DateTime dt = new DateTime();
|
||||
LocalDate d = LocalDate.now();
|
||||
LocalDate lastDayOfPreviousMonth = d.minusMonths(1).dayOfMonth().withMinimumValue();
|
||||
String start = lastDayOfPreviousMonth.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
// 获取当前时间月的第一天
|
||||
LocalDate firstDayOfMonth = dt.toLocalDate().withDayOfMonth(1);
|
||||
String end = firstDayOfMonth.toString("yyyy-MM-dd") + " 00:00:00";
|
||||
map.put("start", start);
|
||||
map.put("end", end);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
getTopMonth();
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.fangjia.job.common.util;
|
||||
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
/**
|
||||
* 钉钉机器人发送消息
|
||||
* https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class DingDingMessageUtil {
|
||||
public static String access_token = "899b3d41c3b235684339e6b6d40333f3f522e513df923e9a5771a704287cef16";
|
||||
|
||||
public static void sendTextMessage(String access_token, String msg) {
|
||||
try {
|
||||
Message message = new Message();
|
||||
message.setMsgtype("text");
|
||||
message.setText(new MessageInfo(msg));
|
||||
DingDingRemoteApi client = RestApiCallUtils.getRestClient(DingDingRemoteApi.class, "https://oapi.dingtalk.com");
|
||||
client.send(access_token, message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendTextMessage(String msg) {
|
||||
try {
|
||||
Message message = new Message();
|
||||
message.setMsgtype("text");
|
||||
message.setText(new MessageInfo(msg));
|
||||
DingDingRemoteApi client = RestApiCallUtils.getRestClient(DingDingRemoteApi.class, "https://oapi.dingtalk.com");
|
||||
client.send(access_token, message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Message {
|
||||
private String msgtype;
|
||||
private MessageInfo text;
|
||||
public String getMsgtype() {
|
||||
return msgtype;
|
||||
}
|
||||
public void setMsgtype(String msgtype) {
|
||||
this.msgtype = msgtype;
|
||||
}
|
||||
public MessageInfo getText() {
|
||||
return text;
|
||||
}
|
||||
public void setText(MessageInfo text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
class MessageInfo {
|
||||
private String content;
|
||||
public MessageInfo(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
interface DingDingRemoteApi {
|
||||
|
||||
@RequestLine("POST /robot/send?access_token={access_token}")
|
||||
@Headers("Content-Type: application/json")
|
||||
public void send(@Param("access_token") String access_token, Message message);
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.fangjia.job.common.util;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
/**
|
||||
* Json 工具类
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class JsonUtils {
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public static String toString(Object obj){
|
||||
return toJson(obj);
|
||||
}
|
||||
|
||||
public static String toJson(Object obj){
|
||||
try{
|
||||
StringWriter writer = new StringWriter();
|
||||
mapper.writeValue(writer, obj);
|
||||
return writer.toString();
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException("序列化对象【"+obj+"】时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T toBean(Class<T> entityClass, String jsonString){
|
||||
try {
|
||||
return mapper.readValue(jsonString, entityClass);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON【"+jsonString+"】转对象时出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于对象通过其他工具已转为JSON的字符形式,这里不需要再加上引号
|
||||
* @param obj
|
||||
* @param isObject
|
||||
*/
|
||||
public static String getJsonSuccess(Object obj){
|
||||
String jsonString = null;
|
||||
if(obj == null){
|
||||
jsonString = "{\"success\":true}";
|
||||
}else{
|
||||
jsonString = "{\"success\":true,\"data\":"+toJson(obj)+"}";
|
||||
}
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
/*public static String getJsonSuccess(Object obj){
|
||||
return getJsonSuccess(obj, null);
|
||||
}*/
|
||||
|
||||
public static String getJsonSuccess(Object obj, String message) {
|
||||
if(obj == null){
|
||||
return "{\"success\":true,\"message\":\""+message+"\"}";
|
||||
}else{
|
||||
try{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("success", true);
|
||||
return "{\"success\":true,"+toString(obj)+",\"message\":\""+message+"\"}";
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException("序列化对象【"+obj+"】时出错", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getJsonError(Object obj){
|
||||
return getJsonError(obj, null);
|
||||
}
|
||||
|
||||
public static String getJsonError(Object obj, String message) {
|
||||
if(obj == null){
|
||||
return "{\"success\":false,\"message\":\""+message+"\"}";
|
||||
}else{
|
||||
try{
|
||||
obj = parseIfException(obj);
|
||||
return "{\"success\":false,\"data\":"+toString(obj)+",\"message\":\""+message+"\"}";
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException("序列化对象【"+obj+"】时出错", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Object parseIfException(Object obj){
|
||||
if(obj instanceof Exception){
|
||||
return getErrorMessage((Exception) obj, null);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static String getErrorMessage(Exception e, String defaultMessage){
|
||||
return defaultMessage != null ? defaultMessage : null;
|
||||
}
|
||||
|
||||
public static ObjectMapper getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.fangjia.job.common.util;
|
||||
|
||||
import com.fangjia.job.common.core.JacksonDecoder;
|
||||
import com.fangjia.job.common.core.JacksonEncoder;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
|
||||
/**
|
||||
* Rest API 调用工具类<br>
|
||||
* 文档:https://github.com/OpenFeign/feign
|
||||
*
|
||||
* @author yinjihuan
|
||||
*
|
||||
*/
|
||||
public class RestApiCallUtils {
|
||||
|
||||
/**
|
||||
* 获取API 接口代理对象
|
||||
* @param apiType 接口类
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getRestClient(Class<T> apiType, String url) {
|
||||
return Feign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
|
||||
.logger(new Logger.JavaLogger().appendToFile("D:\\logs\\fangjia-job-http.log"))
|
||||
.logLevel(Logger.Level.FULL)
|
||||
.target(apiType, url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.fangjia.job.common;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user