Showing
20 changed files
with
1884 additions
and
70 deletions
| ... | @@ -29,11 +29,12 @@ INSERT INTO T_ICLEAR_API_APPINFO VALUES(1,'CTM','iClearExport','b92131f03f19a348 | ... | @@ -29,11 +29,12 @@ INSERT INTO T_ICLEAR_API_APPINFO VALUES(1,'CTM','iClearExport','b92131f03f19a348 |
| 29 | 29 | ||
| 30 | CREATE TABLE T_ICLEAR_API_LOG( | 30 | CREATE TABLE T_ICLEAR_API_LOG( |
| 31 | MSGID int identity(1,1) primary key --PK | 31 | MSGID int identity(1,1) primary key --PK |
| 32 | - ,MSG_TYPE VARCHAR(20) --类型 | 32 | + ,MSG_TYPE VARCHAR(20) --类型: C D |
| 33 | ,APPID VARCHAR(20) --用户ID | 33 | ,APPID VARCHAR(20) --用户ID |
| 34 | ,APPKEY VARCHAR(20) --用户key | 34 | ,APPKEY VARCHAR(20) --用户key |
| 35 | ,CREATE_TIME datetime --创建时间 | 35 | ,CREATE_TIME datetime --创建时间 |
| 36 | ,UPDATE_TIME datetime --更新时间 | 36 | ,UPDATE_TIME datetime --更新时间 |
| 37 | + ,PUSH_TIME datetime --消息推送时间 | ||
| 37 | --,REQUEST_MSG VARCHAR(500) | 38 | --,REQUEST_MSG VARCHAR(500) |
| 38 | ,RECEIVE_RESULT VARCHAR(100) --记录接收后是否验证通过的结果 | 39 | ,RECEIVE_RESULT VARCHAR(100) --记录接收后是否验证通过的结果 |
| 39 | ,RESPONSE_TIME datetime -- 响应时间 | 40 | ,RESPONSE_TIME datetime -- 响应时间 | ... | ... |
No preview for this file type
| ... | @@ -3,11 +3,9 @@ package com.erry.iclear.dateInterface.api; | ... | @@ -3,11 +3,9 @@ package com.erry.iclear.dateInterface.api; |
| 3 | import com.erry.iclear.dateInterface.api.request.Mawb; | 3 | import com.erry.iclear.dateInterface.api.request.Mawb; |
| 4 | import com.erry.iclear.dateInterface.api.response.ResultRS; | 4 | import com.erry.iclear.dateInterface.api.response.ResultRS; |
| 5 | import com.erry.iclear.dateInterface.common.Constant; | 5 | import com.erry.iclear.dateInterface.common.Constant; |
| 6 | -import com.erry.iclear.dateInterface.entity.ChmConsignment; | ||
| 7 | -import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail; | ||
| 8 | import com.erry.iclear.dateInterface.entity.IClearApiLog; | 6 | import com.erry.iclear.dateInterface.entity.IClearApiLog; |
| 9 | import com.erry.iclear.dateInterface.service.*; | 7 | import com.erry.iclear.dateInterface.service.*; |
| 10 | -import com.erry.iclear.dateInterface.util.MD5Util; | 8 | +import com.erry.iclear.dateInterface.util.DateUtils; |
| 11 | import com.erry.iclear.dateInterface.util.SHA256Util; | 9 | import com.erry.iclear.dateInterface.util.SHA256Util; |
| 12 | import com.google.gson.Gson; | 10 | import com.google.gson.Gson; |
| 13 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
| ... | @@ -65,8 +63,9 @@ public class CustomsDataInterface { | ... | @@ -65,8 +63,9 @@ public class CustomsDataInterface { |
| 65 | sw.start("save log"); | 63 | sw.start("save log"); |
| 66 | 64 | ||
| 67 | String appId=(String) request.getHeader("Appid"); | 65 | String appId=(String) request.getHeader("Appid"); |
| 68 | - String appkey=(String) request.getHeader("Appkey"); | 66 | + String appKey=(String) request.getHeader("Appkey"); |
| 69 | - IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLog(mawb,appId,appkey)); | 67 | + String timeStamp=(String) request.getHeader("TimeStamp"); |
| 68 | + IClearApiLog saveIClearApiLogResult = iClearApiLogService.saveIClearApiLog(iClearApiLogService.convertToIClearApiLog(mawb,appId,appKey,DateUtils.convertToDate(timeStamp))); | ||
| 70 | 69 | ||
| 71 | 70 | ||
| 72 | if(!Objects.equals(saveIClearApiLogResult,null)){ | 71 | if(!Objects.equals(saveIClearApiLogResult,null)){ |
| ... | @@ -110,22 +109,10 @@ public class CustomsDataInterface { | ... | @@ -110,22 +109,10 @@ public class CustomsDataInterface { |
| 110 | 109 | ||
| 111 | 110 | ||
| 112 | //4、保存运单到iclear中 | 111 | //4、保存运单到iclear中 |
| 112 | + | ||
| 113 | sw.start("saveToIClear"); | 113 | sw.start("saveToIClear"); |
| 114 | if(result.getSuccess()==true){ | 114 | if(result.getSuccess()==true){ |
| 115 | - ChmConsignment chmConsignment=chmConsignmentService.convertToChmConsignment(mawb); | 115 | + chmConsignmentService.processChmConsignment(mawb, timeStamp); |
| 116 | - List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>(); | ||
| 117 | - mawb.getMawbDetailList().forEach(detail ->{ | ||
| 118 | - chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail)); | ||
| 119 | - }); | ||
| 120 | - chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList); | ||
| 121 | - | ||
| 122 | - ChmConsignment chmConsignmentSaveResult = chmConsignmentService.saveChmConsignment(chmConsignment); | ||
| 123 | - | ||
| 124 | - if(!Objects.equals(chmConsignmentSaveResult,null)){ | ||
| 125 | - log.info("主单"+mawb.getBillNo()+" 保存成功,chmConsignmentId:"+chmConsignmentSaveResult.getId()); | ||
| 126 | - }else{ | ||
| 127 | - log.info("主单"+mawb.getBillNo()+" 保存失败"); | ||
| 128 | - } | ||
| 129 | } | 116 | } |
| 130 | sw.stop(); | 117 | sw.stop(); |
| 131 | 118 | ||
| ... | @@ -150,6 +137,8 @@ public class CustomsDataInterface { | ... | @@ -150,6 +137,8 @@ public class CustomsDataInterface { |
| 150 | } | 137 | } |
| 151 | 138 | ||
| 152 | 139 | ||
| 140 | + | ||
| 141 | + | ||
| 153 | /** | 142 | /** |
| 154 | * 校验用户 | 143 | * 校验用户 |
| 155 | * @param request | 144 | * @param request |
| ... | @@ -220,6 +209,21 @@ public class CustomsDataInterface { | ... | @@ -220,6 +209,21 @@ public class CustomsDataInterface { |
| 220 | } | 209 | } |
| 221 | 210 | ||
| 222 | 211 | ||
| 212 | + /** | ||
| 213 | + * 检查状态是否小于已报关 | ||
| 214 | + * @param statusCode | ||
| 215 | + * @return | ||
| 216 | + * true:报关之前 | ||
| 217 | + * false:报关之后 | ||
| 218 | + */ | ||
| 219 | + private boolean compareStatusCode(String statusCode){ | ||
| 220 | + | ||
| 221 | + | ||
| 222 | + return false; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + | ||
| 226 | + | ||
| 223 | } | 227 | } |
| 224 | 228 | ||
| 225 | 229 | ... | ... |
| ... | @@ -47,5 +47,9 @@ public class Constant { | ... | @@ -47,5 +47,9 @@ public class Constant { |
| 47 | 47 | ||
| 48 | public static String NEW_PACKAGE_TYPE = "NewPackageType_"; | 48 | public static String NEW_PACKAGE_TYPE = "NewPackageType_"; |
| 49 | 49 | ||
| 50 | + public static String TRANSFER_WAY_BILL_STATUS = "transferWaybillStatus_"; | ||
| 51 | + | ||
| 52 | + public static String SUPERVISION_MODE ="supervisionMode_"; | ||
| 53 | + | ||
| 50 | 54 | ||
| 51 | } | 55 | } | ... | ... |
| 1 | package com.erry.iclear.dateInterface.entity; | 1 | package com.erry.iclear.dateInterface.entity; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import com.erry.iclear.dateInterface.api.request.MawbDetail; | ||
| 5 | import com.fasterxml.jackson.annotation.JsonIgnore; | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 6 | import lombok.Data; | 5 | import lombok.Data; |
| 7 | import org.springframework.format.annotation.DateTimeFormat; | 6 | import org.springframework.format.annotation.DateTimeFormat; |
| ... | @@ -28,7 +27,7 @@ public class ChmConsignment implements Serializable { | ... | @@ -28,7 +27,7 @@ public class ChmConsignment implements Serializable { |
| 28 | * 运单表ID,自动增加 | 27 | * 运单表ID,自动增加 |
| 29 | */ | 28 | */ |
| 30 | @Id | 29 | @Id |
| 31 | - @GeneratedValue | 30 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 32 | @Column(name = "ID") | 31 | @Column(name = "ID") |
| 33 | private Long id; | 32 | private Long id; |
| 34 | 33 | ... | ... |
| ... | @@ -24,7 +24,7 @@ public class ChmConsignmentDetail implements Serializable { | ... | @@ -24,7 +24,7 @@ public class ChmConsignmentDetail implements Serializable { |
| 24 | * 运单明细表ID,自动增加 | 24 | * 运单明细表ID,自动增加 |
| 25 | */ | 25 | */ |
| 26 | @Id | 26 | @Id |
| 27 | - @GeneratedValue | 27 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 28 | @Column(name = "ID") | 28 | @Column(name = "ID") |
| 29 | private Long id; | 29 | private Long id; |
| 30 | 30 | ... | ... |
| ... | @@ -20,47 +20,52 @@ public class DictionaryEntries implements Serializable { | ... | @@ -20,47 +20,52 @@ public class DictionaryEntries implements Serializable { |
| 20 | 20 | ||
| 21 | private static final long serialVersionUID = -8423170334642989557L; | 21 | private static final long serialVersionUID = -8423170334642989557L; |
| 22 | @Id | 22 | @Id |
| 23 | + @GeneratedValue | ||
| 23 | @Column(name = "ID") | 24 | @Column(name = "ID") |
| 24 | private Long id; | 25 | private Long id; |
| 25 | 26 | ||
| 26 | @Column(name = "CODE") | 27 | @Column(name = "CODE") |
| 27 | private String code; | 28 | private String code; |
| 28 | 29 | ||
| 29 | - @Column(name = "DICT_CODE") | ||
| 30 | - private String dictCode; | ||
| 31 | - | ||
| 32 | @Column(name = "CHINESE_NAME") | 30 | @Column(name = "CHINESE_NAME") |
| 33 | private String chineseName; | 31 | private String chineseName; |
| 34 | 32 | ||
| 35 | - @Column(name = "ENGLISH_NAME") | ||
| 36 | - private String englishName; | ||
| 37 | - | ||
| 38 | - @Column(name = "DESCRIPTION") | ||
| 39 | - private String description; | ||
| 40 | - | ||
| 41 | - @Column(name = "STATUS") | ||
| 42 | - private Integer status; | ||
| 43 | - | ||
| 44 | - @Column(name = "EXT1") | ||
| 45 | - private Integer ext1; | ||
| 46 | - | ||
| 47 | - @Column(name = "EXT2") | ||
| 48 | - private String ext2; | ||
| 49 | - | ||
| 50 | - @Column(name = "EXT3") | ||
| 51 | - private String ext3; | ||
| 52 | - | ||
| 53 | - @Column(name = "EXT4") | ||
| 54 | - private BigDecimal ext4; | ||
| 55 | - | ||
| 56 | - @Column(name = "EXT5") | ||
| 57 | - private Integer ext5; | ||
| 58 | - | ||
| 59 | - @Column(name = "ORDINAL") | ||
| 60 | - private Integer ordinal; | ||
| 61 | 33 | ||
| 62 | - @Column(name = "EXT6") | 34 | +// @Column(name = "DICT_CODE") |
| 63 | - private String ext6; | 35 | +// private String dictCode; |
| 36 | +// | ||
| 37 | +// @Column(name = "ENGLISH_NAME") | ||
| 38 | +// private String englishName; | ||
| 39 | +// | ||
| 40 | +// @Column(name = "DESCRIPTION") | ||
| 41 | +// private String description; | ||
| 42 | +// | ||
| 43 | +// @Column(name = "STATUS") | ||
| 44 | +// private Integer status; | ||
| 45 | +// | ||
| 46 | +// @Column(name="DICT_ID") | ||
| 47 | +// private String dictId; | ||
| 48 | +// | ||
| 49 | +// @Column(name = "EXT1") | ||
| 50 | +// private Integer ext1; | ||
| 51 | +// | ||
| 52 | +// @Column(name = "EXT2") | ||
| 53 | +// private String ext2; | ||
| 54 | +// | ||
| 55 | +// @Column(name = "EXT3") | ||
| 56 | +// private String ext3; | ||
| 57 | +// | ||
| 58 | +// @Column(name = "EXT4") | ||
| 59 | +// private BigDecimal ext4; | ||
| 60 | +// | ||
| 61 | +// @Column(name = "EXT5") | ||
| 62 | +// private Integer ext5; | ||
| 63 | +// | ||
| 64 | +// @Column(name = "ORDINAL") | ||
| 65 | +// private Integer ordinal; | ||
| 66 | +// | ||
| 67 | +// @Column(name = "EXT6") | ||
| 68 | +// private String ext6; | ||
| 64 | 69 | ||
| 65 | 70 | ||
| 66 | } | 71 | } | ... | ... |
| ... | @@ -38,6 +38,8 @@ public class IClearApiLog implements Serializable { | ... | @@ -38,6 +38,8 @@ public class IClearApiLog implements Serializable { |
| 38 | //收到的json,用 T_ICLEAR_API_MAWB表保存 | 38 | //收到的json,用 T_ICLEAR_API_MAWB表保存 |
| 39 | //@Column(name= "REQUEST_MSG") | 39 | //@Column(name= "REQUEST_MSG") |
| 40 | //private String request_msg; | 40 | //private String request_msg; |
| 41 | + @Column(name= "PUSH_TIME") | ||
| 42 | + private Date pushTime; | ||
| 41 | 43 | ||
| 42 | @Column(name= "RECEIVE_RESULT") | 44 | @Column(name= "RECEIVE_RESULT") |
| 43 | private String receiveResult; | 45 | private String receiveResult; | ... | ... |
| ... | @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ... | @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.context.ApplicationContext; | 10 | import org.springframework.context.ApplicationContext; |
| 11 | import org.springframework.context.ApplicationContextAware; | 11 | import org.springframework.context.ApplicationContextAware; |
| 12 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 13 | +import org.springframework.util.StopWatch; | ||
| 13 | 14 | ||
| 14 | import java.util.HashMap; | 15 | import java.util.HashMap; |
| 15 | import java.util.List; | 16 | import java.util.List; |
| ... | @@ -48,6 +49,8 @@ public class IClearApiSystemInit implements InitializingBean, ApplicationContext | ... | @@ -48,6 +49,8 @@ public class IClearApiSystemInit implements InitializingBean, ApplicationContext |
| 48 | @Override | 49 | @Override |
| 49 | public void afterPropertiesSet() throws Exception { | 50 | public void afterPropertiesSet() throws Exception { |
| 50 | try{ | 51 | try{ |
| 52 | + StopWatch sw = new StopWatch("initSystemCache"); | ||
| 53 | + sw.start("initCache"); | ||
| 51 | log.info("init initAppInfo start>>>>>>>>>"); | 54 | log.info("init initAppInfo start>>>>>>>>>"); |
| 52 | appInfoService.initAppInfo(); | 55 | appInfoService.initAppInfo(); |
| 53 | log.info("init initAppInfo end>>>>>>>>>"); | 56 | log.info("init initAppInfo end>>>>>>>>>"); |
| ... | @@ -68,6 +71,8 @@ public class IClearApiSystemInit implements InitializingBean, ApplicationContext | ... | @@ -68,6 +71,8 @@ public class IClearApiSystemInit implements InitializingBean, ApplicationContext |
| 68 | chmCarryPortService.initChmCarryPort(); | 71 | chmCarryPortService.initChmCarryPort(); |
| 69 | log.info("init initChmCarryPort start>>>>>>>>>"); | 72 | log.info("init initChmCarryPort start>>>>>>>>>"); |
| 70 | 73 | ||
| 74 | + sw.stop(); | ||
| 75 | + System.out.println(sw.prettyPrint()); | ||
| 71 | 76 | ||
| 72 | }catch (Exception e){ | 77 | }catch (Exception e){ |
| 73 | log.error("init afterPropertiesSet error:" + e.getMessage()); | 78 | log.error("init afterPropertiesSet error:" + e.getMessage()); | ... | ... |
| ... | @@ -4,6 +4,7 @@ import com.erry.iclear.dateInterface.entity.ChmConsignment; | ... | @@ -4,6 +4,7 @@ import com.erry.iclear.dateInterface.entity.ChmConsignment; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Query; | 6 | import org.springframework.data.jpa.repository.Query; |
| 7 | +import org.springframework.data.repository.query.Param; | ||
| 7 | import org.springframework.stereotype.Repository; | 8 | import org.springframework.stereotype.Repository; |
| 8 | 9 | ||
| 9 | import java.util.Date; | 10 | import java.util.Date; |
| ... | @@ -22,4 +23,13 @@ public interface ChmConsignmentRepository extends JpaSpecificationExecutor<ChmCo | ... | @@ -22,4 +23,13 @@ public interface ChmConsignmentRepository extends JpaSpecificationExecutor<ChmCo |
| 22 | @Query( nativeQuery = true,value ="select * from T_CHM_CONSIGNMENT where CONSIGNMENT_CODE IN ?1 and CREATE_TIME > ?2 " ) | 23 | @Query( nativeQuery = true,value ="select * from T_CHM_CONSIGNMENT where CONSIGNMENT_CODE IN ?1 and CREATE_TIME > ?2 " ) |
| 23 | public List<ChmConsignment> findChmByCodeListAndCreateTime(List chmConCodeList, Date createTime); | 24 | public List<ChmConsignment> findChmByCodeListAndCreateTime(List chmConCodeList, Date createTime); |
| 24 | 25 | ||
| 26 | + /** | ||
| 27 | + * 根据运单号查找 | ||
| 28 | + * @param consignmentCode | ||
| 29 | + * @param startDate | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + @Query( nativeQuery = true,value ="select * from T_CHM_CONSIGNMENT where CONSIGNMENT_CODE = ?1 and CREATE_TIME>= ?2" ) | ||
| 33 | + public ChmConsignment findChmConsignmentByConsignmentCode(String consignmentCode,Date startDate); | ||
| 34 | + | ||
| 25 | } | 35 | } | ... | ... |
| ... | @@ -15,7 +15,7 @@ import java.util.List; | ... | @@ -15,7 +15,7 @@ import java.util.List; |
| 15 | */ | 15 | */ |
| 16 | @Repository | 16 | @Repository |
| 17 | @Transactional(rollbackFor = Exception.class) | 17 | @Transactional(rollbackFor = Exception.class) |
| 18 | -public interface DictionaryEntriesRepository extends JpaRepository<IClearApiLog, Integer>, JpaSpecificationExecutor<IClearApiLog> { | 18 | +public interface DictionaryEntriesRepository extends JpaRepository<DictionaryEntries, Integer>, JpaSpecificationExecutor<DictionaryEntries> { |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * 根据code查找 | 21 | * 根据code查找 |
| ... | @@ -30,7 +30,7 @@ public interface DictionaryEntriesRepository extends JpaRepository<IClearApiLog | ... | @@ -30,7 +30,7 @@ public interface DictionaryEntriesRepository extends JpaRepository<IClearApiLog |
| 30 | * 查找全部DictionaryEntries | 30 | * 查找全部DictionaryEntries |
| 31 | * @return | 31 | * @return |
| 32 | */ | 32 | */ |
| 33 | - @Query(nativeQuery = true, value = "select * from T_BI_DICTIONARY_ENTRIES where STATUS=1") | 33 | + @Query(nativeQuery = true, value = "select ID,CODE,CHINESE_NAME from T_BI_DICTIONARY_ENTRIES where STATUS=1") |
| 34 | public List<DictionaryEntries> findAllDictionaryEntries(); | 34 | public List<DictionaryEntries> findAllDictionaryEntries(); |
| 35 | 35 | ||
| 36 | 36 | ... | ... |
| ... | @@ -6,6 +6,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ... | @@ -6,6 +6,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.stereotype.Repository; | 6 | import org.springframework.stereotype.Repository; |
| 7 | import org.springframework.transaction.annotation.Transactional; | 7 | import org.springframework.transaction.annotation.Transactional; |
| 8 | 8 | ||
| 9 | +/** | ||
| 10 | + * @author Administrator | ||
| 11 | + */ | ||
| 9 | @Repository | 12 | @Repository |
| 10 | @Transactional(rollbackFor = Exception.class) | 13 | @Transactional(rollbackFor = Exception.class) |
| 11 | public interface MawbDetailRepository extends JpaRepository<MawbDetail, Integer>, JpaSpecificationExecutor<MawbDetail> { | 14 | public interface MawbDetailRepository extends JpaRepository<MawbDetail, Integer>, JpaSpecificationExecutor<MawbDetail> { | ... | ... |
| ... | @@ -4,9 +4,11 @@ import com.erry.iclear.dateInterface.api.request.MawbDetail; | ... | @@ -4,9 +4,11 @@ import com.erry.iclear.dateInterface.api.request.MawbDetail; |
| 4 | import com.erry.iclear.dateInterface.common.Constant; | 4 | import com.erry.iclear.dateInterface.common.Constant; |
| 5 | import com.erry.iclear.dateInterface.entity.*; | 5 | import com.erry.iclear.dateInterface.entity.*; |
| 6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 7 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 8 | 9 | ||
| 9 | import java.math.BigDecimal; | 10 | import java.math.BigDecimal; |
| 11 | +import java.util.Objects; | ||
| 10 | 12 | ||
| 11 | /** | 13 | /** |
| 12 | * @author Administrator | 14 | * @author Administrator |
| ... | @@ -84,9 +86,12 @@ public class ChmConsignmentDetailService { | ... | @@ -84,9 +86,12 @@ public class ChmConsignmentDetailService { |
| 84 | //申报货物英文名称 | 86 | //申报货物英文名称 |
| 85 | result.setContentDescription(mawbDetail.getDeclGoodsEname()); | 87 | result.setContentDescription(mawbDetail.getDeclGoodsEname()); |
| 86 | //目的地代码 | 88 | //目的地代码 |
| 89 | + if(StringUtils.isNotBlank(mawbDetail.getDestCode())){ | ||
| 87 | OrigplacecodeMapping origplacecodeMapping = Constant.origplacecodeMappingCache.get(mawbDetail.getDestCode()); | 90 | OrigplacecodeMapping origplacecodeMapping = Constant.origplacecodeMappingCache.get(mawbDetail.getDestCode()); |
| 88 | result.setOrigplacecodeMapping(origplacecodeMapping); | 91 | result.setOrigplacecodeMapping(origplacecodeMapping); |
| 89 | result.setOrigplacecode(origplacecodeMapping.getOrigplaceName()); | 92 | result.setOrigplacecode(origplacecodeMapping.getOrigplaceName()); |
| 93 | + } | ||
| 94 | + | ||
| 90 | 95 | ||
| 91 | 96 | ||
| 92 | //境内目的地/境内货源地 | 97 | //境内目的地/境内货源地 | ... | ... |
| 1 | package com.erry.iclear.dateInterface.service; | 1 | package com.erry.iclear.dateInterface.service; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.date.DateUtil; | ||
| 3 | import com.erry.iclear.dateInterface.api.request.Mawb; | 4 | import com.erry.iclear.dateInterface.api.request.Mawb; |
| 4 | import com.erry.iclear.dateInterface.common.Constant; | 5 | import com.erry.iclear.dateInterface.common.Constant; |
| 5 | import com.erry.iclear.dateInterface.entity.ChmCarryPort; | 6 | import com.erry.iclear.dateInterface.entity.ChmCarryPort; |
| 6 | import com.erry.iclear.dateInterface.entity.ChmConsignment; | 7 | import com.erry.iclear.dateInterface.entity.ChmConsignment; |
| 8 | +import com.erry.iclear.dateInterface.entity.ChmConsignmentDetail; | ||
| 7 | import com.erry.iclear.dateInterface.entity.DictionaryEntries; | 9 | import com.erry.iclear.dateInterface.entity.DictionaryEntries; |
| 8 | import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository; | 10 | import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository; |
| 11 | +import com.erry.iclear.dateInterface.util.DateUtils; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 12 | 15 | ||
| 16 | +import javax.transaction.Transactional; | ||
| 13 | import java.math.BigDecimal; | 17 | import java.math.BigDecimal; |
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.Date; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Objects; | ||
| 14 | 22 | ||
| 15 | /** | 23 | /** |
| 16 | * @author Administrator | 24 | * @author Administrator |
| 17 | */ | 25 | */ |
| 18 | @Service | 26 | @Service |
| 19 | @Slf4j | 27 | @Slf4j |
| 28 | +@Transactional(rollbackOn = Exception.class) | ||
| 20 | public class ChmConsignmentService { | 29 | public class ChmConsignmentService { |
| 21 | 30 | ||
| 22 | @Autowired | 31 | @Autowired |
| 23 | private ChmConsignmentRepository chmConsignmentRepository; | 32 | private ChmConsignmentRepository chmConsignmentRepository; |
| 24 | 33 | ||
| 34 | + @Autowired | ||
| 35 | + private ChmConsignmentDetailService chmConsignmentDetailService; | ||
| 36 | + | ||
| 25 | /** | 37 | /** |
| 26 | * 转换主单 | 38 | * 转换主单 |
| 27 | * @return | 39 | * @return |
| 28 | */ | 40 | */ |
| 29 | - public ChmConsignment convertToChmConsignment(Mawb mawb){ | 41 | + public ChmConsignment convertToChmConsignment(Mawb mawb,Date pushTime){ |
| 30 | ChmConsignment result = new ChmConsignment(); | 42 | ChmConsignment result = new ChmConsignment(); |
| 31 | try{ | 43 | try{ |
| 32 | //进出口标志:固定值 E | 44 | //进出口标志:固定值 E |
| ... | @@ -37,9 +49,15 @@ public class ChmConsignmentService { | ... | @@ -37,9 +49,15 @@ public class ChmConsignmentService { |
| 37 | result.setDeclaredUnitName(mawb.getAgentName()); | 49 | result.setDeclaredUnitName(mawb.getAgentName()); |
| 38 | //申报单位名称:固定值 联邦快递(中国)有限公司 | 50 | //申报单位名称:固定值 联邦快递(中国)有限公司 |
| 39 | //提单号:有总单号则取值“总单号_运单号”,没有总单号则取值“运单号” | 51 | //提单号:有总单号则取值“总单号_运单号”,没有总单号则取值“运单号” |
| 40 | - String billNo[]=mawb.getBillNo().split("_"); | 52 | + String[] billNo=mawb.getBillNo().split("_"); |
| 53 | + if(billNo.length==1){ | ||
| 54 | + result.setConsignmentCode(billNo[0]); | ||
| 55 | + } | ||
| 56 | + if(billNo.length==2){ | ||
| 41 | result.setConsignmentHeadCode(billNo[0]); | 57 | result.setConsignmentHeadCode(billNo[0]); |
| 42 | result.setConsignmentCode(billNo[1]); | 58 | result.setConsignmentCode(billNo[1]); |
| 59 | + } | ||
| 60 | + | ||
| 43 | //合同号 | 61 | //合同号 |
| 44 | result.setContractCode(mawb.getContrNo()); | 62 | result.setContractCode(mawb.getContrNo()); |
| 45 | //主管海关(申报地海关) | 63 | //主管海关(申报地海关) |
| ... | @@ -97,13 +115,13 @@ public class ChmConsignmentService { | ... | @@ -97,13 +115,13 @@ public class ChmConsignmentService { |
| 97 | //预录入编号 | 115 | //预录入编号 |
| 98 | result.setEnteringNo(mawb.getPreEntryId()); | 116 | result.setEnteringNo(mawb.getPreEntryId()); |
| 99 | //启运国/运抵国 | 117 | //启运国/运抵国 |
| 100 | - DictionaryEntries fromCountryDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+mawb.getOtherCurr()); | 118 | + DictionaryEntries fromCountryDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+mawb.getTradeCountry()); |
| 101 | result.setFromCountryDic(fromCountryDictionaryEntries); | 119 | result.setFromCountryDic(fromCountryDictionaryEntries); |
| 102 | result.setFromCountry(fromCountryDictionaryEntries.getChineseName()); | 120 | result.setFromCountry(fromCountryDictionaryEntries.getChineseName()); |
| 103 | 121 | ||
| 104 | 122 | ||
| 105 | //监管方式 | 123 | //监管方式 |
| 106 | - DictionaryEntries tradeModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+mawb.getOtherCurr()); | 124 | + DictionaryEntries tradeModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.SUPERVISION_MODE+mawb.getTradeMode()); |
| 107 | result.setTradeModeDic(tradeModeDictionaryEntries); | 125 | result.setTradeModeDic(tradeModeDictionaryEntries); |
| 108 | result.setTradeMode(tradeModeDictionaryEntries.getChineseName()); | 126 | result.setTradeMode(tradeModeDictionaryEntries.getChineseName()); |
| 109 | 127 | ||
| ... | @@ -117,8 +135,9 @@ public class ChmConsignmentService { | ... | @@ -117,8 +135,9 @@ public class ChmConsignmentService { |
| 117 | 135 | ||
| 118 | //境内收发货人名称 | 136 | //境内收发货人名称 |
| 119 | result.setOperateUnitName(mawb.getTradeName()); | 137 | result.setOperateUnitName(mawb.getTradeName()); |
| 120 | - //成交方式 | 138 | + //TODO 成交方式 |
| 121 | - DictionaryEntries dealModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CLINCH_TYPE+mawb.getTransMode()); | 139 | +// DictionaryEntries dealModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CLINCH_TYPE+mawb.getTransMode()); |
| 140 | + DictionaryEntries dealModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CLINCH_TYPE+"CIF"); | ||
| 122 | result.setDealModeDic(dealModeDictionaryEntries); | 141 | result.setDealModeDic(dealModeDictionaryEntries); |
| 123 | result.setDealMode(dealModeDictionaryEntries.getChineseName()); | 142 | result.setDealMode(dealModeDictionaryEntries.getChineseName()); |
| 124 | 143 | ||
| ... | @@ -151,7 +170,15 @@ public class ChmConsignmentService { | ... | @@ -151,7 +170,15 @@ public class ChmConsignmentService { |
| 151 | result.setOverseasConsignorFnCname(mawb.getOverseasConsigneeEname()); | 170 | result.setOverseasConsignorFnCname(mawb.getOverseasConsigneeEname()); |
| 152 | 171 | ||
| 153 | 172 | ||
| 173 | + //运单状态: 待申报海关 | ||
| 174 | + DictionaryEntries transferWaybillStatusDictionaryEntries=Constant.dictionaryEntriesCache.get(Constant.TRANSFER_WAY_BILL_STATUS+"5"); | ||
| 175 | + result.setConsStatusDic(transferWaybillStatusDictionaryEntries); | ||
| 176 | + result.setConsStatus(transferWaybillStatusDictionaryEntries.getChineseName()); | ||
| 177 | + //推送时间作为创建时间,可以用来校验数据的有序性,如果新的推送时间小于已有的创建时间,就不更新数据 | ||
| 178 | + result.setCreateTime(pushTime); | ||
| 179 | + | ||
| 154 | }catch (Exception e){ | 180 | }catch (Exception e){ |
| 181 | + e.printStackTrace(); | ||
| 155 | log.error("convertToChmConsignment() error:"+e.getMessage()); | 182 | log.error("convertToChmConsignment() error:"+e.getMessage()); |
| 156 | } | 183 | } |
| 157 | return result; | 184 | return result; |
| ... | @@ -173,4 +200,80 @@ public class ChmConsignmentService { | ... | @@ -173,4 +200,80 @@ public class ChmConsignmentService { |
| 173 | } | 200 | } |
| 174 | 201 | ||
| 175 | 202 | ||
| 203 | + /** | ||
| 204 | + * 根据运单号查找数据 | ||
| 205 | + * @param consignmentCode | ||
| 206 | + * @return | ||
| 207 | + */ | ||
| 208 | + public ChmConsignment findChmConsignmentByConsignmentCode(String consignmentCode, Date startDate){ | ||
| 209 | + try { | ||
| 210 | + return chmConsignmentRepository.findChmConsignmentByConsignmentCode(consignmentCode,startDate); | ||
| 211 | + }catch (Exception e){ | ||
| 212 | + log.error("findChmConsignmentByConsignmentCode() error:"+ e.getMessage()); | ||
| 213 | + } | ||
| 214 | + return null; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * 保存或更新 iclear中的运单信息 | ||
| 220 | + * @param mawb | ||
| 221 | + * @param timeStamp | ||
| 222 | + */ | ||
| 223 | + public void processChmConsignment(Mawb mawb, String timeStamp) { | ||
| 224 | + try { | ||
| 225 | + Date pushTime = DateUtils.timeStampToDate(Long.valueOf(timeStamp)); | ||
| 226 | + | ||
| 227 | + ChmConsignment chmConsignment=this.convertToChmConsignment(mawb,pushTime); | ||
| 228 | + List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>(); | ||
| 229 | + mawb.getMawbDetailList().forEach(detail ->{ | ||
| 230 | + chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail)); | ||
| 231 | + }); | ||
| 232 | + chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList); | ||
| 233 | + | ||
| 234 | + | ||
| 235 | + //校验 7天+运单 ,如果有数据并且 还未报关就更新,如果数据就插入 | ||
| 236 | + ChmConsignment chmConsignmentDB=this.findChmConsignmentByConsignmentCode(mawb.getBillNo(), DateUtils.addDate(DateUtils.getCurrentDate(),-7)); | ||
| 237 | + //新增:如果没有就插入 | ||
| 238 | + if (Objects.equals(chmConsignmentDB,null)){ | ||
| 239 | + log.info("新增主单"+ mawb.getBillNo()); | ||
| 240 | + ChmConsignment chmConsignmentSaveResult = this.saveChmConsignment(chmConsignment); | ||
| 241 | + if(!Objects.equals(chmConsignmentSaveResult,null)){ | ||
| 242 | + log.info("主单"+ mawb.getBillNo()+" 保存成功,chmConsignmentId:"+chmConsignmentSaveResult.getId()); | ||
| 243 | + }else{ | ||
| 244 | + log.info("主单"+ mawb.getBillNo()+" 保存失败"); | ||
| 245 | + } | ||
| 246 | + //更新: | ||
| 247 | + //如果有数据并且满足条件后才能更新数据 | ||
| 248 | + //条件1、状态为 待申报海关 | ||
| 249 | + //条件2、推送时间小于 上次推送的时间 | ||
| 250 | + }else if(!Objects.equals(chmConsignmentDB,null) | ||
| 251 | + && Objects.equals(chmConsignmentDB.getConsStatusDic().getCode(),"transferWaybillStatus_5") | ||
| 252 | + && pushTime.getTime()<chmConsignmentDB.getCreateTime().getTime()){ | ||
| 253 | + //TODO 更新数据 | ||
| 254 | + log.info("更新主单"+ mawb.getBillNo()); | ||
| 255 | + | ||
| 256 | + } | ||
| 257 | + }catch (Exception e){ | ||
| 258 | + log.error(""+e.getMessage()); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + | ||
| 263 | + | ||
| 264 | + | ||
| 265 | + | ||
| 266 | + | ||
| 267 | + | ||
| 268 | + | ||
| 269 | + | ||
| 270 | + | ||
| 271 | + | ||
| 272 | + | ||
| 273 | + | ||
| 274 | + | ||
| 275 | + | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + | ||
| 176 | } | 279 | } | ... | ... |
| ... | @@ -26,6 +26,7 @@ public class DictionaryEntriesService { | ... | @@ -26,6 +26,7 @@ public class DictionaryEntriesService { |
| 26 | try { | 26 | try { |
| 27 | result=dictionaryEntriesRepository.findAllDictionaryEntries(); | 27 | result=dictionaryEntriesRepository.findAllDictionaryEntries(); |
| 28 | }catch (Exception e){ | 28 | }catch (Exception e){ |
| 29 | + e.printStackTrace(); | ||
| 29 | log.error("getAllDictionaryEntries() error:"+e.getMessage()); | 30 | log.error("getAllDictionaryEntries() error:"+e.getMessage()); |
| 30 | } | 31 | } |
| 31 | return result; | 32 | return result; | ... | ... |
| ... | @@ -38,7 +38,7 @@ public class IClearApiLogService { | ... | @@ -38,7 +38,7 @@ public class IClearApiLogService { |
| 38 | * 创建日志 | 38 | * 创建日志 |
| 39 | * @return | 39 | * @return |
| 40 | */ | 40 | */ |
| 41 | - public IClearApiLog convertToIClearApiLog(Mawb mawb,String appId,String appKey){ | 41 | + public IClearApiLog convertToIClearApiLog(Mawb mawb,String appId,String appKey,Date pushTime){ |
| 42 | IClearApiLog result = new IClearApiLog(); | 42 | IClearApiLog result = new IClearApiLog(); |
| 43 | try{ | 43 | try{ |
| 44 | result.setMsgType(Constant.MSG_TYPE_D); | 44 | result.setMsgType(Constant.MSG_TYPE_D); |
| ... | @@ -46,6 +46,7 @@ public class IClearApiLogService { | ... | @@ -46,6 +46,7 @@ public class IClearApiLogService { |
| 46 | result.setAppKey(appKey); | 46 | result.setAppKey(appKey); |
| 47 | result.setCreateTime(new Date()); | 47 | result.setCreateTime(new Date()); |
| 48 | result.setUpdateTime(new Date()); | 48 | result.setUpdateTime(new Date()); |
| 49 | + result.setPushTime(pushTime); | ||
| 49 | result.setReceiveResult(null); | 50 | result.setReceiveResult(null); |
| 50 | result.setResponseTime(null); | 51 | result.setResponseTime(null); |
| 51 | result.setSpendTime(null); | 52 | result.setSpendTime(null); | ... | ... |
| 1 | +package com.erry.iclear.dateInterface.util; | ||
| 2 | + | ||
| 3 | +import java.text.DateFormat; | ||
| 4 | +import java.text.ParseException; | ||
| 5 | +import java.text.SimpleDateFormat; | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.Calendar; | ||
| 8 | +import java.util.Date; | ||
| 9 | +import java.util.GregorianCalendar; | ||
| 10 | +import java.util.HashMap; | ||
| 11 | +import java.util.LinkedHashSet; | ||
| 12 | +import java.util.List; | ||
| 13 | +import java.util.Map; | ||
| 14 | +import java.util.Set; | ||
| 15 | +import java.util.regex.Matcher; | ||
| 16 | +import java.util.regex.Pattern; | ||
| 17 | + | ||
| 18 | +import lombok.extern.slf4j.Slf4j; | ||
| 19 | +import org.springframework.util.Assert; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @author Administrator | ||
| 23 | + */ | ||
| 24 | +@Slf4j | ||
| 25 | +public class DateUtils { | ||
| 26 | + | ||
| 27 | + private DateUtils() { | ||
| 28 | + }; | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + public static String YEAR_MONTH = "yyyyMM"; | ||
| 32 | + public static String SHORT_DATE = "yyyyMMdd"; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 功能:计算两个日期之间相差多少天 ((date2-date1)后取整) | ||
| 36 | + * | ||
| 37 | + * @param date1 减日期 | ||
| 38 | + * @param date2 被减日期 | ||
| 39 | + * @return | ||
| 40 | + */ | ||
| 41 | + public static int dateDiff(Date date1, Date date2) { | ||
| 42 | + Calendar calendar1 = Calendar.getInstance(); | ||
| 43 | + Calendar calendar2 = Calendar.getInstance(); | ||
| 44 | + calendar1.setTime(date1); | ||
| 45 | + calendar2.setTime(date2); | ||
| 46 | + calendar1.set(Calendar.HOUR_OF_DAY, 0); | ||
| 47 | + calendar1.set(Calendar.MINUTE, 0); | ||
| 48 | + calendar1.set(Calendar.SECOND, 0); | ||
| 49 | + calendar1.set(Calendar.MILLISECOND, 0); | ||
| 50 | + | ||
| 51 | + calendar2.set(Calendar.HOUR_OF_DAY, 0); | ||
| 52 | + calendar2.set(Calendar.MINUTE, 0); | ||
| 53 | + calendar2.set(Calendar.SECOND, 0); | ||
| 54 | + calendar2.set(Calendar.MILLISECOND, 0); | ||
| 55 | + | ||
| 56 | + long l = Math.abs(calendar2.getTimeInMillis() - calendar1.getTimeInMillis()); | ||
| 57 | + long increaseDate = l / 1000 / 60 / 60 / 24; | ||
| 58 | + if ((l % (1000 * 60 * 60 * 24)) > 0) { | ||
| 59 | + increaseDate = increaseDate + 1; | ||
| 60 | + } | ||
| 61 | + return (int) increaseDate; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * date2 是否是date1 的下一天 | ||
| 66 | + * | ||
| 67 | + * @param date1 | ||
| 68 | + * @param date2 | ||
| 69 | + * @return | ||
| 70 | + */ | ||
| 71 | + public static boolean isNextDate(Date date1, Date date2) { | ||
| 72 | + if (date2.after(date1) && dateDiff(date1,date2) ==1) { | ||
| 73 | + return true; | ||
| 74 | + } | ||
| 75 | + return false; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 功能:按yyyy-MM-dd HH:mm:ss 或 yyyy-MM-dd转换为日期 | ||
| 80 | + * | ||
| 81 | + * @param s | ||
| 82 | + * @return | ||
| 83 | + * @throws Exception | ||
| 84 | + */ | ||
| 85 | + public static Date parseToDate(String s) throws Exception { | ||
| 86 | + DateFormat df; | ||
| 87 | + if (s == null) { | ||
| 88 | + return null; | ||
| 89 | + } | ||
| 90 | + if (s.contains(":")) { | ||
| 91 | + try { | ||
| 92 | + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 93 | + return df.parse(s); | ||
| 94 | + } catch (Exception e) { | ||
| 95 | + log.error(e.getMessage()); | ||
| 96 | + throw e; | ||
| 97 | + } | ||
| 98 | + } else { | ||
| 99 | + try { | ||
| 100 | + df = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 101 | + return df.parse(s); | ||
| 102 | + } catch (Exception e) { | ||
| 103 | + log.error(e.getMessage()); | ||
| 104 | + throw e; | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * date1 > date2+before-->true | ||
| 111 | + * | ||
| 112 | + * @param date1 | ||
| 113 | + * @param date2 | ||
| 114 | + * @param before | ||
| 115 | + * @return | ||
| 116 | + */ | ||
| 117 | + public static boolean isOverTime(Date date1, Date date2, int before) { | ||
| 118 | + try { | ||
| 119 | + Calendar calendar = Calendar.getInstance(); | ||
| 120 | + calendar.setTime(date2); | ||
| 121 | + calendar.add(Calendar.HOUR, -1 * before); | ||
| 122 | + // 如果参数 Date 等于此 Date,则返回值 0; | ||
| 123 | + // 如果此 Date 在 Date 参数之前,则返回小于 0 的值; | ||
| 124 | + // 如果此 Date 在 Date 参数之后,则返回大于 0 的值。 | ||
| 125 | + if (date1.compareTo(calendar.getTime()) > 0) { | ||
| 126 | + return true; | ||
| 127 | + } | ||
| 128 | + } catch (Exception e) { | ||
| 129 | + log.error(e.getMessage()); | ||
| 130 | + } | ||
| 131 | + return false; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * 功能:判断时间是否是凌晨(0-6),默认当前系统时间 | ||
| 136 | + * | ||
| 137 | + * @param date | ||
| 138 | + * @return | ||
| 139 | + * @throws Exception | ||
| 140 | + */ | ||
| 141 | + public static boolean isDawn(Date date) throws Exception { | ||
| 142 | + boolean isDawn = false; | ||
| 143 | + Calendar tempCal = Calendar.getInstance(); | ||
| 144 | + if (date != null) { | ||
| 145 | + tempCal.setTime(date); | ||
| 146 | + } | ||
| 147 | + int hour = tempCal.get(Calendar.HOUR_OF_DAY); | ||
| 148 | + if (0 <= hour && hour <= 6) { | ||
| 149 | + isDawn = true; | ||
| 150 | + } | ||
| 151 | + return isDawn; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * 功能:根据传入的字符串,得到holdTime,得到的时间为1970年的HH:mm:ss | ||
| 156 | + * 如果格式不对(不为例如:23:12:23或着23:56或着23),抛出异常 | ||
| 157 | + * | ||
| 158 | + * @param str | ||
| 159 | + * @return | ||
| 160 | + */ | ||
| 161 | + public static Date getHoldTimeDate(String str) throws Exception { | ||
| 162 | + boolean flag = false; | ||
| 163 | + Pattern p1 = Pattern.compile("(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})"); | ||
| 164 | + Matcher m1 = p1.matcher(str); | ||
| 165 | + Pattern p2 = Pattern.compile("(0\\d{1}|1\\d{1}|2[0-3])"); | ||
| 166 | + Matcher m2 = p2.matcher(str); | ||
| 167 | + Pattern p3 = Pattern.compile("(0\\d{1}|1\\d{1}|2[0-4]):[0-5]\\d{1}"); | ||
| 168 | + Matcher m3 = p3.matcher(str); | ||
| 169 | + if (m1.matches() || m2.matches() || m3.matches()) { | ||
| 170 | + flag = true; | ||
| 171 | + if (m3.matches()) { | ||
| 172 | + return string2Date(str, "HH:mm"); | ||
| 173 | + } | ||
| 174 | + if (m1.matches()) { | ||
| 175 | + return string2Date(str, "HH:mm:ss"); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + if (m2.matches()) { | ||
| 179 | + return string2Date(str, "HH"); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + if (!flag) { | ||
| 184 | + throw new RuntimeException("holdTime format is invalid!"); | ||
| 185 | + } | ||
| 186 | + return null; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + /** | ||
| 190 | + * 日期转为HoldTime格式HH:mm | ||
| 191 | + * | ||
| 192 | + * @param date | ||
| 193 | + * @return | ||
| 194 | + */ | ||
| 195 | + public static String date2HoldTime(Date date) { | ||
| 196 | + if (date == null){ | ||
| 197 | + return ""; | ||
| 198 | + } | ||
| 199 | + SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm"); | ||
| 200 | + return dateformat.format(date); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + /** | ||
| 204 | + * 功能:算出两个日期中所包含的月份 | ||
| 205 | + * | ||
| 206 | + * @param fromDate | ||
| 207 | + * @param toDate | ||
| 208 | + * @return | ||
| 209 | + */ | ||
| 210 | + public static Set<String> getMonthBetweenTwoDate(Date fromDate, Date toDate) { | ||
| 211 | + long begin = fromDate.getTime(); | ||
| 212 | + long end = toDate.getTime(); | ||
| 213 | + long inter = end - begin; | ||
| 214 | + if (inter < 0) { | ||
| 215 | + inter = inter * (-1); | ||
| 216 | + } | ||
| 217 | + long dateMillSec = 86400000; | ||
| 218 | + long dateCnt = inter / dateMillSec; | ||
| 219 | + long remainder = inter % dateMillSec; | ||
| 220 | + if (remainder != 0) { | ||
| 221 | + dateCnt++; | ||
| 222 | + } | ||
| 223 | + Set<String> set = new LinkedHashSet<String>(); | ||
| 224 | + Calendar cl = Calendar.getInstance(); | ||
| 225 | + cl.setTime(fromDate); | ||
| 226 | + cl.set(Calendar.HOUR_OF_DAY, 0); | ||
| 227 | + cl.set(Calendar.MINUTE, 0); | ||
| 228 | + cl.set(Calendar.SECOND, 0); | ||
| 229 | + cl.set(Calendar.MILLISECOND, 0); | ||
| 230 | + set.add(getDateyyyyMM(cl.getTime())); | ||
| 231 | + for (int i = 1; i <= dateCnt; i++) { | ||
| 232 | + cl.add(Calendar.DAY_OF_YEAR, 1); | ||
| 233 | + set.add(getDateyyyyMM(cl.getTime())); | ||
| 234 | + } | ||
| 235 | + return set; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * 功能:获取yyyyMM的年月 | ||
| 240 | + * | ||
| 241 | + * @param date | ||
| 242 | + * @return | ||
| 243 | + */ | ||
| 244 | + public static String getDateyyyyMM(Date date) { | ||
| 245 | + SimpleDateFormat df = new SimpleDateFormat("yyyyMM"); | ||
| 246 | + return df.format(date); | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + /** | ||
| 250 | + * 功能:获取yyyyMMdd的年月日 | ||
| 251 | + * | ||
| 252 | + * @param date | ||
| 253 | + * @return | ||
| 254 | + */ | ||
| 255 | + public static String getDateyyyyMMdd(Date date) { | ||
| 256 | + SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); | ||
| 257 | + return df.format(date); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * 功能:获取yyyyMM的年月 | ||
| 262 | + * | ||
| 263 | + * @param month | ||
| 264 | + * @return | ||
| 265 | + */ | ||
| 266 | + public static Date parseDateyyyyMM(String month) { | ||
| 267 | + SimpleDateFormat df = new SimpleDateFormat("yyyyMM"); | ||
| 268 | + try { | ||
| 269 | + return df.parse(month); | ||
| 270 | + } catch (ParseException e) { | ||
| 271 | + } | ||
| 272 | + return null; | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + /** | ||
| 276 | + * 功能:格式yyyyMMdd日期 | ||
| 277 | + * | ||
| 278 | + * | ||
| 279 | + * @param date | ||
| 280 | + * @return | ||
| 281 | + */ | ||
| 282 | + public static Date parseDateyyyyMMdd(String date) { | ||
| 283 | + SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); | ||
| 284 | + try { | ||
| 285 | + return df.parse(date); | ||
| 286 | + } catch (ParseException e) { | ||
| 287 | + } | ||
| 288 | + return null; | ||
| 289 | + } | ||
| 290 | + | ||
| 291 | + /** | ||
| 292 | + * 功能:根据两个日期,算出某个月份的第一天,或者最后一天 | ||
| 293 | + * | ||
| 294 | + * @param dateFrom | ||
| 295 | + * @param dateTo | ||
| 296 | + * @param month | ||
| 297 | + * @param flag start | ||
| 298 | + * @return | ||
| 299 | + */ | ||
| 300 | + public static int getDayBetweenDateStartOrEnd(Date dateFrom, Date dateTo, Date month, String flag) { | ||
| 301 | + if (dateFrom.getTime() > dateTo.getTime()) { | ||
| 302 | + Date temp = dateFrom; | ||
| 303 | + dateFrom = dateTo; | ||
| 304 | + dateTo = temp; | ||
| 305 | + } | ||
| 306 | + if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) > 0 | ||
| 307 | + && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) < 0) { | ||
| 308 | + if ("start".equals(flag)){ | ||
| 309 | + return 1; | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + return getMonthsMaxDay(month); | ||
| 313 | + } else if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) == 0 | ||
| 314 | + && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) < 0) { | ||
| 315 | + if ("start".equals(flag)){ | ||
| 316 | + return getDayOfMonth(dateFrom); | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + return getMonthsMaxDay(month); | ||
| 320 | + } else if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) > 0 | ||
| 321 | + && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) == 0) { | ||
| 322 | + if ("start".equals(flag)){ | ||
| 323 | + return 1; | ||
| 324 | + } | ||
| 325 | + return getDayOfMonth(dateTo); | ||
| 326 | + } else { | ||
| 327 | + if ("start".equals(flag)) { | ||
| 328 | + return getDayOfMonth(dateFrom); | ||
| 329 | + } | ||
| 330 | + return getDayOfMonth(dateTo); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + /** | ||
| 336 | + * 功能:根据一个日期,算出是这个月中的第几天 | ||
| 337 | + * | ||
| 338 | + * @param date | ||
| 339 | + * @return | ||
| 340 | + */ | ||
| 341 | + public static int getDayOfMonth(Date date) { | ||
| 342 | + Calendar cal1 = Calendar.getInstance(); | ||
| 343 | + cal1.setTime(date); | ||
| 344 | + return cal1.get(Calendar.DAY_OF_MONTH); | ||
| 345 | + } | ||
| 346 | + | ||
| 347 | + /** | ||
| 348 | + * 功能:取出一个月中某天的日期 | ||
| 349 | + * | ||
| 350 | + * @param month | ||
| 351 | + * @param num | ||
| 352 | + * @return | ||
| 353 | + */ | ||
| 354 | + public static Date getDateOfMonthByNum(String month, int num) { | ||
| 355 | + Calendar cl = Calendar.getInstance(); | ||
| 356 | + cl.setTime(parseDateyyyyMM(month)); | ||
| 357 | + cl.set(Calendar.HOUR_OF_DAY, 0); | ||
| 358 | + cl.set(Calendar.MINUTE, 0); | ||
| 359 | + cl.set(Calendar.SECOND, 0); | ||
| 360 | + cl.set(Calendar.MILLISECOND, 0); | ||
| 361 | + cl.add(Calendar.DAY_OF_YEAR, num - 1); | ||
| 362 | + return cl.getTime(); | ||
| 363 | + } | ||
| 364 | + | ||
| 365 | + /** | ||
| 366 | + * 功能:得到本周第一天日期 | ||
| 367 | + * | ||
| 368 | + * @return | ||
| 369 | + */ | ||
| 370 | + public static Date getCurrentWeekMonday() { | ||
| 371 | + | ||
| 372 | + Calendar cal = Calendar.getInstance(); | ||
| 373 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 374 | + cal.set(Calendar.MINUTE, 0); | ||
| 375 | + cal.set(Calendar.SECOND, 0); | ||
| 376 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 377 | + int index = cal.get(Calendar.DAY_OF_WEEK); | ||
| 378 | + // 转成中国的习惯,如果是第一天,则转化为第七天(星期天外国为一周的第一天,而中国为每周的最后一天) | ||
| 379 | + if (index == 1){ | ||
| 380 | + index = 8; | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + cal.add(Calendar.DATE, -(index - 2)); | ||
| 384 | + return cal.getTime(); | ||
| 385 | + | ||
| 386 | + } | ||
| 387 | + | ||
| 388 | + /** | ||
| 389 | + * 功能:得到本周最后一天的日期 | ||
| 390 | + * | ||
| 391 | + * @return | ||
| 392 | + */ | ||
| 393 | + public static Date getCurrentWeekSaturday() { | ||
| 394 | + Calendar cal = Calendar.getInstance(); | ||
| 395 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 396 | + cal.set(Calendar.MINUTE, 0); | ||
| 397 | + cal.set(Calendar.SECOND, 0); | ||
| 398 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 399 | + int index = cal.get(Calendar.DAY_OF_WEEK); | ||
| 400 | + if (index == 1){ | ||
| 401 | + index = 8; | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + cal.add(Calendar.DATE, -(index - 2)); | ||
| 405 | + cal.add(Calendar.DATE, 6); | ||
| 406 | + return cal.getTime(); | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + /** | ||
| 410 | + * 功能:从指定日期移动一定的天数 | ||
| 411 | + * | ||
| 412 | + * @param date | ||
| 413 | + * @param day | ||
| 414 | + * @return | ||
| 415 | + */ | ||
| 416 | + public static Date moveDay(Date date, int day) { | ||
| 417 | + Calendar cal = Calendar.getInstance(); | ||
| 418 | + cal.setTime(date); | ||
| 419 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 420 | + cal.set(Calendar.MINUTE, 0); | ||
| 421 | + cal.set(Calendar.SECOND, 0); | ||
| 422 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 423 | + cal.add(Calendar.DAY_OF_MONTH, day); | ||
| 424 | + return cal.getTime(); | ||
| 425 | + } | ||
| 426 | + | ||
| 427 | + /** | ||
| 428 | + * 功能:从当天日期移动一定的月数 | ||
| 429 | + * | ||
| 430 | + * @param month | ||
| 431 | + * @return | ||
| 432 | + */ | ||
| 433 | + | ||
| 434 | + public static Date getMoveMonthDate(int month) { | ||
| 435 | + Date nowDate = new Date(); | ||
| 436 | + Calendar cl = Calendar.getInstance(); | ||
| 437 | + cl.setTime(nowDate); | ||
| 438 | + cl.add(Calendar.MONDAY, month - 1); | ||
| 439 | + Date date1 = cl.getTime(); | ||
| 440 | + return date1; | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + /** | ||
| 444 | + * 功能:获取昨天 | ||
| 445 | + * | ||
| 446 | + * @return | ||
| 447 | + */ | ||
| 448 | + public static Date getYesterday() { | ||
| 449 | + Calendar cal = Calendar.getInstance(); | ||
| 450 | + | ||
| 451 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 452 | + cal.set(Calendar.MINUTE, 0); | ||
| 453 | + cal.set(Calendar.SECOND, 0); | ||
| 454 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 455 | + cal.add(Calendar.DAY_OF_MONTH, -1); | ||
| 456 | + return cal.getTime(); | ||
| 457 | + } | ||
| 458 | + | ||
| 459 | + /** | ||
| 460 | + * 功能:根据某个日期,返回本月第一天 | ||
| 461 | + * | ||
| 462 | + * @param date 任何一天 | ||
| 463 | + * @return Date 当月第一天 | ||
| 464 | + */ | ||
| 465 | + public static Date getMonthsFirstDay(Date date) { | ||
| 466 | + Calendar cal = Calendar.getInstance(); | ||
| 467 | + cal.setTime(date); | ||
| 468 | + cal.set(Calendar.DATE, 1); | ||
| 469 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 470 | + cal.set(Calendar.MINUTE, 0); | ||
| 471 | + cal.set(Calendar.SECOND, 0); | ||
| 472 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 473 | + return cal.getTime(); | ||
| 474 | + } | ||
| 475 | + | ||
| 476 | + /** | ||
| 477 | + * 功能:根据某个日期,返回本月最后一天 | ||
| 478 | + * | ||
| 479 | + * @param date 任何一天 | ||
| 480 | + * @return Date 当月第一天 | ||
| 481 | + */ | ||
| 482 | + public static Date getMonthsLastDay(Date date) { | ||
| 483 | + Calendar cal = Calendar.getInstance(); | ||
| 484 | + cal.setTime(date); | ||
| 485 | + cal.set(Calendar.DATE, 1); | ||
| 486 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 487 | + cal.set(Calendar.MINUTE, 0); | ||
| 488 | + cal.set(Calendar.SECOND, 0); | ||
| 489 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 490 | + cal.add(Calendar.MONTH, 1); | ||
| 491 | + cal.add(Calendar.DATE, -1); | ||
| 492 | + return cal.getTime(); | ||
| 493 | + } | ||
| 494 | + | ||
| 495 | + /** | ||
| 496 | + * 功能:获取起始日期和终止日期之间的日期(包含起始和终止日期) | ||
| 497 | + * | ||
| 498 | + * @param startDate | ||
| 499 | + * @param endDate | ||
| 500 | + * @return | ||
| 501 | + */ | ||
| 502 | + public static Set<String> getDayList(Date startDate, Date endDate) { | ||
| 503 | + long begin = startDate.getTime(); | ||
| 504 | + long end = endDate.getTime(); | ||
| 505 | + long inter = end - begin; | ||
| 506 | + if (inter < 0) { | ||
| 507 | + inter = inter * (-1); | ||
| 508 | + } | ||
| 509 | + long dateMillSec = 86400000; | ||
| 510 | + long dateCnt = inter / dateMillSec; | ||
| 511 | + Set<String> set = new LinkedHashSet<String>(); | ||
| 512 | + Calendar cl = Calendar.getInstance(); | ||
| 513 | + cl.setTime(startDate); | ||
| 514 | + cl.set(Calendar.HOUR_OF_DAY, 0); | ||
| 515 | + cl.set(Calendar.MINUTE, 0); | ||
| 516 | + cl.set(Calendar.SECOND, 0); | ||
| 517 | + cl.set(Calendar.MILLISECOND, 0); | ||
| 518 | + set.add(getDateyyyyMMdd(cl.getTime())); | ||
| 519 | + for (int i = 1; i <= dateCnt; i++) { | ||
| 520 | + cl.add(Calendar.DAY_OF_YEAR, 1); | ||
| 521 | + set.add(getDateyyyyMMdd(cl.getTime())); | ||
| 522 | + } | ||
| 523 | + set.add(getDateyyyyMMdd(endDate)); | ||
| 524 | + return set; | ||
| 525 | + } | ||
| 526 | + | ||
| 527 | + /** | ||
| 528 | + * 功能:取得两个日期中最小的日期,如果两个日期参数都为null则返回null | ||
| 529 | + * | ||
| 530 | + * @param date1 | ||
| 531 | + * @param date2 | ||
| 532 | + * @return Date or null | ||
| 533 | + */ | ||
| 534 | + public static Date getMinimizeDate(Date date1, Date date2) { | ||
| 535 | + if (date1 == null) { | ||
| 536 | + return date2; | ||
| 537 | + } | ||
| 538 | + if (date2 == null) { | ||
| 539 | + return date1; | ||
| 540 | + } | ||
| 541 | + if (date1.compareTo(date2) > 0) { | ||
| 542 | + return date2; | ||
| 543 | + } | ||
| 544 | + return date1; | ||
| 545 | + } | ||
| 546 | + | ||
| 547 | + /** | ||
| 548 | + * 功能:取得两个日期中最大的日期,如果两个日期参数都为null则返回null | ||
| 549 | + * | ||
| 550 | + * @param date1 | ||
| 551 | + * @param date2 | ||
| 552 | + * @return | ||
| 553 | + */ | ||
| 554 | + public static Date getMaxmizeDate(Date date1, Date date2) { | ||
| 555 | + if (date1 == null) { | ||
| 556 | + return date2; | ||
| 557 | + } | ||
| 558 | + if (date2 == null) { | ||
| 559 | + return date1; | ||
| 560 | + } | ||
| 561 | + if (date1.compareTo(date2) < 0) { | ||
| 562 | + return date2; | ||
| 563 | + } | ||
| 564 | + return date1; | ||
| 565 | + } | ||
| 566 | + | ||
| 567 | + /** | ||
| 568 | + * 功能:获取指定日期和天数的星期几 | ||
| 569 | + * | ||
| 570 | + * @param date 指定日期 | ||
| 571 | + * @param day 指定天数 | ||
| 572 | + * @return | ||
| 573 | + */ | ||
| 574 | + public static int getDayofWeek(Date date, int day) { | ||
| 575 | + Calendar calendar = Calendar.getInstance(); | ||
| 576 | + calendar.setTime(date); | ||
| 577 | + calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
| 578 | + calendar.set(Calendar.MINUTE, 0); | ||
| 579 | + calendar.set(Calendar.SECOND, 0); | ||
| 580 | + calendar.set(Calendar.MILLISECOND, 0); | ||
| 581 | + calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + day - 1); | ||
| 582 | + return calendar.get(Calendar.DAY_OF_WEEK); | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + /** | ||
| 586 | + * 功能:判断两个Date是否为一天 | ||
| 587 | + * | ||
| 588 | + * @param date1 | ||
| 589 | + * @param date2 | ||
| 590 | + * @return | ||
| 591 | + */ | ||
| 592 | + public static boolean isSameDay(Date date1, Date date2) { | ||
| 593 | + try { | ||
| 594 | + return org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2); | ||
| 595 | + } catch (Exception e) { | ||
| 596 | + return false; | ||
| 597 | + } | ||
| 598 | + } | ||
| 599 | + | ||
| 600 | + /** | ||
| 601 | + * 功能:把date1的小时,分钟,秒换成date2的小时,分钟,秒,返回换值后的date1 | ||
| 602 | + * | ||
| 603 | + * @param date1 | ||
| 604 | + * @param date2 | ||
| 605 | + * @return | ||
| 606 | + */ | ||
| 607 | + public static Date changeTheHourMinuteSecond(Date date1, Date date2) { | ||
| 608 | + Calendar cl1 = Calendar.getInstance(); | ||
| 609 | + cl1.setTime(date1); | ||
| 610 | + cl1.set(Calendar.HOUR_OF_DAY, 0); | ||
| 611 | + cl1.set(Calendar.MINUTE, 0); | ||
| 612 | + cl1.set(Calendar.SECOND, 0); | ||
| 613 | + | ||
| 614 | + Calendar cl2 = Calendar.getInstance(); | ||
| 615 | + cl2.setTime(date2); | ||
| 616 | + cl1.set(Calendar.HOUR_OF_DAY, cl2.get(Calendar.HOUR_OF_DAY)); | ||
| 617 | + cl1.set(Calendar.MINUTE, cl2.get(Calendar.MINUTE)); | ||
| 618 | + cl1.set(Calendar.SECOND, cl2.get(Calendar.SECOND)); | ||
| 619 | + | ||
| 620 | + return cl1.getTime(); | ||
| 621 | + } | ||
| 622 | + | ||
| 623 | + /** | ||
| 624 | + * 功能:把date1的小时,分钟,秒换成23:59:59 | ||
| 625 | + * | ||
| 626 | + * @param date1 | ||
| 627 | + * @return yyyy-MM-dd 23:59:59 | ||
| 628 | + */ | ||
| 629 | + public static Date getDayOfMaxHourMinuteSecond(Date date1) { | ||
| 630 | + Calendar cl1 = Calendar.getInstance(); | ||
| 631 | + cl1.setTime(date1); | ||
| 632 | + cl1.set(Calendar.HOUR_OF_DAY, 23); | ||
| 633 | + cl1.set(Calendar.MINUTE, 59); | ||
| 634 | + cl1.set(Calendar.SECOND, 59); | ||
| 635 | + | ||
| 636 | + return cl1.getTime(); | ||
| 637 | + } | ||
| 638 | + | ||
| 639 | + /** | ||
| 640 | + * 功能:添加天数 | ||
| 641 | + * | ||
| 642 | + * @param basicDate | ||
| 643 | + * @param days 正、负 整数 或0 | ||
| 644 | + * @return | ||
| 645 | + */ | ||
| 646 | + public static String addDays(String basicDate, int days) { | ||
| 647 | + try { | ||
| 648 | + Calendar cal = Calendar.getInstance(); | ||
| 649 | + cal.setTime(java.sql.Date.valueOf(basicDate)); | ||
| 650 | + cal.add(GregorianCalendar.DATE, days); | ||
| 651 | + return formatDate(cal.getTime(), "yyyy-MM-dd"); | ||
| 652 | + } catch (Exception e) { | ||
| 653 | + return ""; | ||
| 654 | + } | ||
| 655 | + } | ||
| 656 | + | ||
| 657 | + /** | ||
| 658 | + * 功能:对日期进行格式化输出 | ||
| 659 | + * | ||
| 660 | + * @param date 日期 | ||
| 661 | + * @param format | ||
| 662 | + * @return | ||
| 663 | + */ | ||
| 664 | + public static String formatDate(Date date, String format) { | ||
| 665 | + try { | ||
| 666 | + if (format != null && !"".equals(format) && date != null) { | ||
| 667 | + SimpleDateFormat formatter = new SimpleDateFormat(format); | ||
| 668 | + return formatter.format(date); | ||
| 669 | + } | ||
| 670 | + } catch (Exception e) { | ||
| 671 | + return ""; | ||
| 672 | + } | ||
| 673 | + return ""; | ||
| 674 | + } | ||
| 675 | + | ||
| 676 | + /** | ||
| 677 | + * 功能:获取两个日期之间的天数 | ||
| 678 | + * | ||
| 679 | + * @param dateFrom 起始日期 | ||
| 680 | + * @param dateEnd 结束日期 | ||
| 681 | + * @return | ||
| 682 | + */ | ||
| 683 | + public static long getDaysBetweenTwoDatesMath(String dateFrom, String dateEnd) { | ||
| 684 | + Date dtFrom = null; | ||
| 685 | + Date dtEnd = null; | ||
| 686 | + dtFrom = string2Date(dateFrom, "yyyy-MM-dd"); | ||
| 687 | + dtEnd = string2Date(dateEnd, "yyyy-MM-dd"); | ||
| 688 | + long begin = dtFrom.getTime(); | ||
| 689 | + long end = dtEnd.getTime(); | ||
| 690 | + long inter = end - begin; | ||
| 691 | + long dateMillSec = 24 * 60 * 60 * 1000; | ||
| 692 | + long dateCnt = inter / dateMillSec; | ||
| 693 | + long remainder = inter % dateMillSec; | ||
| 694 | + if (remainder != 0) { | ||
| 695 | + dateCnt++; | ||
| 696 | + } | ||
| 697 | + return dateCnt; | ||
| 698 | + } | ||
| 699 | + | ||
| 700 | + /** | ||
| 701 | + * 功能:把日期字符串格式化为日期类型 | ||
| 702 | + * | ||
| 703 | + * @param datetext 日期字符串 | ||
| 704 | + * @param format 日期格式,如果不传则使用"yyyy-MM-dd HH:mm:ss"格式 | ||
| 705 | + * @return | ||
| 706 | + */ | ||
| 707 | + public static Date string2Date(String datetext, String format) { | ||
| 708 | + try { | ||
| 709 | + SimpleDateFormat df; | ||
| 710 | + if (datetext == null || "".equals(datetext.trim())) { | ||
| 711 | + return new Date(); | ||
| 712 | + } | ||
| 713 | + if (format != null) { | ||
| 714 | + df = new SimpleDateFormat(format); | ||
| 715 | + } else { | ||
| 716 | + datetext = datetext.replaceAll("/", "-"); | ||
| 717 | + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 718 | + } | ||
| 719 | + Date date = df.parse(datetext); | ||
| 720 | + | ||
| 721 | + return date; | ||
| 722 | + | ||
| 723 | + } | ||
| 724 | + | ||
| 725 | + catch (Exception e) { | ||
| 726 | + e.printStackTrace(); | ||
| 727 | + return new Date(); | ||
| 728 | + } | ||
| 729 | + } | ||
| 730 | + | ||
| 731 | + /** | ||
| 732 | + * 功能:取得两天之间的日期数组,包含开始日期与结束日期 | ||
| 733 | + * | ||
| 734 | + * @param startDateStr 开始日期 | ||
| 735 | + * @param endDateStr 结束日期 | ||
| 736 | + * @return Date[] 日期数组 | ||
| 737 | + */ | ||
| 738 | + public static Date[] getBetweenTwoDayArray(String startDateStr, String endDateStr) { | ||
| 739 | + Date startDate = string2Date(startDateStr, "yyyy-MM-dd"); | ||
| 740 | + int dateNum = Integer.parseInt(getDaysBetweenTwoDates(startDateStr, endDateStr)) + 1; | ||
| 741 | + Date[] dataArray = new Date[dateNum]; | ||
| 742 | + for (int i = 0; i < dateNum; i++) { | ||
| 743 | + dataArray[i] = startDate; | ||
| 744 | + startDate = org.apache.commons.lang3.time.DateUtils.addDays(startDate, 1); | ||
| 745 | + } | ||
| 746 | + return dataArray; | ||
| 747 | + } | ||
| 748 | + | ||
| 749 | + /** | ||
| 750 | + * 功能:获取两日期之间的天数 | ||
| 751 | + * | ||
| 752 | + * @param dateFrom 起始日期 | ||
| 753 | + * @param dateEnd 结束日期 | ||
| 754 | + * @return | ||
| 755 | + */ | ||
| 756 | + public static String getDaysBetweenTwoDates(String dateFrom, String dateEnd) { | ||
| 757 | + Date dtFrom = null; | ||
| 758 | + Date dtEnd = null; | ||
| 759 | + dtFrom = string2Date(dateFrom, "yyyy-MM-dd"); | ||
| 760 | + dtEnd = string2Date(dateEnd, "yyyy-MM-dd"); | ||
| 761 | + long begin = dtFrom.getTime(); | ||
| 762 | + long end = dtEnd.getTime(); | ||
| 763 | + long inter = end - begin; | ||
| 764 | + if (inter < 0) { | ||
| 765 | + inter = inter * (-1); | ||
| 766 | + } | ||
| 767 | + long dateMillSec = 24 * 60 * 60 * 1000; | ||
| 768 | + long dateCnt = inter / dateMillSec; | ||
| 769 | + long remainder = inter % dateMillSec; | ||
| 770 | + | ||
| 771 | + if (remainder != 0) { | ||
| 772 | + dateCnt++; | ||
| 773 | + } | ||
| 774 | + return String.valueOf(dateCnt); | ||
| 775 | + } | ||
| 776 | + | ||
| 777 | + /** | ||
| 778 | + * 功能: 待确定 | ||
| 779 | + * | ||
| 780 | + * @param startDateStr | ||
| 781 | + * @param endDateStr | ||
| 782 | + * @return | ||
| 783 | + */ | ||
| 784 | + public static String[] getBetweenTwoDayMonthArray(String startDateStr, String endDateStr) { | ||
| 785 | + Date[] dateArray = getBetweenTwoDayArray(startDateStr, endDateStr); | ||
| 786 | + | ||
| 787 | + String monthFirstDay = formatDateYyyyMmDd(dateArray[0]).substring(2, 7); | ||
| 788 | + List<String> dayList = new ArrayList<String>(); | ||
| 789 | + dayList.add(monthFirstDay); | ||
| 790 | + for (int i = 0; i < dateArray.length; i++) { | ||
| 791 | + if (!monthFirstDay.equals(formatDateYyyyMmDd(dateArray[i]).substring(2, 7))) { | ||
| 792 | + monthFirstDay = formatDateYyyyMmDd(dateArray[i]).substring(2, 7); | ||
| 793 | + dayList.add(monthFirstDay); | ||
| 794 | + } | ||
| 795 | + } | ||
| 796 | + String[] strArray = new String[dayList.size()]; | ||
| 797 | + for (int i = 0; i < strArray.length; i++) { | ||
| 798 | + strArray[i] = dayList.get(i).substring(0, 2) + dayList.get(i).substring(3, 5); | ||
| 799 | + } | ||
| 800 | + | ||
| 801 | + return strArray; | ||
| 802 | + } | ||
| 803 | + | ||
| 804 | + /** | ||
| 805 | + * 功能:获取星期几 SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and | ||
| 806 | + * SATURDAY | ||
| 807 | + * | ||
| 808 | + * @param date | ||
| 809 | + * @return | ||
| 810 | + */ | ||
| 811 | + public static int getWeekByDate(Date date) { | ||
| 812 | + Calendar cl1 = Calendar.getInstance(); | ||
| 813 | + cl1.setTime(date); | ||
| 814 | + cl1.set(Calendar.HOUR_OF_DAY, 0); | ||
| 815 | + cl1.set(Calendar.MINUTE, 0); | ||
| 816 | + cl1.set(Calendar.SECOND, 0); | ||
| 817 | + return cl1.get(Calendar.DAY_OF_WEEK); | ||
| 818 | + } | ||
| 819 | + | ||
| 820 | + /** | ||
| 821 | + * 功能:字符串转换为日期 | ||
| 822 | + * | ||
| 823 | + * @param datetext yyyy/MM/dd | ||
| 824 | + * @return | ||
| 825 | + */ | ||
| 826 | + public static Date formatDateYyyyMmDd(String datetext) { | ||
| 827 | + try { | ||
| 828 | + SimpleDateFormat df; | ||
| 829 | + if (datetext == null || "".equals(datetext.trim())) { | ||
| 830 | + return null; | ||
| 831 | + } | ||
| 832 | + datetext = datetext.replaceAll("/", "-"); | ||
| 833 | + df = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 834 | + Date date = df.parse(datetext); | ||
| 835 | + return date; | ||
| 836 | + } catch (Exception e) { | ||
| 837 | + e.printStackTrace(); | ||
| 838 | + return null; | ||
| 839 | + } | ||
| 840 | + } | ||
| 841 | + | ||
| 842 | + /** | ||
| 843 | + * 功能: 添加Minute | ||
| 844 | + * | ||
| 845 | + * @param cdate | ||
| 846 | + * @param amount | ||
| 847 | + * @return | ||
| 848 | + */ | ||
| 849 | + public static Date addMinute(Date cdate, int amount) { | ||
| 850 | + Calendar cl = Calendar.getInstance(); | ||
| 851 | + cl.setTime(cdate); | ||
| 852 | + cl.add(Calendar.MINUTE, amount); | ||
| 853 | + return cl.getTime(); | ||
| 854 | + } | ||
| 855 | + | ||
| 856 | + /** | ||
| 857 | + * 功能: 添加Hour | ||
| 858 | + * | ||
| 859 | + * @param cdate | ||
| 860 | + * @param amount | ||
| 861 | + * @return | ||
| 862 | + */ | ||
| 863 | + public static Date addHour(Date cdate, int amount) { | ||
| 864 | + Calendar cl = Calendar.getInstance(); | ||
| 865 | + cl.setTime(cdate); | ||
| 866 | + cl.add(Calendar.HOUR_OF_DAY, amount); | ||
| 867 | + return cl.getTime(); | ||
| 868 | + } | ||
| 869 | + | ||
| 870 | + /** | ||
| 871 | + * 功能: 添加Date | ||
| 872 | + * | ||
| 873 | + * @param cdate | ||
| 874 | + * @param amount | ||
| 875 | + * @return | ||
| 876 | + */ | ||
| 877 | + public static Date addDate(Date cdate, int amount) { | ||
| 878 | + Calendar cl = Calendar.getInstance(); | ||
| 879 | + cl.setTime(cdate); | ||
| 880 | + cl.add(Calendar.DAY_OF_MONTH, amount); | ||
| 881 | + return cl.getTime(); | ||
| 882 | + } | ||
| 883 | + | ||
| 884 | + /** | ||
| 885 | + * 功能: 添加Year | ||
| 886 | + * | ||
| 887 | + * @param basicDate | ||
| 888 | + * @param year | ||
| 889 | + * @return | ||
| 890 | + */ | ||
| 891 | + public static String addYeas(String basicDate, int year) { | ||
| 892 | + try { | ||
| 893 | + Calendar cal = Calendar.getInstance(); | ||
| 894 | + cal.setTime(java.sql.Date.valueOf(basicDate)); | ||
| 895 | + cal.add(GregorianCalendar.YEAR, year); | ||
| 896 | + return formatDate(cal.getTime(), "yyyy-MM-dd"); | ||
| 897 | + } catch (Exception e) { | ||
| 898 | + e.printStackTrace(); | ||
| 899 | + return ""; | ||
| 900 | + } | ||
| 901 | + } | ||
| 902 | + | ||
| 903 | + /** | ||
| 904 | + * 添加Month | ||
| 905 | + * | ||
| 906 | + * @param cdate | ||
| 907 | + * @param amount | ||
| 908 | + * @return | ||
| 909 | + */ | ||
| 910 | + public static Date addMonth(Date cdate, int amount) { | ||
| 911 | + Calendar cl = Calendar.getInstance(); | ||
| 912 | + cl.setTime(cdate); | ||
| 913 | + cl.add(Calendar.MONTH, amount); | ||
| 914 | + return cl.getTime(); | ||
| 915 | + } | ||
| 916 | + | ||
| 917 | + public static String formatDateYyyyMmDd(Date date) { | ||
| 918 | + try { | ||
| 919 | + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 920 | + return formatter.format(date); | ||
| 921 | + | ||
| 922 | + } catch (Exception e) { | ||
| 923 | + return null; | ||
| 924 | + } | ||
| 925 | + } | ||
| 926 | + | ||
| 927 | + /** | ||
| 928 | + * 功能: 日期转换为字符串 | ||
| 929 | + * | ||
| 930 | + * @param dd | ||
| 931 | + * @return yyyy/MM/dd | ||
| 932 | + */ | ||
| 933 | + public static String convertDateToStr(Date dd) { | ||
| 934 | + Calendar calendar = Calendar.getInstance(); | ||
| 935 | + calendar.setTime(dd); | ||
| 936 | + int day = calendar.get(Calendar.DAY_OF_MONTH); | ||
| 937 | + int month = calendar.get(Calendar.MONTH) + 1; | ||
| 938 | + int year = calendar.get(Calendar.YEAR); | ||
| 939 | + String testDate = ""; | ||
| 940 | + testDate = testDate + year + "/"; | ||
| 941 | + if (month < 10) { | ||
| 942 | + testDate = testDate + "0" + month + "/"; | ||
| 943 | + } else { | ||
| 944 | + testDate += month + "/"; | ||
| 945 | + } | ||
| 946 | + if (day < 10) { | ||
| 947 | + testDate = testDate + "0" + day; | ||
| 948 | + } else { | ||
| 949 | + testDate += day; | ||
| 950 | + } | ||
| 951 | + return testDate; | ||
| 952 | + } | ||
| 953 | + | ||
| 954 | + /** | ||
| 955 | + * 功能:根据某个日期,返回本月的天数 | ||
| 956 | + * | ||
| 957 | + * @param date 本月任何一天 | ||
| 958 | + * @return 天数 | ||
| 959 | + */ | ||
| 960 | + public static int getMonthsMaxDay(Date date) { | ||
| 961 | + Calendar cal1 = Calendar.getInstance(); | ||
| 962 | + cal1.setTime(date); | ||
| 963 | + return cal1.getActualMaximum(Calendar.DAY_OF_MONTH); | ||
| 964 | + } | ||
| 965 | + | ||
| 966 | + /** | ||
| 967 | + * 功能:获取指定日 开始本月的之后天数 | ||
| 968 | + * | ||
| 969 | + * @param stringDate yyyy-MM-dd | ||
| 970 | + * @return 天数(eg:"1,2,3,") | ||
| 971 | + */ | ||
| 972 | + public static String getMonthsResidualDayNum(String stringDate) { | ||
| 973 | + Date date = formatDateYyyyMmDd(stringDate); | ||
| 974 | + Calendar cal1 = Calendar.getInstance(); | ||
| 975 | + cal1.setTime(date); | ||
| 976 | + String dayList = ""; | ||
| 977 | + for (int i = Integer.parseInt(stringDate.substring(8)); i < cal1.getActualMaximum(Calendar.DATE) + 1; i++) { | ||
| 978 | + dayList += i + ","; | ||
| 979 | + } | ||
| 980 | + return dayList; | ||
| 981 | + } | ||
| 982 | + | ||
| 983 | + /** | ||
| 984 | + * 功能:获取指定日 开始本月的之前天数 | ||
| 985 | + * | ||
| 986 | + * @param stringDate yyyy-MM-dd | ||
| 987 | + * @return 天数(eg:"1,2,3,") | ||
| 988 | + */ | ||
| 989 | + public static String getMonthsAlreadyDayNum(String stringDate) { | ||
| 990 | + String dayList = ""; | ||
| 991 | + for (int i = 1; i < Integer.parseInt(stringDate.substring(8)) + 1; i++) { | ||
| 992 | + dayList += i + ","; | ||
| 993 | + } | ||
| 994 | + return dayList; | ||
| 995 | + | ||
| 996 | + } | ||
| 997 | + | ||
| 998 | + /** | ||
| 999 | + * 功能:获取指定日 开始本月的所有天数 | ||
| 1000 | + * | ||
| 1001 | + * @param stringDate yyyy-MM-dd | ||
| 1002 | + * @return 天数(eg:"1,2,3,") | ||
| 1003 | + */ | ||
| 1004 | + public static String getMonthsDayNum(String stringDate) { | ||
| 1005 | + Date date = formatDateYyyyMmDd(stringDate); | ||
| 1006 | + Calendar cal1 = Calendar.getInstance(); | ||
| 1007 | + cal1.setTime(date); | ||
| 1008 | + String dayList = ""; | ||
| 1009 | + for (int i = 1; i < cal1.getActualMaximum(Calendar.DATE) + 1; i++) { | ||
| 1010 | + dayList += i + ","; | ||
| 1011 | + } | ||
| 1012 | + return dayList; | ||
| 1013 | + | ||
| 1014 | + } | ||
| 1015 | + | ||
| 1016 | + /** | ||
| 1017 | + * 功能:三个月的指定日期 | ||
| 1018 | + * | ||
| 1019 | + * @param stringDate | ||
| 1020 | + * @return | ||
| 1021 | + */ | ||
| 1022 | + public static Date[] getNextThreeMonths(String stringDate) { | ||
| 1023 | + Date date1 = formatDateYyyyMmDd(stringDate); | ||
| 1024 | + Date date2 = org.apache.commons.lang3.time.DateUtils.addMonths(date1, 1); | ||
| 1025 | + Date date3 = org.apache.commons.lang3.time.DateUtils.addMonths(date2, 1); | ||
| 1026 | + Date[] dataArray = { date1, date2, date3 }; | ||
| 1027 | + return dataArray; | ||
| 1028 | + } | ||
| 1029 | + | ||
| 1030 | + /** | ||
| 1031 | + * 功能:根据某个日期,返回本月的所有日期数组 | ||
| 1032 | + * | ||
| 1033 | + * @param date 给定日期 | ||
| 1034 | + * @return 本月的所有日期数组 | ||
| 1035 | + */ | ||
| 1036 | + public static Date[] getOneMonthsDayArray(Date date) { | ||
| 1037 | + Calendar cal1 = Calendar.getInstance(); | ||
| 1038 | + cal1.setTime(date); | ||
| 1039 | + cal1.set(Calendar.DATE, 1); | ||
| 1040 | + | ||
| 1041 | + int dayTimes = cal1.getActualMaximum(Calendar.DAY_OF_MONTH); | ||
| 1042 | + Date[] dataArray = new Date[dayTimes]; | ||
| 1043 | + | ||
| 1044 | + for (int i = 0; i < dayTimes; i++) { | ||
| 1045 | + dataArray[i] = cal1.getTime(); | ||
| 1046 | + cal1.setTime(org.apache.commons.lang3.time.DateUtils.addDays(dataArray[i], 1)); | ||
| 1047 | + } | ||
| 1048 | + return dataArray; | ||
| 1049 | + } | ||
| 1050 | + | ||
| 1051 | + /** | ||
| 1052 | + * 功能:根据某个日期,返回monthNum个月的第一天数组 | ||
| 1053 | + * | ||
| 1054 | + * @param date 开始日期 | ||
| 1055 | + * @param monthNum 月份个数 | ||
| 1056 | + * @return 每个月的第一天数组 | ||
| 1057 | + */ | ||
| 1058 | + public static Date[] getXMonthsFirstDayArray(Date date, int monthNum) { | ||
| 1059 | + Date[] dataArray = new Date[monthNum]; | ||
| 1060 | + Calendar cal1 = Calendar.getInstance(); | ||
| 1061 | + cal1.setTime(date); | ||
| 1062 | + cal1.set(Calendar.DATE, 1); | ||
| 1063 | + for (int i = 0; i < monthNum; i++) { | ||
| 1064 | + dataArray[i] = org.apache.commons.lang3.time.DateUtils.addMonths(cal1.getTime(), i); | ||
| 1065 | + } | ||
| 1066 | + | ||
| 1067 | + return dataArray; | ||
| 1068 | + } | ||
| 1069 | + | ||
| 1070 | + /** | ||
| 1071 | + * 功能:根据1个日期,返回N天之内的日期数组 | ||
| 1072 | + * | ||
| 1073 | + * @param startDateStr 开始日期 | ||
| 1074 | + * @param dayTimes 天数 | ||
| 1075 | + * @return 这段时间之间的日期数组 | ||
| 1076 | + */ | ||
| 1077 | + public static Date[] getBetweenTwoDayArray(String startDateStr, int dayTimes) { | ||
| 1078 | + Date startDate = formatDateYyyyMmDd(startDateStr); | ||
| 1079 | + Date[] dataArray = new Date[dayTimes]; | ||
| 1080 | + for (int i = 0; i < dayTimes; i++) { | ||
| 1081 | + dataArray[i] = startDate; | ||
| 1082 | + startDate = org.apache.commons.lang3.time.DateUtils.addDays(startDate, 1); | ||
| 1083 | + } | ||
| 1084 | + | ||
| 1085 | + return dataArray; | ||
| 1086 | + } | ||
| 1087 | + | ||
| 1088 | + /** | ||
| 1089 | + * 功能:根据1个日期,返回N天之内的yy-MM月份数组 | ||
| 1090 | + * | ||
| 1091 | + * @param startDateStr 开始日期 | ||
| 1092 | + * @param dayTimes 天数 | ||
| 1093 | + * @return 这段时间之间的日期数组 | ||
| 1094 | + */ | ||
| 1095 | + public static String[] getBetweenTwoDayMonthArray(String startDateStr, int dayTimes) { | ||
| 1096 | + Date[] dateArray = getBetweenTwoDayArray(startDateStr, dayTimes); | ||
| 1097 | + | ||
| 1098 | + String monthFirstDay = formatDateYyyyMmDd(dateArray[0]).substring(2, 7); | ||
| 1099 | + List<String> dayList = new ArrayList<String>(); | ||
| 1100 | + dayList.add(monthFirstDay); | ||
| 1101 | + for (int i = 0; i < dateArray.length; i++) { | ||
| 1102 | + if (!monthFirstDay.equals(formatDateYyyyMmDd(dateArray[i]).substring(2, 7))) { | ||
| 1103 | + | ||
| 1104 | + monthFirstDay = formatDateYyyyMmDd(dateArray[i]).substring(2, 7); | ||
| 1105 | + dayList.add(monthFirstDay); | ||
| 1106 | + } | ||
| 1107 | + } | ||
| 1108 | + | ||
| 1109 | + String[] strArray = new String[dayList.size()]; | ||
| 1110 | + for (int i = 0; i < strArray.length; i++) { | ||
| 1111 | + strArray[i] = dayList.get(i).substring(0, 2) + dayList.get(i).substring(3, 5); | ||
| 1112 | + } | ||
| 1113 | + | ||
| 1114 | + return strArray; | ||
| 1115 | + } | ||
| 1116 | + | ||
| 1117 | + /** | ||
| 1118 | + * 功能:根据1个日期,返回上N个月的第一天 | ||
| 1119 | + * | ||
| 1120 | + * @param date 日期 | ||
| 1121 | + * @param month 上N月 | ||
| 1122 | + * @return 上N个月的第一天 | ||
| 1123 | + */ | ||
| 1124 | + public static Date rollMonth(Date date, int month) { | ||
| 1125 | + try { | ||
| 1126 | + Calendar cal = Calendar.getInstance(); | ||
| 1127 | + cal.setTime(date); | ||
| 1128 | + cal.set(Calendar.DATE, 1); | ||
| 1129 | + cal.roll(Calendar.MONTH, month); | ||
| 1130 | + | ||
| 1131 | + return cal.getTime(); | ||
| 1132 | + | ||
| 1133 | + } catch (Exception e) { | ||
| 1134 | + e.printStackTrace(); | ||
| 1135 | + return null; | ||
| 1136 | + } | ||
| 1137 | + } | ||
| 1138 | + | ||
| 1139 | + /** | ||
| 1140 | + * @return yyyy-MM-dd HH:mm:ss | ||
| 1141 | + */ | ||
| 1142 | + public static String getDateTime() { | ||
| 1143 | + Date dateTime = new Date(); | ||
| 1144 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 1145 | + String strTime = format.format(dateTime); | ||
| 1146 | + return strTime; | ||
| 1147 | + } | ||
| 1148 | + | ||
| 1149 | + /** | ||
| 1150 | + * @return yyyy-MM-dd | ||
| 1151 | + */ | ||
| 1152 | + public static String getDate() { | ||
| 1153 | + Date dateTime = new Date(); | ||
| 1154 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 1155 | + String strTime = format.format(dateTime); | ||
| 1156 | + return strTime; | ||
| 1157 | + } | ||
| 1158 | + | ||
| 1159 | + /** | ||
| 1160 | + * Get the date of monday in this week | ||
| 1161 | + * | ||
| 1162 | + * @return yyyy-MM-dd | ||
| 1163 | + */ | ||
| 1164 | + public static String getMondayOfThisWeek() { | ||
| 1165 | + String strTemp = ""; | ||
| 1166 | + Calendar c = Calendar.getInstance(); | ||
| 1167 | + int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1; | ||
| 1168 | + if (dayofweek == 0){ | ||
| 1169 | + dayofweek = 7; | ||
| 1170 | + } | ||
| 1171 | + | ||
| 1172 | + c.add(Calendar.DATE, -dayofweek + 1); | ||
| 1173 | + strTemp = c.get(1) + "-"; | ||
| 1174 | + if (c.get(2) + 1 < 10){ | ||
| 1175 | + strTemp += "0"; | ||
| 1176 | + } | ||
| 1177 | + | ||
| 1178 | + strTemp = strTemp + (c.get(2) + 1) + "-"; | ||
| 1179 | + if (c.get(5) < 10){ | ||
| 1180 | + strTemp += "0"; | ||
| 1181 | + } | ||
| 1182 | + | ||
| 1183 | + strTemp += c.get(5); | ||
| 1184 | + return strTemp; | ||
| 1185 | + } | ||
| 1186 | + | ||
| 1187 | + /** | ||
| 1188 | + * Get the date of sunday in this week | ||
| 1189 | + * | ||
| 1190 | + * @return yyyy-MM-dd | ||
| 1191 | + */ | ||
| 1192 | + public static String getSundayOfThisWeek() { | ||
| 1193 | + String strTemp = ""; | ||
| 1194 | + Calendar c = Calendar.getInstance(); | ||
| 1195 | + int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1; | ||
| 1196 | + if (dayofweek == 0){ | ||
| 1197 | + dayofweek = 7; | ||
| 1198 | + } | ||
| 1199 | + | ||
| 1200 | + c.add(Calendar.DATE, -dayofweek + 7); | ||
| 1201 | + strTemp = c.get(1) + "-"; | ||
| 1202 | + if (c.get(2) + 1 < 10){ | ||
| 1203 | + strTemp += "0"; | ||
| 1204 | + } | ||
| 1205 | + | ||
| 1206 | + strTemp = strTemp + (c.get(2) + 1) + "-"; | ||
| 1207 | + if (c.get(5) < 10){ | ||
| 1208 | + strTemp += "0"; | ||
| 1209 | + } | ||
| 1210 | + | ||
| 1211 | + strTemp += c.get(5); | ||
| 1212 | + return strTemp; | ||
| 1213 | + } | ||
| 1214 | + | ||
| 1215 | + /** | ||
| 1216 | + * Get the date of AfterDays | ||
| 1217 | + * | ||
| 1218 | + * @param day | ||
| 1219 | + * @return yyyy-MM-dd | ||
| 1220 | + */ | ||
| 1221 | + public static String getTheDayAfterDays(int day) { | ||
| 1222 | + String strTemp = ""; | ||
| 1223 | + Calendar c = Calendar.getInstance(); | ||
| 1224 | + c.add(Calendar.DATE, day); | ||
| 1225 | + strTemp = c.get(1) + "-"; | ||
| 1226 | + if (c.get(2) + 1 < 10){ | ||
| 1227 | + strTemp += "0"; | ||
| 1228 | + } | ||
| 1229 | + | ||
| 1230 | + strTemp = strTemp + (c.get(2) + 1) + "-"; | ||
| 1231 | + if (c.get(5) < 10){ | ||
| 1232 | + strTemp += "0"; | ||
| 1233 | + } | ||
| 1234 | + strTemp += c.get(5); | ||
| 1235 | + return strTemp; | ||
| 1236 | + } | ||
| 1237 | + | ||
| 1238 | + /** | ||
| 1239 | + * Get data time in user's specific format | ||
| 1240 | + * | ||
| 1241 | + * @param strFormat | ||
| 1242 | + * @return String strDtTime | ||
| 1243 | + */ | ||
| 1244 | + public static String getLocalDateTime(String strFormat) { | ||
| 1245 | + String strDtTime = ""; | ||
| 1246 | + if (strFormat != null && !strFormat.equals("")) { | ||
| 1247 | + SimpleDateFormat simpledateformat = new SimpleDateFormat(strFormat); | ||
| 1248 | + long lngVal = System.currentTimeMillis(); | ||
| 1249 | + strDtTime = simpledateformat.format(new Date(lngVal)); | ||
| 1250 | + } | ||
| 1251 | + return strDtTime; | ||
| 1252 | + } | ||
| 1253 | + | ||
| 1254 | + /** | ||
| 1255 | + * Get data time in yyyyMMddHHmmss format | ||
| 1256 | + * | ||
| 1257 | + * @return String strDtTime | ||
| 1258 | + */ | ||
| 1259 | + public static String getDateTimeStamp() { | ||
| 1260 | + SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss"); | ||
| 1261 | + long lngVal = System.currentTimeMillis(); | ||
| 1262 | + String strDtTime = simpledateformat.format(new Date(lngVal)); | ||
| 1263 | + return strDtTime; | ||
| 1264 | + } | ||
| 1265 | + | ||
| 1266 | + /** | ||
| 1267 | + * Get date time in yyyyMMdd format | ||
| 1268 | + * | ||
| 1269 | + * @return String strDtTime | ||
| 1270 | + */ | ||
| 1271 | + public static String getDateStamp() { | ||
| 1272 | + SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); | ||
| 1273 | + long lngVal = System.currentTimeMillis(); | ||
| 1274 | + String strDtTime = simpledateformat.format(new Date(lngVal)); | ||
| 1275 | + return strDtTime; | ||
| 1276 | + } | ||
| 1277 | + | ||
| 1278 | + /** | ||
| 1279 | + * Get date time in HHmmss format | ||
| 1280 | + * | ||
| 1281 | + * @return String strDtTime | ||
| 1282 | + */ | ||
| 1283 | + public static String getTimeStamp() { | ||
| 1284 | + SimpleDateFormat simpledateformat = new SimpleDateFormat("HHmmss"); | ||
| 1285 | + long lngVal = System.currentTimeMillis(); | ||
| 1286 | + String strDtTime = simpledateformat.format(new Date(lngVal)); | ||
| 1287 | + return strDtTime; | ||
| 1288 | + } | ||
| 1289 | + | ||
| 1290 | + /** | ||
| 1291 | + * Get date time in yyyy年MM月dd日hh:mm:ss format | ||
| 1292 | + * | ||
| 1293 | + * @return String sb | ||
| 1294 | + */ | ||
| 1295 | + public static String getDateTimeCN() { | ||
| 1296 | + StringBuffer stringbuffer = new StringBuffer(); | ||
| 1297 | + Calendar calendar = Calendar.getInstance(); | ||
| 1298 | + stringbuffer.setLength(0); | ||
| 1299 | + stringbuffer.append(calendar.get(1)); | ||
| 1300 | + stringbuffer.append('年'); | ||
| 1301 | + stringbuffer.append(calendar.get(2) + 1); | ||
| 1302 | + stringbuffer.append('月'); | ||
| 1303 | + stringbuffer.append(calendar.get(5)); | ||
| 1304 | + stringbuffer.append('日'); | ||
| 1305 | + stringbuffer.append(calendar.get(11)); | ||
| 1306 | + stringbuffer.append(':'); | ||
| 1307 | + if (calendar.get(12) < 10){ | ||
| 1308 | + stringbuffer.append(0); | ||
| 1309 | + } | ||
| 1310 | + | ||
| 1311 | + stringbuffer.append(calendar.get(12)); | ||
| 1312 | + stringbuffer.append(':'); | ||
| 1313 | + if (calendar.get(13) < 10){ | ||
| 1314 | + stringbuffer.append(0); | ||
| 1315 | + } | ||
| 1316 | + | ||
| 1317 | + stringbuffer.append(calendar.get(13)); | ||
| 1318 | + return stringbuffer.toString(); | ||
| 1319 | + } | ||
| 1320 | + | ||
| 1321 | + /** | ||
| 1322 | + * Get date time in Hashmap | ||
| 1323 | + * | ||
| 1324 | + * @return a HashMap | ||
| 1325 | + */ | ||
| 1326 | + public static Map<String, Integer> getDateTimeToHashMap() { | ||
| 1327 | + Map<String, Integer> hpDt = new HashMap<String, Integer>(); | ||
| 1328 | + Calendar cal = Calendar.getInstance(); | ||
| 1329 | + hpDt.put("YEAR", new Integer(cal.get(Calendar.YEAR))); | ||
| 1330 | + hpDt.put("MONTH", new Integer(cal.get(Calendar.MONTH) + 1)); | ||
| 1331 | + hpDt.put("DAY", new Integer(cal.get(Calendar.DAY_OF_MONTH))); | ||
| 1332 | + hpDt.put("HOUR", new Integer(cal.get(Calendar.HOUR_OF_DAY))); | ||
| 1333 | + hpDt.put("MINUTE", new Integer(cal.get(Calendar.MINUTE))); | ||
| 1334 | + hpDt.put("SECOND", new Integer(cal.get(Calendar.SECOND))); | ||
| 1335 | + return hpDt; | ||
| 1336 | + } | ||
| 1337 | + | ||
| 1338 | + /** | ||
| 1339 | + * Format time 2005-10-08 10:03:41.0 to 2005-10-08 10:03:41 . | ||
| 1340 | + * | ||
| 1341 | + * @param str the time string | ||
| 1342 | + * @return String | ||
| 1343 | + */ | ||
| 1344 | + public static String getFormatTimeStamp(String str) { | ||
| 1345 | + str = (str == null) ? "" : str; | ||
| 1346 | + String strTemp = ""; | ||
| 1347 | + for (int i = 0; i < str.length(); i++) { | ||
| 1348 | + if (str.charAt(i) == '.') { | ||
| 1349 | + break; | ||
| 1350 | + } | ||
| 1351 | + strTemp += str.charAt(i); | ||
| 1352 | + } | ||
| 1353 | + return strTemp; | ||
| 1354 | + } | ||
| 1355 | + | ||
| 1356 | + public static String getFormatDate(String str) { | ||
| 1357 | + str = (str == null) ? "" : str; | ||
| 1358 | + String strTemp = ""; | ||
| 1359 | + for (int i = 0; i < str.length(); i++) { | ||
| 1360 | + if (str.charAt(i) == ' ') { | ||
| 1361 | + break; | ||
| 1362 | + } | ||
| 1363 | + strTemp += str.charAt(i); | ||
| 1364 | + } | ||
| 1365 | + return strTemp; | ||
| 1366 | + } | ||
| 1367 | + | ||
| 1368 | + public static boolean isInDayRange(Date availDate, Date indateFrom, Date indateTo) { | ||
| 1369 | + Assert.notNull(availDate); | ||
| 1370 | + Calendar c = Calendar.getInstance(); | ||
| 1371 | + c.setTime(availDate); | ||
| 1372 | + c.set(Calendar.HOUR_OF_DAY, 0); | ||
| 1373 | + c.set(Calendar.MINUTE, 0); | ||
| 1374 | + c.set(Calendar.SECOND, 0); | ||
| 1375 | + c.set(Calendar.MILLISECOND, 0); | ||
| 1376 | + if (indateFrom != null) { | ||
| 1377 | + Calendar c1 = Calendar.getInstance(); | ||
| 1378 | + c1.setTime(indateFrom); | ||
| 1379 | + c1.set(Calendar.HOUR_OF_DAY, 0); | ||
| 1380 | + c1.set(Calendar.MINUTE, 0); | ||
| 1381 | + c1.set(Calendar.SECOND, 0); | ||
| 1382 | + c1.set(Calendar.MILLISECOND, 0); | ||
| 1383 | + if (c.before(c1)){ | ||
| 1384 | + return false; | ||
| 1385 | + } | ||
| 1386 | + } | ||
| 1387 | + if (indateTo != null) { | ||
| 1388 | + Calendar c2 = Calendar.getInstance(); | ||
| 1389 | + c2.setTime(indateTo); | ||
| 1390 | + c2.set(Calendar.HOUR_OF_DAY, 0); | ||
| 1391 | + c2.set(Calendar.MINUTE, 0); | ||
| 1392 | + c2.set(Calendar.SECOND, 0); | ||
| 1393 | + c2.set(Calendar.MILLISECOND, 0); | ||
| 1394 | + if (c.after(c2)) | ||
| 1395 | + return false; | ||
| 1396 | + } | ||
| 1397 | + | ||
| 1398 | + return true; | ||
| 1399 | + } | ||
| 1400 | + | ||
| 1401 | + /** | ||
| 1402 | + * 获取从start到end之间的日期(格式yyyyMM) | ||
| 1403 | + * | ||
| 1404 | + * @param start | ||
| 1405 | + * @param end | ||
| 1406 | + * @return | ||
| 1407 | + */ | ||
| 1408 | + public static List<String> getBetweenMonths(Date start, Date end) { | ||
| 1409 | + SimpleDateFormat df = new SimpleDateFormat(YEAR_MONTH); | ||
| 1410 | + Date _start = org.apache.commons.lang3.time.DateUtils.truncate(start, Calendar.MONTH); | ||
| 1411 | + List<String> months = new ArrayList<String>(); | ||
| 1412 | + while (!_start.after(end)) { | ||
| 1413 | + months.add(df.format(_start)); | ||
| 1414 | + _start = org.apache.commons.lang3.time.DateUtils.addMonths(_start, 1); | ||
| 1415 | + } | ||
| 1416 | + return months; | ||
| 1417 | + } | ||
| 1418 | + | ||
| 1419 | + /** | ||
| 1420 | + * 获取从start到end之间的日期(格式yyyyMMdd) | ||
| 1421 | + * | ||
| 1422 | + * @param start | ||
| 1423 | + * @param end | ||
| 1424 | + * @return | ||
| 1425 | + */ | ||
| 1426 | + public static List<String> getBetweenDays(Date start, Date end) { | ||
| 1427 | + SimpleDateFormat df = new SimpleDateFormat(SHORT_DATE); | ||
| 1428 | + Date _start = org.apache.commons.lang3.time.DateUtils.truncate(start, Calendar.DAY_OF_MONTH); | ||
| 1429 | + List<String> days = new ArrayList<String>(); | ||
| 1430 | + while (!_start.after(end)) { | ||
| 1431 | + days.add(df.format(_start)); | ||
| 1432 | + _start = org.apache.commons.lang3.time.DateUtils.addDays(_start, 1); | ||
| 1433 | + } | ||
| 1434 | + return days; | ||
| 1435 | + } | ||
| 1436 | + | ||
| 1437 | + /** | ||
| 1438 | + * 将字符串日期转换为Date | ||
| 1439 | + * | ||
| 1440 | + * @param s | ||
| 1441 | + * @return | ||
| 1442 | + */ | ||
| 1443 | + public static Date convertToDate(String s) { | ||
| 1444 | + DateFormat df; | ||
| 1445 | + if (s == null) { | ||
| 1446 | + return null; | ||
| 1447 | + } | ||
| 1448 | + if (s.contains(":")) { | ||
| 1449 | + try { | ||
| 1450 | + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 1451 | + return df.parse(s); | ||
| 1452 | + } catch (Exception e) { | ||
| 1453 | + log.error(e.getMessage()); | ||
| 1454 | + return null; | ||
| 1455 | + } | ||
| 1456 | + } else { | ||
| 1457 | + try { | ||
| 1458 | + df = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 1459 | + return df.parse(s); | ||
| 1460 | + } catch (Exception e) { | ||
| 1461 | + log.error(e.getMessage()); | ||
| 1462 | + return null; | ||
| 1463 | + } | ||
| 1464 | + } | ||
| 1465 | + } | ||
| 1466 | + | ||
| 1467 | + /** | ||
| 1468 | + * 获取当期日期 | ||
| 1469 | + * | ||
| 1470 | + * @return | ||
| 1471 | + */ | ||
| 1472 | + public static Date getCurrentDate(){ | ||
| 1473 | + Calendar curDate = Calendar.getInstance(); | ||
| 1474 | + curDate.set(Calendar.HOUR_OF_DAY, 0); | ||
| 1475 | + curDate.set(Calendar.MINUTE, 0); | ||
| 1476 | + curDate.set(Calendar.SECOND, 0); | ||
| 1477 | + curDate.set(Calendar.MILLISECOND, 0); | ||
| 1478 | + | ||
| 1479 | + return curDate.getTime(); | ||
| 1480 | + } | ||
| 1481 | + | ||
| 1482 | + | ||
| 1483 | + public static Date timeStampToDate(long timeStamp){ | ||
| 1484 | + return new Date(timeStamp); | ||
| 1485 | + } | ||
| 1486 | + | ||
| 1487 | +} |
| 1 | +package com.erry.iclear.dateInterface; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.api.request.Mawb; | ||
| 4 | +import com.erry.iclear.dateInterface.api.request.MawbDetail; | ||
| 5 | +import com.erry.iclear.dateInterface.service.ChmConsignmentService; | ||
| 6 | +import org.junit.Test; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | + | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.util.ArrayList; | ||
| 11 | +import java.util.Date; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +public class ChmConsignmentServiceTest extends IClearApiApplicationTests { | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + @Autowired | ||
| 18 | + private ChmConsignmentService chmConsignmentService; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + @Test | ||
| 22 | + public void testProcessChmConsignment(){ | ||
| 23 | + try{ | ||
| 24 | + Mawb mawb = this.createNewMawb(); | ||
| 25 | + String timeStamp = String.valueOf(new Date().getTime()); | ||
| 26 | + chmConsignmentService.processChmConsignment(mawb,timeStamp); | ||
| 27 | + | ||
| 28 | + }catch (Exception e){ | ||
| 29 | + e.printStackTrace(); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + private Mawb createNewMawb(){ | ||
| 34 | + MawbDetail d1 = new MawbDetail(); | ||
| 35 | + d1.setClassMark(""); | ||
| 36 | + d1.setCodeTS("69125472"); | ||
| 37 | + d1.setDeclPrice(BigDecimal.valueOf(111.123)); | ||
| 38 | + d1.setDeclTotal(BigDecimal.valueOf(788)); | ||
| 39 | + d1.setDutyMode("1"); | ||
| 40 | + d1.setExgNo(""); | ||
| 41 | + d1.setExgVersion(""); | ||
| 42 | + d1.setFirstUnit("001"); | ||
| 43 | + d1.setFirstQty(11); | ||
| 44 | + d1.setGUnit("007"); | ||
| 45 | + d1.setGModel("商品规格、型号"); | ||
| 46 | + d1.setGName("餐桌"); | ||
| 47 | + d1.setGNo("1"); | ||
| 48 | + d1.setGQty(1); | ||
| 49 | + d1.setOriginCountry("US"); | ||
| 50 | + d1.setSecondUnit("007"); | ||
| 51 | + d1.setSecondQty(2); | ||
| 52 | + d1.setTradeCurr("USD"); | ||
| 53 | + d1.setUseTo(""); | ||
| 54 | + d1.setWorkUsd(null); | ||
| 55 | + d1.setDestinationCountry("CN"); | ||
| 56 | + d1.setCiqCode(""); | ||
| 57 | + d1.setDeclGoodsEname(""); | ||
| 58 | + d1.setDestCode(""); | ||
| 59 | + d1.setDistrictCode("4408W"); | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + MawbDetail d2 = new MawbDetail(); | ||
| 63 | + d2.setClassMark(""); | ||
| 64 | + d2.setCodeTS("69125472"); | ||
| 65 | + d2.setDeclPrice(BigDecimal.valueOf(45.72)); | ||
| 66 | + d2.setDeclTotal(BigDecimal.valueOf(33)); | ||
| 67 | + d2.setDutyMode("1"); | ||
| 68 | + d2.setExgNo(""); | ||
| 69 | + d2.setExgVersion(""); | ||
| 70 | + d2.setFirstUnit("001"); | ||
| 71 | + d2.setFirstQty(11); | ||
| 72 | + d2.setGUnit("007"); | ||
| 73 | + d2.setGModel("商品规格、型号"); | ||
| 74 | + d2.setGName("餐桌"); | ||
| 75 | + d2.setGNo("2"); | ||
| 76 | + d2.setGQty(22); | ||
| 77 | + d2.setOriginCountry("US"); | ||
| 78 | + d2.setSecondUnit("007"); | ||
| 79 | + d2.setSecondQty(3); | ||
| 80 | + d2.setTradeCurr("USD"); | ||
| 81 | + d2.setUseTo(""); | ||
| 82 | + d2.setWorkUsd(null); | ||
| 83 | + d2.setDestinationCountry("CN"); | ||
| 84 | + d2.setCiqCode(""); | ||
| 85 | + d2.setDeclGoodsEname(""); | ||
| 86 | + d2.setDestCode(""); | ||
| 87 | + d2.setDistrictCode("4408W"); | ||
| 88 | + | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + List<MawbDetail> mawbDetailList = new ArrayList<MawbDetail>(); | ||
| 92 | + mawbDetailList.add(d1); | ||
| 93 | + mawbDetailList.add(d2); | ||
| 94 | + | ||
| 95 | + | ||
| 96 | + | ||
| 97 | + | ||
| 98 | + Mawb mawb = new Mawb(); | ||
| 99 | + mawb.setIEFlag("E"); | ||
| 100 | + mawb.setType("EX"); | ||
| 101 | + mawb.setAgentCode("1111980005"); | ||
| 102 | + mawb.setAgentName("联邦快递(中国)有限公司"); | ||
| 103 | + mawb.setBillNo("202105210784"); | ||
| 104 | + mawb.setContrNo("NO.565733"); | ||
| 105 | + mawb.setCustomMaster("0101"); | ||
| 106 | + mawb.setCutMode("1");//TODO levyType_1 到底是什么code? | ||
| 107 | + mawb.setDeclTrnRel("0"); | ||
| 108 | + mawb.setDistinatePort("ASM000"); | ||
| 109 | + mawb.setEdiId("001"); | ||
| 110 | + mawb.setEntryId("25512456"); | ||
| 111 | + mawb.setFeeCurr("USD"); | ||
| 112 | + mawb.setFeeMark("3"); | ||
| 113 | + mawb.setFeeRate(BigDecimal.valueOf(100.58)); | ||
| 114 | + mawb.setGrossWet(500); | ||
| 115 | + mawb.setIEPort("0101"); | ||
| 116 | + mawb.setInputerName(""); | ||
| 117 | + mawb.setInsurCurr("MOP"); | ||
| 118 | + mawb.setInsurMark("3"); | ||
| 119 | + mawb.setInsurRate(BigDecimal.valueOf(23.44)); | ||
| 120 | + mawb.setManualNo("备案号"); | ||
| 121 | + mawb.setNetWt(BigDecimal.valueOf(80)); | ||
| 122 | + mawb.setOtherCurr("USD"); | ||
| 123 | + mawb.setOtherRate(BigDecimal.valueOf(10)); | ||
| 124 | + mawb.setOtherMark(""); | ||
| 125 | + mawb.setOwnerCode("Z321654987"); | ||
| 126 | + mawb.setOwnerName("上海保险"); | ||
| 127 | + mawb.setPackNo(1); | ||
| 128 | + mawb.setPreEntryId(""); | ||
| 129 | + mawb.setTradeCountry("US"); | ||
| 130 | + mawb.setTradeMode("110"); | ||
| 131 | + mawb.setTradeCode("Z321654987"); | ||
| 132 | + mawb.setTrafMode("1"); | ||
| 133 | + mawb.setTradeName("上海铢怡国际货物运输代理有限公司"); | ||
| 134 | + mawb.setTransMode("3"); | ||
| 135 | + mawb.setWrapType("22"); | ||
| 136 | + mawb.setTradeCodeScc("A74125896321456987"); | ||
| 137 | + mawb.setOwnerCodeScc("A74125896321456987"); | ||
| 138 | + mawb.setTradeAreaCode("US"); | ||
| 139 | + mawb.setMarkNo("N/M"); | ||
| 140 | + mawb.setEntyPortCode("310302"); | ||
| 141 | + mawb.setGoodsPlace(""); | ||
| 142 | + mawb.setDeclareName("张安"); | ||
| 143 | + mawb.setOverseasConsignorCode("Z785421"); | ||
| 144 | + mawb.setOverseasConsigneeCode("Z785421"); | ||
| 145 | + mawb.setOverseasConsigneeEname("出口时必填收件人公司名(原)"); | ||
| 146 | + mawb.setMawbDetailList(mawbDetailList); | ||
| 147 | + | ||
| 148 | + return mawb; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | +} |
| 1 | package com.erry.iclear.dateInterface; | 1 | package com.erry.iclear.dateInterface; |
| 2 | 2 | ||
| 3 | import org.junit.Test; | 3 | import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; | ||
| 4 | import org.springframework.boot.test.context.SpringBootTest; | 5 | import org.springframework.boot.test.context.SpringBootTest; |
| 6 | +import org.springframework.test.context.ActiveProfiles; | ||
| 7 | +import org.springframework.test.context.junit4.SpringRunner; | ||
| 8 | +import org.springframework.test.context.web.WebAppConfiguration; | ||
| 5 | 9 | ||
| 10 | +@RunWith(SpringRunner.class) | ||
| 6 | @SpringBootTest | 11 | @SpringBootTest |
| 12 | +@WebAppConfiguration | ||
| 13 | +@ActiveProfiles("dev") | ||
| 7 | class IClearApiApplicationTests { | 14 | class IClearApiApplicationTests { |
| 8 | 15 | ||
| 9 | @Test | 16 | @Test |
| 10 | - void contextLoads() { | 17 | + public void contextLoads() { |
| 11 | } | 18 | } |
| 12 | 19 | ||
| 13 | } | 20 | } | ... | ... |
| 1 | package com.erry.iclear.dateInterface; | 1 | package com.erry.iclear.dateInterface; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.date.DateUtil; | ||
| 4 | +import com.erry.iclear.dateInterface.util.DateUtils; | ||
| 3 | import com.erry.iclear.dateInterface.util.SHA256Util; | 5 | import com.erry.iclear.dateInterface.util.SHA256Util; |
| 4 | 6 | ||
| 7 | +import java.util.Date; | ||
| 8 | + | ||
| 5 | public class SHA256Test { | 9 | public class SHA256Test { |
| 6 | 10 | ||
| 7 | public static void main(String[] args) { | 11 | public static void main(String[] args) { |
| 8 | - long time =System.currentTimeMillis(); | 12 | +// long time =System.currentTimeMillis(); |
| 9 | - System.out.println(time); | 13 | +// System.out.println(time); |
| 10 | - String str = "CTM"+"iClearExport"+"b92131f03f19a348"+time; | 14 | +// String str = "CTM"+"iClearExport"+"b92131f03f19a348"+time; |
| 11 | - | 15 | +// |
| 12 | - | 16 | +// |
| 13 | - System.out.println(SHA256Util.getSHA256String(str)); | 17 | +// System.out.println(SHA256Util.getSHA256String(str)); |
| 14 | 18 | ||
| 15 | // | 19 | // |
| 16 | // 1623920478192 | 20 | // 1623920478192 |
| 17 | // eaf279997145f440ab5064e43f1a9cfdac15322886936801d57e022cde29919b | 21 | // eaf279997145f440ab5064e43f1a9cfdac15322886936801d57e022cde29919b |
| 22 | + | ||
| 23 | +// | ||
| 24 | +// //String s ="aaa_2222"; | ||
| 25 | +// String s ="2222"; | ||
| 26 | +// String str[]=s.split("_"); | ||
| 27 | +// System.out.println(str[0]); | ||
| 28 | +// //System.out.println(str[1]); | ||
| 29 | +// | ||
| 30 | +// System.out.println(DateUtils.addDate(DateUtils.getCurrentDate(),-7)); | ||
| 31 | +// | ||
| 32 | + | ||
| 33 | + Date currentDate = new Date(); | ||
| 34 | + long timeStamp = currentDate.getTime(); | ||
| 35 | + System.out.println(timeStamp); | ||
| 36 | + String tStr = String.valueOf(timeStamp); | ||
| 37 | + System.out.println(tStr); | ||
| 38 | + System.out.println(Long.valueOf(tStr)); | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + System.out.println(DateUtils.timeStampToDate(Long.valueOf(tStr))); | ||
| 43 | + | ||
| 18 | } | 44 | } |
| 19 | } | 45 | } | ... | ... |
-
Please register or login to post a comment