ApiCarFreeServiceImpl.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. package com.jkcredit.invoice.hub.service.apiCarFree;
  2. import cn.com.taiji.common.manager.net.http.binclient.ApiRequestException;
  3. import cn.com.taiji.sdk.comm.ETCCommHelper;
  4. import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleQueryRequest;
  5. import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleQueryResponse;
  6. import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleRegisterRequest;
  7. import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleRegisterResponse;
  8. import cn.com.taiji.sdk.model.comm.protocol.tts.waybill.*;
  9. import com.alibaba.fastjson.JSON;
  10. import com.alibaba.fastjson.JSONObject;
  11. import com.jkcredit.invoice.hub.constant.CommonConstant;
  12. import com.jkcredit.invoice.hub.enums.ApiResponseCodeEnum;
  13. import com.jkcredit.invoice.hub.model.dto.apiCarFree.InvoiceResult;
  14. import com.jkcredit.invoice.hub.model.dto.apiCarFree.InvoiceResultDto;
  15. import com.jkcredit.invoice.hub.model.dto.apiCarFree.WayBillNumFindInvoiceDto;
  16. import com.jkcredit.invoice.hub.model.dto.carFreeCarrierBillEnd.CarFreeCarrierBillEndDto;
  17. import com.jkcredit.invoice.hub.model.dto.carFreeCarrierBillStart.CarFreeCarrierBillStartDto;
  18. import com.jkcredit.invoice.hub.model.dto.apiCarFree.VehicleRegisterDto;
  19. import com.jkcredit.invoice.hub.model.dto.searchInvoice.SearchInvoiceDto;
  20. import com.jkcredit.invoice.hub.model.po.carFreeCarrierBillStart.CarFreeCarrierBillStartPo;
  21. import com.jkcredit.invoice.hub.model.po.searchInvoice.SearchInvoicePo;
  22. import com.jkcredit.invoice.hub.service.base.BaseService;
  23. import com.jkcredit.invoice.hub.service.carFreeCarrierBillEnd.CarFreeCarrierBillEndService;
  24. import com.jkcredit.invoice.hub.service.carFreeCarrierBillStart.CarFreeCarrierBillStartService;
  25. import com.jkcredit.invoice.hub.service.searchInvoice.SearchInvoiceService;
  26. import com.jkcredit.invoice.hub.service.searchInvoiceResult.SearchInvoiceResultService;
  27. import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
  28. import com.jkcredit.invoice.hub.spi.rest.data.ApiResponseData;
  29. import com.jkcredit.invoice.hub.util.BeanUtil;
  30. import io.netty.util.internal.StringUtil;
  31. import lombok.extern.slf4j.Slf4j;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import java.io.IOException;
  36. import java.util.Date;
  37. import java.util.List;
  38. /**
  39. * @description: 无车api接口
  40. * @author: xusonglin
  41. * @create: 2020/1/16 21:52
  42. * @version: V1.0
  43. **/
  44. @Service
  45. @Slf4j
  46. public class ApiCarFreeServiceImpl extends BaseService implements ApiCarFreeService {
  47. @Autowired
  48. CarFreeCarrierBillStartService wayBillStartService;
  49. @Autowired
  50. CarFreeCarrierBillEndService wayBillEndService;
  51. @Autowired
  52. SearchInvoiceResultService searchInvoiceResultService;
  53. @Autowired
  54. SearchInvoiceService searchInvoiceService;
  55. @Autowired
  56. ApiCarFreeChargeService apiCarFreeChargeService;
  57. @Override
  58. public ApiResponseData vehicleRegisterQuery(JSONObject param) {
  59. long costTimeStart = System.currentTimeMillis();
  60. String result;
  61. try {
  62. VehicleRegisterDto dto = JSON.toJavaObject(param, VehicleRegisterDto.class);
  63. validate(dto);
  64. VehicleQueryRequest request = new VehicleQueryRequest();
  65. request.setPlateNum(dto.getPlateNumber());
  66. request.setPlateColor(dto.getPlateColor());
  67. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  68. request.setWaybillSource(CommonConstant.WAYBILL_SOURCE_1);
  69. String fileName = request.getFilename();
  70. // 调用upload 发送数据
  71. VehicleQueryResponse response = ETCCommHelper.upload(fileName, request, VehicleQueryResponse.class);
  72. result = response.toJson();
  73. long costTimeEnd = System.currentTimeMillis();
  74. log.info("[-vehicleRegisterQuery-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  75. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  76. + ",endTime=" + costTimeEnd);
  77. } catch (IOException e) {
  78. log.error("[-vehicleRegisterQuery-] 网络异常 " + e);
  79. throw new ServiceException(CommonConstant.QUERY_FAILED);
  80. } catch (ApiRequestException apie) {
  81. log.error("[-vehicleRegisterQuery-] 错误信息:" + apie.getMessage());
  82. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  83. } catch (ServiceException se) {
  84. log.error("[-vehicleRegisterQuery-] 错误信息:" + se.getMessage());
  85. throw new ServiceException(se.getMessage());
  86. }
  87. return analyzeApiResultItems(result);
  88. }
  89. @Override
  90. public ApiResponseData vehicleRegister(JSONObject param) {
  91. long costTimeStart = System.currentTimeMillis();
  92. String result;
  93. try {
  94. VehicleRegisterDto dto = JSON.toJavaObject(param, VehicleRegisterDto.class);
  95. validate(dto);
  96. VehicleRegisterRequest request = new VehicleRegisterRequest();
  97. request.setPlateNum(dto.getPlateNumber());
  98. request.setPlateColor(dto.getPlateColor());
  99. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  100. String fileName = request.getFilename();
  101. // 调用upload 发送数据
  102. VehicleRegisterResponse response = ETCCommHelper.upload(fileName, request, VehicleRegisterResponse.class);
  103. result = response.toJson();
  104. long costTimeEnd = System.currentTimeMillis();
  105. log.info("[-apiVehicleRegister-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  106. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  107. + ",endTime=" + costTimeEnd);
  108. } catch (IOException e) {
  109. log.error("[-apiVehicleRegister-] 网络异常 " + e);
  110. throw new ServiceException(CommonConstant.QUERY_FAILED);
  111. } catch (ApiRequestException apie) {
  112. log.error("[-apiVehicleRegister-] 错误信息:" + apie.getMessage());
  113. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  114. } catch (ServiceException se) {
  115. log.error("[-apiVehicleRegister-] 错误信息:" + se.getMessage());
  116. throw new ServiceException(se.getMessage());
  117. }
  118. return analyzeApiResultItems(result);
  119. }
  120. @Override
  121. public ApiResponseData wayBillStart(JSONObject param) {
  122. long costTimeStart = System.currentTimeMillis();
  123. String result;
  124. try {
  125. CarFreeCarrierBillStartDto dto = JSONObject.toJavaObject(param, CarFreeCarrierBillStartDto.class);
  126. validate(dto);
  127. WaybillStartRequest request = new WaybillStartRequest();
  128. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  129. request.setNum(dto.getNum());
  130. request.setPlateNum(dto.getPlateNumber());
  131. request.setPlateColor(dto.getPlateColor());
  132. request.setStartTime(dto.getStartTime());
  133. request.setSourceAddr(dto.getSourceAddr());
  134. request.setDestAddr(dto.getDestAddr());
  135. request.setPredictEndTime(dto.getPredictEndTime());
  136. request.setFee(dto.getFee());
  137. request.setTitleType(dto.getTitleType());
  138. if (!StringUtil.isNullOrEmpty(dto.getTaxPlayerCode())) {
  139. request.setTaxplayerCode(dto.getTaxPlayerCode());
  140. }
  141. String fileName = request.getFilename();
  142. // 调用upload 发送数据
  143. WaybillStartResponse response = ETCCommHelper.upload(fileName, request, WaybillStartResponse.class);
  144. dto.setIsHistory(CommonConstant.REALTIME_WAY_BILL);
  145. wayBillStartService.saveBillStart(dto);
  146. result = response.toJson();
  147. long costTimeEnd = System.currentTimeMillis();
  148. log.info("[-wayBillStart-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  149. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  150. + ",endTime=" + costTimeEnd);
  151. } catch (IOException e) {
  152. log.error("[-wayBillStart-] 网络异常 " + e);
  153. throw new ServiceException(CommonConstant.QUERY_FAILED);
  154. } catch (ApiRequestException apie) {
  155. log.error("[-wayBillStart-] 错误信息:" + apie.getMessage());
  156. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  157. } catch (ServiceException se) {
  158. log.error("[-wayBillStart-] 错误信息:" + se.getMessage());
  159. throw new ServiceException(se.getMessage());
  160. }
  161. return analyzeApiResultItems(result);
  162. }
  163. @Override
  164. @Transactional(rollbackFor = ServiceException.class)
  165. public ApiResponseData wayBillEnd(JSONObject param) {
  166. long costTimeStart = System.currentTimeMillis();
  167. String result;
  168. try {
  169. CarFreeCarrierBillEndDto dto = JSONObject.toJavaObject(param, CarFreeCarrierBillEndDto.class);
  170. validate(dto);
  171. WaybillEndRequest request = new WaybillEndRequest();
  172. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  173. request.setNum(dto.getNum());
  174. request.setRealDestAddr(dto.getRealDestAddr());
  175. request.setEndTime(dto.getEndTime());
  176. String fileName = request.getFilename();
  177. // 调用upload 发送数据
  178. WaybillEndResponse response = ETCCommHelper.upload(fileName, request, WaybillEndResponse.class);
  179. dto.setIsHistory(CommonConstant.REALTIME_WAY_BILL);
  180. wayBillEndService.saveBillEnd(dto);
  181. wayBillStartService.updateBillStartStatus(dto.getNum(), CommonConstant.STATUS_OVER);
  182. result = response.toJson();
  183. long costTimeEnd = System.currentTimeMillis();
  184. log.info("[-waybillEnd-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  185. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  186. + ",endTime=" + costTimeEnd);
  187. } catch (IOException e) {
  188. log.error("[-wayBillEnd-] 网络异常 " + e);
  189. throw new ServiceException(CommonConstant.QUERY_FAILED);
  190. } catch (ApiRequestException apie) {
  191. log.error("[-wayBillEnd-] 错误信息:" + apie.getMessage());
  192. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  193. } catch (ServiceException se) {
  194. log.error("[-wayBillEnd-] 错误信息:" + se.getMessage());
  195. throw new ServiceException(se.getMessage());
  196. }
  197. return analyzeApiResultItems(result);
  198. }
  199. @Override
  200. public ApiResponseData wayBillHistoryStart(JSONObject param) {
  201. long costTimeStart = System.currentTimeMillis();
  202. String result;
  203. try {
  204. CarFreeCarrierBillStartDto dto = JSONObject.toJavaObject(param, CarFreeCarrierBillStartDto.class);
  205. validate(dto);
  206. WaybillHistoryStartRequest request = new WaybillHistoryStartRequest();
  207. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  208. request.setNum(dto.getNum());
  209. request.setPlateNum(dto.getPlateNumber());
  210. request.setPlateColor(dto.getPlateColor());
  211. request.setStartTime(dto.getStartTime());
  212. request.setSourceAddr(dto.getSourceAddr());
  213. request.setDestAddr(dto.getDestAddr());
  214. request.setPredictEndTime(dto.getPredictEndTime());
  215. request.setFee(dto.getFee());
  216. request.setTitleType(dto.getTitleType());
  217. if (!StringUtil.isNullOrEmpty(dto.getTaxPlayerCode())) {
  218. request.setTaxplayerCode(dto.getTaxPlayerCode());
  219. }
  220. String fileName = request.getFilename();
  221. // 调用upload 发送数据
  222. WaybillHistoryStartResponse response = ETCCommHelper.upload(fileName, request, WaybillHistoryStartResponse.class);
  223. dto.setIsHistory(CommonConstant.HISTORY_WAY_BILL);
  224. wayBillStartService.saveBillStart(dto);
  225. result = response.toJson();
  226. long costTimeEnd = System.currentTimeMillis();
  227. log.info("[-wayBillHistoryStart-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  228. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  229. + ",endTime=" + costTimeEnd);
  230. } catch (IOException e) {
  231. log.error("[-wayBillHistoryStart-] 网络异常 " + e);
  232. throw new ServiceException(CommonConstant.QUERY_FAILED);
  233. } catch (ApiRequestException apie) {
  234. log.error("[-wayBillHistoryStart-] 错误信息:" + apie.getMessage());
  235. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  236. } catch (ServiceException se) {
  237. log.error("[-wayBillHistoryStart-] 错误信息:" + se.getMessage());
  238. throw new ServiceException(se.getMessage());
  239. }
  240. return analyzeApiResultItems(result);
  241. }
  242. @Override
  243. public ApiResponseData wayBillHistoryEnd(JSONObject param) {
  244. long costTimeStart = System.currentTimeMillis();
  245. String result;
  246. try {
  247. CarFreeCarrierBillEndDto dto = JSONObject.toJavaObject(param, CarFreeCarrierBillEndDto.class);
  248. validate(dto);
  249. WaybillHistoryEndRequest request = new WaybillHistoryEndRequest();
  250. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  251. request.setNum(dto.getNum());
  252. request.setRealDestAddr(dto.getRealDestAddr());
  253. request.setEndTime(dto.getEndTime());
  254. String fileName = request.getFilename();
  255. // 调用upload 发送数据
  256. WaybillHistoryEndResponse response = ETCCommHelper.upload(fileName, request, WaybillHistoryEndResponse.class);
  257. dto.setIsHistory(CommonConstant.HISTORY_WAY_BILL);
  258. wayBillEndService.saveBillEnd(dto);
  259. wayBillStartService.updateBillStartStatus(dto.getNum(), CommonConstant.STATUS_OVER);
  260. result = response.toJson();
  261. long costTimeEnd = System.currentTimeMillis();
  262. log.info("[-wayBillHistoryEnd-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  263. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  264. + ",endTime=" + costTimeEnd);
  265. } catch (IOException e) {
  266. log.error("[-wayBillHistoryEnd-] 网络异常 " + e);
  267. throw new ServiceException(CommonConstant.QUERY_FAILED);
  268. } catch (ApiRequestException apie) {
  269. log.error("[-wayBillHistoryEnd-] 错误信息:" + apie.getMessage());
  270. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  271. } catch (ServiceException se) {
  272. log.error("[-wayBillHistoryEnd-] 错误信息:" + se.getMessage());
  273. throw new ServiceException(se.getMessage());
  274. }
  275. return analyzeApiResultItems(result);
  276. }
  277. @Override
  278. public ApiResponseData wayBillNumFindInvoice(JSONObject param) {
  279. long costTimeStart = System.currentTimeMillis();
  280. String result;
  281. try {
  282. WayBillNumFindInvoiceDto dto = JSONObject.toJavaObject(param, WayBillNumFindInvoiceDto.class);
  283. validate(dto);
  284. WaybillNumFindInvoiceRequest request = new WaybillNumFindInvoiceRequest();
  285. request.setCompanyNum(CommonConstant.COMPANY_NUMBER);
  286. request.setWaybillNum(dto.getNum());
  287. String fileName = request.getFilename();
  288. // 调用upload 发送数据
  289. WaybillNumFindInvoiceResponse response = ETCCommHelper.upload(fileName, request, WaybillNumFindInvoiceResponse.class);
  290. result = response.toJson();
  291. long costTimeEnd = System.currentTimeMillis();
  292. log.info("[-waiBillNumFindInvoice-] result is " + result.replaceAll("\r|\n", "") + " , request is "
  293. + param + ",costtime=" + (costTimeEnd - costTimeStart) + ",startTime=" + costTimeStart
  294. + ",endTime=" + costTimeEnd);
  295. } catch (IOException e) {
  296. log.error("[-waiBillNumFindInvoice-] 网络异常 " + e);
  297. throw new ServiceException(CommonConstant.QUERY_FAILED);
  298. } catch (ApiRequestException apie) {
  299. log.error("[-waiBillNumFindInvoice-] 错误信息:" + apie.getMessage());
  300. throw new com.jkcredit.invoice.hub.spi.lang.exception.ApiRequestException(apie.getMessage());
  301. } catch (ServiceException se) {
  302. log.error("[-waiBillNumFindInvoice-] 错误信息:" + se.getMessage());
  303. throw new ServiceException(se.getMessage());
  304. }
  305. return ApiResponseData.success(ApiResponseCodeEnum.CODE_200.getValue(), result);
  306. }
  307. @Override
  308. public ApiResponseData findInvoice(JSONObject param) {
  309. try {
  310. CarFreeCarrierBillStartPo po = wayBillStartService.getBillStartByNum(param.getString("num"));
  311. if (po != null) {
  312. wayBillStartService.updateBillStartIsSearch(param.getString("num"));
  313. } else {
  314. po = new CarFreeCarrierBillStartPo();
  315. po.setUserId(param.getLong("userId"));
  316. po.setNum(param.getString("num"));
  317. }
  318. return apiCarFreeChargeService.charge(po);
  319. } catch (ServiceException se) {
  320. log.error("[-findInvoice-] 错误信息:" + se.getMessage());
  321. throw new ServiceException(se.getMessage());
  322. }
  323. }
  324. @Override
  325. public ApiResponseData findNoSearchNums(JSONObject param) {
  326. try {
  327. List<String> nums = wayBillStartService.getNoSearchNums(param.getString("userId"));
  328. return ApiResponseData.success(ApiResponseCodeEnum.CODE_200.getValue(), JSON.toJSONString(nums));
  329. } catch (ServiceException e) {
  330. log.error("[-findNoSearchNums-] 错误信息:" + e.getMessage());
  331. throw new ServiceException(e.getMessage());
  332. }
  333. }
  334. }