PI-11-HS CODE接口-01:
接口调整 新增HS CODE通用模糊查询接口,增加监管条件字段。 mt 2023年2月24日18:02:22
Showing
8 changed files
with
159 additions
and
20 deletions
No preview for this file type
| ... | @@ -25,7 +25,8 @@ public enum ErrorCodeEnum { | ... | @@ -25,7 +25,8 @@ public enum ErrorCodeEnum { |
| 25 | ERROR_30101("30101","数据查询异常(访问数据库超时或者其他数据库异常)"), | 25 | ERROR_30101("30101","数据查询异常(访问数据库超时或者其他数据库异常)"), |
| 26 | ERROR_30102("30102","hscode编码字段长度超过2000字符"), | 26 | ERROR_30102("30102","hscode编码字段长度超过2000字符"), |
| 27 | ERROR_30103("30103","skuCode与skuName必须传递一项"), | 27 | ERROR_30103("30103","skuCode与skuName必须传递一项"), |
| 28 | - ERROR_30104("30104","skuCode或skuName长度超出限制"); | 28 | + ERROR_30104("30104","skuCode或skuName长度超出限制"), |
| 29 | + ERROR_30105("30105","skuCode编码最少输入4位字符,skuName最少输入2个字符"); | ||
| 29 | 30 | ||
| 30 | ErrorCodeEnum(String code,String name){ | 31 | ErrorCodeEnum(String code,String name){ |
| 31 | this.code = code; | 32 | this.code = code; | ... | ... |
| ... | @@ -98,12 +98,12 @@ public class HsCodeInterface { | ... | @@ -98,12 +98,12 @@ public class HsCodeInterface { |
| 98 | long end = System.currentTimeMillis(); | 98 | long end = System.currentTimeMillis(); |
| 99 | iclearApiHsCodeLog.setSpendTime(end-begin); | 99 | iclearApiHsCodeLog.setSpendTime(end-begin); |
| 100 | String skuCode = hscode.getSkuCode(); | 100 | String skuCode = hscode.getSkuCode(); |
| 101 | - if(!StringUtil.isEmpty(skuCode)){ | 101 | + if(!StringUtil.isEmpty(skuCode) && skuCode.length() > 50){ |
| 102 | skuCode = skuCode.substring(0,50); | 102 | skuCode = skuCode.substring(0,50); |
| 103 | } | 103 | } |
| 104 | String skuName = hscode.getSkuName(); | 104 | String skuName = hscode.getSkuName(); |
| 105 | - if(!StringUtil.isEmpty(skuName)){ | 105 | + if(!StringUtil.isEmpty(skuName) && skuName.length() > 1000){ |
| 106 | - skuName = skuName.substring(0,50); | 106 | + skuName = skuName.substring(0,1000); |
| 107 | } | 107 | } |
| 108 | iclearApiHsCodeLog.setCode("[skuCode="+skuCode+"],[skuName="+skuName+"]"); | 108 | iclearApiHsCodeLog.setCode("[skuCode="+skuCode+"],[skuName="+skuName+"]"); |
| 109 | iClearApiHsCodeLogService.saveIClearApiHsCodeLog(iclearApiHsCodeLog); | 109 | iClearApiHsCodeLogService.saveIClearApiHsCodeLog(iclearApiHsCodeLog); | ... | ... |
| ... | @@ -94,5 +94,8 @@ public class Constant { | ... | @@ -94,5 +94,8 @@ public class Constant { |
| 94 | 94 | ||
| 95 | public static String DECLARED_DOC_TYPE_ZERO="declaredDocType_00"; | 95 | public static String DECLARED_DOC_TYPE_ZERO="declaredDocType_00"; |
| 96 | 96 | ||
| 97 | - | 97 | + /** |
| 98 | + * 监管条件 | ||
| 99 | + */ | ||
| 100 | + public static final String supervise_condition = "superviseRestrict"; | ||
| 98 | } | 101 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -41,4 +41,13 @@ public interface DictionaryEntriesRepository extends JpaRepository<DictionaryEn | ... | @@ -41,4 +41,13 @@ public interface DictionaryEntriesRepository extends JpaRepository<DictionaryEn |
| 41 | @Query(nativeQuery = true, value = "SELECT * FROM T_BI_DICTIONARY_ENTRIES WHERE DICT_CODE = ?1 AND EXT6 = ?2") | 41 | @Query(nativeQuery = true, value = "SELECT * FROM T_BI_DICTIONARY_ENTRIES WHERE DICT_CODE = ?1 AND EXT6 = ?2") |
| 42 | public DictionaryEntries findDictionaryEntriesByDicCode(String code,String numBer); | 42 | public DictionaryEntries findDictionaryEntriesByDicCode(String code,String numBer); |
| 43 | 43 | ||
| 44 | + /** | ||
| 45 | + *监管条件 | ||
| 46 | + * @param dictCode | ||
| 47 | + * @param status | ||
| 48 | + * @return | ||
| 49 | + */ | ||
| 50 | + @Query(nativeQuery = true, value = "select CHINESE_NAME from T_BI_DICTIONARY_ENTRIES where DICT_CODE = ?1 AND STATUS=?2 order by ORDINAL") | ||
| 51 | + public List<String> findDicEntByCodeList(String dictCode, Integer status); | ||
| 52 | + | ||
| 44 | } | 53 | } | ... | ... |
| ... | @@ -16,27 +16,35 @@ import java.util.List; | ... | @@ -16,27 +16,35 @@ import java.util.List; |
| 16 | */ | 16 | */ |
| 17 | @Repository | 17 | @Repository |
| 18 | public interface HsCodeRepository extends JpaSpecificationExecutor<HsCode>, JpaRepository<HsCode, Long> { | 18 | public interface HsCodeRepository extends JpaSpecificationExecutor<HsCode>, JpaRepository<HsCode, Long> { |
| 19 | - /** | ||
| 20 | - * | ||
| 21 | - * 根据hscode编码查询最新一条hscode信息 | ||
| 22 | - * @param code | ||
| 23 | - * @return | ||
| 24 | - */ | ||
| 25 | - @Query(nativeQuery = true,value = "select top 1 * from T_CC_HS_CODE where VALIDATE=1 and SKU_CODE =?1 order by id desc ") | ||
| 26 | - public HsCode findHsCodeByCode(String code); | ||
| 27 | 19 | ||
| 28 | /** | 20 | /** |
| 29 | * 根据hscode编码查询对应的hscode | 21 | * 根据hscode编码查询对应的hscode |
| 30 | * @param skuCodeList | 22 | * @param skuCodeList |
| 31 | * @return | 23 | * @return |
| 32 | */ | 24 | */ |
| 33 | - @Query(nativeQuery = true, value = "select * from [dbo].[T_CC_HS_CODE] where VALIDATE=1 and SKU_CODE in ?1") | 25 | + @Query(nativeQuery = true, value = "select * from T_CC_HS_CODE where VALIDATE=1 and SKU_CODE in ?1") |
| 34 | List<HsCode> findHsCodeListByCode(List<String> skuCodeList); | 26 | List<HsCode> findHsCodeListByCode(List<String> skuCodeList); |
| 35 | 27 | ||
| 36 | /** | 28 | /** |
| 29 | + * 根据hscode编码或者商品名称进行模糊查询 | ||
| 30 | + * @param skuCode | ||
| 31 | + * @param skuName | ||
| 32 | + * @return | ||
| 33 | + */ | ||
| 34 | + @Query(nativeQuery = true, value = "SELECT TOP 50 * FROM T_CC_HS_CODE WHERE VALIDATE=1 and SKU_CODE LIKE ?1 AND SKUNAME LIKE ?2") | ||
| 35 | + List<HsCode> fuzzyQueryHsCode(String skuCode,String skuName); | ||
| 36 | + | ||
| 37 | + /** | ||
| 37 | * 查询所有有效hscode | 38 | * 查询所有有效hscode |
| 38 | * @return | 39 | * @return |
| 39 | */ | 40 | */ |
| 40 | @Query(nativeQuery = true,value = "select * from T_CC_HS_CODE where VALIDATE=1") | 41 | @Query(nativeQuery = true,value = "select * from T_CC_HS_CODE where VALIDATE=1") |
| 41 | - public List<HsCode> findAllHsCodeList(); | 42 | + List<HsCode> findAllHsCodeList(); |
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 获取监管条件数据 | ||
| 46 | + * @return | ||
| 47 | + */ | ||
| 48 | + @Query(nativeQuery = true,value = "select * from T_CC_HS_CODE where OUT_RATE <> 0 or MONITOR_CONDITION collate Chinese_PRC_CS_AI_WS LIKE ?1") | ||
| 49 | + List<HsCode> findMonitorCondition(String chinsesName); | ||
| 42 | } | 50 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -3,14 +3,17 @@ package com.erry.iclear.dateInterface.service; | ... | @@ -3,14 +3,17 @@ package com.erry.iclear.dateInterface.service; |
| 3 | import com.erry.iclear.dateInterface.ErrorCodeEnum; | 3 | import com.erry.iclear.dateInterface.ErrorCodeEnum; |
| 4 | import com.erry.iclear.dateInterface.api.request.HsCodeParam; | 4 | import com.erry.iclear.dateInterface.api.request.HsCodeParam; |
| 5 | import com.erry.iclear.dateInterface.api.response.ResultHsCode; | 5 | import com.erry.iclear.dateInterface.api.response.ResultHsCode; |
| 6 | +import com.erry.iclear.dateInterface.common.Constant; | ||
| 6 | import com.erry.iclear.dateInterface.entity.HsCode; | 7 | import com.erry.iclear.dateInterface.entity.HsCode; |
| 8 | +import com.erry.iclear.dateInterface.repository.DictionaryEntriesRepository; | ||
| 7 | import com.erry.iclear.dateInterface.repository.HsCodeRepository; | 9 | import com.erry.iclear.dateInterface.repository.HsCodeRepository; |
| 8 | import com.erry.iclear.dateInterface.util.StringUtil; | 10 | import com.erry.iclear.dateInterface.util.StringUtil; |
| 9 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 12 | -import java.util.Arrays; | 14 | + |
| 13 | -import java.util.List; | 15 | +import java.sql.*; |
| 16 | +import java.util.*; | ||
| 14 | 17 | ||
| 15 | /** | 18 | /** |
| 16 | * hscode service | 19 | * hscode service |
| ... | @@ -20,8 +23,12 @@ import java.util.List; | ... | @@ -20,8 +23,12 @@ import java.util.List; |
| 20 | @Service | 23 | @Service |
| 21 | @Slf4j | 24 | @Slf4j |
| 22 | public class HsCodeService { | 25 | public class HsCodeService { |
| 26 | + | ||
| 23 | @Autowired | 27 | @Autowired |
| 24 | HsCodeRepository hsCodeRepository; | 28 | HsCodeRepository hsCodeRepository; |
| 29 | + @Autowired | ||
| 30 | + DictionaryEntriesRepository dicEntriesRepository; | ||
| 31 | + | ||
| 25 | /** | 32 | /** |
| 26 | * 根据hscode编码查询对应的hscode | 33 | * 根据hscode编码查询对应的hscode |
| 27 | * @param hscode | 34 | * @param hscode |
| ... | @@ -59,6 +66,8 @@ public class HsCodeService { | ... | @@ -59,6 +66,8 @@ public class HsCodeService { |
| 59 | hsCodeList.add(hsCode); | 66 | hsCodeList.add(hsCode); |
| 60 | } | 67 | } |
| 61 | }); | 68 | }); |
| 69 | + //只能申报D类hscode监管条件hscode | ||
| 70 | + this.setHscodeSupervise(hsCodeList); | ||
| 62 | resultHsCode.setSuccess(Boolean.TRUE); | 71 | resultHsCode.setSuccess(Boolean.TRUE); |
| 63 | resultHsCode.setCode(ErrorCodeEnum.SUCCESS.getCode()); | 72 | resultHsCode.setCode(ErrorCodeEnum.SUCCESS.getCode()); |
| 64 | resultHsCode.setMsg(ErrorCodeEnum.SUCCESS.getName()); | 73 | resultHsCode.setMsg(ErrorCodeEnum.SUCCESS.getName()); |
| ... | @@ -80,24 +89,43 @@ public class HsCodeService { | ... | @@ -80,24 +89,43 @@ public class HsCodeService { |
| 80 | public ResultHsCode fuzzyQueryHsCode(HsCodeParam hscode){ | 89 | public ResultHsCode fuzzyQueryHsCode(HsCodeParam hscode){ |
| 81 | ResultHsCode resultHsCode = new ResultHsCode(Boolean.FALSE,"","",null); | 90 | ResultHsCode resultHsCode = new ResultHsCode(Boolean.FALSE,"","",null); |
| 82 | try{ | 91 | try{ |
| 92 | + //编码与品名都为空校验失败 | ||
| 83 | if(StringUtil.isEmpty(hscode.getSkuCode()) && StringUtil.isEmpty(hscode.getSkuName())){ | 93 | if(StringUtil.isEmpty(hscode.getSkuCode()) && StringUtil.isEmpty(hscode.getSkuName())){ |
| 84 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30103.getCode()); | 94 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30103.getCode()); |
| 85 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30103.getName()); | 95 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30103.getName()); |
| 86 | return resultHsCode; | 96 | return resultHsCode; |
| 87 | } | 97 | } |
| 98 | + //编码长度大于50校验失败 | ||
| 88 | if(!StringUtil.isEmpty(hscode.getSkuCode()) && hscode.getSkuCode().length() > 50){ | 99 | if(!StringUtil.isEmpty(hscode.getSkuCode()) && hscode.getSkuCode().length() > 50){ |
| 89 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30104.getCode()); | 100 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30104.getCode()); |
| 90 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30104.getName()); | 101 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30104.getName()); |
| 91 | return resultHsCode; | 102 | return resultHsCode; |
| 92 | } | 103 | } |
| 104 | + //品名长度大于1000校验失败 | ||
| 93 | if(!StringUtil.isEmpty(hscode.getSkuName()) && hscode.getSkuName().length() > 1000){ | 105 | if(!StringUtil.isEmpty(hscode.getSkuName()) && hscode.getSkuName().length() > 1000){ |
| 94 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30104.getCode()); | 106 | resultHsCode.setCode(ErrorCodeEnum.ERROR_30104.getCode()); |
| 95 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30104.getName()); | 107 | resultHsCode.setMsg(ErrorCodeEnum.ERROR_30104.getName()); |
| 96 | return resultHsCode; | 108 | return resultHsCode; |
| 97 | } | 109 | } |
| 98 | - List<HsCode> hsCodeList = null; | 110 | + //编码长度小于4位字符校验失败 |
| 99 | - | 111 | + if(!StringUtil.isEmpty(hscode.getSkuName()) && hscode.getSkuName().length() < 4){ |
| 100 | - | 112 | + resultHsCode.setCode(ErrorCodeEnum.ERROR_30105.getCode()); |
| 113 | + resultHsCode.setMsg(ErrorCodeEnum.ERROR_30105.getName()); | ||
| 114 | + return resultHsCode; | ||
| 115 | + } | ||
| 116 | + //品名长度小于2位字符校验失败 | ||
| 117 | + if(!StringUtil.isEmpty(hscode.getSkuName()) && hscode.getSkuName().length() < 2){ | ||
| 118 | + resultHsCode.setCode(ErrorCodeEnum.ERROR_30105.getCode()); | ||
| 119 | + resultHsCode.setMsg(ErrorCodeEnum.ERROR_30105.getName()); | ||
| 120 | + return resultHsCode; | ||
| 121 | + } | ||
| 122 | + String skuCode = "%"+hscode.getSkuCode()+"%"; | ||
| 123 | + String skuName = "%"+hscode.getSkuName()+"%"; | ||
| 124 | + //模糊查询hscode信息 | ||
| 125 | + List<HsCode> hsCodeList = this.hsCodeRepository.fuzzyQueryHsCode(skuCode,skuName); | ||
| 126 | + //对查询数据进行处理,标志数据是否C类限制品名 | ||
| 127 | + //只能申报D类hscode监管条件hscode | ||
| 128 | + this.setHscodeSupervise(hsCodeList); | ||
| 101 | resultHsCode.setSuccess(Boolean.TRUE); | 129 | resultHsCode.setSuccess(Boolean.TRUE); |
| 102 | resultHsCode.setCode(ErrorCodeEnum.SUCCESS.getCode()); | 130 | resultHsCode.setCode(ErrorCodeEnum.SUCCESS.getCode()); |
| 103 | resultHsCode.setMsg(ErrorCodeEnum.SUCCESS.getName()); | 131 | resultHsCode.setMsg(ErrorCodeEnum.SUCCESS.getName()); |
| ... | @@ -131,4 +159,94 @@ public class HsCodeService { | ... | @@ -131,4 +159,94 @@ public class HsCodeService { |
| 131 | } | 159 | } |
| 132 | return resultHsCode; | 160 | return resultHsCode; |
| 133 | } | 161 | } |
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 只能申报D类hscode监管条件hscode | ||
| 165 | + * 设置hscode | ||
| 166 | + * mt | ||
| 167 | + * 2023年2月24日17:29:49 | ||
| 168 | + */ | ||
| 169 | + public void setHscodeSupervise(List<HsCode> hsCodeList){ | ||
| 170 | + List<Long> hsCodeIds = new ArrayList<>(); | ||
| 171 | + Map<String,Object> hscodeMap = this.getHscodeSupervise(); | ||
| 172 | + StringBuffer shsql = new StringBuffer("'"); | ||
| 173 | + if (hscodeMap !=null && hscodeMap.size()>0){ | ||
| 174 | + for (Map.Entry hscodeEntry :hscodeMap.entrySet()){ | ||
| 175 | + HsCode hsCode = (HsCode) hscodeEntry.getValue(); | ||
| 176 | + hsCodeIds.add(hsCode.getId()); | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + hsCodeList.forEach(hsCode->{ | ||
| 180 | + //判断该hscode是否只能申报D类 | ||
| 181 | + if(hsCodeIds.contains(hsCode.getId())){ | ||
| 182 | + //d类 | ||
| 183 | + hsCode.setRestrictedC(1); | ||
| 184 | + }else{ | ||
| 185 | + //C类 | ||
| 186 | + hsCode.setRestrictedC(0); | ||
| 187 | + } | ||
| 188 | + //如果ID为空,则设置为空 | ||
| 189 | + if(hsCode.getId() == null){ | ||
| 190 | + hsCode.setRestrictedC(null); | ||
| 191 | + } | ||
| 192 | + }); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * 根据监管条件获取数据,只能申报D类hscode信息 | ||
| 197 | + * mt | ||
| 198 | + * 2023年2月24日16:43:46 | ||
| 199 | + * @return | ||
| 200 | + */ | ||
| 201 | + private Map<String,Object> getHscodeSupervise(){ | ||
| 202 | + try { | ||
| 203 | + Map<String,Object> returnMap = new HashMap<>(); | ||
| 204 | + List<String> dictionaryEntriesList = dicEntriesRepository.findDicEntByCodeList(Constant.supervise_condition,1); | ||
| 205 | + if (dictionaryEntriesList !=null && dictionaryEntriesList.size()>0){ | ||
| 206 | + String chinsesName = "%["; | ||
| 207 | + for (int i= 0;i<dictionaryEntriesList.size();i++){ | ||
| 208 | + if (dictionaryEntriesList.size() -1 == i){ | ||
| 209 | + chinsesName += dictionaryEntriesList.get(i)+"]%"; | ||
| 210 | + }else{ | ||
| 211 | + chinsesName += dictionaryEntriesList.get(i)+"|"; | ||
| 212 | + } | ||
| 213 | + } | ||
| 214 | + //查询监管条件数据 | ||
| 215 | + List<HsCode> hsCodeList = this.hsCodeRepository.findMonitorCondition(chinsesName); | ||
| 216 | + hsCodeList.forEach(hsCode->{ | ||
| 217 | + String newCode = getSubHscode(hsCode.getSkuCode()); | ||
| 218 | + returnMap.put(newCode,hsCode); | ||
| 219 | + }); | ||
| 220 | + } | ||
| 221 | + return returnMap; | ||
| 222 | + }catch (Exception e){ | ||
| 223 | + log.error(e.getMessage(),e); | ||
| 224 | + } | ||
| 225 | + return null; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + /** | ||
| 229 | + * 对商品编码进行处理 | ||
| 230 | + * @param code | ||
| 231 | + * @return | ||
| 232 | + */ | ||
| 233 | + private String getSubHscode(String code){ | ||
| 234 | + try { | ||
| 235 | + if (!StringUtil.isEmptyWithTrim(code) && code.length()>6) { | ||
| 236 | + if (code.length() == 7) { | ||
| 237 | + code = "0" + code + "00"; | ||
| 238 | + } else if (code.length() == 8) { | ||
| 239 | + code = code + "00"; | ||
| 240 | + } else if (code.length() == 9) { | ||
| 241 | + code = "0" + code; | ||
| 242 | + } else if (code.length() > 10) { | ||
| 243 | + code = code.substring(0, 10); | ||
| 244 | + } | ||
| 245 | + return code; | ||
| 246 | + } | ||
| 247 | + }catch (Exception e){ | ||
| 248 | + log.error(e.getMessage(),e); | ||
| 249 | + } | ||
| 250 | + return null; | ||
| 251 | + } | ||
| 134 | } | 252 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment