123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- package com.jkcredit.invoice.controller.localBussiness;
- import cn.afterturn.easypoi.excel.ExcelImportUtil;
- import cn.afterturn.easypoi.excel.entity.ImportParams;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.jkcredit.invoice.annotation.LoginRequired;
- import com.jkcredit.invoice.mapper.waybill.NoCarWaybillMapper;
- import com.jkcredit.invoice.model.entity.Calculate.NoCarCalculateInfor;
- import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
- import com.jkcredit.invoice.model.entity.customer.CustomerOper;
- import com.jkcredit.invoice.model.entity.customer.CustomerRec;
- import com.jkcredit.invoice.model.entity.invoice.BillInvoice;
- import com.jkcredit.invoice.model.entity.waybill.NoCarWayBill;
- import com.jkcredit.invoice.service.CalculateInfor.NoCarCalculateInfoService;
- import com.jkcredit.invoice.service.customer.CustomerOperService;
- import com.jkcredit.invoice.service.lowerService.NoCarService;
- import com.jkcredit.invoice.service.nocar.NoCarBillWayImportService;
- import com.jkcredit.invoice.service.nocar.NoCarBillWayService;
- import com.jkcredit.invoice.service.nocar.NoCarRecService;
- import com.jkcredit.invoice.service.nocar.NocarInvoiceService;
- import com.jkcredit.invoice.util.ReadExcelUtil;
- import com.jkcredit.invoice.util.RespR;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.poi.util.IOUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.ResourceUtils;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.net.URLEncoder;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Base64;
- import java.util.List;
- @Slf4j
- @Api(tags = "无车操作")
- @RestController
- @RequestMapping(value = {"/noCar"})
- public class NoCarController {
- @Autowired
- NoCarRecService noCarRecService;
- @Autowired
- NoCarBillWayService noCarBillWayService;
- @Autowired
- NoCarBillWayImportService noCarBillWayImportService;
- @Autowired
- NocarInvoiceService nocarInvoiceService;
- @Autowired
- NoCarCalculateInfoService noCarCalculateInfoService;
- @Autowired
- NoCarWaybillMapper noCarWaybillMapper;
- @Autowired
- NoCarService noCarService;
- @Autowired
- CustomerOperService customerOperService;
- /**
- * 分页查询无车备案信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findCarRec")
- @ApiOperation(value="分页查询无车/自有车备案信息", notes="分页查询无车/自有车备案信息")
- @LoginRequired
- public RespR getCustomersByPage(Page page, CustomerCarRec customerCarRec) {
- try {
- RespR respR = new RespR(noCarRecService.findByPageAndCarRec(page, customerCarRec));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- public void setTimeDue(NoCarWayBill noCarWayBill){
- if(!StringUtils.isEmpty(noCarWayBill.getStartBegin()) && !"null".equals(noCarWayBill.getStartBegin())){
- String [] res = noCarWayBill.getStartBegin().split(",");
- noCarWayBill.setStartBegin(res[0]);
- noCarWayBill.setStartEnd(res[1]);
- }else{
- noCarWayBill.setStartBegin(null);
- }
- if(!StringUtils.isEmpty(noCarWayBill.getEndBegin()) && !"null".equals(noCarWayBill.getEndBegin())){
- String [] res = noCarWayBill.getEndBegin().split(",");
- noCarWayBill.setEndBegin(res[0]);
- noCarWayBill.setEndEnd(res[1]);
- }else{
- noCarWayBill.setEndBegin(null);
- }
- }
- public void setTimeDue2(NoCarWayBill noCarWayBill){
- if("null".equals(noCarWayBill.getStartBegin())){
- noCarWayBill.setStartBegin(null);
- }
- if("null".equals(noCarWayBill.getStartEnd())){
- noCarWayBill.setStartEnd(null);
- }
- if("null".equals(noCarWayBill.getEndBegin())){
- noCarWayBill.setEndBegin(null);
- }
- if("null".equals(noCarWayBill.getEndEnd())){
- noCarWayBill.setEndEnd(null);
- }
- }
- /**
- * 分页查询运单信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findBillWay")
- @ApiOperation(value="分页查询无车运单信息", notes="分页查询无车运单信息")
- @LoginRequired
- public RespR findBillWay(Page page, NoCarWayBill noCarWayBill) {
- try {
- setTimeDue(noCarWayBill);
- RespR respR = new RespR(noCarBillWayService.findByPageAndWayBill(page, noCarWayBill));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询客户运单信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findBillWayCust")
- @ApiOperation(value="分页查询无车运单信息", notes="分页查询无车运单信息")
- @LoginRequired
- public RespR findBillWayCust(Page page, NoCarWayBill noCarWayBill) {
- try {
- setTimeDue2(noCarWayBill);
- RespR respR = new RespR(noCarBillWayService.findByPageAndWayBill(page, noCarWayBill));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询运单信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findImportBillWay")
- @ApiOperation(value="分页查询无车运单信息", notes="分页查询无车运单信息")
- @LoginRequired
- public RespR findImportBillWay(Page page, NoCarWayBill noCarWayBill) {
- try {
- setTimeDue(noCarWayBill);
- RespR respR = new RespR(noCarBillWayImportService.findByPageAndWayBill(page, noCarWayBill));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 重新获取发票并更新状态
- *
- * @return 用户集合
- */
- @PostMapping("/updateStatus")
- @ApiOperation(value="重新获取发票并更新状态", notes="重新获取发票并更新状态")
- @LoginRequired
- public RespR updateStatus(String noCarWayBillStr) {
- List<NoCarWayBill> noCarWayBills = JSON.parseArray(noCarWayBillStr,NoCarWayBill.class);
- try {
- if(noCarWayBills!=null && noCarWayBills.size()>0){
- noCarWayBills.stream().forEach(noCarWayBill -> {
- noCarService.getInvoiceByWayBillNumReal(noCarWayBill,true);
- });
- }
- return new RespR("更新成功");
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- public void delGetInvoce(Integer historyFlag){
- log.info("开始取票HISflag:"+historyFlag);
- NoCarWayBill carWayBill = new NoCarWayBill();
- carWayBill.setHisFlag(historyFlag);
- carWayBill.setBillwayStatus(2);
- List<NoCarWayBill> noCarWayBillsMdEnd = noCarWaybillMapper.selectByHisFlagAndBillStatus(carWayBill);
- if(noCarWayBillsMdEnd!=null && noCarWayBillsMdEnd.size()>0){
- noCarWayBillsMdEnd.stream().forEach(noCarWayBill -> {
- noCarService.getInvoiceByWayBillNumReal(noCarWayBill,true);
- });
- }
- }
- /**
- * 分页查询异常运单信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findBillWayException")
- @ApiOperation(value="分页查询异常运单信息", notes="分页查询异常运单信息")
- @LoginRequired
- public RespR findBillWayException(Page page, NoCarWayBill noCarWayBill) {
- try {
- setTimeDue(noCarWayBill);
- RespR respR = new RespR(noCarBillWayService.findByPageAndWayBillException(page, noCarWayBill));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询无车运单信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findNocarInvoices")
- @ApiOperation(value="分页查询无车发票信息", notes="分页查询无车发票信息")
- @LoginRequired
- public RespR findNocarInvoices(Page page, BillInvoice billInvoice) {
- try {
- if(!StringUtils.isEmpty(billInvoice.getInvoiceMakeTime()) && !"null".equals(billInvoice.getInvoiceMakeTime())){
- String [] res =billInvoice.getInvoiceMakeTime().split(",");
- billInvoice.setInvoiceMakeStart(res[0]);
- billInvoice.setInvoiceMakeEnd(res[1]);
- }
- if(!StringUtils.isEmpty(billInvoice.getCalculateTime()) && !"null".equals(billInvoice.getCalculateTime())){
- String [] res =billInvoice.getCalculateTime().split(",");
- billInvoice.setCalculateTimeStart(res[0]);
- billInvoice.setCalculateTimeEnd(res[1]);
- }
- RespR respR = new RespR(nocarInvoiceService.findByPageAndInvoice(page, billInvoice));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量查询无车发票信息
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImportNocarInvoices")
- @ApiOperation(value="批量查询无车发票信息", notes="批量查询无车发票信息")
- @LoginRequired
- public RespR batchImportNocarInvoices(@RequestParam("file") MultipartFile file) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- // params.setKeyIndex(2);
- List<BillInvoice> list = ExcelImportUtil.importExcel(file.getInputStream(), BillInvoice.class,params) ;
- RespR respR = nocarInvoiceService.findImportNocarInvoices(list);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量查询无车运单信息
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImportNocarBillWay")
- @ApiOperation(value="批量查询无车运单信息", notes="批量查询无车运单信息")
- @LoginRequired
- public RespR batchImportNocarBillWay(@RequestParam("file") MultipartFile file) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- // params.setKeyIndex(2);
- List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params) ;
- RespR respR = noCarBillWayService.findImportNocarBillWay(list);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询无车运单统计信息
- *
- * @param billInvoice
- * @return 用户集合
- */
- @PostMapping("/findNocarInvoicesStatic")
- @ApiOperation(value="分页查询无车发票统计信息", notes="分页查询无车发票统计信息")
- @LoginRequired
- public RespR findNocarInvoicesStatic(BillInvoice billInvoice) {
- try {
- if(!StringUtils.isEmpty(billInvoice.getInvoiceMakeTime()) && !"null".equals(billInvoice.getInvoiceMakeTime())){
- String [] res =billInvoice.getInvoiceMakeTime().split(",");
- billInvoice.setInvoiceMakeStart(res[0]);
- billInvoice.setInvoiceMakeEnd(res[1]);
- }
- if(!StringUtils.isEmpty(billInvoice.getCalculateTime()) && !"null".equals(billInvoice.getCalculateTime())){
- String [] res =billInvoice.getCalculateTime().split(",");
- billInvoice.setCalculateTimeStart(res[0]);
- billInvoice.setCalculateTimeEnd(res[1]);
- }
- RespR respR = new RespR(nocarInvoiceService.findInvoiceStatics(billInvoice));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量运单导入
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImprotBillWay")
- @ApiOperation(value="批量运单导入", notes="批量运单导入")
- @LoginRequired
- public RespR batchImprotBillWay(@RequestParam("file") MultipartFile file,String customerName) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- params.setKeyIndex(2);
- List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params) ;
- buildDate(list);
- RespR respR = noCarBillWayService.batchBillWayStart(list,customerName);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量运单导入
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImprotHistoryBillWay")
- @ApiOperation(value="批量历史运单导入", notes="批量历史运单导入")
- @LoginRequired
- public RespR batchImprotHistoryBillWay(@RequestParam("file") MultipartFile file,String customerName) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- params.setKeyIndex(2);
- List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params);
- log.info("1111111111"+list.size());
- buildDate(list);
- RespR respR = noCarBillWayService.batchHsitoryBillWay(list,customerName);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量运单导入
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImprotEndBillWay")
- @ApiOperation(value="批量运单结束", notes="批量运单结束")
- @LoginRequired
- public RespR batchImprotEndBillWay(@RequestParam("file") MultipartFile file,String customerName) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- params.setKeyIndex(2);
- List<NoCarWayBill> list = ExcelImportUtil.importExcel(file.getInputStream(), NoCarWayBill.class,params);
- buildDateEnd(list);
- log.info("1111111111"+list.size());
- RespR respR = noCarBillWayService.batchBillWayEnd(list,customerName);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- public void buildDate(List<NoCarWayBill> list){
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for(NoCarWayBill noCarWayBill:list){
- noCarWayBill.setStartTime(format.format(noCarWayBill.getStartTimeDate()));
- noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getPredictEndTimeDate()));
- noCarWayBill.setFee(Math.round(noCarWayBill.getFeeD()*100));
- }
- }
- public void buildDateEnd(List<NoCarWayBill> list){
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for(NoCarWayBill noCarWayBill:list){
- noCarWayBill.setPredictEndTime(format.format(noCarWayBill.getActEndTimeDate()));
- }
- }
- /**
- * 分页查询无车计费信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findBatchList")
- @ApiOperation(value="运单批次号查询", notes="运单批次号查询")
- @LoginRequired
- public RespR findBatchList(Page page, CustomerOper customerOper) {
- try {
- RespR respR = new RespR(customerOperService.findAllCustomerOper(page, customerOper));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询无车计费信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findNocarCalculateInfo")
- @ApiOperation(value="分页查询无车计费信息", notes="分页查询无车计费信息")
- @LoginRequired
- public RespR findNocarCalculateInfo(Page page, NoCarCalculateInfor carCalculateInfor) {
- try {
- setTimeDue1(carCalculateInfor);
- RespR respR = new RespR(noCarCalculateInfoService.findByPageAndCalculateInfor(page, carCalculateInfor));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询无车计费统计信息
- *
- * @param carCalculateInfor 参数集
- * @return 用户集合
- */
- @PostMapping("/findNocarCalculateInfoStatis")
- @ApiOperation(value="分页查询无车计费统计信息", notes="分页查询无车计费统计信息")
- @LoginRequired
- public RespR findNocarCalculateInfoStatis(NoCarCalculateInfor carCalculateInfor) {
- try {
- setTimeDue1(carCalculateInfor);
- RespR respR = new RespR(noCarCalculateInfoService.findNocarCalculateInfoStatis(carCalculateInfor));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- @GetMapping("/templateDownload")
- @ApiOperation(value="模板下载", notes="模板下载")
- public RespR contractDownload(String fileName,HttpServletResponse response){
- if("1".equals(fileName)){
- fileName = "运单模板.xlsx";
- }else if("2".equals(fileName)){
- fileName = "运单结束模板.xlsx";
- }else if("3".equals(fileName)){
- fileName = "历史运单模板.xlsx";
- }else if("4".equals(fileName)){
- fileName = "无车发票查询模板.xlsx";
- }else if("5".equals(fileName)){
- fileName = "无车运单查询模板.xlsx";
- }else if("6".equals(fileName)){
- fileName = "自有车交易查询模板.xlsx";
- }else if("7".equals(fileName)){
- fileName = "自有车发票查询模板.xlsx";
- }
- OutputStream outputStream = null;
- InputStream inputStream = null;
- try {
- File file = new File("/home/app/excel/"+fileName);
- inputStream = new FileInputStream(file);
- response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
- outputStream = response.getOutputStream();
- IOUtils.copy(inputStream, outputStream);
- response.flushBuffer();
- return new RespR(true);
- } catch (IOException e) {
- } finally {
- IOUtils.closeQuietly(inputStream);
- IOUtils.closeQuietly(outputStream);
- }
- return new RespR(false);
- }
- public void setTimeDue1(NoCarCalculateInfor carCalculateInfor){
- if(!StringUtils.isEmpty(carCalculateInfor.getInvoiceMakeTime()) && !"null".equals(carCalculateInfor.getInvoiceMakeTime())){
- String [] res = carCalculateInfor.getInvoiceMakeTime().split(",");
- carCalculateInfor.setInvoiceMakeStart(res[0]);
- carCalculateInfor.setInvoiceMakeEnd(res[1]);
- }else{
- carCalculateInfor.setInvoiceMakeTime(null);
- }
- if(!StringUtils.isEmpty(carCalculateInfor.getCalculateTime()) && !"null".equals(carCalculateInfor.getCalculateTime())){
- String [] res = carCalculateInfor.getCalculateTime().split(",");
- carCalculateInfor.setCalculateStart(res[0]);
- carCalculateInfor.setCalculateEnd(res[1]);
- }else{
- carCalculateInfor.setCalculateTime(null);
- }
- }
- }
|