NoCarController.java 41 KB

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