作者 朱兆平

整体处理舱单临时表如业务库处理完毕

... ... @@ -2,7 +2,7 @@
web:
upload-path: upload/
server:
port: 10002
port: 10003
servlet:
context-path: ${SERVER_CONTEXTPATH:}
spring:
... ... @@ -16,7 +16,7 @@ spring:
static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
application:
name: customAnalysisReception
name: ffmInfoAnalysisService
jackson:
serialization:
... ... @@ -32,18 +32,18 @@ spring:
#eureka主机名,会在控制页面中显示
#DEV环境关闭注册。
features:
enabled: true
enabled: false
discovery:
enabled: true
enabled: false
service-registry:
auto-registration:
enabled: true
enabled: false
datasource:
type: com.alibaba.druid.pool.DruidDataSource
#oracle
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@10.50.3.69:1521:CGODB
url: jdbc:oracle:thin:@218.28.199.134:8004:CGODB
username: CGONMS
password: 1q2w3e4r
#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
... ...
... ... @@ -4,6 +4,7 @@
*/
package com.tianbo.analysis;
import com.tianbo.analysis.task.FFMInfoHandle;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
... ... @@ -26,6 +27,9 @@ public class BootApplication {
public static void main(String[] args) {
SpringApplication.run(BootApplication.class, args);
FFMInfoHandle ffmInfoHandle = new FFMInfoHandle();
ffmInfoHandle.dealFFMInfoWithPallet();
}
@Bean
... ...
... ... @@ -5,6 +5,7 @@ import com.tianbo.analysis.model.Originmanifestsecondary;
import java.util.List;
public interface OriginmanifestsecondaryMapper {
int insert(Originmanifestsecondary record);
int insertSelective(Originmanifestsecondary record);
... ...
... ... @@ -4,11 +4,13 @@ import com.tianbo.analysis.dao.FWBINFOMapper;
import com.tianbo.analysis.dao.ORIGINMANIFESTMASTERMapper;
import com.tianbo.analysis.model.FWBINFO;
import com.tianbo.analysis.service.FWBInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class FWBInfoServiceImp implements FWBInfoService {
... ... @@ -25,6 +27,8 @@ public class FWBInfoServiceImp implements FWBInfoService {
if (fwbinfos!=null && !fwbinfos.isEmpty()){
FWBINFO _model_fwb = fwbinfos.get(0);
return originmanifestmasterMapper.updateFWBByFWBInfoAndStatus(_model_fwb);
}else {
log.info("未找到FWBINFO主单信息");
}
return 0;
}
... ...
... ... @@ -6,12 +6,14 @@ import com.tianbo.analysis.model.ORIGINMANIFESTMASTER;
import com.tianbo.analysis.service.FFMInfoService;
import com.tianbo.analysis.service.ManifestMasterService;
import com.tianbo.analysis.service.ManifestSecondService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class ManifestMasterServiceImp implements ManifestMasterService{
... ... @@ -24,6 +26,14 @@ public class ManifestMasterServiceImp implements ManifestMasterService{
@Override
public int insertManifestWithMaster(FFMInfo item){
ORIGINMANIFESTMASTER master = new ORIGINMANIFESTMASTER();
String flightDate = item.getFlightdate().toString();
String flightNo = item.getFlightno();
String weibillMaster = item.getWaybillnomaster();
String weight = item.getManifesttotalweight();
String piece = item.getManifesttotalpiece();
String destnation = item.getDestinationstation();
master.setWaybillnomaster(item.getWaybillnomaster());
master.setFlightDate(item.getFlightdate());
master.setFlightno(item.getFlightno());
... ... @@ -51,11 +61,19 @@ public class ManifestMasterServiceImp implements ManifestMasterService{
master.setIslast("");
master.setCreatedate(new Date());
log.warn(new StringBuilder("开始插入舱单数据到业务库:\n")
.append("航班号:").append(flightNo).append("/").append(flightDate)
.append("\n运单号:").append(weibillMaster)
.append("\n件/重:").append(piece).append("/").append(weight)
.append("\n目的地:").append(destnation)
.toString());
return originmanifestmasterMapper.insertSelective(master);
//写入完毕
}else {
//重复数据不操作,直接更新掉临时表数据状态
ffmInfoService.setDealstatusSuccess(item);
log.info("运单号:"+item.getWaybillnomaster()+"数据已存在与业务库不更新,更新此运单舱单临时表业务数据为已处理");
}
return 0;
}
... ...
... ... @@ -18,29 +18,49 @@ public class ManifestSecondServiceImp implements ManifestSecondService {
@Override
public int setManifestMaster(FFMInfo ffm){
int i =0;
String isBatch = ffm.getIsbatch();
isBatch = (isBatch == null) ? "" : isBatch;
//未分批的分单 如果已经挂载到主单上就不挂载了
if (isBatch.equals("T") || isBatch.equals("S") || isBatch.equals("D") || isBatch.equals("P") || isBatch.equals("M")){
}
//否则是分批标识的 要挂载到最新的航班的主单下 Todo: 这里后面判断是否需要做分批和非分批的挂载方式判定
//从分单表取属于此主单下的分单列表,更新主分单关系
List<Originmanifestsecondary> list_seondary = originmanifestsecondaryMapper.selectByFWb(ffm.getWaybillnomaster());
if (list_seondary != null && !list_seondary.isEmpty()){
for (Originmanifestsecondary manifestsecondary : list_seondary) {
//未分批的分单 如果已经挂载到主单上就不挂载了,减少数据库操作压力
if (isBatch.equals("T") || isBatch.equals("S")){
//从分单表取属于此主单下的分单列表,更新主分单关系
List<Originmanifestsecondary> list_seondary = originmanifestsecondaryMapper.selectByFWb(ffm.getWaybillnomaster());
if (list_seondary != null && !list_seondary.isEmpty()){
for (Originmanifestsecondary manifestsecondary : list_seondary) {
//分单的主单autoid
String masterAutoId = manifestsecondary.getOriginmanifestmasterautoid();
masterAutoId = (masterAutoId == null)? "" : masterAutoId ;
Originmanifestsecondary secondary = new Originmanifestsecondary();
secondary.setAutoid(manifestsecondary.getAutoid());
secondary.setOriginmanifestmasterautoid(ffm.getAutoid());
secondary.setCustomsstatus(ffm.getCustomsstatus());
int i =originmanifestsecondaryMapper.updateMasterAutoId(secondary);
return i;
//如果分单没挂过主单 开始挂
if(masterAutoId.equals("0") || masterAutoId.equals("")){
i += setManifestSecondMasterAutoId(ffm,manifestsecondary);
}
}
}
}
//否则是分批标识的 要挂载到最新的航班的主单下
if (isBatch.equals("D") || isBatch.equals("P") || isBatch.equals("M")){
List<Originmanifestsecondary> list_seondary = originmanifestsecondaryMapper.selectByFWb(ffm.getWaybillnomaster());
if (list_seondary != null && !list_seondary.isEmpty()){
for (Originmanifestsecondary manifestsecondary : list_seondary) {
i += setManifestSecondMasterAutoId(ffm,manifestsecondary);
}
}
}
return i;
}
private int setManifestSecondMasterAutoId(FFMInfo ffm,Originmanifestsecondary manifestsecondary){
return 0;
Originmanifestsecondary secondary = new Originmanifestsecondary();
secondary.setAutoid(manifestsecondary.getAutoid());
secondary.setOriginmanifestmasterautoid(ffm.getAutoid());
secondary.setCustomsstatus(ffm.getCustomsstatus());
int i =originmanifestsecondaryMapper.updateMasterAutoId(secondary);
return i;
}
}
... ...
package com.tianbo.analysis.task;
import com.netflix.discovery.converters.Auto;
import com.tianbo.analysis.dao.FWBINFOMapper;
import com.tianbo.analysis.dao.ORIGINMANIFESTMASTERMapper;
import com.tianbo.analysis.dao.OriginmanifestsecondaryMapper;
import com.tianbo.analysis.model.FFMInfo;
import com.tianbo.analysis.model.FWBINFO;
import com.tianbo.analysis.model.ORIGINMANIFESTMASTER;
import com.tianbo.analysis.model.Originmanifestsecondary;
import com.tianbo.analysis.service.FFMInfoService;
import com.tianbo.analysis.service.FWBInfoService;
import com.tianbo.analysis.service.ManifestMasterService;
import com.tianbo.analysis.service.ManifestSecondService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import javax.annotation.PostConstruct;
import java.util.List;
/**
* ffm临时业务表处理入业务库
*
* 舱单 = 航班号+航班日期+运单号
* 运单 = 运单号
*/
@Slf4j
@Component
public class FFMInfoHandle {
@Autowired
FFMInfoService ffmInfoService;
@Autowired
ORIGINMANIFESTMASTERMapper originmanifestmasterMapper;
@Autowired
ManifestMasterService manifestMasterService;
... ... @@ -38,21 +32,43 @@ public class FFMInfoHandle {
@Autowired
FWBInfoService fwbInfoService;
@Autowired
OriginmanifestsecondaryMapper originmanifestsecondaryMapper;
@Autowired
ManifestSecondService secondService;
public boolean dealFFMInfo(){
private static FFMInfoHandle ffmInfoHandle;
//通过@PostConstruct实现初始化bean之前进行的操作,解决service调用空指针问题
@PostConstruct
public void init() {
ffmInfoHandle = this;
ffmInfoHandle.ffmInfoService = this.ffmInfoService;
ffmInfoHandle.manifestMasterService = this.manifestMasterService;
ffmInfoHandle.fwbInfoService = this.fwbInfoService;
ffmInfoHandle.secondService = this.secondService;
// 初使化时将已静态化的testService实例化
}
/**
* 处理板箱非空的舱单数据入业务库
* @return
*/
public boolean dealFFMInfoWithPallet(){
boolean result =false;
try {
//1.处理板箱非空的数据
List<FFMInfo> ffmInfoList = ffmInfoService.getDistinctFlightWithPallet(false);
//1.取航班非空的板箱的运单列表数据,并且报文接收标识last存在。
List<FFMInfo> ffmInfoList = ffmInfoHandle.ffmInfoService.getDistinctFlightWithPallet(false);
if (ffmInfoList!=null && !ffmInfoList.isEmpty()){
for (FFMInfo item_f:ffmInfoList) {
String flightDate = item_f.getFlightdate().toString();
String flghtNo = item_f.getFlightno();
StringBuilder sb = new StringBuilder();
log.info(sb.append("开始处理航班:").append(flghtNo).append("/").append(flightDate).toString());
//针对补发报文处理,补发的报文: FFM_INFOB表数据,存储的报文批次01对应标识是LAST
List<FFMInfo> ffmlist_reportorder_1 = ffmInfoService.getFFMLastReportOrderByPallet(item_f,false);
List<FFMInfo> ffmlist_reportorder_1 = ffmInfoHandle.ffmInfoService.getFFMLastReportOrderByPallet(item_f,false);
/**
* 判断列表是否为空
... ... @@ -61,23 +77,8 @@ public class FFMInfoHandle {
if (ffmlist_reportorder_1 !=null && !ffmlist_reportorder_1.isEmpty()){
for (FFMInfo item:ffmlist_reportorder_1) {
//1.1 查看舱单运单业务表是否已存在运单数据,不存在则插入业务表,存在则更新临时表的数据为已处理
int Flag = 0;
Flag = manifestMasterService.insertManifestWithMaster(item);
if (Flag>0){
result = true;
//业务数据入库成功后,更新舱单待处理表的数据状态为 1,根据航班号+航班日期+主单号
ffmInfoService.setDealstatusSuccess(item);
//舱单报文入库后, 更新FWB信息,将FWB临时表的信息更新到 舱单业务表
fwbInfoService.updateFwbToManifest(item.getWaybillnomaster());
//分单挂主单
int i = secondService.setManifestMaster(item);
}
result = updateFFM2Manifest(item);
log.info(new StringBuilder("开始入库").append(item.getFlightno()).append("/").append(item.getFlightdate()).append(":").append(item.getWaybillnomaster()).toString());
}
}
/**
... ... @@ -87,43 +88,132 @@ public class FFMInfoHandle {
{
//首先确定带有LAST的ffm的最批次大序号
//根据航班号+航班日期 判断LAST报对应的报文批次
List<FFMInfo> _last = ffmInfoService.getLastReportOrder(item_f,false);
List<FFMInfo> _last_count = ffmInfoService.getLastCountByPallet(item_f,false);
List<FFMInfo> _last = ffmInfoHandle.ffmInfoService.getLastReportOrder(item_f,false);
List<FFMInfo> _last_count = ffmInfoHandle.ffmInfoService.getLastCountByPallet(item_f,false);
if (_last != null && _last.size() > 0 && _last_count != null && _last_count.size() > 0){
int mm = Integer.parseInt(_last.get(0).getReportorder());
int nn = Integer.parseInt(_last_count.get(0).getReportorder());
if (mm > 0 && nn > 0 && mm == nn){
// 业务数据 开始入库
List<FFMInfo> ffmlist = ffmInfoService.getFFMinfoByPallet(item_f,false);
List<FFMInfo> ffmlist = ffmInfoHandle.ffmInfoService.getFFMinfoByPallet(item_f,false);
if (ffmlist != null && ffmlist.size() > 0){
for (FFMInfo item:ffmlist) {
int Flag = 0;
Flag = manifestMasterService.insertManifestWithMaster(item);
result = updateFFM2Manifest(item);
log.info(new StringBuilder("开始入库").append(item.getFlightno()).append("/").append(item.getFlightdate()).append(":").append(item.getWaybillnomaster()).toString());
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
return true;
}
/**
* 查看舱单运单业务表是否已存在运单数据,不存在则插入业务表,存在则更新临时表的数据为已处理
* 将舱单临时表的数据 写入舱单业务表,并挂载主分单关系
* @param item 临时表业务数据
* @return 成功或者失败
*/
private boolean updateFFM2Manifest(FFMInfo item) {
int Flag = 0;
/**
* 舱单业务表插入数据服务,
* 插入前判定是否有此航班的运单数据,插入语成功返回 1
* 业务库存在此航班的运单数据则不会插入,并更新ffminfo临时表的此舱单的数据状态为已处理 返回 0
* @return 0 or 1
*/
Flag = ffmInfoHandle.manifestMasterService.insertManifestWithMaster(item);
log.info(new StringBuilder("运单号:").append(item.getWaybillnomaster()).append("入库数量为:").append(Flag).toString());
if (Flag > 0) {
//业务数据入库成功后,更新舱单待处理表的数据状态为 1,根据航班号+航班日期+主单号
int ffm_i = ffmInfoHandle.ffmInfoService.setDealstatusSuccess(item);
log.info(new StringBuilder("更新运单:").append(item.getWaybillnomaster()).append("舱单临时表状态为:").append("已处理:").append(ffm_i).toString());
//舱单报文入库后, 更新FWB信息,将FWB临时表的信息更新到 舱单业务表
int fwb_i=ffmInfoHandle.fwbInfoService.updateFwbToManifest(item.getWaybillnomaster());
log.info(new StringBuilder("更新运单:").append(item.getWaybillnomaster()).append("运单FWB数据到业务库:").append(fwb_i).toString());
//分单挂主单
int fhl_i = ffmInfoHandle.secondService.setManifestMaster(item);
log.info("挂载分单成功->挂载数量:"+fhl_i);
return true;
}
return false;
}
if (Flag>0){
result = true;
/**
* 处理板箱为空的舱单数据入业务库
* @return
*/
public boolean dealFFMInfoWithNullPallet(){
boolean result = false;
try{
//1.取航班非空的板箱的运单列表数据,并且报文接收标识last存在。
List<FFMInfo> listflightno0 = ffmInfoHandle.ffmInfoService.getDistinctFlightWithPallet(true);
if (listflightno0!=null && listflightno0.size()>0){
for (FFMInfo item_f:listflightno0) {
// CustomsCargoSystem.Helper.Log.ffminfo_log("舱单数据入业务库调试信息", "舱单数据入业务库调试信息(板号空).txt",
//string.Format(@"{0}入业务库开始航班号:{1},航班日期:{2}" + Environment.NewLine, DateTime.Now, item_f.flightno, item_f.flightdate));
//针对补发报文处理
List<FFMInfo> ffmlist_reportorder_1 = ffmInfoHandle.ffmInfoService.getFFMLastReportOrderByPallet(item_f,true);
//业务数据入库成功后,更新舱单待处理表的数据状态为 1,根据航班号+航班日期+主单号
ffmInfoService.setDealstatusSuccess(item);
/**
* 判断列表是否为空
* 不为空则说明 FFM只有一份,第一份报文包含LAST标识
*/
if (ffmlist_reportorder_1 !=null && !ffmlist_reportorder_1.isEmpty()){
for (FFMInfo item:ffmlist_reportorder_1) {
result = updateFFM2Manifest(item);
}
}
/**
* FFM文件多份处理
*/
else
{
//写判断逻辑 根据航班号+航班日期 判断LAST报对应的报文批次
//首先确定带有LAST的ffm的最批次大序号
//根据航班号+航班日期 判断LAST报对应的报文批次
List<FFMInfo> _last = ffmInfoHandle.ffmInfoService.getLastReportOrder(item_f,true);
List<FFMInfo> _last_count = ffmInfoHandle.ffmInfoService.getLastCountByPallet(item_f,true);
if (_last != null && _last.size() > 0 && _last_count != null && _last_count.size() > 0){
int mm = Integer.parseInt(_last.get(0).getReportorder());
int nn = Integer.parseInt(_last_count.get(0).getReportorder());
if (mm > 0 && nn > 0 && mm == nn){
// 业务数据 开始入库
//舱单报文入库后, 更新FWB信息,将FWB临时表的信息更新到 舱单业务表
fwbInfoService.updateFwbToManifest(item.getWaybillnomaster());
List<FFMInfo> ffmlist = ffmInfoHandle.ffmInfoService.getFFMinfoByPallet(item_f,true);
if (ffmlist != null && ffmlist.size() > 0){
//分单挂主单
int i = secondService.setManifestMaster(item);
}
for (FFMInfo item:ffmlist) {
result = updateFFM2Manifest(item);
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
}
... ...
... ... @@ -34,7 +34,7 @@ public class TaskAnalysis {
@Scheduled(fixedDelay = 5000)
// @Scheduled(fixedDelay = 5000)
public void startTask(){
String readDir = receptDir + "/" + today;
String backdireByDay = bakupDir + "/" + today;
... ...