选装售后
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AflVehicleStatusInfoServiceImpl.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.AflVehicleStatusHisInfoRepo;
  13. import com.qtzl.alterSales.dao.repo.jpa.second.AflVehicleStatusInfoRepo;
  14. import com.qtzl.alterSales.manager.enums.BlacklistOpType;
  15. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  16. import com.qtzl.alterSales.manager.model.protocol.external.VehicleBlackListRequest;
  17. import com.qtzl.alterSales.manager.model.protocol.sales.VehicleStatusListChangeRequest;
  18. import com.qtzl.alterSales.manager.service.center.SendCenterService;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.BeanUtils;
  23. import org.springframework.stereotype.Service;
  24. import org.springframework.util.CollectionUtils;
  25. import javax.annotation.Resource;
  26. import java.time.LocalDateTime;
  27. import java.time.format.DateTimeFormatter;
  28. import java.util.List;
  29. import java.util.UUID;
  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. SendCenterService sendCenterService;
  50. @Override
  51. public void VehicleStatusListChange(VehicleStatusListChangeRequest request) throws ServiceHandleException {
  52. log.info("操作状态名单-请求参数为{}", JSON.toJSON(request));
  53. isParamCheck(request);
  54. AflVehicleStatusInfo aflVehicleStatusInfo = aflVehicleStatusInfoRepo.findByVehicleIdAndCardIdAndObuId(request.getVehicleId(),request.getCpuId(),request.getObuId());
  55. Boolean flash = true;
  56. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
  57. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  58. if (aflVehicleStatusInfo!=null){
  59. flash=false;
  60. if (request.getType().equals(aflVehicleStatusInfo.getType())){
  61. //已存在相同类型状态名单,强制修改为手动操作
  62. aflVehicleStatusInfo.setUpdateTime(LocalDateTime.now());
  63. aflVehicleStatusInfo.setManualType(1);
  64. aflVehicleStatusInfoRepo.save(aflVehicleStatusInfo);
  65. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当为状态已为"+
  66. BlacklistOpType.findByCode(request.getType()).getValue());
  67. }
  68. // Duration dur= Duration.between(aflVehicleStatusInfo.getUpdateTime(), LocalDateTime.now() );
  69. // long minute = dur.toMinutes();
  70. // //5分钟内不允许操作
  71. // long minMinute=5L;
  72. // if (minute<minMinute){
  73. // throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("5分钟内不允许进行操作");
  74. // }
  75. AflVehicleStatusHisInfo aflVehicleStatusHisInfo = new AflVehicleStatusHisInfo();
  76. BeanUtils.copyProperties(aflVehicleStatusInfo,aflVehicleStatusHisInfo ,"insertTime");
  77. aflVehicleStatusHisInfo.setId(UUID.randomUUID().toString().replace("-", ""));
  78. aflVehicleStatusHisInfoRepo.save(aflVehicleStatusHisInfo);
  79. }else{
  80. aflVehicleStatusInfo=new AflVehicleStatusInfo();
  81. }
  82. BeanUtils.copyProperties(request,aflVehicleStatusInfo);
  83. if (StringUtils.isEmpty(request.getCreateTime()) ){
  84. aflVehicleStatusInfo.setCreateTime(LocalDateTime.now());
  85. }else {
  86. LocalDateTime createTime = null;
  87. try {
  88. createTime = LocalDateTime.parse(request.getCreateTime(), formatter);
  89. } catch (Exception e) {
  90. log.error("操作状态名单-转换时间异常,时间为{}",request.getCreateTime());
  91. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单生成时间格式有误,格式应为yyyy-MM-ddTHH:mm:ss");
  92. }
  93. aflVehicleStatusInfo.setCreateTime(createTime);
  94. }
  95. if (flash){
  96. AflBindInfo aflBindInfo = aflBindInfoRepo.findByVehicleId(request.getVehicleId());
  97. log.info("操作状态名单-查询车辆绑定记录为{}",JSON.toJSON(aflBindInfo));
  98. if (aflBindInfo==null){
  99. AflCenterVehicleInfo aflCenterVehicleInfo = aflCenterVehicleInfoRepo.findByVehicleId(request.getVehicleId());
  100. log.info("操作状态名单-查询车辆信息为{}",JSON.toJSON(aflCenterVehicleInfo));
  101. if (aflCenterVehicleInfo==null){
  102. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("未查询到该车辆信息");
  103. }
  104. aflVehicleStatusInfo.setPlateNum(aflCenterVehicleInfo.getPlateNum());
  105. aflVehicleStatusInfo.setPlateColor(aflCenterVehicleInfo.getPlateColor());
  106. }else {
  107. aflVehicleStatusInfo.setAgreementNum(aflBindInfo.getAgreementNum());
  108. aflVehicleStatusInfo.setPlateNum(aflBindInfo.getPlateNum());
  109. aflVehicleStatusInfo.setPlateColor(aflBindInfo.getPlateColor());
  110. }
  111. }
  112. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  113. if (BlacklistOpType.OUT.getCode().equals(request.getType())){
  114. List<FssPaccountPay> fssPaccountPays = null;
  115. if (StringUtils.isEmpty(aflVehicleStatusInfo.getAgreementNum())){
  116. fssPaccountPays = fssPaccountPayRepo.findByAgreementNum(aflVehicleStatusInfo.getAgreementNum());
  117. }else {
  118. fssPaccountPays = fssPaccountPayRepo.findByVehicleId(aflVehicleStatusInfo.getPlateNum()+"_"+aflVehicleStatusInfo.getPlateColor());
  119. }
  120. log.info("操作状态名单-查询流水记录为{}",JSON.toJSON(fssPaccountPays));
  121. if (!CollectionUtils.isEmpty(fssPaccountPays)) {
  122. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该协议号或者车辆下存在未扣款流水,不允许反白");
  123. }
  124. }
  125. log.info("操作状态名单-查询状态名单记录为{}",JSON.toJSON(aflVehicleStatusInfo));
  126. VehicleBlackListRequest vehicleBlackListRequest = new VehicleBlackListRequest();
  127. BeanUtils.copyProperties(request,vehicleBlackListRequest);
  128. vehicleBlackListRequest.setCreateTime(aflVehicleStatusInfo.getCreateTime().format(formatter));
  129. boolean implement;
  130. try {
  131. implement = fssBlackListManager.isSue(vehicleBlackListRequest, sendCenterService.getToken(request.getUniqueKey()));
  132. } catch (ServiceHandleException e) {
  133. log.error("请求部中心状态名单接口失败,请求部中心状态名单参数:{}", JSON.toJSON(vehicleBlackListRequest));
  134. e.printStackTrace();
  135. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
  136. }
  137. if (implement){
  138. aflVehicleStatusInfo.setUpdateTime(LocalDateTime.now());
  139. aflVehicleStatusInfo.setManualType(1);
  140. aflVehicleStatusInfoRepo.save(aflVehicleStatusInfo);
  141. }else {
  142. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("操作状态名单失败");
  143. }
  144. }
  145. private void isParamCheck(VehicleStatusListChangeRequest request) throws ServiceHandleException {
  146. if (request==null){
  147. log.error("下黑或返白时,需指定请求参数...");
  148. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定请求参数...");
  149. }
  150. if (request.getType()==null){
  151. log.error("下黑或返白时,需指定状态类型...");
  152. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定状态类型...");
  153. }
  154. if (request.getReason()==null){
  155. log.error("下黑或返白时,需指定状态原因...");
  156. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定状态原因...");
  157. }
  158. if (StringUtils.isEmpty(request.getVehicleId())){
  159. log.error("下黑或返白时,需指定车辆编号...");
  160. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定车辆编号...");
  161. }
  162. if (StringUtils.isEmpty(request.getCpuId())){
  163. log.error("下黑或返白时,需指定卡号...");
  164. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定卡号...");
  165. }
  166. if (StringUtils.isEmpty(request.getObuId())){
  167. log.error("下黑或返白时,需指定OBU号...");
  168. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定OBU号...");
  169. }
  170. if (StringUtils.isEmpty(request.getAgentId())){
  171. log.error("下黑或返白时,需指定下黑渠道...");
  172. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定下黑渠道...");
  173. }
  174. if (StringUtils.isEmpty(request.getUniqueKey())){
  175. log.error("下黑或返白时,需指定uniqueKey...");
  176. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("下黑或返白时,需指定uniqueKey...");
  177. }
  178. }
  179. }