H2018ZhDangerGoodsUtil.java 172 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391
  1. package cn.gov.customs.data.timer;
  2. import cn.gov.customs.data.entity.wxjy.bus.*;
  3. import cn.gov.customs.data.entity.wxjy.common.PubCustomsMapping;
  4. import cn.gov.customs.data.repository.h2018.H2018Repository;
  5. import cn.gov.customs.data.repository.iedg.IedgRepository;
  6. import cn.gov.customs.data.repository.inspect.InspectRepository;
  7. import cn.gov.customs.data.repository.rh2k.Rh2kRepository;
  8. import cn.gov.customs.data.repository.wxjy.WxjyRepository;
  9. import cn.gov.customs.data.repository.wxjy.bus.CustomMonthlyStatFinalRepository;
  10. import cn.gov.customs.data.repository.wxjy.bus.CustomMonthlyStatRepository;
  11. import cn.gov.customs.data.repository.wxjy.bus.EntryHeadRepository;
  12. import cn.gov.customs.data.repository.wxjy.bus.EntryListRepository;
  13. import cn.gov.customs.data.repository.wxjy.common.PubCustomsMappingRepository;
  14. import cn.gov.customs.data.repository.zmqd.ZmqdRepository;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.context.annotation.Configuration;
  19. import org.springframework.context.annotation.PropertySource;
  20. import org.springframework.stereotype.Component;
  21. import java.math.BigDecimal;
  22. import java.math.BigInteger;
  23. import java.text.ParseException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. import java.util.stream.Collectors;
  27. /**
  28. * @Description: H2018危险品
  29. * @Author wq
  30. * @Date 2025-09-30 14:31:11
  31. * @Version 1.0
  32. */
  33. @Component
  34. @Configuration
  35. @PropertySource("classpath:data-acquisition.properties")
  36. public class H2018ZhDangerGoodsUtil {
  37. Logger logger = LoggerFactory.getLogger(H2018ZhDangerGoodsUtil.class);
  38. private static SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
  39. private static SimpleDateFormat monthSdf = new SimpleDateFormat("yyyyMM");
  40. private static SimpleDateFormat daySdf = new SimpleDateFormat("yyyyMMdd");
  41. private static SimpleDateFormat fullSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  42. private static final String IE_DATE_ADAPT = "12:00:00";//下发的报关单I_E_DATE丢失时分精度
  43. private static boolean reGenerateAllData = false;
  44. private static final String noRelStatMonth = "201812"; // 该月及之前月份月度统计中间数据不用维护所有字段内容,比如相对差值字段,去年/前年xx平均值
  45. private static final BigDecimal zero = new BigDecimal(0);
  46. private static HashMap<String, String> rootCustomsMap = new HashMap<String, String>();// 根据关区代码获得所隶属的一级关区代码
  47. private static List<String> hasMultipleCustomList = new ArrayList<String>(); // 拥有下级关区的关区代码
  48. private static Set<String> firstClassCustoms = new HashSet<String>(); // 一级关区代码集合
  49. @Autowired
  50. private H2018Repository h2018Dao;
  51. @Autowired
  52. private WxjyRepository dao;
  53. @Autowired
  54. private IedgRepository iedgRepository;
  55. @Autowired
  56. private InspectRepository inspDao;
  57. @Autowired
  58. private ZmqdRepository zmqdRepository;
  59. @Autowired
  60. private Rh2kRepository rh2kRepository;
  61. @Autowired
  62. private PubCustomsMappingRepository mappingRepository;
  63. @Autowired
  64. private EntryHeadRepository entryHeadRepository;
  65. @Autowired
  66. private EntryListRepository entryListRepository;
  67. @Autowired
  68. private CustomMonthlyStatFinalRepository customMonthlyStatFinalRepository;
  69. @Autowired
  70. private CustomMonthlyStatRepository customMonthlyStatRepository;
  71. @Autowired
  72. private PubCustomsMappingRepository pubCustomsMappingRepository;
  73. /**
  74. * @description: H2018危险品报关单信息
  75. * @param: hsCodes
  76. * endTime
  77. * @return: void
  78. * @author zoumin
  79. * @date: 2021-11-09 16:06:48
  80. * @version 1.0
  81. */
  82. public void h2018Business(List<String> ciqCodeList, Calendar c, String type) {
  83. /**H2018已结关报关单危险品信息*/
  84. logger.info("=================同步H2018已结关(80)报关单危险品信息======start==========");
  85. SimpleDateFormat daySdf = new SimpleDateFormat("yyyy-MM-dd");
  86. Date today = c.getTime();
  87. c.add(Calendar.DATE, -1);
  88. Date yesterday = c.getTime();
  89. String yesterdayStr = "";
  90. Date statBegin = null;
  91. Date statEnd = null;
  92. try {
  93. yesterdayStr = daySdf.format(yesterday);
  94. statBegin = daySdf.parse(yesterdayStr);
  95. statEnd = daySdf.parse(daySdf.format(today));
  96. } catch (ParseException e) {
  97. e.printStackTrace();
  98. return;
  99. }
  100. dao.executeUpdate("delete from WXJY_ENTRY_HEAD where RELEASE_DATE >= ? and RELEASE_DATE < ?", statBegin, statEnd);
  101. dao.executeUpdate("delete from WXJY_ENTRY_LIST where RELEASE_DATE >= ? and RELEASE_DATE < ?", statBegin, statEnd);//根据结关时间同步删除通过报关单号关联的商品编码表 zoumin 2020-11-11
  102. dao.executeUpdate("delete from WXJY_MID_D_M_STATUS where DATA_TYPE = 'EntryHead' and BUSINESS_TYPE = ? and STAT_PERIOD = ?", type, yesterdayStr);
  103. //获取危险品的ciq编码
  104. List<String> allCiqCodeList = (List<String>) iedgRepository.getQueryBySql("select distinct c.ciq_code from iedg_sync_chemicals_ciq c");
  105. try {
  106. // 一体化通关
  107. ythDeclMain(statBegin, statEnd, ciqCodeList, allCiqCodeList);
  108. // 口岸清关(直接进出口)
  109. kaqgDeclMain(statBegin, statEnd, ciqCodeList, allCiqCodeList);
  110. // 转关(因为需求不要求出境的,只考虑维护入境转关类型报关的转关数据发送时间、转关数据核销时间)
  111. zgDeclMain(statBegin, statEnd, ciqCodeList, allCiqCodeList);
  112. //
  113. // 运维时可以查询MiddleDataMainStatus对应记录来分析哪些时间的定时任务没有正确执行,届时进行维护
  114. MiddleDataMainStatus mStatus = new MiddleDataMainStatus();
  115. mStatus.setCreateTime(new Date());
  116. mStatus.setDataType(EntryHead.class.getSimpleName());
  117. mStatus.setStatPeriod(yesterdayStr);
  118. mStatus.setBusinessType(type);
  119. dao.executeUpdate("insert into WXJY_MID_D_M_STATUS (ID,DATA_TYPE, STAT_PERIOD,BUSINESS_TYPE, CREATE_TIME) " +
  120. "values(sys_guid(),?,?,?) ", mStatus.getDataType(), mStatus.getStatPeriod(), mStatus.getBusinessType(), new Date());
  121. } catch (Exception e) {
  122. logger.error("危险品报关单通关时长统计每日中间表数据维护异常", e);
  123. }
  124. try {
  125. //删除中间表中涉案和删单的
  126. delSpecialAndDelHeadLogData(statEnd);
  127. logger.info("每日中间表涉案和删单的数据删除成功!");
  128. } catch (Exception e1) {
  129. logger.error("删除危险品报关单通关时长统计每日中间表涉案和删单数据异常", e1);
  130. }
  131. // 2019-11-19 增加每天维护当月的月度统计数据
  132. // reGenerateAllData 生产环境正式代码设置为false;清空所有中间数据重新生成时设置为true以提升效率,这时会全新生成所有月度统计;
  133. if (!reGenerateAllData) {
  134. // 月度统计维护关区合并的FINAL表用到,需要先初始化,否则首次执行时无法维护几个FINAL后缀的表数据
  135. if (firstClassCustoms.size() == 0) {// 还没有初始化过
  136. rootCustomsMap.clear();
  137. hasMultipleCustomList.clear();
  138. List<PubCustomsMapping> custMapping = mappingRepository.findAll();
  139. for (PubCustomsMapping m : custMapping) {
  140. String pCustomCode = m.getMappingCode();
  141. if (rootCustomsMap.containsValue(pCustomCode)) {
  142. hasMultipleCustomList.add(pCustomCode);
  143. }
  144. rootCustomsMap.put(m.getCustomsCode(), pCustomCode);
  145. firstClassCustoms.add(pCustomCode);
  146. }
  147. }
  148. String dataPeriod = monthSdf.format(yesterday);// 当天凌晨维护的是昨天的数据,故月度统计是昨天所在月度
  149. // 维护月度之前尝试删除可能未删除的月度维护日志,便于月度维护开展
  150. // 月度统计定时维护触发时间晚于每日中间数据维护,需要维护好月度统计日志
  151. dao.executeUpdate("delete from WXJY_MID_D_M_STATUS where STAT_PERIOD = ?", dataPeriod);
  152. Date monthStatBegin = statBegin;// 随意初始化为昨日0点
  153. try {
  154. monthStatBegin = monthSdf.parse(dataPeriod);// 昨日所在月份1日0点
  155. } catch (ParseException e) {
  156. e.printStackTrace();
  157. }
  158. monthlyDataMaintance(dataPeriod, monthStatBegin, statEnd);
  159. // 维护完当月月度统计临时数值后删除维护日志,便于月度统计定时维护持续工作,每月初月度定时任务重新执行一次不碍事
  160. dao.executeUpdate("delete from WXJY_MID_D_M_STATUS where STAT_PERIOD = ?", dataPeriod);
  161. }
  162. }
  163. public void ythDeclMain(Date statBegin, Date statEnd, List<String> code, List<String> allCode) {
  164. Map<String, Object[]> tmpMap1 = new HashMap<String, Object[]>();
  165. Map<String, Date[]> tmpMap2 = new HashMap<String, Date[]>();
  166. Map<String, Date> tmpMap9 = new HashMap<String, Date>();
  167. Map<String, Object[]> tmpMap10 = new HashMap<String, Object[]>();
  168. Map<String, Object[]> tmpMap11 = new HashMap<String, Object[]>();
  169. Map<String, Date> tmpMap12 = new HashMap<String, Date>();
  170. if (code != null && code.size() > 0) {
  171. List<String> entryH2018IdList = new ArrayList<>();//存放所有
  172. StringBuilder codeSb = new StringBuilder();
  173. int j = 1;
  174. for (Iterator itera = code.iterator(); itera.hasNext(); ) {
  175. String ciqCode = (String) itera.next();
  176. codeSb.append("'").append(ciqCode).append("',");
  177. if ((j % 600 == 0 || !itera.hasNext()) && codeSb.length() > 0) {
  178. codeSb.deleteCharAt(codeSb.length() - 1);
  179. String codes = codeSb.toString();
  180. //存在后续查出的报关单前面已经有,所以需要处理去重
  181. //出口按编码、ungid不为空和货物属性包含31或32
  182. //进口按ungid不为空或货物属性包含31或32
  183. String sql = "select distinct(d.ENTRY_ID) from ENTRY_HEAD d, ENTRY_WORKFLOW w,ENTRY_LIST l where " +
  184. "d.ENTRY_ID like '47%' and (substr(d.EDI_REMARK,7,1)!='C' or substr(d.EDI_REMARK,15,1)!='1') " +
  185. "and (substr(d.EDI_REMARK,17,1) in ('a','c','d','e','f') " +
  186. "or substr(d.EDI_REMARK,17,1) = 'C' and substr(d.EDI_REMARK,8,1) = 'G' ) " +
  187. "and d.ENTRY_ID = w.ENTRY_ID and d.ENTRY_ID = l.ENTRY_ID and w.STEP_ID = '80000000' and w.CREATE_DATE >= ? and w.CREATE_DATE < ? " +
  188. "and ((d.I_E_FLAG = 'E' and (l.IQ_CODE in (" + codes + ") or l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  189. "or l.PRODUCT_CHAR_CODE like '%32%')) or (d.I_E_FLAG = 'I' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  190. "or l.PRODUCT_CHAR_CODE like '%32%'))) order by d.ENTRY_ID;";
  191. List<String> entryIdList = (List<String>) h2018Dao.getQueryBySql(sql, statBegin, statEnd);
  192. entryH2018IdList.addAll(entryIdList);
  193. codeSb.delete(0, codeSb.length());
  194. }
  195. j++;
  196. }
  197. //用JDK1.8 Stream中对List进行去重:list.stream().distinct();
  198. entryH2018IdList = (List) entryH2018IdList.stream().distinct().collect(Collectors.toList());
  199. if (entryH2018IdList != null && entryH2018IdList.size() > 0) {
  200. StringBuilder sb = new StringBuilder();
  201. int i = 1;
  202. for (Iterator iterator = entryH2018IdList.iterator(); iterator.hasNext(); ) {
  203. String id = (String) iterator.next();
  204. sb.append("'").append(id).append("',");
  205. if ((i % 300 == 0 || !iterator.hasNext()) && sb.length() > 0) {
  206. List<String> impIdList2 = new ArrayList<String>();//20191210 进口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_LIST_NEW查到精确I_E_DATE
  207. List<String> impIdList3 = new ArrayList<String>();//20211210 出口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_MONITOR_NEW查到精确ARRIVAL_DATE
  208. Map<String, Object> map = new HashMap<String, Object>();
  209. sb.deleteCharAt(sb.length() - 1);
  210. String ids = sb.toString();
  211. String entryIds = sb.toString();
  212. String sql = "select h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT, CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY,"
  213. + " TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),nvl(count(c.ENTRY_ID),0),substr(EDI_REMARK,53,1) "
  214. + "from ENTRY_HEAD h left join `g_whdb_zmqd`.h18c_ENTRY_CONTAINER c on h.ENTRY_ID = c.ENTRY_ID where h.ENTRY_ID in ("
  215. + ids + ") group by h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT, CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY," +
  216. "TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),substr(EDI_REMARK,53,1);";
  217. List<Object[]> list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  218. for (Object[] d : list) {
  219. String idH = (String) d[0];
  220. String iEFlag = (String) d[3];
  221. String traMode = (String) d[4];
  222. if ("I".equals(iEFlag)) {
  223. if ("2".equals(traMode) || "5".equals(traMode)) {
  224. impIdList2.add(idH);
  225. }
  226. } else {
  227. if ("2".equals(traMode) || "5".equals(traMode)) {
  228. impIdList3.add(idH);
  229. }
  230. }
  231. tmpMap1.put((String) d[0],
  232. new Object[]{(Date) d[1], (String) d[2], (String) d[3], (String) d[4], (Date) d[5], (String) d[6], (String) d[7], (String) d[8], (String) d[9], (String) d[10], (String) d[11],
  233. (BigDecimal) d[12], (BigDecimal) d[13], (String) d[14], (String) d[15], (BigInteger) d[16], (String) d[17]});
  234. }
  235. sql = "select h.ENTRY_ID,(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='10000000' AND h.ENTRY_ID = a.ENTRY_ID) as authDate,"
  236. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='80000000' AND h.ENTRY_ID = a.ENTRY_ID) as releaseDate,"
  237. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='81000000' AND h.ENTRY_ID = b.ENTRY_ID) as preReleaseDate,"
  238. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='70000000' AND h.ENTRY_ID = c.ENTRY_ID) as certRlsDate,"
  239. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='82000000' AND h.ENTRY_ID = c.ENTRY_ID) as passDate,"
  240. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='30000000' AND h.ENTRY_ID = c.ENTRY_ID) as orderDate,"
  241. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='30000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as orderReceiveDate,"
  242. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='00200000' AND h.ENTRY_ID = c.ENTRY_ID) as compEleDate,"
  243. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='33000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as profVerifyDate, "
  244. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='00000000' AND h.ENTRY_ID = b.ENTRY_ID) as eleDeclDate, "
  245. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%M%') as assessStartDate, "
  246. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%') as assessEndDate,"
  247. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID in ('10000000','10200000','20000000') AND h.ENTRY_ID = b.ENTRY_ID and substr(b.status_code,4,1) = 5 and b.proc_result like '%E%') as refundDate "
  248. + "from ENTRY_HEAD h where h.ENTRY_ID in (" + ids
  249. + ") group by ENTRY_ID;";
  250. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  251. for (Object[] d : list) {
  252. tmpMap2.put((String) d[0], new Date[]{(Date) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (Date) d[5], (Date) d[6], (Date) d[7], (Date) d[8], (Date) d[9],
  253. (Date) d[10], (Date) d[11], (Date) d[12], (Date) d[13]});
  254. }
  255. sql = "select h.ENTRY_ID,substr(h.CHECK_REQUEST_TOTAL,-1,1),h.CREATE_TIME,h.MAN_CHK_TIME_START,h.MAN_CHK_TIME_END,MAN_PROC_RESULT,MAN_PROC_IDEA,CHECK_CUSTOMS_CODE "
  256. + "from CI_CHECK_MAN_WORK_HEAD h where h.CHECK_STATE = 'M' and h.MODIFY_TIME = "
  257. + "(select max(d.MODIFY_TIME) from CI_CHECK_MAN_WORK_HEAD d where d.ID = h.ID) and h.ENTRY_ID in(" + ids + ") ;";
  258. list = (List<Object[]>) inspDao.getQueryBySql(sql);
  259. for (Object[] d : list) {
  260. tmpMap11.put((String) d[0], new Object[]{(String) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (String) d[5], (String) d[6], (String) d[7]});
  261. }
  262. //货运量毛重、净重、货运值人民币、美元、集装箱数量GROUP_CONCAT方法放在此处当传一个报关单id并且没有随附单证时会报错,所以加上nvl()
  263. sql = "select h.ENTRY_ID,sum(nvl(l.RMB_PRICE,0)),sum(nvl(l.USD_PRICE,0)),h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,"
  264. + "h.OWNER_CODE,h.OWNER_NAME,h.FRN_CONSIGN_CODE,h.FRN_CONSIGN_NAME from ENTRY_HEAD h left join ENTRY_LIST l on h.ENTRY_ID=l.ENTRY_ID "
  265. + "where h.ENTRY_ID in("
  266. + ids + ") group by h.ENTRY_ID,h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,h.OWNER_CODE,h.OWNER_NAME,h.FRN_CONSIGN_CODE,h.FRN_CONSIGN_NAME;";
  267. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  268. for (Object[] d : list) {
  269. tmpMap10.put((String) d[0], new Object[]{(BigDecimal) d[1], (BigDecimal) d[2], (String) d[3], (String) d[4], (String) d[5], (String) d[6], (String) d[7]
  270. , (String) d[8], (String) d[9]});
  271. }
  272. if (impIdList2.size() > 0) {
  273. sb.delete(0, sb.length());
  274. for (String impId : impIdList2) {
  275. sb.append("'").append(impId).append("',");
  276. }
  277. sb.deleteCharAt(sb.length() - 1);
  278. ids = sb.toString();
  279. // 进口新舱单水运、空运的I_E_DATE精准值由MANIFEST_LIST_NEW的REAL_ARRIVE_DATE给定
  280. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号
  281. sql = "select a.ENTRY_ID, b.REAL_ARRIVE_DATE from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.MANIFEST_LIST_NEW b where a.ENTRY_ID in ("
  282. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE and to_char(a.I_E_DATE,'yyyyMMdd') = to_char(b.REAL_ARRIVE_DATE,'yyyyMMdd')";
  283. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  284. for (Object[] d : list) {
  285. String entryId = (String) d[0];
  286. tmpMap9.put(entryId, (Date) d[1]);
  287. }
  288. impIdList2.clear();
  289. }
  290. //出口舱单
  291. if (impIdList3.size() > 0) {
  292. sb.delete(0, sb.length());
  293. for (String impId : impIdList3) {
  294. sb.append("'").append(impId).append("',");
  295. }
  296. sb.deleteCharAt(sb.length() - 1);
  297. ids = sb.toString();
  298. // 出口新舱单水运、空运可能提前但航班晚到,无法用时间去精准定位哪一条会卸载很多次,精准值由MANIFEST_MONITOR_NEW的ARRIVAL_DATE给定
  299. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号,ARRIVAL_DATE为00:00:00的赋值12:00:00
  300. //20210508舱单只获取和武汉海关有关的数据进行时间赋值,所以a.I_E_PORT = b.CUSTOMS_CODE
  301. sql = "select a.ENTRY_ID, min(b.ARRIVAL_DATE) from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.MANIFEST_MONITOR_NEW b where a.ENTRY_ID in ("
  302. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE group by a.ENTRY_ID";
  303. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  304. for (Object[] d : list) {
  305. String entryId = (String) d[0];
  306. tmpMap12.put(entryId, (Date) d[1]);
  307. }
  308. impIdList3.clear();
  309. }
  310. for (Map.Entry<String, Object[]> d : tmpMap1.entrySet()) {
  311. String entryId = d.getKey();
  312. Object[] v = d.getValue();
  313. Date ieDate = (Date) v[0];// 货物运抵时间
  314. String iePort = (String) v[1];
  315. String ieFlag = (String) v[2];
  316. String trafMode = (String) v[3];
  317. Date declDate = (Date) v[4];// 申报时间
  318. String declPort = (String) v[5];// 申报口岸
  319. String consignScc = (String) v[6];
  320. String consignCode = (String) v[7];
  321. String consignName = (String) v[8];
  322. String tradeCountry = (String) v[9];
  323. String tradeMode = (String) v[10];
  324. BigDecimal grossWt = (BigDecimal) v[11];//毛重
  325. BigDecimal netWt = (BigDecimal) v[12];//净重
  326. String advanceDecl = (String) v[13];//判断是否是提前申报
  327. //两步申报都下发到了h2018所以使用00200000节点判断只属于两步申报其中一种类型,
  328. //应当使用edi_remark41位判断是否有值(edi_remark41值为1,2,3均为两步申报)
  329. String twoStep = (String) v[14];//判断是否是两步申报
  330. //2018存在twoStepValue截取出来值为' '情况,需要单独处理
  331. String twoStepDecl = (" ").equals(twoStep) ? "" : twoStep;
  332. BigInteger container = (BigInteger) v[15];// 集装箱数量
  333. String newTwoStep = (String) v[16];//判断是否是新两步申报
  334. Date[] all = tmpMap2.get(entryId);
  335. Date authDate = null;
  336. Date releaseDate = null;
  337. Date preReleaseDate = null;
  338. Date certRlsDate = null;
  339. Date passDate = null;
  340. Date orderDate = null;
  341. Date orderReceiveDate = null;
  342. Date compEleDate = null;
  343. Date profVerifyDate = null;
  344. Date eleDeclDate = null;
  345. Date assessStartDate = null;
  346. Date assessEndDate = null;
  347. Date refundDate = null;
  348. if (all != null) {
  349. authDate = all[0];// 10审单受理时间
  350. releaseDate = all[1];// 80结关时间
  351. preReleaseDate = all[2];// 81担保放行时间
  352. certRlsDate = all[3];// 70单证放行时间
  353. passDate = all[4];// 82000000通道验放
  354. orderDate = all[5];// 30000000现场接单
  355. orderReceiveDate = all[6];// 30现场接单时间
  356. compEleDate = all[7];// 00200000完整申报电子申报时间
  357. profVerifyDate = all[8];// 33专业审证单核时间
  358. eleDeclDate = all[9];// 00电子申报时间
  359. assessStartDate = all[10];// 26排查处置/现场验估时间
  360. assessEndDate = all[11];// 26验估处置完毕时间
  361. refundDate = all[12];// 退单时间
  362. }
  363. Date realArriveDate = tmpMap9.get(entryId);
  364. Object[] obj = tmpMap10.get(entryId);
  365. BigDecimal rmbPrice = zero;
  366. BigDecimal usdPrice = zero;
  367. String agentCode = null;
  368. String agentName = null;
  369. String noteS = null;
  370. String ownerCode = null;
  371. String ownerName = null;
  372. String frnConsignCode = null;
  373. String frnConsignName = null;
  374. if (obj != null) {
  375. rmbPrice = (BigDecimal) obj[0];//人民币
  376. usdPrice = (BigDecimal) obj[1];//美元
  377. agentCode = (String) obj[2];//申报单位代码
  378. agentName = (String) obj[3];//申报单位名称
  379. noteS = (String) obj[4];//备注
  380. ownerCode = (String) obj[5];//生产销售单位代码
  381. ownerName = (String) obj[6];//生产销售单位名称
  382. frnConsignCode = (String) obj[7];//生产销售单位代码
  383. frnConsignName = (String) obj[8];//生产销售单位名称
  384. }
  385. Object[] man = tmpMap11.get(entryId);
  386. String checkFlag = null;
  387. Date manCreateTime = null;
  388. Date manChkTimeStart = null;
  389. Date manChkTimeEnd = null;
  390. String manProcResult = null;
  391. String manProcIdea = null;
  392. String checkCustomsCode = null;
  393. if (man != null) {
  394. checkFlag = (String) man[0];//是否查验送检
  395. manCreateTime = (Date) man[1];//指令下达时间
  396. manChkTimeStart = (Date) man[2];//查验开始时间
  397. manChkTimeEnd = (Date) man[3];//查验结束时间
  398. manProcResult = (String) man[4];//处理结果
  399. manProcIdea = (String) man[5];//处理意见
  400. checkCustomsCode = (String) man[6];//查验关区
  401. }
  402. if ("I".equals(ieFlag)) {
  403. if (realArriveDate != null) {
  404. ieDate = realArriveDate;
  405. } else {
  406. if (ieDate != null) {
  407. // 由于报关单表中I_E_DATE精度不够,需要做(非精准)修正(用户给的建议应该是错的,模糊处理下好了,时分为0的设置为12点)
  408. if ("I".equals(ieFlag)) {// 入境
  409. String ieDateStr = fullSdf.format(ieDate);
  410. if (ieDateStr.endsWith("00:00:00")) {
  411. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  412. try {
  413. ieDate = fullSdf.parse(ieDateStr);
  414. } catch (ParseException e1) {
  415. // TODO Auto-generated catch block
  416. e1.printStackTrace();
  417. }
  418. }
  419. }
  420. }
  421. }
  422. } else {
  423. realArriveDate = tmpMap12.get(entryId);
  424. //ARRIVAL_DATE为00:00:00时赋值12:00:00
  425. if (realArriveDate != null) {
  426. String ieDateStr = fullSdf.format(realArriveDate);
  427. if (ieDateStr.endsWith("00:00:00")) {
  428. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  429. try {
  430. realArriveDate = fullSdf.parse(ieDateStr);
  431. } catch (ParseException e1) {
  432. // TODO Auto-generated catch block
  433. e1.printStackTrace();
  434. }
  435. }
  436. }
  437. }
  438. EntryHead e = new EntryHead();
  439. e.setEntryId(entryId);
  440. e.setAcceptDate(authDate != null ? authDate : orderDate);
  441. e.setCertRlsDate(certRlsDate);// 70单证放行时间
  442. e.setReleaseDate(releaseDate);//80
  443. e.setPreReleaseDate(preReleaseDate);// 81时间
  444. e.setPassMode("1");// 一体化通关
  445. e.setDeclPort(declPort);
  446. e.setIePort(iePort);
  447. e.setIeDate(ieDate);
  448. e.setDeclDate(declDate);
  449. e.setIeFlag(ieFlag);
  450. e.setTrafMode(trafMode);
  451. e.setConsignScc(consignScc);
  452. e.setConsignCode(consignCode);
  453. e.setConsignName(consignName);
  454. e.setTradeCountry(tradeCountry);
  455. e.setTradeMode(tradeMode);
  456. e.setOrderReceiveDate(orderReceiveDate);//30接单时间
  457. e.setCompEleDate(compEleDate);// 00200000完整申报电子申报时间
  458. e.setProfVerifyFlag(profVerifyDate != null ? "1" : "0");
  459. e.setNewTwoStepFlag((null != newTwoStep && !"".equals(newTwoStep) && newTwoStep.equals("1")) ? "1" : "0");
  460. e.setEleDeclDate(eleDeclDate);
  461. e.setAssessStartDate(assessStartDate);
  462. e.setAssessEndDate(assessEndDate);
  463. e.setRefundDate(refundDate);
  464. e.setRefundFlag(refundDate != null ? "1" : "0");
  465. e.setCheckFlag(manCreateTime != null ? "1" : "0");
  466. long orderReceiveCost = 0L;//接单耗时:30000000-10000000
  467. //20210423新增处理10节点无时间时的赋值,避免程序报错
  468. if (orderReceiveDate != null && (authDate != null || orderDate != null)) {
  469. Long time = authDate != null ? authDate.getTime() : orderDate.getTime();
  470. orderReceiveCost = (orderReceiveDate.getTime() - time) / 1000;
  471. e.setOrderReceiveCost(orderReceiveCost);
  472. } else {
  473. e.setOrderReceiveCost(null);
  474. }
  475. long hgCost = 0L;
  476. long totalCost = 0L;
  477. //edi_remark11位为T表示提前申报
  478. if ("T".equals(advanceDecl)) {
  479. e.setDeclAdvanceFlag("1");
  480. } else {
  481. e.setDeclAdvanceFlag("0");
  482. }
  483. if ("I".equals(ieFlag)) {// 入境
  484. /**根据综合处杨科提出的修改意见,这里将原来'电脑审单时间早于货物运抵时间'改成'申报时间早于货物运抵时间'的为提前申报*/
  485. /*if (authDate.before(ieDate)) {
  486. authDate = ieDate;
  487. e.setDeclAdvanceFlag("1");
  488. }*/
  489. if (ieDate != null) {
  490. if (declDate.before(ieDate)) {
  491. authDate = ieDate;
  492. // e.setDeclAdvanceFlag("1");
  493. } else {
  494. //20210423新增处理10节点无时间时的赋值,避免程序报错
  495. if (authDate == null) {
  496. authDate = orderDate;
  497. }
  498. }
  499. }
  500. if (e.getPreReleaseDate() == null && e.getReleaseDate() != null) {
  501. if (authDate != null) {
  502. hgCost = (e.getReleaseDate().getTime() - authDate.getTime()) / 1000;
  503. }
  504. if (ieDate != null) {
  505. totalCost = (e.getReleaseDate().getTime() - ieDate.getTime()) / 1000;
  506. }
  507. } else if (e.getPreReleaseDate() != null) {
  508. if (authDate != null) {
  509. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  510. }
  511. if (ieDate != null) {
  512. totalCost = (e.getPreReleaseDate().getTime() - ieDate.getTime()) / 1000;
  513. }
  514. }
  515. if (hgCost < 0) {
  516. hgCost = 0L;
  517. }
  518. if (totalCost < 0) {
  519. totalCost = hgCost;
  520. }
  521. //新组合查询用00-货物运抵,组合查询用10-货物运抵
  522. e.setBeforeDeclCost((eleDeclDate.getTime() - e.getIeDate().getTime()) / 1000);// 申报前准备时间
  523. if (e.getBeforeDeclCost() < 0) {
  524. e.setBeforeDeclCost(0L);
  525. }
  526. } else {// 出境 海关通关时间=70/81之间较早的时间-受理时间
  527. // 20191211 出口口岸清关、一体化:公路取BINDING_ROAD_TRANSPORT表GEN_DATE;铁路、邮路运输的整体通关时长=海关通关时长
  528. //20210423新增处理10节点无时间时的赋值,避免程序报错
  529. if (authDate == null) {
  530. authDate = orderDate;
  531. }
  532. if (realArriveDate != null) {
  533. //20211209出口舱单有时间赋值给出口货物运抵时间否则使用10审单时间,同时进行计算
  534. e.setExInPortDate(realArriveDate);
  535. } else {
  536. // 取不到数据的统一将货物入境时间设置为受理时间
  537. if ("3".equals(trafMode) || "6".equals(trafMode) || "9".equals(trafMode)) {// 其它运输方式也假设归为一类
  538. e.setExInPortDate(authDate);
  539. } else if ("4".equals(trafMode)) {//TODO 公路:暂时取不到数据
  540. e.setExInPortDate(authDate);
  541. } else {
  542. e.setExInPortDate(authDate);// TODO 出口水运、空运通关时长第一个时间点数据来源还未下发,先临时赋值
  543. }
  544. }
  545. if (e.getCertRlsDate() == null) {
  546. if (e.getPreReleaseDate() != null) {
  547. if (authDate != null) {
  548. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  549. }
  550. totalCost = e.getExInPortDate() != null
  551. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  552. : hgCost;
  553. }
  554. } else {
  555. if (e.getPreReleaseDate() != null) {
  556. if (e.getCertRlsDate().before(e.getPreReleaseDate())) {
  557. if (authDate != null) {
  558. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  559. }
  560. totalCost = e.getExInPortDate() != null
  561. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  562. : hgCost;
  563. } else {
  564. if (authDate != null) {
  565. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  566. }
  567. totalCost = e.getExInPortDate() != null
  568. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  569. : hgCost;
  570. }
  571. } else {
  572. if (authDate != null) {
  573. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  574. }
  575. totalCost = e.getExInPortDate() != null
  576. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  577. : hgCost;
  578. }
  579. }
  580. e.setBeforeDeclCost(e.getExInPortDate() != null
  581. ? ((eleDeclDate.getTime() - e.getExInPortDate().getTime()) / 1000)
  582. : 0L);// 申报前准备时间
  583. if (e.getBeforeDeclCost() < 0) {
  584. e.setBeforeDeclCost(0L);
  585. }
  586. }
  587. e.setMainStatus("1");
  588. e.setCuCost(hgCost);// 海关通关时间(秒)
  589. e.setTotalCost(totalCost);// 总体通关时间
  590. e.setGrossWt(grossWt);//净重
  591. e.setNetWt(netWt);//毛重
  592. e.setRmbPrice(rmbPrice);//人民币
  593. e.setUsdPrice(usdPrice);//美元
  594. e.setContainer(container);//集装箱数量
  595. e.setAgentCode(agentCode);//申报单位代码
  596. e.setAgentName(agentName);//申报单位名称
  597. e.setNoteS(noteS);//备注
  598. e.setOwnerCode(ownerCode);//生产销售单位代码
  599. e.setOwnerName(ownerName);//生产销售单位名称
  600. e.setFrnConsignCode(frnConsignCode);
  601. e.setFrnConsignName(frnConsignName);
  602. //报关模式
  603. String mode = null;
  604. //部分订单既是提前申报又是两步申报,不是两步和提前申报的单子均为一般申报,twoStepDecl:0或者空格:代表一分模式
  605. if ("1".equals(e.getDeclAdvanceFlag()) && (null == twoStepDecl || "".equals(twoStepDecl) || "0".equals(twoStepDecl))) {
  606. mode = "3";
  607. } else if ("1".equals(e.getDeclAdvanceFlag()) && (null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  608. mode = "2,3";
  609. } else if ((null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  610. mode = "2";
  611. } else {
  612. mode = "1";
  613. }
  614. e.setDeclMode(mode);//报关模式
  615. //70000000、80000000、81000000、82000000均为空则表示未放行
  616. if (preReleaseDate == null && certRlsDate == null && releaseDate == null && passDate == null) {
  617. e.setDeclStatus("1");
  618. } else if (releaseDate != null) {
  619. //80表示已结关
  620. e.setDeclStatus("3");
  621. } else {
  622. e.setDeclStatus("2");
  623. }
  624. e.setManCreateTime(manCreateTime);//指令下达时间
  625. e.setManChkTimeStart(manChkTimeStart);//查验开始时间
  626. e.setManChkTimeEnd(manChkTimeEnd);//查验结束时间
  627. e.setManProcResult(manProcResult);
  628. e.setManProcIdea(manProcIdea);
  629. e.setCheckCustomsCode(checkCustomsCode);
  630. dao.executeUpdate("delete from WXJY_ENTRY_HEAD where ENTRY_ID = ?", entryId);
  631. entryHeadRepository.save(e);
  632. }
  633. //ciqCode存在超过600个情况,每个报关单每次查都拼接重复工作太多,所以提出来
  634. //先删除这些报关单下的所有商品信息
  635. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  636. try {
  637. StringBuilder codeListSb = new StringBuilder();
  638. int x = 1;
  639. for (Iterator it = allCode.iterator(); it.hasNext(); ) {
  640. String iqCode = (String) it.next();
  641. codeListSb.append("'").append(iqCode).append("',");
  642. if ((x % 600 == 0 || !it.hasNext()) && codeListSb.length() > 0) {
  643. codeListSb.deleteCharAt(codeListSb.length() - 1);
  644. String iqCodes = codeListSb.toString();
  645. //报关单表体,报关单第九位0=出口1=进口
  646. sql = "select ENTRY_ID,G_NO,CODE_TS,G_NAME,QTY_1,RMB_PRICE,USD_PRICE,G_MODEL,G_CERT_FLAG," +
  647. "(select max(a.CREATE_DATE) from ENTRY_WORKFLOW a where a.STEP_ID='80000000' AND l.ENTRY_ID = a.ENTRY_ID) as RELEASE_DATE," +
  648. "UNGID,UNG_FLAG,UNG_MODEL,UNG_CLASSIFY,UNG_G_NAME,PRODUCT_CHAR_CODE,IQ_CODE " +
  649. "from ENTRY_LIST l where l.ENTRY_ID in (" + entryIds + ") " +
  650. "and ((substr(l.ENTRY_ID,9,1) ='0' and (l.IQ_CODE in (" + iqCodes + ") or l.UNGID is not null " +
  651. "or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')) or " +
  652. "(substr(l.ENTRY_ID,9,1) = '1' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')));";
  653. List<Object[]> codeTsList = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  654. if (null != codeTsList && codeTsList.size() > 0) {
  655. //由于新组合查询不设定某个固定节点更新数据,会存在相同报关单在后面更新流程节点时间,所以先从中间表查出数据进行更新
  656. //会存在商品金额为空的情况,如果只有一条商品并商品为空则报关单头要删除
  657. EntryList entity = null;
  658. for (Object[] codeTs : codeTsList) {//将根据报关单编号查询到的商品编号及报关单号添加到KPI_ENTRY_HEAD_NEW_COPY表里
  659. entity = new EntryList();
  660. entity.setEntryId(codeTs[0] != null ? codeTs[0].toString() : "");
  661. entity.setGNo(codeTs[1] != null ? (BigDecimal) codeTs[1] : new BigDecimal(0));
  662. entity.setCodeTs(codeTs[2] != null ? codeTs[2].toString() : "");
  663. entity.setGName(codeTs[3] != null ? codeTs[3].toString() : "");
  664. entity.setQty1(codeTs[4] != null ? (BigDecimal) codeTs[4] : new BigDecimal(0));
  665. entity.setRmbPrice(codeTs[5] != null ? (BigDecimal) codeTs[5] : new BigDecimal(0));
  666. entity.setUsdPrice(codeTs[6] != null ? (BigDecimal) codeTs[6] : new BigDecimal(0));
  667. entity.setGModel(codeTs[7] != null ? codeTs[7].toString() : "");
  668. entity.setGCertFlag(codeTs[8] != null ? codeTs[8].toString() : "");
  669. entity.setReleaseDate(codeTs[9] != null ? (Date) codeTs[9] : null);
  670. entity.setCodeTsShort(codeTs[2] != null ? codeTs[2].toString().substring(0, 6) : "");
  671. entity.setUngid(codeTs[10] != null ? codeTs[10].toString() : "");
  672. entity.setUngFlag(codeTs[11] != null ? codeTs[11].toString() : "");
  673. entity.setUngModel(codeTs[12] != null ? codeTs[12].toString() : "");
  674. entity.setUngClassify(codeTs[13] != null ? codeTs[13].toString() : "");
  675. entity.setUngGName(codeTs[14] != null ? codeTs[14].toString() : "");
  676. entity.setIqCode(codeTs[16] != null ? codeTs[16].toString() : "");
  677. //货物属性,判断货物属性是否是31/散装危险化学品,32/件装危险化学品
  678. String goods_attr = "";
  679. if (codeTs[15] != null) {
  680. goods_attr = (String) codeTs[15];
  681. if (goods_attr.contains("31")) {
  682. goods_attr = "31";
  683. } else if (goods_attr.contains("32")) {
  684. goods_attr = "32";
  685. } else {
  686. goods_attr = "";
  687. }
  688. }
  689. entity.setProductCharCode(goods_attr);
  690. //查出的数据可能存在ciqCode或者UNGID为空的情况,报关单第九位0=出口1=进口
  691. //出口按ciq编码、ungid不为空和货物属性包含31或32
  692. //进口按ungid不为空或货物属性
  693. String ieFlag = codeTs[0] != null ? codeTs[0].toString().substring(8, 9) : "";
  694. //货物属性为不空时可以初步判定该商品是危化品,接下来只需判断该商品是否还包含危险货物的属性
  695. if (entity.getProductCharCode() != null && !"".equals(entity.getProductCharCode())) {
  696. if (codeTs[10] != null) {
  697. entity.setGoodsType("1,2,3");
  698. } else {
  699. entity.setGoodsType("1");
  700. }
  701. } else {
  702. //货物属性为空时
  703. //出口
  704. if (ieFlag.equals("0")) {
  705. if (codeTs[16] != null) {
  706. //syncChemicalsCiq只可能是包含了危化品,因为这个表的数据就是查询的系统中危险品模块里用户已经维护的包含了危化品的数据
  707. Object[] obj = (Object[]) dao.getObjectBySql("select * from iedg_sync_chemicals_ciq where CIQ_CODE = ?", (String) codeTs[16]);
  708. if (obj != null) {
  709. if (codeTs[16] != null) {
  710. entity.setGoodsType("1,2,3");
  711. } else {
  712. entity.setGoodsType("1");
  713. }
  714. } else {
  715. entity.setGoodsType("2");
  716. }
  717. } else {
  718. entity.setGoodsType("2");
  719. }
  720. } else {
  721. //进口
  722. entity.setGoodsType("2");
  723. }
  724. }
  725. entity.setId(dao.getGuidStringBySql());
  726. entryListRepository.save(entity);
  727. }
  728. }
  729. codeListSb.delete(0, codeListSb.length());
  730. }
  731. x++;
  732. }
  733. } catch (Exception ex) {
  734. // 主键可能因为多次结关跨天,导致新纪录主键重复
  735. logger.error("保存危险品新维度一体化通关中间记录失败,重新保存");
  736. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  737. }
  738. tmpMap1.clear();
  739. tmpMap2.clear();
  740. tmpMap9.clear();
  741. tmpMap10.clear();
  742. tmpMap12.clear();
  743. tmpMap11.clear();
  744. sb.delete(0, sb.length());
  745. }
  746. i++;
  747. }
  748. }
  749. }
  750. }
  751. public void zgDeclMain(Date statBegin, Date statEnd, List<String> code, List<String> allCode) {
  752. Map<String, Object[]> tmpMap1 = new HashMap<String, Object[]>();
  753. Map<String, Date[]> tmpMap2 = new HashMap<String, Date[]>();
  754. Map<String, Date[]> tmpMap5 = new HashMap<String, Date[]>();//转关
  755. Map<String, Date> tmpMap9 = new HashMap<String, Date>();
  756. Map<String, Object[]> tmpMap10 = new HashMap<String, Object[]>();
  757. Map<String, Object[]> tmpMap11 = new HashMap<String, Object[]>();
  758. Map<String, Date> tmpMap12 = new HashMap<String, Date>();
  759. if (code != null && code.size() > 0) {
  760. List<String> entryH2018IdList = new ArrayList<>();//存放所有
  761. StringBuilder codeSb = new StringBuilder();
  762. int j = 1;
  763. for (Iterator itera = code.iterator(); itera.hasNext(); ) {
  764. String ciqCode = (String) itera.next();
  765. codeSb.append("'").append(ciqCode).append("',");
  766. if ((j % 600 == 0 || !itera.hasNext()) && codeSb.length() > 0) {
  767. codeSb.deleteCharAt(codeSb.length() - 1);
  768. String codes = codeSb.toString();
  769. //存在后续查出的报关单前面已经有,所以需要处理去重
  770. //出口按编码、ungid不为空和货物属性包含31或32
  771. //进口按ungid不为空或货物属性包含31或32
  772. String sql = "select distinct(d.ENTRY_ID) from ENTRY_HEAD d, ENTRY_WORKFLOW w, ENTRY_LIST l where " +
  773. "d.ENTRY_ID like '47%' and (substr(d.EDI_REMARK,7,1)!='C' or substr(d.EDI_REMARK,15,1)!='1') " +
  774. "and (substr(d.EDI_REMARK,17,1) not in ('a','c','C','d','e','f') " +
  775. "or (substr(d.EDI_REMARK,17,1) = 'C' and substr(d.EDI_REMARK,8,1) != 'G')) and substr(d.I_E_PORT,0,2)!=substr(d.DECL_PORT,0,2) " +
  776. "and d.ENTRY_ID = w.ENTRY_ID and d.ENTRY_ID = l.ENTRY_ID and w.STEP_ID = '80000000' and w.CREATE_DATE >= ? and w.CREATE_DATE < ? " +
  777. "and ((d.I_E_FLAG = 'E' and (l.IQ_CODE in (" + codes + ") or l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  778. "or l.PRODUCT_CHAR_CODE like '%32%')) or (d.I_E_FLAG = 'I' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  779. "or l.PRODUCT_CHAR_CODE like '%32%'))) order by d.ENTRY_ID;";
  780. List<String> entryIdList = (List<String>) h2018Dao.getQueryBySql(sql, statBegin, statEnd);
  781. entryH2018IdList.addAll(entryIdList);
  782. codeSb.delete(0, codeSb.length());
  783. }
  784. j++;
  785. }
  786. //用JDK1.8 Stream中对List进行去重:list.stream().distinct();
  787. entryH2018IdList = (List) entryH2018IdList.stream().distinct().collect(Collectors.toList());
  788. if (entryH2018IdList != null && entryH2018IdList.size() > 0) {
  789. StringBuilder sb = new StringBuilder();
  790. int i = 1;
  791. for (Iterator iterator = entryH2018IdList.iterator(); iterator.hasNext(); ) {
  792. String id = (String) iterator.next();
  793. sb.append("'").append(id).append("',");
  794. if ((i % 300 == 0 || !iterator.hasNext()) && sb.length() > 0) {
  795. List<String> impIdList = new ArrayList<String>();
  796. List<String> impIdList2 = new ArrayList<String>();//20191210 进口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_LIST_NEW查到精确I_E_DATE
  797. List<String> impIdList3 = new ArrayList<String>();//20211210 出口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_MONITOR_NEW查到精确ARRIVAL_DATE
  798. Map<String, Object> map = new HashMap<String, Object>();
  799. sb.deleteCharAt(sb.length() - 1);
  800. String ids = sb.toString();
  801. String entryIds = sb.toString();
  802. String sql = "select h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT,CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY,"
  803. + " TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),nvl(count(c.ENTRY_ID),0),substr(EDI_REMARK,53,1) "
  804. + "from ENTRY_HEAD h left join `g_whdb_zmqd`.h18c_ENTRY_CONTAINER c on h.ENTRY_ID = c.ENTRY_ID where h.ENTRY_ID in ("
  805. + ids + ") group by h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT, CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY," +
  806. "TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),substr(EDI_REMARK,53,1);";
  807. List<Object[]> list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  808. for (Object[] d : list) {
  809. String idH = (String) d[0];
  810. String iEFlag = (String) d[3];
  811. String traMode = (String) d[4];
  812. if ("I".equals(iEFlag)) {
  813. impIdList.add(idH);
  814. if ("2".equals(traMode) || "5".equals(traMode)) {
  815. impIdList2.add(idH);
  816. }
  817. } else {
  818. if ("2".equals(traMode) || "5".equals(traMode)) {
  819. impIdList3.add(idH);
  820. }
  821. }
  822. tmpMap1.put((String) d[0],
  823. new Object[]{(Date) d[1], (String) d[2], (String) d[3], (String) d[4], (Date) d[5], (String) d[6], (String) d[7], (String) d[8], (String) d[9], (String) d[10], (String) d[11],
  824. (BigDecimal) d[12], (BigDecimal) d[13], (String) d[14], (String) d[15], (BigInteger) d[16], (String) d[17]});
  825. }
  826. sql = "select h.ENTRY_ID,(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='10000000' AND h.ENTRY_ID = a.ENTRY_ID) as authDate,"
  827. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='80000000' AND h.ENTRY_ID = a.ENTRY_ID) as releaseDate,"
  828. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='81000000' AND h.ENTRY_ID = b.ENTRY_ID) as preReleaseDate,"
  829. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='70000000' AND h.ENTRY_ID = c.ENTRY_ID) as certRlsDate,"
  830. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='82000000' AND h.ENTRY_ID = c.ENTRY_ID) as passDate,"
  831. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='30000000' AND h.ENTRY_ID = c.ENTRY_ID) as orderDate,"
  832. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='30000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as orderReceiveDate,"
  833. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='00200000' AND h.ENTRY_ID = c.ENTRY_ID) as compEleDate,"
  834. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='33000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as profVerifyDate, "
  835. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='00000000' AND h.ENTRY_ID = b.ENTRY_ID) as eleDeclDate, "
  836. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%M%') as assessStartDate, "
  837. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%') as assessEndDate,"
  838. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID in ('10000000','10200000','20000000') AND h.ENTRY_ID = b.ENTRY_ID and substr(b.status_code,4,1) = 5 and b.proc_result like '%E%') as refundDate "
  839. + "from ENTRY_HEAD h where h.ENTRY_ID in (" + ids
  840. + ") group by ENTRY_ID;";
  841. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  842. for (Object[] d : list) {
  843. tmpMap2.put((String) d[0], new Date[]{(Date) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (Date) d[5], (Date) d[6], (Date) d[7], (Date) d[8], (Date) d[9],
  844. (Date) d[10], (Date) d[11], (Date) d[12], (Date) d[13]});
  845. }
  846. sql = "select h.ENTRY_ID,substr(h.CHECK_REQUEST_TOTAL,-1,1),h.CREATE_TIME,h.MAN_CHK_TIME_START,h.MAN_CHK_TIME_END,MAN_PROC_RESULT,MAN_PROC_IDEA,CHECK_CUSTOMS_CODE "
  847. + "from CI_CHECK_MAN_WORK_HEAD h where h.CHECK_STATE = 'M' and h.MODIFY_TIME = "
  848. + "(select max(d.MODIFY_TIME) from CI_CHECK_MAN_WORK_HEAD d where d.ID = h.ID) and h.ENTRY_ID in(" + ids + ") ;";
  849. list = (List<Object[]>) inspDao.getQueryBySql(sql);
  850. for (Object[] d : list) {
  851. tmpMap11.put((String) d[0], new Object[]{(String) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (String) d[5], (String) d[6], (String) d[7]});
  852. }
  853. //货运量毛重、净重、货运值人民币、美元、集装箱数量GROUP_CONCAT方法放在此处当传一个报关单id并且没有随附单证时会报错,所以加上nvl()
  854. sql = "select h.ENTRY_ID,sum(nvl(l.RMB_PRICE,0)),sum(nvl(l.USD_PRICE,0)),h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,"
  855. + "h.OWNER_CODE,h.OWNER_NAME,FRN_CONSIGN_CODE,FRN_CONSIGN_NAME from ENTRY_HEAD h left join ENTRY_LIST l on h.ENTRY_ID=l.ENTRY_ID "
  856. + "where h.ENTRY_ID in("
  857. + ids + ") group by h.ENTRY_ID,h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,h.OWNER_CODE,h.OWNER_NAME,FRN_CONSIGN_CODE,FRN_CONSIGN_NAME;";
  858. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  859. for (Object[] d : list) {
  860. tmpMap10.put((String) d[0], new Object[]{(BigDecimal) d[1], (BigDecimal) d[2], (String) d[3], (String) d[4], (String) d[5], (String) d[6], (String) d[7]
  861. , (String) d[8], (String) d[9]});
  862. }
  863. if (impIdList.size() > 0) {
  864. sb.delete(0, sb.length());
  865. for (String impId : impIdList) {
  866. sb.append("'").append(impId).append("',");
  867. }
  868. sb.deleteCharAt(sb.length() - 1);
  869. ids = sb.toString();
  870. // 部分转关类型的报关单需要通过新舱单系统拿到转关数据发送时间和转关数据核销时间
  871. sql = "select a.ENTRY_ID, b.EXAM_TIME, b.CHECK_TIME from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.IM_DECL_CUR_HEAD b, " +
  872. "`g_whdb_h2000_ims_recv`.MANIFEST_CHK_NEW c where a.ENTRY_ID in ("
  873. + ids + ") and (a.ENTRY_ID = c.FORM_ID and c.MANIFEST_ID = b.PRE_NO)";
  874. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  875. for (Object[] d : list) {
  876. String entryId = (String) d[0];
  877. tmpMap5.put(entryId, new Date[]{(Date) d[1], (Date) d[2]});
  878. impIdList.remove(entryId);
  879. }
  880. // 从新舱单关联之后,剩下的再从提运单/转关单关联表查询两个时间值
  881. sb.delete(0, sb.length());
  882. for (String entryId : impIdList) {
  883. sb.append("'").append(entryId).append("',");
  884. }
  885. if (sb.length() > 0) {
  886. List<String> tmpIdList = new ArrayList<String>(impIdList);
  887. sb.deleteCharAt(sb.length() - 1);
  888. ids = sb.toString();
  889. // 2019-11-07 入境报关单整体通关时间第一个时间点计算规则变更,水运和空运取报关单和提运单表中I_E_DATE时分秒不为0的,若都为0,则设置为12点;新舱单中I_E_DATE时分秒基本都为0,故不考虑。
  890. // 公路的取 “进出境承运已确报”(物流监控工作流信息表)
  891. // 经过数据分析,放弃上面方案,改为若I_E_DATE时分为0的改为12点
  892. // 只考虑入境报关单的转关数据:可能查到多余报关单量的数据
  893. sql = "select a.ENTRY_ID, b.EXAM_TIME, b.CHECK_TIME from ENTRY_HEAD a,`g_whdb_h2000_ims_recv`.IM_DECL_CUR_HEAD b," +
  894. "`g_whdb_h2000_ims_recv`.IM_TRANS_LIST_REL c where a.ENTRY_ID in ("
  895. + ids + ") and (a.ENTRY_ID = c.ENTRY_NO and c.PRE_NO = b.PRE_NO)";
  896. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  897. for (Object[] d : list) {
  898. String entryId = (String) d[0];
  899. tmpMap5.put(entryId, new Date[]{(Date) d[1], (Date) d[2]});
  900. tmpIdList.remove(entryId);
  901. }
  902. sb.delete(0, sb.length());
  903. for (String entryId : tmpIdList) {
  904. sb.append("'").append(entryId).append("',");
  905. }
  906. if (sb.length() > 0) {
  907. sb.deleteCharAt(sb.length() - 1);
  908. ids = sb.toString();
  909. sql = "select a.ENTRY_ID, b.EXAM_TIME, b.CHECK_TIME from ENTRY_HEAD a,`g_whdb_h2000_ims_recv`.IM_DECL_CUR_HEAD b," +
  910. "`g_whdb_h2000_ims_recv`.IM_TRANS_LIST_REL c where a.ENTRY_ID in ("
  911. + ids + ") and (a.BILL_NO = c.BILL_NO and c.PRE_NO = b.PRE_NO)";
  912. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  913. for (Object[] d : list) {
  914. String entryId = (String) d[0];
  915. tmpMap5.put(entryId, new Date[]{(Date) d[1], (Date) d[2]});
  916. tmpIdList.remove(entryId);
  917. }
  918. }
  919. sb.delete(0, sb.length());
  920. for (String entryId : tmpIdList) {
  921. sb.append("'").append(entryId).append("',");
  922. }
  923. if (sb.length() > 0) {
  924. sb.deleteCharAt(sb.length() - 1);
  925. ids = sb.toString();
  926. sql = "select a.ENTRY_ID, b.EXAM_TIME, b.CHECK_TIME from ENTRY_HEAD a,`g_whdb_h2000_ims_recv`.IM_DECL_CUR_HEAD b " +
  927. "where a.ENTRY_ID in (" + ids + ") and instr(a.TRAF_NAME,b.PRE_NO) > 0";
  928. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  929. for (Object[] d : list) {
  930. String entryId = (String) d[0];
  931. tmpMap5.put(entryId, new Date[]{(Date) d[1], (Date) d[2]});
  932. tmpIdList.remove(entryId);
  933. }
  934. }
  935. }
  936. }
  937. if (impIdList2.size() > 0) {
  938. sb.delete(0, sb.length());
  939. for (String impId : impIdList2) {
  940. sb.append("'").append(impId).append("',");
  941. }
  942. sb.deleteCharAt(sb.length() - 1);
  943. ids = sb.toString();
  944. // 进口新舱单水运、空运的I_E_DATE精准值由MANIFEST_LIST_NEW的REAL_ARRIVE_DATE给定
  945. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号
  946. sql = "select a.ENTRY_ID, b.REAL_ARRIVE_DATE from ENTRY_HEAD a,`g_whdb_h2000_ims_recv`.MANIFEST_LIST_NEW b where a.ENTRY_ID in ("
  947. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE and to_char(a.I_E_DATE,'yyyyMMdd') = to_char(b.REAL_ARRIVE_DATE,'yyyyMMdd')";
  948. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  949. for (Object[] d : list) {
  950. String entryId = (String) d[0];
  951. tmpMap9.put(entryId, (Date) d[1]);
  952. }
  953. impIdList2.clear();
  954. }
  955. //出口舱单
  956. if (impIdList3.size() > 0) {
  957. sb.delete(0, sb.length());
  958. for (String impId : impIdList3) {
  959. sb.append("'").append(impId).append("',");
  960. }
  961. sb.deleteCharAt(sb.length() - 1);
  962. ids = sb.toString();
  963. // 出口新舱单水运、空运可能提前但航班晚到,无法用时间去精准定位哪一条会卸载很多次,精准值由MANIFEST_MONITOR_NEW的ARRIVAL_DATE给定
  964. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号,ARRIVAL_DATE为00:00:00的赋值12:00:00
  965. //20210508舱单只获取和武汉海关有关的数据进行时间赋值,所以a.I_E_PORT = b.CUSTOMS_CODE
  966. sql = "select a.ENTRY_ID, min(b.ARRIVAL_DATE) from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.MANIFEST_MONITOR_NEW b where a.ENTRY_ID in ("
  967. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE group by a.ENTRY_ID";
  968. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  969. for (Object[] d : list) {
  970. String entryId = (String) d[0];
  971. tmpMap12.put(entryId, (Date) d[1]);
  972. }
  973. impIdList3.clear();
  974. }
  975. for (Map.Entry<String, Object[]> d : tmpMap1.entrySet()) {
  976. String entryId = d.getKey();
  977. Object[] v = d.getValue();
  978. Date ieDate = (Date) v[0];// 货物运抵时间
  979. String iePort = (String) v[1];
  980. String ieFlag = (String) v[2];
  981. String trafMode = (String) v[3];
  982. Date declDate = (Date) v[4];// 申报时间
  983. String declPort = (String) v[5];// 申报口岸
  984. String consignScc = (String) v[6];
  985. String consignCode = (String) v[7];
  986. String consignName = (String) v[8];
  987. String tradeCountry = (String) v[9];
  988. String tradeMode = (String) v[10];
  989. BigDecimal grossWt = (BigDecimal) v[11];//毛重
  990. BigDecimal netWt = (BigDecimal) v[12];//净重
  991. String advanceDecl = (String) v[13];//判断是否是提前申报
  992. //两步申报都下发到了h2018所以使用00200000节点判断只属于两步申报其中一种类型,
  993. //应当使用edi_remark41位判断是否有值(edi_remark41值为1,2,3均为两步申报)
  994. String twoStep = (String) v[14];//判断是否是两步申报
  995. //2018存在twoStepValue截取出来值为' '情况,需要单独处理
  996. String twoStepDecl = (" ").equals(twoStep) ? "" : twoStep;
  997. BigInteger container = (BigInteger) v[15];// 集装箱数量
  998. String newTwoStep = (String) v[16];//判断是否是新两步申报
  999. Date[] all = tmpMap2.get(entryId);
  1000. Date authDate = null;
  1001. Date releaseDate = null;
  1002. Date preReleaseDate = null;
  1003. Date certRlsDate = null;
  1004. Date passDate = null;
  1005. Date orderDate = null;
  1006. Date orderReceiveDate = null;
  1007. Date compEleDate = null;
  1008. Date profVerifyDate = null;
  1009. Date eleDeclDate = null;
  1010. Date assessStartDate = null;
  1011. Date assessEndDate = null;
  1012. Date refundDate = null;
  1013. if (all != null) {
  1014. authDate = all[0];// 10审单受理时间
  1015. releaseDate = all[1];// 80结关时间
  1016. preReleaseDate = all[2];// 81担保放行时间
  1017. certRlsDate = all[3];// 70单证放行时间
  1018. passDate = all[4];// 82000000通道验放
  1019. orderDate = all[5];// 30000000现场接单
  1020. orderReceiveDate = all[6];// 30现场接单时间
  1021. compEleDate = all[7];// 00200000完整申报电子申报时间
  1022. profVerifyDate = all[8];// 33专业审证单核时间
  1023. eleDeclDate = all[9];// 00电子申报时间
  1024. assessStartDate = all[10];// 26排查处置/现场验估时间
  1025. assessEndDate = all[11];// 26验估处置完毕时间
  1026. refundDate = all[12];// 退单时间
  1027. }
  1028. Date examDate = null;// 转关数据发送时间
  1029. Date checkDate = null;// 转关数据核销时间(极少数转关单该字段为空)
  1030. Date[] dt = tmpMap5.get(entryId);
  1031. if (dt != null) {
  1032. examDate = dt[0];// 转关数据发送时间
  1033. checkDate = dt[1];// 转关数据核销时间
  1034. }
  1035. Date realArriveDate = tmpMap9.get(entryId);
  1036. Object[] obj = tmpMap10.get(entryId);
  1037. BigDecimal rmbPrice = zero;
  1038. BigDecimal usdPrice = zero;
  1039. String agentCode = null;
  1040. String agentName = null;
  1041. String noteS = null;
  1042. String ownerCode = null;
  1043. String ownerName = null;
  1044. String frnConsignCode = null;
  1045. String frnConsignName = null;
  1046. if (obj != null) {
  1047. rmbPrice = (BigDecimal) obj[0];//人民币
  1048. usdPrice = (BigDecimal) obj[1];//美元
  1049. agentCode = (String) obj[2];//申报单位代码
  1050. agentName = (String) obj[3];//申报单位名称
  1051. noteS = (String) obj[4];//备注
  1052. ownerCode = (String) obj[5];//生产销售单位代码
  1053. ownerName = (String) obj[6];//生产销售单位名称
  1054. frnConsignCode = (String) obj[7];//生产销售单位代码
  1055. frnConsignName = (String) obj[8];//生产销售单位名称
  1056. }
  1057. Object[] man = tmpMap11.get(entryId);
  1058. String checkFlag = null;
  1059. Date manCreateTime = null;
  1060. Date manChkTimeStart = null;
  1061. Date manChkTimeEnd = null;
  1062. String manProcResult = null;
  1063. String manProcIdea = null;
  1064. String checkCustomsCode = null;
  1065. if (man != null) {
  1066. checkFlag = (String) man[0];//是否查验送检
  1067. manCreateTime = (Date) man[1];//指令下达时间
  1068. manChkTimeStart = (Date) man[2];//查验开始时间
  1069. manChkTimeEnd = (Date) man[3];//查验结束时间
  1070. manProcResult = (String) man[4];//处理结果
  1071. manProcIdea = (String) man[5];//处理意见
  1072. checkCustomsCode = (String) man[6];//查验关区
  1073. }
  1074. if ("I".equals(ieFlag)) {
  1075. if (realArriveDate != null) {
  1076. ieDate = realArriveDate;
  1077. } else {
  1078. if (ieDate != null) {
  1079. // 由于报关单表中I_E_DATE精度不够,需要做(非精准)修正(用户给的建议应该是错的,模糊处理下好了,时分为0的设置为12点)
  1080. if ("I".equals(ieFlag)) {// 入境
  1081. String ieDateStr = fullSdf.format(ieDate);
  1082. if (ieDateStr.endsWith("00:00:00")) {
  1083. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  1084. try {
  1085. ieDate = fullSdf.parse(ieDateStr);
  1086. } catch (ParseException e1) {
  1087. // TODO Auto-generated catch block
  1088. e1.printStackTrace();
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. } else {
  1095. realArriveDate = tmpMap12.get(entryId);
  1096. //ARRIVAL_DATE为00:00:00时赋值12:00:00
  1097. if (realArriveDate != null) {
  1098. String ieDateStr = fullSdf.format(realArriveDate);
  1099. if (ieDateStr.endsWith("00:00:00")) {
  1100. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  1101. try {
  1102. realArriveDate = fullSdf.parse(ieDateStr);
  1103. } catch (ParseException e1) {
  1104. // TODO Auto-generated catch block
  1105. e1.printStackTrace();
  1106. }
  1107. }
  1108. }
  1109. }
  1110. EntryHead e = new EntryHead();
  1111. e.setEntryId(entryId);
  1112. e.setAcceptDate(authDate != null ? authDate : orderDate);
  1113. e.setCertRlsDate(certRlsDate);// 70单证放行时间
  1114. e.setReleaseDate(releaseDate);//80
  1115. e.setPreReleaseDate(preReleaseDate);// 81时间
  1116. e.setPassMode("3");// 转关
  1117. if ("I".equals(ieFlag)) {
  1118. if (examDate != null) {
  1119. e.setPassMode("3");// 转关
  1120. } else {
  1121. e.setPassMode("1");// 一体化
  1122. }
  1123. } else {
  1124. e.setPassMode("3");// 转关
  1125. }
  1126. e.setDeclPort(declPort);
  1127. e.setIePort(iePort);
  1128. e.setIeDate(ieDate);
  1129. e.setDeclDate(declDate);
  1130. e.setIeFlag(ieFlag);
  1131. e.setTrafMode(trafMode);
  1132. e.setConsignScc(consignScc);
  1133. e.setConsignCode(consignCode);
  1134. e.setConsignName(consignName);
  1135. e.setTradeCountry(tradeCountry);
  1136. e.setTradeMode(tradeMode);
  1137. e.setOrderReceiveDate(orderReceiveDate);//30接单时间
  1138. e.setCompEleDate(compEleDate);// 00200000完整申报电子申报时间
  1139. e.setExamDate(examDate);// 转关数据发送时间
  1140. e.setCheckDate(checkDate);// 转关数据核销时间
  1141. e.setProfVerifyFlag(profVerifyDate != null ? "1" : "0");
  1142. e.setNewTwoStepFlag((null != newTwoStep && !"".equals(newTwoStep) && newTwoStep.equals("1")) ? "1" : "0");
  1143. e.setEleDeclDate(eleDeclDate);
  1144. e.setAssessStartDate(assessStartDate);
  1145. e.setAssessEndDate(assessEndDate);
  1146. e.setRefundDate(refundDate);
  1147. e.setRefundFlag(refundDate != null ? "1" : "0");
  1148. e.setCheckFlag(manCreateTime != null ? "1" : "0");
  1149. long orderReceiveCost = 0L;//接单耗时:30000000-10000000
  1150. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1151. if (orderReceiveDate != null && (authDate != null || orderDate != null)) {
  1152. Long time = authDate != null ? authDate.getTime() : orderDate.getTime();
  1153. orderReceiveCost = (orderReceiveDate.getTime() - time) / 1000;
  1154. e.setOrderReceiveCost(orderReceiveCost);
  1155. } else {
  1156. e.setOrderReceiveCost(null);
  1157. }
  1158. long hgCost = 0L;
  1159. long totalCost = 0L;
  1160. //edi_remark11位为T表示提前申报
  1161. if ("T".equals(advanceDecl)) {
  1162. e.setDeclAdvanceFlag("1");
  1163. } else {
  1164. e.setDeclAdvanceFlag("0");
  1165. }
  1166. if ("I".equals(ieFlag)) {// 入境
  1167. /**根据综合处杨科提出的修改意见,这里将原来'电脑审单时间早于货物运抵时间'改成'申报时间早于货物运抵时间'的为提前申报*/
  1168. /*if (authDate.before(ieDate)) {
  1169. authDate = ieDate;
  1170. e.setDeclAdvanceFlag("1");
  1171. }*/
  1172. if (ieDate != null) {
  1173. if (declDate.before(ieDate)) {
  1174. authDate = ieDate;
  1175. // e.setDeclAdvanceFlag("1");
  1176. } else {
  1177. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1178. if (authDate == null) {
  1179. authDate = orderDate;
  1180. }
  1181. }
  1182. }
  1183. if (e.getPreReleaseDate() == null && e.getReleaseDate() != null) {
  1184. if (authDate != null) {
  1185. hgCost = (e.getReleaseDate().getTime() - authDate.getTime()) / 1000;
  1186. }
  1187. if (ieDate != null) {
  1188. totalCost = (e.getReleaseDate().getTime() - ieDate.getTime()) / 1000;
  1189. }
  1190. } else if (e.getPreReleaseDate() != null) {
  1191. if (authDate != null) {
  1192. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1193. }
  1194. if (ieDate != null) {
  1195. totalCost = (e.getPreReleaseDate().getTime() - ieDate.getTime()) / 1000;
  1196. }
  1197. }
  1198. if (hgCost < 0) {
  1199. hgCost = 0L;
  1200. }
  1201. if (totalCost < 0) {
  1202. totalCost = hgCost;
  1203. }
  1204. } else {// 出境 海关通关时间=70/81之间较早的时间-受理时间
  1205. // 20191211 出口口岸清关、一体化:公路取BINDING_ROAD_TRANSPORT表GEN_DATE;铁路、邮路运输的整体通关时长=海关通关时长
  1206. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1207. if (authDate == null) {
  1208. authDate = orderDate;
  1209. }
  1210. if (realArriveDate != null) {
  1211. //20211209出口舱单有时间赋值给出口货物运抵时间否则使用10审单时间,同时进行计算
  1212. e.setExInPortDate(realArriveDate);
  1213. } else {
  1214. // 取不到数据的统一将货物入境时间设置为受理时间
  1215. if ("3".equals(trafMode) || "6".equals(trafMode) || "9".equals(trafMode)) {// 其它运输方式也假设归为一类
  1216. e.setExInPortDate(authDate);
  1217. } else if ("4".equals(trafMode)) {//TODO 公路:暂时取不到数据
  1218. e.setExInPortDate(authDate);
  1219. } else {
  1220. e.setExInPortDate(authDate);// TODO 出口水运、空运通关时长第一个时间点数据来源还未下发,先临时赋值
  1221. }
  1222. }
  1223. if (e.getCertRlsDate() == null) {
  1224. if (e.getPreReleaseDate() != null) {
  1225. if (authDate != null) {
  1226. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1227. }
  1228. totalCost = e.getExInPortDate() != null
  1229. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1230. : hgCost;
  1231. }
  1232. } else {
  1233. if (e.getPreReleaseDate() != null) {
  1234. if (e.getCertRlsDate().before(e.getPreReleaseDate())) {
  1235. if (authDate != null) {
  1236. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  1237. }
  1238. totalCost = e.getExInPortDate() != null
  1239. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1240. : hgCost;
  1241. } else {
  1242. if (authDate != null) {
  1243. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1244. }
  1245. totalCost = e.getExInPortDate() != null
  1246. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1247. : hgCost;
  1248. }
  1249. } else {
  1250. if (authDate != null) {
  1251. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  1252. }
  1253. totalCost = e.getExInPortDate() != null
  1254. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1255. : hgCost;
  1256. }
  1257. }
  1258. }
  1259. e.setMainStatus("1");
  1260. e.setCuCost(hgCost);// 海关通关时间(秒)
  1261. e.setTotalCost(totalCost);// 总体通关时间
  1262. e.setGrossWt(grossWt);//净重
  1263. e.setNetWt(netWt);//毛重
  1264. e.setRmbPrice(rmbPrice);//人民币
  1265. e.setUsdPrice(usdPrice);//美元
  1266. e.setContainer(container);//集装箱数量
  1267. e.setAgentCode(agentCode);//申报单位代码
  1268. e.setAgentName(agentName);//申报单位名称
  1269. e.setNoteS(noteS);//备注
  1270. e.setOwnerCode(ownerCode);//生产销售单位代码
  1271. e.setOwnerName(ownerName);//生产销售单位名称
  1272. e.setFrnConsignCode(frnConsignCode);
  1273. e.setFrnConsignName(frnConsignName);
  1274. if ("I".equals(ieFlag)) {// 仅入境转关单有以下值
  1275. long beforeDeclCost = 0L;
  1276. if (checkDate != null && examDate != null) {
  1277. beforeDeclCost = (eleDeclDate.getTime() - checkDate.getTime()) / 1000;
  1278. if (beforeDeclCost < 0) {
  1279. beforeDeclCost = 0L;
  1280. }
  1281. }
  1282. e.setBeforeDeclCost(beforeDeclCost);// 申报前准备时间
  1283. } else {// TODO 20191025 出境转关单有 货物进港时间 值
  1284. long beforeDeclCost = e.getExInPortDate() != null
  1285. ? (authDate.getTime() - e.getExInPortDate().getTime())
  1286. : 0L;
  1287. if (beforeDeclCost < 0) {
  1288. beforeDeclCost = 0L;
  1289. }
  1290. e.setBeforeDeclCost(beforeDeclCost);
  1291. }
  1292. //报关模式
  1293. String mode = null;
  1294. //部分订单既是提前申报又是两步申报,不是两步和提前申报的单子均为一般申报,twoStepDecl:0或者空格:代表一分模式
  1295. if ("1".equals(e.getDeclAdvanceFlag()) && (null == twoStepDecl || "".equals(twoStepDecl) || "0".equals(twoStepDecl))) {
  1296. mode = "3";
  1297. } else if ("1".equals(e.getDeclAdvanceFlag()) && (null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  1298. mode = "2,3";
  1299. } else if ((null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  1300. mode = "2";
  1301. } else {
  1302. mode = "1";
  1303. }
  1304. e.setDeclMode(mode);//报关模式
  1305. //70000000、80000000、81000000、82000000均为空则表示未放行
  1306. if (preReleaseDate == null && certRlsDate == null && releaseDate == null && passDate == null) {
  1307. e.setDeclStatus("1");
  1308. } else if (releaseDate != null) {
  1309. //80表示已结关
  1310. e.setDeclStatus("3");
  1311. } else {
  1312. e.setDeclStatus("2");
  1313. }
  1314. e.setManCreateTime(manCreateTime);//指令下达时间
  1315. e.setManChkTimeStart(manChkTimeStart);//查验开始时间
  1316. e.setManChkTimeEnd(manChkTimeEnd);//查验结束时间
  1317. e.setManProcResult(manProcResult);
  1318. e.setManProcIdea(manProcIdea);
  1319. e.setCheckCustomsCode(checkCustomsCode);
  1320. dao.executeUpdate("delete from WXJY_ENTRY_HEAD where ENTRY_ID = ?", entryId);
  1321. entryHeadRepository.save(e);
  1322. }
  1323. //ciqCode存在超过600个情况,每个报关单每次查都拼接重复工作太多,所以提出来
  1324. //先删除这些报关单下的所有商品信息
  1325. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  1326. try {
  1327. StringBuilder codeListSb = new StringBuilder();
  1328. int x = 1;
  1329. for (Iterator it = allCode.iterator(); it.hasNext(); ) {
  1330. String iqCode = (String) it.next();
  1331. codeListSb.append("'").append(iqCode).append("',");
  1332. if ((x % 600 == 0 || !it.hasNext()) && codeListSb.length() > 0) {
  1333. codeListSb.deleteCharAt(codeListSb.length() - 1);
  1334. String iqCodes = codeListSb.toString();
  1335. //报关单表体,报关单第九位0=出口1=进口
  1336. sql = "select ENTRY_ID,G_NO,CODE_TS,G_NAME,QTY_1,RMB_PRICE,USD_PRICE,G_MODEL,G_CERT_FLAG," +
  1337. "(select max(a.CREATE_DATE) from ENTRY_WORKFLOW a where a.STEP_ID='80000000' AND l.ENTRY_ID = a.ENTRY_ID) as RELEASE_DATE," +
  1338. "UNGID,UNG_FLAG,UNG_MODEL,UNG_CLASSIFY,UNG_G_NAME,PRODUCT_CHAR_CODE,IQ_CODE " +
  1339. "from ENTRY_LIST l where l.ENTRY_ID in (" + entryIds + ") " +
  1340. "and ((substr(l.ENTRY_ID,9,1) ='0' and (l.IQ_CODE in (" + iqCodes + ") or l.UNGID is not null " +
  1341. "or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')) or " +
  1342. "(substr(l.ENTRY_ID,9,1) = '1' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')));";
  1343. List<Object[]> codeTsList = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1344. if (null != codeTsList && codeTsList.size() > 0) {
  1345. //由于新组合查询不设定某个固定节点更新数据,会存在相同报关单在后面更新流程节点时间,所以先从中间表查出数据进行更新
  1346. //会存在商品金额为空的情况,如果只有一条商品并商品为空则报关单头要删除
  1347. EntryList entity = null;
  1348. for (Object[] codeTs : codeTsList) {//将根据报关单编号查询到的商品编号及报关单号添加到KPI_ENTRY_HEAD_NEW_COPY表里
  1349. entity = new EntryList();
  1350. entity.setEntryId(codeTs[0] != null ? codeTs[0].toString() : "");
  1351. entity.setGNo(codeTs[1] != null ? (BigDecimal) codeTs[1] : new BigDecimal(0));
  1352. entity.setCodeTs(codeTs[2] != null ? codeTs[2].toString() : "");
  1353. entity.setGName(codeTs[3] != null ? codeTs[3].toString() : "");
  1354. entity.setQty1(codeTs[4] != null ? (BigDecimal) codeTs[4] : new BigDecimal(0));
  1355. entity.setRmbPrice(codeTs[5] != null ? (BigDecimal) codeTs[5] : new BigDecimal(0));
  1356. entity.setUsdPrice(codeTs[6] != null ? (BigDecimal) codeTs[6] : new BigDecimal(0));
  1357. entity.setGModel(codeTs[7] != null ? codeTs[7].toString() : "");
  1358. entity.setGCertFlag(codeTs[8] != null ? codeTs[8].toString() : "");
  1359. entity.setReleaseDate(codeTs[9] != null ? (Date) codeTs[9] : null);
  1360. entity.setCodeTsShort(codeTs[2] != null ? codeTs[2].toString().substring(0, 6) : "");
  1361. entity.setUngid(codeTs[10] != null ? codeTs[10].toString() : "");
  1362. entity.setUngFlag(codeTs[11] != null ? codeTs[11].toString() : "");
  1363. entity.setUngModel(codeTs[12] != null ? codeTs[12].toString() : "");
  1364. entity.setUngClassify(codeTs[13] != null ? codeTs[13].toString() : "");
  1365. entity.setUngGName(codeTs[14] != null ? codeTs[14].toString() : "");
  1366. entity.setIqCode(codeTs[16] != null ? codeTs[16].toString() : "");
  1367. //货物属性,判断货物属性是否是31/散装危险化学品,32/件装危险化学品
  1368. String goods_attr = "";
  1369. if (codeTs[15] != null) {
  1370. goods_attr = (String) codeTs[15];
  1371. if (goods_attr.contains("31")) {
  1372. goods_attr = "31";
  1373. } else if (goods_attr.contains("32")) {
  1374. goods_attr = "32";
  1375. } else {
  1376. goods_attr = "";
  1377. }
  1378. }
  1379. entity.setProductCharCode(goods_attr);
  1380. //查出的数据可能存在ciqCode或者UNGID为空的情况,报关单第九位0=出口1=进口
  1381. //出口按ciq编码、ungid不为空和货物属性包含31或32
  1382. //进口按ungid不为空或货物属性
  1383. String ieFlag = codeTs[0] != null ? codeTs[0].toString().substring(8, 9) : "";
  1384. //货物属性为不空时可以初步判定该商品是危化品,接下来只需判断该商品是否还包含危险货物的属性
  1385. if (entity.getProductCharCode() != null && !"".equals(entity.getProductCharCode())) {
  1386. if (codeTs[10] != null) {
  1387. entity.setGoodsType("1,2,3");
  1388. } else {
  1389. entity.setGoodsType("1");
  1390. }
  1391. } else {
  1392. //货物属性为空时
  1393. //出口
  1394. if (ieFlag.equals("0")) {
  1395. if (codeTs[16] != null) {
  1396. //syncChemicalsCiq只可能是包含了危化品,因为这个表的数据就是查询的系统中危险品模块里用户已经维护的包含了危化品的数据
  1397. Object[] obj = (Object[]) dao.getObjectBySql("select * from iedg_sync_chemicals_ciq where CIQ_CODE = ?", (String) codeTs[16]);
  1398. if (obj != null) {
  1399. if (codeTs[16] != null) {
  1400. entity.setGoodsType("1,2,3");
  1401. } else {
  1402. entity.setGoodsType("1");
  1403. }
  1404. } else {
  1405. entity.setGoodsType("2");
  1406. }
  1407. } else {
  1408. entity.setGoodsType("2");
  1409. }
  1410. } else {
  1411. //进口
  1412. entity.setGoodsType("2");
  1413. }
  1414. }
  1415. entity.setId(dao.getGuidStringBySql());
  1416. entryListRepository.save(entity);
  1417. }
  1418. }
  1419. codeListSb.delete(0, codeListSb.length());
  1420. }
  1421. x++;
  1422. }
  1423. } catch (Exception ex) {
  1424. // 主键可能因为多次结关跨天,导致新纪录主键重复
  1425. logger.error("保存危险品新维度一体化通关中间记录失败,重新保存");
  1426. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  1427. }
  1428. tmpMap1.clear();
  1429. tmpMap2.clear();
  1430. tmpMap5.clear();
  1431. tmpMap9.clear();
  1432. tmpMap10.clear();
  1433. tmpMap12.clear();
  1434. tmpMap11.clear();
  1435. sb.delete(0, sb.length());
  1436. }
  1437. i++;
  1438. }
  1439. }
  1440. }
  1441. }
  1442. public void kaqgDeclMain(Date statBegin, Date statEnd, List<String> code, List<String> allCode) {
  1443. Map<String, Object[]> tmpMap1 = new HashMap<String, Object[]>();
  1444. Map<String, Date[]> tmpMap2 = new HashMap<String, Date[]>();
  1445. Map<String, Date> tmpMap9 = new HashMap<String, Date>();
  1446. Map<String, Object[]> tmpMap10 = new HashMap<String, Object[]>();
  1447. Map<String, Object[]> tmpMap11 = new HashMap<String, Object[]>();
  1448. Map<String, Date> tmpMap12 = new HashMap<String, Date>();
  1449. if (code != null && code.size() > 0) {
  1450. List<String> entryH2018IdList = new ArrayList<>();//存放所有
  1451. StringBuilder codeSb = new StringBuilder();
  1452. int j = 1;
  1453. for (Iterator itera = code.iterator(); itera.hasNext(); ) {
  1454. String ciqCode = (String) itera.next();
  1455. codeSb.append("'").append(ciqCode).append("',");
  1456. if ((j % 600 == 0 || !itera.hasNext()) && codeSb.length() > 0) {
  1457. codeSb.deleteCharAt(codeSb.length() - 1);
  1458. String codes = codeSb.toString();
  1459. //存在后续查出的报关单前面已经有,所以需要处理去重
  1460. //出口按编码、ungid不为空和货物属性包含31或32
  1461. //进口按ungid不为空或货物属性包含31或32
  1462. String sql = "select distinct(d.ENTRY_ID) from ENTRY_HEAD d, ENTRY_WORKFLOW w, ENTRY_LIST l where " +
  1463. "d.ENTRY_ID like '47%' and (substr(d.EDI_REMARK,7,1)!='C' or substr(d.EDI_REMARK,15,1)!='1') " +
  1464. "and (substr(d.EDI_REMARK,17,1) not in ('a','c','C','d','e','f') or " +
  1465. "(substr(d.EDI_REMARK,17,1) = 'C' and substr(d.EDI_REMARK,8,1) != 'G')) and substr(d.I_E_PORT,0,2)=substr(d.DECL_PORT,0,2) " +
  1466. "and d.ENTRY_ID = w.ENTRY_ID and d.ENTRY_ID = l.ENTRY_ID and w.STEP_ID = '80000000' and w.CREATE_DATE >= ? and w.CREATE_DATE < ? " +
  1467. "and ((d.I_E_FLAG = 'E' and (l.IQ_CODE in (" + codes + ") or l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  1468. "or l.PRODUCT_CHAR_CODE like '%32%')) or (d.I_E_FLAG = 'I' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' " +
  1469. "or l.PRODUCT_CHAR_CODE like '%32%'))) order by d.ENTRY_ID;";
  1470. List<String> entryIdList = (List<String>) h2018Dao.getQueryBySql(sql, statBegin, statEnd);
  1471. entryH2018IdList.addAll(entryIdList);
  1472. codeSb.delete(0, codeSb.length());
  1473. }
  1474. j++;
  1475. }
  1476. //用JDK1.8 Stream中对List进行去重:list.stream().distinct();
  1477. entryH2018IdList = (List) entryH2018IdList.stream().distinct().collect(Collectors.toList());
  1478. if (entryH2018IdList != null && entryH2018IdList.size() > 0) {
  1479. StringBuilder sb = new StringBuilder();
  1480. int i = 1;
  1481. for (Iterator iterator = entryH2018IdList.iterator(); iterator.hasNext(); ) {
  1482. String id = (String) iterator.next();
  1483. sb.append("'").append(id).append("',");
  1484. if ((i % 300 == 0 || !iterator.hasNext()) && sb.length() > 0) {
  1485. List<String> impIdList2 = new ArrayList<String>();//20191210 进口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_LIST_NEW查到精确I_E_DATE
  1486. List<String> impIdList3 = new ArrayList<String>();//20211210 出口水运(新舱单部分)、空运可以从新舱单系统MANIFEST_MONITOR_NEW查到精确ARRIVAL_DATE
  1487. sb.deleteCharAt(sb.length() - 1);
  1488. String ids = sb.toString();
  1489. String entryIds = sb.toString();
  1490. String sql = "select h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT,CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY,"
  1491. + " TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),nvl(count(c.ENTRY_ID),0),substr(EDI_REMARK,53,1) "
  1492. + "from ENTRY_HEAD h left join `g_whdb_zmqd`.h18c_ENTRY_CONTAINER c on h.ENTRY_ID = c.ENTRY_ID where h.ENTRY_ID in ("
  1493. + ids + ") group by h.ENTRY_ID, I_E_DATE, I_E_PORT, I_E_FLAG, TRAF_MODE, D_DATE, DECL_PORT, CONSIGN_SCC, CONSIGN_CODE, CONSIGN_NAME, FRN_I_E_COUNTRY," +
  1494. "TRADE_MODE, nvl(GROSS_WT,0), nvl(NET_WT,0), substr(EDI_REMARK,11,1), substr(EDI_REMARK,41,1),substr(EDI_REMARK,53,1);";
  1495. List<Object[]> list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1496. for (Object[] d : list) {
  1497. String idH = (String) d[0];
  1498. String iEFlag = (String) d[3];
  1499. String traMode = (String) d[4];
  1500. if ("I".equals(iEFlag)) {
  1501. if ("2".equals(traMode) || "5".equals(traMode)) {
  1502. impIdList2.add(idH);
  1503. }
  1504. } else {
  1505. if ("2".equals(traMode) || "5".equals(traMode)) {
  1506. impIdList3.add(idH);
  1507. }
  1508. }
  1509. tmpMap1.put((String) d[0],
  1510. new Object[]{(Date) d[1], (String) d[2], (String) d[3], (String) d[4], (Date) d[5], (String) d[6], (String) d[7], (String) d[8], (String) d[9], (String) d[10],
  1511. (String) d[11], (BigDecimal) d[12], (BigDecimal) d[13], (String) d[14], (String) d[15], (BigInteger) d[16], (String) d[17]});
  1512. }
  1513. sql = "select h.ENTRY_ID,(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='10000000' AND h.ENTRY_ID = a.ENTRY_ID) as authDate,"
  1514. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW a where STEP_ID='80000000' AND h.ENTRY_ID = a.ENTRY_ID) as releaseDate,"
  1515. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='81000000' AND h.ENTRY_ID = b.ENTRY_ID) as preReleaseDate,"
  1516. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='70000000' AND h.ENTRY_ID = c.ENTRY_ID) as certRlsDate,"
  1517. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='82000000' AND h.ENTRY_ID = c.ENTRY_ID) as passDate,"
  1518. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='30000000' AND h.ENTRY_ID = c.ENTRY_ID) as orderDate,"
  1519. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='30000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as orderReceiveDate,"
  1520. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW c where STEP_ID='00200000' AND h.ENTRY_ID = c.ENTRY_ID) as compEleDate,"
  1521. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='33000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%' and PROC_ER like '47%') as profVerifyDate, "
  1522. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='00000000' AND h.ENTRY_ID = b.ENTRY_ID) as eleDeclDate, "
  1523. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%M%') as assessStartDate, "
  1524. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID='26000000' AND h.ENTRY_ID = b.ENTRY_ID AND PROC_RESULT like '%G%') as assessEndDate,"
  1525. + "(select max(CREATE_DATE) from ENTRY_WORKFLOW b where STEP_ID in ('10000000','10200000','20000000') AND h.ENTRY_ID = b.ENTRY_ID and substr(b.status_code,4,1) = 5 and b.proc_result like '%E%') as refundDate "
  1526. + "from ENTRY_HEAD h where h.ENTRY_ID in (" + ids
  1527. + ") group by ENTRY_ID;";
  1528. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1529. for (Object[] d : list) {
  1530. tmpMap2.put((String) d[0], new Date[]{(Date) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (Date) d[5], (Date) d[6], (Date) d[7], (Date) d[8], (Date) d[9],
  1531. (Date) d[10], (Date) d[11], (Date) d[12], (Date) d[13]});
  1532. }
  1533. sql = "select h.ENTRY_ID,substr(h.CHECK_REQUEST_TOTAL,-1,1),h.CREATE_TIME,h.MAN_CHK_TIME_START,h.MAN_CHK_TIME_END,MAN_PROC_RESULT,MAN_PROC_IDEA,CHECK_CUSTOMS_CODE "
  1534. + "from CI_CHECK_MAN_WORK_HEAD h where h.CHECK_STATE = 'M' and h.MODIFY_TIME = "
  1535. + "(select max(d.MODIFY_TIME) from CI_CHECK_MAN_WORK_HEAD d where d.ID = h.ID) and h.ENTRY_ID in(" + ids + ") ;";
  1536. list = (List<Object[]>) inspDao.getQueryBySql(sql);
  1537. for (Object[] d : list) {
  1538. tmpMap11.put((String) d[0], new Object[]{(String) d[1], (Date) d[2], (Date) d[3], (Date) d[4], (String) d[5], (String) d[6], (String) d[7]});
  1539. }
  1540. //货运量毛重、净重、货运值人民币、美元、集装箱数量GROUP_CONCAT方法放在此处当传一个报关单id并且没有随附单证时会报错,所以加上nvl()
  1541. sql = "select h.ENTRY_ID,sum(nvl(l.RMB_PRICE,0)),sum(nvl(l.USD_PRICE,0)),h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,"
  1542. + "h.OWNER_CODE,h.OWNER_NAME,FRN_CONSIGN_CODE,FRN_CONSIGN_NAME from ENTRY_HEAD h left join ENTRY_LIST l on h.ENTRY_ID=l.ENTRY_ID "
  1543. + "where h.ENTRY_ID in("
  1544. + ids + ") group by h.ENTRY_ID,h.AGENT_CODE,h.AGENT_NAME,h.NOTE_S,h.OWNER_CODE,h.OWNER_NAME,FRN_CONSIGN_CODE,FRN_CONSIGN_NAME;";
  1545. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1546. for (Object[] d : list) {
  1547. tmpMap10.put((String) d[0], new Object[]{(BigDecimal) d[1], (BigDecimal) d[2], (String) d[3], (String) d[4], (String) d[5], (String) d[6], (String) d[7],
  1548. (String) d[8], (String) d[9]});
  1549. }
  1550. if (impIdList2.size() > 0) {
  1551. sb.delete(0, sb.length());
  1552. for (String impId : impIdList2) {
  1553. sb.append("'").append(impId).append("',");
  1554. }
  1555. sb.deleteCharAt(sb.length() - 1);
  1556. ids = sb.toString();
  1557. // 进口新舱单水运、空运的I_E_DATE精准值由MANIFEST_LIST_NEW的REAL_ARRIVE_DATE给定
  1558. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号
  1559. sql = "select a.ENTRY_ID, b.REAL_ARRIVE_DATE from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.MANIFEST_LIST_NEW b where a.ENTRY_ID in ("
  1560. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE and to_char(a.I_E_DATE,'yyyyMMdd') = to_char(b.REAL_ARRIVE_DATE,'yyyyMMdd')";
  1561. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1562. for (Object[] d : list) {
  1563. String entryId = (String) d[0];
  1564. tmpMap9.put(entryId, (Date) d[1]);
  1565. }
  1566. impIdList2.clear();
  1567. }
  1568. //出口舱单
  1569. if (impIdList3.size() > 0) {
  1570. sb.delete(0, sb.length());
  1571. for (String impId : impIdList3) {
  1572. sb.append("'").append(impId).append("',");
  1573. }
  1574. sb.deleteCharAt(sb.length() - 1);
  1575. ids = sb.toString();
  1576. // 出口新舱单水运、空运可能提前但航班晚到,无法用时间去精准定位哪一条会卸载很多次,精准值由MANIFEST_MONITOR_NEW的ARRIVAL_DATE给定
  1577. // 注意:提运单号会被重用,当天的也可能有不同报关单使用了相同的提运单号,ARRIVAL_DATE为00:00:00的赋值12:00:00
  1578. //20210508舱单只获取和武汉海关有关的数据进行时间赋值,所以a.I_E_PORT = b.CUSTOMS_CODE
  1579. sql = "select a.ENTRY_ID, min(b.ARRIVAL_DATE) from ENTRY_HEAD a, `g_whdb_h2000_ims_recv`.MANIFEST_MONITOR_NEW b where a.ENTRY_ID in ("
  1580. + ids + ") and a.BILL_NO = b.BILL_NO and a.I_E_PORT = b.CUSTOMS_CODE group by a.ENTRY_ID";
  1581. list = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1582. for (Object[] d : list) {
  1583. String entryId = (String) d[0];
  1584. tmpMap12.put(entryId, (Date) d[1]);
  1585. }
  1586. impIdList3.clear();
  1587. }
  1588. for (Map.Entry<String, Object[]> d : tmpMap1.entrySet()) {
  1589. String entryId = d.getKey();
  1590. Object[] v = d.getValue();
  1591. Date ieDate = (Date) v[0];// 货物运抵时间
  1592. String iePort = (String) v[1];
  1593. String ieFlag = (String) v[2];
  1594. String trafMode = (String) v[3];
  1595. Date declDate = (Date) v[4];// 申报时间
  1596. String declPort = (String) v[5];// 申报口岸
  1597. String consignScc = (String) v[6];
  1598. String consignCode = (String) v[7];
  1599. String consignName = (String) v[8];
  1600. String tradeCountry = (String) v[9];
  1601. String tradeMode = (String) v[10];
  1602. BigDecimal grossWt = (BigDecimal) v[11];//毛重
  1603. BigDecimal netWt = (BigDecimal) v[12];//净重
  1604. String advanceDecl = (String) v[13];//判断是否是提前申报
  1605. //两步申报都下发到了h2018所以使用00200000节点判断只属于两步申报其中一种类型,
  1606. //应当使用edi_remark41位判断是否有值(edi_remark41值为1,2,3均为两步申报)
  1607. String twoStep = (String) v[14];//判断是否是两步申报
  1608. //2018存在twoStepValue截取出来值为' '情况,需要单独处理
  1609. String twoStepDecl = (" ").equals(twoStep) ? "" : twoStep;
  1610. BigInteger container = (BigInteger) v[15];// 集装箱数量
  1611. String newTwoStep = (String) v[16];//判断是否是新两步申报
  1612. Date[] all = tmpMap2.get(entryId);
  1613. Date authDate = null;
  1614. Date releaseDate = null;
  1615. Date preReleaseDate = null;
  1616. Date certRlsDate = null;
  1617. Date passDate = null;
  1618. Date orderDate = null;
  1619. Date orderReceiveDate = null;
  1620. Date compEleDate = null;
  1621. Date profVerifyDate = null;
  1622. Date eleDeclDate = null;
  1623. Date assessStartDate = null;
  1624. Date assessEndDate = null;
  1625. Date refundDate = null;
  1626. if (all != null) {
  1627. authDate = all[0];// 10审单受理时间
  1628. releaseDate = all[1];// 80结关时间
  1629. preReleaseDate = all[2];// 81担保放行时间
  1630. certRlsDate = all[3];// 70单证放行时间
  1631. passDate = all[4];// 82000000通道验放
  1632. orderDate = all[5];// 30000000现场接单
  1633. orderReceiveDate = all[6];// 30现场接单时间
  1634. compEleDate = all[7];// 00200000完整申报电子申报时间
  1635. profVerifyDate = all[8];// 33专业审证单核时间
  1636. eleDeclDate = all[9];// 00电子申报时间
  1637. assessStartDate = all[10];// 26排查处置/现场验估时间
  1638. assessEndDate = all[11];// 26验估处置完毕时间
  1639. refundDate = all[12];// 退单时间
  1640. }
  1641. Date realArriveDate = tmpMap9.get(entryId);
  1642. Object[] obj = tmpMap10.get(entryId);
  1643. BigDecimal rmbPrice = zero;
  1644. BigDecimal usdPrice = zero;
  1645. String agentCode = null;
  1646. String agentName = null;
  1647. String noteS = null;
  1648. String ownerCode = null;
  1649. String ownerName = null;
  1650. String frnConsignCode = null;
  1651. String frnConsignName = null;
  1652. if (obj != null) {
  1653. rmbPrice = (BigDecimal) obj[0];//人民币
  1654. usdPrice = (BigDecimal) obj[1];//美元
  1655. agentCode = (String) obj[2];//申报单位代码
  1656. agentName = (String) obj[3];//申报单位名称
  1657. noteS = (String) obj[4];//备注
  1658. ownerCode = (String) obj[7];//生产销售单位代码
  1659. ownerName = (String) obj[8];//生产销售单位名称
  1660. frnConsignCode = (String) obj[7];//生产销售单位代码
  1661. frnConsignName = (String) obj[8];//生产销售单位名称
  1662. }
  1663. Object[] man = tmpMap11.get(entryId);
  1664. String checkFlag = null;
  1665. Date manCreateTime = null;
  1666. Date manChkTimeStart = null;
  1667. Date manChkTimeEnd = null;
  1668. String manProcResult = null;
  1669. String manProcIdea = null;
  1670. String checkCustomsCode = null;
  1671. if (man != null) {
  1672. checkFlag = (String) man[0];//是否查验送检
  1673. manCreateTime = (Date) man[1];//指令下达时间
  1674. manChkTimeStart = (Date) man[2];//查验开始时间
  1675. manChkTimeEnd = (Date) man[3];//查验结束时间
  1676. manProcResult = (String) man[4];//处理结果
  1677. manProcIdea = (String) man[5];//处理意见
  1678. checkCustomsCode = (String) man[6];//查验关区
  1679. }
  1680. if ("I".equals(ieFlag)) {
  1681. if (realArriveDate != null) {
  1682. ieDate = realArriveDate;
  1683. } else {
  1684. if (ieDate != null) {
  1685. // 由于报关单表中I_E_DATE精度不够,需要做(非精准)修正(用户给的建议应该是错的,模糊处理下好了,时分为0的设置为12点)
  1686. if ("I".equals(ieFlag)) {// 入境
  1687. String ieDateStr = fullSdf.format(ieDate);
  1688. if (ieDateStr.endsWith("00:00:00")) {
  1689. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  1690. try {
  1691. ieDate = fullSdf.parse(ieDateStr);
  1692. } catch (ParseException e1) {
  1693. // TODO Auto-generated catch block
  1694. e1.printStackTrace();
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }
  1700. } else {
  1701. realArriveDate = tmpMap12.get(entryId);
  1702. //ARRIVAL_DATE为00:00:00时赋值12:00:00
  1703. if (realArriveDate != null) {
  1704. String ieDateStr = fullSdf.format(realArriveDate);
  1705. if (ieDateStr.endsWith("00:00:00")) {
  1706. ieDateStr = ieDateStr.substring(0, 11) + IE_DATE_ADAPT;
  1707. try {
  1708. realArriveDate = fullSdf.parse(ieDateStr);
  1709. } catch (ParseException e1) {
  1710. // TODO Auto-generated catch block
  1711. e1.printStackTrace();
  1712. }
  1713. }
  1714. }
  1715. }
  1716. EntryHead e = new EntryHead();
  1717. e.setEntryId(entryId);
  1718. e.setAcceptDate(authDate != null ? authDate : orderDate);
  1719. e.setCertRlsDate(certRlsDate);// 70单证放行时间
  1720. e.setReleaseDate(releaseDate);//80
  1721. e.setPreReleaseDate(preReleaseDate);// 81时间
  1722. e.setPassMode("2");// 一体化通关
  1723. e.setDeclPort(declPort);
  1724. e.setIePort(iePort);
  1725. e.setIeDate(ieDate);
  1726. e.setDeclDate(declDate);
  1727. e.setIeFlag(ieFlag);
  1728. e.setTrafMode(trafMode);
  1729. e.setConsignScc(consignScc);
  1730. e.setConsignCode(consignCode);
  1731. e.setConsignName(consignName);
  1732. e.setTradeCountry(tradeCountry);
  1733. e.setTradeMode(tradeMode);
  1734. e.setOrderReceiveDate(orderReceiveDate);//30接单时间
  1735. e.setCompEleDate(compEleDate);// 00200000完整申报电子申报时间
  1736. e.setProfVerifyFlag(profVerifyDate != null ? "1" : "0");
  1737. e.setNewTwoStepFlag((null != newTwoStep && !"".equals(newTwoStep) && newTwoStep.equals("1")) ? "1" : "0");
  1738. e.setEleDeclDate(eleDeclDate);
  1739. e.setAssessStartDate(assessStartDate);
  1740. e.setAssessEndDate(assessEndDate);
  1741. e.setRefundDate(refundDate);
  1742. e.setRefundFlag(refundDate != null ? "1" : "0");
  1743. e.setCheckFlag(manCreateTime != null ? "1" : "0");
  1744. long orderReceiveCost = 0L;//接单耗时:30000000-10000000
  1745. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1746. if (orderReceiveDate != null && (authDate != null || orderDate != null)) {
  1747. Long time = authDate != null ? authDate.getTime() : orderDate.getTime();
  1748. orderReceiveCost = (orderReceiveDate.getTime() - time) / 1000;
  1749. e.setOrderReceiveCost(orderReceiveCost);
  1750. } else {
  1751. e.setOrderReceiveCost(null);
  1752. }
  1753. long hgCost = 0L;
  1754. long totalCost = 0L;
  1755. //edi_remark11位为T表示提前申报
  1756. if ("T".equals(advanceDecl)) {
  1757. e.setDeclAdvanceFlag("1");
  1758. } else {
  1759. e.setDeclAdvanceFlag("0");
  1760. }
  1761. if ("I".equals(ieFlag)) {// 入境
  1762. /**根据综合处杨科提出的修改意见,这里将原来'电脑审单时间早于货物运抵时间'改成'申报时间早于货物运抵时间'的为提前申报*/
  1763. if (ieDate != null) {
  1764. if (declDate.before(ieDate)) {
  1765. authDate = ieDate;
  1766. // e.setDeclAdvanceFlag("1");
  1767. } else {
  1768. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1769. if (authDate == null) {
  1770. authDate = orderDate;
  1771. }
  1772. }
  1773. }
  1774. if (e.getPreReleaseDate() == null && e.getReleaseDate() != null) {
  1775. if (authDate != null) {
  1776. hgCost = (e.getReleaseDate().getTime() - authDate.getTime()) / 1000;
  1777. }
  1778. if (ieDate != null) {
  1779. totalCost = (e.getReleaseDate().getTime() - ieDate.getTime()) / 1000;
  1780. }
  1781. } else if (e.getPreReleaseDate() != null) {
  1782. if (authDate != null) {
  1783. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1784. }
  1785. if (ieDate != null) {
  1786. totalCost = (e.getPreReleaseDate().getTime() - ieDate.getTime()) / 1000;
  1787. }
  1788. }
  1789. if (hgCost < 0) {
  1790. hgCost = 0L;
  1791. }
  1792. if (totalCost < 0) {
  1793. totalCost = hgCost;
  1794. }
  1795. //新组合查询用00-货物运抵,组合查询用10-货物运抵
  1796. e.setBeforeDeclCost((eleDeclDate.getTime() - e.getIeDate().getTime()) / 1000);// 申报前准备时间
  1797. if (e.getBeforeDeclCost() < 0) {
  1798. e.setBeforeDeclCost(0L);
  1799. }
  1800. } else {// 出境 海关通关时间=70/81之间较早的时间-受理时间
  1801. // 20191211 出口口岸清关、一体化:公路取BINDING_ROAD_TRANSPORT表GEN_DATE;铁路、邮路运输的整体通关时长=海关通关时长
  1802. //20210423新增处理10节点无时间时的赋值,避免程序报错
  1803. if (authDate == null) {
  1804. authDate = orderDate;
  1805. }
  1806. if (realArriveDate != null) {
  1807. //20211209出口舱单有时间赋值给出口货物运抵时间否则使用10审单时间,同时进行计算
  1808. e.setExInPortDate(realArriveDate);
  1809. } else {
  1810. // 取不到数据的统一将货物入境时间设置为受理时间
  1811. if ("3".equals(trafMode) || "6".equals(trafMode) || "9".equals(trafMode)) {// 其它运输方式也假设归为一类
  1812. e.setExInPortDate(authDate);
  1813. } else if ("4".equals(trafMode)) {//TODO 公路:暂时取不到数据
  1814. e.setExInPortDate(authDate);
  1815. } else {
  1816. e.setExInPortDate(authDate);// TODO 出口水运、空运通关时长第一个时间点数据来源还未下发,先临时赋值
  1817. }
  1818. }
  1819. if (e.getCertRlsDate() == null) {
  1820. if (e.getPreReleaseDate() != null) {
  1821. if (authDate != null) {
  1822. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1823. }
  1824. totalCost = e.getExInPortDate() != null
  1825. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1826. : hgCost;
  1827. }
  1828. } else {
  1829. if (e.getPreReleaseDate() != null) {
  1830. if (e.getCertRlsDate().before(e.getPreReleaseDate())) {
  1831. if (authDate != null) {
  1832. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  1833. }
  1834. totalCost = e.getExInPortDate() != null
  1835. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1836. : hgCost;
  1837. } else {
  1838. if (authDate != null) {
  1839. hgCost = (e.getPreReleaseDate().getTime() - authDate.getTime()) / 1000;
  1840. }
  1841. totalCost = e.getExInPortDate() != null
  1842. ? ((e.getPreReleaseDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1843. : hgCost;
  1844. }
  1845. } else {
  1846. if (authDate != null) {
  1847. hgCost = (e.getCertRlsDate().getTime() - authDate.getTime()) / 1000;
  1848. }
  1849. totalCost = e.getExInPortDate() != null
  1850. ? ((e.getCertRlsDate().getTime() - e.getExInPortDate().getTime()) / 1000)
  1851. : hgCost;
  1852. }
  1853. }
  1854. e.setBeforeDeclCost(e.getExInPortDate() != null
  1855. ? ((eleDeclDate.getTime() - e.getExInPortDate().getTime()) / 1000)
  1856. : 0L);// 申报前准备时间
  1857. if (e.getBeforeDeclCost() < 0) {
  1858. e.setBeforeDeclCost(0L);
  1859. }
  1860. }
  1861. e.setMainStatus("1");
  1862. e.setCuCost(hgCost);// 海关通关时间(秒)
  1863. e.setTotalCost(totalCost);// 总体通关时间
  1864. e.setGrossWt(grossWt);//净重
  1865. e.setNetWt(netWt);//毛重
  1866. e.setRmbPrice(rmbPrice);//人民币
  1867. e.setUsdPrice(usdPrice);//美元
  1868. e.setContainer(container);//集装箱数量
  1869. e.setAgentCode(agentCode);//申报单位代码
  1870. e.setAgentName(agentName);//申报单位名称
  1871. e.setNoteS(noteS);//备注
  1872. e.setOwnerCode(ownerCode);//生产销售单位代码
  1873. e.setOwnerName(ownerName);//生产销售单位名称
  1874. e.setFrnConsignCode(frnConsignCode);
  1875. e.setFrnConsignName(frnConsignName);
  1876. //报关模式
  1877. String mode = null;
  1878. //部分订单既是提前申报又是两步申报,不是两步和提前申报的单子均为一般申报,twoStepDecl:0或者空格:代表一分模式
  1879. if ("1".equals(e.getDeclAdvanceFlag()) && (null == twoStepDecl || "".equals(twoStepDecl) || "0".equals(twoStepDecl))) {
  1880. mode = "3";
  1881. } else if ("1".equals(e.getDeclAdvanceFlag()) && (null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  1882. mode = "2,3";
  1883. } else if ((null != twoStepDecl && "".equals(twoStepDecl)) && !"0".equals(twoStepDecl)) {
  1884. mode = "2";
  1885. } else {
  1886. mode = "1";
  1887. }
  1888. e.setDeclMode(mode);//报关模式
  1889. //70000000、80000000、81000000、82000000均为空则表示未放行
  1890. if (preReleaseDate == null && certRlsDate == null && releaseDate == null && passDate == null) {
  1891. e.setDeclStatus("1");
  1892. } else if (releaseDate != null) {
  1893. //80表示已结关
  1894. e.setDeclStatus("3");
  1895. } else {
  1896. e.setDeclStatus("2");
  1897. }
  1898. e.setManCreateTime(manCreateTime);//指令下达时间
  1899. e.setManChkTimeStart(manChkTimeStart);//查验开始时间
  1900. e.setManChkTimeEnd(manChkTimeEnd);//查验结束时间
  1901. e.setManProcResult(manProcResult);
  1902. e.setManProcIdea(manProcIdea);
  1903. e.setCheckCustomsCode(checkCustomsCode);
  1904. dao.executeUpdate("delete from WXJY_ENTRY_HEAD where ENTRY_ID = ?", entryId);
  1905. entryHeadRepository.save(e);
  1906. }
  1907. //ciqCode存在超过600个情况,每个报关单每次查都拼接重复工作太多,所以提出来
  1908. //先删除这些报关单下的所有商品信息
  1909. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  1910. try {
  1911. StringBuilder codeListSb = new StringBuilder();
  1912. int x = 1;
  1913. for (Iterator it = allCode.iterator(); it.hasNext(); ) {
  1914. String iqCode = (String) it.next();
  1915. codeListSb.append("'").append(iqCode).append("',");
  1916. if ((x % 600 == 0 || !it.hasNext()) && codeListSb.length() > 0) {
  1917. codeListSb.deleteCharAt(codeListSb.length() - 1);
  1918. String iqCodes = codeListSb.toString();
  1919. //报关单表体,报关单第九位0=出口1=进口
  1920. sql = "select ENTRY_ID,G_NO,CODE_TS,G_NAME,QTY_1,RMB_PRICE,USD_PRICE,G_MODEL,G_CERT_FLAG," +
  1921. "(select max(a.CREATE_DATE) from ENTRY_WORKFLOW a where a.STEP_ID='80000000' AND l.ENTRY_ID = a.ENTRY_ID) as RELEASE_DATE," +
  1922. "UNGID,UNG_FLAG,UNG_MODEL,UNG_CLASSIFY,UNG_G_NAME,PRODUCT_CHAR_CODE,IQ_CODE " +
  1923. "from ENTRY_LIST l where l.ENTRY_ID in (" + entryIds + ") " +
  1924. "and ((substr(l.ENTRY_ID,9,1) ='0' and (l.IQ_CODE in (" + iqCodes + ") or l.UNGID is not null " +
  1925. "or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')) or " +
  1926. "(substr(l.ENTRY_ID,9,1) = '1' and (l.UNGID is not null or l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%32%')));";
  1927. List<Object[]> codeTsList = (List<Object[]>) h2018Dao.getQueryBySql(sql);
  1928. if (null != codeTsList && codeTsList.size() > 0) {
  1929. //由于新组合查询不设定某个固定节点更新数据,会存在相同报关单在后面更新流程节点时间,所以先从中间表查出数据进行更新
  1930. //会存在商品金额为空的情况,如果只有一条商品并商品为空则报关单头要删除
  1931. EntryList entity = null;
  1932. for (Object[] codeTs : codeTsList) {//将根据报关单编号查询到的商品编号及报关单号添加到KPI_ENTRY_HEAD_NEW_COPY表里
  1933. entity = new EntryList();
  1934. entity.setEntryId(codeTs[0] != null ? codeTs[0].toString() : "");
  1935. entity.setGNo(codeTs[1] != null ? (BigDecimal) codeTs[1] : new BigDecimal(0));
  1936. entity.setCodeTs(codeTs[2] != null ? codeTs[2].toString() : "");
  1937. entity.setGName(codeTs[3] != null ? codeTs[3].toString() : "");
  1938. entity.setQty1(codeTs[4] != null ? (BigDecimal) codeTs[4] : new BigDecimal(0));
  1939. entity.setRmbPrice(codeTs[5] != null ? (BigDecimal) codeTs[5] : new BigDecimal(0));
  1940. entity.setUsdPrice(codeTs[6] != null ? (BigDecimal) codeTs[6] : new BigDecimal(0));
  1941. entity.setGModel(codeTs[7] != null ? codeTs[7].toString() : "");
  1942. entity.setGCertFlag(codeTs[8] != null ? codeTs[8].toString() : "");
  1943. entity.setReleaseDate(codeTs[9] != null ? (Date) codeTs[9] : null);
  1944. entity.setCodeTsShort(codeTs[2] != null ? codeTs[2].toString().substring(0, 6) : "");
  1945. entity.setUngid(codeTs[10] != null ? codeTs[10].toString() : "");
  1946. entity.setUngFlag(codeTs[11] != null ? codeTs[11].toString() : "");
  1947. entity.setUngModel(codeTs[12] != null ? codeTs[12].toString() : "");
  1948. entity.setUngClassify(codeTs[13] != null ? codeTs[13].toString() : "");
  1949. entity.setUngGName(codeTs[14] != null ? codeTs[14].toString() : "");
  1950. entity.setIqCode(codeTs[16] != null ? codeTs[16].toString() : "");
  1951. //货物属性,判断货物属性是否是31/散装危险化学品,32/件装危险化学品
  1952. String goods_attr = "";
  1953. if (codeTs[15] != null) {
  1954. goods_attr = (String) codeTs[15];
  1955. if (goods_attr.contains("31")) {
  1956. goods_attr = "31";
  1957. } else if (goods_attr.contains("32")) {
  1958. goods_attr = "32";
  1959. } else {
  1960. goods_attr = "";
  1961. }
  1962. }
  1963. entity.setProductCharCode(goods_attr);
  1964. //查出的数据可能存在ciqCode或者UNGID为空的情况,报关单第九位0=出口1=进口
  1965. //出口按ciq编码、ungid不为空和货物属性包含31或32
  1966. //进口按ungid不为空或货物属性
  1967. String ieFlag = codeTs[0] != null ? codeTs[0].toString().substring(8, 9) : "";
  1968. //货物属性为不空时可以初步判定该商品是危化品,接下来只需判断该商品是否还包含危险货物的属性
  1969. if (entity.getProductCharCode() != null && !"".equals(entity.getProductCharCode())) {
  1970. if (codeTs[10] != null) {
  1971. entity.setGoodsType("1,2,3");
  1972. } else {
  1973. entity.setGoodsType("1");
  1974. }
  1975. } else {
  1976. //货物属性为空时
  1977. //出口
  1978. if (ieFlag.equals("0")) {
  1979. if (codeTs[16] != null) {
  1980. //syncChemicalsCiq只可能是包含了危化品,因为这个表的数据就是查询的系统中危险品模块里用户已经维护的包含了危化品的数据
  1981. Object[] obj = (Object[]) dao.getObjectBySql("select * from iedg_sync_chemicals_ciq where CIQ_CODE = ?", (String) codeTs[16]);
  1982. if (obj != null) {
  1983. if (codeTs[16] != null) {
  1984. entity.setGoodsType("1,2,3");
  1985. } else {
  1986. entity.setGoodsType("1");
  1987. }
  1988. } else {
  1989. entity.setGoodsType("2");
  1990. }
  1991. } else {
  1992. entity.setGoodsType("2");
  1993. }
  1994. } else {
  1995. //进口
  1996. entity.setGoodsType("2");
  1997. }
  1998. }
  1999. entity.setId(dao.getGuidStringBySql());
  2000. entryListRepository.save(entity);
  2001. }
  2002. }
  2003. codeListSb.delete(0, codeListSb.length());
  2004. }
  2005. x++;
  2006. }
  2007. } catch (Exception ex) {
  2008. // 主键可能因为多次结关跨天,导致新纪录主键重复
  2009. logger.error("保存危险品新维度一体化通关中间记录失败,重新保存");
  2010. dao.executeUpdate("delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + entryIds + ")");
  2011. }
  2012. tmpMap1.clear();
  2013. tmpMap2.clear();
  2014. tmpMap9.clear();
  2015. tmpMap10.clear();
  2016. tmpMap12.clear();
  2017. tmpMap11.clear();
  2018. sb.delete(0, sb.length());
  2019. }
  2020. i++;
  2021. }
  2022. }
  2023. }
  2024. }
  2025. public void monthlyDataMaintance(String dataPeriod, Date statBegin, Date statEnd) {
  2026. try {
  2027. // 查询当月转关单两个时间不为空的入境转关单信息
  2028. List<Object[]> entryList = (List<Object[]>) dao.getQueryBySql("select DECL_PORT,i_e_flag,CHECK_FLAG,ORDER_RECEIVE_DATE,TOTAL_COST,CU_COST from WXJY_ENTRY_HEAD where RELEASE_DATE >= ? and RELEASE_DATE < ?",
  2029. statBegin, statEnd);
  2030. // 维护CustomMonthlyStat 表1
  2031. mainCustomMonthlyStat(dataPeriod, statBegin, statEnd, entryList);
  2032. } catch (Exception e) {
  2033. logger.error(dataPeriod + " 月通关时长月度统计中间数据维护错误:", e);
  2034. }
  2035. }
  2036. private void mainCustomMonthlyStat(String dataPeriod, Date statBegin, Date statEnd,
  2037. List<Object[]> entryList) {
  2038. Object[] mainRcd = (Object[]) dao.getObjectBySql(
  2039. "select * from WXJY_MID_D_M_STATUS where DATA_TYPE = ? and STAT_PERIOD = ?", CustomMonthlyStat.class.getSimpleName(), dataPeriod);
  2040. if (mainRcd == null) {
  2041. dao.executeUpdate("delete from WXJY_CUSTOM_M_STAT where month = ?", dataPeriod);// 以往维护过程中可能出错生成了部分数据
  2042. dao.executeUpdate("delete from WXJY_CUSTOM_M_STAT_F where month = ?", dataPeriod);
  2043. Set<String> customCodeSet = new HashSet<String>();
  2044. Map<String, Integer> impDeclCountMap = new HashMap<String, Integer>();
  2045. Map<String, Integer> impManDeclCountMap = new HashMap<String, Integer>();
  2046. Map<String, Integer> impAuditDeclCountMap = new HashMap<String, Integer>();
  2047. Map<String, Long> impTotalCostMap = new HashMap<String, Long>();
  2048. Map<String, Long> impHgCostMap = new HashMap<String, Long>();
  2049. Map<String, Integer> expDeclCountMap = new HashMap<String, Integer>();
  2050. Map<String, Integer> expManDeclCountMap = new HashMap<String, Integer>();
  2051. Map<String, Integer> expAuditDeclCountMap = new HashMap<String, Integer>();
  2052. Map<String, Long> expTotalCostMap = new HashMap<String, Long>();
  2053. Map<String, Long> expHgCostMap = new HashMap<String, Long>();
  2054. for (Object[] e : entryList) {
  2055. String customCode = (String) e[0];
  2056. customCodeSet.add(customCode);
  2057. String ieFlag = (String) e[1];
  2058. String checkFlag = (String) e[2];
  2059. Date orderReceiveDate = (Date) e[3];
  2060. Long totalCost = ((BigDecimal) e[4]).longValue();
  2061. Long hgCost = ((BigDecimal) e[5]).longValue();
  2062. if ("I".equals(ieFlag)) {// 入境
  2063. Integer impCount = impDeclCountMap.get(customCode);
  2064. if (impCount == null) {
  2065. impCount = 1;
  2066. } else {
  2067. impCount++;
  2068. }
  2069. impDeclCountMap.put(customCode, impCount);
  2070. Integer impManCount = impManDeclCountMap.get(customCode);
  2071. if (impManCount == null && checkFlag.equals("0")) {
  2072. impManCount = 1;
  2073. } else {
  2074. if (checkFlag.equals("0")) {
  2075. impManCount++;
  2076. }
  2077. }
  2078. impManDeclCountMap.put(customCode, impManCount);
  2079. Integer impAuditCount = impAuditDeclCountMap.get(customCode);
  2080. if (impAuditCount == null && orderReceiveDate != null) {
  2081. impAuditCount = 1;
  2082. } else {
  2083. if (orderReceiveDate != null) {
  2084. impAuditCount++;
  2085. }
  2086. }
  2087. impAuditDeclCountMap.put(customCode, impAuditCount);
  2088. Long sumTotalCost = impTotalCostMap.get(customCode);
  2089. if (sumTotalCost == null) {
  2090. sumTotalCost = totalCost;
  2091. } else {
  2092. sumTotalCost += totalCost;
  2093. }
  2094. impTotalCostMap.put(customCode, sumTotalCost);
  2095. Long sumHgCost = impHgCostMap.get(customCode);
  2096. if (sumHgCost == null) {
  2097. sumHgCost = hgCost;
  2098. } else {
  2099. sumHgCost += hgCost;
  2100. }
  2101. impHgCostMap.put(customCode, sumHgCost);
  2102. } else {// 出境
  2103. Integer expCount = expDeclCountMap.get(customCode);
  2104. if (expCount == null) {
  2105. expCount = 1;
  2106. } else {
  2107. expCount++;
  2108. }
  2109. expDeclCountMap.put(customCode, expCount);
  2110. Integer expManCount = expManDeclCountMap.get(customCode);
  2111. if (expManCount == null && checkFlag.equals("0")) {
  2112. expManCount = 1;
  2113. } else {
  2114. if (checkFlag.equals("0")) {
  2115. expManCount++;
  2116. }
  2117. }
  2118. expManDeclCountMap.put(customCode, expManCount);
  2119. Integer expAuditCount = expAuditDeclCountMap.get(customCode);
  2120. if (expAuditCount == null && orderReceiveDate != null) {
  2121. expAuditCount = 1;
  2122. } else {
  2123. if (orderReceiveDate != null) {
  2124. expAuditCount++;
  2125. }
  2126. }
  2127. expAuditDeclCountMap.put(customCode, expAuditCount);
  2128. Long sumTotalCost = expTotalCostMap.get(customCode);
  2129. if (sumTotalCost == null) {
  2130. sumTotalCost = totalCost;
  2131. } else {
  2132. sumTotalCost += totalCost;
  2133. }
  2134. expTotalCostMap.put(customCode, sumTotalCost);
  2135. Long sumHgCost = expHgCostMap.get(customCode);
  2136. if (sumHgCost == null) {
  2137. sumHgCost = hgCost;
  2138. } else {
  2139. sumHgCost += hgCost;
  2140. }
  2141. expHgCostMap.put(customCode, sumHgCost);
  2142. }
  2143. }
  2144. BigDecimal impTotalCost = new BigDecimal(0);
  2145. BigDecimal impHgCost = new BigDecimal(0);
  2146. BigDecimal expTotalCost = new BigDecimal(0);
  2147. BigDecimal expHgCost = new BigDecimal(0);
  2148. // 当年各平均值为每个月单量x每个月对应时间累加后,除以总单量
  2149. Map<String, BigDecimal> impCurYearTotalCostMap = new HashMap<String, BigDecimal>();
  2150. Map<String, BigDecimal> impCurYearHgCostMap = new HashMap<String, BigDecimal>();
  2151. Map<String, BigDecimal> impLastMonthTotalCostMap = new HashMap<String, BigDecimal>();
  2152. Map<String, BigDecimal> impLastMonthHgCostMap = new HashMap<String, BigDecimal>();
  2153. Map<String, BigDecimal> impLastYearDecemberTotalCostMap = new HashMap<String, BigDecimal>();
  2154. Map<String, BigDecimal> impLastYearDecemberHgCostMap = new HashMap<String, BigDecimal>();
  2155. Map<String, BigDecimal> impYearBeforeLastTotalCostMap = new HashMap<String, BigDecimal>();
  2156. Map<String, BigDecimal> impYearBeforeLastHgCostMap = new HashMap<String, BigDecimal>();
  2157. Map<String, BigDecimal> expCurYearTotalCostMap = new HashMap<String, BigDecimal>();
  2158. Map<String, BigDecimal> expCurYearHgCostMap = new HashMap<String, BigDecimal>();
  2159. Map<String, BigDecimal> expLastMonthTotalCostMap = new HashMap<String, BigDecimal>();
  2160. Map<String, BigDecimal> expLastMonthHgCostMap = new HashMap<String, BigDecimal>();
  2161. Map<String, BigDecimal> expLastYearDecemberTotalCostMap = new HashMap<String, BigDecimal>();
  2162. Map<String, BigDecimal> expLastYearDecemberHgCostMap = new HashMap<String, BigDecimal>();
  2163. Map<String, BigDecimal> expYearBeforeLastTotalCostMap = new HashMap<String, BigDecimal>();
  2164. Map<String, BigDecimal> expYearBeforeLastHgCostMap = new HashMap<String, BigDecimal>();
  2165. Map<String, Integer> impCurYearDeclCountMap = new HashMap<String, Integer>();
  2166. Map<String, Integer> impLastMonthDeclCountMap = new HashMap<String, Integer>();
  2167. Map<String, Integer> impLastYearDecemberDeclCountMap = new HashMap<String, Integer>();
  2168. Map<String, Integer> impYearBeforeLastDeclCountMap = new HashMap<String, Integer>();
  2169. Map<String, Integer> expCurYearDeclCountMap = new HashMap<String, Integer>();
  2170. Map<String, Integer> expLastMonthDeclCountMap = new HashMap<String, Integer>();
  2171. Map<String, Integer> expLastYearDecemberDeclCountMap = new HashMap<String, Integer>();
  2172. Map<String, Integer> expYearBeforeLastDeclCountMap = new HashMap<String, Integer>();
  2173. if (dataPeriod.compareTo(noRelStatMonth) > 0) {
  2174. if (!dataPeriod.endsWith("01")) {
  2175. int sumImpDeclCount = 0;
  2176. int sumExpDeclCount = 0;
  2177. BigDecimal sumImpCurYearTotalCost = new BigDecimal(0);
  2178. BigDecimal sumImpCurYearHgCost = new BigDecimal(0);
  2179. BigDecimal sumExpCurYearTotalCost = new BigDecimal(0);
  2180. BigDecimal sumExpCurYearHgCost = new BigDecimal(0);
  2181. String indexCustCode = null;
  2182. String year = dataPeriod.substring(0, 4);
  2183. List<Object[]> curYearlist = (List<Object[]>) dao.getQueryBySql(
  2184. "select MONTH,CUSTOM_CODE,IMP_DECL_COUNT,IMP_MAN_DECL_COUNT,IMP_MANUAL_AUDIT_DECL_COUNT,IMP_DECL_COUNT_LM,IMP_DECL_COUNT_LY_DEC," +
  2185. "IMP_DECL_COUNT_CURYEAR,IMP_DECL_COUNT_YBL,IMP_TOTAL_COST,IMP_TOTAL_COST_LM,IMP_TOTAL_COST_LY_DEC,IMP_TOTAL_COST_CY,IMP_TOTAL_COST_YBL," +
  2186. "IMP_CU_COST,IMP_CU_COST_LM,IMP_CU_COST_LY_DEC,IMP_CU_COST_CY,IMP_CU_COST_YBL,EXP_DECL_COUNT,EXP_MAN_DECL_COUNT,EXP_MANUAL_AUDIT_DECL_COUNT," +
  2187. "EXP_DECL_COUNT_LM,EXP_DECL_COUNT_LY_DEC,EXP_DECL_COUNT_CURYEAR,EXP_DECL_COUNT_YBL,EXP_TOTAL_COST,EXP_TOTAL_COST_LM,EXP_TOTAL_COST_LY_DEC," +
  2188. "EXP_TOTAL_COST_CY,EXP_TOTAL_COST_YBL,EXP_CU_COST,EXP_CU_COST_LM,EXP_CU_COST_LY_DEC,EXP_CU_COST_CY,EXP_CU_COST_YBL " +
  2189. "from WXJY_CUSTOM_M_STAT where month >= ? and month < ? order by CUSTOM_CODE", year + "01", dataPeriod);
  2190. for (int i = 0; i < curYearlist.size(); i++) {
  2191. Object[] s = curYearlist.get(i);
  2192. String custCode = (String) s[0];
  2193. int impCount = s[2] != null ? ((BigDecimal) s[2]).intValue() : 0;
  2194. int expCount = s[19] != null ? ((BigDecimal) s[19]).intValue() : 0;
  2195. BigDecimal impMultily = new BigDecimal(impCount);
  2196. BigDecimal expMultily = new BigDecimal(expCount);
  2197. BigDecimal impTotalCostT = (BigDecimal) s[10];
  2198. BigDecimal impCuCostT = (BigDecimal) s[15];
  2199. BigDecimal expTotalCostT = (BigDecimal) s[27];
  2200. BigDecimal expCuCostT = (BigDecimal) s[32];
  2201. if (indexCustCode == null || indexCustCode.equals(custCode)) {// 同一关区,累计数据
  2202. indexCustCode = custCode;
  2203. sumImpDeclCount += impCount;
  2204. sumExpDeclCount += expCount;
  2205. sumImpCurYearTotalCost = sumImpCurYearTotalCost.add(impTotalCostT.multiply(impMultily));
  2206. sumImpCurYearHgCost = sumImpCurYearHgCost.add(impCuCostT.multiply(impMultily));
  2207. sumExpCurYearTotalCost = sumExpCurYearTotalCost.add(expTotalCostT.multiply(expMultily));
  2208. sumExpCurYearHgCost = sumExpCurYearHgCost.add(expCuCostT.multiply(expMultily));
  2209. } else {// 切换关区
  2210. if (sumImpDeclCount != 0) {
  2211. BigDecimal impDivide = new BigDecimal(sumImpDeclCount);
  2212. impCurYearTotalCostMap.put(indexCustCode,
  2213. sumImpCurYearTotalCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2214. impCurYearHgCostMap.put(indexCustCode, sumImpCurYearHgCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2215. } else {
  2216. impCurYearTotalCostMap.put(indexCustCode, zero);
  2217. impCurYearHgCostMap.put(indexCustCode, zero);
  2218. }
  2219. if (sumExpDeclCount != 0) {
  2220. BigDecimal expDivide = new BigDecimal(sumExpDeclCount);
  2221. expCurYearTotalCostMap.put(indexCustCode,
  2222. sumExpCurYearTotalCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2223. expCurYearHgCostMap.put(indexCustCode, sumExpCurYearHgCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2224. } else {
  2225. expCurYearTotalCostMap.put(indexCustCode, zero);
  2226. expCurYearHgCostMap.put(indexCustCode, zero);
  2227. }
  2228. impCurYearDeclCountMap.put(indexCustCode, sumImpDeclCount);
  2229. expCurYearDeclCountMap.put(indexCustCode, sumExpDeclCount);
  2230. sumImpDeclCount = impCount;
  2231. sumExpDeclCount = expCount;
  2232. sumImpCurYearTotalCost = new BigDecimal(0);
  2233. sumImpCurYearHgCost = new BigDecimal(0);
  2234. sumExpCurYearTotalCost = new BigDecimal(0);
  2235. sumExpCurYearHgCost = new BigDecimal(0);
  2236. indexCustCode = custCode;
  2237. sumImpCurYearTotalCost = sumImpCurYearTotalCost.add(impTotalCostT.multiply(impMultily));
  2238. sumImpCurYearHgCost = sumImpCurYearHgCost.add(impCuCostT.multiply(impMultily));
  2239. sumExpCurYearTotalCost = sumExpCurYearTotalCost.add(expTotalCostT.multiply(expMultily));
  2240. sumExpCurYearHgCost = sumExpCurYearHgCost.add(expCuCostT.multiply(expMultily));
  2241. }
  2242. if (i == curYearlist.size() - 1) {// 最后一条记录
  2243. BigDecimal impDivide = new BigDecimal(sumImpDeclCount);
  2244. BigDecimal expDivide = new BigDecimal(sumExpDeclCount);
  2245. if (sumImpDeclCount != 0) {
  2246. impCurYearTotalCostMap.put(indexCustCode,
  2247. sumImpCurYearTotalCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2248. impCurYearHgCostMap.put(indexCustCode, sumImpCurYearHgCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2249. } else {
  2250. impCurYearTotalCostMap.put(indexCustCode, zero);
  2251. impCurYearHgCostMap.put(indexCustCode, zero);
  2252. }
  2253. if (sumExpDeclCount != 0) {
  2254. expCurYearTotalCostMap.put(indexCustCode,
  2255. sumExpCurYearTotalCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2256. expCurYearHgCostMap.put(indexCustCode, sumExpCurYearHgCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2257. } else {
  2258. expCurYearTotalCostMap.put(indexCustCode, zero);
  2259. expCurYearHgCostMap.put(indexCustCode, zero);
  2260. }
  2261. }
  2262. }
  2263. }
  2264. // 先查询到上个月的数据备用
  2265. Date curMonth = null;
  2266. try {
  2267. curMonth = monthSdf.parse(dataPeriod);
  2268. } catch (ParseException e1) {
  2269. }
  2270. Calendar cal = Calendar.getInstance();
  2271. cal.setTime(curMonth);
  2272. cal.add(Calendar.MONTH, -1);
  2273. Date lastMonthDate = cal.getTime();
  2274. String lastMonthStr = monthSdf.format(lastMonthDate);
  2275. List<Object[]> lastMonthData = (List<Object[]>) dao.getQueryBySql(
  2276. "select CUSTOM_CODE,IMP_DECL_COUNT,IMP_TOTAL_COST,IMP_CU_COST,EXP_DECL_COUNT,EXP_TOTAL_COST,EXP_CU_COST " +
  2277. "from WXJY_CUSTOM_M_STAT where month = ? ", lastMonthStr);
  2278. for (Object[] s : lastMonthData) {
  2279. String customCode = (String) s[0];
  2280. Integer impDeclCount = Integer.valueOf(((BigDecimal) s[1]).toString());
  2281. BigDecimal impTotalCostT = (BigDecimal) s[2];
  2282. BigDecimal impCuCostT = (BigDecimal) s[3];
  2283. Integer expDeclCount = Integer.valueOf(((BigDecimal) s[4]).toString());
  2284. BigDecimal expTotalCostT = (BigDecimal) s[5];
  2285. BigDecimal expCuCostT = (BigDecimal) s[6];
  2286. impLastMonthTotalCostMap.put(customCode, impTotalCostT);
  2287. impLastMonthHgCostMap.put(customCode, impCuCostT);
  2288. expLastMonthTotalCostMap.put(customCode, expTotalCostT);
  2289. expLastMonthHgCostMap.put(customCode, expCuCostT);
  2290. impLastMonthDeclCountMap.put(customCode, impDeclCount);
  2291. expLastMonthDeclCountMap.put(customCode, expDeclCount);
  2292. }
  2293. // 去年12月数据
  2294. cal.setTime(curMonth);
  2295. cal.add(Calendar.YEAR, -1);
  2296. String lastDecember = yearSdf.format(cal.getTime()) + "12";
  2297. List<Object[]> lastDecData = (List<Object[]>) dao.getQueryBySql(
  2298. "select CUSTOM_CODE,IMP_DECL_COUNT,IMP_TOTAL_COST,IMP_CU_COST,EXP_DECL_COUNT,EXP_TOTAL_COST,EXP_CU_COST " +
  2299. "from WXJY_CUSTOM_M_STAT where month = ? ", lastDecember);
  2300. for (Object[] s : lastDecData) {
  2301. String customCode = (String) s[0];
  2302. Integer impDeclCount = Integer.valueOf(((BigDecimal) s[1]).toString());
  2303. BigDecimal impTotalCostT = (BigDecimal) s[2];
  2304. BigDecimal impCuCostT = (BigDecimal) s[3];
  2305. Integer expDeclCount = Integer.valueOf(((BigDecimal) s[4]).toString());
  2306. BigDecimal expTotalCostT = (BigDecimal) s[5];
  2307. BigDecimal expCuCostT = (BigDecimal) s[6];
  2308. impLastYearDecemberTotalCostMap.put(customCode, impTotalCostT);
  2309. impLastYearDecemberHgCostMap.put(customCode, impCuCostT);
  2310. expLastYearDecemberTotalCostMap.put(customCode, expTotalCostT);
  2311. expLastYearDecemberHgCostMap.put(customCode, expCuCostT);
  2312. impLastYearDecemberDeclCountMap.put(customCode, impDeclCount);
  2313. expLastYearDecemberDeclCountMap.put(customCode, expDeclCount);
  2314. }
  2315. boolean existData = false;
  2316. if (!existData) {
  2317. cal.setTime(curMonth);
  2318. cal.add(Calendar.YEAR, -2);
  2319. String yearBeforeLast = yearSdf.format(cal.getTime());
  2320. String firstMonthOfYearBeforeLast = yearBeforeLast + "01";
  2321. String lastMonthOfYearBeforeLast = yearBeforeLast + "12";
  2322. List<Object[]> list = (List<Object[]>) dao.getQueryBySql(
  2323. "select CUSTOM_CODE,IMP_DECL_COUNT,IMP_TOTAL_COST,IMP_CU_COST,EXP_DECL_COUNT,EXP_TOTAL_COST,EXP_CU_COST " +
  2324. "from WXJY_CUSTOM_M_STAT where month >= ? and month <= ? order by CUSTOM_CODE", firstMonthOfYearBeforeLast,
  2325. lastMonthOfYearBeforeLast);
  2326. if (list.size() > 0) {
  2327. int sumImpDeclCount = 0;
  2328. int sumExpDeclCount = 0;
  2329. BigDecimal sumImpYearBeforeLastTotalCost = new BigDecimal(0);
  2330. BigDecimal sumImpYearBeforeLastHgCost = new BigDecimal(0);
  2331. BigDecimal sumExpYearBeforeLastTotalCost = new BigDecimal(0);
  2332. BigDecimal sumExpYearBeforeLastHgCost = new BigDecimal(0);
  2333. String indexCustCode = null;
  2334. for (int j = 0; j < list.size(); j++) {
  2335. Object[] s = list.get(j);
  2336. String custCode = (String) s[0];
  2337. Integer impCount = Integer.valueOf(((BigDecimal) s[1]).toString());
  2338. BigDecimal impTotalCostT = (BigDecimal) s[2];
  2339. BigDecimal impCuCostT = (BigDecimal) s[3];
  2340. Integer expCount = Integer.valueOf(((BigDecimal) s[4]).toString());
  2341. BigDecimal expTotalCostT = (BigDecimal) s[5];
  2342. BigDecimal expCuCostT = (BigDecimal) s[6];
  2343. BigDecimal impMultily = new BigDecimal(impCount);
  2344. BigDecimal expMultily = new BigDecimal(expCount);
  2345. if (indexCustCode == null || indexCustCode.equals(custCode)) {// 同一关区,累计数据
  2346. indexCustCode = custCode;
  2347. sumImpDeclCount += impCount;
  2348. sumExpDeclCount += expCount;
  2349. sumImpYearBeforeLastTotalCost = sumImpYearBeforeLastTotalCost.add(impTotalCostT.multiply(impMultily));
  2350. sumImpYearBeforeLastHgCost = sumImpYearBeforeLastHgCost.add(impCuCostT.multiply(impMultily));
  2351. sumExpYearBeforeLastTotalCost = sumExpYearBeforeLastTotalCost.add(expTotalCostT.multiply(expMultily));
  2352. sumExpYearBeforeLastHgCost = sumExpYearBeforeLastHgCost.add(expCuCostT.multiply(expMultily));
  2353. } else {// 切换关区
  2354. BigDecimal impDivide = new BigDecimal(sumImpDeclCount);
  2355. BigDecimal expDivide = new BigDecimal(sumExpDeclCount);
  2356. if (sumImpDeclCount != 0) {
  2357. impYearBeforeLastTotalCostMap.put(indexCustCode,
  2358. sumImpYearBeforeLastTotalCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2359. impYearBeforeLastHgCostMap.put(indexCustCode,
  2360. sumImpYearBeforeLastHgCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2361. } else {
  2362. impYearBeforeLastTotalCostMap.put(indexCustCode, zero);
  2363. impYearBeforeLastHgCostMap.put(indexCustCode, zero);
  2364. }
  2365. if (sumExpDeclCount != 0) {
  2366. expYearBeforeLastTotalCostMap.put(indexCustCode,
  2367. sumExpYearBeforeLastTotalCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2368. expYearBeforeLastHgCostMap.put(indexCustCode,
  2369. sumExpYearBeforeLastHgCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2370. } else {
  2371. expYearBeforeLastTotalCostMap.put(indexCustCode, zero);
  2372. expYearBeforeLastHgCostMap.put(indexCustCode, zero);
  2373. }
  2374. impYearBeforeLastDeclCountMap.put(indexCustCode, sumImpDeclCount);
  2375. expYearBeforeLastDeclCountMap.put(indexCustCode, sumExpDeclCount);
  2376. sumImpDeclCount = impCount;
  2377. sumExpDeclCount = expCount;
  2378. sumImpYearBeforeLastTotalCost = new BigDecimal(0);
  2379. sumImpYearBeforeLastHgCost = new BigDecimal(0);
  2380. sumExpYearBeforeLastTotalCost = new BigDecimal(0);
  2381. sumExpYearBeforeLastHgCost = new BigDecimal(0);
  2382. indexCustCode = custCode;
  2383. sumImpYearBeforeLastTotalCost = sumImpYearBeforeLastTotalCost.add(impTotalCostT.multiply(impMultily));
  2384. sumImpYearBeforeLastHgCost = sumImpYearBeforeLastHgCost.add(impCuCostT.multiply(impMultily));
  2385. sumExpYearBeforeLastTotalCost = sumExpYearBeforeLastTotalCost.add(expTotalCostT.multiply(expMultily));
  2386. sumExpYearBeforeLastHgCost = sumExpYearBeforeLastHgCost.add(expCuCostT.multiply(expMultily));
  2387. }
  2388. if (j == list.size() - 1) {// 最后一条记录
  2389. BigDecimal impDivide = new BigDecimal(sumImpDeclCount);
  2390. BigDecimal expDivide = new BigDecimal(sumExpDeclCount);
  2391. if (sumImpDeclCount != 0) {
  2392. impYearBeforeLastTotalCostMap.put(indexCustCode,
  2393. sumImpYearBeforeLastTotalCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2394. impYearBeforeLastHgCostMap.put(indexCustCode,
  2395. sumImpYearBeforeLastHgCost.divide(impDivide, 4, BigDecimal.ROUND_HALF_UP));
  2396. } else {
  2397. impYearBeforeLastTotalCostMap.put(indexCustCode, zero);
  2398. impYearBeforeLastHgCostMap.put(indexCustCode, zero);
  2399. }
  2400. if (sumExpDeclCount != 0) {
  2401. expYearBeforeLastTotalCostMap.put(indexCustCode,
  2402. sumExpYearBeforeLastTotalCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2403. expYearBeforeLastHgCostMap.put(indexCustCode,
  2404. sumExpYearBeforeLastHgCost.divide(expDivide, 4, BigDecimal.ROUND_HALF_UP));
  2405. } else {
  2406. expYearBeforeLastTotalCostMap.put(indexCustCode, zero);
  2407. expYearBeforeLastHgCostMap.put(indexCustCode, zero);
  2408. }
  2409. impYearBeforeLastDeclCountMap.put(indexCustCode, sumImpDeclCount);
  2410. expYearBeforeLastDeclCountMap.put(indexCustCode, sumExpDeclCount);
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }
  2416. for (String customCode : customCodeSet) {
  2417. CustomMonthlyStat stat = new CustomMonthlyStat();
  2418. stat.setCustomCode(customCode);
  2419. stat.setMonth(dataPeriod);
  2420. Integer impCount = impDeclCountMap.get(customCode);
  2421. if (impCount != null) {
  2422. stat.setImpDeclCount(impCount);
  2423. BigDecimal impDeclDiv = new BigDecimal(impCount * 3600);// 每单耗时x小时
  2424. BigDecimal sumImpTotalCost = new BigDecimal(impTotalCostMap.get(customCode));
  2425. impTotalCost = sumImpTotalCost.divide(impDeclDiv, 4, BigDecimal.ROUND_HALF_UP);
  2426. stat.setImpTotalCost(impTotalCost);
  2427. BigDecimal sumImpHgCost = new BigDecimal(impHgCostMap.get(customCode));
  2428. impHgCost = sumImpHgCost.divide(impDeclDiv, 4, BigDecimal.ROUND_HALF_UP);
  2429. stat.setImpCuCost(impHgCost);
  2430. } else {
  2431. stat.setImpDeclCount(0);
  2432. stat.setImpTotalCost(zero);
  2433. stat.setImpCuCost(zero);
  2434. }
  2435. Integer impManCount = impManDeclCountMap.get(customCode);
  2436. if (impManCount != null) {
  2437. stat.setImpManDeclCount(impManCount);
  2438. } else {
  2439. stat.setImpManDeclCount(0);
  2440. }
  2441. Integer impAuditCount = impAuditDeclCountMap.get(customCode);
  2442. if (impAuditCount != null) {
  2443. stat.setImpManualAuditDeclCount(impAuditCount);
  2444. } else {
  2445. stat.setImpManualAuditDeclCount(0);
  2446. }
  2447. Integer expCount = expDeclCountMap.get(customCode);
  2448. if (expCount != null) {
  2449. stat.setExpDeclCount(expCount);
  2450. BigDecimal expDeclDiv = new BigDecimal(expCount * 3600);// 每单耗时x小时
  2451. BigDecimal sumExpTotalCost = new BigDecimal(expTotalCostMap.get(customCode));
  2452. expTotalCost = sumExpTotalCost.divide(expDeclDiv, 4, BigDecimal.ROUND_HALF_UP);
  2453. stat.setExpTotalCost(expTotalCost);
  2454. BigDecimal sumExpHgCost = new BigDecimal(expHgCostMap.get(customCode));
  2455. expHgCost = sumExpHgCost.divide(expDeclDiv, 4, BigDecimal.ROUND_HALF_UP);
  2456. stat.setExpCuCost(expHgCost);
  2457. } else {
  2458. stat.setExpDeclCount(0);
  2459. stat.setExpTotalCost(zero);
  2460. stat.setExpCuCost(zero);
  2461. }
  2462. Integer expManCount = expManDeclCountMap.get(customCode);
  2463. if (expManCount != null) {
  2464. stat.setExpManDeclCount(expManCount);
  2465. } else {
  2466. stat.setExpManDeclCount(0);
  2467. }
  2468. Integer expAuditCount = expAuditDeclCountMap.get(customCode);
  2469. if (expAuditCount != null) {
  2470. stat.setExpManualAuditDeclCount(expAuditCount);
  2471. } else {
  2472. stat.setExpManualAuditDeclCount(0);
  2473. }
  2474. if (dataPeriod.compareTo(noRelStatMonth) > 0) {
  2475. if (dataPeriod.endsWith("01")) {
  2476. stat.setImpTotalCostCurentYear(impTotalCost);
  2477. stat.setImpCuCostCurentYear(impHgCost);
  2478. stat.setExpTotalCostCurentYear(expTotalCost);
  2479. stat.setExpCuCostCurentYear(expHgCost);
  2480. stat.setImpDeclCountCurentYear(stat.getImpDeclCount());
  2481. stat.setExpDeclCountCurentYear(stat.getExpDeclCount());
  2482. } else {// 另外查询当年前面月份数据来计算
  2483. if (impCount == null) { // 当月进口报单量为0
  2484. stat.setImpTotalCostCurentYear(
  2485. impCurYearTotalCostMap.get(customCode) != null ? impCurYearTotalCostMap.get(customCode) : zero);
  2486. stat.setImpCuCostCurentYear(
  2487. impCurYearHgCostMap.get(customCode) != null ? impCurYearHgCostMap.get(customCode) : zero);
  2488. stat.setImpDeclCountCurentYear(
  2489. impCurYearDeclCountMap.get(customCode) != null ? impCurYearDeclCountMap.get(customCode) : 0);
  2490. } else { // 累计前面月份和当月
  2491. Integer impCurYearDeclCount = impCurYearDeclCountMap.get(customCode);
  2492. if (impCurYearDeclCount == null) { // 对应关区当年前面月份入境报单量为0
  2493. stat.setImpTotalCostCurentYear(impTotalCost);
  2494. stat.setImpCuCostCurentYear(impHgCost);
  2495. stat.setImpDeclCountCurentYear(stat.getImpDeclCount());
  2496. } else {
  2497. BigDecimal impCurYearTotalCost = impCurYearTotalCostMap.get(customCode);
  2498. if (impCurYearTotalCost != null) {
  2499. impCurYearTotalCost = impCurYearTotalCost.multiply(new BigDecimal(impCurYearDeclCount))
  2500. .add(impTotalCost)
  2501. .divide(new BigDecimal(impCurYearDeclCount + impCount), 4, BigDecimal.ROUND_HALF_UP);
  2502. stat.setImpTotalCostCurentYear(impCurYearTotalCost);
  2503. } else {
  2504. stat.setImpTotalCostCurentYear(impTotalCost);
  2505. }
  2506. BigDecimal impCurYearCuCost = impCurYearHgCostMap.get(customCode);
  2507. if (impCurYearCuCost != null) {
  2508. impCurYearCuCost = impCurYearCuCost.multiply(new BigDecimal(impCurYearDeclCount)).add(impHgCost)
  2509. .divide(new BigDecimal(impCurYearDeclCount + impCount), 4, BigDecimal.ROUND_HALF_UP);
  2510. stat.setImpCuCostCurentYear(impCurYearCuCost);
  2511. } else {
  2512. stat.setImpCuCostCurentYear(impHgCost);
  2513. }
  2514. stat.setImpDeclCountCurentYear(impCurYearDeclCount + impCount);
  2515. }
  2516. }
  2517. if (expCount == null) {
  2518. stat.setExpTotalCostCurentYear(
  2519. expCurYearTotalCostMap.get(customCode) != null ? expCurYearTotalCostMap.get(customCode) : zero);
  2520. stat.setExpCuCostCurentYear(
  2521. expCurYearHgCostMap.get(customCode) != null ? expCurYearHgCostMap.get(customCode) : zero);
  2522. stat.setExpDeclCountCurentYear(
  2523. expCurYearDeclCountMap.get(customCode) != null ? expCurYearDeclCountMap.get(customCode) : 0);
  2524. } else {
  2525. Integer expCurYearDeclCount = expCurYearDeclCountMap.get(customCode);
  2526. if (expCurYearDeclCount == null) {
  2527. stat.setExpTotalCostCurentYear(expTotalCost);
  2528. stat.setExpCuCostCurentYear(expHgCost);
  2529. stat.setExpDeclCountCurentYear(stat.getExpDeclCount());
  2530. } else {
  2531. BigDecimal expCurYearTotalCost = expCurYearTotalCostMap.get(customCode);
  2532. if (expCurYearTotalCost != null) {
  2533. expCurYearTotalCost = expCurYearTotalCost.multiply(new BigDecimal(expCurYearDeclCount))
  2534. .add(expTotalCost)
  2535. .divide(new BigDecimal(expCurYearDeclCount + expCount), 4, BigDecimal.ROUND_HALF_UP);
  2536. stat.setExpTotalCostCurentYear(expCurYearTotalCost);
  2537. } else {
  2538. stat.setExpTotalCostCurentYear(expTotalCost);
  2539. }
  2540. BigDecimal expCurYearCuCost = expCurYearHgCostMap.get(customCode);
  2541. if (expCurYearCuCost != null) {
  2542. expCurYearCuCost = expCurYearCuCost.multiply(new BigDecimal(expCurYearDeclCount)).add(expHgCost)
  2543. .divide(new BigDecimal(expCurYearDeclCount + expCount), 4, BigDecimal.ROUND_HALF_UP);
  2544. stat.setExpCuCostCurentYear(expCurYearCuCost);
  2545. } else {
  2546. stat.setExpCuCostCurentYear(expHgCost);
  2547. }
  2548. stat.setExpDeclCountCurentYear(expCurYearDeclCount + expCount);
  2549. }
  2550. }
  2551. }
  2552. stat.setImpTotalCostLastMonth(
  2553. impLastMonthTotalCostMap.get(customCode) != null ? impLastMonthTotalCostMap.get(customCode) : zero);
  2554. stat.setImpTotalCostLastYearDecember(
  2555. impLastYearDecemberTotalCostMap.get(customCode) != null ? impLastYearDecemberTotalCostMap.get(customCode)
  2556. : zero);
  2557. stat.setImpTotalCostYearBeforeLast(
  2558. impYearBeforeLastTotalCostMap.get(customCode) != null ? impYearBeforeLastTotalCostMap.get(customCode) : zero);
  2559. stat.setImpCuCostLastMonth(
  2560. impLastMonthHgCostMap.get(customCode) != null ? impLastMonthHgCostMap.get(customCode) : zero);
  2561. stat.setImpCuCostLastYearDecember(
  2562. impLastYearDecemberHgCostMap.get(customCode) != null ? impLastYearDecemberHgCostMap.get(customCode) : zero);
  2563. stat.setImpCuCostYearBeforeLast(
  2564. impYearBeforeLastHgCostMap.get(customCode) != null ? impYearBeforeLastHgCostMap.get(customCode) : zero);
  2565. stat.setExpTotalCostLastMonth(
  2566. expLastMonthTotalCostMap.get(customCode) != null ? expLastMonthTotalCostMap.get(customCode) : zero);
  2567. stat.setExpTotalCostLastYearDecember(
  2568. expLastYearDecemberTotalCostMap.get(customCode) != null ? expLastYearDecemberTotalCostMap.get(customCode)
  2569. : zero);
  2570. stat.setExpTotalCostYearBeforeLast(
  2571. expYearBeforeLastTotalCostMap.get(customCode) != null ? expYearBeforeLastTotalCostMap.get(customCode) : zero);
  2572. stat.setExpCuCostLastMonth(
  2573. expLastMonthHgCostMap.get(customCode) != null ? expLastMonthHgCostMap.get(customCode) : zero);
  2574. stat.setExpCuCostLastYearDecember(
  2575. expLastYearDecemberHgCostMap.get(customCode) != null ? expLastYearDecemberHgCostMap.get(customCode) : zero);
  2576. stat.setExpCuCostYearBeforeLast(
  2577. expYearBeforeLastHgCostMap.get(customCode) != null ? expYearBeforeLastHgCostMap.get(customCode) : zero);
  2578. stat.setImpDeclCountLastMonth(
  2579. impLastMonthDeclCountMap.get(customCode) != null ? impLastMonthDeclCountMap.get(customCode) : 0);
  2580. stat.setImpDeclCountLastYearDecember(
  2581. impLastYearDecemberDeclCountMap.get(customCode) != null ? impLastYearDecemberDeclCountMap.get(customCode) : 0);
  2582. stat.setImpDeclCountYearBeforeLast(
  2583. impYearBeforeLastDeclCountMap.get(customCode) != null ? impYearBeforeLastDeclCountMap.get(customCode) : 0);
  2584. stat.setExpDeclCountLastMonth(
  2585. expLastMonthDeclCountMap.get(customCode) != null ? expLastMonthDeclCountMap.get(customCode) : 0);
  2586. stat.setExpDeclCountLastYearDecember(
  2587. expLastYearDecemberDeclCountMap.get(customCode) != null ? expLastYearDecemberDeclCountMap.get(customCode) : 0);
  2588. stat.setExpDeclCountYearBeforeLast(
  2589. expYearBeforeLastDeclCountMap.get(customCode) != null ? expYearBeforeLastDeclCountMap.get(customCode) : 0);
  2590. }
  2591. stat.setId(dao.getGuidStringBySql());
  2592. customMonthlyStatRepository.save(stat);
  2593. }
  2594. // 20191014 再次维护合并了关区的统计中间数据
  2595. mainCustomMonthlyStatFinal(dataPeriod);
  2596. MiddleDataMainStatus mStatus = new MiddleDataMainStatus();
  2597. mStatus.setCreateTime(new Date());
  2598. mStatus.setDataType(CustomMonthlyStat.class.getSimpleName());
  2599. mStatus.setStatPeriod(dataPeriod);
  2600. dao.executeUpdate("insert into WXJY_MID_D_M_STATUS (ID,DATA_TYPE, STAT_PERIOD, CREATE_TIME) " +
  2601. "values(sys_guid(),?,?,?) ", mStatus.getDataType(), mStatus.getStatPeriod(), mStatus.getCreateTime());
  2602. }
  2603. }
  2604. private void mainCustomMonthlyStatFinal(String dataPeriod) {
  2605. List<Object[]> copyList = new ArrayList<Object[]>();
  2606. List<Object[]> curMonthStat = (List<Object[]>) dao.getQueryBySql("select ID,MONTH,CUSTOM_CODE,IMP_DECL_COUNT,IMP_MAN_DECL_COUNT,IMP_MANUAL_AUDIT_DECL_COUNT,IMP_DECL_COUNT_LM,IMP_DECL_COUNT_LY_DEC," +
  2607. "IMP_DECL_COUNT_CURYEAR,IMP_DECL_COUNT_YBL,IMP_TOTAL_COST,IMP_TOTAL_COST_LM,IMP_TOTAL_COST_LY_DEC,IMP_TOTAL_COST_CY,IMP_TOTAL_COST_YBL," +
  2608. "IMP_CU_COST,IMP_CU_COST_LM,IMP_CU_COST_LY_DEC,IMP_CU_COST_CY,IMP_CU_COST_YBL,EXP_DECL_COUNT,EXP_MAN_DECL_COUNT,EXP_MANUAL_AUDIT_DECL_COUNT," +
  2609. "EXP_DECL_COUNT_LM,EXP_DECL_COUNT_LY_DEC,EXP_DECL_COUNT_CURYEAR,EXP_DECL_COUNT_YBL,EXP_TOTAL_COST,EXP_TOTAL_COST_LM,EXP_TOTAL_COST_LY_DEC," +
  2610. "EXP_TOTAL_COST_CY,EXP_TOTAL_COST_YBL,EXP_CU_COST,EXP_CU_COST_LM,EXP_CU_COST_LY_DEC,EXP_CU_COST_CY,EXP_CU_COST_YBL from WXJY_CUSTOM_M_STAT where month = ?",
  2611. dataPeriod);
  2612. for (Object[] s : curMonthStat) {
  2613. String customCode = (String) s[2];
  2614. s[2] = rootCustomsMap.get(customCode);
  2615. copyList.add(s);
  2616. }
  2617. Integer sumImpDeclCount = 0;// 进口单数
  2618. Integer sumImpManDeclCount = 0;// 进口查验单数
  2619. Integer sumImpAuditDeclCount = 0;// 进口人工审单单数
  2620. Integer sumImpDeclCountLastMonth = 0;// 上个月进口单数
  2621. Integer sumImpDeclCountLastYearDecember = 0;// 去年12月进口单数
  2622. Integer sumImpDeclCountCurentYear = 0;// 今年截止当月总进口单数
  2623. Integer sumImpDeclCountYearBeforeLast = 0;// 前年总进口单数
  2624. Integer sumExpDeclCount = 0;// 出口单数
  2625. Integer sumExpManDeclCount = 0;// 出口查验单数
  2626. Integer sumExpAuditDeclCount = 0;// 出口人工审单单数
  2627. Integer sumExpDeclCountLastMonth = 0;// 上个月出口单数
  2628. Integer sumExpDeclCountLastYearDecember = 0;// 去年12月进口单数
  2629. Integer sumExpDeclCountCurentYear = 0;// 今年截止当月总出口单数
  2630. Integer sumExpDeclCountYearBeforeLast = 0;// 前年总出口单数
  2631. // 20个消耗时间字段
  2632. BigDecimal sumImpTotalCost = zero;// 进口平均整体通关时间(小时)
  2633. BigDecimal sumImpTotalCostLastMonth = zero;// 进口平均整体通关时间-上月
  2634. BigDecimal sumImpTotalCostLastYearDecember = zero;// 进口平均整体通关时间-去年12月
  2635. BigDecimal sumImpTotalCostCurentYear = zero;// 进口平均整体通关时间-1至当月
  2636. BigDecimal sumImpTotalCostYearBeforeLast = zero;// 进口平均整体通关时间-前年
  2637. BigDecimal sumImpCuCost = zero;// 进口平均海关通关时间(小时)
  2638. BigDecimal sumImpCuCostLastMonth = zero;// 进口平均海关通关时间(小时)-上月
  2639. BigDecimal sumImpCuCostLastYearDecember = zero;// 进口平均海关通关时间-去年12月
  2640. BigDecimal sumImpCuCostCurentYear = zero;// 进口平均海关通关时间-1至当月
  2641. BigDecimal sumImpCuCostYearBeforeLast = zero;// 进口平均海关通关时间-前年
  2642. BigDecimal sumExpTotalCost = zero;// 出口平均整体通关时间(小时)
  2643. BigDecimal sumExpTotalCostLastMonth = zero;// 出口平均整体通关时间(小时)-上月
  2644. BigDecimal sumExpTotalCostLastYearDecember = zero; // 出口平均整体通关时间-去年12月
  2645. BigDecimal sumExpTotalCostCurentYear = zero;// 出口平均整体通关时间-1至当月
  2646. BigDecimal sumExpTotalCostYearBeforeLast = zero;// 出口平均整体通关时间-前年
  2647. BigDecimal sumExpCuCost = zero;// 出口平均海关通关时间(小时)
  2648. BigDecimal sumExpCuCostLastMonth = zero;// 出口平均海关通关时间(小时)-上月
  2649. BigDecimal sumExpCuCostLastYearDecember = zero;// 出口平均海关通关时间-去年12月
  2650. BigDecimal sumExpCuCostCurentYear = zero;// 出口平均海关通关时间-1至当月
  2651. BigDecimal sumExpCuCostYearBeforeLast = zero;// 出口平均海关通关时间-前年
  2652. for (String customCode : firstClassCustoms) {
  2653. if (!hasMultipleCustomList.contains(customCode)) {// 无下级关区的关区
  2654. boolean existData = false;
  2655. for (Object[] s : copyList) {
  2656. String customCodeT = (String) s[2];
  2657. if (customCode.equals(customCodeT)) {// 找到了既是唯一一条
  2658. CustomMonthlyStatFinal stat = new CustomMonthlyStatFinal();
  2659. stat.setMonth((String) s[1]);
  2660. stat.setImpDeclCount(Integer.valueOf(((BigDecimal) s[2]).toString()));
  2661. stat.setImpManDeclCount(Integer.valueOf(((BigDecimal) s[3]).toString()));
  2662. stat.setImpManualAuditDeclCount(Integer.valueOf(((BigDecimal) s[4]).toString()));
  2663. stat.setImpDeclCountLastMonth(Integer.valueOf(((BigDecimal) s[5]).toString()));
  2664. stat.setImpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[6]).toString()));
  2665. stat.setImpDeclCountCurentYear(Integer.valueOf(((BigDecimal) s[7]).toString()));
  2666. stat.setImpDeclCountYearBeforeLast(Integer.valueOf(((BigDecimal) s[8]).toString()));
  2667. stat.setImpTotalCost((BigDecimal) s[9]);
  2668. stat.setImpTotalCostLastMonth((BigDecimal) s[10]);
  2669. stat.setImpTotalCostLastYearDecember((BigDecimal) s[11]);
  2670. stat.setImpTotalCostCurentYear((BigDecimal) s[12]);
  2671. stat.setImpTotalCostYearBeforeLast((BigDecimal) s[13]);
  2672. stat.setImpCuCost((BigDecimal) s[14]);
  2673. stat.setImpCuCostLastMonth((BigDecimal) s[15]);
  2674. stat.setImpCuCostLastYearDecember((BigDecimal) s[16]);
  2675. stat.setImpCuCostCurentYear((BigDecimal) s[17]);
  2676. stat.setImpCuCostYearBeforeLast((BigDecimal) s[18]);
  2677. stat.setExpDeclCount(Integer.valueOf(((BigDecimal) s[19]).toString()));
  2678. stat.setExpManDeclCount(Integer.valueOf(((BigDecimal) s[20]).toString()));
  2679. stat.setExpManualAuditDeclCount(Integer.valueOf(((BigDecimal) s[21]).toString()));
  2680. stat.setExpDeclCountLastMonth(Integer.valueOf(((BigDecimal) s[22]).toString()));
  2681. stat.setExpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[23]).toString()));
  2682. stat.setExpDeclCountCurentYear(Integer.valueOf(((BigDecimal) s[24]).toString()));
  2683. stat.setExpDeclCountYearBeforeLast(Integer.valueOf(((BigDecimal) s[25]).toString()));
  2684. stat.setExpTotalCost((BigDecimal) s[26]);
  2685. stat.setExpTotalCostLastMonth((BigDecimal) s[27]);
  2686. stat.setExpTotalCostLastYearDecember((BigDecimal) s[28]);
  2687. stat.setExpTotalCostCurentYear((BigDecimal) s[29]);
  2688. stat.setExpTotalCostYearBeforeLast((BigDecimal) s[30]);
  2689. stat.setExpCuCost((BigDecimal) s[31]);
  2690. stat.setExpCuCostLastMonth((BigDecimal) s[32]);
  2691. stat.setExpCuCostLastYearDecember((BigDecimal) s[33]);
  2692. stat.setExpCuCostCurentYear((BigDecimal) s[34]);
  2693. stat.setExpCuCostYearBeforeLast((BigDecimal) s[35]);
  2694. stat.setId(dao.getGuidStringBySql());
  2695. customMonthlyStatFinalRepository.save(stat);
  2696. existData = true;
  2697. break;
  2698. }
  2699. }
  2700. if (!existData) {// 若不存在关区合并前的统计数据,需要补上合并后的统计记录
  2701. CustomMonthlyStatFinal stat = new CustomMonthlyStatFinal();
  2702. stat.setMonth(dataPeriod);
  2703. stat.setCustomCode(customCode);
  2704. stat.setImpDeclCount(0);
  2705. stat.setImpManDeclCount(0);
  2706. stat.setImpManualAuditDeclCount(0);
  2707. stat.setImpCuCost(zero);
  2708. stat.setImpTotalCost(zero);
  2709. stat.setExpDeclCount(0);
  2710. stat.setExpManDeclCount(0);
  2711. stat.setExpManualAuditDeclCount(0);
  2712. stat.setExpCuCost(zero);
  2713. stat.setExpTotalCost(zero);
  2714. Calendar cal = Calendar.getInstance();
  2715. Date curMonth = new Date();
  2716. try {
  2717. curMonth = monthSdf.parse(dataPeriod);
  2718. } catch (ParseException e) {
  2719. e.printStackTrace();
  2720. }
  2721. cal.setTime(curMonth);
  2722. cal.add(Calendar.MONTH, -1);
  2723. Date lastMonthDate = cal.getTime();
  2724. List<Object[]> lastMonthData = (List<Object[]>) dao.getQueryBySql("select ID,MONTH,CUSTOM_CODE,IMP_DECL_COUNT,IMP_MAN_DECL_COUNT,IMP_MANUAL_AUDIT_DECL_COUNT,IMP_DECL_COUNT_LM,IMP_DECL_COUNT_LY_DEC," +
  2725. "IMP_DECL_COUNT_CURYEAR,IMP_DECL_COUNT_YBL,IMP_TOTAL_COST,IMP_TOTAL_COST_LM,IMP_TOTAL_COST_LY_DEC,IMP_TOTAL_COST_CY,IMP_TOTAL_COST_YBL," +
  2726. "IMP_CU_COST,IMP_CU_COST_LM,IMP_CU_COST_LY_DEC,IMP_CU_COST_CY,IMP_CU_COST_YBL,EXP_DECL_COUNT,EXP_MAN_DECL_COUNT,EXP_MANUAL_AUDIT_DECL_COUNT," +
  2727. "EXP_DECL_COUNT_LM,EXP_DECL_COUNT_LY_DEC,EXP_DECL_COUNT_CURYEAR,EXP_DECL_COUNT_YBL,EXP_TOTAL_COST,EXP_TOTAL_COST_LM,EXP_TOTAL_COST_LY_DEC," +
  2728. "EXP_TOTAL_COST_CY,EXP_TOTAL_COST_YBL,EXP_CU_COST,EXP_CU_COST_LM,EXP_CU_COST_LY_DEC,EXP_CU_COST_CY,EXP_CU_COST_YBL from WXJY_CUSTOM_M_STAT_F where month = ? and CUSTOM_CODE = ?",
  2729. monthSdf.format(lastMonthDate), customCode);
  2730. if (lastMonthData != null && lastMonthData.size() > 0) {
  2731. for (Object[] s : lastMonthData) {
  2732. stat.setImpDeclCountLastMonth(Integer.valueOf(((BigDecimal) s[6]).toString()));
  2733. stat.setImpCuCostLastMonth((BigDecimal) s[15]);
  2734. stat.setImpTotalCostLastMonth((BigDecimal) s[10]);
  2735. stat.setExpDeclCountLastMonth(Integer.valueOf(((BigDecimal) s[22]).toString()));
  2736. stat.setExpCuCostLastMonth((BigDecimal) s[31]);
  2737. stat.setExpTotalCostLastMonth((BigDecimal) s[26]);
  2738. if (dataPeriod.endsWith("01")) {
  2739. stat.setImpDeclCountCurentYear(0);
  2740. stat.setImpCuCostCurentYear(zero);
  2741. stat.setImpTotalCostCurentYear(zero);
  2742. stat.setExpDeclCountCurentYear(0);
  2743. stat.setExpCuCostCurentYear(zero);
  2744. stat.setExpTotalCostCurentYear(zero);
  2745. // 去年12月也就是上个月
  2746. stat.setImpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[3]).toString()));
  2747. stat.setImpCuCostLastYearDecember((BigDecimal) s[14]);
  2748. stat.setImpTotalCostLastYearDecember((BigDecimal) s[9]);
  2749. stat.setExpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[21]).toString()));
  2750. stat.setExpCuCostLastYearDecember((BigDecimal) s[30]);
  2751. stat.setExpTotalCostLastYearDecember((BigDecimal) s[25]);
  2752. // 前年平均值需要重新查询&计算
  2753. if (dataPeriod.compareTo(noRelStatMonth) > 0) {
  2754. cal.setTime(curMonth);
  2755. cal.add(Calendar.YEAR, -1);
  2756. String lastYearJanuary = monthSdf.format(cal.getTime());
  2757. cal.add(Calendar.YEAR, -1);
  2758. String yearBeforeLastJanuary = monthSdf.format(cal.getTime());
  2759. List<Object[]> yearBeforeLastData = (List<Object[]>) dao.getQueryBySql("select ID,MONTH,CUSTOM_CODE,IMP_DECL_COUNT,IMP_MAN_DECL_COUNT,IMP_MANUAL_AUDIT_DECL_COUNT,IMP_DECL_COUNT_LM,IMP_DECL_COUNT_LY_DEC," +
  2760. "IMP_DECL_COUNT_CURYEAR,IMP_DECL_COUNT_YBL,IMP_TOTAL_COST,IMP_TOTAL_COST_LM,IMP_TOTAL_COST_LY_DEC,IMP_TOTAL_COST_CY,IMP_TOTAL_COST_YBL," +
  2761. "IMP_CU_COST,IMP_CU_COST_LM,IMP_CU_COST_LY_DEC,IMP_CU_COST_CY,IMP_CU_COST_YBL,EXP_DECL_COUNT,EXP_MAN_DECL_COUNT,EXP_MANUAL_AUDIT_DECL_COUNT," +
  2762. "EXP_DECL_COUNT_LM,EXP_DECL_COUNT_LY_DEC,EXP_DECL_COUNT_CURYEAR,EXP_DECL_COUNT_YBL,EXP_TOTAL_COST,EXP_TOTAL_COST_LM,EXP_TOTAL_COST_LY_DEC," +
  2763. "EXP_TOTAL_COST_CY,EXP_TOTAL_COST_YBL,EXP_CU_COST,EXP_CU_COST_LM,EXP_CU_COST_LY_DEC,EXP_CU_COST_CY,EXP_CU_COST_YBL from WXJY_CUSTOM_M_STAT_F where" +
  2764. " month >= ? and month < ? and CUSTOM_CODE = ?",
  2765. yearBeforeLastJanuary, lastYearJanuary, customCode);
  2766. if (yearBeforeLastData != null && yearBeforeLastData.size() > 0) {
  2767. int sumImpDeclCountYBL = 0;
  2768. BigDecimal sumImpCuCostYBL = new BigDecimal(0);
  2769. BigDecimal sumImpTotalCostYBL = new BigDecimal(0);
  2770. int sumExpDeclCountYBL = 0;
  2771. BigDecimal sumExCuCostYBL = new BigDecimal(0);
  2772. BigDecimal sumExpTotalCostYBL = new BigDecimal(0);
  2773. for (Object[] t : yearBeforeLastData) {
  2774. Integer impCount = Integer.valueOf(((BigDecimal) t[3]).toString());
  2775. if (impCount != null && impCount != 0) {
  2776. sumImpDeclCountYBL += impCount;
  2777. BigDecimal mul = new BigDecimal(impCount);
  2778. BigDecimal impCuCost = (BigDecimal) t[14];
  2779. if (impCuCost != null) {
  2780. sumImpCuCostYBL = sumImpCuCostYBL.add(impCuCost.multiply(mul));
  2781. }
  2782. BigDecimal impTotalCost = (BigDecimal) t[9];
  2783. if (impTotalCost != null) {
  2784. sumImpTotalCostYBL = sumImpTotalCostYBL.add(impTotalCost.multiply(mul));
  2785. }
  2786. }
  2787. Integer expCount = Integer.valueOf(((BigDecimal) t[21]).toString());
  2788. if (expCount != null && expCount != 0) {
  2789. sumExpDeclCountYBL += expCount;
  2790. BigDecimal mul = new BigDecimal(expCount);
  2791. BigDecimal expCuCost = (BigDecimal) t[30];
  2792. if (expCuCost != null) {
  2793. sumExCuCostYBL = sumExCuCostYBL.add(expCuCost.multiply(mul));
  2794. }
  2795. BigDecimal expTotalCost = (BigDecimal) t[25];
  2796. if (expTotalCost != null) {
  2797. sumExpTotalCostYBL = sumExpTotalCostYBL.add(expTotalCost.multiply(mul));
  2798. }
  2799. }
  2800. }
  2801. if (sumImpDeclCountYBL != 0) {
  2802. BigDecimal div = new BigDecimal(sumImpDeclCountYBL);
  2803. stat.setImpDeclCountYearBeforeLast(sumImpDeclCountYBL);
  2804. stat.setImpCuCostYearBeforeLast(sumImpCuCostYBL.divide(div, 4, BigDecimal.ROUND_HALF_UP));
  2805. stat.setImpTotalCostYearBeforeLast(sumImpTotalCostYBL.divide(div, 4, BigDecimal.ROUND_HALF_UP));
  2806. } else {
  2807. stat.setImpDeclCountYearBeforeLast(0);
  2808. stat.setImpCuCostYearBeforeLast(zero);
  2809. stat.setImpTotalCostYearBeforeLast(zero);
  2810. }
  2811. if (sumExpDeclCountYBL != 0) {
  2812. BigDecimal div = new BigDecimal(sumExpDeclCountYBL);
  2813. stat.setExpDeclCountYearBeforeLast(sumExpDeclCountYBL);
  2814. stat.setExpCuCostYearBeforeLast(sumExCuCostYBL.divide(div, 4, BigDecimal.ROUND_HALF_UP));
  2815. stat.setExpTotalCostYearBeforeLast(sumExpTotalCostYBL.divide(div, 4, BigDecimal.ROUND_HALF_UP));
  2816. } else {
  2817. stat.setExpDeclCountYearBeforeLast(0);
  2818. stat.setExpCuCostYearBeforeLast(zero);
  2819. stat.setExpTotalCostYearBeforeLast(zero);
  2820. }
  2821. } else {
  2822. stat.setImpDeclCountYearBeforeLast(0);
  2823. stat.setImpCuCostYearBeforeLast(zero);
  2824. stat.setImpTotalCostYearBeforeLast(zero);
  2825. stat.setExpDeclCountYearBeforeLast(0);
  2826. stat.setExpCuCostYearBeforeLast(zero);
  2827. stat.setExpTotalCostYearBeforeLast(zero);
  2828. }
  2829. } else {
  2830. stat.setImpDeclCountYearBeforeLast(0);
  2831. stat.setImpCuCostYearBeforeLast(zero);
  2832. stat.setImpTotalCostYearBeforeLast(zero);
  2833. stat.setExpDeclCountYearBeforeLast(0);
  2834. stat.setExpCuCostYearBeforeLast(zero);
  2835. stat.setExpTotalCostYearBeforeLast(zero);
  2836. }
  2837. } else {
  2838. stat.setImpDeclCountCurentYear(Integer.valueOf(((BigDecimal) s[8]).toString()));
  2839. stat.setImpCuCostCurentYear((BigDecimal) s[17]);
  2840. stat.setImpTotalCostCurentYear((BigDecimal) s[12]);
  2841. stat.setExpDeclCountCurentYear(Integer.valueOf(((BigDecimal) s[24]).toString()));
  2842. stat.setExpCuCostCurentYear((BigDecimal) s[33]);
  2843. stat.setExpTotalCostCurentYear((BigDecimal) s[28]);
  2844. // 去年12月数据是上个月对应字段的值
  2845. stat.setImpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[7]).toString()));
  2846. stat.setImpCuCostLastYearDecember((BigDecimal) s[16]);
  2847. stat.setImpTotalCostLastYearDecember((BigDecimal) s[11]);
  2848. stat.setExpDeclCountLastYearDecember(Integer.valueOf(((BigDecimal) s[23]).toString()));
  2849. stat.setExpCuCostLastYearDecember((BigDecimal) s[32]);
  2850. stat.setExpTotalCostLastYearDecember((BigDecimal) s[27]);
  2851. stat.setImpDeclCountYearBeforeLast(Integer.valueOf(((BigDecimal) s[9]).toString()));
  2852. stat.setImpCuCostYearBeforeLast((BigDecimal) s[18]);
  2853. stat.setImpTotalCostYearBeforeLast((BigDecimal) s[13]);
  2854. stat.setExpDeclCountYearBeforeLast(Integer.valueOf(((BigDecimal) s[25]).toString()));
  2855. stat.setExpCuCostYearBeforeLast((BigDecimal) s[34]);
  2856. stat.setExpTotalCostYearBeforeLast((BigDecimal) s[29]);
  2857. }
  2858. break;
  2859. }
  2860. } else {//要求从最早月度开始维护,则若前面数据不存在,当前月度直接设置为0
  2861. stat.setImpDeclCountCurentYear(0);
  2862. stat.setImpCuCostCurentYear(zero);
  2863. stat.setImpTotalCostCurentYear(zero);
  2864. stat.setExpDeclCountCurentYear(0);
  2865. stat.setExpCuCostCurentYear(zero);
  2866. stat.setExpTotalCostCurentYear(zero);
  2867. stat.setImpDeclCountLastMonth(0);
  2868. stat.setImpCuCostLastMonth(zero);
  2869. stat.setImpTotalCostLastMonth(zero);
  2870. stat.setExpDeclCountLastMonth(0);
  2871. stat.setExpCuCostLastMonth(zero);
  2872. stat.setExpTotalCostLastMonth(zero);
  2873. stat.setImpDeclCountLastYearDecember(0);
  2874. stat.setImpCuCostLastYearDecember(zero);
  2875. stat.setImpTotalCostLastYearDecember(zero);
  2876. stat.setExpDeclCountLastYearDecember(0);
  2877. stat.setExpCuCostLastYearDecember(zero);
  2878. stat.setExpTotalCostLastYearDecember(zero);
  2879. stat.setImpDeclCountYearBeforeLast(0);
  2880. stat.setImpCuCostYearBeforeLast(zero);
  2881. stat.setImpTotalCostYearBeforeLast(zero);
  2882. stat.setExpDeclCountYearBeforeLast(0);
  2883. stat.setExpCuCostYearBeforeLast(zero);
  2884. stat.setExpTotalCostYearBeforeLast(zero);
  2885. }
  2886. stat.setId(dao.getGuidStringBySql());
  2887. customMonthlyStatFinalRepository.save(stat);
  2888. }
  2889. } else {// 需要将一级关区及其下级关区的数据合并
  2890. sumImpDeclCount = 0;// 进口单数
  2891. sumImpManDeclCount = 0;//进口查验单数
  2892. sumImpAuditDeclCount = 0;//进口人工审单单数
  2893. sumImpDeclCountLastMonth = 0;// 上个月进口单数
  2894. sumImpDeclCountLastYearDecember = 0;// 去年12月进口单数
  2895. sumImpDeclCountCurentYear = 0;// 今年截止当月总进口单数
  2896. sumImpDeclCountYearBeforeLast = 0;// 前年总进口单数
  2897. sumExpDeclCount = 0;// 出口单数
  2898. sumExpManDeclCount = 0;//进口查验单数
  2899. sumExpAuditDeclCount = 0;//进口人工审单单数
  2900. sumExpDeclCountLastMonth = 0;// 上个月出口单数
  2901. sumExpDeclCountLastYearDecember = 0;// 去年12月进口单数
  2902. sumExpDeclCountCurentYear = 0;// 今年截止当月总出口单数
  2903. sumExpDeclCountYearBeforeLast = 0;// 前年总出口单数
  2904. // 20个消耗时间字段
  2905. sumImpTotalCost = zero;// 进口平均整体通关时间(小时)
  2906. sumImpTotalCostLastMonth = zero;// 进口平均整体通关时间-上月
  2907. sumImpTotalCostLastYearDecember = zero;// 进口平均整体通关时间-去年12月
  2908. sumImpTotalCostCurentYear = zero;// 进口平均整体通关时间-1至当月
  2909. sumImpTotalCostYearBeforeLast = zero;// 进口平均整体通关时间-前年
  2910. sumImpCuCost = zero;// 进口平均海关通关时间(小时)
  2911. sumImpCuCostLastMonth = zero;// 进口平均海关通关时间(小时)-上月
  2912. sumImpCuCostLastYearDecember = zero;// 进口平均海关通关时间-去年12月
  2913. sumImpCuCostCurentYear = zero;// 进口平均海关通关时间-1至当月
  2914. sumImpCuCostYearBeforeLast = zero;// 进口平均海关通关时间-前年
  2915. sumExpTotalCost = zero;// 出口平均整体通关时间(小时)
  2916. sumExpTotalCostLastMonth = zero;// 出口平均整体通关时间(小时)-上月
  2917. sumExpTotalCostLastYearDecember = zero; // 出口平均整体通关时间-去年12月
  2918. sumExpTotalCostCurentYear = zero;// 出口平均整体通关时间-1至当月
  2919. sumExpTotalCostYearBeforeLast = zero;// 出口平均整体通关时间-前年
  2920. sumExpCuCost = zero;// 出口平均海关通关时间(小时)
  2921. sumExpCuCostLastMonth = zero;// 出口平均海关通关时间(小时)-上月
  2922. sumExpCuCostLastYearDecember = zero;// 出口平均海关通关时间-去年12月
  2923. sumExpCuCostCurentYear = zero;// 出口平均海关通关时间-1至当月
  2924. sumExpCuCostYearBeforeLast = zero;// 出口平均海关通关时间-前年
  2925. for (Object[] s : copyList) {
  2926. if (customCode.equals((String) s[2])) {
  2927. sumImpDeclCount += Integer.valueOf(((BigDecimal) s[3]).toString());
  2928. sumImpManDeclCount += Integer.valueOf(((BigDecimal) s[4]).toString());
  2929. sumImpAuditDeclCount += Integer.valueOf(((BigDecimal) s[5]).toString());
  2930. sumImpDeclCountLastMonth += s[6] != null ? Integer.valueOf(((BigDecimal) s[6]).toString()) : 0;
  2931. sumImpDeclCountLastYearDecember += s[7] != null ? Integer.valueOf(((BigDecimal) s[7]).toString())
  2932. : 0;
  2933. sumImpDeclCountCurentYear += s[8] != null ? Integer.valueOf(((BigDecimal) s[8]).toString()) : 0;
  2934. sumImpDeclCountYearBeforeLast += s[9] != null ? Integer.valueOf(((BigDecimal) s[9]).toString()) : 0;
  2935. sumExpDeclCount += Integer.valueOf(((BigDecimal) s[20]).toString());
  2936. sumExpManDeclCount += Integer.valueOf(((BigDecimal) s[21]).toString());
  2937. sumExpAuditDeclCount += Integer.valueOf(((BigDecimal) s[22]).toString());
  2938. sumExpDeclCountLastMonth += s[23] != null ? Integer.valueOf(((BigDecimal) s[23]).toString()) : 0;
  2939. sumExpDeclCountLastYearDecember += s[24] != null ? Integer.valueOf(((BigDecimal) s[24]).toString())
  2940. : 0;
  2941. sumExpDeclCountCurentYear += s[25] != null ? Integer.valueOf(((BigDecimal) s[25]).toString()) : 0;
  2942. sumExpDeclCountYearBeforeLast += s[26] != null ? Integer.valueOf(((BigDecimal) s[26]).toString()) : 0;
  2943. BigDecimal impCurMonthMultiply = (BigDecimal) s[3];
  2944. BigDecimal impLastMonthMultiply = s[6] != null ? (BigDecimal) s[6] : new BigDecimal(0);
  2945. BigDecimal impLastYearDecemberMultiply = s[7] != null ? (BigDecimal) s[7] : new BigDecimal(0);
  2946. BigDecimal impCurYearMultiply = s[8] != null ? (BigDecimal) s[8] : new BigDecimal(0);
  2947. BigDecimal impYearBeforeLastMultiply = s[9] != null ? (BigDecimal) s[9] : new BigDecimal(0);
  2948. BigDecimal expCurMonthMultiply = (BigDecimal) s[20];
  2949. BigDecimal expLastMonthMultiply = s[23] != null ? (BigDecimal) s[23] : new BigDecimal(0);
  2950. BigDecimal expLastYearDecemberMultiply = s[24] != null ? (BigDecimal) s[24] : new BigDecimal(0);
  2951. BigDecimal expCurYearMultiply = s[25] != null ? (BigDecimal) s[25] : new BigDecimal(0);
  2952. BigDecimal expYearBeforeLastMultiply = s[26] != null ? (BigDecimal) s[26] : new BigDecimal(0);
  2953. sumImpTotalCost = s[10] != null
  2954. ? sumImpTotalCost.add(((BigDecimal) s[10]).multiply(impCurMonthMultiply))
  2955. : sumImpTotalCost;
  2956. sumImpTotalCostLastMonth = s[11] != null
  2957. ? sumImpTotalCostLastMonth.add(((BigDecimal) s[11]).multiply(impLastMonthMultiply))
  2958. : sumImpTotalCostLastMonth;
  2959. sumImpTotalCostLastYearDecember = s[12] != null
  2960. ? sumImpTotalCostLastYearDecember
  2961. .add(((BigDecimal) s[12]).multiply(impLastYearDecemberMultiply))
  2962. : sumImpTotalCostLastYearDecember;
  2963. sumImpTotalCostCurentYear = s[13] != null
  2964. ? sumImpTotalCostCurentYear.add(((BigDecimal) s[13]).multiply(impCurYearMultiply))
  2965. : sumImpTotalCostCurentYear;
  2966. sumImpTotalCostYearBeforeLast = s[14] != null
  2967. ? sumImpTotalCostYearBeforeLast.add(((BigDecimal) s[14]).multiply(impYearBeforeLastMultiply))
  2968. : sumImpTotalCostYearBeforeLast;
  2969. sumImpCuCost = s[15] != null ? sumImpCuCost.add(((BigDecimal) s[15]).multiply(impCurMonthMultiply))
  2970. : sumImpCuCost;
  2971. sumImpCuCostLastMonth = s[16] != null
  2972. ? sumImpCuCostLastMonth.add(((BigDecimal) s[16]).multiply(impLastMonthMultiply))
  2973. : sumImpCuCostLastMonth;
  2974. sumImpCuCostLastYearDecember = s[17] != null
  2975. ? sumImpCuCostLastYearDecember.add(((BigDecimal) s[17]).multiply(impLastYearDecemberMultiply))
  2976. : sumImpCuCostLastYearDecember;
  2977. sumImpCuCostCurentYear = s[18] != null
  2978. ? sumImpCuCostCurentYear.add(((BigDecimal) s[18]).multiply(impCurYearMultiply))
  2979. : sumImpCuCostCurentYear;
  2980. sumImpCuCostYearBeforeLast = s[19] != null
  2981. ? sumImpCuCostYearBeforeLast.add(((BigDecimal) s[19]).multiply(impYearBeforeLastMultiply))
  2982. : sumImpCuCostYearBeforeLast;
  2983. sumExpTotalCost = s[27] != null
  2984. ? sumExpTotalCost.add(((BigDecimal) s[27]).multiply(expCurMonthMultiply))
  2985. : sumExpTotalCost;
  2986. sumExpTotalCostLastMonth = s[28] != null
  2987. ? sumExpTotalCostLastMonth.add(((BigDecimal) s[28]).multiply(expLastMonthMultiply))
  2988. : sumExpTotalCostLastMonth;
  2989. sumExpTotalCostLastYearDecember = s[29] != null
  2990. ? sumExpTotalCostLastYearDecember
  2991. .add(((BigDecimal) s[29]).multiply(expLastYearDecemberMultiply))
  2992. : sumExpTotalCostLastYearDecember;
  2993. sumExpTotalCostCurentYear = s[30] != null
  2994. ? sumExpTotalCostCurentYear.add(((BigDecimal) s[30]).multiply(expCurYearMultiply))
  2995. : sumExpTotalCostCurentYear;
  2996. sumExpTotalCostYearBeforeLast = s[31] != null
  2997. ? sumExpTotalCostYearBeforeLast.add(((BigDecimal) s[31]).multiply(expYearBeforeLastMultiply))
  2998. : sumExpTotalCostYearBeforeLast;
  2999. sumExpCuCost = s[32] != null ? sumExpCuCost.add(((BigDecimal) s[32]).multiply(expCurMonthMultiply))
  3000. : sumExpCuCost;
  3001. sumExpCuCostLastMonth = s[33] != null
  3002. ? sumExpCuCostLastMonth.add(((BigDecimal) s[33]).multiply(expLastMonthMultiply))
  3003. : sumExpCuCostLastMonth;
  3004. sumExpCuCostLastYearDecember = s[34] != null
  3005. ? sumExpCuCostLastYearDecember.add(((BigDecimal) s[34]).multiply(expLastYearDecemberMultiply))
  3006. : sumExpCuCostLastYearDecember;
  3007. sumExpCuCostCurentYear = s[35] != null
  3008. ? sumExpCuCostCurentYear.add(((BigDecimal) s[35]).multiply(expCurYearMultiply))
  3009. : sumExpCuCostCurentYear;
  3010. sumExpCuCostYearBeforeLast = s[36] != null
  3011. ? sumExpCuCostYearBeforeLast.add(((BigDecimal) s[36]).multiply(expYearBeforeLastMultiply))
  3012. : sumExpCuCostYearBeforeLast;
  3013. }
  3014. }
  3015. CustomMonthlyStatFinal stat = new CustomMonthlyStatFinal();
  3016. stat.setMonth(dataPeriod);
  3017. stat.setCustomCode(customCode);
  3018. stat.setImpCuCost(
  3019. sumImpDeclCount == 0 ? zero : sumImpCuCost.divide(new BigDecimal(sumImpDeclCount), 4, BigDecimal.ROUND_HALF_UP));
  3020. stat.setImpCuCostCurentYear(sumImpDeclCountCurentYear == 0 ? zero
  3021. : sumImpCuCostCurentYear.divide(new BigDecimal(sumImpDeclCountCurentYear), 4, BigDecimal.ROUND_HALF_UP));
  3022. stat.setImpCuCostLastMonth(sumImpDeclCountLastMonth == 0 ? zero
  3023. : sumImpCuCostLastMonth.divide(new BigDecimal(sumImpDeclCountLastMonth), 4, BigDecimal.ROUND_HALF_UP));
  3024. stat.setImpCuCostLastYearDecember(sumImpDeclCountLastYearDecember == 0 ? zero
  3025. : sumImpCuCostLastYearDecember.divide(new BigDecimal(sumImpDeclCountLastYearDecember), 4,
  3026. BigDecimal.ROUND_HALF_UP));
  3027. stat.setImpCuCostYearBeforeLast(sumImpDeclCountYearBeforeLast == 0 ? zero
  3028. : sumImpCuCostYearBeforeLast.divide(new BigDecimal(sumImpDeclCountYearBeforeLast), 4, BigDecimal.ROUND_HALF_UP));
  3029. stat.setImpDeclCount(sumImpDeclCount);
  3030. stat.setImpManDeclCount(sumImpManDeclCount);
  3031. stat.setImpManualAuditDeclCount(sumImpAuditDeclCount);
  3032. stat.setImpDeclCountCurentYear(sumImpDeclCountCurentYear);
  3033. stat.setImpDeclCountLastMonth(sumImpDeclCountLastMonth);
  3034. stat.setImpDeclCountLastYearDecember(sumImpDeclCountLastYearDecember);
  3035. stat.setImpDeclCountYearBeforeLast(sumImpDeclCountYearBeforeLast);
  3036. stat.setImpTotalCost(
  3037. sumImpDeclCount == 0 ? zero : sumImpTotalCost.divide(new BigDecimal(sumImpDeclCount), 4, BigDecimal.ROUND_HALF_UP));
  3038. stat.setImpTotalCostCurentYear(sumImpDeclCountCurentYear == 0 ? zero
  3039. : sumImpTotalCostCurentYear.divide(new BigDecimal(sumImpDeclCountCurentYear), 4, BigDecimal.ROUND_HALF_UP));
  3040. stat.setImpTotalCostLastMonth(sumImpDeclCountLastMonth == 0 ? zero
  3041. : sumImpTotalCostLastMonth.divide(new BigDecimal(sumImpDeclCountLastMonth), 4, BigDecimal.ROUND_HALF_UP));
  3042. stat.setImpTotalCostLastYearDecember(sumImpDeclCountLastYearDecember == 0 ? zero
  3043. : sumImpTotalCostLastYearDecember.divide(new BigDecimal(sumImpDeclCountLastYearDecember), 4,
  3044. BigDecimal.ROUND_HALF_UP));
  3045. stat.setImpTotalCostYearBeforeLast(sumImpDeclCountYearBeforeLast == 0 ? zero
  3046. : sumImpTotalCostYearBeforeLast.divide(new BigDecimal(sumImpDeclCountYearBeforeLast), 4, BigDecimal.ROUND_HALF_UP));
  3047. stat.setExpCuCost(
  3048. sumExpDeclCount == 0 ? zero : sumExpCuCost.divide(new BigDecimal(sumExpDeclCount), 4, BigDecimal.ROUND_HALF_UP));
  3049. stat.setExpCuCostCurentYear(sumExpDeclCountCurentYear == 0 ? zero
  3050. : sumExpCuCostCurentYear.divide(new BigDecimal(sumExpDeclCountCurentYear), 4, BigDecimal.ROUND_HALF_UP));
  3051. stat.setExpCuCostLastMonth(sumExpDeclCountLastMonth == 0 ? zero
  3052. : sumExpCuCostLastMonth.divide(new BigDecimal(sumExpDeclCountLastMonth), 4, BigDecimal.ROUND_HALF_UP));
  3053. stat.setExpCuCostLastYearDecember(sumExpDeclCountLastYearDecember == 0 ? zero
  3054. : sumExpCuCostLastYearDecember.divide(new BigDecimal(sumExpDeclCountLastYearDecember), 4,
  3055. BigDecimal.ROUND_HALF_UP));
  3056. stat.setExpCuCostYearBeforeLast(sumExpDeclCountYearBeforeLast == 0 ? zero
  3057. : sumExpCuCostYearBeforeLast.divide(new BigDecimal(sumExpDeclCountYearBeforeLast), 4, BigDecimal.ROUND_HALF_UP));
  3058. stat.setExpDeclCount(sumExpDeclCount);
  3059. stat.setExpManDeclCount(sumExpManDeclCount);
  3060. stat.setExpManualAuditDeclCount(sumExpAuditDeclCount);
  3061. stat.setExpDeclCountCurentYear(sumExpDeclCountCurentYear);
  3062. stat.setExpDeclCountLastMonth(sumExpDeclCountLastMonth);
  3063. stat.setExpDeclCountLastYearDecember(sumExpDeclCountLastYearDecember);
  3064. stat.setExpDeclCountYearBeforeLast(sumExpDeclCountYearBeforeLast);
  3065. stat.setExpTotalCost(
  3066. sumExpDeclCount == 0 ? zero : sumExpTotalCost.divide(new BigDecimal(sumExpDeclCount), 4, BigDecimal.ROUND_HALF_UP));
  3067. stat.setExpTotalCostCurentYear(sumExpDeclCountCurentYear == 0 ? zero
  3068. : sumExpTotalCostCurentYear.divide(new BigDecimal(sumExpDeclCountCurentYear), 4, BigDecimal.ROUND_HALF_UP));
  3069. stat.setExpTotalCostLastMonth(sumExpDeclCountLastMonth == 0 ? zero
  3070. : sumExpTotalCostLastMonth.divide(new BigDecimal(sumExpDeclCountLastMonth), 4, BigDecimal.ROUND_HALF_UP));
  3071. stat.setExpTotalCostLastYearDecember(sumExpDeclCountLastYearDecember == 0 ? zero
  3072. : sumExpTotalCostLastYearDecember.divide(new BigDecimal(sumExpDeclCountLastYearDecember), 4,
  3073. BigDecimal.ROUND_HALF_UP));
  3074. stat.setExpTotalCostYearBeforeLast(sumExpDeclCountYearBeforeLast == 0 ? zero
  3075. : sumExpTotalCostYearBeforeLast.divide(new BigDecimal(sumExpDeclCountYearBeforeLast), 4, BigDecimal.ROUND_HALF_UP));
  3076. stat.setId(dao.getGuidStringBySql());
  3077. customMonthlyStatFinalRepository.save(stat);
  3078. }
  3079. }
  3080. }
  3081. /**
  3082. * 删单涉案数据
  3083. * 删单涉案每天跑近一个月数据量大导致日志打不开,现在改为只查和危险品有关的报关单数据
  3084. */
  3085. private void delSpecialAndDelHeadLogData(Date end) {
  3086. //原来写的删单只删当前时间前一天数据,这会导致重刷时间范围数据时剔除不了以前删单的单子,而涉案的总是剔除近一年的,如果刷的是一年以前的也剔除不了
  3087. //所以这里按照传递进来的时间做近一年范围剔除
  3088. //新剔除范围
  3089. Date today = null;
  3090. Calendar c = Calendar.getInstance();
  3091. try {
  3092. today = daySdf.parse(daySdf.format(end));
  3093. c.setTime(today);
  3094. } catch (ParseException e1) {
  3095. // TODO Auto-generated catch block
  3096. e1.printStackTrace();
  3097. }
  3098. String sa_sql = "";//涉案
  3099. List<String> specialEntryIds = new ArrayList<String>();
  3100. List<String> specialH2018EntryIds = new ArrayList<String>();
  3101. List<String> delEntryIds = new ArrayList<String>();
  3102. //flag 生产环境正式代码设置为true;删除5年内的涉案数据设置为false以提升效率
  3103. //刷数据后会存在很多涉案数据没有剔除干净,因此需要flag改为false跑一次,很多当天查出的报关单在前两年涉案
  3104. boolean flag = true;
  3105. if (flag) {//生产环境
  3106. // 每日维护取最近一年涉案的报关单号来过滤需要汇总的报关单
  3107. c.add(Calendar.YEAR, -1);
  3108. sa_sql = "select distinct(ENTRY_ID) from rh2k_SPECIAL_ENTRY where OP_TIME >= ? and OP_TIME < ?";
  3109. specialEntryIds = (List<String>) rh2kRepository.getQueryBySql(sa_sql, c.getTime(), today);
  3110. specialH2018EntryIds = (List<String>) h2018Dao.getQueryBySql(
  3111. "select distinct(ENTRY_ID) from ENTRY_HEAD where D_DATE >= ? and D_DATE < ? " +
  3112. "and NOTE_S like '%处罚决定书%'", c.getTime(), today);
  3113. //20231013发现退单和删单都会进ENTRY_DEL_HEAD_LOG,只有ENTRY_OP_LOG OP_TYPE第一位为0可以区分删单
  3114. delEntryIds = (List<String>) zmqdRepository.getQueryBySql(
  3115. "select distinct(ENTRY_ID) from h18c_ENTRY_OP_LOG where substr(OP_TYPE,1,1) = '0' "
  3116. + "and OP_TIME >= ? and OP_TIME < ?", c.getTime(), today);
  3117. } else {//测试环境
  3118. // 全新生成所有中间数据时,取最近5年的涉案单号,每一年涉案的单号大约几千单,2018以前的很少
  3119. c.add(Calendar.YEAR, -5);
  3120. sa_sql = "select distinct(ENTRY_ID) from rh2k_SPECIAL_ENTRY where OP_TIME >= ?";
  3121. specialEntryIds = (List<String>) rh2kRepository.getQueryBySql(sa_sql, c.getTime());
  3122. specialH2018EntryIds = (List<String>) h2018Dao.getQueryBySql(
  3123. "select distinct(ENTRY_ID) from ENTRY_HEAD where D_DATE >= ? " +
  3124. "and NOTE_S like '%处罚决定书%'", c.getTime());
  3125. try {
  3126. // 把维护记录日期当天及之后所有的的删单记录添加进过滤集合(切记:删单记录大多数在结关之后才执行,全新生成是不考虑)
  3127. delEntryIds = (List<String>) zmqdRepository.getQueryBySql("select distinct(ENTRY_ID) from h18c_ENTRY_OP_LOG "
  3128. + "where substr(OP_TYPE,1,1) = '0' and OP_TIME >= ?", daySdf.parse("20160101"));
  3129. } catch (ParseException e) {
  3130. e.printStackTrace();
  3131. }
  3132. }
  3133. //删单和涉案的单号
  3134. if (specialEntryIds != null && specialEntryIds.size() > 0) {
  3135. delEntryIds.addAll(specialEntryIds);
  3136. }
  3137. if (specialH2018EntryIds != null && specialH2018EntryIds.size() > 0) {
  3138. delEntryIds.addAll(specialH2018EntryIds);
  3139. }
  3140. if (null != delEntryIds && delEntryIds.size() > 0) {
  3141. int currentPage = 1;
  3142. int pageSize = 100;
  3143. int count = 0;
  3144. int page = (delEntryIds.size() % pageSize == 0 ? delEntryIds.size() / pageSize : delEntryIds.size() / pageSize + 1);
  3145. for (int j = 0; j < page; j++) {
  3146. StringBuilder entryIds = new StringBuilder();
  3147. int total = currentPage * pageSize;
  3148. for (int i = count; i < (delEntryIds.size() - count > 100 ? total : delEntryIds.size()); i++) {
  3149. entryIds.append("'").append(delEntryIds.get(i)).append("',");
  3150. }
  3151. entryIds.deleteCharAt(entryIds.length() - 1);
  3152. String ids = entryIds.toString();
  3153. //同步删除通过报关单号关联的商品编码信息
  3154. String sql2 = "delete from WXJY_ENTRY_LIST where ENTRY_ID in (" + ids + ")";
  3155. dao.executeUpdate(sql2);
  3156. String sql = "delete from WXJY_ENTRY_HEAD where ENTRY_ID in (" + ids + ")";
  3157. dao.executeUpdate(sql);
  3158. currentPage++;
  3159. count += pageSize;
  3160. }
  3161. }
  3162. //如果有涉案数据则需要把月度数据重刷
  3163. if (null != delEntryIds && delEntryIds.size() > 0) {
  3164. //由于删掉涉案是在当月重新刷月度数据前执行,所以需要将一级海关存放,否则合并表不生成数据
  3165. rootCustomsMap.clear();
  3166. hasMultipleCustomList.clear();
  3167. firstClassCustoms.clear();
  3168. List<PubCustomsMapping> custMapping = pubCustomsMappingRepository.findAll();
  3169. for (PubCustomsMapping m : custMapping) {
  3170. String pCustomCode = m.getMappingCode();
  3171. if (rootCustomsMap.containsValue(pCustomCode)) {
  3172. hasMultipleCustomList.add(pCustomCode);
  3173. }
  3174. rootCustomsMap.put(m.getCustomsCode(), pCustomCode);
  3175. firstClassCustoms.add(pCustomCode);
  3176. }
  3177. Calendar cl = Calendar.getInstance();
  3178. Date clNow = new Date();
  3179. Date deadline = clNow;
  3180. cl.setTime(today);
  3181. if (flag) {//生产环境
  3182. // 每日维护取最近一年涉案的报关单号来过滤需要汇总的报关单
  3183. cl.add(Calendar.YEAR, -1);
  3184. } else {//测试环境
  3185. // 全新生成所有中间数据时,取最近5年的涉案单号,每一年涉案的单号大约几千单,2018以前的很少
  3186. cl.add(Calendar.YEAR, -5);
  3187. }
  3188. while (!cl.getTime().after(deadline)) {
  3189. String dataPeriod = monthSdf.format(cl.getTime());
  3190. Date statBegin = null;
  3191. try {
  3192. statBegin = monthSdf.parse(dataPeriod);
  3193. } catch (ParseException e) {
  3194. }
  3195. cl.setTime(statBegin);
  3196. cl.add(Calendar.MONTH, 1);
  3197. Date statEnd = cl.getTime();
  3198. //每日数据不重刷
  3199. dao.executeUpdate("delete from WXJY_MID_D_M_STATUS where DATA_TYPE != ? and STAT_PERIOD = ?", EntryHead.class.getSimpleName(), dataPeriod);
  3200. monthlyDataMaintance(dataPeriod, statBegin, statEnd);
  3201. }
  3202. rootCustomsMap.clear();
  3203. hasMultipleCustomList.clear();
  3204. firstClassCustoms.clear();
  3205. logger.info("涉案删除后月份数据重刷成功");
  3206. } else {
  3207. logger.info("最近无涉案数据不需要重新生成月度数据");
  3208. }
  3209. }
  3210. }