H2018ZhOldDangerGoodsUtil.java 172 KB

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