NoCarController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. package com.jkcredit.invoice.controller.localBussiness;
  2. import cn.afterturn.easypoi.excel.ExcelImportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ImportParams;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.jkcredit.invoice.annotation.LoginRequired;
  6. import com.jkcredit.invoice.mapper.waybill.NoCarWaybillMapper;
  7. import com.jkcredit.invoice.model.entity.Calculate.NoCarCalculateInfor;
  8. import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
  9. import com.jkcredit.invoice.model.entity.customer.CustomerOper;
  10. import com.jkcredit.invoice.model.entity.customer.CustomerRec;
  11. import com.jkcredit.invoice.model.entity.invoice.BillInvoice;
  12. import com.jkcredit.invoice.model.entity.waybill.NoCarWayBill;
  13. import com.jkcredit.invoice.service.CalculateInfor.NoCarCalculateInfoService;
  14. import com.jkcredit.invoice.service.customer.CustomerOperService;
  15. import com.jkcredit.invoice.service.lowerService.NoCarService;
  16. import com.jkcredit.invoice.service.nocar.NoCarBillWayService;
  17. import com.jkcredit.invoice.service.nocar.NoCarRecService;
  18. import com.jkcredit.invoice.service.nocar.NocarInvoiceService;
  19. import com.jkcredit.invoice.util.ReadExcelUtil;
  20. import com.jkcredit.invoice.util.RespR;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import org.apache.poi.util.IOUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.util.StringUtils;
  26. import org.springframework.web.bind.annotation.*;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import javax.servlet.http.HttpServletResponse;
  29. import java.io.*;
  30. import java.net.URLEncoder;
  31. import java.text.DateFormat;
  32. import java.text.SimpleDateFormat;
  33. import java.util.ArrayList;
  34. import java.util.Base64;
  35. import java.util.List;
  36. @Api(tags = "无车操作")
  37. @RestController
  38. @RequestMapping(value = {"/noCar"})
  39. public class NoCarController {
  40. @Autowired
  41. NoCarRecService noCarRecService;
  42. @Autowired
  43. NoCarBillWayService noCarBillWayService;
  44. @Autowired
  45. NocarInvoiceService nocarInvoiceService;
  46. @Autowired
  47. NoCarCalculateInfoService noCarCalculateInfoService;
  48. @Autowired
  49. NoCarWaybillMapper noCarWaybillMapper;
  50. @Autowired
  51. NoCarService noCarService;
  52. @Autowired
  53. CustomerOperService customerOperService;
  54. /**
  55. * 分页查询无车备案信息
  56. *
  57. * @param page 参数集
  58. * @return 用户集合
  59. */
  60. @PostMapping("/findCarRec")
  61. @ApiOperation(value="分页查询无车/自有车备案信息", notes="分页查询无车/自有车备案信息")
  62. @LoginRequired
  63. public RespR getCustomersByPage(Page page, CustomerCarRec customerCarRec) {
  64. try {
  65. RespR respR = new RespR(noCarRecService.findByPageAndCarRec(page, customerCarRec));
  66. return respR;
  67. }catch (Exception e){
  68. e.printStackTrace();
  69. return new RespR(false,e.getMessage());
  70. }
  71. }
  72. public void setTimeDue(NoCarWayBill noCarWayBill){
  73. if(!StringUtils.isEmpty(noCarWayBill.getStartBegin()) && !"null".equals(noCarWayBill.getStartBegin())){
  74. String [] res = noCarWayBill.getStartBegin().split(",");
  75. noCarWayBill.setStartBegin(res[0]);
  76. noCarWayBill.setStartEnd(res[1]);
  77. }else{
  78. noCarWayBill.setStartBegin(null);
  79. }
  80. if(!StringUtils.isEmpty(noCarWayBill.getEndBegin()) && !"null".equals(noCarWayBill.getEndBegin())){
  81. String [] res = noCarWayBill.getEndBegin().split(",");
  82. noCarWayBill.setEndBegin(res[0]);
  83. noCarWayBill.setEndEnd(res[1]);
  84. }else{
  85. noCarWayBill.setEndBegin(null);
  86. }
  87. }
  88. /**
  89. * 分页查询运单信息
  90. *
  91. * @param page 参数集
  92. * @return 用户集合
  93. */
  94. @PostMapping("/findBillWay")
  95. @ApiOperation(value="分页查询无车运单信息", notes="分页查询无车运单信息")
  96. @LoginRequired
  97. public RespR findBillWay(Page page, NoCarWayBill noCarWayBill) {
  98. try {
  99. setTimeDue(noCarWayBill);
  100. RespR respR = new RespR(noCarBillWayService.findByPageAndWayBill(page, noCarWayBill));
  101. return respR;
  102. }catch (Exception e){
  103. e.printStackTrace();
  104. return new RespR(false,e.getMessage());
  105. }
  106. }
  107. /**
  108. * 重新获取发票并更新状态
  109. *
  110. * @return 用户集合
  111. */
  112. @PostMapping("/updateStatus")
  113. @ApiOperation(value="重新获取发票并更新状态", notes="重新获取发票并更新状态")
  114. @LoginRequired
  115. public RespR updateStatus() {
  116. try {
  117. delGetInvoce(0);
  118. delGetInvoce(1);
  119. return new RespR("更新成功");
  120. }catch (Exception e){
  121. e.printStackTrace();
  122. return new RespR(false,e.getMessage());
  123. }
  124. }
  125. public void delGetInvoce(Integer historyFlag){
  126. NoCarWayBill carWayBill = new NoCarWayBill();
  127. carWayBill.setHisFlag(historyFlag);
  128. carWayBill.setBillwayStatus(2);
  129. List<NoCarWayBill> noCarWayBillsMdEnd = noCarWaybillMapper.selectByHisFlagAndBillStatus(carWayBill);
  130. if(noCarWayBillsMdEnd!=null && noCarWayBillsMdEnd.size()>0){
  131. noCarWayBillsMdEnd.stream().forEach(noCarWayBill -> {
  132. noCarService.getInvoiceByWayBillNumReal(noCarWayBill,true);
  133. });
  134. }
  135. }
  136. /**
  137. * 分页查询异常运单信息
  138. *
  139. * @param page 参数集
  140. * @return 用户集合
  141. */
  142. @PostMapping("/findBillWayException")
  143. @ApiOperation(value="分页查询异常运单信息", notes="分页查询异常运单信息")
  144. @LoginRequired
  145. public RespR findBillWayException(Page page, NoCarWayBill noCarWayBill) {
  146. try {
  147. setTimeDue(noCarWayBill);
  148. RespR respR = new RespR(noCarBillWayService.findByPageAndWayBillException(page, noCarWayBill));
  149. return respR;
  150. }catch (Exception e){
  151. e.printStackTrace();
  152. return new RespR(false,e.getMessage());
  153. }
  154. }
  155. /**
  156. * 分页查询无车运单信息
  157. *
  158. * @param page 参数集
  159. * @return 用户集合
  160. */
  161. @PostMapping("/findNocarInvoices")
  162. @ApiOperation(value="分页查询无车发票信息", notes="分页查询无车发票信息")
  163. @LoginRequired
  164. public RespR findNocarInvoices(Page page, BillInvoice billInvoice) {
  165. try {
  166. if(!StringUtils.isEmpty(billInvoice.getInvoiceMakeTime()) && !"null".equals(billInvoice.getInvoiceMakeTime())){
  167. String [] res =billInvoice.getInvoiceMakeTime().split(",");
  168. billInvoice.setInvoiceMakeStart(res[0]);
  169. billInvoice.setInvoiceMakeEnd(res[1]);
  170. }
  171. RespR respR = new RespR(nocarInvoiceService.findByPageAndInvoice(page, billInvoice));
  172. return respR;
  173. }catch (Exception e){
  174. e.printStackTrace();
  175. return new RespR(false,e.getMessage());
  176. }
  177. }
  178. /**
  179. * 分页查询无车运单统计信息
  180. *
  181. * @param billInvoice
  182. * @return 用户集合
  183. */
  184. @PostMapping("/findNocarInvoicesStatic")
  185. @ApiOperation(value="分页查询无车发票统计信息", notes="分页查询无车发票统计信息")
  186. @LoginRequired
  187. public RespR findNocarInvoicesStatic(BillInvoice billInvoice) {
  188. try {
  189. RespR respR = new RespR(nocarInvoiceService.findInvoiceStatics(billInvoice));
  190. return respR;
  191. }catch (Exception e){
  192. e.printStackTrace();
  193. return new RespR(false,e.getMessage());
  194. }
  195. }
  196. /**
  197. * 批量运单导入
  198. *
  199. * @param file 参数集
  200. * @return
  201. */
  202. @PostMapping("/batchImprotBillWay")
  203. @ApiOperation(value="批量运单导入", notes="批量运单导入")
  204. @LoginRequired
  205. public RespR batchImprotBillWay(@RequestParam("file") MultipartFile file,String customerName) {
  206. try {
  207. ImportParams params = new ImportParams();
  208. params.setTitleRows(1);
  209. params.setHeadRows(1);
  210. params.setKeyIndex(2);
  211. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params) ;list.remove(0);
  212. buildDate(list);
  213. RespR respR = noCarBillWayService.batchBillWayStart(list,customerName);
  214. return respR;
  215. }catch (Exception e){
  216. e.printStackTrace();
  217. return new RespR(false,e.getMessage());
  218. }
  219. }
  220. /**
  221. * 批量运单导入
  222. *
  223. * @param file 参数集
  224. * @return
  225. */
  226. @PostMapping("/batchImprotHistoryBillWay")
  227. @ApiOperation(value="批量历史运单导入", notes="批量历史运单导入")
  228. @LoginRequired
  229. public RespR batchImprotHistoryBillWay(@RequestParam("file") MultipartFile file,String customerName) {
  230. try {
  231. ImportParams params = new ImportParams();
  232. params.setTitleRows(1);
  233. params.setHeadRows(1);
  234. params.setKeyIndex(2);
  235. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params);list.remove(0);
  236. buildDate(list);
  237. RespR respR = noCarBillWayService.batchHsitoryBillWay(list,customerName);
  238. return respR;
  239. }catch (Exception e){
  240. e.printStackTrace();
  241. return new RespR(false,e.getMessage());
  242. }
  243. }
  244. /**
  245. * 批量运单导入
  246. *
  247. * @param file 参数集
  248. * @return
  249. */
  250. @PostMapping("/batchImprotEndBillWay")
  251. @ApiOperation(value="批量运单结束", notes="批量运单结束")
  252. @LoginRequired
  253. public RespR batchImprotEndBillWay(@RequestParam("file") MultipartFile file,String customerName) {
  254. try {
  255. ImportParams params = new ImportParams();
  256. params.setTitleRows(1);
  257. params.setHeadRows(1);
  258. params.setKeyIndex(2);
  259. List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params);
  260. buildDateEnd(list);
  261. RespR respR = noCarBillWayService.batchBillWayEnd(list,customerName);
  262. return respR;
  263. }catch (Exception e){
  264. e.printStackTrace();
  265. return new RespR(false,e.getMessage());
  266. }
  267. }
  268. public void buildDate(List<NoCarWayBill> list){
  269. DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
  270. for(NoCarWayBill noCarWayBill:list){
  271. noCarWayBill.setStartTime(format.format(noCarWayBill.getStartTimeDate()));
  272. noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getPredictEndTimeDate()));
  273. noCarWayBill.setFee(Math.round(noCarWayBill.getFeeD()*100));
  274. }
  275. }
  276. public void buildDateEnd(List<NoCarWayBill> list){
  277. DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
  278. for(NoCarWayBill noCarWayBill:list){
  279. noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getActEndTimeDate()));
  280. }
  281. }
  282. /**
  283. * 分页查询无车计费信息
  284. *
  285. * @param page 参数集
  286. * @return 用户集合
  287. */
  288. @PostMapping("/findBatchList")
  289. @ApiOperation(value="运单批次号查询", notes="运单批次号查询")
  290. @LoginRequired
  291. public RespR findBatchList(Page page, CustomerOper customerOper) {
  292. try {
  293. RespR respR = new RespR(customerOperService.findAllCustomerOper(page, customerOper));
  294. return respR;
  295. }catch (Exception e){
  296. e.printStackTrace();
  297. return new RespR(false,e.getMessage());
  298. }
  299. }
  300. /**
  301. * 分页查询无车计费信息
  302. *
  303. * @param page 参数集
  304. * @return 用户集合
  305. */
  306. @PostMapping("/findNocarCalculateInfo")
  307. @ApiOperation(value="分页查询无车计费信息", notes="分页查询无车计费信息")
  308. @LoginRequired
  309. public RespR findNocarCalculateInfo(Page page, NoCarCalculateInfor carCalculateInfor) {
  310. try {
  311. setTimeDue1(carCalculateInfor);
  312. RespR respR = new RespR(noCarCalculateInfoService.findByPageAndCalculateInfor(page, carCalculateInfor));
  313. return respR;
  314. }catch (Exception e){
  315. e.printStackTrace();
  316. return new RespR(false,e.getMessage());
  317. }
  318. }
  319. @GetMapping("/templateDownload")
  320. @ApiOperation(value="模板下载", notes="模板下载")
  321. public RespR contractDownload(String fileName,HttpServletResponse response){
  322. if("1".equals(fileName)){
  323. fileName = "运单模板.xlsx";
  324. }else if("2".equals(fileName)){
  325. fileName = "运单结束模板.xlsx";
  326. }else if("3".equals(fileName)){
  327. fileName = "历史运单模板.xlsx";
  328. }
  329. String path = this.getClass().getClassLoader().getResource("").getPath();
  330. OutputStream outputStream = null;
  331. InputStream inputStream = null;
  332. try {
  333. File file = new File(path+"static/templates/excel/"+fileName);
  334. inputStream = new FileInputStream(file);
  335. response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
  336. outputStream = response.getOutputStream();
  337. IOUtils.copy(inputStream, outputStream);
  338. response.flushBuffer();
  339. return new RespR(true);
  340. } catch (IOException e) {
  341. } finally {
  342. IOUtils.closeQuietly(inputStream);
  343. IOUtils.closeQuietly(outputStream);
  344. }
  345. return new RespR(false);
  346. }
  347. public void setTimeDue1(NoCarCalculateInfor carCalculateInfor){
  348. if(!StringUtils.isEmpty(carCalculateInfor.getInvoiceMakeTime()) && !"null".equals(carCalculateInfor.getInvoiceMakeTime())){
  349. String [] res = carCalculateInfor.getInvoiceMakeTime().split(",");
  350. carCalculateInfor.setInvoiceMakeStart(res[0]);
  351. carCalculateInfor.setInvoiceMakeEnd(res[1]);
  352. }else{
  353. carCalculateInfor.setInvoiceMakeTime(null);
  354. }
  355. if(!StringUtils.isEmpty(carCalculateInfor.getCalculateTime()) && !"null".equals(carCalculateInfor.getCalculateTime())){
  356. String [] res = carCalculateInfor.getCalculateTime().split(",");
  357. carCalculateInfor.setCalculateStart(res[0]);
  358. carCalculateInfor.setCalculateEnd(res[1]);
  359. }else{
  360. carCalculateInfor.setCalculateTime(null);
  361. }
  362. }
  363. }