选装售后
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AflVehicleStatusInfoServiceImpl.java 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.qtzl.alterSales.manager.service;
  2. import cn.com.taiji.common.manager.net.http.ServiceHandleException;
  3. import com.alibaba.fastjson.JSON;
  4. import com.qtzl.alterSales.dao.entity.primary.AflBindInfo;
  5. import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay;
  6. import com.qtzl.alterSales.dao.entity.second.AflCenterVehicleInfo;
  7. import com.qtzl.alterSales.dao.entity.second.AflVehicleStatusHisInfo;
  8. import com.qtzl.alterSales.dao.entity.second.AflVehicleStatusInfo;
  9. import com.qtzl.alterSales.dao.repo.jpa.primary.AflBindInfoRepo;
  10. import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo;
  11. import com.qtzl.alterSales.dao.repo.jpa.second.AflCenterVehicleInfoRepo;
  12. import com.qtzl.alterSales.dao.repo.jpa.second.AflTokenRepo;
  13. import com.qtzl.alterSales.dao.repo.jpa.second.AflVehicleStatusHisInfoRepo;
  14. import com.qtzl.alterSales.dao.repo.jpa.second.AflVehicleStatusInfoRepo;
  15. import com.qtzl.alterSales.manager.enums.BlacklistOpType;
  16. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  17. import com.qtzl.alterSales.manager.model.protocol.external.VehicleBlackListRequest;
  18. import com.qtzl.alterSales.manager.model.protocol.sales.VehicleStatusListChangeRequest;
  19. import com.qtzl.alterSales.manager.service.center.SendCenterService;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.beans.BeanUtils;
  24. import org.springframework.stereotype.Service;
  25. import org.springframework.util.CollectionUtils;
  26. import javax.annotation.Resource;
  27. import java.time.LocalDateTime;
  28. import java.time.format.DateTimeFormatter;
  29. import java.util.List;
  30. /**
  31. * @author zhangxin
  32. */
  33. @Service
  34. public class AflVehicleStatusInfoServiceImpl implements AflVehicleStatusInfoService{
  35. private static final Logger log = LoggerFactory.getLogger(AflVehicleStatusInfoServiceImpl.class);
  36. @Resource
  37. AflVehicleStatusInfoRepo aflVehicleStatusInfoRepo;
  38. @Resource
  39. AflVehicleStatusHisInfoRepo aflVehicleStatusHisInfoRepo;
  40. @Resource
  41. AflCenterVehicleInfoRepo aflCenterVehicleInfoRepo;
  42. @Resource
  43. AflBindInfoRepo aflBindInfoRepo;
  44. @Resource
  45. FssPaccountPayRepo fssPaccountPayRepo;
  46. @Resource
  47. private FssBlackListManager fssBlackListManager;
  48. @Resource
  49. private AflTokenRepo aflTokenRepo;
  50. @Resource
  51. SendCenterService sendCenterService;
  52. @Override
  53. public void VehicleStatusListChange(VehicleStatusListChangeRequest request) throws ServiceHandleException {
  54. log.info("操作状态名单-请求参数为{}", JSON.toJSON(request));
  55. isParamCheck(request);
  56. AflVehicleStatusInfo aflVehicleStatusInfo = aflVehicleStatusInfoRepo.findByVehicleIdAndCardIdAndObuId(request.getVehicleId(),request.getCpuId(),request.getObuId());
  57. Boolean flash = true;
  58. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  59. if (aflVehicleStatusInfo!=null){
  60. flash=false;
  61. if (request.getType().equals(aflVehicleStatusInfo.getType())){
  62. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当为状态已为"+ BlacklistOpType.findByCode(request.getType()).getValue());
  63. }
  64. AflVehicleStatusHisInfo aflVehicleStatusHisInfo = new AflVehicleStatusHisInfo();
  65. BeanUtils.copyProperties(aflVehicleStatusInfo,aflVehicleStatusHisInfo);
  66. aflVehicleStatusHisInfoRepo.save(aflVehicleStatusHisInfo);
  67. }else{
  68. aflVehicleStatusInfo=new AflVehicleStatusInfo();
  69. BeanUtils.copyProperties(request,aflVehicleStatusInfo);
  70. }
  71. aflVehicleStatusInfo.setCreateTime(LocalDateTime.now());
  72. if (flash){
  73. AflBindInfo aflBindInfo = aflBindInfoRepo.findByVehicleId(request.getVehicleId());
  74. log.info("操作状态名单-查询车辆绑定记录为{}",JSON.toJSON(aflBindInfo));
  75. if (aflBindInfo==null){
  76. AflCenterVehicleInfo aflCenterVehicleInfo = aflCenterVehicleInfoRepo.findByVehicleId(request.getVehicleId());
  77. log.info("操作状态名单-查询车辆信息为{}",JSON.toJSON(aflCenterVehicleInfo));
  78. if (aflCenterVehicleInfo==null){
  79. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("未查询到该车辆信息");
  80. }
  81. aflVehicleStatusInfo.setPlateNum(aflCenterVehicleInfo.getPlateNum());
  82. aflVehicleStatusInfo.setPlateColor(aflCenterVehicleInfo.getPlateColor());
  83. }else {
  84. aflVehicleStatusInfo.setAgreementNum(aflBindInfo.getAgreementNum());
  85. aflVehicleStatusInfo.setPlateNum(aflBindInfo.getPlateNum());
  86. aflVehicleStatusInfo.setPlateColor(aflBindInfo.getPlateColor());
  87. }
  88. }
  89. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  90. if (BlacklistOpType.OUT.getCode().equals(request.getType())){
  91. List<FssPaccountPay> fssPaccountPays = null;
  92. if (StringUtils.isEmpty(aflVehicleStatusInfo.getAgreementNum())){
  93. fssPaccountPays = fssPaccountPayRepo.findByAgreementNum(aflVehicleStatusInfo.getAgreementNum());
  94. }else {
  95. fssPaccountPays = fssPaccountPayRepo.findByVehicleId(aflVehicleStatusInfo.getPlateNum()+"_"+aflVehicleStatusInfo.getPlateColor());
  96. }
  97. log.info("操作状态名单-查询流水记录为{}",JSON.toJSON(fssPaccountPays));
  98. if (!CollectionUtils.isEmpty(fssPaccountPays)) {
  99. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该协议号或者车辆下存在未扣款流水,不允许反白");
  100. }
  101. }
  102. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  103. VehicleBlackListRequest vehicleBlackListRequest = new VehicleBlackListRequest();
  104. BeanUtils.copyProperties(request,vehicleBlackListRequest);
  105. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
  106. vehicleBlackListRequest.setCreateTime(aflVehicleStatusInfo.getCreateTime().format(formatter));
  107. boolean implement;
  108. try {
  109. implement = fssBlackListManager.isSue(vehicleBlackListRequest, sendCenterService.getToken(request.getUniqueKey()));
  110. } catch (ServiceHandleException e) {
  111. log.error("请求部中心状态名单接口失败,请求部中心状态名单参数:{}", JSON.toJSON(vehicleBlackListRequest));
  112. e.printStackTrace();
  113. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
  114. }
  115. if (implement){
  116. aflVehicleStatusInfo.setUpdateTime(LocalDateTime.now());
  117. aflVehicleStatusInfoRepo.save(aflVehicleStatusInfo);
  118. }else {
  119. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("操作状态名单失败");
  120. }
  121. }
  122. private void isParamCheck(VehicleStatusListChangeRequest request) throws ServiceHandleException {
  123. if (request==null){
  124. log.error("下黑或返白时,需指定请求参数...");
  125. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定请求参数...");
  126. }
  127. if (request.getType()==null){
  128. log.error("下黑或返白时,需指定状态类型...");
  129. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定状态类型...");
  130. }
  131. if (request.getReason()==null){
  132. log.error("下黑或返白时,需指定状态原因...");
  133. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定状态原因...");
  134. }
  135. if (StringUtils.isEmpty(request.getVehicleId())){
  136. log.error("下黑或返白时,需指定车辆编号...");
  137. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定车辆编号...");
  138. }
  139. if (StringUtils.isEmpty(request.getCpuId())){
  140. log.error("下黑或返白时,需指定卡号...");
  141. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定卡号...");
  142. }
  143. if (StringUtils.isEmpty(request.getObuId())){
  144. log.error("下黑或返白时,需指定OBU号...");
  145. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定OBU号...");
  146. }
  147. if (StringUtils.isEmpty(request.getAgentId())){
  148. log.error("下黑或返白时,需指定下黑渠道...");
  149. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定下黑渠道...");
  150. }
  151. if (StringUtils.isEmpty(request.getUniqueKey())){
  152. log.error("下黑或返白时,需指定uniqueKey...");
  153. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定uniqueKey...");
  154. }
  155. }
  156. }