|
@@ -36,8 +36,7 @@ import org.springframework.stereotype.Repository;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -215,7 +214,7 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public RespR noCarWaybillStart(NoCarWayBill noCarWayBill) {
|
|
|
+ public RespR noCarWaybillStart(NoCarWayBill noCarWayBill,NoCarWayBill noCarWayBillDb) {
|
|
|
log.info("运单上传开始:NoCarServiceImpl.noCarWaybillStart{}",noCarWayBill);
|
|
|
//如果运单时间和当前时间差了三天,直接返回
|
|
|
if(DateUtil.getDistanceHours(noCarWayBill.getStartTime(),new Date())<-72){
|
|
@@ -240,14 +239,14 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
noCarWayBill.setUpdateTime(DateUtil.getCurrentDateStr());
|
|
|
noCarWayBill.setHisFlag(0);
|
|
|
noCarWayBill.setBillwayStatus(1);
|
|
|
- insertOrUpdateBill(noCarWayBill);
|
|
|
+ insertOrUpdateBill(noCarWayBill,noCarWayBillDb);
|
|
|
}
|
|
|
return new RespR(responseRespR.getData());
|
|
|
}
|
|
|
//插入或者更新运单
|
|
|
- public void insertOrUpdateBill(NoCarWayBill noCarWayBill){
|
|
|
+ public void insertOrUpdateBill(NoCarWayBill noCarWayBill,NoCarWayBill noCarWayBillDb){
|
|
|
|
|
|
- if(noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum()) == null){
|
|
|
+ if(noCarWayBillDb == null){
|
|
|
noCarWaybillMapper.insert(noCarWayBill);
|
|
|
}else{
|
|
|
noCarWaybillMapper.updateByBillNum(noCarWayBill);
|
|
@@ -298,11 +297,8 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
return new RespR();
|
|
|
}
|
|
|
@Override
|
|
|
- public RespR noCarWaybillEnd(NoCarWayBill noCarWayBill) {
|
|
|
+ public RespR noCarWaybillEnd(NoCarWayBill noCarWayBill,NoCarWayBill noCarWayBill1) {
|
|
|
log.info("运单结束开始:NoCarServiceImpl.noCarWaybillEnd{}",noCarWayBill);
|
|
|
- //查询运单号为开始指令
|
|
|
- NoCarWayBill noCarWayBill1 = noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
-
|
|
|
if(noCarWayBill1 == null || noCarWayBill1.getBillwayStatus() !=1 || noCarWayBill1.getHisFlag() ==1 ){
|
|
|
log.info("运单结束失败:NoCarServiceImpl.noCarWaybillEnd{},msg{}",noCarWayBill,"当前运单状态无法结束,请检查当前指令状态");
|
|
|
noCarWayBill.setFailReason("当前运单状态无法结束,请检查当前指令状态");
|
|
@@ -348,10 +344,8 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public RespR noCarHisWaybillStart(NoCarWayBill noCarWayBill) {
|
|
|
+ public RespR noCarHisWaybillStart(NoCarWayBill noCarWayBill,NoCarWayBill noCarWayBill1) {
|
|
|
log.info("历史运单开始上传:NoCarServiceImpl.noCarHisWaybillStart{},msg{}",noCarWayBill,"开始");
|
|
|
- NoCarWayBill noCarWayBill1 = noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
-
|
|
|
if(noCarWayBill1!=null && noCarWayBill1.getBillwayStatus() ==1){
|
|
|
return new RespR(false,"运单号重复");
|
|
|
}
|
|
@@ -360,8 +354,7 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
return new RespR(false,"失败,运单未满20天时效");
|
|
|
}
|
|
|
if((DateUtil.getDistanceHours(noCarWayBill.getStartTime(),DateUtil.StringToDate(noCarWayBill.getPredictEndTime()))<-96) && (noCarWayBill.getInterType() != 0)){
|
|
|
- log.info("运单结束失败:NoCarServiceImpl.noCarWaybillStart{},msg{}",noCarWayBill,"运单已经超时,请拆分");
|
|
|
- noCarWaybillMapper.updateByBillNum(noCarWayBill1);
|
|
|
+ log.info("历史运单开始上传失败:NoCarServiceImpl.noCarWaybillStart{},msg{}",noCarWayBill,"运单已经超时,请拆分");
|
|
|
return new RespR(false,"失败,承运时长超96小时");
|
|
|
}
|
|
|
|
|
@@ -381,7 +374,7 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
noCarWayBill.setUpdateTime(DateUtil.getCurrentDateStr());
|
|
|
noCarWayBill.setHisFlag(1);
|
|
|
noCarWayBill.setBillwayStatus(1);
|
|
|
- insertOrUpdateBill(noCarWayBill);
|
|
|
+ insertOrUpdateBill(noCarWayBill,noCarWayBill1);
|
|
|
}
|
|
|
return new RespR(responseRespR.getData());
|
|
|
}
|
|
@@ -408,10 +401,8 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
return waybillStartRequest;
|
|
|
}
|
|
|
@Override
|
|
|
- public RespR noCarHisWaybillEnd(NoCarWayBill noCarWayBill) {
|
|
|
+ public RespR noCarHisWaybillEnd(NoCarWayBill noCarWayBill,NoCarWayBill noCarWayBill1) {
|
|
|
log.info("历史运单结束上传:NoCarServiceImpl.noCarHisWaybillEnd{},msg{}",noCarWayBill,"开始");
|
|
|
- //查询运单号为开始指令
|
|
|
- NoCarWayBill noCarWayBill1 = noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
if(noCarWayBill1 == null || noCarWayBill1.getBillwayStatus() !=1 || noCarWayBill.getHisFlag() ==0 || noCarWayBill1.getBillwayStatus() == -3 ){
|
|
|
log.info("运单结束失败:NoCarServiceImpl.noCarWaybillEnd{},msg{}",noCarWayBill,"当前运单状态无法结束,请检查当前指令状态");
|
|
|
noCarWayBill.setFailReason("当前运单状态无法结束,请检查当前指令状态");
|
|
@@ -452,7 +443,26 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
noCarWaybillMapper.updateByBillNum(noCarWayBill1);
|
|
|
return new RespR(waybillEndResponseRespR.getData());
|
|
|
}
|
|
|
-
|
|
|
+ public WaybillNumFindInvoiceResponse buildInterFaceVoiceData(NoCarWayBill noCarWayBill,List<BillInvoice> billInvoices){
|
|
|
+ WaybillNumFindInvoiceResponse waybillNumFindInvoiceResponse = new WaybillNumFindInvoiceResponse();
|
|
|
+ List<InvoiceProcessingListModel> invoiceProcessingListModels = new ArrayList<>();
|
|
|
+ if(billInvoices != null && billInvoices.size()>0){
|
|
|
+ billInvoices.stream().forEach(billInvoice -> {
|
|
|
+ InvoiceProcessingListModel invoiceProcessingListModel = new InvoiceProcessingListModel();
|
|
|
+ BeanUtils.copyProperties(billInvoice,invoiceProcessingListModel);
|
|
|
+ invoiceProcessingListModels.add(invoiceProcessingListModel);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ waybillNumFindInvoiceResponse.setResult(invoiceProcessingListModels);
|
|
|
+ waybillNumFindInvoiceResponse.setPlateNum(noCarWayBill.getPlateNum());
|
|
|
+ waybillNumFindInvoiceResponse.setInfo("成功");
|
|
|
+ waybillNumFindInvoiceResponse.setWaybillStartTime(noCarWayBill.getStartTime());
|
|
|
+ waybillNumFindInvoiceResponse.setWaybillEndTime(noCarWayBill.getPredictEndTime());
|
|
|
+ waybillNumFindInvoiceResponse.setWaybillStatus(3);
|
|
|
+ waybillNumFindInvoiceResponse.setReceiveTime(DateUtil.getCurrentDateStr());
|
|
|
+ waybillNumFindInvoiceResponse.setWaybillNum(noCarWayBill.getBillNum());
|
|
|
+ return waybillNumFindInvoiceResponse;
|
|
|
+ }
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public RespR getInvoiceByWayBillNumReal(NoCarWayBill noCarWayBill, boolean isCurr) {
|
|
@@ -460,10 +470,16 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
NoCarWayBill noCarWayBillDb = noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
if(null == noCarWayBillDb){
|
|
|
log.info("取票失败啦:NoCarServiceImpl.getInvoiceByWayBillNumReal{},isCurr{},msg{}",noCarWayBill,isCurr,"运单号异常,无法开票");
|
|
|
- return new RespR(false,"运单号异常,无法开票");
|
|
|
+ return new RespR(false,"运单状态异常,无法开票");
|
|
|
}
|
|
|
+ if(noCarWayBillDb.getBillwayStatus() == 3){
|
|
|
+ //直接返回发票信息
|
|
|
+ List<BillInvoice> billInvoices = billInvoiceMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
+ if(noCarWayBill.getInterType() == 0){
|
|
|
+ return new RespR(buildInterFaceVoiceData(noCarWayBill,billInvoices));
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ }
|
|
|
RespR respR = checkCarWayBillAndSetInfo(noCarWayBill);
|
|
|
if(respR.getCode() == 1){
|
|
|
log.info("取票失败啦:NoCarServiceImpl.getInvoiceByWayBillNumReal{},isCurr{},msg{}",noCarWayBill,isCurr,respR.getMsg());
|
|
@@ -474,18 +490,6 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
log.info("取票失败啦:NoCarServiceImpl.getInvoiceByWayBillNumReal{},isCurr{},msg{}",noCarWayBill,isCurr,"运单转态,无法开票");
|
|
|
return new RespR(false,"运单状态无法开票");
|
|
|
}
|
|
|
- if(!isCurr){
|
|
|
- //查询本地数据库 如果有发票直接返回
|
|
|
- List<BillInvoice> billInvoices = billInvoiceMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
- if(billInvoices!=null && billInvoices.size()>0){
|
|
|
- return new RespR(billInvoices);
|
|
|
- }
|
|
|
- }
|
|
|
- if(noCarWayBillDb.getBillwayStatus() == 3 && noCarWayBill.getInterType() != 0 ){
|
|
|
- //直接返回发票信息
|
|
|
- List<BillInvoice> billInvoices = billInvoiceMapper.selectByBillNum(noCarWayBill.getBillNum());
|
|
|
- return new RespR(billInvoices);
|
|
|
- }
|
|
|
//进行取票操作
|
|
|
WaybillNumFindInvoiceRequest waybillNumFindInvoiceRequest = new WaybillNumFindInvoiceRequest();
|
|
|
String companyNum = paramService.getParamsByParamName("REQUEST_COMPANY_NUM").getParamValue();
|
|
@@ -506,6 +510,8 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
billInvoiceMapper.deleteByBillNum(noCarWayBill.getBillNum());
|
|
|
//发票入库
|
|
|
List<InvoiceProcessingListModel> invoiceProcessingListModels = responseRespR.getData().getResult();
|
|
|
+ //用set来去重计费信息
|
|
|
+ Set<NoCarCalculateInfor> carCalculateInfors = new HashSet<>();
|
|
|
invoiceProcessingListModels.stream().forEach(invoiceProcessingListModel -> {
|
|
|
BillInvoice billInvoice = buildFromInvoiceProcessingListModel(invoiceProcessingListModel);
|
|
|
billInvoice.setCompanyName(noCarWayBillDb.getCompanyName());
|
|
@@ -520,25 +526,36 @@ public class NoCarServiceImpl implements NoCarService{
|
|
|
calculateInfor.setBuyerName(invoiceProcessingListModel.getBuyerName());
|
|
|
calculateInfor.setBuyerTaxpayerCode(invoiceProcessingListModel.getBuyerTaxpayerCode());
|
|
|
calculateInfor.setInvoiceMakeTime(invoiceProcessingListModel.getInvoiceMakeTime());
|
|
|
- Param param = paramService.getParamsByParamName("CUST_NOCAR_FEE");
|
|
|
- Double fee = Double.parseDouble(param.getParamValue());
|
|
|
- calculateInfor.setFee(fee);
|
|
|
calculateInfor.setTradeId(billInvoice.getTransactionId());
|
|
|
- //先查询数据库中有没有这个交易id
|
|
|
NoCarCalculateInfor noCarCalculateInfor = calculateInforMapper.selectByTradeId(billInvoice.getTransactionId());
|
|
|
- if(noCarCalculateInfor==null){
|
|
|
- Customer customer = customerMapper.selectByCustomerName(noCarWayBill.getCustomerName());
|
|
|
- customer.setInvoiceTime(DateUtil.getCurrentDateStr());
|
|
|
- customer.setAccountBalance(MathUtil.sub(customer.getAccountBalance(),calculateInfor.getFee()));
|
|
|
- customerMapper.updateByPrimaryKeySelective(customer);
|
|
|
- calculateInfor.setCompanyLongName(customer.getCompany());
|
|
|
- calculateInforMapper.insert(calculateInfor);
|
|
|
- billInvoice.setCalculateTime(calculateInfor.getCalculateTime());
|
|
|
- }else{
|
|
|
+ if(noCarCalculateInfor!=null){
|
|
|
billInvoice.setCalculateTime(noCarCalculateInfor.getCalculateTime());
|
|
|
+ }else{
|
|
|
+ if(carCalculateInfors.add(calculateInfor)){
|
|
|
+ billInvoice.setCalculateTime(calculateInfor.getCalculateTime());
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
billInvoiceMapper.insert(billInvoice);
|
|
|
});
|
|
|
+ //统一插入交易id 和 和计费信息
|
|
|
+ Param param = paramService.getParamsByParamName("CUST_NOCAR_FEE");
|
|
|
+ Double fee = Double.parseDouble(param.getParamValue());
|
|
|
+ Customer customer = customerMapper.selectByCustomerNameForLock(noCarWayBill.getCustomerName());
|
|
|
+ customer.setInvoiceTime(DateUtil.getCurrentDateStr());
|
|
|
+ carCalculateInfors.stream().forEach(calculateInfor -> {
|
|
|
+ try {
|
|
|
+ calculateInfor.setCompanyLongName(customer.getCompany());
|
|
|
+ calculateInfor.setFee(fee);
|
|
|
+ calculateInforMapper.insert(calculateInfor);
|
|
|
+ customer.setAccountBalance(MathUtil.sub(customer.getAccountBalance(),calculateInfor.getFee()));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("重复数据来啦"+calculateInfor.getTradeId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ customerMapper.updateByPrimaryKeySelective(customer);
|
|
|
if(noCarWayBill.getInterType() == 0){
|
|
|
return new RespR(responseRespR.getData());
|
|
|
}
|