NoCarInterServiceImpl.java 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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.selectByCustomerNameAndCompanyConcat(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(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. RespR re = noCarCompanyMangerOper.companyDetailAdd(noCarCompanyManger);
  1079. long costtimeend = System.currentTimeMillis();
  1080. log.info("[-NoCarInterServiceImpl.companyDetailAdd-] result is "
  1081. + re.toString() + ", request is " + data + " ,costtime="
  1082. + (costtimeend - costtimestart));
  1083. if (null != re && re.getCode()==0) {
  1084. result.setData(1);
  1085. result.setCode(200);
  1086. result.setMsg("success");
  1087. return result;
  1088. } else {
  1089. result.setData(3);
  1090. result.setCode(200);
  1091. result.setMsg(re.getMsg());
  1092. return result;
  1093. }
  1094. } catch (Exception e) {
  1095. log.error("[-NoCarInterServiceImpl.companyDetailAdd-] get httpclient exception is "
  1096. + e + ", request is " + data);
  1097. }
  1098. return result;
  1099. }
  1100. @Override
  1101. public DataResult operatorEdit(String appKey, String api, String data, String requestid) {
  1102. long costtimestart = System.currentTimeMillis();
  1103. DataResult result = new DataResult();
  1104. result.setData(3);
  1105. result.setCode(200);
  1106. result.setRequestid(requestid);
  1107. result.setMsg("无法认证");
  1108. JSONObject jsonObject = JSONObject.parseObject(data);
  1109. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1110. result.setMsg("有空的必填运单要素,请检查");
  1111. return result;
  1112. }
  1113. //税号 必输
  1114. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1115. String sourceOperatorMobile = jsonObject.getString("sourceOperatorMobile");
  1116. String targetOperatorName = jsonObject.getString("targetOperatorName");
  1117. String targetOperatorMobile = jsonObject.getString("targetOperatorMobile");
  1118. String targetIdentificationId = jsonObject.getString("targetIdentificationId");
  1119. if(StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(targetOperatorName)
  1120. ||StringUtils.isEmpty(targetOperatorMobile) ||StringUtils.isEmpty(sourceOperatorMobile)){
  1121. result.setMsg("有空的必填运单要素,请检查");
  1122. }
  1123. CustomerRec customerRec = new CustomerRec();
  1124. customerRec.setCustomerName(appKey);
  1125. customerRec.setCompanyReferencenum(taxplayerCode);
  1126. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1127. if (customerRec == null) {
  1128. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1129. return result;
  1130. }
  1131. try {
  1132. log.info("[-NoCarInterServiceImpl.operatorEdit-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1133. OperatorEditVo operatorEditVo = new OperatorEditVo();
  1134. operatorEditVo.setCompanyNum(customerRec.getCompanyNum());
  1135. operatorEditVo.setSourceOperatorMobile(sourceOperatorMobile);
  1136. operatorEditVo.setTargetOperatorName(targetOperatorName);
  1137. operatorEditVo.setTargetOperatorMobile(targetOperatorMobile);
  1138. operatorEditVo.setTargetIdentificationId(targetIdentificationId);
  1139. RespR re = noCarCompanyMangerOper.operatorEdit(operatorEditVo);
  1140. long costtimeend = System.currentTimeMillis();
  1141. log.info("[-NoCarInterServiceImpl.operatorEdit-] result is "
  1142. + re.toString() + ", request is " + data + " ,costtime="
  1143. + (costtimeend - costtimestart));
  1144. if (null != re && re.getCode()==0) {
  1145. result.setData(1);
  1146. result.setCode(200);
  1147. result.setMsg("success");
  1148. return result;
  1149. } else {
  1150. result.setData(3);
  1151. result.setCode(200);
  1152. result.setMsg(re.getMsg());
  1153. return result;
  1154. }
  1155. } catch (Exception e) {
  1156. log.error("[-NoCarInterServiceImpl.operatorEdit-] get httpclient exception is "
  1157. + e + ", request is " + data);
  1158. }
  1159. return result;
  1160. }
  1161. @Override
  1162. public DataResult operatorEditConfirm(String appKey, String api, String data, String requestid) {
  1163. long costtimestart = System.currentTimeMillis();
  1164. DataResult result = new DataResult();
  1165. result.setData(3);
  1166. result.setCode(200);
  1167. result.setRequestid(requestid);
  1168. result.setMsg("无法认证");
  1169. JSONObject jsonObject = JSONObject.parseObject(data);
  1170. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1171. result.setMsg("有空的必填运单要素,请检查");
  1172. return result;
  1173. }
  1174. //税号 必输
  1175. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1176. String targetOperatorMobile = jsonObject.getString("targetOperatorMobile");
  1177. String validCode = jsonObject.getString("validCode");
  1178. if(StringUtils.isEmpty(taxplayerCode) || StringUtils.isEmpty(targetOperatorMobile)
  1179. ||StringUtils.isEmpty(validCode)){
  1180. result.setMsg("有空的必填运单要素,请检查");
  1181. }
  1182. CustomerRec customerRec = new CustomerRec();
  1183. customerRec.setCustomerName(appKey);
  1184. customerRec.setCompanyReferencenum(taxplayerCode);
  1185. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1186. if (customerRec == null) {
  1187. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1188. return result;
  1189. }
  1190. try {
  1191. log.info("[-NoCarInterServiceImpl.operatorEditConfirm-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1192. OperatorEditConfirmVo operatorEditConfirmVo = new OperatorEditConfirmVo();
  1193. operatorEditConfirmVo.setCompanyNum(customerRec.getCompanyNum());
  1194. operatorEditConfirmVo.setTargetOperatorMobile(targetOperatorMobile);
  1195. operatorEditConfirmVo.setValidCode(validCode);
  1196. RespR re = noCarCompanyMangerOper.operatorEditConfirm(operatorEditConfirmVo);
  1197. long costtimeend = System.currentTimeMillis();
  1198. log.info("[-NoCarInterServiceImpl.operatorEditConfirm-] result is "
  1199. + re.toString() + ", request is " + data + " ,costtime="
  1200. + (costtimeend - costtimestart));
  1201. if (null != re && re.getCode()==0) {
  1202. result.setData(1);
  1203. result.setCode(200);
  1204. result.setMsg("success");
  1205. return result;
  1206. } else {
  1207. result.setData(3);
  1208. result.setCode(200);
  1209. result.setMsg(re.getMsg());
  1210. return result;
  1211. }
  1212. } catch (Exception e) {
  1213. log.error("[-NoCarInterServiceImpl.operatorEditConfirm-] get httpclient exception is "
  1214. + e + ", request is " + data);
  1215. }
  1216. return result;
  1217. }
  1218. @Override
  1219. public DataResult operatorEvidence(String appKey, String api, String data, String requestid) {
  1220. long costtimestart = System.currentTimeMillis();
  1221. DataResult result = new DataResult();
  1222. result.setData(3);
  1223. result.setCode(200);
  1224. result.setRequestid(requestid);
  1225. result.setMsg("无法认证");
  1226. JSONObject jsonObject = JSONObject.parseObject(data);
  1227. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1228. result.setMsg("有空的必填运单要素,请检查");
  1229. return result;
  1230. }
  1231. //税号 必输
  1232. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1233. String operatorMobile = jsonObject.getString("operatorMobile");
  1234. String contractFileName = jsonObject.getString("contractFileName");
  1235. String base64Str = jsonObject.getString("base64Str");
  1236. if(StringUtils.isEmpty(taxplayerCode)
  1237. ||StringUtils.isEmpty(operatorMobile) ||StringUtils.isEmpty(contractFileName)
  1238. ||StringUtils.isEmpty(base64Str) ){
  1239. result.setMsg("有空的必填运单要素,请检查");
  1240. }
  1241. CustomerRec customerRec = new CustomerRec();
  1242. customerRec.setCustomerName(appKey);
  1243. customerRec.setCompanyReferencenum(taxplayerCode);
  1244. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1245. if (customerRec == null) {
  1246. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1247. return result;
  1248. }
  1249. try {
  1250. log.info("[-NoCarInterServiceImpl.operatorEvidence-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1251. OperatorEvidenceVo operatorEvidenceVo = new OperatorEvidenceVo();
  1252. operatorEvidenceVo.setCompanyNum(customerRec.getCompanyNum());
  1253. operatorEvidenceVo.setOperatorMobile(operatorMobile);
  1254. operatorEvidenceVo.setContractFileName(contractFileName);
  1255. operatorEvidenceVo.setBase64Str(base64Str);
  1256. RespR re = noCarCompanyMangerOper.operatorEvidence(operatorEvidenceVo);
  1257. long costtimeend = System.currentTimeMillis();
  1258. log.info("[-NoCarInterServiceImpl.operatorEvidence-] result is "
  1259. + re.toString() + ", request is " + data + " ,costtime="
  1260. + (costtimeend - costtimestart));
  1261. if (null != re && re.getCode()==0) {
  1262. result.setData(1);
  1263. result.setCode(200);
  1264. result.setMsg("success");
  1265. return result;
  1266. } else {
  1267. result.setData(3);
  1268. result.setCode(200);
  1269. result.setMsg(re.getMsg());
  1270. return result;
  1271. }
  1272. } catch (Exception e) {
  1273. log.error("[-NoCarInterServiceImpl.operatorEvidence-] get httpclient exception is "
  1274. + e + ", request is " + data);
  1275. }
  1276. return result;
  1277. }
  1278. @Override
  1279. public DataResult operatorSendCode(String appKey, String api, String data, String requestid) {
  1280. long costtimestart = System.currentTimeMillis();
  1281. DataResult result = new DataResult();
  1282. result.setData(3);
  1283. result.setCode(200);
  1284. result.setRequestid(requestid);
  1285. result.setMsg("无法认证");
  1286. JSONObject jsonObject = JSONObject.parseObject(data);
  1287. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1288. result.setMsg("有空的必填运单要素,请检查");
  1289. return result;
  1290. }
  1291. //税号 必输
  1292. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1293. if(StringUtils.isEmpty(taxplayerCode)){
  1294. result.setMsg("有空的必填运单要素,请检查");
  1295. }
  1296. CustomerRec customerRec = new CustomerRec();
  1297. customerRec.setCustomerName(appKey);
  1298. customerRec.setCompanyReferencenum(taxplayerCode);
  1299. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1300. if (customerRec == null) {
  1301. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1302. return result;
  1303. }
  1304. try {
  1305. log.info("[-NoCarInterServiceImpl.operatorSendCode-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1306. OperatorSendCodeVo operatorSendCodeVo = new OperatorSendCodeVo();
  1307. operatorSendCodeVo.setBuyerCode(taxplayerCode);
  1308. RespR re = noCarCompanyMangerOper.operatorSendCode(operatorSendCodeVo);
  1309. long costtimeend = System.currentTimeMillis();
  1310. log.info("[-NoCarInterServiceImpl.operatorSendCode-] result is "
  1311. + re.toString() + ", request is " + data + " ,costtime="
  1312. + (costtimeend - costtimestart));
  1313. if (null != re && re.getCode()==0) {
  1314. result.setData(1);
  1315. result.setCode(200);
  1316. result.setMsg("success");
  1317. return result;
  1318. } else {
  1319. result.setData(3);
  1320. result.setCode(200);
  1321. result.setMsg(re.getMsg());
  1322. return result;
  1323. }
  1324. } catch (Exception e) {
  1325. log.error("[-NoCarInterServiceImpl.operatorSendCode-] get httpclient exception is "
  1326. + e + ", request is " + data);
  1327. }
  1328. return result;
  1329. }
  1330. @Override
  1331. public DataResult operatorValidCode(String appKey, String api, String data, String requestid) {
  1332. long costtimestart = System.currentTimeMillis();
  1333. DataResult result = new DataResult();
  1334. result.setData(3);
  1335. result.setCode(200);
  1336. result.setRequestid(requestid);
  1337. result.setMsg("无法认证");
  1338. JSONObject jsonObject = JSONObject.parseObject(data);
  1339. if (StringUtils.isEmpty(data) || null == jsonObject) {
  1340. result.setMsg("有空的必填运单要素,请检查");
  1341. return result;
  1342. }
  1343. //税号 必输
  1344. String taxplayerCode = jsonObject.getString("taxplayerCode");
  1345. String validCode = jsonObject.getString("validCode");
  1346. if(StringUtils.isEmpty(taxplayerCode)||StringUtils.isEmpty(validCode)){
  1347. result.setMsg("有空的必填运单要素,请检查");
  1348. }
  1349. CustomerRec customerRec = new CustomerRec();
  1350. customerRec.setCustomerName(appKey);
  1351. customerRec.setCompanyReferencenum(taxplayerCode);
  1352. customerRec = customerRecMapper.selectByCustomerNameAndCompanyReference(customerRec);
  1353. if (customerRec == null) {
  1354. result.setMsg("客户:" + appKey + ";税号" + taxplayerCode + "未在平台备案成功,请先做备案");
  1355. return result;
  1356. }
  1357. try {
  1358. log.info("[-NoCarInterServiceImpl.operatorValidCode-] request appKey=" + appKey + " ,api=" + api + " ,data=" + data + " ,requestid=" + requestid);
  1359. OperatorSendCodeVo operatorSendCodeVo = new OperatorSendCodeVo();
  1360. operatorSendCodeVo.setBuyerCode(taxplayerCode);
  1361. operatorSendCodeVo.setValidCode(validCode);
  1362. RespR re = noCarCompanyMangerOper.operatorValidCode(operatorSendCodeVo);
  1363. long costtimeend = System.currentTimeMillis();
  1364. log.info("[-NoCarInterServiceImpl.operatorValidCode-] result is "
  1365. + re.toString() + ", request is " + data + " ,costtime="
  1366. + (costtimeend - costtimestart));
  1367. if (null != re && re.getCode()==0) {
  1368. result.setData(1);
  1369. result.setCode(200);
  1370. result.setMsg("success");
  1371. return result;
  1372. } else {
  1373. result.setData(3);
  1374. result.setCode(200);
  1375. result.setMsg(re.getMsg());
  1376. return result;
  1377. }
  1378. } catch (Exception e) {
  1379. log.error("[-NoCarInterServiceImpl.operatorValidCode-] get httpclient exception is "
  1380. + e + ", request is " + data);
  1381. }
  1382. return result;
  1383. }
  1384. }