|
|
@@ -1,245 +1,26 @@ |
|
|
|
package cn.com.taiji.bls.manager.blk; |
|
|
|
|
|
|
|
import cn.com.taiji.bls.manager.globe.GlobalTransactionManager; |
|
|
|
import cn.com.taiji.common.manager.AbstractManager; |
|
|
|
import cn.com.taiji.common.manager.net.http.ServiceHandleException; |
|
|
|
import cn.com.taiji.common.pub.StringTools; |
|
|
|
import cn.com.taiji.core.entity.basic.QtkBlackObuHis; |
|
|
|
import cn.com.taiji.core.entity.black.QtkBlackObu; |
|
|
|
import cn.com.taiji.core.entity.dict.CommonStatus; |
|
|
|
import cn.com.taiji.core.entity.dict.DataSourceEnum; |
|
|
|
import cn.com.taiji.core.entity.dict.TransactionBizType; |
|
|
|
import cn.com.taiji.core.manager.tools.QTKUtils; |
|
|
|
import cn.com.taiji.core.manager.ygz.uploader.YgzUploader; |
|
|
|
import cn.com.taiji.core.model.comm.protocol.bls.obuBlack.ObuBlackListUpload; |
|
|
|
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; |
|
|
|
import cn.com.taiji.core.model.nio.ObuBlackUploadResponse; |
|
|
|
import cn.com.taiji.core.model.nio.protocol.TransException; |
|
|
|
import cn.com.taiji.core.repo.jpa.basic.QtkBlackObuHisRepo; |
|
|
|
import cn.com.taiji.core.repo.jpa.basic.QtkObuInfoRepo; |
|
|
|
import cn.com.taiji.core.repo.jpa.black.QtkBlackObuRepo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import cn.com.taiji.core.model.comm.protocol.bls.*; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@Service("blackObuManager") |
|
|
|
public class BlackObuManagerImpl extends AbstractManager implements BlackObuManager { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private QtkBlackObuRepo blackObuRepo; |
|
|
|
@Autowired |
|
|
|
private QtkObuInfoRepo obuInfoRepo; |
|
|
|
@Autowired |
|
|
|
private QtkBlackObuHisRepo blackObuHisRepo; |
|
|
|
@Autowired |
|
|
|
private YgzUploader ygzUploader; |
|
|
|
@Autowired |
|
|
|
private GlobalTransactionManager transactionManager; |
|
|
|
private final TransactionBizType BLACK_OBU_SYNC = |
|
|
|
TransactionBizType.BLACK_OBU_SYNC; |
|
|
|
private final TransactionBizType BLACKHIS_OBU_SYNC = |
|
|
|
TransactionBizType.BLACKHIS_OBU_SYNC; |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public ObuBlackUploadResponse handleBlackObuList(List<QtkBlackObu> blackObusInDb, QtkBlackObu blackObu, |
|
|
|
ObuBlackListUpload obuBlackListUpload, ObuBlackUploadResponse response) throws ServiceHandleException { |
|
|
|
switch (obuBlackListUpload.getStatus()) { |
|
|
|
case 1://拉黑 |
|
|
|
if (obuBlackListUpload.getType() == 4) { |
|
|
|
//先上传后存储 |
|
|
|
try { |
|
|
|
response = blackUpload(obuBlackListUpload); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("营改增同步上传黑名单失败!"); |
|
|
|
} |
|
|
|
try { |
|
|
|
//仅在黑名单上传成功后进行数据库操作 |
|
|
|
if (response != null && response.getStatusCode() != null && ("200".equals(response.getStatusCode()) || response.getUploadStatus() == 2)) { |
|
|
|
if (blackObu == null) { // 本地黑名单不存在,则录入此黑名单 |
|
|
|
blackObu = new QtkBlackObu(); |
|
|
|
blackObu.setObuId(obuBlackListUpload.getObuId()); |
|
|
|
blackObu.setCreationTime(obuBlackListUpload.getCreationTime()); |
|
|
|
blackObu.setIssuerId(obuBlackListUpload.getIssuerId()); |
|
|
|
blackObu.setStatus(obuBlackListUpload.getStatus()); |
|
|
|
blackObu.setType(obuBlackListUpload.getType()); |
|
|
|
blackObu.setCreateTime(LocalDateTime.now()); |
|
|
|
blackObu.setSourceIn(obuBlackListUpload.getSourceIn()); |
|
|
|
blackObu.setSolution(obuBlackListUpload.getSolution()); |
|
|
|
blackObu.setAgencyId(obuBlackListUpload.getAgencyId()); |
|
|
|
if (obuBlackListUpload.getReason() != null) |
|
|
|
blackObu.setReason(obuBlackListUpload.getReason()); |
|
|
|
if (obuBlackListUpload.getStaffId() != null) |
|
|
|
blackObu.setStaffId(obuBlackListUpload.getStaffId()); |
|
|
|
blackObuRepo.persist(blackObu); |
|
|
|
} else { |
|
|
|
if (blackObusInDb != null && blackObusInDb.size() > 1) { |
|
|
|
if (obuBlackListUpload.getReason() != null) |
|
|
|
blackObu.setReason(obuBlackListUpload.getReason()); |
|
|
|
blackObu.setSourceIn(obuBlackListUpload.getSourceIn()); |
|
|
|
blackObu.setSolution(obuBlackListUpload.getSolution()); |
|
|
|
blackObu.setAgencyId(obuBlackListUpload.getAgencyId()); |
|
|
|
blackObuRepo.deleteAll(blackObusInDb); |
|
|
|
blackObuRepo.persist(blackObu); |
|
|
|
} |
|
|
|
} |
|
|
|
persistTransaction(BLACK_OBU_SYNC, blackObu.getId(), "XHOBU"); |
|
|
|
transactionManager.doTransactionAsyncpObu(blackObu.getId()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new TransException(response.getErrorMsg(), CommonStatus.STATUS_KF_ERROR_SAVE_FILE); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("电子标签仅可操作车型不符黑名单类型!"); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 2://反白 |
|
|
|
|
|
|
|
try { |
|
|
|
response = blackUpload(obuBlackListUpload); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("营改增同步上传白名单失败!"); |
|
|
|
} |
|
|
|
|
|
|
|
QtkBlackObuHis blackObuHis = new QtkBlackObuHis(); |
|
|
|
blackObuHis.setObuId(obuBlackListUpload.getObuId()); |
|
|
|
blackObuHis.setIssuerId(obuBlackListUpload.getIssuerId()); |
|
|
|
blackObuHis.setReleaseTime(QTKUtils.getDateString()); |
|
|
|
blackObuHis.setStatus(obuBlackListUpload.getStatus()); |
|
|
|
blackObuHis.setType(obuBlackListUpload.getType()); |
|
|
|
if (obuBlackListUpload.getReason() != null) blackObuHis.setReasonOut(obuBlackListUpload.getReason()); |
|
|
|
blackObuHis.setStaffIdOut(obuBlackListUpload.getStaffId()); |
|
|
|
blackObuHis.setSourceOut(obuBlackListUpload.getSourceIn()); |
|
|
|
blackObuHis.setLoginSourceHis(obuBlackListUpload.getLoginSource()); |
|
|
|
if (blackObu != null) { |
|
|
|
blackObuHis.setAgencyId(blackObu.getAgencyId()); |
|
|
|
blackObuHis.setSourceIn(blackObu.getSourceIn()); |
|
|
|
blackObuHis.setSolution(blackObu.getSolution()); |
|
|
|
blackObuHis.setLoginSource(blackObu.getLoginSource()); |
|
|
|
blackObuHis.setCreateTime(blackObu.getCreateTime()); |
|
|
|
blackObuHis.setCreationTime(blackObu.getCreationTime()); |
|
|
|
if (blackObu.getReason() != null) blackObuHis.setReasonIn(blackObu.getReason()); |
|
|
|
if (blackObu.getStaffId() != null) blackObuHis.setStaffIdIn(blackObu.getStaffId()); |
|
|
|
} else { |
|
|
|
try { |
|
|
|
LocalDateTime parse = LocalDateTime.parse(obuBlackListUpload.getCreationTime(), |
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")).minusDays(1l); |
|
|
|
blackObuHis.setCreateTime(LocalDateTime.now()); |
|
|
|
blackObuHis.setCreationTime(parse.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))); |
|
|
|
blackObuHis.setReasonIn("渠道未提供"); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
/** |
|
|
|
* 为解决部中心与本地黑名单不一致问题, 应先对本地黑名单进行处理,再上传反白文件 部中心的结果为: |
|
|
|
* 1.对应解除的黑名单不存的 2.反白成功 将本地在用黑名单删除,生成历史黑名单 |
|
|
|
*/ |
|
|
|
if (blackObusInDb != null && blackObusInDb.size() > 0) { |
|
|
|
// 若有多个相同的黑名单 则全部处理掉 |
|
|
|
if (response != null && response.getStatusCode() != null && ("200".equals(response.getStatusCode()) || response.getUploadStatus() == 2)) { |
|
|
|
blackObuRepo.deleteAll(blackObusInDb); |
|
|
|
blackObuHisRepo.persist(blackObuHis); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (response != null && blackObu != null && response.getStatusCode() != null && ("200".equals(response.getStatusCode()) || response.getUploadStatus() == 2)) { |
|
|
|
blackObuRepo.delete(blackObu); |
|
|
|
blackObuHisRepo.persist(blackObuHis); |
|
|
|
} |
|
|
|
} |
|
|
|
persistTransaction(BLACKHIS_OBU_SYNC, blackObu.getId(), "OBUHIS"); |
|
|
|
transactionManager.doTransactionAsyncpObu(blackObuHis.getId()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new TransException(response.getErrorMsg(), CommonStatus.STATUS_KF_ERROR_SAVE_FILE); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
return response; |
|
|
|
public AbstractBlsResponse obuIn(ObuInRequest req) throws ServiceHandleException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
protected void persistTransaction(TransactionBizType businessType, String businessId, |
|
|
|
String info) { |
|
|
|
transactionManager.persistTransaction(businessType, businessId, info); |
|
|
|
|
|
|
|
@Override |
|
|
|
public AbstractBlsResponse obuOut(ObuOutRequest req) throws ServiceHandleException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
private ObuBlackUploadResponse blackUpload(ObuBlackListUpload obuBlackListUpload) throws ServiceHandleException { |
|
|
|
ObuBlackUploadResponse response = ygzUploader.syncDoObuBlackUpload(obuBlackListUpload.getObuId(), obuBlackListUpload.getCreationTime(), obuBlackListUpload.getStatus(), |
|
|
|
obuBlackListUpload.getType(), DataSourceEnum.DSI_INTERFACE); |
|
|
|
if (response == null || !StringTools.hasText(response.getStatusCode())) { |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("省中心接口无响应!"); |
|
|
|
} else { |
|
|
|
if (!"200".equals(response.getStatusCode())) { |
|
|
|
String json = response.getResponseJson(); |
|
|
|
System.out.println(json); |
|
|
|
if (hasText(json)) { |
|
|
|
int indexOf1 = json.indexOf("对应黑名单重复上传");//卡 |
|
|
|
int indexOf2 = json.indexOf("10秒内不允许上传相同的文件"); |
|
|
|
int indexOf3 = json.indexOf("对应解除的黑名单不存在"); |
|
|
|
int indexOf4 = json.indexOf("返白黑名单重复上传"); |
|
|
|
int indexOf5 = json.indexOf("白名单生效时间比黑名单生效时间早"); |
|
|
|
int indexOf6 = json.indexOf("贵州已上传超过5000条"); |
|
|
|
int indexOf7 = json.indexOf("解除黑名单类型不存在"); |
|
|
|
if (indexOf1 > -1) { |
|
|
|
String message = "已在部黑名单中,无需再次上传!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(2); |
|
|
|
return response; |
|
|
|
} else if (indexOf2 > -1) { |
|
|
|
String message = "下黑失败,请5分钟后重试!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(-1); |
|
|
|
return response; |
|
|
|
} else if (indexOf3 > -1) { |
|
|
|
String message = "此OBU不在黑名单中!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(2); |
|
|
|
return response; |
|
|
|
} else if (indexOf4 > -1) { |
|
|
|
String message = "该黑名单已反白,无需再次上传!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(2); |
|
|
|
return response; |
|
|
|
} else if (indexOf5 > -1) { |
|
|
|
String message = "反白失败,需手工反白,请将需反白卡号反馈给管理员!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(0); |
|
|
|
return response; |
|
|
|
} else if (indexOf6 > -1) { |
|
|
|
String message = "当前版本贵州已上传超过5000条,请5分钟后再上传!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(0); |
|
|
|
return response; |
|
|
|
} else if (indexOf7 > -1) { |
|
|
|
String message = "此OBU不在黑名单中!"; |
|
|
|
response.setErrorMsg(message); |
|
|
|
response.setUploadStatus(2); |
|
|
|
return response; |
|
|
|
} else { |
|
|
|
response.setErrorMsg(response.getErrorMsg()); |
|
|
|
response.setUploadStatus(0); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
response.setUploadStatus(1); |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|
if (response.getUploadStatus() == null) { |
|
|
|
response.setUploadStatus(0); |
|
|
|
} |
|
|
|
return response; |
|
|
|
@Override |
|
|
|
public ObuQueryResponse obuQuery(ObuQueryRequest req) throws ServiceHandleException { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |