NoCarInterServiceImpl.java 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  1. package com.jkcredit.invoice.credit.interserver;
  2. import cn.com.taiji.sdk.model.comm.protocol.tts.vehicle.VehicleQueryResponse;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.jkcredit.invoice.common.DataResult;
  6. import com.jkcredit.invoice.mapper.binvoce.BillInvoiceMapper;
  7. import com.jkcredit.invoice.mapper.customer.CustomerCarRecMapper;
  8. import com.jkcredit.invoice.mapper.customer.CustomerMapper;
  9. import com.jkcredit.invoice.mapper.waybill.NoCarWaybillMapper;
  10. import com.jkcredit.invoice.model.entity.customer.Customer;
  11. import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
  12. import com.jkcredit.invoice.model.entity.customer.CustomerRec;
  13. import com.jkcredit.invoice.model.entity.invoice.BillInvoice;
  14. import com.jkcredit.invoice.model.entity.manager.Param;
  15. import com.jkcredit.invoice.model.entity.waybill.NoCarCompanyManger;
  16. import com.jkcredit.invoice.model.entity.waybill.NoCarWayBill;
  17. import com.jkcredit.invoice.model.entity.waybill.NoCarWayBillFileInfo;
  18. import com.jkcredit.invoice.model.vo.OperatorEditConfirmVo;
  19. import com.jkcredit.invoice.model.vo.OperatorEditVo;
  20. import com.jkcredit.invoice.model.vo.OperatorEvidenceVo;
  21. import com.jkcredit.invoice.model.vo.OperatorSendCodeVo;
  22. import com.jkcredit.invoice.service.customer.CustomerRecService;
  23. import com.jkcredit.invoice.service.lowerservice.NoCarService;
  24. import com.jkcredit.invoice.service.lowerservice.vo.HcInvoiceQueryVo;
  25. import com.jkcredit.invoice.service.manager.ParamService;
  26. import com.jkcredit.invoice.service.nocar.NoCarBillWayImportService;
  27. import com.jkcredit.invoice.service.nocar.NoCarCompanyMangerOper;
  28. import com.jkcredit.invoice.service.nocar.WayBillFileService;
  29. import com.jkcredit.invoice.util.DateUtil;
  30. import com.jkcredit.invoice.util.RespR;
  31. import com.jkcredit.invoice.util.StringUtil;
  32. import lombok.extern.slf4j.Slf4j;
  33. import net.sf.json.JSONArray;
  34. import org.apache.commons.lang3.StringUtils;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.stereotype.Service;
  37. import java.util.ArrayList;
  38. import java.util.List;
  39. import static com.jkcredit.invoice.common.CommonConst.COMPUTE;
  40. import static com.jkcredit.invoice.common.CommonConst.NOT_FOUND;
  41. import static com.jkcredit.invoice.common.CommonConst.ONE;
  42. import static com.jkcredit.invoice.common.CommonConst.REC_STATUS_UN;
  43. import static com.jkcredit.invoice.common.CommonConst.REC_STATUS_WAIT;
  44. import static com.jkcredit.invoice.common.CommonConst.RESULT;
  45. import static com.jkcredit.invoice.common.CommonConst.SELF_CAR;
  46. import static com.jkcredit.invoice.common.CommonConst.XY_WAYBILL_HISTORY_END;
  47. import static java.util.stream.Collectors.toList;
  48. /**
  49. * 无车操作接口实现类
  50. * @author mumuxigua
  51. */
  52. @Service("noCarInterService")
  53. @Slf4j
  54. public class NoCarInterServiceImpl implements NoCarInterService {
  55. private static final String PDF = "pdf";
  56. @Autowired
  57. NoCarBillWayImportService noCarWaybillMapperImprt;
  58. @Autowired
  59. CustomerCarRecMapper customerCarRecMapper;
  60. @Autowired
  61. NoCarWaybillMapper noCarWaybillMapper;
  62. @Autowired
  63. CustomerRecService customerRecMapper;
  64. @Autowired
  65. BillInvoiceMapper billInvoiceMapper;
  66. @Autowired
  67. CustomerMapper customerMapper;
  68. @Autowired
  69. ParamService paramService;
  70. @Autowired
  71. private NoCarService noCarService;
  72. @Autowired
  73. private WayBillFileService wayBillFileService;
  74. public static void main(String[] args) {
  75. List<String> list1 = new ArrayList<String>();
  76. list1.add("1");
  77. list1.add("2");
  78. list1.add("3");
  79. list1.add("5");
  80. list1.add("6");
  81. List<String> list2 = new ArrayList<String>();
  82. list2.add("2");
  83. list2.add("3");
  84. list2.add("7");
  85. list2.add("8");
  86. // 交集
  87. List<String> intersection = list1.stream().filter(item -> list2.contains(item)).collect(toList());
  88. System.out.println("---交集 intersection---");
  89. intersection.parallelStream().forEach(System.out::println);
  90. // 差集 (list1 - list2)
  91. List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(toList());
  92. System.out.println("---差集 reduce1 (list1 - list2)---");
  93. // 并集
  94. reduce1.parallelStream().forEach(System.out::println);
  95. List<String> listAll = list1.parallelStream().collect(toList());
  96. List<String> listAll2 = list2.parallelStream().collect(toList());
  97. listAll.addAll(listAll2);
  98. System.out.println("---并集 listAll---");
  99. listAll.parallelStream().forEachOrdered(System.out::println);
  100. // 去重并集
  101. List<String> listAllDistinct = listAll.stream().distinct().collect(toList());
  102. System.out.println("---得到去重并集 listAllDistinct---");
  103. listAllDistinct.parallelStream().forEachOrdered(System.out::println);
  104. System.out.println("---原来的List1---");
  105. list1.parallelStream().forEachOrdered(System.out::println);
  106. System.out.println("---原来的List2---");
  107. list2.parallelStream().forEachOrdered(System.out::println);
  108. }
  109. /**
  110. * 无车 车辆备案接口
  111. *
  112. * @param appKey
  113. * @param api
  114. * @param data
  115. * @return
  116. */
  117. @Override
  118. public DataResult customerCarRec(String appKey, String api, String data, String requestid) {
  119. long costtimestart = System.currentTimeMillis();
  120. DataResult result = new DataResult();
  121. result.setData(3);
  122. result.setCode(200);
  123. result.setRequestid(requestid);
  124. result.setMsg("无法认证");
  125. try {
  126. log.info("[-NoCarInterServiceImpl.customerCarRec-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  127. JSONObject jsonObject = JSONObject.parseObject(data);
  128. //企业名称 选输
  129. String companyName = jsonObject.getString("companyName");
  130. //plateNumber 必输
  131. String plateNumber = jsonObject.getString("plateNumber");
  132. //plateColor 必输
  133. String plateColor = jsonObject.getString("plateColor");
  134. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(plateNumber)
  135. || StringUtils.isEmpty(plateColor)
  136. ) {
  137. result.setMsg("必传参数有空值");
  138. return result;
  139. }
  140. List<CustomerCarRec> customerCarRecList = new ArrayList<CustomerCarRec>();
  141. CustomerCarRec customerCarRec = new CustomerCarRec();
  142. customerCarRec.setCustomerName(appKey);
  143. Customer cust = customerMapper.selectByCustomerName(appKey);
  144. CustomerRec customerRec = new CustomerRec();
  145. customerRec.setCustomerName(appKey);
  146. customerRec.setCompanyName(cust.getCompany());
  147. CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompany(customerRec);
  148. if (null == customerRec1) {
  149. result.setMsg("该客户: " + appKey + " 未备案企业");
  150. return result;
  151. }
  152. customerCarRec.setCompanyName(customerRec1.getCompanyName());
  153. customerCarRec.setCustomerName(customerRec1.getCustomerName());
  154. //无车
  155. customerCarRec.setBusinessType("2");
  156. customerCarRec.setCarColor(plateColor);
  157. customerCarRec.setCarNum(plateNumber);
  158. customerCarRec.setInterType(0);
  159. if (SELF_CAR.equals(customerCarRec.getCarColor())) {
  160. //默认运营车辆
  161. customerCarRec.setServiceOperation(1);
  162. }
  163. customerCarRecList.add(customerCarRec);
  164. return getDataResultss(data, costtimestart, result, noCarService.customerCarRec(customerCarRecList), "[-NoCarInterServiceImpl.customerCarRec-] result is ");
  165. } catch (Exception e) {
  166. log.error("[-NoCarInterServiceImpl.customerCarRec-] get httpclient exception is "
  167. + e + ", request is " + data);
  168. }
  169. return result;
  170. }
  171. /**
  172. * 无车 车辆备案查询接口
  173. *
  174. * @param appKey
  175. * @param api
  176. * @param data
  177. * @return
  178. */
  179. @Override
  180. public DataResult customeRecUpperQuery(String appKey, String api, String data, String requestid) {
  181. long costtimestart = System.currentTimeMillis();
  182. DataResult result = new DataResult();
  183. result.setData(3);
  184. result.setCode(200);
  185. result.setRequestid(requestid);
  186. result.setMsg("无法认证");
  187. try {
  188. log.info("[-NoCarInterServiceImpl.customeRecUpperQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  189. JSONObject jsonObject = JSONObject.parseObject(data);
  190. //备案来源 选输
  191. String waybillSource = jsonObject.getString("waybillSource");
  192. //plateNumber 必输
  193. String plateNumber = jsonObject.getString("plateNumber");
  194. //plateColor 必输
  195. String plateColor = jsonObject.getString("plateColor");
  196. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(plateNumber)
  197. || StringUtils.isEmpty(plateColor)
  198. ) {
  199. result.setMsg("必传参数有空值");
  200. return result;
  201. }
  202. CustomerCarRec customerCarRec = new CustomerCarRec();
  203. Param param = paramService.getParamsByParamName("REQUEST_COMPANY_NUM");
  204. //无车,车辆备案,运单上传,运单查询都是统一用交科的企业编号;自有车用客户的企业编号
  205. customerCarRec.setCompanyNum(param.getParamValue());
  206. customerCarRec.setCarColor(plateColor);
  207. customerCarRec.setCarNum(plateNumber);
  208. customerCarRec.setCustomerName(appKey);
  209. //无车
  210. customerCarRec.setBusinessType("2");
  211. //此处代表仅查询上游接口,无任何处理逻辑
  212. customerCarRec.setInterType(8);
  213. RespR rs = noCarService.customerCarRecQueryUpper(customerCarRec);
  214. long costtimeend = System.currentTimeMillis();
  215. log.info("[-NoCarInterServiceImpl.customeRecUpperQuery-] result is "
  216. + rs.toString() + ", request is " + data + " ,costtime="
  217. + (costtimeend - costtimestart));
  218. if (null != rs && rs.getCode() == 0) {
  219. result.setData(1);
  220. result.setCode(200);
  221. result.setMsg(rs.getData().toString());
  222. JSONObject jb = JSONObject.parseObject(rs.getData().toString());
  223. result.setData(1);
  224. result.setMsg("车辆已备案");
  225. if (null == jb.getJSONArray(RESULT) || jb.getJSONArray(RESULT).size() == 0) {
  226. result.setData(2);
  227. result.setMsg("车辆未备案");
  228. }
  229. return result;
  230. } else {
  231. result.setData(3);
  232. result.setCode(200);
  233. result.setMsg("查询失败");
  234. return result;
  235. }
  236. } catch (Exception e) {
  237. log.error("[-NoCarInterServiceImpl.customeRecUpperQuery-] get httpclient exception is "
  238. + e + ", request is " + data);
  239. }
  240. return result;
  241. }
  242. /**
  243. * 无车 实时运单开始指令接口
  244. *
  245. * @param appKey
  246. * @param api
  247. * @param data
  248. * @return
  249. */
  250. @Override
  251. public DataResult noCarBillStart(String appKey, String api, String data, String requestid) {
  252. long costtimestart = System.currentTimeMillis();
  253. DataResult result = new DataResult();
  254. result.setData(3);
  255. result.setCode(200);
  256. result.setRequestid(requestid);
  257. result.setMsg("无法认证");
  258. try {
  259. log.info("[-NoCarInterServiceImpl.noCarBillStart-] request appKey=" + appKey + " ,api=" + api + " ,data=" + StringUtil.removeJSonField(data,"base64Str") + " ,requestid=" + requestid);
  260. JSONObject jsonObject = JSONObject.parseObject(data);
  261. //运单编号 必选
  262. String num = jsonObject.getString("num");
  263. //车牌号 必选
  264. String plateNumber = jsonObject.getString("plateNumber");
  265. //车牌颜色 必选
  266. String plateColor = jsonObject.getString("plateColor");
  267. //运单开始时间 必选
  268. String startTime = jsonObject.getString("startTime");
  269. //运单开始地址 必选
  270. String sourceAddr = jsonObject.getString("sourceAddr");
  271. //运单目的地址 必选
  272. String destAddr = jsonObject.getString("destAddr");
  273. //运单预计完成时间 必选
  274. String predictEndTime = jsonObject.getString("predictEndTime");
  275. //运单费用 必选
  276. Integer fee = jsonObject.getInteger("fee");
  277. //发票抬头类型 必选
  278. Integer titleType = jsonObject.getInteger("titleType");
  279. //税号 必选
  280. String taxplayerCode = jsonObject.getString("taxplayerCode");
  281. //base流文件 必选
  282. String base64Str = jsonObject.getString("base64Str");
  283. //运单协议名称 必选
  284. String waybillFileName = jsonObject.getString("waybillFileName");
  285. //运单类型 必选
  286. Integer contractType = jsonObject.getInteger("contractType");
  287. if (StringUtils.isEmpty(data) || null == jsonObject
  288. || StringUtils.isEmpty(num)
  289. || StringUtils.isEmpty(plateNumber)
  290. || StringUtils.isEmpty(plateColor)
  291. || StringUtils.isEmpty(startTime)
  292. || StringUtils.isEmpty(sourceAddr)
  293. || StringUtils.isEmpty(destAddr)
  294. || StringUtils.isEmpty(predictEndTime)
  295. || null == fee
  296. || null == titleType
  297. || StringUtils.isEmpty(taxplayerCode)
  298. || StringUtils.isEmpty(base64Str)
  299. || StringUtils.isEmpty(waybillFileName)
  300. || null == contractType
  301. ) {
  302. result.setMsg("必传参数有空值");
  303. return result;
  304. }
  305. if (!DateUtil.isValidDate(startTime)) {
  306. result.setMsg("日期格式有误");
  307. return result;
  308. }
  309. if (!DateUtil.isValidDate(predictEndTime)) {
  310. result.setMsg("日期格式有误");
  311. return result;
  312. }
  313. if(StringUtils.isNotBlank(waybillFileName) && StringUtils.isNotBlank(base64Str) && null != contractType){
  314. String fileType = waybillFileName.substring(waybillFileName.lastIndexOf(".") + 1).toLowerCase();
  315. if (!PDF.equals(fileType)) {
  316. result.setMsg("必须是pdf文件!");
  317. return result;
  318. }
  319. int base64StrLength = base64Str.length();
  320. if (COMPUTE < base64StrLength) {
  321. result.setMsg("pdf不可超过10M!");
  322. return result;
  323. }
  324. base64Str = base64Str.replaceAll(" ", "+");
  325. }
  326. CustomerRec customerRec = new CustomerRec();
  327. customerRec.setCustomerName(appKey);
  328. customerRec.setCompanyReferencenum(taxplayerCode);
  329. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  330. if (customerRec == null || customerRec.getRecStatus() != 1) {
  331. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  332. return result;
  333. }
  334. NoCarWayBill noCarWayBill = getNoCarWayBill(appKey, num, plateNumber, plateColor, startTime, sourceAddr, destAddr, predictEndTime, fee, titleType, taxplayerCode, customerRec);
  335. noCarWayBill.setWaybillFileName(waybillFileName);
  336. noCarWayBill.setBase64Str(base64Str);
  337. noCarWayBill.setContractType(contractType);
  338. DataResult dataResult = getDataResult(appKey, data, costtimestart, result, customerRec, noCarWayBill);
  339. try {
  340. if(dataResult.getData() == 1 && dataResult.getCode()==200 && StringUtils.isNotBlank(waybillFileName) && StringUtils.isNotBlank(base64Str)){
  341. NoCarWayBillFileInfo noCarWayBillFileInfo = new NoCarWayBillFileInfo();
  342. noCarWayBillFileInfo.setBase64Str(base64Str);
  343. noCarWayBillFileInfo.setFileName(waybillFileName);
  344. noCarWayBillFileInfo.setBatchNum("接口运单");
  345. noCarWayBillFileInfo.setWayBillNum(num);
  346. noCarWayBillFileInfo.setCustomerId(appKey);
  347. noCarWayBillFileInfo.setCompanyName(noCarWayBill.getCompanyName());
  348. noCarWayBillFileInfo.setUpdateTime(DateUtil.getCurrentDateStr());
  349. wayBillFileService.insert(noCarWayBillFileInfo);
  350. }
  351. }catch (Exception e){
  352. e.printStackTrace();
  353. log.info("文件入表失败{}",noCarWayBill.getBillNum());
  354. }
  355. return dataResult;
  356. } catch (Exception e) {
  357. log.error("[-NoCarInterServiceImpl.noCarBillStart-] get httpclient exception is "
  358. + e + ", request is " + StringUtil.removeJSonField(data,"base64Str"));
  359. }
  360. return result;
  361. }
  362. private DataResult getDataResult(String appKey, String data, long costtimestart, DataResult result, CustomerRec customerRec, NoCarWayBill noCarWayBill) {
  363. List<CustomerCarRec> customerCarRecs = new ArrayList<>();
  364. CustomerCarRec customerCarRec = new CustomerCarRec();
  365. customerCarRec.setCompanyName(noCarWayBill.getCompanyName());
  366. customerCarRec.setCarNum(noCarWayBill.getPlateNum());
  367. customerCarRec.setCarColor(noCarWayBill.getPlateColor());
  368. customerCarRec.setCustomerName(appKey);
  369. //接口
  370. customerCarRec.setInterType(0);
  371. customerCarRec.setCompanyNum(customerRec.getCompanyNum());
  372. customerCarRec.setBusinessType("2");
  373. //默认运营车辆
  374. customerCarRec.setServiceOperation(1);
  375. noCarWayBill.setTitleType(2);
  376. //接口
  377. noCarWayBill.setInterType(0);
  378. return getDataResult(data, costtimestart, result, noCarWayBill, customerCarRecs, customerCarRec);
  379. }
  380. private NoCarWayBill getNoCarWayBill(String appKey, String num, String plateNumber, String plateColor, String startTime, String sourceAddr, String destAddr, String predictEndTime, Integer fee, Integer titleType, String taxplayerCode, CustomerRec customerRec) {
  381. NoCarWayBill noCarWayBill = new NoCarWayBill();
  382. noCarWayBill.setCustomerName(appKey);
  383. noCarWayBill.setCompanyName(customerRec.getCompanyName());
  384. noCarWayBill.setPlateNum(plateNumber);
  385. noCarWayBill.setBillNum(num);
  386. noCarWayBill.setPlateColor(plateColor);
  387. noCarWayBill.setStartTime(DateUtil.getDistanceHoursFormat(startTime));
  388. noCarWayBill.setSourceAddr(sourceAddr);
  389. noCarWayBill.setDestAddr(destAddr);
  390. noCarWayBill.setPredictEndTime(DateUtil.getDistanceHoursFormat(predictEndTime));
  391. noCarWayBill.setFee(fee.longValue());
  392. noCarWayBill.setTitleType(titleType);
  393. noCarWayBill.setTaxplayerCode(taxplayerCode);
  394. noCarWayBill.setHisFlag(0);
  395. noCarWayBill.setIntfaceStartTime(DateUtil.getCurrentDateStr());
  396. return noCarWayBill;
  397. }
  398. private DataResult getDataResult(String data, long costtimestart, DataResult result, NoCarWayBill noCarWayBill, List<CustomerCarRec> customerCarRecs, CustomerCarRec customerCarRec) {
  399. //先查询上游是否已经备案
  400. RespR<VehicleQueryResponse> respRquery = noCarService.customerCarRecQueryUpper(customerCarRec);
  401. if (respRquery.getCode() == 1 || respRquery.getData() == null || respRquery.getData().getResult() == null || respRquery.getData().getResult().size() <= 0) {
  402. customerCarRecs.add(customerCarRec);
  403. RespR respR = noCarService.customerCarRec(customerCarRecs);
  404. if (respR.getCode() == 1) {
  405. noCarWayBill.setFailReason(respR.getMsg());
  406. noCarWayBill.setBillwayStatus(-2);
  407. insertOrUpdateBillStart(noCarWayBill);
  408. result.setMsg("车牌号备案失败,失败原因:" + respR.getMsg());
  409. return result;
  410. }
  411. }
  412. return getDataResultss(data, costtimestart, result, noCarService.noCarWaybillStart(noCarWayBill), "[-NoCarInterServiceImpl.noCarBillStart-] result is ");
  413. }
  414. /**
  415. * 无车 实时运单结束指令接口
  416. *
  417. * @param appKey
  418. * @param api
  419. * @param data
  420. * @return
  421. */
  422. @Override
  423. public DataResult noCarBillEnd(String appKey, String api, String data, String requestid) {
  424. long costtimestart = System.currentTimeMillis();
  425. DataResult result = new DataResult();
  426. result.setData(3);
  427. result.setCode(200);
  428. result.setRequestid(requestid);
  429. result.setMsg("无法认证");
  430. try {
  431. log.info("[-NoCarInterServiceImpl.noCarBillEnd-] request appKey=" + appKey + " ,api=" + api + " ,data=" + StringUtil.removeJSonField(data,"base64Str") + " ,requestid=" + requestid);
  432. JSONObject jsonObject = JSONObject.parseObject(data);
  433. //运单号 必输
  434. String num = jsonObject.getString("num");
  435. //运单实际目的地址 必输
  436. String realDestAddr = jsonObject.getString("realDestAddr");
  437. //运单实际结束时间 必输
  438. String endTime = jsonObject.getString("endTime");
  439. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(num)
  440. || StringUtils.isEmpty(realDestAddr)
  441. || StringUtils.isEmpty(endTime)
  442. ) {
  443. result.setMsg("必传参数有空值");
  444. return result;
  445. }
  446. if (!DateUtil.isValidDate(endTime)) {
  447. result.setMsg("日期格式有误");
  448. return result;
  449. }
  450. NoCarWayBill noCarWayBill = new NoCarWayBill();
  451. noCarWayBill.setCustomerName(appKey);
  452. noCarWayBill.setBillNum(num);
  453. noCarWayBill.setDestAddr(realDestAddr);
  454. noCarWayBill.setPredictEndTime(DateUtil.getDistanceHoursFormat(endTime));
  455. noCarWayBill.setHisFlag(0);
  456. //接口
  457. noCarWayBill.setInterType(0);
  458. return getDataResultss(data, costtimestart, result, noCarService.noCarWaybillEnd(noCarWayBill), "[-NoCarInterServiceImpl.noCarBillEnd-] result is ");
  459. } catch (Exception e) {
  460. log.error("[-NoCarInterServiceImpl.noCarBillEnd-] get httpclient exception is "
  461. + e + ", request is " + data);
  462. }
  463. return result;
  464. }
  465. /**
  466. * 无车 历史运单开始指令接口
  467. *
  468. * @param appKey
  469. * @param api
  470. * @param data
  471. * @return
  472. */
  473. @Override
  474. public DataResult noCarHisWaybillStart(String appKey, String api, String data, String requestid) {
  475. long costtimestart = System.currentTimeMillis();
  476. DataResult result = new DataResult();
  477. result.setData(3);
  478. result.setCode(200);
  479. result.setRequestid(requestid);
  480. result.setMsg("无法认证");
  481. try {
  482. log.info("[-NoCarInterServiceImpl.noCarHisWaybillStart-] request appKey=" + appKey + " ,api=" + api + " ,data=" + StringUtil.removeJSonField(data,"base64Str") + " ,requestid=" + requestid);
  483. String param = paramService.getParamsByParamName("NO_CAR_HISWAY_BILL_ON_OFF").getParamValue();
  484. if (StringUtils.isBlank(param) || !StringUtils.equals(ONE, param)) {
  485. result.setMsg("历史运单开始指令接口已关闭");
  486. return result;
  487. }
  488. JSONObject jsonObject = JSONObject.parseObject(data);
  489. //运单编号 必选
  490. String num = jsonObject.getString("num");
  491. //车牌号 必选
  492. String plateNumber = jsonObject.getString("plateNumber");
  493. //车牌颜色 必选
  494. String plateColor = jsonObject.getString("plateColor");
  495. //运单开始时间 必选
  496. String startTime = jsonObject.getString("startTime");
  497. //运单开始地址 必选
  498. String sourceAddr = jsonObject.getString("sourceAddr");
  499. //运单目的地址 必选
  500. String destAddr = jsonObject.getString("destAddr");
  501. //运单预计完成时间 必选
  502. String predictEndTime = jsonObject.getString("predictEndTime");
  503. //运单费用 必选
  504. Integer fee = jsonObject.getInteger("fee");
  505. //发票抬头类型 必选
  506. Integer titleType = jsonObject.getInteger("titleType");
  507. //税号 必选
  508. String taxplayerCode = jsonObject.getString("taxplayerCode");
  509. String base64Str = jsonObject.getString("base64Str");
  510. String waybillFileName = jsonObject.getString("waybillFileName");
  511. Integer contractType = jsonObject.getInteger("contractType");
  512. if (StringUtils.isEmpty(data) || null == jsonObject
  513. || StringUtils.isEmpty(num)
  514. || StringUtils.isEmpty(plateNumber)
  515. || StringUtils.isEmpty(plateColor)
  516. || StringUtils.isEmpty(startTime)
  517. || StringUtils.isEmpty(sourceAddr)
  518. || StringUtils.isEmpty(destAddr)
  519. || StringUtils.isEmpty(predictEndTime)
  520. || null == fee
  521. || null == titleType
  522. || StringUtils.isEmpty(taxplayerCode)
  523. || StringUtils.isEmpty(base64Str)
  524. || StringUtils.isEmpty(waybillFileName)
  525. || null == contractType
  526. ) {
  527. result.setMsg("有空的必填运单要素,请检查");
  528. return result;
  529. }
  530. if (!DateUtil.isValidDate(startTime)) {
  531. result.setMsg("日期格式有误");
  532. return result;
  533. }
  534. if (!DateUtil.isValidDate(predictEndTime)) {
  535. result.setMsg("日期格式有误");
  536. return result;
  537. }
  538. CustomerRec customerRec = new CustomerRec();
  539. customerRec.setCustomerName(appKey);
  540. customerRec.setCompanyReferencenum(taxplayerCode);
  541. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  542. if (customerRec == null) {
  543. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  544. return result;
  545. }
  546. if(StringUtils.isNotBlank(waybillFileName) && StringUtils.isNotBlank(base64Str) && null != contractType){
  547. String fileType = waybillFileName.substring(waybillFileName.lastIndexOf(".") + 1).toLowerCase();
  548. if (!PDF.equals(fileType)) {
  549. result.setMsg("必须是pdf文件!");
  550. return result;
  551. }
  552. int base64StrLength = base64Str.length();
  553. if (COMPUTE < base64StrLength) {
  554. result.setMsg("pdf不可超过10M!");
  555. return result;
  556. }
  557. base64Str = base64Str.replaceAll(" ", "+");
  558. }
  559. NoCarWayBill noCarWayBill = getNoCarWayBills(appKey, num, plateNumber, plateColor, startTime, sourceAddr, destAddr, predictEndTime, fee, titleType, taxplayerCode, customerRec);
  560. noCarWayBill.setWaybillFileName(waybillFileName);
  561. noCarWayBill.setBase64Str(base64Str);
  562. noCarWayBill.setContractType(contractType);
  563. List<CustomerCarRec> customerCarRecs = new ArrayList<>();
  564. CustomerCarRec customerCarRec = new CustomerCarRec();
  565. customerCarRec.setCompanyName(noCarWayBill.getCompanyName());
  566. customerCarRec.setCarNum(noCarWayBill.getPlateNum());
  567. customerCarRec.setCarColor(noCarWayBill.getPlateColor());
  568. customerCarRec.setCustomerName(appKey);
  569. customerCarRec.setInterType(0);
  570. customerCarRec.setCompanyNum(customerRec.getCompanyNum());
  571. customerCarRec.setBusinessType("2");
  572. //默认运营车辆
  573. customerCarRec.setServiceOperation(1);
  574. noCarWayBill.setTitleType(2);
  575. if (checkCustomerCarRecQueryResult(result, noCarWayBill, customerCarRecs, customerCarRec)) {
  576. return result;
  577. }
  578. RespR respR = noCarService.noCarHisWaybillStart(noCarWayBill);
  579. try {
  580. if(respR.getCode() == 0 && StringUtils.isNotBlank(waybillFileName) && StringUtils.isNotBlank(base64Str) ){
  581. //上传成功后文件入库
  582. NoCarWayBillFileInfo noCarWayBillFileInfo = new NoCarWayBillFileInfo();
  583. noCarWayBillFileInfo.setBase64Str(base64Str);
  584. noCarWayBillFileInfo.setFileName(waybillFileName);
  585. noCarWayBillFileInfo.setBatchNum("接口运单");
  586. noCarWayBillFileInfo.setWayBillNum(num);
  587. noCarWayBillFileInfo.setUpdateTime(DateUtil.getCurrentDateStr());
  588. noCarWayBillFileInfo.setCustomerId(appKey);
  589. noCarWayBillFileInfo.setCompanyName(noCarWayBill.getCompanyName());
  590. wayBillFileService.insert(noCarWayBillFileInfo);
  591. }
  592. }catch (Exception e){
  593. e.printStackTrace();
  594. log.info("文件入表失败{}",noCarWayBill.getBillNum());
  595. }
  596. return getDataResultss(data, costtimestart, result, respR, "[-NoCarInterServiceImpl.noCarHisWaybillStart-] result is ");
  597. } catch (Exception e) {
  598. log.error("[-NoCarInterServiceImpl.noCarHisWaybillStart-] get httpclient exception is "
  599. + e + ", request is " + StringUtil.removeJSonField(data,"base64Str"));
  600. }
  601. return result;
  602. }
  603. private DataResult getDataResultss(String data, long costtimestart, DataResult result, RespR respR, String s) {
  604. RespR rs = respR;
  605. long costtimeend = System.currentTimeMillis();
  606. log.info(s
  607. + rs.toString() + ", request is " + StringUtil.removeJSonField(data,"base64Str") + " ,costtime="
  608. + (costtimeend - costtimestart));
  609. if (null != rs && rs.getCode() == 0) {
  610. result.setData(1);
  611. result.setCode(200);
  612. result.setMsg(rs.getData().toString());
  613. return result;
  614. } else {
  615. result.setData(3);
  616. result.setCode(200);
  617. result.setMsg(rs.getMsg());
  618. return result;
  619. }
  620. }
  621. private boolean checkCustomerCarRecQueryResult(DataResult result, NoCarWayBill noCarWayBill, List<CustomerCarRec> customerCarRecs, CustomerCarRec customerCarRec) {
  622. //先查询上游是否已经备案
  623. RespR<VehicleQueryResponse> respRquery = noCarService.customerCarRecQueryUpper(customerCarRec);
  624. if (respRquery.getCode() == 1 || respRquery.getData() == null || respRquery.getData().getResult() == null || respRquery.getData().getResult().size() <= 0) {
  625. customerCarRecs.add(customerCarRec);
  626. RespR respR = noCarService.customerCarRec(customerCarRecs);
  627. if (respR.getCode() == 1) {
  628. result.setMsg("车牌号备案失败,失败原因:" + respR.getMsg());
  629. noCarWayBill.setFailReason(respR.getMsg());
  630. noCarWayBill.setBillwayStatus(-2);
  631. insertOrUpdateBillStart(noCarWayBill);
  632. return true;
  633. }
  634. }
  635. return false;
  636. }
  637. private NoCarWayBill getNoCarWayBills(String appKey, String num, String plateNumber, String plateColor, String startTime, String sourceAddr, String destAddr, String predictEndTime, Integer fee, Integer titleType, String taxplayerCode, CustomerRec customerRec) {
  638. NoCarWayBill noCarWayBill = new NoCarWayBill();
  639. noCarWayBill.setCustomerName(appKey);
  640. noCarWayBill.setCompanyName(customerRec.getCompanyName());
  641. noCarWayBill.setPlateNum(plateNumber);
  642. noCarWayBill.setBillNum(num);
  643. noCarWayBill.setPlateColor(plateColor);
  644. noCarWayBill.setStartTime(DateUtil.getDistanceHoursFormat(startTime));
  645. noCarWayBill.setSourceAddr(sourceAddr);
  646. noCarWayBill.setDestAddr(destAddr);
  647. noCarWayBill.setPredictEndTime(DateUtil.getDistanceHoursFormat(predictEndTime));
  648. noCarWayBill.setFee(fee.longValue());
  649. noCarWayBill.setTitleType(titleType);
  650. noCarWayBill.setTaxplayerCode(taxplayerCode);
  651. noCarWayBill.setHisFlag(1);
  652. noCarWayBill.setUpdateTime(DateUtil.getCurrentDateStr());
  653. noCarWayBill.setIntfaceStartTime(DateUtil.getCurrentDateStr());
  654. //接口
  655. noCarWayBill.setInterType(0);
  656. return noCarWayBill;
  657. }
  658. /**
  659. * 插入或者更新运单
  660. * @param noCarWayBill
  661. */
  662. public void insertOrUpdateBillStart(NoCarWayBill noCarWayBill) {
  663. noCarWayBill.setIntfaceStartTime(DateUtil.getCurrentDateStr());
  664. noCarWayBill.setUpdateTime(DateUtil.getCurrentDateStr());
  665. NoCarWayBill curr = noCarWaybillMapper.selectByBillNum(noCarWayBill.getBillNum());
  666. if (null == curr) {
  667. noCarWaybillMapper.insert(noCarWayBill);
  668. } else {
  669. if (curr.getBillwayStatus() < 1) {
  670. noCarWaybillMapper.updateByBillNum(noCarWayBill);
  671. }
  672. }
  673. }
  674. /**
  675. * 无车 历史运单结束指令接口
  676. *
  677. * @param appKey
  678. * @param api
  679. * @param data
  680. * @return
  681. */
  682. @Override
  683. public DataResult noCarHisWaybillEnd(String appKey, String api, String data, String requestid) {
  684. long costtimestart = System.currentTimeMillis();
  685. DataResult result = new DataResult();
  686. result.setData(3);
  687. result.setCode(200);
  688. result.setRequestid(requestid);
  689. result.setMsg("无法认证");
  690. try {
  691. log.info("[-NoCarInterServiceImpl.noCarHisWaybillEnd-] request appKey=" + appKey + " ,api=" + api + " ,data=" + StringUtil.removeJSonField(data,"base64Str") + " ,requestid=" + requestid);
  692. String param = paramService.getParamsByParamName("NO_CAR_HISWAY_BILL_ON_OFF").getParamValue();
  693. if (StringUtils.isBlank(param) || !StringUtils.equals(ONE, param)) {
  694. result.setMsg("历史运单结束指令接口已关闭");
  695. return result;
  696. }
  697. JSONObject jsonObject = JSONObject.parseObject(data);
  698. //运单号 必输
  699. String num = jsonObject.getString("num");
  700. //运单实际目的地址 必输
  701. String realDestAddr = jsonObject.getString("realDestAddr");
  702. //运单实际结束时间 必输
  703. String endTime = jsonObject.getString("endTime");
  704. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(num)
  705. || StringUtils.isEmpty(realDestAddr)
  706. || StringUtils.isEmpty(endTime)
  707. ) {
  708. result.setMsg("有空的必填运单要素,请检查");
  709. return result;
  710. }
  711. if (!DateUtil.isValidDate(endTime)) {
  712. result.setMsg("日期格式有误");
  713. return result;
  714. }
  715. NoCarWayBill noCarWayBill = new NoCarWayBill();
  716. noCarWayBill.setBillNum(num);
  717. noCarWayBill.setDestAddr(realDestAddr);
  718. noCarWayBill.setPredictEndTime(DateUtil.getDistanceHoursFormat(endTime));
  719. noCarWayBill.setHisFlag(1);
  720. noCarWayBill.setCustomerName(appKey);
  721. //接口
  722. noCarWayBill.setInterType(0);
  723. return getDataResultss(data, costtimestart, result, noCarService.noCarHisWaybillEnd(noCarWayBill), "[-NoCarInterServiceImpl.noCarHisWaybillEnd-] result is ");
  724. } catch (Exception e) {
  725. log.error("[-NoCarInterServiceImpl.noCarHisWaybillEnd-] get httpclient exception is "
  726. + e + ", request is " + data);
  727. }
  728. return result;
  729. }
  730. /**
  731. * 无车 运单号查询发票数据
  732. *
  733. * @param appKey
  734. * @param api
  735. * @param data
  736. * @return
  737. */
  738. @Override
  739. public DataResult noCarVoiceQuery(String appKey, String api, String data, String requestid) {
  740. long costtimestart = System.currentTimeMillis();
  741. DataResult result = new DataResult();
  742. result.setData(3);
  743. result.setCode(200);
  744. result.setRequestid(requestid);
  745. result.setMsg("无法认证");
  746. try {
  747. log.info("[-NoCarInterServiceImpl.noCarVoiceQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  748. JSONObject jsonObject = JSONObject.parseObject(data);
  749. //运单号 必输
  750. String num = jsonObject.getString("num");
  751. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(num)
  752. ) {
  753. result.setMsg("有空的必填运单要素,请检查");
  754. return result;
  755. }
  756. NoCarWayBill noCarWayBill1 = null;
  757. try {
  758. noCarWayBill1 = noCarWaybillMapper.selectByBillNum(num);
  759. } catch (Exception e) {
  760. log.info("xuyaoshanchuyundan:" + num);
  761. result.setMsg("平台运单号存在多条,请联系管理员删除无效运单");
  762. return result;
  763. }
  764. if (null == noCarWayBill1) {
  765. noCarWayBill1 = new NoCarWayBill();
  766. noCarWayBill1.setBillNum(num);
  767. noCarWayBill1.setInterType(0);
  768. noCarWayBill1.setBillwayStatus(-5);
  769. }
  770. if (isaBoolean(noCarWayBill1)) {
  771. noCarWayBill1.setBillwayStatus(-5);
  772. }
  773. noCarWayBill1.setCustomerName(appKey);
  774. noCarWayBill1.setCompanyName(noCarWayBill1.getCompanyName());
  775. RespR rs = noCarService.getInvoiceByWayBillNumReal(noCarWayBill1, true);
  776. long costtimeend = System.currentTimeMillis();
  777. log.info("[-NoCarInterServiceImpl.noCarVoiceQuery-] result is "
  778. + rs.toString() + ", request is " + data + " ,costtime="
  779. + (costtimeend - costtimestart));
  780. if (null != rs && rs.getCode() == 0) {
  781. result.setData(1);
  782. result.setCode(200);
  783. result.setMsg(rs.getData().toString());
  784. return result;
  785. } else {
  786. result.setData(3);
  787. if (NOT_FOUND.equals(rs.getMsg())) {
  788. result.setData(2);
  789. }
  790. result.setCode(200);
  791. result.setMsg(noCarWayBill1.getBillwayStatus()+","+rs.getMsg());
  792. return result;
  793. }
  794. } catch (Exception e) {
  795. log.error("[-NoCarInterServiceImpl.noCarVoiceQuery-] get httpclient exception is "
  796. + e + ", request is " + data);
  797. }
  798. return result;
  799. }
  800. private boolean isaBoolean(NoCarWayBill noCarWayBill1) {
  801. return noCarWayBill1.getInterType() == REC_STATUS_WAIT ||
  802. (noCarWayBill1.getBillwayStatus() < REC_STATUS_UN &&
  803. noCarWayBill1.getFailReason() != null &&
  804. noCarWayBill1.getFailReason().contains(XY_WAYBILL_HISTORY_END));
  805. }
  806. /**
  807. * 无车 获取未查询过发票的运单编号
  808. *
  809. * @param appKey
  810. * @param api
  811. * @param data
  812. * @return
  813. */
  814. @Override
  815. public DataResult noCarNoVoiceQuery(String appKey, String api, String data, String requestid) {
  816. long costtimestart = System.currentTimeMillis();
  817. DataResult result = new DataResult();
  818. result.setData(3);
  819. result.setCode(200);
  820. result.setRequestid(requestid);
  821. result.setMsg("无法认证");
  822. try {
  823. log.info("[-NoCarInterServiceImpl.noCarNoVoiceQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  824. String param = paramService.getParamsByParamName("FIND_NO_SEARCH_NUM_ON_OFF").getParamValue();
  825. if (!StringUtils.equals(ONE, param)) {
  826. result.setMsg("获取未查询过发票的运单编号接口已关闭");
  827. return result;
  828. }
  829. List<NoCarWayBill> noCarWayBills = noCarWaybillMapper.getNoCarNoVoiceQuery(appKey);
  830. List<String> list1 = new ArrayList<String>();
  831. for (NoCarWayBill noCarWayBill : noCarWayBills
  832. ) {
  833. list1.add(noCarWayBill.getBillNum());
  834. }
  835. List<BillInvoice> billInvoices = billInvoiceMapper.selectNoCarNoVoiceQuery(appKey);
  836. List<String> list2 = new ArrayList<String>();
  837. for (BillInvoice billInvoice : billInvoices
  838. ) {
  839. list2.add(billInvoice.getWaybillNum());
  840. }
  841. List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(toList());
  842. long costtimeend = System.currentTimeMillis();
  843. log.info("[-NoCarInterServiceImpl.noCarNoVoiceQuery-] result is "
  844. + reduce1.toString() + ", request is " + data + " ,costtime="
  845. + (costtimeend - costtimestart));
  846. if (null != reduce1 && reduce1.size() > 0) {
  847. result.setData(1);
  848. result.setCode(200);
  849. result.setMsg(JSONArray.fromObject(reduce1).toString());
  850. return result;
  851. } else {
  852. result.setData(2);
  853. result.setCode(200);
  854. result.setMsg("未查得");
  855. return result;
  856. }
  857. } catch (Exception e) {
  858. log.error("[-NoCarInterServiceImpl.noCarNoVoiceQuery-] get httpclient exception is "
  859. + e + ", request is " + data);
  860. }
  861. return result;
  862. }
  863. /**
  864. * 无车 账户余额查询接口
  865. *
  866. * @param appKey
  867. * @param api
  868. * @param data
  869. * @return
  870. */
  871. @Override
  872. public DataResult balanceQuery(String appKey, String api, String data, String requestid) {
  873. long costtimestart = System.currentTimeMillis();
  874. DataResult result = new DataResult();
  875. result.setData(3);
  876. result.setCode(200);
  877. result.setRequestid(requestid);
  878. result.setMsg("无法认证");
  879. try {
  880. log.info("[-NoCarInterServiceImpl.balanceQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  881. Customer customer = customerMapper.selectByCustomerName(appKey);
  882. long costtimeend = System.currentTimeMillis();
  883. log.info("[-NoCarInterServiceImpl.balanceQuery-] result is "
  884. + customer.toString() + ", request is " + data + " ,costtime="
  885. + (costtimeend - costtimestart));
  886. if (null != customer) {
  887. result.setData(1);
  888. result.setCode(200);
  889. JSONObject jb = new JSONObject();
  890. jb.put("balance", customer.getAccountBalance());
  891. jb.put("lastDeductionTime", customer.getInvoiceTime());
  892. result.setMsg(jb.toString());
  893. return result;
  894. } else {
  895. result.setData(3);
  896. result.setCode(200);
  897. result.setMsg("无法认证");
  898. return result;
  899. }
  900. } catch (Exception e) {
  901. log.error("[-NoCarInterServiceImpl.balanceQuery-] get httpclient exception is "
  902. + e + ", request is " + data);
  903. }
  904. return result;
  905. }
  906. /**
  907. * 无车 红冲发票查询接口
  908. *
  909. * @param appKey
  910. * @param api
  911. * @param data
  912. * @return
  913. */
  914. @Override
  915. public DataResult redInkInvoiceQuery(String appKey, String api, String data, String requestid) {
  916. long costtimestart = System.currentTimeMillis();
  917. DataResult result = new DataResult();
  918. result.setData(3);
  919. result.setCode(200);
  920. result.setRequestid(requestid);
  921. result.setMsg("无法认证");
  922. try {
  923. log.info("[-NoCarInterServiceImpl.redInkInvoiceQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  924. JSONObject jsonObject = JSONObject.parseObject(data);
  925. //企业税号 必输
  926. String taxplayerCode = jsonObject.getString("taxplayerCode");
  927. //开票月份 样例:yyyy-MM 必输
  928. String month = jsonObject.getString("month");
  929. //查询第几页 示例1,2,3,4…
  930. Long pageNo = jsonObject.getLong("pageNo");
  931. //查询第几页 示例1,2,3,4… 没有就默认1000
  932. Long pageSize = jsonObject.getLong("pageSize");
  933. if (StringUtils.isEmpty(data) || null == jsonObject) {
  934. return result;
  935. }
  936. if (StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(month) || null == pageNo || pageNo < 1) {
  937. return result;
  938. }
  939. if (null == DateUtil.parseDate(month)) {
  940. result.setMsg("日期格式不正确!");
  941. return result;
  942. }
  943. HcInvoiceQueryVo hcInvoiceQueryVo = new HcInvoiceQueryVo();
  944. hcInvoiceQueryVo.setBuyerTaxpayerCode(taxplayerCode);
  945. hcInvoiceQueryVo.setMonth(month);
  946. hcInvoiceQueryVo.setPageSize(pageSize);
  947. hcInvoiceQueryVo.setPageNo(pageNo);
  948. RespR rs = noCarService.hcinvoicequeryinter(hcInvoiceQueryVo);
  949. long costtimeend = System.currentTimeMillis();
  950. log.info("[-NoCarInterServiceImpl.redInkInvoiceQuery-] result is "
  951. + rs.toString() + ", request is " + data + " ,costtime="
  952. + (costtimeend - costtimestart));
  953. if (null != rs && rs.getCode() == 0) {
  954. result.setData(1);
  955. result.setCode(200);
  956. result.setMsg(JSON.toJSONString(rs.getData()));
  957. return result;
  958. } else {
  959. result.setData(3);
  960. result.setCode(200);
  961. result.setMsg("查询失败");
  962. return result;
  963. }
  964. } catch (Exception e) {
  965. log.error("[-NoCarInterServiceImpl.redInkInvoiceQuery-] get httpclient exception is "
  966. + e + ", request is " + data);
  967. }
  968. return result;
  969. }
  970. /**
  971. * 无车 运单号查询发票数据
  972. *
  973. * @param appKey
  974. * @param api
  975. * @param data
  976. * @return
  977. */
  978. @Override
  979. public DataResult noCarVoiceOwnerQuery(String appKey, String api, String data, String requestid) {
  980. long costtimestart = System.currentTimeMillis();
  981. DataResult result = new DataResult();
  982. result.setData(3);
  983. result.setCode(200);
  984. result.setRequestid(requestid);
  985. result.setMsg("无法认证");
  986. try {
  987. log.info("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  988. JSONObject jsonObject = JSONObject.parseObject(data);
  989. //运单号 必输
  990. String num = jsonObject.getString("num");
  991. if (StringUtils.isEmpty(data) || null == jsonObject || StringUtils.isEmpty(num)
  992. ) {
  993. result.setMsg("有空的必填运单要素,请检查");
  994. return result;
  995. }
  996. NoCarWayBill noCarWayBill1 = null;
  997. try {
  998. noCarWayBill1 = noCarWaybillMapper.selectByBillNum(num);
  999. } catch (Exception e) {
  1000. log.info("xuyaoshanchuyundannoCarVoiceOwnerQuery:" + num);
  1001. result.setMsg("平台运单号存在多条,请联系管理员删除无效运单");
  1002. return result;
  1003. }
  1004. if (null == noCarWayBill1) {
  1005. noCarWayBill1 = new NoCarWayBill();
  1006. noCarWayBill1.setBillNum(num);
  1007. }
  1008. noCarWayBill1.setInterType(0);
  1009. RespR rs = noCarService.getInvoiceByWayBillOwnerNumReal(noCarWayBill1, false);
  1010. long costtimeend = System.currentTimeMillis();
  1011. log.info("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] result is "
  1012. + rs.toString() + ", request is " + data + " ,costtime="
  1013. + (costtimeend - costtimestart));
  1014. if (null != rs && rs.getCode() == 0) {
  1015. result.setData(1);
  1016. result.setCode(200);
  1017. result.setMsg(rs.getData().toString());
  1018. return result;
  1019. } else {
  1020. result.setData(3);
  1021. if (NOT_FOUND.equals(rs.getMsg())) {
  1022. result.setData(2);
  1023. }
  1024. result.setCode(200);
  1025. result.setMsg(rs.getMsg());
  1026. return result;
  1027. }
  1028. } catch (Exception e) {
  1029. log.error("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] get httpclient exception is "
  1030. + e + ", request is " + data);
  1031. }
  1032. return result;
  1033. }
  1034. @Autowired
  1035. NoCarCompanyMangerOper noCarCompanyMangerOper;
  1036. @Override
  1037. public DataResult companyDetailAdd(String appKey, String api, String data, String requestid) {
  1038. long costtimestart = System.currentTimeMillis();
  1039. DataResult result = new DataResult();
  1040. result.setData(3);
  1041. result.setCode(200);
  1042. result.setRequestid(requestid);
  1043. result.setMsg("无法认证");
  1044. JSONObject jsonObject = JSONObject.parseObject(data);
  1045. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1046. result.setMsg("有空的必填运单要素,请检查");
  1047. return result;
  1048. }
  1049. //税号 必输
  1050. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1051. String operatorName = jsonObject.getString("operatorName");
  1052. String operatorMobile = jsonObject.getString("operatorMobile");
  1053. String identificationId = jsonObject.getString("identificationId");
  1054. String contractFileName = jsonObject.getString("contractFileName");
  1055. String base64Str = jsonObject.getString("base64Str");
  1056. if(StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(operatorName)
  1057. ||StringUtils.isEmpty(operatorMobile) ||StringUtils.isEmpty(contractFileName)
  1058. ||StringUtils.isEmpty(base64Str) ){
  1059. result.setMsg("有空的必填运单要素,请检查");
  1060. }
  1061. CustomerRec customerRec = new CustomerRec();
  1062. customerRec.setCustomerName(appKey);
  1063. customerRec.setCompanyReferencenum(taxplayerCode);
  1064. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1065. if (customerRec == null) {
  1066. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1067. return result;
  1068. }
  1069. try {
  1070. log.info("[-NoCarInterServiceImpl.companyDetailAdd-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1071. NoCarCompanyManger noCarCompanyManger = new NoCarCompanyManger();
  1072. noCarCompanyManger.setCompanyNum(customerRec.getCompanyNum());
  1073. noCarCompanyManger.setOperatorName(operatorName);
  1074. noCarCompanyManger.setOperatorMobile(operatorMobile);
  1075. noCarCompanyManger.setIdentificationId(identificationId);
  1076. noCarCompanyManger.setContractFileName(contractFileName);
  1077. noCarCompanyManger.setBase64Str(base64Str);
  1078. noCarCompanyManger.setCustId(customerRec.getCustomerName());
  1079. noCarCompanyManger.setCompanyName(customerRec.getCompanyName());
  1080. RespR re = noCarCompanyMangerOper.companyDetailAdd(noCarCompanyManger);
  1081. long costtimeend = System.currentTimeMillis();
  1082. log.info("[-NoCarInterServiceImpl.companyDetailAdd-] result is "
  1083. + re.toString() + ", request is " + data + " ,costtime="
  1084. + (costtimeend - costtimestart));
  1085. if (null != re && re.getCode()==0) {
  1086. result.setData(1);
  1087. result.setCode(200);
  1088. result.setMsg("success");
  1089. return result;
  1090. } else {
  1091. result.setData(3);
  1092. result.setCode(200);
  1093. result.setMsg(re.getMsg());
  1094. return result;
  1095. }
  1096. } catch (Exception e) {
  1097. log.error("[-NoCarInterServiceImpl.companyDetailAdd-] get httpclient exception is "
  1098. + e + ", request is " + data);
  1099. }
  1100. return result;
  1101. }
  1102. @Override
  1103. public DataResult operatorEdit(String appKey, String api, String data, String requestid) {
  1104. long costtimestart = System.currentTimeMillis();
  1105. DataResult result = new DataResult();
  1106. result.setData(3);
  1107. result.setCode(200);
  1108. result.setRequestid(requestid);
  1109. result.setMsg("无法认证");
  1110. JSONObject jsonObject = JSONObject.parseObject(data);
  1111. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1112. result.setMsg("有空的必填运单要素,请检查");
  1113. return result;
  1114. }
  1115. //税号 必输
  1116. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1117. String sourceOperatorMobile = jsonObject.getString("sourceOperatorMobile");
  1118. String targetOperatorName = jsonObject.getString("targetOperatorName");
  1119. String targetOperatorMobile = jsonObject.getString("targetOperatorMobile");
  1120. String targetIdentificationId = jsonObject.getString("targetIdentificationId");
  1121. if(StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(targetOperatorName)
  1122. ||StringUtils.isEmpty(targetOperatorMobile) ||StringUtils.isEmpty(sourceOperatorMobile)){
  1123. result.setMsg("有空的必填运单要素,请检查");
  1124. }
  1125. CustomerRec customerRec = new CustomerRec();
  1126. customerRec.setCustomerName(appKey);
  1127. customerRec.setCompanyReferencenum(taxplayerCode);
  1128. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1129. if (customerRec == null) {
  1130. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1131. return result;
  1132. }
  1133. try {
  1134. log.info("[-NoCarInterServiceImpl.operatorEdit-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1135. OperatorEditVo operatorEditVo = new OperatorEditVo();
  1136. operatorEditVo.setCompanyNum(customerRec.getCompanyNum());
  1137. operatorEditVo.setSourceOperatorMobile(sourceOperatorMobile);
  1138. operatorEditVo.setTargetOperatorName(targetOperatorName);
  1139. operatorEditVo.setTargetOperatorMobile(targetOperatorMobile);
  1140. operatorEditVo.setTargetIdentificationId(targetIdentificationId);
  1141. RespR re = noCarCompanyMangerOper.operatorEdit(operatorEditVo);
  1142. long costtimeend = System.currentTimeMillis();
  1143. log.info("[-NoCarInterServiceImpl.operatorEdit-] result is "
  1144. + re.toString() + ", request is " + data + " ,costtime="
  1145. + (costtimeend - costtimestart));
  1146. if (null != re && re.getCode()==0) {
  1147. result.setData(1);
  1148. result.setCode(200);
  1149. result.setMsg("success");
  1150. return result;
  1151. } else {
  1152. result.setData(3);
  1153. result.setCode(200);
  1154. result.setMsg(re.getMsg());
  1155. return result;
  1156. }
  1157. } catch (Exception e) {
  1158. log.error("[-NoCarInterServiceImpl.operatorEdit-] get httpclient exception is "
  1159. + e + ", request is " + data);
  1160. }
  1161. return result;
  1162. }
  1163. @Override
  1164. public DataResult operatorEditConfirm(String appKey, String api, String data, String requestid) {
  1165. long costtimestart = System.currentTimeMillis();
  1166. DataResult result = new DataResult();
  1167. result.setData(3);
  1168. result.setCode(200);
  1169. result.setRequestid(requestid);
  1170. result.setMsg("无法认证");
  1171. JSONObject jsonObject = JSONObject.parseObject(data);
  1172. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1173. result.setMsg("有空的必填运单要素,请检查");
  1174. return result;
  1175. }
  1176. //税号 必输
  1177. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1178. String targetOperatorMobile = jsonObject.getString("targetOperatorMobile");
  1179. String validCode = jsonObject.getString("validCode");
  1180. if(StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(targetOperatorMobile)
  1181. ||StringUtils.isEmpty(validCode)){
  1182. result.setMsg("有空的必填运单要素,请检查");
  1183. }
  1184. CustomerRec customerRec = new CustomerRec();
  1185. customerRec.setCustomerName(appKey);
  1186. customerRec.setCompanyReferencenum(taxplayerCode);
  1187. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1188. if (customerRec == null) {
  1189. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1190. return result;
  1191. }
  1192. try {
  1193. log.info("[-NoCarInterServiceImpl.operatorEditConfirm-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1194. OperatorEditConfirmVo operatorEditConfirmVo = new OperatorEditConfirmVo();
  1195. operatorEditConfirmVo.setCompanyNum(customerRec.getCompanyNum());
  1196. operatorEditConfirmVo.setTargetOperatorMobile(targetOperatorMobile);
  1197. operatorEditConfirmVo.setValidCode(validCode);
  1198. RespR re = noCarCompanyMangerOper.operatorEditConfirm(operatorEditConfirmVo);
  1199. long costtimeend = System.currentTimeMillis();
  1200. log.info("[-NoCarInterServiceImpl.operatorEditConfirm-] result is "
  1201. + re.toString() + ", request is " + data + " ,costtime="
  1202. + (costtimeend - costtimestart));
  1203. if (null != re && re.getCode()==0) {
  1204. result.setData(1);
  1205. result.setCode(200);
  1206. result.setMsg("success");
  1207. return result;
  1208. } else {
  1209. result.setData(3);
  1210. result.setCode(200);
  1211. result.setMsg(re.getMsg());
  1212. return result;
  1213. }
  1214. } catch (Exception e) {
  1215. log.error("[-NoCarInterServiceImpl.operatorEditConfirm-] get httpclient exception is "
  1216. + e + ", request is " + data);
  1217. }
  1218. return result;
  1219. }
  1220. @Override
  1221. public DataResult operatorEvidence(String appKey, String api, String data, String requestid) {
  1222. long costtimestart = System.currentTimeMillis();
  1223. DataResult result = new DataResult();
  1224. result.setData(3);
  1225. result.setCode(200);
  1226. result.setRequestid(requestid);
  1227. result.setMsg("无法认证");
  1228. JSONObject jsonObject = JSONObject.parseObject(data);
  1229. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1230. result.setMsg("有空的必填运单要素,请检查");
  1231. return result;
  1232. }
  1233. //税号 必输
  1234. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1235. String operatorMobile = jsonObject.getString("operatorMobile");
  1236. String contractFileName = jsonObject.getString("contractFileName");
  1237. String base64Str = jsonObject.getString("base64Str");
  1238. if(StringUtils.isEmpty(taxplayerCode)
  1239. ||StringUtils.isEmpty(operatorMobile) ||StringUtils.isEmpty(contractFileName)
  1240. ||StringUtils.isEmpty(base64Str) ){
  1241. result.setMsg("有空的必填运单要素,请检查");
  1242. }
  1243. CustomerRec customerRec = new CustomerRec();
  1244. customerRec.setCustomerName(appKey);
  1245. customerRec.setCompanyReferencenum(taxplayerCode);
  1246. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1247. if (customerRec == null) {
  1248. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1249. return result;
  1250. }
  1251. try {
  1252. log.info("[-NoCarInterServiceImpl.operatorEvidence-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1253. OperatorEvidenceVo operatorEvidenceVo = new OperatorEvidenceVo();
  1254. operatorEvidenceVo.setCompanyNum(customerRec.getCompanyNum());
  1255. operatorEvidenceVo.setOperatorMobile(operatorMobile);
  1256. operatorEvidenceVo.setContractFileName(contractFileName);
  1257. operatorEvidenceVo.setBase64Str(base64Str);
  1258. RespR re = noCarCompanyMangerOper.operatorEvidence(operatorEvidenceVo);
  1259. long costtimeend = System.currentTimeMillis();
  1260. log.info("[-NoCarInterServiceImpl.operatorEvidence-] result is "
  1261. + re.toString() + ", request is " + data + " ,costtime="
  1262. + (costtimeend - costtimestart));
  1263. if (null != re && re.getCode()==0) {
  1264. result.setData(1);
  1265. result.setCode(200);
  1266. result.setMsg("success");
  1267. return result;
  1268. } else {
  1269. result.setData(3);
  1270. result.setCode(200);
  1271. result.setMsg(re.getMsg());
  1272. return result;
  1273. }
  1274. } catch (Exception e) {
  1275. log.error("[-NoCarInterServiceImpl.operatorEvidence-] get httpclient exception is "
  1276. + e + ", request is " + data);
  1277. }
  1278. return result;
  1279. }
  1280. @Override
  1281. public DataResult operatorSendCode(String appKey, String api, String data, String requestid) {
  1282. long costtimestart = System.currentTimeMillis();
  1283. DataResult result = new DataResult();
  1284. result.setData(3);
  1285. result.setCode(200);
  1286. result.setRequestid(requestid);
  1287. result.setMsg("无法认证");
  1288. JSONObject jsonObject = JSONObject.parseObject(data);
  1289. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1290. result.setMsg("有空的必填运单要素,请检查");
  1291. return result;
  1292. }
  1293. //税号 必输
  1294. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1295. if(StringUtils.isEmpty(taxplayerCode)){
  1296. result.setMsg("有空的必填运单要素,请检查");
  1297. }
  1298. CustomerRec customerRec = new CustomerRec();
  1299. customerRec.setCustomerName(appKey);
  1300. customerRec.setCompanyReferencenum(taxplayerCode);
  1301. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1302. if (customerRec == null) {
  1303. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1304. return result;
  1305. }
  1306. try {
  1307. log.info("[-NoCarInterServiceImpl.operatorSendCode-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1308. OperatorSendCodeVo operatorSendCodeVo = new OperatorSendCodeVo();
  1309. operatorSendCodeVo.setBuyerCode(taxplayerCode);
  1310. RespR re = noCarCompanyMangerOper.operatorSendCode(operatorSendCodeVo, customerRec);
  1311. long costtimeend = System.currentTimeMillis();
  1312. log.info("[-NoCarInterServiceImpl.operatorSendCode-] result is "
  1313. + re.toString() + ", request is " + data + " ,costtime="
  1314. + (costtimeend - costtimestart));
  1315. if (null != re && re.getCode()==0) {
  1316. result.setData(1);
  1317. result.setCode(200);
  1318. result.setMsg("success");
  1319. return result;
  1320. } else {
  1321. result.setData(3);
  1322. result.setCode(200);
  1323. result.setMsg(re.getMsg());
  1324. return result;
  1325. }
  1326. } catch (Exception e) {
  1327. log.error("[-NoCarInterServiceImpl.operatorSendCode-] get httpclient exception is "
  1328. + e + ", request is " + data);
  1329. }
  1330. return result;
  1331. }
  1332. @Override
  1333. public DataResult operatorValidCode(String appKey, String api, String data, String requestid) {
  1334. long costtimestart = System.currentTimeMillis();
  1335. DataResult result = new DataResult();
  1336. result.setData(3);
  1337. result.setCode(200);
  1338. result.setRequestid(requestid);
  1339. result.setMsg("无法认证");
  1340. JSONObject jsonObject = JSONObject.parseObject(data);
  1341. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1342. result.setMsg("有空的必填运单要素,请检查");
  1343. return result;
  1344. }
  1345. //税号 必输
  1346. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1347. String validCode = jsonObject.getString("validCode");
  1348. if(StringUtils.isEmpty(taxplayerCode)||StringUtils.isEmpty(validCode)){
  1349. result.setMsg("有空的必填运单要素,请检查");
  1350. }
  1351. CustomerRec customerRec = new CustomerRec();
  1352. customerRec.setCustomerName(appKey);
  1353. customerRec.setCompanyReferencenum(taxplayerCode);
  1354. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1355. if (customerRec == null) {
  1356. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1357. return result;
  1358. }
  1359. try {
  1360. log.info("[-NoCarInterServiceImpl.operatorValidCode-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1361. OperatorSendCodeVo operatorSendCodeVo = new OperatorSendCodeVo();
  1362. operatorSendCodeVo.setBuyerCode(taxplayerCode);
  1363. operatorSendCodeVo.setValidCode(validCode);
  1364. RespR re = noCarCompanyMangerOper.operatorValidCode(operatorSendCodeVo, customerRec);
  1365. long costtimeend = System.currentTimeMillis();
  1366. log.info("[-NoCarInterServiceImpl.operatorValidCode-] result is "
  1367. + re.toString() + ", request is " + data + " ,costtime="
  1368. + (costtimeend - costtimestart));
  1369. if (null != re && re.getCode()==0) {
  1370. result.setData(1);
  1371. result.setCode(200);
  1372. result.setMsg("success");
  1373. return result;
  1374. } else {
  1375. result.setData(3);
  1376. result.setCode(200);
  1377. result.setMsg(re.getMsg());
  1378. return result;
  1379. }
  1380. } catch (Exception e) {
  1381. log.error("[-NoCarInterServiceImpl.operatorValidCode-] get httpclient exception is "
  1382. + e + ", request is " + data);
  1383. }
  1384. return result;
  1385. }
  1386. }