NoCarController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. package com.jkcredit.invoice.controller.business;
  2. import cn.afterturn.easypoi.excel.ExcelImportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ImportParams;
  4. import com.alibaba.fastjson.JSON;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.jkcredit.invoice.annotation.LoginRequired;
  7. import com.jkcredit.invoice.annotation.annotationdes.AuthenticationInterceptor;
  8. import com.jkcredit.invoice.mapper.waybill.NoCarWaybillMapper;
  9. import com.jkcredit.invoice.model.entity.calculate.NoCarCalculateInfor;
  10. import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
  11. import com.jkcredit.invoice.model.entity.customer.CustomerOper;
  12. import com.jkcredit.invoice.model.entity.invoice.BillInvoice;
  13. import com.jkcredit.invoice.model.entity.user.User;
  14. import com.jkcredit.invoice.model.entity.waybill.NoCarWayBill;
  15. import com.jkcredit.invoice.model.vo.CodeAndNumVo;
  16. import com.jkcredit.invoice.service.calculateinfor.NoCarCalculateInfoService;
  17. import com.jkcredit.invoice.service.customer.CustomerOperService;
  18. import com.jkcredit.invoice.service.lowerservice.CheckHasAuthRole;
  19. import com.jkcredit.invoice.service.lowerservice.NoCarService;
  20. import com.jkcredit.invoice.service.nocar.NoCarBillWayImportService;
  21. import com.jkcredit.invoice.service.nocar.NoCarBillWayService;
  22. import com.jkcredit.invoice.service.nocar.NoCarRecService;
  23. import com.jkcredit.invoice.service.nocar.NocarInvoiceService;
  24. import com.jkcredit.invoice.util.RespR;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.apache.poi.util.IOUtils;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.util.StringUtils;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import javax.servlet.http.HttpServletResponse;
  34. import java.io.*;
  35. import java.net.URLEncoder;
  36. import java.text.DateFormat;
  37. import java.text.SimpleDateFormat;
  38. import java.util.ArrayList;
  39. import java.util.Arrays;
  40. import java.util.List;
  41. import static com.jkcredit.invoice.common.CommonConst.*;
  42. @Api(tags = "无车操作")
  43. @RestController
  44. @RequestMapping(value = {"/noCar"})
  45. @Slf4j
  46. /**
  47. * @Description 无车操作
  48. * @Author mashengyi
  49. * @Date 2022/2/8 18:15
  50. * @Param
  51. * @Return
  52. * @Exception
  53. *
  54. */
  55. public class NoCarController {
  56. @Autowired
  57. NoCarRecService noCarRecService;
  58. @Autowired
  59. NoCarBillWayService noCarBillWayService;
  60. @Autowired
  61. NoCarBillWayImportService noCarBillWayImportService;
  62. @Autowired
  63. NocarInvoiceService nocarInvoiceService;
  64. @Autowired
  65. NoCarCalculateInfoService noCarCalculateInfoService;
  66. @Autowired
  67. NoCarWaybillMapper noCarWaybillMapper;
  68. @Autowired
  69. NoCarService noCarService;
  70. @Autowired
  71. CustomerOperService customerOperService;
  72. @Autowired
  73. private CheckHasAuthRole checkHasAuthRole;
  74. /**
  75. * 分页查询无车备案信息
  76. *
  77. * @param page 参数集
  78. * @return 用户集合
  79. */
  80. @PostMapping("/findCarRec")
  81. @ApiOperation(value = "分页查询无车/自有车备案信息", notes = "分页查询无车/自有车备案信息")
  82. @LoginRequired
  83. public RespR getCustomersByPage(Page page, CustomerCarRec customerCarRec, User user) {
  84. try {
  85. checkHasAuthRole.checkCustomerRole(user, customerCarRec.getCustomerName());
  86. if (!StringUtils.isEmpty(customerCarRec.getStartTime()) && !NULL.equals(customerCarRec.getStartTime())) {
  87. String[] res = customerCarRec.getStartTime().split(",");
  88. customerCarRec.setStartTime(res[0]);
  89. customerCarRec.setEndTime(res[1].replace("00:00:00", "23:59:59"));
  90. } else {
  91. customerCarRec.setStartTime(null);
  92. }
  93. RespR respR = new RespR(noCarRecService.findByPageAndCarRec(page, customerCarRec));
  94. return respR;
  95. } catch (Exception e) {
  96. e.printStackTrace();
  97. return new RespR(false, e.getMessage());
  98. }
  99. }
  100. public void setTimeDue(NoCarWayBill noCarWayBill) {
  101. if (!StringUtils.isEmpty(noCarWayBill.getStartBegin()) && !NULL.equals(noCarWayBill.getStartBegin())) {
  102. String[] res = noCarWayBill.getStartBegin().split(",");
  103. noCarWayBill.setStartBegin(res[0]);
  104. noCarWayBill.setStartEnd(res[1].replace("00:00:00", "23:59:59"));
  105. } else {
  106. noCarWayBill.setStartBegin(null);
  107. }
  108. if (!StringUtils.isEmpty(noCarWayBill.getEndBegin()) && !NULL.equals(noCarWayBill.getEndBegin())) {
  109. String[] res = noCarWayBill.getEndBegin().split(",");
  110. noCarWayBill.setEndBegin(res[0]);
  111. noCarWayBill.setEndEnd(res[1].replace("00:00:00", "23:59:59"));
  112. } else {
  113. noCarWayBill.setEndBegin(null);
  114. }
  115. }
  116. public void setTimeDue2(NoCarWayBill noCarWayBill) {
  117. if (NULL.equals(noCarWayBill.getStartBegin())) {
  118. noCarWayBill.setStartBegin(null);
  119. }
  120. if (NULL.equals(noCarWayBill.getStartEnd())) {
  121. noCarWayBill.setStartEnd(null);
  122. }
  123. if (NULL.equals(noCarWayBill.getEndBegin())) {
  124. noCarWayBill.setEndBegin(null);
  125. }
  126. if (NULL.equals(noCarWayBill.getEndEnd())) {
  127. noCarWayBill.setEndEnd(null);
  128. }
  129. }
  130. /**
  131. * 分页查询运单信息
  132. *
  133. * @param page 参数集
  134. * @return 用户集合
  135. */
  136. @PostMapping("/findBillWay")
  137. @ApiOperation(value = "分页查询无车运单信息", notes = "分页查询无车运单信息")
  138. @LoginRequired
  139. public RespR findBillWay(Page page, NoCarWayBill noCarWayBill, User user) {
  140. try {
  141. checkHasAuthRole.checkCustomerRole(user, noCarWayBill.getCustomerName());
  142. setTimeDue(noCarWayBill);
  143. setBillNums(noCarWayBill);
  144. RespR respR = new RespR(noCarBillWayService.findByPageAndWayBill(page, noCarWayBill));
  145. return respR;
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. return new RespR(false, e.getMessage());
  149. }
  150. }
  151. public void setBillNums(NoCarWayBill noCarWayBill) {
  152. String billNums = noCarWayBill.getBillNum();
  153. if (!StringUtils.isEmpty(billNums)) {
  154. String[] billNumArr = billNums.split(",");
  155. noCarWayBill.setBillNums(Arrays.asList(billNumArr));
  156. }
  157. }
  158. /**
  159. * 分页查询客户运单信息
  160. *
  161. * @param page 参数集
  162. * @return 用户集合
  163. */
  164. @PostMapping("/findBillWayCust")
  165. @ApiOperation(value = "分页查询无车运单信息", notes = "分页查询无车运单信息")
  166. @LoginRequired
  167. public RespR findBillWayCust(Page page, NoCarWayBill noCarWayBill, User user) {
  168. try {
  169. checkHasAuthRole.checkCustomerRole(user, noCarWayBill.getCustomerName());
  170. setTimeDue2(noCarWayBill);
  171. setBillNums(noCarWayBill);
  172. noCarWayBill.setBatchNum("1");
  173. RespR respR = new RespR(noCarBillWayService.findByPageAndWayBill(page, noCarWayBill));
  174. return respR;
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177. return new RespR(false, e.getMessage());
  178. }
  179. }
  180. /**
  181. * 分页查询运单信息
  182. *
  183. * @param page 参数集
  184. * @return 用户集合
  185. */
  186. @PostMapping("/findImportBillWay")
  187. @ApiOperation(value = "分页查询无车运单信息", notes = "分页查询无车运单信息")
  188. @LoginRequired
  189. public RespR findImportBillWay(Page page, NoCarWayBill noCarWayBill, User user) {
  190. try {
  191. checkHasAuthRole.checkCustomerRole(user, noCarWayBill.getCustomerName());
  192. setTimeDue(noCarWayBill);
  193. RespR respR = new RespR(noCarBillWayImportService.findByPageAndWayBill(page, noCarWayBill));
  194. return respR;
  195. } catch (Exception e) {
  196. e.printStackTrace();
  197. return new RespR(false, e.getMessage());
  198. }
  199. }
  200. /**
  201. * 重新获取发票并更新状态
  202. *
  203. * @return 用户集合
  204. */
  205. @PostMapping("/updateStatus")
  206. @ApiOperation(value = "重新获取发票并更新状态", notes = "重新获取发票并更新状态")
  207. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  208. public RespR updateStatus(String noCarWayBillStr) {
  209. if(!checkHasAuthRole.checkMessage(noCarWayBillStr)){
  210. return new RespR(false, "重新获取发票并更新状态失败,请查看数据是否维护准确");
  211. }
  212. List<NoCarWayBill> noCarWayBills = JSON.parseArray(noCarWayBillStr, NoCarWayBill.class);
  213. if (noCarWayBills != null && noCarWayBills.size() > 0) {
  214. noCarWayBills.stream().forEach(noCarWayBill -> {
  215. try {
  216. noCarWayBill.setBillwayStatus(-5);
  217. noCarService.getInvoiceByWayBillNumReal(noCarWayBill, false);
  218. } catch (Exception e) {
  219. log.info("1111111111222222" + e.getMessage());
  220. }
  221. });
  222. }
  223. return new RespR("更新成功");
  224. }
  225. /**
  226. * 分页查询异常运单信息
  227. *
  228. * @param page 参数集
  229. * @return 用户集合
  230. */
  231. @PostMapping("/findBillWayException")
  232. @ApiOperation(value = "分页查询异常运单信息", notes = "分页查询异常运单信息")
  233. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  234. public RespR findBillWayException(Page page, NoCarWayBill noCarWayBill) {
  235. try {
  236. setTimeDue(noCarWayBill);
  237. RespR respR = new RespR(noCarBillWayService.findByPageAndWayBillException(page, noCarWayBill));
  238. return respR;
  239. } catch (Exception e) {
  240. e.printStackTrace();
  241. return new RespR(false, e.getMessage());
  242. }
  243. }
  244. /**
  245. * 分页查询无车运单信息
  246. *
  247. * @param page 参数集
  248. * @return 用户集合
  249. */
  250. @PostMapping("/findNocarInvoices")
  251. @ApiOperation(value = "分页查询无车发票信息", notes = "分页查询无车发票信息")
  252. @LoginRequired
  253. public RespR findNocarInvoices(Page page, BillInvoice billInvoice, User user) {
  254. try {
  255. checkHasAuthRole.checkCustomerRole(user, billInvoice.getCustomerName());
  256. setParams(billInvoice);
  257. RespR respR = new RespR(nocarInvoiceService.findByPageAndInvoice(page, billInvoice));
  258. return respR;
  259. } catch (Exception e) {
  260. e.printStackTrace();
  261. return new RespR(false, e.getMessage());
  262. }
  263. }
  264. private void setParams(BillInvoice billInvoice) {
  265. if (!StringUtils.isEmpty(billInvoice.getInvoiceMakeTime()) && !NULL.equals(billInvoice.getInvoiceMakeTime())) {
  266. String[] res = billInvoice.getInvoiceMakeTime().split(",");
  267. billInvoice.setInvoiceMakeStart(res[0]);
  268. billInvoice.setInvoiceMakeEnd(res[1].replace("00:00:00", "23:59:59"));
  269. }
  270. if (!StringUtils.isEmpty(billInvoice.getCalculateTime()) && !NULL.equals(billInvoice.getCalculateTime())) {
  271. String[] res = billInvoice.getCalculateTime().split(",");
  272. billInvoice.setCalculateTimeStart(res[0]);
  273. billInvoice.setCalculateTimeEnd(res[1].replace("00:00:00", "23:59:59"));
  274. }
  275. if (!StringUtils.isEmpty(billInvoice.getWaybillNum())) {
  276. String[] billNumArr = billInvoice.getWaybillNum().split(",");
  277. billInvoice.setWaybillNums(Arrays.asList(billNumArr));
  278. }
  279. if (!StringUtils.isEmpty(billInvoice.getPlateNum())) {
  280. String[] plateNums = billInvoice.getPlateNum().split(COMMA);
  281. billInvoice.setPlateNums(Arrays.asList(plateNums));
  282. }
  283. if (!StringUtils.isEmpty(billInvoice.getInvoiceCode()) && billInvoice.getInvoiceCode().indexOf(COMMAS) > 0) {
  284. String[] invoiceCodeArr = billInvoice.getInvoiceCode().split(",");
  285. String[] invoiceNumArr = null;
  286. if (billInvoice.getInvoiceNum() != null) {
  287. invoiceNumArr = billInvoice.getInvoiceNum().split(",");
  288. }
  289. List<CodeAndNumVo> codeAndNumVos = new ArrayList<>();
  290. for (int i = 0; i < invoiceCodeArr.length; i++) {
  291. CodeAndNumVo codeAndNumVo = new CodeAndNumVo();
  292. codeAndNumVo.setCode(invoiceCodeArr[i]);
  293. if (invoiceNumArr != null && invoiceNumArr.length >= i + 1) {
  294. codeAndNumVo.setNum(invoiceNumArr[i]);
  295. } else {
  296. codeAndNumVo.setNum("");
  297. }
  298. codeAndNumVos.add(codeAndNumVo);
  299. }
  300. billInvoice.setCodeAndNumVos(codeAndNumVos);
  301. }
  302. }
  303. /**
  304. * 批量查询无车发票信息
  305. *
  306. * @param file 参数集
  307. * @return
  308. */
  309. @PostMapping("/batchImportNocarInvoices")
  310. @ApiOperation(value = "批量查询无车发票信息", notes = "批量查询无车发票信息")
  311. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  312. public RespR batchImportNocarInvoices(@RequestParam("file") MultipartFile file) {
  313. try {
  314. ImportParams params = new ImportParams();
  315. params.setTitleRows(1);
  316. params.setHeadRows(1);
  317. List<BillInvoice> list = ExcelImportUtil.importExcel(file.getInputStream(), BillInvoice.class, params);
  318. RespR respR = nocarInvoiceService.findImportNocarInvoices(list);
  319. return respR;
  320. } catch (Exception e) {
  321. e.printStackTrace();
  322. return new RespR(false, e.getMessage());
  323. }
  324. }
  325. /**
  326. * 批量查询无车运单信息
  327. *
  328. * @param file 参数集
  329. * @return
  330. */
  331. @PostMapping("/batchImportNocarBillWay")
  332. @ApiOperation(value = "批量查询无车运单信息", notes = "批量查询无车运单信息")
  333. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  334. public RespR batchImportNocarBillWay(@RequestParam("file") MultipartFile file) {
  335. try {
  336. ImportParams params = new ImportParams();
  337. params.setTitleRows(1);
  338. params.setHeadRows(1);
  339. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class, params);
  340. RespR respR = noCarBillWayService.findImportNocarBillWay(list);
  341. return respR;
  342. } catch (Exception e) {
  343. e.printStackTrace();
  344. return new RespR(false, e.getMessage());
  345. }
  346. }
  347. /**
  348. * 分页查询无车运单统计信息
  349. *
  350. * @param billInvoice
  351. * @return 用户集合
  352. */
  353. @PostMapping("/findNocarInvoicesStatic")
  354. @ApiOperation(value = "分页查询无车发票统计信息", notes = "分页查询无车发票统计信息")
  355. @LoginRequired
  356. public RespR findNocarInvoicesStatic(BillInvoice billInvoice, User user) {
  357. checkHasAuthRole.checkCustomerRole(user, billInvoice.getCustomerName());
  358. try {
  359. if (!StringUtils.isEmpty(billInvoice.getInvoiceMakeTime()) && !NULL.equals(billInvoice.getInvoiceMakeTime())) {
  360. String[] res = billInvoice.getInvoiceMakeTime().split(",");
  361. billInvoice.setInvoiceMakeStart(res[0]);
  362. billInvoice.setInvoiceMakeEnd(res[1].replace("00:00:00", "23:59:59"));
  363. }
  364. if (!StringUtils.isEmpty(billInvoice.getCalculateTime()) && !NULL.equals(billInvoice.getCalculateTime())) {
  365. String[] res = billInvoice.getCalculateTime().split(",");
  366. billInvoice.setCalculateTimeStart(res[0]);
  367. billInvoice.setCalculateTimeEnd(res[1].replace("00:00:00", "23:59:59"));
  368. }
  369. RespR respR = new RespR(nocarInvoiceService.findInvoiceStatics(billInvoice));
  370. return respR;
  371. } catch (Exception e) {
  372. e.printStackTrace();
  373. return new RespR(false, e.getMessage());
  374. }
  375. }
  376. /**
  377. * 批量运单导入
  378. *
  379. * @param file 参数集
  380. * @return
  381. */
  382. @PostMapping("/batchImprotBillWay")
  383. @ApiOperation(value = "批量运单导入", notes = "批量运单导入")
  384. @LoginRequired
  385. public RespR batchImprotBillWay(@RequestParam("file") MultipartFile file, String customerName, User user) {
  386. try {
  387. if(!checkHasAuthRole.checkMessage(customerName)){
  388. return new RespR(false, "批量运单导入失败,请查看数据是否维护准确");
  389. }
  390. checkHasAuthRole.checkCustomerRole(user, customerName);
  391. ImportParams params = new ImportParams();
  392. params.setTitleRows(1);
  393. params.setHeadRows(1);
  394. params.setKeyIndex(2);
  395. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class, params);
  396. buildDate(list);
  397. RespR respR = noCarBillWayService.batchBillWayStart(list, customerName);
  398. return respR;
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. return new RespR(false, e.getMessage());
  402. }
  403. }
  404. /**
  405. * 批量运单导入
  406. *
  407. * @param file 参数集
  408. * @return
  409. */
  410. @PostMapping("/batchImprotHistoryBillWay")
  411. @ApiOperation(value = "批量历史运单导入", notes = "批量历史运单导入")
  412. @LoginRequired
  413. public RespR batchImprotHistoryBillWay(@RequestParam("file") MultipartFile file, String customerName, User user) {
  414. try {
  415. if(!checkHasAuthRole.checkMessage(customerName)){
  416. return new RespR(false, "批量历史运单导入失败,请查看数据是否维护准确");
  417. }
  418. checkHasAuthRole.checkCustomerRole(user, customerName);
  419. ImportParams params = new ImportParams();
  420. params.setTitleRows(1);
  421. params.setHeadRows(1);
  422. params.setKeyIndex(2);
  423. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class, params);
  424. log.info("batchImprotHistoryBillWay数量" + list.size());
  425. buildDate(list);
  426. RespR respR = noCarBillWayService.batchHsitoryBillWay(list, customerName);
  427. return respR;
  428. } catch (Exception e) {
  429. e.printStackTrace();
  430. return new RespR(false, e.getMessage());
  431. }
  432. }
  433. /**
  434. * 批量运单导入
  435. *
  436. * @param file 参数集
  437. * @return
  438. */
  439. @PostMapping("/batchImprotEndBillWay")
  440. @ApiOperation(value = "批量运单结束", notes = "批量运单结束")
  441. @LoginRequired
  442. public RespR batchImprotEndBillWay(@RequestParam("file") MultipartFile file, String customerName, User user) {
  443. if(!checkHasAuthRole.checkMessage(customerName)){
  444. return new RespR(false, "批量运单结束失败,请查看数据是否维护准确");
  445. }
  446. checkHasAuthRole.checkCustomerRole(user, customerName);
  447. try {
  448. ImportParams params = new ImportParams();
  449. params.setTitleRows(1);
  450. params.setHeadRows(1);
  451. params.setKeyIndex(2);
  452. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class, params);
  453. buildDateEnd(list);
  454. log.info("batchImprotEndBillWay数量" + list.size());
  455. RespR respR = noCarBillWayService.batchBillWayEnd(list, customerName);
  456. return respR;
  457. } catch (Exception e) {
  458. e.printStackTrace();
  459. return new RespR(false, e.getMessage());
  460. }
  461. }
  462. public void buildDate(List<NoCarWayBill> list) {
  463. StringBuffer sb = new StringBuffer();
  464. DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  465. int i = 0;
  466. String strError = "";
  467. for (int j = 0; j < list.size(); j++) {
  468. NoCarWayBill noCarWayBill = list.get(j);
  469. try {
  470. if (null == noCarWayBill) {
  471. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查数据是否未传递");
  472. strError = "第" + (j + 1) + "行数据存在错误,请检查数据是否未传递";
  473. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查数据是否未传递");
  474. }
  475. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getBillNum())) {
  476. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确");
  477. strError = "第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确";
  478. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确");
  479. }
  480. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getPlateNum())) {
  481. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查车牌号码是否未输入或者输入是否正确");
  482. strError = "第" + (j + 1) + "行数据存在错误,请检查车牌号码是否未输入或者输入是否正确";
  483. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查车牌号码是否未输入或者输入是否正确");
  484. }
  485. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getPlateColor())) {
  486. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查车牌颜色是否未输入或者输入是否正确");
  487. strError = "第" + (j + 1) + "行数据存在错误,请检查车牌颜色是否未输入或者输入是否正确";
  488. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查车牌颜色是否未输入或者输入是否正确");
  489. }
  490. if (null == noCarWayBill.getStartTimeDate()) {
  491. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单开始时间是否未输入或者输入是否正确");
  492. strError = "第" + (j + 1) + "行数据存在错误,请检查运单开始时间是否未输入或者输入是否正确";
  493. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单开始时间是否未输入或者输入是否正确");
  494. }
  495. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getSourceAddr())) {
  496. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单开始地址是否未输入或者输入是否正确");
  497. strError = "第" + (j + 1) + "行数据存在错误,请检查运单开始地址是否未输入或者输入是否正确";
  498. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单开始地址是否未输入或者输入是否正确");
  499. }
  500. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getDestAddr())) {
  501. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确");
  502. strError = "第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确";
  503. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确");
  504. }
  505. if (null == noCarWayBill.getPredictEndTimeDate()) {
  506. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单预计完成时间是否未输入或者输入是否正确");
  507. strError = "第" + (j + 1) + "行数据存在错误,请检查运单预计完成时间是否未输入或者输入是否正确";
  508. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单预计完成时间是否未输入或者输入是否正确");
  509. }
  510. if (null == noCarWayBill.getFeeD()) {
  511. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单费用是否未输入或者输入是否正确");
  512. strError = "第" + (j + 1) + "行数据存在错误,请检查运单费用是否未输入或者输入是否正确";
  513. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单费用是否未输入或者输入是否正确");
  514. }
  515. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getTaxplayerCode())) {
  516. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查税号是否未输入或者输入是否正确");
  517. strError = "第" + (j + 1) + "行数据存在错误,请检查税号是否未输入或者输入是否正确";
  518. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查税号是否未输入或者输入是否正确");
  519. }
  520. noCarWayBill.setStartTime(format.format(noCarWayBill.getStartTimeDate()));
  521. noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getPredictEndTimeDate()));
  522. if (noCarWayBill.getFeeD() != null) {
  523. noCarWayBill.setFee(Math.round(noCarWayBill.getFeeD() * 100));
  524. }
  525. noCarWayBill.setTaxplayerCode(noCarWayBill.getTaxplayerCode().trim());
  526. noCarWayBill.setBillNum(noCarWayBill.getBillNum().trim());
  527. } catch (Exception e) {
  528. sb.append(noCarWayBill.getBillNum() + "#");
  529. log.error(noCarWayBill.getBillNum());
  530. i++;
  531. }
  532. }
  533. if (i > 0) {
  534. log.error(org.apache.commons.lang3.StringUtils.isBlank(strError) ? "buildDateError" + sb.toString() + "第" + i + "行数据存在错误,请检查文件中数据,金额是否有空的,时间是否全是时间格式" : "buildDateError" + sb.toString() + strError);
  535. throw new RuntimeException(org.apache.commons.lang3.StringUtils.isBlank(strError) ? "第" + i + "行数据存在错误,请检查文件中数据,金额是否有空的,时间是否全是时间格式" : strError);
  536. }
  537. }
  538. public void buildDateEnd(List<NoCarWayBill> list) {
  539. DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  540. int i = 0;
  541. StringBuffer sb = new StringBuffer();
  542. String strError = "";
  543. for (int j = 0; j < list.size(); j++) {
  544. NoCarWayBill noCarWayBill = list.get(j);
  545. try {
  546. if (null == noCarWayBill) {
  547. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查数据是否未传递");
  548. strError = "第" + (j + 1) + "行数据存在错误,请检查数据是否未传递";
  549. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查数据是否未传递");
  550. }
  551. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getBillNum())) {
  552. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确");
  553. strError = "第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确";
  554. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单编号是否未输入或者输入是否正确");
  555. }
  556. if (null == noCarWayBill.getActEndTimeDate()) {
  557. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单实际结束时间是否未输入或者输入是否正确");
  558. strError = "第" + (j + 1) + "行数据存在错误,请检查运单实际结束时间是否未输入或者输入是否正确";
  559. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单实际结束时间是否未输入或者输入是否正确");
  560. }
  561. if (org.apache.commons.lang3.StringUtils.isBlank(noCarWayBill.getDestAddr())) {
  562. log.error("buildDateError" + sb.toString() + "第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确");
  563. strError = "第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确";
  564. throw new RuntimeException("第" + (j + 1) + "行数据存在错误,请检查运单目的地址是否未输入或者输入是否正确");
  565. }
  566. noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getActEndTimeDate()));
  567. } catch (Exception e) {
  568. sb.append(noCarWayBill.getBillNum() + "#");
  569. log.error(noCarWayBill.getBillNum());
  570. i++;
  571. }
  572. }
  573. if (i > 0) {
  574. log.error(org.apache.commons.lang3.StringUtils.isBlank(strError) ? "buildDateError" + sb.toString() + "第" + i + "行数据存在错误,请检查文件中数据,时间是否全是时间格式" : "buildDateError" + sb.toString() + strError);
  575. throw new RuntimeException(org.apache.commons.lang3.StringUtils.isBlank(strError) ? "第" + i + "行数据存在错误,请检查文件中数据,时间是否全是时间格式" : strError);
  576. }
  577. }
  578. /**
  579. * 分页查询无车计费信息
  580. *
  581. * @param page 参数集
  582. * @return 用户集合
  583. */
  584. @PostMapping("/findBatchList")
  585. @ApiOperation(value = "运单批次号查询", notes = "运单批次号查询")
  586. @LoginRequired
  587. public RespR findBatchList(Page page, CustomerOper customerOper, User user) {
  588. try {
  589. checkHasAuthRole.checkCustomerRole(user, customerOper.getCustomerName());
  590. RespR respR = new RespR(customerOperService.findAllCustomerOper(page, customerOper));
  591. return respR;
  592. } catch (Exception e) {
  593. e.printStackTrace();
  594. return new RespR(false, e.getMessage());
  595. }
  596. }
  597. /**
  598. * 分页查询无车计费信息
  599. *
  600. * @param page 参数集
  601. * @return 用户集合
  602. */
  603. @PostMapping("/findNocarCalculateInfo")
  604. @ApiOperation(value = "分页查询无车计费信息", notes = "分页查询无车计费信息")
  605. @LoginRequired
  606. public RespR findNocarCalculateInfo(Page page, NoCarCalculateInfor carCalculateInfor, User user) {
  607. try {
  608. checkHasAuthRole.checkCustomerRole(user, carCalculateInfor.getCustomId());
  609. setTimeDue1(carCalculateInfor);
  610. RespR respR = new RespR(noCarCalculateInfoService.findByPageAndCalculateInfor(page, carCalculateInfor));
  611. return respR;
  612. } catch (Exception e) {
  613. e.printStackTrace();
  614. return new RespR(false, e.getMessage());
  615. }
  616. }
  617. /**
  618. * 分页查询无车计费统计信息
  619. *
  620. * @param carCalculateInfor 参数集
  621. * @return 用户集合
  622. */
  623. @PostMapping("/findNocarCalculateInfoStatis")
  624. @ApiOperation(value = "分页查询无车计费统计信息", notes = "分页查询无车计费统计信息")
  625. @LoginRequired
  626. public RespR findNocarCalculateInfoStatis(NoCarCalculateInfor carCalculateInfor, User user) {
  627. try {
  628. checkHasAuthRole.checkCustomerRole(user, carCalculateInfor.getCustomId());
  629. setTimeDue1(carCalculateInfor);
  630. RespR respR = new RespR(noCarCalculateInfoService.findNocarCalculateInfoStatis(carCalculateInfor));
  631. return respR;
  632. } catch (Exception e) {
  633. e.printStackTrace();
  634. return new RespR(false, e.getMessage());
  635. }
  636. }
  637. @GetMapping("/templateDownload")
  638. @ApiOperation(value = "模板下载", notes = "模板下载")
  639. public RespR contractDownload(String fileName, HttpServletResponse response) {
  640. if (ONE.equals(fileName)) {
  641. fileName = "运单模板.xlsx";
  642. } else if (TWO.equals(fileName)) {
  643. fileName = "运单结束模板.xlsx";
  644. } else if (THREE.equals(fileName)) {
  645. fileName = "历史运单模板.xlsx";
  646. } else if (FOR.equals(fileName)) {
  647. fileName = "无车发票查询模板.xlsx";
  648. } else if (FIVE.equals(fileName)) {
  649. fileName = "无车运单查询模板.xlsx";
  650. } else if (SIX.equals(fileName)) {
  651. fileName = "自有车交易查询模板.xlsx";
  652. } else if (SEVEN.equals(fileName)) {
  653. fileName = "自有车发票查询模板.xlsx";
  654. } else if (EIGHT.equals(fileName)) {
  655. fileName = "自有车按交易查询申请模板.xlsx";
  656. }
  657. OutputStream outputStream = null;
  658. InputStream inputStream = null;
  659. try {
  660. File file = new File("/home/app/excel/" + fileName);
  661. inputStream = new FileInputStream(file);
  662. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
  663. outputStream = response.getOutputStream();
  664. IOUtils.copy(inputStream, outputStream);
  665. response.flushBuffer();
  666. return new RespR(true);
  667. } catch (IOException e) {
  668. } finally {
  669. IOUtils.closeQuietly(inputStream);
  670. IOUtils.closeQuietly(outputStream);
  671. }
  672. return new RespR(false);
  673. }
  674. public void setTimeDue1(NoCarCalculateInfor carCalculateInfor) {
  675. if (!StringUtils.isEmpty(carCalculateInfor.getInvoiceMakeTime()) && !NULL.equals(carCalculateInfor.getInvoiceMakeTime())) {
  676. String[] res = carCalculateInfor.getInvoiceMakeTime().split(",");
  677. carCalculateInfor.setInvoiceMakeStart(res[0]);
  678. carCalculateInfor.setInvoiceMakeEnd(res[1].replace("00:00:00", "23:59:59"));
  679. } else {
  680. carCalculateInfor.setInvoiceMakeTime(null);
  681. }
  682. if (!StringUtils.isEmpty(carCalculateInfor.getCalculateTime()) && !NULL.equals(carCalculateInfor.getCalculateTime())) {
  683. String[] res = carCalculateInfor.getCalculateTime().split(",");
  684. carCalculateInfor.setCalculateStart(res[0]);
  685. carCalculateInfor.setCalculateEnd(res[1].replace("00:00:00", "23:59:59"));
  686. } else {
  687. carCalculateInfor.setCalculateTime(null);
  688. }
  689. }
  690. }